]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.14.4-201405271114.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.14.4-201405271114.patch
CommitLineData
719bc6c4
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..e289b9b 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,14 +51,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@@ -69,9 +75,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@@ -80,6 +88,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@@ -92,32 +101,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@@ -125,12 +142,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@@ -145,14 +165,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@@ -162,14 +182,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@@ -185,6 +206,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@@ -194,6 +217,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168+pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172@@ -203,7 +227,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@@ -213,8 +242,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@@ -224,6 +257,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@@ -235,13 +269,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@@ -249,9 +287,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 7116fda..d8ed6e8 100644
239--- a/Documentation/kernel-parameters.txt
240+++ b/Documentation/kernel-parameters.txt
241@@ -1084,6 +1084,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@@ -2080,6 +2084,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@@ -2347,6 +2355,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 d7c07fd..1ad8228 100644
291--- a/Makefile
292+++ b/Makefile
293@@ -244,8 +244,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 # Decide whether to build built-in, modular, or both.
304 # Normally, just do built-in.
305@@ -423,8 +424,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@@ -585,6 +586,72 @@ else
317 KBUILD_CFLAGS += -O2
318 endif
319
320+ifndef DISABLE_PAX_PLUGINS
321+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
322+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
323+else
324+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
325+endif
326+ifneq ($(PLUGINCC),)
327+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
328+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
329+endif
330+ifdef CONFIG_PAX_MEMORY_STACKLEAK
331+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
332+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
333+endif
334+ifdef CONFIG_KALLOCSTAT_PLUGIN
335+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
336+endif
337+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
338+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
339+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
340+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
341+endif
342+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
343+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
344+ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
345+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
346+endif
347+endif
348+ifdef CONFIG_CHECKER_PLUGIN
349+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
350+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
351+endif
352+endif
353+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
354+ifdef CONFIG_PAX_SIZE_OVERFLOW
355+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
356+endif
357+ifdef CONFIG_PAX_LATENT_ENTROPY
358+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
359+endif
360+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
361+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
362+endif
363+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
364+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
365+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
366+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
367+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
368+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
369+ifeq ($(KBUILD_EXTMOD),)
370+gcc-plugins:
371+ $(Q)$(MAKE) $(build)=tools/gcc
372+else
373+gcc-plugins: ;
374+endif
375+else
376+gcc-plugins:
377+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
378+ $(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.))
379+else
380+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
381+endif
382+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
383+endif
384+endif
385+
386 include $(srctree)/arch/$(SRCARCH)/Makefile
387
388 ifdef CONFIG_READABLE_ASM
389@@ -779,7 +846,7 @@ export mod_sign_cmd
390
391
392 ifeq ($(KBUILD_EXTMOD),)
393-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
394+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
395
396 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
397 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
398@@ -828,6 +895,8 @@ endif
399
400 # The actual objects are generated when descending,
401 # make sure no implicit rule kicks in
402+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
403+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
404 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
405
406 # Handle descending into subdirectories listed in $(vmlinux-dirs)
407@@ -837,7 +906,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
408 # Error messages still appears in the original language
409
410 PHONY += $(vmlinux-dirs)
411-$(vmlinux-dirs): prepare scripts
412+$(vmlinux-dirs): gcc-plugins prepare scripts
413 $(Q)$(MAKE) $(build)=$@
414
415 define filechk_kernel.release
416@@ -880,10 +949,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
417
418 archprepare: archheaders archscripts prepare1 scripts_basic
419
420+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 prepare0: archprepare FORCE
423 $(Q)$(MAKE) $(build)=.
424
425 # All the preparing..
426+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
427 prepare: prepare0
428
429 # Generate some files
430@@ -991,6 +1063,8 @@ all: modules
431 # using awk while concatenating to the final file.
432
433 PHONY += modules
434+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
435+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
436 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
437 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
438 @$(kecho) ' Building modules, stage 2.';
439@@ -1006,7 +1080,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
440
441 # Target to prepare building external modules
442 PHONY += modules_prepare
443-modules_prepare: prepare scripts
444+modules_prepare: gcc-plugins prepare scripts
445
446 # Target to install modules
447 PHONY += modules_install
448@@ -1072,7 +1146,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
449 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
450 signing_key.priv signing_key.x509 x509.genkey \
451 extra_certificates signing_key.x509.keyid \
452- signing_key.x509.signer
453+ signing_key.x509.signer \
454+ tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
455+ tools/gcc/size_overflow_plugin/size_overflow_hash.h \
456+ tools/gcc/randomize_layout_seed.h
457
458 # clean - Delete most, but leave enough to build external modules
459 #
460@@ -1112,6 +1189,7 @@ distclean: mrproper
461 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
462 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
463 -o -name '.*.rej' \
464+ -o -name '.*.rej' -o -name '*.so' \
465 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
466 -type f -print | xargs rm -f
467
468@@ -1273,6 +1351,8 @@ PHONY += $(module-dirs) modules
469 $(module-dirs): crmodverdir $(objtree)/Module.symvers
470 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
471
472+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
473+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
474 modules: $(module-dirs)
475 @$(kecho) ' Building modules, stage 2.';
476 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
477@@ -1412,17 +1492,21 @@ else
478 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
479 endif
480
481-%.s: %.c prepare scripts FORCE
482+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
483+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
484+%.s: %.c gcc-plugins prepare scripts FORCE
485 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
486 %.i: %.c prepare scripts FORCE
487 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
488-%.o: %.c prepare scripts FORCE
489+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
490+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
491+%.o: %.c gcc-plugins prepare scripts FORCE
492 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
493 %.lst: %.c prepare scripts FORCE
494 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
495-%.s: %.S prepare scripts FORCE
496+%.s: %.S gcc-plugins prepare scripts FORCE
497 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
498-%.o: %.S prepare scripts FORCE
499+%.o: %.S gcc-plugins prepare scripts FORCE
500 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
501 %.symtypes: %.c prepare scripts FORCE
502 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
503@@ -1432,11 +1516,15 @@ endif
504 $(cmd_crmodverdir)
505 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
506 $(build)=$(build-dir)
507-%/: prepare scripts FORCE
508+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
509+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
510+%/: gcc-plugins prepare scripts FORCE
511 $(cmd_crmodverdir)
512 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
513 $(build)=$(build-dir)
514-%.ko: prepare scripts FORCE
515+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
516+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
517+%.ko: gcc-plugins prepare scripts FORCE
518 $(cmd_crmodverdir)
519 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
520 $(build)=$(build-dir) $(@:.ko=.o)
521diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
522index 78b03ef..da28a51 100644
523--- a/arch/alpha/include/asm/atomic.h
524+++ b/arch/alpha/include/asm/atomic.h
525@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
526 #define atomic_dec(v) atomic_sub(1,(v))
527 #define atomic64_dec(v) atomic64_sub(1,(v))
528
529+#define atomic64_read_unchecked(v) atomic64_read(v)
530+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
531+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
532+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
533+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
534+#define atomic64_inc_unchecked(v) atomic64_inc(v)
535+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
536+#define atomic64_dec_unchecked(v) atomic64_dec(v)
537+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
538+
539 #define smp_mb__before_atomic_dec() smp_mb()
540 #define smp_mb__after_atomic_dec() smp_mb()
541 #define smp_mb__before_atomic_inc() smp_mb()
542diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
543index ad368a9..fbe0f25 100644
544--- a/arch/alpha/include/asm/cache.h
545+++ b/arch/alpha/include/asm/cache.h
546@@ -4,19 +4,19 @@
547 #ifndef __ARCH_ALPHA_CACHE_H
548 #define __ARCH_ALPHA_CACHE_H
549
550+#include <linux/const.h>
551
552 /* Bytes per L1 (data) cache line. */
553 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
554-# define L1_CACHE_BYTES 64
555 # define L1_CACHE_SHIFT 6
556 #else
557 /* Both EV4 and EV5 are write-through, read-allocate,
558 direct-mapped, physical.
559 */
560-# define L1_CACHE_BYTES 32
561 # define L1_CACHE_SHIFT 5
562 #endif
563
564+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
565 #define SMP_CACHE_BYTES L1_CACHE_BYTES
566
567 #endif
568diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
569index 968d999..d36b2df 100644
570--- a/arch/alpha/include/asm/elf.h
571+++ b/arch/alpha/include/asm/elf.h
572@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
573
574 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
575
576+#ifdef CONFIG_PAX_ASLR
577+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
578+
579+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
580+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
581+#endif
582+
583 /* $0 is set by ld.so to a pointer to a function which might be
584 registered using atexit. This provides a mean for the dynamic
585 linker to call DT_FINI functions for shared libraries that have
586diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
587index aab14a0..b4fa3e7 100644
588--- a/arch/alpha/include/asm/pgalloc.h
589+++ b/arch/alpha/include/asm/pgalloc.h
590@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
591 pgd_set(pgd, pmd);
592 }
593
594+static inline void
595+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
596+{
597+ pgd_populate(mm, pgd, pmd);
598+}
599+
600 extern pgd_t *pgd_alloc(struct mm_struct *mm);
601
602 static inline void
603diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
604index d8f9b7e..f6222fa 100644
605--- a/arch/alpha/include/asm/pgtable.h
606+++ b/arch/alpha/include/asm/pgtable.h
607@@ -102,6 +102,17 @@ struct vm_area_struct;
608 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
609 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
610 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
611+
612+#ifdef CONFIG_PAX_PAGEEXEC
613+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
614+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
615+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
616+#else
617+# define PAGE_SHARED_NOEXEC PAGE_SHARED
618+# define PAGE_COPY_NOEXEC PAGE_COPY
619+# define PAGE_READONLY_NOEXEC PAGE_READONLY
620+#endif
621+
622 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
623
624 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
625diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
626index 2fd00b7..cfd5069 100644
627--- a/arch/alpha/kernel/module.c
628+++ b/arch/alpha/kernel/module.c
629@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
630
631 /* The small sections were sorted to the end of the segment.
632 The following should definitely cover them. */
633- gp = (u64)me->module_core + me->core_size - 0x8000;
634+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
635 got = sechdrs[me->arch.gotsecindex].sh_addr;
636
637 for (i = 0; i < n; i++) {
638diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
639index 1402fcc..0b1abd2 100644
640--- a/arch/alpha/kernel/osf_sys.c
641+++ b/arch/alpha/kernel/osf_sys.c
642@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
643 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
644
645 static unsigned long
646-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
647- unsigned long limit)
648+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
649+ unsigned long limit, unsigned long flags)
650 {
651 struct vm_unmapped_area_info info;
652+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
653
654 info.flags = 0;
655 info.length = len;
656@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
657 info.high_limit = limit;
658 info.align_mask = 0;
659 info.align_offset = 0;
660+ info.threadstack_offset = offset;
661 return vm_unmapped_area(&info);
662 }
663
664@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
665 merely specific addresses, but regions of memory -- perhaps
666 this feature should be incorporated into all ports? */
667
668+#ifdef CONFIG_PAX_RANDMMAP
669+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
670+#endif
671+
672 if (addr) {
673- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
674+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
675 if (addr != (unsigned long) -ENOMEM)
676 return addr;
677 }
678
679 /* Next, try allocating at TASK_UNMAPPED_BASE. */
680- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
681- len, limit);
682+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
683+
684 if (addr != (unsigned long) -ENOMEM)
685 return addr;
686
687 /* Finally, try allocating in low memory. */
688- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
689+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
690
691 return addr;
692 }
693diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
694index 98838a0..b304fb4 100644
695--- a/arch/alpha/mm/fault.c
696+++ b/arch/alpha/mm/fault.c
697@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
698 __reload_thread(pcb);
699 }
700
701+#ifdef CONFIG_PAX_PAGEEXEC
702+/*
703+ * PaX: decide what to do with offenders (regs->pc = fault address)
704+ *
705+ * returns 1 when task should be killed
706+ * 2 when patched PLT trampoline was detected
707+ * 3 when unpatched PLT trampoline was detected
708+ */
709+static int pax_handle_fetch_fault(struct pt_regs *regs)
710+{
711+
712+#ifdef CONFIG_PAX_EMUPLT
713+ int err;
714+
715+ do { /* PaX: patched PLT emulation #1 */
716+ unsigned int ldah, ldq, jmp;
717+
718+ err = get_user(ldah, (unsigned int *)regs->pc);
719+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
720+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
721+
722+ if (err)
723+ break;
724+
725+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
726+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
727+ jmp == 0x6BFB0000U)
728+ {
729+ unsigned long r27, addr;
730+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
731+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
732+
733+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
734+ err = get_user(r27, (unsigned long *)addr);
735+ if (err)
736+ break;
737+
738+ regs->r27 = r27;
739+ regs->pc = r27;
740+ return 2;
741+ }
742+ } while (0);
743+
744+ do { /* PaX: patched PLT emulation #2 */
745+ unsigned int ldah, lda, br;
746+
747+ err = get_user(ldah, (unsigned int *)regs->pc);
748+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
749+ err |= get_user(br, (unsigned int *)(regs->pc+8));
750+
751+ if (err)
752+ break;
753+
754+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
755+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
756+ (br & 0xFFE00000U) == 0xC3E00000U)
757+ {
758+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
759+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
760+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
761+
762+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
763+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
764+ return 2;
765+ }
766+ } while (0);
767+
768+ do { /* PaX: unpatched PLT emulation */
769+ unsigned int br;
770+
771+ err = get_user(br, (unsigned int *)regs->pc);
772+
773+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
774+ unsigned int br2, ldq, nop, jmp;
775+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
776+
777+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
778+ err = get_user(br2, (unsigned int *)addr);
779+ err |= get_user(ldq, (unsigned int *)(addr+4));
780+ err |= get_user(nop, (unsigned int *)(addr+8));
781+ err |= get_user(jmp, (unsigned int *)(addr+12));
782+ err |= get_user(resolver, (unsigned long *)(addr+16));
783+
784+ if (err)
785+ break;
786+
787+ if (br2 == 0xC3600000U &&
788+ ldq == 0xA77B000CU &&
789+ nop == 0x47FF041FU &&
790+ jmp == 0x6B7B0000U)
791+ {
792+ regs->r28 = regs->pc+4;
793+ regs->r27 = addr+16;
794+ regs->pc = resolver;
795+ return 3;
796+ }
797+ }
798+ } while (0);
799+#endif
800+
801+ return 1;
802+}
803+
804+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
805+{
806+ unsigned long i;
807+
808+ printk(KERN_ERR "PAX: bytes at PC: ");
809+ for (i = 0; i < 5; i++) {
810+ unsigned int c;
811+ if (get_user(c, (unsigned int *)pc+i))
812+ printk(KERN_CONT "???????? ");
813+ else
814+ printk(KERN_CONT "%08x ", c);
815+ }
816+ printk("\n");
817+}
818+#endif
819
820 /*
821 * This routine handles page faults. It determines the address,
822@@ -133,8 +251,29 @@ retry:
823 good_area:
824 si_code = SEGV_ACCERR;
825 if (cause < 0) {
826- if (!(vma->vm_flags & VM_EXEC))
827+ if (!(vma->vm_flags & VM_EXEC)) {
828+
829+#ifdef CONFIG_PAX_PAGEEXEC
830+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
831+ goto bad_area;
832+
833+ up_read(&mm->mmap_sem);
834+ switch (pax_handle_fetch_fault(regs)) {
835+
836+#ifdef CONFIG_PAX_EMUPLT
837+ case 2:
838+ case 3:
839+ return;
840+#endif
841+
842+ }
843+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
844+ do_group_exit(SIGKILL);
845+#else
846 goto bad_area;
847+#endif
848+
849+ }
850 } else if (!cause) {
851 /* Allow reads even for write-only mappings */
852 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
853diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
854index 44298ad..29a20c0 100644
855--- a/arch/arm/Kconfig
856+++ b/arch/arm/Kconfig
857@@ -1862,7 +1862,7 @@ config ALIGNMENT_TRAP
858
859 config UACCESS_WITH_MEMCPY
860 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
861- depends on MMU
862+ depends on MMU && !PAX_MEMORY_UDEREF
863 default y if CPU_FEROCEON
864 help
865 Implement faster copy_to_user and clear_user methods for CPU
866@@ -2125,6 +2125,7 @@ config XIP_PHYS_ADDR
867 config KEXEC
868 bool "Kexec system call (EXPERIMENTAL)"
869 depends on (!SMP || PM_SLEEP_SMP)
870+ depends on !GRKERNSEC_KMEM
871 help
872 kexec is a system call that implements the ability to shutdown your
873 current kernel, and to start another kernel. It is like a reboot
874diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
875index 62d2cb5..09d45e3 100644
876--- a/arch/arm/include/asm/atomic.h
877+++ b/arch/arm/include/asm/atomic.h
878@@ -18,17 +18,35 @@
879 #include <asm/barrier.h>
880 #include <asm/cmpxchg.h>
881
882+#ifdef CONFIG_GENERIC_ATOMIC64
883+#include <asm-generic/atomic64.h>
884+#endif
885+
886 #define ATOMIC_INIT(i) { (i) }
887
888 #ifdef __KERNEL__
889
890+#define _ASM_EXTABLE(from, to) \
891+" .pushsection __ex_table,\"a\"\n"\
892+" .align 3\n" \
893+" .long " #from ", " #to"\n" \
894+" .popsection"
895+
896 /*
897 * On ARM, ordinary assignment (str instruction) doesn't clear the local
898 * strex/ldrex monitor on some implementations. The reason we can use it for
899 * atomic_set() is the clrex or dummy strex done on every exception return.
900 */
901 #define atomic_read(v) (*(volatile int *)&(v)->counter)
902+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
903+{
904+ return v->counter;
905+}
906 #define atomic_set(v,i) (((v)->counter) = (i))
907+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
908+{
909+ v->counter = i;
910+}
911
912 #if __LINUX_ARM_ARCH__ >= 6
913
914@@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
915
916 prefetchw(&v->counter);
917 __asm__ __volatile__("@ atomic_add\n"
918+"1: ldrex %1, [%3]\n"
919+" adds %0, %1, %4\n"
920+
921+#ifdef CONFIG_PAX_REFCOUNT
922+" bvc 3f\n"
923+"2: bkpt 0xf103\n"
924+"3:\n"
925+#endif
926+
927+" strex %1, %0, [%3]\n"
928+" teq %1, #0\n"
929+" bne 1b"
930+
931+#ifdef CONFIG_PAX_REFCOUNT
932+"\n4:\n"
933+ _ASM_EXTABLE(2b, 4b)
934+#endif
935+
936+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
937+ : "r" (&v->counter), "Ir" (i)
938+ : "cc");
939+}
940+
941+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
942+{
943+ unsigned long tmp;
944+ int result;
945+
946+ prefetchw(&v->counter);
947+ __asm__ __volatile__("@ atomic_add_unchecked\n"
948 "1: ldrex %0, [%3]\n"
949 " add %0, %0, %4\n"
950 " strex %1, %0, [%3]\n"
951@@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
952 smp_mb();
953
954 __asm__ __volatile__("@ atomic_add_return\n"
955+"1: ldrex %1, [%3]\n"
956+" adds %0, %1, %4\n"
957+
958+#ifdef CONFIG_PAX_REFCOUNT
959+" bvc 3f\n"
960+" mov %0, %1\n"
961+"2: bkpt 0xf103\n"
962+"3:\n"
963+#endif
964+
965+" strex %1, %0, [%3]\n"
966+" teq %1, #0\n"
967+" bne 1b"
968+
969+#ifdef CONFIG_PAX_REFCOUNT
970+"\n4:\n"
971+ _ASM_EXTABLE(2b, 4b)
972+#endif
973+
974+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
975+ : "r" (&v->counter), "Ir" (i)
976+ : "cc");
977+
978+ smp_mb();
979+
980+ return result;
981+}
982+
983+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
984+{
985+ unsigned long tmp;
986+ int result;
987+
988+ smp_mb();
989+
990+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
991 "1: ldrex %0, [%3]\n"
992 " add %0, %0, %4\n"
993 " strex %1, %0, [%3]\n"
994@@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
995
996 prefetchw(&v->counter);
997 __asm__ __volatile__("@ atomic_sub\n"
998+"1: ldrex %1, [%3]\n"
999+" subs %0, %1, %4\n"
1000+
1001+#ifdef CONFIG_PAX_REFCOUNT
1002+" bvc 3f\n"
1003+"2: bkpt 0xf103\n"
1004+"3:\n"
1005+#endif
1006+
1007+" strex %1, %0, [%3]\n"
1008+" teq %1, #0\n"
1009+" bne 1b"
1010+
1011+#ifdef CONFIG_PAX_REFCOUNT
1012+"\n4:\n"
1013+ _ASM_EXTABLE(2b, 4b)
1014+#endif
1015+
1016+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1017+ : "r" (&v->counter), "Ir" (i)
1018+ : "cc");
1019+}
1020+
1021+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1022+{
1023+ unsigned long tmp;
1024+ int result;
1025+
1026+ prefetchw(&v->counter);
1027+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1028 "1: ldrex %0, [%3]\n"
1029 " sub %0, %0, %4\n"
1030 " strex %1, %0, [%3]\n"
1031@@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1032 smp_mb();
1033
1034 __asm__ __volatile__("@ atomic_sub_return\n"
1035-"1: ldrex %0, [%3]\n"
1036-" sub %0, %0, %4\n"
1037+"1: ldrex %1, [%3]\n"
1038+" subs %0, %1, %4\n"
1039+
1040+#ifdef CONFIG_PAX_REFCOUNT
1041+" bvc 3f\n"
1042+" mov %0, %1\n"
1043+"2: bkpt 0xf103\n"
1044+"3:\n"
1045+#endif
1046+
1047 " strex %1, %0, [%3]\n"
1048 " teq %1, #0\n"
1049 " bne 1b"
1050+
1051+#ifdef CONFIG_PAX_REFCOUNT
1052+"\n4:\n"
1053+ _ASM_EXTABLE(2b, 4b)
1054+#endif
1055+
1056 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1057 : "r" (&v->counter), "Ir" (i)
1058 : "cc");
1059@@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1060 return oldval;
1061 }
1062
1063+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1064+{
1065+ unsigned long oldval, res;
1066+
1067+ smp_mb();
1068+
1069+ do {
1070+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1071+ "ldrex %1, [%3]\n"
1072+ "mov %0, #0\n"
1073+ "teq %1, %4\n"
1074+ "strexeq %0, %5, [%3]\n"
1075+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1076+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1077+ : "cc");
1078+ } while (res);
1079+
1080+ smp_mb();
1081+
1082+ return oldval;
1083+}
1084+
1085 #else /* ARM_ARCH_6 */
1086
1087 #ifdef CONFIG_SMP
1088@@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1089
1090 return val;
1091 }
1092+
1093+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1094+{
1095+ return atomic_add_return(i, v);
1096+}
1097+
1098 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1099+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1100+{
1101+ (void) atomic_add_return(i, v);
1102+}
1103
1104 static inline int atomic_sub_return(int i, atomic_t *v)
1105 {
1106@@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1107 return val;
1108 }
1109 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1110+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1111+{
1112+ (void) atomic_sub_return(i, v);
1113+}
1114
1115 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1116 {
1117@@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1118 return ret;
1119 }
1120
1121+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1122+{
1123+ return atomic_cmpxchg(v, old, new);
1124+}
1125+
1126 #endif /* __LINUX_ARM_ARCH__ */
1127
1128 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1129+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1130+{
1131+ return xchg(&v->counter, new);
1132+}
1133
1134 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1135 {
1136@@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1137 }
1138
1139 #define atomic_inc(v) atomic_add(1, v)
1140+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1141+{
1142+ atomic_add_unchecked(1, v);
1143+}
1144 #define atomic_dec(v) atomic_sub(1, v)
1145+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1146+{
1147+ atomic_sub_unchecked(1, v);
1148+}
1149
1150 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1151+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1152+{
1153+ return atomic_add_return_unchecked(1, v) == 0;
1154+}
1155 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1156 #define atomic_inc_return(v) (atomic_add_return(1, v))
1157+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1158+{
1159+ return atomic_add_return_unchecked(1, v);
1160+}
1161 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1162 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1163
1164@@ -221,6 +410,14 @@ typedef struct {
1165 long long counter;
1166 } atomic64_t;
1167
1168+#ifdef CONFIG_PAX_REFCOUNT
1169+typedef struct {
1170+ long long counter;
1171+} atomic64_unchecked_t;
1172+#else
1173+typedef atomic64_t atomic64_unchecked_t;
1174+#endif
1175+
1176 #define ATOMIC64_INIT(i) { (i) }
1177
1178 #ifdef CONFIG_ARM_LPAE
1179@@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1180 return result;
1181 }
1182
1183+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1184+{
1185+ long long result;
1186+
1187+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1188+" ldrd %0, %H0, [%1]"
1189+ : "=&r" (result)
1190+ : "r" (&v->counter), "Qo" (v->counter)
1191+ );
1192+
1193+ return result;
1194+}
1195+
1196 static inline void atomic64_set(atomic64_t *v, long long i)
1197 {
1198 __asm__ __volatile__("@ atomic64_set\n"
1199@@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1200 : "r" (&v->counter), "r" (i)
1201 );
1202 }
1203+
1204+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1205+{
1206+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1207+" strd %2, %H2, [%1]"
1208+ : "=Qo" (v->counter)
1209+ : "r" (&v->counter), "r" (i)
1210+ );
1211+}
1212 #else
1213 static inline long long atomic64_read(const atomic64_t *v)
1214 {
1215@@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1216 return result;
1217 }
1218
1219+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1220+{
1221+ long long result;
1222+
1223+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1224+" ldrexd %0, %H0, [%1]"
1225+ : "=&r" (result)
1226+ : "r" (&v->counter), "Qo" (v->counter)
1227+ );
1228+
1229+ return result;
1230+}
1231+
1232 static inline void atomic64_set(atomic64_t *v, long long i)
1233 {
1234 long long tmp;
1235@@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1236 : "r" (&v->counter), "r" (i)
1237 : "cc");
1238 }
1239+
1240+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1241+{
1242+ long long tmp;
1243+
1244+ prefetchw(&v->counter);
1245+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1246+"1: ldrexd %0, %H0, [%2]\n"
1247+" strexd %0, %3, %H3, [%2]\n"
1248+" teq %0, #0\n"
1249+" bne 1b"
1250+ : "=&r" (tmp), "=Qo" (v->counter)
1251+ : "r" (&v->counter), "r" (i)
1252+ : "cc");
1253+}
1254 #endif
1255
1256 static inline void atomic64_add(long long i, atomic64_t *v)
1257@@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1258 __asm__ __volatile__("@ atomic64_add\n"
1259 "1: ldrexd %0, %H0, [%3]\n"
1260 " adds %Q0, %Q0, %Q4\n"
1261+" adcs %R0, %R0, %R4\n"
1262+
1263+#ifdef CONFIG_PAX_REFCOUNT
1264+" bvc 3f\n"
1265+"2: bkpt 0xf103\n"
1266+"3:\n"
1267+#endif
1268+
1269+" strexd %1, %0, %H0, [%3]\n"
1270+" teq %1, #0\n"
1271+" bne 1b"
1272+
1273+#ifdef CONFIG_PAX_REFCOUNT
1274+"\n4:\n"
1275+ _ASM_EXTABLE(2b, 4b)
1276+#endif
1277+
1278+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1279+ : "r" (&v->counter), "r" (i)
1280+ : "cc");
1281+}
1282+
1283+static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1284+{
1285+ long long result;
1286+ unsigned long tmp;
1287+
1288+ prefetchw(&v->counter);
1289+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1290+"1: ldrexd %0, %H0, [%3]\n"
1291+" adds %Q0, %Q0, %Q4\n"
1292 " adc %R0, %R0, %R4\n"
1293 " strexd %1, %0, %H0, [%3]\n"
1294 " teq %1, #0\n"
1295@@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1296 __asm__ __volatile__("@ atomic64_add_return\n"
1297 "1: ldrexd %0, %H0, [%3]\n"
1298 " adds %Q0, %Q0, %Q4\n"
1299+" adcs %R0, %R0, %R4\n"
1300+
1301+#ifdef CONFIG_PAX_REFCOUNT
1302+" bvc 3f\n"
1303+" mov %0, %1\n"
1304+" mov %H0, %H1\n"
1305+"2: bkpt 0xf103\n"
1306+"3:\n"
1307+#endif
1308+
1309+" strexd %1, %0, %H0, [%3]\n"
1310+" teq %1, #0\n"
1311+" bne 1b"
1312+
1313+#ifdef CONFIG_PAX_REFCOUNT
1314+"\n4:\n"
1315+ _ASM_EXTABLE(2b, 4b)
1316+#endif
1317+
1318+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1319+ : "r" (&v->counter), "r" (i)
1320+ : "cc");
1321+
1322+ smp_mb();
1323+
1324+ return result;
1325+}
1326+
1327+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1328+{
1329+ long long result;
1330+ unsigned long tmp;
1331+
1332+ smp_mb();
1333+
1334+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1335+"1: ldrexd %0, %H0, [%3]\n"
1336+" adds %Q0, %Q0, %Q4\n"
1337 " adc %R0, %R0, %R4\n"
1338 " strexd %1, %0, %H0, [%3]\n"
1339 " teq %1, #0\n"
1340@@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1341 __asm__ __volatile__("@ atomic64_sub\n"
1342 "1: ldrexd %0, %H0, [%3]\n"
1343 " subs %Q0, %Q0, %Q4\n"
1344+" sbcs %R0, %R0, %R4\n"
1345+
1346+#ifdef CONFIG_PAX_REFCOUNT
1347+" bvc 3f\n"
1348+"2: bkpt 0xf103\n"
1349+"3:\n"
1350+#endif
1351+
1352+" strexd %1, %0, %H0, [%3]\n"
1353+" teq %1, #0\n"
1354+" bne 1b"
1355+
1356+#ifdef CONFIG_PAX_REFCOUNT
1357+"\n4:\n"
1358+ _ASM_EXTABLE(2b, 4b)
1359+#endif
1360+
1361+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1362+ : "r" (&v->counter), "r" (i)
1363+ : "cc");
1364+}
1365+
1366+static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1367+{
1368+ long long result;
1369+ unsigned long tmp;
1370+
1371+ prefetchw(&v->counter);
1372+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1373+"1: ldrexd %0, %H0, [%3]\n"
1374+" subs %Q0, %Q0, %Q4\n"
1375 " sbc %R0, %R0, %R4\n"
1376 " strexd %1, %0, %H0, [%3]\n"
1377 " teq %1, #0\n"
1378@@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1379 __asm__ __volatile__("@ atomic64_sub_return\n"
1380 "1: ldrexd %0, %H0, [%3]\n"
1381 " subs %Q0, %Q0, %Q4\n"
1382-" sbc %R0, %R0, %R4\n"
1383+" sbcs %R0, %R0, %R4\n"
1384+
1385+#ifdef CONFIG_PAX_REFCOUNT
1386+" bvc 3f\n"
1387+" mov %0, %1\n"
1388+" mov %H0, %H1\n"
1389+"2: bkpt 0xf103\n"
1390+"3:\n"
1391+#endif
1392+
1393 " strexd %1, %0, %H0, [%3]\n"
1394 " teq %1, #0\n"
1395 " bne 1b"
1396+
1397+#ifdef CONFIG_PAX_REFCOUNT
1398+"\n4:\n"
1399+ _ASM_EXTABLE(2b, 4b)
1400+#endif
1401+
1402 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1403 : "r" (&v->counter), "r" (i)
1404 : "cc");
1405
1406- smp_mb();
1407-
1408 return result;
1409 }
1410
1411@@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1412 return oldval;
1413 }
1414
1415+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1416+ long long new)
1417+{
1418+ long long oldval;
1419+ unsigned long res;
1420+
1421+ smp_mb();
1422+
1423+ do {
1424+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1425+ "ldrexd %1, %H1, [%3]\n"
1426+ "mov %0, #0\n"
1427+ "teq %1, %4\n"
1428+ "teqeq %H1, %H4\n"
1429+ "strexdeq %0, %5, %H5, [%3]"
1430+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1431+ : "r" (&ptr->counter), "r" (old), "r" (new)
1432+ : "cc");
1433+ } while (res);
1434+
1435+ smp_mb();
1436+
1437+ return oldval;
1438+}
1439+
1440 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1441 {
1442 long long result;
1443@@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1444 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1445 {
1446 long long result;
1447- unsigned long tmp;
1448+ u64 tmp;
1449
1450 smp_mb();
1451
1452 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1453-"1: ldrexd %0, %H0, [%3]\n"
1454-" subs %Q0, %Q0, #1\n"
1455-" sbc %R0, %R0, #0\n"
1456+"1: ldrexd %1, %H1, [%3]\n"
1457+" subs %Q0, %Q1, #1\n"
1458+" sbcs %R0, %R1, #0\n"
1459+
1460+#ifdef CONFIG_PAX_REFCOUNT
1461+" bvc 3f\n"
1462+" mov %Q0, %Q1\n"
1463+" mov %R0, %R1\n"
1464+"2: bkpt 0xf103\n"
1465+"3:\n"
1466+#endif
1467+
1468 " teq %R0, #0\n"
1469-" bmi 2f\n"
1470+" bmi 4f\n"
1471 " strexd %1, %0, %H0, [%3]\n"
1472 " teq %1, #0\n"
1473 " bne 1b\n"
1474-"2:"
1475+"4:\n"
1476+
1477+#ifdef CONFIG_PAX_REFCOUNT
1478+ _ASM_EXTABLE(2b, 4b)
1479+#endif
1480+
1481 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1482 : "r" (&v->counter)
1483 : "cc");
1484@@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1485 " teq %0, %5\n"
1486 " teqeq %H0, %H5\n"
1487 " moveq %1, #0\n"
1488-" beq 2f\n"
1489+" beq 4f\n"
1490 " adds %Q0, %Q0, %Q6\n"
1491-" adc %R0, %R0, %R6\n"
1492+" adcs %R0, %R0, %R6\n"
1493+
1494+#ifdef CONFIG_PAX_REFCOUNT
1495+" bvc 3f\n"
1496+"2: bkpt 0xf103\n"
1497+"3:\n"
1498+#endif
1499+
1500 " strexd %2, %0, %H0, [%4]\n"
1501 " teq %2, #0\n"
1502 " bne 1b\n"
1503-"2:"
1504+"4:\n"
1505+
1506+#ifdef CONFIG_PAX_REFCOUNT
1507+ _ASM_EXTABLE(2b, 4b)
1508+#endif
1509+
1510 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1511 : "r" (&v->counter), "r" (u), "r" (a)
1512 : "cc");
1513@@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1514
1515 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1516 #define atomic64_inc(v) atomic64_add(1LL, (v))
1517+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1518 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1519+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1520 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1521 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1522 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1523+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1524 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1525 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1526 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1527diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1528index 75fe66b..ba3dee4 100644
1529--- a/arch/arm/include/asm/cache.h
1530+++ b/arch/arm/include/asm/cache.h
1531@@ -4,8 +4,10 @@
1532 #ifndef __ASMARM_CACHE_H
1533 #define __ASMARM_CACHE_H
1534
1535+#include <linux/const.h>
1536+
1537 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1538-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1539+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1540
1541 /*
1542 * Memory returned by kmalloc() may be used for DMA, so we must make
1543@@ -24,5 +26,6 @@
1544 #endif
1545
1546 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1547+#define __read_only __attribute__ ((__section__(".data..read_only")))
1548
1549 #endif
1550diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1551index 8b8b616..d973d24 100644
1552--- a/arch/arm/include/asm/cacheflush.h
1553+++ b/arch/arm/include/asm/cacheflush.h
1554@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1555 void (*dma_unmap_area)(const void *, size_t, int);
1556
1557 void (*dma_flush_range)(const void *, const void *);
1558-};
1559+} __no_const;
1560
1561 /*
1562 * Select the calling method
1563diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1564index 5233151..87a71fa 100644
1565--- a/arch/arm/include/asm/checksum.h
1566+++ b/arch/arm/include/asm/checksum.h
1567@@ -37,7 +37,19 @@ __wsum
1568 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1569
1570 __wsum
1571-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1572+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1573+
1574+static inline __wsum
1575+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1576+{
1577+ __wsum ret;
1578+ pax_open_userland();
1579+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1580+ pax_close_userland();
1581+ return ret;
1582+}
1583+
1584+
1585
1586 /*
1587 * Fold a partial checksum without adding pseudo headers
1588diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1589index df2fbba..63fe3e1 100644
1590--- a/arch/arm/include/asm/cmpxchg.h
1591+++ b/arch/arm/include/asm/cmpxchg.h
1592@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1593
1594 #define xchg(ptr,x) \
1595 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1596+#define xchg_unchecked(ptr,x) \
1597+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1598
1599 #include <asm-generic/cmpxchg-local.h>
1600
1601diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1602index 6ddbe44..b5e38b1 100644
1603--- a/arch/arm/include/asm/domain.h
1604+++ b/arch/arm/include/asm/domain.h
1605@@ -48,18 +48,37 @@
1606 * Domain types
1607 */
1608 #define DOMAIN_NOACCESS 0
1609-#define DOMAIN_CLIENT 1
1610 #ifdef CONFIG_CPU_USE_DOMAINS
1611+#define DOMAIN_USERCLIENT 1
1612+#define DOMAIN_KERNELCLIENT 1
1613 #define DOMAIN_MANAGER 3
1614+#define DOMAIN_VECTORS DOMAIN_USER
1615 #else
1616+
1617+#ifdef CONFIG_PAX_KERNEXEC
1618 #define DOMAIN_MANAGER 1
1619+#define DOMAIN_KERNEXEC 3
1620+#else
1621+#define DOMAIN_MANAGER 1
1622+#endif
1623+
1624+#ifdef CONFIG_PAX_MEMORY_UDEREF
1625+#define DOMAIN_USERCLIENT 0
1626+#define DOMAIN_UDEREF 1
1627+#define DOMAIN_VECTORS DOMAIN_KERNEL
1628+#else
1629+#define DOMAIN_USERCLIENT 1
1630+#define DOMAIN_VECTORS DOMAIN_USER
1631+#endif
1632+#define DOMAIN_KERNELCLIENT 1
1633+
1634 #endif
1635
1636 #define domain_val(dom,type) ((type) << (2*(dom)))
1637
1638 #ifndef __ASSEMBLY__
1639
1640-#ifdef CONFIG_CPU_USE_DOMAINS
1641+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1642 static inline void set_domain(unsigned val)
1643 {
1644 asm volatile(
1645@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1646 isb();
1647 }
1648
1649-#define modify_domain(dom,type) \
1650- do { \
1651- struct thread_info *thread = current_thread_info(); \
1652- unsigned int domain = thread->cpu_domain; \
1653- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1654- thread->cpu_domain = domain | domain_val(dom, type); \
1655- set_domain(thread->cpu_domain); \
1656- } while (0)
1657-
1658+extern void modify_domain(unsigned int dom, unsigned int type);
1659 #else
1660 static inline void set_domain(unsigned val) { }
1661 static inline void modify_domain(unsigned dom, unsigned type) { }
1662diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1663index f4b46d3..abc9b2b 100644
1664--- a/arch/arm/include/asm/elf.h
1665+++ b/arch/arm/include/asm/elf.h
1666@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1667 the loader. We need to make sure that it is out of the way of the program
1668 that it will "exec", and that there is sufficient room for the brk. */
1669
1670-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1671+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1672+
1673+#ifdef CONFIG_PAX_ASLR
1674+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1675+
1676+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1677+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1678+#endif
1679
1680 /* When the program starts, a1 contains a pointer to a function to be
1681 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1682@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1683 extern void elf_set_personality(const struct elf32_hdr *);
1684 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1685
1686-struct mm_struct;
1687-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1688-#define arch_randomize_brk arch_randomize_brk
1689-
1690 #ifdef CONFIG_MMU
1691 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1692 struct linux_binprm;
1693diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1694index de53547..52b9a28 100644
1695--- a/arch/arm/include/asm/fncpy.h
1696+++ b/arch/arm/include/asm/fncpy.h
1697@@ -81,7 +81,9 @@
1698 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1699 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1700 \
1701+ pax_open_kernel(); \
1702 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1703+ pax_close_kernel(); \
1704 flush_icache_range((unsigned long)(dest_buf), \
1705 (unsigned long)(dest_buf) + (size)); \
1706 \
1707diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1708index 2aff798..099eb15 100644
1709--- a/arch/arm/include/asm/futex.h
1710+++ b/arch/arm/include/asm/futex.h
1711@@ -45,6 +45,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1712 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1713 return -EFAULT;
1714
1715+ pax_open_userland();
1716+
1717 smp_mb();
1718 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1719 "1: ldrex %1, [%4]\n"
1720@@ -60,6 +62,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1721 : "cc", "memory");
1722 smp_mb();
1723
1724+ pax_close_userland();
1725+
1726 *uval = val;
1727 return ret;
1728 }
1729@@ -90,6 +94,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1730 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1731 return -EFAULT;
1732
1733+ pax_open_userland();
1734+
1735 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1736 "1: " TUSER(ldr) " %1, [%4]\n"
1737 " teq %1, %2\n"
1738@@ -100,6 +106,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1739 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1740 : "cc", "memory");
1741
1742+ pax_close_userland();
1743+
1744 *uval = val;
1745 return ret;
1746 }
1747@@ -122,6 +130,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1748 return -EFAULT;
1749
1750 pagefault_disable(); /* implies preempt_disable() */
1751+ pax_open_userland();
1752
1753 switch (op) {
1754 case FUTEX_OP_SET:
1755@@ -143,6 +152,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1756 ret = -ENOSYS;
1757 }
1758
1759+ pax_close_userland();
1760 pagefault_enable(); /* subsumes preempt_enable() */
1761
1762 if (!ret) {
1763diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1764index 83eb2f7..ed77159 100644
1765--- a/arch/arm/include/asm/kmap_types.h
1766+++ b/arch/arm/include/asm/kmap_types.h
1767@@ -4,6 +4,6 @@
1768 /*
1769 * This is the "bare minimum". AIO seems to require this.
1770 */
1771-#define KM_TYPE_NR 16
1772+#define KM_TYPE_NR 17
1773
1774 #endif
1775diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1776index 9e614a1..3302cca 100644
1777--- a/arch/arm/include/asm/mach/dma.h
1778+++ b/arch/arm/include/asm/mach/dma.h
1779@@ -22,7 +22,7 @@ struct dma_ops {
1780 int (*residue)(unsigned int, dma_t *); /* optional */
1781 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1782 const char *type;
1783-};
1784+} __do_const;
1785
1786 struct dma_struct {
1787 void *addr; /* single DMA address */
1788diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1789index f98c7f3..e5c626d 100644
1790--- a/arch/arm/include/asm/mach/map.h
1791+++ b/arch/arm/include/asm/mach/map.h
1792@@ -23,17 +23,19 @@ struct map_desc {
1793
1794 /* types 0-3 are defined in asm/io.h */
1795 enum {
1796- MT_UNCACHED = 4,
1797- MT_CACHECLEAN,
1798- MT_MINICLEAN,
1799+ MT_UNCACHED_RW = 4,
1800+ MT_CACHECLEAN_RO,
1801+ MT_MINICLEAN_RO,
1802 MT_LOW_VECTORS,
1803 MT_HIGH_VECTORS,
1804- MT_MEMORY_RWX,
1805+ __MT_MEMORY_RWX,
1806 MT_MEMORY_RW,
1807- MT_ROM,
1808- MT_MEMORY_RWX_NONCACHED,
1809+ MT_MEMORY_RX,
1810+ MT_ROM_RX,
1811+ MT_MEMORY_RW_NONCACHED,
1812+ MT_MEMORY_RX_NONCACHED,
1813 MT_MEMORY_RW_DTCM,
1814- MT_MEMORY_RWX_ITCM,
1815+ MT_MEMORY_RX_ITCM,
1816 MT_MEMORY_RW_SO,
1817 MT_MEMORY_DMA_READY,
1818 };
1819diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1820index f94784f..9a09a4a 100644
1821--- a/arch/arm/include/asm/outercache.h
1822+++ b/arch/arm/include/asm/outercache.h
1823@@ -35,7 +35,7 @@ struct outer_cache_fns {
1824 #endif
1825 void (*set_debug)(unsigned long);
1826 void (*resume)(void);
1827-};
1828+} __no_const;
1829
1830 extern struct outer_cache_fns outer_cache;
1831
1832diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1833index 4355f0e..cd9168e 100644
1834--- a/arch/arm/include/asm/page.h
1835+++ b/arch/arm/include/asm/page.h
1836@@ -23,6 +23,7 @@
1837
1838 #else
1839
1840+#include <linux/compiler.h>
1841 #include <asm/glue.h>
1842
1843 /*
1844@@ -114,7 +115,7 @@ struct cpu_user_fns {
1845 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1846 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1847 unsigned long vaddr, struct vm_area_struct *vma);
1848-};
1849+} __no_const;
1850
1851 #ifdef MULTI_USER
1852 extern struct cpu_user_fns cpu_user;
1853diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1854index 78a7793..e3dc06c 100644
1855--- a/arch/arm/include/asm/pgalloc.h
1856+++ b/arch/arm/include/asm/pgalloc.h
1857@@ -17,6 +17,7 @@
1858 #include <asm/processor.h>
1859 #include <asm/cacheflush.h>
1860 #include <asm/tlbflush.h>
1861+#include <asm/system_info.h>
1862
1863 #define check_pgt_cache() do { } while (0)
1864
1865@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1866 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1867 }
1868
1869+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1870+{
1871+ pud_populate(mm, pud, pmd);
1872+}
1873+
1874 #else /* !CONFIG_ARM_LPAE */
1875
1876 /*
1877@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1878 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1879 #define pmd_free(mm, pmd) do { } while (0)
1880 #define pud_populate(mm,pmd,pte) BUG()
1881+#define pud_populate_kernel(mm,pmd,pte) BUG()
1882
1883 #endif /* CONFIG_ARM_LPAE */
1884
1885@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1886 __free_page(pte);
1887 }
1888
1889+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1890+{
1891+#ifdef CONFIG_ARM_LPAE
1892+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1893+#else
1894+ if (addr & SECTION_SIZE)
1895+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1896+ else
1897+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1898+#endif
1899+ flush_pmd_entry(pmdp);
1900+}
1901+
1902 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1903 pmdval_t prot)
1904 {
1905@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1906 static inline void
1907 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1908 {
1909- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1910+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1911 }
1912 #define pmd_pgtable(pmd) pmd_page(pmd)
1913
1914diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1915index 5cfba15..f415e1a 100644
1916--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1917+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1918@@ -20,12 +20,15 @@
1919 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1920 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1921 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1922+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1923 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1924 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1925 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1926+
1927 /*
1928 * - section
1929 */
1930+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1931 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1932 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1933 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1934@@ -37,6 +40,7 @@
1935 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1936 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1937 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1938+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1939
1940 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1941 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1942@@ -66,6 +70,7 @@
1943 * - extended small page/tiny page
1944 */
1945 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1946+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1947 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1948 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1949 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1950diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1951index 219ac88..73ec32a 100644
1952--- a/arch/arm/include/asm/pgtable-2level.h
1953+++ b/arch/arm/include/asm/pgtable-2level.h
1954@@ -126,6 +126,9 @@
1955 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1956 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1957
1958+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1959+#define L_PTE_PXN (_AT(pteval_t, 0))
1960+
1961 /*
1962 * These are the memory types, defined to be compatible with
1963 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1964diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1965index 626989f..9d67a33 100644
1966--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1967+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1968@@ -75,6 +75,7 @@
1969 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1970 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1971 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1972+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1973 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1974
1975 /*
1976diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1977index 85c60ad..b0bbd7e 100644
1978--- a/arch/arm/include/asm/pgtable-3level.h
1979+++ b/arch/arm/include/asm/pgtable-3level.h
1980@@ -82,6 +82,7 @@
1981 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1982 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1983 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1984+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1985 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1986 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1987 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1988@@ -95,6 +96,7 @@
1989 /*
1990 * To be used in assembly code with the upper page attributes.
1991 */
1992+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1993 #define L_PTE_XN_HIGH (1 << (54 - 32))
1994 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1995
1996diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1997index 7d59b52..27a12f8 100644
1998--- a/arch/arm/include/asm/pgtable.h
1999+++ b/arch/arm/include/asm/pgtable.h
2000@@ -33,6 +33,9 @@
2001 #include <asm/pgtable-2level.h>
2002 #endif
2003
2004+#define ktla_ktva(addr) (addr)
2005+#define ktva_ktla(addr) (addr)
2006+
2007 /*
2008 * Just any arbitrary offset to the start of the vmalloc VM area: the
2009 * current 8MB value just means that there will be a 8MB "hole" after the
2010@@ -48,6 +51,9 @@
2011 #define LIBRARY_TEXT_START 0x0c000000
2012
2013 #ifndef __ASSEMBLY__
2014+extern pteval_t __supported_pte_mask;
2015+extern pmdval_t __supported_pmd_mask;
2016+
2017 extern void __pte_error(const char *file, int line, pte_t);
2018 extern void __pmd_error(const char *file, int line, pmd_t);
2019 extern void __pgd_error(const char *file, int line, pgd_t);
2020@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2021 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2022 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2023
2024+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2025+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2026+
2027+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2028+#include <asm/domain.h>
2029+#include <linux/thread_info.h>
2030+#include <linux/preempt.h>
2031+
2032+static inline int test_domain(int domain, int domaintype)
2033+{
2034+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2035+}
2036+#endif
2037+
2038+#ifdef CONFIG_PAX_KERNEXEC
2039+static inline unsigned long pax_open_kernel(void) {
2040+#ifdef CONFIG_ARM_LPAE
2041+ /* TODO */
2042+#else
2043+ preempt_disable();
2044+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2045+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2046+#endif
2047+ return 0;
2048+}
2049+
2050+static inline unsigned long pax_close_kernel(void) {
2051+#ifdef CONFIG_ARM_LPAE
2052+ /* TODO */
2053+#else
2054+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2055+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2056+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2057+ preempt_enable_no_resched();
2058+#endif
2059+ return 0;
2060+}
2061+#else
2062+static inline unsigned long pax_open_kernel(void) { return 0; }
2063+static inline unsigned long pax_close_kernel(void) { return 0; }
2064+#endif
2065+
2066 /*
2067 * This is the lowest virtual address we can permit any user space
2068 * mapping to be mapped at. This is particularly important for
2069@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2070 /*
2071 * The pgprot_* and protection_map entries will be fixed up in runtime
2072 * to include the cachable and bufferable bits based on memory policy,
2073- * as well as any architecture dependent bits like global/ASID and SMP
2074- * shared mapping bits.
2075+ * as well as any architecture dependent bits like global/ASID, PXN,
2076+ * and SMP shared mapping bits.
2077 */
2078 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2079
2080@@ -262,7 +310,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2081 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2082 {
2083 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2084- L_PTE_NONE | L_PTE_VALID;
2085+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2086 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2087 return pte;
2088 }
2089diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2090index c4ae171..ea0c0c2 100644
2091--- a/arch/arm/include/asm/psci.h
2092+++ b/arch/arm/include/asm/psci.h
2093@@ -29,7 +29,7 @@ struct psci_operations {
2094 int (*cpu_off)(struct psci_power_state state);
2095 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2096 int (*migrate)(unsigned long cpuid);
2097-};
2098+} __no_const;
2099
2100 extern struct psci_operations psci_ops;
2101 extern struct smp_operations psci_smp_ops;
2102diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2103index 22a3b9b..7f214ee 100644
2104--- a/arch/arm/include/asm/smp.h
2105+++ b/arch/arm/include/asm/smp.h
2106@@ -112,7 +112,7 @@ struct smp_operations {
2107 int (*cpu_disable)(unsigned int cpu);
2108 #endif
2109 #endif
2110-};
2111+} __no_const;
2112
2113 /*
2114 * set platform specific SMP operations
2115diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2116index 71a06b2..8bb9ae1 100644
2117--- a/arch/arm/include/asm/thread_info.h
2118+++ b/arch/arm/include/asm/thread_info.h
2119@@ -88,9 +88,9 @@ struct thread_info {
2120 .flags = 0, \
2121 .preempt_count = INIT_PREEMPT_COUNT, \
2122 .addr_limit = KERNEL_DS, \
2123- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2124- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2125- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2126+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2127+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2128+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2129 .restart_block = { \
2130 .fn = do_no_restart_syscall, \
2131 }, \
2132@@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2133 #define TIF_SYSCALL_AUDIT 9
2134 #define TIF_SYSCALL_TRACEPOINT 10
2135 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2136-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2137+/* within 8 bits of TIF_SYSCALL_TRACE
2138+ * to meet flexible second operand requirements
2139+ */
2140+#define TIF_GRSEC_SETXID 12
2141+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2142 #define TIF_USING_IWMMXT 17
2143 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2144 #define TIF_RESTORE_SIGMASK 20
2145@@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2146 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2147 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2148 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2149+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2150
2151 /* Checks for any syscall work in entry-common.S */
2152 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2153- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2154+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2155
2156 /*
2157 * Change these and you break ASM code in entry-common.S
2158diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2159index 72abdc5..35acac1 100644
2160--- a/arch/arm/include/asm/uaccess.h
2161+++ b/arch/arm/include/asm/uaccess.h
2162@@ -18,6 +18,7 @@
2163 #include <asm/domain.h>
2164 #include <asm/unified.h>
2165 #include <asm/compiler.h>
2166+#include <asm/pgtable.h>
2167
2168 #if __LINUX_ARM_ARCH__ < 6
2169 #include <asm-generic/uaccess-unaligned.h>
2170@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2171 static inline void set_fs(mm_segment_t fs)
2172 {
2173 current_thread_info()->addr_limit = fs;
2174- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2175+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2176 }
2177
2178 #define segment_eq(a,b) ((a) == (b))
2179
2180+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2181+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2182+
2183+static inline void pax_open_userland(void)
2184+{
2185+
2186+#ifdef CONFIG_PAX_MEMORY_UDEREF
2187+ if (segment_eq(get_fs(), USER_DS)) {
2188+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2189+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2190+ }
2191+#endif
2192+
2193+}
2194+
2195+static inline void pax_close_userland(void)
2196+{
2197+
2198+#ifdef CONFIG_PAX_MEMORY_UDEREF
2199+ if (segment_eq(get_fs(), USER_DS)) {
2200+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2201+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2202+ }
2203+#endif
2204+
2205+}
2206+
2207 #define __addr_ok(addr) ({ \
2208 unsigned long flag; \
2209 __asm__("cmp %2, %0; movlo %0, #0" \
2210@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2211
2212 #define get_user(x,p) \
2213 ({ \
2214+ int __e; \
2215 might_fault(); \
2216- __get_user_check(x,p); \
2217+ pax_open_userland(); \
2218+ __e = __get_user_check(x,p); \
2219+ pax_close_userland(); \
2220+ __e; \
2221 })
2222
2223 extern int __put_user_1(void *, unsigned int);
2224@@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2225
2226 #define put_user(x,p) \
2227 ({ \
2228+ int __e; \
2229 might_fault(); \
2230- __put_user_check(x,p); \
2231+ pax_open_userland(); \
2232+ __e = __put_user_check(x,p); \
2233+ pax_close_userland(); \
2234+ __e; \
2235 })
2236
2237 #else /* CONFIG_MMU */
2238@@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
2239
2240 #endif /* CONFIG_MMU */
2241
2242+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2243 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2244
2245 #define user_addr_max() \
2246@@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
2247 #define __get_user(x,ptr) \
2248 ({ \
2249 long __gu_err = 0; \
2250+ pax_open_userland(); \
2251 __get_user_err((x),(ptr),__gu_err); \
2252+ pax_close_userland(); \
2253 __gu_err; \
2254 })
2255
2256 #define __get_user_error(x,ptr,err) \
2257 ({ \
2258+ pax_open_userland(); \
2259 __get_user_err((x),(ptr),err); \
2260+ pax_close_userland(); \
2261 (void) 0; \
2262 })
2263
2264@@ -319,13 +360,17 @@ do { \
2265 #define __put_user(x,ptr) \
2266 ({ \
2267 long __pu_err = 0; \
2268+ pax_open_userland(); \
2269 __put_user_err((x),(ptr),__pu_err); \
2270+ pax_close_userland(); \
2271 __pu_err; \
2272 })
2273
2274 #define __put_user_error(x,ptr,err) \
2275 ({ \
2276+ pax_open_userland(); \
2277 __put_user_err((x),(ptr),err); \
2278+ pax_close_userland(); \
2279 (void) 0; \
2280 })
2281
2282@@ -425,11 +470,44 @@ do { \
2283
2284
2285 #ifdef CONFIG_MMU
2286-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2287-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2288+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2289+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2290+
2291+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2292+{
2293+ unsigned long ret;
2294+
2295+ check_object_size(to, n, false);
2296+ pax_open_userland();
2297+ ret = ___copy_from_user(to, from, n);
2298+ pax_close_userland();
2299+ return ret;
2300+}
2301+
2302+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2303+{
2304+ unsigned long ret;
2305+
2306+ check_object_size(from, n, true);
2307+ pax_open_userland();
2308+ ret = ___copy_to_user(to, from, n);
2309+ pax_close_userland();
2310+ return ret;
2311+}
2312+
2313 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2314-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2315+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2316 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2317+
2318+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2319+{
2320+ unsigned long ret;
2321+ pax_open_userland();
2322+ ret = ___clear_user(addr, n);
2323+ pax_close_userland();
2324+ return ret;
2325+}
2326+
2327 #else
2328 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2329 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2330@@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2331
2332 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2333 {
2334+ if ((long)n < 0)
2335+ return n;
2336+
2337 if (access_ok(VERIFY_READ, from, n))
2338 n = __copy_from_user(to, from, n);
2339 else /* security hole - plug it */
2340@@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2341
2342 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2343 {
2344+ if ((long)n < 0)
2345+ return n;
2346+
2347 if (access_ok(VERIFY_WRITE, to, n))
2348 n = __copy_to_user(to, from, n);
2349 return n;
2350diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2351index 5af0ed1..cea83883 100644
2352--- a/arch/arm/include/uapi/asm/ptrace.h
2353+++ b/arch/arm/include/uapi/asm/ptrace.h
2354@@ -92,7 +92,7 @@
2355 * ARMv7 groups of PSR bits
2356 */
2357 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2358-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2359+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2360 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2361 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2362
2363diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2364index 85e664b..419a1cd 100644
2365--- a/arch/arm/kernel/armksyms.c
2366+++ b/arch/arm/kernel/armksyms.c
2367@@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2368
2369 /* networking */
2370 EXPORT_SYMBOL(csum_partial);
2371-EXPORT_SYMBOL(csum_partial_copy_from_user);
2372+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2373 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2374 EXPORT_SYMBOL(__csum_ipv6_magic);
2375
2376@@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2377 #ifdef CONFIG_MMU
2378 EXPORT_SYMBOL(copy_page);
2379
2380-EXPORT_SYMBOL(__copy_from_user);
2381-EXPORT_SYMBOL(__copy_to_user);
2382-EXPORT_SYMBOL(__clear_user);
2383+EXPORT_SYMBOL(___copy_from_user);
2384+EXPORT_SYMBOL(___copy_to_user);
2385+EXPORT_SYMBOL(___clear_user);
2386
2387 EXPORT_SYMBOL(__get_user_1);
2388 EXPORT_SYMBOL(__get_user_2);
2389diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2390index 1879e8d..b2207fc 100644
2391--- a/arch/arm/kernel/entry-armv.S
2392+++ b/arch/arm/kernel/entry-armv.S
2393@@ -47,6 +47,87 @@
2394 9997:
2395 .endm
2396
2397+ .macro pax_enter_kernel
2398+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2399+ @ make aligned space for saved DACR
2400+ sub sp, sp, #8
2401+ @ save regs
2402+ stmdb sp!, {r1, r2}
2403+ @ read DACR from cpu_domain into r1
2404+ mov r2, sp
2405+ @ assume 8K pages, since we have to split the immediate in two
2406+ bic r2, r2, #(0x1fc0)
2407+ bic r2, r2, #(0x3f)
2408+ ldr r1, [r2, #TI_CPU_DOMAIN]
2409+ @ store old DACR on stack
2410+ str r1, [sp, #8]
2411+#ifdef CONFIG_PAX_KERNEXEC
2412+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2413+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2414+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2415+#endif
2416+#ifdef CONFIG_PAX_MEMORY_UDEREF
2417+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2418+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2419+#endif
2420+ @ write r1 to current_thread_info()->cpu_domain
2421+ str r1, [r2, #TI_CPU_DOMAIN]
2422+ @ write r1 to DACR
2423+ mcr p15, 0, r1, c3, c0, 0
2424+ @ instruction sync
2425+ instr_sync
2426+ @ restore regs
2427+ ldmia sp!, {r1, r2}
2428+#endif
2429+ .endm
2430+
2431+ .macro pax_open_userland
2432+#ifdef CONFIG_PAX_MEMORY_UDEREF
2433+ @ save regs
2434+ stmdb sp!, {r0, r1}
2435+ @ read DACR from cpu_domain into r1
2436+ mov r0, sp
2437+ @ assume 8K pages, since we have to split the immediate in two
2438+ bic r0, r0, #(0x1fc0)
2439+ bic r0, r0, #(0x3f)
2440+ ldr r1, [r0, #TI_CPU_DOMAIN]
2441+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2442+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2443+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2444+ @ write r1 to current_thread_info()->cpu_domain
2445+ str r1, [r0, #TI_CPU_DOMAIN]
2446+ @ write r1 to DACR
2447+ mcr p15, 0, r1, c3, c0, 0
2448+ @ instruction sync
2449+ instr_sync
2450+ @ restore regs
2451+ ldmia sp!, {r0, r1}
2452+#endif
2453+ .endm
2454+
2455+ .macro pax_close_userland
2456+#ifdef CONFIG_PAX_MEMORY_UDEREF
2457+ @ save regs
2458+ stmdb sp!, {r0, r1}
2459+ @ read DACR from cpu_domain into r1
2460+ mov r0, sp
2461+ @ assume 8K pages, since we have to split the immediate in two
2462+ bic r0, r0, #(0x1fc0)
2463+ bic r0, r0, #(0x3f)
2464+ ldr r1, [r0, #TI_CPU_DOMAIN]
2465+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2466+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2467+ @ write r1 to current_thread_info()->cpu_domain
2468+ str r1, [r0, #TI_CPU_DOMAIN]
2469+ @ write r1 to DACR
2470+ mcr p15, 0, r1, c3, c0, 0
2471+ @ instruction sync
2472+ instr_sync
2473+ @ restore regs
2474+ ldmia sp!, {r0, r1}
2475+#endif
2476+ .endm
2477+
2478 .macro pabt_helper
2479 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2480 #ifdef MULTI_PABORT
2481@@ -89,11 +170,15 @@
2482 * Invalid mode handlers
2483 */
2484 .macro inv_entry, reason
2485+
2486+ pax_enter_kernel
2487+
2488 sub sp, sp, #S_FRAME_SIZE
2489 ARM( stmib sp, {r1 - lr} )
2490 THUMB( stmia sp, {r0 - r12} )
2491 THUMB( str sp, [sp, #S_SP] )
2492 THUMB( str lr, [sp, #S_LR] )
2493+
2494 mov r1, #\reason
2495 .endm
2496
2497@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2498 .macro svc_entry, stack_hole=0
2499 UNWIND(.fnstart )
2500 UNWIND(.save {r0 - pc} )
2501+
2502+ pax_enter_kernel
2503+
2504 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2505+
2506 #ifdef CONFIG_THUMB2_KERNEL
2507 SPFIX( str r0, [sp] ) @ temporarily saved
2508 SPFIX( mov r0, sp )
2509@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2510 ldmia r0, {r3 - r5}
2511 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2512 mov r6, #-1 @ "" "" "" ""
2513+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2514+ @ offset sp by 8 as done in pax_enter_kernel
2515+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2516+#else
2517 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2518+#endif
2519 SPFIX( addeq r2, r2, #4 )
2520 str r3, [sp, #-4]! @ save the "real" r0 copied
2521 @ from the exception stack
2522@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2523 .macro usr_entry
2524 UNWIND(.fnstart )
2525 UNWIND(.cantunwind ) @ don't unwind the user space
2526+
2527+ pax_enter_kernel_user
2528+
2529 sub sp, sp, #S_FRAME_SIZE
2530 ARM( stmib sp, {r1 - r12} )
2531 THUMB( stmia sp, {r0 - r12} )
2532@@ -416,7 +513,9 @@ __und_usr:
2533 tst r3, #PSR_T_BIT @ Thumb mode?
2534 bne __und_usr_thumb
2535 sub r4, r2, #4 @ ARM instr at LR - 4
2536+ pax_open_userland
2537 1: ldrt r0, [r4]
2538+ pax_close_userland
2539 ARM_BE8(rev r0, r0) @ little endian instruction
2540
2541 @ r0 = 32-bit ARM instruction which caused the exception
2542@@ -450,11 +549,15 @@ __und_usr_thumb:
2543 */
2544 .arch armv6t2
2545 #endif
2546+ pax_open_userland
2547 2: ldrht r5, [r4]
2548+ pax_close_userland
2549 ARM_BE8(rev16 r5, r5) @ little endian instruction
2550 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2551 blo __und_usr_fault_16 @ 16bit undefined instruction
2552+ pax_open_userland
2553 3: ldrht r0, [r2]
2554+ pax_close_userland
2555 ARM_BE8(rev16 r0, r0) @ little endian instruction
2556 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2557 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2558@@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2559 */
2560 .pushsection .fixup, "ax"
2561 .align 2
2562-4: mov pc, r9
2563+4: pax_close_userland
2564+ mov pc, r9
2565 .popsection
2566 .pushsection __ex_table,"a"
2567 .long 1b, 4b
2568@@ -694,7 +798,7 @@ ENTRY(__switch_to)
2569 THUMB( str lr, [ip], #4 )
2570 ldr r4, [r2, #TI_TP_VALUE]
2571 ldr r5, [r2, #TI_TP_VALUE + 4]
2572-#ifdef CONFIG_CPU_USE_DOMAINS
2573+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2574 ldr r6, [r2, #TI_CPU_DOMAIN]
2575 #endif
2576 switch_tls r1, r4, r5, r3, r7
2577@@ -703,7 +807,7 @@ ENTRY(__switch_to)
2578 ldr r8, =__stack_chk_guard
2579 ldr r7, [r7, #TSK_STACK_CANARY]
2580 #endif
2581-#ifdef CONFIG_CPU_USE_DOMAINS
2582+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2583 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2584 #endif
2585 mov r5, r0
2586diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2587index a2dcafd..1048b5a 100644
2588--- a/arch/arm/kernel/entry-common.S
2589+++ b/arch/arm/kernel/entry-common.S
2590@@ -10,18 +10,46 @@
2591
2592 #include <asm/unistd.h>
2593 #include <asm/ftrace.h>
2594+#include <asm/domain.h>
2595 #include <asm/unwind.h>
2596
2597+#include "entry-header.S"
2598+
2599 #ifdef CONFIG_NEED_RET_TO_USER
2600 #include <mach/entry-macro.S>
2601 #else
2602 .macro arch_ret_to_user, tmp1, tmp2
2603+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2604+ @ save regs
2605+ stmdb sp!, {r1, r2}
2606+ @ read DACR from cpu_domain into r1
2607+ mov r2, sp
2608+ @ assume 8K pages, since we have to split the immediate in two
2609+ bic r2, r2, #(0x1fc0)
2610+ bic r2, r2, #(0x3f)
2611+ ldr r1, [r2, #TI_CPU_DOMAIN]
2612+#ifdef CONFIG_PAX_KERNEXEC
2613+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2614+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2615+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2616+#endif
2617+#ifdef CONFIG_PAX_MEMORY_UDEREF
2618+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2619+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2620+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2621+#endif
2622+ @ write r1 to current_thread_info()->cpu_domain
2623+ str r1, [r2, #TI_CPU_DOMAIN]
2624+ @ write r1 to DACR
2625+ mcr p15, 0, r1, c3, c0, 0
2626+ @ instruction sync
2627+ instr_sync
2628+ @ restore regs
2629+ ldmia sp!, {r1, r2}
2630+#endif
2631 .endm
2632 #endif
2633
2634-#include "entry-header.S"
2635-
2636-
2637 .align 5
2638 /*
2639 * This is the fast syscall return path. We do as little as
2640@@ -411,6 +439,12 @@ ENTRY(vector_swi)
2641 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2642 #endif
2643
2644+ /*
2645+ * do this here to avoid a performance hit of wrapping the code above
2646+ * that directly dereferences userland to parse the SWI instruction
2647+ */
2648+ pax_enter_kernel_user
2649+
2650 adr tbl, sys_call_table @ load syscall table pointer
2651
2652 #if defined(CONFIG_OABI_COMPAT)
2653diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2654index 39f89fb..d612bd9 100644
2655--- a/arch/arm/kernel/entry-header.S
2656+++ b/arch/arm/kernel/entry-header.S
2657@@ -184,6 +184,60 @@
2658 msr cpsr_c, \rtemp @ switch back to the SVC mode
2659 .endm
2660
2661+ .macro pax_enter_kernel_user
2662+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2663+ @ save regs
2664+ stmdb sp!, {r0, r1}
2665+ @ read DACR from cpu_domain into r1
2666+ mov r0, sp
2667+ @ assume 8K pages, since we have to split the immediate in two
2668+ bic r0, r0, #(0x1fc0)
2669+ bic r0, r0, #(0x3f)
2670+ ldr r1, [r0, #TI_CPU_DOMAIN]
2671+#ifdef CONFIG_PAX_MEMORY_UDEREF
2672+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2673+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2674+#endif
2675+#ifdef CONFIG_PAX_KERNEXEC
2676+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2677+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2678+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2679+#endif
2680+ @ write r1 to current_thread_info()->cpu_domain
2681+ str r1, [r0, #TI_CPU_DOMAIN]
2682+ @ write r1 to DACR
2683+ mcr p15, 0, r1, c3, c0, 0
2684+ @ instruction sync
2685+ instr_sync
2686+ @ restore regs
2687+ ldmia sp!, {r0, r1}
2688+#endif
2689+ .endm
2690+
2691+ .macro pax_exit_kernel
2692+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2693+ @ save regs
2694+ stmdb sp!, {r0, r1}
2695+ @ read old DACR from stack into r1
2696+ ldr r1, [sp, #(8 + S_SP)]
2697+ sub r1, r1, #8
2698+ ldr r1, [r1]
2699+
2700+ @ write r1 to current_thread_info()->cpu_domain
2701+ mov r0, sp
2702+ @ assume 8K pages, since we have to split the immediate in two
2703+ bic r0, r0, #(0x1fc0)
2704+ bic r0, r0, #(0x3f)
2705+ str r1, [r0, #TI_CPU_DOMAIN]
2706+ @ write r1 to DACR
2707+ mcr p15, 0, r1, c3, c0, 0
2708+ @ instruction sync
2709+ instr_sync
2710+ @ restore regs
2711+ ldmia sp!, {r0, r1}
2712+#endif
2713+ .endm
2714+
2715 #ifndef CONFIG_THUMB2_KERNEL
2716 .macro svc_exit, rpsr, irq = 0
2717 .if \irq != 0
2718@@ -203,6 +257,9 @@
2719 blne trace_hardirqs_off
2720 #endif
2721 .endif
2722+
2723+ pax_exit_kernel
2724+
2725 msr spsr_cxsf, \rpsr
2726 #if defined(CONFIG_CPU_V6)
2727 ldr r0, [sp]
2728@@ -266,6 +323,9 @@
2729 blne trace_hardirqs_off
2730 #endif
2731 .endif
2732+
2733+ pax_exit_kernel
2734+
2735 ldr lr, [sp, #S_SP] @ top of the stack
2736 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2737 clrex @ clear the exclusive monitor
2738diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2739index 918875d..cd5fa27 100644
2740--- a/arch/arm/kernel/fiq.c
2741+++ b/arch/arm/kernel/fiq.c
2742@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2743 void *base = vectors_page;
2744 unsigned offset = FIQ_OFFSET;
2745
2746+ pax_open_kernel();
2747 memcpy(base + offset, start, length);
2748+ pax_close_kernel();
2749+
2750 if (!cache_is_vipt_nonaliasing())
2751 flush_icache_range((unsigned long)base + offset, offset +
2752 length);
2753diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2754index f5f381d..a6f36a1 100644
2755--- a/arch/arm/kernel/head.S
2756+++ b/arch/arm/kernel/head.S
2757@@ -437,7 +437,7 @@ __enable_mmu:
2758 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2759 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2760 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2761- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2762+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2763 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2764 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2765 #endif
2766diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2767index 45e4781..8eac93d 100644
2768--- a/arch/arm/kernel/module.c
2769+++ b/arch/arm/kernel/module.c
2770@@ -38,12 +38,39 @@
2771 #endif
2772
2773 #ifdef CONFIG_MMU
2774-void *module_alloc(unsigned long size)
2775+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2776 {
2777+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2778+ return NULL;
2779 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2780- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2781+ GFP_KERNEL, prot, NUMA_NO_NODE,
2782 __builtin_return_address(0));
2783 }
2784+
2785+void *module_alloc(unsigned long size)
2786+{
2787+
2788+#ifdef CONFIG_PAX_KERNEXEC
2789+ return __module_alloc(size, PAGE_KERNEL);
2790+#else
2791+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2792+#endif
2793+
2794+}
2795+
2796+#ifdef CONFIG_PAX_KERNEXEC
2797+void module_free_exec(struct module *mod, void *module_region)
2798+{
2799+ module_free(mod, module_region);
2800+}
2801+EXPORT_SYMBOL(module_free_exec);
2802+
2803+void *module_alloc_exec(unsigned long size)
2804+{
2805+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2806+}
2807+EXPORT_SYMBOL(module_alloc_exec);
2808+#endif
2809 #endif
2810
2811 int
2812diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2813index 07314af..c46655c 100644
2814--- a/arch/arm/kernel/patch.c
2815+++ b/arch/arm/kernel/patch.c
2816@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2817 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2818 int size;
2819
2820+ pax_open_kernel();
2821 if (thumb2 && __opcode_is_thumb16(insn)) {
2822 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2823 size = sizeof(u16);
2824@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2825 *(u32 *)addr = insn;
2826 size = sizeof(u32);
2827 }
2828+ pax_close_kernel();
2829
2830 flush_icache_range((uintptr_t)(addr),
2831 (uintptr_t)(addr) + size);
2832diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2833index 92f7b15..7048500 100644
2834--- a/arch/arm/kernel/process.c
2835+++ b/arch/arm/kernel/process.c
2836@@ -217,6 +217,7 @@ void machine_power_off(void)
2837
2838 if (pm_power_off)
2839 pm_power_off();
2840+ BUG();
2841 }
2842
2843 /*
2844@@ -230,7 +231,7 @@ void machine_power_off(void)
2845 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2846 * to use. Implementing such co-ordination would be essentially impossible.
2847 */
2848-void machine_restart(char *cmd)
2849+__noreturn void machine_restart(char *cmd)
2850 {
2851 local_irq_disable();
2852 smp_send_stop();
2853@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2854
2855 show_regs_print_info(KERN_DEFAULT);
2856
2857- print_symbol("PC is at %s\n", instruction_pointer(regs));
2858- print_symbol("LR is at %s\n", regs->ARM_lr);
2859+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2860+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2861 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2862 "sp : %08lx ip : %08lx fp : %08lx\n",
2863 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2864@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2865 return 0;
2866 }
2867
2868-unsigned long arch_randomize_brk(struct mm_struct *mm)
2869-{
2870- unsigned long range_end = mm->brk + 0x02000000;
2871- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2872-}
2873-
2874 #ifdef CONFIG_MMU
2875 #ifdef CONFIG_KUSER_HELPERS
2876 /*
2877@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2878
2879 static int __init gate_vma_init(void)
2880 {
2881- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2882+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2883 return 0;
2884 }
2885 arch_initcall(gate_vma_init);
2886@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2887
2888 const char *arch_vma_name(struct vm_area_struct *vma)
2889 {
2890- return is_gate_vma(vma) ? "[vectors]" :
2891- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2892- "[sigpage]" : NULL;
2893+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2894 }
2895
2896-static struct page *signal_page;
2897-extern struct page *get_signal_page(void);
2898-
2899 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2900 {
2901 struct mm_struct *mm = current->mm;
2902- unsigned long addr;
2903- int ret;
2904-
2905- if (!signal_page)
2906- signal_page = get_signal_page();
2907- if (!signal_page)
2908- return -ENOMEM;
2909
2910 down_write(&mm->mmap_sem);
2911- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2912- if (IS_ERR_VALUE(addr)) {
2913- ret = addr;
2914- goto up_fail;
2915- }
2916-
2917- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2918- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2919- &signal_page);
2920-
2921- if (ret == 0)
2922- mm->context.sigpage = addr;
2923-
2924- up_fail:
2925+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2926 up_write(&mm->mmap_sem);
2927- return ret;
2928+ return 0;
2929 }
2930 #endif
2931diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2932index 4693188..4596c5e 100644
2933--- a/arch/arm/kernel/psci.c
2934+++ b/arch/arm/kernel/psci.c
2935@@ -24,7 +24,7 @@
2936 #include <asm/opcodes-virt.h>
2937 #include <asm/psci.h>
2938
2939-struct psci_operations psci_ops;
2940+struct psci_operations psci_ops __read_only;
2941
2942 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2943
2944diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2945index 0dd3b79..e018f64 100644
2946--- a/arch/arm/kernel/ptrace.c
2947+++ b/arch/arm/kernel/ptrace.c
2948@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2949 return current_thread_info()->syscall;
2950 }
2951
2952+#ifdef CONFIG_GRKERNSEC_SETXID
2953+extern void gr_delayed_cred_worker(void);
2954+#endif
2955+
2956 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2957 {
2958 current_thread_info()->syscall = scno;
2959
2960+#ifdef CONFIG_GRKERNSEC_SETXID
2961+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2962+ gr_delayed_cred_worker();
2963+#endif
2964+
2965 /* Do the secure computing check first; failures should be fast. */
2966 if (secure_computing(scno) == -1)
2967 return -1;
2968diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2969index 1e8b030..37c3022 100644
2970--- a/arch/arm/kernel/setup.c
2971+++ b/arch/arm/kernel/setup.c
2972@@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2973 unsigned int elf_hwcap __read_mostly;
2974 EXPORT_SYMBOL(elf_hwcap);
2975
2976+pteval_t __supported_pte_mask __read_only;
2977+pmdval_t __supported_pmd_mask __read_only;
2978
2979 #ifdef MULTI_CPU
2980-struct processor processor __read_mostly;
2981+struct processor processor __read_only;
2982 #endif
2983 #ifdef MULTI_TLB
2984-struct cpu_tlb_fns cpu_tlb __read_mostly;
2985+struct cpu_tlb_fns cpu_tlb __read_only;
2986 #endif
2987 #ifdef MULTI_USER
2988-struct cpu_user_fns cpu_user __read_mostly;
2989+struct cpu_user_fns cpu_user __read_only;
2990 #endif
2991 #ifdef MULTI_CACHE
2992-struct cpu_cache_fns cpu_cache __read_mostly;
2993+struct cpu_cache_fns cpu_cache __read_only;
2994 #endif
2995 #ifdef CONFIG_OUTER_CACHE
2996-struct outer_cache_fns outer_cache __read_mostly;
2997+struct outer_cache_fns outer_cache __read_only;
2998 EXPORT_SYMBOL(outer_cache);
2999 #endif
3000
3001@@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3002 asm("mrc p15, 0, %0, c0, c1, 4"
3003 : "=r" (mmfr0));
3004 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3005- (mmfr0 & 0x000000f0) >= 0x00000030)
3006+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3007 cpu_arch = CPU_ARCH_ARMv7;
3008- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3009+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3010+ __supported_pte_mask |= L_PTE_PXN;
3011+ __supported_pmd_mask |= PMD_PXNTABLE;
3012+ }
3013+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3014 (mmfr0 & 0x000000f0) == 0x00000020)
3015 cpu_arch = CPU_ARCH_ARMv6;
3016 else
3017diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3018index 04d6388..5115238 100644
3019--- a/arch/arm/kernel/signal.c
3020+++ b/arch/arm/kernel/signal.c
3021@@ -23,8 +23,6 @@
3022
3023 extern const unsigned long sigreturn_codes[7];
3024
3025-static unsigned long signal_return_offset;
3026-
3027 #ifdef CONFIG_CRUNCH
3028 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3029 {
3030@@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3031 * except when the MPU has protected the vectors
3032 * page from PL0
3033 */
3034- retcode = mm->context.sigpage + signal_return_offset +
3035- (idx << 2) + thumb;
3036+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3037 } else
3038 #endif
3039 {
3040@@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3041 } while (thread_flags & _TIF_WORK_MASK);
3042 return 0;
3043 }
3044-
3045-struct page *get_signal_page(void)
3046-{
3047- unsigned long ptr;
3048- unsigned offset;
3049- struct page *page;
3050- void *addr;
3051-
3052- page = alloc_pages(GFP_KERNEL, 0);
3053-
3054- if (!page)
3055- return NULL;
3056-
3057- addr = page_address(page);
3058-
3059- /* Give the signal return code some randomness */
3060- offset = 0x200 + (get_random_int() & 0x7fc);
3061- signal_return_offset = offset;
3062-
3063- /*
3064- * Copy signal return handlers into the vector page, and
3065- * set sigreturn to be a pointer to these.
3066- */
3067- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3068-
3069- ptr = (unsigned long)addr + offset;
3070- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3071-
3072- return page;
3073-}
3074diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3075index b7b4c86..47c4f77 100644
3076--- a/arch/arm/kernel/smp.c
3077+++ b/arch/arm/kernel/smp.c
3078@@ -73,7 +73,7 @@ enum ipi_msg_type {
3079
3080 static DECLARE_COMPLETION(cpu_running);
3081
3082-static struct smp_operations smp_ops;
3083+static struct smp_operations smp_ops __read_only;
3084
3085 void __init smp_set_ops(struct smp_operations *ops)
3086 {
3087diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3088index 7a3be1d..b00c7de 100644
3089--- a/arch/arm/kernel/tcm.c
3090+++ b/arch/arm/kernel/tcm.c
3091@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3092 .virtual = ITCM_OFFSET,
3093 .pfn = __phys_to_pfn(ITCM_OFFSET),
3094 .length = 0,
3095- .type = MT_MEMORY_RWX_ITCM,
3096+ .type = MT_MEMORY_RX_ITCM,
3097 }
3098 };
3099
3100@@ -267,7 +267,9 @@ no_dtcm:
3101 start = &__sitcm_text;
3102 end = &__eitcm_text;
3103 ram = &__itcm_start;
3104+ pax_open_kernel();
3105 memcpy(start, ram, itcm_code_sz);
3106+ pax_close_kernel();
3107 pr_debug("CPU ITCM: copied code from %p - %p\n",
3108 start, end);
3109 itcm_present = true;
3110diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3111index 172ee18..ce4ec3d 100644
3112--- a/arch/arm/kernel/traps.c
3113+++ b/arch/arm/kernel/traps.c
3114@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3115 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3116 {
3117 #ifdef CONFIG_KALLSYMS
3118- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3119+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3120 #else
3121 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3122 #endif
3123@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3124 static int die_owner = -1;
3125 static unsigned int die_nest_count;
3126
3127+extern void gr_handle_kernel_exploit(void);
3128+
3129 static unsigned long oops_begin(void)
3130 {
3131 int cpu;
3132@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3133 panic("Fatal exception in interrupt");
3134 if (panic_on_oops)
3135 panic("Fatal exception");
3136+
3137+ gr_handle_kernel_exploit();
3138+
3139 if (signr)
3140 do_exit(signr);
3141 }
3142@@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3143 * The user helper at 0xffff0fe0 must be used instead.
3144 * (see entry-armv.S for details)
3145 */
3146+ pax_open_kernel();
3147 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3148+ pax_close_kernel();
3149 }
3150 return 0;
3151
3152@@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3153 kuser_init(vectors_base);
3154
3155 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3156- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3157+
3158+#ifndef CONFIG_PAX_MEMORY_UDEREF
3159+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3160+#endif
3161+
3162 #else /* ifndef CONFIG_CPU_V7M */
3163 /*
3164 * on V7-M there is no need to copy the vector table to a dedicated
3165diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3166index 7bcee5c..e2f3249 100644
3167--- a/arch/arm/kernel/vmlinux.lds.S
3168+++ b/arch/arm/kernel/vmlinux.lds.S
3169@@ -8,7 +8,11 @@
3170 #include <asm/thread_info.h>
3171 #include <asm/memory.h>
3172 #include <asm/page.h>
3173-
3174+
3175+#ifdef CONFIG_PAX_KERNEXEC
3176+#include <asm/pgtable.h>
3177+#endif
3178+
3179 #define PROC_INFO \
3180 . = ALIGN(4); \
3181 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3182@@ -34,7 +38,7 @@
3183 #endif
3184
3185 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3186- defined(CONFIG_GENERIC_BUG)
3187+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3188 #define ARM_EXIT_KEEP(x) x
3189 #define ARM_EXIT_DISCARD(x)
3190 #else
3191@@ -90,6 +94,11 @@ SECTIONS
3192 _text = .;
3193 HEAD_TEXT
3194 }
3195+
3196+#ifdef CONFIG_PAX_KERNEXEC
3197+ . = ALIGN(1<<SECTION_SHIFT);
3198+#endif
3199+
3200 .text : { /* Real text segment */
3201 _stext = .; /* Text and read-only data */
3202 __exception_text_start = .;
3203@@ -112,6 +121,8 @@ SECTIONS
3204 ARM_CPU_KEEP(PROC_INFO)
3205 }
3206
3207+ _etext = .; /* End of text section */
3208+
3209 RO_DATA(PAGE_SIZE)
3210
3211 . = ALIGN(4);
3212@@ -142,7 +153,9 @@ SECTIONS
3213
3214 NOTES
3215
3216- _etext = .; /* End of text and rodata section */
3217+#ifdef CONFIG_PAX_KERNEXEC
3218+ . = ALIGN(1<<SECTION_SHIFT);
3219+#endif
3220
3221 #ifndef CONFIG_XIP_KERNEL
3222 . = ALIGN(PAGE_SIZE);
3223@@ -220,6 +233,11 @@ SECTIONS
3224 . = PAGE_OFFSET + TEXT_OFFSET;
3225 #else
3226 __init_end = .;
3227+
3228+#ifdef CONFIG_PAX_KERNEXEC
3229+ . = ALIGN(1<<SECTION_SHIFT);
3230+#endif
3231+
3232 . = ALIGN(THREAD_SIZE);
3233 __data_loc = .;
3234 #endif
3235diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3236index bd18bb8..87ede26 100644
3237--- a/arch/arm/kvm/arm.c
3238+++ b/arch/arm/kvm/arm.c
3239@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3240 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3241
3242 /* The VMID used in the VTTBR */
3243-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3244+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3245 static u8 kvm_next_vmid;
3246 static DEFINE_SPINLOCK(kvm_vmid_lock);
3247
3248@@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3249 */
3250 static bool need_new_vmid_gen(struct kvm *kvm)
3251 {
3252- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3253+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3254 }
3255
3256 /**
3257@@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3258
3259 /* First user of a new VMID generation? */
3260 if (unlikely(kvm_next_vmid == 0)) {
3261- atomic64_inc(&kvm_vmid_gen);
3262+ atomic64_inc_unchecked(&kvm_vmid_gen);
3263 kvm_next_vmid = 1;
3264
3265 /*
3266@@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3267 kvm_call_hyp(__kvm_flush_vm_context);
3268 }
3269
3270- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3271+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3272 kvm->arch.vmid = kvm_next_vmid;
3273 kvm_next_vmid++;
3274
3275diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3276index 14a0d98..7771a7d 100644
3277--- a/arch/arm/lib/clear_user.S
3278+++ b/arch/arm/lib/clear_user.S
3279@@ -12,14 +12,14 @@
3280
3281 .text
3282
3283-/* Prototype: int __clear_user(void *addr, size_t sz)
3284+/* Prototype: int ___clear_user(void *addr, size_t sz)
3285 * Purpose : clear some user memory
3286 * Params : addr - user memory address to clear
3287 * : sz - number of bytes to clear
3288 * Returns : number of bytes NOT cleared
3289 */
3290 ENTRY(__clear_user_std)
3291-WEAK(__clear_user)
3292+WEAK(___clear_user)
3293 stmfd sp!, {r1, lr}
3294 mov r2, #0
3295 cmp r1, #4
3296@@ -44,7 +44,7 @@ WEAK(__clear_user)
3297 USER( strnebt r2, [r0])
3298 mov r0, #0
3299 ldmfd sp!, {r1, pc}
3300-ENDPROC(__clear_user)
3301+ENDPROC(___clear_user)
3302 ENDPROC(__clear_user_std)
3303
3304 .pushsection .fixup,"ax"
3305diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3306index 66a477a..bee61d3 100644
3307--- a/arch/arm/lib/copy_from_user.S
3308+++ b/arch/arm/lib/copy_from_user.S
3309@@ -16,7 +16,7 @@
3310 /*
3311 * Prototype:
3312 *
3313- * size_t __copy_from_user(void *to, const void *from, size_t n)
3314+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3315 *
3316 * Purpose:
3317 *
3318@@ -84,11 +84,11 @@
3319
3320 .text
3321
3322-ENTRY(__copy_from_user)
3323+ENTRY(___copy_from_user)
3324
3325 #include "copy_template.S"
3326
3327-ENDPROC(__copy_from_user)
3328+ENDPROC(___copy_from_user)
3329
3330 .pushsection .fixup,"ax"
3331 .align 0
3332diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3333index 6ee2f67..d1cce76 100644
3334--- a/arch/arm/lib/copy_page.S
3335+++ b/arch/arm/lib/copy_page.S
3336@@ -10,6 +10,7 @@
3337 * ASM optimised string functions
3338 */
3339 #include <linux/linkage.h>
3340+#include <linux/const.h>
3341 #include <asm/assembler.h>
3342 #include <asm/asm-offsets.h>
3343 #include <asm/cache.h>
3344diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3345index d066df6..df28194 100644
3346--- a/arch/arm/lib/copy_to_user.S
3347+++ b/arch/arm/lib/copy_to_user.S
3348@@ -16,7 +16,7 @@
3349 /*
3350 * Prototype:
3351 *
3352- * size_t __copy_to_user(void *to, const void *from, size_t n)
3353+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3354 *
3355 * Purpose:
3356 *
3357@@ -88,11 +88,11 @@
3358 .text
3359
3360 ENTRY(__copy_to_user_std)
3361-WEAK(__copy_to_user)
3362+WEAK(___copy_to_user)
3363
3364 #include "copy_template.S"
3365
3366-ENDPROC(__copy_to_user)
3367+ENDPROC(___copy_to_user)
3368 ENDPROC(__copy_to_user_std)
3369
3370 .pushsection .fixup,"ax"
3371diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3372index 7d08b43..f7ca7ea 100644
3373--- a/arch/arm/lib/csumpartialcopyuser.S
3374+++ b/arch/arm/lib/csumpartialcopyuser.S
3375@@ -57,8 +57,8 @@
3376 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3377 */
3378
3379-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3380-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3381+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3382+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3383
3384 #include "csumpartialcopygeneric.S"
3385
3386diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3387index 5306de3..aed6d03 100644
3388--- a/arch/arm/lib/delay.c
3389+++ b/arch/arm/lib/delay.c
3390@@ -28,7 +28,7 @@
3391 /*
3392 * Default to the loop-based delay implementation.
3393 */
3394-struct arm_delay_ops arm_delay_ops = {
3395+struct arm_delay_ops arm_delay_ops __read_only = {
3396 .delay = __loop_delay,
3397 .const_udelay = __loop_const_udelay,
3398 .udelay = __loop_udelay,
3399diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3400index 3e58d71..029817c 100644
3401--- a/arch/arm/lib/uaccess_with_memcpy.c
3402+++ b/arch/arm/lib/uaccess_with_memcpy.c
3403@@ -136,7 +136,7 @@ out:
3404 }
3405
3406 unsigned long
3407-__copy_to_user(void __user *to, const void *from, unsigned long n)
3408+___copy_to_user(void __user *to, const void *from, unsigned long n)
3409 {
3410 /*
3411 * This test is stubbed out of the main function above to keep
3412@@ -190,7 +190,7 @@ out:
3413 return n;
3414 }
3415
3416-unsigned long __clear_user(void __user *addr, unsigned long n)
3417+unsigned long ___clear_user(void __user *addr, unsigned long n)
3418 {
3419 /* See rational for this in __copy_to_user() above. */
3420 if (n < 64)
3421diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3422index f7ca97b..3d7e719 100644
3423--- a/arch/arm/mach-at91/setup.c
3424+++ b/arch/arm/mach-at91/setup.c
3425@@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3426
3427 desc->pfn = __phys_to_pfn(base);
3428 desc->length = length;
3429- desc->type = MT_MEMORY_RWX_NONCACHED;
3430+ desc->type = MT_MEMORY_RW_NONCACHED;
3431
3432 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3433 base, length, desc->virtual);
3434diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3435index f3407a5..bd4256f 100644
3436--- a/arch/arm/mach-kirkwood/common.c
3437+++ b/arch/arm/mach-kirkwood/common.c
3438@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3439 clk_gate_ops.disable(hw);
3440 }
3441
3442-static struct clk_ops clk_gate_fn_ops;
3443+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3444+{
3445+ return clk_gate_ops.is_enabled(hw);
3446+}
3447+
3448+static struct clk_ops clk_gate_fn_ops = {
3449+ .enable = clk_gate_fn_enable,
3450+ .disable = clk_gate_fn_disable,
3451+ .is_enabled = clk_gate_fn_is_enabled,
3452+};
3453
3454 static struct clk __init *clk_register_gate_fn(struct device *dev,
3455 const char *name,
3456@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3457 gate_fn->fn_en = fn_en;
3458 gate_fn->fn_dis = fn_dis;
3459
3460- /* ops is the gate ops, but with our enable/disable functions */
3461- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3462- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3463- clk_gate_fn_ops = clk_gate_ops;
3464- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3465- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3466- }
3467-
3468 clk = clk_register(dev, &gate_fn->gate.hw);
3469
3470 if (IS_ERR(clk))
3471diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3472index aead77a..a2253fa 100644
3473--- a/arch/arm/mach-omap2/board-n8x0.c
3474+++ b/arch/arm/mach-omap2/board-n8x0.c
3475@@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3476 }
3477 #endif
3478
3479-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3480+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3481 .late_init = n8x0_menelaus_late_init,
3482 };
3483
3484diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3485index ab43755..ccfa231 100644
3486--- a/arch/arm/mach-omap2/gpmc.c
3487+++ b/arch/arm/mach-omap2/gpmc.c
3488@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3489 };
3490
3491 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3492-static struct irq_chip gpmc_irq_chip;
3493 static int gpmc_irq_start;
3494
3495 static struct resource gpmc_mem_root;
3496@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3497
3498 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3499
3500+static struct irq_chip gpmc_irq_chip = {
3501+ .name = "gpmc",
3502+ .irq_startup = gpmc_irq_noop_ret,
3503+ .irq_enable = gpmc_irq_enable,
3504+ .irq_disable = gpmc_irq_disable,
3505+ .irq_shutdown = gpmc_irq_noop,
3506+ .irq_ack = gpmc_irq_noop,
3507+ .irq_mask = gpmc_irq_noop,
3508+ .irq_unmask = gpmc_irq_noop,
3509+
3510+};
3511+
3512 static int gpmc_setup_irq(void)
3513 {
3514 int i;
3515@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3516 return gpmc_irq_start;
3517 }
3518
3519- gpmc_irq_chip.name = "gpmc";
3520- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3521- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3522- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3523- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3524- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3525- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3526- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3527-
3528 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3529 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3530
3531diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3532index 667915d..2ee1219 100644
3533--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3534+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3535@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3536 int (*finish_suspend)(unsigned long cpu_state);
3537 void (*resume)(void);
3538 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3539-};
3540+} __no_const;
3541
3542 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3543 static struct powerdomain *mpuss_pd;
3544@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3545 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3546 {}
3547
3548-struct cpu_pm_ops omap_pm_ops = {
3549+static struct cpu_pm_ops omap_pm_ops __read_only = {
3550 .finish_suspend = default_finish_suspend,
3551 .resume = dummy_cpu_resume,
3552 .scu_prepare = dummy_scu_prepare,
3553diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3554index 3664562..72f85c6 100644
3555--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3556+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3557@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3558 return NOTIFY_OK;
3559 }
3560
3561-static struct notifier_block __refdata irq_hotplug_notifier = {
3562+static struct notifier_block irq_hotplug_notifier = {
3563 .notifier_call = irq_cpu_hotplug_notify,
3564 };
3565
3566diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3567index 01ef59d..32ae28a8 100644
3568--- a/arch/arm/mach-omap2/omap_device.c
3569+++ b/arch/arm/mach-omap2/omap_device.c
3570@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3571 struct platform_device __init *omap_device_build(const char *pdev_name,
3572 int pdev_id,
3573 struct omap_hwmod *oh,
3574- void *pdata, int pdata_len)
3575+ const void *pdata, int pdata_len)
3576 {
3577 struct omap_hwmod *ohs[] = { oh };
3578
3579@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3580 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3581 int pdev_id,
3582 struct omap_hwmod **ohs,
3583- int oh_cnt, void *pdata,
3584+ int oh_cnt, const void *pdata,
3585 int pdata_len)
3586 {
3587 int ret = -ENOMEM;
3588diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3589index 78c02b3..c94109a 100644
3590--- a/arch/arm/mach-omap2/omap_device.h
3591+++ b/arch/arm/mach-omap2/omap_device.h
3592@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3593 /* Core code interface */
3594
3595 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3596- struct omap_hwmod *oh, void *pdata,
3597+ struct omap_hwmod *oh, const void *pdata,
3598 int pdata_len);
3599
3600 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3601 struct omap_hwmod **oh, int oh_cnt,
3602- void *pdata, int pdata_len);
3603+ const void *pdata, int pdata_len);
3604
3605 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3606 struct omap_hwmod **ohs, int oh_cnt);
3607diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3608index 66c60fe..c78950d 100644
3609--- a/arch/arm/mach-omap2/omap_hwmod.c
3610+++ b/arch/arm/mach-omap2/omap_hwmod.c
3611@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3612 int (*init_clkdm)(struct omap_hwmod *oh);
3613 void (*update_context_lost)(struct omap_hwmod *oh);
3614 int (*get_context_lost)(struct omap_hwmod *oh);
3615-};
3616+} __no_const;
3617
3618 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3619-static struct omap_hwmod_soc_ops soc_ops;
3620+static struct omap_hwmod_soc_ops soc_ops __read_only;
3621
3622 /* omap_hwmod_list contains all registered struct omap_hwmods */
3623 static LIST_HEAD(omap_hwmod_list);
3624diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3625index 95fee54..cfa9cf1 100644
3626--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3627+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3628@@ -10,6 +10,7 @@
3629
3630 #include <linux/kernel.h>
3631 #include <linux/init.h>
3632+#include <asm/pgtable.h>
3633
3634 #include "powerdomain.h"
3635
3636@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3637
3638 void __init am43xx_powerdomains_init(void)
3639 {
3640- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3641+ pax_open_kernel();
3642+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3643+ pax_close_kernel();
3644 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3645 pwrdm_register_pwrdms(powerdomains_am43xx);
3646 pwrdm_complete_init();
3647diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3648index d15c7bb..b2d1f0c 100644
3649--- a/arch/arm/mach-omap2/wd_timer.c
3650+++ b/arch/arm/mach-omap2/wd_timer.c
3651@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3652 struct omap_hwmod *oh;
3653 char *oh_name = "wd_timer2";
3654 char *dev_name = "omap_wdt";
3655- struct omap_wd_timer_platform_data pdata;
3656+ static struct omap_wd_timer_platform_data pdata = {
3657+ .read_reset_sources = prm_read_reset_sources
3658+ };
3659
3660 if (!cpu_class_is_omap2() || of_have_populated_dt())
3661 return 0;
3662@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3663 return -EINVAL;
3664 }
3665
3666- pdata.read_reset_sources = prm_read_reset_sources;
3667-
3668 pdev = omap_device_build(dev_name, id, oh, &pdata,
3669 sizeof(struct omap_wd_timer_platform_data));
3670 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3671diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3672index b82dcae..44ee5b6 100644
3673--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3674+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3675@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3676 bool entered_lp2 = false;
3677
3678 if (tegra_pending_sgi())
3679- ACCESS_ONCE(abort_flag) = true;
3680+ ACCESS_ONCE_RW(abort_flag) = true;
3681
3682 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3683
3684diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3685index 2dea8b5..6499da2 100644
3686--- a/arch/arm/mach-ux500/setup.h
3687+++ b/arch/arm/mach-ux500/setup.h
3688@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3689 .type = MT_DEVICE, \
3690 }
3691
3692-#define __MEM_DEV_DESC(x, sz) { \
3693- .virtual = IO_ADDRESS(x), \
3694- .pfn = __phys_to_pfn(x), \
3695- .length = sz, \
3696- .type = MT_MEMORY_RWX, \
3697-}
3698-
3699 extern struct smp_operations ux500_smp_ops;
3700 extern void ux500_cpu_die(unsigned int cpu);
3701
3702diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3703index ca8ecde..58ba893 100644
3704--- a/arch/arm/mm/Kconfig
3705+++ b/arch/arm/mm/Kconfig
3706@@ -446,6 +446,7 @@ config CPU_32v5
3707
3708 config CPU_32v6
3709 bool
3710+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3711 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3712
3713 config CPU_32v6K
3714@@ -600,6 +601,7 @@ config CPU_CP15_MPU
3715
3716 config CPU_USE_DOMAINS
3717 bool
3718+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3719 help
3720 This option enables or disables the use of domain switching
3721 via the set_fs() function.
3722@@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3723 config KUSER_HELPERS
3724 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3725 default y
3726+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3727 help
3728 Warning: disabling this option may break user programs.
3729
3730@@ -811,7 +814,7 @@ config KUSER_HELPERS
3731 See Documentation/arm/kernel_user_helpers.txt for details.
3732
3733 However, the fixed address nature of these helpers can be used
3734- by ROP (return orientated programming) authors when creating
3735+ by ROP (Return Oriented Programming) authors when creating
3736 exploits.
3737
3738 If all of the binaries and libraries which run on your platform
3739diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3740index 9240364..a2b8cf3 100644
3741--- a/arch/arm/mm/alignment.c
3742+++ b/arch/arm/mm/alignment.c
3743@@ -212,10 +212,12 @@ union offset_union {
3744 #define __get16_unaligned_check(ins,val,addr) \
3745 do { \
3746 unsigned int err = 0, v, a = addr; \
3747+ pax_open_userland(); \
3748 __get8_unaligned_check(ins,v,a,err); \
3749 val = v << ((BE) ? 8 : 0); \
3750 __get8_unaligned_check(ins,v,a,err); \
3751 val |= v << ((BE) ? 0 : 8); \
3752+ pax_close_userland(); \
3753 if (err) \
3754 goto fault; \
3755 } while (0)
3756@@ -229,6 +231,7 @@ union offset_union {
3757 #define __get32_unaligned_check(ins,val,addr) \
3758 do { \
3759 unsigned int err = 0, v, a = addr; \
3760+ pax_open_userland(); \
3761 __get8_unaligned_check(ins,v,a,err); \
3762 val = v << ((BE) ? 24 : 0); \
3763 __get8_unaligned_check(ins,v,a,err); \
3764@@ -237,6 +240,7 @@ union offset_union {
3765 val |= v << ((BE) ? 8 : 16); \
3766 __get8_unaligned_check(ins,v,a,err); \
3767 val |= v << ((BE) ? 0 : 24); \
3768+ pax_close_userland(); \
3769 if (err) \
3770 goto fault; \
3771 } while (0)
3772@@ -250,6 +254,7 @@ union offset_union {
3773 #define __put16_unaligned_check(ins,val,addr) \
3774 do { \
3775 unsigned int err = 0, v = val, a = addr; \
3776+ pax_open_userland(); \
3777 __asm__( FIRST_BYTE_16 \
3778 ARM( "1: "ins" %1, [%2], #1\n" ) \
3779 THUMB( "1: "ins" %1, [%2]\n" ) \
3780@@ -269,6 +274,7 @@ union offset_union {
3781 " .popsection\n" \
3782 : "=r" (err), "=&r" (v), "=&r" (a) \
3783 : "0" (err), "1" (v), "2" (a)); \
3784+ pax_close_userland(); \
3785 if (err) \
3786 goto fault; \
3787 } while (0)
3788@@ -282,6 +288,7 @@ union offset_union {
3789 #define __put32_unaligned_check(ins,val,addr) \
3790 do { \
3791 unsigned int err = 0, v = val, a = addr; \
3792+ pax_open_userland(); \
3793 __asm__( FIRST_BYTE_32 \
3794 ARM( "1: "ins" %1, [%2], #1\n" ) \
3795 THUMB( "1: "ins" %1, [%2]\n" ) \
3796@@ -311,6 +318,7 @@ union offset_union {
3797 " .popsection\n" \
3798 : "=r" (err), "=&r" (v), "=&r" (a) \
3799 : "0" (err), "1" (v), "2" (a)); \
3800+ pax_close_userland(); \
3801 if (err) \
3802 goto fault; \
3803 } while (0)
3804diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3805index 7abde2c..9df495f 100644
3806--- a/arch/arm/mm/cache-l2x0.c
3807+++ b/arch/arm/mm/cache-l2x0.c
3808@@ -46,7 +46,7 @@ struct l2x0_of_data {
3809 void (*setup)(const struct device_node *, u32 *, u32 *);
3810 void (*save)(void);
3811 struct outer_cache_fns outer_cache;
3812-};
3813+} __do_const;
3814
3815 static bool of_init = false;
3816
3817diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3818index 6eb97b3..ac509f6 100644
3819--- a/arch/arm/mm/context.c
3820+++ b/arch/arm/mm/context.c
3821@@ -43,7 +43,7 @@
3822 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3823
3824 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3825-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3826+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3827 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3828
3829 static DEFINE_PER_CPU(atomic64_t, active_asids);
3830@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3831 {
3832 static u32 cur_idx = 1;
3833 u64 asid = atomic64_read(&mm->context.id);
3834- u64 generation = atomic64_read(&asid_generation);
3835+ u64 generation = atomic64_read_unchecked(&asid_generation);
3836
3837 if (asid != 0 && is_reserved_asid(asid)) {
3838 /*
3839@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3840 */
3841 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3842 if (asid == NUM_USER_ASIDS) {
3843- generation = atomic64_add_return(ASID_FIRST_VERSION,
3844+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3845 &asid_generation);
3846 flush_context(cpu);
3847 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3848@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3849 cpu_set_reserved_ttbr0();
3850
3851 asid = atomic64_read(&mm->context.id);
3852- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3853+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3854 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3855 goto switch_mm_fastpath;
3856
3857 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3858 /* Check that our ASID belongs to the current generation. */
3859 asid = atomic64_read(&mm->context.id);
3860- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3861+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3862 asid = new_context(mm, cpu);
3863 atomic64_set(&mm->context.id, asid);
3864 }
3865diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3866index eb8830a..5360ce7 100644
3867--- a/arch/arm/mm/fault.c
3868+++ b/arch/arm/mm/fault.c
3869@@ -25,6 +25,7 @@
3870 #include <asm/system_misc.h>
3871 #include <asm/system_info.h>
3872 #include <asm/tlbflush.h>
3873+#include <asm/sections.h>
3874
3875 #include "fault.h"
3876
3877@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3878 if (fixup_exception(regs))
3879 return;
3880
3881+#ifdef CONFIG_PAX_MEMORY_UDEREF
3882+ if (addr < TASK_SIZE) {
3883+ if (current->signal->curr_ip)
3884+ 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),
3885+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3886+ else
3887+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3888+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3889+ }
3890+#endif
3891+
3892+#ifdef CONFIG_PAX_KERNEXEC
3893+ if ((fsr & FSR_WRITE) &&
3894+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3895+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3896+ {
3897+ if (current->signal->curr_ip)
3898+ 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),
3899+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3900+ else
3901+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3902+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3903+ }
3904+#endif
3905+
3906 /*
3907 * No handler, we'll have to terminate things with extreme prejudice.
3908 */
3909@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3910 }
3911 #endif
3912
3913+#ifdef CONFIG_PAX_PAGEEXEC
3914+ if (fsr & FSR_LNX_PF) {
3915+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3916+ do_group_exit(SIGKILL);
3917+ }
3918+#endif
3919+
3920 tsk->thread.address = addr;
3921 tsk->thread.error_code = fsr;
3922 tsk->thread.trap_no = 14;
3923@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3924 }
3925 #endif /* CONFIG_MMU */
3926
3927+#ifdef CONFIG_PAX_PAGEEXEC
3928+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3929+{
3930+ long i;
3931+
3932+ printk(KERN_ERR "PAX: bytes at PC: ");
3933+ for (i = 0; i < 20; i++) {
3934+ unsigned char c;
3935+ if (get_user(c, (__force unsigned char __user *)pc+i))
3936+ printk(KERN_CONT "?? ");
3937+ else
3938+ printk(KERN_CONT "%02x ", c);
3939+ }
3940+ printk("\n");
3941+
3942+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3943+ for (i = -1; i < 20; i++) {
3944+ unsigned long c;
3945+ if (get_user(c, (__force unsigned long __user *)sp+i))
3946+ printk(KERN_CONT "???????? ");
3947+ else
3948+ printk(KERN_CONT "%08lx ", c);
3949+ }
3950+ printk("\n");
3951+}
3952+#endif
3953+
3954 /*
3955 * First Level Translation Fault Handler
3956 *
3957@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3958 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3959 struct siginfo info;
3960
3961+#ifdef CONFIG_PAX_MEMORY_UDEREF
3962+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3963+ if (current->signal->curr_ip)
3964+ 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),
3965+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3966+ else
3967+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3968+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3969+ goto die;
3970+ }
3971+#endif
3972+
3973 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3974 return;
3975
3976+die:
3977 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3978 inf->name, fsr, addr);
3979
3980@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3981 ifsr_info[nr].name = name;
3982 }
3983
3984+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3985+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3986+
3987 asmlinkage void __exception
3988 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3989 {
3990 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3991 struct siginfo info;
3992+ unsigned long pc = instruction_pointer(regs);
3993+
3994+ if (user_mode(regs)) {
3995+ unsigned long sigpage = current->mm->context.sigpage;
3996+
3997+ if (sigpage <= pc && pc < sigpage + 7*4) {
3998+ if (pc < sigpage + 3*4)
3999+ sys_sigreturn(regs);
4000+ else
4001+ sys_rt_sigreturn(regs);
4002+ return;
4003+ }
4004+ if (pc == 0xffff0f60UL) {
4005+ /*
4006+ * PaX: __kuser_cmpxchg64 emulation
4007+ */
4008+ // TODO
4009+ //regs->ARM_pc = regs->ARM_lr;
4010+ //return;
4011+ }
4012+ if (pc == 0xffff0fa0UL) {
4013+ /*
4014+ * PaX: __kuser_memory_barrier emulation
4015+ */
4016+ // dmb(); implied by the exception
4017+ regs->ARM_pc = regs->ARM_lr;
4018+ return;
4019+ }
4020+ if (pc == 0xffff0fc0UL) {
4021+ /*
4022+ * PaX: __kuser_cmpxchg emulation
4023+ */
4024+ // TODO
4025+ //long new;
4026+ //int op;
4027+
4028+ //op = FUTEX_OP_SET << 28;
4029+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4030+ //regs->ARM_r0 = old != new;
4031+ //regs->ARM_pc = regs->ARM_lr;
4032+ //return;
4033+ }
4034+ if (pc == 0xffff0fe0UL) {
4035+ /*
4036+ * PaX: __kuser_get_tls emulation
4037+ */
4038+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4039+ regs->ARM_pc = regs->ARM_lr;
4040+ return;
4041+ }
4042+ }
4043+
4044+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4045+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4046+ if (current->signal->curr_ip)
4047+ 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),
4048+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4049+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4050+ else
4051+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4052+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4053+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4054+ goto die;
4055+ }
4056+#endif
4057+
4058+#ifdef CONFIG_PAX_REFCOUNT
4059+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4060+ unsigned int bkpt;
4061+
4062+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4063+ current->thread.error_code = ifsr;
4064+ current->thread.trap_no = 0;
4065+ pax_report_refcount_overflow(regs);
4066+ fixup_exception(regs);
4067+ return;
4068+ }
4069+ }
4070+#endif
4071
4072 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4073 return;
4074
4075+die:
4076 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4077 inf->name, ifsr, addr);
4078
4079diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4080index cf08bdf..772656c 100644
4081--- a/arch/arm/mm/fault.h
4082+++ b/arch/arm/mm/fault.h
4083@@ -3,6 +3,7 @@
4084
4085 /*
4086 * Fault status register encodings. We steal bit 31 for our own purposes.
4087+ * Set when the FSR value is from an instruction fault.
4088 */
4089 #define FSR_LNX_PF (1 << 31)
4090 #define FSR_WRITE (1 << 11)
4091@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4092 }
4093 #endif
4094
4095+/* valid for LPAE and !LPAE */
4096+static inline int is_xn_fault(unsigned int fsr)
4097+{
4098+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4099+}
4100+
4101+static inline int is_domain_fault(unsigned int fsr)
4102+{
4103+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4104+}
4105+
4106 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4107 unsigned long search_exception_table(unsigned long addr);
4108
4109diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4110index 804d615..fcec50a 100644
4111--- a/arch/arm/mm/init.c
4112+++ b/arch/arm/mm/init.c
4113@@ -30,6 +30,8 @@
4114 #include <asm/setup.h>
4115 #include <asm/tlb.h>
4116 #include <asm/fixmap.h>
4117+#include <asm/system_info.h>
4118+#include <asm/cp15.h>
4119
4120 #include <asm/mach/arch.h>
4121 #include <asm/mach/map.h>
4122@@ -625,7 +627,46 @@ void free_initmem(void)
4123 {
4124 #ifdef CONFIG_HAVE_TCM
4125 extern char __tcm_start, __tcm_end;
4126+#endif
4127
4128+#ifdef CONFIG_PAX_KERNEXEC
4129+ unsigned long addr;
4130+ pgd_t *pgd;
4131+ pud_t *pud;
4132+ pmd_t *pmd;
4133+ int cpu_arch = cpu_architecture();
4134+ unsigned int cr = get_cr();
4135+
4136+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4137+ /* make pages tables, etc before .text NX */
4138+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4139+ pgd = pgd_offset_k(addr);
4140+ pud = pud_offset(pgd, addr);
4141+ pmd = pmd_offset(pud, addr);
4142+ __section_update(pmd, addr, PMD_SECT_XN);
4143+ }
4144+ /* make init NX */
4145+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4146+ pgd = pgd_offset_k(addr);
4147+ pud = pud_offset(pgd, addr);
4148+ pmd = pmd_offset(pud, addr);
4149+ __section_update(pmd, addr, PMD_SECT_XN);
4150+ }
4151+ /* make kernel code/rodata RX */
4152+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4153+ pgd = pgd_offset_k(addr);
4154+ pud = pud_offset(pgd, addr);
4155+ pmd = pmd_offset(pud, addr);
4156+#ifdef CONFIG_ARM_LPAE
4157+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4158+#else
4159+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4160+#endif
4161+ }
4162+ }
4163+#endif
4164+
4165+#ifdef CONFIG_HAVE_TCM
4166 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4167 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4168 #endif
4169diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4170index f9c32ba..8540068 100644
4171--- a/arch/arm/mm/ioremap.c
4172+++ b/arch/arm/mm/ioremap.c
4173@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4174 unsigned int mtype;
4175
4176 if (cached)
4177- mtype = MT_MEMORY_RWX;
4178+ mtype = MT_MEMORY_RX;
4179 else
4180- mtype = MT_MEMORY_RWX_NONCACHED;
4181+ mtype = MT_MEMORY_RX_NONCACHED;
4182
4183 return __arm_ioremap_caller(phys_addr, size, mtype,
4184 __builtin_return_address(0));
4185diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4186index 5e85ed3..b10a7ed 100644
4187--- a/arch/arm/mm/mmap.c
4188+++ b/arch/arm/mm/mmap.c
4189@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4190 struct vm_area_struct *vma;
4191 int do_align = 0;
4192 int aliasing = cache_is_vipt_aliasing();
4193+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4194 struct vm_unmapped_area_info info;
4195
4196 /*
4197@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4198 if (len > TASK_SIZE)
4199 return -ENOMEM;
4200
4201+#ifdef CONFIG_PAX_RANDMMAP
4202+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4203+#endif
4204+
4205 if (addr) {
4206 if (do_align)
4207 addr = COLOUR_ALIGN(addr, pgoff);
4208@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4209 addr = PAGE_ALIGN(addr);
4210
4211 vma = find_vma(mm, addr);
4212- if (TASK_SIZE - len >= addr &&
4213- (!vma || addr + len <= vma->vm_start))
4214+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4215 return addr;
4216 }
4217
4218@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4219 info.high_limit = TASK_SIZE;
4220 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4221 info.align_offset = pgoff << PAGE_SHIFT;
4222+ info.threadstack_offset = offset;
4223 return vm_unmapped_area(&info);
4224 }
4225
4226@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4227 unsigned long addr = addr0;
4228 int do_align = 0;
4229 int aliasing = cache_is_vipt_aliasing();
4230+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4231 struct vm_unmapped_area_info info;
4232
4233 /*
4234@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4235 return addr;
4236 }
4237
4238+#ifdef CONFIG_PAX_RANDMMAP
4239+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4240+#endif
4241+
4242 /* requesting a specific address */
4243 if (addr) {
4244 if (do_align)
4245@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4246 else
4247 addr = PAGE_ALIGN(addr);
4248 vma = find_vma(mm, addr);
4249- if (TASK_SIZE - len >= addr &&
4250- (!vma || addr + len <= vma->vm_start))
4251+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4252 return addr;
4253 }
4254
4255@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4256 info.high_limit = mm->mmap_base;
4257 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4258 info.align_offset = pgoff << PAGE_SHIFT;
4259+ info.threadstack_offset = offset;
4260 addr = vm_unmapped_area(&info);
4261
4262 /*
4263@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4264 {
4265 unsigned long random_factor = 0UL;
4266
4267+#ifdef CONFIG_PAX_RANDMMAP
4268+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4269+#endif
4270+
4271 /* 8 bits of randomness in 20 address space bits */
4272 if ((current->flags & PF_RANDOMIZE) &&
4273 !(current->personality & ADDR_NO_RANDOMIZE))
4274@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4275
4276 if (mmap_is_legacy()) {
4277 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4278+
4279+#ifdef CONFIG_PAX_RANDMMAP
4280+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4281+ mm->mmap_base += mm->delta_mmap;
4282+#endif
4283+
4284 mm->get_unmapped_area = arch_get_unmapped_area;
4285 } else {
4286 mm->mmap_base = mmap_base(random_factor);
4287+
4288+#ifdef CONFIG_PAX_RANDMMAP
4289+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4290+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4291+#endif
4292+
4293 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4294 }
4295 }
4296diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4297index b68c6b2..f66c492 100644
4298--- a/arch/arm/mm/mmu.c
4299+++ b/arch/arm/mm/mmu.c
4300@@ -39,6 +39,22 @@
4301 #include "mm.h"
4302 #include "tcm.h"
4303
4304+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4305+void modify_domain(unsigned int dom, unsigned int type)
4306+{
4307+ struct thread_info *thread = current_thread_info();
4308+ unsigned int domain = thread->cpu_domain;
4309+ /*
4310+ * DOMAIN_MANAGER might be defined to some other value,
4311+ * use the arch-defined constant
4312+ */
4313+ domain &= ~domain_val(dom, 3);
4314+ thread->cpu_domain = domain | domain_val(dom, type);
4315+ set_domain(thread->cpu_domain);
4316+}
4317+EXPORT_SYMBOL(modify_domain);
4318+#endif
4319+
4320 /*
4321 * empty_zero_page is a special page that is used for
4322 * zero-initialized data and COW.
4323@@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4324 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4325 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4326
4327-static struct mem_type mem_types[] = {
4328+#ifdef CONFIG_PAX_KERNEXEC
4329+#define L_PTE_KERNEXEC L_PTE_RDONLY
4330+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4331+#else
4332+#define L_PTE_KERNEXEC L_PTE_DIRTY
4333+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4334+#endif
4335+
4336+static struct mem_type mem_types[] __read_only = {
4337 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4338 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4339 L_PTE_SHARED,
4340@@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4341 .prot_sect = PROT_SECT_DEVICE,
4342 .domain = DOMAIN_IO,
4343 },
4344- [MT_UNCACHED] = {
4345+ [MT_UNCACHED_RW] = {
4346 .prot_pte = PROT_PTE_DEVICE,
4347 .prot_l1 = PMD_TYPE_TABLE,
4348 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4349 .domain = DOMAIN_IO,
4350 },
4351- [MT_CACHECLEAN] = {
4352- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4353+ [MT_CACHECLEAN_RO] = {
4354+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4355 .domain = DOMAIN_KERNEL,
4356 },
4357 #ifndef CONFIG_ARM_LPAE
4358- [MT_MINICLEAN] = {
4359- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4360+ [MT_MINICLEAN_RO] = {
4361+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4362 .domain = DOMAIN_KERNEL,
4363 },
4364 #endif
4365@@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4366 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4367 L_PTE_RDONLY,
4368 .prot_l1 = PMD_TYPE_TABLE,
4369- .domain = DOMAIN_USER,
4370+ .domain = DOMAIN_VECTORS,
4371 },
4372 [MT_HIGH_VECTORS] = {
4373 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4374 L_PTE_USER | L_PTE_RDONLY,
4375 .prot_l1 = PMD_TYPE_TABLE,
4376- .domain = DOMAIN_USER,
4377+ .domain = DOMAIN_VECTORS,
4378 },
4379- [MT_MEMORY_RWX] = {
4380+ [__MT_MEMORY_RWX] = {
4381 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4382 .prot_l1 = PMD_TYPE_TABLE,
4383 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4384@@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4385 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4386 .domain = DOMAIN_KERNEL,
4387 },
4388- [MT_ROM] = {
4389- .prot_sect = PMD_TYPE_SECT,
4390+ [MT_MEMORY_RX] = {
4391+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4392+ .prot_l1 = PMD_TYPE_TABLE,
4393+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4394+ .domain = DOMAIN_KERNEL,
4395+ },
4396+ [MT_ROM_RX] = {
4397+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4398 .domain = DOMAIN_KERNEL,
4399 },
4400- [MT_MEMORY_RWX_NONCACHED] = {
4401+ [MT_MEMORY_RW_NONCACHED] = {
4402 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4403 L_PTE_MT_BUFFERABLE,
4404 .prot_l1 = PMD_TYPE_TABLE,
4405 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4406 .domain = DOMAIN_KERNEL,
4407 },
4408+ [MT_MEMORY_RX_NONCACHED] = {
4409+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4410+ L_PTE_MT_BUFFERABLE,
4411+ .prot_l1 = PMD_TYPE_TABLE,
4412+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4413+ .domain = DOMAIN_KERNEL,
4414+ },
4415 [MT_MEMORY_RW_DTCM] = {
4416 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4417 L_PTE_XN,
4418@@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4419 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4420 .domain = DOMAIN_KERNEL,
4421 },
4422- [MT_MEMORY_RWX_ITCM] = {
4423- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4424+ [MT_MEMORY_RX_ITCM] = {
4425+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4426 .prot_l1 = PMD_TYPE_TABLE,
4427+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4428 .domain = DOMAIN_KERNEL,
4429 },
4430 [MT_MEMORY_RW_SO] = {
4431@@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4432 * Mark cache clean areas and XIP ROM read only
4433 * from SVC mode and no access from userspace.
4434 */
4435- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4436- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4437- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4438+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4439+#ifdef CONFIG_PAX_KERNEXEC
4440+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4441+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4442+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4443+#endif
4444+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4445+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4446 #endif
4447
4448 if (is_smp()) {
4449@@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4450 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4451 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4452 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4453- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4454- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4455+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4456+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4457 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4458 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4459+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4460+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4461 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4462- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4463- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4464+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4465+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4466+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4467+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4468 }
4469 }
4470
4471@@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4472 if (cpu_arch >= CPU_ARCH_ARMv6) {
4473 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4474 /* Non-cacheable Normal is XCB = 001 */
4475- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4476+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4477+ PMD_SECT_BUFFERED;
4478+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4479 PMD_SECT_BUFFERED;
4480 } else {
4481 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4482- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4483+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4484+ PMD_SECT_TEX(1);
4485+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4486 PMD_SECT_TEX(1);
4487 }
4488 } else {
4489- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4490+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4491+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4492 }
4493
4494 #ifdef CONFIG_ARM_LPAE
4495@@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4496 vecs_pgprot |= PTE_EXT_AF;
4497 #endif
4498
4499+ user_pgprot |= __supported_pte_mask;
4500+
4501 for (i = 0; i < 16; i++) {
4502 pteval_t v = pgprot_val(protection_map[i]);
4503 protection_map[i] = __pgprot(v | user_pgprot);
4504@@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4505
4506 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4507 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4508- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4509- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4510+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4511+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4512 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4513 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4514+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4515+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4516 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4517- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4518- mem_types[MT_ROM].prot_sect |= cp->pmd;
4519+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4520+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4521+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4522
4523 switch (cp->pmd) {
4524 case PMD_SECT_WT:
4525- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4526+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4527 break;
4528 case PMD_SECT_WB:
4529 case PMD_SECT_WBWA:
4530- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4531+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4532 break;
4533 }
4534 pr_info("Memory policy: %sData cache %s\n",
4535@@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4536 return;
4537 }
4538
4539- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4540+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4541 md->virtual >= PAGE_OFFSET &&
4542 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4543 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4544@@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4545 * called function. This means you can't use any function or debugging
4546 * method which may touch any device, otherwise the kernel _will_ crash.
4547 */
4548+
4549+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4550+
4551 static void __init devicemaps_init(const struct machine_desc *mdesc)
4552 {
4553 struct map_desc map;
4554 unsigned long addr;
4555- void *vectors;
4556
4557- /*
4558- * Allocate the vector page early.
4559- */
4560- vectors = early_alloc(PAGE_SIZE * 2);
4561-
4562- early_trap_init(vectors);
4563+ early_trap_init(&vectors);
4564
4565 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4566 pmd_clear(pmd_off_k(addr));
4567@@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4568 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4569 map.virtual = MODULES_VADDR;
4570 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4571- map.type = MT_ROM;
4572+ map.type = MT_ROM_RX;
4573 create_mapping(&map);
4574 #endif
4575
4576@@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4577 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4578 map.virtual = FLUSH_BASE;
4579 map.length = SZ_1M;
4580- map.type = MT_CACHECLEAN;
4581+ map.type = MT_CACHECLEAN_RO;
4582 create_mapping(&map);
4583 #endif
4584 #ifdef FLUSH_BASE_MINICACHE
4585 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4586 map.virtual = FLUSH_BASE_MINICACHE;
4587 map.length = SZ_1M;
4588- map.type = MT_MINICLEAN;
4589+ map.type = MT_MINICLEAN_RO;
4590 create_mapping(&map);
4591 #endif
4592
4593@@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4594 * location (0xffff0000). If we aren't using high-vectors, also
4595 * create a mapping at the low-vectors virtual address.
4596 */
4597- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4598+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4599 map.virtual = 0xffff0000;
4600 map.length = PAGE_SIZE;
4601 #ifdef CONFIG_KUSER_HELPERS
4602@@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4603 static void __init map_lowmem(void)
4604 {
4605 struct memblock_region *reg;
4606+#ifndef CONFIG_PAX_KERNEXEC
4607 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4608 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4609+#endif
4610
4611 /* Map all the lowmem memory banks. */
4612 for_each_memblock(memory, reg) {
4613@@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4614 if (start >= end)
4615 break;
4616
4617+#ifdef CONFIG_PAX_KERNEXEC
4618+ map.pfn = __phys_to_pfn(start);
4619+ map.virtual = __phys_to_virt(start);
4620+ map.length = end - start;
4621+
4622+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4623+ struct map_desc kernel;
4624+ struct map_desc initmap;
4625+
4626+ /* when freeing initmem we will make this RW */
4627+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4628+ initmap.virtual = (unsigned long)__init_begin;
4629+ initmap.length = _sdata - __init_begin;
4630+ initmap.type = __MT_MEMORY_RWX;
4631+ create_mapping(&initmap);
4632+
4633+ /* when freeing initmem we will make this RX */
4634+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4635+ kernel.virtual = (unsigned long)_stext;
4636+ kernel.length = __init_begin - _stext;
4637+ kernel.type = __MT_MEMORY_RWX;
4638+ create_mapping(&kernel);
4639+
4640+ if (map.virtual < (unsigned long)_stext) {
4641+ map.length = (unsigned long)_stext - map.virtual;
4642+ map.type = __MT_MEMORY_RWX;
4643+ create_mapping(&map);
4644+ }
4645+
4646+ map.pfn = __phys_to_pfn(__pa(_sdata));
4647+ map.virtual = (unsigned long)_sdata;
4648+ map.length = end - __pa(_sdata);
4649+ }
4650+
4651+ map.type = MT_MEMORY_RW;
4652+ create_mapping(&map);
4653+#else
4654 if (end < kernel_x_start || start >= kernel_x_end) {
4655 map.pfn = __phys_to_pfn(start);
4656 map.virtual = __phys_to_virt(start);
4657 map.length = end - start;
4658- map.type = MT_MEMORY_RWX;
4659+ map.type = __MT_MEMORY_RWX;
4660
4661 create_mapping(&map);
4662 } else {
4663@@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4664 map.pfn = __phys_to_pfn(kernel_x_start);
4665 map.virtual = __phys_to_virt(kernel_x_start);
4666 map.length = kernel_x_end - kernel_x_start;
4667- map.type = MT_MEMORY_RWX;
4668+ map.type = __MT_MEMORY_RWX;
4669
4670 create_mapping(&map);
4671
4672@@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4673 create_mapping(&map);
4674 }
4675 }
4676+#endif
4677 }
4678 }
4679
4680diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4681index 5b217f4..c23f40e 100644
4682--- a/arch/arm/plat-iop/setup.c
4683+++ b/arch/arm/plat-iop/setup.c
4684@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4685 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4686 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4687 .length = IOP3XX_PERIPHERAL_SIZE,
4688- .type = MT_UNCACHED,
4689+ .type = MT_UNCACHED_RW,
4690 },
4691 };
4692
4693diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4694index a5bc92d..0bb4730 100644
4695--- a/arch/arm/plat-omap/sram.c
4696+++ b/arch/arm/plat-omap/sram.c
4697@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4698 * Looks like we need to preserve some bootloader code at the
4699 * beginning of SRAM for jumping to flash for reboot to work...
4700 */
4701+ pax_open_kernel();
4702 memset_io(omap_sram_base + omap_sram_skip, 0,
4703 omap_sram_size - omap_sram_skip);
4704+ pax_close_kernel();
4705 }
4706diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4707index ce6d763..cfea917 100644
4708--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4709+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4710@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4711 int (*started)(unsigned ch);
4712 int (*flush)(unsigned ch);
4713 int (*stop)(unsigned ch);
4714-};
4715+} __no_const;
4716
4717 extern void *samsung_dmadev_get_ops(void);
4718 extern void *s3c_dma_get_ops(void);
4719diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4720index 6c0f684..5faea9d 100644
4721--- a/arch/arm64/include/asm/uaccess.h
4722+++ b/arch/arm64/include/asm/uaccess.h
4723@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4724 flag; \
4725 })
4726
4727+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4728 #define access_ok(type, addr, size) __range_ok(addr, size)
4729 #define user_addr_max get_fs
4730
4731diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4732index c3a58a1..78fbf54 100644
4733--- a/arch/avr32/include/asm/cache.h
4734+++ b/arch/avr32/include/asm/cache.h
4735@@ -1,8 +1,10 @@
4736 #ifndef __ASM_AVR32_CACHE_H
4737 #define __ASM_AVR32_CACHE_H
4738
4739+#include <linux/const.h>
4740+
4741 #define L1_CACHE_SHIFT 5
4742-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4743+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4744
4745 /*
4746 * Memory returned by kmalloc() may be used for DMA, so we must make
4747diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4748index d232888..87c8df1 100644
4749--- a/arch/avr32/include/asm/elf.h
4750+++ b/arch/avr32/include/asm/elf.h
4751@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4752 the loader. We need to make sure that it is out of the way of the program
4753 that it will "exec", and that there is sufficient room for the brk. */
4754
4755-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4756+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4757
4758+#ifdef CONFIG_PAX_ASLR
4759+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4760+
4761+#define PAX_DELTA_MMAP_LEN 15
4762+#define PAX_DELTA_STACK_LEN 15
4763+#endif
4764
4765 /* This yields a mask that user programs can use to figure out what
4766 instruction set this CPU supports. This could be done in user space,
4767diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4768index 479330b..53717a8 100644
4769--- a/arch/avr32/include/asm/kmap_types.h
4770+++ b/arch/avr32/include/asm/kmap_types.h
4771@@ -2,9 +2,9 @@
4772 #define __ASM_AVR32_KMAP_TYPES_H
4773
4774 #ifdef CONFIG_DEBUG_HIGHMEM
4775-# define KM_TYPE_NR 29
4776+# define KM_TYPE_NR 30
4777 #else
4778-# define KM_TYPE_NR 14
4779+# define KM_TYPE_NR 15
4780 #endif
4781
4782 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4783diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4784index 0eca933..eb78c7b 100644
4785--- a/arch/avr32/mm/fault.c
4786+++ b/arch/avr32/mm/fault.c
4787@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4788
4789 int exception_trace = 1;
4790
4791+#ifdef CONFIG_PAX_PAGEEXEC
4792+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4793+{
4794+ unsigned long i;
4795+
4796+ printk(KERN_ERR "PAX: bytes at PC: ");
4797+ for (i = 0; i < 20; i++) {
4798+ unsigned char c;
4799+ if (get_user(c, (unsigned char *)pc+i))
4800+ printk(KERN_CONT "???????? ");
4801+ else
4802+ printk(KERN_CONT "%02x ", c);
4803+ }
4804+ printk("\n");
4805+}
4806+#endif
4807+
4808 /*
4809 * This routine handles page faults. It determines the address and the
4810 * problem, and then passes it off to one of the appropriate routines.
4811@@ -176,6 +193,16 @@ bad_area:
4812 up_read(&mm->mmap_sem);
4813
4814 if (user_mode(regs)) {
4815+
4816+#ifdef CONFIG_PAX_PAGEEXEC
4817+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4818+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4819+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4820+ do_group_exit(SIGKILL);
4821+ }
4822+ }
4823+#endif
4824+
4825 if (exception_trace && printk_ratelimit())
4826 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4827 "sp %08lx ecr %lu\n",
4828diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4829index 568885a..f8008df 100644
4830--- a/arch/blackfin/include/asm/cache.h
4831+++ b/arch/blackfin/include/asm/cache.h
4832@@ -7,6 +7,7 @@
4833 #ifndef __ARCH_BLACKFIN_CACHE_H
4834 #define __ARCH_BLACKFIN_CACHE_H
4835
4836+#include <linux/const.h>
4837 #include <linux/linkage.h> /* for asmlinkage */
4838
4839 /*
4840@@ -14,7 +15,7 @@
4841 * Blackfin loads 32 bytes for cache
4842 */
4843 #define L1_CACHE_SHIFT 5
4844-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4845+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4846 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4847
4848 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4849diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4850index aea2718..3639a60 100644
4851--- a/arch/cris/include/arch-v10/arch/cache.h
4852+++ b/arch/cris/include/arch-v10/arch/cache.h
4853@@ -1,8 +1,9 @@
4854 #ifndef _ASM_ARCH_CACHE_H
4855 #define _ASM_ARCH_CACHE_H
4856
4857+#include <linux/const.h>
4858 /* Etrax 100LX have 32-byte cache-lines. */
4859-#define L1_CACHE_BYTES 32
4860 #define L1_CACHE_SHIFT 5
4861+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4862
4863 #endif /* _ASM_ARCH_CACHE_H */
4864diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4865index 7caf25d..ee65ac5 100644
4866--- a/arch/cris/include/arch-v32/arch/cache.h
4867+++ b/arch/cris/include/arch-v32/arch/cache.h
4868@@ -1,11 +1,12 @@
4869 #ifndef _ASM_CRIS_ARCH_CACHE_H
4870 #define _ASM_CRIS_ARCH_CACHE_H
4871
4872+#include <linux/const.h>
4873 #include <arch/hwregs/dma.h>
4874
4875 /* A cache-line is 32 bytes. */
4876-#define L1_CACHE_BYTES 32
4877 #define L1_CACHE_SHIFT 5
4878+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4879
4880 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4881
4882diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4883index b86329d..6709906 100644
4884--- a/arch/frv/include/asm/atomic.h
4885+++ b/arch/frv/include/asm/atomic.h
4886@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4887 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4888 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4889
4890+#define atomic64_read_unchecked(v) atomic64_read(v)
4891+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4892+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4893+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4894+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4895+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4896+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4897+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4898+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4899+
4900 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4901 {
4902 int c, old;
4903diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4904index 2797163..c2a401d 100644
4905--- a/arch/frv/include/asm/cache.h
4906+++ b/arch/frv/include/asm/cache.h
4907@@ -12,10 +12,11 @@
4908 #ifndef __ASM_CACHE_H
4909 #define __ASM_CACHE_H
4910
4911+#include <linux/const.h>
4912
4913 /* bytes per L1 cache line */
4914 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4915-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4916+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4917
4918 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4919 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4920diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4921index 43901f2..0d8b865 100644
4922--- a/arch/frv/include/asm/kmap_types.h
4923+++ b/arch/frv/include/asm/kmap_types.h
4924@@ -2,6 +2,6 @@
4925 #ifndef _ASM_KMAP_TYPES_H
4926 #define _ASM_KMAP_TYPES_H
4927
4928-#define KM_TYPE_NR 17
4929+#define KM_TYPE_NR 18
4930
4931 #endif
4932diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4933index 836f147..4cf23f5 100644
4934--- a/arch/frv/mm/elf-fdpic.c
4935+++ b/arch/frv/mm/elf-fdpic.c
4936@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4937 {
4938 struct vm_area_struct *vma;
4939 struct vm_unmapped_area_info info;
4940+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4941
4942 if (len > TASK_SIZE)
4943 return -ENOMEM;
4944@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4945 if (addr) {
4946 addr = PAGE_ALIGN(addr);
4947 vma = find_vma(current->mm, addr);
4948- if (TASK_SIZE - len >= addr &&
4949- (!vma || addr + len <= vma->vm_start))
4950+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4951 goto success;
4952 }
4953
4954@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4955 info.high_limit = (current->mm->start_stack - 0x00200000);
4956 info.align_mask = 0;
4957 info.align_offset = 0;
4958+ info.threadstack_offset = offset;
4959 addr = vm_unmapped_area(&info);
4960 if (!(addr & ~PAGE_MASK))
4961 goto success;
4962diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4963index f4ca594..adc72fd6 100644
4964--- a/arch/hexagon/include/asm/cache.h
4965+++ b/arch/hexagon/include/asm/cache.h
4966@@ -21,9 +21,11 @@
4967 #ifndef __ASM_CACHE_H
4968 #define __ASM_CACHE_H
4969
4970+#include <linux/const.h>
4971+
4972 /* Bytes per L1 cache line */
4973-#define L1_CACHE_SHIFT (5)
4974-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4975+#define L1_CACHE_SHIFT 5
4976+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4977
4978 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4979 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4980diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4981index 0c8e553..112d734 100644
4982--- a/arch/ia64/Kconfig
4983+++ b/arch/ia64/Kconfig
4984@@ -544,6 +544,7 @@ source "drivers/sn/Kconfig"
4985 config KEXEC
4986 bool "kexec system call"
4987 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4988+ depends on !GRKERNSEC_KMEM
4989 help
4990 kexec is a system call that implements the ability to shutdown your
4991 current kernel, and to start another kernel. It is like a reboot
4992diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4993index 6e6fe18..a6ae668 100644
4994--- a/arch/ia64/include/asm/atomic.h
4995+++ b/arch/ia64/include/asm/atomic.h
4996@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4997 #define atomic64_inc(v) atomic64_add(1, (v))
4998 #define atomic64_dec(v) atomic64_sub(1, (v))
4999
5000+#define atomic64_read_unchecked(v) atomic64_read(v)
5001+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5002+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5003+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5004+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5005+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5006+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5007+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5008+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5009+
5010 /* Atomic operations are already serializing */
5011 #define smp_mb__before_atomic_dec() barrier()
5012 #define smp_mb__after_atomic_dec() barrier()
5013diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5014index 988254a..e1ee885 100644
5015--- a/arch/ia64/include/asm/cache.h
5016+++ b/arch/ia64/include/asm/cache.h
5017@@ -1,6 +1,7 @@
5018 #ifndef _ASM_IA64_CACHE_H
5019 #define _ASM_IA64_CACHE_H
5020
5021+#include <linux/const.h>
5022
5023 /*
5024 * Copyright (C) 1998-2000 Hewlett-Packard Co
5025@@ -9,7 +10,7 @@
5026
5027 /* Bytes per L1 (data) cache line. */
5028 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5029-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5030+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5031
5032 #ifdef CONFIG_SMP
5033 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5034diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5035index 5a83c5c..4d7f553 100644
5036--- a/arch/ia64/include/asm/elf.h
5037+++ b/arch/ia64/include/asm/elf.h
5038@@ -42,6 +42,13 @@
5039 */
5040 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5041
5042+#ifdef CONFIG_PAX_ASLR
5043+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5044+
5045+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5046+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5047+#endif
5048+
5049 #define PT_IA_64_UNWIND 0x70000001
5050
5051 /* IA-64 relocations: */
5052diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5053index 5767cdf..7462574 100644
5054--- a/arch/ia64/include/asm/pgalloc.h
5055+++ b/arch/ia64/include/asm/pgalloc.h
5056@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5057 pgd_val(*pgd_entry) = __pa(pud);
5058 }
5059
5060+static inline void
5061+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5062+{
5063+ pgd_populate(mm, pgd_entry, pud);
5064+}
5065+
5066 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5067 {
5068 return quicklist_alloc(0, GFP_KERNEL, NULL);
5069@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5070 pud_val(*pud_entry) = __pa(pmd);
5071 }
5072
5073+static inline void
5074+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5075+{
5076+ pud_populate(mm, pud_entry, pmd);
5077+}
5078+
5079 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5080 {
5081 return quicklist_alloc(0, GFP_KERNEL, NULL);
5082diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5083index 7935115..c0eca6a 100644
5084--- a/arch/ia64/include/asm/pgtable.h
5085+++ b/arch/ia64/include/asm/pgtable.h
5086@@ -12,7 +12,7 @@
5087 * David Mosberger-Tang <davidm@hpl.hp.com>
5088 */
5089
5090-
5091+#include <linux/const.h>
5092 #include <asm/mman.h>
5093 #include <asm/page.h>
5094 #include <asm/processor.h>
5095@@ -142,6 +142,17 @@
5096 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5097 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5098 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5099+
5100+#ifdef CONFIG_PAX_PAGEEXEC
5101+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5102+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5103+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5104+#else
5105+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5106+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5107+# define PAGE_COPY_NOEXEC PAGE_COPY
5108+#endif
5109+
5110 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5111 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5112 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5113diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5114index 45698cd..e8e2dbc 100644
5115--- a/arch/ia64/include/asm/spinlock.h
5116+++ b/arch/ia64/include/asm/spinlock.h
5117@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5118 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5119
5120 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5121- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5122+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5123 }
5124
5125 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5126diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5127index 449c8c0..3d4b1e9 100644
5128--- a/arch/ia64/include/asm/uaccess.h
5129+++ b/arch/ia64/include/asm/uaccess.h
5130@@ -70,6 +70,7 @@
5131 && ((segment).seg == KERNEL_DS.seg \
5132 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5133 })
5134+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5135 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5136
5137 /*
5138@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5139 static inline unsigned long
5140 __copy_to_user (void __user *to, const void *from, unsigned long count)
5141 {
5142+ if (count > INT_MAX)
5143+ return count;
5144+
5145+ if (!__builtin_constant_p(count))
5146+ check_object_size(from, count, true);
5147+
5148 return __copy_user(to, (__force void __user *) from, count);
5149 }
5150
5151 static inline unsigned long
5152 __copy_from_user (void *to, const void __user *from, unsigned long count)
5153 {
5154+ if (count > INT_MAX)
5155+ return count;
5156+
5157+ if (!__builtin_constant_p(count))
5158+ check_object_size(to, count, false);
5159+
5160 return __copy_user((__force void __user *) to, from, count);
5161 }
5162
5163@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5164 ({ \
5165 void __user *__cu_to = (to); \
5166 const void *__cu_from = (from); \
5167- long __cu_len = (n); \
5168+ unsigned long __cu_len = (n); \
5169 \
5170- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5171+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5172+ if (!__builtin_constant_p(n)) \
5173+ check_object_size(__cu_from, __cu_len, true); \
5174 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5175+ } \
5176 __cu_len; \
5177 })
5178
5179@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5180 ({ \
5181 void *__cu_to = (to); \
5182 const void __user *__cu_from = (from); \
5183- long __cu_len = (n); \
5184+ unsigned long __cu_len = (n); \
5185 \
5186 __chk_user_ptr(__cu_from); \
5187- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5188+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5189+ if (!__builtin_constant_p(n)) \
5190+ check_object_size(__cu_to, __cu_len, false); \
5191 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5192+ } \
5193 __cu_len; \
5194 })
5195
5196diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5197index 24603be..948052d 100644
5198--- a/arch/ia64/kernel/module.c
5199+++ b/arch/ia64/kernel/module.c
5200@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5201 void
5202 module_free (struct module *mod, void *module_region)
5203 {
5204- if (mod && mod->arch.init_unw_table &&
5205- module_region == mod->module_init) {
5206+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5207 unw_remove_unwind_table(mod->arch.init_unw_table);
5208 mod->arch.init_unw_table = NULL;
5209 }
5210@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5211 }
5212
5213 static inline int
5214+in_init_rx (const struct module *mod, uint64_t addr)
5215+{
5216+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5217+}
5218+
5219+static inline int
5220+in_init_rw (const struct module *mod, uint64_t addr)
5221+{
5222+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5223+}
5224+
5225+static inline int
5226 in_init (const struct module *mod, uint64_t addr)
5227 {
5228- return addr - (uint64_t) mod->module_init < mod->init_size;
5229+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5230+}
5231+
5232+static inline int
5233+in_core_rx (const struct module *mod, uint64_t addr)
5234+{
5235+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5236+}
5237+
5238+static inline int
5239+in_core_rw (const struct module *mod, uint64_t addr)
5240+{
5241+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5242 }
5243
5244 static inline int
5245 in_core (const struct module *mod, uint64_t addr)
5246 {
5247- return addr - (uint64_t) mod->module_core < mod->core_size;
5248+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5249 }
5250
5251 static inline int
5252@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5253 break;
5254
5255 case RV_BDREL:
5256- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5257+ if (in_init_rx(mod, val))
5258+ val -= (uint64_t) mod->module_init_rx;
5259+ else if (in_init_rw(mod, val))
5260+ val -= (uint64_t) mod->module_init_rw;
5261+ else if (in_core_rx(mod, val))
5262+ val -= (uint64_t) mod->module_core_rx;
5263+ else if (in_core_rw(mod, val))
5264+ val -= (uint64_t) mod->module_core_rw;
5265 break;
5266
5267 case RV_LTV:
5268@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5269 * addresses have been selected...
5270 */
5271 uint64_t gp;
5272- if (mod->core_size > MAX_LTOFF)
5273+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5274 /*
5275 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5276 * at the end of the module.
5277 */
5278- gp = mod->core_size - MAX_LTOFF / 2;
5279+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5280 else
5281- gp = mod->core_size / 2;
5282- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5283+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5284+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5285 mod->arch.gp = gp;
5286 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5287 }
5288diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5289index ab33328..f39506c 100644
5290--- a/arch/ia64/kernel/palinfo.c
5291+++ b/arch/ia64/kernel/palinfo.c
5292@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5293 return NOTIFY_OK;
5294 }
5295
5296-static struct notifier_block __refdata palinfo_cpu_notifier =
5297+static struct notifier_block palinfo_cpu_notifier =
5298 {
5299 .notifier_call = palinfo_cpu_callback,
5300 .priority = 0,
5301diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5302index 41e33f8..65180b2a 100644
5303--- a/arch/ia64/kernel/sys_ia64.c
5304+++ b/arch/ia64/kernel/sys_ia64.c
5305@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5306 unsigned long align_mask = 0;
5307 struct mm_struct *mm = current->mm;
5308 struct vm_unmapped_area_info info;
5309+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5310
5311 if (len > RGN_MAP_LIMIT)
5312 return -ENOMEM;
5313@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5314 if (REGION_NUMBER(addr) == RGN_HPAGE)
5315 addr = 0;
5316 #endif
5317+
5318+#ifdef CONFIG_PAX_RANDMMAP
5319+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5320+ addr = mm->free_area_cache;
5321+ else
5322+#endif
5323+
5324 if (!addr)
5325 addr = TASK_UNMAPPED_BASE;
5326
5327@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5328 info.high_limit = TASK_SIZE;
5329 info.align_mask = align_mask;
5330 info.align_offset = 0;
5331+ info.threadstack_offset = offset;
5332 return vm_unmapped_area(&info);
5333 }
5334
5335diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5336index 84f8a52..7c76178 100644
5337--- a/arch/ia64/kernel/vmlinux.lds.S
5338+++ b/arch/ia64/kernel/vmlinux.lds.S
5339@@ -192,7 +192,7 @@ SECTIONS {
5340 /* Per-cpu data: */
5341 . = ALIGN(PERCPU_PAGE_SIZE);
5342 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5343- __phys_per_cpu_start = __per_cpu_load;
5344+ __phys_per_cpu_start = per_cpu_load;
5345 /*
5346 * ensure percpu data fits
5347 * into percpu page size
5348diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5349index 7225dad..2a7c8256 100644
5350--- a/arch/ia64/mm/fault.c
5351+++ b/arch/ia64/mm/fault.c
5352@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5353 return pte_present(pte);
5354 }
5355
5356+#ifdef CONFIG_PAX_PAGEEXEC
5357+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5358+{
5359+ unsigned long i;
5360+
5361+ printk(KERN_ERR "PAX: bytes at PC: ");
5362+ for (i = 0; i < 8; i++) {
5363+ unsigned int c;
5364+ if (get_user(c, (unsigned int *)pc+i))
5365+ printk(KERN_CONT "???????? ");
5366+ else
5367+ printk(KERN_CONT "%08x ", c);
5368+ }
5369+ printk("\n");
5370+}
5371+#endif
5372+
5373 # define VM_READ_BIT 0
5374 # define VM_WRITE_BIT 1
5375 # define VM_EXEC_BIT 2
5376@@ -151,8 +168,21 @@ retry:
5377 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5378 goto bad_area;
5379
5380- if ((vma->vm_flags & mask) != mask)
5381+ if ((vma->vm_flags & mask) != mask) {
5382+
5383+#ifdef CONFIG_PAX_PAGEEXEC
5384+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5385+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5386+ goto bad_area;
5387+
5388+ up_read(&mm->mmap_sem);
5389+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5390+ do_group_exit(SIGKILL);
5391+ }
5392+#endif
5393+
5394 goto bad_area;
5395+ }
5396
5397 /*
5398 * If for any reason at all we couldn't handle the fault, make
5399diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5400index 68232db..6ca80af 100644
5401--- a/arch/ia64/mm/hugetlbpage.c
5402+++ b/arch/ia64/mm/hugetlbpage.c
5403@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5404 unsigned long pgoff, unsigned long flags)
5405 {
5406 struct vm_unmapped_area_info info;
5407+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5408
5409 if (len > RGN_MAP_LIMIT)
5410 return -ENOMEM;
5411@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5412 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5413 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5414 info.align_offset = 0;
5415+ info.threadstack_offset = offset;
5416 return vm_unmapped_area(&info);
5417 }
5418
5419diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5420index 25c3502..560dae7 100644
5421--- a/arch/ia64/mm/init.c
5422+++ b/arch/ia64/mm/init.c
5423@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5424 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5425 vma->vm_end = vma->vm_start + PAGE_SIZE;
5426 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5427+
5428+#ifdef CONFIG_PAX_PAGEEXEC
5429+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5430+ vma->vm_flags &= ~VM_EXEC;
5431+
5432+#ifdef CONFIG_PAX_MPROTECT
5433+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5434+ vma->vm_flags &= ~VM_MAYEXEC;
5435+#endif
5436+
5437+ }
5438+#endif
5439+
5440 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5441 down_write(&current->mm->mmap_sem);
5442 if (insert_vm_struct(current->mm, vma)) {
5443diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5444index 40b3ee9..8c2c112 100644
5445--- a/arch/m32r/include/asm/cache.h
5446+++ b/arch/m32r/include/asm/cache.h
5447@@ -1,8 +1,10 @@
5448 #ifndef _ASM_M32R_CACHE_H
5449 #define _ASM_M32R_CACHE_H
5450
5451+#include <linux/const.h>
5452+
5453 /* L1 cache line size */
5454 #define L1_CACHE_SHIFT 4
5455-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5456+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5457
5458 #endif /* _ASM_M32R_CACHE_H */
5459diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5460index 82abd15..d95ae5d 100644
5461--- a/arch/m32r/lib/usercopy.c
5462+++ b/arch/m32r/lib/usercopy.c
5463@@ -14,6 +14,9 @@
5464 unsigned long
5465 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5466 {
5467+ if ((long)n < 0)
5468+ return n;
5469+
5470 prefetch(from);
5471 if (access_ok(VERIFY_WRITE, to, n))
5472 __copy_user(to,from,n);
5473@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5474 unsigned long
5475 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5476 {
5477+ if ((long)n < 0)
5478+ return n;
5479+
5480 prefetchw(to);
5481 if (access_ok(VERIFY_READ, from, n))
5482 __copy_user_zeroing(to,from,n);
5483diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5484index 0395c51..5f26031 100644
5485--- a/arch/m68k/include/asm/cache.h
5486+++ b/arch/m68k/include/asm/cache.h
5487@@ -4,9 +4,11 @@
5488 #ifndef __ARCH_M68K_CACHE_H
5489 #define __ARCH_M68K_CACHE_H
5490
5491+#include <linux/const.h>
5492+
5493 /* bytes per L1 cache line */
5494 #define L1_CACHE_SHIFT 4
5495-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5496+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5497
5498 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5499
5500diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5501index 0424315..defcca9 100644
5502--- a/arch/metag/mm/hugetlbpage.c
5503+++ b/arch/metag/mm/hugetlbpage.c
5504@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5505 info.high_limit = TASK_SIZE;
5506 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5507 info.align_offset = 0;
5508+ info.threadstack_offset = 0;
5509 return vm_unmapped_area(&info);
5510 }
5511
5512diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5513index 4efe96a..60e8699 100644
5514--- a/arch/microblaze/include/asm/cache.h
5515+++ b/arch/microblaze/include/asm/cache.h
5516@@ -13,11 +13,12 @@
5517 #ifndef _ASM_MICROBLAZE_CACHE_H
5518 #define _ASM_MICROBLAZE_CACHE_H
5519
5520+#include <linux/const.h>
5521 #include <asm/registers.h>
5522
5523 #define L1_CACHE_SHIFT 5
5524 /* word-granular cache in microblaze */
5525-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5526+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5527
5528 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5529
5530diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5531index 95fa1f1..56a6fa2 100644
5532--- a/arch/mips/Kconfig
5533+++ b/arch/mips/Kconfig
5534@@ -2298,6 +2298,7 @@ source "kernel/Kconfig.preempt"
5535
5536 config KEXEC
5537 bool "Kexec system call"
5538+ depends on !GRKERNSEC_KMEM
5539 help
5540 kexec is a system call that implements the ability to shutdown your
5541 current kernel, and to start another kernel. It is like a reboot
5542diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5543index 02f2444..506969c 100644
5544--- a/arch/mips/cavium-octeon/dma-octeon.c
5545+++ b/arch/mips/cavium-octeon/dma-octeon.c
5546@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5547 if (dma_release_from_coherent(dev, order, vaddr))
5548 return;
5549
5550- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5551+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5552 }
5553
5554 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5555diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5556index 7eed2f2..c4e385d 100644
5557--- a/arch/mips/include/asm/atomic.h
5558+++ b/arch/mips/include/asm/atomic.h
5559@@ -21,15 +21,39 @@
5560 #include <asm/cmpxchg.h>
5561 #include <asm/war.h>
5562
5563+#ifdef CONFIG_GENERIC_ATOMIC64
5564+#include <asm-generic/atomic64.h>
5565+#endif
5566+
5567 #define ATOMIC_INIT(i) { (i) }
5568
5569+#ifdef CONFIG_64BIT
5570+#define _ASM_EXTABLE(from, to) \
5571+" .section __ex_table,\"a\"\n" \
5572+" .dword " #from ", " #to"\n" \
5573+" .previous\n"
5574+#else
5575+#define _ASM_EXTABLE(from, to) \
5576+" .section __ex_table,\"a\"\n" \
5577+" .word " #from ", " #to"\n" \
5578+" .previous\n"
5579+#endif
5580+
5581 /*
5582 * atomic_read - read atomic variable
5583 * @v: pointer of type atomic_t
5584 *
5585 * Atomically reads the value of @v.
5586 */
5587-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5588+static inline int atomic_read(const atomic_t *v)
5589+{
5590+ return (*(volatile const int *) &v->counter);
5591+}
5592+
5593+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5594+{
5595+ return (*(volatile const int *) &v->counter);
5596+}
5597
5598 /*
5599 * atomic_set - set atomic variable
5600@@ -38,7 +62,15 @@
5601 *
5602 * Atomically sets the value of @v to @i.
5603 */
5604-#define atomic_set(v, i) ((v)->counter = (i))
5605+static inline void atomic_set(atomic_t *v, int i)
5606+{
5607+ v->counter = i;
5608+}
5609+
5610+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5611+{
5612+ v->counter = i;
5613+}
5614
5615 /*
5616 * atomic_add - add integer to atomic variable
5617@@ -47,7 +79,67 @@
5618 *
5619 * Atomically adds @i to @v.
5620 */
5621-static __inline__ void atomic_add(int i, atomic_t * v)
5622+static __inline__ void atomic_add(int i, atomic_t *v)
5623+{
5624+ int temp;
5625+
5626+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5627+ __asm__ __volatile__(
5628+ " .set mips3 \n"
5629+ "1: ll %0, %1 # atomic_add \n"
5630+#ifdef CONFIG_PAX_REFCOUNT
5631+ /* Exception on overflow. */
5632+ "2: add %0, %2 \n"
5633+#else
5634+ " addu %0, %2 \n"
5635+#endif
5636+ " sc %0, %1 \n"
5637+ " beqzl %0, 1b \n"
5638+#ifdef CONFIG_PAX_REFCOUNT
5639+ "3: \n"
5640+ _ASM_EXTABLE(2b, 3b)
5641+#endif
5642+ " .set mips0 \n"
5643+ : "=&r" (temp), "+m" (v->counter)
5644+ : "Ir" (i));
5645+ } else if (kernel_uses_llsc) {
5646+ __asm__ __volatile__(
5647+ " .set mips3 \n"
5648+ "1: ll %0, %1 # atomic_add \n"
5649+#ifdef CONFIG_PAX_REFCOUNT
5650+ /* Exception on overflow. */
5651+ "2: add %0, %2 \n"
5652+#else
5653+ " addu %0, %2 \n"
5654+#endif
5655+ " sc %0, %1 \n"
5656+ " beqz %0, 1b \n"
5657+#ifdef CONFIG_PAX_REFCOUNT
5658+ "3: \n"
5659+ _ASM_EXTABLE(2b, 3b)
5660+#endif
5661+ " .set mips0 \n"
5662+ : "=&r" (temp), "+m" (v->counter)
5663+ : "Ir" (i));
5664+ } else {
5665+ unsigned long flags;
5666+
5667+ raw_local_irq_save(flags);
5668+ __asm__ __volatile__(
5669+#ifdef CONFIG_PAX_REFCOUNT
5670+ /* Exception on overflow. */
5671+ "1: add %0, %1 \n"
5672+ "2: \n"
5673+ _ASM_EXTABLE(1b, 2b)
5674+#else
5675+ " addu %0, %1 \n"
5676+#endif
5677+ : "+r" (v->counter) : "Ir" (i));
5678+ raw_local_irq_restore(flags);
5679+ }
5680+}
5681+
5682+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5683 {
5684 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5685 int temp;
5686@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5687 *
5688 * Atomically subtracts @i from @v.
5689 */
5690-static __inline__ void atomic_sub(int i, atomic_t * v)
5691+static __inline__ void atomic_sub(int i, atomic_t *v)
5692+{
5693+ int temp;
5694+
5695+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5696+ __asm__ __volatile__(
5697+ " .set mips3 \n"
5698+ "1: ll %0, %1 # atomic64_sub \n"
5699+#ifdef CONFIG_PAX_REFCOUNT
5700+ /* Exception on overflow. */
5701+ "2: sub %0, %2 \n"
5702+#else
5703+ " subu %0, %2 \n"
5704+#endif
5705+ " sc %0, %1 \n"
5706+ " beqzl %0, 1b \n"
5707+#ifdef CONFIG_PAX_REFCOUNT
5708+ "3: \n"
5709+ _ASM_EXTABLE(2b, 3b)
5710+#endif
5711+ " .set mips0 \n"
5712+ : "=&r" (temp), "+m" (v->counter)
5713+ : "Ir" (i));
5714+ } else if (kernel_uses_llsc) {
5715+ __asm__ __volatile__(
5716+ " .set mips3 \n"
5717+ "1: ll %0, %1 # atomic64_sub \n"
5718+#ifdef CONFIG_PAX_REFCOUNT
5719+ /* Exception on overflow. */
5720+ "2: sub %0, %2 \n"
5721+#else
5722+ " subu %0, %2 \n"
5723+#endif
5724+ " sc %0, %1 \n"
5725+ " beqz %0, 1b \n"
5726+#ifdef CONFIG_PAX_REFCOUNT
5727+ "3: \n"
5728+ _ASM_EXTABLE(2b, 3b)
5729+#endif
5730+ " .set mips0 \n"
5731+ : "=&r" (temp), "+m" (v->counter)
5732+ : "Ir" (i));
5733+ } else {
5734+ unsigned long flags;
5735+
5736+ raw_local_irq_save(flags);
5737+ __asm__ __volatile__(
5738+#ifdef CONFIG_PAX_REFCOUNT
5739+ /* Exception on overflow. */
5740+ "1: sub %0, %1 \n"
5741+ "2: \n"
5742+ _ASM_EXTABLE(1b, 2b)
5743+#else
5744+ " subu %0, %1 \n"
5745+#endif
5746+ : "+r" (v->counter) : "Ir" (i));
5747+ raw_local_irq_restore(flags);
5748+ }
5749+}
5750+
5751+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5752 {
5753 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5754 int temp;
5755@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5756 /*
5757 * Same as above, but return the result value
5758 */
5759-static __inline__ int atomic_add_return(int i, atomic_t * v)
5760+static __inline__ int atomic_add_return(int i, atomic_t *v)
5761+{
5762+ int result;
5763+ int temp;
5764+
5765+ smp_mb__before_llsc();
5766+
5767+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5768+ __asm__ __volatile__(
5769+ " .set mips3 \n"
5770+ "1: ll %1, %2 # atomic_add_return \n"
5771+#ifdef CONFIG_PAX_REFCOUNT
5772+ "2: add %0, %1, %3 \n"
5773+#else
5774+ " addu %0, %1, %3 \n"
5775+#endif
5776+ " sc %0, %2 \n"
5777+ " beqzl %0, 1b \n"
5778+#ifdef CONFIG_PAX_REFCOUNT
5779+ " b 4f \n"
5780+ " .set noreorder \n"
5781+ "3: b 5f \n"
5782+ " move %0, %1 \n"
5783+ " .set reorder \n"
5784+ _ASM_EXTABLE(2b, 3b)
5785+#endif
5786+ "4: addu %0, %1, %3 \n"
5787+#ifdef CONFIG_PAX_REFCOUNT
5788+ "5: \n"
5789+#endif
5790+ " .set mips0 \n"
5791+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5792+ : "Ir" (i));
5793+ } else if (kernel_uses_llsc) {
5794+ __asm__ __volatile__(
5795+ " .set mips3 \n"
5796+ "1: ll %1, %2 # atomic_add_return \n"
5797+#ifdef CONFIG_PAX_REFCOUNT
5798+ "2: add %0, %1, %3 \n"
5799+#else
5800+ " addu %0, %1, %3 \n"
5801+#endif
5802+ " sc %0, %2 \n"
5803+ " bnez %0, 4f \n"
5804+ " b 1b \n"
5805+#ifdef CONFIG_PAX_REFCOUNT
5806+ " .set noreorder \n"
5807+ "3: b 5f \n"
5808+ " move %0, %1 \n"
5809+ " .set reorder \n"
5810+ _ASM_EXTABLE(2b, 3b)
5811+#endif
5812+ "4: addu %0, %1, %3 \n"
5813+#ifdef CONFIG_PAX_REFCOUNT
5814+ "5: \n"
5815+#endif
5816+ " .set mips0 \n"
5817+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5818+ : "Ir" (i));
5819+ } else {
5820+ unsigned long flags;
5821+
5822+ raw_local_irq_save(flags);
5823+ __asm__ __volatile__(
5824+ " lw %0, %1 \n"
5825+#ifdef CONFIG_PAX_REFCOUNT
5826+ /* Exception on overflow. */
5827+ "1: add %0, %2 \n"
5828+#else
5829+ " addu %0, %2 \n"
5830+#endif
5831+ " sw %0, %1 \n"
5832+#ifdef CONFIG_PAX_REFCOUNT
5833+ /* Note: Dest reg is not modified on overflow */
5834+ "2: \n"
5835+ _ASM_EXTABLE(1b, 2b)
5836+#endif
5837+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5838+ raw_local_irq_restore(flags);
5839+ }
5840+
5841+ smp_llsc_mb();
5842+
5843+ return result;
5844+}
5845+
5846+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5847 {
5848 int result;
5849
5850@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5851 return result;
5852 }
5853
5854-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5855+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5856+{
5857+ int result;
5858+ int temp;
5859+
5860+ smp_mb__before_llsc();
5861+
5862+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5863+ __asm__ __volatile__(
5864+ " .set mips3 \n"
5865+ "1: ll %1, %2 # atomic_sub_return \n"
5866+#ifdef CONFIG_PAX_REFCOUNT
5867+ "2: sub %0, %1, %3 \n"
5868+#else
5869+ " subu %0, %1, %3 \n"
5870+#endif
5871+ " sc %0, %2 \n"
5872+ " beqzl %0, 1b \n"
5873+#ifdef CONFIG_PAX_REFCOUNT
5874+ " b 4f \n"
5875+ " .set noreorder \n"
5876+ "3: b 5f \n"
5877+ " move %0, %1 \n"
5878+ " .set reorder \n"
5879+ _ASM_EXTABLE(2b, 3b)
5880+#endif
5881+ "4: subu %0, %1, %3 \n"
5882+#ifdef CONFIG_PAX_REFCOUNT
5883+ "5: \n"
5884+#endif
5885+ " .set mips0 \n"
5886+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5887+ : "Ir" (i), "m" (v->counter)
5888+ : "memory");
5889+ } else if (kernel_uses_llsc) {
5890+ __asm__ __volatile__(
5891+ " .set mips3 \n"
5892+ "1: ll %1, %2 # atomic_sub_return \n"
5893+#ifdef CONFIG_PAX_REFCOUNT
5894+ "2: sub %0, %1, %3 \n"
5895+#else
5896+ " subu %0, %1, %3 \n"
5897+#endif
5898+ " sc %0, %2 \n"
5899+ " bnez %0, 4f \n"
5900+ " b 1b \n"
5901+#ifdef CONFIG_PAX_REFCOUNT
5902+ " .set noreorder \n"
5903+ "3: b 5f \n"
5904+ " move %0, %1 \n"
5905+ " .set reorder \n"
5906+ _ASM_EXTABLE(2b, 3b)
5907+#endif
5908+ "4: subu %0, %1, %3 \n"
5909+#ifdef CONFIG_PAX_REFCOUNT
5910+ "5: \n"
5911+#endif
5912+ " .set mips0 \n"
5913+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5914+ : "Ir" (i));
5915+ } else {
5916+ unsigned long flags;
5917+
5918+ raw_local_irq_save(flags);
5919+ __asm__ __volatile__(
5920+ " lw %0, %1 \n"
5921+#ifdef CONFIG_PAX_REFCOUNT
5922+ /* Exception on overflow. */
5923+ "1: sub %0, %2 \n"
5924+#else
5925+ " subu %0, %2 \n"
5926+#endif
5927+ " sw %0, %1 \n"
5928+#ifdef CONFIG_PAX_REFCOUNT
5929+ /* Note: Dest reg is not modified on overflow */
5930+ "2: \n"
5931+ _ASM_EXTABLE(1b, 2b)
5932+#endif
5933+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5934+ raw_local_irq_restore(flags);
5935+ }
5936+
5937+ smp_llsc_mb();
5938+
5939+ return result;
5940+}
5941+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5942 {
5943 int result;
5944
5945@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5946 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5947 * The function returns the old value of @v minus @i.
5948 */
5949-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5950+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5951 {
5952 int result;
5953
5954@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5955 return result;
5956 }
5957
5958-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5959-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5960+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5961+{
5962+ return cmpxchg(&v->counter, old, new);
5963+}
5964+
5965+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5966+ int new)
5967+{
5968+ return cmpxchg(&(v->counter), old, new);
5969+}
5970+
5971+static inline int atomic_xchg(atomic_t *v, int new)
5972+{
5973+ return xchg(&v->counter, new);
5974+}
5975+
5976+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5977+{
5978+ return xchg(&(v->counter), new);
5979+}
5980
5981 /**
5982 * __atomic_add_unless - add unless the number is a given value
5983@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5984
5985 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5986 #define atomic_inc_return(v) atomic_add_return(1, (v))
5987+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5988+{
5989+ return atomic_add_return_unchecked(1, v);
5990+}
5991
5992 /*
5993 * atomic_sub_and_test - subtract value from variable and test result
5994@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5995 * other cases.
5996 */
5997 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5998+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5999+{
6000+ return atomic_add_return_unchecked(1, v) == 0;
6001+}
6002
6003 /*
6004 * atomic_dec_and_test - decrement by 1 and test
6005@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6006 * Atomically increments @v by 1.
6007 */
6008 #define atomic_inc(v) atomic_add(1, (v))
6009+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6010+{
6011+ atomic_add_unchecked(1, v);
6012+}
6013
6014 /*
6015 * atomic_dec - decrement and test
6016@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6017 * Atomically decrements @v by 1.
6018 */
6019 #define atomic_dec(v) atomic_sub(1, (v))
6020+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6021+{
6022+ atomic_sub_unchecked(1, v);
6023+}
6024
6025 /*
6026 * atomic_add_negative - add and test if negative
6027@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6028 * @v: pointer of type atomic64_t
6029 *
6030 */
6031-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6032+static inline long atomic64_read(const atomic64_t *v)
6033+{
6034+ return (*(volatile const long *) &v->counter);
6035+}
6036+
6037+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6038+{
6039+ return (*(volatile const long *) &v->counter);
6040+}
6041
6042 /*
6043 * atomic64_set - set atomic variable
6044 * @v: pointer of type atomic64_t
6045 * @i: required value
6046 */
6047-#define atomic64_set(v, i) ((v)->counter = (i))
6048+static inline void atomic64_set(atomic64_t *v, long i)
6049+{
6050+ v->counter = i;
6051+}
6052+
6053+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6054+{
6055+ v->counter = i;
6056+}
6057
6058 /*
6059 * atomic64_add - add integer to atomic variable
6060@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6061 *
6062 * Atomically adds @i to @v.
6063 */
6064-static __inline__ void atomic64_add(long i, atomic64_t * v)
6065+static __inline__ void atomic64_add(long i, atomic64_t *v)
6066+{
6067+ long temp;
6068+
6069+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6070+ __asm__ __volatile__(
6071+ " .set mips3 \n"
6072+ "1: lld %0, %1 # atomic64_add \n"
6073+#ifdef CONFIG_PAX_REFCOUNT
6074+ /* Exception on overflow. */
6075+ "2: dadd %0, %2 \n"
6076+#else
6077+ " daddu %0, %2 \n"
6078+#endif
6079+ " scd %0, %1 \n"
6080+ " beqzl %0, 1b \n"
6081+#ifdef CONFIG_PAX_REFCOUNT
6082+ "3: \n"
6083+ _ASM_EXTABLE(2b, 3b)
6084+#endif
6085+ " .set mips0 \n"
6086+ : "=&r" (temp), "+m" (v->counter)
6087+ : "Ir" (i));
6088+ } else if (kernel_uses_llsc) {
6089+ __asm__ __volatile__(
6090+ " .set mips3 \n"
6091+ "1: lld %0, %1 # atomic64_add \n"
6092+#ifdef CONFIG_PAX_REFCOUNT
6093+ /* Exception on overflow. */
6094+ "2: dadd %0, %2 \n"
6095+#else
6096+ " daddu %0, %2 \n"
6097+#endif
6098+ " scd %0, %1 \n"
6099+ " beqz %0, 1b \n"
6100+#ifdef CONFIG_PAX_REFCOUNT
6101+ "3: \n"
6102+ _ASM_EXTABLE(2b, 3b)
6103+#endif
6104+ " .set mips0 \n"
6105+ : "=&r" (temp), "+m" (v->counter)
6106+ : "Ir" (i));
6107+ } else {
6108+ unsigned long flags;
6109+
6110+ raw_local_irq_save(flags);
6111+ __asm__ __volatile__(
6112+#ifdef CONFIG_PAX_REFCOUNT
6113+ /* Exception on overflow. */
6114+ "1: dadd %0, %1 \n"
6115+ "2: \n"
6116+ _ASM_EXTABLE(1b, 2b)
6117+#else
6118+ " daddu %0, %1 \n"
6119+#endif
6120+ : "+r" (v->counter) : "Ir" (i));
6121+ raw_local_irq_restore(flags);
6122+ }
6123+}
6124+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6125 {
6126 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6127 long temp;
6128@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6129 *
6130 * Atomically subtracts @i from @v.
6131 */
6132-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6133+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6134+{
6135+ long temp;
6136+
6137+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6138+ __asm__ __volatile__(
6139+ " .set mips3 \n"
6140+ "1: lld %0, %1 # atomic64_sub \n"
6141+#ifdef CONFIG_PAX_REFCOUNT
6142+ /* Exception on overflow. */
6143+ "2: dsub %0, %2 \n"
6144+#else
6145+ " dsubu %0, %2 \n"
6146+#endif
6147+ " scd %0, %1 \n"
6148+ " beqzl %0, 1b \n"
6149+#ifdef CONFIG_PAX_REFCOUNT
6150+ "3: \n"
6151+ _ASM_EXTABLE(2b, 3b)
6152+#endif
6153+ " .set mips0 \n"
6154+ : "=&r" (temp), "+m" (v->counter)
6155+ : "Ir" (i));
6156+ } else if (kernel_uses_llsc) {
6157+ __asm__ __volatile__(
6158+ " .set mips3 \n"
6159+ "1: lld %0, %1 # atomic64_sub \n"
6160+#ifdef CONFIG_PAX_REFCOUNT
6161+ /* Exception on overflow. */
6162+ "2: dsub %0, %2 \n"
6163+#else
6164+ " dsubu %0, %2 \n"
6165+#endif
6166+ " scd %0, %1 \n"
6167+ " beqz %0, 1b \n"
6168+#ifdef CONFIG_PAX_REFCOUNT
6169+ "3: \n"
6170+ _ASM_EXTABLE(2b, 3b)
6171+#endif
6172+ " .set mips0 \n"
6173+ : "=&r" (temp), "+m" (v->counter)
6174+ : "Ir" (i));
6175+ } else {
6176+ unsigned long flags;
6177+
6178+ raw_local_irq_save(flags);
6179+ __asm__ __volatile__(
6180+#ifdef CONFIG_PAX_REFCOUNT
6181+ /* Exception on overflow. */
6182+ "1: dsub %0, %1 \n"
6183+ "2: \n"
6184+ _ASM_EXTABLE(1b, 2b)
6185+#else
6186+ " dsubu %0, %1 \n"
6187+#endif
6188+ : "+r" (v->counter) : "Ir" (i));
6189+ raw_local_irq_restore(flags);
6190+ }
6191+}
6192+
6193+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6194 {
6195 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6196 long temp;
6197@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6198 /*
6199 * Same as above, but return the result value
6200 */
6201-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6202+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6203+{
6204+ long result;
6205+ long temp;
6206+
6207+ smp_mb__before_llsc();
6208+
6209+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6210+ __asm__ __volatile__(
6211+ " .set mips3 \n"
6212+ "1: lld %1, %2 # atomic64_add_return \n"
6213+#ifdef CONFIG_PAX_REFCOUNT
6214+ "2: dadd %0, %1, %3 \n"
6215+#else
6216+ " daddu %0, %1, %3 \n"
6217+#endif
6218+ " scd %0, %2 \n"
6219+ " beqzl %0, 1b \n"
6220+#ifdef CONFIG_PAX_REFCOUNT
6221+ " b 4f \n"
6222+ " .set noreorder \n"
6223+ "3: b 5f \n"
6224+ " move %0, %1 \n"
6225+ " .set reorder \n"
6226+ _ASM_EXTABLE(2b, 3b)
6227+#endif
6228+ "4: daddu %0, %1, %3 \n"
6229+#ifdef CONFIG_PAX_REFCOUNT
6230+ "5: \n"
6231+#endif
6232+ " .set mips0 \n"
6233+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6234+ : "Ir" (i));
6235+ } else if (kernel_uses_llsc) {
6236+ __asm__ __volatile__(
6237+ " .set mips3 \n"
6238+ "1: lld %1, %2 # atomic64_add_return \n"
6239+#ifdef CONFIG_PAX_REFCOUNT
6240+ "2: dadd %0, %1, %3 \n"
6241+#else
6242+ " daddu %0, %1, %3 \n"
6243+#endif
6244+ " scd %0, %2 \n"
6245+ " bnez %0, 4f \n"
6246+ " b 1b \n"
6247+#ifdef CONFIG_PAX_REFCOUNT
6248+ " .set noreorder \n"
6249+ "3: b 5f \n"
6250+ " move %0, %1 \n"
6251+ " .set reorder \n"
6252+ _ASM_EXTABLE(2b, 3b)
6253+#endif
6254+ "4: daddu %0, %1, %3 \n"
6255+#ifdef CONFIG_PAX_REFCOUNT
6256+ "5: \n"
6257+#endif
6258+ " .set mips0 \n"
6259+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6260+ : "Ir" (i), "m" (v->counter)
6261+ : "memory");
6262+ } else {
6263+ unsigned long flags;
6264+
6265+ raw_local_irq_save(flags);
6266+ __asm__ __volatile__(
6267+ " ld %0, %1 \n"
6268+#ifdef CONFIG_PAX_REFCOUNT
6269+ /* Exception on overflow. */
6270+ "1: dadd %0, %2 \n"
6271+#else
6272+ " daddu %0, %2 \n"
6273+#endif
6274+ " sd %0, %1 \n"
6275+#ifdef CONFIG_PAX_REFCOUNT
6276+ /* Note: Dest reg is not modified on overflow */
6277+ "2: \n"
6278+ _ASM_EXTABLE(1b, 2b)
6279+#endif
6280+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6281+ raw_local_irq_restore(flags);
6282+ }
6283+
6284+ smp_llsc_mb();
6285+
6286+ return result;
6287+}
6288+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6289 {
6290 long result;
6291
6292@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6293 return result;
6294 }
6295
6296-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6297+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6298+{
6299+ long result;
6300+ long temp;
6301+
6302+ smp_mb__before_llsc();
6303+
6304+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6305+ long temp;
6306+
6307+ __asm__ __volatile__(
6308+ " .set mips3 \n"
6309+ "1: lld %1, %2 # atomic64_sub_return \n"
6310+#ifdef CONFIG_PAX_REFCOUNT
6311+ "2: dsub %0, %1, %3 \n"
6312+#else
6313+ " dsubu %0, %1, %3 \n"
6314+#endif
6315+ " scd %0, %2 \n"
6316+ " beqzl %0, 1b \n"
6317+#ifdef CONFIG_PAX_REFCOUNT
6318+ " b 4f \n"
6319+ " .set noreorder \n"
6320+ "3: b 5f \n"
6321+ " move %0, %1 \n"
6322+ " .set reorder \n"
6323+ _ASM_EXTABLE(2b, 3b)
6324+#endif
6325+ "4: dsubu %0, %1, %3 \n"
6326+#ifdef CONFIG_PAX_REFCOUNT
6327+ "5: \n"
6328+#endif
6329+ " .set mips0 \n"
6330+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6331+ : "Ir" (i), "m" (v->counter)
6332+ : "memory");
6333+ } else if (kernel_uses_llsc) {
6334+ __asm__ __volatile__(
6335+ " .set mips3 \n"
6336+ "1: lld %1, %2 # atomic64_sub_return \n"
6337+#ifdef CONFIG_PAX_REFCOUNT
6338+ "2: dsub %0, %1, %3 \n"
6339+#else
6340+ " dsubu %0, %1, %3 \n"
6341+#endif
6342+ " scd %0, %2 \n"
6343+ " bnez %0, 4f \n"
6344+ " b 1b \n"
6345+#ifdef CONFIG_PAX_REFCOUNT
6346+ " .set noreorder \n"
6347+ "3: b 5f \n"
6348+ " move %0, %1 \n"
6349+ " .set reorder \n"
6350+ _ASM_EXTABLE(2b, 3b)
6351+#endif
6352+ "4: dsubu %0, %1, %3 \n"
6353+#ifdef CONFIG_PAX_REFCOUNT
6354+ "5: \n"
6355+#endif
6356+ " .set mips0 \n"
6357+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6358+ : "Ir" (i), "m" (v->counter)
6359+ : "memory");
6360+ } else {
6361+ unsigned long flags;
6362+
6363+ raw_local_irq_save(flags);
6364+ __asm__ __volatile__(
6365+ " ld %0, %1 \n"
6366+#ifdef CONFIG_PAX_REFCOUNT
6367+ /* Exception on overflow. */
6368+ "1: dsub %0, %2 \n"
6369+#else
6370+ " dsubu %0, %2 \n"
6371+#endif
6372+ " sd %0, %1 \n"
6373+#ifdef CONFIG_PAX_REFCOUNT
6374+ /* Note: Dest reg is not modified on overflow */
6375+ "2: \n"
6376+ _ASM_EXTABLE(1b, 2b)
6377+#endif
6378+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6379+ raw_local_irq_restore(flags);
6380+ }
6381+
6382+ smp_llsc_mb();
6383+
6384+ return result;
6385+}
6386+
6387+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6388 {
6389 long result;
6390
6391@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6392 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6393 * The function returns the old value of @v minus @i.
6394 */
6395-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6396+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6397 {
6398 long result;
6399
6400@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6401 return result;
6402 }
6403
6404-#define atomic64_cmpxchg(v, o, n) \
6405- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6406-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6407+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6408+{
6409+ return cmpxchg(&v->counter, old, new);
6410+}
6411+
6412+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6413+ long new)
6414+{
6415+ return cmpxchg(&(v->counter), old, new);
6416+}
6417+
6418+static inline long atomic64_xchg(atomic64_t *v, long new)
6419+{
6420+ return xchg(&v->counter, new);
6421+}
6422+
6423+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6424+{
6425+ return xchg(&(v->counter), new);
6426+}
6427
6428 /**
6429 * atomic64_add_unless - add unless the number is a given value
6430@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6431
6432 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6433 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6434+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6435
6436 /*
6437 * atomic64_sub_and_test - subtract value from variable and test result
6438@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6439 * other cases.
6440 */
6441 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6442+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6443
6444 /*
6445 * atomic64_dec_and_test - decrement by 1 and test
6446@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6447 * Atomically increments @v by 1.
6448 */
6449 #define atomic64_inc(v) atomic64_add(1, (v))
6450+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6451
6452 /*
6453 * atomic64_dec - decrement and test
6454@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6455 * Atomically decrements @v by 1.
6456 */
6457 #define atomic64_dec(v) atomic64_sub(1, (v))
6458+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6459
6460 /*
6461 * atomic64_add_negative - add and test if negative
6462diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6463index b4db69f..8f3b093 100644
6464--- a/arch/mips/include/asm/cache.h
6465+++ b/arch/mips/include/asm/cache.h
6466@@ -9,10 +9,11 @@
6467 #ifndef _ASM_CACHE_H
6468 #define _ASM_CACHE_H
6469
6470+#include <linux/const.h>
6471 #include <kmalloc.h>
6472
6473 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6474-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6475+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6476
6477 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6478 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6479diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6480index d414405..6bb4ba2 100644
6481--- a/arch/mips/include/asm/elf.h
6482+++ b/arch/mips/include/asm/elf.h
6483@@ -398,13 +398,16 @@ extern const char *__elf_platform;
6484 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6485 #endif
6486
6487+#ifdef CONFIG_PAX_ASLR
6488+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6489+
6490+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6491+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6492+#endif
6493+
6494 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6495 struct linux_binprm;
6496 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6497 int uses_interp);
6498
6499-struct mm_struct;
6500-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6501-#define arch_randomize_brk arch_randomize_brk
6502-
6503 #endif /* _ASM_ELF_H */
6504diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6505index c1f6afa..38cc6e9 100644
6506--- a/arch/mips/include/asm/exec.h
6507+++ b/arch/mips/include/asm/exec.h
6508@@ -12,6 +12,6 @@
6509 #ifndef _ASM_EXEC_H
6510 #define _ASM_EXEC_H
6511
6512-extern unsigned long arch_align_stack(unsigned long sp);
6513+#define arch_align_stack(x) ((x) & ~0xfUL)
6514
6515 #endif /* _ASM_EXEC_H */
6516diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6517index 9e8ef59..1139d6b 100644
6518--- a/arch/mips/include/asm/hw_irq.h
6519+++ b/arch/mips/include/asm/hw_irq.h
6520@@ -10,7 +10,7 @@
6521
6522 #include <linux/atomic.h>
6523
6524-extern atomic_t irq_err_count;
6525+extern atomic_unchecked_t irq_err_count;
6526
6527 /*
6528 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6529diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6530index d44622c..64990d2 100644
6531--- a/arch/mips/include/asm/local.h
6532+++ b/arch/mips/include/asm/local.h
6533@@ -12,15 +12,25 @@ typedef struct
6534 atomic_long_t a;
6535 } local_t;
6536
6537+typedef struct {
6538+ atomic_long_unchecked_t a;
6539+} local_unchecked_t;
6540+
6541 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6542
6543 #define local_read(l) atomic_long_read(&(l)->a)
6544+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6545 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6546+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6547
6548 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6549+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6550 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6551+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6552 #define local_inc(l) atomic_long_inc(&(l)->a)
6553+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6554 #define local_dec(l) atomic_long_dec(&(l)->a)
6555+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6556
6557 /*
6558 * Same as above, but return the result value
6559@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6560 return result;
6561 }
6562
6563+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6564+{
6565+ unsigned long result;
6566+
6567+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6568+ unsigned long temp;
6569+
6570+ __asm__ __volatile__(
6571+ " .set mips3 \n"
6572+ "1:" __LL "%1, %2 # local_add_return \n"
6573+ " addu %0, %1, %3 \n"
6574+ __SC "%0, %2 \n"
6575+ " beqzl %0, 1b \n"
6576+ " addu %0, %1, %3 \n"
6577+ " .set mips0 \n"
6578+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6579+ : "Ir" (i), "m" (l->a.counter)
6580+ : "memory");
6581+ } else if (kernel_uses_llsc) {
6582+ unsigned long temp;
6583+
6584+ __asm__ __volatile__(
6585+ " .set mips3 \n"
6586+ "1:" __LL "%1, %2 # local_add_return \n"
6587+ " addu %0, %1, %3 \n"
6588+ __SC "%0, %2 \n"
6589+ " beqz %0, 1b \n"
6590+ " addu %0, %1, %3 \n"
6591+ " .set mips0 \n"
6592+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6593+ : "Ir" (i), "m" (l->a.counter)
6594+ : "memory");
6595+ } else {
6596+ unsigned long flags;
6597+
6598+ local_irq_save(flags);
6599+ result = l->a.counter;
6600+ result += i;
6601+ l->a.counter = result;
6602+ local_irq_restore(flags);
6603+ }
6604+
6605+ return result;
6606+}
6607+
6608 static __inline__ long local_sub_return(long i, local_t * l)
6609 {
6610 unsigned long result;
6611@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6612
6613 #define local_cmpxchg(l, o, n) \
6614 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6615+#define local_cmpxchg_unchecked(l, o, n) \
6616+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6617 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6618
6619 /**
6620diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6621index 5e08bcc..cfedefc 100644
6622--- a/arch/mips/include/asm/page.h
6623+++ b/arch/mips/include/asm/page.h
6624@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6625 #ifdef CONFIG_CPU_MIPS32
6626 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6627 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6628- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6629+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6630 #else
6631 typedef struct { unsigned long long pte; } pte_t;
6632 #define pte_val(x) ((x).pte)
6633diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6634index b336037..5b874cc 100644
6635--- a/arch/mips/include/asm/pgalloc.h
6636+++ b/arch/mips/include/asm/pgalloc.h
6637@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6638 {
6639 set_pud(pud, __pud((unsigned long)pmd));
6640 }
6641+
6642+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6643+{
6644+ pud_populate(mm, pud, pmd);
6645+}
6646 #endif
6647
6648 /*
6649diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6650index 008324d..f67c239 100644
6651--- a/arch/mips/include/asm/pgtable.h
6652+++ b/arch/mips/include/asm/pgtable.h
6653@@ -20,6 +20,9 @@
6654 #include <asm/io.h>
6655 #include <asm/pgtable-bits.h>
6656
6657+#define ktla_ktva(addr) (addr)
6658+#define ktva_ktla(addr) (addr)
6659+
6660 struct mm_struct;
6661 struct vm_area_struct;
6662
6663diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6664index 25da651..ae2a259 100644
6665--- a/arch/mips/include/asm/smtc_proc.h
6666+++ b/arch/mips/include/asm/smtc_proc.h
6667@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6668
6669 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6670
6671-extern atomic_t smtc_fpu_recoveries;
6672+extern atomic_unchecked_t smtc_fpu_recoveries;
6673
6674 #endif /* __ASM_SMTC_PROC_H */
6675diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6676index 24846f9..61c49f0 100644
6677--- a/arch/mips/include/asm/thread_info.h
6678+++ b/arch/mips/include/asm/thread_info.h
6679@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6680 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6681 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6682 #define TIF_32BIT_FPREGS 27 /* 32-bit floating point registers */
6683+/* li takes a 32bit immediate */
6684+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6685 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6686
6687 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6688@@ -134,13 +136,14 @@ static inline struct thread_info *current_thread_info(void)
6689 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6690 #define _TIF_32BIT_FPREGS (1<<TIF_32BIT_FPREGS)
6691 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6692+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6693
6694 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6695- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6696+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6697
6698 /* work to do in syscall_trace_leave() */
6699 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6700- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6701+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6702
6703 /* work to do on interrupt/exception return */
6704 #define _TIF_WORK_MASK \
6705@@ -148,7 +151,7 @@ static inline struct thread_info *current_thread_info(void)
6706 /* work to do on any return to u-space */
6707 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6708 _TIF_WORK_SYSCALL_EXIT | \
6709- _TIF_SYSCALL_TRACEPOINT)
6710+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6711
6712 /*
6713 * We stash processor id into a COP0 register to retrieve it fast
6714diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6715index f3fa375..3af6637 100644
6716--- a/arch/mips/include/asm/uaccess.h
6717+++ b/arch/mips/include/asm/uaccess.h
6718@@ -128,6 +128,7 @@ extern u64 __ua_limit;
6719 __ok == 0; \
6720 })
6721
6722+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6723 #define access_ok(type, addr, size) \
6724 likely(__access_ok((addr), (size), __access_mask))
6725
6726diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6727index 1188e00..41cf144 100644
6728--- a/arch/mips/kernel/binfmt_elfn32.c
6729+++ b/arch/mips/kernel/binfmt_elfn32.c
6730@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6731 #undef ELF_ET_DYN_BASE
6732 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6733
6734+#ifdef CONFIG_PAX_ASLR
6735+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6736+
6737+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6738+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6739+#endif
6740+
6741 #include <asm/processor.h>
6742 #include <linux/module.h>
6743 #include <linux/elfcore.h>
6744diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6745index 7faf5f2..f3d3cf4 100644
6746--- a/arch/mips/kernel/binfmt_elfo32.c
6747+++ b/arch/mips/kernel/binfmt_elfo32.c
6748@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6749 #undef ELF_ET_DYN_BASE
6750 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6751
6752+#ifdef CONFIG_PAX_ASLR
6753+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6754+
6755+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6756+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6757+#endif
6758+
6759 #include <asm/processor.h>
6760
6761 /*
6762diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6763index 2b91fe8..fe4f6b4 100644
6764--- a/arch/mips/kernel/i8259.c
6765+++ b/arch/mips/kernel/i8259.c
6766@@ -205,7 +205,7 @@ spurious_8259A_irq:
6767 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6768 spurious_irq_mask |= irqmask;
6769 }
6770- atomic_inc(&irq_err_count);
6771+ atomic_inc_unchecked(&irq_err_count);
6772 /*
6773 * Theoretically we do not have to handle this IRQ,
6774 * but in Linux this does not cause problems and is
6775diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6776index 44a1f79..2bd6aa3 100644
6777--- a/arch/mips/kernel/irq-gt641xx.c
6778+++ b/arch/mips/kernel/irq-gt641xx.c
6779@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6780 }
6781 }
6782
6783- atomic_inc(&irq_err_count);
6784+ atomic_inc_unchecked(&irq_err_count);
6785 }
6786
6787 void __init gt641xx_irq_init(void)
6788diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6789index d1fea7a..2e591b0 100644
6790--- a/arch/mips/kernel/irq.c
6791+++ b/arch/mips/kernel/irq.c
6792@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6793 printk("unexpected IRQ # %d\n", irq);
6794 }
6795
6796-atomic_t irq_err_count;
6797+atomic_unchecked_t irq_err_count;
6798
6799 int arch_show_interrupts(struct seq_file *p, int prec)
6800 {
6801- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6802+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6803 return 0;
6804 }
6805
6806 asmlinkage void spurious_interrupt(void)
6807 {
6808- atomic_inc(&irq_err_count);
6809+ atomic_inc_unchecked(&irq_err_count);
6810 }
6811
6812 void __init init_IRQ(void)
6813@@ -110,7 +110,10 @@ void __init init_IRQ(void)
6814 #endif
6815 }
6816
6817+
6818 #ifdef DEBUG_STACKOVERFLOW
6819+extern void gr_handle_kernel_exploit(void);
6820+
6821 static inline void check_stack_overflow(void)
6822 {
6823 unsigned long sp;
6824@@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6825 printk("do_IRQ: stack overflow: %ld\n",
6826 sp - sizeof(struct thread_info));
6827 dump_stack();
6828+ gr_handle_kernel_exploit();
6829 }
6830 }
6831 #else
6832diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6833index 6ae540e..b7396dc 100644
6834--- a/arch/mips/kernel/process.c
6835+++ b/arch/mips/kernel/process.c
6836@@ -562,15 +562,3 @@ unsigned long get_wchan(struct task_struct *task)
6837 out:
6838 return pc;
6839 }
6840-
6841-/*
6842- * Don't forget that the stack pointer must be aligned on a 8 bytes
6843- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6844- */
6845-unsigned long arch_align_stack(unsigned long sp)
6846-{
6847- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6848- sp -= get_random_int() & ~PAGE_MASK;
6849-
6850- return sp & ALMASK;
6851-}
6852diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6853index 7da9b76..21578be 100644
6854--- a/arch/mips/kernel/ptrace.c
6855+++ b/arch/mips/kernel/ptrace.c
6856@@ -658,6 +658,10 @@ long arch_ptrace(struct task_struct *child, long request,
6857 return ret;
6858 }
6859
6860+#ifdef CONFIG_GRKERNSEC_SETXID
6861+extern void gr_delayed_cred_worker(void);
6862+#endif
6863+
6864 /*
6865 * Notification of system call entry/exit
6866 * - triggered by current->work.syscall_trace
6867@@ -674,6 +678,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6868 tracehook_report_syscall_entry(regs))
6869 ret = -1;
6870
6871+#ifdef CONFIG_GRKERNSEC_SETXID
6872+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6873+ gr_delayed_cred_worker();
6874+#endif
6875+
6876 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6877 trace_sys_enter(regs, regs->regs[2]);
6878
6879diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6880index 07fc524..b9d7f28 100644
6881--- a/arch/mips/kernel/reset.c
6882+++ b/arch/mips/kernel/reset.c
6883@@ -13,6 +13,7 @@
6884 #include <linux/reboot.h>
6885
6886 #include <asm/reboot.h>
6887+#include <asm/bug.h>
6888
6889 /*
6890 * Urgs ... Too many MIPS machines to handle this in a generic way.
6891@@ -29,16 +30,19 @@ void machine_restart(char *command)
6892 {
6893 if (_machine_restart)
6894 _machine_restart(command);
6895+ BUG();
6896 }
6897
6898 void machine_halt(void)
6899 {
6900 if (_machine_halt)
6901 _machine_halt();
6902+ BUG();
6903 }
6904
6905 void machine_power_off(void)
6906 {
6907 if (pm_power_off)
6908 pm_power_off();
6909+ BUG();
6910 }
6911diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6912index c10aa84..9ec2e60 100644
6913--- a/arch/mips/kernel/smtc-proc.c
6914+++ b/arch/mips/kernel/smtc-proc.c
6915@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6916
6917 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6918
6919-atomic_t smtc_fpu_recoveries;
6920+atomic_unchecked_t smtc_fpu_recoveries;
6921
6922 static int smtc_proc_show(struct seq_file *m, void *v)
6923 {
6924@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6925 for(i = 0; i < NR_CPUS; i++)
6926 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6927 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6928- atomic_read(&smtc_fpu_recoveries));
6929+ atomic_read_unchecked(&smtc_fpu_recoveries));
6930 return 0;
6931 }
6932
6933@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6934 smtc_cpu_stats[i].selfipis = 0;
6935 }
6936
6937- atomic_set(&smtc_fpu_recoveries, 0);
6938+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6939
6940 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6941 }
6942diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6943index dfc1b91..11a2c07 100644
6944--- a/arch/mips/kernel/smtc.c
6945+++ b/arch/mips/kernel/smtc.c
6946@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6947 }
6948 smtc_ipi_qdump();
6949 printk("%d Recoveries of \"stolen\" FPU\n",
6950- atomic_read(&smtc_fpu_recoveries));
6951+ atomic_read_unchecked(&smtc_fpu_recoveries));
6952 }
6953
6954
6955diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6956index c24ad5f..9983ab2 100644
6957--- a/arch/mips/kernel/sync-r4k.c
6958+++ b/arch/mips/kernel/sync-r4k.c
6959@@ -20,8 +20,8 @@
6960 #include <asm/mipsregs.h>
6961
6962 static atomic_t count_start_flag = ATOMIC_INIT(0);
6963-static atomic_t count_count_start = ATOMIC_INIT(0);
6964-static atomic_t count_count_stop = ATOMIC_INIT(0);
6965+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6966+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6967 static atomic_t count_reference = ATOMIC_INIT(0);
6968
6969 #define COUNTON 100
6970@@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
6971
6972 for (i = 0; i < NR_LOOPS; i++) {
6973 /* slaves loop on '!= 2' */
6974- while (atomic_read(&count_count_start) != 1)
6975+ while (atomic_read_unchecked(&count_count_start) != 1)
6976 mb();
6977- atomic_set(&count_count_stop, 0);
6978+ atomic_set_unchecked(&count_count_stop, 0);
6979 smp_wmb();
6980
6981 /* this lets the slaves write their count register */
6982- atomic_inc(&count_count_start);
6983+ atomic_inc_unchecked(&count_count_start);
6984
6985 /*
6986 * Everyone initialises count in the last loop:
6987@@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
6988 /*
6989 * Wait for all slaves to leave the synchronization point:
6990 */
6991- while (atomic_read(&count_count_stop) != 1)
6992+ while (atomic_read_unchecked(&count_count_stop) != 1)
6993 mb();
6994- atomic_set(&count_count_start, 0);
6995+ atomic_set_unchecked(&count_count_start, 0);
6996 smp_wmb();
6997- atomic_inc(&count_count_stop);
6998+ atomic_inc_unchecked(&count_count_stop);
6999 }
7000 /* Arrange for an interrupt in a short while */
7001 write_c0_compare(read_c0_count() + COUNTON);
7002@@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7003 initcount = atomic_read(&count_reference);
7004
7005 for (i = 0; i < NR_LOOPS; i++) {
7006- atomic_inc(&count_count_start);
7007- while (atomic_read(&count_count_start) != 2)
7008+ atomic_inc_unchecked(&count_count_start);
7009+ while (atomic_read_unchecked(&count_count_start) != 2)
7010 mb();
7011
7012 /*
7013@@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7014 if (i == NR_LOOPS-1)
7015 write_c0_count(initcount);
7016
7017- atomic_inc(&count_count_stop);
7018- while (atomic_read(&count_count_stop) != 2)
7019+ atomic_inc_unchecked(&count_count_stop);
7020+ while (atomic_read_unchecked(&count_count_stop) != 2)
7021 mb();
7022 }
7023 /* Arrange for an interrupt in a short while */
7024diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7025index e0b4996..6b43ce7 100644
7026--- a/arch/mips/kernel/traps.c
7027+++ b/arch/mips/kernel/traps.c
7028@@ -691,7 +691,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7029 siginfo_t info;
7030
7031 prev_state = exception_enter();
7032- die_if_kernel("Integer overflow", regs);
7033+ if (unlikely(!user_mode(regs))) {
7034+
7035+#ifdef CONFIG_PAX_REFCOUNT
7036+ if (fixup_exception(regs)) {
7037+ pax_report_refcount_overflow(regs);
7038+ exception_exit(prev_state);
7039+ return;
7040+ }
7041+#endif
7042+
7043+ die("Integer overflow", regs);
7044+ }
7045
7046 info.si_code = FPE_INTOVF;
7047 info.si_signo = SIGFPE;
7048diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7049index becc42b..9e43d4b 100644
7050--- a/arch/mips/mm/fault.c
7051+++ b/arch/mips/mm/fault.c
7052@@ -28,6 +28,23 @@
7053 #include <asm/highmem.h> /* For VMALLOC_END */
7054 #include <linux/kdebug.h>
7055
7056+#ifdef CONFIG_PAX_PAGEEXEC
7057+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7058+{
7059+ unsigned long i;
7060+
7061+ printk(KERN_ERR "PAX: bytes at PC: ");
7062+ for (i = 0; i < 5; i++) {
7063+ unsigned int c;
7064+ if (get_user(c, (unsigned int *)pc+i))
7065+ printk(KERN_CONT "???????? ");
7066+ else
7067+ printk(KERN_CONT "%08x ", c);
7068+ }
7069+ printk("\n");
7070+}
7071+#endif
7072+
7073 /*
7074 * This routine handles page faults. It determines the address,
7075 * and the problem, and then passes it off to one of the appropriate
7076@@ -199,6 +216,14 @@ bad_area:
7077 bad_area_nosemaphore:
7078 /* User mode accesses just cause a SIGSEGV */
7079 if (user_mode(regs)) {
7080+
7081+#ifdef CONFIG_PAX_PAGEEXEC
7082+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7083+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7084+ do_group_exit(SIGKILL);
7085+ }
7086+#endif
7087+
7088 tsk->thread.cp0_badvaddr = address;
7089 tsk->thread.error_code = write;
7090 #if 0
7091diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7092index f1baadd..5472dca 100644
7093--- a/arch/mips/mm/mmap.c
7094+++ b/arch/mips/mm/mmap.c
7095@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7096 struct vm_area_struct *vma;
7097 unsigned long addr = addr0;
7098 int do_color_align;
7099+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7100 struct vm_unmapped_area_info info;
7101
7102 if (unlikely(len > TASK_SIZE))
7103@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7104 do_color_align = 1;
7105
7106 /* requesting a specific address */
7107+
7108+#ifdef CONFIG_PAX_RANDMMAP
7109+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7110+#endif
7111+
7112 if (addr) {
7113 if (do_color_align)
7114 addr = COLOUR_ALIGN(addr, pgoff);
7115@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7116 addr = PAGE_ALIGN(addr);
7117
7118 vma = find_vma(mm, addr);
7119- if (TASK_SIZE - len >= addr &&
7120- (!vma || addr + len <= vma->vm_start))
7121+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7122 return addr;
7123 }
7124
7125 info.length = len;
7126 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7127 info.align_offset = pgoff << PAGE_SHIFT;
7128+ info.threadstack_offset = offset;
7129
7130 if (dir == DOWN) {
7131 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7132@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7133 {
7134 unsigned long random_factor = 0UL;
7135
7136+#ifdef CONFIG_PAX_RANDMMAP
7137+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7138+#endif
7139+
7140 if (current->flags & PF_RANDOMIZE) {
7141 random_factor = get_random_int();
7142 random_factor = random_factor << PAGE_SHIFT;
7143@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7144
7145 if (mmap_is_legacy()) {
7146 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7147+
7148+#ifdef CONFIG_PAX_RANDMMAP
7149+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7150+ mm->mmap_base += mm->delta_mmap;
7151+#endif
7152+
7153 mm->get_unmapped_area = arch_get_unmapped_area;
7154 } else {
7155 mm->mmap_base = mmap_base(random_factor);
7156+
7157+#ifdef CONFIG_PAX_RANDMMAP
7158+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7159+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7160+#endif
7161+
7162 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7163 }
7164 }
7165
7166-static inline unsigned long brk_rnd(void)
7167-{
7168- unsigned long rnd = get_random_int();
7169-
7170- rnd = rnd << PAGE_SHIFT;
7171- /* 8MB for 32bit, 256MB for 64bit */
7172- if (TASK_IS_32BIT_ADDR)
7173- rnd = rnd & 0x7ffffful;
7174- else
7175- rnd = rnd & 0xffffffful;
7176-
7177- return rnd;
7178-}
7179-
7180-unsigned long arch_randomize_brk(struct mm_struct *mm)
7181-{
7182- unsigned long base = mm->brk;
7183- unsigned long ret;
7184-
7185- ret = PAGE_ALIGN(base + brk_rnd());
7186-
7187- if (ret < mm->brk)
7188- return mm->brk;
7189-
7190- return ret;
7191-}
7192-
7193 int __virt_addr_valid(const volatile void *kaddr)
7194 {
7195 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7196diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7197index 59cccd9..f39ac2f 100644
7198--- a/arch/mips/pci/pci-octeon.c
7199+++ b/arch/mips/pci/pci-octeon.c
7200@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7201
7202
7203 static struct pci_ops octeon_pci_ops = {
7204- octeon_read_config,
7205- octeon_write_config,
7206+ .read = octeon_read_config,
7207+ .write = octeon_write_config,
7208 };
7209
7210 static struct resource octeon_pci_mem_resource = {
7211diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7212index 5e36c33..eb4a17b 100644
7213--- a/arch/mips/pci/pcie-octeon.c
7214+++ b/arch/mips/pci/pcie-octeon.c
7215@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7216 }
7217
7218 static struct pci_ops octeon_pcie0_ops = {
7219- octeon_pcie0_read_config,
7220- octeon_pcie0_write_config,
7221+ .read = octeon_pcie0_read_config,
7222+ .write = octeon_pcie0_write_config,
7223 };
7224
7225 static struct resource octeon_pcie0_mem_resource = {
7226@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7227 };
7228
7229 static struct pci_ops octeon_pcie1_ops = {
7230- octeon_pcie1_read_config,
7231- octeon_pcie1_write_config,
7232+ .read = octeon_pcie1_read_config,
7233+ .write = octeon_pcie1_write_config,
7234 };
7235
7236 static struct resource octeon_pcie1_mem_resource = {
7237@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7238 };
7239
7240 static struct pci_ops octeon_dummy_ops = {
7241- octeon_dummy_read_config,
7242- octeon_dummy_write_config,
7243+ .read = octeon_dummy_read_config,
7244+ .write = octeon_dummy_write_config,
7245 };
7246
7247 static struct resource octeon_dummy_mem_resource = {
7248diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7249index a2358b4..7cead4f 100644
7250--- a/arch/mips/sgi-ip27/ip27-nmi.c
7251+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7252@@ -187,9 +187,9 @@ void
7253 cont_nmi_dump(void)
7254 {
7255 #ifndef REAL_NMI_SIGNAL
7256- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7257+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7258
7259- atomic_inc(&nmied_cpus);
7260+ atomic_inc_unchecked(&nmied_cpus);
7261 #endif
7262 /*
7263 * Only allow 1 cpu to proceed
7264@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7265 udelay(10000);
7266 }
7267 #else
7268- while (atomic_read(&nmied_cpus) != num_online_cpus());
7269+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7270 #endif
7271
7272 /*
7273diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7274index a046b30..6799527 100644
7275--- a/arch/mips/sni/rm200.c
7276+++ b/arch/mips/sni/rm200.c
7277@@ -270,7 +270,7 @@ spurious_8259A_irq:
7278 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7279 spurious_irq_mask |= irqmask;
7280 }
7281- atomic_inc(&irq_err_count);
7282+ atomic_inc_unchecked(&irq_err_count);
7283 /*
7284 * Theoretically we do not have to handle this IRQ,
7285 * but in Linux this does not cause problems and is
7286diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7287index 41e873b..34d33a7 100644
7288--- a/arch/mips/vr41xx/common/icu.c
7289+++ b/arch/mips/vr41xx/common/icu.c
7290@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7291
7292 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7293
7294- atomic_inc(&irq_err_count);
7295+ atomic_inc_unchecked(&irq_err_count);
7296
7297 return -1;
7298 }
7299diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7300index ae0e4ee..e8f0692 100644
7301--- a/arch/mips/vr41xx/common/irq.c
7302+++ b/arch/mips/vr41xx/common/irq.c
7303@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7304 irq_cascade_t *cascade;
7305
7306 if (irq >= NR_IRQS) {
7307- atomic_inc(&irq_err_count);
7308+ atomic_inc_unchecked(&irq_err_count);
7309 return;
7310 }
7311
7312@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7313 ret = cascade->get_irq(irq);
7314 irq = ret;
7315 if (ret < 0)
7316- atomic_inc(&irq_err_count);
7317+ atomic_inc_unchecked(&irq_err_count);
7318 else
7319 irq_dispatch(irq);
7320 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7321diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7322index 967d144..db12197 100644
7323--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7324+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7325@@ -11,12 +11,14 @@
7326 #ifndef _ASM_PROC_CACHE_H
7327 #define _ASM_PROC_CACHE_H
7328
7329+#include <linux/const.h>
7330+
7331 /* L1 cache */
7332
7333 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7334 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7335-#define L1_CACHE_BYTES 16 /* bytes per entry */
7336 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7337+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7338 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7339
7340 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7341diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7342index bcb5df2..84fabd2 100644
7343--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7344+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7345@@ -16,13 +16,15 @@
7346 #ifndef _ASM_PROC_CACHE_H
7347 #define _ASM_PROC_CACHE_H
7348
7349+#include <linux/const.h>
7350+
7351 /*
7352 * L1 cache
7353 */
7354 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7355 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7356-#define L1_CACHE_BYTES 32 /* bytes per entry */
7357 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7358+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7359 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7360
7361 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7362diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7363index 4ce7a01..449202a 100644
7364--- a/arch/openrisc/include/asm/cache.h
7365+++ b/arch/openrisc/include/asm/cache.h
7366@@ -19,11 +19,13 @@
7367 #ifndef __ASM_OPENRISC_CACHE_H
7368 #define __ASM_OPENRISC_CACHE_H
7369
7370+#include <linux/const.h>
7371+
7372 /* FIXME: How can we replace these with values from the CPU...
7373 * they shouldn't be hard-coded!
7374 */
7375
7376-#define L1_CACHE_BYTES 16
7377 #define L1_CACHE_SHIFT 4
7378+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7379
7380 #endif /* __ASM_OPENRISC_CACHE_H */
7381diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7382index 472886c..00e7df9 100644
7383--- a/arch/parisc/include/asm/atomic.h
7384+++ b/arch/parisc/include/asm/atomic.h
7385@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7386 return dec;
7387 }
7388
7389+#define atomic64_read_unchecked(v) atomic64_read(v)
7390+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7391+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7392+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7393+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7394+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7395+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7396+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7397+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7398+
7399 #endif /* !CONFIG_64BIT */
7400
7401
7402diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7403index 47f11c7..3420df2 100644
7404--- a/arch/parisc/include/asm/cache.h
7405+++ b/arch/parisc/include/asm/cache.h
7406@@ -5,6 +5,7 @@
7407 #ifndef __ARCH_PARISC_CACHE_H
7408 #define __ARCH_PARISC_CACHE_H
7409
7410+#include <linux/const.h>
7411
7412 /*
7413 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7414@@ -15,13 +16,13 @@
7415 * just ruin performance.
7416 */
7417 #ifdef CONFIG_PA20
7418-#define L1_CACHE_BYTES 64
7419 #define L1_CACHE_SHIFT 6
7420 #else
7421-#define L1_CACHE_BYTES 32
7422 #define L1_CACHE_SHIFT 5
7423 #endif
7424
7425+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7426+
7427 #ifndef __ASSEMBLY__
7428
7429 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7430diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7431index 3391d06..c23a2cc 100644
7432--- a/arch/parisc/include/asm/elf.h
7433+++ b/arch/parisc/include/asm/elf.h
7434@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7435
7436 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7437
7438+#ifdef CONFIG_PAX_ASLR
7439+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7440+
7441+#define PAX_DELTA_MMAP_LEN 16
7442+#define PAX_DELTA_STACK_LEN 16
7443+#endif
7444+
7445 /* This yields a mask that user programs can use to figure out what
7446 instruction set this CPU supports. This could be done in user space,
7447 but it's not easy, and we've already done it here. */
7448diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7449index f213f5b..0af3e8e 100644
7450--- a/arch/parisc/include/asm/pgalloc.h
7451+++ b/arch/parisc/include/asm/pgalloc.h
7452@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7453 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7454 }
7455
7456+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7457+{
7458+ pgd_populate(mm, pgd, pmd);
7459+}
7460+
7461 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7462 {
7463 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7464@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7465 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7466 #define pmd_free(mm, x) do { } while (0)
7467 #define pgd_populate(mm, pmd, pte) BUG()
7468+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7469
7470 #endif
7471
7472diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7473index 22b89d1..ce34230 100644
7474--- a/arch/parisc/include/asm/pgtable.h
7475+++ b/arch/parisc/include/asm/pgtable.h
7476@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7477 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7478 #define PAGE_COPY PAGE_EXECREAD
7479 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7480+
7481+#ifdef CONFIG_PAX_PAGEEXEC
7482+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7483+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7484+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7485+#else
7486+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7487+# define PAGE_COPY_NOEXEC PAGE_COPY
7488+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7489+#endif
7490+
7491 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7492 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7493 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7494diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7495index 4006964..fcb3cc2 100644
7496--- a/arch/parisc/include/asm/uaccess.h
7497+++ b/arch/parisc/include/asm/uaccess.h
7498@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7499 const void __user *from,
7500 unsigned long n)
7501 {
7502- int sz = __compiletime_object_size(to);
7503+ size_t sz = __compiletime_object_size(to);
7504 int ret = -EFAULT;
7505
7506- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7507+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7508 ret = __copy_from_user(to, from, n);
7509 else
7510 copy_from_user_overflow();
7511diff --git a/arch/parisc/include/uapi/asm/resource.h b/arch/parisc/include/uapi/asm/resource.h
7512index 8b06343..090483c 100644
7513--- a/arch/parisc/include/uapi/asm/resource.h
7514+++ b/arch/parisc/include/uapi/asm/resource.h
7515@@ -1,7 +1,6 @@
7516 #ifndef _ASM_PARISC_RESOURCE_H
7517 #define _ASM_PARISC_RESOURCE_H
7518
7519-#define _STK_LIM_MAX 10 * _STK_LIM
7520 #include <asm-generic/resource.h>
7521
7522 #endif
7523diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7524index 50dfafc..b9fc230 100644
7525--- a/arch/parisc/kernel/module.c
7526+++ b/arch/parisc/kernel/module.c
7527@@ -98,16 +98,38 @@
7528
7529 /* three functions to determine where in the module core
7530 * or init pieces the location is */
7531+static inline int in_init_rx(struct module *me, void *loc)
7532+{
7533+ return (loc >= me->module_init_rx &&
7534+ loc < (me->module_init_rx + me->init_size_rx));
7535+}
7536+
7537+static inline int in_init_rw(struct module *me, void *loc)
7538+{
7539+ return (loc >= me->module_init_rw &&
7540+ loc < (me->module_init_rw + me->init_size_rw));
7541+}
7542+
7543 static inline int in_init(struct module *me, void *loc)
7544 {
7545- return (loc >= me->module_init &&
7546- loc <= (me->module_init + me->init_size));
7547+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7548+}
7549+
7550+static inline int in_core_rx(struct module *me, void *loc)
7551+{
7552+ return (loc >= me->module_core_rx &&
7553+ loc < (me->module_core_rx + me->core_size_rx));
7554+}
7555+
7556+static inline int in_core_rw(struct module *me, void *loc)
7557+{
7558+ return (loc >= me->module_core_rw &&
7559+ loc < (me->module_core_rw + me->core_size_rw));
7560 }
7561
7562 static inline int in_core(struct module *me, void *loc)
7563 {
7564- return (loc >= me->module_core &&
7565- loc <= (me->module_core + me->core_size));
7566+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7567 }
7568
7569 static inline int in_local(struct module *me, void *loc)
7570@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7571 }
7572
7573 /* align things a bit */
7574- me->core_size = ALIGN(me->core_size, 16);
7575- me->arch.got_offset = me->core_size;
7576- me->core_size += gots * sizeof(struct got_entry);
7577+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7578+ me->arch.got_offset = me->core_size_rw;
7579+ me->core_size_rw += gots * sizeof(struct got_entry);
7580
7581- me->core_size = ALIGN(me->core_size, 16);
7582- me->arch.fdesc_offset = me->core_size;
7583- me->core_size += fdescs * sizeof(Elf_Fdesc);
7584+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7585+ me->arch.fdesc_offset = me->core_size_rw;
7586+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7587
7588 me->arch.got_max = gots;
7589 me->arch.fdesc_max = fdescs;
7590@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7591
7592 BUG_ON(value == 0);
7593
7594- got = me->module_core + me->arch.got_offset;
7595+ got = me->module_core_rw + me->arch.got_offset;
7596 for (i = 0; got[i].addr; i++)
7597 if (got[i].addr == value)
7598 goto out;
7599@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7600 #ifdef CONFIG_64BIT
7601 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7602 {
7603- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7604+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7605
7606 if (!value) {
7607 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7608@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7609
7610 /* Create new one */
7611 fdesc->addr = value;
7612- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7613+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7614 return (Elf_Addr)fdesc;
7615 }
7616 #endif /* CONFIG_64BIT */
7617@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7618
7619 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7620 end = table + sechdrs[me->arch.unwind_section].sh_size;
7621- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7622+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7623
7624 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7625 me->arch.unwind_section, table, end, gp);
7626diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7627index b7cadc4..bf4a32d 100644
7628--- a/arch/parisc/kernel/sys_parisc.c
7629+++ b/arch/parisc/kernel/sys_parisc.c
7630@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7631 unsigned long task_size = TASK_SIZE;
7632 int do_color_align, last_mmap;
7633 struct vm_unmapped_area_info info;
7634+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7635
7636 if (len > task_size)
7637 return -ENOMEM;
7638@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7639 goto found_addr;
7640 }
7641
7642+#ifdef CONFIG_PAX_RANDMMAP
7643+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7644+#endif
7645+
7646 if (addr) {
7647 if (do_color_align && last_mmap)
7648 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7649@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7650 info.high_limit = mmap_upper_limit();
7651 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7652 info.align_offset = shared_align_offset(last_mmap, pgoff);
7653+ info.threadstack_offset = offset;
7654 addr = vm_unmapped_area(&info);
7655
7656 found_addr:
7657@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7658 unsigned long addr = addr0;
7659 int do_color_align, last_mmap;
7660 struct vm_unmapped_area_info info;
7661+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7662
7663 #ifdef CONFIG_64BIT
7664 /* This should only ever run for 32-bit processes. */
7665@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7666 }
7667
7668 /* requesting a specific address */
7669+#ifdef CONFIG_PAX_RANDMMAP
7670+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7671+#endif
7672+
7673 if (addr) {
7674 if (do_color_align && last_mmap)
7675 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7676@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7677 info.high_limit = mm->mmap_base;
7678 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7679 info.align_offset = shared_align_offset(last_mmap, pgoff);
7680+ info.threadstack_offset = offset;
7681 addr = vm_unmapped_area(&info);
7682 if (!(addr & ~PAGE_MASK))
7683 goto found_addr;
7684@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7685 mm->mmap_legacy_base = mmap_legacy_base();
7686 mm->mmap_base = mmap_upper_limit();
7687
7688+#ifdef CONFIG_PAX_RANDMMAP
7689+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7690+ mm->mmap_legacy_base += mm->delta_mmap;
7691+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7692+ }
7693+#endif
7694+
7695 if (mmap_is_legacy()) {
7696 mm->mmap_base = mm->mmap_legacy_base;
7697 mm->get_unmapped_area = arch_get_unmapped_area;
7698diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7699index 1cd1d0c..44ec918 100644
7700--- a/arch/parisc/kernel/traps.c
7701+++ b/arch/parisc/kernel/traps.c
7702@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7703
7704 down_read(&current->mm->mmap_sem);
7705 vma = find_vma(current->mm,regs->iaoq[0]);
7706- if (vma && (regs->iaoq[0] >= vma->vm_start)
7707- && (vma->vm_flags & VM_EXEC)) {
7708-
7709+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7710 fault_address = regs->iaoq[0];
7711 fault_space = regs->iasq[0];
7712
7713diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7714index 9d08c71..e2b4d20 100644
7715--- a/arch/parisc/mm/fault.c
7716+++ b/arch/parisc/mm/fault.c
7717@@ -15,6 +15,7 @@
7718 #include <linux/sched.h>
7719 #include <linux/interrupt.h>
7720 #include <linux/module.h>
7721+#include <linux/unistd.h>
7722
7723 #include <asm/uaccess.h>
7724 #include <asm/traps.h>
7725@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7726 static unsigned long
7727 parisc_acctyp(unsigned long code, unsigned int inst)
7728 {
7729- if (code == 6 || code == 16)
7730+ if (code == 6 || code == 7 || code == 16)
7731 return VM_EXEC;
7732
7733 switch (inst & 0xf0000000) {
7734@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7735 }
7736 #endif
7737
7738+#ifdef CONFIG_PAX_PAGEEXEC
7739+/*
7740+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7741+ *
7742+ * returns 1 when task should be killed
7743+ * 2 when rt_sigreturn trampoline was detected
7744+ * 3 when unpatched PLT trampoline was detected
7745+ */
7746+static int pax_handle_fetch_fault(struct pt_regs *regs)
7747+{
7748+
7749+#ifdef CONFIG_PAX_EMUPLT
7750+ int err;
7751+
7752+ do { /* PaX: unpatched PLT emulation */
7753+ unsigned int bl, depwi;
7754+
7755+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7756+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7757+
7758+ if (err)
7759+ break;
7760+
7761+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7762+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7763+
7764+ err = get_user(ldw, (unsigned int *)addr);
7765+ err |= get_user(bv, (unsigned int *)(addr+4));
7766+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7767+
7768+ if (err)
7769+ break;
7770+
7771+ if (ldw == 0x0E801096U &&
7772+ bv == 0xEAC0C000U &&
7773+ ldw2 == 0x0E881095U)
7774+ {
7775+ unsigned int resolver, map;
7776+
7777+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7778+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7779+ if (err)
7780+ break;
7781+
7782+ regs->gr[20] = instruction_pointer(regs)+8;
7783+ regs->gr[21] = map;
7784+ regs->gr[22] = resolver;
7785+ regs->iaoq[0] = resolver | 3UL;
7786+ regs->iaoq[1] = regs->iaoq[0] + 4;
7787+ return 3;
7788+ }
7789+ }
7790+ } while (0);
7791+#endif
7792+
7793+#ifdef CONFIG_PAX_EMUTRAMP
7794+
7795+#ifndef CONFIG_PAX_EMUSIGRT
7796+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7797+ return 1;
7798+#endif
7799+
7800+ do { /* PaX: rt_sigreturn emulation */
7801+ unsigned int ldi1, ldi2, bel, nop;
7802+
7803+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7804+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7805+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7806+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7807+
7808+ if (err)
7809+ break;
7810+
7811+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7812+ ldi2 == 0x3414015AU &&
7813+ bel == 0xE4008200U &&
7814+ nop == 0x08000240U)
7815+ {
7816+ regs->gr[25] = (ldi1 & 2) >> 1;
7817+ regs->gr[20] = __NR_rt_sigreturn;
7818+ regs->gr[31] = regs->iaoq[1] + 16;
7819+ regs->sr[0] = regs->iasq[1];
7820+ regs->iaoq[0] = 0x100UL;
7821+ regs->iaoq[1] = regs->iaoq[0] + 4;
7822+ regs->iasq[0] = regs->sr[2];
7823+ regs->iasq[1] = regs->sr[2];
7824+ return 2;
7825+ }
7826+ } while (0);
7827+#endif
7828+
7829+ return 1;
7830+}
7831+
7832+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7833+{
7834+ unsigned long i;
7835+
7836+ printk(KERN_ERR "PAX: bytes at PC: ");
7837+ for (i = 0; i < 5; i++) {
7838+ unsigned int c;
7839+ if (get_user(c, (unsigned int *)pc+i))
7840+ printk(KERN_CONT "???????? ");
7841+ else
7842+ printk(KERN_CONT "%08x ", c);
7843+ }
7844+ printk("\n");
7845+}
7846+#endif
7847+
7848 int fixup_exception(struct pt_regs *regs)
7849 {
7850 const struct exception_table_entry *fix;
7851@@ -210,8 +321,33 @@ retry:
7852
7853 good_area:
7854
7855- if ((vma->vm_flags & acc_type) != acc_type)
7856+ if ((vma->vm_flags & acc_type) != acc_type) {
7857+
7858+#ifdef CONFIG_PAX_PAGEEXEC
7859+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7860+ (address & ~3UL) == instruction_pointer(regs))
7861+ {
7862+ up_read(&mm->mmap_sem);
7863+ switch (pax_handle_fetch_fault(regs)) {
7864+
7865+#ifdef CONFIG_PAX_EMUPLT
7866+ case 3:
7867+ return;
7868+#endif
7869+
7870+#ifdef CONFIG_PAX_EMUTRAMP
7871+ case 2:
7872+ return;
7873+#endif
7874+
7875+ }
7876+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7877+ do_group_exit(SIGKILL);
7878+ }
7879+#endif
7880+
7881 goto bad_area;
7882+ }
7883
7884 /*
7885 * If for any reason at all we couldn't handle the fault, make
7886diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7887index 957bf34..3430cc8 100644
7888--- a/arch/powerpc/Kconfig
7889+++ b/arch/powerpc/Kconfig
7890@@ -393,6 +393,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7891 config KEXEC
7892 bool "kexec system call"
7893 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7894+ depends on !GRKERNSEC_KMEM
7895 help
7896 kexec is a system call that implements the ability to shutdown your
7897 current kernel, and to start another kernel. It is like a reboot
7898diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7899index e3b1d41..8e81edf 100644
7900--- a/arch/powerpc/include/asm/atomic.h
7901+++ b/arch/powerpc/include/asm/atomic.h
7902@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7903 return t1;
7904 }
7905
7906+#define atomic64_read_unchecked(v) atomic64_read(v)
7907+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7908+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7909+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7910+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7911+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7912+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7913+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7914+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7915+
7916 #endif /* __powerpc64__ */
7917
7918 #endif /* __KERNEL__ */
7919diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7920index ed0afc1..0332825 100644
7921--- a/arch/powerpc/include/asm/cache.h
7922+++ b/arch/powerpc/include/asm/cache.h
7923@@ -3,6 +3,7 @@
7924
7925 #ifdef __KERNEL__
7926
7927+#include <linux/const.h>
7928
7929 /* bytes per L1 cache line */
7930 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7931@@ -22,7 +23,7 @@
7932 #define L1_CACHE_SHIFT 7
7933 #endif
7934
7935-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7936+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7937
7938 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7939
7940diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7941index 935b5e7..7001d2d 100644
7942--- a/arch/powerpc/include/asm/elf.h
7943+++ b/arch/powerpc/include/asm/elf.h
7944@@ -28,8 +28,19 @@
7945 the loader. We need to make sure that it is out of the way of the program
7946 that it will "exec", and that there is sufficient room for the brk. */
7947
7948-extern unsigned long randomize_et_dyn(unsigned long base);
7949-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7950+#define ELF_ET_DYN_BASE (0x20000000)
7951+
7952+#ifdef CONFIG_PAX_ASLR
7953+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7954+
7955+#ifdef __powerpc64__
7956+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7957+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7958+#else
7959+#define PAX_DELTA_MMAP_LEN 15
7960+#define PAX_DELTA_STACK_LEN 15
7961+#endif
7962+#endif
7963
7964 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7965
7966@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7967 (0x7ff >> (PAGE_SHIFT - 12)) : \
7968 (0x3ffff >> (PAGE_SHIFT - 12)))
7969
7970-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7971-#define arch_randomize_brk arch_randomize_brk
7972-
7973-
7974 #ifdef CONFIG_SPU_BASE
7975 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7976 #define NT_SPU 1
7977diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7978index 8196e9c..d83a9f3 100644
7979--- a/arch/powerpc/include/asm/exec.h
7980+++ b/arch/powerpc/include/asm/exec.h
7981@@ -4,6 +4,6 @@
7982 #ifndef _ASM_POWERPC_EXEC_H
7983 #define _ASM_POWERPC_EXEC_H
7984
7985-extern unsigned long arch_align_stack(unsigned long sp);
7986+#define arch_align_stack(x) ((x) & ~0xfUL)
7987
7988 #endif /* _ASM_POWERPC_EXEC_H */
7989diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7990index 5acabbd..7ea14fa 100644
7991--- a/arch/powerpc/include/asm/kmap_types.h
7992+++ b/arch/powerpc/include/asm/kmap_types.h
7993@@ -10,7 +10,7 @@
7994 * 2 of the License, or (at your option) any later version.
7995 */
7996
7997-#define KM_TYPE_NR 16
7998+#define KM_TYPE_NR 17
7999
8000 #endif /* __KERNEL__ */
8001 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8002diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8003index b8da913..60b608a 100644
8004--- a/arch/powerpc/include/asm/local.h
8005+++ b/arch/powerpc/include/asm/local.h
8006@@ -9,15 +9,26 @@ typedef struct
8007 atomic_long_t a;
8008 } local_t;
8009
8010+typedef struct
8011+{
8012+ atomic_long_unchecked_t a;
8013+} local_unchecked_t;
8014+
8015 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8016
8017 #define local_read(l) atomic_long_read(&(l)->a)
8018+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8019 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8020+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8021
8022 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8023+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8024 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8025+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8026 #define local_inc(l) atomic_long_inc(&(l)->a)
8027+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8028 #define local_dec(l) atomic_long_dec(&(l)->a)
8029+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8030
8031 static __inline__ long local_add_return(long a, local_t *l)
8032 {
8033@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8034
8035 return t;
8036 }
8037+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8038
8039 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8040
8041@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8042
8043 return t;
8044 }
8045+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8046
8047 static __inline__ long local_inc_return(local_t *l)
8048 {
8049@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8050
8051 #define local_cmpxchg(l, o, n) \
8052 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8053+#define local_cmpxchg_unchecked(l, o, n) \
8054+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8055 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8056
8057 /**
8058diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8059index 8565c25..2865190 100644
8060--- a/arch/powerpc/include/asm/mman.h
8061+++ b/arch/powerpc/include/asm/mman.h
8062@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8063 }
8064 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8065
8066-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8067+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8068 {
8069 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8070 }
8071diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8072index 32e4e21..62afb12 100644
8073--- a/arch/powerpc/include/asm/page.h
8074+++ b/arch/powerpc/include/asm/page.h
8075@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8076 * and needs to be executable. This means the whole heap ends
8077 * up being executable.
8078 */
8079-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8080- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8081+#define VM_DATA_DEFAULT_FLAGS32 \
8082+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8083+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8084
8085 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8086 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8087@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8088 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8089 #endif
8090
8091+#define ktla_ktva(addr) (addr)
8092+#define ktva_ktla(addr) (addr)
8093+
8094 #ifndef CONFIG_PPC_BOOK3S_64
8095 /*
8096 * Use the top bit of the higher-level page table entries to indicate whether
8097diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8098index 88693ce..ac6f9ab 100644
8099--- a/arch/powerpc/include/asm/page_64.h
8100+++ b/arch/powerpc/include/asm/page_64.h
8101@@ -153,15 +153,18 @@ do { \
8102 * stack by default, so in the absence of a PT_GNU_STACK program header
8103 * we turn execute permission off.
8104 */
8105-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8106- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8107+#define VM_STACK_DEFAULT_FLAGS32 \
8108+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8109+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8110
8111 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8112 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8113
8114+#ifndef CONFIG_PAX_PAGEEXEC
8115 #define VM_STACK_DEFAULT_FLAGS \
8116 (is_32bit_task() ? \
8117 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8118+#endif
8119
8120 #include <asm-generic/getorder.h>
8121
8122diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8123index 4b0be20..c15a27d 100644
8124--- a/arch/powerpc/include/asm/pgalloc-64.h
8125+++ b/arch/powerpc/include/asm/pgalloc-64.h
8126@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8127 #ifndef CONFIG_PPC_64K_PAGES
8128
8129 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8130+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8131
8132 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8133 {
8134@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8135 pud_set(pud, (unsigned long)pmd);
8136 }
8137
8138+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8139+{
8140+ pud_populate(mm, pud, pmd);
8141+}
8142+
8143 #define pmd_populate(mm, pmd, pte_page) \
8144 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8145 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8146@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8147 #endif
8148
8149 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8150+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8151
8152 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8153 pte_t *pte)
8154diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8155index 3ebb188..e17dddf 100644
8156--- a/arch/powerpc/include/asm/pgtable.h
8157+++ b/arch/powerpc/include/asm/pgtable.h
8158@@ -2,6 +2,7 @@
8159 #define _ASM_POWERPC_PGTABLE_H
8160 #ifdef __KERNEL__
8161
8162+#include <linux/const.h>
8163 #ifndef __ASSEMBLY__
8164 #include <linux/mmdebug.h>
8165 #include <asm/processor.h> /* For TASK_SIZE */
8166diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8167index 4aad413..85d86bf 100644
8168--- a/arch/powerpc/include/asm/pte-hash32.h
8169+++ b/arch/powerpc/include/asm/pte-hash32.h
8170@@ -21,6 +21,7 @@
8171 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8172 #define _PAGE_USER 0x004 /* usermode access allowed */
8173 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8174+#define _PAGE_EXEC _PAGE_GUARDED
8175 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8176 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8177 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8178diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8179index ce17815..c5574cc 100644
8180--- a/arch/powerpc/include/asm/reg.h
8181+++ b/arch/powerpc/include/asm/reg.h
8182@@ -249,6 +249,7 @@
8183 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8184 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8185 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8186+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8187 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8188 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8189 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8190diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8191index 084e080..9415a3d 100644
8192--- a/arch/powerpc/include/asm/smp.h
8193+++ b/arch/powerpc/include/asm/smp.h
8194@@ -51,7 +51,7 @@ struct smp_ops_t {
8195 int (*cpu_disable)(void);
8196 void (*cpu_die)(unsigned int nr);
8197 int (*cpu_bootable)(unsigned int nr);
8198-};
8199+} __no_const;
8200
8201 extern void smp_send_debugger_break(void);
8202 extern void start_secondary_resume(void);
8203diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8204index b034ecd..af7e31f 100644
8205--- a/arch/powerpc/include/asm/thread_info.h
8206+++ b/arch/powerpc/include/asm/thread_info.h
8207@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8208 #if defined(CONFIG_PPC64)
8209 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8210 #endif
8211+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8212+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8213
8214 /* as above, but as bit values */
8215 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8216@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8217 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8218 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8219 #define _TIF_NOHZ (1<<TIF_NOHZ)
8220+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8221 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8222 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8223- _TIF_NOHZ)
8224+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8225
8226 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8227 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8228diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8229index 9485b43..3bd3c16 100644
8230--- a/arch/powerpc/include/asm/uaccess.h
8231+++ b/arch/powerpc/include/asm/uaccess.h
8232@@ -58,6 +58,7 @@
8233
8234 #endif
8235
8236+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8237 #define access_ok(type, addr, size) \
8238 (__chk_user_ptr(addr), \
8239 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8240@@ -318,52 +319,6 @@ do { \
8241 extern unsigned long __copy_tofrom_user(void __user *to,
8242 const void __user *from, unsigned long size);
8243
8244-#ifndef __powerpc64__
8245-
8246-static inline unsigned long copy_from_user(void *to,
8247- const void __user *from, unsigned long n)
8248-{
8249- unsigned long over;
8250-
8251- if (access_ok(VERIFY_READ, from, n))
8252- return __copy_tofrom_user((__force void __user *)to, from, n);
8253- if ((unsigned long)from < TASK_SIZE) {
8254- over = (unsigned long)from + n - TASK_SIZE;
8255- return __copy_tofrom_user((__force void __user *)to, from,
8256- n - over) + over;
8257- }
8258- return n;
8259-}
8260-
8261-static inline unsigned long copy_to_user(void __user *to,
8262- const void *from, unsigned long n)
8263-{
8264- unsigned long over;
8265-
8266- if (access_ok(VERIFY_WRITE, to, n))
8267- return __copy_tofrom_user(to, (__force void __user *)from, n);
8268- if ((unsigned long)to < TASK_SIZE) {
8269- over = (unsigned long)to + n - TASK_SIZE;
8270- return __copy_tofrom_user(to, (__force void __user *)from,
8271- n - over) + over;
8272- }
8273- return n;
8274-}
8275-
8276-#else /* __powerpc64__ */
8277-
8278-#define __copy_in_user(to, from, size) \
8279- __copy_tofrom_user((to), (from), (size))
8280-
8281-extern unsigned long copy_from_user(void *to, const void __user *from,
8282- unsigned long n);
8283-extern unsigned long copy_to_user(void __user *to, const void *from,
8284- unsigned long n);
8285-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8286- unsigned long n);
8287-
8288-#endif /* __powerpc64__ */
8289-
8290 static inline unsigned long __copy_from_user_inatomic(void *to,
8291 const void __user *from, unsigned long n)
8292 {
8293@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8294 if (ret == 0)
8295 return 0;
8296 }
8297+
8298+ if (!__builtin_constant_p(n))
8299+ check_object_size(to, n, false);
8300+
8301 return __copy_tofrom_user((__force void __user *)to, from, n);
8302 }
8303
8304@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8305 if (ret == 0)
8306 return 0;
8307 }
8308+
8309+ if (!__builtin_constant_p(n))
8310+ check_object_size(from, n, true);
8311+
8312 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8313 }
8314
8315@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8316 return __copy_to_user_inatomic(to, from, size);
8317 }
8318
8319+#ifndef __powerpc64__
8320+
8321+static inline unsigned long __must_check copy_from_user(void *to,
8322+ const void __user *from, unsigned long n)
8323+{
8324+ unsigned long over;
8325+
8326+ if ((long)n < 0)
8327+ return n;
8328+
8329+ if (access_ok(VERIFY_READ, from, n)) {
8330+ if (!__builtin_constant_p(n))
8331+ check_object_size(to, n, false);
8332+ return __copy_tofrom_user((__force void __user *)to, from, n);
8333+ }
8334+ if ((unsigned long)from < TASK_SIZE) {
8335+ over = (unsigned long)from + n - TASK_SIZE;
8336+ if (!__builtin_constant_p(n - over))
8337+ check_object_size(to, n - over, false);
8338+ return __copy_tofrom_user((__force void __user *)to, from,
8339+ n - over) + over;
8340+ }
8341+ return n;
8342+}
8343+
8344+static inline unsigned long __must_check copy_to_user(void __user *to,
8345+ const void *from, unsigned long n)
8346+{
8347+ unsigned long over;
8348+
8349+ if ((long)n < 0)
8350+ return n;
8351+
8352+ if (access_ok(VERIFY_WRITE, to, n)) {
8353+ if (!__builtin_constant_p(n))
8354+ check_object_size(from, n, true);
8355+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8356+ }
8357+ if ((unsigned long)to < TASK_SIZE) {
8358+ over = (unsigned long)to + n - TASK_SIZE;
8359+ if (!__builtin_constant_p(n))
8360+ check_object_size(from, n - over, true);
8361+ return __copy_tofrom_user(to, (__force void __user *)from,
8362+ n - over) + over;
8363+ }
8364+ return n;
8365+}
8366+
8367+#else /* __powerpc64__ */
8368+
8369+#define __copy_in_user(to, from, size) \
8370+ __copy_tofrom_user((to), (from), (size))
8371+
8372+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8373+{
8374+ if ((long)n < 0 || n > INT_MAX)
8375+ return n;
8376+
8377+ if (!__builtin_constant_p(n))
8378+ check_object_size(to, n, false);
8379+
8380+ if (likely(access_ok(VERIFY_READ, from, n)))
8381+ n = __copy_from_user(to, from, n);
8382+ else
8383+ memset(to, 0, n);
8384+ return n;
8385+}
8386+
8387+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8388+{
8389+ if ((long)n < 0 || n > INT_MAX)
8390+ return n;
8391+
8392+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8393+ if (!__builtin_constant_p(n))
8394+ check_object_size(from, n, true);
8395+ n = __copy_to_user(to, from, n);
8396+ }
8397+ return n;
8398+}
8399+
8400+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8401+ unsigned long n);
8402+
8403+#endif /* __powerpc64__ */
8404+
8405 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8406
8407 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8408diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8409index fcc9a89..07be2bb 100644
8410--- a/arch/powerpc/kernel/Makefile
8411+++ b/arch/powerpc/kernel/Makefile
8412@@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8413 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8414 endif
8415
8416+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8417+
8418 obj-y := cputable.o ptrace.o syscalls.o \
8419 irq.o align.o signal_32.o pmc.o vdso.o \
8420 process.o systbl.o idle.o \
8421diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8422index 063b65d..7a26e9d 100644
8423--- a/arch/powerpc/kernel/exceptions-64e.S
8424+++ b/arch/powerpc/kernel/exceptions-64e.S
8425@@ -771,6 +771,7 @@ storage_fault_common:
8426 std r14,_DAR(r1)
8427 std r15,_DSISR(r1)
8428 addi r3,r1,STACK_FRAME_OVERHEAD
8429+ bl .save_nvgprs
8430 mr r4,r14
8431 mr r5,r15
8432 ld r14,PACA_EXGEN+EX_R14(r13)
8433@@ -779,8 +780,7 @@ storage_fault_common:
8434 cmpdi r3,0
8435 bne- 1f
8436 b .ret_from_except_lite
8437-1: bl .save_nvgprs
8438- mr r5,r3
8439+1: mr r5,r3
8440 addi r3,r1,STACK_FRAME_OVERHEAD
8441 ld r4,_DAR(r1)
8442 bl .bad_page_fault
8443diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8444index 38d5073..f00af8d 100644
8445--- a/arch/powerpc/kernel/exceptions-64s.S
8446+++ b/arch/powerpc/kernel/exceptions-64s.S
8447@@ -1584,10 +1584,10 @@ handle_page_fault:
8448 11: ld r4,_DAR(r1)
8449 ld r5,_DSISR(r1)
8450 addi r3,r1,STACK_FRAME_OVERHEAD
8451+ bl .save_nvgprs
8452 bl .do_page_fault
8453 cmpdi r3,0
8454 beq+ 12f
8455- bl .save_nvgprs
8456 mr r5,r3
8457 addi r3,r1,STACK_FRAME_OVERHEAD
8458 lwz r4,_DAR(r1)
8459diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8460index 1d0848b..d74685f 100644
8461--- a/arch/powerpc/kernel/irq.c
8462+++ b/arch/powerpc/kernel/irq.c
8463@@ -447,6 +447,8 @@ void migrate_irqs(void)
8464 }
8465 #endif
8466
8467+extern void gr_handle_kernel_exploit(void);
8468+
8469 static inline void check_stack_overflow(void)
8470 {
8471 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8472@@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8473 printk("do_IRQ: stack overflow: %ld\n",
8474 sp - sizeof(struct thread_info));
8475 dump_stack();
8476+ gr_handle_kernel_exploit();
8477 }
8478 #endif
8479 }
8480diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8481index 6cff040..74ac5d1 100644
8482--- a/arch/powerpc/kernel/module_32.c
8483+++ b/arch/powerpc/kernel/module_32.c
8484@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8485 me->arch.core_plt_section = i;
8486 }
8487 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8488- printk("Module doesn't contain .plt or .init.plt sections.\n");
8489+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8490 return -ENOEXEC;
8491 }
8492
8493@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8494
8495 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8496 /* Init, or core PLT? */
8497- if (location >= mod->module_core
8498- && location < mod->module_core + mod->core_size)
8499+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8500+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8501 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8502- else
8503+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8504+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8505 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8506+ else {
8507+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8508+ return ~0UL;
8509+ }
8510
8511 /* Find this entry, or if that fails, the next avail. entry */
8512 while (entry->jump[0]) {
8513@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8514 }
8515 #ifdef CONFIG_DYNAMIC_FTRACE
8516 module->arch.tramp =
8517- do_plt_call(module->module_core,
8518+ do_plt_call(module->module_core_rx,
8519 (unsigned long)ftrace_caller,
8520 sechdrs, module);
8521 #endif
8522diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8523index 31d0215..206af70 100644
8524--- a/arch/powerpc/kernel/process.c
8525+++ b/arch/powerpc/kernel/process.c
8526@@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
8527 * Lookup NIP late so we have the best change of getting the
8528 * above info out without failing
8529 */
8530- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8531- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8532+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8533+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8534 #endif
8535 show_stack(current, (unsigned long *) regs->gpr[1]);
8536 if (!user_mode(regs))
8537@@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8538 newsp = stack[0];
8539 ip = stack[STACK_FRAME_LR_SAVE];
8540 if (!firstframe || ip != lr) {
8541- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8542+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8543 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8544 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8545- printk(" (%pS)",
8546+ printk(" (%pA)",
8547 (void *)current->ret_stack[curr_frame].ret);
8548 curr_frame--;
8549 }
8550@@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8551 struct pt_regs *regs = (struct pt_regs *)
8552 (sp + STACK_FRAME_OVERHEAD);
8553 lr = regs->link;
8554- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8555+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8556 regs->trap, (void *)regs->nip, (void *)lr);
8557 firstframe = 1;
8558 }
8559@@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
8560 mtspr(SPRN_CTRLT, ctrl);
8561 }
8562 #endif /* CONFIG_PPC64 */
8563-
8564-unsigned long arch_align_stack(unsigned long sp)
8565-{
8566- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8567- sp -= get_random_int() & ~PAGE_MASK;
8568- return sp & ~0xf;
8569-}
8570-
8571-static inline unsigned long brk_rnd(void)
8572-{
8573- unsigned long rnd = 0;
8574-
8575- /* 8MB for 32bit, 1GB for 64bit */
8576- if (is_32bit_task())
8577- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8578- else
8579- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8580-
8581- return rnd << PAGE_SHIFT;
8582-}
8583-
8584-unsigned long arch_randomize_brk(struct mm_struct *mm)
8585-{
8586- unsigned long base = mm->brk;
8587- unsigned long ret;
8588-
8589-#ifdef CONFIG_PPC_STD_MMU_64
8590- /*
8591- * If we are using 1TB segments and we are allowed to randomise
8592- * the heap, we can put it above 1TB so it is backed by a 1TB
8593- * segment. Otherwise the heap will be in the bottom 1TB
8594- * which always uses 256MB segments and this may result in a
8595- * performance penalty.
8596- */
8597- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8598- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8599-#endif
8600-
8601- ret = PAGE_ALIGN(base + brk_rnd());
8602-
8603- if (ret < mm->brk)
8604- return mm->brk;
8605-
8606- return ret;
8607-}
8608-
8609-unsigned long randomize_et_dyn(unsigned long base)
8610-{
8611- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8612-
8613- if (ret < base)
8614- return base;
8615-
8616- return ret;
8617-}
8618diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8619index 2e3d2bf..35df241 100644
8620--- a/arch/powerpc/kernel/ptrace.c
8621+++ b/arch/powerpc/kernel/ptrace.c
8622@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8623 return ret;
8624 }
8625
8626+#ifdef CONFIG_GRKERNSEC_SETXID
8627+extern void gr_delayed_cred_worker(void);
8628+#endif
8629+
8630 /*
8631 * We must return the syscall number to actually look up in the table.
8632 * This can be -1L to skip running any syscall at all.
8633@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8634
8635 secure_computing_strict(regs->gpr[0]);
8636
8637+#ifdef CONFIG_GRKERNSEC_SETXID
8638+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8639+ gr_delayed_cred_worker();
8640+#endif
8641+
8642 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8643 tracehook_report_syscall_entry(regs))
8644 /*
8645@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8646 {
8647 int step;
8648
8649+#ifdef CONFIG_GRKERNSEC_SETXID
8650+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8651+ gr_delayed_cred_worker();
8652+#endif
8653+
8654 audit_syscall_exit(regs);
8655
8656 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8657diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8658index 4e47db6..6dcc96e 100644
8659--- a/arch/powerpc/kernel/signal_32.c
8660+++ b/arch/powerpc/kernel/signal_32.c
8661@@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8662 /* Save user registers on the stack */
8663 frame = &rt_sf->uc.uc_mcontext;
8664 addr = frame;
8665- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8666+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8667 sigret = 0;
8668 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8669 } else {
8670diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8671index d501dc4..e5a0de0 100644
8672--- a/arch/powerpc/kernel/signal_64.c
8673+++ b/arch/powerpc/kernel/signal_64.c
8674@@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8675 current->thread.fp_state.fpscr = 0;
8676
8677 /* Set up to return from userspace. */
8678- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8679+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8680 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8681 } else {
8682 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8683diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8684index 33cd7a0..d615344 100644
8685--- a/arch/powerpc/kernel/traps.c
8686+++ b/arch/powerpc/kernel/traps.c
8687@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8688 return flags;
8689 }
8690
8691+extern void gr_handle_kernel_exploit(void);
8692+
8693 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8694 int signr)
8695 {
8696@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8697 panic("Fatal exception in interrupt");
8698 if (panic_on_oops)
8699 panic("Fatal exception");
8700+
8701+ gr_handle_kernel_exploit();
8702+
8703 do_exit(signr);
8704 }
8705
8706diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8707index 094e45c..d82b848 100644
8708--- a/arch/powerpc/kernel/vdso.c
8709+++ b/arch/powerpc/kernel/vdso.c
8710@@ -35,6 +35,7 @@
8711 #include <asm/vdso.h>
8712 #include <asm/vdso_datapage.h>
8713 #include <asm/setup.h>
8714+#include <asm/mman.h>
8715
8716 #undef DEBUG
8717
8718@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8719 vdso_base = VDSO32_MBASE;
8720 #endif
8721
8722- current->mm->context.vdso_base = 0;
8723+ current->mm->context.vdso_base = ~0UL;
8724
8725 /* vDSO has a problem and was disabled, just don't "enable" it for the
8726 * process
8727@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8728 vdso_base = get_unmapped_area(NULL, vdso_base,
8729 (vdso_pages << PAGE_SHIFT) +
8730 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8731- 0, 0);
8732+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8733 if (IS_ERR_VALUE(vdso_base)) {
8734 rc = vdso_base;
8735 goto fail_mmapsem;
8736diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8737index 3cf541a..ab2d825 100644
8738--- a/arch/powerpc/kvm/powerpc.c
8739+++ b/arch/powerpc/kvm/powerpc.c
8740@@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8741 }
8742 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8743
8744-int kvm_arch_init(void *opaque)
8745+int kvm_arch_init(const void *opaque)
8746 {
8747 return 0;
8748 }
8749diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8750index 5eea6f3..5d10396 100644
8751--- a/arch/powerpc/lib/usercopy_64.c
8752+++ b/arch/powerpc/lib/usercopy_64.c
8753@@ -9,22 +9,6 @@
8754 #include <linux/module.h>
8755 #include <asm/uaccess.h>
8756
8757-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8758-{
8759- if (likely(access_ok(VERIFY_READ, from, n)))
8760- n = __copy_from_user(to, from, n);
8761- else
8762- memset(to, 0, n);
8763- return n;
8764-}
8765-
8766-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8767-{
8768- if (likely(access_ok(VERIFY_WRITE, to, n)))
8769- n = __copy_to_user(to, from, n);
8770- return n;
8771-}
8772-
8773 unsigned long copy_in_user(void __user *to, const void __user *from,
8774 unsigned long n)
8775 {
8776@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8777 return n;
8778 }
8779
8780-EXPORT_SYMBOL(copy_from_user);
8781-EXPORT_SYMBOL(copy_to_user);
8782 EXPORT_SYMBOL(copy_in_user);
8783
8784diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8785index 51ab9e7..7d3c78b 100644
8786--- a/arch/powerpc/mm/fault.c
8787+++ b/arch/powerpc/mm/fault.c
8788@@ -33,6 +33,10 @@
8789 #include <linux/magic.h>
8790 #include <linux/ratelimit.h>
8791 #include <linux/context_tracking.h>
8792+#include <linux/slab.h>
8793+#include <linux/pagemap.h>
8794+#include <linux/compiler.h>
8795+#include <linux/unistd.h>
8796
8797 #include <asm/firmware.h>
8798 #include <asm/page.h>
8799@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8800 }
8801 #endif
8802
8803+#ifdef CONFIG_PAX_PAGEEXEC
8804+/*
8805+ * PaX: decide what to do with offenders (regs->nip = fault address)
8806+ *
8807+ * returns 1 when task should be killed
8808+ */
8809+static int pax_handle_fetch_fault(struct pt_regs *regs)
8810+{
8811+ return 1;
8812+}
8813+
8814+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8815+{
8816+ unsigned long i;
8817+
8818+ printk(KERN_ERR "PAX: bytes at PC: ");
8819+ for (i = 0; i < 5; i++) {
8820+ unsigned int c;
8821+ if (get_user(c, (unsigned int __user *)pc+i))
8822+ printk(KERN_CONT "???????? ");
8823+ else
8824+ printk(KERN_CONT "%08x ", c);
8825+ }
8826+ printk("\n");
8827+}
8828+#endif
8829+
8830 /*
8831 * Check whether the instruction at regs->nip is a store using
8832 * an update addressing form which will update r1.
8833@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8834 * indicate errors in DSISR but can validly be set in SRR1.
8835 */
8836 if (trap == 0x400)
8837- error_code &= 0x48200000;
8838+ error_code &= 0x58200000;
8839 else
8840 is_write = error_code & DSISR_ISSTORE;
8841 #else
8842@@ -378,7 +409,7 @@ good_area:
8843 * "undefined". Of those that can be set, this is the only
8844 * one which seems bad.
8845 */
8846- if (error_code & 0x10000000)
8847+ if (error_code & DSISR_GUARDED)
8848 /* Guarded storage error. */
8849 goto bad_area;
8850 #endif /* CONFIG_8xx */
8851@@ -393,7 +424,7 @@ good_area:
8852 * processors use the same I/D cache coherency mechanism
8853 * as embedded.
8854 */
8855- if (error_code & DSISR_PROTFAULT)
8856+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8857 goto bad_area;
8858 #endif /* CONFIG_PPC_STD_MMU */
8859
8860@@ -483,6 +514,23 @@ bad_area:
8861 bad_area_nosemaphore:
8862 /* User mode accesses cause a SIGSEGV */
8863 if (user_mode(regs)) {
8864+
8865+#ifdef CONFIG_PAX_PAGEEXEC
8866+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8867+#ifdef CONFIG_PPC_STD_MMU
8868+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8869+#else
8870+ if (is_exec && regs->nip == address) {
8871+#endif
8872+ switch (pax_handle_fetch_fault(regs)) {
8873+ }
8874+
8875+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8876+ do_group_exit(SIGKILL);
8877+ }
8878+ }
8879+#endif
8880+
8881 _exception(SIGSEGV, regs, code, address);
8882 goto bail;
8883 }
8884diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8885index cb8bdbe..cde4bc7 100644
8886--- a/arch/powerpc/mm/mmap.c
8887+++ b/arch/powerpc/mm/mmap.c
8888@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8889 return sysctl_legacy_va_layout;
8890 }
8891
8892-static unsigned long mmap_rnd(void)
8893+static unsigned long mmap_rnd(struct mm_struct *mm)
8894 {
8895 unsigned long rnd = 0;
8896
8897+#ifdef CONFIG_PAX_RANDMMAP
8898+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8899+#endif
8900+
8901 if (current->flags & PF_RANDOMIZE) {
8902 /* 8MB for 32bit, 1GB for 64bit */
8903 if (is_32bit_task())
8904@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8905 return rnd << PAGE_SHIFT;
8906 }
8907
8908-static inline unsigned long mmap_base(void)
8909+static inline unsigned long mmap_base(struct mm_struct *mm)
8910 {
8911 unsigned long gap = rlimit(RLIMIT_STACK);
8912
8913@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8914 else if (gap > MAX_GAP)
8915 gap = MAX_GAP;
8916
8917- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8918+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8919 }
8920
8921 /*
8922@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8923 */
8924 if (mmap_is_legacy()) {
8925 mm->mmap_base = TASK_UNMAPPED_BASE;
8926+
8927+#ifdef CONFIG_PAX_RANDMMAP
8928+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8929+ mm->mmap_base += mm->delta_mmap;
8930+#endif
8931+
8932 mm->get_unmapped_area = arch_get_unmapped_area;
8933 } else {
8934- mm->mmap_base = mmap_base();
8935+ mm->mmap_base = mmap_base(mm);
8936+
8937+#ifdef CONFIG_PAX_RANDMMAP
8938+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8939+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8940+#endif
8941+
8942 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8943 }
8944 }
8945diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8946index b0c75cc..ef7fb93 100644
8947--- a/arch/powerpc/mm/slice.c
8948+++ b/arch/powerpc/mm/slice.c
8949@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8950 if ((mm->task_size - len) < addr)
8951 return 0;
8952 vma = find_vma(mm, addr);
8953- return (!vma || (addr + len) <= vma->vm_start);
8954+ return check_heap_stack_gap(vma, addr, len, 0);
8955 }
8956
8957 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8958@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8959 info.align_offset = 0;
8960
8961 addr = TASK_UNMAPPED_BASE;
8962+
8963+#ifdef CONFIG_PAX_RANDMMAP
8964+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8965+ addr += mm->delta_mmap;
8966+#endif
8967+
8968 while (addr < TASK_SIZE) {
8969 info.low_limit = addr;
8970 if (!slice_scan_available(addr, available, 1, &addr))
8971@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8972 if (fixed && addr > (mm->task_size - len))
8973 return -ENOMEM;
8974
8975+#ifdef CONFIG_PAX_RANDMMAP
8976+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8977+ addr = 0;
8978+#endif
8979+
8980 /* If hint, make sure it matches our alignment restrictions */
8981 if (!fixed && addr) {
8982 addr = _ALIGN_UP(addr, 1ul << pshift);
8983diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8984index 4278acf..67fd0e6 100644
8985--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8986+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8987@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8988 }
8989
8990 static struct pci_ops scc_pciex_pci_ops = {
8991- scc_pciex_read_config,
8992- scc_pciex_write_config,
8993+ .read = scc_pciex_read_config,
8994+ .write = scc_pciex_write_config,
8995 };
8996
8997 static void pciex_clear_intr_all(unsigned int __iomem *base)
8998diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8999index 9098692..3d54cd1 100644
9000--- a/arch/powerpc/platforms/cell/spufs/file.c
9001+++ b/arch/powerpc/platforms/cell/spufs/file.c
9002@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9003 return VM_FAULT_NOPAGE;
9004 }
9005
9006-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9007+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9008 unsigned long address,
9009- void *buf, int len, int write)
9010+ void *buf, size_t len, int write)
9011 {
9012 struct spu_context *ctx = vma->vm_file->private_data;
9013 unsigned long offset = address - vma->vm_start;
9014diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9015index 1d47061..0714963 100644
9016--- a/arch/s390/include/asm/atomic.h
9017+++ b/arch/s390/include/asm/atomic.h
9018@@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9019 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9020 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9021
9022+#define atomic64_read_unchecked(v) atomic64_read(v)
9023+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9024+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9025+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9026+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9027+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9028+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9029+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9030+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9031+
9032 #define smp_mb__before_atomic_dec() smp_mb()
9033 #define smp_mb__after_atomic_dec() smp_mb()
9034 #define smp_mb__before_atomic_inc() smp_mb()
9035diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9036index 4d7ccac..d03d0ad 100644
9037--- a/arch/s390/include/asm/cache.h
9038+++ b/arch/s390/include/asm/cache.h
9039@@ -9,8 +9,10 @@
9040 #ifndef __ARCH_S390_CACHE_H
9041 #define __ARCH_S390_CACHE_H
9042
9043-#define L1_CACHE_BYTES 256
9044+#include <linux/const.h>
9045+
9046 #define L1_CACHE_SHIFT 8
9047+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9048 #define NET_SKB_PAD 32
9049
9050 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9051diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9052index 78f4f87..598ce39 100644
9053--- a/arch/s390/include/asm/elf.h
9054+++ b/arch/s390/include/asm/elf.h
9055@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9056 the loader. We need to make sure that it is out of the way of the program
9057 that it will "exec", and that there is sufficient room for the brk. */
9058
9059-extern unsigned long randomize_et_dyn(unsigned long base);
9060-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9061+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9062+
9063+#ifdef CONFIG_PAX_ASLR
9064+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9065+
9066+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9067+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9068+#endif
9069
9070 /* This yields a mask that user programs can use to figure out what
9071 instruction set this CPU supports. */
9072@@ -222,9 +228,6 @@ struct linux_binprm;
9073 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9074 int arch_setup_additional_pages(struct linux_binprm *, int);
9075
9076-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9077-#define arch_randomize_brk arch_randomize_brk
9078-
9079 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9080
9081 #endif
9082diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9083index c4a93d6..4d2a9b4 100644
9084--- a/arch/s390/include/asm/exec.h
9085+++ b/arch/s390/include/asm/exec.h
9086@@ -7,6 +7,6 @@
9087 #ifndef __ASM_EXEC_H
9088 #define __ASM_EXEC_H
9089
9090-extern unsigned long arch_align_stack(unsigned long sp);
9091+#define arch_align_stack(x) ((x) & ~0xfUL)
9092
9093 #endif /* __ASM_EXEC_H */
9094diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9095index 79330af..254cf37 100644
9096--- a/arch/s390/include/asm/uaccess.h
9097+++ b/arch/s390/include/asm/uaccess.h
9098@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9099 __range_ok((unsigned long)(addr), (size)); \
9100 })
9101
9102+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9103 #define access_ok(type, addr, size) __access_ok(addr, size)
9104
9105 /*
9106@@ -245,6 +246,10 @@ static inline unsigned long __must_check
9107 copy_to_user(void __user *to, const void *from, unsigned long n)
9108 {
9109 might_fault();
9110+
9111+ if ((long)n < 0)
9112+ return n;
9113+
9114 return __copy_to_user(to, from, n);
9115 }
9116
9117@@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9118 static inline unsigned long __must_check
9119 __copy_from_user(void *to, const void __user *from, unsigned long n)
9120 {
9121+ if ((long)n < 0)
9122+ return n;
9123+
9124 return uaccess.copy_from_user(n, from, to);
9125 }
9126
9127@@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9128 static inline unsigned long __must_check
9129 copy_from_user(void *to, const void __user *from, unsigned long n)
9130 {
9131- unsigned int sz = __compiletime_object_size(to);
9132+ size_t sz = __compiletime_object_size(to);
9133
9134 might_fault();
9135- if (unlikely(sz != -1 && sz < n)) {
9136+
9137+ if ((long)n < 0)
9138+ return n;
9139+
9140+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9141 copy_from_user_overflow();
9142 return n;
9143 }
9144diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9145index b89b591..fd9609d 100644
9146--- a/arch/s390/kernel/module.c
9147+++ b/arch/s390/kernel/module.c
9148@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9149
9150 /* Increase core size by size of got & plt and set start
9151 offsets for got and plt. */
9152- me->core_size = ALIGN(me->core_size, 4);
9153- me->arch.got_offset = me->core_size;
9154- me->core_size += me->arch.got_size;
9155- me->arch.plt_offset = me->core_size;
9156- me->core_size += me->arch.plt_size;
9157+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9158+ me->arch.got_offset = me->core_size_rw;
9159+ me->core_size_rw += me->arch.got_size;
9160+ me->arch.plt_offset = me->core_size_rx;
9161+ me->core_size_rx += me->arch.plt_size;
9162 return 0;
9163 }
9164
9165@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9166 if (info->got_initialized == 0) {
9167 Elf_Addr *gotent;
9168
9169- gotent = me->module_core + me->arch.got_offset +
9170+ gotent = me->module_core_rw + me->arch.got_offset +
9171 info->got_offset;
9172 *gotent = val;
9173 info->got_initialized = 1;
9174@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9175 rc = apply_rela_bits(loc, val, 0, 64, 0);
9176 else if (r_type == R_390_GOTENT ||
9177 r_type == R_390_GOTPLTENT) {
9178- val += (Elf_Addr) me->module_core - loc;
9179+ val += (Elf_Addr) me->module_core_rw - loc;
9180 rc = apply_rela_bits(loc, val, 1, 32, 1);
9181 }
9182 break;
9183@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9184 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9185 if (info->plt_initialized == 0) {
9186 unsigned int *ip;
9187- ip = me->module_core + me->arch.plt_offset +
9188+ ip = me->module_core_rx + me->arch.plt_offset +
9189 info->plt_offset;
9190 #ifndef CONFIG_64BIT
9191 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9192@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9193 val - loc + 0xffffUL < 0x1ffffeUL) ||
9194 (r_type == R_390_PLT32DBL &&
9195 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9196- val = (Elf_Addr) me->module_core +
9197+ val = (Elf_Addr) me->module_core_rx +
9198 me->arch.plt_offset +
9199 info->plt_offset;
9200 val += rela->r_addend - loc;
9201@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9202 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9203 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9204 val = val + rela->r_addend -
9205- ((Elf_Addr) me->module_core + me->arch.got_offset);
9206+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9207 if (r_type == R_390_GOTOFF16)
9208 rc = apply_rela_bits(loc, val, 0, 16, 0);
9209 else if (r_type == R_390_GOTOFF32)
9210@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9211 break;
9212 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9213 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9214- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9215+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9216 rela->r_addend - loc;
9217 if (r_type == R_390_GOTPC)
9218 rc = apply_rela_bits(loc, val, 1, 32, 0);
9219diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9220index dd14532..1dfc145 100644
9221--- a/arch/s390/kernel/process.c
9222+++ b/arch/s390/kernel/process.c
9223@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9224 }
9225 return 0;
9226 }
9227-
9228-unsigned long arch_align_stack(unsigned long sp)
9229-{
9230- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9231- sp -= get_random_int() & ~PAGE_MASK;
9232- return sp & ~0xf;
9233-}
9234-
9235-static inline unsigned long brk_rnd(void)
9236-{
9237- /* 8MB for 32bit, 1GB for 64bit */
9238- if (is_32bit_task())
9239- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9240- else
9241- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9242-}
9243-
9244-unsigned long arch_randomize_brk(struct mm_struct *mm)
9245-{
9246- unsigned long ret;
9247-
9248- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9249- return (ret > mm->brk) ? ret : mm->brk;
9250-}
9251-
9252-unsigned long randomize_et_dyn(unsigned long base)
9253-{
9254- unsigned long ret;
9255-
9256- if (!(current->flags & PF_RANDOMIZE))
9257- return base;
9258- ret = PAGE_ALIGN(base + brk_rnd());
9259- return (ret > base) ? ret : base;
9260-}
9261diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9262index 9b436c2..54fbf0a 100644
9263--- a/arch/s390/mm/mmap.c
9264+++ b/arch/s390/mm/mmap.c
9265@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9266 */
9267 if (mmap_is_legacy()) {
9268 mm->mmap_base = mmap_base_legacy();
9269+
9270+#ifdef CONFIG_PAX_RANDMMAP
9271+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9272+ mm->mmap_base += mm->delta_mmap;
9273+#endif
9274+
9275 mm->get_unmapped_area = arch_get_unmapped_area;
9276 } else {
9277 mm->mmap_base = mmap_base();
9278+
9279+#ifdef CONFIG_PAX_RANDMMAP
9280+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9281+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9282+#endif
9283+
9284 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9285 }
9286 }
9287@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9288 */
9289 if (mmap_is_legacy()) {
9290 mm->mmap_base = mmap_base_legacy();
9291+
9292+#ifdef CONFIG_PAX_RANDMMAP
9293+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9294+ mm->mmap_base += mm->delta_mmap;
9295+#endif
9296+
9297 mm->get_unmapped_area = s390_get_unmapped_area;
9298 } else {
9299 mm->mmap_base = mmap_base();
9300+
9301+#ifdef CONFIG_PAX_RANDMMAP
9302+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9303+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9304+#endif
9305+
9306 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9307 }
9308 }
9309diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9310index ae3d59f..f65f075 100644
9311--- a/arch/score/include/asm/cache.h
9312+++ b/arch/score/include/asm/cache.h
9313@@ -1,7 +1,9 @@
9314 #ifndef _ASM_SCORE_CACHE_H
9315 #define _ASM_SCORE_CACHE_H
9316
9317+#include <linux/const.h>
9318+
9319 #define L1_CACHE_SHIFT 4
9320-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9321+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9322
9323 #endif /* _ASM_SCORE_CACHE_H */
9324diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9325index f9f3cd5..58ff438 100644
9326--- a/arch/score/include/asm/exec.h
9327+++ b/arch/score/include/asm/exec.h
9328@@ -1,6 +1,6 @@
9329 #ifndef _ASM_SCORE_EXEC_H
9330 #define _ASM_SCORE_EXEC_H
9331
9332-extern unsigned long arch_align_stack(unsigned long sp);
9333+#define arch_align_stack(x) (x)
9334
9335 #endif /* _ASM_SCORE_EXEC_H */
9336diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9337index a1519ad3..e8ac1ff 100644
9338--- a/arch/score/kernel/process.c
9339+++ b/arch/score/kernel/process.c
9340@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9341
9342 return task_pt_regs(task)->cp0_epc;
9343 }
9344-
9345-unsigned long arch_align_stack(unsigned long sp)
9346-{
9347- return sp;
9348-}
9349diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9350index ef9e555..331bd29 100644
9351--- a/arch/sh/include/asm/cache.h
9352+++ b/arch/sh/include/asm/cache.h
9353@@ -9,10 +9,11 @@
9354 #define __ASM_SH_CACHE_H
9355 #ifdef __KERNEL__
9356
9357+#include <linux/const.h>
9358 #include <linux/init.h>
9359 #include <cpu/cache.h>
9360
9361-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9362+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9363
9364 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9365
9366diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9367index 6777177..cb5e44f 100644
9368--- a/arch/sh/mm/mmap.c
9369+++ b/arch/sh/mm/mmap.c
9370@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9371 struct mm_struct *mm = current->mm;
9372 struct vm_area_struct *vma;
9373 int do_colour_align;
9374+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9375 struct vm_unmapped_area_info info;
9376
9377 if (flags & MAP_FIXED) {
9378@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9379 if (filp || (flags & MAP_SHARED))
9380 do_colour_align = 1;
9381
9382+#ifdef CONFIG_PAX_RANDMMAP
9383+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9384+#endif
9385+
9386 if (addr) {
9387 if (do_colour_align)
9388 addr = COLOUR_ALIGN(addr, pgoff);
9389@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9390 addr = PAGE_ALIGN(addr);
9391
9392 vma = find_vma(mm, addr);
9393- if (TASK_SIZE - len >= addr &&
9394- (!vma || addr + len <= vma->vm_start))
9395+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9396 return addr;
9397 }
9398
9399 info.flags = 0;
9400 info.length = len;
9401- info.low_limit = TASK_UNMAPPED_BASE;
9402+ info.low_limit = mm->mmap_base;
9403 info.high_limit = TASK_SIZE;
9404 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9405 info.align_offset = pgoff << PAGE_SHIFT;
9406@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9407 struct mm_struct *mm = current->mm;
9408 unsigned long addr = addr0;
9409 int do_colour_align;
9410+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9411 struct vm_unmapped_area_info info;
9412
9413 if (flags & MAP_FIXED) {
9414@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9415 if (filp || (flags & MAP_SHARED))
9416 do_colour_align = 1;
9417
9418+#ifdef CONFIG_PAX_RANDMMAP
9419+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9420+#endif
9421+
9422 /* requesting a specific address */
9423 if (addr) {
9424 if (do_colour_align)
9425@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9426 addr = PAGE_ALIGN(addr);
9427
9428 vma = find_vma(mm, addr);
9429- if (TASK_SIZE - len >= addr &&
9430- (!vma || addr + len <= vma->vm_start))
9431+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9432 return addr;
9433 }
9434
9435@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9436 VM_BUG_ON(addr != -ENOMEM);
9437 info.flags = 0;
9438 info.low_limit = TASK_UNMAPPED_BASE;
9439+
9440+#ifdef CONFIG_PAX_RANDMMAP
9441+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9442+ info.low_limit += mm->delta_mmap;
9443+#endif
9444+
9445 info.high_limit = TASK_SIZE;
9446 addr = vm_unmapped_area(&info);
9447 }
9448diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9449index be56a24..443328f 100644
9450--- a/arch/sparc/include/asm/atomic_64.h
9451+++ b/arch/sparc/include/asm/atomic_64.h
9452@@ -14,18 +14,40 @@
9453 #define ATOMIC64_INIT(i) { (i) }
9454
9455 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9456+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9457+{
9458+ return v->counter;
9459+}
9460 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9461+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9462+{
9463+ return v->counter;
9464+}
9465
9466 #define atomic_set(v, i) (((v)->counter) = i)
9467+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9468+{
9469+ v->counter = i;
9470+}
9471 #define atomic64_set(v, i) (((v)->counter) = i)
9472+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9473+{
9474+ v->counter = i;
9475+}
9476
9477 extern void atomic_add(int, atomic_t *);
9478+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9479 extern void atomic64_add(long, atomic64_t *);
9480+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9481 extern void atomic_sub(int, atomic_t *);
9482+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9483 extern void atomic64_sub(long, atomic64_t *);
9484+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9485
9486 extern int atomic_add_ret(int, atomic_t *);
9487+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9488 extern long atomic64_add_ret(long, atomic64_t *);
9489+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9490 extern int atomic_sub_ret(int, atomic_t *);
9491 extern long atomic64_sub_ret(long, atomic64_t *);
9492
9493@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9494 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9495
9496 #define atomic_inc_return(v) atomic_add_ret(1, v)
9497+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9498+{
9499+ return atomic_add_ret_unchecked(1, v);
9500+}
9501 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9502+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9503+{
9504+ return atomic64_add_ret_unchecked(1, v);
9505+}
9506
9507 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9508 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9509
9510 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9511+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9512+{
9513+ return atomic_add_ret_unchecked(i, v);
9514+}
9515 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9516+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9517+{
9518+ return atomic64_add_ret_unchecked(i, v);
9519+}
9520
9521 /*
9522 * atomic_inc_and_test - increment and test
9523@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9524 * other cases.
9525 */
9526 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9527+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9528+{
9529+ return atomic_inc_return_unchecked(v) == 0;
9530+}
9531 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9532
9533 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9534@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9535 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9536
9537 #define atomic_inc(v) atomic_add(1, v)
9538+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9539+{
9540+ atomic_add_unchecked(1, v);
9541+}
9542 #define atomic64_inc(v) atomic64_add(1, v)
9543+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9544+{
9545+ atomic64_add_unchecked(1, v);
9546+}
9547
9548 #define atomic_dec(v) atomic_sub(1, v)
9549+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9550+{
9551+ atomic_sub_unchecked(1, v);
9552+}
9553 #define atomic64_dec(v) atomic64_sub(1, v)
9554+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9555+{
9556+ atomic64_sub_unchecked(1, v);
9557+}
9558
9559 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9560 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9561
9562 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9563+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9564+{
9565+ return cmpxchg(&v->counter, old, new);
9566+}
9567 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9568+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9569+{
9570+ return xchg(&v->counter, new);
9571+}
9572
9573 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9574 {
9575- int c, old;
9576+ int c, old, new;
9577 c = atomic_read(v);
9578 for (;;) {
9579- if (unlikely(c == (u)))
9580+ if (unlikely(c == u))
9581 break;
9582- old = atomic_cmpxchg((v), c, c + (a));
9583+
9584+ asm volatile("addcc %2, %0, %0\n"
9585+
9586+#ifdef CONFIG_PAX_REFCOUNT
9587+ "tvs %%icc, 6\n"
9588+#endif
9589+
9590+ : "=r" (new)
9591+ : "0" (c), "ir" (a)
9592+ : "cc");
9593+
9594+ old = atomic_cmpxchg(v, c, new);
9595 if (likely(old == c))
9596 break;
9597 c = old;
9598@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9599 #define atomic64_cmpxchg(v, o, n) \
9600 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9601 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9602+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9603+{
9604+ return xchg(&v->counter, new);
9605+}
9606
9607 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9608 {
9609- long c, old;
9610+ long c, old, new;
9611 c = atomic64_read(v);
9612 for (;;) {
9613- if (unlikely(c == (u)))
9614+ if (unlikely(c == u))
9615 break;
9616- old = atomic64_cmpxchg((v), c, c + (a));
9617+
9618+ asm volatile("addcc %2, %0, %0\n"
9619+
9620+#ifdef CONFIG_PAX_REFCOUNT
9621+ "tvs %%xcc, 6\n"
9622+#endif
9623+
9624+ : "=r" (new)
9625+ : "0" (c), "ir" (a)
9626+ : "cc");
9627+
9628+ old = atomic64_cmpxchg(v, c, new);
9629 if (likely(old == c))
9630 break;
9631 c = old;
9632 }
9633- return c != (u);
9634+ return c != u;
9635 }
9636
9637 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9638diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9639index 5bb6991..5c2132e 100644
9640--- a/arch/sparc/include/asm/cache.h
9641+++ b/arch/sparc/include/asm/cache.h
9642@@ -7,10 +7,12 @@
9643 #ifndef _SPARC_CACHE_H
9644 #define _SPARC_CACHE_H
9645
9646+#include <linux/const.h>
9647+
9648 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9649
9650 #define L1_CACHE_SHIFT 5
9651-#define L1_CACHE_BYTES 32
9652+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9653
9654 #ifdef CONFIG_SPARC32
9655 #define SMP_CACHE_BYTES_SHIFT 5
9656diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9657index a24e41f..47677ff 100644
9658--- a/arch/sparc/include/asm/elf_32.h
9659+++ b/arch/sparc/include/asm/elf_32.h
9660@@ -114,6 +114,13 @@ typedef struct {
9661
9662 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9663
9664+#ifdef CONFIG_PAX_ASLR
9665+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9666+
9667+#define PAX_DELTA_MMAP_LEN 16
9668+#define PAX_DELTA_STACK_LEN 16
9669+#endif
9670+
9671 /* This yields a mask that user programs can use to figure out what
9672 instruction set this cpu supports. This can NOT be done in userspace
9673 on Sparc. */
9674diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9675index 370ca1e..d4f4a98 100644
9676--- a/arch/sparc/include/asm/elf_64.h
9677+++ b/arch/sparc/include/asm/elf_64.h
9678@@ -189,6 +189,13 @@ typedef struct {
9679 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9680 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9681
9682+#ifdef CONFIG_PAX_ASLR
9683+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9684+
9685+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9686+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9687+#endif
9688+
9689 extern unsigned long sparc64_elf_hwcap;
9690 #define ELF_HWCAP sparc64_elf_hwcap
9691
9692diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9693index 9b1c36d..209298b 100644
9694--- a/arch/sparc/include/asm/pgalloc_32.h
9695+++ b/arch/sparc/include/asm/pgalloc_32.h
9696@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9697 }
9698
9699 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9700+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9701
9702 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9703 unsigned long address)
9704diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9705index bcfe063..b333142 100644
9706--- a/arch/sparc/include/asm/pgalloc_64.h
9707+++ b/arch/sparc/include/asm/pgalloc_64.h
9708@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9709 }
9710
9711 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9712+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9713
9714 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9715 {
9716diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9717index 59ba6f6..4518128 100644
9718--- a/arch/sparc/include/asm/pgtable.h
9719+++ b/arch/sparc/include/asm/pgtable.h
9720@@ -5,4 +5,8 @@
9721 #else
9722 #include <asm/pgtable_32.h>
9723 #endif
9724+
9725+#define ktla_ktva(addr) (addr)
9726+#define ktva_ktla(addr) (addr)
9727+
9728 #endif
9729diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9730index 502f632..da1917f 100644
9731--- a/arch/sparc/include/asm/pgtable_32.h
9732+++ b/arch/sparc/include/asm/pgtable_32.h
9733@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9734 #define PAGE_SHARED SRMMU_PAGE_SHARED
9735 #define PAGE_COPY SRMMU_PAGE_COPY
9736 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9737+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9738+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9739+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9740 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9741
9742 /* Top-level page directory - dummy used by init-mm.
9743@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9744
9745 /* xwr */
9746 #define __P000 PAGE_NONE
9747-#define __P001 PAGE_READONLY
9748-#define __P010 PAGE_COPY
9749-#define __P011 PAGE_COPY
9750+#define __P001 PAGE_READONLY_NOEXEC
9751+#define __P010 PAGE_COPY_NOEXEC
9752+#define __P011 PAGE_COPY_NOEXEC
9753 #define __P100 PAGE_READONLY
9754 #define __P101 PAGE_READONLY
9755 #define __P110 PAGE_COPY
9756 #define __P111 PAGE_COPY
9757
9758 #define __S000 PAGE_NONE
9759-#define __S001 PAGE_READONLY
9760-#define __S010 PAGE_SHARED
9761-#define __S011 PAGE_SHARED
9762+#define __S001 PAGE_READONLY_NOEXEC
9763+#define __S010 PAGE_SHARED_NOEXEC
9764+#define __S011 PAGE_SHARED_NOEXEC
9765 #define __S100 PAGE_READONLY
9766 #define __S101 PAGE_READONLY
9767 #define __S110 PAGE_SHARED
9768diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
9769index 0f9e945..a949e55 100644
9770--- a/arch/sparc/include/asm/pgtable_64.h
9771+++ b/arch/sparc/include/asm/pgtable_64.h
9772@@ -71,6 +71,23 @@
9773
9774 #include <linux/sched.h>
9775
9776+extern unsigned long sparc64_valid_addr_bitmap[];
9777+
9778+/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
9779+static inline bool __kern_addr_valid(unsigned long paddr)
9780+{
9781+ if ((paddr >> MAX_PHYS_ADDRESS_BITS) != 0UL)
9782+ return false;
9783+ return test_bit(paddr >> ILOG2_4MB, sparc64_valid_addr_bitmap);
9784+}
9785+
9786+static inline bool kern_addr_valid(unsigned long addr)
9787+{
9788+ unsigned long paddr = __pa(addr);
9789+
9790+ return __kern_addr_valid(paddr);
9791+}
9792+
9793 /* Entries per page directory level. */
9794 #define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
9795 #define PTRS_PER_PMD (1UL << PMD_BITS)
9796@@ -79,9 +96,12 @@
9797 /* Kernel has a separate 44bit address space. */
9798 #define FIRST_USER_ADDRESS 0
9799
9800-#define pte_ERROR(e) __builtin_trap()
9801-#define pmd_ERROR(e) __builtin_trap()
9802-#define pgd_ERROR(e) __builtin_trap()
9803+#define pmd_ERROR(e) \
9804+ pr_err("%s:%d: bad pmd %p(%016lx) seen at (%pS)\n", \
9805+ __FILE__, __LINE__, &(e), pmd_val(e), __builtin_return_address(0))
9806+#define pgd_ERROR(e) \
9807+ pr_err("%s:%d: bad pgd %p(%016lx) seen at (%pS)\n", \
9808+ __FILE__, __LINE__, &(e), pgd_val(e), __builtin_return_address(0))
9809
9810 #endif /* !(__ASSEMBLY__) */
9811
9812@@ -633,7 +653,7 @@ static inline unsigned long pmd_large(pmd_t pmd)
9813 {
9814 pte_t pte = __pte(pmd_val(pmd));
9815
9816- return (pte_val(pte) & _PAGE_PMD_HUGE) && pte_present(pte);
9817+ return pte_val(pte) & _PAGE_PMD_HUGE;
9818 }
9819
9820 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
9821@@ -719,20 +739,6 @@ static inline pmd_t pmd_mkwrite(pmd_t pmd)
9822 return __pmd(pte_val(pte));
9823 }
9824
9825-static inline pmd_t pmd_mknotpresent(pmd_t pmd)
9826-{
9827- unsigned long mask;
9828-
9829- if (tlb_type == hypervisor)
9830- mask = _PAGE_PRESENT_4V;
9831- else
9832- mask = _PAGE_PRESENT_4U;
9833-
9834- pmd_val(pmd) &= ~mask;
9835-
9836- return pmd;
9837-}
9838-
9839 static inline pmd_t pmd_mksplitting(pmd_t pmd)
9840 {
9841 pte_t pte = __pte(pmd_val(pmd));
9842@@ -757,6 +763,20 @@ static inline int pmd_present(pmd_t pmd)
9843
9844 #define pmd_none(pmd) (!pmd_val(pmd))
9845
9846+/* pmd_bad() is only called on non-trans-huge PMDs. Our encoding is
9847+ * very simple, it's just the physical address. PTE tables are of
9848+ * size PAGE_SIZE so make sure the sub-PAGE_SIZE bits are clear and
9849+ * the top bits outside of the range of any physical address size we
9850+ * support are clear as well. We also validate the physical itself.
9851+ */
9852+#define pmd_bad(pmd) ((pmd_val(pmd) & ~PAGE_MASK) || \
9853+ !__kern_addr_valid(pmd_val(pmd)))
9854+
9855+#define pud_none(pud) (!pud_val(pud))
9856+
9857+#define pud_bad(pud) ((pud_val(pud) & ~PAGE_MASK) || \
9858+ !__kern_addr_valid(pud_val(pud)))
9859+
9860 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
9861 extern void set_pmd_at(struct mm_struct *mm, unsigned long addr,
9862 pmd_t *pmdp, pmd_t pmd);
9863@@ -790,10 +810,7 @@ static inline unsigned long __pmd_page(pmd_t pmd)
9864 #define pud_page_vaddr(pud) \
9865 ((unsigned long) __va(pud_val(pud)))
9866 #define pud_page(pud) virt_to_page((void *)pud_page_vaddr(pud))
9867-#define pmd_bad(pmd) (0)
9868 #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0UL)
9869-#define pud_none(pud) (!pud_val(pud))
9870-#define pud_bad(pud) (0)
9871 #define pud_present(pud) (pud_val(pud) != 0U)
9872 #define pud_clear(pudp) (pud_val(*(pudp)) = 0UL)
9873
9874@@ -893,6 +910,10 @@ extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);
9875 extern void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,
9876 pmd_t *pmd);
9877
9878+#define __HAVE_ARCH_PMDP_INVALIDATE
9879+extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
9880+ pmd_t *pmdp);
9881+
9882 #define __HAVE_ARCH_PGTABLE_DEPOSIT
9883 extern void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
9884 pgtable_t pgtable);
9885@@ -919,18 +940,6 @@ extern unsigned long pte_file(pte_t);
9886 extern pte_t pgoff_to_pte(unsigned long);
9887 #define PTE_FILE_MAX_BITS (64UL - PAGE_SHIFT - 1UL)
9888
9889-extern unsigned long sparc64_valid_addr_bitmap[];
9890-
9891-/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
9892-static inline bool kern_addr_valid(unsigned long addr)
9893-{
9894- unsigned long paddr = __pa(addr);
9895-
9896- if ((paddr >> 41UL) != 0UL)
9897- return false;
9898- return test_bit(paddr >> 22, sparc64_valid_addr_bitmap);
9899-}
9900-
9901 extern int page_in_phys_avail(unsigned long paddr);
9902
9903 /*
9904diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9905index 79da178..c2eede8 100644
9906--- a/arch/sparc/include/asm/pgtsrmmu.h
9907+++ b/arch/sparc/include/asm/pgtsrmmu.h
9908@@ -115,6 +115,11 @@
9909 SRMMU_EXEC | SRMMU_REF)
9910 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9911 SRMMU_EXEC | SRMMU_REF)
9912+
9913+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9914+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9915+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9916+
9917 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9918 SRMMU_DIRTY | SRMMU_REF)
9919
9920diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9921index 9689176..63c18ea 100644
9922--- a/arch/sparc/include/asm/spinlock_64.h
9923+++ b/arch/sparc/include/asm/spinlock_64.h
9924@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9925
9926 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9927
9928-static void inline arch_read_lock(arch_rwlock_t *lock)
9929+static inline void arch_read_lock(arch_rwlock_t *lock)
9930 {
9931 unsigned long tmp1, tmp2;
9932
9933 __asm__ __volatile__ (
9934 "1: ldsw [%2], %0\n"
9935 " brlz,pn %0, 2f\n"
9936-"4: add %0, 1, %1\n"
9937+"4: addcc %0, 1, %1\n"
9938+
9939+#ifdef CONFIG_PAX_REFCOUNT
9940+" tvs %%icc, 6\n"
9941+#endif
9942+
9943 " cas [%2], %0, %1\n"
9944 " cmp %0, %1\n"
9945 " bne,pn %%icc, 1b\n"
9946@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9947 " .previous"
9948 : "=&r" (tmp1), "=&r" (tmp2)
9949 : "r" (lock)
9950- : "memory");
9951+ : "memory", "cc");
9952 }
9953
9954-static int inline arch_read_trylock(arch_rwlock_t *lock)
9955+static inline int arch_read_trylock(arch_rwlock_t *lock)
9956 {
9957 int tmp1, tmp2;
9958
9959@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9960 "1: ldsw [%2], %0\n"
9961 " brlz,a,pn %0, 2f\n"
9962 " mov 0, %0\n"
9963-" add %0, 1, %1\n"
9964+" addcc %0, 1, %1\n"
9965+
9966+#ifdef CONFIG_PAX_REFCOUNT
9967+" tvs %%icc, 6\n"
9968+#endif
9969+
9970 " cas [%2], %0, %1\n"
9971 " cmp %0, %1\n"
9972 " bne,pn %%icc, 1b\n"
9973@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9974 return tmp1;
9975 }
9976
9977-static void inline arch_read_unlock(arch_rwlock_t *lock)
9978+static inline void arch_read_unlock(arch_rwlock_t *lock)
9979 {
9980 unsigned long tmp1, tmp2;
9981
9982 __asm__ __volatile__(
9983 "1: lduw [%2], %0\n"
9984-" sub %0, 1, %1\n"
9985+" subcc %0, 1, %1\n"
9986+
9987+#ifdef CONFIG_PAX_REFCOUNT
9988+" tvs %%icc, 6\n"
9989+#endif
9990+
9991 " cas [%2], %0, %1\n"
9992 " cmp %0, %1\n"
9993 " bne,pn %%xcc, 1b\n"
9994@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9995 : "memory");
9996 }
9997
9998-static void inline arch_write_lock(arch_rwlock_t *lock)
9999+static inline void arch_write_lock(arch_rwlock_t *lock)
10000 {
10001 unsigned long mask, tmp1, tmp2;
10002
10003@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10004 : "memory");
10005 }
10006
10007-static void inline arch_write_unlock(arch_rwlock_t *lock)
10008+static inline void arch_write_unlock(arch_rwlock_t *lock)
10009 {
10010 __asm__ __volatile__(
10011 " stw %%g0, [%0]"
10012@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10013 : "memory");
10014 }
10015
10016-static int inline arch_write_trylock(arch_rwlock_t *lock)
10017+static inline int arch_write_trylock(arch_rwlock_t *lock)
10018 {
10019 unsigned long mask, tmp1, tmp2, result;
10020
10021diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10022index 96efa7a..16858bf 100644
10023--- a/arch/sparc/include/asm/thread_info_32.h
10024+++ b/arch/sparc/include/asm/thread_info_32.h
10025@@ -49,6 +49,8 @@ struct thread_info {
10026 unsigned long w_saved;
10027
10028 struct restart_block restart_block;
10029+
10030+ unsigned long lowest_stack;
10031 };
10032
10033 /*
10034diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10035index a5f01ac..703b554 100644
10036--- a/arch/sparc/include/asm/thread_info_64.h
10037+++ b/arch/sparc/include/asm/thread_info_64.h
10038@@ -63,6 +63,8 @@ struct thread_info {
10039 struct pt_regs *kern_una_regs;
10040 unsigned int kern_una_insn;
10041
10042+ unsigned long lowest_stack;
10043+
10044 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10045 };
10046
10047@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10048 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10049 /* flag bit 4 is available */
10050 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10051-/* flag bit 6 is available */
10052+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10053 #define TIF_32BIT 7 /* 32-bit binary */
10054 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10055 #define TIF_SECCOMP 9 /* secure computing */
10056 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10057 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10058+
10059 /* NOTE: Thread flags >= 12 should be ones we have no interest
10060 * in using in assembly, else we can't use the mask as
10061 * an immediate value in instructions such as andcc.
10062@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10063 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10064 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10065 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10066+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10067
10068 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10069 _TIF_DO_NOTIFY_RESUME_MASK | \
10070 _TIF_NEED_RESCHED)
10071 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10072
10073+#define _TIF_WORK_SYSCALL \
10074+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10075+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10076+
10077+
10078 /*
10079 * Thread-synchronous status.
10080 *
10081diff --git a/arch/sparc/include/asm/tsb.h b/arch/sparc/include/asm/tsb.h
10082index 2230f80..90916f9 100644
10083--- a/arch/sparc/include/asm/tsb.h
10084+++ b/arch/sparc/include/asm/tsb.h
10085@@ -171,7 +171,8 @@ extern struct tsb_phys_patch_entry __tsb_phys_patch, __tsb_phys_patch_end;
10086 andcc REG1, REG2, %g0; \
10087 be,pt %xcc, 700f; \
10088 sethi %hi(4 * 1024 * 1024), REG2; \
10089- andn REG1, REG2, REG1; \
10090+ brgez,pn REG1, FAIL_LABEL; \
10091+ andn REG1, REG2, REG1; \
10092 and VADDR, REG2, REG2; \
10093 brlz,pt REG1, PTE_LABEL; \
10094 or REG1, REG2, REG1; \
10095diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10096index 0167d26..767bb0c 100644
10097--- a/arch/sparc/include/asm/uaccess.h
10098+++ b/arch/sparc/include/asm/uaccess.h
10099@@ -1,5 +1,6 @@
10100 #ifndef ___ASM_SPARC_UACCESS_H
10101 #define ___ASM_SPARC_UACCESS_H
10102+
10103 #if defined(__sparc__) && defined(__arch64__)
10104 #include <asm/uaccess_64.h>
10105 #else
10106diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10107index 53a28dd..50c38c3 100644
10108--- a/arch/sparc/include/asm/uaccess_32.h
10109+++ b/arch/sparc/include/asm/uaccess_32.h
10110@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
10111
10112 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10113 {
10114- if (n && __access_ok((unsigned long) to, n))
10115+ if ((long)n < 0)
10116+ return n;
10117+
10118+ if (n && __access_ok((unsigned long) to, n)) {
10119+ if (!__builtin_constant_p(n))
10120+ check_object_size(from, n, true);
10121 return __copy_user(to, (__force void __user *) from, n);
10122- else
10123+ } else
10124 return n;
10125 }
10126
10127 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10128 {
10129+ if ((long)n < 0)
10130+ return n;
10131+
10132+ if (!__builtin_constant_p(n))
10133+ check_object_size(from, n, true);
10134+
10135 return __copy_user(to, (__force void __user *) from, n);
10136 }
10137
10138 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10139 {
10140- if (n && __access_ok((unsigned long) from, n))
10141+ if ((long)n < 0)
10142+ return n;
10143+
10144+ if (n && __access_ok((unsigned long) from, n)) {
10145+ if (!__builtin_constant_p(n))
10146+ check_object_size(to, n, false);
10147 return __copy_user((__force void __user *) to, from, n);
10148- else
10149+ } else
10150 return n;
10151 }
10152
10153 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10154 {
10155+ if ((long)n < 0)
10156+ return n;
10157+
10158 return __copy_user((__force void __user *) to, from, n);
10159 }
10160
10161diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10162index ad7e178..c9e7423 100644
10163--- a/arch/sparc/include/asm/uaccess_64.h
10164+++ b/arch/sparc/include/asm/uaccess_64.h
10165@@ -10,6 +10,7 @@
10166 #include <linux/compiler.h>
10167 #include <linux/string.h>
10168 #include <linux/thread_info.h>
10169+#include <linux/kernel.h>
10170 #include <asm/asi.h>
10171 #include <asm/spitfire.h>
10172 #include <asm-generic/uaccess-unaligned.h>
10173@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10174 static inline unsigned long __must_check
10175 copy_from_user(void *to, const void __user *from, unsigned long size)
10176 {
10177- unsigned long ret = ___copy_from_user(to, from, size);
10178+ unsigned long ret;
10179
10180+ if ((long)size < 0 || size > INT_MAX)
10181+ return size;
10182+
10183+ if (!__builtin_constant_p(size))
10184+ check_object_size(to, size, false);
10185+
10186+ ret = ___copy_from_user(to, from, size);
10187 if (unlikely(ret))
10188 ret = copy_from_user_fixup(to, from, size);
10189
10190@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10191 static inline unsigned long __must_check
10192 copy_to_user(void __user *to, const void *from, unsigned long size)
10193 {
10194- unsigned long ret = ___copy_to_user(to, from, size);
10195+ unsigned long ret;
10196
10197+ if ((long)size < 0 || size > INT_MAX)
10198+ return size;
10199+
10200+ if (!__builtin_constant_p(size))
10201+ check_object_size(from, size, true);
10202+
10203+ ret = ___copy_to_user(to, from, size);
10204 if (unlikely(ret))
10205 ret = copy_to_user_fixup(to, from, size);
10206 return ret;
10207diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10208index d15cc17..d0ae796 100644
10209--- a/arch/sparc/kernel/Makefile
10210+++ b/arch/sparc/kernel/Makefile
10211@@ -4,7 +4,7 @@
10212 #
10213
10214 asflags-y := -ansi
10215-ccflags-y := -Werror
10216+#ccflags-y := -Werror
10217
10218 extra-y := head_$(BITS).o
10219
10220diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10221index 510baec..9ff2607 100644
10222--- a/arch/sparc/kernel/process_32.c
10223+++ b/arch/sparc/kernel/process_32.c
10224@@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10225
10226 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10227 r->psr, r->pc, r->npc, r->y, print_tainted());
10228- printk("PC: <%pS>\n", (void *) r->pc);
10229+ printk("PC: <%pA>\n", (void *) r->pc);
10230 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10231 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10232 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10233 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10234 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10235 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10236- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10237+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10238
10239 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10240 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10241@@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10242 rw = (struct reg_window32 *) fp;
10243 pc = rw->ins[7];
10244 printk("[%08lx : ", pc);
10245- printk("%pS ] ", (void *) pc);
10246+ printk("%pA ] ", (void *) pc);
10247 fp = rw->ins[6];
10248 } while (++count < 16);
10249 printk("\n");
10250diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10251index d7b4967..2edf827 100644
10252--- a/arch/sparc/kernel/process_64.c
10253+++ b/arch/sparc/kernel/process_64.c
10254@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10255 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10256 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10257 if (regs->tstate & TSTATE_PRIV)
10258- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10259+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10260 }
10261
10262 void show_regs(struct pt_regs *regs)
10263@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10264
10265 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10266 regs->tpc, regs->tnpc, regs->y, print_tainted());
10267- printk("TPC: <%pS>\n", (void *) regs->tpc);
10268+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10269 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10270 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10271 regs->u_regs[3]);
10272@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10273 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10274 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10275 regs->u_regs[15]);
10276- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10277+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10278 show_regwindow(regs);
10279 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10280 }
10281@@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10282 ((tp && tp->task) ? tp->task->pid : -1));
10283
10284 if (gp->tstate & TSTATE_PRIV) {
10285- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10286+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10287 (void *) gp->tpc,
10288 (void *) gp->o7,
10289 (void *) gp->i7,
10290diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10291index 79cc0d1..ec62734 100644
10292--- a/arch/sparc/kernel/prom_common.c
10293+++ b/arch/sparc/kernel/prom_common.c
10294@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10295
10296 unsigned int prom_early_allocated __initdata;
10297
10298-static struct of_pdt_ops prom_sparc_ops __initdata = {
10299+static struct of_pdt_ops prom_sparc_ops __initconst = {
10300 .nextprop = prom_common_nextprop,
10301 .getproplen = prom_getproplen,
10302 .getproperty = prom_getproperty,
10303diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10304index c13c9f2..d572c34 100644
10305--- a/arch/sparc/kernel/ptrace_64.c
10306+++ b/arch/sparc/kernel/ptrace_64.c
10307@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10308 return ret;
10309 }
10310
10311+#ifdef CONFIG_GRKERNSEC_SETXID
10312+extern void gr_delayed_cred_worker(void);
10313+#endif
10314+
10315 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10316 {
10317 int ret = 0;
10318@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10319 if (test_thread_flag(TIF_NOHZ))
10320 user_exit();
10321
10322+#ifdef CONFIG_GRKERNSEC_SETXID
10323+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10324+ gr_delayed_cred_worker();
10325+#endif
10326+
10327 if (test_thread_flag(TIF_SYSCALL_TRACE))
10328 ret = tracehook_report_syscall_entry(regs);
10329
10330@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10331 if (test_thread_flag(TIF_NOHZ))
10332 user_exit();
10333
10334+#ifdef CONFIG_GRKERNSEC_SETXID
10335+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10336+ gr_delayed_cred_worker();
10337+#endif
10338+
10339 audit_syscall_exit(regs);
10340
10341 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10342diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10343index b085311..6f885f7 100644
10344--- a/arch/sparc/kernel/smp_64.c
10345+++ b/arch/sparc/kernel/smp_64.c
10346@@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10347 extern unsigned long xcall_flush_dcache_page_spitfire;
10348
10349 #ifdef CONFIG_DEBUG_DCFLUSH
10350-extern atomic_t dcpage_flushes;
10351-extern atomic_t dcpage_flushes_xcall;
10352+extern atomic_unchecked_t dcpage_flushes;
10353+extern atomic_unchecked_t dcpage_flushes_xcall;
10354 #endif
10355
10356 static inline void __local_flush_dcache_page(struct page *page)
10357@@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10358 return;
10359
10360 #ifdef CONFIG_DEBUG_DCFLUSH
10361- atomic_inc(&dcpage_flushes);
10362+ atomic_inc_unchecked(&dcpage_flushes);
10363 #endif
10364
10365 this_cpu = get_cpu();
10366@@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10367 xcall_deliver(data0, __pa(pg_addr),
10368 (u64) pg_addr, cpumask_of(cpu));
10369 #ifdef CONFIG_DEBUG_DCFLUSH
10370- atomic_inc(&dcpage_flushes_xcall);
10371+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10372 #endif
10373 }
10374 }
10375@@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10376 preempt_disable();
10377
10378 #ifdef CONFIG_DEBUG_DCFLUSH
10379- atomic_inc(&dcpage_flushes);
10380+ atomic_inc_unchecked(&dcpage_flushes);
10381 #endif
10382 data0 = 0;
10383 pg_addr = page_address(page);
10384@@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10385 xcall_deliver(data0, __pa(pg_addr),
10386 (u64) pg_addr, cpu_online_mask);
10387 #ifdef CONFIG_DEBUG_DCFLUSH
10388- atomic_inc(&dcpage_flushes_xcall);
10389+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10390 #endif
10391 }
10392 __local_flush_dcache_page(page);
10393diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10394index 3a8d184..49498a8 100644
10395--- a/arch/sparc/kernel/sys_sparc_32.c
10396+++ b/arch/sparc/kernel/sys_sparc_32.c
10397@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10398 if (len > TASK_SIZE - PAGE_SIZE)
10399 return -ENOMEM;
10400 if (!addr)
10401- addr = TASK_UNMAPPED_BASE;
10402+ addr = current->mm->mmap_base;
10403
10404 info.flags = 0;
10405 info.length = len;
10406diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10407index beb0b5a..5a153f7 100644
10408--- a/arch/sparc/kernel/sys_sparc_64.c
10409+++ b/arch/sparc/kernel/sys_sparc_64.c
10410@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10411 struct vm_area_struct * vma;
10412 unsigned long task_size = TASK_SIZE;
10413 int do_color_align;
10414+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10415 struct vm_unmapped_area_info info;
10416
10417 if (flags & MAP_FIXED) {
10418 /* We do not accept a shared mapping if it would violate
10419 * cache aliasing constraints.
10420 */
10421- if ((flags & MAP_SHARED) &&
10422+ if ((filp || (flags & MAP_SHARED)) &&
10423 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10424 return -EINVAL;
10425 return addr;
10426@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10427 if (filp || (flags & MAP_SHARED))
10428 do_color_align = 1;
10429
10430+#ifdef CONFIG_PAX_RANDMMAP
10431+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10432+#endif
10433+
10434 if (addr) {
10435 if (do_color_align)
10436 addr = COLOR_ALIGN(addr, pgoff);
10437@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10438 addr = PAGE_ALIGN(addr);
10439
10440 vma = find_vma(mm, addr);
10441- if (task_size - len >= addr &&
10442- (!vma || addr + len <= vma->vm_start))
10443+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10444 return addr;
10445 }
10446
10447 info.flags = 0;
10448 info.length = len;
10449- info.low_limit = TASK_UNMAPPED_BASE;
10450+ info.low_limit = mm->mmap_base;
10451 info.high_limit = min(task_size, VA_EXCLUDE_START);
10452 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10453 info.align_offset = pgoff << PAGE_SHIFT;
10454+ info.threadstack_offset = offset;
10455 addr = vm_unmapped_area(&info);
10456
10457 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10458 VM_BUG_ON(addr != -ENOMEM);
10459 info.low_limit = VA_EXCLUDE_END;
10460+
10461+#ifdef CONFIG_PAX_RANDMMAP
10462+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10463+ info.low_limit += mm->delta_mmap;
10464+#endif
10465+
10466 info.high_limit = task_size;
10467 addr = vm_unmapped_area(&info);
10468 }
10469@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10470 unsigned long task_size = STACK_TOP32;
10471 unsigned long addr = addr0;
10472 int do_color_align;
10473+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10474 struct vm_unmapped_area_info info;
10475
10476 /* This should only ever run for 32-bit processes. */
10477@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10478 /* We do not accept a shared mapping if it would violate
10479 * cache aliasing constraints.
10480 */
10481- if ((flags & MAP_SHARED) &&
10482+ if ((filp || (flags & MAP_SHARED)) &&
10483 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10484 return -EINVAL;
10485 return addr;
10486@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10487 if (filp || (flags & MAP_SHARED))
10488 do_color_align = 1;
10489
10490+#ifdef CONFIG_PAX_RANDMMAP
10491+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10492+#endif
10493+
10494 /* requesting a specific address */
10495 if (addr) {
10496 if (do_color_align)
10497@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10498 addr = PAGE_ALIGN(addr);
10499
10500 vma = find_vma(mm, addr);
10501- if (task_size - len >= addr &&
10502- (!vma || addr + len <= vma->vm_start))
10503+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10504 return addr;
10505 }
10506
10507@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10508 info.high_limit = mm->mmap_base;
10509 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10510 info.align_offset = pgoff << PAGE_SHIFT;
10511+ info.threadstack_offset = offset;
10512 addr = vm_unmapped_area(&info);
10513
10514 /*
10515@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10516 VM_BUG_ON(addr != -ENOMEM);
10517 info.flags = 0;
10518 info.low_limit = TASK_UNMAPPED_BASE;
10519+
10520+#ifdef CONFIG_PAX_RANDMMAP
10521+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10522+ info.low_limit += mm->delta_mmap;
10523+#endif
10524+
10525 info.high_limit = STACK_TOP32;
10526 addr = vm_unmapped_area(&info);
10527 }
10528@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10529 EXPORT_SYMBOL(get_fb_unmapped_area);
10530
10531 /* Essentially the same as PowerPC. */
10532-static unsigned long mmap_rnd(void)
10533+static unsigned long mmap_rnd(struct mm_struct *mm)
10534 {
10535 unsigned long rnd = 0UL;
10536
10537+#ifdef CONFIG_PAX_RANDMMAP
10538+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10539+#endif
10540+
10541 if (current->flags & PF_RANDOMIZE) {
10542 unsigned long val = get_random_int();
10543 if (test_thread_flag(TIF_32BIT))
10544@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10545
10546 void arch_pick_mmap_layout(struct mm_struct *mm)
10547 {
10548- unsigned long random_factor = mmap_rnd();
10549+ unsigned long random_factor = mmap_rnd(mm);
10550 unsigned long gap;
10551
10552 /*
10553@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10554 gap == RLIM_INFINITY ||
10555 sysctl_legacy_va_layout) {
10556 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10557+
10558+#ifdef CONFIG_PAX_RANDMMAP
10559+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10560+ mm->mmap_base += mm->delta_mmap;
10561+#endif
10562+
10563 mm->get_unmapped_area = arch_get_unmapped_area;
10564 } else {
10565 /* We know it's 32-bit */
10566@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10567 gap = (task_size / 6 * 5);
10568
10569 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10570+
10571+#ifdef CONFIG_PAX_RANDMMAP
10572+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10573+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10574+#endif
10575+
10576 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10577 }
10578 }
10579diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10580index 33a17e7..d87fb1f 100644
10581--- a/arch/sparc/kernel/syscalls.S
10582+++ b/arch/sparc/kernel/syscalls.S
10583@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10584 #endif
10585 .align 32
10586 1: ldx [%g6 + TI_FLAGS], %l5
10587- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10588+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10589 be,pt %icc, rtrap
10590 nop
10591 call syscall_trace_leave
10592@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10593
10594 srl %i3, 0, %o3 ! IEU0
10595 srl %i2, 0, %o2 ! IEU0 Group
10596- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10597+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10598 bne,pn %icc, linux_syscall_trace32 ! CTI
10599 mov %i0, %l5 ! IEU1
10600 5: call %l7 ! CTI Group brk forced
10601@@ -208,7 +208,7 @@ linux_sparc_syscall:
10602
10603 mov %i3, %o3 ! IEU1
10604 mov %i4, %o4 ! IEU0 Group
10605- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10606+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10607 bne,pn %icc, linux_syscall_trace ! CTI Group
10608 mov %i0, %l5 ! IEU0
10609 2: call %l7 ! CTI Group brk forced
10610@@ -223,7 +223,7 @@ ret_sys_call:
10611
10612 cmp %o0, -ERESTART_RESTARTBLOCK
10613 bgeu,pn %xcc, 1f
10614- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10615+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10616 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10617
10618 2:
10619diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10620index 6629829..036032d 100644
10621--- a/arch/sparc/kernel/traps_32.c
10622+++ b/arch/sparc/kernel/traps_32.c
10623@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10624 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10625 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10626
10627+extern void gr_handle_kernel_exploit(void);
10628+
10629 void die_if_kernel(char *str, struct pt_regs *regs)
10630 {
10631 static int die_counter;
10632@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10633 count++ < 30 &&
10634 (((unsigned long) rw) >= PAGE_OFFSET) &&
10635 !(((unsigned long) rw) & 0x7)) {
10636- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10637+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10638 (void *) rw->ins[7]);
10639 rw = (struct reg_window32 *)rw->ins[6];
10640 }
10641 }
10642 printk("Instruction DUMP:");
10643 instruction_dump ((unsigned long *) regs->pc);
10644- if(regs->psr & PSR_PS)
10645+ if(regs->psr & PSR_PS) {
10646+ gr_handle_kernel_exploit();
10647 do_exit(SIGKILL);
10648+ }
10649 do_exit(SIGSEGV);
10650 }
10651
10652diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10653index 4ced92f..965eeed 100644
10654--- a/arch/sparc/kernel/traps_64.c
10655+++ b/arch/sparc/kernel/traps_64.c
10656@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10657 i + 1,
10658 p->trapstack[i].tstate, p->trapstack[i].tpc,
10659 p->trapstack[i].tnpc, p->trapstack[i].tt);
10660- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10661+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10662 }
10663 }
10664
10665@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10666
10667 lvl -= 0x100;
10668 if (regs->tstate & TSTATE_PRIV) {
10669+
10670+#ifdef CONFIG_PAX_REFCOUNT
10671+ if (lvl == 6)
10672+ pax_report_refcount_overflow(regs);
10673+#endif
10674+
10675 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10676 die_if_kernel(buffer, regs);
10677 }
10678@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10679 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10680 {
10681 char buffer[32];
10682-
10683+
10684 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10685 0, lvl, SIGTRAP) == NOTIFY_STOP)
10686 return;
10687
10688+#ifdef CONFIG_PAX_REFCOUNT
10689+ if (lvl == 6)
10690+ pax_report_refcount_overflow(regs);
10691+#endif
10692+
10693 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10694
10695 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10696@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10697 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10698 printk("%s" "ERROR(%d): ",
10699 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10700- printk("TPC<%pS>\n", (void *) regs->tpc);
10701+ printk("TPC<%pA>\n", (void *) regs->tpc);
10702 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10703 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10704 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10705@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10706 smp_processor_id(),
10707 (type & 0x1) ? 'I' : 'D',
10708 regs->tpc);
10709- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10710+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10711 panic("Irrecoverable Cheetah+ parity error.");
10712 }
10713
10714@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10715 smp_processor_id(),
10716 (type & 0x1) ? 'I' : 'D',
10717 regs->tpc);
10718- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10719+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10720 }
10721
10722 struct sun4v_error_entry {
10723@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10724 /*0x38*/u64 reserved_5;
10725 };
10726
10727-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10728-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10729+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10730+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10731
10732 static const char *sun4v_err_type_to_str(u8 type)
10733 {
10734@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10735 }
10736
10737 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10738- int cpu, const char *pfx, atomic_t *ocnt)
10739+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10740 {
10741 u64 *raw_ptr = (u64 *) ent;
10742 u32 attrs;
10743@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10744
10745 show_regs(regs);
10746
10747- if ((cnt = atomic_read(ocnt)) != 0) {
10748- atomic_set(ocnt, 0);
10749+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10750+ atomic_set_unchecked(ocnt, 0);
10751 wmb();
10752 printk("%s: Queue overflowed %d times.\n",
10753 pfx, cnt);
10754@@ -2046,7 +2057,7 @@ out:
10755 */
10756 void sun4v_resum_overflow(struct pt_regs *regs)
10757 {
10758- atomic_inc(&sun4v_resum_oflow_cnt);
10759+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10760 }
10761
10762 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10763@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10764 /* XXX Actually even this can make not that much sense. Perhaps
10765 * XXX we should just pull the plug and panic directly from here?
10766 */
10767- atomic_inc(&sun4v_nonresum_oflow_cnt);
10768+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10769 }
10770
10771 unsigned long sun4v_err_itlb_vaddr;
10772@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10773
10774 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10775 regs->tpc, tl);
10776- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10777+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10778 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10779- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10780+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10781 (void *) regs->u_regs[UREG_I7]);
10782 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10783 "pte[%lx] error[%lx]\n",
10784@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10785
10786 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10787 regs->tpc, tl);
10788- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10789+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10790 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10791- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10792+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10793 (void *) regs->u_regs[UREG_I7]);
10794 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10795 "pte[%lx] error[%lx]\n",
10796@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10797 fp = (unsigned long)sf->fp + STACK_BIAS;
10798 }
10799
10800- printk(" [%016lx] %pS\n", pc, (void *) pc);
10801+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10802 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10803 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10804 int index = tsk->curr_ret_stack;
10805 if (tsk->ret_stack && index >= graph) {
10806 pc = tsk->ret_stack[index - graph].ret;
10807- printk(" [%016lx] %pS\n", pc, (void *) pc);
10808+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10809 graph++;
10810 }
10811 }
10812@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10813 return (struct reg_window *) (fp + STACK_BIAS);
10814 }
10815
10816+extern void gr_handle_kernel_exploit(void);
10817+
10818 void die_if_kernel(char *str, struct pt_regs *regs)
10819 {
10820 static int die_counter;
10821@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10822 while (rw &&
10823 count++ < 30 &&
10824 kstack_valid(tp, (unsigned long) rw)) {
10825- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10826+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10827 (void *) rw->ins[7]);
10828
10829 rw = kernel_stack_up(rw);
10830@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10831 }
10832 user_instruction_dump ((unsigned int __user *) regs->tpc);
10833 }
10834- if (regs->tstate & TSTATE_PRIV)
10835+ if (regs->tstate & TSTATE_PRIV) {
10836+ gr_handle_kernel_exploit();
10837 do_exit(SIGKILL);
10838+ }
10839 do_exit(SIGSEGV);
10840 }
10841 EXPORT_SYMBOL(die_if_kernel);
10842diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10843index 3c1a7cb..9046547 100644
10844--- a/arch/sparc/kernel/unaligned_64.c
10845+++ b/arch/sparc/kernel/unaligned_64.c
10846@@ -166,17 +166,23 @@ static unsigned long *fetch_reg_addr(unsigned int reg, struct pt_regs *regs)
10847 unsigned long compute_effective_address(struct pt_regs *regs,
10848 unsigned int insn, unsigned int rd)
10849 {
10850+ int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
10851 unsigned int rs1 = (insn >> 14) & 0x1f;
10852 unsigned int rs2 = insn & 0x1f;
10853- int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
10854+ unsigned long addr;
10855
10856 if (insn & 0x2000) {
10857 maybe_flush_windows(rs1, 0, rd, from_kernel);
10858- return (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
10859+ addr = (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
10860 } else {
10861 maybe_flush_windows(rs1, rs2, rd, from_kernel);
10862- return (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
10863+ addr = (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
10864 }
10865+
10866+ if (!from_kernel && test_thread_flag(TIF_32BIT))
10867+ addr &= 0xffffffff;
10868+
10869+ return addr;
10870 }
10871
10872 /* This is just to make gcc think die_if_kernel does return... */
10873@@ -289,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
10874 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10875
10876 if (__ratelimit(&ratelimit)) {
10877- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10878+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10879 regs->tpc, (void *) regs->tpc);
10880 }
10881 }
10882diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10883index dbe119b..089c7c1 100644
10884--- a/arch/sparc/lib/Makefile
10885+++ b/arch/sparc/lib/Makefile
10886@@ -2,7 +2,7 @@
10887 #
10888
10889 asflags-y := -ansi -DST_DIV0=0x02
10890-ccflags-y := -Werror
10891+#ccflags-y := -Werror
10892
10893 lib-$(CONFIG_SPARC32) += ashrdi3.o
10894 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10895diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10896index 85c233d..68500e0 100644
10897--- a/arch/sparc/lib/atomic_64.S
10898+++ b/arch/sparc/lib/atomic_64.S
10899@@ -17,7 +17,12 @@
10900 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10901 BACKOFF_SETUP(%o2)
10902 1: lduw [%o1], %g1
10903- add %g1, %o0, %g7
10904+ addcc %g1, %o0, %g7
10905+
10906+#ifdef CONFIG_PAX_REFCOUNT
10907+ tvs %icc, 6
10908+#endif
10909+
10910 cas [%o1], %g1, %g7
10911 cmp %g1, %g7
10912 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10913@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10914 2: BACKOFF_SPIN(%o2, %o3, 1b)
10915 ENDPROC(atomic_add)
10916
10917+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10918+ BACKOFF_SETUP(%o2)
10919+1: lduw [%o1], %g1
10920+ add %g1, %o0, %g7
10921+ cas [%o1], %g1, %g7
10922+ cmp %g1, %g7
10923+ bne,pn %icc, 2f
10924+ nop
10925+ retl
10926+ nop
10927+2: BACKOFF_SPIN(%o2, %o3, 1b)
10928+ENDPROC(atomic_add_unchecked)
10929+
10930 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10931 BACKOFF_SETUP(%o2)
10932 1: lduw [%o1], %g1
10933- sub %g1, %o0, %g7
10934+ subcc %g1, %o0, %g7
10935+
10936+#ifdef CONFIG_PAX_REFCOUNT
10937+ tvs %icc, 6
10938+#endif
10939+
10940 cas [%o1], %g1, %g7
10941 cmp %g1, %g7
10942 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10943@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10944 2: BACKOFF_SPIN(%o2, %o3, 1b)
10945 ENDPROC(atomic_sub)
10946
10947+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10948+ BACKOFF_SETUP(%o2)
10949+1: lduw [%o1], %g1
10950+ sub %g1, %o0, %g7
10951+ cas [%o1], %g1, %g7
10952+ cmp %g1, %g7
10953+ bne,pn %icc, 2f
10954+ nop
10955+ retl
10956+ nop
10957+2: BACKOFF_SPIN(%o2, %o3, 1b)
10958+ENDPROC(atomic_sub_unchecked)
10959+
10960 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10961 BACKOFF_SETUP(%o2)
10962 1: lduw [%o1], %g1
10963- add %g1, %o0, %g7
10964+ addcc %g1, %o0, %g7
10965+
10966+#ifdef CONFIG_PAX_REFCOUNT
10967+ tvs %icc, 6
10968+#endif
10969+
10970 cas [%o1], %g1, %g7
10971 cmp %g1, %g7
10972 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10973@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10974 2: BACKOFF_SPIN(%o2, %o3, 1b)
10975 ENDPROC(atomic_add_ret)
10976
10977+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10978+ BACKOFF_SETUP(%o2)
10979+1: lduw [%o1], %g1
10980+ addcc %g1, %o0, %g7
10981+ cas [%o1], %g1, %g7
10982+ cmp %g1, %g7
10983+ bne,pn %icc, 2f
10984+ add %g7, %o0, %g7
10985+ sra %g7, 0, %o0
10986+ retl
10987+ nop
10988+2: BACKOFF_SPIN(%o2, %o3, 1b)
10989+ENDPROC(atomic_add_ret_unchecked)
10990+
10991 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10992 BACKOFF_SETUP(%o2)
10993 1: lduw [%o1], %g1
10994- sub %g1, %o0, %g7
10995+ subcc %g1, %o0, %g7
10996+
10997+#ifdef CONFIG_PAX_REFCOUNT
10998+ tvs %icc, 6
10999+#endif
11000+
11001 cas [%o1], %g1, %g7
11002 cmp %g1, %g7
11003 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11004@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11005 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11006 BACKOFF_SETUP(%o2)
11007 1: ldx [%o1], %g1
11008- add %g1, %o0, %g7
11009+ addcc %g1, %o0, %g7
11010+
11011+#ifdef CONFIG_PAX_REFCOUNT
11012+ tvs %xcc, 6
11013+#endif
11014+
11015 casx [%o1], %g1, %g7
11016 cmp %g1, %g7
11017 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11018@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11019 2: BACKOFF_SPIN(%o2, %o3, 1b)
11020 ENDPROC(atomic64_add)
11021
11022+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11023+ BACKOFF_SETUP(%o2)
11024+1: ldx [%o1], %g1
11025+ addcc %g1, %o0, %g7
11026+ casx [%o1], %g1, %g7
11027+ cmp %g1, %g7
11028+ bne,pn %xcc, 2f
11029+ nop
11030+ retl
11031+ nop
11032+2: BACKOFF_SPIN(%o2, %o3, 1b)
11033+ENDPROC(atomic64_add_unchecked)
11034+
11035 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11036 BACKOFF_SETUP(%o2)
11037 1: ldx [%o1], %g1
11038- sub %g1, %o0, %g7
11039+ subcc %g1, %o0, %g7
11040+
11041+#ifdef CONFIG_PAX_REFCOUNT
11042+ tvs %xcc, 6
11043+#endif
11044+
11045 casx [%o1], %g1, %g7
11046 cmp %g1, %g7
11047 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11048@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11049 2: BACKOFF_SPIN(%o2, %o3, 1b)
11050 ENDPROC(atomic64_sub)
11051
11052+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11053+ BACKOFF_SETUP(%o2)
11054+1: ldx [%o1], %g1
11055+ subcc %g1, %o0, %g7
11056+ casx [%o1], %g1, %g7
11057+ cmp %g1, %g7
11058+ bne,pn %xcc, 2f
11059+ nop
11060+ retl
11061+ nop
11062+2: BACKOFF_SPIN(%o2, %o3, 1b)
11063+ENDPROC(atomic64_sub_unchecked)
11064+
11065 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11066 BACKOFF_SETUP(%o2)
11067 1: ldx [%o1], %g1
11068- add %g1, %o0, %g7
11069+ addcc %g1, %o0, %g7
11070+
11071+#ifdef CONFIG_PAX_REFCOUNT
11072+ tvs %xcc, 6
11073+#endif
11074+
11075 casx [%o1], %g1, %g7
11076 cmp %g1, %g7
11077 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11078@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11079 2: BACKOFF_SPIN(%o2, %o3, 1b)
11080 ENDPROC(atomic64_add_ret)
11081
11082+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11083+ BACKOFF_SETUP(%o2)
11084+1: ldx [%o1], %g1
11085+ addcc %g1, %o0, %g7
11086+ casx [%o1], %g1, %g7
11087+ cmp %g1, %g7
11088+ bne,pn %xcc, 2f
11089+ add %g7, %o0, %g7
11090+ mov %g7, %o0
11091+ retl
11092+ nop
11093+2: BACKOFF_SPIN(%o2, %o3, 1b)
11094+ENDPROC(atomic64_add_ret_unchecked)
11095+
11096 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11097 BACKOFF_SETUP(%o2)
11098 1: ldx [%o1], %g1
11099- sub %g1, %o0, %g7
11100+ subcc %g1, %o0, %g7
11101+
11102+#ifdef CONFIG_PAX_REFCOUNT
11103+ tvs %xcc, 6
11104+#endif
11105+
11106 casx [%o1], %g1, %g7
11107 cmp %g1, %g7
11108 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11109diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11110index 323335b..ed85ea2 100644
11111--- a/arch/sparc/lib/ksyms.c
11112+++ b/arch/sparc/lib/ksyms.c
11113@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11114
11115 /* Atomic counter implementation. */
11116 EXPORT_SYMBOL(atomic_add);
11117+EXPORT_SYMBOL(atomic_add_unchecked);
11118 EXPORT_SYMBOL(atomic_add_ret);
11119+EXPORT_SYMBOL(atomic_add_ret_unchecked);
11120 EXPORT_SYMBOL(atomic_sub);
11121+EXPORT_SYMBOL(atomic_sub_unchecked);
11122 EXPORT_SYMBOL(atomic_sub_ret);
11123 EXPORT_SYMBOL(atomic64_add);
11124+EXPORT_SYMBOL(atomic64_add_unchecked);
11125 EXPORT_SYMBOL(atomic64_add_ret);
11126+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11127 EXPORT_SYMBOL(atomic64_sub);
11128+EXPORT_SYMBOL(atomic64_sub_unchecked);
11129 EXPORT_SYMBOL(atomic64_sub_ret);
11130 EXPORT_SYMBOL(atomic64_dec_if_positive);
11131
11132diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11133index 30c3ecc..736f015 100644
11134--- a/arch/sparc/mm/Makefile
11135+++ b/arch/sparc/mm/Makefile
11136@@ -2,7 +2,7 @@
11137 #
11138
11139 asflags-y := -ansi
11140-ccflags-y := -Werror
11141+#ccflags-y := -Werror
11142
11143 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11144 obj-y += fault_$(BITS).o
11145diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11146index 59dbd46..1dd7f5e 100644
11147--- a/arch/sparc/mm/fault_32.c
11148+++ b/arch/sparc/mm/fault_32.c
11149@@ -21,6 +21,9 @@
11150 #include <linux/perf_event.h>
11151 #include <linux/interrupt.h>
11152 #include <linux/kdebug.h>
11153+#include <linux/slab.h>
11154+#include <linux/pagemap.h>
11155+#include <linux/compiler.h>
11156
11157 #include <asm/page.h>
11158 #include <asm/pgtable.h>
11159@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11160 return safe_compute_effective_address(regs, insn);
11161 }
11162
11163+#ifdef CONFIG_PAX_PAGEEXEC
11164+#ifdef CONFIG_PAX_DLRESOLVE
11165+static void pax_emuplt_close(struct vm_area_struct *vma)
11166+{
11167+ vma->vm_mm->call_dl_resolve = 0UL;
11168+}
11169+
11170+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11171+{
11172+ unsigned int *kaddr;
11173+
11174+ vmf->page = alloc_page(GFP_HIGHUSER);
11175+ if (!vmf->page)
11176+ return VM_FAULT_OOM;
11177+
11178+ kaddr = kmap(vmf->page);
11179+ memset(kaddr, 0, PAGE_SIZE);
11180+ kaddr[0] = 0x9DE3BFA8U; /* save */
11181+ flush_dcache_page(vmf->page);
11182+ kunmap(vmf->page);
11183+ return VM_FAULT_MAJOR;
11184+}
11185+
11186+static const struct vm_operations_struct pax_vm_ops = {
11187+ .close = pax_emuplt_close,
11188+ .fault = pax_emuplt_fault
11189+};
11190+
11191+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11192+{
11193+ int ret;
11194+
11195+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11196+ vma->vm_mm = current->mm;
11197+ vma->vm_start = addr;
11198+ vma->vm_end = addr + PAGE_SIZE;
11199+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11200+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11201+ vma->vm_ops = &pax_vm_ops;
11202+
11203+ ret = insert_vm_struct(current->mm, vma);
11204+ if (ret)
11205+ return ret;
11206+
11207+ ++current->mm->total_vm;
11208+ return 0;
11209+}
11210+#endif
11211+
11212+/*
11213+ * PaX: decide what to do with offenders (regs->pc = fault address)
11214+ *
11215+ * returns 1 when task should be killed
11216+ * 2 when patched PLT trampoline was detected
11217+ * 3 when unpatched PLT trampoline was detected
11218+ */
11219+static int pax_handle_fetch_fault(struct pt_regs *regs)
11220+{
11221+
11222+#ifdef CONFIG_PAX_EMUPLT
11223+ int err;
11224+
11225+ do { /* PaX: patched PLT emulation #1 */
11226+ unsigned int sethi1, sethi2, jmpl;
11227+
11228+ err = get_user(sethi1, (unsigned int *)regs->pc);
11229+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11230+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11231+
11232+ if (err)
11233+ break;
11234+
11235+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11236+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11237+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11238+ {
11239+ unsigned int addr;
11240+
11241+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11242+ addr = regs->u_regs[UREG_G1];
11243+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11244+ regs->pc = addr;
11245+ regs->npc = addr+4;
11246+ return 2;
11247+ }
11248+ } while (0);
11249+
11250+ do { /* PaX: patched PLT emulation #2 */
11251+ unsigned int ba;
11252+
11253+ err = get_user(ba, (unsigned int *)regs->pc);
11254+
11255+ if (err)
11256+ break;
11257+
11258+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11259+ unsigned int addr;
11260+
11261+ if ((ba & 0xFFC00000U) == 0x30800000U)
11262+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11263+ else
11264+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11265+ regs->pc = addr;
11266+ regs->npc = addr+4;
11267+ return 2;
11268+ }
11269+ } while (0);
11270+
11271+ do { /* PaX: patched PLT emulation #3 */
11272+ unsigned int sethi, bajmpl, nop;
11273+
11274+ err = get_user(sethi, (unsigned int *)regs->pc);
11275+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11276+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11277+
11278+ if (err)
11279+ break;
11280+
11281+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11282+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11283+ nop == 0x01000000U)
11284+ {
11285+ unsigned int addr;
11286+
11287+ addr = (sethi & 0x003FFFFFU) << 10;
11288+ regs->u_regs[UREG_G1] = addr;
11289+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11290+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11291+ else
11292+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11293+ regs->pc = addr;
11294+ regs->npc = addr+4;
11295+ return 2;
11296+ }
11297+ } while (0);
11298+
11299+ do { /* PaX: unpatched PLT emulation step 1 */
11300+ unsigned int sethi, ba, nop;
11301+
11302+ err = get_user(sethi, (unsigned int *)regs->pc);
11303+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11304+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11305+
11306+ if (err)
11307+ break;
11308+
11309+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11310+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11311+ nop == 0x01000000U)
11312+ {
11313+ unsigned int addr, save, call;
11314+
11315+ if ((ba & 0xFFC00000U) == 0x30800000U)
11316+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11317+ else
11318+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11319+
11320+ err = get_user(save, (unsigned int *)addr);
11321+ err |= get_user(call, (unsigned int *)(addr+4));
11322+ err |= get_user(nop, (unsigned int *)(addr+8));
11323+ if (err)
11324+ break;
11325+
11326+#ifdef CONFIG_PAX_DLRESOLVE
11327+ if (save == 0x9DE3BFA8U &&
11328+ (call & 0xC0000000U) == 0x40000000U &&
11329+ nop == 0x01000000U)
11330+ {
11331+ struct vm_area_struct *vma;
11332+ unsigned long call_dl_resolve;
11333+
11334+ down_read(&current->mm->mmap_sem);
11335+ call_dl_resolve = current->mm->call_dl_resolve;
11336+ up_read(&current->mm->mmap_sem);
11337+ if (likely(call_dl_resolve))
11338+ goto emulate;
11339+
11340+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11341+
11342+ down_write(&current->mm->mmap_sem);
11343+ if (current->mm->call_dl_resolve) {
11344+ call_dl_resolve = current->mm->call_dl_resolve;
11345+ up_write(&current->mm->mmap_sem);
11346+ if (vma)
11347+ kmem_cache_free(vm_area_cachep, vma);
11348+ goto emulate;
11349+ }
11350+
11351+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11352+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11353+ up_write(&current->mm->mmap_sem);
11354+ if (vma)
11355+ kmem_cache_free(vm_area_cachep, vma);
11356+ return 1;
11357+ }
11358+
11359+ if (pax_insert_vma(vma, call_dl_resolve)) {
11360+ up_write(&current->mm->mmap_sem);
11361+ kmem_cache_free(vm_area_cachep, vma);
11362+ return 1;
11363+ }
11364+
11365+ current->mm->call_dl_resolve = call_dl_resolve;
11366+ up_write(&current->mm->mmap_sem);
11367+
11368+emulate:
11369+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11370+ regs->pc = call_dl_resolve;
11371+ regs->npc = addr+4;
11372+ return 3;
11373+ }
11374+#endif
11375+
11376+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11377+ if ((save & 0xFFC00000U) == 0x05000000U &&
11378+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11379+ nop == 0x01000000U)
11380+ {
11381+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11382+ regs->u_regs[UREG_G2] = addr + 4;
11383+ addr = (save & 0x003FFFFFU) << 10;
11384+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11385+ regs->pc = addr;
11386+ regs->npc = addr+4;
11387+ return 3;
11388+ }
11389+ }
11390+ } while (0);
11391+
11392+ do { /* PaX: unpatched PLT emulation step 2 */
11393+ unsigned int save, call, nop;
11394+
11395+ err = get_user(save, (unsigned int *)(regs->pc-4));
11396+ err |= get_user(call, (unsigned int *)regs->pc);
11397+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11398+ if (err)
11399+ break;
11400+
11401+ if (save == 0x9DE3BFA8U &&
11402+ (call & 0xC0000000U) == 0x40000000U &&
11403+ nop == 0x01000000U)
11404+ {
11405+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11406+
11407+ regs->u_regs[UREG_RETPC] = regs->pc;
11408+ regs->pc = dl_resolve;
11409+ regs->npc = dl_resolve+4;
11410+ return 3;
11411+ }
11412+ } while (0);
11413+#endif
11414+
11415+ return 1;
11416+}
11417+
11418+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11419+{
11420+ unsigned long i;
11421+
11422+ printk(KERN_ERR "PAX: bytes at PC: ");
11423+ for (i = 0; i < 8; i++) {
11424+ unsigned int c;
11425+ if (get_user(c, (unsigned int *)pc+i))
11426+ printk(KERN_CONT "???????? ");
11427+ else
11428+ printk(KERN_CONT "%08x ", c);
11429+ }
11430+ printk("\n");
11431+}
11432+#endif
11433+
11434 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11435 int text_fault)
11436 {
11437@@ -229,6 +503,24 @@ good_area:
11438 if (!(vma->vm_flags & VM_WRITE))
11439 goto bad_area;
11440 } else {
11441+
11442+#ifdef CONFIG_PAX_PAGEEXEC
11443+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11444+ up_read(&mm->mmap_sem);
11445+ switch (pax_handle_fetch_fault(regs)) {
11446+
11447+#ifdef CONFIG_PAX_EMUPLT
11448+ case 2:
11449+ case 3:
11450+ return;
11451+#endif
11452+
11453+ }
11454+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11455+ do_group_exit(SIGKILL);
11456+ }
11457+#endif
11458+
11459 /* Allow reads even for write-only mappings */
11460 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11461 goto bad_area;
11462diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11463index 69bb818..3542236 100644
11464--- a/arch/sparc/mm/fault_64.c
11465+++ b/arch/sparc/mm/fault_64.c
11466@@ -22,6 +22,9 @@
11467 #include <linux/kdebug.h>
11468 #include <linux/percpu.h>
11469 #include <linux/context_tracking.h>
11470+#include <linux/slab.h>
11471+#include <linux/pagemap.h>
11472+#include <linux/compiler.h>
11473
11474 #include <asm/page.h>
11475 #include <asm/pgtable.h>
11476@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11477 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11478 regs->tpc);
11479 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11480- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11481+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11482 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11483 dump_stack();
11484 unhandled_fault(regs->tpc, current, regs);
11485@@ -96,38 +99,51 @@ static unsigned int get_user_insn(unsigned long tpc)
11486 pte_t *ptep, pte;
11487 unsigned long pa;
11488 u32 insn = 0;
11489- unsigned long pstate;
11490
11491- if (pgd_none(*pgdp))
11492- goto outret;
11493+ if (pgd_none(*pgdp) || unlikely(pgd_bad(*pgdp)))
11494+ goto out;
11495 pudp = pud_offset(pgdp, tpc);
11496- if (pud_none(*pudp))
11497- goto outret;
11498- pmdp = pmd_offset(pudp, tpc);
11499- if (pmd_none(*pmdp))
11500- goto outret;
11501+ if (pud_none(*pudp) || unlikely(pud_bad(*pudp)))
11502+ goto out;
11503
11504 /* This disables preemption for us as well. */
11505- __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
11506- __asm__ __volatile__("wrpr %0, %1, %%pstate"
11507- : : "r" (pstate), "i" (PSTATE_IE));
11508- ptep = pte_offset_map(pmdp, tpc);
11509- pte = *ptep;
11510- if (!pte_present(pte))
11511- goto out;
11512+ local_irq_disable();
11513
11514- pa = (pte_pfn(pte) << PAGE_SHIFT);
11515- pa += (tpc & ~PAGE_MASK);
11516+ pmdp = pmd_offset(pudp, tpc);
11517+ if (pmd_none(*pmdp) || unlikely(pmd_bad(*pmdp)))
11518+ goto out_irq_enable;
11519
11520- /* Use phys bypass so we don't pollute dtlb/dcache. */
11521- __asm__ __volatile__("lduwa [%1] %2, %0"
11522- : "=r" (insn)
11523- : "r" (pa), "i" (ASI_PHYS_USE_EC));
11524+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
11525+ if (pmd_trans_huge(*pmdp)) {
11526+ if (pmd_trans_splitting(*pmdp))
11527+ goto out_irq_enable;
11528
11529+ pa = pmd_pfn(*pmdp) << PAGE_SHIFT;
11530+ pa += tpc & ~HPAGE_MASK;
11531+
11532+ /* Use phys bypass so we don't pollute dtlb/dcache. */
11533+ __asm__ __volatile__("lduwa [%1] %2, %0"
11534+ : "=r" (insn)
11535+ : "r" (pa), "i" (ASI_PHYS_USE_EC));
11536+ } else
11537+#endif
11538+ {
11539+ ptep = pte_offset_map(pmdp, tpc);
11540+ pte = *ptep;
11541+ if (pte_present(pte)) {
11542+ pa = (pte_pfn(pte) << PAGE_SHIFT);
11543+ pa += (tpc & ~PAGE_MASK);
11544+
11545+ /* Use phys bypass so we don't pollute dtlb/dcache. */
11546+ __asm__ __volatile__("lduwa [%1] %2, %0"
11547+ : "=r" (insn)
11548+ : "r" (pa), "i" (ASI_PHYS_USE_EC));
11549+ }
11550+ pte_unmap(ptep);
11551+ }
11552+out_irq_enable:
11553+ local_irq_enable();
11554 out:
11555- pte_unmap(ptep);
11556- __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
11557-outret:
11558 return insn;
11559 }
11560
11561@@ -153,7 +169,8 @@ show_signal_msg(struct pt_regs *regs, int sig, int code,
11562 }
11563
11564 static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11565- unsigned int insn, int fault_code)
11566+ unsigned long fault_addr, unsigned int insn,
11567+ int fault_code)
11568 {
11569 unsigned long addr;
11570 siginfo_t info;
11571@@ -161,10 +178,18 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11572 info.si_code = code;
11573 info.si_signo = sig;
11574 info.si_errno = 0;
11575- if (fault_code & FAULT_CODE_ITLB)
11576+ if (fault_code & FAULT_CODE_ITLB) {
11577 addr = regs->tpc;
11578- else
11579- addr = compute_effective_address(regs, insn, 0);
11580+ } else {
11581+ /* If we were able to probe the faulting instruction, use it
11582+ * to compute a precise fault address. Otherwise use the fault
11583+ * time provided address which may only have page granularity.
11584+ */
11585+ if (insn)
11586+ addr = compute_effective_address(regs, insn, 0);
11587+ else
11588+ addr = fault_addr;
11589+ }
11590 info.si_addr = (void __user *) addr;
11591 info.si_trapno = 0;
11592
11593@@ -239,7 +264,7 @@ static void __kprobes do_kernel_fault(struct pt_regs *regs, int si_code,
11594 /* The si_code was set to make clear whether
11595 * this was a SEGV_MAPERR or SEGV_ACCERR fault.
11596 */
11597- do_fault_siginfo(si_code, SIGSEGV, regs, insn, fault_code);
11598+ do_fault_siginfo(si_code, SIGSEGV, regs, address, insn, fault_code);
11599 return;
11600 }
11601
11602@@ -271,6 +296,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11603 show_regs(regs);
11604 }
11605
11606+#ifdef CONFIG_PAX_PAGEEXEC
11607+#ifdef CONFIG_PAX_DLRESOLVE
11608+static void pax_emuplt_close(struct vm_area_struct *vma)
11609+{
11610+ vma->vm_mm->call_dl_resolve = 0UL;
11611+}
11612+
11613+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11614+{
11615+ unsigned int *kaddr;
11616+
11617+ vmf->page = alloc_page(GFP_HIGHUSER);
11618+ if (!vmf->page)
11619+ return VM_FAULT_OOM;
11620+
11621+ kaddr = kmap(vmf->page);
11622+ memset(kaddr, 0, PAGE_SIZE);
11623+ kaddr[0] = 0x9DE3BFA8U; /* save */
11624+ flush_dcache_page(vmf->page);
11625+ kunmap(vmf->page);
11626+ return VM_FAULT_MAJOR;
11627+}
11628+
11629+static const struct vm_operations_struct pax_vm_ops = {
11630+ .close = pax_emuplt_close,
11631+ .fault = pax_emuplt_fault
11632+};
11633+
11634+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11635+{
11636+ int ret;
11637+
11638+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11639+ vma->vm_mm = current->mm;
11640+ vma->vm_start = addr;
11641+ vma->vm_end = addr + PAGE_SIZE;
11642+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11643+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11644+ vma->vm_ops = &pax_vm_ops;
11645+
11646+ ret = insert_vm_struct(current->mm, vma);
11647+ if (ret)
11648+ return ret;
11649+
11650+ ++current->mm->total_vm;
11651+ return 0;
11652+}
11653+#endif
11654+
11655+/*
11656+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11657+ *
11658+ * returns 1 when task should be killed
11659+ * 2 when patched PLT trampoline was detected
11660+ * 3 when unpatched PLT trampoline was detected
11661+ */
11662+static int pax_handle_fetch_fault(struct pt_regs *regs)
11663+{
11664+
11665+#ifdef CONFIG_PAX_EMUPLT
11666+ int err;
11667+
11668+ do { /* PaX: patched PLT emulation #1 */
11669+ unsigned int sethi1, sethi2, jmpl;
11670+
11671+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11672+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11673+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11674+
11675+ if (err)
11676+ break;
11677+
11678+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11679+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11680+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11681+ {
11682+ unsigned long addr;
11683+
11684+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11685+ addr = regs->u_regs[UREG_G1];
11686+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11687+
11688+ if (test_thread_flag(TIF_32BIT))
11689+ addr &= 0xFFFFFFFFUL;
11690+
11691+ regs->tpc = addr;
11692+ regs->tnpc = addr+4;
11693+ return 2;
11694+ }
11695+ } while (0);
11696+
11697+ do { /* PaX: patched PLT emulation #2 */
11698+ unsigned int ba;
11699+
11700+ err = get_user(ba, (unsigned int *)regs->tpc);
11701+
11702+ if (err)
11703+ break;
11704+
11705+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11706+ unsigned long addr;
11707+
11708+ if ((ba & 0xFFC00000U) == 0x30800000U)
11709+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11710+ else
11711+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11712+
11713+ if (test_thread_flag(TIF_32BIT))
11714+ addr &= 0xFFFFFFFFUL;
11715+
11716+ regs->tpc = addr;
11717+ regs->tnpc = addr+4;
11718+ return 2;
11719+ }
11720+ } while (0);
11721+
11722+ do { /* PaX: patched PLT emulation #3 */
11723+ unsigned int sethi, bajmpl, nop;
11724+
11725+ err = get_user(sethi, (unsigned int *)regs->tpc);
11726+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11727+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11728+
11729+ if (err)
11730+ break;
11731+
11732+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11733+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11734+ nop == 0x01000000U)
11735+ {
11736+ unsigned long addr;
11737+
11738+ addr = (sethi & 0x003FFFFFU) << 10;
11739+ regs->u_regs[UREG_G1] = addr;
11740+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11741+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11742+ else
11743+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11744+
11745+ if (test_thread_flag(TIF_32BIT))
11746+ addr &= 0xFFFFFFFFUL;
11747+
11748+ regs->tpc = addr;
11749+ regs->tnpc = addr+4;
11750+ return 2;
11751+ }
11752+ } while (0);
11753+
11754+ do { /* PaX: patched PLT emulation #4 */
11755+ unsigned int sethi, mov1, call, mov2;
11756+
11757+ err = get_user(sethi, (unsigned int *)regs->tpc);
11758+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11759+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11760+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11761+
11762+ if (err)
11763+ break;
11764+
11765+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11766+ mov1 == 0x8210000FU &&
11767+ (call & 0xC0000000U) == 0x40000000U &&
11768+ mov2 == 0x9E100001U)
11769+ {
11770+ unsigned long addr;
11771+
11772+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11773+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11774+
11775+ if (test_thread_flag(TIF_32BIT))
11776+ addr &= 0xFFFFFFFFUL;
11777+
11778+ regs->tpc = addr;
11779+ regs->tnpc = addr+4;
11780+ return 2;
11781+ }
11782+ } while (0);
11783+
11784+ do { /* PaX: patched PLT emulation #5 */
11785+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11786+
11787+ err = get_user(sethi, (unsigned int *)regs->tpc);
11788+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11789+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11790+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11791+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11792+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11793+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11794+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11795+
11796+ if (err)
11797+ break;
11798+
11799+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11800+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11801+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11802+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11803+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11804+ sllx == 0x83287020U &&
11805+ jmpl == 0x81C04005U &&
11806+ nop == 0x01000000U)
11807+ {
11808+ unsigned long addr;
11809+
11810+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11811+ regs->u_regs[UREG_G1] <<= 32;
11812+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11813+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11814+ regs->tpc = addr;
11815+ regs->tnpc = addr+4;
11816+ return 2;
11817+ }
11818+ } while (0);
11819+
11820+ do { /* PaX: patched PLT emulation #6 */
11821+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11822+
11823+ err = get_user(sethi, (unsigned int *)regs->tpc);
11824+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11825+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11826+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11827+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11828+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11829+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11830+
11831+ if (err)
11832+ break;
11833+
11834+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11835+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11836+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11837+ sllx == 0x83287020U &&
11838+ (or & 0xFFFFE000U) == 0x8A116000U &&
11839+ jmpl == 0x81C04005U &&
11840+ nop == 0x01000000U)
11841+ {
11842+ unsigned long addr;
11843+
11844+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11845+ regs->u_regs[UREG_G1] <<= 32;
11846+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11847+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11848+ regs->tpc = addr;
11849+ regs->tnpc = addr+4;
11850+ return 2;
11851+ }
11852+ } while (0);
11853+
11854+ do { /* PaX: unpatched PLT emulation step 1 */
11855+ unsigned int sethi, ba, nop;
11856+
11857+ err = get_user(sethi, (unsigned int *)regs->tpc);
11858+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11859+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11860+
11861+ if (err)
11862+ break;
11863+
11864+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11865+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11866+ nop == 0x01000000U)
11867+ {
11868+ unsigned long addr;
11869+ unsigned int save, call;
11870+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11871+
11872+ if ((ba & 0xFFC00000U) == 0x30800000U)
11873+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11874+ else
11875+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11876+
11877+ if (test_thread_flag(TIF_32BIT))
11878+ addr &= 0xFFFFFFFFUL;
11879+
11880+ err = get_user(save, (unsigned int *)addr);
11881+ err |= get_user(call, (unsigned int *)(addr+4));
11882+ err |= get_user(nop, (unsigned int *)(addr+8));
11883+ if (err)
11884+ break;
11885+
11886+#ifdef CONFIG_PAX_DLRESOLVE
11887+ if (save == 0x9DE3BFA8U &&
11888+ (call & 0xC0000000U) == 0x40000000U &&
11889+ nop == 0x01000000U)
11890+ {
11891+ struct vm_area_struct *vma;
11892+ unsigned long call_dl_resolve;
11893+
11894+ down_read(&current->mm->mmap_sem);
11895+ call_dl_resolve = current->mm->call_dl_resolve;
11896+ up_read(&current->mm->mmap_sem);
11897+ if (likely(call_dl_resolve))
11898+ goto emulate;
11899+
11900+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11901+
11902+ down_write(&current->mm->mmap_sem);
11903+ if (current->mm->call_dl_resolve) {
11904+ call_dl_resolve = current->mm->call_dl_resolve;
11905+ up_write(&current->mm->mmap_sem);
11906+ if (vma)
11907+ kmem_cache_free(vm_area_cachep, vma);
11908+ goto emulate;
11909+ }
11910+
11911+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11912+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11913+ up_write(&current->mm->mmap_sem);
11914+ if (vma)
11915+ kmem_cache_free(vm_area_cachep, vma);
11916+ return 1;
11917+ }
11918+
11919+ if (pax_insert_vma(vma, call_dl_resolve)) {
11920+ up_write(&current->mm->mmap_sem);
11921+ kmem_cache_free(vm_area_cachep, vma);
11922+ return 1;
11923+ }
11924+
11925+ current->mm->call_dl_resolve = call_dl_resolve;
11926+ up_write(&current->mm->mmap_sem);
11927+
11928+emulate:
11929+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11930+ regs->tpc = call_dl_resolve;
11931+ regs->tnpc = addr+4;
11932+ return 3;
11933+ }
11934+#endif
11935+
11936+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11937+ if ((save & 0xFFC00000U) == 0x05000000U &&
11938+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11939+ nop == 0x01000000U)
11940+ {
11941+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11942+ regs->u_regs[UREG_G2] = addr + 4;
11943+ addr = (save & 0x003FFFFFU) << 10;
11944+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11945+
11946+ if (test_thread_flag(TIF_32BIT))
11947+ addr &= 0xFFFFFFFFUL;
11948+
11949+ regs->tpc = addr;
11950+ regs->tnpc = addr+4;
11951+ return 3;
11952+ }
11953+
11954+ /* PaX: 64-bit PLT stub */
11955+ err = get_user(sethi1, (unsigned int *)addr);
11956+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11957+ err |= get_user(or1, (unsigned int *)(addr+8));
11958+ err |= get_user(or2, (unsigned int *)(addr+12));
11959+ err |= get_user(sllx, (unsigned int *)(addr+16));
11960+ err |= get_user(add, (unsigned int *)(addr+20));
11961+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11962+ err |= get_user(nop, (unsigned int *)(addr+28));
11963+ if (err)
11964+ break;
11965+
11966+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11967+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11968+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11969+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11970+ sllx == 0x89293020U &&
11971+ add == 0x8A010005U &&
11972+ jmpl == 0x89C14000U &&
11973+ nop == 0x01000000U)
11974+ {
11975+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11976+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11977+ regs->u_regs[UREG_G4] <<= 32;
11978+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11979+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11980+ regs->u_regs[UREG_G4] = addr + 24;
11981+ addr = regs->u_regs[UREG_G5];
11982+ regs->tpc = addr;
11983+ regs->tnpc = addr+4;
11984+ return 3;
11985+ }
11986+ }
11987+ } while (0);
11988+
11989+#ifdef CONFIG_PAX_DLRESOLVE
11990+ do { /* PaX: unpatched PLT emulation step 2 */
11991+ unsigned int save, call, nop;
11992+
11993+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11994+ err |= get_user(call, (unsigned int *)regs->tpc);
11995+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11996+ if (err)
11997+ break;
11998+
11999+ if (save == 0x9DE3BFA8U &&
12000+ (call & 0xC0000000U) == 0x40000000U &&
12001+ nop == 0x01000000U)
12002+ {
12003+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12004+
12005+ if (test_thread_flag(TIF_32BIT))
12006+ dl_resolve &= 0xFFFFFFFFUL;
12007+
12008+ regs->u_regs[UREG_RETPC] = regs->tpc;
12009+ regs->tpc = dl_resolve;
12010+ regs->tnpc = dl_resolve+4;
12011+ return 3;
12012+ }
12013+ } while (0);
12014+#endif
12015+
12016+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12017+ unsigned int sethi, ba, nop;
12018+
12019+ err = get_user(sethi, (unsigned int *)regs->tpc);
12020+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12021+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12022+
12023+ if (err)
12024+ break;
12025+
12026+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12027+ (ba & 0xFFF00000U) == 0x30600000U &&
12028+ nop == 0x01000000U)
12029+ {
12030+ unsigned long addr;
12031+
12032+ addr = (sethi & 0x003FFFFFU) << 10;
12033+ regs->u_regs[UREG_G1] = addr;
12034+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12035+
12036+ if (test_thread_flag(TIF_32BIT))
12037+ addr &= 0xFFFFFFFFUL;
12038+
12039+ regs->tpc = addr;
12040+ regs->tnpc = addr+4;
12041+ return 2;
12042+ }
12043+ } while (0);
12044+
12045+#endif
12046+
12047+ return 1;
12048+}
12049+
12050+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12051+{
12052+ unsigned long i;
12053+
12054+ printk(KERN_ERR "PAX: bytes at PC: ");
12055+ for (i = 0; i < 8; i++) {
12056+ unsigned int c;
12057+ if (get_user(c, (unsigned int *)pc+i))
12058+ printk(KERN_CONT "???????? ");
12059+ else
12060+ printk(KERN_CONT "%08x ", c);
12061+ }
12062+ printk("\n");
12063+}
12064+#endif
12065+
12066 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12067 {
12068 enum ctx_state prev_state = exception_enter();
12069@@ -344,6 +829,29 @@ retry:
12070 if (!vma)
12071 goto bad_area;
12072
12073+#ifdef CONFIG_PAX_PAGEEXEC
12074+ /* PaX: detect ITLB misses on non-exec pages */
12075+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12076+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12077+ {
12078+ if (address != regs->tpc)
12079+ goto good_area;
12080+
12081+ up_read(&mm->mmap_sem);
12082+ switch (pax_handle_fetch_fault(regs)) {
12083+
12084+#ifdef CONFIG_PAX_EMUPLT
12085+ case 2:
12086+ case 3:
12087+ return;
12088+#endif
12089+
12090+ }
12091+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12092+ do_group_exit(SIGKILL);
12093+ }
12094+#endif
12095+
12096 /* Pure DTLB misses do not tell us whether the fault causing
12097 * load/store/atomic was a write or not, it only says that there
12098 * was no match. So in such a case we (carefully) read the
12099@@ -525,7 +1033,7 @@ do_sigbus:
12100 * Send a sigbus, regardless of whether we were in kernel
12101 * or user mode.
12102 */
12103- do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, insn, fault_code);
12104+ do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, address, insn, fault_code);
12105
12106 /* Kernel mode? Handle exceptions or die */
12107 if (regs->tstate & TSTATE_PRIV)
12108diff --git a/arch/sparc/mm/gup.c b/arch/sparc/mm/gup.c
12109index c4d3da6..1aed043 100644
12110--- a/arch/sparc/mm/gup.c
12111+++ b/arch/sparc/mm/gup.c
12112@@ -73,7 +73,7 @@ static int gup_huge_pmd(pmd_t *pmdp, pmd_t pmd, unsigned long addr,
12113 struct page *head, *page, *tail;
12114 int refs;
12115
12116- if (!pmd_large(pmd))
12117+ if (!(pmd_val(pmd) & _PAGE_VALID))
12118 return 0;
12119
12120 if (write && !pmd_write(pmd))
12121diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12122index 9bd9ce8..dc84852 100644
12123--- a/arch/sparc/mm/hugetlbpage.c
12124+++ b/arch/sparc/mm/hugetlbpage.c
12125@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12126 unsigned long addr,
12127 unsigned long len,
12128 unsigned long pgoff,
12129- unsigned long flags)
12130+ unsigned long flags,
12131+ unsigned long offset)
12132 {
12133+ struct mm_struct *mm = current->mm;
12134 unsigned long task_size = TASK_SIZE;
12135 struct vm_unmapped_area_info info;
12136
12137@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12138
12139 info.flags = 0;
12140 info.length = len;
12141- info.low_limit = TASK_UNMAPPED_BASE;
12142+ info.low_limit = mm->mmap_base;
12143 info.high_limit = min(task_size, VA_EXCLUDE_START);
12144 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12145 info.align_offset = 0;
12146+ info.threadstack_offset = offset;
12147 addr = vm_unmapped_area(&info);
12148
12149 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12150 VM_BUG_ON(addr != -ENOMEM);
12151 info.low_limit = VA_EXCLUDE_END;
12152+
12153+#ifdef CONFIG_PAX_RANDMMAP
12154+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12155+ info.low_limit += mm->delta_mmap;
12156+#endif
12157+
12158 info.high_limit = task_size;
12159 addr = vm_unmapped_area(&info);
12160 }
12161@@ -55,7 +64,8 @@ static unsigned long
12162 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12163 const unsigned long len,
12164 const unsigned long pgoff,
12165- const unsigned long flags)
12166+ const unsigned long flags,
12167+ const unsigned long offset)
12168 {
12169 struct mm_struct *mm = current->mm;
12170 unsigned long addr = addr0;
12171@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12172 info.high_limit = mm->mmap_base;
12173 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12174 info.align_offset = 0;
12175+ info.threadstack_offset = offset;
12176 addr = vm_unmapped_area(&info);
12177
12178 /*
12179@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12180 VM_BUG_ON(addr != -ENOMEM);
12181 info.flags = 0;
12182 info.low_limit = TASK_UNMAPPED_BASE;
12183+
12184+#ifdef CONFIG_PAX_RANDMMAP
12185+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12186+ info.low_limit += mm->delta_mmap;
12187+#endif
12188+
12189 info.high_limit = STACK_TOP32;
12190 addr = vm_unmapped_area(&info);
12191 }
12192@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12193 struct mm_struct *mm = current->mm;
12194 struct vm_area_struct *vma;
12195 unsigned long task_size = TASK_SIZE;
12196+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12197
12198 if (test_thread_flag(TIF_32BIT))
12199 task_size = STACK_TOP32;
12200@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12201 return addr;
12202 }
12203
12204+#ifdef CONFIG_PAX_RANDMMAP
12205+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12206+#endif
12207+
12208 if (addr) {
12209 addr = ALIGN(addr, HPAGE_SIZE);
12210 vma = find_vma(mm, addr);
12211- if (task_size - len >= addr &&
12212- (!vma || addr + len <= vma->vm_start))
12213+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12214 return addr;
12215 }
12216 if (mm->get_unmapped_area == arch_get_unmapped_area)
12217 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12218- pgoff, flags);
12219+ pgoff, flags, offset);
12220 else
12221 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12222- pgoff, flags);
12223+ pgoff, flags, offset);
12224 }
12225
12226 pte_t *huge_pte_alloc(struct mm_struct *mm,
12227diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12228index eafbc65..5a8070d 100644
12229--- a/arch/sparc/mm/init_64.c
12230+++ b/arch/sparc/mm/init_64.c
12231@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12232 int num_kernel_image_mappings;
12233
12234 #ifdef CONFIG_DEBUG_DCFLUSH
12235-atomic_t dcpage_flushes = ATOMIC_INIT(0);
12236+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12237 #ifdef CONFIG_SMP
12238-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12239+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12240 #endif
12241 #endif
12242
12243@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
12244 {
12245 BUG_ON(tlb_type == hypervisor);
12246 #ifdef CONFIG_DEBUG_DCFLUSH
12247- atomic_inc(&dcpage_flushes);
12248+ atomic_inc_unchecked(&dcpage_flushes);
12249 #endif
12250
12251 #ifdef DCACHE_ALIASING_POSSIBLE
12252@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
12253
12254 #ifdef CONFIG_DEBUG_DCFLUSH
12255 seq_printf(m, "DCPageFlushes\t: %d\n",
12256- atomic_read(&dcpage_flushes));
12257+ atomic_read_unchecked(&dcpage_flushes));
12258 #ifdef CONFIG_SMP
12259 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12260- atomic_read(&dcpage_flushes_xcall));
12261+ atomic_read_unchecked(&dcpage_flushes_xcall));
12262 #endif /* CONFIG_SMP */
12263 #endif /* CONFIG_DEBUG_DCFLUSH */
12264 }
12265diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c
12266index b12cb5e..b89aba2 100644
12267--- a/arch/sparc/mm/tlb.c
12268+++ b/arch/sparc/mm/tlb.c
12269@@ -134,7 +134,7 @@ no_cache_flush:
12270
12271 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
12272 static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
12273- pmd_t pmd, bool exec)
12274+ pmd_t pmd)
12275 {
12276 unsigned long end;
12277 pte_t *pte;
12278@@ -142,8 +142,11 @@ static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
12279 pte = pte_offset_map(&pmd, vaddr);
12280 end = vaddr + HPAGE_SIZE;
12281 while (vaddr < end) {
12282- if (pte_val(*pte) & _PAGE_VALID)
12283+ if (pte_val(*pte) & _PAGE_VALID) {
12284+ bool exec = pte_exec(*pte);
12285+
12286 tlb_batch_add_one(mm, vaddr, exec);
12287+ }
12288 pte++;
12289 vaddr += PAGE_SIZE;
12290 }
12291@@ -177,19 +180,30 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,
12292 }
12293
12294 if (!pmd_none(orig)) {
12295- pte_t orig_pte = __pte(pmd_val(orig));
12296- bool exec = pte_exec(orig_pte);
12297-
12298 addr &= HPAGE_MASK;
12299 if (pmd_trans_huge(orig)) {
12300+ pte_t orig_pte = __pte(pmd_val(orig));
12301+ bool exec = pte_exec(orig_pte);
12302+
12303 tlb_batch_add_one(mm, addr, exec);
12304 tlb_batch_add_one(mm, addr + REAL_HPAGE_SIZE, exec);
12305 } else {
12306- tlb_batch_pmd_scan(mm, addr, orig, exec);
12307+ tlb_batch_pmd_scan(mm, addr, orig);
12308 }
12309 }
12310 }
12311
12312+void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
12313+ pmd_t *pmdp)
12314+{
12315+ pmd_t entry = *pmdp;
12316+
12317+ pmd_val(entry) &= ~_PAGE_VALID;
12318+
12319+ set_pmd_at(vma->vm_mm, address, pmdp, entry);
12320+ flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
12321+}
12322+
12323 void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
12324 pgtable_t pgtable)
12325 {
12326diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12327index b3692ce..e4517c9 100644
12328--- a/arch/tile/Kconfig
12329+++ b/arch/tile/Kconfig
12330@@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
12331
12332 config KEXEC
12333 bool "kexec system call"
12334+ depends on !GRKERNSEC_KMEM
12335 ---help---
12336 kexec is a system call that implements the ability to shutdown your
12337 current kernel, and to start another kernel. It is like a reboot
12338diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12339index ad220ee..2f537b3 100644
12340--- a/arch/tile/include/asm/atomic_64.h
12341+++ b/arch/tile/include/asm/atomic_64.h
12342@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12343
12344 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12345
12346+#define atomic64_read_unchecked(v) atomic64_read(v)
12347+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12348+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12349+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12350+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12351+#define atomic64_inc_unchecked(v) atomic64_inc(v)
12352+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12353+#define atomic64_dec_unchecked(v) atomic64_dec(v)
12354+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12355+
12356 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
12357 #define smp_mb__before_atomic_dec() smp_mb()
12358 #define smp_mb__after_atomic_dec() smp_mb()
12359diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12360index 6160761..00cac88 100644
12361--- a/arch/tile/include/asm/cache.h
12362+++ b/arch/tile/include/asm/cache.h
12363@@ -15,11 +15,12 @@
12364 #ifndef _ASM_TILE_CACHE_H
12365 #define _ASM_TILE_CACHE_H
12366
12367+#include <linux/const.h>
12368 #include <arch/chip.h>
12369
12370 /* bytes per L1 data cache line */
12371 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12372-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12373+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12374
12375 /* bytes per L2 cache line */
12376 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12377diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12378index b6cde32..c0cb736 100644
12379--- a/arch/tile/include/asm/uaccess.h
12380+++ b/arch/tile/include/asm/uaccess.h
12381@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12382 const void __user *from,
12383 unsigned long n)
12384 {
12385- int sz = __compiletime_object_size(to);
12386+ size_t sz = __compiletime_object_size(to);
12387
12388- if (likely(sz == -1 || sz >= n))
12389+ if (likely(sz == (size_t)-1 || sz >= n))
12390 n = _copy_from_user(to, from, n);
12391 else
12392 copy_from_user_overflow();
12393diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12394index 0cb3bba..7338b2d 100644
12395--- a/arch/tile/mm/hugetlbpage.c
12396+++ b/arch/tile/mm/hugetlbpage.c
12397@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12398 info.high_limit = TASK_SIZE;
12399 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12400 info.align_offset = 0;
12401+ info.threadstack_offset = 0;
12402 return vm_unmapped_area(&info);
12403 }
12404
12405@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12406 info.high_limit = current->mm->mmap_base;
12407 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12408 info.align_offset = 0;
12409+ info.threadstack_offset = 0;
12410 addr = vm_unmapped_area(&info);
12411
12412 /*
12413diff --git a/arch/um/Makefile b/arch/um/Makefile
12414index 36e658a..71a5c5a 100644
12415--- a/arch/um/Makefile
12416+++ b/arch/um/Makefile
12417@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12418 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12419 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12420
12421+ifdef CONSTIFY_PLUGIN
12422+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12423+endif
12424+
12425 #This will adjust *FLAGS accordingly to the platform.
12426 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12427
12428diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12429index 19e1bdd..3665b77 100644
12430--- a/arch/um/include/asm/cache.h
12431+++ b/arch/um/include/asm/cache.h
12432@@ -1,6 +1,7 @@
12433 #ifndef __UM_CACHE_H
12434 #define __UM_CACHE_H
12435
12436+#include <linux/const.h>
12437
12438 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12439 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12440@@ -12,6 +13,6 @@
12441 # define L1_CACHE_SHIFT 5
12442 #endif
12443
12444-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12445+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12446
12447 #endif
12448diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12449index 2e0a6b1..a64d0f5 100644
12450--- a/arch/um/include/asm/kmap_types.h
12451+++ b/arch/um/include/asm/kmap_types.h
12452@@ -8,6 +8,6 @@
12453
12454 /* No more #include "asm/arch/kmap_types.h" ! */
12455
12456-#define KM_TYPE_NR 14
12457+#define KM_TYPE_NR 15
12458
12459 #endif
12460diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12461index 5ff53d9..5850cdf 100644
12462--- a/arch/um/include/asm/page.h
12463+++ b/arch/um/include/asm/page.h
12464@@ -14,6 +14,9 @@
12465 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12466 #define PAGE_MASK (~(PAGE_SIZE-1))
12467
12468+#define ktla_ktva(addr) (addr)
12469+#define ktva_ktla(addr) (addr)
12470+
12471 #ifndef __ASSEMBLY__
12472
12473 struct page;
12474diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12475index 0032f92..cd151e0 100644
12476--- a/arch/um/include/asm/pgtable-3level.h
12477+++ b/arch/um/include/asm/pgtable-3level.h
12478@@ -58,6 +58,7 @@
12479 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12480 #define pud_populate(mm, pud, pmd) \
12481 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12482+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12483
12484 #ifdef CONFIG_64BIT
12485 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12486diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12487index eecc414..48adb87 100644
12488--- a/arch/um/kernel/process.c
12489+++ b/arch/um/kernel/process.c
12490@@ -356,22 +356,6 @@ int singlestepping(void * t)
12491 return 2;
12492 }
12493
12494-/*
12495- * Only x86 and x86_64 have an arch_align_stack().
12496- * All other arches have "#define arch_align_stack(x) (x)"
12497- * in their asm/system.h
12498- * As this is included in UML from asm-um/system-generic.h,
12499- * we can use it to behave as the subarch does.
12500- */
12501-#ifndef arch_align_stack
12502-unsigned long arch_align_stack(unsigned long sp)
12503-{
12504- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12505- sp -= get_random_int() % 8192;
12506- return sp & ~0xf;
12507-}
12508-#endif
12509-
12510 unsigned long get_wchan(struct task_struct *p)
12511 {
12512 unsigned long stack_page, sp, ip;
12513diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12514index ad8f795..2c7eec6 100644
12515--- a/arch/unicore32/include/asm/cache.h
12516+++ b/arch/unicore32/include/asm/cache.h
12517@@ -12,8 +12,10 @@
12518 #ifndef __UNICORE_CACHE_H__
12519 #define __UNICORE_CACHE_H__
12520
12521-#define L1_CACHE_SHIFT (5)
12522-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12523+#include <linux/const.h>
12524+
12525+#define L1_CACHE_SHIFT 5
12526+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12527
12528 /*
12529 * Memory returned by kmalloc() may be used for DMA, so we must make
12530diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12531index 0af5250..59f9597 100644
12532--- a/arch/x86/Kconfig
12533+++ b/arch/x86/Kconfig
12534@@ -126,7 +126,7 @@ config X86
12535 select RTC_LIB
12536 select HAVE_DEBUG_STACKOVERFLOW
12537 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12538- select HAVE_CC_STACKPROTECTOR
12539+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12540
12541 config INSTRUCTION_DECODER
12542 def_bool y
12543@@ -251,7 +251,7 @@ config X86_HT
12544
12545 config X86_32_LAZY_GS
12546 def_bool y
12547- depends on X86_32 && !CC_STACKPROTECTOR
12548+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12549
12550 config ARCH_HWEIGHT_CFLAGS
12551 string
12552@@ -589,6 +589,7 @@ config SCHED_OMIT_FRAME_POINTER
12553
12554 menuconfig HYPERVISOR_GUEST
12555 bool "Linux guest support"
12556+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12557 ---help---
12558 Say Y here to enable options for running Linux under various hyper-
12559 visors. This option enables basic hypervisor detection and platform
12560@@ -1111,7 +1112,7 @@ choice
12561
12562 config NOHIGHMEM
12563 bool "off"
12564- depends on !X86_NUMAQ
12565+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12566 ---help---
12567 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12568 However, the address space of 32-bit x86 processors is only 4
12569@@ -1148,7 +1149,7 @@ config NOHIGHMEM
12570
12571 config HIGHMEM4G
12572 bool "4GB"
12573- depends on !X86_NUMAQ
12574+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12575 ---help---
12576 Select this if you have a 32-bit processor and between 1 and 4
12577 gigabytes of physical RAM.
12578@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
12579 hex
12580 default 0xB0000000 if VMSPLIT_3G_OPT
12581 default 0x80000000 if VMSPLIT_2G
12582- default 0x78000000 if VMSPLIT_2G_OPT
12583+ default 0x70000000 if VMSPLIT_2G_OPT
12584 default 0x40000000 if VMSPLIT_1G
12585 default 0xC0000000
12586 depends on X86_32
12587@@ -1605,6 +1606,7 @@ source kernel/Kconfig.hz
12588
12589 config KEXEC
12590 bool "kexec system call"
12591+ depends on !GRKERNSEC_KMEM
12592 ---help---
12593 kexec is a system call that implements the ability to shutdown your
12594 current kernel, and to start another kernel. It is like a reboot
12595@@ -1756,7 +1758,9 @@ config X86_NEED_RELOCS
12596
12597 config PHYSICAL_ALIGN
12598 hex "Alignment value to which kernel should be aligned"
12599- default "0x200000"
12600+ default "0x1000000"
12601+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12602+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12603 range 0x2000 0x1000000 if X86_32
12604 range 0x200000 0x1000000 if X86_64
12605 ---help---
12606@@ -1836,9 +1840,10 @@ config DEBUG_HOTPLUG_CPU0
12607 If unsure, say N.
12608
12609 config COMPAT_VDSO
12610- def_bool y
12611+ def_bool n
12612 prompt "Compat VDSO support"
12613 depends on X86_32 || IA32_EMULATION
12614+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12615 ---help---
12616 Map the 32-bit VDSO to the predictable old-style address too.
12617
12618diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12619index f3aaf23..a1d3c49 100644
12620--- a/arch/x86/Kconfig.cpu
12621+++ b/arch/x86/Kconfig.cpu
12622@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12623
12624 config X86_F00F_BUG
12625 def_bool y
12626- depends on M586MMX || M586TSC || M586 || M486
12627+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12628
12629 config X86_INVD_BUG
12630 def_bool y
12631@@ -327,7 +327,7 @@ config X86_INVD_BUG
12632
12633 config X86_ALIGNMENT_16
12634 def_bool y
12635- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12636+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12637
12638 config X86_INTEL_USERCOPY
12639 def_bool y
12640@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12641 # generates cmov.
12642 config X86_CMOV
12643 def_bool y
12644- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12645+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12646
12647 config X86_MINIMUM_CPU_FAMILY
12648 int
12649diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12650index 321a52c..3d51a5e 100644
12651--- a/arch/x86/Kconfig.debug
12652+++ b/arch/x86/Kconfig.debug
12653@@ -84,7 +84,7 @@ config X86_PTDUMP
12654 config DEBUG_RODATA
12655 bool "Write protect kernel read-only data structures"
12656 default y
12657- depends on DEBUG_KERNEL
12658+ depends on DEBUG_KERNEL && BROKEN
12659 ---help---
12660 Mark the kernel read-only data as write-protected in the pagetables,
12661 in order to catch accidental (and incorrect) writes to such const
12662@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12663
12664 config DEBUG_SET_MODULE_RONX
12665 bool "Set loadable kernel module data as NX and text as RO"
12666- depends on MODULES
12667+ depends on MODULES && BROKEN
12668 ---help---
12669 This option helps catch unintended modifications to loadable
12670 kernel module's text and read-only data. It also prevents execution
12671diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12672index 0dd99ea..4a63d82 100644
12673--- a/arch/x86/Makefile
12674+++ b/arch/x86/Makefile
12675@@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12676 # CPU-specific tuning. Anything which can be shared with UML should go here.
12677 include $(srctree)/arch/x86/Makefile_32.cpu
12678 KBUILD_CFLAGS += $(cflags-y)
12679-
12680- # temporary until string.h is fixed
12681- KBUILD_CFLAGS += -ffreestanding
12682 else
12683 BITS := 64
12684 UTS_MACHINE := x86_64
12685@@ -112,6 +109,9 @@ else
12686 KBUILD_CFLAGS += -maccumulate-outgoing-args
12687 endif
12688
12689+# temporary until string.h is fixed
12690+KBUILD_CFLAGS += -ffreestanding
12691+
12692 # Make sure compiler does not have buggy stack-protector support.
12693 ifdef CONFIG_CC_STACKPROTECTOR
12694 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12695@@ -269,3 +269,12 @@ define archhelp
12696 echo ' FDINITRD=file initrd for the booted kernel'
12697 echo ' kvmconfig - Enable additional options for guest kernel support'
12698 endef
12699+
12700+define OLD_LD
12701+
12702+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12703+*** Please upgrade your binutils to 2.18 or newer
12704+endef
12705+
12706+archprepare:
12707+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12708diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12709index 878df7e..a803913 100644
12710--- a/arch/x86/boot/Makefile
12711+++ b/arch/x86/boot/Makefile
12712@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12713 # ---------------------------------------------------------------------------
12714
12715 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12716+ifdef CONSTIFY_PLUGIN
12717+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12718+endif
12719 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12720 GCOV_PROFILE := n
12721
12722diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12723index 878e4b9..20537ab 100644
12724--- a/arch/x86/boot/bitops.h
12725+++ b/arch/x86/boot/bitops.h
12726@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12727 u8 v;
12728 const u32 *p = (const u32 *)addr;
12729
12730- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12731+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12732 return v;
12733 }
12734
12735@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12736
12737 static inline void set_bit(int nr, void *addr)
12738 {
12739- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12740+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12741 }
12742
12743 #endif /* BOOT_BITOPS_H */
12744diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12745index 50f8c5e..4f84fff 100644
12746--- a/arch/x86/boot/boot.h
12747+++ b/arch/x86/boot/boot.h
12748@@ -84,7 +84,7 @@ static inline void io_delay(void)
12749 static inline u16 ds(void)
12750 {
12751 u16 seg;
12752- asm("movw %%ds,%0" : "=rm" (seg));
12753+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12754 return seg;
12755 }
12756
12757@@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12758 static inline int memcmp(const void *s1, const void *s2, size_t len)
12759 {
12760 u8 diff;
12761- asm("repe; cmpsb; setnz %0"
12762+ asm volatile("repe; cmpsb; setnz %0"
12763 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12764 return diff;
12765 }
12766diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12767index 0fcd913..3bb5c42 100644
12768--- a/arch/x86/boot/compressed/Makefile
12769+++ b/arch/x86/boot/compressed/Makefile
12770@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12771 KBUILD_CFLAGS += -mno-mmx -mno-sse
12772 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12773 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12774+ifdef CONSTIFY_PLUGIN
12775+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12776+endif
12777
12778 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12779 GCOV_PROFILE := n
12780diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12781index a53440e..c3dbf1e 100644
12782--- a/arch/x86/boot/compressed/efi_stub_32.S
12783+++ b/arch/x86/boot/compressed/efi_stub_32.S
12784@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12785 * parameter 2, ..., param n. To make things easy, we save the return
12786 * address of efi_call_phys in a global variable.
12787 */
12788- popl %ecx
12789- movl %ecx, saved_return_addr(%edx)
12790- /* get the function pointer into ECX*/
12791- popl %ecx
12792- movl %ecx, efi_rt_function_ptr(%edx)
12793+ popl saved_return_addr(%edx)
12794+ popl efi_rt_function_ptr(%edx)
12795
12796 /*
12797 * 3. Call the physical function.
12798 */
12799- call *%ecx
12800+ call *efi_rt_function_ptr(%edx)
12801
12802 /*
12803 * 4. Balance the stack. And because EAX contain the return value,
12804@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12805 1: popl %edx
12806 subl $1b, %edx
12807
12808- movl efi_rt_function_ptr(%edx), %ecx
12809- pushl %ecx
12810+ pushl efi_rt_function_ptr(%edx)
12811
12812 /*
12813 * 10. Push the saved return address onto the stack and return.
12814 */
12815- movl saved_return_addr(%edx), %ecx
12816- pushl %ecx
12817- ret
12818+ jmpl *saved_return_addr(%edx)
12819 ENDPROC(efi_call_phys)
12820 .previous
12821
12822diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12823index f45ab7a..ebc015f 100644
12824--- a/arch/x86/boot/compressed/head_32.S
12825+++ b/arch/x86/boot/compressed/head_32.S
12826@@ -119,10 +119,10 @@ preferred_addr:
12827 addl %eax, %ebx
12828 notl %eax
12829 andl %eax, %ebx
12830- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12831+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12832 jge 1f
12833 #endif
12834- movl $LOAD_PHYSICAL_ADDR, %ebx
12835+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12836 1:
12837
12838 /* Target address to relocate to for decompression */
12839diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12840index b10fa66..5ee0472 100644
12841--- a/arch/x86/boot/compressed/head_64.S
12842+++ b/arch/x86/boot/compressed/head_64.S
12843@@ -94,10 +94,10 @@ ENTRY(startup_32)
12844 addl %eax, %ebx
12845 notl %eax
12846 andl %eax, %ebx
12847- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12848+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12849 jge 1f
12850 #endif
12851- movl $LOAD_PHYSICAL_ADDR, %ebx
12852+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12853 1:
12854
12855 /* Target address to relocate to for decompression */
12856@@ -268,10 +268,10 @@ preferred_addr:
12857 addq %rax, %rbp
12858 notq %rax
12859 andq %rax, %rbp
12860- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12861+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12862 jge 1f
12863 #endif
12864- movq $LOAD_PHYSICAL_ADDR, %rbp
12865+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12866 1:
12867
12868 /* Target address to relocate to for decompression */
12869@@ -363,8 +363,8 @@ gdt:
12870 .long gdt
12871 .word 0
12872 .quad 0x0000000000000000 /* NULL descriptor */
12873- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12874- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12875+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12876+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12877 .quad 0x0080890000000000 /* TS descriptor */
12878 .quad 0x0000000000000000 /* TS continued */
12879 gdt_end:
12880diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12881index 196eaf3..c96716d 100644
12882--- a/arch/x86/boot/compressed/misc.c
12883+++ b/arch/x86/boot/compressed/misc.c
12884@@ -218,7 +218,7 @@ void __putstr(const char *s)
12885
12886 void *memset(void *s, int c, size_t n)
12887 {
12888- int i;
12889+ size_t i;
12890 char *ss = s;
12891
12892 for (i = 0; i < n; i++)
12893@@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12894 * Calculate the delta between where vmlinux was linked to load
12895 * and where it was actually loaded.
12896 */
12897- delta = min_addr - LOAD_PHYSICAL_ADDR;
12898+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12899 if (!delta) {
12900 debug_putstr("No relocation needed... ");
12901 return;
12902@@ -347,7 +347,7 @@ static void parse_elf(void *output)
12903 Elf32_Ehdr ehdr;
12904 Elf32_Phdr *phdrs, *phdr;
12905 #endif
12906- void *dest;
12907+ void *dest, *prev;
12908 int i;
12909
12910 memcpy(&ehdr, output, sizeof(ehdr));
12911@@ -374,13 +374,16 @@ static void parse_elf(void *output)
12912 case PT_LOAD:
12913 #ifdef CONFIG_RELOCATABLE
12914 dest = output;
12915- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12916+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12917 #else
12918 dest = (void *)(phdr->p_paddr);
12919 #endif
12920 memcpy(dest,
12921 output + phdr->p_offset,
12922 phdr->p_filesz);
12923+ if (i)
12924+ memset(prev, 0xff, dest - prev);
12925+ prev = dest + phdr->p_filesz;
12926 break;
12927 default: /* Ignore other PT_* */ break;
12928 }
12929@@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
12930 error("Destination address too large");
12931 #endif
12932 #ifndef CONFIG_RELOCATABLE
12933- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12934+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12935 error("Wrong destination address");
12936 #endif
12937
12938diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12939index 100a9a1..bb3bdb0 100644
12940--- a/arch/x86/boot/cpucheck.c
12941+++ b/arch/x86/boot/cpucheck.c
12942@@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12943 u32 ecx = MSR_K7_HWCR;
12944 u32 eax, edx;
12945
12946- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12947+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12948 eax &= ~(1 << 15);
12949- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12950+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12951
12952 get_cpuflags(); /* Make sure it really did something */
12953 err = check_cpuflags();
12954@@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12955 u32 ecx = MSR_VIA_FCR;
12956 u32 eax, edx;
12957
12958- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12959+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12960 eax |= (1<<1)|(1<<7);
12961- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12962+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12963
12964 set_bit(X86_FEATURE_CX8, cpu.flags);
12965 err = check_cpuflags();
12966@@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12967 u32 eax, edx;
12968 u32 level = 1;
12969
12970- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12971- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12972- asm("cpuid"
12973+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12974+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12975+ asm volatile("cpuid"
12976 : "+a" (level), "=d" (cpu.flags[0])
12977 : : "ecx", "ebx");
12978- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12979+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12980
12981 err = check_cpuflags();
12982 }
12983diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12984index ec3b8ba..6a0db1f 100644
12985--- a/arch/x86/boot/header.S
12986+++ b/arch/x86/boot/header.S
12987@@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12988 # single linked list of
12989 # struct setup_data
12990
12991-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12992+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12993
12994 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12995+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12996+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12997+#else
12998 #define VO_INIT_SIZE (VO__end - VO__text)
12999+#endif
13000 #if ZO_INIT_SIZE > VO_INIT_SIZE
13001 #define INIT_SIZE ZO_INIT_SIZE
13002 #else
13003diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13004index db75d07..8e6d0af 100644
13005--- a/arch/x86/boot/memory.c
13006+++ b/arch/x86/boot/memory.c
13007@@ -19,7 +19,7 @@
13008
13009 static int detect_memory_e820(void)
13010 {
13011- int count = 0;
13012+ unsigned int count = 0;
13013 struct biosregs ireg, oreg;
13014 struct e820entry *desc = boot_params.e820_map;
13015 static struct e820entry buf; /* static so it is zeroed */
13016diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13017index 11e8c6e..fdbb1ed 100644
13018--- a/arch/x86/boot/video-vesa.c
13019+++ b/arch/x86/boot/video-vesa.c
13020@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
13021
13022 boot_params.screen_info.vesapm_seg = oreg.es;
13023 boot_params.screen_info.vesapm_off = oreg.di;
13024+ boot_params.screen_info.vesapm_size = oreg.cx;
13025 }
13026
13027 /*
13028diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13029index 43eda28..5ab5fdb 100644
13030--- a/arch/x86/boot/video.c
13031+++ b/arch/x86/boot/video.c
13032@@ -96,7 +96,7 @@ static void store_mode_params(void)
13033 static unsigned int get_entry(void)
13034 {
13035 char entry_buf[4];
13036- int i, len = 0;
13037+ unsigned int i, len = 0;
13038 int key;
13039 unsigned int v;
13040
13041diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13042index 9105655..41779c1 100644
13043--- a/arch/x86/crypto/aes-x86_64-asm_64.S
13044+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13045@@ -8,6 +8,8 @@
13046 * including this sentence is retained in full.
13047 */
13048
13049+#include <asm/alternative-asm.h>
13050+
13051 .extern crypto_ft_tab
13052 .extern crypto_it_tab
13053 .extern crypto_fl_tab
13054@@ -70,6 +72,8 @@
13055 je B192; \
13056 leaq 32(r9),r9;
13057
13058+#define ret pax_force_retaddr; ret
13059+
13060 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13061 movq r1,r2; \
13062 movq r3,r4; \
13063diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13064index 477e9d7..c92c7d8 100644
13065--- a/arch/x86/crypto/aesni-intel_asm.S
13066+++ b/arch/x86/crypto/aesni-intel_asm.S
13067@@ -31,6 +31,7 @@
13068
13069 #include <linux/linkage.h>
13070 #include <asm/inst.h>
13071+#include <asm/alternative-asm.h>
13072
13073 #ifdef __x86_64__
13074 .data
13075@@ -205,7 +206,7 @@ enc: .octa 0x2
13076 * num_initial_blocks = b mod 4
13077 * encrypt the initial num_initial_blocks blocks and apply ghash on
13078 * the ciphertext
13079-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13080+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13081 * are clobbered
13082 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13083 */
13084@@ -214,8 +215,8 @@ enc: .octa 0x2
13085 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13086 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13087 mov arg7, %r10 # %r10 = AAD
13088- mov arg8, %r12 # %r12 = aadLen
13089- mov %r12, %r11
13090+ mov arg8, %r15 # %r15 = aadLen
13091+ mov %r15, %r11
13092 pxor %xmm\i, %xmm\i
13093 _get_AAD_loop\num_initial_blocks\operation:
13094 movd (%r10), \TMP1
13095@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13096 psrldq $4, %xmm\i
13097 pxor \TMP1, %xmm\i
13098 add $4, %r10
13099- sub $4, %r12
13100+ sub $4, %r15
13101 jne _get_AAD_loop\num_initial_blocks\operation
13102 cmp $16, %r11
13103 je _get_AAD_loop2_done\num_initial_blocks\operation
13104- mov $16, %r12
13105+ mov $16, %r15
13106 _get_AAD_loop2\num_initial_blocks\operation:
13107 psrldq $4, %xmm\i
13108- sub $4, %r12
13109- cmp %r11, %r12
13110+ sub $4, %r15
13111+ cmp %r11, %r15
13112 jne _get_AAD_loop2\num_initial_blocks\operation
13113 _get_AAD_loop2_done\num_initial_blocks\operation:
13114 movdqa SHUF_MASK(%rip), %xmm14
13115@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13116 * num_initial_blocks = b mod 4
13117 * encrypt the initial num_initial_blocks blocks and apply ghash on
13118 * the ciphertext
13119-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13120+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13121 * are clobbered
13122 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13123 */
13124@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13125 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13126 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13127 mov arg7, %r10 # %r10 = AAD
13128- mov arg8, %r12 # %r12 = aadLen
13129- mov %r12, %r11
13130+ mov arg8, %r15 # %r15 = aadLen
13131+ mov %r15, %r11
13132 pxor %xmm\i, %xmm\i
13133 _get_AAD_loop\num_initial_blocks\operation:
13134 movd (%r10), \TMP1
13135@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13136 psrldq $4, %xmm\i
13137 pxor \TMP1, %xmm\i
13138 add $4, %r10
13139- sub $4, %r12
13140+ sub $4, %r15
13141 jne _get_AAD_loop\num_initial_blocks\operation
13142 cmp $16, %r11
13143 je _get_AAD_loop2_done\num_initial_blocks\operation
13144- mov $16, %r12
13145+ mov $16, %r15
13146 _get_AAD_loop2\num_initial_blocks\operation:
13147 psrldq $4, %xmm\i
13148- sub $4, %r12
13149- cmp %r11, %r12
13150+ sub $4, %r15
13151+ cmp %r11, %r15
13152 jne _get_AAD_loop2\num_initial_blocks\operation
13153 _get_AAD_loop2_done\num_initial_blocks\operation:
13154 movdqa SHUF_MASK(%rip), %xmm14
13155@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13156 *
13157 *****************************************************************************/
13158 ENTRY(aesni_gcm_dec)
13159- push %r12
13160+ push %r15
13161 push %r13
13162 push %r14
13163 mov %rsp, %r14
13164@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13165 */
13166 sub $VARIABLE_OFFSET, %rsp
13167 and $~63, %rsp # align rsp to 64 bytes
13168- mov %arg6, %r12
13169- movdqu (%r12), %xmm13 # %xmm13 = HashKey
13170+ mov %arg6, %r15
13171+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
13172 movdqa SHUF_MASK(%rip), %xmm2
13173 PSHUFB_XMM %xmm2, %xmm13
13174
13175@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13176 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13177 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13178 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13179- mov %r13, %r12
13180- and $(3<<4), %r12
13181+ mov %r13, %r15
13182+ and $(3<<4), %r15
13183 jz _initial_num_blocks_is_0_decrypt
13184- cmp $(2<<4), %r12
13185+ cmp $(2<<4), %r15
13186 jb _initial_num_blocks_is_1_decrypt
13187 je _initial_num_blocks_is_2_decrypt
13188 _initial_num_blocks_is_3_decrypt:
13189@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13190 sub $16, %r11
13191 add %r13, %r11
13192 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13193- lea SHIFT_MASK+16(%rip), %r12
13194- sub %r13, %r12
13195+ lea SHIFT_MASK+16(%rip), %r15
13196+ sub %r13, %r15
13197 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13198 # (%r13 is the number of bytes in plaintext mod 16)
13199- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13200+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13201 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13202
13203 movdqa %xmm1, %xmm2
13204 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13205- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13206+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13207 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13208 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13209 pand %xmm1, %xmm2
13210@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13211 sub $1, %r13
13212 jne _less_than_8_bytes_left_decrypt
13213 _multiple_of_16_bytes_decrypt:
13214- mov arg8, %r12 # %r13 = aadLen (number of bytes)
13215- shl $3, %r12 # convert into number of bits
13216- movd %r12d, %xmm15 # len(A) in %xmm15
13217+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
13218+ shl $3, %r15 # convert into number of bits
13219+ movd %r15d, %xmm15 # len(A) in %xmm15
13220 shl $3, %arg4 # len(C) in bits (*128)
13221 MOVQ_R64_XMM %arg4, %xmm1
13222 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13223@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13224 mov %r14, %rsp
13225 pop %r14
13226 pop %r13
13227- pop %r12
13228+ pop %r15
13229+ pax_force_retaddr
13230 ret
13231 ENDPROC(aesni_gcm_dec)
13232
13233@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13234 * poly = x^128 + x^127 + x^126 + x^121 + 1
13235 ***************************************************************************/
13236 ENTRY(aesni_gcm_enc)
13237- push %r12
13238+ push %r15
13239 push %r13
13240 push %r14
13241 mov %rsp, %r14
13242@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13243 #
13244 sub $VARIABLE_OFFSET, %rsp
13245 and $~63, %rsp
13246- mov %arg6, %r12
13247- movdqu (%r12), %xmm13
13248+ mov %arg6, %r15
13249+ movdqu (%r15), %xmm13
13250 movdqa SHUF_MASK(%rip), %xmm2
13251 PSHUFB_XMM %xmm2, %xmm13
13252
13253@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13254 movdqa %xmm13, HashKey(%rsp)
13255 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13256 and $-16, %r13
13257- mov %r13, %r12
13258+ mov %r13, %r15
13259
13260 # Encrypt first few blocks
13261
13262- and $(3<<4), %r12
13263+ and $(3<<4), %r15
13264 jz _initial_num_blocks_is_0_encrypt
13265- cmp $(2<<4), %r12
13266+ cmp $(2<<4), %r15
13267 jb _initial_num_blocks_is_1_encrypt
13268 je _initial_num_blocks_is_2_encrypt
13269 _initial_num_blocks_is_3_encrypt:
13270@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13271 sub $16, %r11
13272 add %r13, %r11
13273 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13274- lea SHIFT_MASK+16(%rip), %r12
13275- sub %r13, %r12
13276+ lea SHIFT_MASK+16(%rip), %r15
13277+ sub %r13, %r15
13278 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13279 # (%r13 is the number of bytes in plaintext mod 16)
13280- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13281+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13282 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13283 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13284- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13285+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13286 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13287 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13288 movdqa SHUF_MASK(%rip), %xmm10
13289@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13290 sub $1, %r13
13291 jne _less_than_8_bytes_left_encrypt
13292 _multiple_of_16_bytes_encrypt:
13293- mov arg8, %r12 # %r12 = addLen (number of bytes)
13294- shl $3, %r12
13295- movd %r12d, %xmm15 # len(A) in %xmm15
13296+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13297+ shl $3, %r15
13298+ movd %r15d, %xmm15 # len(A) in %xmm15
13299 shl $3, %arg4 # len(C) in bits (*128)
13300 MOVQ_R64_XMM %arg4, %xmm1
13301 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13302@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13303 mov %r14, %rsp
13304 pop %r14
13305 pop %r13
13306- pop %r12
13307+ pop %r15
13308+ pax_force_retaddr
13309 ret
13310 ENDPROC(aesni_gcm_enc)
13311
13312@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13313 pxor %xmm1, %xmm0
13314 movaps %xmm0, (TKEYP)
13315 add $0x10, TKEYP
13316+ pax_force_retaddr
13317 ret
13318 ENDPROC(_key_expansion_128)
13319 ENDPROC(_key_expansion_256a)
13320@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13321 shufps $0b01001110, %xmm2, %xmm1
13322 movaps %xmm1, 0x10(TKEYP)
13323 add $0x20, TKEYP
13324+ pax_force_retaddr
13325 ret
13326 ENDPROC(_key_expansion_192a)
13327
13328@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13329
13330 movaps %xmm0, (TKEYP)
13331 add $0x10, TKEYP
13332+ pax_force_retaddr
13333 ret
13334 ENDPROC(_key_expansion_192b)
13335
13336@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13337 pxor %xmm1, %xmm2
13338 movaps %xmm2, (TKEYP)
13339 add $0x10, TKEYP
13340+ pax_force_retaddr
13341 ret
13342 ENDPROC(_key_expansion_256b)
13343
13344@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13345 #ifndef __x86_64__
13346 popl KEYP
13347 #endif
13348+ pax_force_retaddr
13349 ret
13350 ENDPROC(aesni_set_key)
13351
13352@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13353 popl KLEN
13354 popl KEYP
13355 #endif
13356+ pax_force_retaddr
13357 ret
13358 ENDPROC(aesni_enc)
13359
13360@@ -1974,6 +1983,7 @@ _aesni_enc1:
13361 AESENC KEY STATE
13362 movaps 0x70(TKEYP), KEY
13363 AESENCLAST KEY STATE
13364+ pax_force_retaddr
13365 ret
13366 ENDPROC(_aesni_enc1)
13367
13368@@ -2083,6 +2093,7 @@ _aesni_enc4:
13369 AESENCLAST KEY STATE2
13370 AESENCLAST KEY STATE3
13371 AESENCLAST KEY STATE4
13372+ pax_force_retaddr
13373 ret
13374 ENDPROC(_aesni_enc4)
13375
13376@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13377 popl KLEN
13378 popl KEYP
13379 #endif
13380+ pax_force_retaddr
13381 ret
13382 ENDPROC(aesni_dec)
13383
13384@@ -2164,6 +2176,7 @@ _aesni_dec1:
13385 AESDEC KEY STATE
13386 movaps 0x70(TKEYP), KEY
13387 AESDECLAST KEY STATE
13388+ pax_force_retaddr
13389 ret
13390 ENDPROC(_aesni_dec1)
13391
13392@@ -2273,6 +2286,7 @@ _aesni_dec4:
13393 AESDECLAST KEY STATE2
13394 AESDECLAST KEY STATE3
13395 AESDECLAST KEY STATE4
13396+ pax_force_retaddr
13397 ret
13398 ENDPROC(_aesni_dec4)
13399
13400@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13401 popl KEYP
13402 popl LEN
13403 #endif
13404+ pax_force_retaddr
13405 ret
13406 ENDPROC(aesni_ecb_enc)
13407
13408@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13409 popl KEYP
13410 popl LEN
13411 #endif
13412+ pax_force_retaddr
13413 ret
13414 ENDPROC(aesni_ecb_dec)
13415
13416@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13417 popl LEN
13418 popl IVP
13419 #endif
13420+ pax_force_retaddr
13421 ret
13422 ENDPROC(aesni_cbc_enc)
13423
13424@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13425 popl LEN
13426 popl IVP
13427 #endif
13428+ pax_force_retaddr
13429 ret
13430 ENDPROC(aesni_cbc_dec)
13431
13432@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13433 mov $1, TCTR_LOW
13434 MOVQ_R64_XMM TCTR_LOW INC
13435 MOVQ_R64_XMM CTR TCTR_LOW
13436+ pax_force_retaddr
13437 ret
13438 ENDPROC(_aesni_inc_init)
13439
13440@@ -2579,6 +2598,7 @@ _aesni_inc:
13441 .Linc_low:
13442 movaps CTR, IV
13443 PSHUFB_XMM BSWAP_MASK IV
13444+ pax_force_retaddr
13445 ret
13446 ENDPROC(_aesni_inc)
13447
13448@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13449 .Lctr_enc_ret:
13450 movups IV, (IVP)
13451 .Lctr_enc_just_ret:
13452+ pax_force_retaddr
13453 ret
13454 ENDPROC(aesni_ctr_enc)
13455
13456@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13457 pxor INC, STATE4
13458 movdqu STATE4, 0x70(OUTP)
13459
13460+ pax_force_retaddr
13461 ret
13462 ENDPROC(aesni_xts_crypt8)
13463
13464diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13465index 246c670..466e2d6 100644
13466--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13467+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13468@@ -21,6 +21,7 @@
13469 */
13470
13471 #include <linux/linkage.h>
13472+#include <asm/alternative-asm.h>
13473
13474 .file "blowfish-x86_64-asm.S"
13475 .text
13476@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13477 jnz .L__enc_xor;
13478
13479 write_block();
13480+ pax_force_retaddr
13481 ret;
13482 .L__enc_xor:
13483 xor_block();
13484+ pax_force_retaddr
13485 ret;
13486 ENDPROC(__blowfish_enc_blk)
13487
13488@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13489
13490 movq %r11, %rbp;
13491
13492+ pax_force_retaddr
13493 ret;
13494 ENDPROC(blowfish_dec_blk)
13495
13496@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13497
13498 popq %rbx;
13499 popq %rbp;
13500+ pax_force_retaddr
13501 ret;
13502
13503 .L__enc_xor4:
13504@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13505
13506 popq %rbx;
13507 popq %rbp;
13508+ pax_force_retaddr
13509 ret;
13510 ENDPROC(__blowfish_enc_blk_4way)
13511
13512@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13513 popq %rbx;
13514 popq %rbp;
13515
13516+ pax_force_retaddr
13517 ret;
13518 ENDPROC(blowfish_dec_blk_4way)
13519diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13520index ce71f92..1dce7ec 100644
13521--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13522+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13523@@ -16,6 +16,7 @@
13524 */
13525
13526 #include <linux/linkage.h>
13527+#include <asm/alternative-asm.h>
13528
13529 #define CAMELLIA_TABLE_BYTE_LEN 272
13530
13531@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13532 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13533 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13534 %rcx, (%r9));
13535+ pax_force_retaddr
13536 ret;
13537 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13538
13539@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13540 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13541 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13542 %rax, (%r9));
13543+ pax_force_retaddr
13544 ret;
13545 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13546
13547@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13548 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13549 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13550
13551+ pax_force_retaddr
13552 ret;
13553
13554 .align 8
13555@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13556 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13557 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13558
13559+ pax_force_retaddr
13560 ret;
13561
13562 .align 8
13563@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13564 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13565 %xmm8, %rsi);
13566
13567+ pax_force_retaddr
13568 ret;
13569 ENDPROC(camellia_ecb_enc_16way)
13570
13571@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13572 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13573 %xmm8, %rsi);
13574
13575+ pax_force_retaddr
13576 ret;
13577 ENDPROC(camellia_ecb_dec_16way)
13578
13579@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13580 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13581 %xmm8, %rsi);
13582
13583+ pax_force_retaddr
13584 ret;
13585 ENDPROC(camellia_cbc_dec_16way)
13586
13587@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13588 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13589 %xmm8, %rsi);
13590
13591+ pax_force_retaddr
13592 ret;
13593 ENDPROC(camellia_ctr_16way)
13594
13595@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13596 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13597 %xmm8, %rsi);
13598
13599+ pax_force_retaddr
13600 ret;
13601 ENDPROC(camellia_xts_crypt_16way)
13602
13603diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13604index 0e0b886..5a3123c 100644
13605--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13606+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13607@@ -11,6 +11,7 @@
13608 */
13609
13610 #include <linux/linkage.h>
13611+#include <asm/alternative-asm.h>
13612
13613 #define CAMELLIA_TABLE_BYTE_LEN 272
13614
13615@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13616 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13617 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13618 %rcx, (%r9));
13619+ pax_force_retaddr
13620 ret;
13621 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13622
13623@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13624 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13625 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13626 %rax, (%r9));
13627+ pax_force_retaddr
13628 ret;
13629 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13630
13631@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13632 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13633 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13634
13635+ pax_force_retaddr
13636 ret;
13637
13638 .align 8
13639@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13640 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13641 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13642
13643+ pax_force_retaddr
13644 ret;
13645
13646 .align 8
13647@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13648
13649 vzeroupper;
13650
13651+ pax_force_retaddr
13652 ret;
13653 ENDPROC(camellia_ecb_enc_32way)
13654
13655@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13656
13657 vzeroupper;
13658
13659+ pax_force_retaddr
13660 ret;
13661 ENDPROC(camellia_ecb_dec_32way)
13662
13663@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13664
13665 vzeroupper;
13666
13667+ pax_force_retaddr
13668 ret;
13669 ENDPROC(camellia_cbc_dec_32way)
13670
13671@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13672
13673 vzeroupper;
13674
13675+ pax_force_retaddr
13676 ret;
13677 ENDPROC(camellia_ctr_32way)
13678
13679@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13680
13681 vzeroupper;
13682
13683+ pax_force_retaddr
13684 ret;
13685 ENDPROC(camellia_xts_crypt_32way)
13686
13687diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13688index 310319c..db3d7b5 100644
13689--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13690+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13691@@ -21,6 +21,7 @@
13692 */
13693
13694 #include <linux/linkage.h>
13695+#include <asm/alternative-asm.h>
13696
13697 .file "camellia-x86_64-asm_64.S"
13698 .text
13699@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13700 enc_outunpack(mov, RT1);
13701
13702 movq RRBP, %rbp;
13703+ pax_force_retaddr
13704 ret;
13705
13706 .L__enc_xor:
13707 enc_outunpack(xor, RT1);
13708
13709 movq RRBP, %rbp;
13710+ pax_force_retaddr
13711 ret;
13712 ENDPROC(__camellia_enc_blk)
13713
13714@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13715 dec_outunpack();
13716
13717 movq RRBP, %rbp;
13718+ pax_force_retaddr
13719 ret;
13720 ENDPROC(camellia_dec_blk)
13721
13722@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13723
13724 movq RRBP, %rbp;
13725 popq %rbx;
13726+ pax_force_retaddr
13727 ret;
13728
13729 .L__enc2_xor:
13730@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13731
13732 movq RRBP, %rbp;
13733 popq %rbx;
13734+ pax_force_retaddr
13735 ret;
13736 ENDPROC(__camellia_enc_blk_2way)
13737
13738@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13739
13740 movq RRBP, %rbp;
13741 movq RXOR, %rbx;
13742+ pax_force_retaddr
13743 ret;
13744 ENDPROC(camellia_dec_blk_2way)
13745diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13746index c35fd5d..2d8c7db 100644
13747--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13748+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13749@@ -24,6 +24,7 @@
13750 */
13751
13752 #include <linux/linkage.h>
13753+#include <asm/alternative-asm.h>
13754
13755 .file "cast5-avx-x86_64-asm_64.S"
13756
13757@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13758 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13759 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13760
13761+ pax_force_retaddr
13762 ret;
13763 ENDPROC(__cast5_enc_blk16)
13764
13765@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13766 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13767 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13768
13769+ pax_force_retaddr
13770 ret;
13771
13772 .L__skip_dec:
13773@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13774 vmovdqu RR4, (6*4*4)(%r11);
13775 vmovdqu RL4, (7*4*4)(%r11);
13776
13777+ pax_force_retaddr
13778 ret;
13779 ENDPROC(cast5_ecb_enc_16way)
13780
13781@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13782 vmovdqu RR4, (6*4*4)(%r11);
13783 vmovdqu RL4, (7*4*4)(%r11);
13784
13785+ pax_force_retaddr
13786 ret;
13787 ENDPROC(cast5_ecb_dec_16way)
13788
13789@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13790 * %rdx: src
13791 */
13792
13793- pushq %r12;
13794+ pushq %r14;
13795
13796 movq %rsi, %r11;
13797- movq %rdx, %r12;
13798+ movq %rdx, %r14;
13799
13800 vmovdqu (0*16)(%rdx), RL1;
13801 vmovdqu (1*16)(%rdx), RR1;
13802@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13803 call __cast5_dec_blk16;
13804
13805 /* xor with src */
13806- vmovq (%r12), RX;
13807+ vmovq (%r14), RX;
13808 vpshufd $0x4f, RX, RX;
13809 vpxor RX, RR1, RR1;
13810- vpxor 0*16+8(%r12), RL1, RL1;
13811- vpxor 1*16+8(%r12), RR2, RR2;
13812- vpxor 2*16+8(%r12), RL2, RL2;
13813- vpxor 3*16+8(%r12), RR3, RR3;
13814- vpxor 4*16+8(%r12), RL3, RL3;
13815- vpxor 5*16+8(%r12), RR4, RR4;
13816- vpxor 6*16+8(%r12), RL4, RL4;
13817+ vpxor 0*16+8(%r14), RL1, RL1;
13818+ vpxor 1*16+8(%r14), RR2, RR2;
13819+ vpxor 2*16+8(%r14), RL2, RL2;
13820+ vpxor 3*16+8(%r14), RR3, RR3;
13821+ vpxor 4*16+8(%r14), RL3, RL3;
13822+ vpxor 5*16+8(%r14), RR4, RR4;
13823+ vpxor 6*16+8(%r14), RL4, RL4;
13824
13825 vmovdqu RR1, (0*16)(%r11);
13826 vmovdqu RL1, (1*16)(%r11);
13827@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13828 vmovdqu RR4, (6*16)(%r11);
13829 vmovdqu RL4, (7*16)(%r11);
13830
13831- popq %r12;
13832+ popq %r14;
13833
13834+ pax_force_retaddr
13835 ret;
13836 ENDPROC(cast5_cbc_dec_16way)
13837
13838@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13839 * %rcx: iv (big endian, 64bit)
13840 */
13841
13842- pushq %r12;
13843+ pushq %r14;
13844
13845 movq %rsi, %r11;
13846- movq %rdx, %r12;
13847+ movq %rdx, %r14;
13848
13849 vpcmpeqd RTMP, RTMP, RTMP;
13850 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13851@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13852 call __cast5_enc_blk16;
13853
13854 /* dst = src ^ iv */
13855- vpxor (0*16)(%r12), RR1, RR1;
13856- vpxor (1*16)(%r12), RL1, RL1;
13857- vpxor (2*16)(%r12), RR2, RR2;
13858- vpxor (3*16)(%r12), RL2, RL2;
13859- vpxor (4*16)(%r12), RR3, RR3;
13860- vpxor (5*16)(%r12), RL3, RL3;
13861- vpxor (6*16)(%r12), RR4, RR4;
13862- vpxor (7*16)(%r12), RL4, RL4;
13863+ vpxor (0*16)(%r14), RR1, RR1;
13864+ vpxor (1*16)(%r14), RL1, RL1;
13865+ vpxor (2*16)(%r14), RR2, RR2;
13866+ vpxor (3*16)(%r14), RL2, RL2;
13867+ vpxor (4*16)(%r14), RR3, RR3;
13868+ vpxor (5*16)(%r14), RL3, RL3;
13869+ vpxor (6*16)(%r14), RR4, RR4;
13870+ vpxor (7*16)(%r14), RL4, RL4;
13871 vmovdqu RR1, (0*16)(%r11);
13872 vmovdqu RL1, (1*16)(%r11);
13873 vmovdqu RR2, (2*16)(%r11);
13874@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13875 vmovdqu RR4, (6*16)(%r11);
13876 vmovdqu RL4, (7*16)(%r11);
13877
13878- popq %r12;
13879+ popq %r14;
13880
13881+ pax_force_retaddr
13882 ret;
13883 ENDPROC(cast5_ctr_16way)
13884diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13885index e3531f8..e123f35 100644
13886--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13887+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13888@@ -24,6 +24,7 @@
13889 */
13890
13891 #include <linux/linkage.h>
13892+#include <asm/alternative-asm.h>
13893 #include "glue_helper-asm-avx.S"
13894
13895 .file "cast6-avx-x86_64-asm_64.S"
13896@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13897 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13898 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13899
13900+ pax_force_retaddr
13901 ret;
13902 ENDPROC(__cast6_enc_blk8)
13903
13904@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13905 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13906 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13907
13908+ pax_force_retaddr
13909 ret;
13910 ENDPROC(__cast6_dec_blk8)
13911
13912@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13913
13914 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13915
13916+ pax_force_retaddr
13917 ret;
13918 ENDPROC(cast6_ecb_enc_8way)
13919
13920@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13921
13922 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13923
13924+ pax_force_retaddr
13925 ret;
13926 ENDPROC(cast6_ecb_dec_8way)
13927
13928@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13929 * %rdx: src
13930 */
13931
13932- pushq %r12;
13933+ pushq %r14;
13934
13935 movq %rsi, %r11;
13936- movq %rdx, %r12;
13937+ movq %rdx, %r14;
13938
13939 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13940
13941 call __cast6_dec_blk8;
13942
13943- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13944+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13945
13946- popq %r12;
13947+ popq %r14;
13948
13949+ pax_force_retaddr
13950 ret;
13951 ENDPROC(cast6_cbc_dec_8way)
13952
13953@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13954 * %rcx: iv (little endian, 128bit)
13955 */
13956
13957- pushq %r12;
13958+ pushq %r14;
13959
13960 movq %rsi, %r11;
13961- movq %rdx, %r12;
13962+ movq %rdx, %r14;
13963
13964 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13965 RD2, RX, RKR, RKM);
13966
13967 call __cast6_enc_blk8;
13968
13969- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13970+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13971
13972- popq %r12;
13973+ popq %r14;
13974
13975+ pax_force_retaddr
13976 ret;
13977 ENDPROC(cast6_ctr_8way)
13978
13979@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13980 /* dst <= regs xor IVs(in dst) */
13981 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13982
13983+ pax_force_retaddr
13984 ret;
13985 ENDPROC(cast6_xts_enc_8way)
13986
13987@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13988 /* dst <= regs xor IVs(in dst) */
13989 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13990
13991+ pax_force_retaddr
13992 ret;
13993 ENDPROC(cast6_xts_dec_8way)
13994diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13995index dbc4339..de6e120 100644
13996--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13997+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13998@@ -45,6 +45,7 @@
13999
14000 #include <asm/inst.h>
14001 #include <linux/linkage.h>
14002+#include <asm/alternative-asm.h>
14003
14004 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14005
14006@@ -312,6 +313,7 @@ do_return:
14007 popq %rsi
14008 popq %rdi
14009 popq %rbx
14010+ pax_force_retaddr
14011 ret
14012
14013 ################################################################
14014diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14015index 185fad4..ff4cd36 100644
14016--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14017+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14018@@ -18,6 +18,7 @@
14019
14020 #include <linux/linkage.h>
14021 #include <asm/inst.h>
14022+#include <asm/alternative-asm.h>
14023
14024 .data
14025
14026@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14027 psrlq $1, T2
14028 pxor T2, T1
14029 pxor T1, DATA
14030+ pax_force_retaddr
14031 ret
14032 ENDPROC(__clmul_gf128mul_ble)
14033
14034@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14035 call __clmul_gf128mul_ble
14036 PSHUFB_XMM BSWAP DATA
14037 movups DATA, (%rdi)
14038+ pax_force_retaddr
14039 ret
14040 ENDPROC(clmul_ghash_mul)
14041
14042@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14043 PSHUFB_XMM BSWAP DATA
14044 movups DATA, (%rdi)
14045 .Lupdate_just_ret:
14046+ pax_force_retaddr
14047 ret
14048 ENDPROC(clmul_ghash_update)
14049diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14050index 9279e0b..c4b3d2c 100644
14051--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14052+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14053@@ -1,4 +1,5 @@
14054 #include <linux/linkage.h>
14055+#include <asm/alternative-asm.h>
14056
14057 # enter salsa20_encrypt_bytes
14058 ENTRY(salsa20_encrypt_bytes)
14059@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14060 add %r11,%rsp
14061 mov %rdi,%rax
14062 mov %rsi,%rdx
14063+ pax_force_retaddr
14064 ret
14065 # bytesatleast65:
14066 ._bytesatleast65:
14067@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14068 add %r11,%rsp
14069 mov %rdi,%rax
14070 mov %rsi,%rdx
14071+ pax_force_retaddr
14072 ret
14073 ENDPROC(salsa20_keysetup)
14074
14075@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14076 add %r11,%rsp
14077 mov %rdi,%rax
14078 mov %rsi,%rdx
14079+ pax_force_retaddr
14080 ret
14081 ENDPROC(salsa20_ivsetup)
14082diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14083index 2f202f4..d9164d6 100644
14084--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14085+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14086@@ -24,6 +24,7 @@
14087 */
14088
14089 #include <linux/linkage.h>
14090+#include <asm/alternative-asm.h>
14091 #include "glue_helper-asm-avx.S"
14092
14093 .file "serpent-avx-x86_64-asm_64.S"
14094@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14095 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14096 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14097
14098+ pax_force_retaddr
14099 ret;
14100 ENDPROC(__serpent_enc_blk8_avx)
14101
14102@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14103 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14104 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14105
14106+ pax_force_retaddr
14107 ret;
14108 ENDPROC(__serpent_dec_blk8_avx)
14109
14110@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14111
14112 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14113
14114+ pax_force_retaddr
14115 ret;
14116 ENDPROC(serpent_ecb_enc_8way_avx)
14117
14118@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14119
14120 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14121
14122+ pax_force_retaddr
14123 ret;
14124 ENDPROC(serpent_ecb_dec_8way_avx)
14125
14126@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14127
14128 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14129
14130+ pax_force_retaddr
14131 ret;
14132 ENDPROC(serpent_cbc_dec_8way_avx)
14133
14134@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14135
14136 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14137
14138+ pax_force_retaddr
14139 ret;
14140 ENDPROC(serpent_ctr_8way_avx)
14141
14142@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14143 /* dst <= regs xor IVs(in dst) */
14144 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14145
14146+ pax_force_retaddr
14147 ret;
14148 ENDPROC(serpent_xts_enc_8way_avx)
14149
14150@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14151 /* dst <= regs xor IVs(in dst) */
14152 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14153
14154+ pax_force_retaddr
14155 ret;
14156 ENDPROC(serpent_xts_dec_8way_avx)
14157diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14158index b222085..abd483c 100644
14159--- a/arch/x86/crypto/serpent-avx2-asm_64.S
14160+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14161@@ -15,6 +15,7 @@
14162 */
14163
14164 #include <linux/linkage.h>
14165+#include <asm/alternative-asm.h>
14166 #include "glue_helper-asm-avx2.S"
14167
14168 .file "serpent-avx2-asm_64.S"
14169@@ -610,6 +611,7 @@ __serpent_enc_blk16:
14170 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14171 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14172
14173+ pax_force_retaddr
14174 ret;
14175 ENDPROC(__serpent_enc_blk16)
14176
14177@@ -664,6 +666,7 @@ __serpent_dec_blk16:
14178 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14179 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14180
14181+ pax_force_retaddr
14182 ret;
14183 ENDPROC(__serpent_dec_blk16)
14184
14185@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14186
14187 vzeroupper;
14188
14189+ pax_force_retaddr
14190 ret;
14191 ENDPROC(serpent_ecb_enc_16way)
14192
14193@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14194
14195 vzeroupper;
14196
14197+ pax_force_retaddr
14198 ret;
14199 ENDPROC(serpent_ecb_dec_16way)
14200
14201@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14202
14203 vzeroupper;
14204
14205+ pax_force_retaddr
14206 ret;
14207 ENDPROC(serpent_cbc_dec_16way)
14208
14209@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14210
14211 vzeroupper;
14212
14213+ pax_force_retaddr
14214 ret;
14215 ENDPROC(serpent_ctr_16way)
14216
14217@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14218
14219 vzeroupper;
14220
14221+ pax_force_retaddr
14222 ret;
14223 ENDPROC(serpent_xts_enc_16way)
14224
14225@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14226
14227 vzeroupper;
14228
14229+ pax_force_retaddr
14230 ret;
14231 ENDPROC(serpent_xts_dec_16way)
14232diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14233index acc066c..1559cc4 100644
14234--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14235+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14236@@ -25,6 +25,7 @@
14237 */
14238
14239 #include <linux/linkage.h>
14240+#include <asm/alternative-asm.h>
14241
14242 .file "serpent-sse2-x86_64-asm_64.S"
14243 .text
14244@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14245 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14246 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14247
14248+ pax_force_retaddr
14249 ret;
14250
14251 .L__enc_xor8:
14252 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14253 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14254
14255+ pax_force_retaddr
14256 ret;
14257 ENDPROC(__serpent_enc_blk_8way)
14258
14259@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14260 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14261 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14262
14263+ pax_force_retaddr
14264 ret;
14265 ENDPROC(serpent_dec_blk_8way)
14266diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14267index a410950..9dfe7ad 100644
14268--- a/arch/x86/crypto/sha1_ssse3_asm.S
14269+++ b/arch/x86/crypto/sha1_ssse3_asm.S
14270@@ -29,6 +29,7 @@
14271 */
14272
14273 #include <linux/linkage.h>
14274+#include <asm/alternative-asm.h>
14275
14276 #define CTX %rdi // arg1
14277 #define BUF %rsi // arg2
14278@@ -75,9 +76,9 @@
14279
14280 push %rbx
14281 push %rbp
14282- push %r12
14283+ push %r14
14284
14285- mov %rsp, %r12
14286+ mov %rsp, %r14
14287 sub $64, %rsp # allocate workspace
14288 and $~15, %rsp # align stack
14289
14290@@ -99,11 +100,12 @@
14291 xor %rax, %rax
14292 rep stosq
14293
14294- mov %r12, %rsp # deallocate workspace
14295+ mov %r14, %rsp # deallocate workspace
14296
14297- pop %r12
14298+ pop %r14
14299 pop %rbp
14300 pop %rbx
14301+ pax_force_retaddr
14302 ret
14303
14304 ENDPROC(\name)
14305diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14306index 642f156..51a513c 100644
14307--- a/arch/x86/crypto/sha256-avx-asm.S
14308+++ b/arch/x86/crypto/sha256-avx-asm.S
14309@@ -49,6 +49,7 @@
14310
14311 #ifdef CONFIG_AS_AVX
14312 #include <linux/linkage.h>
14313+#include <asm/alternative-asm.h>
14314
14315 ## assume buffers not aligned
14316 #define VMOVDQ vmovdqu
14317@@ -460,6 +461,7 @@ done_hash:
14318 popq %r13
14319 popq %rbp
14320 popq %rbx
14321+ pax_force_retaddr
14322 ret
14323 ENDPROC(sha256_transform_avx)
14324
14325diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14326index 9e86944..3795e6a 100644
14327--- a/arch/x86/crypto/sha256-avx2-asm.S
14328+++ b/arch/x86/crypto/sha256-avx2-asm.S
14329@@ -50,6 +50,7 @@
14330
14331 #ifdef CONFIG_AS_AVX2
14332 #include <linux/linkage.h>
14333+#include <asm/alternative-asm.h>
14334
14335 ## assume buffers not aligned
14336 #define VMOVDQ vmovdqu
14337@@ -720,6 +721,7 @@ done_hash:
14338 popq %r12
14339 popq %rbp
14340 popq %rbx
14341+ pax_force_retaddr
14342 ret
14343 ENDPROC(sha256_transform_rorx)
14344
14345diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14346index f833b74..8c62a9e 100644
14347--- a/arch/x86/crypto/sha256-ssse3-asm.S
14348+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14349@@ -47,6 +47,7 @@
14350 ########################################################################
14351
14352 #include <linux/linkage.h>
14353+#include <asm/alternative-asm.h>
14354
14355 ## assume buffers not aligned
14356 #define MOVDQ movdqu
14357@@ -471,6 +472,7 @@ done_hash:
14358 popq %rbp
14359 popq %rbx
14360
14361+ pax_force_retaddr
14362 ret
14363 ENDPROC(sha256_transform_ssse3)
14364
14365diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14366index 974dde9..a823ff9 100644
14367--- a/arch/x86/crypto/sha512-avx-asm.S
14368+++ b/arch/x86/crypto/sha512-avx-asm.S
14369@@ -49,6 +49,7 @@
14370
14371 #ifdef CONFIG_AS_AVX
14372 #include <linux/linkage.h>
14373+#include <asm/alternative-asm.h>
14374
14375 .text
14376
14377@@ -364,6 +365,7 @@ updateblock:
14378 mov frame_RSPSAVE(%rsp), %rsp
14379
14380 nowork:
14381+ pax_force_retaddr
14382 ret
14383 ENDPROC(sha512_transform_avx)
14384
14385diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14386index 568b961..ed20c37 100644
14387--- a/arch/x86/crypto/sha512-avx2-asm.S
14388+++ b/arch/x86/crypto/sha512-avx2-asm.S
14389@@ -51,6 +51,7 @@
14390
14391 #ifdef CONFIG_AS_AVX2
14392 #include <linux/linkage.h>
14393+#include <asm/alternative-asm.h>
14394
14395 .text
14396
14397@@ -678,6 +679,7 @@ done_hash:
14398
14399 # Restore Stack Pointer
14400 mov frame_RSPSAVE(%rsp), %rsp
14401+ pax_force_retaddr
14402 ret
14403 ENDPROC(sha512_transform_rorx)
14404
14405diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14406index fb56855..6edd768 100644
14407--- a/arch/x86/crypto/sha512-ssse3-asm.S
14408+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14409@@ -48,6 +48,7 @@
14410 ########################################################################
14411
14412 #include <linux/linkage.h>
14413+#include <asm/alternative-asm.h>
14414
14415 .text
14416
14417@@ -363,6 +364,7 @@ updateblock:
14418 mov frame_RSPSAVE(%rsp), %rsp
14419
14420 nowork:
14421+ pax_force_retaddr
14422 ret
14423 ENDPROC(sha512_transform_ssse3)
14424
14425diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14426index 0505813..b067311 100644
14427--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14428+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14429@@ -24,6 +24,7 @@
14430 */
14431
14432 #include <linux/linkage.h>
14433+#include <asm/alternative-asm.h>
14434 #include "glue_helper-asm-avx.S"
14435
14436 .file "twofish-avx-x86_64-asm_64.S"
14437@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14438 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14439 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14440
14441+ pax_force_retaddr
14442 ret;
14443 ENDPROC(__twofish_enc_blk8)
14444
14445@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14446 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14447 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14448
14449+ pax_force_retaddr
14450 ret;
14451 ENDPROC(__twofish_dec_blk8)
14452
14453@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14454
14455 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14456
14457+ pax_force_retaddr
14458 ret;
14459 ENDPROC(twofish_ecb_enc_8way)
14460
14461@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14462
14463 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14464
14465+ pax_force_retaddr
14466 ret;
14467 ENDPROC(twofish_ecb_dec_8way)
14468
14469@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14470 * %rdx: src
14471 */
14472
14473- pushq %r12;
14474+ pushq %r14;
14475
14476 movq %rsi, %r11;
14477- movq %rdx, %r12;
14478+ movq %rdx, %r14;
14479
14480 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14481
14482 call __twofish_dec_blk8;
14483
14484- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14485+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14486
14487- popq %r12;
14488+ popq %r14;
14489
14490+ pax_force_retaddr
14491 ret;
14492 ENDPROC(twofish_cbc_dec_8way)
14493
14494@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14495 * %rcx: iv (little endian, 128bit)
14496 */
14497
14498- pushq %r12;
14499+ pushq %r14;
14500
14501 movq %rsi, %r11;
14502- movq %rdx, %r12;
14503+ movq %rdx, %r14;
14504
14505 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14506 RD2, RX0, RX1, RY0);
14507
14508 call __twofish_enc_blk8;
14509
14510- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14511+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14512
14513- popq %r12;
14514+ popq %r14;
14515
14516+ pax_force_retaddr
14517 ret;
14518 ENDPROC(twofish_ctr_8way)
14519
14520@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14521 /* dst <= regs xor IVs(in dst) */
14522 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14523
14524+ pax_force_retaddr
14525 ret;
14526 ENDPROC(twofish_xts_enc_8way)
14527
14528@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14529 /* dst <= regs xor IVs(in dst) */
14530 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14531
14532+ pax_force_retaddr
14533 ret;
14534 ENDPROC(twofish_xts_dec_8way)
14535diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14536index 1c3b7ce..02f578d 100644
14537--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14538+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14539@@ -21,6 +21,7 @@
14540 */
14541
14542 #include <linux/linkage.h>
14543+#include <asm/alternative-asm.h>
14544
14545 .file "twofish-x86_64-asm-3way.S"
14546 .text
14547@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14548 popq %r13;
14549 popq %r14;
14550 popq %r15;
14551+ pax_force_retaddr
14552 ret;
14553
14554 .L__enc_xor3:
14555@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14556 popq %r13;
14557 popq %r14;
14558 popq %r15;
14559+ pax_force_retaddr
14560 ret;
14561 ENDPROC(__twofish_enc_blk_3way)
14562
14563@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14564 popq %r13;
14565 popq %r14;
14566 popq %r15;
14567+ pax_force_retaddr
14568 ret;
14569 ENDPROC(twofish_dec_blk_3way)
14570diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14571index a039d21..524b8b2 100644
14572--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14573+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14574@@ -22,6 +22,7 @@
14575
14576 #include <linux/linkage.h>
14577 #include <asm/asm-offsets.h>
14578+#include <asm/alternative-asm.h>
14579
14580 #define a_offset 0
14581 #define b_offset 4
14582@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14583
14584 popq R1
14585 movq $1,%rax
14586+ pax_force_retaddr
14587 ret
14588 ENDPROC(twofish_enc_blk)
14589
14590@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14591
14592 popq R1
14593 movq $1,%rax
14594+ pax_force_retaddr
14595 ret
14596 ENDPROC(twofish_dec_blk)
14597diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14598index d21ff89..6da8e6e 100644
14599--- a/arch/x86/ia32/ia32_aout.c
14600+++ b/arch/x86/ia32/ia32_aout.c
14601@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14602 unsigned long dump_start, dump_size;
14603 struct user32 dump;
14604
14605+ memset(&dump, 0, sizeof(dump));
14606+
14607 fs = get_fs();
14608 set_fs(KERNEL_DS);
14609 has_dumped = 1;
14610diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14611index 2206757..85cbcfa 100644
14612--- a/arch/x86/ia32/ia32_signal.c
14613+++ b/arch/x86/ia32/ia32_signal.c
14614@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14615 if (__get_user(set.sig[0], &frame->sc.oldmask)
14616 || (_COMPAT_NSIG_WORDS > 1
14617 && __copy_from_user((((char *) &set.sig) + 4),
14618- &frame->extramask,
14619+ frame->extramask,
14620 sizeof(frame->extramask))))
14621 goto badframe;
14622
14623@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14624 sp -= frame_size;
14625 /* Align the stack pointer according to the i386 ABI,
14626 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14627- sp = ((sp + 4) & -16ul) - 4;
14628+ sp = ((sp - 12) & -16ul) - 4;
14629 return (void __user *) sp;
14630 }
14631
14632@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14633 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14634 sigreturn);
14635 else
14636- restorer = &frame->retcode;
14637+ restorer = frame->retcode;
14638 }
14639
14640 put_user_try {
14641@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14642 * These are actually not used anymore, but left because some
14643 * gdb versions depend on them as a marker.
14644 */
14645- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14646+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14647 } put_user_catch(err);
14648
14649 if (err)
14650@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14651 0xb8,
14652 __NR_ia32_rt_sigreturn,
14653 0x80cd,
14654- 0,
14655+ 0
14656 };
14657
14658 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14659@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14660
14661 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14662 restorer = ksig->ka.sa.sa_restorer;
14663+ else if (current->mm->context.vdso)
14664+ /* Return stub is in 32bit vsyscall page */
14665+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14666 else
14667- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14668- rt_sigreturn);
14669+ restorer = frame->retcode;
14670 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14671
14672 /*
14673 * Not actually used anymore, but left because some gdb
14674 * versions need it.
14675 */
14676- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14677+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14678 } put_user_catch(err);
14679
14680 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14681diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14682index 4299eb0..c0687a7 100644
14683--- a/arch/x86/ia32/ia32entry.S
14684+++ b/arch/x86/ia32/ia32entry.S
14685@@ -15,8 +15,10 @@
14686 #include <asm/irqflags.h>
14687 #include <asm/asm.h>
14688 #include <asm/smap.h>
14689+#include <asm/pgtable.h>
14690 #include <linux/linkage.h>
14691 #include <linux/err.h>
14692+#include <asm/alternative-asm.h>
14693
14694 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14695 #include <linux/elf-em.h>
14696@@ -62,12 +64,12 @@
14697 */
14698 .macro LOAD_ARGS32 offset, _r9=0
14699 .if \_r9
14700- movl \offset+16(%rsp),%r9d
14701+ movl \offset+R9(%rsp),%r9d
14702 .endif
14703- movl \offset+40(%rsp),%ecx
14704- movl \offset+48(%rsp),%edx
14705- movl \offset+56(%rsp),%esi
14706- movl \offset+64(%rsp),%edi
14707+ movl \offset+RCX(%rsp),%ecx
14708+ movl \offset+RDX(%rsp),%edx
14709+ movl \offset+RSI(%rsp),%esi
14710+ movl \offset+RDI(%rsp),%edi
14711 movl %eax,%eax /* zero extension */
14712 .endm
14713
14714@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14715 ENDPROC(native_irq_enable_sysexit)
14716 #endif
14717
14718+ .macro pax_enter_kernel_user
14719+ pax_set_fptr_mask
14720+#ifdef CONFIG_PAX_MEMORY_UDEREF
14721+ call pax_enter_kernel_user
14722+#endif
14723+ .endm
14724+
14725+ .macro pax_exit_kernel_user
14726+#ifdef CONFIG_PAX_MEMORY_UDEREF
14727+ call pax_exit_kernel_user
14728+#endif
14729+#ifdef CONFIG_PAX_RANDKSTACK
14730+ pushq %rax
14731+ pushq %r11
14732+ call pax_randomize_kstack
14733+ popq %r11
14734+ popq %rax
14735+#endif
14736+ .endm
14737+
14738+ .macro pax_erase_kstack
14739+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14740+ call pax_erase_kstack
14741+#endif
14742+ .endm
14743+
14744 /*
14745 * 32bit SYSENTER instruction entry.
14746 *
14747@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14748 CFI_REGISTER rsp,rbp
14749 SWAPGS_UNSAFE_STACK
14750 movq PER_CPU_VAR(kernel_stack), %rsp
14751- addq $(KERNEL_STACK_OFFSET),%rsp
14752- /*
14753- * No need to follow this irqs on/off section: the syscall
14754- * disabled irqs, here we enable it straight after entry:
14755- */
14756- ENABLE_INTERRUPTS(CLBR_NONE)
14757 movl %ebp,%ebp /* zero extension */
14758 pushq_cfi $__USER32_DS
14759 /*CFI_REL_OFFSET ss,0*/
14760@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14761 CFI_REL_OFFSET rsp,0
14762 pushfq_cfi
14763 /*CFI_REL_OFFSET rflags,0*/
14764- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14765- CFI_REGISTER rip,r10
14766+ orl $X86_EFLAGS_IF,(%rsp)
14767+ GET_THREAD_INFO(%r11)
14768+ movl TI_sysenter_return(%r11), %r11d
14769+ CFI_REGISTER rip,r11
14770 pushq_cfi $__USER32_CS
14771 /*CFI_REL_OFFSET cs,0*/
14772 movl %eax, %eax
14773- pushq_cfi %r10
14774+ pushq_cfi %r11
14775 CFI_REL_OFFSET rip,0
14776 pushq_cfi %rax
14777 cld
14778 SAVE_ARGS 0,1,0
14779+ pax_enter_kernel_user
14780+
14781+#ifdef CONFIG_PAX_RANDKSTACK
14782+ pax_erase_kstack
14783+#endif
14784+
14785+ /*
14786+ * No need to follow this irqs on/off section: the syscall
14787+ * disabled irqs, here we enable it straight after entry:
14788+ */
14789+ ENABLE_INTERRUPTS(CLBR_NONE)
14790 /* no need to do an access_ok check here because rbp has been
14791 32bit zero extended */
14792+
14793+#ifdef CONFIG_PAX_MEMORY_UDEREF
14794+ addq pax_user_shadow_base,%rbp
14795+ ASM_PAX_OPEN_USERLAND
14796+#endif
14797+
14798 ASM_STAC
14799 1: movl (%rbp),%ebp
14800 _ASM_EXTABLE(1b,ia32_badarg)
14801 ASM_CLAC
14802- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14803- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14804+
14805+#ifdef CONFIG_PAX_MEMORY_UDEREF
14806+ ASM_PAX_CLOSE_USERLAND
14807+#endif
14808+
14809+ GET_THREAD_INFO(%r11)
14810+ orl $TS_COMPAT,TI_status(%r11)
14811+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14812 CFI_REMEMBER_STATE
14813 jnz sysenter_tracesys
14814 cmpq $(IA32_NR_syscalls-1),%rax
14815@@ -162,15 +209,18 @@ sysenter_do_call:
14816 sysenter_dispatch:
14817 call *ia32_sys_call_table(,%rax,8)
14818 movq %rax,RAX-ARGOFFSET(%rsp)
14819+ GET_THREAD_INFO(%r11)
14820 DISABLE_INTERRUPTS(CLBR_NONE)
14821 TRACE_IRQS_OFF
14822- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14823+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14824 jnz sysexit_audit
14825 sysexit_from_sys_call:
14826- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14827+ pax_exit_kernel_user
14828+ pax_erase_kstack
14829+ andl $~TS_COMPAT,TI_status(%r11)
14830 /* clear IF, that popfq doesn't enable interrupts early */
14831- andl $~0x200,EFLAGS-R11(%rsp)
14832- movl RIP-R11(%rsp),%edx /* User %eip */
14833+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14834+ movl RIP(%rsp),%edx /* User %eip */
14835 CFI_REGISTER rip,rdx
14836 RESTORE_ARGS 0,24,0,0,0,0
14837 xorq %r8,%r8
14838@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14839 movl %eax,%esi /* 2nd arg: syscall number */
14840 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14841 call __audit_syscall_entry
14842+
14843+ pax_erase_kstack
14844+
14845 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14846 cmpq $(IA32_NR_syscalls-1),%rax
14847 ja ia32_badsys
14848@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14849 .endm
14850
14851 .macro auditsys_exit exit
14852- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14853+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14854 jnz ia32_ret_from_sys_call
14855 TRACE_IRQS_ON
14856 ENABLE_INTERRUPTS(CLBR_NONE)
14857@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14858 1: setbe %al /* 1 if error, 0 if not */
14859 movzbl %al,%edi /* zero-extend that into %edi */
14860 call __audit_syscall_exit
14861+ GET_THREAD_INFO(%r11)
14862 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14863 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14864 DISABLE_INTERRUPTS(CLBR_NONE)
14865 TRACE_IRQS_OFF
14866- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14867+ testl %edi,TI_flags(%r11)
14868 jz \exit
14869 CLEAR_RREGS -ARGOFFSET
14870 jmp int_with_check
14871@@ -237,7 +291,7 @@ sysexit_audit:
14872
14873 sysenter_tracesys:
14874 #ifdef CONFIG_AUDITSYSCALL
14875- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14876+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14877 jz sysenter_auditsys
14878 #endif
14879 SAVE_REST
14880@@ -249,6 +303,9 @@ sysenter_tracesys:
14881 RESTORE_REST
14882 cmpq $(IA32_NR_syscalls-1),%rax
14883 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14884+
14885+ pax_erase_kstack
14886+
14887 jmp sysenter_do_call
14888 CFI_ENDPROC
14889 ENDPROC(ia32_sysenter_target)
14890@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14891 ENTRY(ia32_cstar_target)
14892 CFI_STARTPROC32 simple
14893 CFI_SIGNAL_FRAME
14894- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14895+ CFI_DEF_CFA rsp,0
14896 CFI_REGISTER rip,rcx
14897 /*CFI_REGISTER rflags,r11*/
14898 SWAPGS_UNSAFE_STACK
14899 movl %esp,%r8d
14900 CFI_REGISTER rsp,r8
14901 movq PER_CPU_VAR(kernel_stack),%rsp
14902+ SAVE_ARGS 8*6,0,0
14903+ pax_enter_kernel_user
14904+
14905+#ifdef CONFIG_PAX_RANDKSTACK
14906+ pax_erase_kstack
14907+#endif
14908+
14909 /*
14910 * No need to follow this irqs on/off section: the syscall
14911 * disabled irqs and here we enable it straight after entry:
14912 */
14913 ENABLE_INTERRUPTS(CLBR_NONE)
14914- SAVE_ARGS 8,0,0
14915 movl %eax,%eax /* zero extension */
14916 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14917 movq %rcx,RIP-ARGOFFSET(%rsp)
14918@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14919 /* no need to do an access_ok check here because r8 has been
14920 32bit zero extended */
14921 /* hardware stack frame is complete now */
14922+
14923+#ifdef CONFIG_PAX_MEMORY_UDEREF
14924+ ASM_PAX_OPEN_USERLAND
14925+ movq pax_user_shadow_base,%r8
14926+ addq RSP-ARGOFFSET(%rsp),%r8
14927+#endif
14928+
14929 ASM_STAC
14930 1: movl (%r8),%r9d
14931 _ASM_EXTABLE(1b,ia32_badarg)
14932 ASM_CLAC
14933- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14934- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14935+
14936+#ifdef CONFIG_PAX_MEMORY_UDEREF
14937+ ASM_PAX_CLOSE_USERLAND
14938+#endif
14939+
14940+ GET_THREAD_INFO(%r11)
14941+ orl $TS_COMPAT,TI_status(%r11)
14942+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14943 CFI_REMEMBER_STATE
14944 jnz cstar_tracesys
14945 cmpq $IA32_NR_syscalls-1,%rax
14946@@ -319,13 +395,16 @@ cstar_do_call:
14947 cstar_dispatch:
14948 call *ia32_sys_call_table(,%rax,8)
14949 movq %rax,RAX-ARGOFFSET(%rsp)
14950+ GET_THREAD_INFO(%r11)
14951 DISABLE_INTERRUPTS(CLBR_NONE)
14952 TRACE_IRQS_OFF
14953- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14954+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14955 jnz sysretl_audit
14956 sysretl_from_sys_call:
14957- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14958- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14959+ pax_exit_kernel_user
14960+ pax_erase_kstack
14961+ andl $~TS_COMPAT,TI_status(%r11)
14962+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14963 movl RIP-ARGOFFSET(%rsp),%ecx
14964 CFI_REGISTER rip,rcx
14965 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14966@@ -352,7 +431,7 @@ sysretl_audit:
14967
14968 cstar_tracesys:
14969 #ifdef CONFIG_AUDITSYSCALL
14970- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14971+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14972 jz cstar_auditsys
14973 #endif
14974 xchgl %r9d,%ebp
14975@@ -366,11 +445,19 @@ cstar_tracesys:
14976 xchgl %ebp,%r9d
14977 cmpq $(IA32_NR_syscalls-1),%rax
14978 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14979+
14980+ pax_erase_kstack
14981+
14982 jmp cstar_do_call
14983 END(ia32_cstar_target)
14984
14985 ia32_badarg:
14986 ASM_CLAC
14987+
14988+#ifdef CONFIG_PAX_MEMORY_UDEREF
14989+ ASM_PAX_CLOSE_USERLAND
14990+#endif
14991+
14992 movq $-EFAULT,%rax
14993 jmp ia32_sysret
14994 CFI_ENDPROC
14995@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14996 CFI_REL_OFFSET rip,RIP-RIP
14997 PARAVIRT_ADJUST_EXCEPTION_FRAME
14998 SWAPGS
14999- /*
15000- * No need to follow this irqs on/off section: the syscall
15001- * disabled irqs and here we enable it straight after entry:
15002- */
15003- ENABLE_INTERRUPTS(CLBR_NONE)
15004 movl %eax,%eax
15005 pushq_cfi %rax
15006 cld
15007 /* note the registers are not zero extended to the sf.
15008 this could be a problem. */
15009 SAVE_ARGS 0,1,0
15010- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15011- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15012+ pax_enter_kernel_user
15013+
15014+#ifdef CONFIG_PAX_RANDKSTACK
15015+ pax_erase_kstack
15016+#endif
15017+
15018+ /*
15019+ * No need to follow this irqs on/off section: the syscall
15020+ * disabled irqs and here we enable it straight after entry:
15021+ */
15022+ ENABLE_INTERRUPTS(CLBR_NONE)
15023+ GET_THREAD_INFO(%r11)
15024+ orl $TS_COMPAT,TI_status(%r11)
15025+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15026 jnz ia32_tracesys
15027 cmpq $(IA32_NR_syscalls-1),%rax
15028 ja ia32_badsys
15029@@ -442,6 +536,9 @@ ia32_tracesys:
15030 RESTORE_REST
15031 cmpq $(IA32_NR_syscalls-1),%rax
15032 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15033+
15034+ pax_erase_kstack
15035+
15036 jmp ia32_do_call
15037 END(ia32_syscall)
15038
15039diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15040index 8e0ceec..af13504 100644
15041--- a/arch/x86/ia32/sys_ia32.c
15042+++ b/arch/x86/ia32/sys_ia32.c
15043@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15044 */
15045 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15046 {
15047- typeof(ubuf->st_uid) uid = 0;
15048- typeof(ubuf->st_gid) gid = 0;
15049+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
15050+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
15051 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15052 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15053 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15054diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15055index 372231c..51b537d 100644
15056--- a/arch/x86/include/asm/alternative-asm.h
15057+++ b/arch/x86/include/asm/alternative-asm.h
15058@@ -18,6 +18,45 @@
15059 .endm
15060 #endif
15061
15062+#ifdef KERNEXEC_PLUGIN
15063+ .macro pax_force_retaddr_bts rip=0
15064+ btsq $63,\rip(%rsp)
15065+ .endm
15066+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15067+ .macro pax_force_retaddr rip=0, reload=0
15068+ btsq $63,\rip(%rsp)
15069+ .endm
15070+ .macro pax_force_fptr ptr
15071+ btsq $63,\ptr
15072+ .endm
15073+ .macro pax_set_fptr_mask
15074+ .endm
15075+#endif
15076+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15077+ .macro pax_force_retaddr rip=0, reload=0
15078+ .if \reload
15079+ pax_set_fptr_mask
15080+ .endif
15081+ orq %r12,\rip(%rsp)
15082+ .endm
15083+ .macro pax_force_fptr ptr
15084+ orq %r12,\ptr
15085+ .endm
15086+ .macro pax_set_fptr_mask
15087+ movabs $0x8000000000000000,%r12
15088+ .endm
15089+#endif
15090+#else
15091+ .macro pax_force_retaddr rip=0, reload=0
15092+ .endm
15093+ .macro pax_force_fptr ptr
15094+ .endm
15095+ .macro pax_force_retaddr_bts rip=0
15096+ .endm
15097+ .macro pax_set_fptr_mask
15098+ .endm
15099+#endif
15100+
15101 .macro altinstruction_entry orig alt feature orig_len alt_len
15102 .long \orig - .
15103 .long \alt - .
15104diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15105index 0a3f9c9..c9d081d 100644
15106--- a/arch/x86/include/asm/alternative.h
15107+++ b/arch/x86/include/asm/alternative.h
15108@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15109 ".pushsection .discard,\"aw\",@progbits\n" \
15110 DISCARD_ENTRY(1) \
15111 ".popsection\n" \
15112- ".pushsection .altinstr_replacement, \"ax\"\n" \
15113+ ".pushsection .altinstr_replacement, \"a\"\n" \
15114 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15115 ".popsection"
15116
15117@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15118 DISCARD_ENTRY(1) \
15119 DISCARD_ENTRY(2) \
15120 ".popsection\n" \
15121- ".pushsection .altinstr_replacement, \"ax\"\n" \
15122+ ".pushsection .altinstr_replacement, \"a\"\n" \
15123 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15124 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15125 ".popsection"
15126diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15127index 1d2091a..f5074c1 100644
15128--- a/arch/x86/include/asm/apic.h
15129+++ b/arch/x86/include/asm/apic.h
15130@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15131
15132 #ifdef CONFIG_X86_LOCAL_APIC
15133
15134-extern unsigned int apic_verbosity;
15135+extern int apic_verbosity;
15136 extern int local_apic_timer_c2_ok;
15137
15138 extern int disable_apic;
15139diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15140index 20370c6..a2eb9b0 100644
15141--- a/arch/x86/include/asm/apm.h
15142+++ b/arch/x86/include/asm/apm.h
15143@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15144 __asm__ __volatile__(APM_DO_ZERO_SEGS
15145 "pushl %%edi\n\t"
15146 "pushl %%ebp\n\t"
15147- "lcall *%%cs:apm_bios_entry\n\t"
15148+ "lcall *%%ss:apm_bios_entry\n\t"
15149 "setc %%al\n\t"
15150 "popl %%ebp\n\t"
15151 "popl %%edi\n\t"
15152@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15153 __asm__ __volatile__(APM_DO_ZERO_SEGS
15154 "pushl %%edi\n\t"
15155 "pushl %%ebp\n\t"
15156- "lcall *%%cs:apm_bios_entry\n\t"
15157+ "lcall *%%ss:apm_bios_entry\n\t"
15158 "setc %%bl\n\t"
15159 "popl %%ebp\n\t"
15160 "popl %%edi\n\t"
15161diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15162index b17f4f4..9620151 100644
15163--- a/arch/x86/include/asm/atomic.h
15164+++ b/arch/x86/include/asm/atomic.h
15165@@ -23,7 +23,18 @@
15166 */
15167 static inline int atomic_read(const atomic_t *v)
15168 {
15169- return (*(volatile int *)&(v)->counter);
15170+ return (*(volatile const int *)&(v)->counter);
15171+}
15172+
15173+/**
15174+ * atomic_read_unchecked - read atomic variable
15175+ * @v: pointer of type atomic_unchecked_t
15176+ *
15177+ * Atomically reads the value of @v.
15178+ */
15179+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15180+{
15181+ return (*(volatile const int *)&(v)->counter);
15182 }
15183
15184 /**
15185@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
15186 }
15187
15188 /**
15189+ * atomic_set_unchecked - set atomic variable
15190+ * @v: pointer of type atomic_unchecked_t
15191+ * @i: required value
15192+ *
15193+ * Atomically sets the value of @v to @i.
15194+ */
15195+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15196+{
15197+ v->counter = i;
15198+}
15199+
15200+/**
15201 * atomic_add - add integer to atomic variable
15202 * @i: integer value to add
15203 * @v: pointer of type atomic_t
15204@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
15205 */
15206 static inline void atomic_add(int i, atomic_t *v)
15207 {
15208- asm volatile(LOCK_PREFIX "addl %1,%0"
15209+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15210+
15211+#ifdef CONFIG_PAX_REFCOUNT
15212+ "jno 0f\n"
15213+ LOCK_PREFIX "subl %1,%0\n"
15214+ "int $4\n0:\n"
15215+ _ASM_EXTABLE(0b, 0b)
15216+#endif
15217+
15218+ : "+m" (v->counter)
15219+ : "ir" (i));
15220+}
15221+
15222+/**
15223+ * atomic_add_unchecked - add integer to atomic variable
15224+ * @i: integer value to add
15225+ * @v: pointer of type atomic_unchecked_t
15226+ *
15227+ * Atomically adds @i to @v.
15228+ */
15229+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15230+{
15231+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15232 : "+m" (v->counter)
15233 : "ir" (i));
15234 }
15235@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
15236 */
15237 static inline void atomic_sub(int i, atomic_t *v)
15238 {
15239- asm volatile(LOCK_PREFIX "subl %1,%0"
15240+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15241+
15242+#ifdef CONFIG_PAX_REFCOUNT
15243+ "jno 0f\n"
15244+ LOCK_PREFIX "addl %1,%0\n"
15245+ "int $4\n0:\n"
15246+ _ASM_EXTABLE(0b, 0b)
15247+#endif
15248+
15249+ : "+m" (v->counter)
15250+ : "ir" (i));
15251+}
15252+
15253+/**
15254+ * atomic_sub_unchecked - subtract integer from atomic variable
15255+ * @i: integer value to subtract
15256+ * @v: pointer of type atomic_unchecked_t
15257+ *
15258+ * Atomically subtracts @i from @v.
15259+ */
15260+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15261+{
15262+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15263 : "+m" (v->counter)
15264 : "ir" (i));
15265 }
15266@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15267 */
15268 static inline int atomic_sub_and_test(int i, atomic_t *v)
15269 {
15270- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15271+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15272 }
15273
15274 /**
15275@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15276 */
15277 static inline void atomic_inc(atomic_t *v)
15278 {
15279- asm volatile(LOCK_PREFIX "incl %0"
15280+ asm volatile(LOCK_PREFIX "incl %0\n"
15281+
15282+#ifdef CONFIG_PAX_REFCOUNT
15283+ "jno 0f\n"
15284+ LOCK_PREFIX "decl %0\n"
15285+ "int $4\n0:\n"
15286+ _ASM_EXTABLE(0b, 0b)
15287+#endif
15288+
15289+ : "+m" (v->counter));
15290+}
15291+
15292+/**
15293+ * atomic_inc_unchecked - increment atomic variable
15294+ * @v: pointer of type atomic_unchecked_t
15295+ *
15296+ * Atomically increments @v by 1.
15297+ */
15298+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15299+{
15300+ asm volatile(LOCK_PREFIX "incl %0\n"
15301 : "+m" (v->counter));
15302 }
15303
15304@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15305 */
15306 static inline void atomic_dec(atomic_t *v)
15307 {
15308- asm volatile(LOCK_PREFIX "decl %0"
15309+ asm volatile(LOCK_PREFIX "decl %0\n"
15310+
15311+#ifdef CONFIG_PAX_REFCOUNT
15312+ "jno 0f\n"
15313+ LOCK_PREFIX "incl %0\n"
15314+ "int $4\n0:\n"
15315+ _ASM_EXTABLE(0b, 0b)
15316+#endif
15317+
15318+ : "+m" (v->counter));
15319+}
15320+
15321+/**
15322+ * atomic_dec_unchecked - decrement atomic variable
15323+ * @v: pointer of type atomic_unchecked_t
15324+ *
15325+ * Atomically decrements @v by 1.
15326+ */
15327+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15328+{
15329+ asm volatile(LOCK_PREFIX "decl %0\n"
15330 : "+m" (v->counter));
15331 }
15332
15333@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15334 */
15335 static inline int atomic_dec_and_test(atomic_t *v)
15336 {
15337- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15338+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15339 }
15340
15341 /**
15342@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15343 */
15344 static inline int atomic_inc_and_test(atomic_t *v)
15345 {
15346- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15347+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15348+}
15349+
15350+/**
15351+ * atomic_inc_and_test_unchecked - increment and test
15352+ * @v: pointer of type atomic_unchecked_t
15353+ *
15354+ * Atomically increments @v by 1
15355+ * and returns true if the result is zero, or false for all
15356+ * other cases.
15357+ */
15358+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15359+{
15360+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15361 }
15362
15363 /**
15364@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15365 */
15366 static inline int atomic_add_negative(int i, atomic_t *v)
15367 {
15368- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15369+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15370 }
15371
15372 /**
15373@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15374 */
15375 static inline int atomic_add_return(int i, atomic_t *v)
15376 {
15377+ return i + xadd_check_overflow(&v->counter, i);
15378+}
15379+
15380+/**
15381+ * atomic_add_return_unchecked - add integer and return
15382+ * @i: integer value to add
15383+ * @v: pointer of type atomic_unchecked_t
15384+ *
15385+ * Atomically adds @i to @v and returns @i + @v
15386+ */
15387+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15388+{
15389 return i + xadd(&v->counter, i);
15390 }
15391
15392@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15393 }
15394
15395 #define atomic_inc_return(v) (atomic_add_return(1, v))
15396+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15397+{
15398+ return atomic_add_return_unchecked(1, v);
15399+}
15400 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15401
15402-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15403+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15404+{
15405+ return cmpxchg(&v->counter, old, new);
15406+}
15407+
15408+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15409 {
15410 return cmpxchg(&v->counter, old, new);
15411 }
15412@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15413 return xchg(&v->counter, new);
15414 }
15415
15416+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15417+{
15418+ return xchg(&v->counter, new);
15419+}
15420+
15421 /**
15422 * __atomic_add_unless - add unless the number is already a given value
15423 * @v: pointer of type atomic_t
15424@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15425 * Atomically adds @a to @v, so long as @v was not already @u.
15426 * Returns the old value of @v.
15427 */
15428-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15429+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15430 {
15431- int c, old;
15432+ int c, old, new;
15433 c = atomic_read(v);
15434 for (;;) {
15435- if (unlikely(c == (u)))
15436+ if (unlikely(c == u))
15437 break;
15438- old = atomic_cmpxchg((v), c, c + (a));
15439+
15440+ asm volatile("addl %2,%0\n"
15441+
15442+#ifdef CONFIG_PAX_REFCOUNT
15443+ "jno 0f\n"
15444+ "subl %2,%0\n"
15445+ "int $4\n0:\n"
15446+ _ASM_EXTABLE(0b, 0b)
15447+#endif
15448+
15449+ : "=r" (new)
15450+ : "0" (c), "ir" (a));
15451+
15452+ old = atomic_cmpxchg(v, c, new);
15453 if (likely(old == c))
15454 break;
15455 c = old;
15456@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15457 }
15458
15459 /**
15460+ * atomic_inc_not_zero_hint - increment if not null
15461+ * @v: pointer of type atomic_t
15462+ * @hint: probable value of the atomic before the increment
15463+ *
15464+ * This version of atomic_inc_not_zero() gives a hint of probable
15465+ * value of the atomic. This helps processor to not read the memory
15466+ * before doing the atomic read/modify/write cycle, lowering
15467+ * number of bus transactions on some arches.
15468+ *
15469+ * Returns: 0 if increment was not done, 1 otherwise.
15470+ */
15471+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15472+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15473+{
15474+ int val, c = hint, new;
15475+
15476+ /* sanity test, should be removed by compiler if hint is a constant */
15477+ if (!hint)
15478+ return __atomic_add_unless(v, 1, 0);
15479+
15480+ do {
15481+ asm volatile("incl %0\n"
15482+
15483+#ifdef CONFIG_PAX_REFCOUNT
15484+ "jno 0f\n"
15485+ "decl %0\n"
15486+ "int $4\n0:\n"
15487+ _ASM_EXTABLE(0b, 0b)
15488+#endif
15489+
15490+ : "=r" (new)
15491+ : "0" (c));
15492+
15493+ val = atomic_cmpxchg(v, c, new);
15494+ if (val == c)
15495+ return 1;
15496+ c = val;
15497+ } while (c);
15498+
15499+ return 0;
15500+}
15501+
15502+/**
15503 * atomic_inc_short - increment of a short integer
15504 * @v: pointer to type int
15505 *
15506@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15507 #endif
15508
15509 /* These are x86-specific, used by some header files */
15510-#define atomic_clear_mask(mask, addr) \
15511- asm volatile(LOCK_PREFIX "andl %0,%1" \
15512- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15513+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15514+{
15515+ asm volatile(LOCK_PREFIX "andl %1,%0"
15516+ : "+m" (v->counter)
15517+ : "r" (~(mask))
15518+ : "memory");
15519+}
15520
15521-#define atomic_set_mask(mask, addr) \
15522- asm volatile(LOCK_PREFIX "orl %0,%1" \
15523- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15524- : "memory")
15525+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15526+{
15527+ asm volatile(LOCK_PREFIX "andl %1,%0"
15528+ : "+m" (v->counter)
15529+ : "r" (~(mask))
15530+ : "memory");
15531+}
15532+
15533+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15534+{
15535+ asm volatile(LOCK_PREFIX "orl %1,%0"
15536+ : "+m" (v->counter)
15537+ : "r" (mask)
15538+ : "memory");
15539+}
15540+
15541+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15542+{
15543+ asm volatile(LOCK_PREFIX "orl %1,%0"
15544+ : "+m" (v->counter)
15545+ : "r" (mask)
15546+ : "memory");
15547+}
15548
15549 /* Atomic operations are already serializing on x86 */
15550 #define smp_mb__before_atomic_dec() barrier()
15551diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15552index b154de7..bf18a5a 100644
15553--- a/arch/x86/include/asm/atomic64_32.h
15554+++ b/arch/x86/include/asm/atomic64_32.h
15555@@ -12,6 +12,14 @@ typedef struct {
15556 u64 __aligned(8) counter;
15557 } atomic64_t;
15558
15559+#ifdef CONFIG_PAX_REFCOUNT
15560+typedef struct {
15561+ u64 __aligned(8) counter;
15562+} atomic64_unchecked_t;
15563+#else
15564+typedef atomic64_t atomic64_unchecked_t;
15565+#endif
15566+
15567 #define ATOMIC64_INIT(val) { (val) }
15568
15569 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15570@@ -37,21 +45,31 @@ typedef struct {
15571 ATOMIC64_DECL_ONE(sym##_386)
15572
15573 ATOMIC64_DECL_ONE(add_386);
15574+ATOMIC64_DECL_ONE(add_unchecked_386);
15575 ATOMIC64_DECL_ONE(sub_386);
15576+ATOMIC64_DECL_ONE(sub_unchecked_386);
15577 ATOMIC64_DECL_ONE(inc_386);
15578+ATOMIC64_DECL_ONE(inc_unchecked_386);
15579 ATOMIC64_DECL_ONE(dec_386);
15580+ATOMIC64_DECL_ONE(dec_unchecked_386);
15581 #endif
15582
15583 #define alternative_atomic64(f, out, in...) \
15584 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15585
15586 ATOMIC64_DECL(read);
15587+ATOMIC64_DECL(read_unchecked);
15588 ATOMIC64_DECL(set);
15589+ATOMIC64_DECL(set_unchecked);
15590 ATOMIC64_DECL(xchg);
15591 ATOMIC64_DECL(add_return);
15592+ATOMIC64_DECL(add_return_unchecked);
15593 ATOMIC64_DECL(sub_return);
15594+ATOMIC64_DECL(sub_return_unchecked);
15595 ATOMIC64_DECL(inc_return);
15596+ATOMIC64_DECL(inc_return_unchecked);
15597 ATOMIC64_DECL(dec_return);
15598+ATOMIC64_DECL(dec_return_unchecked);
15599 ATOMIC64_DECL(dec_if_positive);
15600 ATOMIC64_DECL(inc_not_zero);
15601 ATOMIC64_DECL(add_unless);
15602@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15603 }
15604
15605 /**
15606+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15607+ * @p: pointer to type atomic64_unchecked_t
15608+ * @o: expected value
15609+ * @n: new value
15610+ *
15611+ * Atomically sets @v to @n if it was equal to @o and returns
15612+ * the old value.
15613+ */
15614+
15615+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15616+{
15617+ return cmpxchg64(&v->counter, o, n);
15618+}
15619+
15620+/**
15621 * atomic64_xchg - xchg atomic64 variable
15622 * @v: pointer to type atomic64_t
15623 * @n: value to assign
15624@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15625 }
15626
15627 /**
15628+ * atomic64_set_unchecked - set atomic64 variable
15629+ * @v: pointer to type atomic64_unchecked_t
15630+ * @n: value to assign
15631+ *
15632+ * Atomically sets the value of @v to @n.
15633+ */
15634+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15635+{
15636+ unsigned high = (unsigned)(i >> 32);
15637+ unsigned low = (unsigned)i;
15638+ alternative_atomic64(set, /* no output */,
15639+ "S" (v), "b" (low), "c" (high)
15640+ : "eax", "edx", "memory");
15641+}
15642+
15643+/**
15644 * atomic64_read - read atomic64 variable
15645 * @v: pointer to type atomic64_t
15646 *
15647@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15648 }
15649
15650 /**
15651+ * atomic64_read_unchecked - read atomic64 variable
15652+ * @v: pointer to type atomic64_unchecked_t
15653+ *
15654+ * Atomically reads the value of @v and returns it.
15655+ */
15656+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15657+{
15658+ long long r;
15659+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15660+ return r;
15661+ }
15662+
15663+/**
15664 * atomic64_add_return - add and return
15665 * @i: integer value to add
15666 * @v: pointer to type atomic64_t
15667@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15668 return i;
15669 }
15670
15671+/**
15672+ * atomic64_add_return_unchecked - add and return
15673+ * @i: integer value to add
15674+ * @v: pointer to type atomic64_unchecked_t
15675+ *
15676+ * Atomically adds @i to @v and returns @i + *@v
15677+ */
15678+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15679+{
15680+ alternative_atomic64(add_return_unchecked,
15681+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15682+ ASM_NO_INPUT_CLOBBER("memory"));
15683+ return i;
15684+}
15685+
15686 /*
15687 * Other variants with different arithmetic operators:
15688 */
15689@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15690 return a;
15691 }
15692
15693+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15694+{
15695+ long long a;
15696+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15697+ "S" (v) : "memory", "ecx");
15698+ return a;
15699+}
15700+
15701 static inline long long atomic64_dec_return(atomic64_t *v)
15702 {
15703 long long a;
15704@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15705 }
15706
15707 /**
15708+ * atomic64_add_unchecked - add integer to atomic64 variable
15709+ * @i: integer value to add
15710+ * @v: pointer to type atomic64_unchecked_t
15711+ *
15712+ * Atomically adds @i to @v.
15713+ */
15714+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15715+{
15716+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15717+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15718+ ASM_NO_INPUT_CLOBBER("memory"));
15719+ return i;
15720+}
15721+
15722+/**
15723 * atomic64_sub - subtract the atomic64 variable
15724 * @i: integer value to subtract
15725 * @v: pointer to type atomic64_t
15726diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15727index 46e9052..ae45136 100644
15728--- a/arch/x86/include/asm/atomic64_64.h
15729+++ b/arch/x86/include/asm/atomic64_64.h
15730@@ -18,7 +18,19 @@
15731 */
15732 static inline long atomic64_read(const atomic64_t *v)
15733 {
15734- return (*(volatile long *)&(v)->counter);
15735+ return (*(volatile const long *)&(v)->counter);
15736+}
15737+
15738+/**
15739+ * atomic64_read_unchecked - read atomic64 variable
15740+ * @v: pointer of type atomic64_unchecked_t
15741+ *
15742+ * Atomically reads the value of @v.
15743+ * Doesn't imply a read memory barrier.
15744+ */
15745+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15746+{
15747+ return (*(volatile const long *)&(v)->counter);
15748 }
15749
15750 /**
15751@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15752 }
15753
15754 /**
15755+ * atomic64_set_unchecked - set atomic64 variable
15756+ * @v: pointer to type atomic64_unchecked_t
15757+ * @i: required value
15758+ *
15759+ * Atomically sets the value of @v to @i.
15760+ */
15761+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15762+{
15763+ v->counter = i;
15764+}
15765+
15766+/**
15767 * atomic64_add - add integer to atomic64 variable
15768 * @i: integer value to add
15769 * @v: pointer to type atomic64_t
15770@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15771 */
15772 static inline void atomic64_add(long i, atomic64_t *v)
15773 {
15774+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15775+
15776+#ifdef CONFIG_PAX_REFCOUNT
15777+ "jno 0f\n"
15778+ LOCK_PREFIX "subq %1,%0\n"
15779+ "int $4\n0:\n"
15780+ _ASM_EXTABLE(0b, 0b)
15781+#endif
15782+
15783+ : "=m" (v->counter)
15784+ : "er" (i), "m" (v->counter));
15785+}
15786+
15787+/**
15788+ * atomic64_add_unchecked - add integer to atomic64 variable
15789+ * @i: integer value to add
15790+ * @v: pointer to type atomic64_unchecked_t
15791+ *
15792+ * Atomically adds @i to @v.
15793+ */
15794+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15795+{
15796 asm volatile(LOCK_PREFIX "addq %1,%0"
15797 : "=m" (v->counter)
15798 : "er" (i), "m" (v->counter));
15799@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15800 */
15801 static inline void atomic64_sub(long i, atomic64_t *v)
15802 {
15803- asm volatile(LOCK_PREFIX "subq %1,%0"
15804+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15805+
15806+#ifdef CONFIG_PAX_REFCOUNT
15807+ "jno 0f\n"
15808+ LOCK_PREFIX "addq %1,%0\n"
15809+ "int $4\n0:\n"
15810+ _ASM_EXTABLE(0b, 0b)
15811+#endif
15812+
15813+ : "=m" (v->counter)
15814+ : "er" (i), "m" (v->counter));
15815+}
15816+
15817+/**
15818+ * atomic64_sub_unchecked - subtract the atomic64 variable
15819+ * @i: integer value to subtract
15820+ * @v: pointer to type atomic64_unchecked_t
15821+ *
15822+ * Atomically subtracts @i from @v.
15823+ */
15824+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15825+{
15826+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15827 : "=m" (v->counter)
15828 : "er" (i), "m" (v->counter));
15829 }
15830@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15831 */
15832 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15833 {
15834- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15835+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15836 }
15837
15838 /**
15839@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15840 */
15841 static inline void atomic64_inc(atomic64_t *v)
15842 {
15843+ asm volatile(LOCK_PREFIX "incq %0\n"
15844+
15845+#ifdef CONFIG_PAX_REFCOUNT
15846+ "jno 0f\n"
15847+ LOCK_PREFIX "decq %0\n"
15848+ "int $4\n0:\n"
15849+ _ASM_EXTABLE(0b, 0b)
15850+#endif
15851+
15852+ : "=m" (v->counter)
15853+ : "m" (v->counter));
15854+}
15855+
15856+/**
15857+ * atomic64_inc_unchecked - increment atomic64 variable
15858+ * @v: pointer to type atomic64_unchecked_t
15859+ *
15860+ * Atomically increments @v by 1.
15861+ */
15862+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15863+{
15864 asm volatile(LOCK_PREFIX "incq %0"
15865 : "=m" (v->counter)
15866 : "m" (v->counter));
15867@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15868 */
15869 static inline void atomic64_dec(atomic64_t *v)
15870 {
15871- asm volatile(LOCK_PREFIX "decq %0"
15872+ asm volatile(LOCK_PREFIX "decq %0\n"
15873+
15874+#ifdef CONFIG_PAX_REFCOUNT
15875+ "jno 0f\n"
15876+ LOCK_PREFIX "incq %0\n"
15877+ "int $4\n0:\n"
15878+ _ASM_EXTABLE(0b, 0b)
15879+#endif
15880+
15881+ : "=m" (v->counter)
15882+ : "m" (v->counter));
15883+}
15884+
15885+/**
15886+ * atomic64_dec_unchecked - decrement atomic64 variable
15887+ * @v: pointer to type atomic64_t
15888+ *
15889+ * Atomically decrements @v by 1.
15890+ */
15891+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15892+{
15893+ asm volatile(LOCK_PREFIX "decq %0\n"
15894 : "=m" (v->counter)
15895 : "m" (v->counter));
15896 }
15897@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15898 */
15899 static inline int atomic64_dec_and_test(atomic64_t *v)
15900 {
15901- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15902+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15903 }
15904
15905 /**
15906@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15907 */
15908 static inline int atomic64_inc_and_test(atomic64_t *v)
15909 {
15910- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15911+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15912 }
15913
15914 /**
15915@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15916 */
15917 static inline int atomic64_add_negative(long i, atomic64_t *v)
15918 {
15919- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15920+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15921 }
15922
15923 /**
15924@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15925 */
15926 static inline long atomic64_add_return(long i, atomic64_t *v)
15927 {
15928+ return i + xadd_check_overflow(&v->counter, i);
15929+}
15930+
15931+/**
15932+ * atomic64_add_return_unchecked - add and return
15933+ * @i: integer value to add
15934+ * @v: pointer to type atomic64_unchecked_t
15935+ *
15936+ * Atomically adds @i to @v and returns @i + @v
15937+ */
15938+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15939+{
15940 return i + xadd(&v->counter, i);
15941 }
15942
15943@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15944 }
15945
15946 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15947+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15948+{
15949+ return atomic64_add_return_unchecked(1, v);
15950+}
15951 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15952
15953 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15954@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15955 return cmpxchg(&v->counter, old, new);
15956 }
15957
15958+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15959+{
15960+ return cmpxchg(&v->counter, old, new);
15961+}
15962+
15963 static inline long atomic64_xchg(atomic64_t *v, long new)
15964 {
15965 return xchg(&v->counter, new);
15966@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15967 */
15968 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15969 {
15970- long c, old;
15971+ long c, old, new;
15972 c = atomic64_read(v);
15973 for (;;) {
15974- if (unlikely(c == (u)))
15975+ if (unlikely(c == u))
15976 break;
15977- old = atomic64_cmpxchg((v), c, c + (a));
15978+
15979+ asm volatile("add %2,%0\n"
15980+
15981+#ifdef CONFIG_PAX_REFCOUNT
15982+ "jno 0f\n"
15983+ "sub %2,%0\n"
15984+ "int $4\n0:\n"
15985+ _ASM_EXTABLE(0b, 0b)
15986+#endif
15987+
15988+ : "=r" (new)
15989+ : "0" (c), "ir" (a));
15990+
15991+ old = atomic64_cmpxchg(v, c, new);
15992 if (likely(old == c))
15993 break;
15994 c = old;
15995 }
15996- return c != (u);
15997+ return c != u;
15998 }
15999
16000 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16001diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16002index 9fc1af7..fc71228 100644
16003--- a/arch/x86/include/asm/bitops.h
16004+++ b/arch/x86/include/asm/bitops.h
16005@@ -49,7 +49,7 @@
16006 * a mask operation on a byte.
16007 */
16008 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16009-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16010+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16011 #define CONST_MASK(nr) (1 << ((nr) & 7))
16012
16013 /**
16014@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16015 */
16016 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16017 {
16018- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16019+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16020 }
16021
16022 /**
16023@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16024 */
16025 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16026 {
16027- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16028+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16029 }
16030
16031 /**
16032@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16033 */
16034 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16035 {
16036- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16037+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16038 }
16039
16040 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16041@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16042 *
16043 * Undefined if no bit exists, so code should check against 0 first.
16044 */
16045-static inline unsigned long __ffs(unsigned long word)
16046+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16047 {
16048 asm("rep; bsf %1,%0"
16049 : "=r" (word)
16050@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
16051 *
16052 * Undefined if no zero exists, so code should check against ~0UL first.
16053 */
16054-static inline unsigned long ffz(unsigned long word)
16055+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16056 {
16057 asm("rep; bsf %1,%0"
16058 : "=r" (word)
16059@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
16060 *
16061 * Undefined if no set bit exists, so code should check against 0 first.
16062 */
16063-static inline unsigned long __fls(unsigned long word)
16064+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16065 {
16066 asm("bsr %1,%0"
16067 : "=r" (word)
16068@@ -436,7 +436,7 @@ static inline int ffs(int x)
16069 * set bit if value is nonzero. The last (most significant) bit is
16070 * at position 32.
16071 */
16072-static inline int fls(int x)
16073+static inline int __intentional_overflow(-1) fls(int x)
16074 {
16075 int r;
16076
16077@@ -478,7 +478,7 @@ static inline int fls(int x)
16078 * at position 64.
16079 */
16080 #ifdef CONFIG_X86_64
16081-static __always_inline int fls64(__u64 x)
16082+static __always_inline long fls64(__u64 x)
16083 {
16084 int bitpos = -1;
16085 /*
16086diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16087index 4fa687a..60f2d39 100644
16088--- a/arch/x86/include/asm/boot.h
16089+++ b/arch/x86/include/asm/boot.h
16090@@ -6,10 +6,15 @@
16091 #include <uapi/asm/boot.h>
16092
16093 /* Physical address where kernel should be loaded. */
16094-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16095+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16096 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16097 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16098
16099+#ifndef __ASSEMBLY__
16100+extern unsigned char __LOAD_PHYSICAL_ADDR[];
16101+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16102+#endif
16103+
16104 /* Minimum kernel alignment, as a power of two */
16105 #ifdef CONFIG_X86_64
16106 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16107diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16108index 48f99f1..d78ebf9 100644
16109--- a/arch/x86/include/asm/cache.h
16110+++ b/arch/x86/include/asm/cache.h
16111@@ -5,12 +5,13 @@
16112
16113 /* L1 cache line size */
16114 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16115-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16116+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16117
16118 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16119+#define __read_only __attribute__((__section__(".data..read_only")))
16120
16121 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16122-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16123+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16124
16125 #ifdef CONFIG_X86_VSMP
16126 #ifdef CONFIG_SMP
16127diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16128index 9863ee3..4a1f8e1 100644
16129--- a/arch/x86/include/asm/cacheflush.h
16130+++ b/arch/x86/include/asm/cacheflush.h
16131@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16132 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16133
16134 if (pg_flags == _PGMT_DEFAULT)
16135- return -1;
16136+ return ~0UL;
16137 else if (pg_flags == _PGMT_WC)
16138 return _PAGE_CACHE_WC;
16139 else if (pg_flags == _PGMT_UC_MINUS)
16140diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16141index cb4c73b..c473c29 100644
16142--- a/arch/x86/include/asm/calling.h
16143+++ b/arch/x86/include/asm/calling.h
16144@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16145 #define RSP 152
16146 #define SS 160
16147
16148-#define ARGOFFSET R11
16149-#define SWFRAME ORIG_RAX
16150+#define ARGOFFSET R15
16151
16152 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16153- subq $9*8+\addskip, %rsp
16154- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16155- movq_cfi rdi, 8*8
16156- movq_cfi rsi, 7*8
16157- movq_cfi rdx, 6*8
16158+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16159+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16160+ movq_cfi rdi, RDI
16161+ movq_cfi rsi, RSI
16162+ movq_cfi rdx, RDX
16163
16164 .if \save_rcx
16165- movq_cfi rcx, 5*8
16166+ movq_cfi rcx, RCX
16167 .endif
16168
16169- movq_cfi rax, 4*8
16170+ movq_cfi rax, RAX
16171
16172 .if \save_r891011
16173- movq_cfi r8, 3*8
16174- movq_cfi r9, 2*8
16175- movq_cfi r10, 1*8
16176- movq_cfi r11, 0*8
16177+ movq_cfi r8, R8
16178+ movq_cfi r9, R9
16179+ movq_cfi r10, R10
16180+ movq_cfi r11, R11
16181 .endif
16182
16183+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16184+ movq_cfi r12, R12
16185+#endif
16186+
16187 .endm
16188
16189-#define ARG_SKIP (9*8)
16190+#define ARG_SKIP ORIG_RAX
16191
16192 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16193 rstor_r8910=1, rstor_rdx=1
16194+
16195+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16196+ movq_cfi_restore R12, r12
16197+#endif
16198+
16199 .if \rstor_r11
16200- movq_cfi_restore 0*8, r11
16201+ movq_cfi_restore R11, r11
16202 .endif
16203
16204 .if \rstor_r8910
16205- movq_cfi_restore 1*8, r10
16206- movq_cfi_restore 2*8, r9
16207- movq_cfi_restore 3*8, r8
16208+ movq_cfi_restore R10, r10
16209+ movq_cfi_restore R9, r9
16210+ movq_cfi_restore R8, r8
16211 .endif
16212
16213 .if \rstor_rax
16214- movq_cfi_restore 4*8, rax
16215+ movq_cfi_restore RAX, rax
16216 .endif
16217
16218 .if \rstor_rcx
16219- movq_cfi_restore 5*8, rcx
16220+ movq_cfi_restore RCX, rcx
16221 .endif
16222
16223 .if \rstor_rdx
16224- movq_cfi_restore 6*8, rdx
16225+ movq_cfi_restore RDX, rdx
16226 .endif
16227
16228- movq_cfi_restore 7*8, rsi
16229- movq_cfi_restore 8*8, rdi
16230+ movq_cfi_restore RSI, rsi
16231+ movq_cfi_restore RDI, rdi
16232
16233- .if ARG_SKIP+\addskip > 0
16234- addq $ARG_SKIP+\addskip, %rsp
16235- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16236+ .if ORIG_RAX+\addskip > 0
16237+ addq $ORIG_RAX+\addskip, %rsp
16238+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16239 .endif
16240 .endm
16241
16242- .macro LOAD_ARGS offset, skiprax=0
16243- movq \offset(%rsp), %r11
16244- movq \offset+8(%rsp), %r10
16245- movq \offset+16(%rsp), %r9
16246- movq \offset+24(%rsp), %r8
16247- movq \offset+40(%rsp), %rcx
16248- movq \offset+48(%rsp), %rdx
16249- movq \offset+56(%rsp), %rsi
16250- movq \offset+64(%rsp), %rdi
16251+ .macro LOAD_ARGS skiprax=0
16252+ movq R11(%rsp), %r11
16253+ movq R10(%rsp), %r10
16254+ movq R9(%rsp), %r9
16255+ movq R8(%rsp), %r8
16256+ movq RCX(%rsp), %rcx
16257+ movq RDX(%rsp), %rdx
16258+ movq RSI(%rsp), %rsi
16259+ movq RDI(%rsp), %rdi
16260 .if \skiprax
16261 .else
16262- movq \offset+72(%rsp), %rax
16263+ movq RAX(%rsp), %rax
16264 .endif
16265 .endm
16266
16267-#define REST_SKIP (6*8)
16268-
16269 .macro SAVE_REST
16270- subq $REST_SKIP, %rsp
16271- CFI_ADJUST_CFA_OFFSET REST_SKIP
16272- movq_cfi rbx, 5*8
16273- movq_cfi rbp, 4*8
16274- movq_cfi r12, 3*8
16275- movq_cfi r13, 2*8
16276- movq_cfi r14, 1*8
16277- movq_cfi r15, 0*8
16278+ movq_cfi rbx, RBX
16279+ movq_cfi rbp, RBP
16280+
16281+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16282+ movq_cfi r12, R12
16283+#endif
16284+
16285+ movq_cfi r13, R13
16286+ movq_cfi r14, R14
16287+ movq_cfi r15, R15
16288 .endm
16289
16290 .macro RESTORE_REST
16291- movq_cfi_restore 0*8, r15
16292- movq_cfi_restore 1*8, r14
16293- movq_cfi_restore 2*8, r13
16294- movq_cfi_restore 3*8, r12
16295- movq_cfi_restore 4*8, rbp
16296- movq_cfi_restore 5*8, rbx
16297- addq $REST_SKIP, %rsp
16298- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16299+ movq_cfi_restore R15, r15
16300+ movq_cfi_restore R14, r14
16301+ movq_cfi_restore R13, r13
16302+
16303+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16304+ movq_cfi_restore R12, r12
16305+#endif
16306+
16307+ movq_cfi_restore RBP, rbp
16308+ movq_cfi_restore RBX, rbx
16309 .endm
16310
16311 .macro SAVE_ALL
16312diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16313index f50de69..2b0a458 100644
16314--- a/arch/x86/include/asm/checksum_32.h
16315+++ b/arch/x86/include/asm/checksum_32.h
16316@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16317 int len, __wsum sum,
16318 int *src_err_ptr, int *dst_err_ptr);
16319
16320+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16321+ int len, __wsum sum,
16322+ int *src_err_ptr, int *dst_err_ptr);
16323+
16324+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16325+ int len, __wsum sum,
16326+ int *src_err_ptr, int *dst_err_ptr);
16327+
16328 /*
16329 * Note: when you get a NULL pointer exception here this means someone
16330 * passed in an incorrect kernel address to one of these functions.
16331@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16332
16333 might_sleep();
16334 stac();
16335- ret = csum_partial_copy_generic((__force void *)src, dst,
16336+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16337 len, sum, err_ptr, NULL);
16338 clac();
16339
16340@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16341 might_sleep();
16342 if (access_ok(VERIFY_WRITE, dst, len)) {
16343 stac();
16344- ret = csum_partial_copy_generic(src, (__force void *)dst,
16345+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16346 len, sum, NULL, err_ptr);
16347 clac();
16348 return ret;
16349diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16350index d47786a..2d8883e 100644
16351--- a/arch/x86/include/asm/cmpxchg.h
16352+++ b/arch/x86/include/asm/cmpxchg.h
16353@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16354 __compiletime_error("Bad argument size for cmpxchg");
16355 extern void __xadd_wrong_size(void)
16356 __compiletime_error("Bad argument size for xadd");
16357+extern void __xadd_check_overflow_wrong_size(void)
16358+ __compiletime_error("Bad argument size for xadd_check_overflow");
16359 extern void __add_wrong_size(void)
16360 __compiletime_error("Bad argument size for add");
16361+extern void __add_check_overflow_wrong_size(void)
16362+ __compiletime_error("Bad argument size for add_check_overflow");
16363
16364 /*
16365 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16366@@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16367 __ret; \
16368 })
16369
16370+#ifdef CONFIG_PAX_REFCOUNT
16371+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16372+ ({ \
16373+ __typeof__ (*(ptr)) __ret = (arg); \
16374+ switch (sizeof(*(ptr))) { \
16375+ case __X86_CASE_L: \
16376+ asm volatile (lock #op "l %0, %1\n" \
16377+ "jno 0f\n" \
16378+ "mov %0,%1\n" \
16379+ "int $4\n0:\n" \
16380+ _ASM_EXTABLE(0b, 0b) \
16381+ : "+r" (__ret), "+m" (*(ptr)) \
16382+ : : "memory", "cc"); \
16383+ break; \
16384+ case __X86_CASE_Q: \
16385+ asm volatile (lock #op "q %q0, %1\n" \
16386+ "jno 0f\n" \
16387+ "mov %0,%1\n" \
16388+ "int $4\n0:\n" \
16389+ _ASM_EXTABLE(0b, 0b) \
16390+ : "+r" (__ret), "+m" (*(ptr)) \
16391+ : : "memory", "cc"); \
16392+ break; \
16393+ default: \
16394+ __ ## op ## _check_overflow_wrong_size(); \
16395+ } \
16396+ __ret; \
16397+ })
16398+#else
16399+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16400+#endif
16401+
16402 /*
16403 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16404 * Since this is generally used to protect other memory information, we
16405@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16406 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16407 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16408
16409+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16410+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16411+
16412 #define __add(ptr, inc, lock) \
16413 ({ \
16414 __typeof__ (*(ptr)) __ret = (inc); \
16415diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16416index 59c6c40..5e0b22c 100644
16417--- a/arch/x86/include/asm/compat.h
16418+++ b/arch/x86/include/asm/compat.h
16419@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16420 typedef u32 compat_uint_t;
16421 typedef u32 compat_ulong_t;
16422 typedef u64 __attribute__((aligned(4))) compat_u64;
16423-typedef u32 compat_uptr_t;
16424+typedef u32 __user compat_uptr_t;
16425
16426 struct compat_timespec {
16427 compat_time_t tv_sec;
16428diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16429index 5f12968..a383517 100644
16430--- a/arch/x86/include/asm/cpufeature.h
16431+++ b/arch/x86/include/asm/cpufeature.h
16432@@ -203,7 +203,7 @@
16433 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16434 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16435 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16436-
16437+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16438
16439 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16440 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16441@@ -211,7 +211,7 @@
16442 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16443 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16444 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16445-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16446+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16447 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16448 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16449 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16450@@ -358,6 +358,7 @@ extern const char * const x86_power_flags[32];
16451 #undef cpu_has_centaur_mcr
16452 #define cpu_has_centaur_mcr 0
16453
16454+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16455 #endif /* CONFIG_X86_64 */
16456
16457 #if __GNUC__ >= 4
16458@@ -410,7 +411,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16459
16460 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16461 t_warn:
16462- warn_pre_alternatives();
16463+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16464+ warn_pre_alternatives();
16465 return false;
16466 #endif
16467
16468@@ -430,7 +432,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16469 ".section .discard,\"aw\",@progbits\n"
16470 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16471 ".previous\n"
16472- ".section .altinstr_replacement,\"ax\"\n"
16473+ ".section .altinstr_replacement,\"a\"\n"
16474 "3: movb $1,%0\n"
16475 "4:\n"
16476 ".previous\n"
16477@@ -467,7 +469,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16478 " .byte 2b - 1b\n" /* src len */
16479 " .byte 4f - 3f\n" /* repl len */
16480 ".previous\n"
16481- ".section .altinstr_replacement,\"ax\"\n"
16482+ ".section .altinstr_replacement,\"a\"\n"
16483 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16484 "4:\n"
16485 ".previous\n"
16486@@ -500,7 +502,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16487 ".section .discard,\"aw\",@progbits\n"
16488 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16489 ".previous\n"
16490- ".section .altinstr_replacement,\"ax\"\n"
16491+ ".section .altinstr_replacement,\"a\"\n"
16492 "3: movb $0,%0\n"
16493 "4:\n"
16494 ".previous\n"
16495@@ -514,7 +516,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16496 ".section .discard,\"aw\",@progbits\n"
16497 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16498 ".previous\n"
16499- ".section .altinstr_replacement,\"ax\"\n"
16500+ ".section .altinstr_replacement,\"a\"\n"
16501 "5: movb $1,%0\n"
16502 "6:\n"
16503 ".previous\n"
16504diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16505index 50d033a..37deb26 100644
16506--- a/arch/x86/include/asm/desc.h
16507+++ b/arch/x86/include/asm/desc.h
16508@@ -4,6 +4,7 @@
16509 #include <asm/desc_defs.h>
16510 #include <asm/ldt.h>
16511 #include <asm/mmu.h>
16512+#include <asm/pgtable.h>
16513
16514 #include <linux/smp.h>
16515 #include <linux/percpu.h>
16516@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16517
16518 desc->type = (info->read_exec_only ^ 1) << 1;
16519 desc->type |= info->contents << 2;
16520+ desc->type |= info->seg_not_present ^ 1;
16521
16522 desc->s = 1;
16523 desc->dpl = 0x3;
16524@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16525 }
16526
16527 extern struct desc_ptr idt_descr;
16528-extern gate_desc idt_table[];
16529-extern struct desc_ptr debug_idt_descr;
16530-extern gate_desc debug_idt_table[];
16531-
16532-struct gdt_page {
16533- struct desc_struct gdt[GDT_ENTRIES];
16534-} __attribute__((aligned(PAGE_SIZE)));
16535-
16536-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16537+extern gate_desc idt_table[IDT_ENTRIES];
16538+extern const struct desc_ptr debug_idt_descr;
16539+extern gate_desc debug_idt_table[IDT_ENTRIES];
16540
16541+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16542 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16543 {
16544- return per_cpu(gdt_page, cpu).gdt;
16545+ return cpu_gdt_table[cpu];
16546 }
16547
16548 #ifdef CONFIG_X86_64
16549@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16550 unsigned long base, unsigned dpl, unsigned flags,
16551 unsigned short seg)
16552 {
16553- gate->a = (seg << 16) | (base & 0xffff);
16554- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16555+ gate->gate.offset_low = base;
16556+ gate->gate.seg = seg;
16557+ gate->gate.reserved = 0;
16558+ gate->gate.type = type;
16559+ gate->gate.s = 0;
16560+ gate->gate.dpl = dpl;
16561+ gate->gate.p = 1;
16562+ gate->gate.offset_high = base >> 16;
16563 }
16564
16565 #endif
16566@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16567
16568 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16569 {
16570+ pax_open_kernel();
16571 memcpy(&idt[entry], gate, sizeof(*gate));
16572+ pax_close_kernel();
16573 }
16574
16575 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16576 {
16577+ pax_open_kernel();
16578 memcpy(&ldt[entry], desc, 8);
16579+ pax_close_kernel();
16580 }
16581
16582 static inline void
16583@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16584 default: size = sizeof(*gdt); break;
16585 }
16586
16587+ pax_open_kernel();
16588 memcpy(&gdt[entry], desc, size);
16589+ pax_close_kernel();
16590 }
16591
16592 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16593@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16594
16595 static inline void native_load_tr_desc(void)
16596 {
16597+ pax_open_kernel();
16598 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16599+ pax_close_kernel();
16600 }
16601
16602 static inline void native_load_gdt(const struct desc_ptr *dtr)
16603@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16604 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16605 unsigned int i;
16606
16607+ pax_open_kernel();
16608 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16609 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16610+ pax_close_kernel();
16611 }
16612
16613 #define _LDT_empty(info) \
16614@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16615 preempt_enable();
16616 }
16617
16618-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16619+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16620 {
16621 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16622 }
16623@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16624 }
16625
16626 #ifdef CONFIG_X86_64
16627-static inline void set_nmi_gate(int gate, void *addr)
16628+static inline void set_nmi_gate(int gate, const void *addr)
16629 {
16630 gate_desc s;
16631
16632@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16633 #endif
16634
16635 #ifdef CONFIG_TRACING
16636-extern struct desc_ptr trace_idt_descr;
16637-extern gate_desc trace_idt_table[];
16638+extern const struct desc_ptr trace_idt_descr;
16639+extern gate_desc trace_idt_table[IDT_ENTRIES];
16640 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16641 {
16642 write_idt_entry(trace_idt_table, entry, gate);
16643 }
16644
16645-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16646+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16647 unsigned dpl, unsigned ist, unsigned seg)
16648 {
16649 gate_desc s;
16650@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16651 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16652 #endif
16653
16654-static inline void _set_gate(int gate, unsigned type, void *addr,
16655+static inline void _set_gate(int gate, unsigned type, const void *addr,
16656 unsigned dpl, unsigned ist, unsigned seg)
16657 {
16658 gate_desc s;
16659@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16660 #define set_intr_gate(n, addr) \
16661 do { \
16662 BUG_ON((unsigned)n > 0xFF); \
16663- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16664+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16665 __KERNEL_CS); \
16666- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16667+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16668 0, 0, __KERNEL_CS); \
16669 } while (0)
16670
16671@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16672 /*
16673 * This routine sets up an interrupt gate at directory privilege level 3.
16674 */
16675-static inline void set_system_intr_gate(unsigned int n, void *addr)
16676+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16677 {
16678 BUG_ON((unsigned)n > 0xFF);
16679 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16680 }
16681
16682-static inline void set_system_trap_gate(unsigned int n, void *addr)
16683+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16684 {
16685 BUG_ON((unsigned)n > 0xFF);
16686 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16687 }
16688
16689-static inline void set_trap_gate(unsigned int n, void *addr)
16690+static inline void set_trap_gate(unsigned int n, const void *addr)
16691 {
16692 BUG_ON((unsigned)n > 0xFF);
16693 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16694@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16695 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16696 {
16697 BUG_ON((unsigned)n > 0xFF);
16698- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16699+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16700 }
16701
16702-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16703+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16704 {
16705 BUG_ON((unsigned)n > 0xFF);
16706 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16707 }
16708
16709-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16710+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16711 {
16712 BUG_ON((unsigned)n > 0xFF);
16713 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16714@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16715 else
16716 load_idt((const struct desc_ptr *)&idt_descr);
16717 }
16718+
16719+#ifdef CONFIG_X86_32
16720+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16721+{
16722+ struct desc_struct d;
16723+
16724+ if (likely(limit))
16725+ limit = (limit - 1UL) >> PAGE_SHIFT;
16726+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16727+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16728+}
16729+#endif
16730+
16731 #endif /* _ASM_X86_DESC_H */
16732diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16733index 278441f..b95a174 100644
16734--- a/arch/x86/include/asm/desc_defs.h
16735+++ b/arch/x86/include/asm/desc_defs.h
16736@@ -31,6 +31,12 @@ struct desc_struct {
16737 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16738 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16739 };
16740+ struct {
16741+ u16 offset_low;
16742+ u16 seg;
16743+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16744+ unsigned offset_high: 16;
16745+ } gate;
16746 };
16747 } __attribute__((packed));
16748
16749diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16750index ced283a..ffe04cc 100644
16751--- a/arch/x86/include/asm/div64.h
16752+++ b/arch/x86/include/asm/div64.h
16753@@ -39,7 +39,7 @@
16754 __mod; \
16755 })
16756
16757-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16758+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16759 {
16760 union {
16761 u64 v64;
16762diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16763index 9c999c1..3860cb8 100644
16764--- a/arch/x86/include/asm/elf.h
16765+++ b/arch/x86/include/asm/elf.h
16766@@ -243,7 +243,25 @@ extern int force_personality32;
16767 the loader. We need to make sure that it is out of the way of the program
16768 that it will "exec", and that there is sufficient room for the brk. */
16769
16770+#ifdef CONFIG_PAX_SEGMEXEC
16771+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16772+#else
16773 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16774+#endif
16775+
16776+#ifdef CONFIG_PAX_ASLR
16777+#ifdef CONFIG_X86_32
16778+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16779+
16780+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16781+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16782+#else
16783+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16784+
16785+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16786+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16787+#endif
16788+#endif
16789
16790 /* This yields a mask that user programs can use to figure out what
16791 instruction set this CPU supports. This could be done in user space,
16792@@ -296,16 +314,12 @@ do { \
16793
16794 #define ARCH_DLINFO \
16795 do { \
16796- if (vdso_enabled) \
16797- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16798- (unsigned long)current->mm->context.vdso); \
16799+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16800 } while (0)
16801
16802 #define ARCH_DLINFO_X32 \
16803 do { \
16804- if (vdso_enabled) \
16805- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16806- (unsigned long)current->mm->context.vdso); \
16807+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16808 } while (0)
16809
16810 #define AT_SYSINFO 32
16811@@ -320,7 +334,7 @@ else \
16812
16813 #endif /* !CONFIG_X86_32 */
16814
16815-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16816+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16817
16818 #define VDSO_ENTRY \
16819 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16820@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16821 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16822 #define compat_arch_setup_additional_pages syscall32_setup_pages
16823
16824-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16825-#define arch_randomize_brk arch_randomize_brk
16826-
16827 /*
16828 * True on X86_32 or when emulating IA32 on X86_64
16829 */
16830diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16831index 77a99ac..39ff7f5 100644
16832--- a/arch/x86/include/asm/emergency-restart.h
16833+++ b/arch/x86/include/asm/emergency-restart.h
16834@@ -1,6 +1,6 @@
16835 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16836 #define _ASM_X86_EMERGENCY_RESTART_H
16837
16838-extern void machine_emergency_restart(void);
16839+extern void machine_emergency_restart(void) __noreturn;
16840
16841 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16842diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16843index d3d7469..677ef72 100644
16844--- a/arch/x86/include/asm/floppy.h
16845+++ b/arch/x86/include/asm/floppy.h
16846@@ -229,18 +229,18 @@ static struct fd_routine_l {
16847 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16848 } fd_routine[] = {
16849 {
16850- request_dma,
16851- free_dma,
16852- get_dma_residue,
16853- dma_mem_alloc,
16854- hard_dma_setup
16855+ ._request_dma = request_dma,
16856+ ._free_dma = free_dma,
16857+ ._get_dma_residue = get_dma_residue,
16858+ ._dma_mem_alloc = dma_mem_alloc,
16859+ ._dma_setup = hard_dma_setup
16860 },
16861 {
16862- vdma_request_dma,
16863- vdma_nop,
16864- vdma_get_dma_residue,
16865- vdma_mem_alloc,
16866- vdma_dma_setup
16867+ ._request_dma = vdma_request_dma,
16868+ ._free_dma = vdma_nop,
16869+ ._get_dma_residue = vdma_get_dma_residue,
16870+ ._dma_mem_alloc = vdma_mem_alloc,
16871+ ._dma_setup = vdma_dma_setup
16872 }
16873 };
16874
16875diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16876index cea1c76..6c0d79b 100644
16877--- a/arch/x86/include/asm/fpu-internal.h
16878+++ b/arch/x86/include/asm/fpu-internal.h
16879@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16880 #define user_insn(insn, output, input...) \
16881 ({ \
16882 int err; \
16883+ pax_open_userland(); \
16884 asm volatile(ASM_STAC "\n" \
16885- "1:" #insn "\n\t" \
16886+ "1:" \
16887+ __copyuser_seg \
16888+ #insn "\n\t" \
16889 "2: " ASM_CLAC "\n" \
16890 ".section .fixup,\"ax\"\n" \
16891 "3: movl $-1,%[err]\n" \
16892@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16893 _ASM_EXTABLE(1b, 3b) \
16894 : [err] "=r" (err), output \
16895 : "0"(0), input); \
16896+ pax_close_userland(); \
16897 err; \
16898 })
16899
16900@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16901 "fnclex\n\t"
16902 "emms\n\t"
16903 "fildl %P[addr]" /* set F?P to defined value */
16904- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16905+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16906 }
16907
16908 return fpu_restore_checking(&tsk->thread.fpu);
16909diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16910index b4c1f54..e290c08 100644
16911--- a/arch/x86/include/asm/futex.h
16912+++ b/arch/x86/include/asm/futex.h
16913@@ -12,6 +12,7 @@
16914 #include <asm/smap.h>
16915
16916 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16917+ typecheck(u32 __user *, uaddr); \
16918 asm volatile("\t" ASM_STAC "\n" \
16919 "1:\t" insn "\n" \
16920 "2:\t" ASM_CLAC "\n" \
16921@@ -20,15 +21,16 @@
16922 "\tjmp\t2b\n" \
16923 "\t.previous\n" \
16924 _ASM_EXTABLE(1b, 3b) \
16925- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16926+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16927 : "i" (-EFAULT), "0" (oparg), "1" (0))
16928
16929 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16930+ typecheck(u32 __user *, uaddr); \
16931 asm volatile("\t" ASM_STAC "\n" \
16932 "1:\tmovl %2, %0\n" \
16933 "\tmovl\t%0, %3\n" \
16934 "\t" insn "\n" \
16935- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16936+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16937 "\tjnz\t1b\n" \
16938 "3:\t" ASM_CLAC "\n" \
16939 "\t.section .fixup,\"ax\"\n" \
16940@@ -38,7 +40,7 @@
16941 _ASM_EXTABLE(1b, 4b) \
16942 _ASM_EXTABLE(2b, 4b) \
16943 : "=&a" (oldval), "=&r" (ret), \
16944- "+m" (*uaddr), "=&r" (tem) \
16945+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16946 : "r" (oparg), "i" (-EFAULT), "1" (0))
16947
16948 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16949@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16950
16951 pagefault_disable();
16952
16953+ pax_open_userland();
16954 switch (op) {
16955 case FUTEX_OP_SET:
16956- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16957+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16958 break;
16959 case FUTEX_OP_ADD:
16960- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16961+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16962 uaddr, oparg);
16963 break;
16964 case FUTEX_OP_OR:
16965@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16966 default:
16967 ret = -ENOSYS;
16968 }
16969+ pax_close_userland();
16970
16971 pagefault_enable();
16972
16973diff --git a/arch/x86/include/asm/hugetlb.h b/arch/x86/include/asm/hugetlb.h
16974index a809121..68c0539 100644
16975--- a/arch/x86/include/asm/hugetlb.h
16976+++ b/arch/x86/include/asm/hugetlb.h
16977@@ -52,6 +52,7 @@ static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
16978 static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
16979 unsigned long addr, pte_t *ptep)
16980 {
16981+ ptep_clear_flush(vma, addr, ptep);
16982 }
16983
16984 static inline int huge_pte_none(pte_t pte)
16985diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16986index 67d69b8..50e4b77 100644
16987--- a/arch/x86/include/asm/hw_irq.h
16988+++ b/arch/x86/include/asm/hw_irq.h
16989@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16990 extern void enable_IO_APIC(void);
16991
16992 /* Statistics */
16993-extern atomic_t irq_err_count;
16994-extern atomic_t irq_mis_count;
16995+extern atomic_unchecked_t irq_err_count;
16996+extern atomic_unchecked_t irq_mis_count;
16997
16998 /* EISA */
16999 extern void eisa_set_level_irq(unsigned int irq);
17000diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17001index a203659..9889f1c 100644
17002--- a/arch/x86/include/asm/i8259.h
17003+++ b/arch/x86/include/asm/i8259.h
17004@@ -62,7 +62,7 @@ struct legacy_pic {
17005 void (*init)(int auto_eoi);
17006 int (*irq_pending)(unsigned int irq);
17007 void (*make_irq)(unsigned int irq);
17008-};
17009+} __do_const;
17010
17011 extern struct legacy_pic *legacy_pic;
17012 extern struct legacy_pic null_legacy_pic;
17013diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17014index 91d9c69..dfae7d0 100644
17015--- a/arch/x86/include/asm/io.h
17016+++ b/arch/x86/include/asm/io.h
17017@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17018 "m" (*(volatile type __force *)addr) barrier); }
17019
17020 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17021-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17022-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17023+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17024+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17025
17026 build_mmio_read(__readb, "b", unsigned char, "=q", )
17027-build_mmio_read(__readw, "w", unsigned short, "=r", )
17028-build_mmio_read(__readl, "l", unsigned int, "=r", )
17029+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17030+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17031
17032 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17033 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17034@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17035 return ioremap_nocache(offset, size);
17036 }
17037
17038-extern void iounmap(volatile void __iomem *addr);
17039+extern void iounmap(const volatile void __iomem *addr);
17040
17041 extern void set_iounmap_nonlazy(void);
17042
17043@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
17044
17045 #include <linux/vmalloc.h>
17046
17047+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17048+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17049+{
17050+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17051+}
17052+
17053+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17054+{
17055+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17056+}
17057+
17058 /*
17059 * Convert a virtual cached pointer to an uncached pointer
17060 */
17061diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17062index bba3cf8..06bc8da 100644
17063--- a/arch/x86/include/asm/irqflags.h
17064+++ b/arch/x86/include/asm/irqflags.h
17065@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17066 sti; \
17067 sysexit
17068
17069+#define GET_CR0_INTO_RDI mov %cr0, %rdi
17070+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17071+#define GET_CR3_INTO_RDI mov %cr3, %rdi
17072+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17073+
17074 #else
17075 #define INTERRUPT_RETURN iret
17076 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17077diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17078index 9454c16..e4100e3 100644
17079--- a/arch/x86/include/asm/kprobes.h
17080+++ b/arch/x86/include/asm/kprobes.h
17081@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17082 #define RELATIVEJUMP_SIZE 5
17083 #define RELATIVECALL_OPCODE 0xe8
17084 #define RELATIVE_ADDR_SIZE 4
17085-#define MAX_STACK_SIZE 64
17086-#define MIN_STACK_SIZE(ADDR) \
17087- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17088- THREAD_SIZE - (unsigned long)(ADDR))) \
17089- ? (MAX_STACK_SIZE) \
17090- : (((unsigned long)current_thread_info()) + \
17091- THREAD_SIZE - (unsigned long)(ADDR)))
17092+#define MAX_STACK_SIZE 64UL
17093+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17094
17095 #define flush_insn_slot(p) do { } while (0)
17096
17097diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17098index 4ad6560..75c7bdd 100644
17099--- a/arch/x86/include/asm/local.h
17100+++ b/arch/x86/include/asm/local.h
17101@@ -10,33 +10,97 @@ typedef struct {
17102 atomic_long_t a;
17103 } local_t;
17104
17105+typedef struct {
17106+ atomic_long_unchecked_t a;
17107+} local_unchecked_t;
17108+
17109 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17110
17111 #define local_read(l) atomic_long_read(&(l)->a)
17112+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17113 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17114+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17115
17116 static inline void local_inc(local_t *l)
17117 {
17118- asm volatile(_ASM_INC "%0"
17119+ asm volatile(_ASM_INC "%0\n"
17120+
17121+#ifdef CONFIG_PAX_REFCOUNT
17122+ "jno 0f\n"
17123+ _ASM_DEC "%0\n"
17124+ "int $4\n0:\n"
17125+ _ASM_EXTABLE(0b, 0b)
17126+#endif
17127+
17128+ : "+m" (l->a.counter));
17129+}
17130+
17131+static inline void local_inc_unchecked(local_unchecked_t *l)
17132+{
17133+ asm volatile(_ASM_INC "%0\n"
17134 : "+m" (l->a.counter));
17135 }
17136
17137 static inline void local_dec(local_t *l)
17138 {
17139- asm volatile(_ASM_DEC "%0"
17140+ asm volatile(_ASM_DEC "%0\n"
17141+
17142+#ifdef CONFIG_PAX_REFCOUNT
17143+ "jno 0f\n"
17144+ _ASM_INC "%0\n"
17145+ "int $4\n0:\n"
17146+ _ASM_EXTABLE(0b, 0b)
17147+#endif
17148+
17149+ : "+m" (l->a.counter));
17150+}
17151+
17152+static inline void local_dec_unchecked(local_unchecked_t *l)
17153+{
17154+ asm volatile(_ASM_DEC "%0\n"
17155 : "+m" (l->a.counter));
17156 }
17157
17158 static inline void local_add(long i, local_t *l)
17159 {
17160- asm volatile(_ASM_ADD "%1,%0"
17161+ asm volatile(_ASM_ADD "%1,%0\n"
17162+
17163+#ifdef CONFIG_PAX_REFCOUNT
17164+ "jno 0f\n"
17165+ _ASM_SUB "%1,%0\n"
17166+ "int $4\n0:\n"
17167+ _ASM_EXTABLE(0b, 0b)
17168+#endif
17169+
17170+ : "+m" (l->a.counter)
17171+ : "ir" (i));
17172+}
17173+
17174+static inline void local_add_unchecked(long i, local_unchecked_t *l)
17175+{
17176+ asm volatile(_ASM_ADD "%1,%0\n"
17177 : "+m" (l->a.counter)
17178 : "ir" (i));
17179 }
17180
17181 static inline void local_sub(long i, local_t *l)
17182 {
17183- asm volatile(_ASM_SUB "%1,%0"
17184+ asm volatile(_ASM_SUB "%1,%0\n"
17185+
17186+#ifdef CONFIG_PAX_REFCOUNT
17187+ "jno 0f\n"
17188+ _ASM_ADD "%1,%0\n"
17189+ "int $4\n0:\n"
17190+ _ASM_EXTABLE(0b, 0b)
17191+#endif
17192+
17193+ : "+m" (l->a.counter)
17194+ : "ir" (i));
17195+}
17196+
17197+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17198+{
17199+ asm volatile(_ASM_SUB "%1,%0\n"
17200 : "+m" (l->a.counter)
17201 : "ir" (i));
17202 }
17203@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17204 */
17205 static inline int local_sub_and_test(long i, local_t *l)
17206 {
17207- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17208+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17209 }
17210
17211 /**
17212@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17213 */
17214 static inline int local_dec_and_test(local_t *l)
17215 {
17216- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17217+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17218 }
17219
17220 /**
17221@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17222 */
17223 static inline int local_inc_and_test(local_t *l)
17224 {
17225- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17226+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17227 }
17228
17229 /**
17230@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17231 */
17232 static inline int local_add_negative(long i, local_t *l)
17233 {
17234- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17235+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17236 }
17237
17238 /**
17239@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17240 static inline long local_add_return(long i, local_t *l)
17241 {
17242 long __i = i;
17243+ asm volatile(_ASM_XADD "%0, %1\n"
17244+
17245+#ifdef CONFIG_PAX_REFCOUNT
17246+ "jno 0f\n"
17247+ _ASM_MOV "%0,%1\n"
17248+ "int $4\n0:\n"
17249+ _ASM_EXTABLE(0b, 0b)
17250+#endif
17251+
17252+ : "+r" (i), "+m" (l->a.counter)
17253+ : : "memory");
17254+ return i + __i;
17255+}
17256+
17257+/**
17258+ * local_add_return_unchecked - add and return
17259+ * @i: integer value to add
17260+ * @l: pointer to type local_unchecked_t
17261+ *
17262+ * Atomically adds @i to @l and returns @i + @l
17263+ */
17264+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17265+{
17266+ long __i = i;
17267 asm volatile(_ASM_XADD "%0, %1;"
17268 : "+r" (i), "+m" (l->a.counter)
17269 : : "memory");
17270@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17271
17272 #define local_cmpxchg(l, o, n) \
17273 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17274+#define local_cmpxchg_unchecked(l, o, n) \
17275+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17276 /* Always has a lock prefix */
17277 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17278
17279diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17280new file mode 100644
17281index 0000000..2bfd3ba
17282--- /dev/null
17283+++ b/arch/x86/include/asm/mman.h
17284@@ -0,0 +1,15 @@
17285+#ifndef _X86_MMAN_H
17286+#define _X86_MMAN_H
17287+
17288+#include <uapi/asm/mman.h>
17289+
17290+#ifdef __KERNEL__
17291+#ifndef __ASSEMBLY__
17292+#ifdef CONFIG_X86_32
17293+#define arch_mmap_check i386_mmap_check
17294+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17295+#endif
17296+#endif
17297+#endif
17298+
17299+#endif /* X86_MMAN_H */
17300diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17301index 5f55e69..e20bfb1 100644
17302--- a/arch/x86/include/asm/mmu.h
17303+++ b/arch/x86/include/asm/mmu.h
17304@@ -9,7 +9,7 @@
17305 * we put the segment information here.
17306 */
17307 typedef struct {
17308- void *ldt;
17309+ struct desc_struct *ldt;
17310 int size;
17311
17312 #ifdef CONFIG_X86_64
17313@@ -18,7 +18,19 @@ typedef struct {
17314 #endif
17315
17316 struct mutex lock;
17317- void *vdso;
17318+ unsigned long vdso;
17319+
17320+#ifdef CONFIG_X86_32
17321+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17322+ unsigned long user_cs_base;
17323+ unsigned long user_cs_limit;
17324+
17325+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17326+ cpumask_t cpu_user_cs_mask;
17327+#endif
17328+
17329+#endif
17330+#endif
17331 } mm_context_t;
17332
17333 #ifdef CONFIG_SMP
17334diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17335index be12c53..4d24039 100644
17336--- a/arch/x86/include/asm/mmu_context.h
17337+++ b/arch/x86/include/asm/mmu_context.h
17338@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17339
17340 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17341 {
17342+
17343+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17344+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17345+ unsigned int i;
17346+ pgd_t *pgd;
17347+
17348+ pax_open_kernel();
17349+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17350+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17351+ set_pgd_batched(pgd+i, native_make_pgd(0));
17352+ pax_close_kernel();
17353+ }
17354+#endif
17355+
17356 #ifdef CONFIG_SMP
17357 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17358 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17359@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17360 struct task_struct *tsk)
17361 {
17362 unsigned cpu = smp_processor_id();
17363+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17364+ int tlbstate = TLBSTATE_OK;
17365+#endif
17366
17367 if (likely(prev != next)) {
17368 #ifdef CONFIG_SMP
17369+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17370+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17371+#endif
17372 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17373 this_cpu_write(cpu_tlbstate.active_mm, next);
17374 #endif
17375 cpumask_set_cpu(cpu, mm_cpumask(next));
17376
17377 /* Re-load page tables */
17378+#ifdef CONFIG_PAX_PER_CPU_PGD
17379+ pax_open_kernel();
17380+
17381+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17382+ if (static_cpu_has(X86_FEATURE_PCID))
17383+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17384+ else
17385+#endif
17386+
17387+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17388+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17389+ pax_close_kernel();
17390+ 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));
17391+
17392+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17393+ if (static_cpu_has(X86_FEATURE_PCID)) {
17394+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17395+ u64 descriptor[2];
17396+ descriptor[0] = PCID_USER;
17397+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17398+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17399+ descriptor[0] = PCID_KERNEL;
17400+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17401+ }
17402+ } else {
17403+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17404+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17405+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17406+ else
17407+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17408+ }
17409+ } else
17410+#endif
17411+
17412+ load_cr3(get_cpu_pgd(cpu, kernel));
17413+#else
17414 load_cr3(next->pgd);
17415+#endif
17416
17417 /* Stop flush ipis for the previous mm */
17418 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17419@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17420 /* Load the LDT, if the LDT is different: */
17421 if (unlikely(prev->context.ldt != next->context.ldt))
17422 load_LDT_nolock(&next->context);
17423+
17424+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17425+ if (!(__supported_pte_mask & _PAGE_NX)) {
17426+ smp_mb__before_clear_bit();
17427+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17428+ smp_mb__after_clear_bit();
17429+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17430+ }
17431+#endif
17432+
17433+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17434+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17435+ prev->context.user_cs_limit != next->context.user_cs_limit))
17436+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17437+#ifdef CONFIG_SMP
17438+ else if (unlikely(tlbstate != TLBSTATE_OK))
17439+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17440+#endif
17441+#endif
17442+
17443 }
17444+ else {
17445+
17446+#ifdef CONFIG_PAX_PER_CPU_PGD
17447+ pax_open_kernel();
17448+
17449+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17450+ if (static_cpu_has(X86_FEATURE_PCID))
17451+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17452+ else
17453+#endif
17454+
17455+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17456+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17457+ pax_close_kernel();
17458+ 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));
17459+
17460+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17461+ if (static_cpu_has(X86_FEATURE_PCID)) {
17462+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17463+ u64 descriptor[2];
17464+ descriptor[0] = PCID_USER;
17465+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17466+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17467+ descriptor[0] = PCID_KERNEL;
17468+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17469+ }
17470+ } else {
17471+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17472+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17473+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17474+ else
17475+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17476+ }
17477+ } else
17478+#endif
17479+
17480+ load_cr3(get_cpu_pgd(cpu, kernel));
17481+#endif
17482+
17483 #ifdef CONFIG_SMP
17484- else {
17485 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17486 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17487
17488@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17489 * tlb flush IPI delivery. We must reload CR3
17490 * to make sure to use no freed page tables.
17491 */
17492+
17493+#ifndef CONFIG_PAX_PER_CPU_PGD
17494 load_cr3(next->pgd);
17495+#endif
17496+
17497 load_LDT_nolock(&next->context);
17498+
17499+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17500+ if (!(__supported_pte_mask & _PAGE_NX))
17501+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17502+#endif
17503+
17504+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17505+#ifdef CONFIG_PAX_PAGEEXEC
17506+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17507+#endif
17508+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17509+#endif
17510+
17511 }
17512+#endif
17513 }
17514-#endif
17515 }
17516
17517 #define activate_mm(prev, next) \
17518diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17519index e3b7819..b257c64 100644
17520--- a/arch/x86/include/asm/module.h
17521+++ b/arch/x86/include/asm/module.h
17522@@ -5,6 +5,7 @@
17523
17524 #ifdef CONFIG_X86_64
17525 /* X86_64 does not define MODULE_PROC_FAMILY */
17526+#define MODULE_PROC_FAMILY ""
17527 #elif defined CONFIG_M486
17528 #define MODULE_PROC_FAMILY "486 "
17529 #elif defined CONFIG_M586
17530@@ -57,8 +58,20 @@
17531 #error unknown processor family
17532 #endif
17533
17534-#ifdef CONFIG_X86_32
17535-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17536+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17537+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17538+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17539+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17540+#else
17541+#define MODULE_PAX_KERNEXEC ""
17542 #endif
17543
17544+#ifdef CONFIG_PAX_MEMORY_UDEREF
17545+#define MODULE_PAX_UDEREF "UDEREF "
17546+#else
17547+#define MODULE_PAX_UDEREF ""
17548+#endif
17549+
17550+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17551+
17552 #endif /* _ASM_X86_MODULE_H */
17553diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17554index 86f9301..b365cda 100644
17555--- a/arch/x86/include/asm/nmi.h
17556+++ b/arch/x86/include/asm/nmi.h
17557@@ -40,11 +40,11 @@ struct nmiaction {
17558 nmi_handler_t handler;
17559 unsigned long flags;
17560 const char *name;
17561-};
17562+} __do_const;
17563
17564 #define register_nmi_handler(t, fn, fg, n, init...) \
17565 ({ \
17566- static struct nmiaction init fn##_na = { \
17567+ static const struct nmiaction init fn##_na = { \
17568 .handler = (fn), \
17569 .name = (n), \
17570 .flags = (fg), \
17571@@ -52,7 +52,7 @@ struct nmiaction {
17572 __register_nmi_handler((t), &fn##_na); \
17573 })
17574
17575-int __register_nmi_handler(unsigned int, struct nmiaction *);
17576+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17577
17578 void unregister_nmi_handler(unsigned int, const char *);
17579
17580diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17581index 775873d..de5f0304 100644
17582--- a/arch/x86/include/asm/page.h
17583+++ b/arch/x86/include/asm/page.h
17584@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17585 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17586
17587 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17588+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17589
17590 #define __boot_va(x) __va(x)
17591 #define __boot_pa(x) __pa(x)
17592diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17593index 0f1ddee..e2fc3d1 100644
17594--- a/arch/x86/include/asm/page_64.h
17595+++ b/arch/x86/include/asm/page_64.h
17596@@ -7,9 +7,9 @@
17597
17598 /* duplicated to the one in bootmem.h */
17599 extern unsigned long max_pfn;
17600-extern unsigned long phys_base;
17601+extern const unsigned long phys_base;
17602
17603-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17604+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17605 {
17606 unsigned long y = x - __START_KERNEL_map;
17607
17608diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17609index cd6e1610..70f4418 100644
17610--- a/arch/x86/include/asm/paravirt.h
17611+++ b/arch/x86/include/asm/paravirt.h
17612@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17613 return (pmd_t) { ret };
17614 }
17615
17616-static inline pmdval_t pmd_val(pmd_t pmd)
17617+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17618 {
17619 pmdval_t ret;
17620
17621@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17622 val);
17623 }
17624
17625+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17626+{
17627+ pgdval_t val = native_pgd_val(pgd);
17628+
17629+ if (sizeof(pgdval_t) > sizeof(long))
17630+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17631+ val, (u64)val >> 32);
17632+ else
17633+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17634+ val);
17635+}
17636+
17637 static inline void pgd_clear(pgd_t *pgdp)
17638 {
17639 set_pgd(pgdp, __pgd(0));
17640@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17641 pv_mmu_ops.set_fixmap(idx, phys, flags);
17642 }
17643
17644+#ifdef CONFIG_PAX_KERNEXEC
17645+static inline unsigned long pax_open_kernel(void)
17646+{
17647+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17648+}
17649+
17650+static inline unsigned long pax_close_kernel(void)
17651+{
17652+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17653+}
17654+#else
17655+static inline unsigned long pax_open_kernel(void) { return 0; }
17656+static inline unsigned long pax_close_kernel(void) { return 0; }
17657+#endif
17658+
17659 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17660
17661 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17662@@ -906,7 +933,7 @@ extern void default_banner(void);
17663
17664 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17665 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17666-#define PARA_INDIRECT(addr) *%cs:addr
17667+#define PARA_INDIRECT(addr) *%ss:addr
17668 #endif
17669
17670 #define INTERRUPT_RETURN \
17671@@ -981,6 +1008,21 @@ extern void default_banner(void);
17672 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17673 CLBR_NONE, \
17674 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17675+
17676+#define GET_CR0_INTO_RDI \
17677+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17678+ mov %rax,%rdi
17679+
17680+#define SET_RDI_INTO_CR0 \
17681+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17682+
17683+#define GET_CR3_INTO_RDI \
17684+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17685+ mov %rax,%rdi
17686+
17687+#define SET_RDI_INTO_CR3 \
17688+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17689+
17690 #endif /* CONFIG_X86_32 */
17691
17692 #endif /* __ASSEMBLY__ */
17693diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17694index 7549b8b..f0edfda 100644
17695--- a/arch/x86/include/asm/paravirt_types.h
17696+++ b/arch/x86/include/asm/paravirt_types.h
17697@@ -84,7 +84,7 @@ struct pv_init_ops {
17698 */
17699 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17700 unsigned long addr, unsigned len);
17701-};
17702+} __no_const __no_randomize_layout;
17703
17704
17705 struct pv_lazy_ops {
17706@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17707 void (*enter)(void);
17708 void (*leave)(void);
17709 void (*flush)(void);
17710-};
17711+} __no_randomize_layout;
17712
17713 struct pv_time_ops {
17714 unsigned long long (*sched_clock)(void);
17715 unsigned long long (*steal_clock)(int cpu);
17716 unsigned long (*get_tsc_khz)(void);
17717-};
17718+} __no_const __no_randomize_layout;
17719
17720 struct pv_cpu_ops {
17721 /* hooks for various privileged instructions */
17722@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17723
17724 void (*start_context_switch)(struct task_struct *prev);
17725 void (*end_context_switch)(struct task_struct *next);
17726-};
17727+} __no_const __no_randomize_layout;
17728
17729 struct pv_irq_ops {
17730 /*
17731@@ -215,7 +215,7 @@ struct pv_irq_ops {
17732 #ifdef CONFIG_X86_64
17733 void (*adjust_exception_frame)(void);
17734 #endif
17735-};
17736+} __no_randomize_layout;
17737
17738 struct pv_apic_ops {
17739 #ifdef CONFIG_X86_LOCAL_APIC
17740@@ -223,7 +223,7 @@ struct pv_apic_ops {
17741 unsigned long start_eip,
17742 unsigned long start_esp);
17743 #endif
17744-};
17745+} __no_const __no_randomize_layout;
17746
17747 struct pv_mmu_ops {
17748 unsigned long (*read_cr2)(void);
17749@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17750 struct paravirt_callee_save make_pud;
17751
17752 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17753+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17754 #endif /* PAGETABLE_LEVELS == 4 */
17755 #endif /* PAGETABLE_LEVELS >= 3 */
17756
17757@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17758 an mfn. We can tell which is which from the index. */
17759 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17760 phys_addr_t phys, pgprot_t flags);
17761-};
17762+
17763+#ifdef CONFIG_PAX_KERNEXEC
17764+ unsigned long (*pax_open_kernel)(void);
17765+ unsigned long (*pax_close_kernel)(void);
17766+#endif
17767+
17768+} __no_randomize_layout;
17769
17770 struct arch_spinlock;
17771 #ifdef CONFIG_SMP
17772@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17773 struct pv_lock_ops {
17774 struct paravirt_callee_save lock_spinning;
17775 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17776-};
17777+} __no_randomize_layout;
17778
17779 /* This contains all the paravirt structures: we get a convenient
17780 * number for each function using the offset which we use to indicate
17781- * what to patch. */
17782+ * what to patch.
17783+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17784+ */
17785+
17786 struct paravirt_patch_template {
17787 struct pv_init_ops pv_init_ops;
17788 struct pv_time_ops pv_time_ops;
17789@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17790 struct pv_apic_ops pv_apic_ops;
17791 struct pv_mmu_ops pv_mmu_ops;
17792 struct pv_lock_ops pv_lock_ops;
17793-};
17794+} __no_randomize_layout;
17795
17796 extern struct pv_info pv_info;
17797 extern struct pv_init_ops pv_init_ops;
17798diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17799index c4412e9..90e88c5 100644
17800--- a/arch/x86/include/asm/pgalloc.h
17801+++ b/arch/x86/include/asm/pgalloc.h
17802@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17803 pmd_t *pmd, pte_t *pte)
17804 {
17805 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17806+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17807+}
17808+
17809+static inline void pmd_populate_user(struct mm_struct *mm,
17810+ pmd_t *pmd, pte_t *pte)
17811+{
17812+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17813 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17814 }
17815
17816@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17817
17818 #ifdef CONFIG_X86_PAE
17819 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17820+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17821+{
17822+ pud_populate(mm, pudp, pmd);
17823+}
17824 #else /* !CONFIG_X86_PAE */
17825 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17826 {
17827 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17828 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17829 }
17830+
17831+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17832+{
17833+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17834+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17835+}
17836 #endif /* CONFIG_X86_PAE */
17837
17838 #if PAGETABLE_LEVELS > 3
17839@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17840 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17841 }
17842
17843+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17844+{
17845+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17846+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17847+}
17848+
17849 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17850 {
17851 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17852diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17853index 0d193e2..bf59aeb 100644
17854--- a/arch/x86/include/asm/pgtable-2level.h
17855+++ b/arch/x86/include/asm/pgtable-2level.h
17856@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17857
17858 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17859 {
17860+ pax_open_kernel();
17861 *pmdp = pmd;
17862+ pax_close_kernel();
17863 }
17864
17865 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17866diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17867index 81bb91b..9392125 100644
17868--- a/arch/x86/include/asm/pgtable-3level.h
17869+++ b/arch/x86/include/asm/pgtable-3level.h
17870@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17871
17872 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17873 {
17874+ pax_open_kernel();
17875 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17876+ pax_close_kernel();
17877 }
17878
17879 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17880 {
17881+ pax_open_kernel();
17882 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17883+ pax_close_kernel();
17884 }
17885
17886 /*
17887diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17888index bbc8b12..f228861 100644
17889--- a/arch/x86/include/asm/pgtable.h
17890+++ b/arch/x86/include/asm/pgtable.h
17891@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17892
17893 #ifndef __PAGETABLE_PUD_FOLDED
17894 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17895+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17896 #define pgd_clear(pgd) native_pgd_clear(pgd)
17897 #endif
17898
17899@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17900
17901 #define arch_end_context_switch(prev) do {} while(0)
17902
17903+#define pax_open_kernel() native_pax_open_kernel()
17904+#define pax_close_kernel() native_pax_close_kernel()
17905 #endif /* CONFIG_PARAVIRT */
17906
17907+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17908+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17909+
17910+#ifdef CONFIG_PAX_KERNEXEC
17911+static inline unsigned long native_pax_open_kernel(void)
17912+{
17913+ unsigned long cr0;
17914+
17915+ preempt_disable();
17916+ barrier();
17917+ cr0 = read_cr0() ^ X86_CR0_WP;
17918+ BUG_ON(cr0 & X86_CR0_WP);
17919+ write_cr0(cr0);
17920+ return cr0 ^ X86_CR0_WP;
17921+}
17922+
17923+static inline unsigned long native_pax_close_kernel(void)
17924+{
17925+ unsigned long cr0;
17926+
17927+ cr0 = read_cr0() ^ X86_CR0_WP;
17928+ BUG_ON(!(cr0 & X86_CR0_WP));
17929+ write_cr0(cr0);
17930+ barrier();
17931+ preempt_enable_no_resched();
17932+ return cr0 ^ X86_CR0_WP;
17933+}
17934+#else
17935+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17936+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17937+#endif
17938+
17939 /*
17940 * The following only work if pte_present() is true.
17941 * Undefined behaviour if not..
17942 */
17943+static inline int pte_user(pte_t pte)
17944+{
17945+ return pte_val(pte) & _PAGE_USER;
17946+}
17947+
17948 static inline int pte_dirty(pte_t pte)
17949 {
17950 return pte_flags(pte) & _PAGE_DIRTY;
17951@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17952 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17953 }
17954
17955+static inline unsigned long pgd_pfn(pgd_t pgd)
17956+{
17957+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17958+}
17959+
17960 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17961
17962 static inline int pmd_large(pmd_t pte)
17963@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17964 return pte_clear_flags(pte, _PAGE_RW);
17965 }
17966
17967+static inline pte_t pte_mkread(pte_t pte)
17968+{
17969+ return __pte(pte_val(pte) | _PAGE_USER);
17970+}
17971+
17972 static inline pte_t pte_mkexec(pte_t pte)
17973 {
17974- return pte_clear_flags(pte, _PAGE_NX);
17975+#ifdef CONFIG_X86_PAE
17976+ if (__supported_pte_mask & _PAGE_NX)
17977+ return pte_clear_flags(pte, _PAGE_NX);
17978+ else
17979+#endif
17980+ return pte_set_flags(pte, _PAGE_USER);
17981+}
17982+
17983+static inline pte_t pte_exprotect(pte_t pte)
17984+{
17985+#ifdef CONFIG_X86_PAE
17986+ if (__supported_pte_mask & _PAGE_NX)
17987+ return pte_set_flags(pte, _PAGE_NX);
17988+ else
17989+#endif
17990+ return pte_clear_flags(pte, _PAGE_USER);
17991 }
17992
17993 static inline pte_t pte_mkdirty(pte_t pte)
17994@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17995 #endif
17996
17997 #ifndef __ASSEMBLY__
17998+
17999+#ifdef CONFIG_PAX_PER_CPU_PGD
18000+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18001+enum cpu_pgd_type {kernel = 0, user = 1};
18002+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18003+{
18004+ return cpu_pgd[cpu][type];
18005+}
18006+#endif
18007+
18008 #include <linux/mm_types.h>
18009 #include <linux/mmdebug.h>
18010 #include <linux/log2.h>
18011@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18012 * Currently stuck as a macro due to indirect forward reference to
18013 * linux/mmzone.h's __section_mem_map_addr() definition:
18014 */
18015-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18016+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18017
18018 /* Find an entry in the second-level page table.. */
18019 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18020@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18021 * Currently stuck as a macro due to indirect forward reference to
18022 * linux/mmzone.h's __section_mem_map_addr() definition:
18023 */
18024-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18025+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18026
18027 /* to find an entry in a page-table-directory. */
18028 static inline unsigned long pud_index(unsigned long address)
18029@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18030
18031 static inline int pgd_bad(pgd_t pgd)
18032 {
18033- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18034+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18035 }
18036
18037 static inline int pgd_none(pgd_t pgd)
18038@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
18039 * pgd_offset() returns a (pgd_t *)
18040 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18041 */
18042-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18043+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18044+
18045+#ifdef CONFIG_PAX_PER_CPU_PGD
18046+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18047+#endif
18048+
18049 /*
18050 * a shortcut which implies the use of the kernel's pgd, instead
18051 * of a process's
18052@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
18053 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18054 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18055
18056+#ifdef CONFIG_X86_32
18057+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18058+#else
18059+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18060+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18061+
18062+#ifdef CONFIG_PAX_MEMORY_UDEREF
18063+#ifdef __ASSEMBLY__
18064+#define pax_user_shadow_base pax_user_shadow_base(%rip)
18065+#else
18066+extern unsigned long pax_user_shadow_base;
18067+extern pgdval_t clone_pgd_mask;
18068+#endif
18069+#endif
18070+
18071+#endif
18072+
18073 #ifndef __ASSEMBLY__
18074
18075 extern int direct_gbpages;
18076@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18077 * dst and src can be on the same page, but the range must not overlap,
18078 * and must not cross a page boundary.
18079 */
18080-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18081+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18082 {
18083- memcpy(dst, src, count * sizeof(pgd_t));
18084+ pax_open_kernel();
18085+ while (count--)
18086+ *dst++ = *src++;
18087+ pax_close_kernel();
18088 }
18089
18090+#ifdef CONFIG_PAX_PER_CPU_PGD
18091+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18092+#endif
18093+
18094+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18095+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18096+#else
18097+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18098+#endif
18099+
18100 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18101 static inline int page_level_shift(enum pg_level level)
18102 {
18103diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18104index 9ee3221..b979c6b 100644
18105--- a/arch/x86/include/asm/pgtable_32.h
18106+++ b/arch/x86/include/asm/pgtable_32.h
18107@@ -25,9 +25,6 @@
18108 struct mm_struct;
18109 struct vm_area_struct;
18110
18111-extern pgd_t swapper_pg_dir[1024];
18112-extern pgd_t initial_page_table[1024];
18113-
18114 static inline void pgtable_cache_init(void) { }
18115 static inline void check_pgt_cache(void) { }
18116 void paging_init(void);
18117@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18118 # include <asm/pgtable-2level.h>
18119 #endif
18120
18121+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18122+extern pgd_t initial_page_table[PTRS_PER_PGD];
18123+#ifdef CONFIG_X86_PAE
18124+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18125+#endif
18126+
18127 #if defined(CONFIG_HIGHPTE)
18128 #define pte_offset_map(dir, address) \
18129 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18130@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18131 /* Clear a kernel PTE and flush it from the TLB */
18132 #define kpte_clear_flush(ptep, vaddr) \
18133 do { \
18134+ pax_open_kernel(); \
18135 pte_clear(&init_mm, (vaddr), (ptep)); \
18136+ pax_close_kernel(); \
18137 __flush_tlb_one((vaddr)); \
18138 } while (0)
18139
18140 #endif /* !__ASSEMBLY__ */
18141
18142+#define HAVE_ARCH_UNMAPPED_AREA
18143+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18144+
18145 /*
18146 * kern_addr_valid() is (1) for FLATMEM and (0) for
18147 * SPARSEMEM and DISCONTIGMEM
18148diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18149index ed5903b..c7fe163 100644
18150--- a/arch/x86/include/asm/pgtable_32_types.h
18151+++ b/arch/x86/include/asm/pgtable_32_types.h
18152@@ -8,7 +8,7 @@
18153 */
18154 #ifdef CONFIG_X86_PAE
18155 # include <asm/pgtable-3level_types.h>
18156-# define PMD_SIZE (1UL << PMD_SHIFT)
18157+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18158 # define PMD_MASK (~(PMD_SIZE - 1))
18159 #else
18160 # include <asm/pgtable-2level_types.h>
18161@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18162 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18163 #endif
18164
18165+#ifdef CONFIG_PAX_KERNEXEC
18166+#ifndef __ASSEMBLY__
18167+extern unsigned char MODULES_EXEC_VADDR[];
18168+extern unsigned char MODULES_EXEC_END[];
18169+#endif
18170+#include <asm/boot.h>
18171+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18172+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18173+#else
18174+#define ktla_ktva(addr) (addr)
18175+#define ktva_ktla(addr) (addr)
18176+#endif
18177+
18178 #define MODULES_VADDR VMALLOC_START
18179 #define MODULES_END VMALLOC_END
18180 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18181diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18182index e22c1db..23a625a 100644
18183--- a/arch/x86/include/asm/pgtable_64.h
18184+++ b/arch/x86/include/asm/pgtable_64.h
18185@@ -16,10 +16,14 @@
18186
18187 extern pud_t level3_kernel_pgt[512];
18188 extern pud_t level3_ident_pgt[512];
18189+extern pud_t level3_vmalloc_start_pgt[512];
18190+extern pud_t level3_vmalloc_end_pgt[512];
18191+extern pud_t level3_vmemmap_pgt[512];
18192+extern pud_t level2_vmemmap_pgt[512];
18193 extern pmd_t level2_kernel_pgt[512];
18194 extern pmd_t level2_fixmap_pgt[512];
18195-extern pmd_t level2_ident_pgt[512];
18196-extern pgd_t init_level4_pgt[];
18197+extern pmd_t level2_ident_pgt[512*2];
18198+extern pgd_t init_level4_pgt[512];
18199
18200 #define swapper_pg_dir init_level4_pgt
18201
18202@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18203
18204 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18205 {
18206+ pax_open_kernel();
18207 *pmdp = pmd;
18208+ pax_close_kernel();
18209 }
18210
18211 static inline void native_pmd_clear(pmd_t *pmd)
18212@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18213
18214 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18215 {
18216+ pax_open_kernel();
18217 *pudp = pud;
18218+ pax_close_kernel();
18219 }
18220
18221 static inline void native_pud_clear(pud_t *pud)
18222@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18223
18224 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18225 {
18226+ pax_open_kernel();
18227+ *pgdp = pgd;
18228+ pax_close_kernel();
18229+}
18230+
18231+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18232+{
18233 *pgdp = pgd;
18234 }
18235
18236diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18237index c883bf7..19970b3 100644
18238--- a/arch/x86/include/asm/pgtable_64_types.h
18239+++ b/arch/x86/include/asm/pgtable_64_types.h
18240@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
18241 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18242 #define MODULES_END _AC(0xffffffffff000000, UL)
18243 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18244+#define MODULES_EXEC_VADDR MODULES_VADDR
18245+#define MODULES_EXEC_END MODULES_END
18246+
18247+#define ktla_ktva(addr) (addr)
18248+#define ktva_ktla(addr) (addr)
18249
18250 #define EARLY_DYNAMIC_PAGE_TABLES 64
18251
18252diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18253index 94e40f1..ebd03e4 100644
18254--- a/arch/x86/include/asm/pgtable_types.h
18255+++ b/arch/x86/include/asm/pgtable_types.h
18256@@ -16,13 +16,12 @@
18257 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18258 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18259 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18260-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18261+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18262 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18263 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18264 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18265-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18266-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18267-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18268+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18269+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18270 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18271
18272 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18273@@ -40,7 +39,6 @@
18274 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18275 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18276 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18277-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18278 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18279 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18280 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18281@@ -87,8 +85,10 @@
18282
18283 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18284 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18285-#else
18286+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18287 #define _PAGE_NX (_AT(pteval_t, 0))
18288+#else
18289+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18290 #endif
18291
18292 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18293@@ -147,6 +147,9 @@
18294 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18295 _PAGE_ACCESSED)
18296
18297+#define PAGE_READONLY_NOEXEC PAGE_READONLY
18298+#define PAGE_SHARED_NOEXEC PAGE_SHARED
18299+
18300 #define __PAGE_KERNEL_EXEC \
18301 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18302 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18303@@ -157,7 +160,7 @@
18304 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18305 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18306 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18307-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18308+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18309 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18310 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18311 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18312@@ -219,8 +222,8 @@
18313 * bits are combined, this will alow user to access the high address mapped
18314 * VDSO in the presence of CONFIG_COMPAT_VDSO
18315 */
18316-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18317-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
18318+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18319+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18320 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18321 #endif
18322
18323@@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18324 {
18325 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18326 }
18327+#endif
18328
18329+#if PAGETABLE_LEVELS == 3
18330+#include <asm-generic/pgtable-nopud.h>
18331+#endif
18332+
18333+#if PAGETABLE_LEVELS == 2
18334+#include <asm-generic/pgtable-nopmd.h>
18335+#endif
18336+
18337+#ifndef __ASSEMBLY__
18338 #if PAGETABLE_LEVELS > 3
18339 typedef struct { pudval_t pud; } pud_t;
18340
18341@@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18342 return pud.pud;
18343 }
18344 #else
18345-#include <asm-generic/pgtable-nopud.h>
18346-
18347 static inline pudval_t native_pud_val(pud_t pud)
18348 {
18349 return native_pgd_val(pud.pgd);
18350@@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18351 return pmd.pmd;
18352 }
18353 #else
18354-#include <asm-generic/pgtable-nopmd.h>
18355-
18356 static inline pmdval_t native_pmd_val(pmd_t pmd)
18357 {
18358 return native_pgd_val(pmd.pud.pgd);
18359@@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
18360
18361 extern pteval_t __supported_pte_mask;
18362 extern void set_nx(void);
18363-extern int nx_enabled;
18364
18365 #define pgprot_writecombine pgprot_writecombine
18366 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18367diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18368index c8b0519..fd29e73 100644
18369--- a/arch/x86/include/asm/preempt.h
18370+++ b/arch/x86/include/asm/preempt.h
18371@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18372 */
18373 static __always_inline bool __preempt_count_dec_and_test(void)
18374 {
18375- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18376+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18377 }
18378
18379 /*
18380diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18381index fdedd38..95c02c2 100644
18382--- a/arch/x86/include/asm/processor.h
18383+++ b/arch/x86/include/asm/processor.h
18384@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18385 /* Index into per_cpu list: */
18386 u16 cpu_index;
18387 u32 microcode;
18388-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18389+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18390
18391 #define X86_VENDOR_INTEL 0
18392 #define X86_VENDOR_CYRIX 1
18393@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18394 : "memory");
18395 }
18396
18397+/* invpcid (%rdx),%rax */
18398+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18399+
18400+#define INVPCID_SINGLE_ADDRESS 0UL
18401+#define INVPCID_SINGLE_CONTEXT 1UL
18402+#define INVPCID_ALL_GLOBAL 2UL
18403+#define INVPCID_ALL_MONGLOBAL 3UL
18404+
18405+#define PCID_KERNEL 0UL
18406+#define PCID_USER 1UL
18407+#define PCID_NOFLUSH (1UL << 63)
18408+
18409 static inline void load_cr3(pgd_t *pgdir)
18410 {
18411- write_cr3(__pa(pgdir));
18412+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18413 }
18414
18415 #ifdef CONFIG_X86_32
18416@@ -283,7 +295,7 @@ struct tss_struct {
18417
18418 } ____cacheline_aligned;
18419
18420-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18421+extern struct tss_struct init_tss[NR_CPUS];
18422
18423 /*
18424 * Save the original ist values for checking stack pointers during debugging
18425@@ -470,6 +482,7 @@ struct thread_struct {
18426 unsigned short ds;
18427 unsigned short fsindex;
18428 unsigned short gsindex;
18429+ unsigned short ss;
18430 #endif
18431 #ifdef CONFIG_X86_32
18432 unsigned long ip;
18433@@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
18434 extern unsigned long mmu_cr4_features;
18435 extern u32 *trampoline_cr4_features;
18436
18437-static inline void set_in_cr4(unsigned long mask)
18438-{
18439- unsigned long cr4;
18440-
18441- mmu_cr4_features |= mask;
18442- if (trampoline_cr4_features)
18443- *trampoline_cr4_features = mmu_cr4_features;
18444- cr4 = read_cr4();
18445- cr4 |= mask;
18446- write_cr4(cr4);
18447-}
18448-
18449-static inline void clear_in_cr4(unsigned long mask)
18450-{
18451- unsigned long cr4;
18452-
18453- mmu_cr4_features &= ~mask;
18454- if (trampoline_cr4_features)
18455- *trampoline_cr4_features = mmu_cr4_features;
18456- cr4 = read_cr4();
18457- cr4 &= ~mask;
18458- write_cr4(cr4);
18459-}
18460+extern void set_in_cr4(unsigned long mask);
18461+extern void clear_in_cr4(unsigned long mask);
18462
18463 typedef struct {
18464 unsigned long seg;
18465@@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
18466 */
18467 #define TASK_SIZE PAGE_OFFSET
18468 #define TASK_SIZE_MAX TASK_SIZE
18469+
18470+#ifdef CONFIG_PAX_SEGMEXEC
18471+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18472+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18473+#else
18474 #define STACK_TOP TASK_SIZE
18475-#define STACK_TOP_MAX STACK_TOP
18476+#endif
18477+
18478+#define STACK_TOP_MAX TASK_SIZE
18479
18480 #define INIT_THREAD { \
18481- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18482+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18483 .vm86_info = NULL, \
18484 .sysenter_cs = __KERNEL_CS, \
18485 .io_bitmap_ptr = NULL, \
18486@@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
18487 */
18488 #define INIT_TSS { \
18489 .x86_tss = { \
18490- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18491+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18492 .ss0 = __KERNEL_DS, \
18493 .ss1 = __KERNEL_CS, \
18494 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18495@@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
18496 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18497
18498 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18499-#define KSTK_TOP(info) \
18500-({ \
18501- unsigned long *__ptr = (unsigned long *)(info); \
18502- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18503-})
18504+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18505
18506 /*
18507 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18508@@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18509 #define task_pt_regs(task) \
18510 ({ \
18511 struct pt_regs *__regs__; \
18512- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18513+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18514 __regs__ - 1; \
18515 })
18516
18517@@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18518 /*
18519 * User space process size. 47bits minus one guard page.
18520 */
18521-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18522+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18523
18524 /* This decides where the kernel will search for a free chunk of vm
18525 * space during mmap's.
18526 */
18527 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18528- 0xc0000000 : 0xFFFFe000)
18529+ 0xc0000000 : 0xFFFFf000)
18530
18531 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18532 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18533@@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18534 #define STACK_TOP_MAX TASK_SIZE_MAX
18535
18536 #define INIT_THREAD { \
18537- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18538+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18539 }
18540
18541 #define INIT_TSS { \
18542- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18543+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18544 }
18545
18546 /*
18547@@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18548 */
18549 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18550
18551+#ifdef CONFIG_PAX_SEGMEXEC
18552+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18553+#endif
18554+
18555 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18556
18557 /* Get/set a process' ability to use the timestamp counter instruction */
18558@@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18559 return 0;
18560 }
18561
18562-extern unsigned long arch_align_stack(unsigned long sp);
18563+#define arch_align_stack(x) ((x) & ~0xfUL)
18564 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18565
18566 void default_idle(void);
18567@@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
18568 #define xen_set_default_idle 0
18569 #endif
18570
18571-void stop_this_cpu(void *dummy);
18572+void stop_this_cpu(void *dummy) __noreturn;
18573 void df_debug(struct pt_regs *regs, long error_code);
18574 #endif /* _ASM_X86_PROCESSOR_H */
18575diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18576index 14fd6fd..6740420 100644
18577--- a/arch/x86/include/asm/ptrace.h
18578+++ b/arch/x86/include/asm/ptrace.h
18579@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18580 }
18581
18582 /*
18583- * user_mode_vm(regs) determines whether a register set came from user mode.
18584+ * user_mode(regs) determines whether a register set came from user mode.
18585 * This is true if V8086 mode was enabled OR if the register set was from
18586 * protected mode with RPL-3 CS value. This tricky test checks that with
18587 * one comparison. Many places in the kernel can bypass this full check
18588- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18589+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18590+ * be used.
18591 */
18592-static inline int user_mode(struct pt_regs *regs)
18593+static inline int user_mode_novm(struct pt_regs *regs)
18594 {
18595 #ifdef CONFIG_X86_32
18596 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18597 #else
18598- return !!(regs->cs & 3);
18599+ return !!(regs->cs & SEGMENT_RPL_MASK);
18600 #endif
18601 }
18602
18603-static inline int user_mode_vm(struct pt_regs *regs)
18604+static inline int user_mode(struct pt_regs *regs)
18605 {
18606 #ifdef CONFIG_X86_32
18607 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18608 USER_RPL;
18609 #else
18610- return user_mode(regs);
18611+ return user_mode_novm(regs);
18612 #endif
18613 }
18614
18615@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18616 #ifdef CONFIG_X86_64
18617 static inline bool user_64bit_mode(struct pt_regs *regs)
18618 {
18619+ unsigned long cs = regs->cs & 0xffff;
18620 #ifndef CONFIG_PARAVIRT
18621 /*
18622 * On non-paravirt systems, this is the only long mode CPL 3
18623 * selector. We do not allow long mode selectors in the LDT.
18624 */
18625- return regs->cs == __USER_CS;
18626+ return cs == __USER_CS;
18627 #else
18628 /* Headers are too twisted for this to go in paravirt.h. */
18629- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18630+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18631 #endif
18632 }
18633
18634@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18635 * Traps from the kernel do not save sp and ss.
18636 * Use the helper function to retrieve sp.
18637 */
18638- if (offset == offsetof(struct pt_regs, sp) &&
18639- regs->cs == __KERNEL_CS)
18640- return kernel_stack_pointer(regs);
18641+ if (offset == offsetof(struct pt_regs, sp)) {
18642+ unsigned long cs = regs->cs & 0xffff;
18643+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18644+ return kernel_stack_pointer(regs);
18645+ }
18646 #endif
18647 return *(unsigned long *)((unsigned long)regs + offset);
18648 }
18649diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18650index 9c6b890..5305f53 100644
18651--- a/arch/x86/include/asm/realmode.h
18652+++ b/arch/x86/include/asm/realmode.h
18653@@ -22,16 +22,14 @@ struct real_mode_header {
18654 #endif
18655 /* APM/BIOS reboot */
18656 u32 machine_real_restart_asm;
18657-#ifdef CONFIG_X86_64
18658 u32 machine_real_restart_seg;
18659-#endif
18660 };
18661
18662 /* This must match data at trampoline_32/64.S */
18663 struct trampoline_header {
18664 #ifdef CONFIG_X86_32
18665 u32 start;
18666- u16 gdt_pad;
18667+ u16 boot_cs;
18668 u16 gdt_limit;
18669 u32 gdt_base;
18670 #else
18671diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18672index a82c4f1..ac45053 100644
18673--- a/arch/x86/include/asm/reboot.h
18674+++ b/arch/x86/include/asm/reboot.h
18675@@ -6,13 +6,13 @@
18676 struct pt_regs;
18677
18678 struct machine_ops {
18679- void (*restart)(char *cmd);
18680- void (*halt)(void);
18681- void (*power_off)(void);
18682+ void (* __noreturn restart)(char *cmd);
18683+ void (* __noreturn halt)(void);
18684+ void (* __noreturn power_off)(void);
18685 void (*shutdown)(void);
18686 void (*crash_shutdown)(struct pt_regs *);
18687- void (*emergency_restart)(void);
18688-};
18689+ void (* __noreturn emergency_restart)(void);
18690+} __no_const;
18691
18692 extern struct machine_ops machine_ops;
18693
18694diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18695index 8f7866a..e442f20 100644
18696--- a/arch/x86/include/asm/rmwcc.h
18697+++ b/arch/x86/include/asm/rmwcc.h
18698@@ -3,7 +3,34 @@
18699
18700 #ifdef CC_HAVE_ASM_GOTO
18701
18702-#define __GEN_RMWcc(fullop, var, cc, ...) \
18703+#ifdef CONFIG_PAX_REFCOUNT
18704+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18705+do { \
18706+ asm_volatile_goto (fullop \
18707+ ";jno 0f\n" \
18708+ fullantiop \
18709+ ";int $4\n0:\n" \
18710+ _ASM_EXTABLE(0b, 0b) \
18711+ ";j" cc " %l[cc_label]" \
18712+ : : "m" (var), ## __VA_ARGS__ \
18713+ : "memory" : cc_label); \
18714+ return 0; \
18715+cc_label: \
18716+ return 1; \
18717+} while (0)
18718+#else
18719+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18720+do { \
18721+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18722+ : : "m" (var), ## __VA_ARGS__ \
18723+ : "memory" : cc_label); \
18724+ return 0; \
18725+cc_label: \
18726+ return 1; \
18727+} while (0)
18728+#endif
18729+
18730+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18731 do { \
18732 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18733 : : "m" (var), ## __VA_ARGS__ \
18734@@ -13,15 +40,46 @@ cc_label: \
18735 return 1; \
18736 } while (0)
18737
18738-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18739- __GEN_RMWcc(op " " arg0, var, cc)
18740+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18741+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18742
18743-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18744- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18745+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18746+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18747+
18748+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18749+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18750+
18751+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18752+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18753
18754 #else /* !CC_HAVE_ASM_GOTO */
18755
18756-#define __GEN_RMWcc(fullop, var, cc, ...) \
18757+#ifdef CONFIG_PAX_REFCOUNT
18758+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18759+do { \
18760+ char c; \
18761+ asm volatile (fullop \
18762+ ";jno 0f\n" \
18763+ fullantiop \
18764+ ";int $4\n0:\n" \
18765+ _ASM_EXTABLE(0b, 0b) \
18766+ "; set" cc " %1" \
18767+ : "+m" (var), "=qm" (c) \
18768+ : __VA_ARGS__ : "memory"); \
18769+ return c != 0; \
18770+} while (0)
18771+#else
18772+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18773+do { \
18774+ char c; \
18775+ asm volatile (fullop "; set" cc " %1" \
18776+ : "+m" (var), "=qm" (c) \
18777+ : __VA_ARGS__ : "memory"); \
18778+ return c != 0; \
18779+} while (0)
18780+#endif
18781+
18782+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18783 do { \
18784 char c; \
18785 asm volatile (fullop "; set" cc " %1" \
18786@@ -30,11 +88,17 @@ do { \
18787 return c != 0; \
18788 } while (0)
18789
18790-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18791- __GEN_RMWcc(op " " arg0, var, cc)
18792+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18793+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18794+
18795+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18796+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18797+
18798+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18799+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18800
18801-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18802- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18803+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18804+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18805
18806 #endif /* CC_HAVE_ASM_GOTO */
18807
18808diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18809index cad82c9..2e5c5c1 100644
18810--- a/arch/x86/include/asm/rwsem.h
18811+++ b/arch/x86/include/asm/rwsem.h
18812@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18813 {
18814 asm volatile("# beginning down_read\n\t"
18815 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18816+
18817+#ifdef CONFIG_PAX_REFCOUNT
18818+ "jno 0f\n"
18819+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18820+ "int $4\n0:\n"
18821+ _ASM_EXTABLE(0b, 0b)
18822+#endif
18823+
18824 /* adds 0x00000001 */
18825 " jns 1f\n"
18826 " call call_rwsem_down_read_failed\n"
18827@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18828 "1:\n\t"
18829 " mov %1,%2\n\t"
18830 " add %3,%2\n\t"
18831+
18832+#ifdef CONFIG_PAX_REFCOUNT
18833+ "jno 0f\n"
18834+ "sub %3,%2\n"
18835+ "int $4\n0:\n"
18836+ _ASM_EXTABLE(0b, 0b)
18837+#endif
18838+
18839 " jle 2f\n\t"
18840 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18841 " jnz 1b\n\t"
18842@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18843 long tmp;
18844 asm volatile("# beginning down_write\n\t"
18845 LOCK_PREFIX " xadd %1,(%2)\n\t"
18846+
18847+#ifdef CONFIG_PAX_REFCOUNT
18848+ "jno 0f\n"
18849+ "mov %1,(%2)\n"
18850+ "int $4\n0:\n"
18851+ _ASM_EXTABLE(0b, 0b)
18852+#endif
18853+
18854 /* adds 0xffff0001, returns the old value */
18855 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18856 /* was the active mask 0 before? */
18857@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18858 long tmp;
18859 asm volatile("# beginning __up_read\n\t"
18860 LOCK_PREFIX " xadd %1,(%2)\n\t"
18861+
18862+#ifdef CONFIG_PAX_REFCOUNT
18863+ "jno 0f\n"
18864+ "mov %1,(%2)\n"
18865+ "int $4\n0:\n"
18866+ _ASM_EXTABLE(0b, 0b)
18867+#endif
18868+
18869 /* subtracts 1, returns the old value */
18870 " jns 1f\n\t"
18871 " call call_rwsem_wake\n" /* expects old value in %edx */
18872@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18873 long tmp;
18874 asm volatile("# beginning __up_write\n\t"
18875 LOCK_PREFIX " xadd %1,(%2)\n\t"
18876+
18877+#ifdef CONFIG_PAX_REFCOUNT
18878+ "jno 0f\n"
18879+ "mov %1,(%2)\n"
18880+ "int $4\n0:\n"
18881+ _ASM_EXTABLE(0b, 0b)
18882+#endif
18883+
18884 /* subtracts 0xffff0001, returns the old value */
18885 " jns 1f\n\t"
18886 " call call_rwsem_wake\n" /* expects old value in %edx */
18887@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18888 {
18889 asm volatile("# beginning __downgrade_write\n\t"
18890 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18891+
18892+#ifdef CONFIG_PAX_REFCOUNT
18893+ "jno 0f\n"
18894+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18895+ "int $4\n0:\n"
18896+ _ASM_EXTABLE(0b, 0b)
18897+#endif
18898+
18899 /*
18900 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18901 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18902@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18903 */
18904 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18905 {
18906- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18907+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18908+
18909+#ifdef CONFIG_PAX_REFCOUNT
18910+ "jno 0f\n"
18911+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18912+ "int $4\n0:\n"
18913+ _ASM_EXTABLE(0b, 0b)
18914+#endif
18915+
18916 : "+m" (sem->count)
18917 : "er" (delta));
18918 }
18919@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18920 */
18921 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18922 {
18923- return delta + xadd(&sem->count, delta);
18924+ return delta + xadd_check_overflow(&sem->count, delta);
18925 }
18926
18927 #endif /* __KERNEL__ */
18928diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18929index 6f1c3a8..7744f19 100644
18930--- a/arch/x86/include/asm/segment.h
18931+++ b/arch/x86/include/asm/segment.h
18932@@ -64,10 +64,15 @@
18933 * 26 - ESPFIX small SS
18934 * 27 - per-cpu [ offset to per-cpu data area ]
18935 * 28 - stack_canary-20 [ for stack protector ]
18936- * 29 - unused
18937- * 30 - unused
18938+ * 29 - PCI BIOS CS
18939+ * 30 - PCI BIOS DS
18940 * 31 - TSS for double fault handler
18941 */
18942+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18943+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18944+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18945+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18946+
18947 #define GDT_ENTRY_TLS_MIN 6
18948 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18949
18950@@ -79,6 +84,8 @@
18951
18952 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18953
18954+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18955+
18956 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18957
18958 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18959@@ -104,6 +111,12 @@
18960 #define __KERNEL_STACK_CANARY 0
18961 #endif
18962
18963+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18964+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18965+
18966+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18967+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18968+
18969 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18970
18971 /*
18972@@ -141,7 +154,7 @@
18973 */
18974
18975 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18976-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18977+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18978
18979
18980 #else
18981@@ -165,6 +178,8 @@
18982 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18983 #define __USER32_DS __USER_DS
18984
18985+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18986+
18987 #define GDT_ENTRY_TSS 8 /* needs two entries */
18988 #define GDT_ENTRY_LDT 10 /* needs two entries */
18989 #define GDT_ENTRY_TLS_MIN 12
18990@@ -173,6 +188,8 @@
18991 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18992 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18993
18994+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18995+
18996 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18997 #define FS_TLS 0
18998 #define GS_TLS 1
18999@@ -180,12 +197,14 @@
19000 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19001 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19002
19003-#define GDT_ENTRIES 16
19004+#define GDT_ENTRIES 17
19005
19006 #endif
19007
19008 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19009+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19010 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19011+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19012 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19013 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19014 #ifndef CONFIG_PARAVIRT
19015@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19016 {
19017 unsigned long __limit;
19018 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19019- return __limit + 1;
19020+ return __limit;
19021 }
19022
19023 #endif /* !__ASSEMBLY__ */
19024diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19025index 8d3120f..352b440 100644
19026--- a/arch/x86/include/asm/smap.h
19027+++ b/arch/x86/include/asm/smap.h
19028@@ -25,11 +25,40 @@
19029
19030 #include <asm/alternative-asm.h>
19031
19032+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19033+#define ASM_PAX_OPEN_USERLAND \
19034+ 661: jmp 663f; \
19035+ .pushsection .altinstr_replacement, "a" ; \
19036+ 662: pushq %rax; nop; \
19037+ .popsection ; \
19038+ .pushsection .altinstructions, "a" ; \
19039+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19040+ .popsection ; \
19041+ call __pax_open_userland; \
19042+ popq %rax; \
19043+ 663:
19044+
19045+#define ASM_PAX_CLOSE_USERLAND \
19046+ 661: jmp 663f; \
19047+ .pushsection .altinstr_replacement, "a" ; \
19048+ 662: pushq %rax; nop; \
19049+ .popsection; \
19050+ .pushsection .altinstructions, "a" ; \
19051+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19052+ .popsection; \
19053+ call __pax_close_userland; \
19054+ popq %rax; \
19055+ 663:
19056+#else
19057+#define ASM_PAX_OPEN_USERLAND
19058+#define ASM_PAX_CLOSE_USERLAND
19059+#endif
19060+
19061 #ifdef CONFIG_X86_SMAP
19062
19063 #define ASM_CLAC \
19064 661: ASM_NOP3 ; \
19065- .pushsection .altinstr_replacement, "ax" ; \
19066+ .pushsection .altinstr_replacement, "a" ; \
19067 662: __ASM_CLAC ; \
19068 .popsection ; \
19069 .pushsection .altinstructions, "a" ; \
19070@@ -38,7 +67,7 @@
19071
19072 #define ASM_STAC \
19073 661: ASM_NOP3 ; \
19074- .pushsection .altinstr_replacement, "ax" ; \
19075+ .pushsection .altinstr_replacement, "a" ; \
19076 662: __ASM_STAC ; \
19077 .popsection ; \
19078 .pushsection .altinstructions, "a" ; \
19079@@ -56,6 +85,37 @@
19080
19081 #include <asm/alternative.h>
19082
19083+#define __HAVE_ARCH_PAX_OPEN_USERLAND
19084+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19085+
19086+extern void __pax_open_userland(void);
19087+static __always_inline unsigned long pax_open_userland(void)
19088+{
19089+
19090+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19091+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19092+ :
19093+ : [open] "i" (__pax_open_userland)
19094+ : "memory", "rax");
19095+#endif
19096+
19097+ return 0;
19098+}
19099+
19100+extern void __pax_close_userland(void);
19101+static __always_inline unsigned long pax_close_userland(void)
19102+{
19103+
19104+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19105+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19106+ :
19107+ : [close] "i" (__pax_close_userland)
19108+ : "memory", "rax");
19109+#endif
19110+
19111+ return 0;
19112+}
19113+
19114 #ifdef CONFIG_X86_SMAP
19115
19116 static __always_inline void clac(void)
19117diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19118index 8cd27e0..7f05ec8 100644
19119--- a/arch/x86/include/asm/smp.h
19120+++ b/arch/x86/include/asm/smp.h
19121@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19122 /* cpus sharing the last level cache: */
19123 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19124 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19125-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19126+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19127
19128 static inline struct cpumask *cpu_sibling_mask(int cpu)
19129 {
19130@@ -78,7 +78,7 @@ struct smp_ops {
19131
19132 void (*send_call_func_ipi)(const struct cpumask *mask);
19133 void (*send_call_func_single_ipi)(int cpu);
19134-};
19135+} __no_const;
19136
19137 /* Globals due to paravirt */
19138 extern void set_cpu_sibling_map(int cpu);
19139@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19140 extern int safe_smp_processor_id(void);
19141
19142 #elif defined(CONFIG_X86_64_SMP)
19143-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19144-
19145-#define stack_smp_processor_id() \
19146-({ \
19147- struct thread_info *ti; \
19148- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19149- ti->cpu; \
19150-})
19151+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19152+#define stack_smp_processor_id() raw_smp_processor_id()
19153 #define safe_smp_processor_id() smp_processor_id()
19154
19155 #endif
19156diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19157index 0f62f54..cb5d0dd 100644
19158--- a/arch/x86/include/asm/spinlock.h
19159+++ b/arch/x86/include/asm/spinlock.h
19160@@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19161 static inline void arch_read_lock(arch_rwlock_t *rw)
19162 {
19163 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19164+
19165+#ifdef CONFIG_PAX_REFCOUNT
19166+ "jno 0f\n"
19167+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19168+ "int $4\n0:\n"
19169+ _ASM_EXTABLE(0b, 0b)
19170+#endif
19171+
19172 "jns 1f\n"
19173 "call __read_lock_failed\n\t"
19174 "1:\n"
19175@@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19176 static inline void arch_write_lock(arch_rwlock_t *rw)
19177 {
19178 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19179+
19180+#ifdef CONFIG_PAX_REFCOUNT
19181+ "jno 0f\n"
19182+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19183+ "int $4\n0:\n"
19184+ _ASM_EXTABLE(0b, 0b)
19185+#endif
19186+
19187 "jz 1f\n"
19188 "call __write_lock_failed\n\t"
19189 "1:\n"
19190@@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19191
19192 static inline void arch_read_unlock(arch_rwlock_t *rw)
19193 {
19194- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19195+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19196+
19197+#ifdef CONFIG_PAX_REFCOUNT
19198+ "jno 0f\n"
19199+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19200+ "int $4\n0:\n"
19201+ _ASM_EXTABLE(0b, 0b)
19202+#endif
19203+
19204 :"+m" (rw->lock) : : "memory");
19205 }
19206
19207 static inline void arch_write_unlock(arch_rwlock_t *rw)
19208 {
19209- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19210+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19211+
19212+#ifdef CONFIG_PAX_REFCOUNT
19213+ "jno 0f\n"
19214+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19215+ "int $4\n0:\n"
19216+ _ASM_EXTABLE(0b, 0b)
19217+#endif
19218+
19219 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19220 }
19221
19222diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19223index 6a99859..03cb807 100644
19224--- a/arch/x86/include/asm/stackprotector.h
19225+++ b/arch/x86/include/asm/stackprotector.h
19226@@ -47,7 +47,7 @@
19227 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19228 */
19229 #define GDT_STACK_CANARY_INIT \
19230- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19231+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19232
19233 /*
19234 * Initialize the stackprotector canary value.
19235@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19236
19237 static inline void load_stack_canary_segment(void)
19238 {
19239-#ifdef CONFIG_X86_32
19240+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19241 asm volatile ("mov %0, %%gs" : : "r" (0));
19242 #endif
19243 }
19244diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19245index 70bbe39..4ae2bd4 100644
19246--- a/arch/x86/include/asm/stacktrace.h
19247+++ b/arch/x86/include/asm/stacktrace.h
19248@@ -11,28 +11,20 @@
19249
19250 extern int kstack_depth_to_print;
19251
19252-struct thread_info;
19253+struct task_struct;
19254 struct stacktrace_ops;
19255
19256-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19257- unsigned long *stack,
19258- unsigned long bp,
19259- const struct stacktrace_ops *ops,
19260- void *data,
19261- unsigned long *end,
19262- int *graph);
19263+typedef unsigned long walk_stack_t(struct task_struct *task,
19264+ void *stack_start,
19265+ unsigned long *stack,
19266+ unsigned long bp,
19267+ const struct stacktrace_ops *ops,
19268+ void *data,
19269+ unsigned long *end,
19270+ int *graph);
19271
19272-extern unsigned long
19273-print_context_stack(struct thread_info *tinfo,
19274- unsigned long *stack, unsigned long bp,
19275- const struct stacktrace_ops *ops, void *data,
19276- unsigned long *end, int *graph);
19277-
19278-extern unsigned long
19279-print_context_stack_bp(struct thread_info *tinfo,
19280- unsigned long *stack, unsigned long bp,
19281- const struct stacktrace_ops *ops, void *data,
19282- unsigned long *end, int *graph);
19283+extern walk_stack_t print_context_stack;
19284+extern walk_stack_t print_context_stack_bp;
19285
19286 /* Generic stack tracer with callbacks */
19287
19288@@ -40,7 +32,7 @@ struct stacktrace_ops {
19289 void (*address)(void *data, unsigned long address, int reliable);
19290 /* On negative return stop dumping */
19291 int (*stack)(void *data, char *name);
19292- walk_stack_t walk_stack;
19293+ walk_stack_t *walk_stack;
19294 };
19295
19296 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19297diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19298index d7f3b3b..3cc39f1 100644
19299--- a/arch/x86/include/asm/switch_to.h
19300+++ b/arch/x86/include/asm/switch_to.h
19301@@ -108,7 +108,7 @@ do { \
19302 "call __switch_to\n\t" \
19303 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19304 __switch_canary \
19305- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19306+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19307 "movq %%rax,%%rdi\n\t" \
19308 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19309 "jnz ret_from_fork\n\t" \
19310@@ -119,7 +119,7 @@ do { \
19311 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19312 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19313 [_tif_fork] "i" (_TIF_FORK), \
19314- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19315+ [thread_info] "m" (current_tinfo), \
19316 [current_task] "m" (current_task) \
19317 __switch_canary_iparam \
19318 : "memory", "cc" __EXTRA_CLOBBER)
19319diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19320index e1940c0..ac50dd8 100644
19321--- a/arch/x86/include/asm/thread_info.h
19322+++ b/arch/x86/include/asm/thread_info.h
19323@@ -10,6 +10,7 @@
19324 #include <linux/compiler.h>
19325 #include <asm/page.h>
19326 #include <asm/types.h>
19327+#include <asm/percpu.h>
19328
19329 /*
19330 * low level task data that entry.S needs immediate access to
19331@@ -23,7 +24,6 @@ struct exec_domain;
19332 #include <linux/atomic.h>
19333
19334 struct thread_info {
19335- struct task_struct *task; /* main task structure */
19336 struct exec_domain *exec_domain; /* execution domain */
19337 __u32 flags; /* low level flags */
19338 __u32 status; /* thread synchronous flags */
19339@@ -32,19 +32,13 @@ struct thread_info {
19340 mm_segment_t addr_limit;
19341 struct restart_block restart_block;
19342 void __user *sysenter_return;
19343-#ifdef CONFIG_X86_32
19344- unsigned long previous_esp; /* ESP of the previous stack in
19345- case of nested (IRQ) stacks
19346- */
19347- __u8 supervisor_stack[0];
19348-#endif
19349+ unsigned long lowest_stack;
19350 unsigned int sig_on_uaccess_error:1;
19351 unsigned int uaccess_err:1; /* uaccess failed */
19352 };
19353
19354-#define INIT_THREAD_INFO(tsk) \
19355+#define INIT_THREAD_INFO \
19356 { \
19357- .task = &tsk, \
19358 .exec_domain = &default_exec_domain, \
19359 .flags = 0, \
19360 .cpu = 0, \
19361@@ -55,7 +49,7 @@ struct thread_info {
19362 }, \
19363 }
19364
19365-#define init_thread_info (init_thread_union.thread_info)
19366+#define init_thread_info (init_thread_union.stack)
19367 #define init_stack (init_thread_union.stack)
19368
19369 #else /* !__ASSEMBLY__ */
19370@@ -95,6 +89,7 @@ struct thread_info {
19371 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19372 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19373 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19374+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19375
19376 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19377 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19378@@ -118,17 +113,18 @@ struct thread_info {
19379 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19380 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19381 #define _TIF_X32 (1 << TIF_X32)
19382+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19383
19384 /* work to do in syscall_trace_enter() */
19385 #define _TIF_WORK_SYSCALL_ENTRY \
19386 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19387 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19388- _TIF_NOHZ)
19389+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19390
19391 /* work to do in syscall_trace_leave() */
19392 #define _TIF_WORK_SYSCALL_EXIT \
19393 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19394- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19395+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19396
19397 /* work to do on interrupt/exception return */
19398 #define _TIF_WORK_MASK \
19399@@ -139,7 +135,7 @@ struct thread_info {
19400 /* work to do on any return to user space */
19401 #define _TIF_ALLWORK_MASK \
19402 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19403- _TIF_NOHZ)
19404+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19405
19406 /* Only used for 64 bit */
19407 #define _TIF_DO_NOTIFY_MASK \
19408@@ -153,6 +149,23 @@ struct thread_info {
19409 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19410 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19411
19412+#ifdef __ASSEMBLY__
19413+/* how to get the thread information struct from ASM */
19414+#define GET_THREAD_INFO(reg) \
19415+ mov PER_CPU_VAR(current_tinfo), reg
19416+
19417+/* use this one if reg already contains %esp */
19418+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19419+#else
19420+/* how to get the thread information struct from C */
19421+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19422+
19423+static __always_inline struct thread_info *current_thread_info(void)
19424+{
19425+ return this_cpu_read_stable(current_tinfo);
19426+}
19427+#endif
19428+
19429 #ifdef CONFIG_X86_32
19430
19431 #define STACK_WARN (THREAD_SIZE/8)
19432@@ -169,31 +182,10 @@ struct thread_info {
19433 sp; \
19434 })
19435
19436-/* how to get the thread information struct from C */
19437-static inline struct thread_info *current_thread_info(void)
19438-{
19439- return (struct thread_info *)
19440- (current_stack_pointer & ~(THREAD_SIZE - 1));
19441-}
19442-
19443-#else /* !__ASSEMBLY__ */
19444-
19445-/* how to get the thread information struct from ASM */
19446-#define GET_THREAD_INFO(reg) \
19447- movl $-THREAD_SIZE, reg; \
19448- andl %esp, reg
19449-
19450-/* use this one if reg already contains %esp */
19451-#define GET_THREAD_INFO_WITH_ESP(reg) \
19452- andl $-THREAD_SIZE, reg
19453-
19454 #endif
19455
19456 #else /* X86_32 */
19457
19458-#include <asm/percpu.h>
19459-#define KERNEL_STACK_OFFSET (5*8)
19460-
19461 /*
19462 * macros/functions for gaining access to the thread information structure
19463 * preempt_count needs to be 1 initially, until the scheduler is functional.
19464@@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
19465 #ifndef __ASSEMBLY__
19466 DECLARE_PER_CPU(unsigned long, kernel_stack);
19467
19468-static inline struct thread_info *current_thread_info(void)
19469-{
19470- struct thread_info *ti;
19471- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19472- KERNEL_STACK_OFFSET - THREAD_SIZE);
19473- return ti;
19474-}
19475-
19476-#else /* !__ASSEMBLY__ */
19477-
19478-/* how to get the thread information struct from ASM */
19479-#define GET_THREAD_INFO(reg) \
19480- movq PER_CPU_VAR(kernel_stack),reg ; \
19481- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19482-
19483-/*
19484- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19485- * a certain register (to be used in assembler memory operands).
19486- */
19487-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19488-
19489+/* how to get the current stack pointer from C */
19490+register unsigned long current_stack_pointer asm("rsp") __used;
19491 #endif
19492
19493 #endif /* !X86_32 */
19494@@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
19495 extern void arch_task_cache_init(void);
19496 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19497 extern void arch_release_task_struct(struct task_struct *tsk);
19498+
19499+#define __HAVE_THREAD_FUNCTIONS
19500+#define task_thread_info(task) (&(task)->tinfo)
19501+#define task_stack_page(task) ((task)->stack)
19502+#define setup_thread_stack(p, org) do {} while (0)
19503+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19504+
19505 #endif
19506 #endif /* _ASM_X86_THREAD_INFO_H */
19507diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19508index 04905bf..49203ca 100644
19509--- a/arch/x86/include/asm/tlbflush.h
19510+++ b/arch/x86/include/asm/tlbflush.h
19511@@ -17,18 +17,44 @@
19512
19513 static inline void __native_flush_tlb(void)
19514 {
19515+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19516+ u64 descriptor[2];
19517+
19518+ descriptor[0] = PCID_KERNEL;
19519+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19520+ return;
19521+ }
19522+
19523+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19524+ if (static_cpu_has(X86_FEATURE_PCID)) {
19525+ unsigned int cpu = raw_get_cpu();
19526+
19527+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19528+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19529+ raw_put_cpu_no_resched();
19530+ return;
19531+ }
19532+#endif
19533+
19534 native_write_cr3(native_read_cr3());
19535 }
19536
19537 static inline void __native_flush_tlb_global_irq_disabled(void)
19538 {
19539- unsigned long cr4;
19540+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19541+ u64 descriptor[2];
19542
19543- cr4 = native_read_cr4();
19544- /* clear PGE */
19545- native_write_cr4(cr4 & ~X86_CR4_PGE);
19546- /* write old PGE again and flush TLBs */
19547- native_write_cr4(cr4);
19548+ descriptor[0] = PCID_KERNEL;
19549+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19550+ } else {
19551+ unsigned long cr4;
19552+
19553+ cr4 = native_read_cr4();
19554+ /* clear PGE */
19555+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19556+ /* write old PGE again and flush TLBs */
19557+ native_write_cr4(cr4);
19558+ }
19559 }
19560
19561 static inline void __native_flush_tlb_global(void)
19562@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19563
19564 static inline void __native_flush_tlb_single(unsigned long addr)
19565 {
19566+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19567+ u64 descriptor[2];
19568+
19569+ descriptor[0] = PCID_KERNEL;
19570+ descriptor[1] = addr;
19571+
19572+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19573+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19574+ if (addr < TASK_SIZE_MAX)
19575+ descriptor[1] += pax_user_shadow_base;
19576+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19577+ }
19578+
19579+ descriptor[0] = PCID_USER;
19580+ descriptor[1] = addr;
19581+#endif
19582+
19583+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19584+ return;
19585+ }
19586+
19587+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19588+ if (static_cpu_has(X86_FEATURE_PCID)) {
19589+ unsigned int cpu = raw_get_cpu();
19590+
19591+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19592+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19593+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19594+ raw_put_cpu_no_resched();
19595+
19596+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19597+ addr += pax_user_shadow_base;
19598+ }
19599+#endif
19600+
19601 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19602 }
19603
19604diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19605index 0d592e0..f58a222 100644
19606--- a/arch/x86/include/asm/uaccess.h
19607+++ b/arch/x86/include/asm/uaccess.h
19608@@ -7,6 +7,7 @@
19609 #include <linux/compiler.h>
19610 #include <linux/thread_info.h>
19611 #include <linux/string.h>
19612+#include <linux/spinlock.h>
19613 #include <asm/asm.h>
19614 #include <asm/page.h>
19615 #include <asm/smap.h>
19616@@ -29,7 +30,12 @@
19617
19618 #define get_ds() (KERNEL_DS)
19619 #define get_fs() (current_thread_info()->addr_limit)
19620+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19621+void __set_fs(mm_segment_t x);
19622+void set_fs(mm_segment_t x);
19623+#else
19624 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19625+#endif
19626
19627 #define segment_eq(a, b) ((a).seg == (b).seg)
19628
19629@@ -85,8 +91,34 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19630 * checks that the pointer is in the user space range - after calling
19631 * this function, memory access functions may still return -EFAULT.
19632 */
19633-#define access_ok(type, addr, size) \
19634- likely(!__range_not_ok(addr, size, user_addr_max()))
19635+extern int _cond_resched(void);
19636+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19637+#define access_ok(type, addr, size) \
19638+({ \
19639+ long __size = size; \
19640+ unsigned long __addr = (unsigned long)addr; \
19641+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19642+ unsigned long __end_ao = __addr + __size - 1; \
19643+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19644+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19645+ while(__addr_ao <= __end_ao) { \
19646+ char __c_ao; \
19647+ __addr_ao += PAGE_SIZE; \
19648+ if (__size > PAGE_SIZE) \
19649+ _cond_resched(); \
19650+ if (__get_user(__c_ao, (char __user *)__addr)) \
19651+ break; \
19652+ if (type != VERIFY_WRITE) { \
19653+ __addr = __addr_ao; \
19654+ continue; \
19655+ } \
19656+ if (__put_user(__c_ao, (char __user *)__addr)) \
19657+ break; \
19658+ __addr = __addr_ao; \
19659+ } \
19660+ } \
19661+ __ret_ao; \
19662+})
19663
19664 /*
19665 * The exception table consists of pairs of addresses relative to the
19666@@ -176,10 +208,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19667 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19668 __chk_user_ptr(ptr); \
19669 might_fault(); \
19670+ pax_open_userland(); \
19671 asm volatile("call __get_user_%P3" \
19672 : "=a" (__ret_gu), "=r" (__val_gu) \
19673 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19674 (x) = (__typeof__(*(ptr))) __val_gu; \
19675+ pax_close_userland(); \
19676 __ret_gu; \
19677 })
19678
19679@@ -187,13 +221,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19680 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19681 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19682
19683-
19684+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19685+#define __copyuser_seg "gs;"
19686+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19687+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19688+#else
19689+#define __copyuser_seg
19690+#define __COPYUSER_SET_ES
19691+#define __COPYUSER_RESTORE_ES
19692+#endif
19693
19694 #ifdef CONFIG_X86_32
19695 #define __put_user_asm_u64(x, addr, err, errret) \
19696 asm volatile(ASM_STAC "\n" \
19697- "1: movl %%eax,0(%2)\n" \
19698- "2: movl %%edx,4(%2)\n" \
19699+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19700+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19701 "3: " ASM_CLAC "\n" \
19702 ".section .fixup,\"ax\"\n" \
19703 "4: movl %3,%0\n" \
19704@@ -206,8 +248,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19705
19706 #define __put_user_asm_ex_u64(x, addr) \
19707 asm volatile(ASM_STAC "\n" \
19708- "1: movl %%eax,0(%1)\n" \
19709- "2: movl %%edx,4(%1)\n" \
19710+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19711+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19712 "3: " ASM_CLAC "\n" \
19713 _ASM_EXTABLE_EX(1b, 2b) \
19714 _ASM_EXTABLE_EX(2b, 3b) \
19715@@ -257,7 +299,8 @@ extern void __put_user_8(void);
19716 __typeof__(*(ptr)) __pu_val; \
19717 __chk_user_ptr(ptr); \
19718 might_fault(); \
19719- __pu_val = x; \
19720+ __pu_val = (x); \
19721+ pax_open_userland(); \
19722 switch (sizeof(*(ptr))) { \
19723 case 1: \
19724 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19725@@ -275,6 +318,7 @@ extern void __put_user_8(void);
19726 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19727 break; \
19728 } \
19729+ pax_close_userland(); \
19730 __ret_pu; \
19731 })
19732
19733@@ -355,8 +399,10 @@ do { \
19734 } while (0)
19735
19736 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19737+do { \
19738+ pax_open_userland(); \
19739 asm volatile(ASM_STAC "\n" \
19740- "1: mov"itype" %2,%"rtype"1\n" \
19741+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19742 "2: " ASM_CLAC "\n" \
19743 ".section .fixup,\"ax\"\n" \
19744 "3: mov %3,%0\n" \
19745@@ -364,8 +410,10 @@ do { \
19746 " jmp 2b\n" \
19747 ".previous\n" \
19748 _ASM_EXTABLE(1b, 3b) \
19749- : "=r" (err), ltype(x) \
19750- : "m" (__m(addr)), "i" (errret), "0" (err))
19751+ : "=r" (err), ltype (x) \
19752+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19753+ pax_close_userland(); \
19754+} while (0)
19755
19756 #define __get_user_size_ex(x, ptr, size) \
19757 do { \
19758@@ -389,7 +437,7 @@ do { \
19759 } while (0)
19760
19761 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19762- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19763+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19764 "2:\n" \
19765 _ASM_EXTABLE_EX(1b, 2b) \
19766 : ltype(x) : "m" (__m(addr)))
19767@@ -406,13 +454,24 @@ do { \
19768 int __gu_err; \
19769 unsigned long __gu_val; \
19770 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19771- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19772+ (x) = (__typeof__(*(ptr)))__gu_val; \
19773 __gu_err; \
19774 })
19775
19776 /* FIXME: this hack is definitely wrong -AK */
19777 struct __large_struct { unsigned long buf[100]; };
19778-#define __m(x) (*(struct __large_struct __user *)(x))
19779+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19780+#define ____m(x) \
19781+({ \
19782+ unsigned long ____x = (unsigned long)(x); \
19783+ if (____x < pax_user_shadow_base) \
19784+ ____x += pax_user_shadow_base; \
19785+ (typeof(x))____x; \
19786+})
19787+#else
19788+#define ____m(x) (x)
19789+#endif
19790+#define __m(x) (*(struct __large_struct __user *)____m(x))
19791
19792 /*
19793 * Tell gcc we read from memory instead of writing: this is because
19794@@ -420,8 +479,10 @@ struct __large_struct { unsigned long buf[100]; };
19795 * aliasing issues.
19796 */
19797 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19798+do { \
19799+ pax_open_userland(); \
19800 asm volatile(ASM_STAC "\n" \
19801- "1: mov"itype" %"rtype"1,%2\n" \
19802+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19803 "2: " ASM_CLAC "\n" \
19804 ".section .fixup,\"ax\"\n" \
19805 "3: mov %3,%0\n" \
19806@@ -429,10 +490,12 @@ struct __large_struct { unsigned long buf[100]; };
19807 ".previous\n" \
19808 _ASM_EXTABLE(1b, 3b) \
19809 : "=r"(err) \
19810- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19811+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19812+ pax_close_userland(); \
19813+} while (0)
19814
19815 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19816- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19817+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19818 "2:\n" \
19819 _ASM_EXTABLE_EX(1b, 2b) \
19820 : : ltype(x), "m" (__m(addr)))
19821@@ -442,11 +505,13 @@ struct __large_struct { unsigned long buf[100]; };
19822 */
19823 #define uaccess_try do { \
19824 current_thread_info()->uaccess_err = 0; \
19825+ pax_open_userland(); \
19826 stac(); \
19827 barrier();
19828
19829 #define uaccess_catch(err) \
19830 clac(); \
19831+ pax_close_userland(); \
19832 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19833 } while (0)
19834
19835@@ -471,8 +536,12 @@ struct __large_struct { unsigned long buf[100]; };
19836 * On error, the variable @x is set to zero.
19837 */
19838
19839+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19840+#define __get_user(x, ptr) get_user((x), (ptr))
19841+#else
19842 #define __get_user(x, ptr) \
19843 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19844+#endif
19845
19846 /**
19847 * __put_user: - Write a simple value into user space, with less checking.
19848@@ -494,8 +563,12 @@ struct __large_struct { unsigned long buf[100]; };
19849 * Returns zero on success, or -EFAULT on error.
19850 */
19851
19852+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19853+#define __put_user(x, ptr) put_user((x), (ptr))
19854+#else
19855 #define __put_user(x, ptr) \
19856 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19857+#endif
19858
19859 #define __get_user_unaligned __get_user
19860 #define __put_user_unaligned __put_user
19861@@ -513,7 +586,7 @@ struct __large_struct { unsigned long buf[100]; };
19862 #define get_user_ex(x, ptr) do { \
19863 unsigned long __gue_val; \
19864 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19865- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19866+ (x) = (__typeof__(*(ptr)))__gue_val; \
19867 } while (0)
19868
19869 #define put_user_try uaccess_try
19870@@ -542,18 +615,19 @@ extern void __cmpxchg_wrong_size(void)
19871 __typeof__(ptr) __uval = (uval); \
19872 __typeof__(*(ptr)) __old = (old); \
19873 __typeof__(*(ptr)) __new = (new); \
19874+ pax_open_userland(); \
19875 switch (size) { \
19876 case 1: \
19877 { \
19878 asm volatile("\t" ASM_STAC "\n" \
19879- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19880+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19881 "2:\t" ASM_CLAC "\n" \
19882 "\t.section .fixup, \"ax\"\n" \
19883 "3:\tmov %3, %0\n" \
19884 "\tjmp 2b\n" \
19885 "\t.previous\n" \
19886 _ASM_EXTABLE(1b, 3b) \
19887- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19888+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19889 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19890 : "memory" \
19891 ); \
19892@@ -562,14 +636,14 @@ extern void __cmpxchg_wrong_size(void)
19893 case 2: \
19894 { \
19895 asm volatile("\t" ASM_STAC "\n" \
19896- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19897+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19898 "2:\t" ASM_CLAC "\n" \
19899 "\t.section .fixup, \"ax\"\n" \
19900 "3:\tmov %3, %0\n" \
19901 "\tjmp 2b\n" \
19902 "\t.previous\n" \
19903 _ASM_EXTABLE(1b, 3b) \
19904- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19905+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19906 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19907 : "memory" \
19908 ); \
19909@@ -578,14 +652,14 @@ extern void __cmpxchg_wrong_size(void)
19910 case 4: \
19911 { \
19912 asm volatile("\t" ASM_STAC "\n" \
19913- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19914+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19915 "2:\t" ASM_CLAC "\n" \
19916 "\t.section .fixup, \"ax\"\n" \
19917 "3:\tmov %3, %0\n" \
19918 "\tjmp 2b\n" \
19919 "\t.previous\n" \
19920 _ASM_EXTABLE(1b, 3b) \
19921- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19922+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19923 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19924 : "memory" \
19925 ); \
19926@@ -597,14 +671,14 @@ extern void __cmpxchg_wrong_size(void)
19927 __cmpxchg_wrong_size(); \
19928 \
19929 asm volatile("\t" ASM_STAC "\n" \
19930- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19931+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19932 "2:\t" ASM_CLAC "\n" \
19933 "\t.section .fixup, \"ax\"\n" \
19934 "3:\tmov %3, %0\n" \
19935 "\tjmp 2b\n" \
19936 "\t.previous\n" \
19937 _ASM_EXTABLE(1b, 3b) \
19938- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19939+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19940 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19941 : "memory" \
19942 ); \
19943@@ -613,6 +687,7 @@ extern void __cmpxchg_wrong_size(void)
19944 default: \
19945 __cmpxchg_wrong_size(); \
19946 } \
19947+ pax_close_userland(); \
19948 *__uval = __old; \
19949 __ret; \
19950 })
19951@@ -636,17 +711,6 @@ extern struct movsl_mask {
19952
19953 #define ARCH_HAS_NOCACHE_UACCESS 1
19954
19955-#ifdef CONFIG_X86_32
19956-# include <asm/uaccess_32.h>
19957-#else
19958-# include <asm/uaccess_64.h>
19959-#endif
19960-
19961-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19962- unsigned n);
19963-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19964- unsigned n);
19965-
19966 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19967 # define copy_user_diag __compiletime_error
19968 #else
19969@@ -656,7 +720,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19970 extern void copy_user_diag("copy_from_user() buffer size is too small")
19971 copy_from_user_overflow(void);
19972 extern void copy_user_diag("copy_to_user() buffer size is too small")
19973-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19974+copy_to_user_overflow(void);
19975
19976 #undef copy_user_diag
19977
19978@@ -669,7 +733,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19979
19980 extern void
19981 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19982-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19983+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19984 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19985
19986 #else
19987@@ -684,10 +748,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19988
19989 #endif
19990
19991+#ifdef CONFIG_X86_32
19992+# include <asm/uaccess_32.h>
19993+#else
19994+# include <asm/uaccess_64.h>
19995+#endif
19996+
19997 static inline unsigned long __must_check
19998 copy_from_user(void *to, const void __user *from, unsigned long n)
19999 {
20000- int sz = __compiletime_object_size(to);
20001+ size_t sz = __compiletime_object_size(to);
20002
20003 might_fault();
20004
20005@@ -709,12 +779,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20006 * case, and do only runtime checking for non-constant sizes.
20007 */
20008
20009- if (likely(sz < 0 || sz >= n))
20010- n = _copy_from_user(to, from, n);
20011- else if(__builtin_constant_p(n))
20012- copy_from_user_overflow();
20013- else
20014- __copy_from_user_overflow(sz, n);
20015+ if (likely(sz != (size_t)-1 && sz < n)) {
20016+ if(__builtin_constant_p(n))
20017+ copy_from_user_overflow();
20018+ else
20019+ __copy_from_user_overflow(sz, n);
20020+ } if (access_ok(VERIFY_READ, from, n))
20021+ n = __copy_from_user(to, from, n);
20022+ else if ((long)n > 0)
20023+ memset(to, 0, n);
20024
20025 return n;
20026 }
20027@@ -722,17 +795,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20028 static inline unsigned long __must_check
20029 copy_to_user(void __user *to, const void *from, unsigned long n)
20030 {
20031- int sz = __compiletime_object_size(from);
20032+ size_t sz = __compiletime_object_size(from);
20033
20034 might_fault();
20035
20036 /* See the comment in copy_from_user() above. */
20037- if (likely(sz < 0 || sz >= n))
20038- n = _copy_to_user(to, from, n);
20039- else if(__builtin_constant_p(n))
20040- copy_to_user_overflow();
20041- else
20042- __copy_to_user_overflow(sz, n);
20043+ if (likely(sz != (size_t)-1 && sz < n)) {
20044+ if(__builtin_constant_p(n))
20045+ copy_to_user_overflow();
20046+ else
20047+ __copy_to_user_overflow(sz, n);
20048+ } else if (access_ok(VERIFY_WRITE, to, n))
20049+ n = __copy_to_user(to, from, n);
20050
20051 return n;
20052 }
20053diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20054index 3c03a5d..1071638 100644
20055--- a/arch/x86/include/asm/uaccess_32.h
20056+++ b/arch/x86/include/asm/uaccess_32.h
20057@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20058 static __always_inline unsigned long __must_check
20059 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20060 {
20061+ if ((long)n < 0)
20062+ return n;
20063+
20064+ check_object_size(from, n, true);
20065+
20066 if (__builtin_constant_p(n)) {
20067 unsigned long ret;
20068
20069@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20070 __copy_to_user(void __user *to, const void *from, unsigned long n)
20071 {
20072 might_fault();
20073+
20074 return __copy_to_user_inatomic(to, from, n);
20075 }
20076
20077 static __always_inline unsigned long
20078 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20079 {
20080+ if ((long)n < 0)
20081+ return n;
20082+
20083 /* Avoid zeroing the tail if the copy fails..
20084 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20085 * but as the zeroing behaviour is only significant when n is not
20086@@ -137,6 +146,12 @@ static __always_inline unsigned long
20087 __copy_from_user(void *to, const void __user *from, unsigned long n)
20088 {
20089 might_fault();
20090+
20091+ if ((long)n < 0)
20092+ return n;
20093+
20094+ check_object_size(to, n, false);
20095+
20096 if (__builtin_constant_p(n)) {
20097 unsigned long ret;
20098
20099@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20100 const void __user *from, unsigned long n)
20101 {
20102 might_fault();
20103+
20104+ if ((long)n < 0)
20105+ return n;
20106+
20107 if (__builtin_constant_p(n)) {
20108 unsigned long ret;
20109
20110@@ -181,7 +200,10 @@ static __always_inline unsigned long
20111 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20112 unsigned long n)
20113 {
20114- return __copy_from_user_ll_nocache_nozero(to, from, n);
20115+ if ((long)n < 0)
20116+ return n;
20117+
20118+ return __copy_from_user_ll_nocache_nozero(to, from, n);
20119 }
20120
20121 #endif /* _ASM_X86_UACCESS_32_H */
20122diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20123index 12a26b9..206c200 100644
20124--- a/arch/x86/include/asm/uaccess_64.h
20125+++ b/arch/x86/include/asm/uaccess_64.h
20126@@ -10,6 +10,9 @@
20127 #include <asm/alternative.h>
20128 #include <asm/cpufeature.h>
20129 #include <asm/page.h>
20130+#include <asm/pgtable.h>
20131+
20132+#define set_fs(x) (current_thread_info()->addr_limit = (x))
20133
20134 /*
20135 * Copy To/From Userspace
20136@@ -17,14 +20,14 @@
20137
20138 /* Handles exceptions in both to and from, but doesn't do access_ok */
20139 __must_check unsigned long
20140-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20141+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20142 __must_check unsigned long
20143-copy_user_generic_string(void *to, const void *from, unsigned len);
20144+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20145 __must_check unsigned long
20146-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20147+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20148
20149 static __always_inline __must_check unsigned long
20150-copy_user_generic(void *to, const void *from, unsigned len)
20151+copy_user_generic(void *to, const void *from, unsigned long len)
20152 {
20153 unsigned ret;
20154
20155@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20156 }
20157
20158 __must_check unsigned long
20159-copy_in_user(void __user *to, const void __user *from, unsigned len);
20160+copy_in_user(void __user *to, const void __user *from, unsigned long len);
20161
20162 static __always_inline __must_check
20163-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20164+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20165 {
20166- int ret = 0;
20167+ size_t sz = __compiletime_object_size(dst);
20168+ unsigned ret = 0;
20169+
20170+ if (size > INT_MAX)
20171+ return size;
20172+
20173+ check_object_size(dst, size, false);
20174+
20175+#ifdef CONFIG_PAX_MEMORY_UDEREF
20176+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20177+ return size;
20178+#endif
20179+
20180+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20181+ if(__builtin_constant_p(size))
20182+ copy_from_user_overflow();
20183+ else
20184+ __copy_from_user_overflow(sz, size);
20185+ return size;
20186+ }
20187
20188 if (!__builtin_constant_p(size))
20189- return copy_user_generic(dst, (__force void *)src, size);
20190+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20191 switch (size) {
20192- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20193+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20194 ret, "b", "b", "=q", 1);
20195 return ret;
20196- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20197+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20198 ret, "w", "w", "=r", 2);
20199 return ret;
20200- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20201+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20202 ret, "l", "k", "=r", 4);
20203 return ret;
20204- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20205+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20206 ret, "q", "", "=r", 8);
20207 return ret;
20208 case 10:
20209- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20210+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20211 ret, "q", "", "=r", 10);
20212 if (unlikely(ret))
20213 return ret;
20214 __get_user_asm(*(u16 *)(8 + (char *)dst),
20215- (u16 __user *)(8 + (char __user *)src),
20216+ (const u16 __user *)(8 + (const char __user *)src),
20217 ret, "w", "w", "=r", 2);
20218 return ret;
20219 case 16:
20220- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20221+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20222 ret, "q", "", "=r", 16);
20223 if (unlikely(ret))
20224 return ret;
20225 __get_user_asm(*(u64 *)(8 + (char *)dst),
20226- (u64 __user *)(8 + (char __user *)src),
20227+ (const u64 __user *)(8 + (const char __user *)src),
20228 ret, "q", "", "=r", 8);
20229 return ret;
20230 default:
20231- return copy_user_generic(dst, (__force void *)src, size);
20232+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20233 }
20234 }
20235
20236 static __always_inline __must_check
20237-int __copy_from_user(void *dst, const void __user *src, unsigned size)
20238+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20239 {
20240 might_fault();
20241 return __copy_from_user_nocheck(dst, src, size);
20242 }
20243
20244 static __always_inline __must_check
20245-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20246+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20247 {
20248- int ret = 0;
20249+ size_t sz = __compiletime_object_size(src);
20250+ unsigned ret = 0;
20251+
20252+ if (size > INT_MAX)
20253+ return size;
20254+
20255+ check_object_size(src, size, true);
20256+
20257+#ifdef CONFIG_PAX_MEMORY_UDEREF
20258+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20259+ return size;
20260+#endif
20261+
20262+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20263+ if(__builtin_constant_p(size))
20264+ copy_to_user_overflow();
20265+ else
20266+ __copy_to_user_overflow(sz, size);
20267+ return size;
20268+ }
20269
20270 if (!__builtin_constant_p(size))
20271- return copy_user_generic((__force void *)dst, src, size);
20272+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20273 switch (size) {
20274- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20275+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20276 ret, "b", "b", "iq", 1);
20277 return ret;
20278- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20279+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20280 ret, "w", "w", "ir", 2);
20281 return ret;
20282- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20283+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20284 ret, "l", "k", "ir", 4);
20285 return ret;
20286- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20287+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20288 ret, "q", "", "er", 8);
20289 return ret;
20290 case 10:
20291- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20292+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20293 ret, "q", "", "er", 10);
20294 if (unlikely(ret))
20295 return ret;
20296 asm("":::"memory");
20297- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20298+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20299 ret, "w", "w", "ir", 2);
20300 return ret;
20301 case 16:
20302- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20303+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20304 ret, "q", "", "er", 16);
20305 if (unlikely(ret))
20306 return ret;
20307 asm("":::"memory");
20308- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20309+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20310 ret, "q", "", "er", 8);
20311 return ret;
20312 default:
20313- return copy_user_generic((__force void *)dst, src, size);
20314+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20315 }
20316 }
20317
20318 static __always_inline __must_check
20319-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20320+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20321 {
20322 might_fault();
20323 return __copy_to_user_nocheck(dst, src, size);
20324 }
20325
20326 static __always_inline __must_check
20327-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20328+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20329 {
20330- int ret = 0;
20331+ unsigned ret = 0;
20332
20333 might_fault();
20334+
20335+ if (size > INT_MAX)
20336+ return size;
20337+
20338+#ifdef CONFIG_PAX_MEMORY_UDEREF
20339+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20340+ return size;
20341+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20342+ return size;
20343+#endif
20344+
20345 if (!__builtin_constant_p(size))
20346- return copy_user_generic((__force void *)dst,
20347- (__force void *)src, size);
20348+ return copy_user_generic((__force_kernel void *)____m(dst),
20349+ (__force_kernel const void *)____m(src), size);
20350 switch (size) {
20351 case 1: {
20352 u8 tmp;
20353- __get_user_asm(tmp, (u8 __user *)src,
20354+ __get_user_asm(tmp, (const u8 __user *)src,
20355 ret, "b", "b", "=q", 1);
20356 if (likely(!ret))
20357 __put_user_asm(tmp, (u8 __user *)dst,
20358@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20359 }
20360 case 2: {
20361 u16 tmp;
20362- __get_user_asm(tmp, (u16 __user *)src,
20363+ __get_user_asm(tmp, (const u16 __user *)src,
20364 ret, "w", "w", "=r", 2);
20365 if (likely(!ret))
20366 __put_user_asm(tmp, (u16 __user *)dst,
20367@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20368
20369 case 4: {
20370 u32 tmp;
20371- __get_user_asm(tmp, (u32 __user *)src,
20372+ __get_user_asm(tmp, (const u32 __user *)src,
20373 ret, "l", "k", "=r", 4);
20374 if (likely(!ret))
20375 __put_user_asm(tmp, (u32 __user *)dst,
20376@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20377 }
20378 case 8: {
20379 u64 tmp;
20380- __get_user_asm(tmp, (u64 __user *)src,
20381+ __get_user_asm(tmp, (const u64 __user *)src,
20382 ret, "q", "", "=r", 8);
20383 if (likely(!ret))
20384 __put_user_asm(tmp, (u64 __user *)dst,
20385@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20386 return ret;
20387 }
20388 default:
20389- return copy_user_generic((__force void *)dst,
20390- (__force void *)src, size);
20391+ return copy_user_generic((__force_kernel void *)____m(dst),
20392+ (__force_kernel const void *)____m(src), size);
20393 }
20394 }
20395
20396-static __must_check __always_inline int
20397-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20398+static __must_check __always_inline unsigned long
20399+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20400 {
20401 return __copy_from_user_nocheck(dst, src, size);
20402 }
20403
20404-static __must_check __always_inline int
20405-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20406+static __must_check __always_inline unsigned long
20407+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20408 {
20409 return __copy_to_user_nocheck(dst, src, size);
20410 }
20411
20412-extern long __copy_user_nocache(void *dst, const void __user *src,
20413- unsigned size, int zerorest);
20414+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20415+ unsigned long size, int zerorest);
20416
20417-static inline int
20418-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20419+static inline unsigned long
20420+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20421 {
20422 might_fault();
20423+
20424+ if (size > INT_MAX)
20425+ return size;
20426+
20427+#ifdef CONFIG_PAX_MEMORY_UDEREF
20428+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20429+ return size;
20430+#endif
20431+
20432 return __copy_user_nocache(dst, src, size, 1);
20433 }
20434
20435-static inline int
20436+static inline unsigned long
20437 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20438- unsigned size)
20439+ unsigned long size)
20440 {
20441+ if (size > INT_MAX)
20442+ return size;
20443+
20444+#ifdef CONFIG_PAX_MEMORY_UDEREF
20445+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20446+ return size;
20447+#endif
20448+
20449 return __copy_user_nocache(dst, src, size, 0);
20450 }
20451
20452 unsigned long
20453-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20454+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20455
20456 #endif /* _ASM_X86_UACCESS_64_H */
20457diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20458index 5b238981..77fdd78 100644
20459--- a/arch/x86/include/asm/word-at-a-time.h
20460+++ b/arch/x86/include/asm/word-at-a-time.h
20461@@ -11,7 +11,7 @@
20462 * and shift, for example.
20463 */
20464 struct word_at_a_time {
20465- const unsigned long one_bits, high_bits;
20466+ unsigned long one_bits, high_bits;
20467 };
20468
20469 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20470diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20471index e45e4da..44e8572 100644
20472--- a/arch/x86/include/asm/x86_init.h
20473+++ b/arch/x86/include/asm/x86_init.h
20474@@ -129,7 +129,7 @@ struct x86_init_ops {
20475 struct x86_init_timers timers;
20476 struct x86_init_iommu iommu;
20477 struct x86_init_pci pci;
20478-};
20479+} __no_const;
20480
20481 /**
20482 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20483@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20484 void (*setup_percpu_clockev)(void);
20485 void (*early_percpu_clock_init)(void);
20486 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20487-};
20488+} __no_const;
20489
20490 struct timespec;
20491
20492@@ -168,7 +168,7 @@ struct x86_platform_ops {
20493 void (*save_sched_clock_state)(void);
20494 void (*restore_sched_clock_state)(void);
20495 void (*apic_post_init)(void);
20496-};
20497+} __no_const;
20498
20499 struct pci_dev;
20500 struct msi_msg;
20501@@ -185,7 +185,7 @@ struct x86_msi_ops {
20502 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20503 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20504 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20505-};
20506+} __no_const;
20507
20508 struct IO_APIC_route_entry;
20509 struct io_apic_irq_attr;
20510@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20511 unsigned int destination, int vector,
20512 struct io_apic_irq_attr *attr);
20513 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20514-};
20515+} __no_const;
20516
20517 extern struct x86_init_ops x86_init;
20518 extern struct x86_cpuinit_ops x86_cpuinit;
20519diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20520index 3e276eb..2eb3c30 100644
20521--- a/arch/x86/include/asm/xen/page.h
20522+++ b/arch/x86/include/asm/xen/page.h
20523@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20524 extern struct page *m2p_find_override(unsigned long mfn);
20525 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20526
20527-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20528+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20529 {
20530 unsigned long mfn;
20531
20532diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20533index 6c1d741..39e6ecf 100644
20534--- a/arch/x86/include/asm/xsave.h
20535+++ b/arch/x86/include/asm/xsave.h
20536@@ -80,8 +80,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20537 if (unlikely(err))
20538 return -EFAULT;
20539
20540+ pax_open_userland();
20541 __asm__ __volatile__(ASM_STAC "\n"
20542- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20543+ "1:"
20544+ __copyuser_seg
20545+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20546 "2: " ASM_CLAC "\n"
20547 ".section .fixup,\"ax\"\n"
20548 "3: movl $-1,%[err]\n"
20549@@ -91,18 +94,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20550 : [err] "=r" (err)
20551 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20552 : "memory");
20553+ pax_close_userland();
20554 return err;
20555 }
20556
20557 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20558 {
20559 int err;
20560- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20561+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20562 u32 lmask = mask;
20563 u32 hmask = mask >> 32;
20564
20565+ pax_open_userland();
20566 __asm__ __volatile__(ASM_STAC "\n"
20567- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20568+ "1:"
20569+ __copyuser_seg
20570+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20571 "2: " ASM_CLAC "\n"
20572 ".section .fixup,\"ax\"\n"
20573 "3: movl $-1,%[err]\n"
20574@@ -112,6 +119,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20575 : [err] "=r" (err)
20576 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20577 : "memory"); /* memory required? */
20578+ pax_close_userland();
20579 return err;
20580 }
20581
20582diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20583index bbae024..e1528f9 100644
20584--- a/arch/x86/include/uapi/asm/e820.h
20585+++ b/arch/x86/include/uapi/asm/e820.h
20586@@ -63,7 +63,7 @@ struct e820map {
20587 #define ISA_START_ADDRESS 0xa0000
20588 #define ISA_END_ADDRESS 0x100000
20589
20590-#define BIOS_BEGIN 0x000a0000
20591+#define BIOS_BEGIN 0x000c0000
20592 #define BIOS_END 0x00100000
20593
20594 #define BIOS_ROM_BASE 0xffe00000
20595diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20596index 7b0a55a..ad115bf 100644
20597--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20598+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20599@@ -49,7 +49,6 @@
20600 #define EFLAGS 144
20601 #define RSP 152
20602 #define SS 160
20603-#define ARGOFFSET R11
20604 #endif /* __ASSEMBLY__ */
20605
20606 /* top of stack page */
20607diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20608index cb648c8..91cb07e 100644
20609--- a/arch/x86/kernel/Makefile
20610+++ b/arch/x86/kernel/Makefile
20611@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20612 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20613 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20614 obj-y += probe_roms.o
20615-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20616+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20617 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20618 obj-y += syscall_$(BITS).o
20619 obj-$(CONFIG_X86_64) += vsyscall_64.o
20620diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20621index 1dac942..19c8b0c 100644
20622--- a/arch/x86/kernel/acpi/boot.c
20623+++ b/arch/x86/kernel/acpi/boot.c
20624@@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20625 * If your system is blacklisted here, but you find that acpi=force
20626 * works for you, please contact linux-acpi@vger.kernel.org
20627 */
20628-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20629+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20630 /*
20631 * Boxes that need ACPI disabled
20632 */
20633@@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20634 };
20635
20636 /* second table for DMI checks that should run after early-quirks */
20637-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20638+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20639 /*
20640 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20641 * which includes some code which overrides all temperature
20642diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20643index 3a2ae4c..9db31d6 100644
20644--- a/arch/x86/kernel/acpi/sleep.c
20645+++ b/arch/x86/kernel/acpi/sleep.c
20646@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20647 #else /* CONFIG_64BIT */
20648 #ifdef CONFIG_SMP
20649 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20650+
20651+ pax_open_kernel();
20652 early_gdt_descr.address =
20653 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20654+ pax_close_kernel();
20655+
20656 initial_gs = per_cpu_offset(smp_processor_id());
20657 #endif
20658 initial_code = (unsigned long)wakeup_long64;
20659diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20660index 665c6b7..eae4d56 100644
20661--- a/arch/x86/kernel/acpi/wakeup_32.S
20662+++ b/arch/x86/kernel/acpi/wakeup_32.S
20663@@ -29,13 +29,11 @@ wakeup_pmode_return:
20664 # and restore the stack ... but you need gdt for this to work
20665 movl saved_context_esp, %esp
20666
20667- movl %cs:saved_magic, %eax
20668- cmpl $0x12345678, %eax
20669+ cmpl $0x12345678, saved_magic
20670 jne bogus_magic
20671
20672 # jump to place where we left off
20673- movl saved_eip, %eax
20674- jmp *%eax
20675+ jmp *(saved_eip)
20676
20677 bogus_magic:
20678 jmp bogus_magic
20679diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20680index df94598..f3b29bf 100644
20681--- a/arch/x86/kernel/alternative.c
20682+++ b/arch/x86/kernel/alternative.c
20683@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20684 */
20685 for (a = start; a < end; a++) {
20686 instr = (u8 *)&a->instr_offset + a->instr_offset;
20687+
20688+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20689+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20690+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20691+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20692+#endif
20693+
20694 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20695 BUG_ON(a->replacementlen > a->instrlen);
20696 BUG_ON(a->instrlen > sizeof(insnbuf));
20697@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20698 for (poff = start; poff < end; poff++) {
20699 u8 *ptr = (u8 *)poff + *poff;
20700
20701+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20702+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20703+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20704+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20705+#endif
20706+
20707 if (!*poff || ptr < text || ptr >= text_end)
20708 continue;
20709 /* turn DS segment override prefix into lock prefix */
20710- if (*ptr == 0x3e)
20711+ if (*ktla_ktva(ptr) == 0x3e)
20712 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20713 }
20714 mutex_unlock(&text_mutex);
20715@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20716 for (poff = start; poff < end; poff++) {
20717 u8 *ptr = (u8 *)poff + *poff;
20718
20719+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20720+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20721+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20722+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20723+#endif
20724+
20725 if (!*poff || ptr < text || ptr >= text_end)
20726 continue;
20727 /* turn lock prefix into DS segment override prefix */
20728- if (*ptr == 0xf0)
20729+ if (*ktla_ktva(ptr) == 0xf0)
20730 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20731 }
20732 mutex_unlock(&text_mutex);
20733@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20734
20735 BUG_ON(p->len > MAX_PATCH_LEN);
20736 /* prep the buffer with the original instructions */
20737- memcpy(insnbuf, p->instr, p->len);
20738+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20739 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20740 (unsigned long)p->instr, p->len);
20741
20742@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20743 if (!uniproc_patched || num_possible_cpus() == 1)
20744 free_init_pages("SMP alternatives",
20745 (unsigned long)__smp_locks,
20746- (unsigned long)__smp_locks_end);
20747+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20748 #endif
20749
20750 apply_paravirt(__parainstructions, __parainstructions_end);
20751@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20752 * instructions. And on the local CPU you need to be protected again NMI or MCE
20753 * handlers seeing an inconsistent instruction while you patch.
20754 */
20755-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20756+void *__kprobes text_poke_early(void *addr, const void *opcode,
20757 size_t len)
20758 {
20759 unsigned long flags;
20760 local_irq_save(flags);
20761- memcpy(addr, opcode, len);
20762+
20763+ pax_open_kernel();
20764+ memcpy(ktla_ktva(addr), opcode, len);
20765 sync_core();
20766+ pax_close_kernel();
20767+
20768 local_irq_restore(flags);
20769 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20770 that causes hangs on some VIA CPUs. */
20771@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20772 */
20773 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20774 {
20775- unsigned long flags;
20776- char *vaddr;
20777+ unsigned char *vaddr = ktla_ktva(addr);
20778 struct page *pages[2];
20779- int i;
20780+ size_t i;
20781
20782 if (!core_kernel_text((unsigned long)addr)) {
20783- pages[0] = vmalloc_to_page(addr);
20784- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20785+ pages[0] = vmalloc_to_page(vaddr);
20786+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20787 } else {
20788- pages[0] = virt_to_page(addr);
20789+ pages[0] = virt_to_page(vaddr);
20790 WARN_ON(!PageReserved(pages[0]));
20791- pages[1] = virt_to_page(addr + PAGE_SIZE);
20792+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20793 }
20794 BUG_ON(!pages[0]);
20795- local_irq_save(flags);
20796- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20797- if (pages[1])
20798- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20799- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20800- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20801- clear_fixmap(FIX_TEXT_POKE0);
20802- if (pages[1])
20803- clear_fixmap(FIX_TEXT_POKE1);
20804- local_flush_tlb();
20805- sync_core();
20806- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20807- that causes hangs on some VIA CPUs. */
20808+ text_poke_early(addr, opcode, len);
20809 for (i = 0; i < len; i++)
20810- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20811- local_irq_restore(flags);
20812+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20813 return addr;
20814 }
20815
20816@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20817 if (likely(!bp_patching_in_progress))
20818 return 0;
20819
20820- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20821+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20822 return 0;
20823
20824 /* set up the specified breakpoint handler */
20825@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20826 */
20827 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20828 {
20829- unsigned char int3 = 0xcc;
20830+ const unsigned char int3 = 0xcc;
20831
20832 bp_int3_handler = handler;
20833 bp_int3_addr = (u8 *)addr + sizeof(int3);
20834diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20835index 7f26c9a..694544e 100644
20836--- a/arch/x86/kernel/apic/apic.c
20837+++ b/arch/x86/kernel/apic/apic.c
20838@@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
20839 /*
20840 * Debug level, exported for io_apic.c
20841 */
20842-unsigned int apic_verbosity;
20843+int apic_verbosity;
20844
20845 int pic_mode;
20846
20847@@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20848 apic_write(APIC_ESR, 0);
20849 v = apic_read(APIC_ESR);
20850 ack_APIC_irq();
20851- atomic_inc(&irq_err_count);
20852+ atomic_inc_unchecked(&irq_err_count);
20853
20854 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20855 smp_processor_id(), v);
20856diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20857index 2c621a6..fa2b1ae 100644
20858--- a/arch/x86/kernel/apic/apic_flat_64.c
20859+++ b/arch/x86/kernel/apic/apic_flat_64.c
20860@@ -154,7 +154,7 @@ static int flat_probe(void)
20861 return 1;
20862 }
20863
20864-static struct apic apic_flat = {
20865+static struct apic apic_flat __read_only = {
20866 .name = "flat",
20867 .probe = flat_probe,
20868 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20869@@ -268,7 +268,7 @@ static int physflat_probe(void)
20870 return 0;
20871 }
20872
20873-static struct apic apic_physflat = {
20874+static struct apic apic_physflat __read_only = {
20875
20876 .name = "physical flat",
20877 .probe = physflat_probe,
20878diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20879index 191ce75..2db6d63 100644
20880--- a/arch/x86/kernel/apic/apic_noop.c
20881+++ b/arch/x86/kernel/apic/apic_noop.c
20882@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20883 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20884 }
20885
20886-struct apic apic_noop = {
20887+struct apic apic_noop __read_only = {
20888 .name = "noop",
20889 .probe = noop_probe,
20890 .acpi_madt_oem_check = NULL,
20891diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20892index d50e364..543bee3 100644
20893--- a/arch/x86/kernel/apic/bigsmp_32.c
20894+++ b/arch/x86/kernel/apic/bigsmp_32.c
20895@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20896 return dmi_bigsmp;
20897 }
20898
20899-static struct apic apic_bigsmp = {
20900+static struct apic apic_bigsmp __read_only = {
20901
20902 .name = "bigsmp",
20903 .probe = probe_bigsmp,
20904diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20905index c552247..587a316 100644
20906--- a/arch/x86/kernel/apic/es7000_32.c
20907+++ b/arch/x86/kernel/apic/es7000_32.c
20908@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20909 return ret && es7000_apic_is_cluster();
20910 }
20911
20912-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20913-static struct apic __refdata apic_es7000_cluster = {
20914+static struct apic apic_es7000_cluster __read_only = {
20915
20916 .name = "es7000",
20917 .probe = probe_es7000,
20918@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20919 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20920 };
20921
20922-static struct apic __refdata apic_es7000 = {
20923+static struct apic apic_es7000 __read_only = {
20924
20925 .name = "es7000",
20926 .probe = probe_es7000,
20927diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20928index 6ad4658..38a7b5c 100644
20929--- a/arch/x86/kernel/apic/io_apic.c
20930+++ b/arch/x86/kernel/apic/io_apic.c
20931@@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20932 }
20933 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20934
20935-void lock_vector_lock(void)
20936+void lock_vector_lock(void) __acquires(vector_lock)
20937 {
20938 /* Used to the online set of cpus does not change
20939 * during assign_irq_vector.
20940@@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20941 raw_spin_lock(&vector_lock);
20942 }
20943
20944-void unlock_vector_lock(void)
20945+void unlock_vector_lock(void) __releases(vector_lock)
20946 {
20947 raw_spin_unlock(&vector_lock);
20948 }
20949@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20950 ack_APIC_irq();
20951 }
20952
20953-atomic_t irq_mis_count;
20954+atomic_unchecked_t irq_mis_count;
20955
20956 #ifdef CONFIG_GENERIC_PENDING_IRQ
20957 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20958@@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20959 * at the cpu.
20960 */
20961 if (!(v & (1 << (i & 0x1f)))) {
20962- atomic_inc(&irq_mis_count);
20963+ atomic_inc_unchecked(&irq_mis_count);
20964
20965 eoi_ioapic_irq(irq, cfg);
20966 }
20967diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20968index 1e42e8f..daacf44 100644
20969--- a/arch/x86/kernel/apic/numaq_32.c
20970+++ b/arch/x86/kernel/apic/numaq_32.c
20971@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20972 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20973 }
20974
20975-/* Use __refdata to keep false positive warning calm. */
20976-static struct apic __refdata apic_numaq = {
20977+static struct apic apic_numaq __read_only = {
20978
20979 .name = "NUMAQ",
20980 .probe = probe_numaq,
20981diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20982index eb35ef9..f184a21 100644
20983--- a/arch/x86/kernel/apic/probe_32.c
20984+++ b/arch/x86/kernel/apic/probe_32.c
20985@@ -72,7 +72,7 @@ static int probe_default(void)
20986 return 1;
20987 }
20988
20989-static struct apic apic_default = {
20990+static struct apic apic_default __read_only = {
20991
20992 .name = "default",
20993 .probe = probe_default,
20994diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20995index 00146f9..5e299b8 100644
20996--- a/arch/x86/kernel/apic/summit_32.c
20997+++ b/arch/x86/kernel/apic/summit_32.c
20998@@ -485,7 +485,7 @@ void setup_summit(void)
20999 }
21000 #endif
21001
21002-static struct apic apic_summit = {
21003+static struct apic apic_summit __read_only = {
21004
21005 .name = "summit",
21006 .probe = probe_summit,
21007diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21008index cac85ee..01fa741 100644
21009--- a/arch/x86/kernel/apic/x2apic_cluster.c
21010+++ b/arch/x86/kernel/apic/x2apic_cluster.c
21011@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21012 return notifier_from_errno(err);
21013 }
21014
21015-static struct notifier_block __refdata x2apic_cpu_notifier = {
21016+static struct notifier_block x2apic_cpu_notifier = {
21017 .notifier_call = update_clusterinfo,
21018 };
21019
21020@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21021 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21022 }
21023
21024-static struct apic apic_x2apic_cluster = {
21025+static struct apic apic_x2apic_cluster __read_only = {
21026
21027 .name = "cluster x2apic",
21028 .probe = x2apic_cluster_probe,
21029diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21030index de231e3..1d1b2ee 100644
21031--- a/arch/x86/kernel/apic/x2apic_phys.c
21032+++ b/arch/x86/kernel/apic/x2apic_phys.c
21033@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21034 return apic == &apic_x2apic_phys;
21035 }
21036
21037-static struct apic apic_x2apic_phys = {
21038+static struct apic apic_x2apic_phys __read_only = {
21039
21040 .name = "physical x2apic",
21041 .probe = x2apic_phys_probe,
21042diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21043index d263b13..963258b 100644
21044--- a/arch/x86/kernel/apic/x2apic_uv_x.c
21045+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21046@@ -350,7 +350,7 @@ static int uv_probe(void)
21047 return apic == &apic_x2apic_uv_x;
21048 }
21049
21050-static struct apic __refdata apic_x2apic_uv_x = {
21051+static struct apic apic_x2apic_uv_x __read_only = {
21052
21053 .name = "UV large system",
21054 .probe = uv_probe,
21055diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21056index 3ab0343..814c4787 100644
21057--- a/arch/x86/kernel/apm_32.c
21058+++ b/arch/x86/kernel/apm_32.c
21059@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21060 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21061 * even though they are called in protected mode.
21062 */
21063-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21064+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21065 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21066
21067 static const char driver_version[] = "1.16ac"; /* no spaces */
21068@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21069 BUG_ON(cpu != 0);
21070 gdt = get_cpu_gdt_table(cpu);
21071 save_desc_40 = gdt[0x40 / 8];
21072+
21073+ pax_open_kernel();
21074 gdt[0x40 / 8] = bad_bios_desc;
21075+ pax_close_kernel();
21076
21077 apm_irq_save(flags);
21078 APM_DO_SAVE_SEGS;
21079@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21080 &call->esi);
21081 APM_DO_RESTORE_SEGS;
21082 apm_irq_restore(flags);
21083+
21084+ pax_open_kernel();
21085 gdt[0x40 / 8] = save_desc_40;
21086+ pax_close_kernel();
21087+
21088 put_cpu();
21089
21090 return call->eax & 0xff;
21091@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21092 BUG_ON(cpu != 0);
21093 gdt = get_cpu_gdt_table(cpu);
21094 save_desc_40 = gdt[0x40 / 8];
21095+
21096+ pax_open_kernel();
21097 gdt[0x40 / 8] = bad_bios_desc;
21098+ pax_close_kernel();
21099
21100 apm_irq_save(flags);
21101 APM_DO_SAVE_SEGS;
21102@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21103 &call->eax);
21104 APM_DO_RESTORE_SEGS;
21105 apm_irq_restore(flags);
21106+
21107+ pax_open_kernel();
21108 gdt[0x40 / 8] = save_desc_40;
21109+ pax_close_kernel();
21110+
21111 put_cpu();
21112 return error;
21113 }
21114@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
21115 * code to that CPU.
21116 */
21117 gdt = get_cpu_gdt_table(0);
21118+
21119+ pax_open_kernel();
21120 set_desc_base(&gdt[APM_CS >> 3],
21121 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21122 set_desc_base(&gdt[APM_CS_16 >> 3],
21123 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21124 set_desc_base(&gdt[APM_DS >> 3],
21125 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21126+ pax_close_kernel();
21127
21128 proc_create("apm", 0, NULL, &apm_file_ops);
21129
21130diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21131index 9f6b934..cf5ffb3 100644
21132--- a/arch/x86/kernel/asm-offsets.c
21133+++ b/arch/x86/kernel/asm-offsets.c
21134@@ -32,6 +32,8 @@ void common(void) {
21135 OFFSET(TI_flags, thread_info, flags);
21136 OFFSET(TI_status, thread_info, status);
21137 OFFSET(TI_addr_limit, thread_info, addr_limit);
21138+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21139+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21140
21141 BLANK();
21142 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21143@@ -52,8 +54,26 @@ void common(void) {
21144 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21145 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21146 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21147+
21148+#ifdef CONFIG_PAX_KERNEXEC
21149+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21150 #endif
21151
21152+#ifdef CONFIG_PAX_MEMORY_UDEREF
21153+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21154+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21155+#ifdef CONFIG_X86_64
21156+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21157+#endif
21158+#endif
21159+
21160+#endif
21161+
21162+ BLANK();
21163+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21164+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21165+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21166+
21167 #ifdef CONFIG_XEN
21168 BLANK();
21169 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21170diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21171index e7c798b..2b2019b 100644
21172--- a/arch/x86/kernel/asm-offsets_64.c
21173+++ b/arch/x86/kernel/asm-offsets_64.c
21174@@ -77,6 +77,7 @@ int main(void)
21175 BLANK();
21176 #undef ENTRY
21177
21178+ DEFINE(TSS_size, sizeof(struct tss_struct));
21179 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21180 BLANK();
21181
21182diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21183index 7fd54f0..0691410 100644
21184--- a/arch/x86/kernel/cpu/Makefile
21185+++ b/arch/x86/kernel/cpu/Makefile
21186@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21187 CFLAGS_REMOVE_perf_event.o = -pg
21188 endif
21189
21190-# Make sure load_percpu_segment has no stackprotector
21191-nostackp := $(call cc-option, -fno-stack-protector)
21192-CFLAGS_common.o := $(nostackp)
21193-
21194 obj-y := intel_cacheinfo.o scattered.o topology.o
21195 obj-y += proc.o capflags.o powerflags.o common.o
21196 obj-y += rdrand.o
21197diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21198index c67ffa6..f41fbbf 100644
21199--- a/arch/x86/kernel/cpu/amd.c
21200+++ b/arch/x86/kernel/cpu/amd.c
21201@@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21202 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21203 {
21204 /* AMD errata T13 (order #21922) */
21205- if ((c->x86 == 6)) {
21206+ if (c->x86 == 6) {
21207 /* Duron Rev A0 */
21208 if (c->x86_model == 3 && c->x86_mask == 0)
21209 size = 64;
21210diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21211index 8e28bf2..bf5c0d2 100644
21212--- a/arch/x86/kernel/cpu/common.c
21213+++ b/arch/x86/kernel/cpu/common.c
21214@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
21215
21216 static const struct cpu_dev *this_cpu = &default_cpu;
21217
21218-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21219-#ifdef CONFIG_X86_64
21220- /*
21221- * We need valid kernel segments for data and code in long mode too
21222- * IRET will check the segment types kkeil 2000/10/28
21223- * Also sysret mandates a special GDT layout
21224- *
21225- * TLS descriptors are currently at a different place compared to i386.
21226- * Hopefully nobody expects them at a fixed place (Wine?)
21227- */
21228- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21229- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21230- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21231- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21232- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21233- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21234-#else
21235- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21236- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21237- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21238- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21239- /*
21240- * Segments used for calling PnP BIOS have byte granularity.
21241- * They code segments and data segments have fixed 64k limits,
21242- * the transfer segment sizes are set at run time.
21243- */
21244- /* 32-bit code */
21245- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21246- /* 16-bit code */
21247- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21248- /* 16-bit data */
21249- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21250- /* 16-bit data */
21251- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21252- /* 16-bit data */
21253- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21254- /*
21255- * The APM segments have byte granularity and their bases
21256- * are set at run time. All have 64k limits.
21257- */
21258- /* 32-bit code */
21259- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21260- /* 16-bit code */
21261- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21262- /* data */
21263- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21264-
21265- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21266- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21267- GDT_STACK_CANARY_INIT
21268-#endif
21269-} };
21270-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21271-
21272 static int __init x86_xsave_setup(char *s)
21273 {
21274 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21275@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21276 }
21277 }
21278
21279+#ifdef CONFIG_X86_64
21280+static __init int setup_disable_pcid(char *arg)
21281+{
21282+ setup_clear_cpu_cap(X86_FEATURE_PCID);
21283+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21284+
21285+#ifdef CONFIG_PAX_MEMORY_UDEREF
21286+ if (clone_pgd_mask != ~(pgdval_t)0UL)
21287+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21288+#endif
21289+
21290+ return 1;
21291+}
21292+__setup("nopcid", setup_disable_pcid);
21293+
21294+static void setup_pcid(struct cpuinfo_x86 *c)
21295+{
21296+ if (!cpu_has(c, X86_FEATURE_PCID)) {
21297+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
21298+
21299+#ifdef CONFIG_PAX_MEMORY_UDEREF
21300+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
21301+ pax_open_kernel();
21302+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21303+ pax_close_kernel();
21304+ printk("PAX: slow and weak UDEREF enabled\n");
21305+ } else
21306+ printk("PAX: UDEREF disabled\n");
21307+#endif
21308+
21309+ return;
21310+ }
21311+
21312+ printk("PAX: PCID detected\n");
21313+ set_in_cr4(X86_CR4_PCIDE);
21314+
21315+#ifdef CONFIG_PAX_MEMORY_UDEREF
21316+ pax_open_kernel();
21317+ clone_pgd_mask = ~(pgdval_t)0UL;
21318+ pax_close_kernel();
21319+ if (pax_user_shadow_base)
21320+ printk("PAX: weak UDEREF enabled\n");
21321+ else {
21322+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21323+ printk("PAX: strong UDEREF enabled\n");
21324+ }
21325+#endif
21326+
21327+ if (cpu_has(c, X86_FEATURE_INVPCID))
21328+ printk("PAX: INVPCID detected\n");
21329+}
21330+#endif
21331+
21332 /*
21333 * Some CPU features depend on higher CPUID levels, which may not always
21334 * be available due to CPUID level capping or broken virtualization
21335@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21336 {
21337 struct desc_ptr gdt_descr;
21338
21339- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21340+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21341 gdt_descr.size = GDT_SIZE - 1;
21342 load_gdt(&gdt_descr);
21343 /* Reload the per-cpu base */
21344@@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21345 setup_smep(c);
21346 setup_smap(c);
21347
21348+#ifdef CONFIG_X86_64
21349+ setup_pcid(c);
21350+#endif
21351+
21352 /*
21353 * The vendor-specific functions might have changed features.
21354 * Now we do "generic changes."
21355@@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21356 /* Filter out anything that depends on CPUID levels we don't have */
21357 filter_cpuid_features(c, true);
21358
21359+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21360+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21361+#endif
21362+
21363 /* If the model name is still unset, do table lookup. */
21364 if (!c->x86_model_id[0]) {
21365 const char *p;
21366@@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
21367 }
21368 __setup("clearcpuid=", setup_disablecpuid);
21369
21370+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21371+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21372+
21373 #ifdef CONFIG_X86_64
21374-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21375-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21376- (unsigned long) debug_idt_table };
21377+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21378+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21379
21380 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21381 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21382@@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
21383 EXPORT_PER_CPU_SYMBOL(current_task);
21384
21385 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21386- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21387+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21388 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21389
21390 DEFINE_PER_CPU(char *, irq_stack_ptr) =
21391@@ -1245,7 +1254,7 @@ void cpu_init(void)
21392 load_ucode_ap();
21393
21394 cpu = stack_smp_processor_id();
21395- t = &per_cpu(init_tss, cpu);
21396+ t = init_tss + cpu;
21397 oist = &per_cpu(orig_ist, cpu);
21398
21399 #ifdef CONFIG_NUMA
21400@@ -1280,7 +1289,6 @@ void cpu_init(void)
21401 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21402 barrier();
21403
21404- x86_configure_nx();
21405 enable_x2apic();
21406
21407 /*
21408@@ -1332,7 +1340,7 @@ void cpu_init(void)
21409 {
21410 int cpu = smp_processor_id();
21411 struct task_struct *curr = current;
21412- struct tss_struct *t = &per_cpu(init_tss, cpu);
21413+ struct tss_struct *t = init_tss + cpu;
21414 struct thread_struct *thread = &curr->thread;
21415
21416 show_ucode_info_early();
21417diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21418index 0641113..06f5ba4 100644
21419--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21420+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21421@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21422 };
21423
21424 #ifdef CONFIG_AMD_NB
21425+static struct attribute *default_attrs_amd_nb[] = {
21426+ &type.attr,
21427+ &level.attr,
21428+ &coherency_line_size.attr,
21429+ &physical_line_partition.attr,
21430+ &ways_of_associativity.attr,
21431+ &number_of_sets.attr,
21432+ &size.attr,
21433+ &shared_cpu_map.attr,
21434+ &shared_cpu_list.attr,
21435+ NULL,
21436+ NULL,
21437+ NULL,
21438+ NULL
21439+};
21440+
21441 static struct attribute **amd_l3_attrs(void)
21442 {
21443 static struct attribute **attrs;
21444@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21445
21446 n = ARRAY_SIZE(default_attrs);
21447
21448- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21449- n += 2;
21450-
21451- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21452- n += 1;
21453-
21454- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21455- if (attrs == NULL)
21456- return attrs = default_attrs;
21457-
21458- for (n = 0; default_attrs[n]; n++)
21459- attrs[n] = default_attrs[n];
21460+ attrs = default_attrs_amd_nb;
21461
21462 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21463 attrs[n++] = &cache_disable_0.attr;
21464@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21465 .default_attrs = default_attrs,
21466 };
21467
21468+#ifdef CONFIG_AMD_NB
21469+static struct kobj_type ktype_cache_amd_nb = {
21470+ .sysfs_ops = &sysfs_ops,
21471+ .default_attrs = default_attrs_amd_nb,
21472+};
21473+#endif
21474+
21475 static struct kobj_type ktype_percpu_entry = {
21476 .sysfs_ops = &sysfs_ops,
21477 };
21478@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21479 return retval;
21480 }
21481
21482+#ifdef CONFIG_AMD_NB
21483+ amd_l3_attrs();
21484+#endif
21485+
21486 for (i = 0; i < num_cache_leaves; i++) {
21487+ struct kobj_type *ktype;
21488+
21489 this_object = INDEX_KOBJECT_PTR(cpu, i);
21490 this_object->cpu = cpu;
21491 this_object->index = i;
21492
21493 this_leaf = CPUID4_INFO_IDX(cpu, i);
21494
21495- ktype_cache.default_attrs = default_attrs;
21496+ ktype = &ktype_cache;
21497 #ifdef CONFIG_AMD_NB
21498 if (this_leaf->base.nb)
21499- ktype_cache.default_attrs = amd_l3_attrs();
21500+ ktype = &ktype_cache_amd_nb;
21501 #endif
21502 retval = kobject_init_and_add(&(this_object->kobj),
21503- &ktype_cache,
21504+ ktype,
21505 per_cpu(ici_cache_kobject, cpu),
21506 "index%1lu", i);
21507 if (unlikely(retval)) {
21508diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21509index 4d5419b..95f11bb 100644
21510--- a/arch/x86/kernel/cpu/mcheck/mce.c
21511+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21512@@ -45,6 +45,7 @@
21513 #include <asm/processor.h>
21514 #include <asm/mce.h>
21515 #include <asm/msr.h>
21516+#include <asm/local.h>
21517
21518 #include "mce-internal.h"
21519
21520@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21521 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21522 m->cs, m->ip);
21523
21524- if (m->cs == __KERNEL_CS)
21525+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21526 print_symbol("{%s}", m->ip);
21527 pr_cont("\n");
21528 }
21529@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21530
21531 #define PANIC_TIMEOUT 5 /* 5 seconds */
21532
21533-static atomic_t mce_paniced;
21534+static atomic_unchecked_t mce_paniced;
21535
21536 static int fake_panic;
21537-static atomic_t mce_fake_paniced;
21538+static atomic_unchecked_t mce_fake_paniced;
21539
21540 /* Panic in progress. Enable interrupts and wait for final IPI */
21541 static void wait_for_panic(void)
21542@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21543 /*
21544 * Make sure only one CPU runs in machine check panic
21545 */
21546- if (atomic_inc_return(&mce_paniced) > 1)
21547+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21548 wait_for_panic();
21549 barrier();
21550
21551@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21552 console_verbose();
21553 } else {
21554 /* Don't log too much for fake panic */
21555- if (atomic_inc_return(&mce_fake_paniced) > 1)
21556+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21557 return;
21558 }
21559 /* First print corrected ones that are still unlogged */
21560@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21561 if (!fake_panic) {
21562 if (panic_timeout == 0)
21563 panic_timeout = mca_cfg.panic_timeout;
21564- panic(msg);
21565+ panic("%s", msg);
21566 } else
21567 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21568 }
21569@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21570 * might have been modified by someone else.
21571 */
21572 rmb();
21573- if (atomic_read(&mce_paniced))
21574+ if (atomic_read_unchecked(&mce_paniced))
21575 wait_for_panic();
21576 if (!mca_cfg.monarch_timeout)
21577 goto out;
21578@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21579 }
21580
21581 /* Call the installed machine check handler for this CPU setup. */
21582-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21583+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21584 unexpected_machine_check;
21585
21586 /*
21587@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21588 return;
21589 }
21590
21591+ pax_open_kernel();
21592 machine_check_vector = do_machine_check;
21593+ pax_close_kernel();
21594
21595 __mcheck_cpu_init_generic();
21596 __mcheck_cpu_init_vendor(c);
21597@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21598 */
21599
21600 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21601-static int mce_chrdev_open_count; /* #times opened */
21602+static local_t mce_chrdev_open_count; /* #times opened */
21603 static int mce_chrdev_open_exclu; /* already open exclusive? */
21604
21605 static int mce_chrdev_open(struct inode *inode, struct file *file)
21606@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21607 spin_lock(&mce_chrdev_state_lock);
21608
21609 if (mce_chrdev_open_exclu ||
21610- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21611+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21612 spin_unlock(&mce_chrdev_state_lock);
21613
21614 return -EBUSY;
21615@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21616
21617 if (file->f_flags & O_EXCL)
21618 mce_chrdev_open_exclu = 1;
21619- mce_chrdev_open_count++;
21620+ local_inc(&mce_chrdev_open_count);
21621
21622 spin_unlock(&mce_chrdev_state_lock);
21623
21624@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21625 {
21626 spin_lock(&mce_chrdev_state_lock);
21627
21628- mce_chrdev_open_count--;
21629+ local_dec(&mce_chrdev_open_count);
21630 mce_chrdev_open_exclu = 0;
21631
21632 spin_unlock(&mce_chrdev_state_lock);
21633@@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
21634
21635 for (i = 0; i < mca_cfg.banks; i++) {
21636 struct mce_bank *b = &mce_banks[i];
21637- struct device_attribute *a = &b->attr;
21638+ device_attribute_no_const *a = &b->attr;
21639
21640 sysfs_attr_init(&a->attr);
21641 a->attr.name = b->attrname;
21642@@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
21643 static void mce_reset(void)
21644 {
21645 cpu_missing = 0;
21646- atomic_set(&mce_fake_paniced, 0);
21647+ atomic_set_unchecked(&mce_fake_paniced, 0);
21648 atomic_set(&mce_executing, 0);
21649 atomic_set(&mce_callin, 0);
21650 atomic_set(&global_nwo, 0);
21651diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21652index a304298..49b6d06 100644
21653--- a/arch/x86/kernel/cpu/mcheck/p5.c
21654+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21655@@ -10,6 +10,7 @@
21656 #include <asm/processor.h>
21657 #include <asm/mce.h>
21658 #include <asm/msr.h>
21659+#include <asm/pgtable.h>
21660
21661 /* By default disabled */
21662 int mce_p5_enabled __read_mostly;
21663@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21664 if (!cpu_has(c, X86_FEATURE_MCE))
21665 return;
21666
21667+ pax_open_kernel();
21668 machine_check_vector = pentium_machine_check;
21669+ pax_close_kernel();
21670 /* Make sure the vector pointer is visible before we enable MCEs: */
21671 wmb();
21672
21673diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21674index 7dc5564..1273569 100644
21675--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21676+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21677@@ -9,6 +9,7 @@
21678 #include <asm/processor.h>
21679 #include <asm/mce.h>
21680 #include <asm/msr.h>
21681+#include <asm/pgtable.h>
21682
21683 /* Machine check handler for WinChip C6: */
21684 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21685@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21686 {
21687 u32 lo, hi;
21688
21689+ pax_open_kernel();
21690 machine_check_vector = winchip_machine_check;
21691+ pax_close_kernel();
21692 /* Make sure the vector pointer is visible before we enable MCEs: */
21693 wmb();
21694
21695diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21696index 15c9876..0a43909 100644
21697--- a/arch/x86/kernel/cpu/microcode/core.c
21698+++ b/arch/x86/kernel/cpu/microcode/core.c
21699@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21700 return NOTIFY_OK;
21701 }
21702
21703-static struct notifier_block __refdata mc_cpu_notifier = {
21704+static struct notifier_block mc_cpu_notifier = {
21705 .notifier_call = mc_cpu_callback,
21706 };
21707
21708diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21709index a276fa7..e66810f 100644
21710--- a/arch/x86/kernel/cpu/microcode/intel.c
21711+++ b/arch/x86/kernel/cpu/microcode/intel.c
21712@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21713
21714 static int get_ucode_user(void *to, const void *from, size_t n)
21715 {
21716- return copy_from_user(to, from, n);
21717+ return copy_from_user(to, (const void __force_user *)from, n);
21718 }
21719
21720 static enum ucode_state
21721 request_microcode_user(int cpu, const void __user *buf, size_t size)
21722 {
21723- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21724+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21725 }
21726
21727 static void microcode_fini_cpu(int cpu)
21728diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21729index f961de9..8a9d332 100644
21730--- a/arch/x86/kernel/cpu/mtrr/main.c
21731+++ b/arch/x86/kernel/cpu/mtrr/main.c
21732@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21733 u64 size_or_mask, size_and_mask;
21734 static bool mtrr_aps_delayed_init;
21735
21736-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21737+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21738
21739 const struct mtrr_ops *mtrr_if;
21740
21741diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21742index df5e41f..816c719 100644
21743--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21744+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21745@@ -25,7 +25,7 @@ struct mtrr_ops {
21746 int (*validate_add_page)(unsigned long base, unsigned long size,
21747 unsigned int type);
21748 int (*have_wrcomb)(void);
21749-};
21750+} __do_const;
21751
21752 extern int generic_get_free_region(unsigned long base, unsigned long size,
21753 int replace_reg);
21754diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21755index 79f9f84..38ace52 100644
21756--- a/arch/x86/kernel/cpu/perf_event.c
21757+++ b/arch/x86/kernel/cpu/perf_event.c
21758@@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21759 pr_info("no hardware sampling interrupt available.\n");
21760 }
21761
21762-static struct attribute_group x86_pmu_format_group = {
21763+static attribute_group_no_const x86_pmu_format_group = {
21764 .name = "format",
21765 .attrs = NULL,
21766 };
21767@@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21768 NULL,
21769 };
21770
21771-static struct attribute_group x86_pmu_events_group = {
21772+static attribute_group_no_const x86_pmu_events_group = {
21773 .name = "events",
21774 .attrs = events_attr,
21775 };
21776@@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
21777 if (idx > GDT_ENTRIES)
21778 return 0;
21779
21780- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21781+ desc = get_cpu_gdt_table(smp_processor_id());
21782 }
21783
21784 return get_desc_base(desc + idx);
21785@@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21786 break;
21787
21788 perf_callchain_store(entry, frame.return_address);
21789- fp = frame.next_frame;
21790+ fp = (const void __force_user *)frame.next_frame;
21791 }
21792 }
21793
21794diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21795index 639d128..e92d7e5 100644
21796--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21797+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21798@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21799 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21800 {
21801 struct attribute **attrs;
21802- struct attribute_group *attr_group;
21803+ attribute_group_no_const *attr_group;
21804 int i = 0, j;
21805
21806 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21807diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21808index aa333d9..f9db700 100644
21809--- a/arch/x86/kernel/cpu/perf_event_intel.c
21810+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21811@@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
21812 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21813
21814 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21815- u64 capabilities;
21816+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21817
21818- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21819- x86_pmu.intel_cap.capabilities = capabilities;
21820+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21821+ x86_pmu.intel_cap.capabilities = capabilities;
21822 }
21823
21824 intel_ds_init();
21825diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21826index 5ad35ad..e0a3960 100644
21827--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21828+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21829@@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
21830 NULL,
21831 };
21832
21833-static struct attribute_group rapl_pmu_events_group = {
21834+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21835 .name = "events",
21836 .attrs = NULL, /* patched at runtime */
21837 };
21838diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21839index 047f540..afdeba0 100644
21840--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21841+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21842@@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21843 static int __init uncore_type_init(struct intel_uncore_type *type)
21844 {
21845 struct intel_uncore_pmu *pmus;
21846- struct attribute_group *attr_group;
21847+ attribute_group_no_const *attr_group;
21848 struct attribute **attrs;
21849 int i, j;
21850
21851diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21852index a80ab71..4089da5 100644
21853--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21854+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21855@@ -498,7 +498,7 @@ struct intel_uncore_box {
21856 struct uncore_event_desc {
21857 struct kobj_attribute attr;
21858 const char *config;
21859-};
21860+} __do_const;
21861
21862 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21863 { \
21864diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21865index 7d9481c..99c7e4b 100644
21866--- a/arch/x86/kernel/cpuid.c
21867+++ b/arch/x86/kernel/cpuid.c
21868@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21869 return notifier_from_errno(err);
21870 }
21871
21872-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21873+static struct notifier_block cpuid_class_cpu_notifier =
21874 {
21875 .notifier_call = cpuid_class_cpu_callback,
21876 };
21877diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21878index a57902e..ebaae2a 100644
21879--- a/arch/x86/kernel/crash.c
21880+++ b/arch/x86/kernel/crash.c
21881@@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21882 {
21883 #ifdef CONFIG_X86_32
21884 struct pt_regs fixed_regs;
21885-#endif
21886
21887-#ifdef CONFIG_X86_32
21888- if (!user_mode_vm(regs)) {
21889+ if (!user_mode(regs)) {
21890 crash_fixup_ss_esp(&fixed_regs, regs);
21891 regs = &fixed_regs;
21892 }
21893diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21894index afa64ad..dce67dd 100644
21895--- a/arch/x86/kernel/crash_dump_64.c
21896+++ b/arch/x86/kernel/crash_dump_64.c
21897@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21898 return -ENOMEM;
21899
21900 if (userbuf) {
21901- if (copy_to_user(buf, vaddr + offset, csize)) {
21902+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21903 iounmap(vaddr);
21904 return -EFAULT;
21905 }
21906diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21907index f6dfd93..892ade4 100644
21908--- a/arch/x86/kernel/doublefault.c
21909+++ b/arch/x86/kernel/doublefault.c
21910@@ -12,7 +12,7 @@
21911
21912 #define DOUBLEFAULT_STACKSIZE (1024)
21913 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21914-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21915+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21916
21917 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21918
21919@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21920 unsigned long gdt, tss;
21921
21922 native_store_gdt(&gdt_desc);
21923- gdt = gdt_desc.address;
21924+ gdt = (unsigned long)gdt_desc.address;
21925
21926 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21927
21928@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21929 /* 0x2 bit is always set */
21930 .flags = X86_EFLAGS_SF | 0x2,
21931 .sp = STACK_START,
21932- .es = __USER_DS,
21933+ .es = __KERNEL_DS,
21934 .cs = __KERNEL_CS,
21935 .ss = __KERNEL_DS,
21936- .ds = __USER_DS,
21937+ .ds = __KERNEL_DS,
21938 .fs = __KERNEL_PERCPU,
21939
21940 .__cr3 = __pa_nodebug(swapper_pg_dir),
21941diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21942index d9c12d3..7858b62 100644
21943--- a/arch/x86/kernel/dumpstack.c
21944+++ b/arch/x86/kernel/dumpstack.c
21945@@ -2,6 +2,9 @@
21946 * Copyright (C) 1991, 1992 Linus Torvalds
21947 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21948 */
21949+#ifdef CONFIG_GRKERNSEC_HIDESYM
21950+#define __INCLUDED_BY_HIDESYM 1
21951+#endif
21952 #include <linux/kallsyms.h>
21953 #include <linux/kprobes.h>
21954 #include <linux/uaccess.h>
21955@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21956 static void
21957 print_ftrace_graph_addr(unsigned long addr, void *data,
21958 const struct stacktrace_ops *ops,
21959- struct thread_info *tinfo, int *graph)
21960+ struct task_struct *task, int *graph)
21961 {
21962- struct task_struct *task;
21963 unsigned long ret_addr;
21964 int index;
21965
21966 if (addr != (unsigned long)return_to_handler)
21967 return;
21968
21969- task = tinfo->task;
21970 index = task->curr_ret_stack;
21971
21972 if (!task->ret_stack || index < *graph)
21973@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21974 static inline void
21975 print_ftrace_graph_addr(unsigned long addr, void *data,
21976 const struct stacktrace_ops *ops,
21977- struct thread_info *tinfo, int *graph)
21978+ struct task_struct *task, int *graph)
21979 { }
21980 #endif
21981
21982@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21983 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21984 */
21985
21986-static inline int valid_stack_ptr(struct thread_info *tinfo,
21987- void *p, unsigned int size, void *end)
21988+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21989 {
21990- void *t = tinfo;
21991 if (end) {
21992 if (p < end && p >= (end-THREAD_SIZE))
21993 return 1;
21994@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21995 }
21996
21997 unsigned long
21998-print_context_stack(struct thread_info *tinfo,
21999+print_context_stack(struct task_struct *task, void *stack_start,
22000 unsigned long *stack, unsigned long bp,
22001 const struct stacktrace_ops *ops, void *data,
22002 unsigned long *end, int *graph)
22003 {
22004 struct stack_frame *frame = (struct stack_frame *)bp;
22005
22006- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22007+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22008 unsigned long addr;
22009
22010 addr = *stack;
22011@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22012 } else {
22013 ops->address(data, addr, 0);
22014 }
22015- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22016+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22017 }
22018 stack++;
22019 }
22020@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22021 EXPORT_SYMBOL_GPL(print_context_stack);
22022
22023 unsigned long
22024-print_context_stack_bp(struct thread_info *tinfo,
22025+print_context_stack_bp(struct task_struct *task, void *stack_start,
22026 unsigned long *stack, unsigned long bp,
22027 const struct stacktrace_ops *ops, void *data,
22028 unsigned long *end, int *graph)
22029@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22030 struct stack_frame *frame = (struct stack_frame *)bp;
22031 unsigned long *ret_addr = &frame->return_address;
22032
22033- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22034+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22035 unsigned long addr = *ret_addr;
22036
22037 if (!__kernel_text_address(addr))
22038@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22039 ops->address(data, addr, 1);
22040 frame = frame->next_frame;
22041 ret_addr = &frame->return_address;
22042- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22043+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22044 }
22045
22046 return (unsigned long)frame;
22047@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22048 static void print_trace_address(void *data, unsigned long addr, int reliable)
22049 {
22050 touch_nmi_watchdog();
22051- printk(data);
22052+ printk("%s", (char *)data);
22053 printk_stack_address(addr, reliable);
22054 }
22055
22056@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
22057 }
22058 EXPORT_SYMBOL_GPL(oops_begin);
22059
22060+extern void gr_handle_kernel_exploit(void);
22061+
22062 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22063 {
22064 if (regs && kexec_should_crash(current))
22065@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22066 panic("Fatal exception in interrupt");
22067 if (panic_on_oops)
22068 panic("Fatal exception");
22069- do_exit(signr);
22070+
22071+ gr_handle_kernel_exploit();
22072+
22073+ do_group_exit(signr);
22074 }
22075
22076 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
22077@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
22078 print_modules();
22079 show_regs(regs);
22080 #ifdef CONFIG_X86_32
22081- if (user_mode_vm(regs)) {
22082+ if (user_mode(regs)) {
22083 sp = regs->sp;
22084 ss = regs->ss & 0xffff;
22085 } else {
22086@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22087 unsigned long flags = oops_begin();
22088 int sig = SIGSEGV;
22089
22090- if (!user_mode_vm(regs))
22091+ if (!user_mode(regs))
22092 report_bug(regs->ip, regs);
22093
22094 if (__die(str, regs, err))
22095diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22096index f2a1770..10fa52d 100644
22097--- a/arch/x86/kernel/dumpstack_32.c
22098+++ b/arch/x86/kernel/dumpstack_32.c
22099@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22100 bp = stack_frame(task, regs);
22101
22102 for (;;) {
22103- struct thread_info *context;
22104+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22105
22106- context = (struct thread_info *)
22107- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
22108- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
22109+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22110
22111- stack = (unsigned long *)context->previous_esp;
22112- if (!stack)
22113+ if (stack_start == task_stack_page(task))
22114 break;
22115+ stack = *(unsigned long **)stack_start;
22116 if (ops->stack(data, "IRQ") < 0)
22117 break;
22118 touch_nmi_watchdog();
22119@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
22120 int i;
22121
22122 show_regs_print_info(KERN_EMERG);
22123- __show_regs(regs, !user_mode_vm(regs));
22124+ __show_regs(regs, !user_mode(regs));
22125
22126 /*
22127 * When in-kernel, we also print out the stack and code at the
22128 * time of the fault..
22129 */
22130- if (!user_mode_vm(regs)) {
22131+ if (!user_mode(regs)) {
22132 unsigned int code_prologue = code_bytes * 43 / 64;
22133 unsigned int code_len = code_bytes;
22134 unsigned char c;
22135 u8 *ip;
22136+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22137
22138 pr_emerg("Stack:\n");
22139 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22140
22141 pr_emerg("Code:");
22142
22143- ip = (u8 *)regs->ip - code_prologue;
22144+ ip = (u8 *)regs->ip - code_prologue + cs_base;
22145 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22146 /* try starting at IP */
22147- ip = (u8 *)regs->ip;
22148+ ip = (u8 *)regs->ip + cs_base;
22149 code_len = code_len - code_prologue + 1;
22150 }
22151 for (i = 0; i < code_len; i++, ip++) {
22152@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
22153 pr_cont(" Bad EIP value.");
22154 break;
22155 }
22156- if (ip == (u8 *)regs->ip)
22157+ if (ip == (u8 *)regs->ip + cs_base)
22158 pr_cont(" <%02x>", c);
22159 else
22160 pr_cont(" %02x", c);
22161@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
22162 {
22163 unsigned short ud2;
22164
22165+ ip = ktla_ktva(ip);
22166 if (ip < PAGE_OFFSET)
22167 return 0;
22168 if (probe_kernel_address((unsigned short *)ip, ud2))
22169@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
22170
22171 return ud2 == 0x0b0f;
22172 }
22173+
22174+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22175+void pax_check_alloca(unsigned long size)
22176+{
22177+ unsigned long sp = (unsigned long)&sp, stack_left;
22178+
22179+ /* all kernel stacks are of the same size */
22180+ stack_left = sp & (THREAD_SIZE - 1);
22181+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22182+}
22183+EXPORT_SYMBOL(pax_check_alloca);
22184+#endif
22185diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22186index addb207..921706b 100644
22187--- a/arch/x86/kernel/dumpstack_64.c
22188+++ b/arch/x86/kernel/dumpstack_64.c
22189@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22190 unsigned long *irq_stack_end =
22191 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22192 unsigned used = 0;
22193- struct thread_info *tinfo;
22194 int graph = 0;
22195 unsigned long dummy;
22196+ void *stack_start;
22197
22198 if (!task)
22199 task = current;
22200@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22201 * current stack address. If the stacks consist of nested
22202 * exceptions
22203 */
22204- tinfo = task_thread_info(task);
22205 for (;;) {
22206 char *id;
22207 unsigned long *estack_end;
22208+
22209 estack_end = in_exception_stack(cpu, (unsigned long)stack,
22210 &used, &id);
22211
22212@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22213 if (ops->stack(data, id) < 0)
22214 break;
22215
22216- bp = ops->walk_stack(tinfo, stack, bp, ops,
22217+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
22218 data, estack_end, &graph);
22219 ops->stack(data, "<EOE>");
22220 /*
22221@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22222 * second-to-last pointer (index -2 to end) in the
22223 * exception stack:
22224 */
22225+ if ((u16)estack_end[-1] != __KERNEL_DS)
22226+ goto out;
22227 stack = (unsigned long *) estack_end[-2];
22228 continue;
22229 }
22230@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22231 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
22232 if (ops->stack(data, "IRQ") < 0)
22233 break;
22234- bp = ops->walk_stack(tinfo, stack, bp,
22235+ bp = ops->walk_stack(task, irq_stack, stack, bp,
22236 ops, data, irq_stack_end, &graph);
22237 /*
22238 * We link to the next stack (which would be
22239@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22240 /*
22241 * This handles the process stack:
22242 */
22243- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22244+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22245+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22246+out:
22247 put_cpu();
22248 }
22249 EXPORT_SYMBOL(dump_trace);
22250@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
22251
22252 return ud2 == 0x0b0f;
22253 }
22254+
22255+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22256+void pax_check_alloca(unsigned long size)
22257+{
22258+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22259+ unsigned cpu, used;
22260+ char *id;
22261+
22262+ /* check the process stack first */
22263+ stack_start = (unsigned long)task_stack_page(current);
22264+ stack_end = stack_start + THREAD_SIZE;
22265+ if (likely(stack_start <= sp && sp < stack_end)) {
22266+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
22267+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22268+ return;
22269+ }
22270+
22271+ cpu = get_cpu();
22272+
22273+ /* check the irq stacks */
22274+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22275+ stack_start = stack_end - IRQ_STACK_SIZE;
22276+ if (stack_start <= sp && sp < stack_end) {
22277+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22278+ put_cpu();
22279+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22280+ return;
22281+ }
22282+
22283+ /* check the exception stacks */
22284+ used = 0;
22285+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22286+ stack_start = stack_end - EXCEPTION_STKSZ;
22287+ if (stack_end && stack_start <= sp && sp < stack_end) {
22288+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22289+ put_cpu();
22290+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22291+ return;
22292+ }
22293+
22294+ put_cpu();
22295+
22296+ /* unknown stack */
22297+ BUG();
22298+}
22299+EXPORT_SYMBOL(pax_check_alloca);
22300+#endif
22301diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22302index 988c00a..4f673b6 100644
22303--- a/arch/x86/kernel/e820.c
22304+++ b/arch/x86/kernel/e820.c
22305@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22306
22307 static void early_panic(char *msg)
22308 {
22309- early_printk(msg);
22310- panic(msg);
22311+ early_printk("%s", msg);
22312+ panic("%s", msg);
22313 }
22314
22315 static int userdef __initdata;
22316diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22317index 01d1c18..8073693 100644
22318--- a/arch/x86/kernel/early_printk.c
22319+++ b/arch/x86/kernel/early_printk.c
22320@@ -7,6 +7,7 @@
22321 #include <linux/pci_regs.h>
22322 #include <linux/pci_ids.h>
22323 #include <linux/errno.h>
22324+#include <linux/sched.h>
22325 #include <asm/io.h>
22326 #include <asm/processor.h>
22327 #include <asm/fcntl.h>
22328diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22329index a2a4f46..6cab058 100644
22330--- a/arch/x86/kernel/entry_32.S
22331+++ b/arch/x86/kernel/entry_32.S
22332@@ -177,13 +177,153 @@
22333 /*CFI_REL_OFFSET gs, PT_GS*/
22334 .endm
22335 .macro SET_KERNEL_GS reg
22336+
22337+#ifdef CONFIG_CC_STACKPROTECTOR
22338 movl $(__KERNEL_STACK_CANARY), \reg
22339+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22340+ movl $(__USER_DS), \reg
22341+#else
22342+ xorl \reg, \reg
22343+#endif
22344+
22345 movl \reg, %gs
22346 .endm
22347
22348 #endif /* CONFIG_X86_32_LAZY_GS */
22349
22350-.macro SAVE_ALL
22351+.macro pax_enter_kernel
22352+#ifdef CONFIG_PAX_KERNEXEC
22353+ call pax_enter_kernel
22354+#endif
22355+.endm
22356+
22357+.macro pax_exit_kernel
22358+#ifdef CONFIG_PAX_KERNEXEC
22359+ call pax_exit_kernel
22360+#endif
22361+.endm
22362+
22363+#ifdef CONFIG_PAX_KERNEXEC
22364+ENTRY(pax_enter_kernel)
22365+#ifdef CONFIG_PARAVIRT
22366+ pushl %eax
22367+ pushl %ecx
22368+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22369+ mov %eax, %esi
22370+#else
22371+ mov %cr0, %esi
22372+#endif
22373+ bts $16, %esi
22374+ jnc 1f
22375+ mov %cs, %esi
22376+ cmp $__KERNEL_CS, %esi
22377+ jz 3f
22378+ ljmp $__KERNEL_CS, $3f
22379+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22380+2:
22381+#ifdef CONFIG_PARAVIRT
22382+ mov %esi, %eax
22383+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22384+#else
22385+ mov %esi, %cr0
22386+#endif
22387+3:
22388+#ifdef CONFIG_PARAVIRT
22389+ popl %ecx
22390+ popl %eax
22391+#endif
22392+ ret
22393+ENDPROC(pax_enter_kernel)
22394+
22395+ENTRY(pax_exit_kernel)
22396+#ifdef CONFIG_PARAVIRT
22397+ pushl %eax
22398+ pushl %ecx
22399+#endif
22400+ mov %cs, %esi
22401+ cmp $__KERNEXEC_KERNEL_CS, %esi
22402+ jnz 2f
22403+#ifdef CONFIG_PARAVIRT
22404+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22405+ mov %eax, %esi
22406+#else
22407+ mov %cr0, %esi
22408+#endif
22409+ btr $16, %esi
22410+ ljmp $__KERNEL_CS, $1f
22411+1:
22412+#ifdef CONFIG_PARAVIRT
22413+ mov %esi, %eax
22414+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22415+#else
22416+ mov %esi, %cr0
22417+#endif
22418+2:
22419+#ifdef CONFIG_PARAVIRT
22420+ popl %ecx
22421+ popl %eax
22422+#endif
22423+ ret
22424+ENDPROC(pax_exit_kernel)
22425+#endif
22426+
22427+ .macro pax_erase_kstack
22428+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22429+ call pax_erase_kstack
22430+#endif
22431+ .endm
22432+
22433+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22434+/*
22435+ * ebp: thread_info
22436+ */
22437+ENTRY(pax_erase_kstack)
22438+ pushl %edi
22439+ pushl %ecx
22440+ pushl %eax
22441+
22442+ mov TI_lowest_stack(%ebp), %edi
22443+ mov $-0xBEEF, %eax
22444+ std
22445+
22446+1: mov %edi, %ecx
22447+ and $THREAD_SIZE_asm - 1, %ecx
22448+ shr $2, %ecx
22449+ repne scasl
22450+ jecxz 2f
22451+
22452+ cmp $2*16, %ecx
22453+ jc 2f
22454+
22455+ mov $2*16, %ecx
22456+ repe scasl
22457+ jecxz 2f
22458+ jne 1b
22459+
22460+2: cld
22461+ mov %esp, %ecx
22462+ sub %edi, %ecx
22463+
22464+ cmp $THREAD_SIZE_asm, %ecx
22465+ jb 3f
22466+ ud2
22467+3:
22468+
22469+ shr $2, %ecx
22470+ rep stosl
22471+
22472+ mov TI_task_thread_sp0(%ebp), %edi
22473+ sub $128, %edi
22474+ mov %edi, TI_lowest_stack(%ebp)
22475+
22476+ popl %eax
22477+ popl %ecx
22478+ popl %edi
22479+ ret
22480+ENDPROC(pax_erase_kstack)
22481+#endif
22482+
22483+.macro __SAVE_ALL _DS
22484 cld
22485 PUSH_GS
22486 pushl_cfi %fs
22487@@ -206,7 +346,7 @@
22488 CFI_REL_OFFSET ecx, 0
22489 pushl_cfi %ebx
22490 CFI_REL_OFFSET ebx, 0
22491- movl $(__USER_DS), %edx
22492+ movl $\_DS, %edx
22493 movl %edx, %ds
22494 movl %edx, %es
22495 movl $(__KERNEL_PERCPU), %edx
22496@@ -214,6 +354,15 @@
22497 SET_KERNEL_GS %edx
22498 .endm
22499
22500+.macro SAVE_ALL
22501+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22502+ __SAVE_ALL __KERNEL_DS
22503+ pax_enter_kernel
22504+#else
22505+ __SAVE_ALL __USER_DS
22506+#endif
22507+.endm
22508+
22509 .macro RESTORE_INT_REGS
22510 popl_cfi %ebx
22511 CFI_RESTORE ebx
22512@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22513 popfl_cfi
22514 jmp syscall_exit
22515 CFI_ENDPROC
22516-END(ret_from_fork)
22517+ENDPROC(ret_from_fork)
22518
22519 ENTRY(ret_from_kernel_thread)
22520 CFI_STARTPROC
22521@@ -344,7 +493,15 @@ ret_from_intr:
22522 andl $SEGMENT_RPL_MASK, %eax
22523 #endif
22524 cmpl $USER_RPL, %eax
22525+
22526+#ifdef CONFIG_PAX_KERNEXEC
22527+ jae resume_userspace
22528+
22529+ pax_exit_kernel
22530+ jmp resume_kernel
22531+#else
22532 jb resume_kernel # not returning to v8086 or userspace
22533+#endif
22534
22535 ENTRY(resume_userspace)
22536 LOCKDEP_SYS_EXIT
22537@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22538 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22539 # int/exception return?
22540 jne work_pending
22541- jmp restore_all
22542-END(ret_from_exception)
22543+ jmp restore_all_pax
22544+ENDPROC(ret_from_exception)
22545
22546 #ifdef CONFIG_PREEMPT
22547 ENTRY(resume_kernel)
22548@@ -369,7 +526,7 @@ need_resched:
22549 jz restore_all
22550 call preempt_schedule_irq
22551 jmp need_resched
22552-END(resume_kernel)
22553+ENDPROC(resume_kernel)
22554 #endif
22555 CFI_ENDPROC
22556 /*
22557@@ -403,30 +560,45 @@ sysenter_past_esp:
22558 /*CFI_REL_OFFSET cs, 0*/
22559 /*
22560 * Push current_thread_info()->sysenter_return to the stack.
22561- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22562- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22563 */
22564- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22565+ pushl_cfi $0
22566 CFI_REL_OFFSET eip, 0
22567
22568 pushl_cfi %eax
22569 SAVE_ALL
22570+ GET_THREAD_INFO(%ebp)
22571+ movl TI_sysenter_return(%ebp),%ebp
22572+ movl %ebp,PT_EIP(%esp)
22573 ENABLE_INTERRUPTS(CLBR_NONE)
22574
22575 /*
22576 * Load the potential sixth argument from user stack.
22577 * Careful about security.
22578 */
22579+ movl PT_OLDESP(%esp),%ebp
22580+
22581+#ifdef CONFIG_PAX_MEMORY_UDEREF
22582+ mov PT_OLDSS(%esp),%ds
22583+1: movl %ds:(%ebp),%ebp
22584+ push %ss
22585+ pop %ds
22586+#else
22587 cmpl $__PAGE_OFFSET-3,%ebp
22588 jae syscall_fault
22589 ASM_STAC
22590 1: movl (%ebp),%ebp
22591 ASM_CLAC
22592+#endif
22593+
22594 movl %ebp,PT_EBP(%esp)
22595 _ASM_EXTABLE(1b,syscall_fault)
22596
22597 GET_THREAD_INFO(%ebp)
22598
22599+#ifdef CONFIG_PAX_RANDKSTACK
22600+ pax_erase_kstack
22601+#endif
22602+
22603 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22604 jnz sysenter_audit
22605 sysenter_do_call:
22606@@ -441,12 +613,24 @@ sysenter_do_call:
22607 testl $_TIF_ALLWORK_MASK, %ecx
22608 jne sysexit_audit
22609 sysenter_exit:
22610+
22611+#ifdef CONFIG_PAX_RANDKSTACK
22612+ pushl_cfi %eax
22613+ movl %esp, %eax
22614+ call pax_randomize_kstack
22615+ popl_cfi %eax
22616+#endif
22617+
22618+ pax_erase_kstack
22619+
22620 /* if something modifies registers it must also disable sysexit */
22621 movl PT_EIP(%esp), %edx
22622 movl PT_OLDESP(%esp), %ecx
22623 xorl %ebp,%ebp
22624 TRACE_IRQS_ON
22625 1: mov PT_FS(%esp), %fs
22626+2: mov PT_DS(%esp), %ds
22627+3: mov PT_ES(%esp), %es
22628 PTGS_TO_GS
22629 ENABLE_INTERRUPTS_SYSEXIT
22630
22631@@ -463,6 +647,9 @@ sysenter_audit:
22632 movl %eax,%edx /* 2nd arg: syscall number */
22633 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22634 call __audit_syscall_entry
22635+
22636+ pax_erase_kstack
22637+
22638 pushl_cfi %ebx
22639 movl PT_EAX(%esp),%eax /* reload syscall number */
22640 jmp sysenter_do_call
22641@@ -488,10 +675,16 @@ sysexit_audit:
22642
22643 CFI_ENDPROC
22644 .pushsection .fixup,"ax"
22645-2: movl $0,PT_FS(%esp)
22646+4: movl $0,PT_FS(%esp)
22647+ jmp 1b
22648+5: movl $0,PT_DS(%esp)
22649+ jmp 1b
22650+6: movl $0,PT_ES(%esp)
22651 jmp 1b
22652 .popsection
22653- _ASM_EXTABLE(1b,2b)
22654+ _ASM_EXTABLE(1b,4b)
22655+ _ASM_EXTABLE(2b,5b)
22656+ _ASM_EXTABLE(3b,6b)
22657 PTGS_TO_GS_EX
22658 ENDPROC(ia32_sysenter_target)
22659
22660@@ -506,6 +699,11 @@ ENTRY(system_call)
22661 pushl_cfi %eax # save orig_eax
22662 SAVE_ALL
22663 GET_THREAD_INFO(%ebp)
22664+
22665+#ifdef CONFIG_PAX_RANDKSTACK
22666+ pax_erase_kstack
22667+#endif
22668+
22669 # system call tracing in operation / emulation
22670 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22671 jnz syscall_trace_entry
22672@@ -524,6 +722,15 @@ syscall_exit:
22673 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22674 jne syscall_exit_work
22675
22676+restore_all_pax:
22677+
22678+#ifdef CONFIG_PAX_RANDKSTACK
22679+ movl %esp, %eax
22680+ call pax_randomize_kstack
22681+#endif
22682+
22683+ pax_erase_kstack
22684+
22685 restore_all:
22686 TRACE_IRQS_IRET
22687 restore_all_notrace:
22688@@ -580,14 +787,34 @@ ldt_ss:
22689 * compensating for the offset by changing to the ESPFIX segment with
22690 * a base address that matches for the difference.
22691 */
22692-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22693+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22694 mov %esp, %edx /* load kernel esp */
22695 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22696 mov %dx, %ax /* eax: new kernel esp */
22697 sub %eax, %edx /* offset (low word is 0) */
22698+#ifdef CONFIG_SMP
22699+ movl PER_CPU_VAR(cpu_number), %ebx
22700+ shll $PAGE_SHIFT_asm, %ebx
22701+ addl $cpu_gdt_table, %ebx
22702+#else
22703+ movl $cpu_gdt_table, %ebx
22704+#endif
22705 shr $16, %edx
22706- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22707- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22708+
22709+#ifdef CONFIG_PAX_KERNEXEC
22710+ mov %cr0, %esi
22711+ btr $16, %esi
22712+ mov %esi, %cr0
22713+#endif
22714+
22715+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22716+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22717+
22718+#ifdef CONFIG_PAX_KERNEXEC
22719+ bts $16, %esi
22720+ mov %esi, %cr0
22721+#endif
22722+
22723 pushl_cfi $__ESPFIX_SS
22724 pushl_cfi %eax /* new kernel esp */
22725 /* Disable interrupts, but do not irqtrace this section: we
22726@@ -616,20 +843,18 @@ work_resched:
22727 movl TI_flags(%ebp), %ecx
22728 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22729 # than syscall tracing?
22730- jz restore_all
22731+ jz restore_all_pax
22732 testb $_TIF_NEED_RESCHED, %cl
22733 jnz work_resched
22734
22735 work_notifysig: # deal with pending signals and
22736 # notify-resume requests
22737+ movl %esp, %eax
22738 #ifdef CONFIG_VM86
22739 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22740- movl %esp, %eax
22741 jne work_notifysig_v86 # returning to kernel-space or
22742 # vm86-space
22743 1:
22744-#else
22745- movl %esp, %eax
22746 #endif
22747 TRACE_IRQS_ON
22748 ENABLE_INTERRUPTS(CLBR_NONE)
22749@@ -650,7 +875,7 @@ work_notifysig_v86:
22750 movl %eax, %esp
22751 jmp 1b
22752 #endif
22753-END(work_pending)
22754+ENDPROC(work_pending)
22755
22756 # perform syscall exit tracing
22757 ALIGN
22758@@ -658,11 +883,14 @@ syscall_trace_entry:
22759 movl $-ENOSYS,PT_EAX(%esp)
22760 movl %esp, %eax
22761 call syscall_trace_enter
22762+
22763+ pax_erase_kstack
22764+
22765 /* What it returned is what we'll actually use. */
22766 cmpl $(NR_syscalls), %eax
22767 jnae syscall_call
22768 jmp syscall_exit
22769-END(syscall_trace_entry)
22770+ENDPROC(syscall_trace_entry)
22771
22772 # perform syscall exit tracing
22773 ALIGN
22774@@ -675,21 +903,25 @@ syscall_exit_work:
22775 movl %esp, %eax
22776 call syscall_trace_leave
22777 jmp resume_userspace
22778-END(syscall_exit_work)
22779+ENDPROC(syscall_exit_work)
22780 CFI_ENDPROC
22781
22782 RING0_INT_FRAME # can't unwind into user space anyway
22783 syscall_fault:
22784+#ifdef CONFIG_PAX_MEMORY_UDEREF
22785+ push %ss
22786+ pop %ds
22787+#endif
22788 ASM_CLAC
22789 GET_THREAD_INFO(%ebp)
22790 movl $-EFAULT,PT_EAX(%esp)
22791 jmp resume_userspace
22792-END(syscall_fault)
22793+ENDPROC(syscall_fault)
22794
22795 syscall_badsys:
22796 movl $-ENOSYS,PT_EAX(%esp)
22797 jmp resume_userspace
22798-END(syscall_badsys)
22799+ENDPROC(syscall_badsys)
22800 CFI_ENDPROC
22801 /*
22802 * End of kprobes section
22803@@ -705,8 +937,15 @@ END(syscall_badsys)
22804 * normal stack and adjusts ESP with the matching offset.
22805 */
22806 /* fixup the stack */
22807- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22808- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22809+#ifdef CONFIG_SMP
22810+ movl PER_CPU_VAR(cpu_number), %ebx
22811+ shll $PAGE_SHIFT_asm, %ebx
22812+ addl $cpu_gdt_table, %ebx
22813+#else
22814+ movl $cpu_gdt_table, %ebx
22815+#endif
22816+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22817+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22818 shl $16, %eax
22819 addl %esp, %eax /* the adjusted stack pointer */
22820 pushl_cfi $__KERNEL_DS
22821@@ -759,7 +998,7 @@ vector=vector+1
22822 .endr
22823 2: jmp common_interrupt
22824 .endr
22825-END(irq_entries_start)
22826+ENDPROC(irq_entries_start)
22827
22828 .previous
22829 END(interrupt)
22830@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22831 pushl_cfi $do_coprocessor_error
22832 jmp error_code
22833 CFI_ENDPROC
22834-END(coprocessor_error)
22835+ENDPROC(coprocessor_error)
22836
22837 ENTRY(simd_coprocessor_error)
22838 RING0_INT_FRAME
22839@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22840 .section .altinstructions,"a"
22841 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22842 .previous
22843-.section .altinstr_replacement,"ax"
22844+.section .altinstr_replacement,"a"
22845 663: pushl $do_simd_coprocessor_error
22846 664:
22847 .previous
22848@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22849 #endif
22850 jmp error_code
22851 CFI_ENDPROC
22852-END(simd_coprocessor_error)
22853+ENDPROC(simd_coprocessor_error)
22854
22855 ENTRY(device_not_available)
22856 RING0_INT_FRAME
22857@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22858 pushl_cfi $do_device_not_available
22859 jmp error_code
22860 CFI_ENDPROC
22861-END(device_not_available)
22862+ENDPROC(device_not_available)
22863
22864 #ifdef CONFIG_PARAVIRT
22865 ENTRY(native_iret)
22866 iret
22867 _ASM_EXTABLE(native_iret, iret_exc)
22868-END(native_iret)
22869+ENDPROC(native_iret)
22870
22871 ENTRY(native_irq_enable_sysexit)
22872 sti
22873 sysexit
22874-END(native_irq_enable_sysexit)
22875+ENDPROC(native_irq_enable_sysexit)
22876 #endif
22877
22878 ENTRY(overflow)
22879@@ -872,7 +1111,7 @@ ENTRY(overflow)
22880 pushl_cfi $do_overflow
22881 jmp error_code
22882 CFI_ENDPROC
22883-END(overflow)
22884+ENDPROC(overflow)
22885
22886 ENTRY(bounds)
22887 RING0_INT_FRAME
22888@@ -881,7 +1120,7 @@ ENTRY(bounds)
22889 pushl_cfi $do_bounds
22890 jmp error_code
22891 CFI_ENDPROC
22892-END(bounds)
22893+ENDPROC(bounds)
22894
22895 ENTRY(invalid_op)
22896 RING0_INT_FRAME
22897@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22898 pushl_cfi $do_invalid_op
22899 jmp error_code
22900 CFI_ENDPROC
22901-END(invalid_op)
22902+ENDPROC(invalid_op)
22903
22904 ENTRY(coprocessor_segment_overrun)
22905 RING0_INT_FRAME
22906@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22907 pushl_cfi $do_coprocessor_segment_overrun
22908 jmp error_code
22909 CFI_ENDPROC
22910-END(coprocessor_segment_overrun)
22911+ENDPROC(coprocessor_segment_overrun)
22912
22913 ENTRY(invalid_TSS)
22914 RING0_EC_FRAME
22915@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22916 pushl_cfi $do_invalid_TSS
22917 jmp error_code
22918 CFI_ENDPROC
22919-END(invalid_TSS)
22920+ENDPROC(invalid_TSS)
22921
22922 ENTRY(segment_not_present)
22923 RING0_EC_FRAME
22924@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22925 pushl_cfi $do_segment_not_present
22926 jmp error_code
22927 CFI_ENDPROC
22928-END(segment_not_present)
22929+ENDPROC(segment_not_present)
22930
22931 ENTRY(stack_segment)
22932 RING0_EC_FRAME
22933@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22934 pushl_cfi $do_stack_segment
22935 jmp error_code
22936 CFI_ENDPROC
22937-END(stack_segment)
22938+ENDPROC(stack_segment)
22939
22940 ENTRY(alignment_check)
22941 RING0_EC_FRAME
22942@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22943 pushl_cfi $do_alignment_check
22944 jmp error_code
22945 CFI_ENDPROC
22946-END(alignment_check)
22947+ENDPROC(alignment_check)
22948
22949 ENTRY(divide_error)
22950 RING0_INT_FRAME
22951@@ -940,7 +1179,7 @@ ENTRY(divide_error)
22952 pushl_cfi $do_divide_error
22953 jmp error_code
22954 CFI_ENDPROC
22955-END(divide_error)
22956+ENDPROC(divide_error)
22957
22958 #ifdef CONFIG_X86_MCE
22959 ENTRY(machine_check)
22960@@ -950,7 +1189,7 @@ ENTRY(machine_check)
22961 pushl_cfi machine_check_vector
22962 jmp error_code
22963 CFI_ENDPROC
22964-END(machine_check)
22965+ENDPROC(machine_check)
22966 #endif
22967
22968 ENTRY(spurious_interrupt_bug)
22969@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22970 pushl_cfi $do_spurious_interrupt_bug
22971 jmp error_code
22972 CFI_ENDPROC
22973-END(spurious_interrupt_bug)
22974+ENDPROC(spurious_interrupt_bug)
22975 /*
22976 * End of kprobes section
22977 */
22978@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22979
22980 ENTRY(mcount)
22981 ret
22982-END(mcount)
22983+ENDPROC(mcount)
22984
22985 ENTRY(ftrace_caller)
22986 cmpl $0, function_trace_stop
22987@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22988 .globl ftrace_stub
22989 ftrace_stub:
22990 ret
22991-END(ftrace_caller)
22992+ENDPROC(ftrace_caller)
22993
22994 ENTRY(ftrace_regs_caller)
22995 pushf /* push flags before compare (in cs location) */
22996@@ -1207,7 +1446,7 @@ trace:
22997 popl %ecx
22998 popl %eax
22999 jmp ftrace_stub
23000-END(mcount)
23001+ENDPROC(mcount)
23002 #endif /* CONFIG_DYNAMIC_FTRACE */
23003 #endif /* CONFIG_FUNCTION_TRACER */
23004
23005@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
23006 popl %ecx
23007 popl %eax
23008 ret
23009-END(ftrace_graph_caller)
23010+ENDPROC(ftrace_graph_caller)
23011
23012 .globl return_to_handler
23013 return_to_handler:
23014@@ -1291,15 +1530,18 @@ error_code:
23015 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23016 REG_TO_PTGS %ecx
23017 SET_KERNEL_GS %ecx
23018- movl $(__USER_DS), %ecx
23019+ movl $(__KERNEL_DS), %ecx
23020 movl %ecx, %ds
23021 movl %ecx, %es
23022+
23023+ pax_enter_kernel
23024+
23025 TRACE_IRQS_OFF
23026 movl %esp,%eax # pt_regs pointer
23027 call *%edi
23028 jmp ret_from_exception
23029 CFI_ENDPROC
23030-END(page_fault)
23031+ENDPROC(page_fault)
23032
23033 /*
23034 * Debug traps and NMI can happen at the one SYSENTER instruction
23035@@ -1342,7 +1584,7 @@ debug_stack_correct:
23036 call do_debug
23037 jmp ret_from_exception
23038 CFI_ENDPROC
23039-END(debug)
23040+ENDPROC(debug)
23041
23042 /*
23043 * NMI is doubly nasty. It can happen _while_ we're handling
23044@@ -1380,6 +1622,9 @@ nmi_stack_correct:
23045 xorl %edx,%edx # zero error code
23046 movl %esp,%eax # pt_regs pointer
23047 call do_nmi
23048+
23049+ pax_exit_kernel
23050+
23051 jmp restore_all_notrace
23052 CFI_ENDPROC
23053
23054@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
23055 FIXUP_ESPFIX_STACK # %eax == %esp
23056 xorl %edx,%edx # zero error code
23057 call do_nmi
23058+
23059+ pax_exit_kernel
23060+
23061 RESTORE_REGS
23062 lss 12+4(%esp), %esp # back to espfix stack
23063 CFI_ADJUST_CFA_OFFSET -24
23064 jmp irq_return
23065 CFI_ENDPROC
23066-END(nmi)
23067+ENDPROC(nmi)
23068
23069 ENTRY(int3)
23070 RING0_INT_FRAME
23071@@ -1434,14 +1682,14 @@ ENTRY(int3)
23072 call do_int3
23073 jmp ret_from_exception
23074 CFI_ENDPROC
23075-END(int3)
23076+ENDPROC(int3)
23077
23078 ENTRY(general_protection)
23079 RING0_EC_FRAME
23080 pushl_cfi $do_general_protection
23081 jmp error_code
23082 CFI_ENDPROC
23083-END(general_protection)
23084+ENDPROC(general_protection)
23085
23086 #ifdef CONFIG_KVM_GUEST
23087 ENTRY(async_page_fault)
23088@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
23089 pushl_cfi $do_async_page_fault
23090 jmp error_code
23091 CFI_ENDPROC
23092-END(async_page_fault)
23093+ENDPROC(async_page_fault)
23094 #endif
23095
23096 /*
23097diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23098index 1e96c36..3ff710a 100644
23099--- a/arch/x86/kernel/entry_64.S
23100+++ b/arch/x86/kernel/entry_64.S
23101@@ -59,6 +59,8 @@
23102 #include <asm/context_tracking.h>
23103 #include <asm/smap.h>
23104 #include <linux/err.h>
23105+#include <asm/pgtable.h>
23106+#include <asm/alternative-asm.h>
23107
23108 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23109 #include <linux/elf-em.h>
23110@@ -80,8 +82,9 @@
23111 #ifdef CONFIG_DYNAMIC_FTRACE
23112
23113 ENTRY(function_hook)
23114+ pax_force_retaddr
23115 retq
23116-END(function_hook)
23117+ENDPROC(function_hook)
23118
23119 /* skip is set if stack has been adjusted */
23120 .macro ftrace_caller_setup skip=0
23121@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
23122 #endif
23123
23124 GLOBAL(ftrace_stub)
23125+ pax_force_retaddr
23126 retq
23127-END(ftrace_caller)
23128+ENDPROC(ftrace_caller)
23129
23130 ENTRY(ftrace_regs_caller)
23131 /* Save the current flags before compare (in SS location)*/
23132@@ -191,7 +195,7 @@ ftrace_restore_flags:
23133 popfq
23134 jmp ftrace_stub
23135
23136-END(ftrace_regs_caller)
23137+ENDPROC(ftrace_regs_caller)
23138
23139
23140 #else /* ! CONFIG_DYNAMIC_FTRACE */
23141@@ -212,6 +216,7 @@ ENTRY(function_hook)
23142 #endif
23143
23144 GLOBAL(ftrace_stub)
23145+ pax_force_retaddr
23146 retq
23147
23148 trace:
23149@@ -225,12 +230,13 @@ trace:
23150 #endif
23151 subq $MCOUNT_INSN_SIZE, %rdi
23152
23153+ pax_force_fptr ftrace_trace_function
23154 call *ftrace_trace_function
23155
23156 MCOUNT_RESTORE_FRAME
23157
23158 jmp ftrace_stub
23159-END(function_hook)
23160+ENDPROC(function_hook)
23161 #endif /* CONFIG_DYNAMIC_FTRACE */
23162 #endif /* CONFIG_FUNCTION_TRACER */
23163
23164@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
23165
23166 MCOUNT_RESTORE_FRAME
23167
23168+ pax_force_retaddr
23169 retq
23170-END(ftrace_graph_caller)
23171+ENDPROC(ftrace_graph_caller)
23172
23173 GLOBAL(return_to_handler)
23174 subq $24, %rsp
23175@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
23176 movq 8(%rsp), %rdx
23177 movq (%rsp), %rax
23178 addq $24, %rsp
23179+ pax_force_fptr %rdi
23180 jmp *%rdi
23181+ENDPROC(return_to_handler)
23182 #endif
23183
23184
23185@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
23186 ENDPROC(native_usergs_sysret64)
23187 #endif /* CONFIG_PARAVIRT */
23188
23189+ .macro ljmpq sel, off
23190+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23191+ .byte 0x48; ljmp *1234f(%rip)
23192+ .pushsection .rodata
23193+ .align 16
23194+ 1234: .quad \off; .word \sel
23195+ .popsection
23196+#else
23197+ pushq $\sel
23198+ pushq $\off
23199+ lretq
23200+#endif
23201+ .endm
23202+
23203+ .macro pax_enter_kernel
23204+ pax_set_fptr_mask
23205+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23206+ call pax_enter_kernel
23207+#endif
23208+ .endm
23209+
23210+ .macro pax_exit_kernel
23211+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23212+ call pax_exit_kernel
23213+#endif
23214+
23215+ .endm
23216+
23217+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23218+ENTRY(pax_enter_kernel)
23219+ pushq %rdi
23220+
23221+#ifdef CONFIG_PARAVIRT
23222+ PV_SAVE_REGS(CLBR_RDI)
23223+#endif
23224+
23225+#ifdef CONFIG_PAX_KERNEXEC
23226+ GET_CR0_INTO_RDI
23227+ bts $16,%rdi
23228+ jnc 3f
23229+ mov %cs,%edi
23230+ cmp $__KERNEL_CS,%edi
23231+ jnz 2f
23232+1:
23233+#endif
23234+
23235+#ifdef CONFIG_PAX_MEMORY_UDEREF
23236+ 661: jmp 111f
23237+ .pushsection .altinstr_replacement, "a"
23238+ 662: ASM_NOP2
23239+ .popsection
23240+ .pushsection .altinstructions, "a"
23241+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23242+ .popsection
23243+ GET_CR3_INTO_RDI
23244+ cmp $0,%dil
23245+ jnz 112f
23246+ mov $__KERNEL_DS,%edi
23247+ mov %edi,%ss
23248+ jmp 111f
23249+112: cmp $1,%dil
23250+ jz 113f
23251+ ud2
23252+113: sub $4097,%rdi
23253+ bts $63,%rdi
23254+ SET_RDI_INTO_CR3
23255+ mov $__UDEREF_KERNEL_DS,%edi
23256+ mov %edi,%ss
23257+111:
23258+#endif
23259+
23260+#ifdef CONFIG_PARAVIRT
23261+ PV_RESTORE_REGS(CLBR_RDI)
23262+#endif
23263+
23264+ popq %rdi
23265+ pax_force_retaddr
23266+ retq
23267+
23268+#ifdef CONFIG_PAX_KERNEXEC
23269+2: ljmpq __KERNEL_CS,1b
23270+3: ljmpq __KERNEXEC_KERNEL_CS,4f
23271+4: SET_RDI_INTO_CR0
23272+ jmp 1b
23273+#endif
23274+ENDPROC(pax_enter_kernel)
23275+
23276+ENTRY(pax_exit_kernel)
23277+ pushq %rdi
23278+
23279+#ifdef CONFIG_PARAVIRT
23280+ PV_SAVE_REGS(CLBR_RDI)
23281+#endif
23282+
23283+#ifdef CONFIG_PAX_KERNEXEC
23284+ mov %cs,%rdi
23285+ cmp $__KERNEXEC_KERNEL_CS,%edi
23286+ jz 2f
23287+ GET_CR0_INTO_RDI
23288+ bts $16,%rdi
23289+ jnc 4f
23290+1:
23291+#endif
23292+
23293+#ifdef CONFIG_PAX_MEMORY_UDEREF
23294+ 661: jmp 111f
23295+ .pushsection .altinstr_replacement, "a"
23296+ 662: ASM_NOP2
23297+ .popsection
23298+ .pushsection .altinstructions, "a"
23299+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23300+ .popsection
23301+ mov %ss,%edi
23302+ cmp $__UDEREF_KERNEL_DS,%edi
23303+ jnz 111f
23304+ GET_CR3_INTO_RDI
23305+ cmp $0,%dil
23306+ jz 112f
23307+ ud2
23308+112: add $4097,%rdi
23309+ bts $63,%rdi
23310+ SET_RDI_INTO_CR3
23311+ mov $__KERNEL_DS,%edi
23312+ mov %edi,%ss
23313+111:
23314+#endif
23315+
23316+#ifdef CONFIG_PARAVIRT
23317+ PV_RESTORE_REGS(CLBR_RDI);
23318+#endif
23319+
23320+ popq %rdi
23321+ pax_force_retaddr
23322+ retq
23323+
23324+#ifdef CONFIG_PAX_KERNEXEC
23325+2: GET_CR0_INTO_RDI
23326+ btr $16,%rdi
23327+ jnc 4f
23328+ ljmpq __KERNEL_CS,3f
23329+3: SET_RDI_INTO_CR0
23330+ jmp 1b
23331+4: ud2
23332+ jmp 4b
23333+#endif
23334+ENDPROC(pax_exit_kernel)
23335+#endif
23336+
23337+ .macro pax_enter_kernel_user
23338+ pax_set_fptr_mask
23339+#ifdef CONFIG_PAX_MEMORY_UDEREF
23340+ call pax_enter_kernel_user
23341+#endif
23342+ .endm
23343+
23344+ .macro pax_exit_kernel_user
23345+#ifdef CONFIG_PAX_MEMORY_UDEREF
23346+ call pax_exit_kernel_user
23347+#endif
23348+#ifdef CONFIG_PAX_RANDKSTACK
23349+ pushq %rax
23350+ pushq %r11
23351+ call pax_randomize_kstack
23352+ popq %r11
23353+ popq %rax
23354+#endif
23355+ .endm
23356+
23357+#ifdef CONFIG_PAX_MEMORY_UDEREF
23358+ENTRY(pax_enter_kernel_user)
23359+ pushq %rdi
23360+ pushq %rbx
23361+
23362+#ifdef CONFIG_PARAVIRT
23363+ PV_SAVE_REGS(CLBR_RDI)
23364+#endif
23365+
23366+ 661: jmp 111f
23367+ .pushsection .altinstr_replacement, "a"
23368+ 662: ASM_NOP2
23369+ .popsection
23370+ .pushsection .altinstructions, "a"
23371+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23372+ .popsection
23373+ GET_CR3_INTO_RDI
23374+ cmp $1,%dil
23375+ jnz 4f
23376+ sub $4097,%rdi
23377+ bts $63,%rdi
23378+ SET_RDI_INTO_CR3
23379+ jmp 3f
23380+111:
23381+
23382+ GET_CR3_INTO_RDI
23383+ mov %rdi,%rbx
23384+ add $__START_KERNEL_map,%rbx
23385+ sub phys_base(%rip),%rbx
23386+
23387+#ifdef CONFIG_PARAVIRT
23388+ cmpl $0, pv_info+PARAVIRT_enabled
23389+ jz 1f
23390+ pushq %rdi
23391+ i = 0
23392+ .rept USER_PGD_PTRS
23393+ mov i*8(%rbx),%rsi
23394+ mov $0,%sil
23395+ lea i*8(%rbx),%rdi
23396+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23397+ i = i + 1
23398+ .endr
23399+ popq %rdi
23400+ jmp 2f
23401+1:
23402+#endif
23403+
23404+ i = 0
23405+ .rept USER_PGD_PTRS
23406+ movb $0,i*8(%rbx)
23407+ i = i + 1
23408+ .endr
23409+
23410+2: SET_RDI_INTO_CR3
23411+
23412+#ifdef CONFIG_PAX_KERNEXEC
23413+ GET_CR0_INTO_RDI
23414+ bts $16,%rdi
23415+ SET_RDI_INTO_CR0
23416+#endif
23417+
23418+3:
23419+
23420+#ifdef CONFIG_PARAVIRT
23421+ PV_RESTORE_REGS(CLBR_RDI)
23422+#endif
23423+
23424+ popq %rbx
23425+ popq %rdi
23426+ pax_force_retaddr
23427+ retq
23428+4: ud2
23429+ENDPROC(pax_enter_kernel_user)
23430+
23431+ENTRY(pax_exit_kernel_user)
23432+ pushq %rdi
23433+ pushq %rbx
23434+
23435+#ifdef CONFIG_PARAVIRT
23436+ PV_SAVE_REGS(CLBR_RDI)
23437+#endif
23438+
23439+ GET_CR3_INTO_RDI
23440+ 661: jmp 1f
23441+ .pushsection .altinstr_replacement, "a"
23442+ 662: ASM_NOP2
23443+ .popsection
23444+ .pushsection .altinstructions, "a"
23445+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23446+ .popsection
23447+ cmp $0,%dil
23448+ jnz 3f
23449+ add $4097,%rdi
23450+ bts $63,%rdi
23451+ SET_RDI_INTO_CR3
23452+ jmp 2f
23453+1:
23454+
23455+ mov %rdi,%rbx
23456+
23457+#ifdef CONFIG_PAX_KERNEXEC
23458+ GET_CR0_INTO_RDI
23459+ btr $16,%rdi
23460+ jnc 3f
23461+ SET_RDI_INTO_CR0
23462+#endif
23463+
23464+ add $__START_KERNEL_map,%rbx
23465+ sub phys_base(%rip),%rbx
23466+
23467+#ifdef CONFIG_PARAVIRT
23468+ cmpl $0, pv_info+PARAVIRT_enabled
23469+ jz 1f
23470+ i = 0
23471+ .rept USER_PGD_PTRS
23472+ mov i*8(%rbx),%rsi
23473+ mov $0x67,%sil
23474+ lea i*8(%rbx),%rdi
23475+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23476+ i = i + 1
23477+ .endr
23478+ jmp 2f
23479+1:
23480+#endif
23481+
23482+ i = 0
23483+ .rept USER_PGD_PTRS
23484+ movb $0x67,i*8(%rbx)
23485+ i = i + 1
23486+ .endr
23487+2:
23488+
23489+#ifdef CONFIG_PARAVIRT
23490+ PV_RESTORE_REGS(CLBR_RDI)
23491+#endif
23492+
23493+ popq %rbx
23494+ popq %rdi
23495+ pax_force_retaddr
23496+ retq
23497+3: ud2
23498+ENDPROC(pax_exit_kernel_user)
23499+#endif
23500+
23501+ .macro pax_enter_kernel_nmi
23502+ pax_set_fptr_mask
23503+
23504+#ifdef CONFIG_PAX_KERNEXEC
23505+ GET_CR0_INTO_RDI
23506+ bts $16,%rdi
23507+ jc 110f
23508+ SET_RDI_INTO_CR0
23509+ or $2,%ebx
23510+110:
23511+#endif
23512+
23513+#ifdef CONFIG_PAX_MEMORY_UDEREF
23514+ 661: jmp 111f
23515+ .pushsection .altinstr_replacement, "a"
23516+ 662: ASM_NOP2
23517+ .popsection
23518+ .pushsection .altinstructions, "a"
23519+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23520+ .popsection
23521+ GET_CR3_INTO_RDI
23522+ cmp $0,%dil
23523+ jz 111f
23524+ sub $4097,%rdi
23525+ or $4,%ebx
23526+ bts $63,%rdi
23527+ SET_RDI_INTO_CR3
23528+ mov $__UDEREF_KERNEL_DS,%edi
23529+ mov %edi,%ss
23530+111:
23531+#endif
23532+ .endm
23533+
23534+ .macro pax_exit_kernel_nmi
23535+#ifdef CONFIG_PAX_KERNEXEC
23536+ btr $1,%ebx
23537+ jnc 110f
23538+ GET_CR0_INTO_RDI
23539+ btr $16,%rdi
23540+ SET_RDI_INTO_CR0
23541+110:
23542+#endif
23543+
23544+#ifdef CONFIG_PAX_MEMORY_UDEREF
23545+ btr $2,%ebx
23546+ jnc 111f
23547+ GET_CR3_INTO_RDI
23548+ add $4097,%rdi
23549+ bts $63,%rdi
23550+ SET_RDI_INTO_CR3
23551+ mov $__KERNEL_DS,%edi
23552+ mov %edi,%ss
23553+111:
23554+#endif
23555+ .endm
23556+
23557+ .macro pax_erase_kstack
23558+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23559+ call pax_erase_kstack
23560+#endif
23561+ .endm
23562+
23563+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23564+ENTRY(pax_erase_kstack)
23565+ pushq %rdi
23566+ pushq %rcx
23567+ pushq %rax
23568+ pushq %r11
23569+
23570+ GET_THREAD_INFO(%r11)
23571+ mov TI_lowest_stack(%r11), %rdi
23572+ mov $-0xBEEF, %rax
23573+ std
23574+
23575+1: mov %edi, %ecx
23576+ and $THREAD_SIZE_asm - 1, %ecx
23577+ shr $3, %ecx
23578+ repne scasq
23579+ jecxz 2f
23580+
23581+ cmp $2*8, %ecx
23582+ jc 2f
23583+
23584+ mov $2*8, %ecx
23585+ repe scasq
23586+ jecxz 2f
23587+ jne 1b
23588+
23589+2: cld
23590+ mov %esp, %ecx
23591+ sub %edi, %ecx
23592+
23593+ cmp $THREAD_SIZE_asm, %rcx
23594+ jb 3f
23595+ ud2
23596+3:
23597+
23598+ shr $3, %ecx
23599+ rep stosq
23600+
23601+ mov TI_task_thread_sp0(%r11), %rdi
23602+ sub $256, %rdi
23603+ mov %rdi, TI_lowest_stack(%r11)
23604+
23605+ popq %r11
23606+ popq %rax
23607+ popq %rcx
23608+ popq %rdi
23609+ pax_force_retaddr
23610+ ret
23611+ENDPROC(pax_erase_kstack)
23612+#endif
23613
23614 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23615 #ifdef CONFIG_TRACE_IRQFLAGS
23616@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23617 .endm
23618
23619 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23620- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23621+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23622 jnc 1f
23623 TRACE_IRQS_ON_DEBUG
23624 1:
23625@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23626 movq \tmp,R11+\offset(%rsp)
23627 .endm
23628
23629- .macro FAKE_STACK_FRAME child_rip
23630- /* push in order ss, rsp, eflags, cs, rip */
23631- xorl %eax, %eax
23632- pushq_cfi $__KERNEL_DS /* ss */
23633- /*CFI_REL_OFFSET ss,0*/
23634- pushq_cfi %rax /* rsp */
23635- CFI_REL_OFFSET rsp,0
23636- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23637- /*CFI_REL_OFFSET rflags,0*/
23638- pushq_cfi $__KERNEL_CS /* cs */
23639- /*CFI_REL_OFFSET cs,0*/
23640- pushq_cfi \child_rip /* rip */
23641- CFI_REL_OFFSET rip,0
23642- pushq_cfi %rax /* orig rax */
23643- .endm
23644-
23645- .macro UNFAKE_STACK_FRAME
23646- addq $8*6, %rsp
23647- CFI_ADJUST_CFA_OFFSET -(6*8)
23648- .endm
23649-
23650 /*
23651 * initial frame state for interrupts (and exceptions without error code)
23652 */
23653@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23654 /* save partial stack frame */
23655 .macro SAVE_ARGS_IRQ
23656 cld
23657- /* start from rbp in pt_regs and jump over */
23658- movq_cfi rdi, (RDI-RBP)
23659- movq_cfi rsi, (RSI-RBP)
23660- movq_cfi rdx, (RDX-RBP)
23661- movq_cfi rcx, (RCX-RBP)
23662- movq_cfi rax, (RAX-RBP)
23663- movq_cfi r8, (R8-RBP)
23664- movq_cfi r9, (R9-RBP)
23665- movq_cfi r10, (R10-RBP)
23666- movq_cfi r11, (R11-RBP)
23667+ /* start from r15 in pt_regs and jump over */
23668+ movq_cfi rdi, RDI
23669+ movq_cfi rsi, RSI
23670+ movq_cfi rdx, RDX
23671+ movq_cfi rcx, RCX
23672+ movq_cfi rax, RAX
23673+ movq_cfi r8, R8
23674+ movq_cfi r9, R9
23675+ movq_cfi r10, R10
23676+ movq_cfi r11, R11
23677+ movq_cfi r12, R12
23678
23679 /* Save rbp so that we can unwind from get_irq_regs() */
23680- movq_cfi rbp, 0
23681+ movq_cfi rbp, RBP
23682
23683 /* Save previous stack value */
23684 movq %rsp, %rsi
23685
23686- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23687- testl $3, CS-RBP(%rsi)
23688+ movq %rsp,%rdi /* arg1 for handler */
23689+ testb $3, CS(%rsi)
23690 je 1f
23691 SWAPGS
23692 /*
23693@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23694 0x06 /* DW_OP_deref */, \
23695 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23696 0x22 /* DW_OP_plus */
23697+
23698+#ifdef CONFIG_PAX_MEMORY_UDEREF
23699+ testb $3, CS(%rdi)
23700+ jnz 1f
23701+ pax_enter_kernel
23702+ jmp 2f
23703+1: pax_enter_kernel_user
23704+2:
23705+#else
23706+ pax_enter_kernel
23707+#endif
23708+
23709 /* We entered an interrupt context - irqs are off: */
23710 TRACE_IRQS_OFF
23711 .endm
23712@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23713 js 1f /* negative -> in kernel */
23714 SWAPGS
23715 xorl %ebx,%ebx
23716-1: ret
23717+1:
23718+#ifdef CONFIG_PAX_MEMORY_UDEREF
23719+ testb $3, CS+8(%rsp)
23720+ jnz 1f
23721+ pax_enter_kernel
23722+ jmp 2f
23723+1: pax_enter_kernel_user
23724+2:
23725+#else
23726+ pax_enter_kernel
23727+#endif
23728+ pax_force_retaddr
23729+ ret
23730 CFI_ENDPROC
23731-END(save_paranoid)
23732+ENDPROC(save_paranoid)
23733+
23734+ENTRY(save_paranoid_nmi)
23735+ XCPT_FRAME 1 RDI+8
23736+ cld
23737+ movq_cfi rdi, RDI+8
23738+ movq_cfi rsi, RSI+8
23739+ movq_cfi rdx, RDX+8
23740+ movq_cfi rcx, RCX+8
23741+ movq_cfi rax, RAX+8
23742+ movq_cfi r8, R8+8
23743+ movq_cfi r9, R9+8
23744+ movq_cfi r10, R10+8
23745+ movq_cfi r11, R11+8
23746+ movq_cfi rbx, RBX+8
23747+ movq_cfi rbp, RBP+8
23748+ movq_cfi r12, R12+8
23749+ movq_cfi r13, R13+8
23750+ movq_cfi r14, R14+8
23751+ movq_cfi r15, R15+8
23752+ movl $1,%ebx
23753+ movl $MSR_GS_BASE,%ecx
23754+ rdmsr
23755+ testl %edx,%edx
23756+ js 1f /* negative -> in kernel */
23757+ SWAPGS
23758+ xorl %ebx,%ebx
23759+1: pax_enter_kernel_nmi
23760+ pax_force_retaddr
23761+ ret
23762+ CFI_ENDPROC
23763+ENDPROC(save_paranoid_nmi)
23764 .popsection
23765
23766 /*
23767@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23768
23769 RESTORE_REST
23770
23771- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23772+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23773 jz 1f
23774
23775 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23776@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23777 jmp ret_from_sys_call # go to the SYSRET fastpath
23778
23779 1:
23780- subq $REST_SKIP, %rsp # leave space for volatiles
23781- CFI_ADJUST_CFA_OFFSET REST_SKIP
23782 movq %rbp, %rdi
23783 call *%rbx
23784 movl $0, RAX(%rsp)
23785 RESTORE_REST
23786 jmp int_ret_from_sys_call
23787 CFI_ENDPROC
23788-END(ret_from_fork)
23789+ENDPROC(ret_from_fork)
23790
23791 /*
23792 * System call entry. Up to 6 arguments in registers are supported.
23793@@ -593,7 +1059,7 @@ END(ret_from_fork)
23794 ENTRY(system_call)
23795 CFI_STARTPROC simple
23796 CFI_SIGNAL_FRAME
23797- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23798+ CFI_DEF_CFA rsp,0
23799 CFI_REGISTER rip,rcx
23800 /*CFI_REGISTER rflags,r11*/
23801 SWAPGS_UNSAFE_STACK
23802@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23803
23804 movq %rsp,PER_CPU_VAR(old_rsp)
23805 movq PER_CPU_VAR(kernel_stack),%rsp
23806+ SAVE_ARGS 8*6,0
23807+ pax_enter_kernel_user
23808+
23809+#ifdef CONFIG_PAX_RANDKSTACK
23810+ pax_erase_kstack
23811+#endif
23812+
23813 /*
23814 * No need to follow this irqs off/on section - it's straight
23815 * and short:
23816 */
23817 ENABLE_INTERRUPTS(CLBR_NONE)
23818- SAVE_ARGS 8,0
23819 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23820 movq %rcx,RIP-ARGOFFSET(%rsp)
23821 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23822- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23823+ GET_THREAD_INFO(%rcx)
23824+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23825 jnz tracesys
23826 system_call_fastpath:
23827 #if __SYSCALL_MASK == ~0
23828@@ -639,10 +1112,13 @@ sysret_check:
23829 LOCKDEP_SYS_EXIT
23830 DISABLE_INTERRUPTS(CLBR_NONE)
23831 TRACE_IRQS_OFF
23832- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23833+ GET_THREAD_INFO(%rcx)
23834+ movl TI_flags(%rcx),%edx
23835 andl %edi,%edx
23836 jnz sysret_careful
23837 CFI_REMEMBER_STATE
23838+ pax_exit_kernel_user
23839+ pax_erase_kstack
23840 /*
23841 * sysretq will re-enable interrupts:
23842 */
23843@@ -701,6 +1177,9 @@ auditsys:
23844 movq %rax,%rsi /* 2nd arg: syscall number */
23845 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23846 call __audit_syscall_entry
23847+
23848+ pax_erase_kstack
23849+
23850 LOAD_ARGS 0 /* reload call-clobbered registers */
23851 jmp system_call_fastpath
23852
23853@@ -722,7 +1201,7 @@ sysret_audit:
23854 /* Do syscall tracing */
23855 tracesys:
23856 #ifdef CONFIG_AUDITSYSCALL
23857- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23858+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23859 jz auditsys
23860 #endif
23861 SAVE_REST
23862@@ -730,12 +1209,15 @@ tracesys:
23863 FIXUP_TOP_OF_STACK %rdi
23864 movq %rsp,%rdi
23865 call syscall_trace_enter
23866+
23867+ pax_erase_kstack
23868+
23869 /*
23870 * Reload arg registers from stack in case ptrace changed them.
23871 * We don't reload %rax because syscall_trace_enter() returned
23872 * the value it wants us to use in the table lookup.
23873 */
23874- LOAD_ARGS ARGOFFSET, 1
23875+ LOAD_ARGS 1
23876 RESTORE_REST
23877 #if __SYSCALL_MASK == ~0
23878 cmpq $__NR_syscall_max,%rax
23879@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23880 andl %edi,%edx
23881 jnz int_careful
23882 andl $~TS_COMPAT,TI_status(%rcx)
23883- jmp retint_swapgs
23884+ pax_exit_kernel_user
23885+ pax_erase_kstack
23886+ jmp retint_swapgs_pax
23887
23888 /* Either reschedule or signal or syscall exit tracking needed. */
23889 /* First do a reschedule test. */
23890@@ -811,7 +1295,7 @@ int_restore_rest:
23891 TRACE_IRQS_OFF
23892 jmp int_with_check
23893 CFI_ENDPROC
23894-END(system_call)
23895+ENDPROC(system_call)
23896
23897 .macro FORK_LIKE func
23898 ENTRY(stub_\func)
23899@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23900 DEFAULT_FRAME 0 8 /* offset 8: return address */
23901 call sys_\func
23902 RESTORE_TOP_OF_STACK %r11, 8
23903- ret $REST_SKIP /* pop extended registers */
23904+ pax_force_retaddr
23905+ ret
23906 CFI_ENDPROC
23907-END(stub_\func)
23908+ENDPROC(stub_\func)
23909 .endm
23910
23911 .macro FIXED_FRAME label,func
23912@@ -836,9 +1321,10 @@ ENTRY(\label)
23913 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23914 call \func
23915 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23916+ pax_force_retaddr
23917 ret
23918 CFI_ENDPROC
23919-END(\label)
23920+ENDPROC(\label)
23921 .endm
23922
23923 FORK_LIKE clone
23924@@ -846,19 +1332,6 @@ END(\label)
23925 FORK_LIKE vfork
23926 FIXED_FRAME stub_iopl, sys_iopl
23927
23928-ENTRY(ptregscall_common)
23929- DEFAULT_FRAME 1 8 /* offset 8: return address */
23930- RESTORE_TOP_OF_STACK %r11, 8
23931- movq_cfi_restore R15+8, r15
23932- movq_cfi_restore R14+8, r14
23933- movq_cfi_restore R13+8, r13
23934- movq_cfi_restore R12+8, r12
23935- movq_cfi_restore RBP+8, rbp
23936- movq_cfi_restore RBX+8, rbx
23937- ret $REST_SKIP /* pop extended registers */
23938- CFI_ENDPROC
23939-END(ptregscall_common)
23940-
23941 ENTRY(stub_execve)
23942 CFI_STARTPROC
23943 addq $8, %rsp
23944@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23945 RESTORE_REST
23946 jmp int_ret_from_sys_call
23947 CFI_ENDPROC
23948-END(stub_execve)
23949+ENDPROC(stub_execve)
23950
23951 /*
23952 * sigreturn is special because it needs to restore all registers on return.
23953@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23954 RESTORE_REST
23955 jmp int_ret_from_sys_call
23956 CFI_ENDPROC
23957-END(stub_rt_sigreturn)
23958+ENDPROC(stub_rt_sigreturn)
23959
23960 #ifdef CONFIG_X86_X32_ABI
23961 ENTRY(stub_x32_rt_sigreturn)
23962@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23963 RESTORE_REST
23964 jmp int_ret_from_sys_call
23965 CFI_ENDPROC
23966-END(stub_x32_rt_sigreturn)
23967+ENDPROC(stub_x32_rt_sigreturn)
23968
23969 ENTRY(stub_x32_execve)
23970 CFI_STARTPROC
23971@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23972 RESTORE_REST
23973 jmp int_ret_from_sys_call
23974 CFI_ENDPROC
23975-END(stub_x32_execve)
23976+ENDPROC(stub_x32_execve)
23977
23978 #endif
23979
23980@@ -952,7 +1425,7 @@ vector=vector+1
23981 2: jmp common_interrupt
23982 .endr
23983 CFI_ENDPROC
23984-END(irq_entries_start)
23985+ENDPROC(irq_entries_start)
23986
23987 .previous
23988 END(interrupt)
23989@@ -969,8 +1442,8 @@ END(interrupt)
23990 /* 0(%rsp): ~(interrupt number) */
23991 .macro interrupt func
23992 /* reserve pt_regs for scratch regs and rbp */
23993- subq $ORIG_RAX-RBP, %rsp
23994- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23995+ subq $ORIG_RAX, %rsp
23996+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23997 SAVE_ARGS_IRQ
23998 call \func
23999 .endm
24000@@ -997,14 +1470,14 @@ ret_from_intr:
24001
24002 /* Restore saved previous stack */
24003 popq %rsi
24004- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24005- leaq ARGOFFSET-RBP(%rsi), %rsp
24006+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24007+ movq %rsi, %rsp
24008 CFI_DEF_CFA_REGISTER rsp
24009- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24010+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24011
24012 exit_intr:
24013 GET_THREAD_INFO(%rcx)
24014- testl $3,CS-ARGOFFSET(%rsp)
24015+ testb $3,CS-ARGOFFSET(%rsp)
24016 je retint_kernel
24017
24018 /* Interrupt came from user space */
24019@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
24020 * The iretq could re-enable interrupts:
24021 */
24022 DISABLE_INTERRUPTS(CLBR_ANY)
24023+ pax_exit_kernel_user
24024+retint_swapgs_pax:
24025 TRACE_IRQS_IRETQ
24026 SWAPGS
24027 jmp restore_args
24028
24029 retint_restore_args: /* return to kernel space */
24030 DISABLE_INTERRUPTS(CLBR_ANY)
24031+ pax_exit_kernel
24032+ pax_force_retaddr (RIP-ARGOFFSET)
24033 /*
24034 * The iretq could re-enable interrupts:
24035 */
24036@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
24037 #endif
24038
24039 CFI_ENDPROC
24040-END(common_interrupt)
24041+ENDPROC(common_interrupt)
24042 /*
24043 * End of kprobes section
24044 */
24045@@ -1130,7 +1607,7 @@ ENTRY(\sym)
24046 interrupt \do_sym
24047 jmp ret_from_intr
24048 CFI_ENDPROC
24049-END(\sym)
24050+ENDPROC(\sym)
24051 .endm
24052
24053 #ifdef CONFIG_TRACING
24054@@ -1218,7 +1695,7 @@ ENTRY(\sym)
24055 call \do_sym
24056 jmp error_exit /* %ebx: no swapgs flag */
24057 CFI_ENDPROC
24058-END(\sym)
24059+ENDPROC(\sym)
24060 .endm
24061
24062 .macro paranoidzeroentry sym do_sym
24063@@ -1236,10 +1713,10 @@ ENTRY(\sym)
24064 call \do_sym
24065 jmp paranoid_exit /* %ebx: no swapgs flag */
24066 CFI_ENDPROC
24067-END(\sym)
24068+ENDPROC(\sym)
24069 .endm
24070
24071-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24072+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24073 .macro paranoidzeroentry_ist sym do_sym ist
24074 ENTRY(\sym)
24075 INTR_FRAME
24076@@ -1252,12 +1729,18 @@ ENTRY(\sym)
24077 TRACE_IRQS_OFF_DEBUG
24078 movq %rsp,%rdi /* pt_regs pointer */
24079 xorl %esi,%esi /* no error code */
24080+#ifdef CONFIG_SMP
24081+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24082+ lea init_tss(%r13), %r13
24083+#else
24084+ lea init_tss(%rip), %r13
24085+#endif
24086 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
24087 call \do_sym
24088 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
24089 jmp paranoid_exit /* %ebx: no swapgs flag */
24090 CFI_ENDPROC
24091-END(\sym)
24092+ENDPROC(\sym)
24093 .endm
24094
24095 .macro errorentry sym do_sym
24096@@ -1275,7 +1758,7 @@ ENTRY(\sym)
24097 call \do_sym
24098 jmp error_exit /* %ebx: no swapgs flag */
24099 CFI_ENDPROC
24100-END(\sym)
24101+ENDPROC(\sym)
24102 .endm
24103
24104 #ifdef CONFIG_TRACING
24105@@ -1306,7 +1789,7 @@ ENTRY(\sym)
24106 call \do_sym
24107 jmp paranoid_exit /* %ebx: no swapgs flag */
24108 CFI_ENDPROC
24109-END(\sym)
24110+ENDPROC(\sym)
24111 .endm
24112
24113 zeroentry divide_error do_divide_error
24114@@ -1336,9 +1819,10 @@ gs_change:
24115 2: mfence /* workaround */
24116 SWAPGS
24117 popfq_cfi
24118+ pax_force_retaddr
24119 ret
24120 CFI_ENDPROC
24121-END(native_load_gs_index)
24122+ENDPROC(native_load_gs_index)
24123
24124 _ASM_EXTABLE(gs_change,bad_gs)
24125 .section .fixup,"ax"
24126@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
24127 CFI_DEF_CFA_REGISTER rsp
24128 CFI_ADJUST_CFA_OFFSET -8
24129 decl PER_CPU_VAR(irq_count)
24130+ pax_force_retaddr
24131 ret
24132 CFI_ENDPROC
24133-END(do_softirq_own_stack)
24134+ENDPROC(do_softirq_own_stack)
24135
24136 #ifdef CONFIG_XEN
24137 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
24138@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24139 decl PER_CPU_VAR(irq_count)
24140 jmp error_exit
24141 CFI_ENDPROC
24142-END(xen_do_hypervisor_callback)
24143+ENDPROC(xen_do_hypervisor_callback)
24144
24145 /*
24146 * Hypervisor uses this for application faults while it executes.
24147@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
24148 SAVE_ALL
24149 jmp error_exit
24150 CFI_ENDPROC
24151-END(xen_failsafe_callback)
24152+ENDPROC(xen_failsafe_callback)
24153
24154 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24155 xen_hvm_callback_vector xen_evtchn_do_upcall
24156@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
24157 DEFAULT_FRAME
24158 DISABLE_INTERRUPTS(CLBR_NONE)
24159 TRACE_IRQS_OFF_DEBUG
24160- testl %ebx,%ebx /* swapgs needed? */
24161+ testl $1,%ebx /* swapgs needed? */
24162 jnz paranoid_restore
24163- testl $3,CS(%rsp)
24164+ testb $3,CS(%rsp)
24165 jnz paranoid_userspace
24166+#ifdef CONFIG_PAX_MEMORY_UDEREF
24167+ pax_exit_kernel
24168+ TRACE_IRQS_IRETQ 0
24169+ SWAPGS_UNSAFE_STACK
24170+ RESTORE_ALL 8
24171+ pax_force_retaddr_bts
24172+ jmp irq_return
24173+#endif
24174 paranoid_swapgs:
24175+#ifdef CONFIG_PAX_MEMORY_UDEREF
24176+ pax_exit_kernel_user
24177+#else
24178+ pax_exit_kernel
24179+#endif
24180 TRACE_IRQS_IRETQ 0
24181 SWAPGS_UNSAFE_STACK
24182 RESTORE_ALL 8
24183 jmp irq_return
24184 paranoid_restore:
24185+ pax_exit_kernel
24186 TRACE_IRQS_IRETQ_DEBUG 0
24187 RESTORE_ALL 8
24188+ pax_force_retaddr_bts
24189 jmp irq_return
24190 paranoid_userspace:
24191 GET_THREAD_INFO(%rcx)
24192@@ -1557,7 +2057,7 @@ paranoid_schedule:
24193 TRACE_IRQS_OFF
24194 jmp paranoid_userspace
24195 CFI_ENDPROC
24196-END(paranoid_exit)
24197+ENDPROC(paranoid_exit)
24198
24199 /*
24200 * Exception entry point. This expects an error code/orig_rax on the stack.
24201@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
24202 movq_cfi r14, R14+8
24203 movq_cfi r15, R15+8
24204 xorl %ebx,%ebx
24205- testl $3,CS+8(%rsp)
24206+ testb $3,CS+8(%rsp)
24207 je error_kernelspace
24208 error_swapgs:
24209 SWAPGS
24210 error_sti:
24211+#ifdef CONFIG_PAX_MEMORY_UDEREF
24212+ testb $3, CS+8(%rsp)
24213+ jnz 1f
24214+ pax_enter_kernel
24215+ jmp 2f
24216+1: pax_enter_kernel_user
24217+2:
24218+#else
24219+ pax_enter_kernel
24220+#endif
24221 TRACE_IRQS_OFF
24222+ pax_force_retaddr
24223 ret
24224
24225 /*
24226@@ -1616,7 +2127,7 @@ bstep_iret:
24227 movq %rcx,RIP+8(%rsp)
24228 jmp error_swapgs
24229 CFI_ENDPROC
24230-END(error_entry)
24231+ENDPROC(error_entry)
24232
24233
24234 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24235@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
24236 DISABLE_INTERRUPTS(CLBR_NONE)
24237 TRACE_IRQS_OFF
24238 GET_THREAD_INFO(%rcx)
24239- testl %eax,%eax
24240+ testl $1,%eax
24241 jne retint_kernel
24242 LOCKDEP_SYS_EXIT_IRQ
24243 movl TI_flags(%rcx),%edx
24244@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
24245 jnz retint_careful
24246 jmp retint_swapgs
24247 CFI_ENDPROC
24248-END(error_exit)
24249+ENDPROC(error_exit)
24250
24251 /*
24252 * Test if a given stack is an NMI stack or not.
24253@@ -1694,9 +2205,11 @@ ENTRY(nmi)
24254 * If %cs was not the kernel segment, then the NMI triggered in user
24255 * space, which means it is definitely not nested.
24256 */
24257+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24258+ je 1f
24259 cmpl $__KERNEL_CS, 16(%rsp)
24260 jne first_nmi
24261-
24262+1:
24263 /*
24264 * Check the special variable on the stack to see if NMIs are
24265 * executing.
24266@@ -1730,8 +2243,7 @@ nested_nmi:
24267
24268 1:
24269 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24270- leaq -1*8(%rsp), %rdx
24271- movq %rdx, %rsp
24272+ subq $8, %rsp
24273 CFI_ADJUST_CFA_OFFSET 1*8
24274 leaq -10*8(%rsp), %rdx
24275 pushq_cfi $__KERNEL_DS
24276@@ -1749,6 +2261,7 @@ nested_nmi_out:
24277 CFI_RESTORE rdx
24278
24279 /* No need to check faults here */
24280+# pax_force_retaddr_bts
24281 INTERRUPT_RETURN
24282
24283 CFI_RESTORE_STATE
24284@@ -1845,13 +2358,13 @@ end_repeat_nmi:
24285 subq $ORIG_RAX-R15, %rsp
24286 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24287 /*
24288- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24289+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24290 * as we should not be calling schedule in NMI context.
24291 * Even with normal interrupts enabled. An NMI should not be
24292 * setting NEED_RESCHED or anything that normal interrupts and
24293 * exceptions might do.
24294 */
24295- call save_paranoid
24296+ call save_paranoid_nmi
24297 DEFAULT_FRAME 0
24298
24299 /*
24300@@ -1861,9 +2374,9 @@ end_repeat_nmi:
24301 * NMI itself takes a page fault, the page fault that was preempted
24302 * will read the information from the NMI page fault and not the
24303 * origin fault. Save it off and restore it if it changes.
24304- * Use the r12 callee-saved register.
24305+ * Use the r13 callee-saved register.
24306 */
24307- movq %cr2, %r12
24308+ movq %cr2, %r13
24309
24310 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24311 movq %rsp,%rdi
24312@@ -1872,31 +2385,36 @@ end_repeat_nmi:
24313
24314 /* Did the NMI take a page fault? Restore cr2 if it did */
24315 movq %cr2, %rcx
24316- cmpq %rcx, %r12
24317+ cmpq %rcx, %r13
24318 je 1f
24319- movq %r12, %cr2
24320+ movq %r13, %cr2
24321 1:
24322
24323- testl %ebx,%ebx /* swapgs needed? */
24324+ testl $1,%ebx /* swapgs needed? */
24325 jnz nmi_restore
24326 nmi_swapgs:
24327 SWAPGS_UNSAFE_STACK
24328 nmi_restore:
24329+ pax_exit_kernel_nmi
24330 /* Pop the extra iret frame at once */
24331 RESTORE_ALL 6*8
24332+ testb $3, 8(%rsp)
24333+ jnz 1f
24334+ pax_force_retaddr_bts
24335+1:
24336
24337 /* Clear the NMI executing stack variable */
24338 movq $0, 5*8(%rsp)
24339 jmp irq_return
24340 CFI_ENDPROC
24341-END(nmi)
24342+ENDPROC(nmi)
24343
24344 ENTRY(ignore_sysret)
24345 CFI_STARTPROC
24346 mov $-ENOSYS,%eax
24347 sysret
24348 CFI_ENDPROC
24349-END(ignore_sysret)
24350+ENDPROC(ignore_sysret)
24351
24352 /*
24353 * End of kprobes section
24354diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24355index 1ffc32d..e52c745 100644
24356--- a/arch/x86/kernel/ftrace.c
24357+++ b/arch/x86/kernel/ftrace.c
24358@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24359 {
24360 unsigned char replaced[MCOUNT_INSN_SIZE];
24361
24362+ ip = ktla_ktva(ip);
24363+
24364 /*
24365 * Note: Due to modules and __init, code can
24366 * disappear and change, we need to protect against faulting
24367@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24368 unsigned char old[MCOUNT_INSN_SIZE];
24369 int ret;
24370
24371- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24372+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24373
24374 ftrace_update_func = ip;
24375 /* Make sure the breakpoints see the ftrace_update_func update */
24376@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24377 * kernel identity mapping to modify code.
24378 */
24379 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24380- ip = (unsigned long)__va(__pa_symbol(ip));
24381+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24382
24383 return probe_kernel_write((void *)ip, val, size);
24384 }
24385@@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
24386 unsigned char replaced[MCOUNT_INSN_SIZE];
24387 unsigned char brk = BREAKPOINT_INSTRUCTION;
24388
24389- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24390+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24391 return -EFAULT;
24392
24393 /* Make sure it is what we expect it to be */
24394@@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
24395 return ret;
24396
24397 fail_update:
24398- probe_kernel_write((void *)ip, &old_code[0], 1);
24399+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
24400 goto out;
24401 }
24402
24403diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24404index 85126cc..1bbce17 100644
24405--- a/arch/x86/kernel/head64.c
24406+++ b/arch/x86/kernel/head64.c
24407@@ -67,12 +67,12 @@ again:
24408 pgd = *pgd_p;
24409
24410 /*
24411- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24412- * critical -- __PAGE_OFFSET would point us back into the dynamic
24413+ * The use of __early_va rather than __va here is critical:
24414+ * __va would point us back into the dynamic
24415 * range and we might end up looping forever...
24416 */
24417 if (pgd)
24418- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24419+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24420 else {
24421 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24422 reset_early_page_tables();
24423@@ -82,13 +82,13 @@ again:
24424 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24425 for (i = 0; i < PTRS_PER_PUD; i++)
24426 pud_p[i] = 0;
24427- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24428+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24429 }
24430 pud_p += pud_index(address);
24431 pud = *pud_p;
24432
24433 if (pud)
24434- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24435+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24436 else {
24437 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24438 reset_early_page_tables();
24439@@ -98,7 +98,7 @@ again:
24440 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24441 for (i = 0; i < PTRS_PER_PMD; i++)
24442 pmd_p[i] = 0;
24443- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24444+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24445 }
24446 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24447 pmd_p[pmd_index(address)] = pmd;
24448@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24449 if (console_loglevel == 10)
24450 early_printk("Kernel alive\n");
24451
24452- clear_page(init_level4_pgt);
24453 /* set init_level4_pgt kernel high mapping*/
24454 init_level4_pgt[511] = early_level4_pgt[511];
24455
24456diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24457index f36bd42..56ee1534 100644
24458--- a/arch/x86/kernel/head_32.S
24459+++ b/arch/x86/kernel/head_32.S
24460@@ -26,6 +26,12 @@
24461 /* Physical address */
24462 #define pa(X) ((X) - __PAGE_OFFSET)
24463
24464+#ifdef CONFIG_PAX_KERNEXEC
24465+#define ta(X) (X)
24466+#else
24467+#define ta(X) ((X) - __PAGE_OFFSET)
24468+#endif
24469+
24470 /*
24471 * References to members of the new_cpu_data structure.
24472 */
24473@@ -55,11 +61,7 @@
24474 * and small than max_low_pfn, otherwise will waste some page table entries
24475 */
24476
24477-#if PTRS_PER_PMD > 1
24478-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24479-#else
24480-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24481-#endif
24482+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24483
24484 /* Number of possible pages in the lowmem region */
24485 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24486@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24487 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24488
24489 /*
24490+ * Real beginning of normal "text" segment
24491+ */
24492+ENTRY(stext)
24493+ENTRY(_stext)
24494+
24495+/*
24496 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24497 * %esi points to the real-mode code as a 32-bit pointer.
24498 * CS and DS must be 4 GB flat segments, but we don't depend on
24499@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24500 * can.
24501 */
24502 __HEAD
24503+
24504+#ifdef CONFIG_PAX_KERNEXEC
24505+ jmp startup_32
24506+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24507+.fill PAGE_SIZE-5,1,0xcc
24508+#endif
24509+
24510 ENTRY(startup_32)
24511 movl pa(stack_start),%ecx
24512
24513@@ -106,6 +121,59 @@ ENTRY(startup_32)
24514 2:
24515 leal -__PAGE_OFFSET(%ecx),%esp
24516
24517+#ifdef CONFIG_SMP
24518+ movl $pa(cpu_gdt_table),%edi
24519+ movl $__per_cpu_load,%eax
24520+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24521+ rorl $16,%eax
24522+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24523+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24524+ movl $__per_cpu_end - 1,%eax
24525+ subl $__per_cpu_start,%eax
24526+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24527+#endif
24528+
24529+#ifdef CONFIG_PAX_MEMORY_UDEREF
24530+ movl $NR_CPUS,%ecx
24531+ movl $pa(cpu_gdt_table),%edi
24532+1:
24533+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24534+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24535+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24536+ addl $PAGE_SIZE_asm,%edi
24537+ loop 1b
24538+#endif
24539+
24540+#ifdef CONFIG_PAX_KERNEXEC
24541+ movl $pa(boot_gdt),%edi
24542+ movl $__LOAD_PHYSICAL_ADDR,%eax
24543+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24544+ rorl $16,%eax
24545+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24546+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24547+ rorl $16,%eax
24548+
24549+ ljmp $(__BOOT_CS),$1f
24550+1:
24551+
24552+ movl $NR_CPUS,%ecx
24553+ movl $pa(cpu_gdt_table),%edi
24554+ addl $__PAGE_OFFSET,%eax
24555+1:
24556+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24557+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24558+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24559+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24560+ rorl $16,%eax
24561+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24562+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24563+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24564+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24565+ rorl $16,%eax
24566+ addl $PAGE_SIZE_asm,%edi
24567+ loop 1b
24568+#endif
24569+
24570 /*
24571 * Clear BSS first so that there are no surprises...
24572 */
24573@@ -201,8 +269,11 @@ ENTRY(startup_32)
24574 movl %eax, pa(max_pfn_mapped)
24575
24576 /* Do early initialization of the fixmap area */
24577- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24578- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24579+#ifdef CONFIG_COMPAT_VDSO
24580+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24581+#else
24582+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24583+#endif
24584 #else /* Not PAE */
24585
24586 page_pde_offset = (__PAGE_OFFSET >> 20);
24587@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24588 movl %eax, pa(max_pfn_mapped)
24589
24590 /* Do early initialization of the fixmap area */
24591- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24592- movl %eax,pa(initial_page_table+0xffc)
24593+#ifdef CONFIG_COMPAT_VDSO
24594+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24595+#else
24596+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24597+#endif
24598 #endif
24599
24600 #ifdef CONFIG_PARAVIRT
24601@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24602 cmpl $num_subarch_entries, %eax
24603 jae bad_subarch
24604
24605- movl pa(subarch_entries)(,%eax,4), %eax
24606- subl $__PAGE_OFFSET, %eax
24607- jmp *%eax
24608+ jmp *pa(subarch_entries)(,%eax,4)
24609
24610 bad_subarch:
24611 WEAK(lguest_entry)
24612@@ -261,10 +333,10 @@ WEAK(xen_entry)
24613 __INITDATA
24614
24615 subarch_entries:
24616- .long default_entry /* normal x86/PC */
24617- .long lguest_entry /* lguest hypervisor */
24618- .long xen_entry /* Xen hypervisor */
24619- .long default_entry /* Moorestown MID */
24620+ .long ta(default_entry) /* normal x86/PC */
24621+ .long ta(lguest_entry) /* lguest hypervisor */
24622+ .long ta(xen_entry) /* Xen hypervisor */
24623+ .long ta(default_entry) /* Moorestown MID */
24624 num_subarch_entries = (. - subarch_entries) / 4
24625 .previous
24626 #else
24627@@ -354,6 +426,7 @@ default_entry:
24628 movl pa(mmu_cr4_features),%eax
24629 movl %eax,%cr4
24630
24631+#ifdef CONFIG_X86_PAE
24632 testb $X86_CR4_PAE, %al # check if PAE is enabled
24633 jz enable_paging
24634
24635@@ -382,6 +455,9 @@ default_entry:
24636 /* Make changes effective */
24637 wrmsr
24638
24639+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24640+#endif
24641+
24642 enable_paging:
24643
24644 /*
24645@@ -449,14 +525,20 @@ is486:
24646 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24647 movl %eax,%ss # after changing gdt.
24648
24649- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24650+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24651 movl %eax,%ds
24652 movl %eax,%es
24653
24654 movl $(__KERNEL_PERCPU), %eax
24655 movl %eax,%fs # set this cpu's percpu
24656
24657+#ifdef CONFIG_CC_STACKPROTECTOR
24658 movl $(__KERNEL_STACK_CANARY),%eax
24659+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24660+ movl $(__USER_DS),%eax
24661+#else
24662+ xorl %eax,%eax
24663+#endif
24664 movl %eax,%gs
24665
24666 xorl %eax,%eax # Clear LDT
24667@@ -512,8 +594,11 @@ setup_once:
24668 * relocation. Manually set base address in stack canary
24669 * segment descriptor.
24670 */
24671- movl $gdt_page,%eax
24672+ movl $cpu_gdt_table,%eax
24673 movl $stack_canary,%ecx
24674+#ifdef CONFIG_SMP
24675+ addl $__per_cpu_load,%ecx
24676+#endif
24677 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24678 shrl $16, %ecx
24679 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24680@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24681 cmpl $2,(%esp) # X86_TRAP_NMI
24682 je is_nmi # Ignore NMI
24683
24684- cmpl $2,%ss:early_recursion_flag
24685+ cmpl $1,%ss:early_recursion_flag
24686 je hlt_loop
24687 incl %ss:early_recursion_flag
24688
24689@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24690 pushl (20+6*4)(%esp) /* trapno */
24691 pushl $fault_msg
24692 call printk
24693-#endif
24694 call dump_stack
24695+#endif
24696 hlt_loop:
24697 hlt
24698 jmp hlt_loop
24699@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24700 /* This is the default interrupt "handler" :-) */
24701 ALIGN
24702 ignore_int:
24703- cld
24704 #ifdef CONFIG_PRINTK
24705+ cmpl $2,%ss:early_recursion_flag
24706+ je hlt_loop
24707+ incl %ss:early_recursion_flag
24708+ cld
24709 pushl %eax
24710 pushl %ecx
24711 pushl %edx
24712@@ -617,9 +705,6 @@ ignore_int:
24713 movl $(__KERNEL_DS),%eax
24714 movl %eax,%ds
24715 movl %eax,%es
24716- cmpl $2,early_recursion_flag
24717- je hlt_loop
24718- incl early_recursion_flag
24719 pushl 16(%esp)
24720 pushl 24(%esp)
24721 pushl 32(%esp)
24722@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24723 /*
24724 * BSS section
24725 */
24726-__PAGE_ALIGNED_BSS
24727- .align PAGE_SIZE
24728 #ifdef CONFIG_X86_PAE
24729+.section .initial_pg_pmd,"a",@progbits
24730 initial_pg_pmd:
24731 .fill 1024*KPMDS,4,0
24732 #else
24733+.section .initial_page_table,"a",@progbits
24734 ENTRY(initial_page_table)
24735 .fill 1024,4,0
24736 #endif
24737+.section .initial_pg_fixmap,"a",@progbits
24738 initial_pg_fixmap:
24739 .fill 1024,4,0
24740+.section .empty_zero_page,"a",@progbits
24741 ENTRY(empty_zero_page)
24742 .fill 4096,1,0
24743+.section .swapper_pg_dir,"a",@progbits
24744 ENTRY(swapper_pg_dir)
24745+#ifdef CONFIG_X86_PAE
24746+ .fill 4,8,0
24747+#else
24748 .fill 1024,4,0
24749+#endif
24750
24751 /*
24752 * This starts the data section.
24753 */
24754 #ifdef CONFIG_X86_PAE
24755-__PAGE_ALIGNED_DATA
24756- /* Page-aligned for the benefit of paravirt? */
24757- .align PAGE_SIZE
24758+.section .initial_page_table,"a",@progbits
24759 ENTRY(initial_page_table)
24760 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24761 # if KPMDS == 3
24762@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24763 # error "Kernel PMDs should be 1, 2 or 3"
24764 # endif
24765 .align PAGE_SIZE /* needs to be page-sized too */
24766+
24767+#ifdef CONFIG_PAX_PER_CPU_PGD
24768+ENTRY(cpu_pgd)
24769+ .rept 2*NR_CPUS
24770+ .fill 4,8,0
24771+ .endr
24772+#endif
24773+
24774 #endif
24775
24776 .data
24777 .balign 4
24778 ENTRY(stack_start)
24779- .long init_thread_union+THREAD_SIZE
24780+ .long init_thread_union+THREAD_SIZE-8
24781
24782 __INITRODATA
24783 int_msg:
24784@@ -727,7 +825,7 @@ fault_msg:
24785 * segment size, and 32-bit linear address value:
24786 */
24787
24788- .data
24789+.section .rodata,"a",@progbits
24790 .globl boot_gdt_descr
24791 .globl idt_descr
24792
24793@@ -736,7 +834,7 @@ fault_msg:
24794 .word 0 # 32 bit align gdt_desc.address
24795 boot_gdt_descr:
24796 .word __BOOT_DS+7
24797- .long boot_gdt - __PAGE_OFFSET
24798+ .long pa(boot_gdt)
24799
24800 .word 0 # 32-bit align idt_desc.address
24801 idt_descr:
24802@@ -747,7 +845,7 @@ idt_descr:
24803 .word 0 # 32 bit align gdt_desc.address
24804 ENTRY(early_gdt_descr)
24805 .word GDT_ENTRIES*8-1
24806- .long gdt_page /* Overwritten for secondary CPUs */
24807+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24808
24809 /*
24810 * The boot_gdt must mirror the equivalent in setup.S and is
24811@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24812 .align L1_CACHE_BYTES
24813 ENTRY(boot_gdt)
24814 .fill GDT_ENTRY_BOOT_CS,8,0
24815- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24816- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24817+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24818+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24819+
24820+ .align PAGE_SIZE_asm
24821+ENTRY(cpu_gdt_table)
24822+ .rept NR_CPUS
24823+ .quad 0x0000000000000000 /* NULL descriptor */
24824+ .quad 0x0000000000000000 /* 0x0b reserved */
24825+ .quad 0x0000000000000000 /* 0x13 reserved */
24826+ .quad 0x0000000000000000 /* 0x1b reserved */
24827+
24828+#ifdef CONFIG_PAX_KERNEXEC
24829+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24830+#else
24831+ .quad 0x0000000000000000 /* 0x20 unused */
24832+#endif
24833+
24834+ .quad 0x0000000000000000 /* 0x28 unused */
24835+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24836+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24837+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24838+ .quad 0x0000000000000000 /* 0x4b reserved */
24839+ .quad 0x0000000000000000 /* 0x53 reserved */
24840+ .quad 0x0000000000000000 /* 0x5b reserved */
24841+
24842+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24843+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24844+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24845+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24846+
24847+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24848+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24849+
24850+ /*
24851+ * Segments used for calling PnP BIOS have byte granularity.
24852+ * The code segments and data segments have fixed 64k limits,
24853+ * the transfer segment sizes are set at run time.
24854+ */
24855+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24856+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24857+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24858+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24859+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24860+
24861+ /*
24862+ * The APM segments have byte granularity and their bases
24863+ * are set at run time. All have 64k limits.
24864+ */
24865+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24866+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24867+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24868+
24869+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24870+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24871+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24872+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24873+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24874+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24875+
24876+ /* Be sure this is zeroed to avoid false validations in Xen */
24877+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24878+ .endr
24879diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24880index a468c0a..c7dec74 100644
24881--- a/arch/x86/kernel/head_64.S
24882+++ b/arch/x86/kernel/head_64.S
24883@@ -20,6 +20,8 @@
24884 #include <asm/processor-flags.h>
24885 #include <asm/percpu.h>
24886 #include <asm/nops.h>
24887+#include <asm/cpufeature.h>
24888+#include <asm/alternative-asm.h>
24889
24890 #ifdef CONFIG_PARAVIRT
24891 #include <asm/asm-offsets.h>
24892@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24893 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24894 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24895 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24896+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24897+L3_VMALLOC_START = pud_index(VMALLOC_START)
24898+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24899+L3_VMALLOC_END = pud_index(VMALLOC_END)
24900+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24901+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24902
24903 .text
24904 __HEAD
24905@@ -89,11 +97,24 @@ startup_64:
24906 * Fixup the physical addresses in the page table
24907 */
24908 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24909+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24910+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24911+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24912+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24913+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24914
24915- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24916- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24917+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24918+#ifndef CONFIG_XEN
24919+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24920+#endif
24921+
24922+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24923+
24924+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24925+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24926
24927 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24928+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24929
24930 /*
24931 * Set up the identity mapping for the switchover. These
24932@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24933 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24934 1:
24935
24936- /* Enable PAE mode and PGE */
24937- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24938+ /* Enable PAE mode and PSE/PGE */
24939+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24940 movq %rcx, %cr4
24941
24942 /* Setup early boot stage 4 level pagetables. */
24943@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24944 movl $MSR_EFER, %ecx
24945 rdmsr
24946 btsl $_EFER_SCE, %eax /* Enable System Call */
24947- btl $20,%edi /* No Execute supported? */
24948+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24949 jnc 1f
24950 btsl $_EFER_NX, %eax
24951 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24952+#ifndef CONFIG_EFI
24953+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24954+#endif
24955+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24956+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24957+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24958+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24959+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24960+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24961 1: wrmsr /* Make changes effective */
24962
24963 /* Setup cr0 */
24964@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24965 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24966 * address given in m16:64.
24967 */
24968+ pax_set_fptr_mask
24969 movq initial_code(%rip),%rax
24970 pushq $0 # fake return address to stop unwinder
24971 pushq $__KERNEL_CS # set correct cs
24972@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24973 .quad INIT_PER_CPU_VAR(irq_stack_union)
24974
24975 GLOBAL(stack_start)
24976- .quad init_thread_union+THREAD_SIZE-8
24977+ .quad init_thread_union+THREAD_SIZE-16
24978 .word 0
24979 __FINITDATA
24980
24981@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24982 call dump_stack
24983 #ifdef CONFIG_KALLSYMS
24984 leaq early_idt_ripmsg(%rip),%rdi
24985- movq 40(%rsp),%rsi # %rip again
24986+ movq 88(%rsp),%rsi # %rip again
24987 call __print_symbol
24988 #endif
24989 #endif /* EARLY_PRINTK */
24990@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24991 early_recursion_flag:
24992 .long 0
24993
24994+ .section .rodata,"a",@progbits
24995 #ifdef CONFIG_EARLY_PRINTK
24996 early_idt_msg:
24997 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24998@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24999 NEXT_PAGE(early_dynamic_pgts)
25000 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25001
25002- .data
25003+ .section .rodata,"a",@progbits
25004
25005-#ifndef CONFIG_XEN
25006 NEXT_PAGE(init_level4_pgt)
25007- .fill 512,8,0
25008-#else
25009-NEXT_PAGE(init_level4_pgt)
25010- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25011 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25012 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25013+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
25014+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25015+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
25016+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25017+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25018+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25019 .org init_level4_pgt + L4_START_KERNEL*8, 0
25020 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25021 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25022
25023+#ifdef CONFIG_PAX_PER_CPU_PGD
25024+NEXT_PAGE(cpu_pgd)
25025+ .rept 2*NR_CPUS
25026+ .fill 512,8,0
25027+ .endr
25028+#endif
25029+
25030 NEXT_PAGE(level3_ident_pgt)
25031 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25032+#ifdef CONFIG_XEN
25033 .fill 511, 8, 0
25034+#else
25035+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25036+ .fill 510,8,0
25037+#endif
25038+
25039+NEXT_PAGE(level3_vmalloc_start_pgt)
25040+ .fill 512,8,0
25041+
25042+NEXT_PAGE(level3_vmalloc_end_pgt)
25043+ .fill 512,8,0
25044+
25045+NEXT_PAGE(level3_vmemmap_pgt)
25046+ .fill L3_VMEMMAP_START,8,0
25047+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25048+
25049 NEXT_PAGE(level2_ident_pgt)
25050- /* Since I easily can, map the first 1G.
25051+ /* Since I easily can, map the first 2G.
25052 * Don't set NX because code runs from these pages.
25053 */
25054- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25055-#endif
25056+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25057
25058 NEXT_PAGE(level3_kernel_pgt)
25059 .fill L3_START_KERNEL,8,0
25060@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
25061 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25062 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25063
25064+NEXT_PAGE(level2_vmemmap_pgt)
25065+ .fill 512,8,0
25066+
25067 NEXT_PAGE(level2_kernel_pgt)
25068 /*
25069 * 512 MB kernel mapping. We spend a full page on this pagetable
25070@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
25071 NEXT_PAGE(level2_fixmap_pgt)
25072 .fill 506,8,0
25073 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25074- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25075- .fill 5,8,0
25076+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25077+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25078+ .fill 4,8,0
25079
25080 NEXT_PAGE(level1_fixmap_pgt)
25081 .fill 512,8,0
25082
25083+NEXT_PAGE(level1_vsyscall_pgt)
25084+ .fill 512,8,0
25085+
25086 #undef PMDS
25087
25088- .data
25089+ .align PAGE_SIZE
25090+ENTRY(cpu_gdt_table)
25091+ .rept NR_CPUS
25092+ .quad 0x0000000000000000 /* NULL descriptor */
25093+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25094+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
25095+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
25096+ .quad 0x00cffb000000ffff /* __USER32_CS */
25097+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25098+ .quad 0x00affb000000ffff /* __USER_CS */
25099+
25100+#ifdef CONFIG_PAX_KERNEXEC
25101+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25102+#else
25103+ .quad 0x0 /* unused */
25104+#endif
25105+
25106+ .quad 0,0 /* TSS */
25107+ .quad 0,0 /* LDT */
25108+ .quad 0,0,0 /* three TLS descriptors */
25109+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
25110+ /* asm/segment.h:GDT_ENTRIES must match this */
25111+
25112+#ifdef CONFIG_PAX_MEMORY_UDEREF
25113+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25114+#else
25115+ .quad 0x0 /* unused */
25116+#endif
25117+
25118+ /* zero the remaining page */
25119+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25120+ .endr
25121+
25122 .align 16
25123 .globl early_gdt_descr
25124 early_gdt_descr:
25125 .word GDT_ENTRIES*8-1
25126 early_gdt_descr_base:
25127- .quad INIT_PER_CPU_VAR(gdt_page)
25128+ .quad cpu_gdt_table
25129
25130 ENTRY(phys_base)
25131 /* This must match the first entry in level2_kernel_pgt */
25132 .quad 0x0000000000000000
25133
25134 #include "../../x86/xen/xen-head.S"
25135-
25136- __PAGE_ALIGNED_BSS
25137+
25138+ .section .rodata,"a",@progbits
25139 NEXT_PAGE(empty_zero_page)
25140 .skip PAGE_SIZE
25141diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25142index 05fd74f..c3548b1 100644
25143--- a/arch/x86/kernel/i386_ksyms_32.c
25144+++ b/arch/x86/kernel/i386_ksyms_32.c
25145@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25146 EXPORT_SYMBOL(cmpxchg8b_emu);
25147 #endif
25148
25149+EXPORT_SYMBOL_GPL(cpu_gdt_table);
25150+
25151 /* Networking helper routines. */
25152 EXPORT_SYMBOL(csum_partial_copy_generic);
25153+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25154+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25155
25156 EXPORT_SYMBOL(__get_user_1);
25157 EXPORT_SYMBOL(__get_user_2);
25158@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25159 EXPORT_SYMBOL(___preempt_schedule_context);
25160 #endif
25161 #endif
25162+
25163+#ifdef CONFIG_PAX_KERNEXEC
25164+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25165+#endif
25166+
25167+#ifdef CONFIG_PAX_PER_CPU_PGD
25168+EXPORT_SYMBOL(cpu_pgd);
25169+#endif
25170diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25171index d5dd808..b6432cf 100644
25172--- a/arch/x86/kernel/i387.c
25173+++ b/arch/x86/kernel/i387.c
25174@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25175 static inline bool interrupted_user_mode(void)
25176 {
25177 struct pt_regs *regs = get_irq_regs();
25178- return regs && user_mode_vm(regs);
25179+ return regs && user_mode(regs);
25180 }
25181
25182 /*
25183diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25184index 2e977b5..5f2c273 100644
25185--- a/arch/x86/kernel/i8259.c
25186+++ b/arch/x86/kernel/i8259.c
25187@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25188 static void make_8259A_irq(unsigned int irq)
25189 {
25190 disable_irq_nosync(irq);
25191- io_apic_irqs &= ~(1<<irq);
25192+ io_apic_irqs &= ~(1UL<<irq);
25193 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25194 i8259A_chip.name);
25195 enable_irq(irq);
25196@@ -209,7 +209,7 @@ spurious_8259A_irq:
25197 "spurious 8259A interrupt: IRQ%d.\n", irq);
25198 spurious_irq_mask |= irqmask;
25199 }
25200- atomic_inc(&irq_err_count);
25201+ atomic_inc_unchecked(&irq_err_count);
25202 /*
25203 * Theoretically we do not have to handle this IRQ,
25204 * but in Linux this does not cause problems and is
25205@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
25206 /* (slave's support for AEOI in flat mode is to be investigated) */
25207 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25208
25209+ pax_open_kernel();
25210 if (auto_eoi)
25211 /*
25212 * In AEOI mode we just have to mask the interrupt
25213 * when acking.
25214 */
25215- i8259A_chip.irq_mask_ack = disable_8259A_irq;
25216+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25217 else
25218- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25219+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25220+ pax_close_kernel();
25221
25222 udelay(100); /* wait for 8259A to initialize */
25223
25224diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25225index a979b5b..1d6db75 100644
25226--- a/arch/x86/kernel/io_delay.c
25227+++ b/arch/x86/kernel/io_delay.c
25228@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25229 * Quirk table for systems that misbehave (lock up, etc.) if port
25230 * 0x80 is used:
25231 */
25232-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25233+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25234 {
25235 .callback = dmi_io_delay_0xed_port,
25236 .ident = "Compaq Presario V6000",
25237diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25238index 4ddaf66..49d5c18 100644
25239--- a/arch/x86/kernel/ioport.c
25240+++ b/arch/x86/kernel/ioport.c
25241@@ -6,6 +6,7 @@
25242 #include <linux/sched.h>
25243 #include <linux/kernel.h>
25244 #include <linux/capability.h>
25245+#include <linux/security.h>
25246 #include <linux/errno.h>
25247 #include <linux/types.h>
25248 #include <linux/ioport.h>
25249@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25250 return -EINVAL;
25251 if (turn_on && !capable(CAP_SYS_RAWIO))
25252 return -EPERM;
25253+#ifdef CONFIG_GRKERNSEC_IO
25254+ if (turn_on && grsec_disable_privio) {
25255+ gr_handle_ioperm();
25256+ return -ENODEV;
25257+ }
25258+#endif
25259
25260 /*
25261 * If it's the first ioperm() call in this thread's lifetime, set the
25262@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25263 * because the ->io_bitmap_max value must match the bitmap
25264 * contents:
25265 */
25266- tss = &per_cpu(init_tss, get_cpu());
25267+ tss = init_tss + get_cpu();
25268
25269 if (turn_on)
25270 bitmap_clear(t->io_bitmap_ptr, from, num);
25271@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25272 if (level > old) {
25273 if (!capable(CAP_SYS_RAWIO))
25274 return -EPERM;
25275+#ifdef CONFIG_GRKERNSEC_IO
25276+ if (grsec_disable_privio) {
25277+ gr_handle_iopl();
25278+ return -ENODEV;
25279+ }
25280+#endif
25281 }
25282 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25283 t->iopl = level << 12;
25284diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25285index d99f31d..1c0f466 100644
25286--- a/arch/x86/kernel/irq.c
25287+++ b/arch/x86/kernel/irq.c
25288@@ -21,7 +21,7 @@
25289 #define CREATE_TRACE_POINTS
25290 #include <asm/trace/irq_vectors.h>
25291
25292-atomic_t irq_err_count;
25293+atomic_unchecked_t irq_err_count;
25294
25295 /* Function pointer for generic interrupt vector handling */
25296 void (*x86_platform_ipi_callback)(void) = NULL;
25297@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25298 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
25299 seq_printf(p, " Machine check polls\n");
25300 #endif
25301- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25302+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25303 #if defined(CONFIG_X86_IO_APIC)
25304- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25305+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25306 #endif
25307 return 0;
25308 }
25309@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25310
25311 u64 arch_irq_stat(void)
25312 {
25313- u64 sum = atomic_read(&irq_err_count);
25314+ u64 sum = atomic_read_unchecked(&irq_err_count);
25315 return sum;
25316 }
25317
25318diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25319index d7fcbed..96e715a 100644
25320--- a/arch/x86/kernel/irq_32.c
25321+++ b/arch/x86/kernel/irq_32.c
25322@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25323
25324 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25325
25326+extern void gr_handle_kernel_exploit(void);
25327+
25328 int sysctl_panic_on_stackoverflow __read_mostly;
25329
25330 /* Debugging check for stack overflow: is there less than 1KB free? */
25331@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25332 __asm__ __volatile__("andl %%esp,%0" :
25333 "=r" (sp) : "0" (THREAD_SIZE - 1));
25334
25335- return sp < (sizeof(struct thread_info) + STACK_WARN);
25336+ return sp < STACK_WARN;
25337 }
25338
25339 static void print_stack_overflow(void)
25340 {
25341 printk(KERN_WARNING "low stack detected by irq handler\n");
25342 dump_stack();
25343+ gr_handle_kernel_exploit();
25344 if (sysctl_panic_on_stackoverflow)
25345 panic("low stack detected by irq handler - check messages\n");
25346 }
25347@@ -59,8 +62,8 @@ static inline void print_stack_overflow(void) { }
25348 * per-CPU IRQ handling contexts (thread information and stack)
25349 */
25350 union irq_ctx {
25351- struct thread_info tinfo;
25352- u32 stack[THREAD_SIZE/sizeof(u32)];
25353+ unsigned long previous_esp;
25354+ u32 stack[THREAD_SIZE/sizeof(u32)];
25355 } __attribute__((aligned(THREAD_SIZE)));
25356
25357 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
25358@@ -80,10 +83,9 @@ static void call_on_stack(void *func, void *stack)
25359 static inline int
25360 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25361 {
25362- union irq_ctx *curctx, *irqctx;
25363+ union irq_ctx *irqctx;
25364 u32 *isp, arg1, arg2;
25365
25366- curctx = (union irq_ctx *) current_thread_info();
25367 irqctx = __this_cpu_read(hardirq_ctx);
25368
25369 /*
25370@@ -92,13 +94,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25371 * handler) we can't do that and just have to keep using the
25372 * current stack (which is the irq stack already after all)
25373 */
25374- if (unlikely(curctx == irqctx))
25375+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
25376 return 0;
25377
25378 /* build the stack frame on the IRQ stack */
25379- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25380- irqctx->tinfo.task = curctx->tinfo.task;
25381- irqctx->tinfo.previous_esp = current_stack_pointer;
25382+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25383+ irqctx->previous_esp = current_stack_pointer;
25384+
25385+#ifdef CONFIG_PAX_MEMORY_UDEREF
25386+ __set_fs(MAKE_MM_SEG(0));
25387+#endif
25388
25389 if (unlikely(overflow))
25390 call_on_stack(print_stack_overflow, isp);
25391@@ -110,6 +115,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25392 : "0" (irq), "1" (desc), "2" (isp),
25393 "D" (desc->handle_irq)
25394 : "memory", "cc", "ecx");
25395+
25396+#ifdef CONFIG_PAX_MEMORY_UDEREF
25397+ __set_fs(current_thread_info()->addr_limit);
25398+#endif
25399+
25400 return 1;
25401 }
25402
25403@@ -118,48 +128,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25404 */
25405 void irq_ctx_init(int cpu)
25406 {
25407- union irq_ctx *irqctx;
25408-
25409 if (per_cpu(hardirq_ctx, cpu))
25410 return;
25411
25412- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25413- THREADINFO_GFP,
25414- THREAD_SIZE_ORDER));
25415- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25416- irqctx->tinfo.cpu = cpu;
25417- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25418-
25419- per_cpu(hardirq_ctx, cpu) = irqctx;
25420-
25421- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25422- THREADINFO_GFP,
25423- THREAD_SIZE_ORDER));
25424- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25425- irqctx->tinfo.cpu = cpu;
25426- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25427-
25428- per_cpu(softirq_ctx, cpu) = irqctx;
25429-
25430- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25431- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
25432+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25433+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25434 }
25435
25436 void do_softirq_own_stack(void)
25437 {
25438- struct thread_info *curctx;
25439 union irq_ctx *irqctx;
25440 u32 *isp;
25441
25442- curctx = current_thread_info();
25443 irqctx = __this_cpu_read(softirq_ctx);
25444- irqctx->tinfo.task = curctx->task;
25445- irqctx->tinfo.previous_esp = current_stack_pointer;
25446+ irqctx->previous_esp = current_stack_pointer;
25447
25448 /* build the stack frame on the softirq stack */
25449- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25450+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25451+
25452+#ifdef CONFIG_PAX_MEMORY_UDEREF
25453+ __set_fs(MAKE_MM_SEG(0));
25454+#endif
25455
25456 call_on_stack(__do_softirq, isp);
25457+
25458+#ifdef CONFIG_PAX_MEMORY_UDEREF
25459+ __set_fs(current_thread_info()->addr_limit);
25460+#endif
25461+
25462 }
25463
25464 bool handle_irq(unsigned irq, struct pt_regs *regs)
25465@@ -173,7 +169,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25466 if (unlikely(!desc))
25467 return false;
25468
25469- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25470+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25471 if (unlikely(overflow))
25472 print_stack_overflow();
25473 desc->handle_irq(irq, desc);
25474diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25475index 4d1c746..55a22d6 100644
25476--- a/arch/x86/kernel/irq_64.c
25477+++ b/arch/x86/kernel/irq_64.c
25478@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25479 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25480 EXPORT_PER_CPU_SYMBOL(irq_regs);
25481
25482+extern void gr_handle_kernel_exploit(void);
25483+
25484 int sysctl_panic_on_stackoverflow;
25485
25486 /*
25487@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25488 u64 estack_top, estack_bottom;
25489 u64 curbase = (u64)task_stack_page(current);
25490
25491- if (user_mode_vm(regs))
25492+ if (user_mode(regs))
25493 return;
25494
25495 if (regs->sp >= curbase + sizeof(struct thread_info) +
25496@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25497 irq_stack_top, irq_stack_bottom,
25498 estack_top, estack_bottom);
25499
25500+ gr_handle_kernel_exploit();
25501+
25502 if (sysctl_panic_on_stackoverflow)
25503 panic("low stack detected by irq handler - check messages\n");
25504 #endif
25505diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25506index 26d5a55..a01160a 100644
25507--- a/arch/x86/kernel/jump_label.c
25508+++ b/arch/x86/kernel/jump_label.c
25509@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25510 * Jump label is enabled for the first time.
25511 * So we expect a default_nop...
25512 */
25513- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25514+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25515 != 0))
25516 bug_at((void *)entry->code, __LINE__);
25517 } else {
25518@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25519 * ...otherwise expect an ideal_nop. Otherwise
25520 * something went horribly wrong.
25521 */
25522- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25523+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25524 != 0))
25525 bug_at((void *)entry->code, __LINE__);
25526 }
25527@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25528 * are converting the default nop to the ideal nop.
25529 */
25530 if (init) {
25531- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25532+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25533 bug_at((void *)entry->code, __LINE__);
25534 } else {
25535 code.jump = 0xe9;
25536 code.offset = entry->target -
25537 (entry->code + JUMP_LABEL_NOP_SIZE);
25538- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25539+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25540 bug_at((void *)entry->code, __LINE__);
25541 }
25542 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25543diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25544index 7ec1d5f..5a7d130 100644
25545--- a/arch/x86/kernel/kgdb.c
25546+++ b/arch/x86/kernel/kgdb.c
25547@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25548 #ifdef CONFIG_X86_32
25549 switch (regno) {
25550 case GDB_SS:
25551- if (!user_mode_vm(regs))
25552+ if (!user_mode(regs))
25553 *(unsigned long *)mem = __KERNEL_DS;
25554 break;
25555 case GDB_SP:
25556- if (!user_mode_vm(regs))
25557+ if (!user_mode(regs))
25558 *(unsigned long *)mem = kernel_stack_pointer(regs);
25559 break;
25560 case GDB_GS:
25561@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25562 bp->attr.bp_addr = breakinfo[breakno].addr;
25563 bp->attr.bp_len = breakinfo[breakno].len;
25564 bp->attr.bp_type = breakinfo[breakno].type;
25565- info->address = breakinfo[breakno].addr;
25566+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25567+ info->address = ktla_ktva(breakinfo[breakno].addr);
25568+ else
25569+ info->address = breakinfo[breakno].addr;
25570 info->len = breakinfo[breakno].len;
25571 info->type = breakinfo[breakno].type;
25572 val = arch_install_hw_breakpoint(bp);
25573@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25574 case 'k':
25575 /* clear the trace bit */
25576 linux_regs->flags &= ~X86_EFLAGS_TF;
25577- atomic_set(&kgdb_cpu_doing_single_step, -1);
25578+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25579
25580 /* set the trace bit if we're stepping */
25581 if (remcomInBuffer[0] == 's') {
25582 linux_regs->flags |= X86_EFLAGS_TF;
25583- atomic_set(&kgdb_cpu_doing_single_step,
25584+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25585 raw_smp_processor_id());
25586 }
25587
25588@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25589
25590 switch (cmd) {
25591 case DIE_DEBUG:
25592- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25593+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25594 if (user_mode(regs))
25595 return single_step_cont(regs, args);
25596 break;
25597@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25598 #endif /* CONFIG_DEBUG_RODATA */
25599
25600 bpt->type = BP_BREAKPOINT;
25601- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25602+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25603 BREAK_INSTR_SIZE);
25604 if (err)
25605 return err;
25606- err = probe_kernel_write((char *)bpt->bpt_addr,
25607+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25608 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25609 #ifdef CONFIG_DEBUG_RODATA
25610 if (!err)
25611@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25612 return -EBUSY;
25613 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25614 BREAK_INSTR_SIZE);
25615- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25616+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25617 if (err)
25618 return err;
25619 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25620@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25621 if (mutex_is_locked(&text_mutex))
25622 goto knl_write;
25623 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25624- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25625+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25626 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25627 goto knl_write;
25628 return err;
25629 knl_write:
25630 #endif /* CONFIG_DEBUG_RODATA */
25631- return probe_kernel_write((char *)bpt->bpt_addr,
25632+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25633 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25634 }
25635
25636diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25637index 79a3f96..6ba030a 100644
25638--- a/arch/x86/kernel/kprobes/core.c
25639+++ b/arch/x86/kernel/kprobes/core.c
25640@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25641 s32 raddr;
25642 } __packed *insn;
25643
25644- insn = (struct __arch_relative_insn *)from;
25645+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25646+
25647+ pax_open_kernel();
25648 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25649 insn->op = op;
25650+ pax_close_kernel();
25651 }
25652
25653 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25654@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25655 kprobe_opcode_t opcode;
25656 kprobe_opcode_t *orig_opcodes = opcodes;
25657
25658- if (search_exception_tables((unsigned long)opcodes))
25659+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25660 return 0; /* Page fault may occur on this address. */
25661
25662 retry:
25663@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25664 * for the first byte, we can recover the original instruction
25665 * from it and kp->opcode.
25666 */
25667- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25668+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25669 buf[0] = kp->opcode;
25670- return (unsigned long)buf;
25671+ return ktva_ktla((unsigned long)buf);
25672 }
25673
25674 /*
25675@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25676 /* Another subsystem puts a breakpoint, failed to recover */
25677 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25678 return 0;
25679+ pax_open_kernel();
25680 memcpy(dest, insn.kaddr, insn.length);
25681+ pax_close_kernel();
25682
25683 #ifdef CONFIG_X86_64
25684 if (insn_rip_relative(&insn)) {
25685@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25686 return 0;
25687 }
25688 disp = (u8 *) dest + insn_offset_displacement(&insn);
25689+ pax_open_kernel();
25690 *(s32 *) disp = (s32) newdisp;
25691+ pax_close_kernel();
25692 }
25693 #endif
25694 return insn.length;
25695@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25696 * nor set current_kprobe, because it doesn't use single
25697 * stepping.
25698 */
25699- regs->ip = (unsigned long)p->ainsn.insn;
25700+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25701 preempt_enable_no_resched();
25702 return;
25703 }
25704@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25705 regs->flags &= ~X86_EFLAGS_IF;
25706 /* single step inline if the instruction is an int3 */
25707 if (p->opcode == BREAKPOINT_INSTRUCTION)
25708- regs->ip = (unsigned long)p->addr;
25709+ regs->ip = ktla_ktva((unsigned long)p->addr);
25710 else
25711- regs->ip = (unsigned long)p->ainsn.insn;
25712+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25713 }
25714
25715 /*
25716@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25717 setup_singlestep(p, regs, kcb, 0);
25718 return 1;
25719 }
25720- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25721+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25722 /*
25723 * The breakpoint instruction was removed right
25724 * after we hit it. Another cpu has removed
25725@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25726 " movq %rax, 152(%rsp)\n"
25727 RESTORE_REGS_STRING
25728 " popfq\n"
25729+#ifdef KERNEXEC_PLUGIN
25730+ " btsq $63,(%rsp)\n"
25731+#endif
25732 #else
25733 " pushf\n"
25734 SAVE_REGS_STRING
25735@@ -779,7 +789,7 @@ static void __kprobes
25736 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25737 {
25738 unsigned long *tos = stack_addr(regs);
25739- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25740+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25741 unsigned long orig_ip = (unsigned long)p->addr;
25742 kprobe_opcode_t *insn = p->ainsn.insn;
25743
25744@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25745 struct die_args *args = data;
25746 int ret = NOTIFY_DONE;
25747
25748- if (args->regs && user_mode_vm(args->regs))
25749+ if (args->regs && user_mode(args->regs))
25750 return ret;
25751
25752 switch (val) {
25753diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25754index 898160b..758cde8 100644
25755--- a/arch/x86/kernel/kprobes/opt.c
25756+++ b/arch/x86/kernel/kprobes/opt.c
25757@@ -79,6 +79,7 @@ found:
25758 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25759 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25760 {
25761+ pax_open_kernel();
25762 #ifdef CONFIG_X86_64
25763 *addr++ = 0x48;
25764 *addr++ = 0xbf;
25765@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25766 *addr++ = 0xb8;
25767 #endif
25768 *(unsigned long *)addr = val;
25769+ pax_close_kernel();
25770 }
25771
25772 asm (
25773@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25774 * Verify if the address gap is in 2GB range, because this uses
25775 * a relative jump.
25776 */
25777- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25778+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25779 if (abs(rel) > 0x7fffffff)
25780 return -ERANGE;
25781
25782@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25783 op->optinsn.size = ret;
25784
25785 /* Copy arch-dep-instance from template */
25786- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25787+ pax_open_kernel();
25788+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25789+ pax_close_kernel();
25790
25791 /* Set probe information */
25792 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25793
25794 /* Set probe function call */
25795- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25796+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25797
25798 /* Set returning jmp instruction at the tail of out-of-line buffer */
25799- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25800+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25801 (u8 *)op->kp.addr + op->optinsn.size);
25802
25803 flush_icache_range((unsigned long) buf,
25804@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25805 WARN_ON(kprobe_disabled(&op->kp));
25806
25807 /* Backup instructions which will be replaced by jump address */
25808- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25809+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25810 RELATIVE_ADDR_SIZE);
25811
25812 insn_buf[0] = RELATIVEJUMP_OPCODE;
25813@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25814 /* This kprobe is really able to run optimized path. */
25815 op = container_of(p, struct optimized_kprobe, kp);
25816 /* Detour through copied instructions */
25817- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25818+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25819 if (!reenter)
25820 reset_current_kprobe();
25821 preempt_enable_no_resched();
25822diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25823index c2bedae..25e7ab6 100644
25824--- a/arch/x86/kernel/ksysfs.c
25825+++ b/arch/x86/kernel/ksysfs.c
25826@@ -184,7 +184,7 @@ out:
25827
25828 static struct kobj_attribute type_attr = __ATTR_RO(type);
25829
25830-static struct bin_attribute data_attr = {
25831+static bin_attribute_no_const data_attr __read_only = {
25832 .attr = {
25833 .name = "data",
25834 .mode = S_IRUGO,
25835diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25836index af1d14a..81ae763 100644
25837--- a/arch/x86/kernel/ldt.c
25838+++ b/arch/x86/kernel/ldt.c
25839@@ -20,6 +20,8 @@
25840 #include <asm/mmu_context.h>
25841 #include <asm/syscalls.h>
25842
25843+int sysctl_ldt16 = 0;
25844+
25845 #ifdef CONFIG_SMP
25846 static void flush_ldt(void *current_mm)
25847 {
25848@@ -66,13 +68,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25849 if (reload) {
25850 #ifdef CONFIG_SMP
25851 preempt_disable();
25852- load_LDT(pc);
25853+ load_LDT_nolock(pc);
25854 if (!cpumask_equal(mm_cpumask(current->mm),
25855 cpumask_of(smp_processor_id())))
25856 smp_call_function(flush_ldt, current->mm, 1);
25857 preempt_enable();
25858 #else
25859- load_LDT(pc);
25860+ load_LDT_nolock(pc);
25861 #endif
25862 }
25863 if (oldsize) {
25864@@ -94,7 +96,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25865 return err;
25866
25867 for (i = 0; i < old->size; i++)
25868- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25869+ write_ldt_entry(new->ldt, i, old->ldt + i);
25870 return 0;
25871 }
25872
25873@@ -115,6 +117,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25874 retval = copy_ldt(&mm->context, &old_mm->context);
25875 mutex_unlock(&old_mm->context.lock);
25876 }
25877+
25878+ if (tsk == current) {
25879+ mm->context.vdso = 0;
25880+
25881+#ifdef CONFIG_X86_32
25882+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25883+ mm->context.user_cs_base = 0UL;
25884+ mm->context.user_cs_limit = ~0UL;
25885+
25886+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25887+ cpus_clear(mm->context.cpu_user_cs_mask);
25888+#endif
25889+
25890+#endif
25891+#endif
25892+
25893+ }
25894+
25895 return retval;
25896 }
25897
25898@@ -229,12 +249,19 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25899 }
25900 }
25901
25902+#ifdef CONFIG_PAX_SEGMEXEC
25903+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25904+ error = -EINVAL;
25905+ goto out_unlock;
25906+ }
25907+#endif
25908+
25909 /*
25910 * On x86-64 we do not support 16-bit segments due to
25911 * IRET leaking the high bits of the kernel stack address.
25912 */
25913 #ifdef CONFIG_X86_64
25914- if (!ldt_info.seg_32bit) {
25915+ if (!ldt_info.seg_32bit && !sysctl_ldt16) {
25916 error = -EINVAL;
25917 goto out_unlock;
25918 }
25919diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25920index 1667b1d..16492c5 100644
25921--- a/arch/x86/kernel/machine_kexec_32.c
25922+++ b/arch/x86/kernel/machine_kexec_32.c
25923@@ -25,7 +25,7 @@
25924 #include <asm/cacheflush.h>
25925 #include <asm/debugreg.h>
25926
25927-static void set_idt(void *newidt, __u16 limit)
25928+static void set_idt(struct desc_struct *newidt, __u16 limit)
25929 {
25930 struct desc_ptr curidt;
25931
25932@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25933 }
25934
25935
25936-static void set_gdt(void *newgdt, __u16 limit)
25937+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25938 {
25939 struct desc_ptr curgdt;
25940
25941@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25942 }
25943
25944 control_page = page_address(image->control_code_page);
25945- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25946+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25947
25948 relocate_kernel_ptr = control_page;
25949 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25950diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25951index 18be189..4a9fe40 100644
25952--- a/arch/x86/kernel/module.c
25953+++ b/arch/x86/kernel/module.c
25954@@ -43,15 +43,60 @@ do { \
25955 } while (0)
25956 #endif
25957
25958-void *module_alloc(unsigned long size)
25959+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25960 {
25961- if (PAGE_ALIGN(size) > MODULES_LEN)
25962+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25963 return NULL;
25964 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25965- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25966+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25967 NUMA_NO_NODE, __builtin_return_address(0));
25968 }
25969
25970+void *module_alloc(unsigned long size)
25971+{
25972+
25973+#ifdef CONFIG_PAX_KERNEXEC
25974+ return __module_alloc(size, PAGE_KERNEL);
25975+#else
25976+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25977+#endif
25978+
25979+}
25980+
25981+#ifdef CONFIG_PAX_KERNEXEC
25982+#ifdef CONFIG_X86_32
25983+void *module_alloc_exec(unsigned long size)
25984+{
25985+ struct vm_struct *area;
25986+
25987+ if (size == 0)
25988+ return NULL;
25989+
25990+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25991+ return area ? area->addr : NULL;
25992+}
25993+EXPORT_SYMBOL(module_alloc_exec);
25994+
25995+void module_free_exec(struct module *mod, void *module_region)
25996+{
25997+ vunmap(module_region);
25998+}
25999+EXPORT_SYMBOL(module_free_exec);
26000+#else
26001+void module_free_exec(struct module *mod, void *module_region)
26002+{
26003+ module_free(mod, module_region);
26004+}
26005+EXPORT_SYMBOL(module_free_exec);
26006+
26007+void *module_alloc_exec(unsigned long size)
26008+{
26009+ return __module_alloc(size, PAGE_KERNEL_RX);
26010+}
26011+EXPORT_SYMBOL(module_alloc_exec);
26012+#endif
26013+#endif
26014+
26015 #ifdef CONFIG_X86_32
26016 int apply_relocate(Elf32_Shdr *sechdrs,
26017 const char *strtab,
26018@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26019 unsigned int i;
26020 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26021 Elf32_Sym *sym;
26022- uint32_t *location;
26023+ uint32_t *plocation, location;
26024
26025 DEBUGP("Applying relocate section %u to %u\n",
26026 relsec, sechdrs[relsec].sh_info);
26027 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26028 /* This is where to make the change */
26029- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26030- + rel[i].r_offset;
26031+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26032+ location = (uint32_t)plocation;
26033+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26034+ plocation = ktla_ktva((void *)plocation);
26035 /* This is the symbol it is referring to. Note that all
26036 undefined symbols have been resolved. */
26037 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26038@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26039 switch (ELF32_R_TYPE(rel[i].r_info)) {
26040 case R_386_32:
26041 /* We add the value into the location given */
26042- *location += sym->st_value;
26043+ pax_open_kernel();
26044+ *plocation += sym->st_value;
26045+ pax_close_kernel();
26046 break;
26047 case R_386_PC32:
26048 /* Add the value, subtract its position */
26049- *location += sym->st_value - (uint32_t)location;
26050+ pax_open_kernel();
26051+ *plocation += sym->st_value - location;
26052+ pax_close_kernel();
26053 break;
26054 default:
26055 pr_err("%s: Unknown relocation: %u\n",
26056@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26057 case R_X86_64_NONE:
26058 break;
26059 case R_X86_64_64:
26060+ pax_open_kernel();
26061 *(u64 *)loc = val;
26062+ pax_close_kernel();
26063 break;
26064 case R_X86_64_32:
26065+ pax_open_kernel();
26066 *(u32 *)loc = val;
26067+ pax_close_kernel();
26068 if (val != *(u32 *)loc)
26069 goto overflow;
26070 break;
26071 case R_X86_64_32S:
26072+ pax_open_kernel();
26073 *(s32 *)loc = val;
26074+ pax_close_kernel();
26075 if ((s64)val != *(s32 *)loc)
26076 goto overflow;
26077 break;
26078 case R_X86_64_PC32:
26079 val -= (u64)loc;
26080+ pax_open_kernel();
26081 *(u32 *)loc = val;
26082+ pax_close_kernel();
26083+
26084 #if 0
26085 if ((s64)val != *(s32 *)loc)
26086 goto overflow;
26087diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26088index 05266b5..3432443 100644
26089--- a/arch/x86/kernel/msr.c
26090+++ b/arch/x86/kernel/msr.c
26091@@ -37,6 +37,7 @@
26092 #include <linux/notifier.h>
26093 #include <linux/uaccess.h>
26094 #include <linux/gfp.h>
26095+#include <linux/grsecurity.h>
26096
26097 #include <asm/processor.h>
26098 #include <asm/msr.h>
26099@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26100 int err = 0;
26101 ssize_t bytes = 0;
26102
26103+#ifdef CONFIG_GRKERNSEC_KMEM
26104+ gr_handle_msr_write();
26105+ return -EPERM;
26106+#endif
26107+
26108 if (count % 8)
26109 return -EINVAL; /* Invalid chunk size */
26110
26111@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26112 err = -EBADF;
26113 break;
26114 }
26115+#ifdef CONFIG_GRKERNSEC_KMEM
26116+ gr_handle_msr_write();
26117+ return -EPERM;
26118+#endif
26119 if (copy_from_user(&regs, uregs, sizeof regs)) {
26120 err = -EFAULT;
26121 break;
26122@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26123 return notifier_from_errno(err);
26124 }
26125
26126-static struct notifier_block __refdata msr_class_cpu_notifier = {
26127+static struct notifier_block msr_class_cpu_notifier = {
26128 .notifier_call = msr_class_cpu_callback,
26129 };
26130
26131diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26132index 6fcb49c..5b3f4ff 100644
26133--- a/arch/x86/kernel/nmi.c
26134+++ b/arch/x86/kernel/nmi.c
26135@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
26136 return handled;
26137 }
26138
26139-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26140+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26141 {
26142 struct nmi_desc *desc = nmi_to_desc(type);
26143 unsigned long flags;
26144@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26145 * event confuses some handlers (kdump uses this flag)
26146 */
26147 if (action->flags & NMI_FLAG_FIRST)
26148- list_add_rcu(&action->list, &desc->head);
26149+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26150 else
26151- list_add_tail_rcu(&action->list, &desc->head);
26152+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26153
26154 spin_unlock_irqrestore(&desc->lock, flags);
26155 return 0;
26156@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26157 if (!strcmp(n->name, name)) {
26158 WARN(in_nmi(),
26159 "Trying to free NMI (%s) from NMI context!\n", n->name);
26160- list_del_rcu(&n->list);
26161+ pax_list_del_rcu((struct list_head *)&n->list);
26162 break;
26163 }
26164 }
26165@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
26166 dotraplinkage notrace __kprobes void
26167 do_nmi(struct pt_regs *regs, long error_code)
26168 {
26169+
26170+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26171+ if (!user_mode(regs)) {
26172+ unsigned long cs = regs->cs & 0xFFFF;
26173+ unsigned long ip = ktva_ktla(regs->ip);
26174+
26175+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26176+ regs->ip = ip;
26177+ }
26178+#endif
26179+
26180 nmi_nesting_preprocess(regs);
26181
26182 nmi_enter();
26183diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26184index 6d9582e..f746287 100644
26185--- a/arch/x86/kernel/nmi_selftest.c
26186+++ b/arch/x86/kernel/nmi_selftest.c
26187@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26188 {
26189 /* trap all the unknown NMIs we may generate */
26190 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26191- __initdata);
26192+ __initconst);
26193 }
26194
26195 static void __init cleanup_nmi_testsuite(void)
26196@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26197 unsigned long timeout;
26198
26199 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26200- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26201+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26202 nmi_fail = FAILURE;
26203 return;
26204 }
26205diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26206index bbb6c73..24a58ef 100644
26207--- a/arch/x86/kernel/paravirt-spinlocks.c
26208+++ b/arch/x86/kernel/paravirt-spinlocks.c
26209@@ -8,7 +8,7 @@
26210
26211 #include <asm/paravirt.h>
26212
26213-struct pv_lock_ops pv_lock_ops = {
26214+struct pv_lock_ops pv_lock_ops __read_only = {
26215 #ifdef CONFIG_SMP
26216 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26217 .unlock_kick = paravirt_nop,
26218diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26219index 1b10af8..45bfbec 100644
26220--- a/arch/x86/kernel/paravirt.c
26221+++ b/arch/x86/kernel/paravirt.c
26222@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
26223 {
26224 return x;
26225 }
26226+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26227+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26228+#endif
26229
26230 void __init default_banner(void)
26231 {
26232@@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26233
26234 if (opfunc == NULL)
26235 /* If there's no function, patch it with a ud2a (BUG) */
26236- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26237- else if (opfunc == _paravirt_nop)
26238+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26239+ else if (opfunc == (void *)_paravirt_nop)
26240 /* If the operation is a nop, then nop the callsite */
26241 ret = paravirt_patch_nop();
26242
26243 /* identity functions just return their single argument */
26244- else if (opfunc == _paravirt_ident_32)
26245+ else if (opfunc == (void *)_paravirt_ident_32)
26246 ret = paravirt_patch_ident_32(insnbuf, len);
26247- else if (opfunc == _paravirt_ident_64)
26248+ else if (opfunc == (void *)_paravirt_ident_64)
26249 ret = paravirt_patch_ident_64(insnbuf, len);
26250+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26251+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26252+ ret = paravirt_patch_ident_64(insnbuf, len);
26253+#endif
26254
26255 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26256 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26257@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26258 if (insn_len > len || start == NULL)
26259 insn_len = len;
26260 else
26261- memcpy(insnbuf, start, insn_len);
26262+ memcpy(insnbuf, ktla_ktva(start), insn_len);
26263
26264 return insn_len;
26265 }
26266@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26267 return this_cpu_read(paravirt_lazy_mode);
26268 }
26269
26270-struct pv_info pv_info = {
26271+struct pv_info pv_info __read_only = {
26272 .name = "bare hardware",
26273 .paravirt_enabled = 0,
26274 .kernel_rpl = 0,
26275@@ -310,16 +317,16 @@ struct pv_info pv_info = {
26276 #endif
26277 };
26278
26279-struct pv_init_ops pv_init_ops = {
26280+struct pv_init_ops pv_init_ops __read_only = {
26281 .patch = native_patch,
26282 };
26283
26284-struct pv_time_ops pv_time_ops = {
26285+struct pv_time_ops pv_time_ops __read_only = {
26286 .sched_clock = native_sched_clock,
26287 .steal_clock = native_steal_clock,
26288 };
26289
26290-__visible struct pv_irq_ops pv_irq_ops = {
26291+__visible struct pv_irq_ops pv_irq_ops __read_only = {
26292 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26293 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26294 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26295@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26296 #endif
26297 };
26298
26299-__visible struct pv_cpu_ops pv_cpu_ops = {
26300+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26301 .cpuid = native_cpuid,
26302 .get_debugreg = native_get_debugreg,
26303 .set_debugreg = native_set_debugreg,
26304@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
26305 .end_context_switch = paravirt_nop,
26306 };
26307
26308-struct pv_apic_ops pv_apic_ops = {
26309+struct pv_apic_ops pv_apic_ops __read_only= {
26310 #ifdef CONFIG_X86_LOCAL_APIC
26311 .startup_ipi_hook = paravirt_nop,
26312 #endif
26313 };
26314
26315-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26316+#ifdef CONFIG_X86_32
26317+#ifdef CONFIG_X86_PAE
26318+/* 64-bit pagetable entries */
26319+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26320+#else
26321 /* 32-bit pagetable entries */
26322 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26323+#endif
26324 #else
26325 /* 64-bit pagetable entries */
26326 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26327 #endif
26328
26329-struct pv_mmu_ops pv_mmu_ops = {
26330+struct pv_mmu_ops pv_mmu_ops __read_only = {
26331
26332 .read_cr2 = native_read_cr2,
26333 .write_cr2 = native_write_cr2,
26334@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26335 .make_pud = PTE_IDENT,
26336
26337 .set_pgd = native_set_pgd,
26338+ .set_pgd_batched = native_set_pgd_batched,
26339 #endif
26340 #endif /* PAGETABLE_LEVELS >= 3 */
26341
26342@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26343 },
26344
26345 .set_fixmap = native_set_fixmap,
26346+
26347+#ifdef CONFIG_PAX_KERNEXEC
26348+ .pax_open_kernel = native_pax_open_kernel,
26349+ .pax_close_kernel = native_pax_close_kernel,
26350+#endif
26351+
26352 };
26353
26354 EXPORT_SYMBOL_GPL(pv_time_ops);
26355diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26356index 299d493..2ccb0ee 100644
26357--- a/arch/x86/kernel/pci-calgary_64.c
26358+++ b/arch/x86/kernel/pci-calgary_64.c
26359@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
26360 tce_space = be64_to_cpu(readq(target));
26361 tce_space = tce_space & TAR_SW_BITS;
26362
26363- tce_space = tce_space & (~specified_table_size);
26364+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26365 info->tce_space = (u64 *)__va(tce_space);
26366 }
26367 }
26368diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26369index 35ccf75..7a15747 100644
26370--- a/arch/x86/kernel/pci-iommu_table.c
26371+++ b/arch/x86/kernel/pci-iommu_table.c
26372@@ -2,7 +2,7 @@
26373 #include <asm/iommu_table.h>
26374 #include <linux/string.h>
26375 #include <linux/kallsyms.h>
26376-
26377+#include <linux/sched.h>
26378
26379 #define DEBUG 1
26380
26381diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26382index 6c483ba..d10ce2f 100644
26383--- a/arch/x86/kernel/pci-swiotlb.c
26384+++ b/arch/x86/kernel/pci-swiotlb.c
26385@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26386 void *vaddr, dma_addr_t dma_addr,
26387 struct dma_attrs *attrs)
26388 {
26389- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26390+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26391 }
26392
26393 static struct dma_map_ops swiotlb_dma_ops = {
26394diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26395index ca7f0d5..8996469 100644
26396--- a/arch/x86/kernel/preempt.S
26397+++ b/arch/x86/kernel/preempt.S
26398@@ -3,12 +3,14 @@
26399 #include <asm/dwarf2.h>
26400 #include <asm/asm.h>
26401 #include <asm/calling.h>
26402+#include <asm/alternative-asm.h>
26403
26404 ENTRY(___preempt_schedule)
26405 CFI_STARTPROC
26406 SAVE_ALL
26407 call preempt_schedule
26408 RESTORE_ALL
26409+ pax_force_retaddr
26410 ret
26411 CFI_ENDPROC
26412
26413@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26414 SAVE_ALL
26415 call preempt_schedule_context
26416 RESTORE_ALL
26417+ pax_force_retaddr
26418 ret
26419 CFI_ENDPROC
26420
26421diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26422index 3fb8d95..254dc51 100644
26423--- a/arch/x86/kernel/process.c
26424+++ b/arch/x86/kernel/process.c
26425@@ -36,7 +36,8 @@
26426 * section. Since TSS's are completely CPU-local, we want them
26427 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26428 */
26429-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26430+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26431+EXPORT_SYMBOL(init_tss);
26432
26433 #ifdef CONFIG_X86_64
26434 static DEFINE_PER_CPU(unsigned char, is_idle);
26435@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26436 task_xstate_cachep =
26437 kmem_cache_create("task_xstate", xstate_size,
26438 __alignof__(union thread_xstate),
26439- SLAB_PANIC | SLAB_NOTRACK, NULL);
26440+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26441 }
26442
26443 /*
26444@@ -105,7 +106,7 @@ void exit_thread(void)
26445 unsigned long *bp = t->io_bitmap_ptr;
26446
26447 if (bp) {
26448- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26449+ struct tss_struct *tss = init_tss + get_cpu();
26450
26451 t->io_bitmap_ptr = NULL;
26452 clear_thread_flag(TIF_IO_BITMAP);
26453@@ -125,6 +126,9 @@ void flush_thread(void)
26454 {
26455 struct task_struct *tsk = current;
26456
26457+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26458+ loadsegment(gs, 0);
26459+#endif
26460 flush_ptrace_hw_breakpoint(tsk);
26461 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26462 drop_init_fpu(tsk);
26463@@ -271,7 +275,7 @@ static void __exit_idle(void)
26464 void exit_idle(void)
26465 {
26466 /* idle loop has pid 0 */
26467- if (current->pid)
26468+ if (task_pid_nr(current))
26469 return;
26470 __exit_idle();
26471 }
26472@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26473 return ret;
26474 }
26475 #endif
26476-void stop_this_cpu(void *dummy)
26477+__noreturn void stop_this_cpu(void *dummy)
26478 {
26479 local_irq_disable();
26480 /*
26481@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26482 }
26483 early_param("idle", idle_setup);
26484
26485-unsigned long arch_align_stack(unsigned long sp)
26486+#ifdef CONFIG_PAX_RANDKSTACK
26487+void pax_randomize_kstack(struct pt_regs *regs)
26488 {
26489- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26490- sp -= get_random_int() % 8192;
26491- return sp & ~0xf;
26492-}
26493+ struct thread_struct *thread = &current->thread;
26494+ unsigned long time;
26495
26496-unsigned long arch_randomize_brk(struct mm_struct *mm)
26497-{
26498- unsigned long range_end = mm->brk + 0x02000000;
26499- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26500-}
26501+ if (!randomize_va_space)
26502+ return;
26503+
26504+ if (v8086_mode(regs))
26505+ return;
26506
26507+ rdtscl(time);
26508+
26509+ /* P4 seems to return a 0 LSB, ignore it */
26510+#ifdef CONFIG_MPENTIUM4
26511+ time &= 0x3EUL;
26512+ time <<= 2;
26513+#elif defined(CONFIG_X86_64)
26514+ time &= 0xFUL;
26515+ time <<= 4;
26516+#else
26517+ time &= 0x1FUL;
26518+ time <<= 3;
26519+#endif
26520+
26521+ thread->sp0 ^= time;
26522+ load_sp0(init_tss + smp_processor_id(), thread);
26523+
26524+#ifdef CONFIG_X86_64
26525+ this_cpu_write(kernel_stack, thread->sp0);
26526+#endif
26527+}
26528+#endif
26529diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26530index 0de43e9..056b840 100644
26531--- a/arch/x86/kernel/process_32.c
26532+++ b/arch/x86/kernel/process_32.c
26533@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26534 unsigned long thread_saved_pc(struct task_struct *tsk)
26535 {
26536 return ((unsigned long *)tsk->thread.sp)[3];
26537+//XXX return tsk->thread.eip;
26538 }
26539
26540 void __show_regs(struct pt_regs *regs, int all)
26541@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26542 unsigned long sp;
26543 unsigned short ss, gs;
26544
26545- if (user_mode_vm(regs)) {
26546+ if (user_mode(regs)) {
26547 sp = regs->sp;
26548 ss = regs->ss & 0xffff;
26549- gs = get_user_gs(regs);
26550 } else {
26551 sp = kernel_stack_pointer(regs);
26552 savesegment(ss, ss);
26553- savesegment(gs, gs);
26554 }
26555+ gs = get_user_gs(regs);
26556
26557 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26558 (u16)regs->cs, regs->ip, regs->flags,
26559- smp_processor_id());
26560+ raw_smp_processor_id());
26561 print_symbol("EIP is at %s\n", regs->ip);
26562
26563 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26564@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26565 int copy_thread(unsigned long clone_flags, unsigned long sp,
26566 unsigned long arg, struct task_struct *p)
26567 {
26568- struct pt_regs *childregs = task_pt_regs(p);
26569+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26570 struct task_struct *tsk;
26571 int err;
26572
26573 p->thread.sp = (unsigned long) childregs;
26574 p->thread.sp0 = (unsigned long) (childregs+1);
26575+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26576
26577 if (unlikely(p->flags & PF_KTHREAD)) {
26578 /* kernel thread */
26579 memset(childregs, 0, sizeof(struct pt_regs));
26580 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26581- task_user_gs(p) = __KERNEL_STACK_CANARY;
26582- childregs->ds = __USER_DS;
26583- childregs->es = __USER_DS;
26584+ savesegment(gs, childregs->gs);
26585+ childregs->ds = __KERNEL_DS;
26586+ childregs->es = __KERNEL_DS;
26587 childregs->fs = __KERNEL_PERCPU;
26588 childregs->bx = sp; /* function */
26589 childregs->bp = arg;
26590@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26591 struct thread_struct *prev = &prev_p->thread,
26592 *next = &next_p->thread;
26593 int cpu = smp_processor_id();
26594- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26595+ struct tss_struct *tss = init_tss + cpu;
26596 fpu_switch_t fpu;
26597
26598 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26599@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26600 */
26601 lazy_save_gs(prev->gs);
26602
26603+#ifdef CONFIG_PAX_MEMORY_UDEREF
26604+ __set_fs(task_thread_info(next_p)->addr_limit);
26605+#endif
26606+
26607 /*
26608 * Load the per-thread Thread-Local Storage descriptor.
26609 */
26610@@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26611 */
26612 arch_end_context_switch(next_p);
26613
26614+ this_cpu_write(current_task, next_p);
26615+ this_cpu_write(current_tinfo, &next_p->tinfo);
26616+
26617 /*
26618 * Restore %gs if needed (which is common)
26619 */
26620@@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26621
26622 switch_fpu_finish(next_p, fpu);
26623
26624- this_cpu_write(current_task, next_p);
26625-
26626 return prev_p;
26627 }
26628
26629@@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
26630 } while (count++ < 16);
26631 return 0;
26632 }
26633-
26634diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26635index 9c0280f..5bbb1c0 100644
26636--- a/arch/x86/kernel/process_64.c
26637+++ b/arch/x86/kernel/process_64.c
26638@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26639 struct pt_regs *childregs;
26640 struct task_struct *me = current;
26641
26642- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26643+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26644 childregs = task_pt_regs(p);
26645 p->thread.sp = (unsigned long) childregs;
26646 p->thread.usersp = me->thread.usersp;
26647+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26648 set_tsk_thread_flag(p, TIF_FORK);
26649 p->thread.fpu_counter = 0;
26650 p->thread.io_bitmap_ptr = NULL;
26651@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26652 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26653 savesegment(es, p->thread.es);
26654 savesegment(ds, p->thread.ds);
26655+ savesegment(ss, p->thread.ss);
26656+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26657 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26658
26659 if (unlikely(p->flags & PF_KTHREAD)) {
26660@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26661 struct thread_struct *prev = &prev_p->thread;
26662 struct thread_struct *next = &next_p->thread;
26663 int cpu = smp_processor_id();
26664- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26665+ struct tss_struct *tss = init_tss + cpu;
26666 unsigned fsindex, gsindex;
26667 fpu_switch_t fpu;
26668
26669@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26670 if (unlikely(next->ds | prev->ds))
26671 loadsegment(ds, next->ds);
26672
26673+ savesegment(ss, prev->ss);
26674+ if (unlikely(next->ss != prev->ss))
26675+ loadsegment(ss, next->ss);
26676
26677 /* We must save %fs and %gs before load_TLS() because
26678 * %fs and %gs may be cleared by load_TLS().
26679@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26680 prev->usersp = this_cpu_read(old_rsp);
26681 this_cpu_write(old_rsp, next->usersp);
26682 this_cpu_write(current_task, next_p);
26683+ this_cpu_write(current_tinfo, &next_p->tinfo);
26684
26685 /*
26686 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26687@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26688 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26689 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26690
26691- this_cpu_write(kernel_stack,
26692- (unsigned long)task_stack_page(next_p) +
26693- THREAD_SIZE - KERNEL_STACK_OFFSET);
26694+ this_cpu_write(kernel_stack, next->sp0);
26695
26696 /*
26697 * Now maybe reload the debug registers and handle I/O bitmaps
26698@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26699 if (!p || p == current || p->state == TASK_RUNNING)
26700 return 0;
26701 stack = (unsigned long)task_stack_page(p);
26702- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26703+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26704 return 0;
26705 fp = *(u64 *)(p->thread.sp);
26706 do {
26707- if (fp < (unsigned long)stack ||
26708- fp >= (unsigned long)stack+THREAD_SIZE)
26709+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26710 return 0;
26711 ip = *(u64 *)(fp+8);
26712 if (!in_sched_functions(ip))
26713diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26714index 7461f50..1334029 100644
26715--- a/arch/x86/kernel/ptrace.c
26716+++ b/arch/x86/kernel/ptrace.c
26717@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26718 {
26719 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26720 unsigned long sp = (unsigned long)&regs->sp;
26721- struct thread_info *tinfo;
26722
26723- if (context == (sp & ~(THREAD_SIZE - 1)))
26724+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26725 return sp;
26726
26727- tinfo = (struct thread_info *)context;
26728- if (tinfo->previous_esp)
26729- return tinfo->previous_esp;
26730+ sp = *(unsigned long *)context;
26731+ if (sp)
26732+ return sp;
26733
26734 return (unsigned long)regs;
26735 }
26736@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26737 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26738 {
26739 int i;
26740- int dr7 = 0;
26741+ unsigned long dr7 = 0;
26742 struct arch_hw_breakpoint *info;
26743
26744 for (i = 0; i < HBP_NUM; i++) {
26745@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26746 unsigned long addr, unsigned long data)
26747 {
26748 int ret;
26749- unsigned long __user *datap = (unsigned long __user *)data;
26750+ unsigned long __user *datap = (__force unsigned long __user *)data;
26751
26752 switch (request) {
26753 /* read the word at location addr in the USER area. */
26754@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26755 if ((int) addr < 0)
26756 return -EIO;
26757 ret = do_get_thread_area(child, addr,
26758- (struct user_desc __user *)data);
26759+ (__force struct user_desc __user *) data);
26760 break;
26761
26762 case PTRACE_SET_THREAD_AREA:
26763 if ((int) addr < 0)
26764 return -EIO;
26765 ret = do_set_thread_area(child, addr,
26766- (struct user_desc __user *)data, 0);
26767+ (__force struct user_desc __user *) data, 0);
26768 break;
26769 #endif
26770
26771@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26772
26773 #ifdef CONFIG_X86_64
26774
26775-static struct user_regset x86_64_regsets[] __read_mostly = {
26776+static user_regset_no_const x86_64_regsets[] __read_only = {
26777 [REGSET_GENERAL] = {
26778 .core_note_type = NT_PRSTATUS,
26779 .n = sizeof(struct user_regs_struct) / sizeof(long),
26780@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26781 #endif /* CONFIG_X86_64 */
26782
26783 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26784-static struct user_regset x86_32_regsets[] __read_mostly = {
26785+static user_regset_no_const x86_32_regsets[] __read_only = {
26786 [REGSET_GENERAL] = {
26787 .core_note_type = NT_PRSTATUS,
26788 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26789@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26790 */
26791 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26792
26793-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26794+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26795 {
26796 #ifdef CONFIG_X86_64
26797 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26798@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26799 memset(info, 0, sizeof(*info));
26800 info->si_signo = SIGTRAP;
26801 info->si_code = si_code;
26802- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26803+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26804 }
26805
26806 void user_single_step_siginfo(struct task_struct *tsk,
26807@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26808 # define IS_IA32 0
26809 #endif
26810
26811+#ifdef CONFIG_GRKERNSEC_SETXID
26812+extern void gr_delayed_cred_worker(void);
26813+#endif
26814+
26815 /*
26816 * We must return the syscall number to actually look up in the table.
26817 * This can be -1L to skip running any syscall at all.
26818@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26819
26820 user_exit();
26821
26822+#ifdef CONFIG_GRKERNSEC_SETXID
26823+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26824+ gr_delayed_cred_worker();
26825+#endif
26826+
26827 /*
26828 * If we stepped into a sysenter/syscall insn, it trapped in
26829 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26830@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26831 */
26832 user_exit();
26833
26834+#ifdef CONFIG_GRKERNSEC_SETXID
26835+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26836+ gr_delayed_cred_worker();
26837+#endif
26838+
26839 audit_syscall_exit(regs);
26840
26841 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26842diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26843index 2f355d2..e75ed0a 100644
26844--- a/arch/x86/kernel/pvclock.c
26845+++ b/arch/x86/kernel/pvclock.c
26846@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26847 reset_hung_task_detector();
26848 }
26849
26850-static atomic64_t last_value = ATOMIC64_INIT(0);
26851+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26852
26853 void pvclock_resume(void)
26854 {
26855- atomic64_set(&last_value, 0);
26856+ atomic64_set_unchecked(&last_value, 0);
26857 }
26858
26859 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26860@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26861 * updating at the same time, and one of them could be slightly behind,
26862 * making the assumption that last_value always go forward fail to hold.
26863 */
26864- last = atomic64_read(&last_value);
26865+ last = atomic64_read_unchecked(&last_value);
26866 do {
26867 if (ret < last)
26868 return last;
26869- last = atomic64_cmpxchg(&last_value, last, ret);
26870+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26871 } while (unlikely(last != ret));
26872
26873 return ret;
26874diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26875index c752cb4..866c432 100644
26876--- a/arch/x86/kernel/reboot.c
26877+++ b/arch/x86/kernel/reboot.c
26878@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26879
26880 void __noreturn machine_real_restart(unsigned int type)
26881 {
26882+
26883+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26884+ struct desc_struct *gdt;
26885+#endif
26886+
26887 local_irq_disable();
26888
26889 /*
26890@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26891
26892 /* Jump to the identity-mapped low memory code */
26893 #ifdef CONFIG_X86_32
26894- asm volatile("jmpl *%0" : :
26895+
26896+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26897+ gdt = get_cpu_gdt_table(smp_processor_id());
26898+ pax_open_kernel();
26899+#ifdef CONFIG_PAX_MEMORY_UDEREF
26900+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26901+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26902+ loadsegment(ds, __KERNEL_DS);
26903+ loadsegment(es, __KERNEL_DS);
26904+ loadsegment(ss, __KERNEL_DS);
26905+#endif
26906+#ifdef CONFIG_PAX_KERNEXEC
26907+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26908+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26909+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26910+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26911+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26912+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26913+#endif
26914+ pax_close_kernel();
26915+#endif
26916+
26917+ asm volatile("ljmpl *%0" : :
26918 "rm" (real_mode_header->machine_real_restart_asm),
26919 "a" (type));
26920 #else
26921@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26922 * try to force a triple fault and then cycle between hitting the keyboard
26923 * controller and doing that
26924 */
26925-static void native_machine_emergency_restart(void)
26926+static void __noreturn native_machine_emergency_restart(void)
26927 {
26928 int i;
26929 int attempt = 0;
26930@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26931 #endif
26932 }
26933
26934-static void __machine_emergency_restart(int emergency)
26935+static void __noreturn __machine_emergency_restart(int emergency)
26936 {
26937 reboot_emergency = emergency;
26938 machine_ops.emergency_restart();
26939 }
26940
26941-static void native_machine_restart(char *__unused)
26942+static void __noreturn native_machine_restart(char *__unused)
26943 {
26944 pr_notice("machine restart\n");
26945
26946@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26947 __machine_emergency_restart(0);
26948 }
26949
26950-static void native_machine_halt(void)
26951+static void __noreturn native_machine_halt(void)
26952 {
26953 /* Stop other cpus and apics */
26954 machine_shutdown();
26955@@ -618,7 +645,7 @@ static void native_machine_halt(void)
26956 stop_this_cpu(NULL);
26957 }
26958
26959-static void native_machine_power_off(void)
26960+static void __noreturn native_machine_power_off(void)
26961 {
26962 if (pm_power_off) {
26963 if (!reboot_force)
26964@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26965 }
26966 /* A fallback in case there is no PM info available */
26967 tboot_shutdown(TB_SHUTDOWN_HALT);
26968+ unreachable();
26969 }
26970
26971-struct machine_ops machine_ops = {
26972+struct machine_ops machine_ops __read_only = {
26973 .power_off = native_machine_power_off,
26974 .shutdown = native_machine_shutdown,
26975 .emergency_restart = native_machine_emergency_restart,
26976diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26977index c8e41e9..64049ef 100644
26978--- a/arch/x86/kernel/reboot_fixups_32.c
26979+++ b/arch/x86/kernel/reboot_fixups_32.c
26980@@ -57,7 +57,7 @@ struct device_fixup {
26981 unsigned int vendor;
26982 unsigned int device;
26983 void (*reboot_fixup)(struct pci_dev *);
26984-};
26985+} __do_const;
26986
26987 /*
26988 * PCI ids solely used for fixups_table go here
26989diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26990index 3fd2c69..a444264 100644
26991--- a/arch/x86/kernel/relocate_kernel_64.S
26992+++ b/arch/x86/kernel/relocate_kernel_64.S
26993@@ -96,8 +96,7 @@ relocate_kernel:
26994
26995 /* jump to identity mapped page */
26996 addq $(identity_mapped - relocate_kernel), %r8
26997- pushq %r8
26998- ret
26999+ jmp *%r8
27000
27001 identity_mapped:
27002 /* set return address to 0 if not preserving context */
27003diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27004index ce72964..be8aea7 100644
27005--- a/arch/x86/kernel/setup.c
27006+++ b/arch/x86/kernel/setup.c
27007@@ -110,6 +110,7 @@
27008 #include <asm/mce.h>
27009 #include <asm/alternative.h>
27010 #include <asm/prom.h>
27011+#include <asm/boot.h>
27012
27013 /*
27014 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27015@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27016 #endif
27017
27018
27019-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27020-__visible unsigned long mmu_cr4_features;
27021+#ifdef CONFIG_X86_64
27022+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27023+#elif defined(CONFIG_X86_PAE)
27024+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27025 #else
27026-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27027+__visible unsigned long mmu_cr4_features __read_only;
27028 #endif
27029
27030+void set_in_cr4(unsigned long mask)
27031+{
27032+ unsigned long cr4 = read_cr4();
27033+
27034+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27035+ return;
27036+
27037+ pax_open_kernel();
27038+ mmu_cr4_features |= mask;
27039+ pax_close_kernel();
27040+
27041+ if (trampoline_cr4_features)
27042+ *trampoline_cr4_features = mmu_cr4_features;
27043+ cr4 |= mask;
27044+ write_cr4(cr4);
27045+}
27046+EXPORT_SYMBOL(set_in_cr4);
27047+
27048+void clear_in_cr4(unsigned long mask)
27049+{
27050+ unsigned long cr4 = read_cr4();
27051+
27052+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27053+ return;
27054+
27055+ pax_open_kernel();
27056+ mmu_cr4_features &= ~mask;
27057+ pax_close_kernel();
27058+
27059+ if (trampoline_cr4_features)
27060+ *trampoline_cr4_features = mmu_cr4_features;
27061+ cr4 &= ~mask;
27062+ write_cr4(cr4);
27063+}
27064+EXPORT_SYMBOL(clear_in_cr4);
27065+
27066 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27067 int bootloader_type, bootloader_version;
27068
27069@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27070 * area (640->1Mb) as ram even though it is not.
27071 * take them out.
27072 */
27073- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27074+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27075
27076 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27077 }
27078@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27079 /* called before trim_bios_range() to spare extra sanitize */
27080 static void __init e820_add_kernel_range(void)
27081 {
27082- u64 start = __pa_symbol(_text);
27083+ u64 start = __pa_symbol(ktla_ktva(_text));
27084 u64 size = __pa_symbol(_end) - start;
27085
27086 /*
27087@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27088
27089 void __init setup_arch(char **cmdline_p)
27090 {
27091+#ifdef CONFIG_X86_32
27092+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27093+#else
27094 memblock_reserve(__pa_symbol(_text),
27095 (unsigned long)__bss_stop - (unsigned long)_text);
27096+#endif
27097
27098 early_reserve_initrd();
27099
27100@@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
27101
27102 if (!boot_params.hdr.root_flags)
27103 root_mountflags &= ~MS_RDONLY;
27104- init_mm.start_code = (unsigned long) _text;
27105- init_mm.end_code = (unsigned long) _etext;
27106+ init_mm.start_code = ktla_ktva((unsigned long) _text);
27107+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
27108 init_mm.end_data = (unsigned long) _edata;
27109 init_mm.brk = _brk_end;
27110
27111- code_resource.start = __pa_symbol(_text);
27112- code_resource.end = __pa_symbol(_etext)-1;
27113- data_resource.start = __pa_symbol(_etext);
27114+ code_resource.start = __pa_symbol(ktla_ktva(_text));
27115+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27116+ data_resource.start = __pa_symbol(_sdata);
27117 data_resource.end = __pa_symbol(_edata)-1;
27118 bss_resource.start = __pa_symbol(__bss_start);
27119 bss_resource.end = __pa_symbol(__bss_stop)-1;
27120diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27121index 5cdff03..80fa283 100644
27122--- a/arch/x86/kernel/setup_percpu.c
27123+++ b/arch/x86/kernel/setup_percpu.c
27124@@ -21,19 +21,17 @@
27125 #include <asm/cpu.h>
27126 #include <asm/stackprotector.h>
27127
27128-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27129+#ifdef CONFIG_SMP
27130+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27131 EXPORT_PER_CPU_SYMBOL(cpu_number);
27132+#endif
27133
27134-#ifdef CONFIG_X86_64
27135 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27136-#else
27137-#define BOOT_PERCPU_OFFSET 0
27138-#endif
27139
27140 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27141 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27142
27143-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27144+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27145 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27146 };
27147 EXPORT_SYMBOL(__per_cpu_offset);
27148@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27149 {
27150 #ifdef CONFIG_NEED_MULTIPLE_NODES
27151 pg_data_t *last = NULL;
27152- unsigned int cpu;
27153+ int cpu;
27154
27155 for_each_possible_cpu(cpu) {
27156 int node = early_cpu_to_node(cpu);
27157@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27158 {
27159 #ifdef CONFIG_X86_32
27160 struct desc_struct gdt;
27161+ unsigned long base = per_cpu_offset(cpu);
27162
27163- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27164- 0x2 | DESCTYPE_S, 0x8);
27165- gdt.s = 1;
27166+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27167+ 0x83 | DESCTYPE_S, 0xC);
27168 write_gdt_entry(get_cpu_gdt_table(cpu),
27169 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27170 #endif
27171@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27172 /* alrighty, percpu areas up and running */
27173 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27174 for_each_possible_cpu(cpu) {
27175+#ifdef CONFIG_CC_STACKPROTECTOR
27176+#ifdef CONFIG_X86_32
27177+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
27178+#endif
27179+#endif
27180 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27181 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27182 per_cpu(cpu_number, cpu) = cpu;
27183@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27184 */
27185 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27186 #endif
27187+#ifdef CONFIG_CC_STACKPROTECTOR
27188+#ifdef CONFIG_X86_32
27189+ if (!cpu)
27190+ per_cpu(stack_canary.canary, cpu) = canary;
27191+#endif
27192+#endif
27193 /*
27194 * Up to this point, the boot CPU has been using .init.data
27195 * area. Reload any changed state for the boot CPU.
27196diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27197index 9e5de68..16c53cb 100644
27198--- a/arch/x86/kernel/signal.c
27199+++ b/arch/x86/kernel/signal.c
27200@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27201 * Align the stack pointer according to the i386 ABI,
27202 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27203 */
27204- sp = ((sp + 4) & -16ul) - 4;
27205+ sp = ((sp - 12) & -16ul) - 4;
27206 #else /* !CONFIG_X86_32 */
27207 sp = round_down(sp, 16) - 8;
27208 #endif
27209@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27210 }
27211
27212 if (current->mm->context.vdso)
27213- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
27214+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
27215 else
27216- restorer = &frame->retcode;
27217+ restorer = (void __user *)&frame->retcode;
27218 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27219 restorer = ksig->ka.sa.sa_restorer;
27220
27221@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27222 * reasons and because gdb uses it as a signature to notice
27223 * signal handler stack frames.
27224 */
27225- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27226+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27227
27228 if (err)
27229 return -EFAULT;
27230@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27231 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27232
27233 /* Set up to return from userspace. */
27234- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27235+ if (current->mm->context.vdso)
27236+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27237+ else
27238+ restorer = (void __user *)&frame->retcode;
27239 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27240 restorer = ksig->ka.sa.sa_restorer;
27241 put_user_ex(restorer, &frame->pretcode);
27242@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27243 * reasons and because gdb uses it as a signature to notice
27244 * signal handler stack frames.
27245 */
27246- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27247+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27248 } put_user_catch(err);
27249
27250 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27251@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27252 {
27253 int usig = signr_convert(ksig->sig);
27254 sigset_t *set = sigmask_to_save();
27255- compat_sigset_t *cset = (compat_sigset_t *) set;
27256+ sigset_t sigcopy;
27257+ compat_sigset_t *cset;
27258+
27259+ sigcopy = *set;
27260+
27261+ cset = (compat_sigset_t *) &sigcopy;
27262
27263 /* Set up the stack frame */
27264 if (is_ia32_frame()) {
27265@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27266 } else if (is_x32_frame()) {
27267 return x32_setup_rt_frame(ksig, cset, regs);
27268 } else {
27269- return __setup_rt_frame(ksig->sig, ksig, set, regs);
27270+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27271 }
27272 }
27273
27274diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27275index 7c3a5a6..f0a8961 100644
27276--- a/arch/x86/kernel/smp.c
27277+++ b/arch/x86/kernel/smp.c
27278@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27279
27280 __setup("nonmi_ipi", nonmi_ipi_setup);
27281
27282-struct smp_ops smp_ops = {
27283+struct smp_ops smp_ops __read_only = {
27284 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27285 .smp_prepare_cpus = native_smp_prepare_cpus,
27286 .smp_cpus_done = native_smp_cpus_done,
27287diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27288index a32da80..30c97f1 100644
27289--- a/arch/x86/kernel/smpboot.c
27290+++ b/arch/x86/kernel/smpboot.c
27291@@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
27292
27293 enable_start_cpu0 = 0;
27294
27295-#ifdef CONFIG_X86_32
27296- /* switch away from the initial page table */
27297- load_cr3(swapper_pg_dir);
27298- __flush_tlb_all();
27299-#endif
27300-
27301 /* otherwise gcc will move up smp_processor_id before the cpu_init */
27302 barrier();
27303+
27304+ /* switch away from the initial page table */
27305+#ifdef CONFIG_PAX_PER_CPU_PGD
27306+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27307+ __flush_tlb_all();
27308+#elif defined(CONFIG_X86_32)
27309+ load_cr3(swapper_pg_dir);
27310+ __flush_tlb_all();
27311+#endif
27312+
27313 /*
27314 * Check TSC synchronization with the BP:
27315 */
27316@@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27317 alternatives_enable_smp();
27318
27319 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27320- (THREAD_SIZE + task_stack_page(idle))) - 1);
27321+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27322 per_cpu(current_task, cpu) = idle;
27323+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27324
27325 #ifdef CONFIG_X86_32
27326 /* Stack for startup_32 can be just as for start_secondary onwards */
27327@@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27328 #else
27329 clear_tsk_thread_flag(idle, TIF_FORK);
27330 initial_gs = per_cpu_offset(cpu);
27331- per_cpu(kernel_stack, cpu) =
27332- (unsigned long)task_stack_page(idle) -
27333- KERNEL_STACK_OFFSET + THREAD_SIZE;
27334+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27335 #endif
27336+
27337+ pax_open_kernel();
27338 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27339+ pax_close_kernel();
27340+
27341 initial_code = (unsigned long)start_secondary;
27342 stack_start = idle->thread.sp;
27343
27344@@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27345 /* the FPU context is blank, nobody can own it */
27346 __cpu_disable_lazy_restore(cpu);
27347
27348+#ifdef CONFIG_PAX_PER_CPU_PGD
27349+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27350+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27351+ KERNEL_PGD_PTRS);
27352+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27353+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27354+ KERNEL_PGD_PTRS);
27355+#endif
27356+
27357 err = do_boot_cpu(apicid, cpu, tidle);
27358 if (err) {
27359 pr_debug("do_boot_cpu failed %d\n", err);
27360diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27361index 9b4d51d..5d28b58 100644
27362--- a/arch/x86/kernel/step.c
27363+++ b/arch/x86/kernel/step.c
27364@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27365 struct desc_struct *desc;
27366 unsigned long base;
27367
27368- seg &= ~7UL;
27369+ seg >>= 3;
27370
27371 mutex_lock(&child->mm->context.lock);
27372- if (unlikely((seg >> 3) >= child->mm->context.size))
27373+ if (unlikely(seg >= child->mm->context.size))
27374 addr = -1L; /* bogus selector, access would fault */
27375 else {
27376 desc = child->mm->context.ldt + seg;
27377@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27378 addr += base;
27379 }
27380 mutex_unlock(&child->mm->context.lock);
27381- }
27382+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27383+ addr = ktla_ktva(addr);
27384
27385 return addr;
27386 }
27387@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27388 unsigned char opcode[15];
27389 unsigned long addr = convert_ip_to_linear(child, regs);
27390
27391+ if (addr == -EINVAL)
27392+ return 0;
27393+
27394 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27395 for (i = 0; i < copied; i++) {
27396 switch (opcode[i]) {
27397diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27398new file mode 100644
27399index 0000000..5877189
27400--- /dev/null
27401+++ b/arch/x86/kernel/sys_i386_32.c
27402@@ -0,0 +1,189 @@
27403+/*
27404+ * This file contains various random system calls that
27405+ * have a non-standard calling sequence on the Linux/i386
27406+ * platform.
27407+ */
27408+
27409+#include <linux/errno.h>
27410+#include <linux/sched.h>
27411+#include <linux/mm.h>
27412+#include <linux/fs.h>
27413+#include <linux/smp.h>
27414+#include <linux/sem.h>
27415+#include <linux/msg.h>
27416+#include <linux/shm.h>
27417+#include <linux/stat.h>
27418+#include <linux/syscalls.h>
27419+#include <linux/mman.h>
27420+#include <linux/file.h>
27421+#include <linux/utsname.h>
27422+#include <linux/ipc.h>
27423+#include <linux/elf.h>
27424+
27425+#include <linux/uaccess.h>
27426+#include <linux/unistd.h>
27427+
27428+#include <asm/syscalls.h>
27429+
27430+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27431+{
27432+ unsigned long pax_task_size = TASK_SIZE;
27433+
27434+#ifdef CONFIG_PAX_SEGMEXEC
27435+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27436+ pax_task_size = SEGMEXEC_TASK_SIZE;
27437+#endif
27438+
27439+ if (flags & MAP_FIXED)
27440+ if (len > pax_task_size || addr > pax_task_size - len)
27441+ return -EINVAL;
27442+
27443+ return 0;
27444+}
27445+
27446+/*
27447+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27448+ */
27449+static unsigned long get_align_mask(void)
27450+{
27451+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27452+ return 0;
27453+
27454+ if (!(current->flags & PF_RANDOMIZE))
27455+ return 0;
27456+
27457+ return va_align.mask;
27458+}
27459+
27460+unsigned long
27461+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27462+ unsigned long len, unsigned long pgoff, unsigned long flags)
27463+{
27464+ struct mm_struct *mm = current->mm;
27465+ struct vm_area_struct *vma;
27466+ unsigned long pax_task_size = TASK_SIZE;
27467+ struct vm_unmapped_area_info info;
27468+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27469+
27470+#ifdef CONFIG_PAX_SEGMEXEC
27471+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27472+ pax_task_size = SEGMEXEC_TASK_SIZE;
27473+#endif
27474+
27475+ pax_task_size -= PAGE_SIZE;
27476+
27477+ if (len > pax_task_size)
27478+ return -ENOMEM;
27479+
27480+ if (flags & MAP_FIXED)
27481+ return addr;
27482+
27483+#ifdef CONFIG_PAX_RANDMMAP
27484+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27485+#endif
27486+
27487+ if (addr) {
27488+ addr = PAGE_ALIGN(addr);
27489+ if (pax_task_size - len >= addr) {
27490+ vma = find_vma(mm, addr);
27491+ if (check_heap_stack_gap(vma, addr, len, offset))
27492+ return addr;
27493+ }
27494+ }
27495+
27496+ info.flags = 0;
27497+ info.length = len;
27498+ info.align_mask = filp ? get_align_mask() : 0;
27499+ info.align_offset = pgoff << PAGE_SHIFT;
27500+ info.threadstack_offset = offset;
27501+
27502+#ifdef CONFIG_PAX_PAGEEXEC
27503+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27504+ info.low_limit = 0x00110000UL;
27505+ info.high_limit = mm->start_code;
27506+
27507+#ifdef CONFIG_PAX_RANDMMAP
27508+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27509+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27510+#endif
27511+
27512+ if (info.low_limit < info.high_limit) {
27513+ addr = vm_unmapped_area(&info);
27514+ if (!IS_ERR_VALUE(addr))
27515+ return addr;
27516+ }
27517+ } else
27518+#endif
27519+
27520+ info.low_limit = mm->mmap_base;
27521+ info.high_limit = pax_task_size;
27522+
27523+ return vm_unmapped_area(&info);
27524+}
27525+
27526+unsigned long
27527+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27528+ const unsigned long len, const unsigned long pgoff,
27529+ const unsigned long flags)
27530+{
27531+ struct vm_area_struct *vma;
27532+ struct mm_struct *mm = current->mm;
27533+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27534+ struct vm_unmapped_area_info info;
27535+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27536+
27537+#ifdef CONFIG_PAX_SEGMEXEC
27538+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27539+ pax_task_size = SEGMEXEC_TASK_SIZE;
27540+#endif
27541+
27542+ pax_task_size -= PAGE_SIZE;
27543+
27544+ /* requested length too big for entire address space */
27545+ if (len > pax_task_size)
27546+ return -ENOMEM;
27547+
27548+ if (flags & MAP_FIXED)
27549+ return addr;
27550+
27551+#ifdef CONFIG_PAX_PAGEEXEC
27552+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27553+ goto bottomup;
27554+#endif
27555+
27556+#ifdef CONFIG_PAX_RANDMMAP
27557+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27558+#endif
27559+
27560+ /* requesting a specific address */
27561+ if (addr) {
27562+ addr = PAGE_ALIGN(addr);
27563+ if (pax_task_size - len >= addr) {
27564+ vma = find_vma(mm, addr);
27565+ if (check_heap_stack_gap(vma, addr, len, offset))
27566+ return addr;
27567+ }
27568+ }
27569+
27570+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27571+ info.length = len;
27572+ info.low_limit = PAGE_SIZE;
27573+ info.high_limit = mm->mmap_base;
27574+ info.align_mask = filp ? get_align_mask() : 0;
27575+ info.align_offset = pgoff << PAGE_SHIFT;
27576+ info.threadstack_offset = offset;
27577+
27578+ addr = vm_unmapped_area(&info);
27579+ if (!(addr & ~PAGE_MASK))
27580+ return addr;
27581+ VM_BUG_ON(addr != -ENOMEM);
27582+
27583+bottomup:
27584+ /*
27585+ * A failed mmap() very likely causes application failure,
27586+ * so fall back to the bottom-up function here. This scenario
27587+ * can happen with large stack limits and large mmap()
27588+ * allocations.
27589+ */
27590+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27591+}
27592diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27593index 30277e2..5664a29 100644
27594--- a/arch/x86/kernel/sys_x86_64.c
27595+++ b/arch/x86/kernel/sys_x86_64.c
27596@@ -81,8 +81,8 @@ out:
27597 return error;
27598 }
27599
27600-static void find_start_end(unsigned long flags, unsigned long *begin,
27601- unsigned long *end)
27602+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27603+ unsigned long *begin, unsigned long *end)
27604 {
27605 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27606 unsigned long new_begin;
27607@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27608 *begin = new_begin;
27609 }
27610 } else {
27611- *begin = current->mm->mmap_legacy_base;
27612+ *begin = mm->mmap_legacy_base;
27613 *end = TASK_SIZE;
27614 }
27615 }
27616@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27617 struct vm_area_struct *vma;
27618 struct vm_unmapped_area_info info;
27619 unsigned long begin, end;
27620+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27621
27622 if (flags & MAP_FIXED)
27623 return addr;
27624
27625- find_start_end(flags, &begin, &end);
27626+ find_start_end(mm, flags, &begin, &end);
27627
27628 if (len > end)
27629 return -ENOMEM;
27630
27631+#ifdef CONFIG_PAX_RANDMMAP
27632+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27633+#endif
27634+
27635 if (addr) {
27636 addr = PAGE_ALIGN(addr);
27637 vma = find_vma(mm, addr);
27638- if (end - len >= addr &&
27639- (!vma || addr + len <= vma->vm_start))
27640+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27641 return addr;
27642 }
27643
27644@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27645 info.high_limit = end;
27646 info.align_mask = filp ? get_align_mask() : 0;
27647 info.align_offset = pgoff << PAGE_SHIFT;
27648+ info.threadstack_offset = offset;
27649 return vm_unmapped_area(&info);
27650 }
27651
27652@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27653 struct mm_struct *mm = current->mm;
27654 unsigned long addr = addr0;
27655 struct vm_unmapped_area_info info;
27656+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27657
27658 /* requested length too big for entire address space */
27659 if (len > TASK_SIZE)
27660@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27661 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27662 goto bottomup;
27663
27664+#ifdef CONFIG_PAX_RANDMMAP
27665+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27666+#endif
27667+
27668 /* requesting a specific address */
27669 if (addr) {
27670 addr = PAGE_ALIGN(addr);
27671 vma = find_vma(mm, addr);
27672- if (TASK_SIZE - len >= addr &&
27673- (!vma || addr + len <= vma->vm_start))
27674+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27675 return addr;
27676 }
27677
27678@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27679 info.high_limit = mm->mmap_base;
27680 info.align_mask = filp ? get_align_mask() : 0;
27681 info.align_offset = pgoff << PAGE_SHIFT;
27682+ info.threadstack_offset = offset;
27683 addr = vm_unmapped_area(&info);
27684 if (!(addr & ~PAGE_MASK))
27685 return addr;
27686diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27687index 91a4496..bb87552 100644
27688--- a/arch/x86/kernel/tboot.c
27689+++ b/arch/x86/kernel/tboot.c
27690@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27691
27692 void tboot_shutdown(u32 shutdown_type)
27693 {
27694- void (*shutdown)(void);
27695+ void (* __noreturn shutdown)(void);
27696
27697 if (!tboot_enabled())
27698 return;
27699@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27700
27701 switch_to_tboot_pt();
27702
27703- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27704+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27705 shutdown();
27706
27707 /* should not reach here */
27708@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27709 return -ENODEV;
27710 }
27711
27712-static atomic_t ap_wfs_count;
27713+static atomic_unchecked_t ap_wfs_count;
27714
27715 static int tboot_wait_for_aps(int num_aps)
27716 {
27717@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27718 {
27719 switch (action) {
27720 case CPU_DYING:
27721- atomic_inc(&ap_wfs_count);
27722+ atomic_inc_unchecked(&ap_wfs_count);
27723 if (num_online_cpus() == 1)
27724- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27725+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27726 return NOTIFY_BAD;
27727 break;
27728 }
27729@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27730
27731 tboot_create_trampoline();
27732
27733- atomic_set(&ap_wfs_count, 0);
27734+ atomic_set_unchecked(&ap_wfs_count, 0);
27735 register_hotcpu_notifier(&tboot_cpu_notifier);
27736
27737 #ifdef CONFIG_DEBUG_FS
27738diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27739index 24d3c91..d06b473 100644
27740--- a/arch/x86/kernel/time.c
27741+++ b/arch/x86/kernel/time.c
27742@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27743 {
27744 unsigned long pc = instruction_pointer(regs);
27745
27746- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27747+ if (!user_mode(regs) && in_lock_functions(pc)) {
27748 #ifdef CONFIG_FRAME_POINTER
27749- return *(unsigned long *)(regs->bp + sizeof(long));
27750+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27751 #else
27752 unsigned long *sp =
27753 (unsigned long *)kernel_stack_pointer(regs);
27754@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27755 * or above a saved flags. Eflags has bits 22-31 zero,
27756 * kernel addresses don't.
27757 */
27758+
27759+#ifdef CONFIG_PAX_KERNEXEC
27760+ return ktla_ktva(sp[0]);
27761+#else
27762 if (sp[0] >> 22)
27763 return sp[0];
27764 if (sp[1] >> 22)
27765 return sp[1];
27766 #endif
27767+
27768+#endif
27769 }
27770 return pc;
27771 }
27772diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27773index f7fec09..9991981 100644
27774--- a/arch/x86/kernel/tls.c
27775+++ b/arch/x86/kernel/tls.c
27776@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27777 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27778 return -EINVAL;
27779
27780+#ifdef CONFIG_PAX_SEGMEXEC
27781+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27782+ return -EINVAL;
27783+#endif
27784+
27785 set_tls_desc(p, idx, &info, 1);
27786
27787 return 0;
27788@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27789
27790 if (kbuf)
27791 info = kbuf;
27792- else if (__copy_from_user(infobuf, ubuf, count))
27793+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27794 return -EFAULT;
27795 else
27796 info = infobuf;
27797diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27798index 1c113db..287b42e 100644
27799--- a/arch/x86/kernel/tracepoint.c
27800+++ b/arch/x86/kernel/tracepoint.c
27801@@ -9,11 +9,11 @@
27802 #include <linux/atomic.h>
27803
27804 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27805-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27806+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27807 (unsigned long) trace_idt_table };
27808
27809 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27810-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27811+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27812
27813 static int trace_irq_vector_refcount;
27814 static DEFINE_MUTEX(irq_vector_mutex);
27815diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27816index 57409f6..b505597 100644
27817--- a/arch/x86/kernel/traps.c
27818+++ b/arch/x86/kernel/traps.c
27819@@ -66,7 +66,7 @@
27820 #include <asm/proto.h>
27821
27822 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27823-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27824+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27825 #else
27826 #include <asm/processor-flags.h>
27827 #include <asm/setup.h>
27828@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27829 #endif
27830
27831 /* Must be page-aligned because the real IDT is used in a fixmap. */
27832-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27833+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27834
27835 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27836 EXPORT_SYMBOL_GPL(used_vectors);
27837@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27838 }
27839
27840 static int __kprobes
27841-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27842+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27843 struct pt_regs *regs, long error_code)
27844 {
27845 #ifdef CONFIG_X86_32
27846- if (regs->flags & X86_VM_MASK) {
27847+ if (v8086_mode(regs)) {
27848 /*
27849 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27850 * On nmi (interrupt 2), do_trap should not be called.
27851@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27852 return -1;
27853 }
27854 #endif
27855- if (!user_mode(regs)) {
27856+ if (!user_mode_novm(regs)) {
27857 if (!fixup_exception(regs)) {
27858 tsk->thread.error_code = error_code;
27859 tsk->thread.trap_nr = trapnr;
27860+
27861+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27862+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27863+ str = "PAX: suspicious stack segment fault";
27864+#endif
27865+
27866 die(str, regs, error_code);
27867 }
27868+
27869+#ifdef CONFIG_PAX_REFCOUNT
27870+ if (trapnr == X86_TRAP_OF)
27871+ pax_report_refcount_overflow(regs);
27872+#endif
27873+
27874 return 0;
27875 }
27876
27877@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27878 }
27879
27880 static void __kprobes
27881-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27882+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27883 long error_code, siginfo_t *info)
27884 {
27885 struct task_struct *tsk = current;
27886@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27887 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27888 printk_ratelimit()) {
27889 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27890- tsk->comm, tsk->pid, str,
27891+ tsk->comm, task_pid_nr(tsk), str,
27892 regs->ip, regs->sp, error_code);
27893 print_vma_addr(" in ", regs->ip);
27894 pr_cont("\n");
27895@@ -251,6 +263,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27896 tsk->thread.error_code = error_code;
27897 tsk->thread.trap_nr = X86_TRAP_DF;
27898
27899+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27900+ if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27901+ die("grsec: kernel stack overflow detected", regs, error_code);
27902+#endif
27903+
27904 #ifdef CONFIG_DOUBLEFAULT
27905 df_debug(regs, error_code);
27906 #endif
27907@@ -273,7 +290,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27908 conditional_sti(regs);
27909
27910 #ifdef CONFIG_X86_32
27911- if (regs->flags & X86_VM_MASK) {
27912+ if (v8086_mode(regs)) {
27913 local_irq_enable();
27914 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27915 goto exit;
27916@@ -281,18 +298,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27917 #endif
27918
27919 tsk = current;
27920- if (!user_mode(regs)) {
27921+ if (!user_mode_novm(regs)) {
27922 if (fixup_exception(regs))
27923 goto exit;
27924
27925 tsk->thread.error_code = error_code;
27926 tsk->thread.trap_nr = X86_TRAP_GP;
27927 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27928- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27929+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27930+
27931+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27932+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27933+ die("PAX: suspicious general protection fault", regs, error_code);
27934+ else
27935+#endif
27936+
27937 die("general protection fault", regs, error_code);
27938+ }
27939 goto exit;
27940 }
27941
27942+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27943+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27944+ struct mm_struct *mm = tsk->mm;
27945+ unsigned long limit;
27946+
27947+ down_write(&mm->mmap_sem);
27948+ limit = mm->context.user_cs_limit;
27949+ if (limit < TASK_SIZE) {
27950+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27951+ up_write(&mm->mmap_sem);
27952+ return;
27953+ }
27954+ up_write(&mm->mmap_sem);
27955+ }
27956+#endif
27957+
27958 tsk->thread.error_code = error_code;
27959 tsk->thread.trap_nr = X86_TRAP_GP;
27960
27961@@ -453,7 +494,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27962 /* It's safe to allow irq's after DR6 has been saved */
27963 preempt_conditional_sti(regs);
27964
27965- if (regs->flags & X86_VM_MASK) {
27966+ if (v8086_mode(regs)) {
27967 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27968 X86_TRAP_DB);
27969 preempt_conditional_cli(regs);
27970@@ -468,7 +509,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27971 * We already checked v86 mode above, so we can check for kernel mode
27972 * by just checking the CPL of CS.
27973 */
27974- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27975+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27976 tsk->thread.debugreg6 &= ~DR_STEP;
27977 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27978 regs->flags &= ~X86_EFLAGS_TF;
27979@@ -500,7 +541,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27980 return;
27981 conditional_sti(regs);
27982
27983- if (!user_mode_vm(regs))
27984+ if (!user_mode(regs))
27985 {
27986 if (!fixup_exception(regs)) {
27987 task->thread.error_code = error_code;
27988diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27989index cfbe99f..a6e8fa7 100644
27990--- a/arch/x86/kernel/tsc.c
27991+++ b/arch/x86/kernel/tsc.c
27992@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27993 */
27994 smp_wmb();
27995
27996- ACCESS_ONCE(c2n->head) = data;
27997+ ACCESS_ONCE_RW(c2n->head) = data;
27998 }
27999
28000 /*
28001diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28002index 2ed8459..7cf329f 100644
28003--- a/arch/x86/kernel/uprobes.c
28004+++ b/arch/x86/kernel/uprobes.c
28005@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28006 int ret = NOTIFY_DONE;
28007
28008 /* We are only interested in userspace traps */
28009- if (regs && !user_mode_vm(regs))
28010+ if (regs && !user_mode(regs))
28011 return NOTIFY_DONE;
28012
28013 switch (val) {
28014@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28015
28016 if (ncopied != rasize) {
28017 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28018- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28019+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28020
28021 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28022 }
28023diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28024index b9242ba..50c5edd 100644
28025--- a/arch/x86/kernel/verify_cpu.S
28026+++ b/arch/x86/kernel/verify_cpu.S
28027@@ -20,6 +20,7 @@
28028 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28029 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28030 * arch/x86/kernel/head_32.S: processor startup
28031+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28032 *
28033 * verify_cpu, returns the status of longmode and SSE in register %eax.
28034 * 0: Success 1: Failure
28035diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28036index e8edcf5..27f9344 100644
28037--- a/arch/x86/kernel/vm86_32.c
28038+++ b/arch/x86/kernel/vm86_32.c
28039@@ -44,6 +44,7 @@
28040 #include <linux/ptrace.h>
28041 #include <linux/audit.h>
28042 #include <linux/stddef.h>
28043+#include <linux/grsecurity.h>
28044
28045 #include <asm/uaccess.h>
28046 #include <asm/io.h>
28047@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28048 do_exit(SIGSEGV);
28049 }
28050
28051- tss = &per_cpu(init_tss, get_cpu());
28052+ tss = init_tss + get_cpu();
28053 current->thread.sp0 = current->thread.saved_sp0;
28054 current->thread.sysenter_cs = __KERNEL_CS;
28055 load_sp0(tss, &current->thread);
28056@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28057
28058 if (tsk->thread.saved_sp0)
28059 return -EPERM;
28060+
28061+#ifdef CONFIG_GRKERNSEC_VM86
28062+ if (!capable(CAP_SYS_RAWIO)) {
28063+ gr_handle_vm86();
28064+ return -EPERM;
28065+ }
28066+#endif
28067+
28068 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28069 offsetof(struct kernel_vm86_struct, vm86plus) -
28070 sizeof(info.regs));
28071@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28072 int tmp;
28073 struct vm86plus_struct __user *v86;
28074
28075+#ifdef CONFIG_GRKERNSEC_VM86
28076+ if (!capable(CAP_SYS_RAWIO)) {
28077+ gr_handle_vm86();
28078+ return -EPERM;
28079+ }
28080+#endif
28081+
28082 tsk = current;
28083 switch (cmd) {
28084 case VM86_REQUEST_IRQ:
28085@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28086 tsk->thread.saved_fs = info->regs32->fs;
28087 tsk->thread.saved_gs = get_user_gs(info->regs32);
28088
28089- tss = &per_cpu(init_tss, get_cpu());
28090+ tss = init_tss + get_cpu();
28091 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28092 if (cpu_has_sep)
28093 tsk->thread.sysenter_cs = 0;
28094@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28095 goto cannot_handle;
28096 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28097 goto cannot_handle;
28098- intr_ptr = (unsigned long __user *) (i << 2);
28099+ intr_ptr = (__force unsigned long __user *) (i << 2);
28100 if (get_user(segoffs, intr_ptr))
28101 goto cannot_handle;
28102 if ((segoffs >> 16) == BIOSSEG)
28103diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28104index da6b35a..977e9cf 100644
28105--- a/arch/x86/kernel/vmlinux.lds.S
28106+++ b/arch/x86/kernel/vmlinux.lds.S
28107@@ -26,6 +26,13 @@
28108 #include <asm/page_types.h>
28109 #include <asm/cache.h>
28110 #include <asm/boot.h>
28111+#include <asm/segment.h>
28112+
28113+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28114+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28115+#else
28116+#define __KERNEL_TEXT_OFFSET 0
28117+#endif
28118
28119 #undef i386 /* in case the preprocessor is a 32bit one */
28120
28121@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28122
28123 PHDRS {
28124 text PT_LOAD FLAGS(5); /* R_E */
28125+#ifdef CONFIG_X86_32
28126+ module PT_LOAD FLAGS(5); /* R_E */
28127+#endif
28128+#ifdef CONFIG_XEN
28129+ rodata PT_LOAD FLAGS(5); /* R_E */
28130+#else
28131+ rodata PT_LOAD FLAGS(4); /* R__ */
28132+#endif
28133 data PT_LOAD FLAGS(6); /* RW_ */
28134-#ifdef CONFIG_X86_64
28135+ init.begin PT_LOAD FLAGS(6); /* RW_ */
28136 #ifdef CONFIG_SMP
28137 percpu PT_LOAD FLAGS(6); /* RW_ */
28138 #endif
28139+ text.init PT_LOAD FLAGS(5); /* R_E */
28140+ text.exit PT_LOAD FLAGS(5); /* R_E */
28141 init PT_LOAD FLAGS(7); /* RWE */
28142-#endif
28143 note PT_NOTE FLAGS(0); /* ___ */
28144 }
28145
28146 SECTIONS
28147 {
28148 #ifdef CONFIG_X86_32
28149- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28150- phys_startup_32 = startup_32 - LOAD_OFFSET;
28151+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28152 #else
28153- . = __START_KERNEL;
28154- phys_startup_64 = startup_64 - LOAD_OFFSET;
28155+ . = __START_KERNEL;
28156 #endif
28157
28158 /* Text and read-only data */
28159- .text : AT(ADDR(.text) - LOAD_OFFSET) {
28160- _text = .;
28161+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28162 /* bootstrapping code */
28163+#ifdef CONFIG_X86_32
28164+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28165+#else
28166+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28167+#endif
28168+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28169+ _text = .;
28170 HEAD_TEXT
28171 . = ALIGN(8);
28172 _stext = .;
28173@@ -104,13 +124,47 @@ SECTIONS
28174 IRQENTRY_TEXT
28175 *(.fixup)
28176 *(.gnu.warning)
28177- /* End of text section */
28178- _etext = .;
28179 } :text = 0x9090
28180
28181- NOTES :text :note
28182+ . += __KERNEL_TEXT_OFFSET;
28183
28184- EXCEPTION_TABLE(16) :text = 0x9090
28185+#ifdef CONFIG_X86_32
28186+ . = ALIGN(PAGE_SIZE);
28187+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28188+
28189+#ifdef CONFIG_PAX_KERNEXEC
28190+ MODULES_EXEC_VADDR = .;
28191+ BYTE(0)
28192+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28193+ . = ALIGN(HPAGE_SIZE) - 1;
28194+ MODULES_EXEC_END = .;
28195+#endif
28196+
28197+ } :module
28198+#endif
28199+
28200+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28201+ /* End of text section */
28202+ BYTE(0)
28203+ _etext = . - __KERNEL_TEXT_OFFSET;
28204+ }
28205+
28206+#ifdef CONFIG_X86_32
28207+ . = ALIGN(PAGE_SIZE);
28208+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28209+ . = ALIGN(PAGE_SIZE);
28210+ *(.empty_zero_page)
28211+ *(.initial_pg_fixmap)
28212+ *(.initial_pg_pmd)
28213+ *(.initial_page_table)
28214+ *(.swapper_pg_dir)
28215+ } :rodata
28216+#endif
28217+
28218+ . = ALIGN(PAGE_SIZE);
28219+ NOTES :rodata :note
28220+
28221+ EXCEPTION_TABLE(16) :rodata
28222
28223 #if defined(CONFIG_DEBUG_RODATA)
28224 /* .text should occupy whole number of pages */
28225@@ -122,16 +176,20 @@ SECTIONS
28226
28227 /* Data */
28228 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28229+
28230+#ifdef CONFIG_PAX_KERNEXEC
28231+ . = ALIGN(HPAGE_SIZE);
28232+#else
28233+ . = ALIGN(PAGE_SIZE);
28234+#endif
28235+
28236 /* Start of data section */
28237 _sdata = .;
28238
28239 /* init_task */
28240 INIT_TASK_DATA(THREAD_SIZE)
28241
28242-#ifdef CONFIG_X86_32
28243- /* 32 bit has nosave before _edata */
28244 NOSAVE_DATA
28245-#endif
28246
28247 PAGE_ALIGNED_DATA(PAGE_SIZE)
28248
28249@@ -172,12 +230,19 @@ SECTIONS
28250 #endif /* CONFIG_X86_64 */
28251
28252 /* Init code and data - will be freed after init */
28253- . = ALIGN(PAGE_SIZE);
28254 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28255+ BYTE(0)
28256+
28257+#ifdef CONFIG_PAX_KERNEXEC
28258+ . = ALIGN(HPAGE_SIZE);
28259+#else
28260+ . = ALIGN(PAGE_SIZE);
28261+#endif
28262+
28263 __init_begin = .; /* paired with __init_end */
28264- }
28265+ } :init.begin
28266
28267-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28268+#ifdef CONFIG_SMP
28269 /*
28270 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28271 * output PHDR, so the next output section - .init.text - should
28272@@ -186,12 +251,27 @@ SECTIONS
28273 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28274 #endif
28275
28276- INIT_TEXT_SECTION(PAGE_SIZE)
28277-#ifdef CONFIG_X86_64
28278- :init
28279-#endif
28280+ . = ALIGN(PAGE_SIZE);
28281+ init_begin = .;
28282+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28283+ VMLINUX_SYMBOL(_sinittext) = .;
28284+ INIT_TEXT
28285+ VMLINUX_SYMBOL(_einittext) = .;
28286+ . = ALIGN(PAGE_SIZE);
28287+ } :text.init
28288
28289- INIT_DATA_SECTION(16)
28290+ /*
28291+ * .exit.text is discard at runtime, not link time, to deal with
28292+ * references from .altinstructions and .eh_frame
28293+ */
28294+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28295+ EXIT_TEXT
28296+ . = ALIGN(16);
28297+ } :text.exit
28298+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28299+
28300+ . = ALIGN(PAGE_SIZE);
28301+ INIT_DATA_SECTION(16) :init
28302
28303 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28304 __x86_cpu_dev_start = .;
28305@@ -262,19 +342,12 @@ SECTIONS
28306 }
28307
28308 . = ALIGN(8);
28309- /*
28310- * .exit.text is discard at runtime, not link time, to deal with
28311- * references from .altinstructions and .eh_frame
28312- */
28313- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28314- EXIT_TEXT
28315- }
28316
28317 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28318 EXIT_DATA
28319 }
28320
28321-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28322+#ifndef CONFIG_SMP
28323 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28324 #endif
28325
28326@@ -293,16 +366,10 @@ SECTIONS
28327 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28328 __smp_locks = .;
28329 *(.smp_locks)
28330- . = ALIGN(PAGE_SIZE);
28331 __smp_locks_end = .;
28332+ . = ALIGN(PAGE_SIZE);
28333 }
28334
28335-#ifdef CONFIG_X86_64
28336- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28337- NOSAVE_DATA
28338- }
28339-#endif
28340-
28341 /* BSS */
28342 . = ALIGN(PAGE_SIZE);
28343 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28344@@ -318,6 +385,7 @@ SECTIONS
28345 __brk_base = .;
28346 . += 64 * 1024; /* 64k alignment slop space */
28347 *(.brk_reservation) /* areas brk users have reserved */
28348+ . = ALIGN(HPAGE_SIZE);
28349 __brk_limit = .;
28350 }
28351
28352@@ -344,13 +412,12 @@ SECTIONS
28353 * for the boot processor.
28354 */
28355 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28356-INIT_PER_CPU(gdt_page);
28357 INIT_PER_CPU(irq_stack_union);
28358
28359 /*
28360 * Build-time check on the image size:
28361 */
28362-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28363+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28364 "kernel image bigger than KERNEL_IMAGE_SIZE");
28365
28366 #ifdef CONFIG_SMP
28367diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28368index 1f96f93..6f29be7 100644
28369--- a/arch/x86/kernel/vsyscall_64.c
28370+++ b/arch/x86/kernel/vsyscall_64.c
28371@@ -56,15 +56,13 @@
28372 DEFINE_VVAR(int, vgetcpu_mode);
28373 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
28374
28375-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28376+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28377
28378 static int __init vsyscall_setup(char *str)
28379 {
28380 if (str) {
28381 if (!strcmp("emulate", str))
28382 vsyscall_mode = EMULATE;
28383- else if (!strcmp("native", str))
28384- vsyscall_mode = NATIVE;
28385 else if (!strcmp("none", str))
28386 vsyscall_mode = NONE;
28387 else
28388@@ -101,7 +99,7 @@ void update_vsyscall(struct timekeeper *tk)
28389 vdata->monotonic_time_sec = tk->xtime_sec
28390 + tk->wall_to_monotonic.tv_sec;
28391 vdata->monotonic_time_snsec = tk->xtime_nsec
28392- + (tk->wall_to_monotonic.tv_nsec
28393+ + ((u64)tk->wall_to_monotonic.tv_nsec
28394 << tk->shift);
28395 while (vdata->monotonic_time_snsec >=
28396 (((u64)NSEC_PER_SEC) << tk->shift)) {
28397@@ -323,8 +321,7 @@ do_ret:
28398 return true;
28399
28400 sigsegv:
28401- force_sig(SIGSEGV, current);
28402- return true;
28403+ do_group_exit(SIGKILL);
28404 }
28405
28406 /*
28407@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
28408 extern char __vvar_page;
28409 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28410
28411- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28412- vsyscall_mode == NATIVE
28413- ? PAGE_KERNEL_VSYSCALL
28414- : PAGE_KERNEL_VVAR);
28415+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28416 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28417 (unsigned long)VSYSCALL_START);
28418
28419diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28420index 04068192..4d75aa6 100644
28421--- a/arch/x86/kernel/x8664_ksyms_64.c
28422+++ b/arch/x86/kernel/x8664_ksyms_64.c
28423@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28424 EXPORT_SYMBOL(copy_user_generic_unrolled);
28425 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28426 EXPORT_SYMBOL(__copy_user_nocache);
28427-EXPORT_SYMBOL(_copy_from_user);
28428-EXPORT_SYMBOL(_copy_to_user);
28429
28430 EXPORT_SYMBOL(copy_page);
28431 EXPORT_SYMBOL(clear_page);
28432@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28433 EXPORT_SYMBOL(___preempt_schedule_context);
28434 #endif
28435 #endif
28436+
28437+#ifdef CONFIG_PAX_PER_CPU_PGD
28438+EXPORT_SYMBOL(cpu_pgd);
28439+#endif
28440diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28441index e48b674..a451dd9 100644
28442--- a/arch/x86/kernel/x86_init.c
28443+++ b/arch/x86/kernel/x86_init.c
28444@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28445 static void default_nmi_init(void) { };
28446 static int default_i8042_detect(void) { return 1; };
28447
28448-struct x86_platform_ops x86_platform = {
28449+struct x86_platform_ops x86_platform __read_only = {
28450 .calibrate_tsc = native_calibrate_tsc,
28451 .get_wallclock = mach_get_cmos_time,
28452 .set_wallclock = mach_set_rtc_mmss,
28453@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28454 EXPORT_SYMBOL_GPL(x86_platform);
28455
28456 #if defined(CONFIG_PCI_MSI)
28457-struct x86_msi_ops x86_msi = {
28458+struct x86_msi_ops x86_msi __read_only = {
28459 .setup_msi_irqs = native_setup_msi_irqs,
28460 .compose_msi_msg = native_compose_msi_msg,
28461 .teardown_msi_irq = native_teardown_msi_irq,
28462@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28463 }
28464 #endif
28465
28466-struct x86_io_apic_ops x86_io_apic_ops = {
28467+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28468 .init = native_io_apic_init_mappings,
28469 .read = native_io_apic_read,
28470 .write = native_io_apic_write,
28471diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28472index a4b451c..8dfe1ad 100644
28473--- a/arch/x86/kernel/xsave.c
28474+++ b/arch/x86/kernel/xsave.c
28475@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28476
28477 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28478 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28479- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28480+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28481
28482 if (!use_xsave())
28483 return err;
28484
28485- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28486+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28487
28488 /*
28489 * Read the xstate_bv which we copied (directly from the cpu or
28490 * from the state in task struct) to the user buffers.
28491 */
28492- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28493+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28494
28495 /*
28496 * For legacy compatible, we always set FP/SSE bits in the bit
28497@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28498 */
28499 xstate_bv |= XSTATE_FPSSE;
28500
28501- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28502+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28503
28504 return err;
28505 }
28506@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28507 {
28508 int err;
28509
28510+ buf = (struct xsave_struct __user *)____m(buf);
28511 if (use_xsave())
28512 err = xsave_user(buf);
28513 else if (use_fxsr())
28514@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28515 */
28516 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28517 {
28518+ buf = (void __user *)____m(buf);
28519 if (use_xsave()) {
28520 if ((unsigned long)buf % 64 || fx_only) {
28521 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28522diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28523index c697625..a032162 100644
28524--- a/arch/x86/kvm/cpuid.c
28525+++ b/arch/x86/kvm/cpuid.c
28526@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28527 struct kvm_cpuid2 *cpuid,
28528 struct kvm_cpuid_entry2 __user *entries)
28529 {
28530- int r;
28531+ int r, i;
28532
28533 r = -E2BIG;
28534 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28535 goto out;
28536 r = -EFAULT;
28537- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28538- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28539+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28540 goto out;
28541+ for (i = 0; i < cpuid->nent; ++i) {
28542+ struct kvm_cpuid_entry2 cpuid_entry;
28543+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28544+ goto out;
28545+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28546+ }
28547 vcpu->arch.cpuid_nent = cpuid->nent;
28548 kvm_apic_set_version(vcpu);
28549 kvm_x86_ops->cpuid_update(vcpu);
28550@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28551 struct kvm_cpuid2 *cpuid,
28552 struct kvm_cpuid_entry2 __user *entries)
28553 {
28554- int r;
28555+ int r, i;
28556
28557 r = -E2BIG;
28558 if (cpuid->nent < vcpu->arch.cpuid_nent)
28559 goto out;
28560 r = -EFAULT;
28561- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28562- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28563+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28564 goto out;
28565+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28566+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28567+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28568+ goto out;
28569+ }
28570 return 0;
28571
28572 out:
28573diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28574index 9736529..ab4f54c 100644
28575--- a/arch/x86/kvm/lapic.c
28576+++ b/arch/x86/kvm/lapic.c
28577@@ -55,7 +55,7 @@
28578 #define APIC_BUS_CYCLE_NS 1
28579
28580 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28581-#define apic_debug(fmt, arg...)
28582+#define apic_debug(fmt, arg...) do {} while (0)
28583
28584 #define APIC_LVT_NUM 6
28585 /* 14 is the version for Xeon and Pentium 8.4.8*/
28586diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28587index cba218a..1cc1bed 100644
28588--- a/arch/x86/kvm/paging_tmpl.h
28589+++ b/arch/x86/kvm/paging_tmpl.h
28590@@ -331,7 +331,7 @@ retry_walk:
28591 if (unlikely(kvm_is_error_hva(host_addr)))
28592 goto error;
28593
28594- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28595+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28596 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28597 goto error;
28598 walker->ptep_user[walker->level - 1] = ptep_user;
28599diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28600index 2de1bc0..22251ee 100644
28601--- a/arch/x86/kvm/svm.c
28602+++ b/arch/x86/kvm/svm.c
28603@@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28604 int cpu = raw_smp_processor_id();
28605
28606 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28607+
28608+ pax_open_kernel();
28609 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28610+ pax_close_kernel();
28611+
28612 load_TR_desc();
28613 }
28614
28615@@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28616 #endif
28617 #endif
28618
28619+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28620+ __set_fs(current_thread_info()->addr_limit);
28621+#endif
28622+
28623 reload_tss(vcpu);
28624
28625 local_irq_disable();
28626diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28627index 3927528..fc19971 100644
28628--- a/arch/x86/kvm/vmx.c
28629+++ b/arch/x86/kvm/vmx.c
28630@@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28631 #endif
28632 }
28633
28634-static void vmcs_clear_bits(unsigned long field, u32 mask)
28635+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28636 {
28637 vmcs_writel(field, vmcs_readl(field) & ~mask);
28638 }
28639
28640-static void vmcs_set_bits(unsigned long field, u32 mask)
28641+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28642 {
28643 vmcs_writel(field, vmcs_readl(field) | mask);
28644 }
28645@@ -1585,7 +1585,11 @@ static void reload_tss(void)
28646 struct desc_struct *descs;
28647
28648 descs = (void *)gdt->address;
28649+
28650+ pax_open_kernel();
28651 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28652+ pax_close_kernel();
28653+
28654 load_TR_desc();
28655 }
28656
28657@@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28658 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28659 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28660
28661+#ifdef CONFIG_PAX_PER_CPU_PGD
28662+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28663+#endif
28664+
28665 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28666 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28667 vmx->loaded_vmcs->cpu = cpu;
28668@@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28669 * reads and returns guest's timestamp counter "register"
28670 * guest_tsc = host_tsc + tsc_offset -- 21.3
28671 */
28672-static u64 guest_read_tsc(void)
28673+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28674 {
28675 u64 host_tsc, tsc_offset;
28676
28677@@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
28678 if (!cpu_has_vmx_flexpriority())
28679 flexpriority_enabled = 0;
28680
28681- if (!cpu_has_vmx_tpr_shadow())
28682- kvm_x86_ops->update_cr8_intercept = NULL;
28683+ if (!cpu_has_vmx_tpr_shadow()) {
28684+ pax_open_kernel();
28685+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28686+ pax_close_kernel();
28687+ }
28688
28689 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28690 kvm_disable_largepages();
28691@@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
28692 if (!cpu_has_vmx_apicv())
28693 enable_apicv = 0;
28694
28695+ pax_open_kernel();
28696 if (enable_apicv)
28697- kvm_x86_ops->update_cr8_intercept = NULL;
28698+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28699 else {
28700- kvm_x86_ops->hwapic_irr_update = NULL;
28701- kvm_x86_ops->deliver_posted_interrupt = NULL;
28702- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28703+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28704+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28705+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28706 }
28707+ pax_close_kernel();
28708
28709 if (nested)
28710 nested_vmx_setup_ctls_msrs();
28711@@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28712
28713 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28714 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28715+
28716+#ifndef CONFIG_PAX_PER_CPU_PGD
28717 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28718+#endif
28719
28720 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28721 #ifdef CONFIG_X86_64
28722@@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28723 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28724 vmx->host_idt_base = dt.address;
28725
28726- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28727+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28728
28729 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28730 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28731@@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28732 "jmp 2f \n\t"
28733 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28734 "2: "
28735+
28736+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28737+ "ljmp %[cs],$3f\n\t"
28738+ "3: "
28739+#endif
28740+
28741 /* Save guest registers, load host registers, keep flags */
28742 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28743 "pop %0 \n\t"
28744@@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28745 #endif
28746 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28747 [wordsize]"i"(sizeof(ulong))
28748+
28749+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28750+ ,[cs]"i"(__KERNEL_CS)
28751+#endif
28752+
28753 : "cc", "memory"
28754 #ifdef CONFIG_X86_64
28755 , "rax", "rbx", "rdi", "rsi"
28756@@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28757 if (debugctlmsr)
28758 update_debugctlmsr(debugctlmsr);
28759
28760-#ifndef CONFIG_X86_64
28761+#ifdef CONFIG_X86_32
28762 /*
28763 * The sysexit path does not restore ds/es, so we must set them to
28764 * a reasonable value ourselves.
28765@@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28766 * may be executed in interrupt context, which saves and restore segments
28767 * around it, nullifying its effect.
28768 */
28769- loadsegment(ds, __USER_DS);
28770- loadsegment(es, __USER_DS);
28771+ loadsegment(ds, __KERNEL_DS);
28772+ loadsegment(es, __KERNEL_DS);
28773+ loadsegment(ss, __KERNEL_DS);
28774+
28775+#ifdef CONFIG_PAX_KERNEXEC
28776+ loadsegment(fs, __KERNEL_PERCPU);
28777+#endif
28778+
28779+#ifdef CONFIG_PAX_MEMORY_UDEREF
28780+ __set_fs(current_thread_info()->addr_limit);
28781+#endif
28782+
28783 #endif
28784
28785 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28786diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28787index 2b85784..ad70e19 100644
28788--- a/arch/x86/kvm/x86.c
28789+++ b/arch/x86/kvm/x86.c
28790@@ -1777,8 +1777,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28791 {
28792 struct kvm *kvm = vcpu->kvm;
28793 int lm = is_long_mode(vcpu);
28794- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28795- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28796+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28797+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28798 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28799 : kvm->arch.xen_hvm_config.blob_size_32;
28800 u32 page_num = data & ~PAGE_MASK;
28801@@ -2689,6 +2689,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28802 if (n < msr_list.nmsrs)
28803 goto out;
28804 r = -EFAULT;
28805+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28806+ goto out;
28807 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28808 num_msrs_to_save * sizeof(u32)))
28809 goto out;
28810@@ -5503,7 +5505,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28811 };
28812 #endif
28813
28814-int kvm_arch_init(void *opaque)
28815+int kvm_arch_init(const void *opaque)
28816 {
28817 int r;
28818 struct kvm_x86_ops *ops = opaque;
28819diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28820index ad1fb5f..fe30b66 100644
28821--- a/arch/x86/lguest/boot.c
28822+++ b/arch/x86/lguest/boot.c
28823@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28824 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28825 * Launcher to reboot us.
28826 */
28827-static void lguest_restart(char *reason)
28828+static __noreturn void lguest_restart(char *reason)
28829 {
28830 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28831+ BUG();
28832 }
28833
28834 /*G:050
28835diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28836index 00933d5..3a64af9 100644
28837--- a/arch/x86/lib/atomic64_386_32.S
28838+++ b/arch/x86/lib/atomic64_386_32.S
28839@@ -48,6 +48,10 @@ BEGIN(read)
28840 movl (v), %eax
28841 movl 4(v), %edx
28842 RET_ENDP
28843+BEGIN(read_unchecked)
28844+ movl (v), %eax
28845+ movl 4(v), %edx
28846+RET_ENDP
28847 #undef v
28848
28849 #define v %esi
28850@@ -55,6 +59,10 @@ BEGIN(set)
28851 movl %ebx, (v)
28852 movl %ecx, 4(v)
28853 RET_ENDP
28854+BEGIN(set_unchecked)
28855+ movl %ebx, (v)
28856+ movl %ecx, 4(v)
28857+RET_ENDP
28858 #undef v
28859
28860 #define v %esi
28861@@ -70,6 +78,20 @@ RET_ENDP
28862 BEGIN(add)
28863 addl %eax, (v)
28864 adcl %edx, 4(v)
28865+
28866+#ifdef CONFIG_PAX_REFCOUNT
28867+ jno 0f
28868+ subl %eax, (v)
28869+ sbbl %edx, 4(v)
28870+ int $4
28871+0:
28872+ _ASM_EXTABLE(0b, 0b)
28873+#endif
28874+
28875+RET_ENDP
28876+BEGIN(add_unchecked)
28877+ addl %eax, (v)
28878+ adcl %edx, 4(v)
28879 RET_ENDP
28880 #undef v
28881
28882@@ -77,6 +99,24 @@ RET_ENDP
28883 BEGIN(add_return)
28884 addl (v), %eax
28885 adcl 4(v), %edx
28886+
28887+#ifdef CONFIG_PAX_REFCOUNT
28888+ into
28889+1234:
28890+ _ASM_EXTABLE(1234b, 2f)
28891+#endif
28892+
28893+ movl %eax, (v)
28894+ movl %edx, 4(v)
28895+
28896+#ifdef CONFIG_PAX_REFCOUNT
28897+2:
28898+#endif
28899+
28900+RET_ENDP
28901+BEGIN(add_return_unchecked)
28902+ addl (v), %eax
28903+ adcl 4(v), %edx
28904 movl %eax, (v)
28905 movl %edx, 4(v)
28906 RET_ENDP
28907@@ -86,6 +126,20 @@ RET_ENDP
28908 BEGIN(sub)
28909 subl %eax, (v)
28910 sbbl %edx, 4(v)
28911+
28912+#ifdef CONFIG_PAX_REFCOUNT
28913+ jno 0f
28914+ addl %eax, (v)
28915+ adcl %edx, 4(v)
28916+ int $4
28917+0:
28918+ _ASM_EXTABLE(0b, 0b)
28919+#endif
28920+
28921+RET_ENDP
28922+BEGIN(sub_unchecked)
28923+ subl %eax, (v)
28924+ sbbl %edx, 4(v)
28925 RET_ENDP
28926 #undef v
28927
28928@@ -96,6 +150,27 @@ BEGIN(sub_return)
28929 sbbl $0, %edx
28930 addl (v), %eax
28931 adcl 4(v), %edx
28932+
28933+#ifdef CONFIG_PAX_REFCOUNT
28934+ into
28935+1234:
28936+ _ASM_EXTABLE(1234b, 2f)
28937+#endif
28938+
28939+ movl %eax, (v)
28940+ movl %edx, 4(v)
28941+
28942+#ifdef CONFIG_PAX_REFCOUNT
28943+2:
28944+#endif
28945+
28946+RET_ENDP
28947+BEGIN(sub_return_unchecked)
28948+ negl %edx
28949+ negl %eax
28950+ sbbl $0, %edx
28951+ addl (v), %eax
28952+ adcl 4(v), %edx
28953 movl %eax, (v)
28954 movl %edx, 4(v)
28955 RET_ENDP
28956@@ -105,6 +180,20 @@ RET_ENDP
28957 BEGIN(inc)
28958 addl $1, (v)
28959 adcl $0, 4(v)
28960+
28961+#ifdef CONFIG_PAX_REFCOUNT
28962+ jno 0f
28963+ subl $1, (v)
28964+ sbbl $0, 4(v)
28965+ int $4
28966+0:
28967+ _ASM_EXTABLE(0b, 0b)
28968+#endif
28969+
28970+RET_ENDP
28971+BEGIN(inc_unchecked)
28972+ addl $1, (v)
28973+ adcl $0, 4(v)
28974 RET_ENDP
28975 #undef v
28976
28977@@ -114,6 +203,26 @@ BEGIN(inc_return)
28978 movl 4(v), %edx
28979 addl $1, %eax
28980 adcl $0, %edx
28981+
28982+#ifdef CONFIG_PAX_REFCOUNT
28983+ into
28984+1234:
28985+ _ASM_EXTABLE(1234b, 2f)
28986+#endif
28987+
28988+ movl %eax, (v)
28989+ movl %edx, 4(v)
28990+
28991+#ifdef CONFIG_PAX_REFCOUNT
28992+2:
28993+#endif
28994+
28995+RET_ENDP
28996+BEGIN(inc_return_unchecked)
28997+ movl (v), %eax
28998+ movl 4(v), %edx
28999+ addl $1, %eax
29000+ adcl $0, %edx
29001 movl %eax, (v)
29002 movl %edx, 4(v)
29003 RET_ENDP
29004@@ -123,6 +232,20 @@ RET_ENDP
29005 BEGIN(dec)
29006 subl $1, (v)
29007 sbbl $0, 4(v)
29008+
29009+#ifdef CONFIG_PAX_REFCOUNT
29010+ jno 0f
29011+ addl $1, (v)
29012+ adcl $0, 4(v)
29013+ int $4
29014+0:
29015+ _ASM_EXTABLE(0b, 0b)
29016+#endif
29017+
29018+RET_ENDP
29019+BEGIN(dec_unchecked)
29020+ subl $1, (v)
29021+ sbbl $0, 4(v)
29022 RET_ENDP
29023 #undef v
29024
29025@@ -132,6 +255,26 @@ BEGIN(dec_return)
29026 movl 4(v), %edx
29027 subl $1, %eax
29028 sbbl $0, %edx
29029+
29030+#ifdef CONFIG_PAX_REFCOUNT
29031+ into
29032+1234:
29033+ _ASM_EXTABLE(1234b, 2f)
29034+#endif
29035+
29036+ movl %eax, (v)
29037+ movl %edx, 4(v)
29038+
29039+#ifdef CONFIG_PAX_REFCOUNT
29040+2:
29041+#endif
29042+
29043+RET_ENDP
29044+BEGIN(dec_return_unchecked)
29045+ movl (v), %eax
29046+ movl 4(v), %edx
29047+ subl $1, %eax
29048+ sbbl $0, %edx
29049 movl %eax, (v)
29050 movl %edx, 4(v)
29051 RET_ENDP
29052@@ -143,6 +286,13 @@ BEGIN(add_unless)
29053 adcl %edx, %edi
29054 addl (v), %eax
29055 adcl 4(v), %edx
29056+
29057+#ifdef CONFIG_PAX_REFCOUNT
29058+ into
29059+1234:
29060+ _ASM_EXTABLE(1234b, 2f)
29061+#endif
29062+
29063 cmpl %eax, %ecx
29064 je 3f
29065 1:
29066@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29067 1:
29068 addl $1, %eax
29069 adcl $0, %edx
29070+
29071+#ifdef CONFIG_PAX_REFCOUNT
29072+ into
29073+1234:
29074+ _ASM_EXTABLE(1234b, 2f)
29075+#endif
29076+
29077 movl %eax, (v)
29078 movl %edx, 4(v)
29079 movl $1, %eax
29080@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29081 movl 4(v), %edx
29082 subl $1, %eax
29083 sbbl $0, %edx
29084+
29085+#ifdef CONFIG_PAX_REFCOUNT
29086+ into
29087+1234:
29088+ _ASM_EXTABLE(1234b, 1f)
29089+#endif
29090+
29091 js 1f
29092 movl %eax, (v)
29093 movl %edx, 4(v)
29094diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29095index f5cc9eb..51fa319 100644
29096--- a/arch/x86/lib/atomic64_cx8_32.S
29097+++ b/arch/x86/lib/atomic64_cx8_32.S
29098@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29099 CFI_STARTPROC
29100
29101 read64 %ecx
29102+ pax_force_retaddr
29103 ret
29104 CFI_ENDPROC
29105 ENDPROC(atomic64_read_cx8)
29106
29107+ENTRY(atomic64_read_unchecked_cx8)
29108+ CFI_STARTPROC
29109+
29110+ read64 %ecx
29111+ pax_force_retaddr
29112+ ret
29113+ CFI_ENDPROC
29114+ENDPROC(atomic64_read_unchecked_cx8)
29115+
29116 ENTRY(atomic64_set_cx8)
29117 CFI_STARTPROC
29118
29119@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29120 cmpxchg8b (%esi)
29121 jne 1b
29122
29123+ pax_force_retaddr
29124 ret
29125 CFI_ENDPROC
29126 ENDPROC(atomic64_set_cx8)
29127
29128+ENTRY(atomic64_set_unchecked_cx8)
29129+ CFI_STARTPROC
29130+
29131+1:
29132+/* we don't need LOCK_PREFIX since aligned 64-bit writes
29133+ * are atomic on 586 and newer */
29134+ cmpxchg8b (%esi)
29135+ jne 1b
29136+
29137+ pax_force_retaddr
29138+ ret
29139+ CFI_ENDPROC
29140+ENDPROC(atomic64_set_unchecked_cx8)
29141+
29142 ENTRY(atomic64_xchg_cx8)
29143 CFI_STARTPROC
29144
29145@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29146 cmpxchg8b (%esi)
29147 jne 1b
29148
29149+ pax_force_retaddr
29150 ret
29151 CFI_ENDPROC
29152 ENDPROC(atomic64_xchg_cx8)
29153
29154-.macro addsub_return func ins insc
29155-ENTRY(atomic64_\func\()_return_cx8)
29156+.macro addsub_return func ins insc unchecked=""
29157+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29158 CFI_STARTPROC
29159 SAVE ebp
29160 SAVE ebx
29161@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29162 movl %edx, %ecx
29163 \ins\()l %esi, %ebx
29164 \insc\()l %edi, %ecx
29165+
29166+.ifb \unchecked
29167+#ifdef CONFIG_PAX_REFCOUNT
29168+ into
29169+2:
29170+ _ASM_EXTABLE(2b, 3f)
29171+#endif
29172+.endif
29173+
29174 LOCK_PREFIX
29175 cmpxchg8b (%ebp)
29176 jne 1b
29177-
29178-10:
29179 movl %ebx, %eax
29180 movl %ecx, %edx
29181+
29182+.ifb \unchecked
29183+#ifdef CONFIG_PAX_REFCOUNT
29184+3:
29185+#endif
29186+.endif
29187+
29188 RESTORE edi
29189 RESTORE esi
29190 RESTORE ebx
29191 RESTORE ebp
29192+ pax_force_retaddr
29193 ret
29194 CFI_ENDPROC
29195-ENDPROC(atomic64_\func\()_return_cx8)
29196+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29197 .endm
29198
29199 addsub_return add add adc
29200 addsub_return sub sub sbb
29201+addsub_return add add adc _unchecked
29202+addsub_return sub sub sbb _unchecked
29203
29204-.macro incdec_return func ins insc
29205-ENTRY(atomic64_\func\()_return_cx8)
29206+.macro incdec_return func ins insc unchecked=""
29207+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29208 CFI_STARTPROC
29209 SAVE ebx
29210
29211@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29212 movl %edx, %ecx
29213 \ins\()l $1, %ebx
29214 \insc\()l $0, %ecx
29215+
29216+.ifb \unchecked
29217+#ifdef CONFIG_PAX_REFCOUNT
29218+ into
29219+2:
29220+ _ASM_EXTABLE(2b, 3f)
29221+#endif
29222+.endif
29223+
29224 LOCK_PREFIX
29225 cmpxchg8b (%esi)
29226 jne 1b
29227
29228-10:
29229 movl %ebx, %eax
29230 movl %ecx, %edx
29231+
29232+.ifb \unchecked
29233+#ifdef CONFIG_PAX_REFCOUNT
29234+3:
29235+#endif
29236+.endif
29237+
29238 RESTORE ebx
29239+ pax_force_retaddr
29240 ret
29241 CFI_ENDPROC
29242-ENDPROC(atomic64_\func\()_return_cx8)
29243+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29244 .endm
29245
29246 incdec_return inc add adc
29247 incdec_return dec sub sbb
29248+incdec_return inc add adc _unchecked
29249+incdec_return dec sub sbb _unchecked
29250
29251 ENTRY(atomic64_dec_if_positive_cx8)
29252 CFI_STARTPROC
29253@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29254 movl %edx, %ecx
29255 subl $1, %ebx
29256 sbb $0, %ecx
29257+
29258+#ifdef CONFIG_PAX_REFCOUNT
29259+ into
29260+1234:
29261+ _ASM_EXTABLE(1234b, 2f)
29262+#endif
29263+
29264 js 2f
29265 LOCK_PREFIX
29266 cmpxchg8b (%esi)
29267@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29268 movl %ebx, %eax
29269 movl %ecx, %edx
29270 RESTORE ebx
29271+ pax_force_retaddr
29272 ret
29273 CFI_ENDPROC
29274 ENDPROC(atomic64_dec_if_positive_cx8)
29275@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29276 movl %edx, %ecx
29277 addl %ebp, %ebx
29278 adcl %edi, %ecx
29279+
29280+#ifdef CONFIG_PAX_REFCOUNT
29281+ into
29282+1234:
29283+ _ASM_EXTABLE(1234b, 3f)
29284+#endif
29285+
29286 LOCK_PREFIX
29287 cmpxchg8b (%esi)
29288 jne 1b
29289@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29290 CFI_ADJUST_CFA_OFFSET -8
29291 RESTORE ebx
29292 RESTORE ebp
29293+ pax_force_retaddr
29294 ret
29295 4:
29296 cmpl %edx, 4(%esp)
29297@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29298 xorl %ecx, %ecx
29299 addl $1, %ebx
29300 adcl %edx, %ecx
29301+
29302+#ifdef CONFIG_PAX_REFCOUNT
29303+ into
29304+1234:
29305+ _ASM_EXTABLE(1234b, 3f)
29306+#endif
29307+
29308 LOCK_PREFIX
29309 cmpxchg8b (%esi)
29310 jne 1b
29311@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29312 movl $1, %eax
29313 3:
29314 RESTORE ebx
29315+ pax_force_retaddr
29316 ret
29317 CFI_ENDPROC
29318 ENDPROC(atomic64_inc_not_zero_cx8)
29319diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29320index e78b8ee..7e173a8 100644
29321--- a/arch/x86/lib/checksum_32.S
29322+++ b/arch/x86/lib/checksum_32.S
29323@@ -29,7 +29,8 @@
29324 #include <asm/dwarf2.h>
29325 #include <asm/errno.h>
29326 #include <asm/asm.h>
29327-
29328+#include <asm/segment.h>
29329+
29330 /*
29331 * computes a partial checksum, e.g. for TCP/UDP fragments
29332 */
29333@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29334
29335 #define ARGBASE 16
29336 #define FP 12
29337-
29338-ENTRY(csum_partial_copy_generic)
29339+
29340+ENTRY(csum_partial_copy_generic_to_user)
29341 CFI_STARTPROC
29342+
29343+#ifdef CONFIG_PAX_MEMORY_UDEREF
29344+ pushl_cfi %gs
29345+ popl_cfi %es
29346+ jmp csum_partial_copy_generic
29347+#endif
29348+
29349+ENTRY(csum_partial_copy_generic_from_user)
29350+
29351+#ifdef CONFIG_PAX_MEMORY_UDEREF
29352+ pushl_cfi %gs
29353+ popl_cfi %ds
29354+#endif
29355+
29356+ENTRY(csum_partial_copy_generic)
29357 subl $4,%esp
29358 CFI_ADJUST_CFA_OFFSET 4
29359 pushl_cfi %edi
29360@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29361 jmp 4f
29362 SRC(1: movw (%esi), %bx )
29363 addl $2, %esi
29364-DST( movw %bx, (%edi) )
29365+DST( movw %bx, %es:(%edi) )
29366 addl $2, %edi
29367 addw %bx, %ax
29368 adcl $0, %eax
29369@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29370 SRC(1: movl (%esi), %ebx )
29371 SRC( movl 4(%esi), %edx )
29372 adcl %ebx, %eax
29373-DST( movl %ebx, (%edi) )
29374+DST( movl %ebx, %es:(%edi) )
29375 adcl %edx, %eax
29376-DST( movl %edx, 4(%edi) )
29377+DST( movl %edx, %es:4(%edi) )
29378
29379 SRC( movl 8(%esi), %ebx )
29380 SRC( movl 12(%esi), %edx )
29381 adcl %ebx, %eax
29382-DST( movl %ebx, 8(%edi) )
29383+DST( movl %ebx, %es:8(%edi) )
29384 adcl %edx, %eax
29385-DST( movl %edx, 12(%edi) )
29386+DST( movl %edx, %es:12(%edi) )
29387
29388 SRC( movl 16(%esi), %ebx )
29389 SRC( movl 20(%esi), %edx )
29390 adcl %ebx, %eax
29391-DST( movl %ebx, 16(%edi) )
29392+DST( movl %ebx, %es:16(%edi) )
29393 adcl %edx, %eax
29394-DST( movl %edx, 20(%edi) )
29395+DST( movl %edx, %es:20(%edi) )
29396
29397 SRC( movl 24(%esi), %ebx )
29398 SRC( movl 28(%esi), %edx )
29399 adcl %ebx, %eax
29400-DST( movl %ebx, 24(%edi) )
29401+DST( movl %ebx, %es:24(%edi) )
29402 adcl %edx, %eax
29403-DST( movl %edx, 28(%edi) )
29404+DST( movl %edx, %es:28(%edi) )
29405
29406 lea 32(%esi), %esi
29407 lea 32(%edi), %edi
29408@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29409 shrl $2, %edx # This clears CF
29410 SRC(3: movl (%esi), %ebx )
29411 adcl %ebx, %eax
29412-DST( movl %ebx, (%edi) )
29413+DST( movl %ebx, %es:(%edi) )
29414 lea 4(%esi), %esi
29415 lea 4(%edi), %edi
29416 dec %edx
29417@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29418 jb 5f
29419 SRC( movw (%esi), %cx )
29420 leal 2(%esi), %esi
29421-DST( movw %cx, (%edi) )
29422+DST( movw %cx, %es:(%edi) )
29423 leal 2(%edi), %edi
29424 je 6f
29425 shll $16,%ecx
29426 SRC(5: movb (%esi), %cl )
29427-DST( movb %cl, (%edi) )
29428+DST( movb %cl, %es:(%edi) )
29429 6: addl %ecx, %eax
29430 adcl $0, %eax
29431 7:
29432@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29433
29434 6001:
29435 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29436- movl $-EFAULT, (%ebx)
29437+ movl $-EFAULT, %ss:(%ebx)
29438
29439 # zero the complete destination - computing the rest
29440 # is too much work
29441@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29442
29443 6002:
29444 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29445- movl $-EFAULT,(%ebx)
29446+ movl $-EFAULT,%ss:(%ebx)
29447 jmp 5000b
29448
29449 .previous
29450
29451+ pushl_cfi %ss
29452+ popl_cfi %ds
29453+ pushl_cfi %ss
29454+ popl_cfi %es
29455 popl_cfi %ebx
29456 CFI_RESTORE ebx
29457 popl_cfi %esi
29458@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29459 popl_cfi %ecx # equivalent to addl $4,%esp
29460 ret
29461 CFI_ENDPROC
29462-ENDPROC(csum_partial_copy_generic)
29463+ENDPROC(csum_partial_copy_generic_to_user)
29464
29465 #else
29466
29467 /* Version for PentiumII/PPro */
29468
29469 #define ROUND1(x) \
29470+ nop; nop; nop; \
29471 SRC(movl x(%esi), %ebx ) ; \
29472 addl %ebx, %eax ; \
29473- DST(movl %ebx, x(%edi) ) ;
29474+ DST(movl %ebx, %es:x(%edi)) ;
29475
29476 #define ROUND(x) \
29477+ nop; nop; nop; \
29478 SRC(movl x(%esi), %ebx ) ; \
29479 adcl %ebx, %eax ; \
29480- DST(movl %ebx, x(%edi) ) ;
29481+ DST(movl %ebx, %es:x(%edi)) ;
29482
29483 #define ARGBASE 12
29484-
29485-ENTRY(csum_partial_copy_generic)
29486+
29487+ENTRY(csum_partial_copy_generic_to_user)
29488 CFI_STARTPROC
29489+
29490+#ifdef CONFIG_PAX_MEMORY_UDEREF
29491+ pushl_cfi %gs
29492+ popl_cfi %es
29493+ jmp csum_partial_copy_generic
29494+#endif
29495+
29496+ENTRY(csum_partial_copy_generic_from_user)
29497+
29498+#ifdef CONFIG_PAX_MEMORY_UDEREF
29499+ pushl_cfi %gs
29500+ popl_cfi %ds
29501+#endif
29502+
29503+ENTRY(csum_partial_copy_generic)
29504 pushl_cfi %ebx
29505 CFI_REL_OFFSET ebx, 0
29506 pushl_cfi %edi
29507@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29508 subl %ebx, %edi
29509 lea -1(%esi),%edx
29510 andl $-32,%edx
29511- lea 3f(%ebx,%ebx), %ebx
29512+ lea 3f(%ebx,%ebx,2), %ebx
29513 testl %esi, %esi
29514 jmp *%ebx
29515 1: addl $64,%esi
29516@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29517 jb 5f
29518 SRC( movw (%esi), %dx )
29519 leal 2(%esi), %esi
29520-DST( movw %dx, (%edi) )
29521+DST( movw %dx, %es:(%edi) )
29522 leal 2(%edi), %edi
29523 je 6f
29524 shll $16,%edx
29525 5:
29526 SRC( movb (%esi), %dl )
29527-DST( movb %dl, (%edi) )
29528+DST( movb %dl, %es:(%edi) )
29529 6: addl %edx, %eax
29530 adcl $0, %eax
29531 7:
29532 .section .fixup, "ax"
29533 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29534- movl $-EFAULT, (%ebx)
29535+ movl $-EFAULT, %ss:(%ebx)
29536 # zero the complete destination (computing the rest is too much work)
29537 movl ARGBASE+8(%esp),%edi # dst
29538 movl ARGBASE+12(%esp),%ecx # len
29539@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29540 rep; stosb
29541 jmp 7b
29542 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29543- movl $-EFAULT, (%ebx)
29544+ movl $-EFAULT, %ss:(%ebx)
29545 jmp 7b
29546 .previous
29547
29548+#ifdef CONFIG_PAX_MEMORY_UDEREF
29549+ pushl_cfi %ss
29550+ popl_cfi %ds
29551+ pushl_cfi %ss
29552+ popl_cfi %es
29553+#endif
29554+
29555 popl_cfi %esi
29556 CFI_RESTORE esi
29557 popl_cfi %edi
29558@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29559 CFI_RESTORE ebx
29560 ret
29561 CFI_ENDPROC
29562-ENDPROC(csum_partial_copy_generic)
29563+ENDPROC(csum_partial_copy_generic_to_user)
29564
29565 #undef ROUND
29566 #undef ROUND1
29567diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29568index f2145cf..cea889d 100644
29569--- a/arch/x86/lib/clear_page_64.S
29570+++ b/arch/x86/lib/clear_page_64.S
29571@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29572 movl $4096/8,%ecx
29573 xorl %eax,%eax
29574 rep stosq
29575+ pax_force_retaddr
29576 ret
29577 CFI_ENDPROC
29578 ENDPROC(clear_page_c)
29579@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29580 movl $4096,%ecx
29581 xorl %eax,%eax
29582 rep stosb
29583+ pax_force_retaddr
29584 ret
29585 CFI_ENDPROC
29586 ENDPROC(clear_page_c_e)
29587@@ -43,6 +45,7 @@ ENTRY(clear_page)
29588 leaq 64(%rdi),%rdi
29589 jnz .Lloop
29590 nop
29591+ pax_force_retaddr
29592 ret
29593 CFI_ENDPROC
29594 .Lclear_page_end:
29595@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29596
29597 #include <asm/cpufeature.h>
29598
29599- .section .altinstr_replacement,"ax"
29600+ .section .altinstr_replacement,"a"
29601 1: .byte 0xeb /* jmp <disp8> */
29602 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29603 2: .byte 0xeb /* jmp <disp8> */
29604diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29605index 1e572c5..2a162cd 100644
29606--- a/arch/x86/lib/cmpxchg16b_emu.S
29607+++ b/arch/x86/lib/cmpxchg16b_emu.S
29608@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29609
29610 popf
29611 mov $1, %al
29612+ pax_force_retaddr
29613 ret
29614
29615 not_same:
29616 popf
29617 xor %al,%al
29618+ pax_force_retaddr
29619 ret
29620
29621 CFI_ENDPROC
29622diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29623index 176cca6..e0d658e 100644
29624--- a/arch/x86/lib/copy_page_64.S
29625+++ b/arch/x86/lib/copy_page_64.S
29626@@ -9,6 +9,7 @@ copy_page_rep:
29627 CFI_STARTPROC
29628 movl $4096/8, %ecx
29629 rep movsq
29630+ pax_force_retaddr
29631 ret
29632 CFI_ENDPROC
29633 ENDPROC(copy_page_rep)
29634@@ -24,8 +25,8 @@ ENTRY(copy_page)
29635 CFI_ADJUST_CFA_OFFSET 2*8
29636 movq %rbx, (%rsp)
29637 CFI_REL_OFFSET rbx, 0
29638- movq %r12, 1*8(%rsp)
29639- CFI_REL_OFFSET r12, 1*8
29640+ movq %r13, 1*8(%rsp)
29641+ CFI_REL_OFFSET r13, 1*8
29642
29643 movl $(4096/64)-5, %ecx
29644 .p2align 4
29645@@ -38,7 +39,7 @@ ENTRY(copy_page)
29646 movq 0x8*4(%rsi), %r9
29647 movq 0x8*5(%rsi), %r10
29648 movq 0x8*6(%rsi), %r11
29649- movq 0x8*7(%rsi), %r12
29650+ movq 0x8*7(%rsi), %r13
29651
29652 prefetcht0 5*64(%rsi)
29653
29654@@ -49,7 +50,7 @@ ENTRY(copy_page)
29655 movq %r9, 0x8*4(%rdi)
29656 movq %r10, 0x8*5(%rdi)
29657 movq %r11, 0x8*6(%rdi)
29658- movq %r12, 0x8*7(%rdi)
29659+ movq %r13, 0x8*7(%rdi)
29660
29661 leaq 64 (%rsi), %rsi
29662 leaq 64 (%rdi), %rdi
29663@@ -68,7 +69,7 @@ ENTRY(copy_page)
29664 movq 0x8*4(%rsi), %r9
29665 movq 0x8*5(%rsi), %r10
29666 movq 0x8*6(%rsi), %r11
29667- movq 0x8*7(%rsi), %r12
29668+ movq 0x8*7(%rsi), %r13
29669
29670 movq %rax, 0x8*0(%rdi)
29671 movq %rbx, 0x8*1(%rdi)
29672@@ -77,7 +78,7 @@ ENTRY(copy_page)
29673 movq %r9, 0x8*4(%rdi)
29674 movq %r10, 0x8*5(%rdi)
29675 movq %r11, 0x8*6(%rdi)
29676- movq %r12, 0x8*7(%rdi)
29677+ movq %r13, 0x8*7(%rdi)
29678
29679 leaq 64(%rdi), %rdi
29680 leaq 64(%rsi), %rsi
29681@@ -85,10 +86,11 @@ ENTRY(copy_page)
29682
29683 movq (%rsp), %rbx
29684 CFI_RESTORE rbx
29685- movq 1*8(%rsp), %r12
29686- CFI_RESTORE r12
29687+ movq 1*8(%rsp), %r13
29688+ CFI_RESTORE r13
29689 addq $2*8, %rsp
29690 CFI_ADJUST_CFA_OFFSET -2*8
29691+ pax_force_retaddr
29692 ret
29693 .Lcopy_page_end:
29694 CFI_ENDPROC
29695@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29696
29697 #include <asm/cpufeature.h>
29698
29699- .section .altinstr_replacement,"ax"
29700+ .section .altinstr_replacement,"a"
29701 1: .byte 0xeb /* jmp <disp8> */
29702 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29703 2:
29704diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29705index dee945d..a84067b 100644
29706--- a/arch/x86/lib/copy_user_64.S
29707+++ b/arch/x86/lib/copy_user_64.S
29708@@ -18,31 +18,7 @@
29709 #include <asm/alternative-asm.h>
29710 #include <asm/asm.h>
29711 #include <asm/smap.h>
29712-
29713-/*
29714- * By placing feature2 after feature1 in altinstructions section, we logically
29715- * implement:
29716- * If CPU has feature2, jmp to alt2 is used
29717- * else if CPU has feature1, jmp to alt1 is used
29718- * else jmp to orig is used.
29719- */
29720- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29721-0:
29722- .byte 0xe9 /* 32bit jump */
29723- .long \orig-1f /* by default jump to orig */
29724-1:
29725- .section .altinstr_replacement,"ax"
29726-2: .byte 0xe9 /* near jump with 32bit immediate */
29727- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29728-3: .byte 0xe9 /* near jump with 32bit immediate */
29729- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29730- .previous
29731-
29732- .section .altinstructions,"a"
29733- altinstruction_entry 0b,2b,\feature1,5,5
29734- altinstruction_entry 0b,3b,\feature2,5,5
29735- .previous
29736- .endm
29737+#include <asm/pgtable.h>
29738
29739 .macro ALIGN_DESTINATION
29740 #ifdef FIX_ALIGNMENT
29741@@ -70,52 +46,6 @@
29742 #endif
29743 .endm
29744
29745-/* Standard copy_to_user with segment limit checking */
29746-ENTRY(_copy_to_user)
29747- CFI_STARTPROC
29748- GET_THREAD_INFO(%rax)
29749- movq %rdi,%rcx
29750- addq %rdx,%rcx
29751- jc bad_to_user
29752- cmpq TI_addr_limit(%rax),%rcx
29753- ja bad_to_user
29754- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29755- copy_user_generic_unrolled,copy_user_generic_string, \
29756- copy_user_enhanced_fast_string
29757- CFI_ENDPROC
29758-ENDPROC(_copy_to_user)
29759-
29760-/* Standard copy_from_user with segment limit checking */
29761-ENTRY(_copy_from_user)
29762- CFI_STARTPROC
29763- GET_THREAD_INFO(%rax)
29764- movq %rsi,%rcx
29765- addq %rdx,%rcx
29766- jc bad_from_user
29767- cmpq TI_addr_limit(%rax),%rcx
29768- ja bad_from_user
29769- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29770- copy_user_generic_unrolled,copy_user_generic_string, \
29771- copy_user_enhanced_fast_string
29772- CFI_ENDPROC
29773-ENDPROC(_copy_from_user)
29774-
29775- .section .fixup,"ax"
29776- /* must zero dest */
29777-ENTRY(bad_from_user)
29778-bad_from_user:
29779- CFI_STARTPROC
29780- movl %edx,%ecx
29781- xorl %eax,%eax
29782- rep
29783- stosb
29784-bad_to_user:
29785- movl %edx,%eax
29786- ret
29787- CFI_ENDPROC
29788-ENDPROC(bad_from_user)
29789- .previous
29790-
29791 /*
29792 * copy_user_generic_unrolled - memory copy with exception handling.
29793 * This version is for CPUs like P4 that don't have efficient micro
29794@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29795 */
29796 ENTRY(copy_user_generic_unrolled)
29797 CFI_STARTPROC
29798+ ASM_PAX_OPEN_USERLAND
29799 ASM_STAC
29800 cmpl $8,%edx
29801 jb 20f /* less then 8 bytes, go to byte copy loop */
29802@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29803 jnz 21b
29804 23: xor %eax,%eax
29805 ASM_CLAC
29806+ ASM_PAX_CLOSE_USERLAND
29807+ pax_force_retaddr
29808 ret
29809
29810 .section .fixup,"ax"
29811@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29812 */
29813 ENTRY(copy_user_generic_string)
29814 CFI_STARTPROC
29815+ ASM_PAX_OPEN_USERLAND
29816 ASM_STAC
29817 cmpl $8,%edx
29818 jb 2f /* less than 8 bytes, go to byte copy loop */
29819@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29820 movsb
29821 xorl %eax,%eax
29822 ASM_CLAC
29823+ ASM_PAX_CLOSE_USERLAND
29824+ pax_force_retaddr
29825 ret
29826
29827 .section .fixup,"ax"
29828@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29829 */
29830 ENTRY(copy_user_enhanced_fast_string)
29831 CFI_STARTPROC
29832+ ASM_PAX_OPEN_USERLAND
29833 ASM_STAC
29834 movl %edx,%ecx
29835 1: rep
29836 movsb
29837 xorl %eax,%eax
29838 ASM_CLAC
29839+ ASM_PAX_CLOSE_USERLAND
29840+ pax_force_retaddr
29841 ret
29842
29843 .section .fixup,"ax"
29844diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29845index 6a4f43c..c70fb52 100644
29846--- a/arch/x86/lib/copy_user_nocache_64.S
29847+++ b/arch/x86/lib/copy_user_nocache_64.S
29848@@ -8,6 +8,7 @@
29849
29850 #include <linux/linkage.h>
29851 #include <asm/dwarf2.h>
29852+#include <asm/alternative-asm.h>
29853
29854 #define FIX_ALIGNMENT 1
29855
29856@@ -16,6 +17,7 @@
29857 #include <asm/thread_info.h>
29858 #include <asm/asm.h>
29859 #include <asm/smap.h>
29860+#include <asm/pgtable.h>
29861
29862 .macro ALIGN_DESTINATION
29863 #ifdef FIX_ALIGNMENT
29864@@ -49,6 +51,16 @@
29865 */
29866 ENTRY(__copy_user_nocache)
29867 CFI_STARTPROC
29868+
29869+#ifdef CONFIG_PAX_MEMORY_UDEREF
29870+ mov pax_user_shadow_base,%rcx
29871+ cmp %rcx,%rsi
29872+ jae 1f
29873+ add %rcx,%rsi
29874+1:
29875+#endif
29876+
29877+ ASM_PAX_OPEN_USERLAND
29878 ASM_STAC
29879 cmpl $8,%edx
29880 jb 20f /* less then 8 bytes, go to byte copy loop */
29881@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29882 jnz 21b
29883 23: xorl %eax,%eax
29884 ASM_CLAC
29885+ ASM_PAX_CLOSE_USERLAND
29886 sfence
29887+ pax_force_retaddr
29888 ret
29889
29890 .section .fixup,"ax"
29891diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29892index 2419d5f..fe52d0e 100644
29893--- a/arch/x86/lib/csum-copy_64.S
29894+++ b/arch/x86/lib/csum-copy_64.S
29895@@ -9,6 +9,7 @@
29896 #include <asm/dwarf2.h>
29897 #include <asm/errno.h>
29898 #include <asm/asm.h>
29899+#include <asm/alternative-asm.h>
29900
29901 /*
29902 * Checksum copy with exception handling.
29903@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29904 CFI_ADJUST_CFA_OFFSET 7*8
29905 movq %rbx, 2*8(%rsp)
29906 CFI_REL_OFFSET rbx, 2*8
29907- movq %r12, 3*8(%rsp)
29908- CFI_REL_OFFSET r12, 3*8
29909+ movq %r15, 3*8(%rsp)
29910+ CFI_REL_OFFSET r15, 3*8
29911 movq %r14, 4*8(%rsp)
29912 CFI_REL_OFFSET r14, 4*8
29913 movq %r13, 5*8(%rsp)
29914@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29915 movl %edx, %ecx
29916
29917 xorl %r9d, %r9d
29918- movq %rcx, %r12
29919+ movq %rcx, %r15
29920
29921- shrq $6, %r12
29922+ shrq $6, %r15
29923 jz .Lhandle_tail /* < 64 */
29924
29925 clc
29926
29927 /* main loop. clear in 64 byte blocks */
29928 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29929- /* r11: temp3, rdx: temp4, r12 loopcnt */
29930+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29931 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29932 .p2align 4
29933 .Lloop:
29934@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29935 adcq %r14, %rax
29936 adcq %r13, %rax
29937
29938- decl %r12d
29939+ decl %r15d
29940
29941 dest
29942 movq %rbx, (%rsi)
29943@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29944 .Lende:
29945 movq 2*8(%rsp), %rbx
29946 CFI_RESTORE rbx
29947- movq 3*8(%rsp), %r12
29948- CFI_RESTORE r12
29949+ movq 3*8(%rsp), %r15
29950+ CFI_RESTORE r15
29951 movq 4*8(%rsp), %r14
29952 CFI_RESTORE r14
29953 movq 5*8(%rsp), %r13
29954@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29955 CFI_RESTORE rbp
29956 addq $7*8, %rsp
29957 CFI_ADJUST_CFA_OFFSET -7*8
29958+ pax_force_retaddr
29959 ret
29960 CFI_RESTORE_STATE
29961
29962diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29963index 7609e0e..b449b98 100644
29964--- a/arch/x86/lib/csum-wrappers_64.c
29965+++ b/arch/x86/lib/csum-wrappers_64.c
29966@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29967 len -= 2;
29968 }
29969 }
29970+ pax_open_userland();
29971 stac();
29972- isum = csum_partial_copy_generic((__force const void *)src,
29973+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29974 dst, len, isum, errp, NULL);
29975 clac();
29976+ pax_close_userland();
29977 if (unlikely(*errp))
29978 goto out_err;
29979
29980@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29981 }
29982
29983 *errp = 0;
29984+ pax_open_userland();
29985 stac();
29986- ret = csum_partial_copy_generic(src, (void __force *)dst,
29987+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29988 len, isum, NULL, errp);
29989 clac();
29990+ pax_close_userland();
29991 return ret;
29992 }
29993 EXPORT_SYMBOL(csum_partial_copy_to_user);
29994diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29995index a451235..1daa956 100644
29996--- a/arch/x86/lib/getuser.S
29997+++ b/arch/x86/lib/getuser.S
29998@@ -33,17 +33,40 @@
29999 #include <asm/thread_info.h>
30000 #include <asm/asm.h>
30001 #include <asm/smap.h>
30002+#include <asm/segment.h>
30003+#include <asm/pgtable.h>
30004+#include <asm/alternative-asm.h>
30005+
30006+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30007+#define __copyuser_seg gs;
30008+#else
30009+#define __copyuser_seg
30010+#endif
30011
30012 .text
30013 ENTRY(__get_user_1)
30014 CFI_STARTPROC
30015+
30016+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30017 GET_THREAD_INFO(%_ASM_DX)
30018 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30019 jae bad_get_user
30020 ASM_STAC
30021-1: movzbl (%_ASM_AX),%edx
30022+
30023+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30024+ mov pax_user_shadow_base,%_ASM_DX
30025+ cmp %_ASM_DX,%_ASM_AX
30026+ jae 1234f
30027+ add %_ASM_DX,%_ASM_AX
30028+1234:
30029+#endif
30030+
30031+#endif
30032+
30033+1: __copyuser_seg movzbl (%_ASM_AX),%edx
30034 xor %eax,%eax
30035 ASM_CLAC
30036+ pax_force_retaddr
30037 ret
30038 CFI_ENDPROC
30039 ENDPROC(__get_user_1)
30040@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30041 ENTRY(__get_user_2)
30042 CFI_STARTPROC
30043 add $1,%_ASM_AX
30044+
30045+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30046 jc bad_get_user
30047 GET_THREAD_INFO(%_ASM_DX)
30048 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30049 jae bad_get_user
30050 ASM_STAC
30051-2: movzwl -1(%_ASM_AX),%edx
30052+
30053+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30054+ mov pax_user_shadow_base,%_ASM_DX
30055+ cmp %_ASM_DX,%_ASM_AX
30056+ jae 1234f
30057+ add %_ASM_DX,%_ASM_AX
30058+1234:
30059+#endif
30060+
30061+#endif
30062+
30063+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30064 xor %eax,%eax
30065 ASM_CLAC
30066+ pax_force_retaddr
30067 ret
30068 CFI_ENDPROC
30069 ENDPROC(__get_user_2)
30070@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30071 ENTRY(__get_user_4)
30072 CFI_STARTPROC
30073 add $3,%_ASM_AX
30074+
30075+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30076 jc bad_get_user
30077 GET_THREAD_INFO(%_ASM_DX)
30078 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30079 jae bad_get_user
30080 ASM_STAC
30081-3: movl -3(%_ASM_AX),%edx
30082+
30083+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30084+ mov pax_user_shadow_base,%_ASM_DX
30085+ cmp %_ASM_DX,%_ASM_AX
30086+ jae 1234f
30087+ add %_ASM_DX,%_ASM_AX
30088+1234:
30089+#endif
30090+
30091+#endif
30092+
30093+3: __copyuser_seg movl -3(%_ASM_AX),%edx
30094 xor %eax,%eax
30095 ASM_CLAC
30096+ pax_force_retaddr
30097 ret
30098 CFI_ENDPROC
30099 ENDPROC(__get_user_4)
30100@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30101 GET_THREAD_INFO(%_ASM_DX)
30102 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30103 jae bad_get_user
30104+
30105+#ifdef CONFIG_PAX_MEMORY_UDEREF
30106+ mov pax_user_shadow_base,%_ASM_DX
30107+ cmp %_ASM_DX,%_ASM_AX
30108+ jae 1234f
30109+ add %_ASM_DX,%_ASM_AX
30110+1234:
30111+#endif
30112+
30113 ASM_STAC
30114 4: movq -7(%_ASM_AX),%rdx
30115 xor %eax,%eax
30116 ASM_CLAC
30117+ pax_force_retaddr
30118 ret
30119 #else
30120 add $7,%_ASM_AX
30121@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30122 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30123 jae bad_get_user_8
30124 ASM_STAC
30125-4: movl -7(%_ASM_AX),%edx
30126-5: movl -3(%_ASM_AX),%ecx
30127+4: __copyuser_seg movl -7(%_ASM_AX),%edx
30128+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30129 xor %eax,%eax
30130 ASM_CLAC
30131+ pax_force_retaddr
30132 ret
30133 #endif
30134 CFI_ENDPROC
30135@@ -113,6 +175,7 @@ bad_get_user:
30136 xor %edx,%edx
30137 mov $(-EFAULT),%_ASM_AX
30138 ASM_CLAC
30139+ pax_force_retaddr
30140 ret
30141 CFI_ENDPROC
30142 END(bad_get_user)
30143@@ -124,6 +187,7 @@ bad_get_user_8:
30144 xor %ecx,%ecx
30145 mov $(-EFAULT),%_ASM_AX
30146 ASM_CLAC
30147+ pax_force_retaddr
30148 ret
30149 CFI_ENDPROC
30150 END(bad_get_user_8)
30151diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30152index 54fcffe..7be149e 100644
30153--- a/arch/x86/lib/insn.c
30154+++ b/arch/x86/lib/insn.c
30155@@ -20,8 +20,10 @@
30156
30157 #ifdef __KERNEL__
30158 #include <linux/string.h>
30159+#include <asm/pgtable_types.h>
30160 #else
30161 #include <string.h>
30162+#define ktla_ktva(addr) addr
30163 #endif
30164 #include <asm/inat.h>
30165 #include <asm/insn.h>
30166@@ -53,8 +55,8 @@
30167 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30168 {
30169 memset(insn, 0, sizeof(*insn));
30170- insn->kaddr = kaddr;
30171- insn->next_byte = kaddr;
30172+ insn->kaddr = ktla_ktva(kaddr);
30173+ insn->next_byte = ktla_ktva(kaddr);
30174 insn->x86_64 = x86_64 ? 1 : 0;
30175 insn->opnd_bytes = 4;
30176 if (x86_64)
30177diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30178index 05a95e7..326f2fa 100644
30179--- a/arch/x86/lib/iomap_copy_64.S
30180+++ b/arch/x86/lib/iomap_copy_64.S
30181@@ -17,6 +17,7 @@
30182
30183 #include <linux/linkage.h>
30184 #include <asm/dwarf2.h>
30185+#include <asm/alternative-asm.h>
30186
30187 /*
30188 * override generic version in lib/iomap_copy.c
30189@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30190 CFI_STARTPROC
30191 movl %edx,%ecx
30192 rep movsd
30193+ pax_force_retaddr
30194 ret
30195 CFI_ENDPROC
30196 ENDPROC(__iowrite32_copy)
30197diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30198index 56313a3..0db417e 100644
30199--- a/arch/x86/lib/memcpy_64.S
30200+++ b/arch/x86/lib/memcpy_64.S
30201@@ -24,7 +24,7 @@
30202 * This gets patched over the unrolled variant (below) via the
30203 * alternative instructions framework:
30204 */
30205- .section .altinstr_replacement, "ax", @progbits
30206+ .section .altinstr_replacement, "a", @progbits
30207 .Lmemcpy_c:
30208 movq %rdi, %rax
30209 movq %rdx, %rcx
30210@@ -33,6 +33,7 @@
30211 rep movsq
30212 movl %edx, %ecx
30213 rep movsb
30214+ pax_force_retaddr
30215 ret
30216 .Lmemcpy_e:
30217 .previous
30218@@ -44,11 +45,12 @@
30219 * This gets patched over the unrolled variant (below) via the
30220 * alternative instructions framework:
30221 */
30222- .section .altinstr_replacement, "ax", @progbits
30223+ .section .altinstr_replacement, "a", @progbits
30224 .Lmemcpy_c_e:
30225 movq %rdi, %rax
30226 movq %rdx, %rcx
30227 rep movsb
30228+ pax_force_retaddr
30229 ret
30230 .Lmemcpy_e_e:
30231 .previous
30232@@ -136,6 +138,7 @@ ENTRY(memcpy)
30233 movq %r9, 1*8(%rdi)
30234 movq %r10, -2*8(%rdi, %rdx)
30235 movq %r11, -1*8(%rdi, %rdx)
30236+ pax_force_retaddr
30237 retq
30238 .p2align 4
30239 .Lless_16bytes:
30240@@ -148,6 +151,7 @@ ENTRY(memcpy)
30241 movq -1*8(%rsi, %rdx), %r9
30242 movq %r8, 0*8(%rdi)
30243 movq %r9, -1*8(%rdi, %rdx)
30244+ pax_force_retaddr
30245 retq
30246 .p2align 4
30247 .Lless_8bytes:
30248@@ -161,6 +165,7 @@ ENTRY(memcpy)
30249 movl -4(%rsi, %rdx), %r8d
30250 movl %ecx, (%rdi)
30251 movl %r8d, -4(%rdi, %rdx)
30252+ pax_force_retaddr
30253 retq
30254 .p2align 4
30255 .Lless_3bytes:
30256@@ -179,6 +184,7 @@ ENTRY(memcpy)
30257 movb %cl, (%rdi)
30258
30259 .Lend:
30260+ pax_force_retaddr
30261 retq
30262 CFI_ENDPROC
30263 ENDPROC(memcpy)
30264diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30265index 65268a6..dd1de11 100644
30266--- a/arch/x86/lib/memmove_64.S
30267+++ b/arch/x86/lib/memmove_64.S
30268@@ -202,14 +202,16 @@ ENTRY(memmove)
30269 movb (%rsi), %r11b
30270 movb %r11b, (%rdi)
30271 13:
30272+ pax_force_retaddr
30273 retq
30274 CFI_ENDPROC
30275
30276- .section .altinstr_replacement,"ax"
30277+ .section .altinstr_replacement,"a"
30278 .Lmemmove_begin_forward_efs:
30279 /* Forward moving data. */
30280 movq %rdx, %rcx
30281 rep movsb
30282+ pax_force_retaddr
30283 retq
30284 .Lmemmove_end_forward_efs:
30285 .previous
30286diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30287index 2dcb380..2eb79fe 100644
30288--- a/arch/x86/lib/memset_64.S
30289+++ b/arch/x86/lib/memset_64.S
30290@@ -16,7 +16,7 @@
30291 *
30292 * rax original destination
30293 */
30294- .section .altinstr_replacement, "ax", @progbits
30295+ .section .altinstr_replacement, "a", @progbits
30296 .Lmemset_c:
30297 movq %rdi,%r9
30298 movq %rdx,%rcx
30299@@ -30,6 +30,7 @@
30300 movl %edx,%ecx
30301 rep stosb
30302 movq %r9,%rax
30303+ pax_force_retaddr
30304 ret
30305 .Lmemset_e:
30306 .previous
30307@@ -45,13 +46,14 @@
30308 *
30309 * rax original destination
30310 */
30311- .section .altinstr_replacement, "ax", @progbits
30312+ .section .altinstr_replacement, "a", @progbits
30313 .Lmemset_c_e:
30314 movq %rdi,%r9
30315 movb %sil,%al
30316 movq %rdx,%rcx
30317 rep stosb
30318 movq %r9,%rax
30319+ pax_force_retaddr
30320 ret
30321 .Lmemset_e_e:
30322 .previous
30323@@ -118,6 +120,7 @@ ENTRY(__memset)
30324
30325 .Lende:
30326 movq %r10,%rax
30327+ pax_force_retaddr
30328 ret
30329
30330 CFI_RESTORE_STATE
30331diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30332index c9f2d9b..e7fd2c0 100644
30333--- a/arch/x86/lib/mmx_32.c
30334+++ b/arch/x86/lib/mmx_32.c
30335@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30336 {
30337 void *p;
30338 int i;
30339+ unsigned long cr0;
30340
30341 if (unlikely(in_interrupt()))
30342 return __memcpy(to, from, len);
30343@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30344 kernel_fpu_begin();
30345
30346 __asm__ __volatile__ (
30347- "1: prefetch (%0)\n" /* This set is 28 bytes */
30348- " prefetch 64(%0)\n"
30349- " prefetch 128(%0)\n"
30350- " prefetch 192(%0)\n"
30351- " prefetch 256(%0)\n"
30352+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30353+ " prefetch 64(%1)\n"
30354+ " prefetch 128(%1)\n"
30355+ " prefetch 192(%1)\n"
30356+ " prefetch 256(%1)\n"
30357 "2: \n"
30358 ".section .fixup, \"ax\"\n"
30359- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30360+ "3: \n"
30361+
30362+#ifdef CONFIG_PAX_KERNEXEC
30363+ " movl %%cr0, %0\n"
30364+ " movl %0, %%eax\n"
30365+ " andl $0xFFFEFFFF, %%eax\n"
30366+ " movl %%eax, %%cr0\n"
30367+#endif
30368+
30369+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30370+
30371+#ifdef CONFIG_PAX_KERNEXEC
30372+ " movl %0, %%cr0\n"
30373+#endif
30374+
30375 " jmp 2b\n"
30376 ".previous\n"
30377 _ASM_EXTABLE(1b, 3b)
30378- : : "r" (from));
30379+ : "=&r" (cr0) : "r" (from) : "ax");
30380
30381 for ( ; i > 5; i--) {
30382 __asm__ __volatile__ (
30383- "1: prefetch 320(%0)\n"
30384- "2: movq (%0), %%mm0\n"
30385- " movq 8(%0), %%mm1\n"
30386- " movq 16(%0), %%mm2\n"
30387- " movq 24(%0), %%mm3\n"
30388- " movq %%mm0, (%1)\n"
30389- " movq %%mm1, 8(%1)\n"
30390- " movq %%mm2, 16(%1)\n"
30391- " movq %%mm3, 24(%1)\n"
30392- " movq 32(%0), %%mm0\n"
30393- " movq 40(%0), %%mm1\n"
30394- " movq 48(%0), %%mm2\n"
30395- " movq 56(%0), %%mm3\n"
30396- " movq %%mm0, 32(%1)\n"
30397- " movq %%mm1, 40(%1)\n"
30398- " movq %%mm2, 48(%1)\n"
30399- " movq %%mm3, 56(%1)\n"
30400+ "1: prefetch 320(%1)\n"
30401+ "2: movq (%1), %%mm0\n"
30402+ " movq 8(%1), %%mm1\n"
30403+ " movq 16(%1), %%mm2\n"
30404+ " movq 24(%1), %%mm3\n"
30405+ " movq %%mm0, (%2)\n"
30406+ " movq %%mm1, 8(%2)\n"
30407+ " movq %%mm2, 16(%2)\n"
30408+ " movq %%mm3, 24(%2)\n"
30409+ " movq 32(%1), %%mm0\n"
30410+ " movq 40(%1), %%mm1\n"
30411+ " movq 48(%1), %%mm2\n"
30412+ " movq 56(%1), %%mm3\n"
30413+ " movq %%mm0, 32(%2)\n"
30414+ " movq %%mm1, 40(%2)\n"
30415+ " movq %%mm2, 48(%2)\n"
30416+ " movq %%mm3, 56(%2)\n"
30417 ".section .fixup, \"ax\"\n"
30418- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30419+ "3:\n"
30420+
30421+#ifdef CONFIG_PAX_KERNEXEC
30422+ " movl %%cr0, %0\n"
30423+ " movl %0, %%eax\n"
30424+ " andl $0xFFFEFFFF, %%eax\n"
30425+ " movl %%eax, %%cr0\n"
30426+#endif
30427+
30428+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30429+
30430+#ifdef CONFIG_PAX_KERNEXEC
30431+ " movl %0, %%cr0\n"
30432+#endif
30433+
30434 " jmp 2b\n"
30435 ".previous\n"
30436 _ASM_EXTABLE(1b, 3b)
30437- : : "r" (from), "r" (to) : "memory");
30438+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30439
30440 from += 64;
30441 to += 64;
30442@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30443 static void fast_copy_page(void *to, void *from)
30444 {
30445 int i;
30446+ unsigned long cr0;
30447
30448 kernel_fpu_begin();
30449
30450@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30451 * but that is for later. -AV
30452 */
30453 __asm__ __volatile__(
30454- "1: prefetch (%0)\n"
30455- " prefetch 64(%0)\n"
30456- " prefetch 128(%0)\n"
30457- " prefetch 192(%0)\n"
30458- " prefetch 256(%0)\n"
30459+ "1: prefetch (%1)\n"
30460+ " prefetch 64(%1)\n"
30461+ " prefetch 128(%1)\n"
30462+ " prefetch 192(%1)\n"
30463+ " prefetch 256(%1)\n"
30464 "2: \n"
30465 ".section .fixup, \"ax\"\n"
30466- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30467+ "3: \n"
30468+
30469+#ifdef CONFIG_PAX_KERNEXEC
30470+ " movl %%cr0, %0\n"
30471+ " movl %0, %%eax\n"
30472+ " andl $0xFFFEFFFF, %%eax\n"
30473+ " movl %%eax, %%cr0\n"
30474+#endif
30475+
30476+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30477+
30478+#ifdef CONFIG_PAX_KERNEXEC
30479+ " movl %0, %%cr0\n"
30480+#endif
30481+
30482 " jmp 2b\n"
30483 ".previous\n"
30484- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30485+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30486
30487 for (i = 0; i < (4096-320)/64; i++) {
30488 __asm__ __volatile__ (
30489- "1: prefetch 320(%0)\n"
30490- "2: movq (%0), %%mm0\n"
30491- " movntq %%mm0, (%1)\n"
30492- " movq 8(%0), %%mm1\n"
30493- " movntq %%mm1, 8(%1)\n"
30494- " movq 16(%0), %%mm2\n"
30495- " movntq %%mm2, 16(%1)\n"
30496- " movq 24(%0), %%mm3\n"
30497- " movntq %%mm3, 24(%1)\n"
30498- " movq 32(%0), %%mm4\n"
30499- " movntq %%mm4, 32(%1)\n"
30500- " movq 40(%0), %%mm5\n"
30501- " movntq %%mm5, 40(%1)\n"
30502- " movq 48(%0), %%mm6\n"
30503- " movntq %%mm6, 48(%1)\n"
30504- " movq 56(%0), %%mm7\n"
30505- " movntq %%mm7, 56(%1)\n"
30506+ "1: prefetch 320(%1)\n"
30507+ "2: movq (%1), %%mm0\n"
30508+ " movntq %%mm0, (%2)\n"
30509+ " movq 8(%1), %%mm1\n"
30510+ " movntq %%mm1, 8(%2)\n"
30511+ " movq 16(%1), %%mm2\n"
30512+ " movntq %%mm2, 16(%2)\n"
30513+ " movq 24(%1), %%mm3\n"
30514+ " movntq %%mm3, 24(%2)\n"
30515+ " movq 32(%1), %%mm4\n"
30516+ " movntq %%mm4, 32(%2)\n"
30517+ " movq 40(%1), %%mm5\n"
30518+ " movntq %%mm5, 40(%2)\n"
30519+ " movq 48(%1), %%mm6\n"
30520+ " movntq %%mm6, 48(%2)\n"
30521+ " movq 56(%1), %%mm7\n"
30522+ " movntq %%mm7, 56(%2)\n"
30523 ".section .fixup, \"ax\"\n"
30524- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30525+ "3:\n"
30526+
30527+#ifdef CONFIG_PAX_KERNEXEC
30528+ " movl %%cr0, %0\n"
30529+ " movl %0, %%eax\n"
30530+ " andl $0xFFFEFFFF, %%eax\n"
30531+ " movl %%eax, %%cr0\n"
30532+#endif
30533+
30534+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30535+
30536+#ifdef CONFIG_PAX_KERNEXEC
30537+ " movl %0, %%cr0\n"
30538+#endif
30539+
30540 " jmp 2b\n"
30541 ".previous\n"
30542- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30543+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30544
30545 from += 64;
30546 to += 64;
30547@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30548 static void fast_copy_page(void *to, void *from)
30549 {
30550 int i;
30551+ unsigned long cr0;
30552
30553 kernel_fpu_begin();
30554
30555 __asm__ __volatile__ (
30556- "1: prefetch (%0)\n"
30557- " prefetch 64(%0)\n"
30558- " prefetch 128(%0)\n"
30559- " prefetch 192(%0)\n"
30560- " prefetch 256(%0)\n"
30561+ "1: prefetch (%1)\n"
30562+ " prefetch 64(%1)\n"
30563+ " prefetch 128(%1)\n"
30564+ " prefetch 192(%1)\n"
30565+ " prefetch 256(%1)\n"
30566 "2: \n"
30567 ".section .fixup, \"ax\"\n"
30568- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30569+ "3: \n"
30570+
30571+#ifdef CONFIG_PAX_KERNEXEC
30572+ " movl %%cr0, %0\n"
30573+ " movl %0, %%eax\n"
30574+ " andl $0xFFFEFFFF, %%eax\n"
30575+ " movl %%eax, %%cr0\n"
30576+#endif
30577+
30578+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30579+
30580+#ifdef CONFIG_PAX_KERNEXEC
30581+ " movl %0, %%cr0\n"
30582+#endif
30583+
30584 " jmp 2b\n"
30585 ".previous\n"
30586- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30587+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30588
30589 for (i = 0; i < 4096/64; i++) {
30590 __asm__ __volatile__ (
30591- "1: prefetch 320(%0)\n"
30592- "2: movq (%0), %%mm0\n"
30593- " movq 8(%0), %%mm1\n"
30594- " movq 16(%0), %%mm2\n"
30595- " movq 24(%0), %%mm3\n"
30596- " movq %%mm0, (%1)\n"
30597- " movq %%mm1, 8(%1)\n"
30598- " movq %%mm2, 16(%1)\n"
30599- " movq %%mm3, 24(%1)\n"
30600- " movq 32(%0), %%mm0\n"
30601- " movq 40(%0), %%mm1\n"
30602- " movq 48(%0), %%mm2\n"
30603- " movq 56(%0), %%mm3\n"
30604- " movq %%mm0, 32(%1)\n"
30605- " movq %%mm1, 40(%1)\n"
30606- " movq %%mm2, 48(%1)\n"
30607- " movq %%mm3, 56(%1)\n"
30608+ "1: prefetch 320(%1)\n"
30609+ "2: movq (%1), %%mm0\n"
30610+ " movq 8(%1), %%mm1\n"
30611+ " movq 16(%1), %%mm2\n"
30612+ " movq 24(%1), %%mm3\n"
30613+ " movq %%mm0, (%2)\n"
30614+ " movq %%mm1, 8(%2)\n"
30615+ " movq %%mm2, 16(%2)\n"
30616+ " movq %%mm3, 24(%2)\n"
30617+ " movq 32(%1), %%mm0\n"
30618+ " movq 40(%1), %%mm1\n"
30619+ " movq 48(%1), %%mm2\n"
30620+ " movq 56(%1), %%mm3\n"
30621+ " movq %%mm0, 32(%2)\n"
30622+ " movq %%mm1, 40(%2)\n"
30623+ " movq %%mm2, 48(%2)\n"
30624+ " movq %%mm3, 56(%2)\n"
30625 ".section .fixup, \"ax\"\n"
30626- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30627+ "3:\n"
30628+
30629+#ifdef CONFIG_PAX_KERNEXEC
30630+ " movl %%cr0, %0\n"
30631+ " movl %0, %%eax\n"
30632+ " andl $0xFFFEFFFF, %%eax\n"
30633+ " movl %%eax, %%cr0\n"
30634+#endif
30635+
30636+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30637+
30638+#ifdef CONFIG_PAX_KERNEXEC
30639+ " movl %0, %%cr0\n"
30640+#endif
30641+
30642 " jmp 2b\n"
30643 ".previous\n"
30644 _ASM_EXTABLE(1b, 3b)
30645- : : "r" (from), "r" (to) : "memory");
30646+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30647
30648 from += 64;
30649 to += 64;
30650diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30651index f6d13ee..d789440 100644
30652--- a/arch/x86/lib/msr-reg.S
30653+++ b/arch/x86/lib/msr-reg.S
30654@@ -3,6 +3,7 @@
30655 #include <asm/dwarf2.h>
30656 #include <asm/asm.h>
30657 #include <asm/msr.h>
30658+#include <asm/alternative-asm.h>
30659
30660 #ifdef CONFIG_X86_64
30661 /*
30662@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30663 movl %edi, 28(%r10)
30664 popq_cfi %rbp
30665 popq_cfi %rbx
30666+ pax_force_retaddr
30667 ret
30668 3:
30669 CFI_RESTORE_STATE
30670diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30671index fc6ba17..d4d989d 100644
30672--- a/arch/x86/lib/putuser.S
30673+++ b/arch/x86/lib/putuser.S
30674@@ -16,7 +16,9 @@
30675 #include <asm/errno.h>
30676 #include <asm/asm.h>
30677 #include <asm/smap.h>
30678-
30679+#include <asm/segment.h>
30680+#include <asm/pgtable.h>
30681+#include <asm/alternative-asm.h>
30682
30683 /*
30684 * __put_user_X
30685@@ -30,57 +32,125 @@
30686 * as they get called from within inline assembly.
30687 */
30688
30689-#define ENTER CFI_STARTPROC ; \
30690- GET_THREAD_INFO(%_ASM_BX)
30691-#define EXIT ASM_CLAC ; \
30692- ret ; \
30693+#define ENTER CFI_STARTPROC
30694+#define EXIT ASM_CLAC ; \
30695+ pax_force_retaddr ; \
30696+ ret ; \
30697 CFI_ENDPROC
30698
30699+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30700+#define _DEST %_ASM_CX,%_ASM_BX
30701+#else
30702+#define _DEST %_ASM_CX
30703+#endif
30704+
30705+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30706+#define __copyuser_seg gs;
30707+#else
30708+#define __copyuser_seg
30709+#endif
30710+
30711 .text
30712 ENTRY(__put_user_1)
30713 ENTER
30714+
30715+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30716+ GET_THREAD_INFO(%_ASM_BX)
30717 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30718 jae bad_put_user
30719 ASM_STAC
30720-1: movb %al,(%_ASM_CX)
30721+
30722+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30723+ mov pax_user_shadow_base,%_ASM_BX
30724+ cmp %_ASM_BX,%_ASM_CX
30725+ jb 1234f
30726+ xor %ebx,%ebx
30727+1234:
30728+#endif
30729+
30730+#endif
30731+
30732+1: __copyuser_seg movb %al,(_DEST)
30733 xor %eax,%eax
30734 EXIT
30735 ENDPROC(__put_user_1)
30736
30737 ENTRY(__put_user_2)
30738 ENTER
30739+
30740+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30741+ GET_THREAD_INFO(%_ASM_BX)
30742 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30743 sub $1,%_ASM_BX
30744 cmp %_ASM_BX,%_ASM_CX
30745 jae bad_put_user
30746 ASM_STAC
30747-2: movw %ax,(%_ASM_CX)
30748+
30749+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30750+ mov pax_user_shadow_base,%_ASM_BX
30751+ cmp %_ASM_BX,%_ASM_CX
30752+ jb 1234f
30753+ xor %ebx,%ebx
30754+1234:
30755+#endif
30756+
30757+#endif
30758+
30759+2: __copyuser_seg movw %ax,(_DEST)
30760 xor %eax,%eax
30761 EXIT
30762 ENDPROC(__put_user_2)
30763
30764 ENTRY(__put_user_4)
30765 ENTER
30766+
30767+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30768+ GET_THREAD_INFO(%_ASM_BX)
30769 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30770 sub $3,%_ASM_BX
30771 cmp %_ASM_BX,%_ASM_CX
30772 jae bad_put_user
30773 ASM_STAC
30774-3: movl %eax,(%_ASM_CX)
30775+
30776+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30777+ mov pax_user_shadow_base,%_ASM_BX
30778+ cmp %_ASM_BX,%_ASM_CX
30779+ jb 1234f
30780+ xor %ebx,%ebx
30781+1234:
30782+#endif
30783+
30784+#endif
30785+
30786+3: __copyuser_seg movl %eax,(_DEST)
30787 xor %eax,%eax
30788 EXIT
30789 ENDPROC(__put_user_4)
30790
30791 ENTRY(__put_user_8)
30792 ENTER
30793+
30794+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30795+ GET_THREAD_INFO(%_ASM_BX)
30796 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30797 sub $7,%_ASM_BX
30798 cmp %_ASM_BX,%_ASM_CX
30799 jae bad_put_user
30800 ASM_STAC
30801-4: mov %_ASM_AX,(%_ASM_CX)
30802+
30803+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30804+ mov pax_user_shadow_base,%_ASM_BX
30805+ cmp %_ASM_BX,%_ASM_CX
30806+ jb 1234f
30807+ xor %ebx,%ebx
30808+1234:
30809+#endif
30810+
30811+#endif
30812+
30813+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30814 #ifdef CONFIG_X86_32
30815-5: movl %edx,4(%_ASM_CX)
30816+5: __copyuser_seg movl %edx,4(_DEST)
30817 #endif
30818 xor %eax,%eax
30819 EXIT
30820diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30821index 1cad221..de671ee 100644
30822--- a/arch/x86/lib/rwlock.S
30823+++ b/arch/x86/lib/rwlock.S
30824@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30825 FRAME
30826 0: LOCK_PREFIX
30827 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30828+
30829+#ifdef CONFIG_PAX_REFCOUNT
30830+ jno 1234f
30831+ LOCK_PREFIX
30832+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30833+ int $4
30834+1234:
30835+ _ASM_EXTABLE(1234b, 1234b)
30836+#endif
30837+
30838 1: rep; nop
30839 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30840 jne 1b
30841 LOCK_PREFIX
30842 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30843+
30844+#ifdef CONFIG_PAX_REFCOUNT
30845+ jno 1234f
30846+ LOCK_PREFIX
30847+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30848+ int $4
30849+1234:
30850+ _ASM_EXTABLE(1234b, 1234b)
30851+#endif
30852+
30853 jnz 0b
30854 ENDFRAME
30855+ pax_force_retaddr
30856 ret
30857 CFI_ENDPROC
30858 END(__write_lock_failed)
30859@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30860 FRAME
30861 0: LOCK_PREFIX
30862 READ_LOCK_SIZE(inc) (%__lock_ptr)
30863+
30864+#ifdef CONFIG_PAX_REFCOUNT
30865+ jno 1234f
30866+ LOCK_PREFIX
30867+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30868+ int $4
30869+1234:
30870+ _ASM_EXTABLE(1234b, 1234b)
30871+#endif
30872+
30873 1: rep; nop
30874 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30875 js 1b
30876 LOCK_PREFIX
30877 READ_LOCK_SIZE(dec) (%__lock_ptr)
30878+
30879+#ifdef CONFIG_PAX_REFCOUNT
30880+ jno 1234f
30881+ LOCK_PREFIX
30882+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30883+ int $4
30884+1234:
30885+ _ASM_EXTABLE(1234b, 1234b)
30886+#endif
30887+
30888 js 0b
30889 ENDFRAME
30890+ pax_force_retaddr
30891 ret
30892 CFI_ENDPROC
30893 END(__read_lock_failed)
30894diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30895index 5dff5f0..cadebf4 100644
30896--- a/arch/x86/lib/rwsem.S
30897+++ b/arch/x86/lib/rwsem.S
30898@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30899 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30900 CFI_RESTORE __ASM_REG(dx)
30901 restore_common_regs
30902+ pax_force_retaddr
30903 ret
30904 CFI_ENDPROC
30905 ENDPROC(call_rwsem_down_read_failed)
30906@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30907 movq %rax,%rdi
30908 call rwsem_down_write_failed
30909 restore_common_regs
30910+ pax_force_retaddr
30911 ret
30912 CFI_ENDPROC
30913 ENDPROC(call_rwsem_down_write_failed)
30914@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30915 movq %rax,%rdi
30916 call rwsem_wake
30917 restore_common_regs
30918-1: ret
30919+1: pax_force_retaddr
30920+ ret
30921 CFI_ENDPROC
30922 ENDPROC(call_rwsem_wake)
30923
30924@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30925 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30926 CFI_RESTORE __ASM_REG(dx)
30927 restore_common_regs
30928+ pax_force_retaddr
30929 ret
30930 CFI_ENDPROC
30931 ENDPROC(call_rwsem_downgrade_wake)
30932diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30933index a63efd6..8149fbe 100644
30934--- a/arch/x86/lib/thunk_64.S
30935+++ b/arch/x86/lib/thunk_64.S
30936@@ -8,6 +8,7 @@
30937 #include <linux/linkage.h>
30938 #include <asm/dwarf2.h>
30939 #include <asm/calling.h>
30940+#include <asm/alternative-asm.h>
30941
30942 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30943 .macro THUNK name, func, put_ret_addr_in_rdi=0
30944@@ -15,11 +16,11 @@
30945 \name:
30946 CFI_STARTPROC
30947
30948- /* this one pushes 9 elems, the next one would be %rIP */
30949- SAVE_ARGS
30950+ /* this one pushes 15+1 elems, the next one would be %rIP */
30951+ SAVE_ARGS 8
30952
30953 .if \put_ret_addr_in_rdi
30954- movq_cfi_restore 9*8, rdi
30955+ movq_cfi_restore RIP, rdi
30956 .endif
30957
30958 call \func
30959@@ -38,8 +39,9 @@
30960
30961 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30962 CFI_STARTPROC
30963- SAVE_ARGS
30964+ SAVE_ARGS 8
30965 restore:
30966- RESTORE_ARGS
30967+ RESTORE_ARGS 1,8
30968+ pax_force_retaddr
30969 ret
30970 CFI_ENDPROC
30971diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30972index e2f5e21..4b22130 100644
30973--- a/arch/x86/lib/usercopy_32.c
30974+++ b/arch/x86/lib/usercopy_32.c
30975@@ -42,11 +42,13 @@ do { \
30976 int __d0; \
30977 might_fault(); \
30978 __asm__ __volatile__( \
30979+ __COPYUSER_SET_ES \
30980 ASM_STAC "\n" \
30981 "0: rep; stosl\n" \
30982 " movl %2,%0\n" \
30983 "1: rep; stosb\n" \
30984 "2: " ASM_CLAC "\n" \
30985+ __COPYUSER_RESTORE_ES \
30986 ".section .fixup,\"ax\"\n" \
30987 "3: lea 0(%2,%0,4),%0\n" \
30988 " jmp 2b\n" \
30989@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30990
30991 #ifdef CONFIG_X86_INTEL_USERCOPY
30992 static unsigned long
30993-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30994+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30995 {
30996 int d0, d1;
30997 __asm__ __volatile__(
30998@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30999 " .align 2,0x90\n"
31000 "3: movl 0(%4), %%eax\n"
31001 "4: movl 4(%4), %%edx\n"
31002- "5: movl %%eax, 0(%3)\n"
31003- "6: movl %%edx, 4(%3)\n"
31004+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31005+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31006 "7: movl 8(%4), %%eax\n"
31007 "8: movl 12(%4),%%edx\n"
31008- "9: movl %%eax, 8(%3)\n"
31009- "10: movl %%edx, 12(%3)\n"
31010+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31011+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31012 "11: movl 16(%4), %%eax\n"
31013 "12: movl 20(%4), %%edx\n"
31014- "13: movl %%eax, 16(%3)\n"
31015- "14: movl %%edx, 20(%3)\n"
31016+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31017+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31018 "15: movl 24(%4), %%eax\n"
31019 "16: movl 28(%4), %%edx\n"
31020- "17: movl %%eax, 24(%3)\n"
31021- "18: movl %%edx, 28(%3)\n"
31022+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31023+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31024 "19: movl 32(%4), %%eax\n"
31025 "20: movl 36(%4), %%edx\n"
31026- "21: movl %%eax, 32(%3)\n"
31027- "22: movl %%edx, 36(%3)\n"
31028+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31029+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31030 "23: movl 40(%4), %%eax\n"
31031 "24: movl 44(%4), %%edx\n"
31032- "25: movl %%eax, 40(%3)\n"
31033- "26: movl %%edx, 44(%3)\n"
31034+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31035+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31036 "27: movl 48(%4), %%eax\n"
31037 "28: movl 52(%4), %%edx\n"
31038- "29: movl %%eax, 48(%3)\n"
31039- "30: movl %%edx, 52(%3)\n"
31040+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31041+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31042 "31: movl 56(%4), %%eax\n"
31043 "32: movl 60(%4), %%edx\n"
31044- "33: movl %%eax, 56(%3)\n"
31045- "34: movl %%edx, 60(%3)\n"
31046+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31047+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31048 " addl $-64, %0\n"
31049 " addl $64, %4\n"
31050 " addl $64, %3\n"
31051@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31052 " shrl $2, %0\n"
31053 " andl $3, %%eax\n"
31054 " cld\n"
31055+ __COPYUSER_SET_ES
31056 "99: rep; movsl\n"
31057 "36: movl %%eax, %0\n"
31058 "37: rep; movsb\n"
31059 "100:\n"
31060+ __COPYUSER_RESTORE_ES
31061+ ".section .fixup,\"ax\"\n"
31062+ "101: lea 0(%%eax,%0,4),%0\n"
31063+ " jmp 100b\n"
31064+ ".previous\n"
31065+ _ASM_EXTABLE(1b,100b)
31066+ _ASM_EXTABLE(2b,100b)
31067+ _ASM_EXTABLE(3b,100b)
31068+ _ASM_EXTABLE(4b,100b)
31069+ _ASM_EXTABLE(5b,100b)
31070+ _ASM_EXTABLE(6b,100b)
31071+ _ASM_EXTABLE(7b,100b)
31072+ _ASM_EXTABLE(8b,100b)
31073+ _ASM_EXTABLE(9b,100b)
31074+ _ASM_EXTABLE(10b,100b)
31075+ _ASM_EXTABLE(11b,100b)
31076+ _ASM_EXTABLE(12b,100b)
31077+ _ASM_EXTABLE(13b,100b)
31078+ _ASM_EXTABLE(14b,100b)
31079+ _ASM_EXTABLE(15b,100b)
31080+ _ASM_EXTABLE(16b,100b)
31081+ _ASM_EXTABLE(17b,100b)
31082+ _ASM_EXTABLE(18b,100b)
31083+ _ASM_EXTABLE(19b,100b)
31084+ _ASM_EXTABLE(20b,100b)
31085+ _ASM_EXTABLE(21b,100b)
31086+ _ASM_EXTABLE(22b,100b)
31087+ _ASM_EXTABLE(23b,100b)
31088+ _ASM_EXTABLE(24b,100b)
31089+ _ASM_EXTABLE(25b,100b)
31090+ _ASM_EXTABLE(26b,100b)
31091+ _ASM_EXTABLE(27b,100b)
31092+ _ASM_EXTABLE(28b,100b)
31093+ _ASM_EXTABLE(29b,100b)
31094+ _ASM_EXTABLE(30b,100b)
31095+ _ASM_EXTABLE(31b,100b)
31096+ _ASM_EXTABLE(32b,100b)
31097+ _ASM_EXTABLE(33b,100b)
31098+ _ASM_EXTABLE(34b,100b)
31099+ _ASM_EXTABLE(35b,100b)
31100+ _ASM_EXTABLE(36b,100b)
31101+ _ASM_EXTABLE(37b,100b)
31102+ _ASM_EXTABLE(99b,101b)
31103+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
31104+ : "1"(to), "2"(from), "0"(size)
31105+ : "eax", "edx", "memory");
31106+ return size;
31107+}
31108+
31109+static unsigned long
31110+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31111+{
31112+ int d0, d1;
31113+ __asm__ __volatile__(
31114+ " .align 2,0x90\n"
31115+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31116+ " cmpl $67, %0\n"
31117+ " jbe 3f\n"
31118+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31119+ " .align 2,0x90\n"
31120+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31121+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31122+ "5: movl %%eax, 0(%3)\n"
31123+ "6: movl %%edx, 4(%3)\n"
31124+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31125+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31126+ "9: movl %%eax, 8(%3)\n"
31127+ "10: movl %%edx, 12(%3)\n"
31128+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31129+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31130+ "13: movl %%eax, 16(%3)\n"
31131+ "14: movl %%edx, 20(%3)\n"
31132+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31133+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31134+ "17: movl %%eax, 24(%3)\n"
31135+ "18: movl %%edx, 28(%3)\n"
31136+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31137+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31138+ "21: movl %%eax, 32(%3)\n"
31139+ "22: movl %%edx, 36(%3)\n"
31140+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31141+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31142+ "25: movl %%eax, 40(%3)\n"
31143+ "26: movl %%edx, 44(%3)\n"
31144+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31145+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31146+ "29: movl %%eax, 48(%3)\n"
31147+ "30: movl %%edx, 52(%3)\n"
31148+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31149+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31150+ "33: movl %%eax, 56(%3)\n"
31151+ "34: movl %%edx, 60(%3)\n"
31152+ " addl $-64, %0\n"
31153+ " addl $64, %4\n"
31154+ " addl $64, %3\n"
31155+ " cmpl $63, %0\n"
31156+ " ja 1b\n"
31157+ "35: movl %0, %%eax\n"
31158+ " shrl $2, %0\n"
31159+ " andl $3, %%eax\n"
31160+ " cld\n"
31161+ "99: rep; "__copyuser_seg" movsl\n"
31162+ "36: movl %%eax, %0\n"
31163+ "37: rep; "__copyuser_seg" movsb\n"
31164+ "100:\n"
31165 ".section .fixup,\"ax\"\n"
31166 "101: lea 0(%%eax,%0,4),%0\n"
31167 " jmp 100b\n"
31168@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31169 int d0, d1;
31170 __asm__ __volatile__(
31171 " .align 2,0x90\n"
31172- "0: movl 32(%4), %%eax\n"
31173+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31174 " cmpl $67, %0\n"
31175 " jbe 2f\n"
31176- "1: movl 64(%4), %%eax\n"
31177+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31178 " .align 2,0x90\n"
31179- "2: movl 0(%4), %%eax\n"
31180- "21: movl 4(%4), %%edx\n"
31181+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31182+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31183 " movl %%eax, 0(%3)\n"
31184 " movl %%edx, 4(%3)\n"
31185- "3: movl 8(%4), %%eax\n"
31186- "31: movl 12(%4),%%edx\n"
31187+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31188+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31189 " movl %%eax, 8(%3)\n"
31190 " movl %%edx, 12(%3)\n"
31191- "4: movl 16(%4), %%eax\n"
31192- "41: movl 20(%4), %%edx\n"
31193+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31194+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31195 " movl %%eax, 16(%3)\n"
31196 " movl %%edx, 20(%3)\n"
31197- "10: movl 24(%4), %%eax\n"
31198- "51: movl 28(%4), %%edx\n"
31199+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31200+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31201 " movl %%eax, 24(%3)\n"
31202 " movl %%edx, 28(%3)\n"
31203- "11: movl 32(%4), %%eax\n"
31204- "61: movl 36(%4), %%edx\n"
31205+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31206+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31207 " movl %%eax, 32(%3)\n"
31208 " movl %%edx, 36(%3)\n"
31209- "12: movl 40(%4), %%eax\n"
31210- "71: movl 44(%4), %%edx\n"
31211+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31212+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31213 " movl %%eax, 40(%3)\n"
31214 " movl %%edx, 44(%3)\n"
31215- "13: movl 48(%4), %%eax\n"
31216- "81: movl 52(%4), %%edx\n"
31217+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31218+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31219 " movl %%eax, 48(%3)\n"
31220 " movl %%edx, 52(%3)\n"
31221- "14: movl 56(%4), %%eax\n"
31222- "91: movl 60(%4), %%edx\n"
31223+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31224+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31225 " movl %%eax, 56(%3)\n"
31226 " movl %%edx, 60(%3)\n"
31227 " addl $-64, %0\n"
31228@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31229 " shrl $2, %0\n"
31230 " andl $3, %%eax\n"
31231 " cld\n"
31232- "6: rep; movsl\n"
31233+ "6: rep; "__copyuser_seg" movsl\n"
31234 " movl %%eax,%0\n"
31235- "7: rep; movsb\n"
31236+ "7: rep; "__copyuser_seg" movsb\n"
31237 "8:\n"
31238 ".section .fixup,\"ax\"\n"
31239 "9: lea 0(%%eax,%0,4),%0\n"
31240@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31241
31242 __asm__ __volatile__(
31243 " .align 2,0x90\n"
31244- "0: movl 32(%4), %%eax\n"
31245+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31246 " cmpl $67, %0\n"
31247 " jbe 2f\n"
31248- "1: movl 64(%4), %%eax\n"
31249+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31250 " .align 2,0x90\n"
31251- "2: movl 0(%4), %%eax\n"
31252- "21: movl 4(%4), %%edx\n"
31253+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31254+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31255 " movnti %%eax, 0(%3)\n"
31256 " movnti %%edx, 4(%3)\n"
31257- "3: movl 8(%4), %%eax\n"
31258- "31: movl 12(%4),%%edx\n"
31259+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31260+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31261 " movnti %%eax, 8(%3)\n"
31262 " movnti %%edx, 12(%3)\n"
31263- "4: movl 16(%4), %%eax\n"
31264- "41: movl 20(%4), %%edx\n"
31265+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31266+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31267 " movnti %%eax, 16(%3)\n"
31268 " movnti %%edx, 20(%3)\n"
31269- "10: movl 24(%4), %%eax\n"
31270- "51: movl 28(%4), %%edx\n"
31271+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31272+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31273 " movnti %%eax, 24(%3)\n"
31274 " movnti %%edx, 28(%3)\n"
31275- "11: movl 32(%4), %%eax\n"
31276- "61: movl 36(%4), %%edx\n"
31277+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31278+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31279 " movnti %%eax, 32(%3)\n"
31280 " movnti %%edx, 36(%3)\n"
31281- "12: movl 40(%4), %%eax\n"
31282- "71: movl 44(%4), %%edx\n"
31283+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31284+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31285 " movnti %%eax, 40(%3)\n"
31286 " movnti %%edx, 44(%3)\n"
31287- "13: movl 48(%4), %%eax\n"
31288- "81: movl 52(%4), %%edx\n"
31289+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31290+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31291 " movnti %%eax, 48(%3)\n"
31292 " movnti %%edx, 52(%3)\n"
31293- "14: movl 56(%4), %%eax\n"
31294- "91: movl 60(%4), %%edx\n"
31295+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31296+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31297 " movnti %%eax, 56(%3)\n"
31298 " movnti %%edx, 60(%3)\n"
31299 " addl $-64, %0\n"
31300@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31301 " shrl $2, %0\n"
31302 " andl $3, %%eax\n"
31303 " cld\n"
31304- "6: rep; movsl\n"
31305+ "6: rep; "__copyuser_seg" movsl\n"
31306 " movl %%eax,%0\n"
31307- "7: rep; movsb\n"
31308+ "7: rep; "__copyuser_seg" movsb\n"
31309 "8:\n"
31310 ".section .fixup,\"ax\"\n"
31311 "9: lea 0(%%eax,%0,4),%0\n"
31312@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31313
31314 __asm__ __volatile__(
31315 " .align 2,0x90\n"
31316- "0: movl 32(%4), %%eax\n"
31317+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31318 " cmpl $67, %0\n"
31319 " jbe 2f\n"
31320- "1: movl 64(%4), %%eax\n"
31321+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31322 " .align 2,0x90\n"
31323- "2: movl 0(%4), %%eax\n"
31324- "21: movl 4(%4), %%edx\n"
31325+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31326+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31327 " movnti %%eax, 0(%3)\n"
31328 " movnti %%edx, 4(%3)\n"
31329- "3: movl 8(%4), %%eax\n"
31330- "31: movl 12(%4),%%edx\n"
31331+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31332+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31333 " movnti %%eax, 8(%3)\n"
31334 " movnti %%edx, 12(%3)\n"
31335- "4: movl 16(%4), %%eax\n"
31336- "41: movl 20(%4), %%edx\n"
31337+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31338+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31339 " movnti %%eax, 16(%3)\n"
31340 " movnti %%edx, 20(%3)\n"
31341- "10: movl 24(%4), %%eax\n"
31342- "51: movl 28(%4), %%edx\n"
31343+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31344+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31345 " movnti %%eax, 24(%3)\n"
31346 " movnti %%edx, 28(%3)\n"
31347- "11: movl 32(%4), %%eax\n"
31348- "61: movl 36(%4), %%edx\n"
31349+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31350+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31351 " movnti %%eax, 32(%3)\n"
31352 " movnti %%edx, 36(%3)\n"
31353- "12: movl 40(%4), %%eax\n"
31354- "71: movl 44(%4), %%edx\n"
31355+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31356+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31357 " movnti %%eax, 40(%3)\n"
31358 " movnti %%edx, 44(%3)\n"
31359- "13: movl 48(%4), %%eax\n"
31360- "81: movl 52(%4), %%edx\n"
31361+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31362+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31363 " movnti %%eax, 48(%3)\n"
31364 " movnti %%edx, 52(%3)\n"
31365- "14: movl 56(%4), %%eax\n"
31366- "91: movl 60(%4), %%edx\n"
31367+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31368+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31369 " movnti %%eax, 56(%3)\n"
31370 " movnti %%edx, 60(%3)\n"
31371 " addl $-64, %0\n"
31372@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31373 " shrl $2, %0\n"
31374 " andl $3, %%eax\n"
31375 " cld\n"
31376- "6: rep; movsl\n"
31377+ "6: rep; "__copyuser_seg" movsl\n"
31378 " movl %%eax,%0\n"
31379- "7: rep; movsb\n"
31380+ "7: rep; "__copyuser_seg" movsb\n"
31381 "8:\n"
31382 ".section .fixup,\"ax\"\n"
31383 "9: lea 0(%%eax,%0,4),%0\n"
31384@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31385 */
31386 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31387 unsigned long size);
31388-unsigned long __copy_user_intel(void __user *to, const void *from,
31389+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31390+ unsigned long size);
31391+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31392 unsigned long size);
31393 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31394 const void __user *from, unsigned long size);
31395 #endif /* CONFIG_X86_INTEL_USERCOPY */
31396
31397 /* Generic arbitrary sized copy. */
31398-#define __copy_user(to, from, size) \
31399+#define __copy_user(to, from, size, prefix, set, restore) \
31400 do { \
31401 int __d0, __d1, __d2; \
31402 __asm__ __volatile__( \
31403+ set \
31404 " cmp $7,%0\n" \
31405 " jbe 1f\n" \
31406 " movl %1,%0\n" \
31407 " negl %0\n" \
31408 " andl $7,%0\n" \
31409 " subl %0,%3\n" \
31410- "4: rep; movsb\n" \
31411+ "4: rep; "prefix"movsb\n" \
31412 " movl %3,%0\n" \
31413 " shrl $2,%0\n" \
31414 " andl $3,%3\n" \
31415 " .align 2,0x90\n" \
31416- "0: rep; movsl\n" \
31417+ "0: rep; "prefix"movsl\n" \
31418 " movl %3,%0\n" \
31419- "1: rep; movsb\n" \
31420+ "1: rep; "prefix"movsb\n" \
31421 "2:\n" \
31422+ restore \
31423 ".section .fixup,\"ax\"\n" \
31424 "5: addl %3,%0\n" \
31425 " jmp 2b\n" \
31426@@ -538,14 +650,14 @@ do { \
31427 " negl %0\n" \
31428 " andl $7,%0\n" \
31429 " subl %0,%3\n" \
31430- "4: rep; movsb\n" \
31431+ "4: rep; "__copyuser_seg"movsb\n" \
31432 " movl %3,%0\n" \
31433 " shrl $2,%0\n" \
31434 " andl $3,%3\n" \
31435 " .align 2,0x90\n" \
31436- "0: rep; movsl\n" \
31437+ "0: rep; "__copyuser_seg"movsl\n" \
31438 " movl %3,%0\n" \
31439- "1: rep; movsb\n" \
31440+ "1: rep; "__copyuser_seg"movsb\n" \
31441 "2:\n" \
31442 ".section .fixup,\"ax\"\n" \
31443 "5: addl %3,%0\n" \
31444@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31445 {
31446 stac();
31447 if (movsl_is_ok(to, from, n))
31448- __copy_user(to, from, n);
31449+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31450 else
31451- n = __copy_user_intel(to, from, n);
31452+ n = __generic_copy_to_user_intel(to, from, n);
31453 clac();
31454 return n;
31455 }
31456@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31457 {
31458 stac();
31459 if (movsl_is_ok(to, from, n))
31460- __copy_user(to, from, n);
31461+ __copy_user(to, from, n, __copyuser_seg, "", "");
31462 else
31463- n = __copy_user_intel((void __user *)to,
31464- (const void *)from, n);
31465+ n = __generic_copy_from_user_intel(to, from, n);
31466 clac();
31467 return n;
31468 }
31469@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31470 if (n > 64 && cpu_has_xmm2)
31471 n = __copy_user_intel_nocache(to, from, n);
31472 else
31473- __copy_user(to, from, n);
31474+ __copy_user(to, from, n, __copyuser_seg, "", "");
31475 #else
31476- __copy_user(to, from, n);
31477+ __copy_user(to, from, n, __copyuser_seg, "", "");
31478 #endif
31479 clac();
31480 return n;
31481 }
31482 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31483
31484-/**
31485- * copy_to_user: - Copy a block of data into user space.
31486- * @to: Destination address, in user space.
31487- * @from: Source address, in kernel space.
31488- * @n: Number of bytes to copy.
31489- *
31490- * Context: User context only. This function may sleep.
31491- *
31492- * Copy data from kernel space to user space.
31493- *
31494- * Returns number of bytes that could not be copied.
31495- * On success, this will be zero.
31496- */
31497-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31498+#ifdef CONFIG_PAX_MEMORY_UDEREF
31499+void __set_fs(mm_segment_t x)
31500 {
31501- if (access_ok(VERIFY_WRITE, to, n))
31502- n = __copy_to_user(to, from, n);
31503- return n;
31504+ switch (x.seg) {
31505+ case 0:
31506+ loadsegment(gs, 0);
31507+ break;
31508+ case TASK_SIZE_MAX:
31509+ loadsegment(gs, __USER_DS);
31510+ break;
31511+ case -1UL:
31512+ loadsegment(gs, __KERNEL_DS);
31513+ break;
31514+ default:
31515+ BUG();
31516+ }
31517 }
31518-EXPORT_SYMBOL(_copy_to_user);
31519+EXPORT_SYMBOL(__set_fs);
31520
31521-/**
31522- * copy_from_user: - Copy a block of data from user space.
31523- * @to: Destination address, in kernel space.
31524- * @from: Source address, in user space.
31525- * @n: Number of bytes to copy.
31526- *
31527- * Context: User context only. This function may sleep.
31528- *
31529- * Copy data from user space to kernel space.
31530- *
31531- * Returns number of bytes that could not be copied.
31532- * On success, this will be zero.
31533- *
31534- * If some data could not be copied, this function will pad the copied
31535- * data to the requested size using zero bytes.
31536- */
31537-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31538+void set_fs(mm_segment_t x)
31539 {
31540- if (access_ok(VERIFY_READ, from, n))
31541- n = __copy_from_user(to, from, n);
31542- else
31543- memset(to, 0, n);
31544- return n;
31545+ current_thread_info()->addr_limit = x;
31546+ __set_fs(x);
31547 }
31548-EXPORT_SYMBOL(_copy_from_user);
31549+EXPORT_SYMBOL(set_fs);
31550+#endif
31551diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31552index c905e89..01ab928 100644
31553--- a/arch/x86/lib/usercopy_64.c
31554+++ b/arch/x86/lib/usercopy_64.c
31555@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31556 might_fault();
31557 /* no memory constraint because it doesn't change any memory gcc knows
31558 about */
31559+ pax_open_userland();
31560 stac();
31561 asm volatile(
31562 " testq %[size8],%[size8]\n"
31563@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31564 _ASM_EXTABLE(0b,3b)
31565 _ASM_EXTABLE(1b,2b)
31566 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31567- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31568+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31569 [zero] "r" (0UL), [eight] "r" (8UL));
31570 clac();
31571+ pax_close_userland();
31572 return size;
31573 }
31574 EXPORT_SYMBOL(__clear_user);
31575@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31576 }
31577 EXPORT_SYMBOL(clear_user);
31578
31579-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31580+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31581 {
31582- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31583- return copy_user_generic((__force void *)to, (__force void *)from, len);
31584- }
31585- return len;
31586+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31587+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31588+ return len;
31589 }
31590 EXPORT_SYMBOL(copy_in_user);
31591
31592@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31593 * it is not necessary to optimize tail handling.
31594 */
31595 __visible unsigned long
31596-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31597+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31598 {
31599 char c;
31600 unsigned zero_len;
31601
31602+ clac();
31603+ pax_close_userland();
31604 for (; len; --len, to++) {
31605 if (__get_user_nocheck(c, from++, sizeof(char)))
31606 break;
31607@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31608 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31609 if (__put_user_nocheck(c, to++, sizeof(char)))
31610 break;
31611- clac();
31612 return len;
31613 }
31614diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31615index 6a19ad9..1c48f9a 100644
31616--- a/arch/x86/mm/Makefile
31617+++ b/arch/x86/mm/Makefile
31618@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31619 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31620
31621 obj-$(CONFIG_MEMTEST) += memtest.o
31622+
31623+quote:="
31624+obj-$(CONFIG_X86_64) += uderef_64.o
31625+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31626diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31627index 903ec1e..c4166b2 100644
31628--- a/arch/x86/mm/extable.c
31629+++ b/arch/x86/mm/extable.c
31630@@ -6,12 +6,24 @@
31631 static inline unsigned long
31632 ex_insn_addr(const struct exception_table_entry *x)
31633 {
31634- return (unsigned long)&x->insn + x->insn;
31635+ unsigned long reloc = 0;
31636+
31637+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31638+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31639+#endif
31640+
31641+ return (unsigned long)&x->insn + x->insn + reloc;
31642 }
31643 static inline unsigned long
31644 ex_fixup_addr(const struct exception_table_entry *x)
31645 {
31646- return (unsigned long)&x->fixup + x->fixup;
31647+ unsigned long reloc = 0;
31648+
31649+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31650+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31651+#endif
31652+
31653+ return (unsigned long)&x->fixup + x->fixup + reloc;
31654 }
31655
31656 int fixup_exception(struct pt_regs *regs)
31657@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31658 unsigned long new_ip;
31659
31660 #ifdef CONFIG_PNPBIOS
31661- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31662+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31663 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31664 extern u32 pnp_bios_is_utter_crap;
31665 pnp_bios_is_utter_crap = 1;
31666@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31667 i += 4;
31668 p->fixup -= i;
31669 i += 4;
31670+
31671+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31672+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31673+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31674+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31675+#endif
31676+
31677 }
31678 }
31679
31680diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31681index a10c8c7..35a5abb 100644
31682--- a/arch/x86/mm/fault.c
31683+++ b/arch/x86/mm/fault.c
31684@@ -14,11 +14,18 @@
31685 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31686 #include <linux/prefetch.h> /* prefetchw */
31687 #include <linux/context_tracking.h> /* exception_enter(), ... */
31688+#include <linux/unistd.h>
31689+#include <linux/compiler.h>
31690
31691 #include <asm/traps.h> /* dotraplinkage, ... */
31692 #include <asm/pgalloc.h> /* pgd_*(), ... */
31693 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31694 #include <asm/fixmap.h> /* VSYSCALL_START */
31695+#include <asm/tlbflush.h>
31696+
31697+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31698+#include <asm/stacktrace.h>
31699+#endif
31700
31701 #define CREATE_TRACE_POINTS
31702 #include <asm/trace/exceptions.h>
31703@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31704 int ret = 0;
31705
31706 /* kprobe_running() needs smp_processor_id() */
31707- if (kprobes_built_in() && !user_mode_vm(regs)) {
31708+ if (kprobes_built_in() && !user_mode(regs)) {
31709 preempt_disable();
31710 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31711 ret = 1;
31712@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31713 return !instr_lo || (instr_lo>>1) == 1;
31714 case 0x00:
31715 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31716- if (probe_kernel_address(instr, opcode))
31717+ if (user_mode(regs)) {
31718+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31719+ return 0;
31720+ } else if (probe_kernel_address(instr, opcode))
31721 return 0;
31722
31723 *prefetch = (instr_lo == 0xF) &&
31724@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31725 while (instr < max_instr) {
31726 unsigned char opcode;
31727
31728- if (probe_kernel_address(instr, opcode))
31729+ if (user_mode(regs)) {
31730+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31731+ break;
31732+ } else if (probe_kernel_address(instr, opcode))
31733 break;
31734
31735 instr++;
31736@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31737 force_sig_info(si_signo, &info, tsk);
31738 }
31739
31740+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31741+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31742+#endif
31743+
31744+#ifdef CONFIG_PAX_EMUTRAMP
31745+static int pax_handle_fetch_fault(struct pt_regs *regs);
31746+#endif
31747+
31748+#ifdef CONFIG_PAX_PAGEEXEC
31749+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31750+{
31751+ pgd_t *pgd;
31752+ pud_t *pud;
31753+ pmd_t *pmd;
31754+
31755+ pgd = pgd_offset(mm, address);
31756+ if (!pgd_present(*pgd))
31757+ return NULL;
31758+ pud = pud_offset(pgd, address);
31759+ if (!pud_present(*pud))
31760+ return NULL;
31761+ pmd = pmd_offset(pud, address);
31762+ if (!pmd_present(*pmd))
31763+ return NULL;
31764+ return pmd;
31765+}
31766+#endif
31767+
31768 DEFINE_SPINLOCK(pgd_lock);
31769 LIST_HEAD(pgd_list);
31770
31771@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31772 for (address = VMALLOC_START & PMD_MASK;
31773 address >= TASK_SIZE && address < FIXADDR_TOP;
31774 address += PMD_SIZE) {
31775+
31776+#ifdef CONFIG_PAX_PER_CPU_PGD
31777+ unsigned long cpu;
31778+#else
31779 struct page *page;
31780+#endif
31781
31782 spin_lock(&pgd_lock);
31783+
31784+#ifdef CONFIG_PAX_PER_CPU_PGD
31785+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31786+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31787+ pmd_t *ret;
31788+
31789+ ret = vmalloc_sync_one(pgd, address);
31790+ if (!ret)
31791+ break;
31792+ pgd = get_cpu_pgd(cpu, kernel);
31793+#else
31794 list_for_each_entry(page, &pgd_list, lru) {
31795+ pgd_t *pgd;
31796 spinlock_t *pgt_lock;
31797 pmd_t *ret;
31798
31799@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31800 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31801
31802 spin_lock(pgt_lock);
31803- ret = vmalloc_sync_one(page_address(page), address);
31804+ pgd = page_address(page);
31805+#endif
31806+
31807+ ret = vmalloc_sync_one(pgd, address);
31808+
31809+#ifndef CONFIG_PAX_PER_CPU_PGD
31810 spin_unlock(pgt_lock);
31811+#endif
31812
31813 if (!ret)
31814 break;
31815@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31816 * an interrupt in the middle of a task switch..
31817 */
31818 pgd_paddr = read_cr3();
31819+
31820+#ifdef CONFIG_PAX_PER_CPU_PGD
31821+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31822+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31823+#endif
31824+
31825 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31826 if (!pmd_k)
31827 return -1;
31828@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31829 * happen within a race in page table update. In the later
31830 * case just flush:
31831 */
31832- pgd = pgd_offset(current->active_mm, address);
31833+
31834 pgd_ref = pgd_offset_k(address);
31835 if (pgd_none(*pgd_ref))
31836 return -1;
31837
31838+#ifdef CONFIG_PAX_PER_CPU_PGD
31839+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31840+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31841+ if (pgd_none(*pgd)) {
31842+ set_pgd(pgd, *pgd_ref);
31843+ arch_flush_lazy_mmu_mode();
31844+ } else {
31845+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31846+ }
31847+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31848+#else
31849+ pgd = pgd_offset(current->active_mm, address);
31850+#endif
31851+
31852 if (pgd_none(*pgd)) {
31853 set_pgd(pgd, *pgd_ref);
31854 arch_flush_lazy_mmu_mode();
31855@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31856 static int is_errata100(struct pt_regs *regs, unsigned long address)
31857 {
31858 #ifdef CONFIG_X86_64
31859- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31860+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31861 return 1;
31862 #endif
31863 return 0;
31864@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31865 }
31866
31867 static const char nx_warning[] = KERN_CRIT
31868-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31869+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31870
31871 static void
31872 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31873@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31874 if (!oops_may_print())
31875 return;
31876
31877- if (error_code & PF_INSTR) {
31878+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31879 unsigned int level;
31880
31881 pte_t *pte = lookup_address(address, &level);
31882
31883 if (pte && pte_present(*pte) && !pte_exec(*pte))
31884- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31885+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31886 }
31887
31888+#ifdef CONFIG_PAX_KERNEXEC
31889+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31890+ if (current->signal->curr_ip)
31891+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31892+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31893+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31894+ else
31895+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31896+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31897+ }
31898+#endif
31899+
31900 printk(KERN_ALERT "BUG: unable to handle kernel ");
31901 if (address < PAGE_SIZE)
31902 printk(KERN_CONT "NULL pointer dereference");
31903@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31904 return;
31905 }
31906 #endif
31907+
31908+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31909+ if (pax_is_fetch_fault(regs, error_code, address)) {
31910+
31911+#ifdef CONFIG_PAX_EMUTRAMP
31912+ switch (pax_handle_fetch_fault(regs)) {
31913+ case 2:
31914+ return;
31915+ }
31916+#endif
31917+
31918+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31919+ do_group_exit(SIGKILL);
31920+ }
31921+#endif
31922+
31923 /* Kernel addresses are always protection faults: */
31924 if (address >= TASK_SIZE)
31925 error_code |= PF_PROT;
31926@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31927 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31928 printk(KERN_ERR
31929 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31930- tsk->comm, tsk->pid, address);
31931+ tsk->comm, task_pid_nr(tsk), address);
31932 code = BUS_MCEERR_AR;
31933 }
31934 #endif
31935@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31936 return 1;
31937 }
31938
31939+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31940+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31941+{
31942+ pte_t *pte;
31943+ pmd_t *pmd;
31944+ spinlock_t *ptl;
31945+ unsigned char pte_mask;
31946+
31947+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31948+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31949+ return 0;
31950+
31951+ /* PaX: it's our fault, let's handle it if we can */
31952+
31953+ /* PaX: take a look at read faults before acquiring any locks */
31954+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31955+ /* instruction fetch attempt from a protected page in user mode */
31956+ up_read(&mm->mmap_sem);
31957+
31958+#ifdef CONFIG_PAX_EMUTRAMP
31959+ switch (pax_handle_fetch_fault(regs)) {
31960+ case 2:
31961+ return 1;
31962+ }
31963+#endif
31964+
31965+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31966+ do_group_exit(SIGKILL);
31967+ }
31968+
31969+ pmd = pax_get_pmd(mm, address);
31970+ if (unlikely(!pmd))
31971+ return 0;
31972+
31973+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31974+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31975+ pte_unmap_unlock(pte, ptl);
31976+ return 0;
31977+ }
31978+
31979+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31980+ /* write attempt to a protected page in user mode */
31981+ pte_unmap_unlock(pte, ptl);
31982+ return 0;
31983+ }
31984+
31985+#ifdef CONFIG_SMP
31986+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31987+#else
31988+ if (likely(address > get_limit(regs->cs)))
31989+#endif
31990+ {
31991+ set_pte(pte, pte_mkread(*pte));
31992+ __flush_tlb_one(address);
31993+ pte_unmap_unlock(pte, ptl);
31994+ up_read(&mm->mmap_sem);
31995+ return 1;
31996+ }
31997+
31998+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31999+
32000+ /*
32001+ * PaX: fill DTLB with user rights and retry
32002+ */
32003+ __asm__ __volatile__ (
32004+ "orb %2,(%1)\n"
32005+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32006+/*
32007+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32008+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32009+ * page fault when examined during a TLB load attempt. this is true not only
32010+ * for PTEs holding a non-present entry but also present entries that will
32011+ * raise a page fault (such as those set up by PaX, or the copy-on-write
32012+ * mechanism). in effect it means that we do *not* need to flush the TLBs
32013+ * for our target pages since their PTEs are simply not in the TLBs at all.
32014+
32015+ * the best thing in omitting it is that we gain around 15-20% speed in the
32016+ * fast path of the page fault handler and can get rid of tracing since we
32017+ * can no longer flush unintended entries.
32018+ */
32019+ "invlpg (%0)\n"
32020+#endif
32021+ __copyuser_seg"testb $0,(%0)\n"
32022+ "xorb %3,(%1)\n"
32023+ :
32024+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32025+ : "memory", "cc");
32026+ pte_unmap_unlock(pte, ptl);
32027+ up_read(&mm->mmap_sem);
32028+ return 1;
32029+}
32030+#endif
32031+
32032 /*
32033 * Handle a spurious fault caused by a stale TLB entry.
32034 *
32035@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
32036 static inline int
32037 access_error(unsigned long error_code, struct vm_area_struct *vma)
32038 {
32039+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32040+ return 1;
32041+
32042 if (error_code & PF_WRITE) {
32043 /* write, present and write, not present: */
32044 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32045@@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32046 if (error_code & PF_USER)
32047 return false;
32048
32049- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32050+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32051 return false;
32052
32053 return true;
32054@@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32055 tsk = current;
32056 mm = tsk->mm;
32057
32058+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32059+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32060+ if (!search_exception_tables(regs->ip)) {
32061+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32062+ bad_area_nosemaphore(regs, error_code, address);
32063+ return;
32064+ }
32065+ if (address < pax_user_shadow_base) {
32066+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32067+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32068+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32069+ } else
32070+ address -= pax_user_shadow_base;
32071+ }
32072+#endif
32073+
32074 /*
32075 * Detect and handle instructions that would cause a page fault for
32076 * both a tracked kernel page and a userspace page.
32077@@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32078 * User-mode registers count as a user access even for any
32079 * potential system fault or CPU buglet:
32080 */
32081- if (user_mode_vm(regs)) {
32082+ if (user_mode(regs)) {
32083 local_irq_enable();
32084 error_code |= PF_USER;
32085 flags |= FAULT_FLAG_USER;
32086@@ -1162,6 +1386,11 @@ retry:
32087 might_sleep();
32088 }
32089
32090+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32091+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32092+ return;
32093+#endif
32094+
32095 vma = find_vma(mm, address);
32096 if (unlikely(!vma)) {
32097 bad_area(regs, error_code, address);
32098@@ -1173,18 +1402,24 @@ retry:
32099 bad_area(regs, error_code, address);
32100 return;
32101 }
32102- if (error_code & PF_USER) {
32103- /*
32104- * Accessing the stack below %sp is always a bug.
32105- * The large cushion allows instructions like enter
32106- * and pusha to work. ("enter $65535, $31" pushes
32107- * 32 pointers and then decrements %sp by 65535.)
32108- */
32109- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32110- bad_area(regs, error_code, address);
32111- return;
32112- }
32113+ /*
32114+ * Accessing the stack below %sp is always a bug.
32115+ * The large cushion allows instructions like enter
32116+ * and pusha to work. ("enter $65535, $31" pushes
32117+ * 32 pointers and then decrements %sp by 65535.)
32118+ */
32119+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32120+ bad_area(regs, error_code, address);
32121+ return;
32122 }
32123+
32124+#ifdef CONFIG_PAX_SEGMEXEC
32125+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32126+ bad_area(regs, error_code, address);
32127+ return;
32128+ }
32129+#endif
32130+
32131 if (unlikely(expand_stack(vma, address))) {
32132 bad_area(regs, error_code, address);
32133 return;
32134@@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32135 exception_exit(prev_state);
32136 }
32137 #endif /* CONFIG_TRACING */
32138+
32139+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32140+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32141+{
32142+ struct mm_struct *mm = current->mm;
32143+ unsigned long ip = regs->ip;
32144+
32145+ if (v8086_mode(regs))
32146+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32147+
32148+#ifdef CONFIG_PAX_PAGEEXEC
32149+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32150+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32151+ return true;
32152+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32153+ return true;
32154+ return false;
32155+ }
32156+#endif
32157+
32158+#ifdef CONFIG_PAX_SEGMEXEC
32159+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32160+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32161+ return true;
32162+ return false;
32163+ }
32164+#endif
32165+
32166+ return false;
32167+}
32168+#endif
32169+
32170+#ifdef CONFIG_PAX_EMUTRAMP
32171+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32172+{
32173+ int err;
32174+
32175+ do { /* PaX: libffi trampoline emulation */
32176+ unsigned char mov, jmp;
32177+ unsigned int addr1, addr2;
32178+
32179+#ifdef CONFIG_X86_64
32180+ if ((regs->ip + 9) >> 32)
32181+ break;
32182+#endif
32183+
32184+ err = get_user(mov, (unsigned char __user *)regs->ip);
32185+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32186+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32187+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32188+
32189+ if (err)
32190+ break;
32191+
32192+ if (mov == 0xB8 && jmp == 0xE9) {
32193+ regs->ax = addr1;
32194+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32195+ return 2;
32196+ }
32197+ } while (0);
32198+
32199+ do { /* PaX: gcc trampoline emulation #1 */
32200+ unsigned char mov1, mov2;
32201+ unsigned short jmp;
32202+ unsigned int addr1, addr2;
32203+
32204+#ifdef CONFIG_X86_64
32205+ if ((regs->ip + 11) >> 32)
32206+ break;
32207+#endif
32208+
32209+ err = get_user(mov1, (unsigned char __user *)regs->ip);
32210+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32211+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32212+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32213+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32214+
32215+ if (err)
32216+ break;
32217+
32218+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32219+ regs->cx = addr1;
32220+ regs->ax = addr2;
32221+ regs->ip = addr2;
32222+ return 2;
32223+ }
32224+ } while (0);
32225+
32226+ do { /* PaX: gcc trampoline emulation #2 */
32227+ unsigned char mov, jmp;
32228+ unsigned int addr1, addr2;
32229+
32230+#ifdef CONFIG_X86_64
32231+ if ((regs->ip + 9) >> 32)
32232+ break;
32233+#endif
32234+
32235+ err = get_user(mov, (unsigned char __user *)regs->ip);
32236+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32237+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32238+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32239+
32240+ if (err)
32241+ break;
32242+
32243+ if (mov == 0xB9 && jmp == 0xE9) {
32244+ regs->cx = addr1;
32245+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32246+ return 2;
32247+ }
32248+ } while (0);
32249+
32250+ return 1; /* PaX in action */
32251+}
32252+
32253+#ifdef CONFIG_X86_64
32254+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32255+{
32256+ int err;
32257+
32258+ do { /* PaX: libffi trampoline emulation */
32259+ unsigned short mov1, mov2, jmp1;
32260+ unsigned char stcclc, jmp2;
32261+ unsigned long addr1, addr2;
32262+
32263+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32264+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32265+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32266+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32267+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32268+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32269+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32270+
32271+ if (err)
32272+ break;
32273+
32274+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32275+ regs->r11 = addr1;
32276+ regs->r10 = addr2;
32277+ if (stcclc == 0xF8)
32278+ regs->flags &= ~X86_EFLAGS_CF;
32279+ else
32280+ regs->flags |= X86_EFLAGS_CF;
32281+ regs->ip = addr1;
32282+ return 2;
32283+ }
32284+ } while (0);
32285+
32286+ do { /* PaX: gcc trampoline emulation #1 */
32287+ unsigned short mov1, mov2, jmp1;
32288+ unsigned char jmp2;
32289+ unsigned int addr1;
32290+ unsigned long addr2;
32291+
32292+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32293+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32294+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32295+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32296+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32297+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32298+
32299+ if (err)
32300+ break;
32301+
32302+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32303+ regs->r11 = addr1;
32304+ regs->r10 = addr2;
32305+ regs->ip = addr1;
32306+ return 2;
32307+ }
32308+ } while (0);
32309+
32310+ do { /* PaX: gcc trampoline emulation #2 */
32311+ unsigned short mov1, mov2, jmp1;
32312+ unsigned char jmp2;
32313+ unsigned long addr1, addr2;
32314+
32315+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32316+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32317+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32318+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32319+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32320+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32321+
32322+ if (err)
32323+ break;
32324+
32325+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32326+ regs->r11 = addr1;
32327+ regs->r10 = addr2;
32328+ regs->ip = addr1;
32329+ return 2;
32330+ }
32331+ } while (0);
32332+
32333+ return 1; /* PaX in action */
32334+}
32335+#endif
32336+
32337+/*
32338+ * PaX: decide what to do with offenders (regs->ip = fault address)
32339+ *
32340+ * returns 1 when task should be killed
32341+ * 2 when gcc trampoline was detected
32342+ */
32343+static int pax_handle_fetch_fault(struct pt_regs *regs)
32344+{
32345+ if (v8086_mode(regs))
32346+ return 1;
32347+
32348+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32349+ return 1;
32350+
32351+#ifdef CONFIG_X86_32
32352+ return pax_handle_fetch_fault_32(regs);
32353+#else
32354+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32355+ return pax_handle_fetch_fault_32(regs);
32356+ else
32357+ return pax_handle_fetch_fault_64(regs);
32358+#endif
32359+}
32360+#endif
32361+
32362+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32363+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32364+{
32365+ long i;
32366+
32367+ printk(KERN_ERR "PAX: bytes at PC: ");
32368+ for (i = 0; i < 20; i++) {
32369+ unsigned char c;
32370+ if (get_user(c, (unsigned char __force_user *)pc+i))
32371+ printk(KERN_CONT "?? ");
32372+ else
32373+ printk(KERN_CONT "%02x ", c);
32374+ }
32375+ printk("\n");
32376+
32377+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32378+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32379+ unsigned long c;
32380+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32381+#ifdef CONFIG_X86_32
32382+ printk(KERN_CONT "???????? ");
32383+#else
32384+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32385+ printk(KERN_CONT "???????? ???????? ");
32386+ else
32387+ printk(KERN_CONT "???????????????? ");
32388+#endif
32389+ } else {
32390+#ifdef CONFIG_X86_64
32391+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32392+ printk(KERN_CONT "%08x ", (unsigned int)c);
32393+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32394+ } else
32395+#endif
32396+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32397+ }
32398+ }
32399+ printk("\n");
32400+}
32401+#endif
32402+
32403+/**
32404+ * probe_kernel_write(): safely attempt to write to a location
32405+ * @dst: address to write to
32406+ * @src: pointer to the data that shall be written
32407+ * @size: size of the data chunk
32408+ *
32409+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32410+ * happens, handle that and return -EFAULT.
32411+ */
32412+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32413+{
32414+ long ret;
32415+ mm_segment_t old_fs = get_fs();
32416+
32417+ set_fs(KERNEL_DS);
32418+ pagefault_disable();
32419+ pax_open_kernel();
32420+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32421+ pax_close_kernel();
32422+ pagefault_enable();
32423+ set_fs(old_fs);
32424+
32425+ return ret ? -EFAULT : 0;
32426+}
32427diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32428index 207d9aef..69030980 100644
32429--- a/arch/x86/mm/gup.c
32430+++ b/arch/x86/mm/gup.c
32431@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32432 addr = start;
32433 len = (unsigned long) nr_pages << PAGE_SHIFT;
32434 end = start + len;
32435- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32436+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32437 (void __user *)start, len)))
32438 return 0;
32439
32440@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32441 goto slow_irqon;
32442 #endif
32443
32444+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32445+ (void __user *)start, len)))
32446+ return 0;
32447+
32448 /*
32449 * XXX: batch / limit 'nr', to avoid large irq off latency
32450 * needs some instrumenting to determine the common sizes used by
32451diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32452index 4500142..53a363c 100644
32453--- a/arch/x86/mm/highmem_32.c
32454+++ b/arch/x86/mm/highmem_32.c
32455@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32456 idx = type + KM_TYPE_NR*smp_processor_id();
32457 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32458 BUG_ON(!pte_none(*(kmap_pte-idx)));
32459+
32460+ pax_open_kernel();
32461 set_pte(kmap_pte-idx, mk_pte(page, prot));
32462+ pax_close_kernel();
32463+
32464 arch_flush_lazy_mmu_mode();
32465
32466 return (void *)vaddr;
32467diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32468index 8c9f647..57cb402 100644
32469--- a/arch/x86/mm/hugetlbpage.c
32470+++ b/arch/x86/mm/hugetlbpage.c
32471@@ -90,23 +90,24 @@ int pmd_huge_support(void)
32472 #ifdef CONFIG_HUGETLB_PAGE
32473 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32474 unsigned long addr, unsigned long len,
32475- unsigned long pgoff, unsigned long flags)
32476+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32477 {
32478 struct hstate *h = hstate_file(file);
32479 struct vm_unmapped_area_info info;
32480-
32481+
32482 info.flags = 0;
32483 info.length = len;
32484 info.low_limit = current->mm->mmap_legacy_base;
32485 info.high_limit = TASK_SIZE;
32486 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32487 info.align_offset = 0;
32488+ info.threadstack_offset = offset;
32489 return vm_unmapped_area(&info);
32490 }
32491
32492 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32493 unsigned long addr0, unsigned long len,
32494- unsigned long pgoff, unsigned long flags)
32495+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32496 {
32497 struct hstate *h = hstate_file(file);
32498 struct vm_unmapped_area_info info;
32499@@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32500 info.high_limit = current->mm->mmap_base;
32501 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32502 info.align_offset = 0;
32503+ info.threadstack_offset = offset;
32504 addr = vm_unmapped_area(&info);
32505
32506 /*
32507@@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32508 VM_BUG_ON(addr != -ENOMEM);
32509 info.flags = 0;
32510 info.low_limit = TASK_UNMAPPED_BASE;
32511+
32512+#ifdef CONFIG_PAX_RANDMMAP
32513+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32514+ info.low_limit += current->mm->delta_mmap;
32515+#endif
32516+
32517 info.high_limit = TASK_SIZE;
32518 addr = vm_unmapped_area(&info);
32519 }
32520@@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32521 struct hstate *h = hstate_file(file);
32522 struct mm_struct *mm = current->mm;
32523 struct vm_area_struct *vma;
32524+ unsigned long pax_task_size = TASK_SIZE;
32525+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32526
32527 if (len & ~huge_page_mask(h))
32528 return -EINVAL;
32529- if (len > TASK_SIZE)
32530+
32531+#ifdef CONFIG_PAX_SEGMEXEC
32532+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32533+ pax_task_size = SEGMEXEC_TASK_SIZE;
32534+#endif
32535+
32536+ pax_task_size -= PAGE_SIZE;
32537+
32538+ if (len > pax_task_size)
32539 return -ENOMEM;
32540
32541 if (flags & MAP_FIXED) {
32542@@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32543 return addr;
32544 }
32545
32546+#ifdef CONFIG_PAX_RANDMMAP
32547+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32548+#endif
32549+
32550 if (addr) {
32551 addr = ALIGN(addr, huge_page_size(h));
32552 vma = find_vma(mm, addr);
32553- if (TASK_SIZE - len >= addr &&
32554- (!vma || addr + len <= vma->vm_start))
32555+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32556 return addr;
32557 }
32558 if (mm->get_unmapped_area == arch_get_unmapped_area)
32559 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32560- pgoff, flags);
32561+ pgoff, flags, offset);
32562 else
32563 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32564- pgoff, flags);
32565+ pgoff, flags, offset);
32566 }
32567 #endif /* CONFIG_HUGETLB_PAGE */
32568
32569diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32570index f971306..e83e0f6 100644
32571--- a/arch/x86/mm/init.c
32572+++ b/arch/x86/mm/init.c
32573@@ -4,6 +4,7 @@
32574 #include <linux/swap.h>
32575 #include <linux/memblock.h>
32576 #include <linux/bootmem.h> /* for max_low_pfn */
32577+#include <linux/tboot.h>
32578
32579 #include <asm/cacheflush.h>
32580 #include <asm/e820.h>
32581@@ -17,6 +18,8 @@
32582 #include <asm/proto.h>
32583 #include <asm/dma.h> /* for MAX_DMA_PFN */
32584 #include <asm/microcode.h>
32585+#include <asm/desc.h>
32586+#include <asm/bios_ebda.h>
32587
32588 #include "mm_internal.h"
32589
32590@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32591 early_ioremap_page_table_range_init();
32592 #endif
32593
32594+#ifdef CONFIG_PAX_PER_CPU_PGD
32595+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32596+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32597+ KERNEL_PGD_PTRS);
32598+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32599+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32600+ KERNEL_PGD_PTRS);
32601+ load_cr3(get_cpu_pgd(0, kernel));
32602+#else
32603 load_cr3(swapper_pg_dir);
32604+#endif
32605+
32606 __flush_tlb_all();
32607
32608 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32609@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32610 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32611 * mmio resources as well as potential bios/acpi data regions.
32612 */
32613+
32614+#ifdef CONFIG_GRKERNSEC_KMEM
32615+static unsigned int ebda_start __read_only;
32616+static unsigned int ebda_end __read_only;
32617+#endif
32618+
32619 int devmem_is_allowed(unsigned long pagenr)
32620 {
32621- if (pagenr < 256)
32622+#ifdef CONFIG_GRKERNSEC_KMEM
32623+ /* allow BDA */
32624+ if (!pagenr)
32625 return 1;
32626+ /* allow EBDA */
32627+ if (pagenr >= ebda_start && pagenr < ebda_end)
32628+ return 1;
32629+ /* if tboot is in use, allow access to its hardcoded serial log range */
32630+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32631+ return 1;
32632+#else
32633+ if (!pagenr)
32634+ return 1;
32635+#ifdef CONFIG_VM86
32636+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32637+ return 1;
32638+#endif
32639+#endif
32640+
32641+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32642+ return 1;
32643+#ifdef CONFIG_GRKERNSEC_KMEM
32644+ /* throw out everything else below 1MB */
32645+ if (pagenr <= 256)
32646+ return 0;
32647+#endif
32648 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32649 return 0;
32650 if (!page_is_ram(pagenr))
32651@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32652 #endif
32653 }
32654
32655+#ifdef CONFIG_GRKERNSEC_KMEM
32656+static inline void gr_init_ebda(void)
32657+{
32658+ unsigned int ebda_addr;
32659+ unsigned int ebda_size = 0;
32660+
32661+ ebda_addr = get_bios_ebda();
32662+ if (ebda_addr) {
32663+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32664+ ebda_size <<= 10;
32665+ }
32666+ if (ebda_addr && ebda_size) {
32667+ ebda_start = ebda_addr >> PAGE_SHIFT;
32668+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32669+ } else {
32670+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32671+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32672+ }
32673+}
32674+#else
32675+static inline void gr_init_ebda(void) { }
32676+#endif
32677+
32678 void free_initmem(void)
32679 {
32680+#ifdef CONFIG_PAX_KERNEXEC
32681+#ifdef CONFIG_X86_32
32682+ /* PaX: limit KERNEL_CS to actual size */
32683+ unsigned long addr, limit;
32684+ struct desc_struct d;
32685+ int cpu;
32686+#else
32687+ pgd_t *pgd;
32688+ pud_t *pud;
32689+ pmd_t *pmd;
32690+ unsigned long addr, end;
32691+#endif
32692+#endif
32693+
32694+ gr_init_ebda();
32695+
32696+#ifdef CONFIG_PAX_KERNEXEC
32697+#ifdef CONFIG_X86_32
32698+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32699+ limit = (limit - 1UL) >> PAGE_SHIFT;
32700+
32701+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32702+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32703+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32704+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32705+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32706+ }
32707+
32708+ /* PaX: make KERNEL_CS read-only */
32709+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32710+ if (!paravirt_enabled())
32711+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32712+/*
32713+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32714+ pgd = pgd_offset_k(addr);
32715+ pud = pud_offset(pgd, addr);
32716+ pmd = pmd_offset(pud, addr);
32717+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32718+ }
32719+*/
32720+#ifdef CONFIG_X86_PAE
32721+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32722+/*
32723+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32724+ pgd = pgd_offset_k(addr);
32725+ pud = pud_offset(pgd, addr);
32726+ pmd = pmd_offset(pud, addr);
32727+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32728+ }
32729+*/
32730+#endif
32731+
32732+#ifdef CONFIG_MODULES
32733+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32734+#endif
32735+
32736+#else
32737+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32738+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32739+ pgd = pgd_offset_k(addr);
32740+ pud = pud_offset(pgd, addr);
32741+ pmd = pmd_offset(pud, addr);
32742+ if (!pmd_present(*pmd))
32743+ continue;
32744+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32745+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32746+ else
32747+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32748+ }
32749+
32750+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32751+ end = addr + KERNEL_IMAGE_SIZE;
32752+ for (; addr < end; addr += PMD_SIZE) {
32753+ pgd = pgd_offset_k(addr);
32754+ pud = pud_offset(pgd, addr);
32755+ pmd = pmd_offset(pud, addr);
32756+ if (!pmd_present(*pmd))
32757+ continue;
32758+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32759+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32760+ }
32761+#endif
32762+
32763+ flush_tlb_all();
32764+#endif
32765+
32766 free_init_pages("unused kernel",
32767 (unsigned long)(&__init_begin),
32768 (unsigned long)(&__init_end));
32769diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32770index e395048..cd38278 100644
32771--- a/arch/x86/mm/init_32.c
32772+++ b/arch/x86/mm/init_32.c
32773@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32774 bool __read_mostly __vmalloc_start_set = false;
32775
32776 /*
32777- * Creates a middle page table and puts a pointer to it in the
32778- * given global directory entry. This only returns the gd entry
32779- * in non-PAE compilation mode, since the middle layer is folded.
32780- */
32781-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32782-{
32783- pud_t *pud;
32784- pmd_t *pmd_table;
32785-
32786-#ifdef CONFIG_X86_PAE
32787- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32788- pmd_table = (pmd_t *)alloc_low_page();
32789- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32790- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32791- pud = pud_offset(pgd, 0);
32792- BUG_ON(pmd_table != pmd_offset(pud, 0));
32793-
32794- return pmd_table;
32795- }
32796-#endif
32797- pud = pud_offset(pgd, 0);
32798- pmd_table = pmd_offset(pud, 0);
32799-
32800- return pmd_table;
32801-}
32802-
32803-/*
32804 * Create a page table and place a pointer to it in a middle page
32805 * directory entry:
32806 */
32807@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32808 pte_t *page_table = (pte_t *)alloc_low_page();
32809
32810 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32811+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32812+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32813+#else
32814 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32815+#endif
32816 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32817 }
32818
32819 return pte_offset_kernel(pmd, 0);
32820 }
32821
32822+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32823+{
32824+ pud_t *pud;
32825+ pmd_t *pmd_table;
32826+
32827+ pud = pud_offset(pgd, 0);
32828+ pmd_table = pmd_offset(pud, 0);
32829+
32830+ return pmd_table;
32831+}
32832+
32833 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32834 {
32835 int pgd_idx = pgd_index(vaddr);
32836@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32837 int pgd_idx, pmd_idx;
32838 unsigned long vaddr;
32839 pgd_t *pgd;
32840+ pud_t *pud;
32841 pmd_t *pmd;
32842 pte_t *pte = NULL;
32843 unsigned long count = page_table_range_init_count(start, end);
32844@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32845 pgd = pgd_base + pgd_idx;
32846
32847 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32848- pmd = one_md_table_init(pgd);
32849- pmd = pmd + pmd_index(vaddr);
32850+ pud = pud_offset(pgd, vaddr);
32851+ pmd = pmd_offset(pud, vaddr);
32852+
32853+#ifdef CONFIG_X86_PAE
32854+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32855+#endif
32856+
32857 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32858 pmd++, pmd_idx++) {
32859 pte = page_table_kmap_check(one_page_table_init(pmd),
32860@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32861 }
32862 }
32863
32864-static inline int is_kernel_text(unsigned long addr)
32865+static inline int is_kernel_text(unsigned long start, unsigned long end)
32866 {
32867- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32868- return 1;
32869- return 0;
32870+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32871+ end <= ktla_ktva((unsigned long)_stext)) &&
32872+ (start >= ktla_ktva((unsigned long)_einittext) ||
32873+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32874+
32875+#ifdef CONFIG_ACPI_SLEEP
32876+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32877+#endif
32878+
32879+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32880+ return 0;
32881+ return 1;
32882 }
32883
32884 /*
32885@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32886 unsigned long last_map_addr = end;
32887 unsigned long start_pfn, end_pfn;
32888 pgd_t *pgd_base = swapper_pg_dir;
32889- int pgd_idx, pmd_idx, pte_ofs;
32890+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32891 unsigned long pfn;
32892 pgd_t *pgd;
32893+ pud_t *pud;
32894 pmd_t *pmd;
32895 pte_t *pte;
32896 unsigned pages_2m, pages_4k;
32897@@ -291,8 +295,13 @@ repeat:
32898 pfn = start_pfn;
32899 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32900 pgd = pgd_base + pgd_idx;
32901- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32902- pmd = one_md_table_init(pgd);
32903+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32904+ pud = pud_offset(pgd, 0);
32905+ pmd = pmd_offset(pud, 0);
32906+
32907+#ifdef CONFIG_X86_PAE
32908+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32909+#endif
32910
32911 if (pfn >= end_pfn)
32912 continue;
32913@@ -304,14 +313,13 @@ repeat:
32914 #endif
32915 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32916 pmd++, pmd_idx++) {
32917- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32918+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32919
32920 /*
32921 * Map with big pages if possible, otherwise
32922 * create normal page tables:
32923 */
32924 if (use_pse) {
32925- unsigned int addr2;
32926 pgprot_t prot = PAGE_KERNEL_LARGE;
32927 /*
32928 * first pass will use the same initial
32929@@ -322,11 +330,7 @@ repeat:
32930 _PAGE_PSE);
32931
32932 pfn &= PMD_MASK >> PAGE_SHIFT;
32933- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32934- PAGE_OFFSET + PAGE_SIZE-1;
32935-
32936- if (is_kernel_text(addr) ||
32937- is_kernel_text(addr2))
32938+ if (is_kernel_text(address, address + PMD_SIZE))
32939 prot = PAGE_KERNEL_LARGE_EXEC;
32940
32941 pages_2m++;
32942@@ -343,7 +347,7 @@ repeat:
32943 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32944 pte += pte_ofs;
32945 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32946- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32947+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32948 pgprot_t prot = PAGE_KERNEL;
32949 /*
32950 * first pass will use the same initial
32951@@ -351,7 +355,7 @@ repeat:
32952 */
32953 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32954
32955- if (is_kernel_text(addr))
32956+ if (is_kernel_text(address, address + PAGE_SIZE))
32957 prot = PAGE_KERNEL_EXEC;
32958
32959 pages_4k++;
32960@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32961
32962 pud = pud_offset(pgd, va);
32963 pmd = pmd_offset(pud, va);
32964- if (!pmd_present(*pmd))
32965+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32966 break;
32967
32968 /* should not be large page here */
32969@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32970
32971 static void __init pagetable_init(void)
32972 {
32973- pgd_t *pgd_base = swapper_pg_dir;
32974-
32975- permanent_kmaps_init(pgd_base);
32976+ permanent_kmaps_init(swapper_pg_dir);
32977 }
32978
32979-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32980+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32981 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32982
32983 /* user-defined highmem size */
32984@@ -787,10 +789,10 @@ void __init mem_init(void)
32985 ((unsigned long)&__init_end -
32986 (unsigned long)&__init_begin) >> 10,
32987
32988- (unsigned long)&_etext, (unsigned long)&_edata,
32989- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32990+ (unsigned long)&_sdata, (unsigned long)&_edata,
32991+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32992
32993- (unsigned long)&_text, (unsigned long)&_etext,
32994+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32995 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32996
32997 /*
32998@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32999 if (!kernel_set_to_readonly)
33000 return;
33001
33002+ start = ktla_ktva(start);
33003 pr_debug("Set kernel text: %lx - %lx for read write\n",
33004 start, start+size);
33005
33006@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
33007 if (!kernel_set_to_readonly)
33008 return;
33009
33010+ start = ktla_ktva(start);
33011 pr_debug("Set kernel text: %lx - %lx for read only\n",
33012 start, start+size);
33013
33014@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
33015 unsigned long start = PFN_ALIGN(_text);
33016 unsigned long size = PFN_ALIGN(_etext) - start;
33017
33018+ start = ktla_ktva(start);
33019 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33020 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33021 size >> 10);
33022diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33023index f35c66c..84b95ef 100644
33024--- a/arch/x86/mm/init_64.c
33025+++ b/arch/x86/mm/init_64.c
33026@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33027 * around without checking the pgd every time.
33028 */
33029
33030-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
33031+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
33032 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33033
33034 int force_personality32;
33035@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33036
33037 for (address = start; address <= end; address += PGDIR_SIZE) {
33038 const pgd_t *pgd_ref = pgd_offset_k(address);
33039+
33040+#ifdef CONFIG_PAX_PER_CPU_PGD
33041+ unsigned long cpu;
33042+#else
33043 struct page *page;
33044+#endif
33045
33046 if (pgd_none(*pgd_ref))
33047 continue;
33048
33049 spin_lock(&pgd_lock);
33050+
33051+#ifdef CONFIG_PAX_PER_CPU_PGD
33052+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33053+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33054+
33055+ if (pgd_none(*pgd))
33056+ set_pgd(pgd, *pgd_ref);
33057+ else
33058+ BUG_ON(pgd_page_vaddr(*pgd)
33059+ != pgd_page_vaddr(*pgd_ref));
33060+ pgd = pgd_offset_cpu(cpu, kernel, address);
33061+#else
33062 list_for_each_entry(page, &pgd_list, lru) {
33063 pgd_t *pgd;
33064 spinlock_t *pgt_lock;
33065@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33066 /* the pgt_lock only for Xen */
33067 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33068 spin_lock(pgt_lock);
33069+#endif
33070
33071 if (pgd_none(*pgd))
33072 set_pgd(pgd, *pgd_ref);
33073@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33074 BUG_ON(pgd_page_vaddr(*pgd)
33075 != pgd_page_vaddr(*pgd_ref));
33076
33077+#ifndef CONFIG_PAX_PER_CPU_PGD
33078 spin_unlock(pgt_lock);
33079+#endif
33080+
33081 }
33082 spin_unlock(&pgd_lock);
33083 }
33084@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33085 {
33086 if (pgd_none(*pgd)) {
33087 pud_t *pud = (pud_t *)spp_getpage();
33088- pgd_populate(&init_mm, pgd, pud);
33089+ pgd_populate_kernel(&init_mm, pgd, pud);
33090 if (pud != pud_offset(pgd, 0))
33091 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33092 pud, pud_offset(pgd, 0));
33093@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33094 {
33095 if (pud_none(*pud)) {
33096 pmd_t *pmd = (pmd_t *) spp_getpage();
33097- pud_populate(&init_mm, pud, pmd);
33098+ pud_populate_kernel(&init_mm, pud, pmd);
33099 if (pmd != pmd_offset(pud, 0))
33100 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33101 pmd, pmd_offset(pud, 0));
33102@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33103 pmd = fill_pmd(pud, vaddr);
33104 pte = fill_pte(pmd, vaddr);
33105
33106+ pax_open_kernel();
33107 set_pte(pte, new_pte);
33108+ pax_close_kernel();
33109
33110 /*
33111 * It's enough to flush this one mapping.
33112@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33113 pgd = pgd_offset_k((unsigned long)__va(phys));
33114 if (pgd_none(*pgd)) {
33115 pud = (pud_t *) spp_getpage();
33116- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33117- _PAGE_USER));
33118+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33119 }
33120 pud = pud_offset(pgd, (unsigned long)__va(phys));
33121 if (pud_none(*pud)) {
33122 pmd = (pmd_t *) spp_getpage();
33123- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33124- _PAGE_USER));
33125+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33126 }
33127 pmd = pmd_offset(pud, phys);
33128 BUG_ON(!pmd_none(*pmd));
33129@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33130 prot);
33131
33132 spin_lock(&init_mm.page_table_lock);
33133- pud_populate(&init_mm, pud, pmd);
33134+ pud_populate_kernel(&init_mm, pud, pmd);
33135 spin_unlock(&init_mm.page_table_lock);
33136 }
33137 __flush_tlb_all();
33138@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33139 page_size_mask);
33140
33141 spin_lock(&init_mm.page_table_lock);
33142- pgd_populate(&init_mm, pgd, pud);
33143+ pgd_populate_kernel(&init_mm, pgd, pud);
33144 spin_unlock(&init_mm.page_table_lock);
33145 pgd_changed = true;
33146 }
33147@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
33148 static struct vm_area_struct gate_vma = {
33149 .vm_start = VSYSCALL_START,
33150 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
33151- .vm_page_prot = PAGE_READONLY_EXEC,
33152- .vm_flags = VM_READ | VM_EXEC
33153+ .vm_page_prot = PAGE_READONLY,
33154+ .vm_flags = VM_READ
33155 };
33156
33157 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33158@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
33159
33160 const char *arch_vma_name(struct vm_area_struct *vma)
33161 {
33162- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33163+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33164 return "[vdso]";
33165 if (vma == &gate_vma)
33166 return "[vsyscall]";
33167diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33168index 7b179b4..6bd17777 100644
33169--- a/arch/x86/mm/iomap_32.c
33170+++ b/arch/x86/mm/iomap_32.c
33171@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33172 type = kmap_atomic_idx_push();
33173 idx = type + KM_TYPE_NR * smp_processor_id();
33174 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33175+
33176+ pax_open_kernel();
33177 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33178+ pax_close_kernel();
33179+
33180 arch_flush_lazy_mmu_mode();
33181
33182 return (void *)vaddr;
33183diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33184index 799580c..72f9fe0 100644
33185--- a/arch/x86/mm/ioremap.c
33186+++ b/arch/x86/mm/ioremap.c
33187@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
33188 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
33189 int is_ram = page_is_ram(pfn);
33190
33191- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
33192+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
33193 return NULL;
33194 WARN_ON_ONCE(is_ram);
33195 }
33196@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
33197 *
33198 * Caller must ensure there is only one unmapping for the same pointer.
33199 */
33200-void iounmap(volatile void __iomem *addr)
33201+void iounmap(const volatile void __iomem *addr)
33202 {
33203 struct vm_struct *p, *o;
33204
33205@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33206
33207 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33208 if (page_is_ram(start >> PAGE_SHIFT))
33209+#ifdef CONFIG_HIGHMEM
33210+ if ((start >> PAGE_SHIFT) < max_low_pfn)
33211+#endif
33212 return __va(phys);
33213
33214 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33215@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33216 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33217 {
33218 if (page_is_ram(phys >> PAGE_SHIFT))
33219+#ifdef CONFIG_HIGHMEM
33220+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
33221+#endif
33222 return;
33223
33224 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33225@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
33226 early_param("early_ioremap_debug", early_ioremap_debug_setup);
33227
33228 static __initdata int after_paging_init;
33229-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33230+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33231
33232 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33233 {
33234@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33235 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
33236
33237 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33238- memset(bm_pte, 0, sizeof(bm_pte));
33239- pmd_populate_kernel(&init_mm, pmd, bm_pte);
33240+ pmd_populate_user(&init_mm, pmd, bm_pte);
33241
33242 /*
33243 * The boot-ioremap range spans multiple pmds, for which
33244diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33245index d87dd6d..bf3fa66 100644
33246--- a/arch/x86/mm/kmemcheck/kmemcheck.c
33247+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33248@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33249 * memory (e.g. tracked pages)? For now, we need this to avoid
33250 * invoking kmemcheck for PnP BIOS calls.
33251 */
33252- if (regs->flags & X86_VM_MASK)
33253+ if (v8086_mode(regs))
33254 return false;
33255- if (regs->cs != __KERNEL_CS)
33256+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33257 return false;
33258
33259 pte = kmemcheck_pte_lookup(address);
33260diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33261index 25e7e13..1964579 100644
33262--- a/arch/x86/mm/mmap.c
33263+++ b/arch/x86/mm/mmap.c
33264@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33265 * Leave an at least ~128 MB hole with possible stack randomization.
33266 */
33267 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33268-#define MAX_GAP (TASK_SIZE/6*5)
33269+#define MAX_GAP (pax_task_size/6*5)
33270
33271 static int mmap_is_legacy(void)
33272 {
33273@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33274 return rnd << PAGE_SHIFT;
33275 }
33276
33277-static unsigned long mmap_base(void)
33278+static unsigned long mmap_base(struct mm_struct *mm)
33279 {
33280 unsigned long gap = rlimit(RLIMIT_STACK);
33281+ unsigned long pax_task_size = TASK_SIZE;
33282+
33283+#ifdef CONFIG_PAX_SEGMEXEC
33284+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33285+ pax_task_size = SEGMEXEC_TASK_SIZE;
33286+#endif
33287
33288 if (gap < MIN_GAP)
33289 gap = MIN_GAP;
33290 else if (gap > MAX_GAP)
33291 gap = MAX_GAP;
33292
33293- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33294+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33295 }
33296
33297 /*
33298 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33299 * does, but not when emulating X86_32
33300 */
33301-static unsigned long mmap_legacy_base(void)
33302+static unsigned long mmap_legacy_base(struct mm_struct *mm)
33303 {
33304- if (mmap_is_ia32())
33305+ if (mmap_is_ia32()) {
33306+
33307+#ifdef CONFIG_PAX_SEGMEXEC
33308+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33309+ return SEGMEXEC_TASK_UNMAPPED_BASE;
33310+ else
33311+#endif
33312+
33313 return TASK_UNMAPPED_BASE;
33314- else
33315+ } else
33316 return TASK_UNMAPPED_BASE + mmap_rnd();
33317 }
33318
33319@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33320 */
33321 void arch_pick_mmap_layout(struct mm_struct *mm)
33322 {
33323- mm->mmap_legacy_base = mmap_legacy_base();
33324- mm->mmap_base = mmap_base();
33325+ mm->mmap_legacy_base = mmap_legacy_base(mm);
33326+ mm->mmap_base = mmap_base(mm);
33327+
33328+#ifdef CONFIG_PAX_RANDMMAP
33329+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
33330+ mm->mmap_legacy_base += mm->delta_mmap;
33331+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33332+ }
33333+#endif
33334
33335 if (mmap_is_legacy()) {
33336 mm->mmap_base = mm->mmap_legacy_base;
33337diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33338index 0057a7a..95c7edd 100644
33339--- a/arch/x86/mm/mmio-mod.c
33340+++ b/arch/x86/mm/mmio-mod.c
33341@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33342 break;
33343 default:
33344 {
33345- unsigned char *ip = (unsigned char *)instptr;
33346+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33347 my_trace->opcode = MMIO_UNKNOWN_OP;
33348 my_trace->width = 0;
33349 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33350@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33351 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33352 void __iomem *addr)
33353 {
33354- static atomic_t next_id;
33355+ static atomic_unchecked_t next_id;
33356 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33357 /* These are page-unaligned. */
33358 struct mmiotrace_map map = {
33359@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33360 .private = trace
33361 },
33362 .phys = offset,
33363- .id = atomic_inc_return(&next_id)
33364+ .id = atomic_inc_return_unchecked(&next_id)
33365 };
33366 map.map_id = trace->id;
33367
33368@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33369 ioremap_trace_core(offset, size, addr);
33370 }
33371
33372-static void iounmap_trace_core(volatile void __iomem *addr)
33373+static void iounmap_trace_core(const volatile void __iomem *addr)
33374 {
33375 struct mmiotrace_map map = {
33376 .phys = 0,
33377@@ -328,7 +328,7 @@ not_enabled:
33378 }
33379 }
33380
33381-void mmiotrace_iounmap(volatile void __iomem *addr)
33382+void mmiotrace_iounmap(const volatile void __iomem *addr)
33383 {
33384 might_sleep();
33385 if (is_enabled()) /* recheck and proper locking in *_core() */
33386diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33387index 27aa0455..0eb1406 100644
33388--- a/arch/x86/mm/numa.c
33389+++ b/arch/x86/mm/numa.c
33390@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33391 return true;
33392 }
33393
33394-static int __init numa_register_memblks(struct numa_meminfo *mi)
33395+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33396 {
33397 unsigned long uninitialized_var(pfn_align);
33398 int i, nid;
33399diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33400index 461bc82..4e091a3 100644
33401--- a/arch/x86/mm/pageattr-test.c
33402+++ b/arch/x86/mm/pageattr-test.c
33403@@ -35,7 +35,7 @@ enum {
33404
33405 static int pte_testbit(pte_t pte)
33406 {
33407- return pte_flags(pte) & _PAGE_UNUSED1;
33408+ return pte_flags(pte) & _PAGE_CPA_TEST;
33409 }
33410
33411 struct split_state {
33412diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33413index a348868..3c64310 100644
33414--- a/arch/x86/mm/pageattr.c
33415+++ b/arch/x86/mm/pageattr.c
33416@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33417 */
33418 #ifdef CONFIG_PCI_BIOS
33419 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33420- pgprot_val(forbidden) |= _PAGE_NX;
33421+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33422 #endif
33423
33424 /*
33425@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33426 * Does not cover __inittext since that is gone later on. On
33427 * 64bit we do not enforce !NX on the low mapping
33428 */
33429- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33430- pgprot_val(forbidden) |= _PAGE_NX;
33431+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33432+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33433
33434+#ifdef CONFIG_DEBUG_RODATA
33435 /*
33436 * The .rodata section needs to be read-only. Using the pfn
33437 * catches all aliases.
33438@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33439 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33440 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33441 pgprot_val(forbidden) |= _PAGE_RW;
33442+#endif
33443
33444 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33445 /*
33446@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33447 }
33448 #endif
33449
33450+#ifdef CONFIG_PAX_KERNEXEC
33451+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33452+ pgprot_val(forbidden) |= _PAGE_RW;
33453+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33454+ }
33455+#endif
33456+
33457 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33458
33459 return prot;
33460@@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33461 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33462 {
33463 /* change init_mm */
33464+ pax_open_kernel();
33465 set_pte_atomic(kpte, pte);
33466+
33467 #ifdef CONFIG_X86_32
33468 if (!SHARED_KERNEL_PMD) {
33469+
33470+#ifdef CONFIG_PAX_PER_CPU_PGD
33471+ unsigned long cpu;
33472+#else
33473 struct page *page;
33474+#endif
33475
33476+#ifdef CONFIG_PAX_PER_CPU_PGD
33477+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33478+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33479+#else
33480 list_for_each_entry(page, &pgd_list, lru) {
33481- pgd_t *pgd;
33482+ pgd_t *pgd = (pgd_t *)page_address(page);
33483+#endif
33484+
33485 pud_t *pud;
33486 pmd_t *pmd;
33487
33488- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33489+ pgd += pgd_index(address);
33490 pud = pud_offset(pgd, address);
33491 pmd = pmd_offset(pud, address);
33492 set_pte_atomic((pte_t *)pmd, pte);
33493 }
33494 }
33495 #endif
33496+ pax_close_kernel();
33497 }
33498
33499 static int
33500diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33501index 6574388..87e9bef 100644
33502--- a/arch/x86/mm/pat.c
33503+++ b/arch/x86/mm/pat.c
33504@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33505
33506 if (!entry) {
33507 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33508- current->comm, current->pid, start, end - 1);
33509+ current->comm, task_pid_nr(current), start, end - 1);
33510 return -EINVAL;
33511 }
33512
33513@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33514
33515 while (cursor < to) {
33516 if (!devmem_is_allowed(pfn)) {
33517- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33518- current->comm, from, to - 1);
33519+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33520+ current->comm, from, to - 1, cursor);
33521 return 0;
33522 }
33523 cursor += PAGE_SIZE;
33524@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33525 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33526 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33527 "for [mem %#010Lx-%#010Lx]\n",
33528- current->comm, current->pid,
33529+ current->comm, task_pid_nr(current),
33530 cattr_name(flags),
33531 base, (unsigned long long)(base + size-1));
33532 return -EINVAL;
33533@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33534 flags = lookup_memtype(paddr);
33535 if (want_flags != flags) {
33536 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33537- current->comm, current->pid,
33538+ current->comm, task_pid_nr(current),
33539 cattr_name(want_flags),
33540 (unsigned long long)paddr,
33541 (unsigned long long)(paddr + size - 1),
33542@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33543 free_memtype(paddr, paddr + size);
33544 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33545 " for [mem %#010Lx-%#010Lx], got %s\n",
33546- current->comm, current->pid,
33547+ current->comm, task_pid_nr(current),
33548 cattr_name(want_flags),
33549 (unsigned long long)paddr,
33550 (unsigned long long)(paddr + size - 1),
33551diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33552index 415f6c4..d319983 100644
33553--- a/arch/x86/mm/pat_rbtree.c
33554+++ b/arch/x86/mm/pat_rbtree.c
33555@@ -160,7 +160,7 @@ success:
33556
33557 failure:
33558 printk(KERN_INFO "%s:%d conflicting memory types "
33559- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33560+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33561 end, cattr_name(found_type), cattr_name(match->type));
33562 return -EBUSY;
33563 }
33564diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33565index 9f0614d..92ae64a 100644
33566--- a/arch/x86/mm/pf_in.c
33567+++ b/arch/x86/mm/pf_in.c
33568@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33569 int i;
33570 enum reason_type rv = OTHERS;
33571
33572- p = (unsigned char *)ins_addr;
33573+ p = (unsigned char *)ktla_ktva(ins_addr);
33574 p += skip_prefix(p, &prf);
33575 p += get_opcode(p, &opcode);
33576
33577@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33578 struct prefix_bits prf;
33579 int i;
33580
33581- p = (unsigned char *)ins_addr;
33582+ p = (unsigned char *)ktla_ktva(ins_addr);
33583 p += skip_prefix(p, &prf);
33584 p += get_opcode(p, &opcode);
33585
33586@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33587 struct prefix_bits prf;
33588 int i;
33589
33590- p = (unsigned char *)ins_addr;
33591+ p = (unsigned char *)ktla_ktva(ins_addr);
33592 p += skip_prefix(p, &prf);
33593 p += get_opcode(p, &opcode);
33594
33595@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33596 struct prefix_bits prf;
33597 int i;
33598
33599- p = (unsigned char *)ins_addr;
33600+ p = (unsigned char *)ktla_ktva(ins_addr);
33601 p += skip_prefix(p, &prf);
33602 p += get_opcode(p, &opcode);
33603 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33604@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33605 struct prefix_bits prf;
33606 int i;
33607
33608- p = (unsigned char *)ins_addr;
33609+ p = (unsigned char *)ktla_ktva(ins_addr);
33610 p += skip_prefix(p, &prf);
33611 p += get_opcode(p, &opcode);
33612 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33613diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33614index c96314a..433b127 100644
33615--- a/arch/x86/mm/pgtable.c
33616+++ b/arch/x86/mm/pgtable.c
33617@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33618 list_del(&page->lru);
33619 }
33620
33621-#define UNSHARED_PTRS_PER_PGD \
33622- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33623+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33624+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33625
33626+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33627+{
33628+ unsigned int count = USER_PGD_PTRS;
33629
33630+ if (!pax_user_shadow_base)
33631+ return;
33632+
33633+ while (count--)
33634+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33635+}
33636+#endif
33637+
33638+#ifdef CONFIG_PAX_PER_CPU_PGD
33639+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33640+{
33641+ unsigned int count = USER_PGD_PTRS;
33642+
33643+ while (count--) {
33644+ pgd_t pgd;
33645+
33646+#ifdef CONFIG_X86_64
33647+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33648+#else
33649+ pgd = *src++;
33650+#endif
33651+
33652+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33653+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33654+#endif
33655+
33656+ *dst++ = pgd;
33657+ }
33658+
33659+}
33660+#endif
33661+
33662+#ifdef CONFIG_X86_64
33663+#define pxd_t pud_t
33664+#define pyd_t pgd_t
33665+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33666+#define pgtable_pxd_page_ctor(page) true
33667+#define pgtable_pxd_page_dtor(page)
33668+#define pxd_free(mm, pud) pud_free((mm), (pud))
33669+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33670+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33671+#define PYD_SIZE PGDIR_SIZE
33672+#else
33673+#define pxd_t pmd_t
33674+#define pyd_t pud_t
33675+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33676+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33677+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33678+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33679+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33680+#define pyd_offset(mm, address) pud_offset((mm), (address))
33681+#define PYD_SIZE PUD_SIZE
33682+#endif
33683+
33684+#ifdef CONFIG_PAX_PER_CPU_PGD
33685+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33686+static inline void pgd_dtor(pgd_t *pgd) {}
33687+#else
33688 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33689 {
33690 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33691@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33692 pgd_list_del(pgd);
33693 spin_unlock(&pgd_lock);
33694 }
33695+#endif
33696
33697 /*
33698 * List of all pgd's needed for non-PAE so it can invalidate entries
33699@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33700 * -- nyc
33701 */
33702
33703-#ifdef CONFIG_X86_PAE
33704+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33705 /*
33706 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33707 * updating the top-level pagetable entries to guarantee the
33708@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33709 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33710 * and initialize the kernel pmds here.
33711 */
33712-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33713+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33714
33715 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33716 {
33717@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33718 */
33719 flush_tlb_mm(mm);
33720 }
33721+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33722+#define PREALLOCATED_PXDS USER_PGD_PTRS
33723 #else /* !CONFIG_X86_PAE */
33724
33725 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33726-#define PREALLOCATED_PMDS 0
33727+#define PREALLOCATED_PXDS 0
33728
33729 #endif /* CONFIG_X86_PAE */
33730
33731-static void free_pmds(pmd_t *pmds[])
33732+static void free_pxds(pxd_t *pxds[])
33733 {
33734 int i;
33735
33736- for(i = 0; i < PREALLOCATED_PMDS; i++)
33737- if (pmds[i]) {
33738- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33739- free_page((unsigned long)pmds[i]);
33740+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33741+ if (pxds[i]) {
33742+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33743+ free_page((unsigned long)pxds[i]);
33744 }
33745 }
33746
33747-static int preallocate_pmds(pmd_t *pmds[])
33748+static int preallocate_pxds(pxd_t *pxds[])
33749 {
33750 int i;
33751 bool failed = false;
33752
33753- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33754- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33755- if (!pmd)
33756+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33757+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33758+ if (!pxd)
33759 failed = true;
33760- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33761- free_page((unsigned long)pmd);
33762- pmd = NULL;
33763+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33764+ free_page((unsigned long)pxd);
33765+ pxd = NULL;
33766 failed = true;
33767 }
33768- pmds[i] = pmd;
33769+ pxds[i] = pxd;
33770 }
33771
33772 if (failed) {
33773- free_pmds(pmds);
33774+ free_pxds(pxds);
33775 return -ENOMEM;
33776 }
33777
33778@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33779 * preallocate which never got a corresponding vma will need to be
33780 * freed manually.
33781 */
33782-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33783+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33784 {
33785 int i;
33786
33787- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33788+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33789 pgd_t pgd = pgdp[i];
33790
33791 if (pgd_val(pgd) != 0) {
33792- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33793+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33794
33795- pgdp[i] = native_make_pgd(0);
33796+ set_pgd(pgdp + i, native_make_pgd(0));
33797
33798- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33799- pmd_free(mm, pmd);
33800+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33801+ pxd_free(mm, pxd);
33802 }
33803 }
33804 }
33805
33806-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33807+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33808 {
33809- pud_t *pud;
33810+ pyd_t *pyd;
33811 int i;
33812
33813- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33814+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33815 return;
33816
33817- pud = pud_offset(pgd, 0);
33818-
33819- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33820- pmd_t *pmd = pmds[i];
33821+#ifdef CONFIG_X86_64
33822+ pyd = pyd_offset(mm, 0L);
33823+#else
33824+ pyd = pyd_offset(pgd, 0L);
33825+#endif
33826
33827+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33828+ pxd_t *pxd = pxds[i];
33829 if (i >= KERNEL_PGD_BOUNDARY)
33830- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33831- sizeof(pmd_t) * PTRS_PER_PMD);
33832+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33833+ sizeof(pxd_t) * PTRS_PER_PMD);
33834
33835- pud_populate(mm, pud, pmd);
33836+ pyd_populate(mm, pyd, pxd);
33837 }
33838 }
33839
33840 pgd_t *pgd_alloc(struct mm_struct *mm)
33841 {
33842 pgd_t *pgd;
33843- pmd_t *pmds[PREALLOCATED_PMDS];
33844+ pxd_t *pxds[PREALLOCATED_PXDS];
33845
33846 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33847
33848@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33849
33850 mm->pgd = pgd;
33851
33852- if (preallocate_pmds(pmds) != 0)
33853+ if (preallocate_pxds(pxds) != 0)
33854 goto out_free_pgd;
33855
33856 if (paravirt_pgd_alloc(mm) != 0)
33857- goto out_free_pmds;
33858+ goto out_free_pxds;
33859
33860 /*
33861 * Make sure that pre-populating the pmds is atomic with
33862@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33863 spin_lock(&pgd_lock);
33864
33865 pgd_ctor(mm, pgd);
33866- pgd_prepopulate_pmd(mm, pgd, pmds);
33867+ pgd_prepopulate_pxd(mm, pgd, pxds);
33868
33869 spin_unlock(&pgd_lock);
33870
33871 return pgd;
33872
33873-out_free_pmds:
33874- free_pmds(pmds);
33875+out_free_pxds:
33876+ free_pxds(pxds);
33877 out_free_pgd:
33878 free_page((unsigned long)pgd);
33879 out:
33880@@ -313,7 +380,7 @@ out:
33881
33882 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33883 {
33884- pgd_mop_up_pmds(mm, pgd);
33885+ pgd_mop_up_pxds(mm, pgd);
33886 pgd_dtor(pgd);
33887 paravirt_pgd_free(mm, pgd);
33888 free_page((unsigned long)pgd);
33889diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33890index a69bcb8..19068ab 100644
33891--- a/arch/x86/mm/pgtable_32.c
33892+++ b/arch/x86/mm/pgtable_32.c
33893@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33894 return;
33895 }
33896 pte = pte_offset_kernel(pmd, vaddr);
33897+
33898+ pax_open_kernel();
33899 if (pte_val(pteval))
33900 set_pte_at(&init_mm, vaddr, pte, pteval);
33901 else
33902 pte_clear(&init_mm, vaddr, pte);
33903+ pax_close_kernel();
33904
33905 /*
33906 * It's enough to flush this one mapping.
33907diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33908index e666cbb..61788c45 100644
33909--- a/arch/x86/mm/physaddr.c
33910+++ b/arch/x86/mm/physaddr.c
33911@@ -10,7 +10,7 @@
33912 #ifdef CONFIG_X86_64
33913
33914 #ifdef CONFIG_DEBUG_VIRTUAL
33915-unsigned long __phys_addr(unsigned long x)
33916+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33917 {
33918 unsigned long y = x - __START_KERNEL_map;
33919
33920@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33921 #else
33922
33923 #ifdef CONFIG_DEBUG_VIRTUAL
33924-unsigned long __phys_addr(unsigned long x)
33925+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33926 {
33927 unsigned long phys_addr = x - PAGE_OFFSET;
33928 /* VMALLOC_* aren't constants */
33929diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33930index 90555bf..f5f1828 100644
33931--- a/arch/x86/mm/setup_nx.c
33932+++ b/arch/x86/mm/setup_nx.c
33933@@ -5,8 +5,10 @@
33934 #include <asm/pgtable.h>
33935 #include <asm/proto.h>
33936
33937+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33938 static int disable_nx;
33939
33940+#ifndef CONFIG_PAX_PAGEEXEC
33941 /*
33942 * noexec = on|off
33943 *
33944@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33945 return 0;
33946 }
33947 early_param("noexec", noexec_setup);
33948+#endif
33949+
33950+#endif
33951
33952 void x86_configure_nx(void)
33953 {
33954+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33955 if (cpu_has_nx && !disable_nx)
33956 __supported_pte_mask |= _PAGE_NX;
33957 else
33958+#endif
33959 __supported_pte_mask &= ~_PAGE_NX;
33960 }
33961
33962diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33963index dd8dda1..9e9b0f6 100644
33964--- a/arch/x86/mm/tlb.c
33965+++ b/arch/x86/mm/tlb.c
33966@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33967 BUG();
33968 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33969 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33970+
33971+#ifndef CONFIG_PAX_PER_CPU_PGD
33972 load_cr3(swapper_pg_dir);
33973+#endif
33974+
33975 }
33976 }
33977 EXPORT_SYMBOL_GPL(leave_mm);
33978diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33979new file mode 100644
33980index 0000000..dace51c
33981--- /dev/null
33982+++ b/arch/x86/mm/uderef_64.c
33983@@ -0,0 +1,37 @@
33984+#include <linux/mm.h>
33985+#include <asm/pgtable.h>
33986+#include <asm/uaccess.h>
33987+
33988+#ifdef CONFIG_PAX_MEMORY_UDEREF
33989+/* PaX: due to the special call convention these functions must
33990+ * - remain leaf functions under all configurations,
33991+ * - never be called directly, only dereferenced from the wrappers.
33992+ */
33993+void __pax_open_userland(void)
33994+{
33995+ unsigned int cpu;
33996+
33997+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33998+ return;
33999+
34000+ cpu = raw_get_cpu();
34001+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34002+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34003+ raw_put_cpu_no_resched();
34004+}
34005+EXPORT_SYMBOL(__pax_open_userland);
34006+
34007+void __pax_close_userland(void)
34008+{
34009+ unsigned int cpu;
34010+
34011+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34012+ return;
34013+
34014+ cpu = raw_get_cpu();
34015+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34016+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34017+ raw_put_cpu_no_resched();
34018+}
34019+EXPORT_SYMBOL(__pax_close_userland);
34020+#endif
34021diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34022index 0149575..f746de8 100644
34023--- a/arch/x86/net/bpf_jit.S
34024+++ b/arch/x86/net/bpf_jit.S
34025@@ -9,6 +9,7 @@
34026 */
34027 #include <linux/linkage.h>
34028 #include <asm/dwarf2.h>
34029+#include <asm/alternative-asm.h>
34030
34031 /*
34032 * Calling convention :
34033@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
34034 jle bpf_slow_path_word
34035 mov (SKBDATA,%rsi),%eax
34036 bswap %eax /* ntohl() */
34037+ pax_force_retaddr
34038 ret
34039
34040 sk_load_half:
34041@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
34042 jle bpf_slow_path_half
34043 movzwl (SKBDATA,%rsi),%eax
34044 rol $8,%ax # ntohs()
34045+ pax_force_retaddr
34046 ret
34047
34048 sk_load_byte:
34049@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
34050 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34051 jle bpf_slow_path_byte
34052 movzbl (SKBDATA,%rsi),%eax
34053+ pax_force_retaddr
34054 ret
34055
34056 /**
34057@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
34058 movzbl (SKBDATA,%rsi),%ebx
34059 and $15,%bl
34060 shl $2,%bl
34061+ pax_force_retaddr
34062 ret
34063
34064 /* rsi contains offset and can be scratched */
34065@@ -109,6 +114,7 @@ bpf_slow_path_word:
34066 js bpf_error
34067 mov -12(%rbp),%eax
34068 bswap %eax
34069+ pax_force_retaddr
34070 ret
34071
34072 bpf_slow_path_half:
34073@@ -117,12 +123,14 @@ bpf_slow_path_half:
34074 mov -12(%rbp),%ax
34075 rol $8,%ax
34076 movzwl %ax,%eax
34077+ pax_force_retaddr
34078 ret
34079
34080 bpf_slow_path_byte:
34081 bpf_slow_path_common(1)
34082 js bpf_error
34083 movzbl -12(%rbp),%eax
34084+ pax_force_retaddr
34085 ret
34086
34087 bpf_slow_path_byte_msh:
34088@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
34089 and $15,%al
34090 shl $2,%al
34091 xchg %eax,%ebx
34092+ pax_force_retaddr
34093 ret
34094
34095 #define sk_negative_common(SIZE) \
34096@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
34097 sk_negative_common(4)
34098 mov (%rax), %eax
34099 bswap %eax
34100+ pax_force_retaddr
34101 ret
34102
34103 bpf_slow_path_half_neg:
34104@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
34105 mov (%rax),%ax
34106 rol $8,%ax
34107 movzwl %ax,%eax
34108+ pax_force_retaddr
34109 ret
34110
34111 bpf_slow_path_byte_neg:
34112@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
34113 .globl sk_load_byte_negative_offset
34114 sk_negative_common(1)
34115 movzbl (%rax), %eax
34116+ pax_force_retaddr
34117 ret
34118
34119 bpf_slow_path_byte_msh_neg:
34120@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
34121 and $15,%al
34122 shl $2,%al
34123 xchg %eax,%ebx
34124+ pax_force_retaddr
34125 ret
34126
34127 bpf_error:
34128@@ -197,4 +210,5 @@ bpf_error:
34129 xor %eax,%eax
34130 mov -8(%rbp),%rbx
34131 leaveq
34132+ pax_force_retaddr
34133 ret
34134diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34135index 4ed75dd..3cf24f0b 100644
34136--- a/arch/x86/net/bpf_jit_comp.c
34137+++ b/arch/x86/net/bpf_jit_comp.c
34138@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34139 return ptr + len;
34140 }
34141
34142+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34143+#define MAX_INSTR_CODE_SIZE 96
34144+#else
34145+#define MAX_INSTR_CODE_SIZE 64
34146+#endif
34147+
34148 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
34149
34150 #define EMIT1(b1) EMIT(b1, 1)
34151 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
34152 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
34153 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
34154+
34155+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34156+/* original constant will appear in ecx */
34157+#define DILUTE_CONST_SEQUENCE(_off, _key) \
34158+do { \
34159+ /* mov ecx, randkey */ \
34160+ EMIT1(0xb9); \
34161+ EMIT(_key, 4); \
34162+ /* xor ecx, randkey ^ off */ \
34163+ EMIT2(0x81, 0xf1); \
34164+ EMIT((_key) ^ (_off), 4); \
34165+} while (0)
34166+
34167+#define EMIT1_off32(b1, _off) \
34168+do { \
34169+ switch (b1) { \
34170+ case 0x05: /* add eax, imm32 */ \
34171+ case 0x2d: /* sub eax, imm32 */ \
34172+ case 0x25: /* and eax, imm32 */ \
34173+ case 0x0d: /* or eax, imm32 */ \
34174+ case 0xb8: /* mov eax, imm32 */ \
34175+ case 0x35: /* xor eax, imm32 */ \
34176+ case 0x3d: /* cmp eax, imm32 */ \
34177+ case 0xa9: /* test eax, imm32 */ \
34178+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34179+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
34180+ break; \
34181+ case 0xbb: /* mov ebx, imm32 */ \
34182+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34183+ /* mov ebx, ecx */ \
34184+ EMIT2(0x89, 0xcb); \
34185+ break; \
34186+ case 0xbe: /* mov esi, imm32 */ \
34187+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34188+ /* mov esi, ecx */ \
34189+ EMIT2(0x89, 0xce); \
34190+ break; \
34191+ case 0xe8: /* call rel imm32, always to known funcs */ \
34192+ EMIT1(b1); \
34193+ EMIT(_off, 4); \
34194+ break; \
34195+ case 0xe9: /* jmp rel imm32 */ \
34196+ EMIT1(b1); \
34197+ EMIT(_off, 4); \
34198+ /* prevent fall-through, we're not called if off = 0 */ \
34199+ EMIT(0xcccccccc, 4); \
34200+ EMIT(0xcccccccc, 4); \
34201+ break; \
34202+ default: \
34203+ BUILD_BUG(); \
34204+ } \
34205+} while (0)
34206+
34207+#define EMIT2_off32(b1, b2, _off) \
34208+do { \
34209+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
34210+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
34211+ EMIT(randkey, 4); \
34212+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
34213+ EMIT((_off) - randkey, 4); \
34214+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
34215+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34216+ /* imul eax, ecx */ \
34217+ EMIT3(0x0f, 0xaf, 0xc1); \
34218+ } else { \
34219+ BUILD_BUG(); \
34220+ } \
34221+} while (0)
34222+#else
34223 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
34224+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
34225+#endif
34226
34227 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
34228 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
34229@@ -91,6 +168,24 @@ do { \
34230 #define X86_JBE 0x76
34231 #define X86_JA 0x77
34232
34233+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34234+#define APPEND_FLOW_VERIFY() \
34235+do { \
34236+ /* mov ecx, randkey */ \
34237+ EMIT1(0xb9); \
34238+ EMIT(randkey, 4); \
34239+ /* cmp ecx, randkey */ \
34240+ EMIT2(0x81, 0xf9); \
34241+ EMIT(randkey, 4); \
34242+ /* jz after 8 int 3s */ \
34243+ EMIT2(0x74, 0x08); \
34244+ EMIT(0xcccccccc, 4); \
34245+ EMIT(0xcccccccc, 4); \
34246+} while (0)
34247+#else
34248+#define APPEND_FLOW_VERIFY() do { } while (0)
34249+#endif
34250+
34251 #define EMIT_COND_JMP(op, offset) \
34252 do { \
34253 if (is_near(offset)) \
34254@@ -98,6 +193,7 @@ do { \
34255 else { \
34256 EMIT2(0x0f, op + 0x10); \
34257 EMIT(offset, 4); /* jxx .+off32 */ \
34258+ APPEND_FLOW_VERIFY(); \
34259 } \
34260 } while (0)
34261
34262@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
34263 return -1;
34264 }
34265
34266-struct bpf_binary_header {
34267- unsigned int pages;
34268- /* Note : for security reasons, bpf code will follow a randomly
34269- * sized amount of int3 instructions
34270- */
34271- u8 image[];
34272-};
34273-
34274-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34275+/* Note : for security reasons, bpf code will follow a randomly
34276+ * sized amount of int3 instructions
34277+ */
34278+static u8 *bpf_alloc_binary(unsigned int proglen,
34279 u8 **image_ptr)
34280 {
34281 unsigned int sz, hole;
34282- struct bpf_binary_header *header;
34283+ u8 *header;
34284
34285 /* Most of BPF filters are really small,
34286 * but if some of them fill a page, allow at least
34287 * 128 extra bytes to insert a random section of int3
34288 */
34289- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34290- header = module_alloc(sz);
34291+ sz = round_up(proglen + 128, PAGE_SIZE);
34292+ header = module_alloc_exec(sz);
34293 if (!header)
34294 return NULL;
34295
34296+ pax_open_kernel();
34297 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34298+ pax_close_kernel();
34299
34300- header->pages = sz / PAGE_SIZE;
34301- hole = sz - (proglen + sizeof(*header));
34302+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34303
34304 /* insert a random number of int3 instructions before BPF code */
34305- *image_ptr = &header->image[prandom_u32() % hole];
34306+ *image_ptr = &header[prandom_u32() % hole];
34307 return header;
34308 }
34309
34310 void bpf_jit_compile(struct sk_filter *fp)
34311 {
34312- u8 temp[64];
34313+ u8 temp[MAX_INSTR_CODE_SIZE];
34314 u8 *prog;
34315 unsigned int proglen, oldproglen = 0;
34316 int ilen, i;
34317 int t_offset, f_offset;
34318 u8 t_op, f_op, seen = 0, pass;
34319 u8 *image = NULL;
34320- struct bpf_binary_header *header = NULL;
34321+ u8 *header = NULL;
34322 u8 *func;
34323 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34324 unsigned int cleanup_addr; /* epilogue code offset */
34325 unsigned int *addrs;
34326 const struct sock_filter *filter = fp->insns;
34327 int flen = fp->len;
34328+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34329+ unsigned int randkey;
34330+#endif
34331
34332 if (!bpf_jit_enable)
34333 return;
34334@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34335 return;
34336
34337 /* Before first pass, make a rough estimation of addrs[]
34338- * each bpf instruction is translated to less than 64 bytes
34339+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34340 */
34341 for (proglen = 0, i = 0; i < flen; i++) {
34342- proglen += 64;
34343+ proglen += MAX_INSTR_CODE_SIZE;
34344 addrs[i] = proglen;
34345 }
34346 cleanup_addr = proglen; /* epilogue address */
34347@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34348 for (i = 0; i < flen; i++) {
34349 unsigned int K = filter[i].k;
34350
34351+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34352+ randkey = prandom_u32();
34353+#endif
34354+
34355 switch (filter[i].code) {
34356 case BPF_S_ALU_ADD_X: /* A += X; */
34357 seen |= SEEN_XREG;
34358@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34359 case BPF_S_ALU_MUL_K: /* A *= K */
34360 if (is_imm8(K))
34361 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34362- else {
34363- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34364- EMIT(K, 4);
34365- }
34366+ else
34367+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34368 break;
34369 case BPF_S_ALU_DIV_X: /* A /= X; */
34370 seen |= SEEN_XREG;
34371@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34372 break;
34373 }
34374 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34375+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34376+ DILUTE_CONST_SEQUENCE(K, randkey);
34377+#else
34378 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34379+#endif
34380 EMIT2(0xf7, 0xf1); /* div %ecx */
34381 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34382 break;
34383@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34384 if (K == 1)
34385 break;
34386 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34387+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34388+ DILUTE_CONST_SEQUENCE(K, randkey);
34389+#else
34390 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34391+#endif
34392 EMIT2(0xf7, 0xf1); /* div %ecx */
34393 break;
34394 case BPF_S_ALU_AND_X:
34395@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34396 if (is_imm8(K)) {
34397 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34398 } else {
34399- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34400- EMIT(K, 4);
34401+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34402 }
34403 } else {
34404 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34405@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34406 if (unlikely(proglen + ilen > oldproglen)) {
34407 pr_err("bpb_jit_compile fatal error\n");
34408 kfree(addrs);
34409- module_free(NULL, header);
34410+ module_free_exec(NULL, image);
34411 return;
34412 }
34413+ pax_open_kernel();
34414 memcpy(image + proglen, temp, ilen);
34415+ pax_close_kernel();
34416 }
34417 proglen += ilen;
34418 addrs[i] = proglen;
34419@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34420
34421 if (image) {
34422 bpf_flush_icache(header, image + proglen);
34423- set_memory_ro((unsigned long)header, header->pages);
34424 fp->bpf_func = (void *)image;
34425 }
34426 out:
34427@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34428 {
34429 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34430 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34431- struct bpf_binary_header *header = (void *)addr;
34432
34433- set_memory_rw(addr, header->pages);
34434- module_free(NULL, header);
34435+ set_memory_rw(addr, 1);
34436+ module_free_exec(NULL, (void *)addr);
34437 kfree(fp);
34438 }
34439
34440diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34441index 5d04be5..2beeaa2 100644
34442--- a/arch/x86/oprofile/backtrace.c
34443+++ b/arch/x86/oprofile/backtrace.c
34444@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34445 struct stack_frame_ia32 *fp;
34446 unsigned long bytes;
34447
34448- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34449+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34450 if (bytes != 0)
34451 return NULL;
34452
34453- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34454+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34455
34456 oprofile_add_trace(bufhead[0].return_address);
34457
34458@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34459 struct stack_frame bufhead[2];
34460 unsigned long bytes;
34461
34462- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34463+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34464 if (bytes != 0)
34465 return NULL;
34466
34467@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34468 {
34469 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34470
34471- if (!user_mode_vm(regs)) {
34472+ if (!user_mode(regs)) {
34473 unsigned long stack = kernel_stack_pointer(regs);
34474 if (depth)
34475 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34476diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34477index 6890d84..1dad1f1 100644
34478--- a/arch/x86/oprofile/nmi_int.c
34479+++ b/arch/x86/oprofile/nmi_int.c
34480@@ -23,6 +23,7 @@
34481 #include <asm/nmi.h>
34482 #include <asm/msr.h>
34483 #include <asm/apic.h>
34484+#include <asm/pgtable.h>
34485
34486 #include "op_counter.h"
34487 #include "op_x86_model.h"
34488@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34489 if (ret)
34490 return ret;
34491
34492- if (!model->num_virt_counters)
34493- model->num_virt_counters = model->num_counters;
34494+ if (!model->num_virt_counters) {
34495+ pax_open_kernel();
34496+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34497+ pax_close_kernel();
34498+ }
34499
34500 mux_init(ops);
34501
34502diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34503index 50d86c0..7985318 100644
34504--- a/arch/x86/oprofile/op_model_amd.c
34505+++ b/arch/x86/oprofile/op_model_amd.c
34506@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34507 num_counters = AMD64_NUM_COUNTERS;
34508 }
34509
34510- op_amd_spec.num_counters = num_counters;
34511- op_amd_spec.num_controls = num_counters;
34512- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34513+ pax_open_kernel();
34514+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34515+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34516+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34517+ pax_close_kernel();
34518
34519 return 0;
34520 }
34521diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34522index d90528e..0127e2b 100644
34523--- a/arch/x86/oprofile/op_model_ppro.c
34524+++ b/arch/x86/oprofile/op_model_ppro.c
34525@@ -19,6 +19,7 @@
34526 #include <asm/msr.h>
34527 #include <asm/apic.h>
34528 #include <asm/nmi.h>
34529+#include <asm/pgtable.h>
34530
34531 #include "op_x86_model.h"
34532 #include "op_counter.h"
34533@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34534
34535 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34536
34537- op_arch_perfmon_spec.num_counters = num_counters;
34538- op_arch_perfmon_spec.num_controls = num_counters;
34539+ pax_open_kernel();
34540+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34541+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34542+ pax_close_kernel();
34543 }
34544
34545 static int arch_perfmon_init(struct oprofile_operations *ignore)
34546diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34547index 71e8a67..6a313bb 100644
34548--- a/arch/x86/oprofile/op_x86_model.h
34549+++ b/arch/x86/oprofile/op_x86_model.h
34550@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34551 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34552 struct op_msrs const * const msrs);
34553 #endif
34554-};
34555+} __do_const;
34556
34557 struct op_counter_config;
34558
34559diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34560index 84b9d67..260e5ff 100644
34561--- a/arch/x86/pci/intel_mid_pci.c
34562+++ b/arch/x86/pci/intel_mid_pci.c
34563@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34564 pr_info("Intel MID platform detected, using MID PCI ops\n");
34565 pci_mmcfg_late_init();
34566 pcibios_enable_irq = intel_mid_pci_irq_enable;
34567- pci_root_ops = intel_mid_pci_ops;
34568+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34569 pci_soc_mode = 1;
34570 /* Continue with standard init */
34571 return 1;
34572diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34573index 372e9b8..e775a6c 100644
34574--- a/arch/x86/pci/irq.c
34575+++ b/arch/x86/pci/irq.c
34576@@ -50,7 +50,7 @@ struct irq_router {
34577 struct irq_router_handler {
34578 u16 vendor;
34579 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34580-};
34581+} __do_const;
34582
34583 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34584 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34585@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34586 return 0;
34587 }
34588
34589-static __initdata struct irq_router_handler pirq_routers[] = {
34590+static __initconst const struct irq_router_handler pirq_routers[] = {
34591 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34592 { PCI_VENDOR_ID_AL, ali_router_probe },
34593 { PCI_VENDOR_ID_ITE, ite_router_probe },
34594@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34595 static void __init pirq_find_router(struct irq_router *r)
34596 {
34597 struct irq_routing_table *rt = pirq_table;
34598- struct irq_router_handler *h;
34599+ const struct irq_router_handler *h;
34600
34601 #ifdef CONFIG_PCI_BIOS
34602 if (!rt->signature) {
34603@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34604 return 0;
34605 }
34606
34607-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34608+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34609 {
34610 .callback = fix_broken_hp_bios_irq9,
34611 .ident = "HP Pavilion N5400 Series Laptop",
34612diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34613index c77b24a..c979855 100644
34614--- a/arch/x86/pci/pcbios.c
34615+++ b/arch/x86/pci/pcbios.c
34616@@ -79,7 +79,7 @@ union bios32 {
34617 static struct {
34618 unsigned long address;
34619 unsigned short segment;
34620-} bios32_indirect = { 0, __KERNEL_CS };
34621+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34622
34623 /*
34624 * Returns the entry point for the given service, NULL on error
34625@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34626 unsigned long length; /* %ecx */
34627 unsigned long entry; /* %edx */
34628 unsigned long flags;
34629+ struct desc_struct d, *gdt;
34630
34631 local_irq_save(flags);
34632- __asm__("lcall *(%%edi); cld"
34633+
34634+ gdt = get_cpu_gdt_table(smp_processor_id());
34635+
34636+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34637+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34638+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34639+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34640+
34641+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34642 : "=a" (return_code),
34643 "=b" (address),
34644 "=c" (length),
34645 "=d" (entry)
34646 : "0" (service),
34647 "1" (0),
34648- "D" (&bios32_indirect));
34649+ "D" (&bios32_indirect),
34650+ "r"(__PCIBIOS_DS)
34651+ : "memory");
34652+
34653+ pax_open_kernel();
34654+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34655+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34656+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34657+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34658+ pax_close_kernel();
34659+
34660 local_irq_restore(flags);
34661
34662 switch (return_code) {
34663- case 0:
34664- return address + entry;
34665- case 0x80: /* Not present */
34666- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34667- return 0;
34668- default: /* Shouldn't happen */
34669- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34670- service, return_code);
34671+ case 0: {
34672+ int cpu;
34673+ unsigned char flags;
34674+
34675+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34676+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34677+ printk(KERN_WARNING "bios32_service: not valid\n");
34678 return 0;
34679+ }
34680+ address = address + PAGE_OFFSET;
34681+ length += 16UL; /* some BIOSs underreport this... */
34682+ flags = 4;
34683+ if (length >= 64*1024*1024) {
34684+ length >>= PAGE_SHIFT;
34685+ flags |= 8;
34686+ }
34687+
34688+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34689+ gdt = get_cpu_gdt_table(cpu);
34690+ pack_descriptor(&d, address, length, 0x9b, flags);
34691+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34692+ pack_descriptor(&d, address, length, 0x93, flags);
34693+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34694+ }
34695+ return entry;
34696+ }
34697+ case 0x80: /* Not present */
34698+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34699+ return 0;
34700+ default: /* Shouldn't happen */
34701+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34702+ service, return_code);
34703+ return 0;
34704 }
34705 }
34706
34707 static struct {
34708 unsigned long address;
34709 unsigned short segment;
34710-} pci_indirect = { 0, __KERNEL_CS };
34711+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34712
34713-static int pci_bios_present;
34714+static int pci_bios_present __read_only;
34715
34716 static int check_pcibios(void)
34717 {
34718@@ -131,11 +174,13 @@ static int check_pcibios(void)
34719 unsigned long flags, pcibios_entry;
34720
34721 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34722- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34723+ pci_indirect.address = pcibios_entry;
34724
34725 local_irq_save(flags);
34726- __asm__(
34727- "lcall *(%%edi); cld\n\t"
34728+ __asm__("movw %w6, %%ds\n\t"
34729+ "lcall *%%ss:(%%edi); cld\n\t"
34730+ "push %%ss\n\t"
34731+ "pop %%ds\n\t"
34732 "jc 1f\n\t"
34733 "xor %%ah, %%ah\n"
34734 "1:"
34735@@ -144,7 +189,8 @@ static int check_pcibios(void)
34736 "=b" (ebx),
34737 "=c" (ecx)
34738 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34739- "D" (&pci_indirect)
34740+ "D" (&pci_indirect),
34741+ "r" (__PCIBIOS_DS)
34742 : "memory");
34743 local_irq_restore(flags);
34744
34745@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34746
34747 switch (len) {
34748 case 1:
34749- __asm__("lcall *(%%esi); cld\n\t"
34750+ __asm__("movw %w6, %%ds\n\t"
34751+ "lcall *%%ss:(%%esi); cld\n\t"
34752+ "push %%ss\n\t"
34753+ "pop %%ds\n\t"
34754 "jc 1f\n\t"
34755 "xor %%ah, %%ah\n"
34756 "1:"
34757@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34758 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34759 "b" (bx),
34760 "D" ((long)reg),
34761- "S" (&pci_indirect));
34762+ "S" (&pci_indirect),
34763+ "r" (__PCIBIOS_DS));
34764 /*
34765 * Zero-extend the result beyond 8 bits, do not trust the
34766 * BIOS having done it:
34767@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34768 *value &= 0xff;
34769 break;
34770 case 2:
34771- __asm__("lcall *(%%esi); cld\n\t"
34772+ __asm__("movw %w6, %%ds\n\t"
34773+ "lcall *%%ss:(%%esi); cld\n\t"
34774+ "push %%ss\n\t"
34775+ "pop %%ds\n\t"
34776 "jc 1f\n\t"
34777 "xor %%ah, %%ah\n"
34778 "1:"
34779@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34780 : "1" (PCIBIOS_READ_CONFIG_WORD),
34781 "b" (bx),
34782 "D" ((long)reg),
34783- "S" (&pci_indirect));
34784+ "S" (&pci_indirect),
34785+ "r" (__PCIBIOS_DS));
34786 /*
34787 * Zero-extend the result beyond 16 bits, do not trust the
34788 * BIOS having done it:
34789@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34790 *value &= 0xffff;
34791 break;
34792 case 4:
34793- __asm__("lcall *(%%esi); cld\n\t"
34794+ __asm__("movw %w6, %%ds\n\t"
34795+ "lcall *%%ss:(%%esi); cld\n\t"
34796+ "push %%ss\n\t"
34797+ "pop %%ds\n\t"
34798 "jc 1f\n\t"
34799 "xor %%ah, %%ah\n"
34800 "1:"
34801@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34802 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34803 "b" (bx),
34804 "D" ((long)reg),
34805- "S" (&pci_indirect));
34806+ "S" (&pci_indirect),
34807+ "r" (__PCIBIOS_DS));
34808 break;
34809 }
34810
34811@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34812
34813 switch (len) {
34814 case 1:
34815- __asm__("lcall *(%%esi); cld\n\t"
34816+ __asm__("movw %w6, %%ds\n\t"
34817+ "lcall *%%ss:(%%esi); cld\n\t"
34818+ "push %%ss\n\t"
34819+ "pop %%ds\n\t"
34820 "jc 1f\n\t"
34821 "xor %%ah, %%ah\n"
34822 "1:"
34823@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34824 "c" (value),
34825 "b" (bx),
34826 "D" ((long)reg),
34827- "S" (&pci_indirect));
34828+ "S" (&pci_indirect),
34829+ "r" (__PCIBIOS_DS));
34830 break;
34831 case 2:
34832- __asm__("lcall *(%%esi); cld\n\t"
34833+ __asm__("movw %w6, %%ds\n\t"
34834+ "lcall *%%ss:(%%esi); cld\n\t"
34835+ "push %%ss\n\t"
34836+ "pop %%ds\n\t"
34837 "jc 1f\n\t"
34838 "xor %%ah, %%ah\n"
34839 "1:"
34840@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34841 "c" (value),
34842 "b" (bx),
34843 "D" ((long)reg),
34844- "S" (&pci_indirect));
34845+ "S" (&pci_indirect),
34846+ "r" (__PCIBIOS_DS));
34847 break;
34848 case 4:
34849- __asm__("lcall *(%%esi); cld\n\t"
34850+ __asm__("movw %w6, %%ds\n\t"
34851+ "lcall *%%ss:(%%esi); cld\n\t"
34852+ "push %%ss\n\t"
34853+ "pop %%ds\n\t"
34854 "jc 1f\n\t"
34855 "xor %%ah, %%ah\n"
34856 "1:"
34857@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34858 "c" (value),
34859 "b" (bx),
34860 "D" ((long)reg),
34861- "S" (&pci_indirect));
34862+ "S" (&pci_indirect),
34863+ "r" (__PCIBIOS_DS));
34864 break;
34865 }
34866
34867@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34868
34869 DBG("PCI: Fetching IRQ routing table... ");
34870 __asm__("push %%es\n\t"
34871+ "movw %w8, %%ds\n\t"
34872 "push %%ds\n\t"
34873 "pop %%es\n\t"
34874- "lcall *(%%esi); cld\n\t"
34875+ "lcall *%%ss:(%%esi); cld\n\t"
34876 "pop %%es\n\t"
34877+ "push %%ss\n\t"
34878+ "pop %%ds\n"
34879 "jc 1f\n\t"
34880 "xor %%ah, %%ah\n"
34881 "1:"
34882@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34883 "1" (0),
34884 "D" ((long) &opt),
34885 "S" (&pci_indirect),
34886- "m" (opt)
34887+ "m" (opt),
34888+ "r" (__PCIBIOS_DS)
34889 : "memory");
34890 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34891 if (ret & 0xff00)
34892@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34893 {
34894 int ret;
34895
34896- __asm__("lcall *(%%esi); cld\n\t"
34897+ __asm__("movw %w5, %%ds\n\t"
34898+ "lcall *%%ss:(%%esi); cld\n\t"
34899+ "push %%ss\n\t"
34900+ "pop %%ds\n"
34901 "jc 1f\n\t"
34902 "xor %%ah, %%ah\n"
34903 "1:"
34904@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34905 : "0" (PCIBIOS_SET_PCI_HW_INT),
34906 "b" ((dev->bus->number << 8) | dev->devfn),
34907 "c" ((irq << 8) | (pin + 10)),
34908- "S" (&pci_indirect));
34909+ "S" (&pci_indirect),
34910+ "r" (__PCIBIOS_DS));
34911 return !(ret & 0xff00);
34912 }
34913 EXPORT_SYMBOL(pcibios_set_irq_routing);
34914diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34915index 9ee3491..872192f 100644
34916--- a/arch/x86/platform/efi/efi_32.c
34917+++ b/arch/x86/platform/efi/efi_32.c
34918@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34919 {
34920 struct desc_ptr gdt_descr;
34921
34922+#ifdef CONFIG_PAX_KERNEXEC
34923+ struct desc_struct d;
34924+#endif
34925+
34926 local_irq_save(efi_rt_eflags);
34927
34928 load_cr3(initial_page_table);
34929 __flush_tlb_all();
34930
34931+#ifdef CONFIG_PAX_KERNEXEC
34932+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34933+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34934+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34935+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34936+#endif
34937+
34938 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34939 gdt_descr.size = GDT_SIZE - 1;
34940 load_gdt(&gdt_descr);
34941@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34942 {
34943 struct desc_ptr gdt_descr;
34944
34945+#ifdef CONFIG_PAX_KERNEXEC
34946+ struct desc_struct d;
34947+
34948+ memset(&d, 0, sizeof d);
34949+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34950+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34951+#endif
34952+
34953 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34954 gdt_descr.size = GDT_SIZE - 1;
34955 load_gdt(&gdt_descr);
34956
34957+#ifdef CONFIG_PAX_PER_CPU_PGD
34958+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34959+#else
34960 load_cr3(swapper_pg_dir);
34961+#endif
34962+
34963 __flush_tlb_all();
34964
34965 local_irq_restore(efi_rt_eflags);
34966diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34967index 666b74a..673d88f 100644
34968--- a/arch/x86/platform/efi/efi_64.c
34969+++ b/arch/x86/platform/efi/efi_64.c
34970@@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
34971 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34972 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34973 }
34974+
34975+#ifdef CONFIG_PAX_PER_CPU_PGD
34976+ load_cr3(swapper_pg_dir);
34977+#endif
34978+
34979 __flush_tlb_all();
34980 }
34981
34982@@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
34983 for (pgd = 0; pgd < n_pgds; pgd++)
34984 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34985 kfree(save_pgd);
34986+
34987+#ifdef CONFIG_PAX_PER_CPU_PGD
34988+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34989+#endif
34990+
34991 __flush_tlb_all();
34992 local_irq_restore(efi_flags);
34993 early_code_mapping_set_exec(0);
34994diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34995index fbe66e6..eae5e38 100644
34996--- a/arch/x86/platform/efi/efi_stub_32.S
34997+++ b/arch/x86/platform/efi/efi_stub_32.S
34998@@ -6,7 +6,9 @@
34999 */
35000
35001 #include <linux/linkage.h>
35002+#include <linux/init.h>
35003 #include <asm/page_types.h>
35004+#include <asm/segment.h>
35005
35006 /*
35007 * efi_call_phys(void *, ...) is a function with variable parameters.
35008@@ -20,7 +22,7 @@
35009 * service functions will comply with gcc calling convention, too.
35010 */
35011
35012-.text
35013+__INIT
35014 ENTRY(efi_call_phys)
35015 /*
35016 * 0. The function can only be called in Linux kernel. So CS has been
35017@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
35018 * The mapping of lower virtual memory has been created in prelog and
35019 * epilog.
35020 */
35021- movl $1f, %edx
35022- subl $__PAGE_OFFSET, %edx
35023- jmp *%edx
35024+#ifdef CONFIG_PAX_KERNEXEC
35025+ movl $(__KERNEXEC_EFI_DS), %edx
35026+ mov %edx, %ds
35027+ mov %edx, %es
35028+ mov %edx, %ss
35029+ addl $2f,(1f)
35030+ ljmp *(1f)
35031+
35032+__INITDATA
35033+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
35034+.previous
35035+
35036+2:
35037+ subl $2b,(1b)
35038+#else
35039+ jmp 1f-__PAGE_OFFSET
35040 1:
35041+#endif
35042
35043 /*
35044 * 2. Now on the top of stack is the return
35045@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35046 * parameter 2, ..., param n. To make things easy, we save the return
35047 * address of efi_call_phys in a global variable.
35048 */
35049- popl %edx
35050- movl %edx, saved_return_addr
35051- /* get the function pointer into ECX*/
35052- popl %ecx
35053- movl %ecx, efi_rt_function_ptr
35054- movl $2f, %edx
35055- subl $__PAGE_OFFSET, %edx
35056- pushl %edx
35057+ popl (saved_return_addr)
35058+ popl (efi_rt_function_ptr)
35059
35060 /*
35061 * 3. Clear PG bit in %CR0.
35062@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35063 /*
35064 * 5. Call the physical function.
35065 */
35066- jmp *%ecx
35067+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
35068
35069-2:
35070 /*
35071 * 6. After EFI runtime service returns, control will return to
35072 * following instruction. We'd better readjust stack pointer first.
35073@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35074 movl %cr0, %edx
35075 orl $0x80000000, %edx
35076 movl %edx, %cr0
35077- jmp 1f
35078-1:
35079+
35080 /*
35081 * 8. Now restore the virtual mode from flat mode by
35082 * adding EIP with PAGE_OFFSET.
35083 */
35084- movl $1f, %edx
35085- jmp *%edx
35086+#ifdef CONFIG_PAX_KERNEXEC
35087+ movl $(__KERNEL_DS), %edx
35088+ mov %edx, %ds
35089+ mov %edx, %es
35090+ mov %edx, %ss
35091+ ljmp $(__KERNEL_CS),$1f
35092+#else
35093+ jmp 1f+__PAGE_OFFSET
35094+#endif
35095 1:
35096
35097 /*
35098 * 9. Balance the stack. And because EAX contain the return value,
35099 * we'd better not clobber it.
35100 */
35101- leal efi_rt_function_ptr, %edx
35102- movl (%edx), %ecx
35103- pushl %ecx
35104+ pushl (efi_rt_function_ptr)
35105
35106 /*
35107- * 10. Push the saved return address onto the stack and return.
35108+ * 10. Return to the saved return address.
35109 */
35110- leal saved_return_addr, %edx
35111- movl (%edx), %ecx
35112- pushl %ecx
35113- ret
35114+ jmpl *(saved_return_addr)
35115 ENDPROC(efi_call_phys)
35116 .previous
35117
35118-.data
35119+__INITDATA
35120 saved_return_addr:
35121 .long 0
35122 efi_rt_function_ptr:
35123diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35124index 88073b1..1cc2f53 100644
35125--- a/arch/x86/platform/efi/efi_stub_64.S
35126+++ b/arch/x86/platform/efi/efi_stub_64.S
35127@@ -7,6 +7,7 @@
35128 */
35129
35130 #include <linux/linkage.h>
35131+#include <asm/alternative-asm.h>
35132
35133 #define SAVE_XMM \
35134 mov %rsp, %rax; \
35135@@ -77,6 +78,7 @@ ENTRY(efi_call0)
35136 RESTORE_PGT
35137 addq $32, %rsp
35138 RESTORE_XMM
35139+ pax_force_retaddr 0, 1
35140 ret
35141 ENDPROC(efi_call0)
35142
35143@@ -89,6 +91,7 @@ ENTRY(efi_call1)
35144 RESTORE_PGT
35145 addq $32, %rsp
35146 RESTORE_XMM
35147+ pax_force_retaddr 0, 1
35148 ret
35149 ENDPROC(efi_call1)
35150
35151@@ -101,6 +104,7 @@ ENTRY(efi_call2)
35152 RESTORE_PGT
35153 addq $32, %rsp
35154 RESTORE_XMM
35155+ pax_force_retaddr 0, 1
35156 ret
35157 ENDPROC(efi_call2)
35158
35159@@ -114,6 +118,7 @@ ENTRY(efi_call3)
35160 RESTORE_PGT
35161 addq $32, %rsp
35162 RESTORE_XMM
35163+ pax_force_retaddr 0, 1
35164 ret
35165 ENDPROC(efi_call3)
35166
35167@@ -128,6 +133,7 @@ ENTRY(efi_call4)
35168 RESTORE_PGT
35169 addq $32, %rsp
35170 RESTORE_XMM
35171+ pax_force_retaddr 0, 1
35172 ret
35173 ENDPROC(efi_call4)
35174
35175@@ -143,6 +149,7 @@ ENTRY(efi_call5)
35176 RESTORE_PGT
35177 addq $48, %rsp
35178 RESTORE_XMM
35179+ pax_force_retaddr 0, 1
35180 ret
35181 ENDPROC(efi_call5)
35182
35183@@ -161,6 +168,7 @@ ENTRY(efi_call6)
35184 RESTORE_PGT
35185 addq $48, %rsp
35186 RESTORE_XMM
35187+ pax_force_retaddr 0, 1
35188 ret
35189 ENDPROC(efi_call6)
35190
35191diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35192index 1bbedc4..eb795b5 100644
35193--- a/arch/x86/platform/intel-mid/intel-mid.c
35194+++ b/arch/x86/platform/intel-mid/intel-mid.c
35195@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35196 {
35197 };
35198
35199-static void intel_mid_reboot(void)
35200+static void __noreturn intel_mid_reboot(void)
35201 {
35202 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35203+ BUG();
35204 }
35205
35206 static unsigned long __init intel_mid_calibrate_tsc(void)
35207diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35208index d6ee929..3637cb5 100644
35209--- a/arch/x86/platform/olpc/olpc_dt.c
35210+++ b/arch/x86/platform/olpc/olpc_dt.c
35211@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35212 return res;
35213 }
35214
35215-static struct of_pdt_ops prom_olpc_ops __initdata = {
35216+static struct of_pdt_ops prom_olpc_ops __initconst = {
35217 .nextprop = olpc_dt_nextprop,
35218 .getproplen = olpc_dt_getproplen,
35219 .getproperty = olpc_dt_getproperty,
35220diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35221index 424f4c9..f2a2988 100644
35222--- a/arch/x86/power/cpu.c
35223+++ b/arch/x86/power/cpu.c
35224@@ -137,11 +137,8 @@ static void do_fpu_end(void)
35225 static void fix_processor_context(void)
35226 {
35227 int cpu = smp_processor_id();
35228- struct tss_struct *t = &per_cpu(init_tss, cpu);
35229-#ifdef CONFIG_X86_64
35230- struct desc_struct *desc = get_cpu_gdt_table(cpu);
35231- tss_desc tss;
35232-#endif
35233+ struct tss_struct *t = init_tss + cpu;
35234+
35235 set_tss_desc(cpu, t); /*
35236 * This just modifies memory; should not be
35237 * necessary. But... This is necessary, because
35238@@ -150,10 +147,6 @@ static void fix_processor_context(void)
35239 */
35240
35241 #ifdef CONFIG_X86_64
35242- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35243- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35244- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35245-
35246 syscall_init(); /* This sets MSR_*STAR and related */
35247 #endif
35248 load_TR_desc(); /* This does ltr */
35249diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35250index bad628a..a102610 100644
35251--- a/arch/x86/realmode/init.c
35252+++ b/arch/x86/realmode/init.c
35253@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35254 __va(real_mode_header->trampoline_header);
35255
35256 #ifdef CONFIG_X86_32
35257- trampoline_header->start = __pa_symbol(startup_32_smp);
35258+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35259+
35260+#ifdef CONFIG_PAX_KERNEXEC
35261+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35262+#endif
35263+
35264+ trampoline_header->boot_cs = __BOOT_CS;
35265 trampoline_header->gdt_limit = __BOOT_DS + 7;
35266 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35267 #else
35268@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35269 *trampoline_cr4_features = read_cr4();
35270
35271 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35272- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35273+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35274 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35275 #endif
35276 }
35277diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35278index 3497f14..cc73b92 100644
35279--- a/arch/x86/realmode/rm/Makefile
35280+++ b/arch/x86/realmode/rm/Makefile
35281@@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35282
35283 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35284 -I$(srctree)/arch/x86/boot
35285+ifdef CONSTIFY_PLUGIN
35286+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35287+endif
35288 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35289 GCOV_PROFILE := n
35290diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35291index a28221d..93c40f1 100644
35292--- a/arch/x86/realmode/rm/header.S
35293+++ b/arch/x86/realmode/rm/header.S
35294@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35295 #endif
35296 /* APM/BIOS reboot */
35297 .long pa_machine_real_restart_asm
35298-#ifdef CONFIG_X86_64
35299+#ifdef CONFIG_X86_32
35300+ .long __KERNEL_CS
35301+#else
35302 .long __KERNEL32_CS
35303 #endif
35304 END(real_mode_header)
35305diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35306index 48ddd76..c26749f 100644
35307--- a/arch/x86/realmode/rm/trampoline_32.S
35308+++ b/arch/x86/realmode/rm/trampoline_32.S
35309@@ -24,6 +24,12 @@
35310 #include <asm/page_types.h>
35311 #include "realmode.h"
35312
35313+#ifdef CONFIG_PAX_KERNEXEC
35314+#define ta(X) (X)
35315+#else
35316+#define ta(X) (pa_ ## X)
35317+#endif
35318+
35319 .text
35320 .code16
35321
35322@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35323
35324 cli # We should be safe anyway
35325
35326- movl tr_start, %eax # where we need to go
35327-
35328 movl $0xA5A5A5A5, trampoline_status
35329 # write marker for master knows we're running
35330
35331@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35332 movw $1, %dx # protected mode (PE) bit
35333 lmsw %dx # into protected mode
35334
35335- ljmpl $__BOOT_CS, $pa_startup_32
35336+ ljmpl *(trampoline_header)
35337
35338 .section ".text32","ax"
35339 .code32
35340@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35341 .balign 8
35342 GLOBAL(trampoline_header)
35343 tr_start: .space 4
35344- tr_gdt_pad: .space 2
35345+ tr_boot_cs: .space 2
35346 tr_gdt: .space 6
35347 END(trampoline_header)
35348
35349diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35350index dac7b20..72dbaca 100644
35351--- a/arch/x86/realmode/rm/trampoline_64.S
35352+++ b/arch/x86/realmode/rm/trampoline_64.S
35353@@ -93,6 +93,7 @@ ENTRY(startup_32)
35354 movl %edx, %gs
35355
35356 movl pa_tr_cr4, %eax
35357+ andl $~X86_CR4_PCIDE, %eax
35358 movl %eax, %cr4 # Enable PAE mode
35359
35360 # Setup trampoline 4 level pagetables
35361@@ -106,7 +107,7 @@ ENTRY(startup_32)
35362 wrmsr
35363
35364 # Enable paging and in turn activate Long Mode
35365- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35366+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35367 movl %eax, %cr0
35368
35369 /*
35370diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35371index 9e7e147..25a4158 100644
35372--- a/arch/x86/realmode/rm/wakeup_asm.S
35373+++ b/arch/x86/realmode/rm/wakeup_asm.S
35374@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35375 lgdtl pmode_gdt
35376
35377 /* This really couldn't... */
35378- movl pmode_entry, %eax
35379 movl pmode_cr0, %ecx
35380 movl %ecx, %cr0
35381- ljmpl $__KERNEL_CS, $pa_startup_32
35382- /* -> jmp *%eax in trampoline_32.S */
35383+
35384+ ljmpl *pmode_entry
35385 #else
35386 jmp trampoline_start
35387 #endif
35388diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35389index e812034..c747134 100644
35390--- a/arch/x86/tools/Makefile
35391+++ b/arch/x86/tools/Makefile
35392@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35393
35394 $(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
35395
35396-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35397+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35398 hostprogs-y += relocs
35399 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35400 relocs: $(obj)/relocs
35401diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35402index cfbdbdb..1aa763c 100644
35403--- a/arch/x86/tools/relocs.c
35404+++ b/arch/x86/tools/relocs.c
35405@@ -1,5 +1,7 @@
35406 /* This is included from relocs_32/64.c */
35407
35408+#include "../../../include/generated/autoconf.h"
35409+
35410 #define ElfW(type) _ElfW(ELF_BITS, type)
35411 #define _ElfW(bits, type) __ElfW(bits, type)
35412 #define __ElfW(bits, type) Elf##bits##_##type
35413@@ -11,6 +13,7 @@
35414 #define Elf_Sym ElfW(Sym)
35415
35416 static Elf_Ehdr ehdr;
35417+static Elf_Phdr *phdr;
35418
35419 struct relocs {
35420 uint32_t *offset;
35421@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35422 }
35423 }
35424
35425+static void read_phdrs(FILE *fp)
35426+{
35427+ unsigned int i;
35428+
35429+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35430+ if (!phdr) {
35431+ die("Unable to allocate %d program headers\n",
35432+ ehdr.e_phnum);
35433+ }
35434+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35435+ die("Seek to %d failed: %s\n",
35436+ ehdr.e_phoff, strerror(errno));
35437+ }
35438+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35439+ die("Cannot read ELF program headers: %s\n",
35440+ strerror(errno));
35441+ }
35442+ for(i = 0; i < ehdr.e_phnum; i++) {
35443+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35444+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35445+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35446+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35447+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35448+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35449+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35450+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35451+ }
35452+
35453+}
35454+
35455 static void read_shdrs(FILE *fp)
35456 {
35457- int i;
35458+ unsigned int i;
35459 Elf_Shdr shdr;
35460
35461 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35462@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35463
35464 static void read_strtabs(FILE *fp)
35465 {
35466- int i;
35467+ unsigned int i;
35468 for (i = 0; i < ehdr.e_shnum; i++) {
35469 struct section *sec = &secs[i];
35470 if (sec->shdr.sh_type != SHT_STRTAB) {
35471@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35472
35473 static void read_symtabs(FILE *fp)
35474 {
35475- int i,j;
35476+ unsigned int i,j;
35477 for (i = 0; i < ehdr.e_shnum; i++) {
35478 struct section *sec = &secs[i];
35479 if (sec->shdr.sh_type != SHT_SYMTAB) {
35480@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35481 }
35482
35483
35484-static void read_relocs(FILE *fp)
35485+static void read_relocs(FILE *fp, int use_real_mode)
35486 {
35487- int i,j;
35488+ unsigned int i,j;
35489+ uint32_t base;
35490+
35491 for (i = 0; i < ehdr.e_shnum; i++) {
35492 struct section *sec = &secs[i];
35493 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35494@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35495 die("Cannot read symbol table: %s\n",
35496 strerror(errno));
35497 }
35498+ base = 0;
35499+
35500+#ifdef CONFIG_X86_32
35501+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35502+ if (phdr[j].p_type != PT_LOAD )
35503+ continue;
35504+ 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)
35505+ continue;
35506+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35507+ break;
35508+ }
35509+#endif
35510+
35511 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35512 Elf_Rel *rel = &sec->reltab[j];
35513- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35514+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35515 rel->r_info = elf_xword_to_cpu(rel->r_info);
35516 #if (SHT_REL_TYPE == SHT_RELA)
35517 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35518@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35519
35520 static void print_absolute_symbols(void)
35521 {
35522- int i;
35523+ unsigned int i;
35524 const char *format;
35525
35526 if (ELF_BITS == 64)
35527@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35528 for (i = 0; i < ehdr.e_shnum; i++) {
35529 struct section *sec = &secs[i];
35530 char *sym_strtab;
35531- int j;
35532+ unsigned int j;
35533
35534 if (sec->shdr.sh_type != SHT_SYMTAB) {
35535 continue;
35536@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35537
35538 static void print_absolute_relocs(void)
35539 {
35540- int i, printed = 0;
35541+ unsigned int i, printed = 0;
35542 const char *format;
35543
35544 if (ELF_BITS == 64)
35545@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35546 struct section *sec_applies, *sec_symtab;
35547 char *sym_strtab;
35548 Elf_Sym *sh_symtab;
35549- int j;
35550+ unsigned int j;
35551 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35552 continue;
35553 }
35554@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35555 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35556 Elf_Sym *sym, const char *symname))
35557 {
35558- int i;
35559+ unsigned int i;
35560 /* Walk through the relocations */
35561 for (i = 0; i < ehdr.e_shnum; i++) {
35562 char *sym_strtab;
35563 Elf_Sym *sh_symtab;
35564 struct section *sec_applies, *sec_symtab;
35565- int j;
35566+ unsigned int j;
35567 struct section *sec = &secs[i];
35568
35569 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35570@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35571 {
35572 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35573 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35574+ char *sym_strtab = sec->link->link->strtab;
35575+
35576+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35577+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35578+ return 0;
35579+
35580+#ifdef CONFIG_PAX_KERNEXEC
35581+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35582+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35583+ return 0;
35584+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35585+ return 0;
35586+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35587+ return 0;
35588+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35589+ return 0;
35590+#endif
35591
35592 switch (r_type) {
35593 case R_386_NONE:
35594@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35595
35596 static void emit_relocs(int as_text, int use_real_mode)
35597 {
35598- int i;
35599+ unsigned int i;
35600 int (*write_reloc)(uint32_t, FILE *) = write32;
35601 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35602 const char *symname);
35603@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35604 {
35605 regex_init(use_real_mode);
35606 read_ehdr(fp);
35607+ read_phdrs(fp);
35608 read_shdrs(fp);
35609 read_strtabs(fp);
35610 read_symtabs(fp);
35611- read_relocs(fp);
35612+ read_relocs(fp, use_real_mode);
35613 if (ELF_BITS == 64)
35614 percpu_init();
35615 if (show_absolute_syms) {
35616diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35617index 80ffa5b..a33bd15 100644
35618--- a/arch/x86/um/tls_32.c
35619+++ b/arch/x86/um/tls_32.c
35620@@ -260,7 +260,7 @@ out:
35621 if (unlikely(task == current &&
35622 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35623 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35624- "without flushed TLS.", current->pid);
35625+ "without flushed TLS.", task_pid_nr(current));
35626 }
35627
35628 return 0;
35629diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35630index fd14be1..e3c79c0 100644
35631--- a/arch/x86/vdso/Makefile
35632+++ b/arch/x86/vdso/Makefile
35633@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35634 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35635 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35636
35637-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35638+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35639 GCOV_PROFILE := n
35640
35641 #
35642diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35643index d6bfb87..a75c5f7 100644
35644--- a/arch/x86/vdso/vdso32-setup.c
35645+++ b/arch/x86/vdso/vdso32-setup.c
35646@@ -25,6 +25,7 @@
35647 #include <asm/tlbflush.h>
35648 #include <asm/vdso.h>
35649 #include <asm/proto.h>
35650+#include <asm/mman.h>
35651
35652 enum {
35653 VDSO_DISABLED = 0,
35654@@ -41,6 +42,7 @@ enum {
35655 #ifdef CONFIG_X86_64
35656 #define vdso_enabled sysctl_vsyscall32
35657 #define arch_setup_additional_pages syscall32_setup_pages
35658+extern int sysctl_ldt16;
35659 #endif
35660
35661 /*
35662@@ -226,7 +228,7 @@ static inline void map_compat_vdso(int map)
35663 void enable_sep_cpu(void)
35664 {
35665 int cpu = get_cpu();
35666- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35667+ struct tss_struct *tss = init_tss + cpu;
35668
35669 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35670 put_cpu();
35671@@ -249,7 +251,7 @@ static int __init gate_vma_init(void)
35672 gate_vma.vm_start = FIXADDR_USER_START;
35673 gate_vma.vm_end = FIXADDR_USER_END;
35674 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35675- gate_vma.vm_page_prot = __P101;
35676+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35677
35678 return 0;
35679 }
35680@@ -330,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35681 if (compat)
35682 addr = VDSO_HIGH_BASE;
35683 else {
35684- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35685+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35686 if (IS_ERR_VALUE(addr)) {
35687 ret = addr;
35688 goto up_fail;
35689 }
35690 }
35691
35692- current->mm->context.vdso = (void *)addr;
35693+ current->mm->context.vdso = addr;
35694
35695 if (compat_uses_vma || !compat) {
35696 /*
35697@@ -353,11 +355,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35698 }
35699
35700 current_thread_info()->sysenter_return =
35701- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35702+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35703
35704 up_fail:
35705 if (ret)
35706- current->mm->context.vdso = NULL;
35707+ current->mm->context.vdso = 0;
35708
35709 up_write(&mm->mmap_sem);
35710
35711@@ -380,6 +382,13 @@ static struct ctl_table abi_table2[] = {
35712 .mode = 0644,
35713 .proc_handler = proc_dointvec
35714 },
35715+ {
35716+ .procname = "ldt16",
35717+ .data = &sysctl_ldt16,
35718+ .maxlen = sizeof(int),
35719+ .mode = 0644,
35720+ .proc_handler = proc_dointvec
35721+ },
35722 {}
35723 };
35724
35725@@ -404,8 +413,14 @@ __initcall(ia32_binfmt_init);
35726
35727 const char *arch_vma_name(struct vm_area_struct *vma)
35728 {
35729- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35730+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35731 return "[vdso]";
35732+
35733+#ifdef CONFIG_PAX_SEGMEXEC
35734+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35735+ return "[vdso]";
35736+#endif
35737+
35738 return NULL;
35739 }
35740
35741@@ -415,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35742 * Check to see if the corresponding task was created in compat vdso
35743 * mode.
35744 */
35745- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35746+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35747 return &gate_vma;
35748 return NULL;
35749 }
35750diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35751index 431e875..cbb23f3 100644
35752--- a/arch/x86/vdso/vma.c
35753+++ b/arch/x86/vdso/vma.c
35754@@ -16,8 +16,6 @@
35755 #include <asm/vdso.h>
35756 #include <asm/page.h>
35757
35758-unsigned int __read_mostly vdso_enabled = 1;
35759-
35760 extern char vdso_start[], vdso_end[];
35761 extern unsigned short vdso_sync_cpuid;
35762
35763@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35764 * unaligned here as a result of stack start randomization.
35765 */
35766 addr = PAGE_ALIGN(addr);
35767- addr = align_vdso_addr(addr);
35768
35769 return addr;
35770 }
35771@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35772 unsigned size)
35773 {
35774 struct mm_struct *mm = current->mm;
35775- unsigned long addr;
35776+ unsigned long addr = 0;
35777 int ret;
35778
35779- if (!vdso_enabled)
35780- return 0;
35781-
35782 down_write(&mm->mmap_sem);
35783+
35784+#ifdef CONFIG_PAX_RANDMMAP
35785+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35786+#endif
35787+
35788 addr = vdso_addr(mm->start_stack, size);
35789+ addr = align_vdso_addr(addr);
35790 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35791 if (IS_ERR_VALUE(addr)) {
35792 ret = addr;
35793 goto up_fail;
35794 }
35795
35796- current->mm->context.vdso = (void *)addr;
35797+ mm->context.vdso = addr;
35798
35799 ret = install_special_mapping(mm, addr, size,
35800 VM_READ|VM_EXEC|
35801 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35802 pages);
35803- if (ret) {
35804- current->mm->context.vdso = NULL;
35805- goto up_fail;
35806- }
35807+ if (ret)
35808+ mm->context.vdso = 0;
35809
35810 up_fail:
35811 up_write(&mm->mmap_sem);
35812@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35813 vdsox32_size);
35814 }
35815 #endif
35816-
35817-static __init int vdso_setup(char *s)
35818-{
35819- vdso_enabled = simple_strtoul(s, NULL, 0);
35820- return 0;
35821-}
35822-__setup("vdso=", vdso_setup);
35823diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35824index 01b9026..1e476df 100644
35825--- a/arch/x86/xen/Kconfig
35826+++ b/arch/x86/xen/Kconfig
35827@@ -9,6 +9,7 @@ config XEN
35828 select XEN_HAVE_PVMMU
35829 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35830 depends on X86_TSC
35831+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35832 help
35833 This is the Linux Xen port. Enabling this will allow the
35834 kernel to boot in a paravirtualized environment under the
35835diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35836index 201d09a..e4723e5 100644
35837--- a/arch/x86/xen/enlighten.c
35838+++ b/arch/x86/xen/enlighten.c
35839@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35840
35841 struct shared_info xen_dummy_shared_info;
35842
35843-void *xen_initial_gdt;
35844-
35845 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35846 __read_mostly int xen_have_vector_callback;
35847 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35848@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35849 {
35850 unsigned long va = dtr->address;
35851 unsigned int size = dtr->size + 1;
35852- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35853- unsigned long frames[pages];
35854+ unsigned long frames[65536 / PAGE_SIZE];
35855 int f;
35856
35857 /*
35858@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35859 {
35860 unsigned long va = dtr->address;
35861 unsigned int size = dtr->size + 1;
35862- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35863- unsigned long frames[pages];
35864+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35865 int f;
35866
35867 /*
35868@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35869 * 8-byte entries, or 16 4k pages..
35870 */
35871
35872- BUG_ON(size > 65536);
35873+ BUG_ON(size > GDT_SIZE);
35874 BUG_ON(va & ~PAGE_MASK);
35875
35876 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35877@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35878 return 0;
35879 }
35880
35881-static void set_xen_basic_apic_ops(void)
35882+static void __init set_xen_basic_apic_ops(void)
35883 {
35884 apic->read = xen_apic_read;
35885 apic->write = xen_apic_write;
35886@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35887 #endif
35888 };
35889
35890-static void xen_reboot(int reason)
35891+static __noreturn void xen_reboot(int reason)
35892 {
35893 struct sched_shutdown r = { .reason = reason };
35894
35895- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35896- BUG();
35897+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35898+ BUG();
35899 }
35900
35901-static void xen_restart(char *msg)
35902+static __noreturn void xen_restart(char *msg)
35903 {
35904 xen_reboot(SHUTDOWN_reboot);
35905 }
35906
35907-static void xen_emergency_restart(void)
35908+static __noreturn void xen_emergency_restart(void)
35909 {
35910 xen_reboot(SHUTDOWN_reboot);
35911 }
35912
35913-static void xen_machine_halt(void)
35914+static __noreturn void xen_machine_halt(void)
35915 {
35916 xen_reboot(SHUTDOWN_poweroff);
35917 }
35918
35919-static void xen_machine_power_off(void)
35920+static __noreturn void xen_machine_power_off(void)
35921 {
35922 if (pm_power_off)
35923 pm_power_off();
35924@@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
35925 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35926
35927 /* Work out if we support NX */
35928- x86_configure_nx();
35929+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35930+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35931+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35932+ unsigned l, h;
35933+
35934+ __supported_pte_mask |= _PAGE_NX;
35935+ rdmsr(MSR_EFER, l, h);
35936+ l |= EFER_NX;
35937+ wrmsr(MSR_EFER, l, h);
35938+ }
35939+#endif
35940
35941 /* Get mfn list */
35942 xen_build_dynamic_phys_to_machine();
35943@@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
35944
35945 machine_ops = xen_machine_ops;
35946
35947- /*
35948- * The only reliable way to retain the initial address of the
35949- * percpu gdt_page is to remember it here, so we can go and
35950- * mark it RW later, when the initial percpu area is freed.
35951- */
35952- xen_initial_gdt = &per_cpu(gdt_page, 0);
35953-
35954 xen_smp_init();
35955
35956 #ifdef CONFIG_ACPI_NUMA
35957diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35958index 2423ef0..4f6fb5b 100644
35959--- a/arch/x86/xen/mmu.c
35960+++ b/arch/x86/xen/mmu.c
35961@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35962 return val;
35963 }
35964
35965-static pteval_t pte_pfn_to_mfn(pteval_t val)
35966+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35967 {
35968 if (val & _PAGE_PRESENT) {
35969 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35970@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35971 /* L3_k[510] -> level2_kernel_pgt
35972 * L3_i[511] -> level2_fixmap_pgt */
35973 convert_pfn_mfn(level3_kernel_pgt);
35974+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35975+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35976+ convert_pfn_mfn(level3_vmemmap_pgt);
35977 }
35978 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35979 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35980@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35981 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35982 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35983 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35984+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35985+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35986+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35987 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35988 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35989+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35990 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35991 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35992
35993@@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
35994 pv_mmu_ops.set_pud = xen_set_pud;
35995 #if PAGETABLE_LEVELS == 4
35996 pv_mmu_ops.set_pgd = xen_set_pgd;
35997+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35998 #endif
35999
36000 /* This will work as long as patching hasn't happened yet
36001@@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
36002 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
36003 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
36004 .set_pgd = xen_set_pgd_hyper,
36005+ .set_pgd_batched = xen_set_pgd_hyper,
36006
36007 .alloc_pud = xen_alloc_pmd_init,
36008 .release_pud = xen_release_pmd_init,
36009diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
36010index a18eadd..2e2f10e 100644
36011--- a/arch/x86/xen/smp.c
36012+++ b/arch/x86/xen/smp.c
36013@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
36014
36015 if (xen_pv_domain()) {
36016 if (!xen_feature(XENFEAT_writable_page_tables))
36017- /* We've switched to the "real" per-cpu gdt, so make
36018- * sure the old memory can be recycled. */
36019- make_lowmem_page_readwrite(xen_initial_gdt);
36020-
36021 #ifdef CONFIG_X86_32
36022 /*
36023 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
36024 * expects __USER_DS
36025 */
36026- loadsegment(ds, __USER_DS);
36027- loadsegment(es, __USER_DS);
36028+ loadsegment(ds, __KERNEL_DS);
36029+ loadsegment(es, __KERNEL_DS);
36030 #endif
36031
36032 xen_filter_cpu_maps();
36033@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36034 #ifdef CONFIG_X86_32
36035 /* Note: PVH is not yet supported on x86_32. */
36036 ctxt->user_regs.fs = __KERNEL_PERCPU;
36037- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
36038+ savesegment(gs, ctxt->user_regs.gs);
36039 #endif
36040 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
36041
36042@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36043 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
36044 ctxt->flags = VGCF_IN_KERNEL;
36045 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
36046- ctxt->user_regs.ds = __USER_DS;
36047- ctxt->user_regs.es = __USER_DS;
36048+ ctxt->user_regs.ds = __KERNEL_DS;
36049+ ctxt->user_regs.es = __KERNEL_DS;
36050 ctxt->user_regs.ss = __KERNEL_DS;
36051
36052 xen_copy_trap_info(ctxt->trap_ctxt);
36053@@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
36054 int rc;
36055
36056 per_cpu(current_task, cpu) = idle;
36057+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
36058 #ifdef CONFIG_X86_32
36059 irq_ctx_init(cpu);
36060 #else
36061 clear_tsk_thread_flag(idle, TIF_FORK);
36062- per_cpu(kernel_stack, cpu) =
36063- (unsigned long)task_stack_page(idle) -
36064- KERNEL_STACK_OFFSET + THREAD_SIZE;
36065+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36066 #endif
36067 xen_setup_runstate_info(cpu);
36068 xen_setup_timer(cpu);
36069@@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36070
36071 void __init xen_smp_init(void)
36072 {
36073- smp_ops = xen_smp_ops;
36074+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36075 xen_fill_possible_map();
36076 }
36077
36078diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36079index 33ca6e4..0ded929 100644
36080--- a/arch/x86/xen/xen-asm_32.S
36081+++ b/arch/x86/xen/xen-asm_32.S
36082@@ -84,14 +84,14 @@ ENTRY(xen_iret)
36083 ESP_OFFSET=4 # bytes pushed onto stack
36084
36085 /*
36086- * Store vcpu_info pointer for easy access. Do it this way to
36087- * avoid having to reload %fs
36088+ * Store vcpu_info pointer for easy access.
36089 */
36090 #ifdef CONFIG_SMP
36091- GET_THREAD_INFO(%eax)
36092- movl %ss:TI_cpu(%eax), %eax
36093- movl %ss:__per_cpu_offset(,%eax,4), %eax
36094- mov %ss:xen_vcpu(%eax), %eax
36095+ push %fs
36096+ mov $(__KERNEL_PERCPU), %eax
36097+ mov %eax, %fs
36098+ mov PER_CPU_VAR(xen_vcpu), %eax
36099+ pop %fs
36100 #else
36101 movl %ss:xen_vcpu, %eax
36102 #endif
36103diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36104index 485b695..fda3e7c 100644
36105--- a/arch/x86/xen/xen-head.S
36106+++ b/arch/x86/xen/xen-head.S
36107@@ -39,6 +39,17 @@ ENTRY(startup_xen)
36108 #ifdef CONFIG_X86_32
36109 mov %esi,xen_start_info
36110 mov $init_thread_union+THREAD_SIZE,%esp
36111+#ifdef CONFIG_SMP
36112+ movl $cpu_gdt_table,%edi
36113+ movl $__per_cpu_load,%eax
36114+ movw %ax,__KERNEL_PERCPU + 2(%edi)
36115+ rorl $16,%eax
36116+ movb %al,__KERNEL_PERCPU + 4(%edi)
36117+ movb %ah,__KERNEL_PERCPU + 7(%edi)
36118+ movl $__per_cpu_end - 1,%eax
36119+ subl $__per_cpu_start,%eax
36120+ movw %ax,__KERNEL_PERCPU + 0(%edi)
36121+#endif
36122 #else
36123 mov %rsi,xen_start_info
36124 mov $init_thread_union+THREAD_SIZE,%rsp
36125diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36126index 1cb6f4c..9981524 100644
36127--- a/arch/x86/xen/xen-ops.h
36128+++ b/arch/x86/xen/xen-ops.h
36129@@ -10,8 +10,6 @@
36130 extern const char xen_hypervisor_callback[];
36131 extern const char xen_failsafe_callback[];
36132
36133-extern void *xen_initial_gdt;
36134-
36135 struct trap_info;
36136 void xen_copy_trap_info(struct trap_info *traps);
36137
36138diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36139index 525bd3d..ef888b1 100644
36140--- a/arch/xtensa/variants/dc232b/include/variant/core.h
36141+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36142@@ -119,9 +119,9 @@
36143 ----------------------------------------------------------------------*/
36144
36145 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36146-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36147 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36148 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36149+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36150
36151 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36152 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36153diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36154index 2f33760..835e50a 100644
36155--- a/arch/xtensa/variants/fsf/include/variant/core.h
36156+++ b/arch/xtensa/variants/fsf/include/variant/core.h
36157@@ -11,6 +11,7 @@
36158 #ifndef _XTENSA_CORE_H
36159 #define _XTENSA_CORE_H
36160
36161+#include <linux/const.h>
36162
36163 /****************************************************************************
36164 Parameters Useful for Any Code, USER or PRIVILEGED
36165@@ -112,9 +113,9 @@
36166 ----------------------------------------------------------------------*/
36167
36168 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36169-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36170 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36171 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36172+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36173
36174 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36175 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36176diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36177index af00795..2bb8105 100644
36178--- a/arch/xtensa/variants/s6000/include/variant/core.h
36179+++ b/arch/xtensa/variants/s6000/include/variant/core.h
36180@@ -11,6 +11,7 @@
36181 #ifndef _XTENSA_CORE_CONFIGURATION_H
36182 #define _XTENSA_CORE_CONFIGURATION_H
36183
36184+#include <linux/const.h>
36185
36186 /****************************************************************************
36187 Parameters Useful for Any Code, USER or PRIVILEGED
36188@@ -118,9 +119,9 @@
36189 ----------------------------------------------------------------------*/
36190
36191 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36192-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36193 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36194 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36195+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36196
36197 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36198 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36199diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
36200index 4e491d9..c8e18e4 100644
36201--- a/block/blk-cgroup.c
36202+++ b/block/blk-cgroup.c
36203@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
36204 static struct cgroup_subsys_state *
36205 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36206 {
36207- static atomic64_t id_seq = ATOMIC64_INIT(0);
36208+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
36209 struct blkcg *blkcg;
36210
36211 if (!parent_css) {
36212@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36213
36214 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
36215 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
36216- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
36217+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
36218 done:
36219 spin_lock_init(&blkcg->lock);
36220 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
36221diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36222index 1855bf5..af12b06 100644
36223--- a/block/blk-iopoll.c
36224+++ b/block/blk-iopoll.c
36225@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
36226 }
36227 EXPORT_SYMBOL(blk_iopoll_complete);
36228
36229-static void blk_iopoll_softirq(struct softirq_action *h)
36230+static __latent_entropy void blk_iopoll_softirq(void)
36231 {
36232 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36233 int rearm = 0, budget = blk_iopoll_budget;
36234diff --git a/block/blk-map.c b/block/blk-map.c
36235index ae4ae10..c470b8d 100644
36236--- a/block/blk-map.c
36237+++ b/block/blk-map.c
36238@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36239 if (!len || !kbuf)
36240 return -EINVAL;
36241
36242- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36243+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36244 if (do_copy)
36245 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36246 else
36247diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36248index 57790c1..5e988dd 100644
36249--- a/block/blk-softirq.c
36250+++ b/block/blk-softirq.c
36251@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36252 * Softirq action handler - move entries to local list and loop over them
36253 * while passing them to the queue registered handler.
36254 */
36255-static void blk_done_softirq(struct softirq_action *h)
36256+static __latent_entropy void blk_done_softirq(void)
36257 {
36258 struct list_head *cpu_list, local_list;
36259
36260diff --git a/block/bsg.c b/block/bsg.c
36261index 420a5a9..23834aa 100644
36262--- a/block/bsg.c
36263+++ b/block/bsg.c
36264@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36265 struct sg_io_v4 *hdr, struct bsg_device *bd,
36266 fmode_t has_write_perm)
36267 {
36268+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36269+ unsigned char *cmdptr;
36270+
36271 if (hdr->request_len > BLK_MAX_CDB) {
36272 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36273 if (!rq->cmd)
36274 return -ENOMEM;
36275- }
36276+ cmdptr = rq->cmd;
36277+ } else
36278+ cmdptr = tmpcmd;
36279
36280- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36281+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36282 hdr->request_len))
36283 return -EFAULT;
36284
36285+ if (cmdptr != rq->cmd)
36286+ memcpy(rq->cmd, cmdptr, hdr->request_len);
36287+
36288 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36289 if (blk_verify_command(rq->cmd, has_write_perm))
36290 return -EPERM;
36291diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36292index fbd5a67..f24fd95 100644
36293--- a/block/compat_ioctl.c
36294+++ b/block/compat_ioctl.c
36295@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36296 cgc = compat_alloc_user_space(sizeof(*cgc));
36297 cgc32 = compat_ptr(arg);
36298
36299- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36300+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36301 get_user(data, &cgc32->buffer) ||
36302 put_user(compat_ptr(data), &cgc->buffer) ||
36303 copy_in_user(&cgc->buflen, &cgc32->buflen,
36304@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36305 err |= __get_user(f->spec1, &uf->spec1);
36306 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36307 err |= __get_user(name, &uf->name);
36308- f->name = compat_ptr(name);
36309+ f->name = (void __force_kernel *)compat_ptr(name);
36310 if (err) {
36311 err = -EFAULT;
36312 goto out;
36313diff --git a/block/genhd.c b/block/genhd.c
36314index 791f419..89f21c4 100644
36315--- a/block/genhd.c
36316+++ b/block/genhd.c
36317@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36318
36319 /*
36320 * Register device numbers dev..(dev+range-1)
36321- * range must be nonzero
36322+ * Noop if @range is zero.
36323 * The hash chain is sorted on range, so that subranges can override.
36324 */
36325 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36326 struct kobject *(*probe)(dev_t, int *, void *),
36327 int (*lock)(dev_t, void *), void *data)
36328 {
36329- kobj_map(bdev_map, devt, range, module, probe, lock, data);
36330+ if (range)
36331+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
36332 }
36333
36334 EXPORT_SYMBOL(blk_register_region);
36335
36336+/* undo blk_register_region(), noop if @range is zero */
36337 void blk_unregister_region(dev_t devt, unsigned long range)
36338 {
36339- kobj_unmap(bdev_map, devt, range);
36340+ if (range)
36341+ kobj_unmap(bdev_map, devt, range);
36342 }
36343
36344 EXPORT_SYMBOL(blk_unregister_region);
36345diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36346index dc51f46..d5446a8 100644
36347--- a/block/partitions/efi.c
36348+++ b/block/partitions/efi.c
36349@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36350 if (!gpt)
36351 return NULL;
36352
36353+ if (!le32_to_cpu(gpt->num_partition_entries))
36354+ return NULL;
36355+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36356+ if (!pte)
36357+ return NULL;
36358+
36359 count = le32_to_cpu(gpt->num_partition_entries) *
36360 le32_to_cpu(gpt->sizeof_partition_entry);
36361- if (!count)
36362- return NULL;
36363- pte = kmalloc(count, GFP_KERNEL);
36364- if (!pte)
36365- return NULL;
36366-
36367 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36368 (u8 *) pte, count) < count) {
36369 kfree(pte);
36370diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36371index 2648797..92ed21f 100644
36372--- a/block/scsi_ioctl.c
36373+++ b/block/scsi_ioctl.c
36374@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36375 return put_user(0, p);
36376 }
36377
36378-static int sg_get_timeout(struct request_queue *q)
36379+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36380 {
36381 return jiffies_to_clock_t(q->sg_timeout);
36382 }
36383@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36384 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36385 struct sg_io_hdr *hdr, fmode_t mode)
36386 {
36387- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36388+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36389+ unsigned char *cmdptr;
36390+
36391+ if (rq->cmd != rq->__cmd)
36392+ cmdptr = rq->cmd;
36393+ else
36394+ cmdptr = tmpcmd;
36395+
36396+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36397 return -EFAULT;
36398+
36399+ if (cmdptr != rq->cmd)
36400+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36401+
36402 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36403 return -EPERM;
36404
36405@@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36406 int err;
36407 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36408 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36409+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36410+ unsigned char *cmdptr;
36411
36412 if (!sic)
36413 return -EINVAL;
36414@@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36415 */
36416 err = -EFAULT;
36417 rq->cmd_len = cmdlen;
36418- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36419+
36420+ if (rq->cmd != rq->__cmd)
36421+ cmdptr = rq->cmd;
36422+ else
36423+ cmdptr = tmpcmd;
36424+
36425+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36426 goto error;
36427
36428+ if (rq->cmd != cmdptr)
36429+ memcpy(rq->cmd, cmdptr, cmdlen);
36430+
36431 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36432 goto error;
36433
36434diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36435index 7bdd61b..afec999 100644
36436--- a/crypto/cryptd.c
36437+++ b/crypto/cryptd.c
36438@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36439
36440 struct cryptd_blkcipher_request_ctx {
36441 crypto_completion_t complete;
36442-};
36443+} __no_const;
36444
36445 struct cryptd_hash_ctx {
36446 struct crypto_shash *child;
36447@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36448
36449 struct cryptd_aead_request_ctx {
36450 crypto_completion_t complete;
36451-};
36452+} __no_const;
36453
36454 static void cryptd_queue_worker(struct work_struct *work);
36455
36456diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36457index 309d345..1632720 100644
36458--- a/crypto/pcrypt.c
36459+++ b/crypto/pcrypt.c
36460@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36461 int ret;
36462
36463 pinst->kobj.kset = pcrypt_kset;
36464- ret = kobject_add(&pinst->kobj, NULL, name);
36465+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36466 if (!ret)
36467 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36468
36469diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36470index 15dddc1..b61cf0c 100644
36471--- a/drivers/acpi/acpica/hwxfsleep.c
36472+++ b/drivers/acpi/acpica/hwxfsleep.c
36473@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36474 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36475
36476 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36477- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36478- acpi_hw_extended_sleep},
36479- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36480- acpi_hw_extended_wake_prep},
36481- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36482+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36483+ .extended_function = acpi_hw_extended_sleep},
36484+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36485+ .extended_function = acpi_hw_extended_wake_prep},
36486+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36487+ .extended_function = acpi_hw_extended_wake}
36488 };
36489
36490 /*
36491diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36492index e5bcd91..74f050d 100644
36493--- a/drivers/acpi/apei/apei-internal.h
36494+++ b/drivers/acpi/apei/apei-internal.h
36495@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36496 struct apei_exec_ins_type {
36497 u32 flags;
36498 apei_exec_ins_func_t run;
36499-};
36500+} __do_const;
36501
36502 struct apei_exec_context {
36503 u32 ip;
36504diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36505index dab7cb7..f0d2994 100644
36506--- a/drivers/acpi/apei/ghes.c
36507+++ b/drivers/acpi/apei/ghes.c
36508@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36509 const struct acpi_hest_generic *generic,
36510 const struct acpi_generic_status *estatus)
36511 {
36512- static atomic_t seqno;
36513+ static atomic_unchecked_t seqno;
36514 unsigned int curr_seqno;
36515 char pfx_seq[64];
36516
36517@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36518 else
36519 pfx = KERN_ERR;
36520 }
36521- curr_seqno = atomic_inc_return(&seqno);
36522+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36523 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36524 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36525 pfx_seq, generic->header.source_id);
36526diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36527index a83e3c6..c3d617f 100644
36528--- a/drivers/acpi/bgrt.c
36529+++ b/drivers/acpi/bgrt.c
36530@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36531 if (!bgrt_image)
36532 return -ENODEV;
36533
36534- bin_attr_image.private = bgrt_image;
36535- bin_attr_image.size = bgrt_image_size;
36536+ pax_open_kernel();
36537+ *(void **)&bin_attr_image.private = bgrt_image;
36538+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36539+ pax_close_kernel();
36540
36541 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36542 if (!bgrt_kobj)
36543diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36544index afec452..c5d8b96 100644
36545--- a/drivers/acpi/blacklist.c
36546+++ b/drivers/acpi/blacklist.c
36547@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36548 u32 is_critical_error;
36549 };
36550
36551-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36552+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36553
36554 /*
36555 * POLICY: If *anything* doesn't work, put it on the blacklist.
36556@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36557 return 0;
36558 }
36559
36560-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36561+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36562 {
36563 .callback = dmi_disable_osi_vista,
36564 .ident = "Fujitsu Siemens",
36565diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36566index c68e724..e863008 100644
36567--- a/drivers/acpi/custom_method.c
36568+++ b/drivers/acpi/custom_method.c
36569@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36570 struct acpi_table_header table;
36571 acpi_status status;
36572
36573+#ifdef CONFIG_GRKERNSEC_KMEM
36574+ return -EPERM;
36575+#endif
36576+
36577 if (!(*ppos)) {
36578 /* parse the table header to get the table length */
36579 if (count <= sizeof(struct acpi_table_header))
36580diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36581index 3dca36d..abaf070 100644
36582--- a/drivers/acpi/processor_idle.c
36583+++ b/drivers/acpi/processor_idle.c
36584@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36585 {
36586 int i, count = CPUIDLE_DRIVER_STATE_START;
36587 struct acpi_processor_cx *cx;
36588- struct cpuidle_state *state;
36589+ cpuidle_state_no_const *state;
36590 struct cpuidle_driver *drv = &acpi_idle_driver;
36591
36592 if (!pr->flags.power_setup_done)
36593diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36594index 91a32ce..d77fcaf 100644
36595--- a/drivers/acpi/sysfs.c
36596+++ b/drivers/acpi/sysfs.c
36597@@ -425,11 +425,11 @@ static u32 num_counters;
36598 static struct attribute **all_attrs;
36599 static u32 acpi_gpe_count;
36600
36601-static struct attribute_group interrupt_stats_attr_group = {
36602+static attribute_group_no_const interrupt_stats_attr_group = {
36603 .name = "interrupts",
36604 };
36605
36606-static struct kobj_attribute *counter_attrs;
36607+static kobj_attribute_no_const *counter_attrs;
36608
36609 static void delete_gpe_attr_array(void)
36610 {
36611diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36612index 36605ab..6ef6d4b 100644
36613--- a/drivers/ata/libahci.c
36614+++ b/drivers/ata/libahci.c
36615@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36616 }
36617 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36618
36619-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36620+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36621 struct ata_taskfile *tf, int is_cmd, u16 flags,
36622 unsigned long timeout_msec)
36623 {
36624diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36625index 0a79c54..c1b92ed 100644
36626--- a/drivers/ata/libata-core.c
36627+++ b/drivers/ata/libata-core.c
36628@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36629 static void ata_dev_xfermask(struct ata_device *dev);
36630 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36631
36632-atomic_t ata_print_id = ATOMIC_INIT(0);
36633+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36634
36635 struct ata_force_param {
36636 const char *name;
36637@@ -4858,7 +4858,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36638 struct ata_port *ap;
36639 unsigned int tag;
36640
36641- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36642+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36643 ap = qc->ap;
36644
36645 qc->flags = 0;
36646@@ -4874,7 +4874,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36647 struct ata_port *ap;
36648 struct ata_link *link;
36649
36650- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36651+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36652 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36653 ap = qc->ap;
36654 link = qc->dev->link;
36655@@ -5993,6 +5993,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36656 return;
36657
36658 spin_lock(&lock);
36659+ pax_open_kernel();
36660
36661 for (cur = ops->inherits; cur; cur = cur->inherits) {
36662 void **inherit = (void **)cur;
36663@@ -6006,8 +6007,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36664 if (IS_ERR(*pp))
36665 *pp = NULL;
36666
36667- ops->inherits = NULL;
36668+ *(struct ata_port_operations **)&ops->inherits = NULL;
36669
36670+ pax_close_kernel();
36671 spin_unlock(&lock);
36672 }
36673
36674@@ -6200,7 +6202,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36675
36676 /* give ports names and add SCSI hosts */
36677 for (i = 0; i < host->n_ports; i++) {
36678- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36679+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36680 host->ports[i]->local_port_no = i + 1;
36681 }
36682
36683diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36684index ef8567d..8bdbd03 100644
36685--- a/drivers/ata/libata-scsi.c
36686+++ b/drivers/ata/libata-scsi.c
36687@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36688
36689 if (rc)
36690 return rc;
36691- ap->print_id = atomic_inc_return(&ata_print_id);
36692+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36693 return 0;
36694 }
36695 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36696diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36697index 45b5ab3..98446b8 100644
36698--- a/drivers/ata/libata.h
36699+++ b/drivers/ata/libata.h
36700@@ -53,7 +53,7 @@ enum {
36701 ATA_DNXFER_QUIET = (1 << 31),
36702 };
36703
36704-extern atomic_t ata_print_id;
36705+extern atomic_unchecked_t ata_print_id;
36706 extern int atapi_passthru16;
36707 extern int libata_fua;
36708 extern int libata_noacpi;
36709diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36710index 73492dd..ca2bff5 100644
36711--- a/drivers/ata/pata_arasan_cf.c
36712+++ b/drivers/ata/pata_arasan_cf.c
36713@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36714 /* Handle platform specific quirks */
36715 if (quirk) {
36716 if (quirk & CF_BROKEN_PIO) {
36717- ap->ops->set_piomode = NULL;
36718+ pax_open_kernel();
36719+ *(void **)&ap->ops->set_piomode = NULL;
36720+ pax_close_kernel();
36721 ap->pio_mask = 0;
36722 }
36723 if (quirk & CF_BROKEN_MWDMA)
36724diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36725index f9b983a..887b9d8 100644
36726--- a/drivers/atm/adummy.c
36727+++ b/drivers/atm/adummy.c
36728@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36729 vcc->pop(vcc, skb);
36730 else
36731 dev_kfree_skb_any(skb);
36732- atomic_inc(&vcc->stats->tx);
36733+ atomic_inc_unchecked(&vcc->stats->tx);
36734
36735 return 0;
36736 }
36737diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36738index 62a7607..cc4be104 100644
36739--- a/drivers/atm/ambassador.c
36740+++ b/drivers/atm/ambassador.c
36741@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36742 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36743
36744 // VC layer stats
36745- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36746+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36747
36748 // free the descriptor
36749 kfree (tx_descr);
36750@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36751 dump_skb ("<<<", vc, skb);
36752
36753 // VC layer stats
36754- atomic_inc(&atm_vcc->stats->rx);
36755+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36756 __net_timestamp(skb);
36757 // end of our responsibility
36758 atm_vcc->push (atm_vcc, skb);
36759@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36760 } else {
36761 PRINTK (KERN_INFO, "dropped over-size frame");
36762 // should we count this?
36763- atomic_inc(&atm_vcc->stats->rx_drop);
36764+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36765 }
36766
36767 } else {
36768@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36769 }
36770
36771 if (check_area (skb->data, skb->len)) {
36772- atomic_inc(&atm_vcc->stats->tx_err);
36773+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36774 return -ENOMEM; // ?
36775 }
36776
36777diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36778index 0e3f8f9..765a7a5 100644
36779--- a/drivers/atm/atmtcp.c
36780+++ b/drivers/atm/atmtcp.c
36781@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36782 if (vcc->pop) vcc->pop(vcc,skb);
36783 else dev_kfree_skb(skb);
36784 if (dev_data) return 0;
36785- atomic_inc(&vcc->stats->tx_err);
36786+ atomic_inc_unchecked(&vcc->stats->tx_err);
36787 return -ENOLINK;
36788 }
36789 size = skb->len+sizeof(struct atmtcp_hdr);
36790@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36791 if (!new_skb) {
36792 if (vcc->pop) vcc->pop(vcc,skb);
36793 else dev_kfree_skb(skb);
36794- atomic_inc(&vcc->stats->tx_err);
36795+ atomic_inc_unchecked(&vcc->stats->tx_err);
36796 return -ENOBUFS;
36797 }
36798 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36799@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36800 if (vcc->pop) vcc->pop(vcc,skb);
36801 else dev_kfree_skb(skb);
36802 out_vcc->push(out_vcc,new_skb);
36803- atomic_inc(&vcc->stats->tx);
36804- atomic_inc(&out_vcc->stats->rx);
36805+ atomic_inc_unchecked(&vcc->stats->tx);
36806+ atomic_inc_unchecked(&out_vcc->stats->rx);
36807 return 0;
36808 }
36809
36810@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36811 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36812 read_unlock(&vcc_sklist_lock);
36813 if (!out_vcc) {
36814- atomic_inc(&vcc->stats->tx_err);
36815+ atomic_inc_unchecked(&vcc->stats->tx_err);
36816 goto done;
36817 }
36818 skb_pull(skb,sizeof(struct atmtcp_hdr));
36819@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36820 __net_timestamp(new_skb);
36821 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36822 out_vcc->push(out_vcc,new_skb);
36823- atomic_inc(&vcc->stats->tx);
36824- atomic_inc(&out_vcc->stats->rx);
36825+ atomic_inc_unchecked(&vcc->stats->tx);
36826+ atomic_inc_unchecked(&out_vcc->stats->rx);
36827 done:
36828 if (vcc->pop) vcc->pop(vcc,skb);
36829 else dev_kfree_skb(skb);
36830diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36831index b1955ba..b179940 100644
36832--- a/drivers/atm/eni.c
36833+++ b/drivers/atm/eni.c
36834@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36835 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36836 vcc->dev->number);
36837 length = 0;
36838- atomic_inc(&vcc->stats->rx_err);
36839+ atomic_inc_unchecked(&vcc->stats->rx_err);
36840 }
36841 else {
36842 length = ATM_CELL_SIZE-1; /* no HEC */
36843@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36844 size);
36845 }
36846 eff = length = 0;
36847- atomic_inc(&vcc->stats->rx_err);
36848+ atomic_inc_unchecked(&vcc->stats->rx_err);
36849 }
36850 else {
36851 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36852@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36853 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36854 vcc->dev->number,vcc->vci,length,size << 2,descr);
36855 length = eff = 0;
36856- atomic_inc(&vcc->stats->rx_err);
36857+ atomic_inc_unchecked(&vcc->stats->rx_err);
36858 }
36859 }
36860 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36861@@ -767,7 +767,7 @@ rx_dequeued++;
36862 vcc->push(vcc,skb);
36863 pushed++;
36864 }
36865- atomic_inc(&vcc->stats->rx);
36866+ atomic_inc_unchecked(&vcc->stats->rx);
36867 }
36868 wake_up(&eni_dev->rx_wait);
36869 }
36870@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36871 PCI_DMA_TODEVICE);
36872 if (vcc->pop) vcc->pop(vcc,skb);
36873 else dev_kfree_skb_irq(skb);
36874- atomic_inc(&vcc->stats->tx);
36875+ atomic_inc_unchecked(&vcc->stats->tx);
36876 wake_up(&eni_dev->tx_wait);
36877 dma_complete++;
36878 }
36879diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36880index b41c948..a002b17 100644
36881--- a/drivers/atm/firestream.c
36882+++ b/drivers/atm/firestream.c
36883@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36884 }
36885 }
36886
36887- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36888+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36889
36890 fs_dprintk (FS_DEBUG_TXMEM, "i");
36891 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36892@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36893 #endif
36894 skb_put (skb, qe->p1 & 0xffff);
36895 ATM_SKB(skb)->vcc = atm_vcc;
36896- atomic_inc(&atm_vcc->stats->rx);
36897+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36898 __net_timestamp(skb);
36899 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36900 atm_vcc->push (atm_vcc, skb);
36901@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36902 kfree (pe);
36903 }
36904 if (atm_vcc)
36905- atomic_inc(&atm_vcc->stats->rx_drop);
36906+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36907 break;
36908 case 0x1f: /* Reassembly abort: no buffers. */
36909 /* Silently increment error counter. */
36910 if (atm_vcc)
36911- atomic_inc(&atm_vcc->stats->rx_drop);
36912+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36913 break;
36914 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36915 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36916diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36917index 204814e..cede831 100644
36918--- a/drivers/atm/fore200e.c
36919+++ b/drivers/atm/fore200e.c
36920@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36921 #endif
36922 /* check error condition */
36923 if (*entry->status & STATUS_ERROR)
36924- atomic_inc(&vcc->stats->tx_err);
36925+ atomic_inc_unchecked(&vcc->stats->tx_err);
36926 else
36927- atomic_inc(&vcc->stats->tx);
36928+ atomic_inc_unchecked(&vcc->stats->tx);
36929 }
36930 }
36931
36932@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36933 if (skb == NULL) {
36934 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36935
36936- atomic_inc(&vcc->stats->rx_drop);
36937+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36938 return -ENOMEM;
36939 }
36940
36941@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36942
36943 dev_kfree_skb_any(skb);
36944
36945- atomic_inc(&vcc->stats->rx_drop);
36946+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36947 return -ENOMEM;
36948 }
36949
36950 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36951
36952 vcc->push(vcc, skb);
36953- atomic_inc(&vcc->stats->rx);
36954+ atomic_inc_unchecked(&vcc->stats->rx);
36955
36956 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36957
36958@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36959 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36960 fore200e->atm_dev->number,
36961 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36962- atomic_inc(&vcc->stats->rx_err);
36963+ atomic_inc_unchecked(&vcc->stats->rx_err);
36964 }
36965 }
36966
36967@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36968 goto retry_here;
36969 }
36970
36971- atomic_inc(&vcc->stats->tx_err);
36972+ atomic_inc_unchecked(&vcc->stats->tx_err);
36973
36974 fore200e->tx_sat++;
36975 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36976diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36977index aa6be26..f70a785 100644
36978--- a/drivers/atm/he.c
36979+++ b/drivers/atm/he.c
36980@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36981
36982 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36983 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36984- atomic_inc(&vcc->stats->rx_drop);
36985+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36986 goto return_host_buffers;
36987 }
36988
36989@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36990 RBRQ_LEN_ERR(he_dev->rbrq_head)
36991 ? "LEN_ERR" : "",
36992 vcc->vpi, vcc->vci);
36993- atomic_inc(&vcc->stats->rx_err);
36994+ atomic_inc_unchecked(&vcc->stats->rx_err);
36995 goto return_host_buffers;
36996 }
36997
36998@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36999 vcc->push(vcc, skb);
37000 spin_lock(&he_dev->global_lock);
37001
37002- atomic_inc(&vcc->stats->rx);
37003+ atomic_inc_unchecked(&vcc->stats->rx);
37004
37005 return_host_buffers:
37006 ++pdus_assembled;
37007@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
37008 tpd->vcc->pop(tpd->vcc, tpd->skb);
37009 else
37010 dev_kfree_skb_any(tpd->skb);
37011- atomic_inc(&tpd->vcc->stats->tx_err);
37012+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
37013 }
37014 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
37015 return;
37016@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37017 vcc->pop(vcc, skb);
37018 else
37019 dev_kfree_skb_any(skb);
37020- atomic_inc(&vcc->stats->tx_err);
37021+ atomic_inc_unchecked(&vcc->stats->tx_err);
37022 return -EINVAL;
37023 }
37024
37025@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37026 vcc->pop(vcc, skb);
37027 else
37028 dev_kfree_skb_any(skb);
37029- atomic_inc(&vcc->stats->tx_err);
37030+ atomic_inc_unchecked(&vcc->stats->tx_err);
37031 return -EINVAL;
37032 }
37033 #endif
37034@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37035 vcc->pop(vcc, skb);
37036 else
37037 dev_kfree_skb_any(skb);
37038- atomic_inc(&vcc->stats->tx_err);
37039+ atomic_inc_unchecked(&vcc->stats->tx_err);
37040 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37041 return -ENOMEM;
37042 }
37043@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37044 vcc->pop(vcc, skb);
37045 else
37046 dev_kfree_skb_any(skb);
37047- atomic_inc(&vcc->stats->tx_err);
37048+ atomic_inc_unchecked(&vcc->stats->tx_err);
37049 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37050 return -ENOMEM;
37051 }
37052@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37053 __enqueue_tpd(he_dev, tpd, cid);
37054 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37055
37056- atomic_inc(&vcc->stats->tx);
37057+ atomic_inc_unchecked(&vcc->stats->tx);
37058
37059 return 0;
37060 }
37061diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
37062index 1dc0519..1aadaf7 100644
37063--- a/drivers/atm/horizon.c
37064+++ b/drivers/atm/horizon.c
37065@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
37066 {
37067 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
37068 // VC layer stats
37069- atomic_inc(&vcc->stats->rx);
37070+ atomic_inc_unchecked(&vcc->stats->rx);
37071 __net_timestamp(skb);
37072 // end of our responsibility
37073 vcc->push (vcc, skb);
37074@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
37075 dev->tx_iovec = NULL;
37076
37077 // VC layer stats
37078- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37079+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37080
37081 // free the skb
37082 hrz_kfree_skb (skb);
37083diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
37084index 1bdf104..9dc44b1 100644
37085--- a/drivers/atm/idt77252.c
37086+++ b/drivers/atm/idt77252.c
37087@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
37088 else
37089 dev_kfree_skb(skb);
37090
37091- atomic_inc(&vcc->stats->tx);
37092+ atomic_inc_unchecked(&vcc->stats->tx);
37093 }
37094
37095 atomic_dec(&scq->used);
37096@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37097 if ((sb = dev_alloc_skb(64)) == NULL) {
37098 printk("%s: Can't allocate buffers for aal0.\n",
37099 card->name);
37100- atomic_add(i, &vcc->stats->rx_drop);
37101+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37102 break;
37103 }
37104 if (!atm_charge(vcc, sb->truesize)) {
37105 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37106 card->name);
37107- atomic_add(i - 1, &vcc->stats->rx_drop);
37108+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37109 dev_kfree_skb(sb);
37110 break;
37111 }
37112@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37113 ATM_SKB(sb)->vcc = vcc;
37114 __net_timestamp(sb);
37115 vcc->push(vcc, sb);
37116- atomic_inc(&vcc->stats->rx);
37117+ atomic_inc_unchecked(&vcc->stats->rx);
37118
37119 cell += ATM_CELL_PAYLOAD;
37120 }
37121@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37122 "(CDC: %08x)\n",
37123 card->name, len, rpp->len, readl(SAR_REG_CDC));
37124 recycle_rx_pool_skb(card, rpp);
37125- atomic_inc(&vcc->stats->rx_err);
37126+ atomic_inc_unchecked(&vcc->stats->rx_err);
37127 return;
37128 }
37129 if (stat & SAR_RSQE_CRC) {
37130 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37131 recycle_rx_pool_skb(card, rpp);
37132- atomic_inc(&vcc->stats->rx_err);
37133+ atomic_inc_unchecked(&vcc->stats->rx_err);
37134 return;
37135 }
37136 if (skb_queue_len(&rpp->queue) > 1) {
37137@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37138 RXPRINTK("%s: Can't alloc RX skb.\n",
37139 card->name);
37140 recycle_rx_pool_skb(card, rpp);
37141- atomic_inc(&vcc->stats->rx_err);
37142+ atomic_inc_unchecked(&vcc->stats->rx_err);
37143 return;
37144 }
37145 if (!atm_charge(vcc, skb->truesize)) {
37146@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37147 __net_timestamp(skb);
37148
37149 vcc->push(vcc, skb);
37150- atomic_inc(&vcc->stats->rx);
37151+ atomic_inc_unchecked(&vcc->stats->rx);
37152
37153 return;
37154 }
37155@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37156 __net_timestamp(skb);
37157
37158 vcc->push(vcc, skb);
37159- atomic_inc(&vcc->stats->rx);
37160+ atomic_inc_unchecked(&vcc->stats->rx);
37161
37162 if (skb->truesize > SAR_FB_SIZE_3)
37163 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37164@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37165 if (vcc->qos.aal != ATM_AAL0) {
37166 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37167 card->name, vpi, vci);
37168- atomic_inc(&vcc->stats->rx_drop);
37169+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37170 goto drop;
37171 }
37172
37173 if ((sb = dev_alloc_skb(64)) == NULL) {
37174 printk("%s: Can't allocate buffers for AAL0.\n",
37175 card->name);
37176- atomic_inc(&vcc->stats->rx_err);
37177+ atomic_inc_unchecked(&vcc->stats->rx_err);
37178 goto drop;
37179 }
37180
37181@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37182 ATM_SKB(sb)->vcc = vcc;
37183 __net_timestamp(sb);
37184 vcc->push(vcc, sb);
37185- atomic_inc(&vcc->stats->rx);
37186+ atomic_inc_unchecked(&vcc->stats->rx);
37187
37188 drop:
37189 skb_pull(queue, 64);
37190@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37191
37192 if (vc == NULL) {
37193 printk("%s: NULL connection in send().\n", card->name);
37194- atomic_inc(&vcc->stats->tx_err);
37195+ atomic_inc_unchecked(&vcc->stats->tx_err);
37196 dev_kfree_skb(skb);
37197 return -EINVAL;
37198 }
37199 if (!test_bit(VCF_TX, &vc->flags)) {
37200 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37201- atomic_inc(&vcc->stats->tx_err);
37202+ atomic_inc_unchecked(&vcc->stats->tx_err);
37203 dev_kfree_skb(skb);
37204 return -EINVAL;
37205 }
37206@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37207 break;
37208 default:
37209 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37210- atomic_inc(&vcc->stats->tx_err);
37211+ atomic_inc_unchecked(&vcc->stats->tx_err);
37212 dev_kfree_skb(skb);
37213 return -EINVAL;
37214 }
37215
37216 if (skb_shinfo(skb)->nr_frags != 0) {
37217 printk("%s: No scatter-gather yet.\n", card->name);
37218- atomic_inc(&vcc->stats->tx_err);
37219+ atomic_inc_unchecked(&vcc->stats->tx_err);
37220 dev_kfree_skb(skb);
37221 return -EINVAL;
37222 }
37223@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37224
37225 err = queue_skb(card, vc, skb, oam);
37226 if (err) {
37227- atomic_inc(&vcc->stats->tx_err);
37228+ atomic_inc_unchecked(&vcc->stats->tx_err);
37229 dev_kfree_skb(skb);
37230 return err;
37231 }
37232@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37233 skb = dev_alloc_skb(64);
37234 if (!skb) {
37235 printk("%s: Out of memory in send_oam().\n", card->name);
37236- atomic_inc(&vcc->stats->tx_err);
37237+ atomic_inc_unchecked(&vcc->stats->tx_err);
37238 return -ENOMEM;
37239 }
37240 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37241diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37242index 4217f29..88f547a 100644
37243--- a/drivers/atm/iphase.c
37244+++ b/drivers/atm/iphase.c
37245@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37246 status = (u_short) (buf_desc_ptr->desc_mode);
37247 if (status & (RX_CER | RX_PTE | RX_OFL))
37248 {
37249- atomic_inc(&vcc->stats->rx_err);
37250+ atomic_inc_unchecked(&vcc->stats->rx_err);
37251 IF_ERR(printk("IA: bad packet, dropping it");)
37252 if (status & RX_CER) {
37253 IF_ERR(printk(" cause: packet CRC error\n");)
37254@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37255 len = dma_addr - buf_addr;
37256 if (len > iadev->rx_buf_sz) {
37257 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37258- atomic_inc(&vcc->stats->rx_err);
37259+ atomic_inc_unchecked(&vcc->stats->rx_err);
37260 goto out_free_desc;
37261 }
37262
37263@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37264 ia_vcc = INPH_IA_VCC(vcc);
37265 if (ia_vcc == NULL)
37266 {
37267- atomic_inc(&vcc->stats->rx_err);
37268+ atomic_inc_unchecked(&vcc->stats->rx_err);
37269 atm_return(vcc, skb->truesize);
37270 dev_kfree_skb_any(skb);
37271 goto INCR_DLE;
37272@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37273 if ((length > iadev->rx_buf_sz) || (length >
37274 (skb->len - sizeof(struct cpcs_trailer))))
37275 {
37276- atomic_inc(&vcc->stats->rx_err);
37277+ atomic_inc_unchecked(&vcc->stats->rx_err);
37278 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37279 length, skb->len);)
37280 atm_return(vcc, skb->truesize);
37281@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37282
37283 IF_RX(printk("rx_dle_intr: skb push");)
37284 vcc->push(vcc,skb);
37285- atomic_inc(&vcc->stats->rx);
37286+ atomic_inc_unchecked(&vcc->stats->rx);
37287 iadev->rx_pkt_cnt++;
37288 }
37289 INCR_DLE:
37290@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37291 {
37292 struct k_sonet_stats *stats;
37293 stats = &PRIV(_ia_dev[board])->sonet_stats;
37294- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37295- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37296- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37297- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37298- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37299- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37300- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37301- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37302- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37303+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37304+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37305+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37306+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37307+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37308+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37309+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37310+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37311+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37312 }
37313 ia_cmds.status = 0;
37314 break;
37315@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37316 if ((desc == 0) || (desc > iadev->num_tx_desc))
37317 {
37318 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37319- atomic_inc(&vcc->stats->tx);
37320+ atomic_inc_unchecked(&vcc->stats->tx);
37321 if (vcc->pop)
37322 vcc->pop(vcc, skb);
37323 else
37324@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37325 ATM_DESC(skb) = vcc->vci;
37326 skb_queue_tail(&iadev->tx_dma_q, skb);
37327
37328- atomic_inc(&vcc->stats->tx);
37329+ atomic_inc_unchecked(&vcc->stats->tx);
37330 iadev->tx_pkt_cnt++;
37331 /* Increment transaction counter */
37332 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37333
37334 #if 0
37335 /* add flow control logic */
37336- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37337+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37338 if (iavcc->vc_desc_cnt > 10) {
37339 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37340 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37341diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37342index fa7d701..1e404c7 100644
37343--- a/drivers/atm/lanai.c
37344+++ b/drivers/atm/lanai.c
37345@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37346 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37347 lanai_endtx(lanai, lvcc);
37348 lanai_free_skb(lvcc->tx.atmvcc, skb);
37349- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37350+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37351 }
37352
37353 /* Try to fill the buffer - don't call unless there is backlog */
37354@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37355 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37356 __net_timestamp(skb);
37357 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37358- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37359+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37360 out:
37361 lvcc->rx.buf.ptr = end;
37362 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37363@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37364 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37365 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37366 lanai->stats.service_rxnotaal5++;
37367- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37368+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37369 return 0;
37370 }
37371 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37372@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37373 int bytes;
37374 read_unlock(&vcc_sklist_lock);
37375 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37376- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37377+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37378 lvcc->stats.x.aal5.service_trash++;
37379 bytes = (SERVICE_GET_END(s) * 16) -
37380 (((unsigned long) lvcc->rx.buf.ptr) -
37381@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37382 }
37383 if (s & SERVICE_STREAM) {
37384 read_unlock(&vcc_sklist_lock);
37385- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37386+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37387 lvcc->stats.x.aal5.service_stream++;
37388 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37389 "PDU on VCI %d!\n", lanai->number, vci);
37390@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37391 return 0;
37392 }
37393 DPRINTK("got rx crc error on vci %d\n", vci);
37394- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37395+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37396 lvcc->stats.x.aal5.service_rxcrc++;
37397 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37398 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37399diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37400index 9587e95..b45c5cb 100644
37401--- a/drivers/atm/nicstar.c
37402+++ b/drivers/atm/nicstar.c
37403@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37404 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37405 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37406 card->index);
37407- atomic_inc(&vcc->stats->tx_err);
37408+ atomic_inc_unchecked(&vcc->stats->tx_err);
37409 dev_kfree_skb_any(skb);
37410 return -EINVAL;
37411 }
37412@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37413 if (!vc->tx) {
37414 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37415 card->index);
37416- atomic_inc(&vcc->stats->tx_err);
37417+ atomic_inc_unchecked(&vcc->stats->tx_err);
37418 dev_kfree_skb_any(skb);
37419 return -EINVAL;
37420 }
37421@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37422 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37423 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37424 card->index);
37425- atomic_inc(&vcc->stats->tx_err);
37426+ atomic_inc_unchecked(&vcc->stats->tx_err);
37427 dev_kfree_skb_any(skb);
37428 return -EINVAL;
37429 }
37430
37431 if (skb_shinfo(skb)->nr_frags != 0) {
37432 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37433- atomic_inc(&vcc->stats->tx_err);
37434+ atomic_inc_unchecked(&vcc->stats->tx_err);
37435 dev_kfree_skb_any(skb);
37436 return -EINVAL;
37437 }
37438@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37439 }
37440
37441 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37442- atomic_inc(&vcc->stats->tx_err);
37443+ atomic_inc_unchecked(&vcc->stats->tx_err);
37444 dev_kfree_skb_any(skb);
37445 return -EIO;
37446 }
37447- atomic_inc(&vcc->stats->tx);
37448+ atomic_inc_unchecked(&vcc->stats->tx);
37449
37450 return 0;
37451 }
37452@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37453 printk
37454 ("nicstar%d: Can't allocate buffers for aal0.\n",
37455 card->index);
37456- atomic_add(i, &vcc->stats->rx_drop);
37457+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37458 break;
37459 }
37460 if (!atm_charge(vcc, sb->truesize)) {
37461 RXPRINTK
37462 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37463 card->index);
37464- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37465+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37466 dev_kfree_skb_any(sb);
37467 break;
37468 }
37469@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37470 ATM_SKB(sb)->vcc = vcc;
37471 __net_timestamp(sb);
37472 vcc->push(vcc, sb);
37473- atomic_inc(&vcc->stats->rx);
37474+ atomic_inc_unchecked(&vcc->stats->rx);
37475 cell += ATM_CELL_PAYLOAD;
37476 }
37477
37478@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37479 if (iovb == NULL) {
37480 printk("nicstar%d: Out of iovec buffers.\n",
37481 card->index);
37482- atomic_inc(&vcc->stats->rx_drop);
37483+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37484 recycle_rx_buf(card, skb);
37485 return;
37486 }
37487@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37488 small or large buffer itself. */
37489 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37490 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37491- atomic_inc(&vcc->stats->rx_err);
37492+ atomic_inc_unchecked(&vcc->stats->rx_err);
37493 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37494 NS_MAX_IOVECS);
37495 NS_PRV_IOVCNT(iovb) = 0;
37496@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37497 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37498 card->index);
37499 which_list(card, skb);
37500- atomic_inc(&vcc->stats->rx_err);
37501+ atomic_inc_unchecked(&vcc->stats->rx_err);
37502 recycle_rx_buf(card, skb);
37503 vc->rx_iov = NULL;
37504 recycle_iov_buf(card, iovb);
37505@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37506 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37507 card->index);
37508 which_list(card, skb);
37509- atomic_inc(&vcc->stats->rx_err);
37510+ atomic_inc_unchecked(&vcc->stats->rx_err);
37511 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37512 NS_PRV_IOVCNT(iovb));
37513 vc->rx_iov = NULL;
37514@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37515 printk(" - PDU size mismatch.\n");
37516 else
37517 printk(".\n");
37518- atomic_inc(&vcc->stats->rx_err);
37519+ atomic_inc_unchecked(&vcc->stats->rx_err);
37520 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37521 NS_PRV_IOVCNT(iovb));
37522 vc->rx_iov = NULL;
37523@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37524 /* skb points to a small buffer */
37525 if (!atm_charge(vcc, skb->truesize)) {
37526 push_rxbufs(card, skb);
37527- atomic_inc(&vcc->stats->rx_drop);
37528+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37529 } else {
37530 skb_put(skb, len);
37531 dequeue_sm_buf(card, skb);
37532@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37533 ATM_SKB(skb)->vcc = vcc;
37534 __net_timestamp(skb);
37535 vcc->push(vcc, skb);
37536- atomic_inc(&vcc->stats->rx);
37537+ atomic_inc_unchecked(&vcc->stats->rx);
37538 }
37539 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37540 struct sk_buff *sb;
37541@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37542 if (len <= NS_SMBUFSIZE) {
37543 if (!atm_charge(vcc, sb->truesize)) {
37544 push_rxbufs(card, sb);
37545- atomic_inc(&vcc->stats->rx_drop);
37546+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37547 } else {
37548 skb_put(sb, len);
37549 dequeue_sm_buf(card, sb);
37550@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37551 ATM_SKB(sb)->vcc = vcc;
37552 __net_timestamp(sb);
37553 vcc->push(vcc, sb);
37554- atomic_inc(&vcc->stats->rx);
37555+ atomic_inc_unchecked(&vcc->stats->rx);
37556 }
37557
37558 push_rxbufs(card, skb);
37559@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37560
37561 if (!atm_charge(vcc, skb->truesize)) {
37562 push_rxbufs(card, skb);
37563- atomic_inc(&vcc->stats->rx_drop);
37564+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37565 } else {
37566 dequeue_lg_buf(card, skb);
37567 #ifdef NS_USE_DESTRUCTORS
37568@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37569 ATM_SKB(skb)->vcc = vcc;
37570 __net_timestamp(skb);
37571 vcc->push(vcc, skb);
37572- atomic_inc(&vcc->stats->rx);
37573+ atomic_inc_unchecked(&vcc->stats->rx);
37574 }
37575
37576 push_rxbufs(card, sb);
37577@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37578 printk
37579 ("nicstar%d: Out of huge buffers.\n",
37580 card->index);
37581- atomic_inc(&vcc->stats->rx_drop);
37582+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37583 recycle_iovec_rx_bufs(card,
37584 (struct iovec *)
37585 iovb->data,
37586@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37587 card->hbpool.count++;
37588 } else
37589 dev_kfree_skb_any(hb);
37590- atomic_inc(&vcc->stats->rx_drop);
37591+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37592 } else {
37593 /* Copy the small buffer to the huge buffer */
37594 sb = (struct sk_buff *)iov->iov_base;
37595@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37596 #endif /* NS_USE_DESTRUCTORS */
37597 __net_timestamp(hb);
37598 vcc->push(vcc, hb);
37599- atomic_inc(&vcc->stats->rx);
37600+ atomic_inc_unchecked(&vcc->stats->rx);
37601 }
37602 }
37603
37604diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37605index e3fb496..d9646bf 100644
37606--- a/drivers/atm/solos-pci.c
37607+++ b/drivers/atm/solos-pci.c
37608@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37609 }
37610 atm_charge(vcc, skb->truesize);
37611 vcc->push(vcc, skb);
37612- atomic_inc(&vcc->stats->rx);
37613+ atomic_inc_unchecked(&vcc->stats->rx);
37614 break;
37615
37616 case PKT_STATUS:
37617@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37618 vcc = SKB_CB(oldskb)->vcc;
37619
37620 if (vcc) {
37621- atomic_inc(&vcc->stats->tx);
37622+ atomic_inc_unchecked(&vcc->stats->tx);
37623 solos_pop(vcc, oldskb);
37624 } else {
37625 dev_kfree_skb_irq(oldskb);
37626diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37627index 0215934..ce9f5b1 100644
37628--- a/drivers/atm/suni.c
37629+++ b/drivers/atm/suni.c
37630@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37631
37632
37633 #define ADD_LIMITED(s,v) \
37634- atomic_add((v),&stats->s); \
37635- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37636+ atomic_add_unchecked((v),&stats->s); \
37637+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37638
37639
37640 static void suni_hz(unsigned long from_timer)
37641diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37642index 5120a96..e2572bd 100644
37643--- a/drivers/atm/uPD98402.c
37644+++ b/drivers/atm/uPD98402.c
37645@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37646 struct sonet_stats tmp;
37647 int error = 0;
37648
37649- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37650+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37651 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37652 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37653 if (zero && !error) {
37654@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37655
37656
37657 #define ADD_LIMITED(s,v) \
37658- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37659- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37660- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37661+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37662+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37663+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37664
37665
37666 static void stat_event(struct atm_dev *dev)
37667@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37668 if (reason & uPD98402_INT_PFM) stat_event(dev);
37669 if (reason & uPD98402_INT_PCO) {
37670 (void) GET(PCOCR); /* clear interrupt cause */
37671- atomic_add(GET(HECCT),
37672+ atomic_add_unchecked(GET(HECCT),
37673 &PRIV(dev)->sonet_stats.uncorr_hcs);
37674 }
37675 if ((reason & uPD98402_INT_RFO) &&
37676@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37677 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37678 uPD98402_INT_LOS),PIMR); /* enable them */
37679 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37680- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37681- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37682- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37683+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37684+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37685+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37686 return 0;
37687 }
37688
37689diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37690index 969c3c2..9b72956 100644
37691--- a/drivers/atm/zatm.c
37692+++ b/drivers/atm/zatm.c
37693@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37694 }
37695 if (!size) {
37696 dev_kfree_skb_irq(skb);
37697- if (vcc) atomic_inc(&vcc->stats->rx_err);
37698+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37699 continue;
37700 }
37701 if (!atm_charge(vcc,skb->truesize)) {
37702@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37703 skb->len = size;
37704 ATM_SKB(skb)->vcc = vcc;
37705 vcc->push(vcc,skb);
37706- atomic_inc(&vcc->stats->rx);
37707+ atomic_inc_unchecked(&vcc->stats->rx);
37708 }
37709 zout(pos & 0xffff,MTA(mbx));
37710 #if 0 /* probably a stupid idea */
37711@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37712 skb_queue_head(&zatm_vcc->backlog,skb);
37713 break;
37714 }
37715- atomic_inc(&vcc->stats->tx);
37716+ atomic_inc_unchecked(&vcc->stats->tx);
37717 wake_up(&zatm_vcc->tx_wait);
37718 }
37719
37720diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37721index 59dc808..f10c74e 100644
37722--- a/drivers/base/bus.c
37723+++ b/drivers/base/bus.c
37724@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37725 return -EINVAL;
37726
37727 mutex_lock(&subsys->p->mutex);
37728- list_add_tail(&sif->node, &subsys->p->interfaces);
37729+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37730 if (sif->add_dev) {
37731 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37732 while ((dev = subsys_dev_iter_next(&iter)))
37733@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37734 subsys = sif->subsys;
37735
37736 mutex_lock(&subsys->p->mutex);
37737- list_del_init(&sif->node);
37738+ pax_list_del_init((struct list_head *)&sif->node);
37739 if (sif->remove_dev) {
37740 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37741 while ((dev = subsys_dev_iter_next(&iter)))
37742diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37743index 25798db..15f130e 100644
37744--- a/drivers/base/devtmpfs.c
37745+++ b/drivers/base/devtmpfs.c
37746@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37747 if (!thread)
37748 return 0;
37749
37750- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37751+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37752 if (err)
37753 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37754 else
37755@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37756 *err = sys_unshare(CLONE_NEWNS);
37757 if (*err)
37758 goto out;
37759- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37760+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37761 if (*err)
37762 goto out;
37763- sys_chdir("/.."); /* will traverse into overmounted root */
37764- sys_chroot(".");
37765+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37766+ sys_chroot((char __force_user *)".");
37767 complete(&setup_done);
37768 while (1) {
37769 spin_lock(&req_lock);
37770diff --git a/drivers/base/node.c b/drivers/base/node.c
37771index bc9f43b..29703b8 100644
37772--- a/drivers/base/node.c
37773+++ b/drivers/base/node.c
37774@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37775 struct node_attr {
37776 struct device_attribute attr;
37777 enum node_states state;
37778-};
37779+} __do_const;
37780
37781 static ssize_t show_node_state(struct device *dev,
37782 struct device_attribute *attr, char *buf)
37783diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37784index bfb8955..4ebff34 100644
37785--- a/drivers/base/power/domain.c
37786+++ b/drivers/base/power/domain.c
37787@@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37788
37789 if (dev->power.subsys_data->domain_data) {
37790 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37791- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37792+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37793 if (clear_td)
37794- gpd_data->td = (struct gpd_timing_data){ 0 };
37795+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37796
37797 if (--gpd_data->refcount == 0) {
37798 dev->power.subsys_data->domain_data = NULL;
37799@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37800 {
37801 struct cpuidle_driver *cpuidle_drv;
37802 struct gpd_cpu_data *cpu_data;
37803- struct cpuidle_state *idle_state;
37804+ cpuidle_state_no_const *idle_state;
37805 int ret = 0;
37806
37807 if (IS_ERR_OR_NULL(genpd) || state < 0)
37808@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37809 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37810 {
37811 struct gpd_cpu_data *cpu_data;
37812- struct cpuidle_state *idle_state;
37813+ cpuidle_state_no_const *idle_state;
37814 int ret = 0;
37815
37816 if (IS_ERR_OR_NULL(genpd))
37817diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37818index 03e089a..0e9560c 100644
37819--- a/drivers/base/power/sysfs.c
37820+++ b/drivers/base/power/sysfs.c
37821@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37822 return -EIO;
37823 }
37824 }
37825- return sprintf(buf, p);
37826+ return sprintf(buf, "%s", p);
37827 }
37828
37829 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37830diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37831index 2d56f41..8830f19 100644
37832--- a/drivers/base/power/wakeup.c
37833+++ b/drivers/base/power/wakeup.c
37834@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37835 * They need to be modified together atomically, so it's better to use one
37836 * atomic variable to hold them both.
37837 */
37838-static atomic_t combined_event_count = ATOMIC_INIT(0);
37839+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37840
37841 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37842 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37843
37844 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37845 {
37846- unsigned int comb = atomic_read(&combined_event_count);
37847+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37848
37849 *cnt = (comb >> IN_PROGRESS_BITS);
37850 *inpr = comb & MAX_IN_PROGRESS;
37851@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37852 ws->start_prevent_time = ws->last_time;
37853
37854 /* Increment the counter of events in progress. */
37855- cec = atomic_inc_return(&combined_event_count);
37856+ cec = atomic_inc_return_unchecked(&combined_event_count);
37857
37858 trace_wakeup_source_activate(ws->name, cec);
37859 }
37860@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37861 * Increment the counter of registered wakeup events and decrement the
37862 * couter of wakeup events in progress simultaneously.
37863 */
37864- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37865+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37866 trace_wakeup_source_deactivate(ws->name, cec);
37867
37868 split_counters(&cnt, &inpr);
37869diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37870index e8d11b6..7b1b36f 100644
37871--- a/drivers/base/syscore.c
37872+++ b/drivers/base/syscore.c
37873@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37874 void register_syscore_ops(struct syscore_ops *ops)
37875 {
37876 mutex_lock(&syscore_ops_lock);
37877- list_add_tail(&ops->node, &syscore_ops_list);
37878+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37879 mutex_unlock(&syscore_ops_lock);
37880 }
37881 EXPORT_SYMBOL_GPL(register_syscore_ops);
37882@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37883 void unregister_syscore_ops(struct syscore_ops *ops)
37884 {
37885 mutex_lock(&syscore_ops_lock);
37886- list_del(&ops->node);
37887+ pax_list_del((struct list_head *)&ops->node);
37888 mutex_unlock(&syscore_ops_lock);
37889 }
37890 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37891diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37892index 036e8ab..6221dec 100644
37893--- a/drivers/block/cciss.c
37894+++ b/drivers/block/cciss.c
37895@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37896 while (!list_empty(&h->reqQ)) {
37897 c = list_entry(h->reqQ.next, CommandList_struct, list);
37898 /* can't do anything if fifo is full */
37899- if ((h->access.fifo_full(h))) {
37900+ if ((h->access->fifo_full(h))) {
37901 dev_warn(&h->pdev->dev, "fifo full\n");
37902 break;
37903 }
37904@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37905 h->Qdepth--;
37906
37907 /* Tell the controller execute command */
37908- h->access.submit_command(h, c);
37909+ h->access->submit_command(h, c);
37910
37911 /* Put job onto the completed Q */
37912 addQ(&h->cmpQ, c);
37913@@ -3447,17 +3447,17 @@ startio:
37914
37915 static inline unsigned long get_next_completion(ctlr_info_t *h)
37916 {
37917- return h->access.command_completed(h);
37918+ return h->access->command_completed(h);
37919 }
37920
37921 static inline int interrupt_pending(ctlr_info_t *h)
37922 {
37923- return h->access.intr_pending(h);
37924+ return h->access->intr_pending(h);
37925 }
37926
37927 static inline long interrupt_not_for_us(ctlr_info_t *h)
37928 {
37929- return ((h->access.intr_pending(h) == 0) ||
37930+ return ((h->access->intr_pending(h) == 0) ||
37931 (h->interrupts_enabled == 0));
37932 }
37933
37934@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37935 u32 a;
37936
37937 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37938- return h->access.command_completed(h);
37939+ return h->access->command_completed(h);
37940
37941 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37942 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37943@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37944 trans_support & CFGTBL_Trans_use_short_tags);
37945
37946 /* Change the access methods to the performant access methods */
37947- h->access = SA5_performant_access;
37948+ h->access = &SA5_performant_access;
37949 h->transMethod = CFGTBL_Trans_Performant;
37950
37951 return;
37952@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37953 if (prod_index < 0)
37954 return -ENODEV;
37955 h->product_name = products[prod_index].product_name;
37956- h->access = *(products[prod_index].access);
37957+ h->access = products[prod_index].access;
37958
37959 if (cciss_board_disabled(h)) {
37960 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37961@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37962 }
37963
37964 /* make sure the board interrupts are off */
37965- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37966+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37967 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37968 if (rc)
37969 goto clean2;
37970@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37971 * fake ones to scoop up any residual completions.
37972 */
37973 spin_lock_irqsave(&h->lock, flags);
37974- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37975+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37976 spin_unlock_irqrestore(&h->lock, flags);
37977 free_irq(h->intr[h->intr_mode], h);
37978 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37979@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37980 dev_info(&h->pdev->dev, "Board READY.\n");
37981 dev_info(&h->pdev->dev,
37982 "Waiting for stale completions to drain.\n");
37983- h->access.set_intr_mask(h, CCISS_INTR_ON);
37984+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37985 msleep(10000);
37986- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37987+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37988
37989 rc = controller_reset_failed(h->cfgtable);
37990 if (rc)
37991@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37992 cciss_scsi_setup(h);
37993
37994 /* Turn the interrupts on so we can service requests */
37995- h->access.set_intr_mask(h, CCISS_INTR_ON);
37996+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37997
37998 /* Get the firmware version */
37999 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
38000@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
38001 kfree(flush_buf);
38002 if (return_code != IO_OK)
38003 dev_warn(&h->pdev->dev, "Error flushing cache\n");
38004- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38005+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38006 free_irq(h->intr[h->intr_mode], h);
38007 }
38008
38009diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
38010index 7fda30e..2f27946 100644
38011--- a/drivers/block/cciss.h
38012+++ b/drivers/block/cciss.h
38013@@ -101,7 +101,7 @@ struct ctlr_info
38014 /* information about each logical volume */
38015 drive_info_struct *drv[CISS_MAX_LUN];
38016
38017- struct access_method access;
38018+ struct access_method *access;
38019
38020 /* queue and queue Info */
38021 struct list_head reqQ;
38022@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
38023 }
38024
38025 static struct access_method SA5_access = {
38026- SA5_submit_command,
38027- SA5_intr_mask,
38028- SA5_fifo_full,
38029- SA5_intr_pending,
38030- SA5_completed,
38031+ .submit_command = SA5_submit_command,
38032+ .set_intr_mask = SA5_intr_mask,
38033+ .fifo_full = SA5_fifo_full,
38034+ .intr_pending = SA5_intr_pending,
38035+ .command_completed = SA5_completed,
38036 };
38037
38038 static struct access_method SA5B_access = {
38039- SA5_submit_command,
38040- SA5B_intr_mask,
38041- SA5_fifo_full,
38042- SA5B_intr_pending,
38043- SA5_completed,
38044+ .submit_command = SA5_submit_command,
38045+ .set_intr_mask = SA5B_intr_mask,
38046+ .fifo_full = SA5_fifo_full,
38047+ .intr_pending = SA5B_intr_pending,
38048+ .command_completed = SA5_completed,
38049 };
38050
38051 static struct access_method SA5_performant_access = {
38052- SA5_submit_command,
38053- SA5_performant_intr_mask,
38054- SA5_fifo_full,
38055- SA5_performant_intr_pending,
38056- SA5_performant_completed,
38057+ .submit_command = SA5_submit_command,
38058+ .set_intr_mask = SA5_performant_intr_mask,
38059+ .fifo_full = SA5_fifo_full,
38060+ .intr_pending = SA5_performant_intr_pending,
38061+ .command_completed = SA5_performant_completed,
38062 };
38063
38064 struct board_type {
38065diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
38066index 2b94403..fd6ad1f 100644
38067--- a/drivers/block/cpqarray.c
38068+++ b/drivers/block/cpqarray.c
38069@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38070 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
38071 goto Enomem4;
38072 }
38073- hba[i]->access.set_intr_mask(hba[i], 0);
38074+ hba[i]->access->set_intr_mask(hba[i], 0);
38075 if (request_irq(hba[i]->intr, do_ida_intr,
38076 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
38077 {
38078@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38079 add_timer(&hba[i]->timer);
38080
38081 /* Enable IRQ now that spinlock and rate limit timer are set up */
38082- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38083+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38084
38085 for(j=0; j<NWD; j++) {
38086 struct gendisk *disk = ida_gendisk[i][j];
38087@@ -694,7 +694,7 @@ DBGINFO(
38088 for(i=0; i<NR_PRODUCTS; i++) {
38089 if (board_id == products[i].board_id) {
38090 c->product_name = products[i].product_name;
38091- c->access = *(products[i].access);
38092+ c->access = products[i].access;
38093 break;
38094 }
38095 }
38096@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
38097 hba[ctlr]->intr = intr;
38098 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
38099 hba[ctlr]->product_name = products[j].product_name;
38100- hba[ctlr]->access = *(products[j].access);
38101+ hba[ctlr]->access = products[j].access;
38102 hba[ctlr]->ctlr = ctlr;
38103 hba[ctlr]->board_id = board_id;
38104 hba[ctlr]->pci_dev = NULL; /* not PCI */
38105@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
38106
38107 while((c = h->reqQ) != NULL) {
38108 /* Can't do anything if we're busy */
38109- if (h->access.fifo_full(h) == 0)
38110+ if (h->access->fifo_full(h) == 0)
38111 return;
38112
38113 /* Get the first entry from the request Q */
38114@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38115 h->Qdepth--;
38116
38117 /* Tell the controller to do our bidding */
38118- h->access.submit_command(h, c);
38119+ h->access->submit_command(h, c);
38120
38121 /* Get onto the completion Q */
38122 addQ(&h->cmpQ, c);
38123@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38124 unsigned long flags;
38125 __u32 a,a1;
38126
38127- istat = h->access.intr_pending(h);
38128+ istat = h->access->intr_pending(h);
38129 /* Is this interrupt for us? */
38130 if (istat == 0)
38131 return IRQ_NONE;
38132@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38133 */
38134 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38135 if (istat & FIFO_NOT_EMPTY) {
38136- while((a = h->access.command_completed(h))) {
38137+ while((a = h->access->command_completed(h))) {
38138 a1 = a; a &= ~3;
38139 if ((c = h->cmpQ) == NULL)
38140 {
38141@@ -1448,11 +1448,11 @@ static int sendcmd(
38142 /*
38143 * Disable interrupt
38144 */
38145- info_p->access.set_intr_mask(info_p, 0);
38146+ info_p->access->set_intr_mask(info_p, 0);
38147 /* Make sure there is room in the command FIFO */
38148 /* Actually it should be completely empty at this time. */
38149 for (i = 200000; i > 0; i--) {
38150- temp = info_p->access.fifo_full(info_p);
38151+ temp = info_p->access->fifo_full(info_p);
38152 if (temp != 0) {
38153 break;
38154 }
38155@@ -1465,7 +1465,7 @@ DBG(
38156 /*
38157 * Send the cmd
38158 */
38159- info_p->access.submit_command(info_p, c);
38160+ info_p->access->submit_command(info_p, c);
38161 complete = pollcomplete(ctlr);
38162
38163 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38164@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38165 * we check the new geometry. Then turn interrupts back on when
38166 * we're done.
38167 */
38168- host->access.set_intr_mask(host, 0);
38169+ host->access->set_intr_mask(host, 0);
38170 getgeometry(ctlr);
38171- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38172+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38173
38174 for(i=0; i<NWD; i++) {
38175 struct gendisk *disk = ida_gendisk[ctlr][i];
38176@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38177 /* Wait (up to 2 seconds) for a command to complete */
38178
38179 for (i = 200000; i > 0; i--) {
38180- done = hba[ctlr]->access.command_completed(hba[ctlr]);
38181+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
38182 if (done == 0) {
38183 udelay(10); /* a short fixed delay */
38184 } else
38185diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38186index be73e9d..7fbf140 100644
38187--- a/drivers/block/cpqarray.h
38188+++ b/drivers/block/cpqarray.h
38189@@ -99,7 +99,7 @@ struct ctlr_info {
38190 drv_info_t drv[NWD];
38191 struct proc_dir_entry *proc;
38192
38193- struct access_method access;
38194+ struct access_method *access;
38195
38196 cmdlist_t *reqQ;
38197 cmdlist_t *cmpQ;
38198diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38199index 0e06f0c..c47b81d 100644
38200--- a/drivers/block/drbd/drbd_int.h
38201+++ b/drivers/block/drbd/drbd_int.h
38202@@ -582,7 +582,7 @@ struct drbd_epoch {
38203 struct drbd_tconn *tconn;
38204 struct list_head list;
38205 unsigned int barrier_nr;
38206- atomic_t epoch_size; /* increased on every request added. */
38207+ atomic_unchecked_t epoch_size; /* increased on every request added. */
38208 atomic_t active; /* increased on every req. added, and dec on every finished. */
38209 unsigned long flags;
38210 };
38211@@ -1022,7 +1022,7 @@ struct drbd_conf {
38212 unsigned int al_tr_number;
38213 int al_tr_cycle;
38214 wait_queue_head_t seq_wait;
38215- atomic_t packet_seq;
38216+ atomic_unchecked_t packet_seq;
38217 unsigned int peer_seq;
38218 spinlock_t peer_seq_lock;
38219 unsigned int minor;
38220@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38221 char __user *uoptval;
38222 int err;
38223
38224- uoptval = (char __user __force *)optval;
38225+ uoptval = (char __force_user *)optval;
38226
38227 set_fs(KERNEL_DS);
38228 if (level == SOL_SOCKET)
38229diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
38230index 89c497c..9c736ae 100644
38231--- a/drivers/block/drbd/drbd_interval.c
38232+++ b/drivers/block/drbd/drbd_interval.c
38233@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
38234 }
38235
38236 static const struct rb_augment_callbacks augment_callbacks = {
38237- augment_propagate,
38238- augment_copy,
38239- augment_rotate,
38240+ .propagate = augment_propagate,
38241+ .copy = augment_copy,
38242+ .rotate = augment_rotate,
38243 };
38244
38245 /**
38246diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38247index 929468e..7d934eb 100644
38248--- a/drivers/block/drbd/drbd_main.c
38249+++ b/drivers/block/drbd/drbd_main.c
38250@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
38251 p->sector = sector;
38252 p->block_id = block_id;
38253 p->blksize = blksize;
38254- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
38255+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
38256 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
38257 }
38258
38259@@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
38260 return -EIO;
38261 p->sector = cpu_to_be64(req->i.sector);
38262 p->block_id = (unsigned long)req;
38263- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
38264+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
38265 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
38266 if (mdev->state.conn >= C_SYNC_SOURCE &&
38267 mdev->state.conn <= C_PAUSED_SYNC_T)
38268@@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
38269 {
38270 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
38271
38272- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
38273- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
38274+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
38275+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
38276 kfree(tconn->current_epoch);
38277
38278 idr_destroy(&tconn->volumes);
38279diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38280index c706d50..5e1b472 100644
38281--- a/drivers/block/drbd/drbd_nl.c
38282+++ b/drivers/block/drbd/drbd_nl.c
38283@@ -3440,7 +3440,7 @@ out:
38284
38285 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
38286 {
38287- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38288+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38289 struct sk_buff *msg;
38290 struct drbd_genlmsghdr *d_out;
38291 unsigned seq;
38292@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
38293 return;
38294 }
38295
38296- seq = atomic_inc_return(&drbd_genl_seq);
38297+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38298 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38299 if (!msg)
38300 goto failed;
38301diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38302index d073305..4998fea 100644
38303--- a/drivers/block/drbd/drbd_receiver.c
38304+++ b/drivers/block/drbd/drbd_receiver.c
38305@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
38306 {
38307 int err;
38308
38309- atomic_set(&mdev->packet_seq, 0);
38310+ atomic_set_unchecked(&mdev->packet_seq, 0);
38311 mdev->peer_seq = 0;
38312
38313 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
38314@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
38315 do {
38316 next_epoch = NULL;
38317
38318- epoch_size = atomic_read(&epoch->epoch_size);
38319+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38320
38321 switch (ev & ~EV_CLEANUP) {
38322 case EV_PUT:
38323@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
38324 rv = FE_DESTROYED;
38325 } else {
38326 epoch->flags = 0;
38327- atomic_set(&epoch->epoch_size, 0);
38328+ atomic_set_unchecked(&epoch->epoch_size, 0);
38329 /* atomic_set(&epoch->active, 0); is already zero */
38330 if (rv == FE_STILL_LIVE)
38331 rv = FE_RECYCLED;
38332@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
38333 conn_wait_active_ee_empty(tconn);
38334 drbd_flush(tconn);
38335
38336- if (atomic_read(&tconn->current_epoch->epoch_size)) {
38337+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
38338 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38339 if (epoch)
38340 break;
38341@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
38342 }
38343
38344 epoch->flags = 0;
38345- atomic_set(&epoch->epoch_size, 0);
38346+ atomic_set_unchecked(&epoch->epoch_size, 0);
38347 atomic_set(&epoch->active, 0);
38348
38349 spin_lock(&tconn->epoch_lock);
38350- if (atomic_read(&tconn->current_epoch->epoch_size)) {
38351+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
38352 list_add(&epoch->list, &tconn->current_epoch->list);
38353 tconn->current_epoch = epoch;
38354 tconn->epochs++;
38355@@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
38356
38357 err = wait_for_and_update_peer_seq(mdev, peer_seq);
38358 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
38359- atomic_inc(&tconn->current_epoch->epoch_size);
38360+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
38361 err2 = drbd_drain_block(mdev, pi->size);
38362 if (!err)
38363 err = err2;
38364@@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
38365
38366 spin_lock(&tconn->epoch_lock);
38367 peer_req->epoch = tconn->current_epoch;
38368- atomic_inc(&peer_req->epoch->epoch_size);
38369+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38370 atomic_inc(&peer_req->epoch->active);
38371 spin_unlock(&tconn->epoch_lock);
38372
38373@@ -4345,7 +4345,7 @@ struct data_cmd {
38374 int expect_payload;
38375 size_t pkt_size;
38376 int (*fn)(struct drbd_tconn *, struct packet_info *);
38377-};
38378+} __do_const;
38379
38380 static struct data_cmd drbd_cmd_handler[] = {
38381 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38382@@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
38383 if (!list_empty(&tconn->current_epoch->list))
38384 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
38385 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38386- atomic_set(&tconn->current_epoch->epoch_size, 0);
38387+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
38388 tconn->send.seen_any_write_yet = false;
38389
38390 conn_info(tconn, "Connection closed\n");
38391@@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
38392 struct asender_cmd {
38393 size_t pkt_size;
38394 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
38395-};
38396+} __do_const;
38397
38398 static struct asender_cmd asender_tbl[] = {
38399 [P_PING] = { 0, got_Ping },
38400diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38401index 66e8c3b..9b68dd9 100644
38402--- a/drivers/block/loop.c
38403+++ b/drivers/block/loop.c
38404@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38405
38406 file_start_write(file);
38407 set_fs(get_ds());
38408- bw = file->f_op->write(file, buf, len, &pos);
38409+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38410 set_fs(old_fs);
38411 file_end_write(file);
38412 if (likely(bw == len))
38413diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38414index 091b9ea..f5428f8 100644
38415--- a/drivers/block/null_blk.c
38416+++ b/drivers/block/null_blk.c
38417@@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38418 return 0;
38419 }
38420
38421-static struct blk_mq_ops null_mq_ops = {
38422- .queue_rq = null_queue_rq,
38423- .map_queue = blk_mq_map_queue,
38424+static struct blk_mq_ops null_mq_single_ops = {
38425+ .queue_rq = null_queue_rq,
38426+ .map_queue = blk_mq_map_queue,
38427 .init_hctx = null_init_hctx,
38428 .complete = null_softirq_done_fn,
38429+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
38430+ .free_hctx = blk_mq_free_single_hw_queue,
38431+};
38432+
38433+static struct blk_mq_ops null_mq_per_node_ops = {
38434+ .queue_rq = null_queue_rq,
38435+ .map_queue = blk_mq_map_queue,
38436+ .init_hctx = null_init_hctx,
38437+ .alloc_hctx = null_alloc_hctx,
38438+ .free_hctx = null_free_hctx,
38439 };
38440
38441 static struct blk_mq_reg null_mq_reg = {
38442- .ops = &null_mq_ops,
38443+ .ops = &null_mq_single_ops,
38444 .queue_depth = 64,
38445 .cmd_size = sizeof(struct nullb_cmd),
38446 .flags = BLK_MQ_F_SHOULD_MERGE,
38447@@ -521,13 +531,8 @@ static int null_add_dev(void)
38448 null_mq_reg.queue_depth = hw_queue_depth;
38449 null_mq_reg.nr_hw_queues = submit_queues;
38450
38451- if (use_per_node_hctx) {
38452- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38453- null_mq_reg.ops->free_hctx = null_free_hctx;
38454- } else {
38455- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38456- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38457- }
38458+ if (use_per_node_hctx)
38459+ null_mq_reg.ops = &null_mq_per_node_ops;
38460
38461 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38462 } else if (queue_mode == NULL_Q_BIO) {
38463diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38464index a2af73d..c0b8f61 100644
38465--- a/drivers/block/pktcdvd.c
38466+++ b/drivers/block/pktcdvd.c
38467@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38468
38469 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38470 {
38471- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38472+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38473 }
38474
38475 /*
38476@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38477 return -EROFS;
38478 }
38479 pd->settings.fp = ti.fp;
38480- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38481+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38482
38483 if (ti.nwa_v) {
38484 pd->nwa = be32_to_cpu(ti.next_writable);
38485diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38486index e5565fb..71be10b4 100644
38487--- a/drivers/block/smart1,2.h
38488+++ b/drivers/block/smart1,2.h
38489@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38490 }
38491
38492 static struct access_method smart4_access = {
38493- smart4_submit_command,
38494- smart4_intr_mask,
38495- smart4_fifo_full,
38496- smart4_intr_pending,
38497- smart4_completed,
38498+ .submit_command = smart4_submit_command,
38499+ .set_intr_mask = smart4_intr_mask,
38500+ .fifo_full = smart4_fifo_full,
38501+ .intr_pending = smart4_intr_pending,
38502+ .command_completed = smart4_completed,
38503 };
38504
38505 /*
38506@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38507 }
38508
38509 static struct access_method smart2_access = {
38510- smart2_submit_command,
38511- smart2_intr_mask,
38512- smart2_fifo_full,
38513- smart2_intr_pending,
38514- smart2_completed,
38515+ .submit_command = smart2_submit_command,
38516+ .set_intr_mask = smart2_intr_mask,
38517+ .fifo_full = smart2_fifo_full,
38518+ .intr_pending = smart2_intr_pending,
38519+ .command_completed = smart2_completed,
38520 };
38521
38522 /*
38523@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38524 }
38525
38526 static struct access_method smart2e_access = {
38527- smart2e_submit_command,
38528- smart2e_intr_mask,
38529- smart2e_fifo_full,
38530- smart2e_intr_pending,
38531- smart2e_completed,
38532+ .submit_command = smart2e_submit_command,
38533+ .set_intr_mask = smart2e_intr_mask,
38534+ .fifo_full = smart2e_fifo_full,
38535+ .intr_pending = smart2e_intr_pending,
38536+ .command_completed = smart2e_completed,
38537 };
38538
38539 /*
38540@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38541 }
38542
38543 static struct access_method smart1_access = {
38544- smart1_submit_command,
38545- smart1_intr_mask,
38546- smart1_fifo_full,
38547- smart1_intr_pending,
38548- smart1_completed,
38549+ .submit_command = smart1_submit_command,
38550+ .set_intr_mask = smart1_intr_mask,
38551+ .fifo_full = smart1_fifo_full,
38552+ .intr_pending = smart1_intr_pending,
38553+ .command_completed = smart1_completed,
38554 };
38555diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38556index f038dba..bb74c08 100644
38557--- a/drivers/bluetooth/btwilink.c
38558+++ b/drivers/bluetooth/btwilink.c
38559@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38560
38561 static int bt_ti_probe(struct platform_device *pdev)
38562 {
38563- static struct ti_st *hst;
38564+ struct ti_st *hst;
38565 struct hci_dev *hdev;
38566 int err;
38567
38568diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38569index 8a3aff7..d7538c2 100644
38570--- a/drivers/cdrom/cdrom.c
38571+++ b/drivers/cdrom/cdrom.c
38572@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38573 ENSURE(reset, CDC_RESET);
38574 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38575 cdi->mc_flags = 0;
38576- cdo->n_minors = 0;
38577 cdi->options = CDO_USE_FFLAGS;
38578
38579 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38580@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38581 else
38582 cdi->cdda_method = CDDA_OLD;
38583
38584- if (!cdo->generic_packet)
38585- cdo->generic_packet = cdrom_dummy_generic_packet;
38586+ if (!cdo->generic_packet) {
38587+ pax_open_kernel();
38588+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38589+ pax_close_kernel();
38590+ }
38591
38592 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38593 mutex_lock(&cdrom_mutex);
38594@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38595 if (cdi->exit)
38596 cdi->exit(cdi);
38597
38598- cdi->ops->n_minors--;
38599 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38600 }
38601
38602@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38603 */
38604 nr = nframes;
38605 do {
38606- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38607+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38608 if (cgc.buffer)
38609 break;
38610
38611@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38612 struct cdrom_device_info *cdi;
38613 int ret;
38614
38615- ret = scnprintf(info + *pos, max_size - *pos, header);
38616+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38617 if (!ret)
38618 return 1;
38619
38620diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38621index 51e75ad..39c4c76 100644
38622--- a/drivers/cdrom/gdrom.c
38623+++ b/drivers/cdrom/gdrom.c
38624@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38625 .audio_ioctl = gdrom_audio_ioctl,
38626 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38627 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38628- .n_minors = 1,
38629 };
38630
38631 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38632diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38633index 1386749..5430258 100644
38634--- a/drivers/char/Kconfig
38635+++ b/drivers/char/Kconfig
38636@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38637
38638 config DEVKMEM
38639 bool "/dev/kmem virtual device support"
38640- default y
38641+ default n
38642+ depends on !GRKERNSEC_KMEM
38643 help
38644 Say Y here if you want to support the /dev/kmem device. The
38645 /dev/kmem device is rarely used, but can be used for certain
38646@@ -577,6 +578,7 @@ config DEVPORT
38647 bool
38648 depends on !M68K
38649 depends on ISA || PCI
38650+ depends on !GRKERNSEC_KMEM
38651 default y
38652
38653 source "drivers/s390/char/Kconfig"
38654diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38655index a48e05b..6bac831 100644
38656--- a/drivers/char/agp/compat_ioctl.c
38657+++ b/drivers/char/agp/compat_ioctl.c
38658@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38659 return -ENOMEM;
38660 }
38661
38662- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38663+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38664 sizeof(*usegment) * ureserve.seg_count)) {
38665 kfree(usegment);
38666 kfree(ksegment);
38667diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38668index 1b19239..963967b 100644
38669--- a/drivers/char/agp/frontend.c
38670+++ b/drivers/char/agp/frontend.c
38671@@ -731,6 +731,7 @@ static int agpioc_info_wrap(struct agp_file_private *priv, void __user *arg)
38672
38673 agp_copy_info(agp_bridge, &kerninfo);
38674
38675+ memset(&userinfo, 0, sizeof(userinfo));
38676 userinfo.version.major = kerninfo.version.major;
38677 userinfo.version.minor = kerninfo.version.minor;
38678 userinfo.bridge_id = kerninfo.device->vendor |
38679@@ -819,7 +820,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38680 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38681 return -EFAULT;
38682
38683- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38684+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38685 return -EFAULT;
38686
38687 client = agp_find_client_by_pid(reserve.pid);
38688@@ -849,7 +850,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38689 if (segment == NULL)
38690 return -ENOMEM;
38691
38692- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38693+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38694 sizeof(struct agp_segment) * reserve.seg_count)) {
38695 kfree(segment);
38696 return -EFAULT;
38697diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38698index 4f94375..413694e 100644
38699--- a/drivers/char/genrtc.c
38700+++ b/drivers/char/genrtc.c
38701@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38702 switch (cmd) {
38703
38704 case RTC_PLL_GET:
38705+ memset(&pll, 0, sizeof(pll));
38706 if (get_rtc_pll(&pll))
38707 return -EINVAL;
38708 else
38709diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38710index d5d4cd8..22d561d 100644
38711--- a/drivers/char/hpet.c
38712+++ b/drivers/char/hpet.c
38713@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38714 }
38715
38716 static int
38717-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38718+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38719 struct hpet_info *info)
38720 {
38721 struct hpet_timer __iomem *timer;
38722diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38723index 86fe45c..c0ea948 100644
38724--- a/drivers/char/hw_random/intel-rng.c
38725+++ b/drivers/char/hw_random/intel-rng.c
38726@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38727
38728 if (no_fwh_detect)
38729 return -ENODEV;
38730- printk(warning);
38731+ printk("%s", warning);
38732 return -EBUSY;
38733 }
38734
38735diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38736index ec4e10f..f2a763b 100644
38737--- a/drivers/char/ipmi/ipmi_msghandler.c
38738+++ b/drivers/char/ipmi/ipmi_msghandler.c
38739@@ -420,7 +420,7 @@ struct ipmi_smi {
38740 struct proc_dir_entry *proc_dir;
38741 char proc_dir_name[10];
38742
38743- atomic_t stats[IPMI_NUM_STATS];
38744+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38745
38746 /*
38747 * run_to_completion duplicate of smb_info, smi_info
38748@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38749
38750
38751 #define ipmi_inc_stat(intf, stat) \
38752- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38753+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38754 #define ipmi_get_stat(intf, stat) \
38755- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38756+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38757
38758 static int is_lan_addr(struct ipmi_addr *addr)
38759 {
38760@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38761 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38762 init_waitqueue_head(&intf->waitq);
38763 for (i = 0; i < IPMI_NUM_STATS; i++)
38764- atomic_set(&intf->stats[i], 0);
38765+ atomic_set_unchecked(&intf->stats[i], 0);
38766
38767 intf->proc_dir = NULL;
38768
38769diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38770index 03f4189..e79f5e0 100644
38771--- a/drivers/char/ipmi/ipmi_si_intf.c
38772+++ b/drivers/char/ipmi/ipmi_si_intf.c
38773@@ -280,7 +280,7 @@ struct smi_info {
38774 unsigned char slave_addr;
38775
38776 /* Counters and things for the proc filesystem. */
38777- atomic_t stats[SI_NUM_STATS];
38778+ atomic_unchecked_t stats[SI_NUM_STATS];
38779
38780 struct task_struct *thread;
38781
38782@@ -289,9 +289,9 @@ struct smi_info {
38783 };
38784
38785 #define smi_inc_stat(smi, stat) \
38786- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38787+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38788 #define smi_get_stat(smi, stat) \
38789- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38790+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38791
38792 #define SI_MAX_PARMS 4
38793
38794@@ -3339,7 +3339,7 @@ static int try_smi_init(struct smi_info *new_smi)
38795 atomic_set(&new_smi->req_events, 0);
38796 new_smi->run_to_completion = 0;
38797 for (i = 0; i < SI_NUM_STATS; i++)
38798- atomic_set(&new_smi->stats[i], 0);
38799+ atomic_set_unchecked(&new_smi->stats[i], 0);
38800
38801 new_smi->interrupt_disabled = 1;
38802 atomic_set(&new_smi->stop_operation, 0);
38803diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38804index 92c5937..1be4e4d 100644
38805--- a/drivers/char/mem.c
38806+++ b/drivers/char/mem.c
38807@@ -18,6 +18,7 @@
38808 #include <linux/raw.h>
38809 #include <linux/tty.h>
38810 #include <linux/capability.h>
38811+#include <linux/security.h>
38812 #include <linux/ptrace.h>
38813 #include <linux/device.h>
38814 #include <linux/highmem.h>
38815@@ -36,6 +37,10 @@
38816
38817 #define DEVPORT_MINOR 4
38818
38819+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38820+extern const struct file_operations grsec_fops;
38821+#endif
38822+
38823 static inline unsigned long size_inside_page(unsigned long start,
38824 unsigned long size)
38825 {
38826@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38827
38828 while (cursor < to) {
38829 if (!devmem_is_allowed(pfn)) {
38830+#ifdef CONFIG_GRKERNSEC_KMEM
38831+ gr_handle_mem_readwrite(from, to);
38832+#else
38833 printk(KERN_INFO
38834 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38835 current->comm, from, to);
38836+#endif
38837 return 0;
38838 }
38839 cursor += PAGE_SIZE;
38840@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38841 }
38842 return 1;
38843 }
38844+#elif defined(CONFIG_GRKERNSEC_KMEM)
38845+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38846+{
38847+ return 0;
38848+}
38849 #else
38850 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38851 {
38852@@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38853
38854 while (count > 0) {
38855 unsigned long remaining;
38856+ char *temp;
38857
38858 sz = size_inside_page(p, count);
38859
38860@@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38861 if (!ptr)
38862 return -EFAULT;
38863
38864- remaining = copy_to_user(buf, ptr, sz);
38865+#ifdef CONFIG_PAX_USERCOPY
38866+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38867+ if (!temp) {
38868+ unxlate_dev_mem_ptr(p, ptr);
38869+ return -ENOMEM;
38870+ }
38871+ memcpy(temp, ptr, sz);
38872+#else
38873+ temp = ptr;
38874+#endif
38875+
38876+ remaining = copy_to_user(buf, temp, sz);
38877+
38878+#ifdef CONFIG_PAX_USERCOPY
38879+ kfree(temp);
38880+#endif
38881+
38882 unxlate_dev_mem_ptr(p, ptr);
38883 if (remaining)
38884 return -EFAULT;
38885@@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38886 size_t count, loff_t *ppos)
38887 {
38888 unsigned long p = *ppos;
38889- ssize_t low_count, read, sz;
38890+ ssize_t low_count, read, sz, err = 0;
38891 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38892- int err = 0;
38893
38894 read = 0;
38895 if (p < (unsigned long) high_memory) {
38896@@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38897 }
38898 #endif
38899 while (low_count > 0) {
38900+ char *temp;
38901+
38902 sz = size_inside_page(p, low_count);
38903
38904 /*
38905@@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38906 */
38907 kbuf = xlate_dev_kmem_ptr((char *)p);
38908
38909- if (copy_to_user(buf, kbuf, sz))
38910+#ifdef CONFIG_PAX_USERCOPY
38911+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38912+ if (!temp)
38913+ return -ENOMEM;
38914+ memcpy(temp, kbuf, sz);
38915+#else
38916+ temp = kbuf;
38917+#endif
38918+
38919+ err = copy_to_user(buf, temp, sz);
38920+
38921+#ifdef CONFIG_PAX_USERCOPY
38922+ kfree(temp);
38923+#endif
38924+
38925+ if (err)
38926 return -EFAULT;
38927 buf += sz;
38928 p += sz;
38929@@ -821,6 +868,9 @@ static const struct memdev {
38930 #ifdef CONFIG_PRINTK
38931 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38932 #endif
38933+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38934+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38935+#endif
38936 };
38937
38938 static int memory_open(struct inode *inode, struct file *filp)
38939@@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
38940 continue;
38941
38942 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38943- NULL, devlist[minor].name);
38944+ NULL, "%s", devlist[minor].name);
38945 }
38946
38947 return tty_init();
38948diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38949index 9df78e2..01ba9ae 100644
38950--- a/drivers/char/nvram.c
38951+++ b/drivers/char/nvram.c
38952@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38953
38954 spin_unlock_irq(&rtc_lock);
38955
38956- if (copy_to_user(buf, contents, tmp - contents))
38957+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38958 return -EFAULT;
38959
38960 *ppos = i;
38961diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38962index 8320abd..ec48108 100644
38963--- a/drivers/char/pcmcia/synclink_cs.c
38964+++ b/drivers/char/pcmcia/synclink_cs.c
38965@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38966
38967 if (debug_level >= DEBUG_LEVEL_INFO)
38968 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38969- __FILE__, __LINE__, info->device_name, port->count);
38970+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38971
38972- WARN_ON(!port->count);
38973+ WARN_ON(!atomic_read(&port->count));
38974
38975 if (tty_port_close_start(port, tty, filp) == 0)
38976 goto cleanup;
38977@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38978 cleanup:
38979 if (debug_level >= DEBUG_LEVEL_INFO)
38980 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38981- tty->driver->name, port->count);
38982+ tty->driver->name, atomic_read(&port->count));
38983 }
38984
38985 /* Wait until the transmitter is empty.
38986@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38987
38988 if (debug_level >= DEBUG_LEVEL_INFO)
38989 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38990- __FILE__, __LINE__, tty->driver->name, port->count);
38991+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38992
38993 /* If port is closing, signal caller to try again */
38994 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38995@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38996 goto cleanup;
38997 }
38998 spin_lock(&port->lock);
38999- port->count++;
39000+ atomic_inc(&port->count);
39001 spin_unlock(&port->lock);
39002 spin_unlock_irqrestore(&info->netlock, flags);
39003
39004- if (port->count == 1) {
39005+ if (atomic_read(&port->count) == 1) {
39006 /* 1st open on this device, init hardware */
39007 retval = startup(info, tty);
39008 if (retval < 0)
39009@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39010 unsigned short new_crctype;
39011
39012 /* return error if TTY interface open */
39013- if (info->port.count)
39014+ if (atomic_read(&info->port.count))
39015 return -EBUSY;
39016
39017 switch (encoding)
39018@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
39019
39020 /* arbitrate between network and tty opens */
39021 spin_lock_irqsave(&info->netlock, flags);
39022- if (info->port.count != 0 || info->netcount != 0) {
39023+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39024 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39025 spin_unlock_irqrestore(&info->netlock, flags);
39026 return -EBUSY;
39027@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39028 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
39029
39030 /* return error if TTY interface open */
39031- if (info->port.count)
39032+ if (atomic_read(&info->port.count))
39033 return -EBUSY;
39034
39035 if (cmd != SIOCWANDEV)
39036diff --git a/drivers/char/random.c b/drivers/char/random.c
39037index 429b75b..a7f4145 100644
39038--- a/drivers/char/random.c
39039+++ b/drivers/char/random.c
39040@@ -270,10 +270,17 @@
39041 /*
39042 * Configuration information
39043 */
39044+#ifdef CONFIG_GRKERNSEC_RANDNET
39045+#define INPUT_POOL_SHIFT 14
39046+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
39047+#define OUTPUT_POOL_SHIFT 12
39048+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
39049+#else
39050 #define INPUT_POOL_SHIFT 12
39051 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
39052 #define OUTPUT_POOL_SHIFT 10
39053 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
39054+#endif
39055 #define SEC_XFER_SIZE 512
39056 #define EXTRACT_SIZE 10
39057
39058@@ -284,9 +291,6 @@
39059 /*
39060 * To allow fractional bits to be tracked, the entropy_count field is
39061 * denominated in units of 1/8th bits.
39062- *
39063- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
39064- * credit_entropy_bits() needs to be 64 bits wide.
39065 */
39066 #define ENTROPY_SHIFT 3
39067 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
39068@@ -361,12 +365,19 @@ static struct poolinfo {
39069 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
39070 int tap1, tap2, tap3, tap4, tap5;
39071 } poolinfo_table[] = {
39072+#ifdef CONFIG_GRKERNSEC_RANDNET
39073+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
39074+ { S(512), 411, 308, 208, 104, 1 },
39075+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
39076+ { S(128), 104, 76, 51, 25, 1 },
39077+#else
39078 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
39079 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
39080 { S(128), 104, 76, 51, 25, 1 },
39081 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
39082 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
39083 { S(32), 26, 19, 14, 7, 1 },
39084+#endif
39085 #if 0
39086 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
39087 { S(2048), 1638, 1231, 819, 411, 1 },
39088@@ -433,9 +444,9 @@ struct entropy_store {
39089 };
39090
39091 static void push_to_pool(struct work_struct *work);
39092-static __u32 input_pool_data[INPUT_POOL_WORDS];
39093-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39094-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39095+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39096+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39097+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39098
39099 static struct entropy_store input_pool = {
39100 .poolinfo = &poolinfo_table[0],
39101@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
39102 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
39103 }
39104
39105- ACCESS_ONCE(r->input_rotate) = input_rotate;
39106- ACCESS_ONCE(r->add_ptr) = i;
39107+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
39108+ ACCESS_ONCE_RW(r->add_ptr) = i;
39109 smp_wmb();
39110
39111 if (out)
39112@@ -632,7 +643,7 @@ retry:
39113 /* The +2 corresponds to the /4 in the denominator */
39114
39115 do {
39116- unsigned int anfrac = min(pnfrac, pool_size/2);
39117+ u64 anfrac = min(pnfrac, pool_size/2);
39118 unsigned int add =
39119 ((pool_size - entropy_count)*anfrac*3) >> s;
39120
39121@@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39122
39123 extract_buf(r, tmp);
39124 i = min_t(int, nbytes, EXTRACT_SIZE);
39125- if (copy_to_user(buf, tmp, i)) {
39126+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39127 ret = -EFAULT;
39128 break;
39129 }
39130@@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
39131 #include <linux/sysctl.h>
39132
39133 static int min_read_thresh = 8, min_write_thresh;
39134-static int max_read_thresh = INPUT_POOL_WORDS * 32;
39135+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
39136 static int max_write_thresh = INPUT_POOL_WORDS * 32;
39137 static char sysctl_bootid[16];
39138
39139@@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
39140 static int proc_do_uuid(struct ctl_table *table, int write,
39141 void __user *buffer, size_t *lenp, loff_t *ppos)
39142 {
39143- struct ctl_table fake_table;
39144+ ctl_table_no_const fake_table;
39145 unsigned char buf[64], tmp_uuid[16], *uuid;
39146
39147 uuid = table->data;
39148@@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39149 static int proc_do_entropy(ctl_table *table, int write,
39150 void __user *buffer, size_t *lenp, loff_t *ppos)
39151 {
39152- ctl_table fake_table;
39153+ ctl_table_no_const fake_table;
39154 int entropy_count;
39155
39156 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39157diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39158index 7cc1fe22..b602d6b 100644
39159--- a/drivers/char/sonypi.c
39160+++ b/drivers/char/sonypi.c
39161@@ -54,6 +54,7 @@
39162
39163 #include <asm/uaccess.h>
39164 #include <asm/io.h>
39165+#include <asm/local.h>
39166
39167 #include <linux/sonypi.h>
39168
39169@@ -490,7 +491,7 @@ static struct sonypi_device {
39170 spinlock_t fifo_lock;
39171 wait_queue_head_t fifo_proc_list;
39172 struct fasync_struct *fifo_async;
39173- int open_count;
39174+ local_t open_count;
39175 int model;
39176 struct input_dev *input_jog_dev;
39177 struct input_dev *input_key_dev;
39178@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39179 static int sonypi_misc_release(struct inode *inode, struct file *file)
39180 {
39181 mutex_lock(&sonypi_device.lock);
39182- sonypi_device.open_count--;
39183+ local_dec(&sonypi_device.open_count);
39184 mutex_unlock(&sonypi_device.lock);
39185 return 0;
39186 }
39187@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39188 {
39189 mutex_lock(&sonypi_device.lock);
39190 /* Flush input queue on first open */
39191- if (!sonypi_device.open_count)
39192+ if (!local_read(&sonypi_device.open_count))
39193 kfifo_reset(&sonypi_device.fifo);
39194- sonypi_device.open_count++;
39195+ local_inc(&sonypi_device.open_count);
39196 mutex_unlock(&sonypi_device.lock);
39197
39198 return 0;
39199diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39200index b9a57fa..5bb9e38 100644
39201--- a/drivers/char/tpm/tpm_acpi.c
39202+++ b/drivers/char/tpm/tpm_acpi.c
39203@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39204 virt = acpi_os_map_memory(start, len);
39205 if (!virt) {
39206 kfree(log->bios_event_log);
39207+ log->bios_event_log = NULL;
39208 printk("%s: ERROR - Unable to map memory\n", __func__);
39209 return -EIO;
39210 }
39211
39212- memcpy_fromio(log->bios_event_log, virt, len);
39213+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39214
39215 acpi_os_unmap_memory(virt, len);
39216 return 0;
39217diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39218index 59f7cb2..bac8b6d 100644
39219--- a/drivers/char/tpm/tpm_eventlog.c
39220+++ b/drivers/char/tpm/tpm_eventlog.c
39221@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39222 event = addr;
39223
39224 if ((event->event_type == 0 && event->event_size == 0) ||
39225- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39226+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39227 return NULL;
39228
39229 return addr;
39230@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39231 return NULL;
39232
39233 if ((event->event_type == 0 && event->event_size == 0) ||
39234- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39235+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39236 return NULL;
39237
39238 (*pos)++;
39239@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39240 int i;
39241
39242 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39243- seq_putc(m, data[i]);
39244+ if (!seq_putc(m, data[i]))
39245+ return -EFAULT;
39246
39247 return 0;
39248 }
39249diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39250index 6928d09..ff6abe8 100644
39251--- a/drivers/char/virtio_console.c
39252+++ b/drivers/char/virtio_console.c
39253@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39254 if (to_user) {
39255 ssize_t ret;
39256
39257- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39258+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39259 if (ret)
39260 return -EFAULT;
39261 } else {
39262@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39263 if (!port_has_data(port) && !port->host_connected)
39264 return 0;
39265
39266- return fill_readbuf(port, ubuf, count, true);
39267+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39268 }
39269
39270 static int wait_port_writable(struct port *port, bool nonblock)
39271diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39272index 57a078e..c17cde8 100644
39273--- a/drivers/clk/clk-composite.c
39274+++ b/drivers/clk/clk-composite.c
39275@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39276 struct clk *clk;
39277 struct clk_init_data init;
39278 struct clk_composite *composite;
39279- struct clk_ops *clk_composite_ops;
39280+ clk_ops_no_const *clk_composite_ops;
39281
39282 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39283 if (!composite) {
39284diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
39285index 5983a26..65d5f46 100644
39286--- a/drivers/clk/socfpga/clk.c
39287+++ b/drivers/clk/socfpga/clk.c
39288@@ -22,6 +22,7 @@
39289 #include <linux/clk-provider.h>
39290 #include <linux/io.h>
39291 #include <linux/of.h>
39292+#include <asm/pgtable.h>
39293
39294 /* Clock Manager offsets */
39295 #define CLKMGR_CTRL 0x0
39296@@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
39297 streq(clk_name, "periph_pll") ||
39298 streq(clk_name, "sdram_pll")) {
39299 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39300- clk_pll_ops.enable = clk_gate_ops.enable;
39301- clk_pll_ops.disable = clk_gate_ops.disable;
39302+ pax_open_kernel();
39303+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39304+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39305+ pax_close_kernel();
39306 }
39307
39308 clk = clk_register(NULL, &socfpga_clk->hw.hw);
39309@@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
39310 return parent_rate / div;
39311 }
39312
39313-static struct clk_ops gateclk_ops = {
39314+static clk_ops_no_const gateclk_ops __read_only = {
39315 .recalc_rate = socfpga_clk_recalc_rate,
39316 .get_parent = socfpga_clk_get_parent,
39317 .set_parent = socfpga_clk_set_parent,
39318diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39319index 18448a7..d5fad43 100644
39320--- a/drivers/cpufreq/acpi-cpufreq.c
39321+++ b/drivers/cpufreq/acpi-cpufreq.c
39322@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39323 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39324 per_cpu(acfreq_data, cpu) = data;
39325
39326- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39327- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39328+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39329+ pax_open_kernel();
39330+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39331+ pax_close_kernel();
39332+ }
39333
39334 result = acpi_processor_register_performance(data->acpi_data, cpu);
39335 if (result)
39336@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39337 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39338 break;
39339 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39340- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39341+ pax_open_kernel();
39342+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39343+ pax_close_kernel();
39344 break;
39345 default:
39346 break;
39347@@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
39348 if (!msrs)
39349 return;
39350
39351- acpi_cpufreq_driver.boost_supported = true;
39352- acpi_cpufreq_driver.boost_enabled = boost_state(0);
39353+ pax_open_kernel();
39354+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39355+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39356+ pax_close_kernel();
39357 get_online_cpus();
39358
39359 /* Force all MSRs to the same value */
39360diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39361index 199b52b..e3503bb 100644
39362--- a/drivers/cpufreq/cpufreq.c
39363+++ b/drivers/cpufreq/cpufreq.c
39364@@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39365 #endif
39366
39367 mutex_lock(&cpufreq_governor_mutex);
39368- list_del(&governor->governor_list);
39369+ pax_list_del(&governor->governor_list);
39370 mutex_unlock(&cpufreq_governor_mutex);
39371 return;
39372 }
39373@@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39374 return NOTIFY_OK;
39375 }
39376
39377-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39378+static struct notifier_block cpufreq_cpu_notifier = {
39379 .notifier_call = cpufreq_cpu_callback,
39380 };
39381
39382@@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
39383 return 0;
39384
39385 write_lock_irqsave(&cpufreq_driver_lock, flags);
39386- cpufreq_driver->boost_enabled = state;
39387+ pax_open_kernel();
39388+ *(bool *)&cpufreq_driver->boost_enabled = state;
39389+ pax_close_kernel();
39390 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39391
39392 ret = cpufreq_driver->set_boost(state);
39393 if (ret) {
39394 write_lock_irqsave(&cpufreq_driver_lock, flags);
39395- cpufreq_driver->boost_enabled = !state;
39396+ pax_open_kernel();
39397+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39398+ pax_close_kernel();
39399 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39400
39401 pr_err("%s: Cannot %s BOOST\n", __func__,
39402@@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39403
39404 pr_debug("trying to register driver %s\n", driver_data->name);
39405
39406- if (driver_data->setpolicy)
39407- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39408+ if (driver_data->setpolicy) {
39409+ pax_open_kernel();
39410+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39411+ pax_close_kernel();
39412+ }
39413
39414 write_lock_irqsave(&cpufreq_driver_lock, flags);
39415 if (cpufreq_driver) {
39416@@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39417 * Check if driver provides function to enable boost -
39418 * if not, use cpufreq_boost_set_sw as default
39419 */
39420- if (!cpufreq_driver->set_boost)
39421- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39422+ if (!cpufreq_driver->set_boost) {
39423+ pax_open_kernel();
39424+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39425+ pax_close_kernel();
39426+ }
39427
39428 ret = cpufreq_sysfs_create_file(&boost.attr);
39429 if (ret) {
39430diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39431index ba43991..23858ffb 100644
39432--- a/drivers/cpufreq/cpufreq_governor.c
39433+++ b/drivers/cpufreq/cpufreq_governor.c
39434@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39435 struct dbs_data *dbs_data;
39436 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39437 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39438- struct od_ops *od_ops = NULL;
39439+ const struct od_ops *od_ops = NULL;
39440 struct od_dbs_tuners *od_tuners = NULL;
39441 struct cs_dbs_tuners *cs_tuners = NULL;
39442 struct cpu_dbs_common_info *cpu_cdbs;
39443@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39444
39445 if ((cdata->governor == GOV_CONSERVATIVE) &&
39446 (!policy->governor->initialized)) {
39447- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39448+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39449
39450 cpufreq_register_notifier(cs_ops->notifier_block,
39451 CPUFREQ_TRANSITION_NOTIFIER);
39452@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39453
39454 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39455 (policy->governor->initialized == 1)) {
39456- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39457+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39458
39459 cpufreq_unregister_notifier(cs_ops->notifier_block,
39460 CPUFREQ_TRANSITION_NOTIFIER);
39461diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39462index bfb9ae1..e1d3a7e 100644
39463--- a/drivers/cpufreq/cpufreq_governor.h
39464+++ b/drivers/cpufreq/cpufreq_governor.h
39465@@ -205,7 +205,7 @@ struct common_dbs_data {
39466 void (*exit)(struct dbs_data *dbs_data);
39467
39468 /* Governor specific ops, see below */
39469- void *gov_ops;
39470+ const void *gov_ops;
39471 };
39472
39473 /* Governor Per policy data */
39474@@ -225,7 +225,7 @@ struct od_ops {
39475 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39476 unsigned int freq_next, unsigned int relation);
39477 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39478-};
39479+} __no_const;
39480
39481 struct cs_ops {
39482 struct notifier_block *notifier_block;
39483diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39484index 18d4091..434be15 100644
39485--- a/drivers/cpufreq/cpufreq_ondemand.c
39486+++ b/drivers/cpufreq/cpufreq_ondemand.c
39487@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39488
39489 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39490
39491-static struct od_ops od_ops = {
39492+static struct od_ops od_ops __read_only = {
39493 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39494 .powersave_bias_target = generic_powersave_bias_target,
39495 .freq_increase = dbs_freq_increase,
39496@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39497 (struct cpufreq_policy *, unsigned int, unsigned int),
39498 unsigned int powersave_bias)
39499 {
39500- od_ops.powersave_bias_target = f;
39501+ pax_open_kernel();
39502+ *(void **)&od_ops.powersave_bias_target = f;
39503+ pax_close_kernel();
39504 od_set_powersave_bias(powersave_bias);
39505 }
39506 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39507
39508 void od_unregister_powersave_bias_handler(void)
39509 {
39510- od_ops.powersave_bias_target = generic_powersave_bias_target;
39511+ pax_open_kernel();
39512+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39513+ pax_close_kernel();
39514 od_set_powersave_bias(0);
39515 }
39516 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39517diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39518index 2cd36b9..8f07fae 100644
39519--- a/drivers/cpufreq/intel_pstate.c
39520+++ b/drivers/cpufreq/intel_pstate.c
39521@@ -124,10 +124,10 @@ struct pstate_funcs {
39522 struct cpu_defaults {
39523 struct pstate_adjust_policy pid_policy;
39524 struct pstate_funcs funcs;
39525-};
39526+} __do_const;
39527
39528 static struct pstate_adjust_policy pid_params;
39529-static struct pstate_funcs pstate_funcs;
39530+static struct pstate_funcs *pstate_funcs;
39531
39532 struct perf_limits {
39533 int no_turbo;
39534@@ -518,7 +518,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39535
39536 cpu->pstate.current_pstate = pstate;
39537
39538- pstate_funcs.set(cpu, pstate);
39539+ pstate_funcs->set(cpu, pstate);
39540 }
39541
39542 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39543@@ -540,12 +540,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39544 {
39545 sprintf(cpu->name, "Intel 2nd generation core");
39546
39547- cpu->pstate.min_pstate = pstate_funcs.get_min();
39548- cpu->pstate.max_pstate = pstate_funcs.get_max();
39549- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39550+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39551+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39552+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39553
39554- if (pstate_funcs.get_vid)
39555- pstate_funcs.get_vid(cpu);
39556+ if (pstate_funcs->get_vid)
39557+ pstate_funcs->get_vid(cpu);
39558
39559 /*
39560 * goto max pstate so we don't slow up boot if we are built-in if we are
39561@@ -832,9 +832,9 @@ static int intel_pstate_msrs_not_valid(void)
39562 rdmsrl(MSR_IA32_APERF, aperf);
39563 rdmsrl(MSR_IA32_MPERF, mperf);
39564
39565- if (!pstate_funcs.get_max() ||
39566- !pstate_funcs.get_min() ||
39567- !pstate_funcs.get_turbo())
39568+ if (!pstate_funcs->get_max() ||
39569+ !pstate_funcs->get_min() ||
39570+ !pstate_funcs->get_turbo())
39571 return -ENODEV;
39572
39573 rdmsrl(MSR_IA32_APERF, tmp);
39574@@ -848,7 +848,7 @@ static int intel_pstate_msrs_not_valid(void)
39575 return 0;
39576 }
39577
39578-static void copy_pid_params(struct pstate_adjust_policy *policy)
39579+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39580 {
39581 pid_params.sample_rate_ms = policy->sample_rate_ms;
39582 pid_params.p_gain_pct = policy->p_gain_pct;
39583@@ -860,11 +860,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39584
39585 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39586 {
39587- pstate_funcs.get_max = funcs->get_max;
39588- pstate_funcs.get_min = funcs->get_min;
39589- pstate_funcs.get_turbo = funcs->get_turbo;
39590- pstate_funcs.set = funcs->set;
39591- pstate_funcs.get_vid = funcs->get_vid;
39592+ pstate_funcs = funcs;
39593 }
39594
39595 #if IS_ENABLED(CONFIG_ACPI)
39596diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39597index 3d1cba9..0ab21d2 100644
39598--- a/drivers/cpufreq/p4-clockmod.c
39599+++ b/drivers/cpufreq/p4-clockmod.c
39600@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39601 case 0x0F: /* Core Duo */
39602 case 0x16: /* Celeron Core */
39603 case 0x1C: /* Atom */
39604- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39605+ pax_open_kernel();
39606+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39607+ pax_close_kernel();
39608 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39609 case 0x0D: /* Pentium M (Dothan) */
39610- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39611+ pax_open_kernel();
39612+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39613+ pax_close_kernel();
39614 /* fall through */
39615 case 0x09: /* Pentium M (Banias) */
39616 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39617@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39618
39619 /* on P-4s, the TSC runs with constant frequency independent whether
39620 * throttling is active or not. */
39621- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39622+ pax_open_kernel();
39623+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39624+ pax_close_kernel();
39625
39626 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39627 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39628diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39629index 724ffbd..f06aaaa 100644
39630--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39631+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39632@@ -18,14 +18,12 @@
39633 #include <asm/head.h>
39634 #include <asm/timer.h>
39635
39636-static struct cpufreq_driver *cpufreq_us3_driver;
39637-
39638 struct us3_freq_percpu_info {
39639 struct cpufreq_frequency_table table[4];
39640 };
39641
39642 /* Indexed by cpu number. */
39643-static struct us3_freq_percpu_info *us3_freq_table;
39644+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39645
39646 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39647 * in the Safari config register.
39648@@ -156,18 +154,28 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39649
39650 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39651 {
39652- if (cpufreq_us3_driver) {
39653- cpufreq_frequency_table_put_attr(policy->cpu);
39654- us3_freq_target(policy, 0);
39655- }
39656+ cpufreq_frequency_table_put_attr(policy->cpu);
39657+ us3_freq_target(policy, 0);
39658
39659 return 0;
39660 }
39661
39662+static int __init us3_freq_init(void);
39663+static void __exit us3_freq_exit(void);
39664+
39665+static struct cpufreq_driver cpufreq_us3_driver = {
39666+ .init = us3_freq_cpu_init,
39667+ .verify = cpufreq_generic_frequency_table_verify,
39668+ .target_index = us3_freq_target,
39669+ .get = us3_freq_get,
39670+ .exit = us3_freq_cpu_exit,
39671+ .name = "UltraSPARC-III",
39672+
39673+};
39674+
39675 static int __init us3_freq_init(void)
39676 {
39677 unsigned long manuf, impl, ver;
39678- int ret;
39679
39680 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39681 return -ENODEV;
39682@@ -180,55 +188,15 @@ static int __init us3_freq_init(void)
39683 (impl == CHEETAH_IMPL ||
39684 impl == CHEETAH_PLUS_IMPL ||
39685 impl == JAGUAR_IMPL ||
39686- impl == PANTHER_IMPL)) {
39687- struct cpufreq_driver *driver;
39688-
39689- ret = -ENOMEM;
39690- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39691- if (!driver)
39692- goto err_out;
39693-
39694- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39695- GFP_KERNEL);
39696- if (!us3_freq_table)
39697- goto err_out;
39698-
39699- driver->init = us3_freq_cpu_init;
39700- driver->verify = cpufreq_generic_frequency_table_verify;
39701- driver->target_index = us3_freq_target;
39702- driver->get = us3_freq_get;
39703- driver->exit = us3_freq_cpu_exit;
39704- strcpy(driver->name, "UltraSPARC-III");
39705-
39706- cpufreq_us3_driver = driver;
39707- ret = cpufreq_register_driver(driver);
39708- if (ret)
39709- goto err_out;
39710-
39711- return 0;
39712-
39713-err_out:
39714- if (driver) {
39715- kfree(driver);
39716- cpufreq_us3_driver = NULL;
39717- }
39718- kfree(us3_freq_table);
39719- us3_freq_table = NULL;
39720- return ret;
39721- }
39722+ impl == PANTHER_IMPL))
39723+ return cpufreq_register_driver(&cpufreq_us3_driver);
39724
39725 return -ENODEV;
39726 }
39727
39728 static void __exit us3_freq_exit(void)
39729 {
39730- if (cpufreq_us3_driver) {
39731- cpufreq_unregister_driver(cpufreq_us3_driver);
39732- kfree(cpufreq_us3_driver);
39733- cpufreq_us3_driver = NULL;
39734- kfree(us3_freq_table);
39735- us3_freq_table = NULL;
39736- }
39737+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39738 }
39739
39740 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39741diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39742index 4e1daca..e707b61 100644
39743--- a/drivers/cpufreq/speedstep-centrino.c
39744+++ b/drivers/cpufreq/speedstep-centrino.c
39745@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39746 !cpu_has(cpu, X86_FEATURE_EST))
39747 return -ENODEV;
39748
39749- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39750- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39751+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39752+ pax_open_kernel();
39753+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39754+ pax_close_kernel();
39755+ }
39756
39757 if (policy->cpu != 0)
39758 return -ENODEV;
39759diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39760index 06dbe7c..c2c8671 100644
39761--- a/drivers/cpuidle/driver.c
39762+++ b/drivers/cpuidle/driver.c
39763@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39764
39765 static void poll_idle_init(struct cpuidle_driver *drv)
39766 {
39767- struct cpuidle_state *state = &drv->states[0];
39768+ cpuidle_state_no_const *state = &drv->states[0];
39769
39770 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39771 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39772diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39773index ca89412..a7b9c49 100644
39774--- a/drivers/cpuidle/governor.c
39775+++ b/drivers/cpuidle/governor.c
39776@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39777 mutex_lock(&cpuidle_lock);
39778 if (__cpuidle_find_governor(gov->name) == NULL) {
39779 ret = 0;
39780- list_add_tail(&gov->governor_list, &cpuidle_governors);
39781+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39782 if (!cpuidle_curr_governor ||
39783 cpuidle_curr_governor->rating < gov->rating)
39784 cpuidle_switch_governor(gov);
39785diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39786index e918b6d..f87ea80 100644
39787--- a/drivers/cpuidle/sysfs.c
39788+++ b/drivers/cpuidle/sysfs.c
39789@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39790 NULL
39791 };
39792
39793-static struct attribute_group cpuidle_attr_group = {
39794+static attribute_group_no_const cpuidle_attr_group = {
39795 .attrs = cpuidle_default_attrs,
39796 .name = "cpuidle",
39797 };
39798diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39799index 12fea3e..1e28f47 100644
39800--- a/drivers/crypto/hifn_795x.c
39801+++ b/drivers/crypto/hifn_795x.c
39802@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39803 MODULE_PARM_DESC(hifn_pll_ref,
39804 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39805
39806-static atomic_t hifn_dev_number;
39807+static atomic_unchecked_t hifn_dev_number;
39808
39809 #define ACRYPTO_OP_DECRYPT 0
39810 #define ACRYPTO_OP_ENCRYPT 1
39811@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39812 goto err_out_disable_pci_device;
39813
39814 snprintf(name, sizeof(name), "hifn%d",
39815- atomic_inc_return(&hifn_dev_number)-1);
39816+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39817
39818 err = pci_request_regions(pdev, name);
39819 if (err)
39820diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39821index a0b2f7e..1b6f028 100644
39822--- a/drivers/devfreq/devfreq.c
39823+++ b/drivers/devfreq/devfreq.c
39824@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39825 goto err_out;
39826 }
39827
39828- list_add(&governor->node, &devfreq_governor_list);
39829+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39830
39831 list_for_each_entry(devfreq, &devfreq_list, node) {
39832 int ret = 0;
39833@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39834 }
39835 }
39836
39837- list_del(&governor->node);
39838+ pax_list_del((struct list_head *)&governor->node);
39839 err_out:
39840 mutex_unlock(&devfreq_list_lock);
39841
39842diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39843index 2e7b394..1371a64 100644
39844--- a/drivers/dma/sh/shdma-base.c
39845+++ b/drivers/dma/sh/shdma-base.c
39846@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39847 schan->slave_id = -EINVAL;
39848 }
39849
39850- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39851- sdev->desc_size, GFP_KERNEL);
39852+ schan->desc = kcalloc(sdev->desc_size,
39853+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39854 if (!schan->desc) {
39855 ret = -ENOMEM;
39856 goto edescalloc;
39857diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39858index 0d765c0..60b7480 100644
39859--- a/drivers/dma/sh/shdmac.c
39860+++ b/drivers/dma/sh/shdmac.c
39861@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39862 return ret;
39863 }
39864
39865-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39866+static struct notifier_block sh_dmae_nmi_notifier = {
39867 .notifier_call = sh_dmae_nmi_handler,
39868
39869 /* Run before NMI debug handler and KGDB */
39870diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39871index 592af5f..bb1d583 100644
39872--- a/drivers/edac/edac_device.c
39873+++ b/drivers/edac/edac_device.c
39874@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39875 */
39876 int edac_device_alloc_index(void)
39877 {
39878- static atomic_t device_indexes = ATOMIC_INIT(0);
39879+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39880
39881- return atomic_inc_return(&device_indexes) - 1;
39882+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39883 }
39884 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39885
39886diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39887index b335c6a..db65b44 100644
39888--- a/drivers/edac/edac_mc_sysfs.c
39889+++ b/drivers/edac/edac_mc_sysfs.c
39890@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39891 struct dev_ch_attribute {
39892 struct device_attribute attr;
39893 int channel;
39894-};
39895+} __do_const;
39896
39897 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39898 struct dev_ch_attribute dev_attr_legacy_##_name = \
39899@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39900 }
39901
39902 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39903+ pax_open_kernel();
39904 if (mci->get_sdram_scrub_rate) {
39905- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39906- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39907+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39908+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39909 }
39910 if (mci->set_sdram_scrub_rate) {
39911- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39912- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39913+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39914+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39915 }
39916+ pax_close_kernel();
39917 err = device_create_file(&mci->dev,
39918 &dev_attr_sdram_scrub_rate);
39919 if (err) {
39920diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39921index 2cf44b4d..6dd2dc7 100644
39922--- a/drivers/edac/edac_pci.c
39923+++ b/drivers/edac/edac_pci.c
39924@@ -29,7 +29,7 @@
39925
39926 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39927 static LIST_HEAD(edac_pci_list);
39928-static atomic_t pci_indexes = ATOMIC_INIT(0);
39929+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39930
39931 /*
39932 * edac_pci_alloc_ctl_info
39933@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39934 */
39935 int edac_pci_alloc_index(void)
39936 {
39937- return atomic_inc_return(&pci_indexes) - 1;
39938+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39939 }
39940 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39941
39942diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39943index e8658e4..22746d6 100644
39944--- a/drivers/edac/edac_pci_sysfs.c
39945+++ b/drivers/edac/edac_pci_sysfs.c
39946@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39947 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39948 static int edac_pci_poll_msec = 1000; /* one second workq period */
39949
39950-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39951-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39952+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39953+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39954
39955 static struct kobject *edac_pci_top_main_kobj;
39956 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39957@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39958 void *value;
39959 ssize_t(*show) (void *, char *);
39960 ssize_t(*store) (void *, const char *, size_t);
39961-};
39962+} __do_const;
39963
39964 /* Set of show/store abstract level functions for PCI Parity object */
39965 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39966@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39967 edac_printk(KERN_CRIT, EDAC_PCI,
39968 "Signaled System Error on %s\n",
39969 pci_name(dev));
39970- atomic_inc(&pci_nonparity_count);
39971+ atomic_inc_unchecked(&pci_nonparity_count);
39972 }
39973
39974 if (status & (PCI_STATUS_PARITY)) {
39975@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39976 "Master Data Parity Error on %s\n",
39977 pci_name(dev));
39978
39979- atomic_inc(&pci_parity_count);
39980+ atomic_inc_unchecked(&pci_parity_count);
39981 }
39982
39983 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39984@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39985 "Detected Parity Error on %s\n",
39986 pci_name(dev));
39987
39988- atomic_inc(&pci_parity_count);
39989+ atomic_inc_unchecked(&pci_parity_count);
39990 }
39991 }
39992
39993@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39994 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39995 "Signaled System Error on %s\n",
39996 pci_name(dev));
39997- atomic_inc(&pci_nonparity_count);
39998+ atomic_inc_unchecked(&pci_nonparity_count);
39999 }
40000
40001 if (status & (PCI_STATUS_PARITY)) {
40002@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40003 "Master Data Parity Error on "
40004 "%s\n", pci_name(dev));
40005
40006- atomic_inc(&pci_parity_count);
40007+ atomic_inc_unchecked(&pci_parity_count);
40008 }
40009
40010 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40011@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40012 "Detected Parity Error on %s\n",
40013 pci_name(dev));
40014
40015- atomic_inc(&pci_parity_count);
40016+ atomic_inc_unchecked(&pci_parity_count);
40017 }
40018 }
40019 }
40020@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
40021 if (!check_pci_errors)
40022 return;
40023
40024- before_count = atomic_read(&pci_parity_count);
40025+ before_count = atomic_read_unchecked(&pci_parity_count);
40026
40027 /* scan all PCI devices looking for a Parity Error on devices and
40028 * bridges.
40029@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
40030 /* Only if operator has selected panic on PCI Error */
40031 if (edac_pci_get_panic_on_pe()) {
40032 /* If the count is different 'after' from 'before' */
40033- if (before_count != atomic_read(&pci_parity_count))
40034+ if (before_count != atomic_read_unchecked(&pci_parity_count))
40035 panic("EDAC: PCI Parity Error");
40036 }
40037 }
40038diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
40039index 51b7e3a..aa8a3e8 100644
40040--- a/drivers/edac/mce_amd.h
40041+++ b/drivers/edac/mce_amd.h
40042@@ -77,7 +77,7 @@ struct amd_decoder_ops {
40043 bool (*mc0_mce)(u16, u8);
40044 bool (*mc1_mce)(u16, u8);
40045 bool (*mc2_mce)(u16, u8);
40046-};
40047+} __no_const;
40048
40049 void amd_report_gart_errors(bool);
40050 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
40051diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
40052index 57ea7f4..af06b76 100644
40053--- a/drivers/firewire/core-card.c
40054+++ b/drivers/firewire/core-card.c
40055@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
40056 const struct fw_card_driver *driver,
40057 struct device *device)
40058 {
40059- static atomic_t index = ATOMIC_INIT(-1);
40060+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
40061
40062- card->index = atomic_inc_return(&index);
40063+ card->index = atomic_inc_return_unchecked(&index);
40064 card->driver = driver;
40065 card->device = device;
40066 card->current_tlabel = 0;
40067@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40068
40069 void fw_core_remove_card(struct fw_card *card)
40070 {
40071- struct fw_card_driver dummy_driver = dummy_driver_template;
40072+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
40073
40074 card->driver->update_phy_reg(card, 4,
40075 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40076diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40077index 2c6d5e1..a2cca6b 100644
40078--- a/drivers/firewire/core-device.c
40079+++ b/drivers/firewire/core-device.c
40080@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40081 struct config_rom_attribute {
40082 struct device_attribute attr;
40083 u32 key;
40084-};
40085+} __do_const;
40086
40087 static ssize_t show_immediate(struct device *dev,
40088 struct device_attribute *dattr, char *buf)
40089diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40090index eb6935c..3cc2bfa 100644
40091--- a/drivers/firewire/core-transaction.c
40092+++ b/drivers/firewire/core-transaction.c
40093@@ -38,6 +38,7 @@
40094 #include <linux/timer.h>
40095 #include <linux/types.h>
40096 #include <linux/workqueue.h>
40097+#include <linux/sched.h>
40098
40099 #include <asm/byteorder.h>
40100
40101diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40102index c98764a..551b520 100644
40103--- a/drivers/firewire/core.h
40104+++ b/drivers/firewire/core.h
40105@@ -111,6 +111,7 @@ struct fw_card_driver {
40106
40107 int (*stop_iso)(struct fw_iso_context *ctx);
40108 };
40109+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40110
40111 void fw_card_initialize(struct fw_card *card,
40112 const struct fw_card_driver *driver, struct device *device);
40113diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40114index 8db6632..9bbc8ca 100644
40115--- a/drivers/firewire/ohci.c
40116+++ b/drivers/firewire/ohci.c
40117@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
40118 be32_to_cpu(ohci->next_header));
40119 }
40120
40121+#ifndef CONFIG_GRKERNSEC
40122 if (param_remote_dma) {
40123 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40124 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40125 }
40126+#endif
40127
40128 spin_unlock_irq(&ohci->lock);
40129
40130@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40131 unsigned long flags;
40132 int n, ret = 0;
40133
40134+#ifndef CONFIG_GRKERNSEC
40135 if (param_remote_dma)
40136 return 0;
40137+#endif
40138
40139 /*
40140 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40141diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40142index 94a58a0..f5eba42 100644
40143--- a/drivers/firmware/dmi-id.c
40144+++ b/drivers/firmware/dmi-id.c
40145@@ -16,7 +16,7 @@
40146 struct dmi_device_attribute{
40147 struct device_attribute dev_attr;
40148 int field;
40149-};
40150+} __do_const;
40151 #define to_dmi_dev_attr(_dev_attr) \
40152 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40153
40154diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40155index 17afc51..0ef90cd 100644
40156--- a/drivers/firmware/dmi_scan.c
40157+++ b/drivers/firmware/dmi_scan.c
40158@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40159 if (buf == NULL)
40160 return -1;
40161
40162- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40163+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40164
40165 dmi_unmap(buf);
40166 return 0;
40167diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40168index 1491dd4..aa910db 100644
40169--- a/drivers/firmware/efi/cper.c
40170+++ b/drivers/firmware/efi/cper.c
40171@@ -41,12 +41,12 @@
40172 */
40173 u64 cper_next_record_id(void)
40174 {
40175- static atomic64_t seq;
40176+ static atomic64_unchecked_t seq;
40177
40178- if (!atomic64_read(&seq))
40179- atomic64_set(&seq, ((u64)get_seconds()) << 32);
40180+ if (!atomic64_read_unchecked(&seq))
40181+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40182
40183- return atomic64_inc_return(&seq);
40184+ return atomic64_inc_return_unchecked(&seq);
40185 }
40186 EXPORT_SYMBOL_GPL(cper_next_record_id);
40187
40188diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40189index 4753bac..02861a2 100644
40190--- a/drivers/firmware/efi/efi.c
40191+++ b/drivers/firmware/efi/efi.c
40192@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
40193 };
40194
40195 static struct efivars generic_efivars;
40196-static struct efivar_operations generic_ops;
40197+static efivar_operations_no_const generic_ops __read_only;
40198
40199 static int generic_ops_register(void)
40200 {
40201- generic_ops.get_variable = efi.get_variable;
40202- generic_ops.set_variable = efi.set_variable;
40203- generic_ops.get_next_variable = efi.get_next_variable;
40204- generic_ops.query_variable_store = efi_query_variable_store;
40205+ pax_open_kernel();
40206+ *(void **)&generic_ops.get_variable = efi.get_variable;
40207+ *(void **)&generic_ops.set_variable = efi.set_variable;
40208+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40209+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40210+ pax_close_kernel();
40211
40212 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40213 }
40214diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40215index 3dc2482..7bd2f61 100644
40216--- a/drivers/firmware/efi/efivars.c
40217+++ b/drivers/firmware/efi/efivars.c
40218@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40219 static int
40220 create_efivars_bin_attributes(void)
40221 {
40222- struct bin_attribute *attr;
40223+ bin_attribute_no_const *attr;
40224 int error;
40225
40226 /* new_var */
40227diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40228index 2a90ba6..07f3733 100644
40229--- a/drivers/firmware/google/memconsole.c
40230+++ b/drivers/firmware/google/memconsole.c
40231@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
40232 if (!found_memconsole())
40233 return -ENODEV;
40234
40235- memconsole_bin_attr.size = memconsole_length;
40236+ pax_open_kernel();
40237+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40238+ pax_close_kernel();
40239
40240 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40241
40242diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40243index 1e98a98..b444372 100644
40244--- a/drivers/gpio/gpio-em.c
40245+++ b/drivers/gpio/gpio-em.c
40246@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40247 struct em_gio_priv *p;
40248 struct resource *io[2], *irq[2];
40249 struct gpio_chip *gpio_chip;
40250- struct irq_chip *irq_chip;
40251+ irq_chip_no_const *irq_chip;
40252 const char *name = dev_name(&pdev->dev);
40253 int ret;
40254
40255diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40256index f5bf3c3..7baaa59 100644
40257--- a/drivers/gpio/gpio-ich.c
40258+++ b/drivers/gpio/gpio-ich.c
40259@@ -71,7 +71,7 @@ struct ichx_desc {
40260 /* Some chipsets have quirks, let these use their own request/get */
40261 int (*request)(struct gpio_chip *chip, unsigned offset);
40262 int (*get)(struct gpio_chip *chip, unsigned offset);
40263-};
40264+} __do_const;
40265
40266 static struct {
40267 spinlock_t lock;
40268diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40269index ca76ce7..68b384b 100644
40270--- a/drivers/gpio/gpio-rcar.c
40271+++ b/drivers/gpio/gpio-rcar.c
40272@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40273 struct gpio_rcar_priv *p;
40274 struct resource *io, *irq;
40275 struct gpio_chip *gpio_chip;
40276- struct irq_chip *irq_chip;
40277+ irq_chip_no_const *irq_chip;
40278 const char *name = dev_name(&pdev->dev);
40279 int ret;
40280
40281diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40282index 9902732..64b62dd 100644
40283--- a/drivers/gpio/gpio-vr41xx.c
40284+++ b/drivers/gpio/gpio-vr41xx.c
40285@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
40286 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40287 maskl, pendl, maskh, pendh);
40288
40289- atomic_inc(&irq_err_count);
40290+ atomic_inc_unchecked(&irq_err_count);
40291
40292 return -EINVAL;
40293 }
40294diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40295index 3b7d32d..05c2f74 100644
40296--- a/drivers/gpu/drm/drm_crtc.c
40297+++ b/drivers/gpu/drm/drm_crtc.c
40298@@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40299 goto done;
40300 }
40301
40302- if (copy_to_user(&enum_ptr[copied].name,
40303+ if (copy_to_user(enum_ptr[copied].name,
40304 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40305 ret = -EFAULT;
40306 goto done;
40307diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40308index 345be03..158368d 100644
40309--- a/drivers/gpu/drm/drm_drv.c
40310+++ b/drivers/gpu/drm/drm_drv.c
40311@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
40312 /**
40313 * Copy and IOCTL return string to user space
40314 */
40315-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
40316+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
40317 {
40318 int len;
40319
40320@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
40321 struct drm_file *file_priv = filp->private_data;
40322 struct drm_device *dev;
40323 const struct drm_ioctl_desc *ioctl = NULL;
40324- drm_ioctl_t *func;
40325+ drm_ioctl_no_const_t func;
40326 unsigned int nr = DRM_IOCTL_NR(cmd);
40327 int retcode = -EINVAL;
40328 char stack_kdata[128];
40329diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40330index 7f2af9a..1561914 100644
40331--- a/drivers/gpu/drm/drm_fops.c
40332+++ b/drivers/gpu/drm/drm_fops.c
40333@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
40334 if (drm_device_is_unplugged(dev))
40335 return -ENODEV;
40336
40337- if (!dev->open_count++)
40338+ if (local_inc_return(&dev->open_count) == 1)
40339 need_setup = 1;
40340 mutex_lock(&dev->struct_mutex);
40341 old_imapping = inode->i_mapping;
40342@@ -127,7 +127,7 @@ err_undo:
40343 iput(container_of(dev->dev_mapping, struct inode, i_data));
40344 dev->dev_mapping = old_mapping;
40345 mutex_unlock(&dev->struct_mutex);
40346- dev->open_count--;
40347+ local_dec(&dev->open_count);
40348 return retcode;
40349 }
40350 EXPORT_SYMBOL(drm_open);
40351@@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
40352
40353 mutex_lock(&drm_global_mutex);
40354
40355- DRM_DEBUG("open_count = %d\n", dev->open_count);
40356+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40357
40358 if (dev->driver->preclose)
40359 dev->driver->preclose(dev, file_priv);
40360@@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
40361 * Begin inline drm_release
40362 */
40363
40364- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40365+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40366 task_pid_nr(current),
40367 (long)old_encode_dev(file_priv->minor->device),
40368- dev->open_count);
40369+ local_read(&dev->open_count));
40370
40371 /* Release any auth tokens that might point to this file_priv,
40372 (do that under the drm_global_mutex) */
40373@@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
40374 * End inline drm_release
40375 */
40376
40377- if (!--dev->open_count) {
40378+ if (local_dec_and_test(&dev->open_count)) {
40379 retcode = drm_lastclose(dev);
40380 if (drm_device_is_unplugged(dev))
40381 drm_put_dev(dev);
40382diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40383index 3d2e91c..d31c4c9 100644
40384--- a/drivers/gpu/drm/drm_global.c
40385+++ b/drivers/gpu/drm/drm_global.c
40386@@ -36,7 +36,7 @@
40387 struct drm_global_item {
40388 struct mutex mutex;
40389 void *object;
40390- int refcount;
40391+ atomic_t refcount;
40392 };
40393
40394 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40395@@ -49,7 +49,7 @@ void drm_global_init(void)
40396 struct drm_global_item *item = &glob[i];
40397 mutex_init(&item->mutex);
40398 item->object = NULL;
40399- item->refcount = 0;
40400+ atomic_set(&item->refcount, 0);
40401 }
40402 }
40403
40404@@ -59,7 +59,7 @@ void drm_global_release(void)
40405 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40406 struct drm_global_item *item = &glob[i];
40407 BUG_ON(item->object != NULL);
40408- BUG_ON(item->refcount != 0);
40409+ BUG_ON(atomic_read(&item->refcount) != 0);
40410 }
40411 }
40412
40413@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40414 struct drm_global_item *item = &glob[ref->global_type];
40415
40416 mutex_lock(&item->mutex);
40417- if (item->refcount == 0) {
40418+ if (atomic_read(&item->refcount) == 0) {
40419 item->object = kzalloc(ref->size, GFP_KERNEL);
40420 if (unlikely(item->object == NULL)) {
40421 ret = -ENOMEM;
40422@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40423 goto out_err;
40424
40425 }
40426- ++item->refcount;
40427+ atomic_inc(&item->refcount);
40428 ref->object = item->object;
40429 mutex_unlock(&item->mutex);
40430 return 0;
40431@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40432 struct drm_global_item *item = &glob[ref->global_type];
40433
40434 mutex_lock(&item->mutex);
40435- BUG_ON(item->refcount == 0);
40436+ BUG_ON(atomic_read(&item->refcount) == 0);
40437 BUG_ON(ref->object != item->object);
40438- if (--item->refcount == 0) {
40439+ if (atomic_dec_and_test(&item->refcount)) {
40440 ref->release(ref);
40441 item->object = NULL;
40442 }
40443diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40444index 7473035..a48b9c5 100644
40445--- a/drivers/gpu/drm/drm_info.c
40446+++ b/drivers/gpu/drm/drm_info.c
40447@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40448 struct drm_local_map *map;
40449 struct drm_map_list *r_list;
40450
40451- /* Hardcoded from _DRM_FRAME_BUFFER,
40452- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40453- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40454- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40455+ static const char * const types[] = {
40456+ [_DRM_FRAME_BUFFER] = "FB",
40457+ [_DRM_REGISTERS] = "REG",
40458+ [_DRM_SHM] = "SHM",
40459+ [_DRM_AGP] = "AGP",
40460+ [_DRM_SCATTER_GATHER] = "SG",
40461+ [_DRM_CONSISTENT] = "PCI"};
40462 const char *type;
40463 int i;
40464
40465@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40466 map = r_list->map;
40467 if (!map)
40468 continue;
40469- if (map->type < 0 || map->type > 5)
40470+ if (map->type >= ARRAY_SIZE(types))
40471 type = "??";
40472 else
40473 type = types[map->type];
40474@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40475 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40476 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40477 vma->vm_flags & VM_IO ? 'i' : '-',
40478+#ifdef CONFIG_GRKERNSEC_HIDESYM
40479+ 0);
40480+#else
40481 vma->vm_pgoff);
40482+#endif
40483
40484 #if defined(__i386__)
40485 pgprot = pgprot_val(vma->vm_page_prot);
40486diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40487index 2f4c4343..dd12cd2 100644
40488--- a/drivers/gpu/drm/drm_ioc32.c
40489+++ b/drivers/gpu/drm/drm_ioc32.c
40490@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40491 request = compat_alloc_user_space(nbytes);
40492 if (!access_ok(VERIFY_WRITE, request, nbytes))
40493 return -EFAULT;
40494- list = (struct drm_buf_desc *) (request + 1);
40495+ list = (struct drm_buf_desc __user *) (request + 1);
40496
40497 if (__put_user(count, &request->count)
40498 || __put_user(list, &request->list))
40499@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40500 request = compat_alloc_user_space(nbytes);
40501 if (!access_ok(VERIFY_WRITE, request, nbytes))
40502 return -EFAULT;
40503- list = (struct drm_buf_pub *) (request + 1);
40504+ list = (struct drm_buf_pub __user *) (request + 1);
40505
40506 if (__put_user(count, &request->count)
40507 || __put_user(list, &request->list))
40508@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40509 return 0;
40510 }
40511
40512-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40513+drm_ioctl_compat_t drm_compat_ioctls[] = {
40514 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40515 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40516 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40517@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40518 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40519 {
40520 unsigned int nr = DRM_IOCTL_NR(cmd);
40521- drm_ioctl_compat_t *fn;
40522 int ret;
40523
40524 /* Assume that ioctls without an explicit compat routine will just
40525@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40526 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40527 return drm_ioctl(filp, cmd, arg);
40528
40529- fn = drm_compat_ioctls[nr];
40530-
40531- if (fn != NULL)
40532- ret = (*fn) (filp, cmd, arg);
40533+ if (drm_compat_ioctls[nr] != NULL)
40534+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40535 else
40536 ret = drm_ioctl(filp, cmd, arg);
40537
40538diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40539index 98a33c580..8fd1c2b 100644
40540--- a/drivers/gpu/drm/drm_stub.c
40541+++ b/drivers/gpu/drm/drm_stub.c
40542@@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
40543
40544 drm_device_set_unplugged(dev);
40545
40546- if (dev->open_count == 0) {
40547+ if (local_read(&dev->open_count) == 0) {
40548 drm_put_dev(dev);
40549 }
40550 mutex_unlock(&drm_global_mutex);
40551diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40552index c22c309..ae758c3 100644
40553--- a/drivers/gpu/drm/drm_sysfs.c
40554+++ b/drivers/gpu/drm/drm_sysfs.c
40555@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40556 */
40557 int drm_sysfs_device_add(struct drm_minor *minor)
40558 {
40559- char *minor_str;
40560+ const char *minor_str;
40561 int r;
40562
40563 if (minor->type == DRM_MINOR_CONTROL)
40564diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40565index d4d16ed..8fb0b51 100644
40566--- a/drivers/gpu/drm/i810/i810_drv.h
40567+++ b/drivers/gpu/drm/i810/i810_drv.h
40568@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40569 int page_flipping;
40570
40571 wait_queue_head_t irq_queue;
40572- atomic_t irq_received;
40573- atomic_t irq_emitted;
40574+ atomic_unchecked_t irq_received;
40575+ atomic_unchecked_t irq_emitted;
40576
40577 int front_offset;
40578 } drm_i810_private_t;
40579diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40580index b2b46c5..feb9fe7 100644
40581--- a/drivers/gpu/drm/i915/i915_debugfs.c
40582+++ b/drivers/gpu/drm/i915/i915_debugfs.c
40583@@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40584 I915_READ(GTIMR));
40585 }
40586 seq_printf(m, "Interrupts received: %d\n",
40587- atomic_read(&dev_priv->irq_received));
40588+ atomic_read_unchecked(&dev_priv->irq_received));
40589 for_each_ring(ring, dev_priv, i) {
40590 if (INTEL_INFO(dev)->gen >= 6) {
40591 seq_printf(m,
40592diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40593index 15a74f9..4278889 100644
40594--- a/drivers/gpu/drm/i915/i915_dma.c
40595+++ b/drivers/gpu/drm/i915/i915_dma.c
40596@@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40597 bool can_switch;
40598
40599 spin_lock(&dev->count_lock);
40600- can_switch = (dev->open_count == 0);
40601+ can_switch = (local_read(&dev->open_count) == 0);
40602 spin_unlock(&dev->count_lock);
40603 return can_switch;
40604 }
40605diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40606index df77e20..d3fda9f 100644
40607--- a/drivers/gpu/drm/i915/i915_drv.h
40608+++ b/drivers/gpu/drm/i915/i915_drv.h
40609@@ -1361,7 +1361,7 @@ typedef struct drm_i915_private {
40610 drm_dma_handle_t *status_page_dmah;
40611 struct resource mch_res;
40612
40613- atomic_t irq_received;
40614+ atomic_unchecked_t irq_received;
40615
40616 /* protects the irq masks */
40617 spinlock_t irq_lock;
40618diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40619index d269ecf..6d857bc 100644
40620--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40621+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40622@@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40623
40624 static int
40625 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40626- int count)
40627+ unsigned int count)
40628 {
40629- int i;
40630+ unsigned int i;
40631 unsigned relocs_total = 0;
40632 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40633
40634diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40635index 3c59584..500f2e9 100644
40636--- a/drivers/gpu/drm/i915/i915_ioc32.c
40637+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40638@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40639 (unsigned long)request);
40640 }
40641
40642-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40643+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40644 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40645 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40646 [DRM_I915_GETPARAM] = compat_i915_getparam,
40647@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40648 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40649 {
40650 unsigned int nr = DRM_IOCTL_NR(cmd);
40651- drm_ioctl_compat_t *fn = NULL;
40652 int ret;
40653
40654 if (nr < DRM_COMMAND_BASE)
40655 return drm_compat_ioctl(filp, cmd, arg);
40656
40657- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40658- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40659-
40660- if (fn != NULL)
40661+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40662+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40663 ret = (*fn) (filp, cmd, arg);
40664- else
40665+ } else
40666 ret = drm_ioctl(filp, cmd, arg);
40667
40668 return ret;
40669diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40670index d554169..f4426bb 100644
40671--- a/drivers/gpu/drm/i915/i915_irq.c
40672+++ b/drivers/gpu/drm/i915/i915_irq.c
40673@@ -1438,7 +1438,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40674 int pipe;
40675 u32 pipe_stats[I915_MAX_PIPES];
40676
40677- atomic_inc(&dev_priv->irq_received);
40678+ atomic_inc_unchecked(&dev_priv->irq_received);
40679
40680 while (true) {
40681 iir = I915_READ(VLV_IIR);
40682@@ -1751,7 +1751,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40683 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40684 irqreturn_t ret = IRQ_NONE;
40685
40686- atomic_inc(&dev_priv->irq_received);
40687+ atomic_inc_unchecked(&dev_priv->irq_received);
40688
40689 /* We get interrupts on unclaimed registers, so check for this before we
40690 * do any I915_{READ,WRITE}. */
40691@@ -1821,7 +1821,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40692 uint32_t tmp = 0;
40693 enum pipe pipe;
40694
40695- atomic_inc(&dev_priv->irq_received);
40696+ atomic_inc_unchecked(&dev_priv->irq_received);
40697
40698 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40699 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40700@@ -2645,7 +2645,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40701 {
40702 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40703
40704- atomic_set(&dev_priv->irq_received, 0);
40705+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40706
40707 I915_WRITE(HWSTAM, 0xeffe);
40708
40709@@ -2663,7 +2663,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40710 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40711 int pipe;
40712
40713- atomic_set(&dev_priv->irq_received, 0);
40714+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40715
40716 /* VLV magic */
40717 I915_WRITE(VLV_IMR, 0);
40718@@ -2694,7 +2694,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40719 struct drm_i915_private *dev_priv = dev->dev_private;
40720 int pipe;
40721
40722- atomic_set(&dev_priv->irq_received, 0);
40723+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40724
40725 I915_WRITE(GEN8_MASTER_IRQ, 0);
40726 POSTING_READ(GEN8_MASTER_IRQ);
40727@@ -3018,7 +3018,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40728 if (!dev_priv)
40729 return;
40730
40731- atomic_set(&dev_priv->irq_received, 0);
40732+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40733
40734 I915_WRITE(GEN8_MASTER_IRQ, 0);
40735
40736@@ -3112,7 +3112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40737 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40738 int pipe;
40739
40740- atomic_set(&dev_priv->irq_received, 0);
40741+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40742
40743 for_each_pipe(pipe)
40744 I915_WRITE(PIPESTAT(pipe), 0);
40745@@ -3198,7 +3198,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40746 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40747 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40748
40749- atomic_inc(&dev_priv->irq_received);
40750+ atomic_inc_unchecked(&dev_priv->irq_received);
40751
40752 iir = I915_READ16(IIR);
40753 if (iir == 0)
40754@@ -3277,7 +3277,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40755 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40756 int pipe;
40757
40758- atomic_set(&dev_priv->irq_received, 0);
40759+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40760
40761 if (I915_HAS_HOTPLUG(dev)) {
40762 I915_WRITE(PORT_HOTPLUG_EN, 0);
40763@@ -3384,7 +3384,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40764 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40765 int pipe, ret = IRQ_NONE;
40766
40767- atomic_inc(&dev_priv->irq_received);
40768+ atomic_inc_unchecked(&dev_priv->irq_received);
40769
40770 iir = I915_READ(IIR);
40771 do {
40772@@ -3511,7 +3511,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40773 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40774 int pipe;
40775
40776- atomic_set(&dev_priv->irq_received, 0);
40777+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40778
40779 I915_WRITE(PORT_HOTPLUG_EN, 0);
40780 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40781@@ -3627,7 +3627,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40782 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40783 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40784
40785- atomic_inc(&dev_priv->irq_received);
40786+ atomic_inc_unchecked(&dev_priv->irq_received);
40787
40788 iir = I915_READ(IIR);
40789
40790diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40791index 9b8a7c7..60f6003 100644
40792--- a/drivers/gpu/drm/i915/intel_display.c
40793+++ b/drivers/gpu/drm/i915/intel_display.c
40794@@ -10776,13 +10776,13 @@ struct intel_quirk {
40795 int subsystem_vendor;
40796 int subsystem_device;
40797 void (*hook)(struct drm_device *dev);
40798-};
40799+} __do_const;
40800
40801 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40802 struct intel_dmi_quirk {
40803 void (*hook)(struct drm_device *dev);
40804 const struct dmi_system_id (*dmi_id_list)[];
40805-};
40806+} __do_const;
40807
40808 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40809 {
40810@@ -10790,18 +10790,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40811 return 1;
40812 }
40813
40814-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40815+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40816 {
40817- .dmi_id_list = &(const struct dmi_system_id[]) {
40818- {
40819- .callback = intel_dmi_reverse_brightness,
40820- .ident = "NCR Corporation",
40821- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40822- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40823- },
40824- },
40825- { } /* terminating entry */
40826+ .callback = intel_dmi_reverse_brightness,
40827+ .ident = "NCR Corporation",
40828+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40829+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40830 },
40831+ },
40832+ { } /* terminating entry */
40833+};
40834+
40835+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40836+ {
40837+ .dmi_id_list = &intel_dmi_quirks_table,
40838 .hook = quirk_invert_brightness,
40839 },
40840 };
40841diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40842index fe45321..836fdca 100644
40843--- a/drivers/gpu/drm/mga/mga_drv.h
40844+++ b/drivers/gpu/drm/mga/mga_drv.h
40845@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40846 u32 clear_cmd;
40847 u32 maccess;
40848
40849- atomic_t vbl_received; /**< Number of vblanks received. */
40850+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40851 wait_queue_head_t fence_queue;
40852- atomic_t last_fence_retired;
40853+ atomic_unchecked_t last_fence_retired;
40854 u32 next_fence_to_post;
40855
40856 unsigned int fb_cpp;
40857diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40858index 86b4bb8..ae237ad 100644
40859--- a/drivers/gpu/drm/mga/mga_ioc32.c
40860+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40861@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40862 return 0;
40863 }
40864
40865-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40866+drm_ioctl_compat_t mga_compat_ioctls[] = {
40867 [DRM_MGA_INIT] = compat_mga_init,
40868 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40869 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40870@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40871 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40872 {
40873 unsigned int nr = DRM_IOCTL_NR(cmd);
40874- drm_ioctl_compat_t *fn = NULL;
40875 int ret;
40876
40877 if (nr < DRM_COMMAND_BASE)
40878 return drm_compat_ioctl(filp, cmd, arg);
40879
40880- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40881- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40882-
40883- if (fn != NULL)
40884+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40885+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40886 ret = (*fn) (filp, cmd, arg);
40887- else
40888+ } else
40889 ret = drm_ioctl(filp, cmd, arg);
40890
40891 return ret;
40892diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40893index 1b071b8..de8601a 100644
40894--- a/drivers/gpu/drm/mga/mga_irq.c
40895+++ b/drivers/gpu/drm/mga/mga_irq.c
40896@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40897 if (crtc != 0)
40898 return 0;
40899
40900- return atomic_read(&dev_priv->vbl_received);
40901+ return atomic_read_unchecked(&dev_priv->vbl_received);
40902 }
40903
40904
40905@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40906 /* VBLANK interrupt */
40907 if (status & MGA_VLINEPEN) {
40908 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40909- atomic_inc(&dev_priv->vbl_received);
40910+ atomic_inc_unchecked(&dev_priv->vbl_received);
40911 drm_handle_vblank(dev, 0);
40912 handled = 1;
40913 }
40914@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40915 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40916 MGA_WRITE(MGA_PRIMEND, prim_end);
40917
40918- atomic_inc(&dev_priv->last_fence_retired);
40919+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40920 wake_up(&dev_priv->fence_queue);
40921 handled = 1;
40922 }
40923@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40924 * using fences.
40925 */
40926 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40927- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40928+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40929 - *sequence) <= (1 << 23)));
40930
40931 *sequence = cur_fence;
40932diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40933index 4c3feaa..26391ce 100644
40934--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40935+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40936@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40937 struct bit_table {
40938 const char id;
40939 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40940-};
40941+} __no_const;
40942
40943 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40944
40945diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40946index 23ca7a5..b6c955d 100644
40947--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40948+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40949@@ -97,7 +97,6 @@ struct nouveau_drm {
40950 struct drm_global_reference mem_global_ref;
40951 struct ttm_bo_global_ref bo_global_ref;
40952 struct ttm_bo_device bdev;
40953- atomic_t validate_sequence;
40954 int (*move)(struct nouveau_channel *,
40955 struct ttm_buffer_object *,
40956 struct ttm_mem_reg *, struct ttm_mem_reg *);
40957diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40958index c1a7e5a..38b8539 100644
40959--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40960+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40961@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40962 unsigned long arg)
40963 {
40964 unsigned int nr = DRM_IOCTL_NR(cmd);
40965- drm_ioctl_compat_t *fn = NULL;
40966+ drm_ioctl_compat_t fn = NULL;
40967 int ret;
40968
40969 if (nr < DRM_COMMAND_BASE)
40970diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40971index d45d50d..72a5dd2 100644
40972--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40973+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40974@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40975 }
40976
40977 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40978- nouveau_vram_manager_init,
40979- nouveau_vram_manager_fini,
40980- nouveau_vram_manager_new,
40981- nouveau_vram_manager_del,
40982- nouveau_vram_manager_debug
40983+ .init = nouveau_vram_manager_init,
40984+ .takedown = nouveau_vram_manager_fini,
40985+ .get_node = nouveau_vram_manager_new,
40986+ .put_node = nouveau_vram_manager_del,
40987+ .debug = nouveau_vram_manager_debug
40988 };
40989
40990 static int
40991@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40992 }
40993
40994 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40995- nouveau_gart_manager_init,
40996- nouveau_gart_manager_fini,
40997- nouveau_gart_manager_new,
40998- nouveau_gart_manager_del,
40999- nouveau_gart_manager_debug
41000+ .init = nouveau_gart_manager_init,
41001+ .takedown = nouveau_gart_manager_fini,
41002+ .get_node = nouveau_gart_manager_new,
41003+ .put_node = nouveau_gart_manager_del,
41004+ .debug = nouveau_gart_manager_debug
41005 };
41006
41007 #include <core/subdev/vm/nv04.h>
41008@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41009 }
41010
41011 const struct ttm_mem_type_manager_func nv04_gart_manager = {
41012- nv04_gart_manager_init,
41013- nv04_gart_manager_fini,
41014- nv04_gart_manager_new,
41015- nv04_gart_manager_del,
41016- nv04_gart_manager_debug
41017+ .init = nv04_gart_manager_init,
41018+ .takedown = nv04_gart_manager_fini,
41019+ .get_node = nv04_gart_manager_new,
41020+ .put_node = nv04_gart_manager_del,
41021+ .debug = nv04_gart_manager_debug
41022 };
41023
41024 int
41025diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
41026index 471347e..5adc6b9 100644
41027--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
41028+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
41029@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
41030 bool can_switch;
41031
41032 spin_lock(&dev->count_lock);
41033- can_switch = (dev->open_count == 0);
41034+ can_switch = (local_read(&dev->open_count) == 0);
41035 spin_unlock(&dev->count_lock);
41036 return can_switch;
41037 }
41038diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
41039index eb89653..613cf71 100644
41040--- a/drivers/gpu/drm/qxl/qxl_cmd.c
41041+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
41042@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
41043 int ret;
41044
41045 mutex_lock(&qdev->async_io_mutex);
41046- irq_num = atomic_read(&qdev->irq_received_io_cmd);
41047+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41048 if (qdev->last_sent_io_cmd > irq_num) {
41049 if (intr)
41050 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41051- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41052+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41053 else
41054 ret = wait_event_timeout(qdev->io_cmd_event,
41055- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41056+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41057 /* 0 is timeout, just bail the "hw" has gone away */
41058 if (ret <= 0)
41059 goto out;
41060- irq_num = atomic_read(&qdev->irq_received_io_cmd);
41061+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41062 }
41063 outb(val, addr);
41064 qdev->last_sent_io_cmd = irq_num + 1;
41065 if (intr)
41066 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41067- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41068+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41069 else
41070 ret = wait_event_timeout(qdev->io_cmd_event,
41071- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41072+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41073 out:
41074 if (ret > 0)
41075 ret = 0;
41076diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
41077index c3c2bbd..bc3c0fb 100644
41078--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
41079+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
41080@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
41081 struct drm_info_node *node = (struct drm_info_node *) m->private;
41082 struct qxl_device *qdev = node->minor->dev->dev_private;
41083
41084- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
41085- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
41086- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
41087- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
41088+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
41089+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
41090+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
41091+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
41092 seq_printf(m, "%d\n", qdev->irq_received_error);
41093 return 0;
41094 }
41095diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
41096index 36ed40b..0397633 100644
41097--- a/drivers/gpu/drm/qxl/qxl_drv.h
41098+++ b/drivers/gpu/drm/qxl/qxl_drv.h
41099@@ -290,10 +290,10 @@ struct qxl_device {
41100 unsigned int last_sent_io_cmd;
41101
41102 /* interrupt handling */
41103- atomic_t irq_received;
41104- atomic_t irq_received_display;
41105- atomic_t irq_received_cursor;
41106- atomic_t irq_received_io_cmd;
41107+ atomic_unchecked_t irq_received;
41108+ atomic_unchecked_t irq_received_display;
41109+ atomic_unchecked_t irq_received_cursor;
41110+ atomic_unchecked_t irq_received_io_cmd;
41111 unsigned irq_received_error;
41112 wait_queue_head_t display_event;
41113 wait_queue_head_t cursor_event;
41114diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
41115index 0bb86e6..d41416d 100644
41116--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
41117+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
41118@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41119
41120 /* TODO copy slow path code from i915 */
41121 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
41122- 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);
41123+ 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);
41124
41125 {
41126 struct qxl_drawable *draw = fb_cmd;
41127@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41128 struct drm_qxl_reloc reloc;
41129
41130 if (copy_from_user(&reloc,
41131- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
41132+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
41133 sizeof(reloc))) {
41134 ret = -EFAULT;
41135 goto out_free_bos;
41136@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
41137
41138 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
41139
41140- struct drm_qxl_command *commands =
41141- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
41142+ struct drm_qxl_command __user *commands =
41143+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
41144
41145- if (copy_from_user(&user_cmd, &commands[cmd_num],
41146+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
41147 sizeof(user_cmd)))
41148 return -EFAULT;
41149
41150diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
41151index 28f84b4..fb3e224 100644
41152--- a/drivers/gpu/drm/qxl/qxl_irq.c
41153+++ b/drivers/gpu/drm/qxl/qxl_irq.c
41154@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
41155
41156 pending = xchg(&qdev->ram_header->int_pending, 0);
41157
41158- atomic_inc(&qdev->irq_received);
41159+ atomic_inc_unchecked(&qdev->irq_received);
41160
41161 if (pending & QXL_INTERRUPT_DISPLAY) {
41162- atomic_inc(&qdev->irq_received_display);
41163+ atomic_inc_unchecked(&qdev->irq_received_display);
41164 wake_up_all(&qdev->display_event);
41165 qxl_queue_garbage_collect(qdev, false);
41166 }
41167 if (pending & QXL_INTERRUPT_CURSOR) {
41168- atomic_inc(&qdev->irq_received_cursor);
41169+ atomic_inc_unchecked(&qdev->irq_received_cursor);
41170 wake_up_all(&qdev->cursor_event);
41171 }
41172 if (pending & QXL_INTERRUPT_IO_CMD) {
41173- atomic_inc(&qdev->irq_received_io_cmd);
41174+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
41175 wake_up_all(&qdev->io_cmd_event);
41176 }
41177 if (pending & QXL_INTERRUPT_ERROR) {
41178@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41179 init_waitqueue_head(&qdev->io_cmd_event);
41180 INIT_WORK(&qdev->client_monitors_config_work,
41181 qxl_client_monitors_config_work_func);
41182- atomic_set(&qdev->irq_received, 0);
41183- atomic_set(&qdev->irq_received_display, 0);
41184- atomic_set(&qdev->irq_received_cursor, 0);
41185- atomic_set(&qdev->irq_received_io_cmd, 0);
41186+ atomic_set_unchecked(&qdev->irq_received, 0);
41187+ atomic_set_unchecked(&qdev->irq_received_display, 0);
41188+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41189+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41190 qdev->irq_received_error = 0;
41191 ret = drm_irq_install(qdev->ddev);
41192 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41193diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41194index c7e7e65..7dddd4d 100644
41195--- a/drivers/gpu/drm/qxl/qxl_ttm.c
41196+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41197@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41198 }
41199 }
41200
41201-static struct vm_operations_struct qxl_ttm_vm_ops;
41202+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41203 static const struct vm_operations_struct *ttm_vm_ops;
41204
41205 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41206@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41207 return r;
41208 if (unlikely(ttm_vm_ops == NULL)) {
41209 ttm_vm_ops = vma->vm_ops;
41210+ pax_open_kernel();
41211 qxl_ttm_vm_ops = *ttm_vm_ops;
41212 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41213+ pax_close_kernel();
41214 }
41215 vma->vm_ops = &qxl_ttm_vm_ops;
41216 return 0;
41217@@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41218 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41219 {
41220 #if defined(CONFIG_DEBUG_FS)
41221- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41222- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41223- unsigned i;
41224+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41225+ {
41226+ .name = "qxl_mem_mm",
41227+ .show = &qxl_mm_dump_table,
41228+ },
41229+ {
41230+ .name = "qxl_surf_mm",
41231+ .show = &qxl_mm_dump_table,
41232+ }
41233+ };
41234
41235- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41236- if (i == 0)
41237- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41238- else
41239- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41240- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41241- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41242- qxl_mem_types_list[i].driver_features = 0;
41243- if (i == 0)
41244- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41245- else
41246- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41247+ pax_open_kernel();
41248+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41249+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41250+ pax_close_kernel();
41251
41252- }
41253- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41254+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41255 #else
41256 return 0;
41257 #endif
41258diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41259index 59459fe..be26b31 100644
41260--- a/drivers/gpu/drm/r128/r128_cce.c
41261+++ b/drivers/gpu/drm/r128/r128_cce.c
41262@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41263
41264 /* GH: Simple idle check.
41265 */
41266- atomic_set(&dev_priv->idle_count, 0);
41267+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41268
41269 /* We don't support anything other than bus-mastering ring mode,
41270 * but the ring can be in either AGP or PCI space for the ring
41271diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41272index 5bf3f5f..7000661 100644
41273--- a/drivers/gpu/drm/r128/r128_drv.h
41274+++ b/drivers/gpu/drm/r128/r128_drv.h
41275@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
41276 int is_pci;
41277 unsigned long cce_buffers_offset;
41278
41279- atomic_t idle_count;
41280+ atomic_unchecked_t idle_count;
41281
41282 int page_flipping;
41283 int current_page;
41284 u32 crtc_offset;
41285 u32 crtc_offset_cntl;
41286
41287- atomic_t vbl_received;
41288+ atomic_unchecked_t vbl_received;
41289
41290 u32 color_fmt;
41291 unsigned int front_offset;
41292diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41293index b0d0fd3..a6fbbe4 100644
41294--- a/drivers/gpu/drm/r128/r128_ioc32.c
41295+++ b/drivers/gpu/drm/r128/r128_ioc32.c
41296@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41297 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41298 }
41299
41300-drm_ioctl_compat_t *r128_compat_ioctls[] = {
41301+drm_ioctl_compat_t r128_compat_ioctls[] = {
41302 [DRM_R128_INIT] = compat_r128_init,
41303 [DRM_R128_DEPTH] = compat_r128_depth,
41304 [DRM_R128_STIPPLE] = compat_r128_stipple,
41305@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41306 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41307 {
41308 unsigned int nr = DRM_IOCTL_NR(cmd);
41309- drm_ioctl_compat_t *fn = NULL;
41310 int ret;
41311
41312 if (nr < DRM_COMMAND_BASE)
41313 return drm_compat_ioctl(filp, cmd, arg);
41314
41315- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
41316- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41317-
41318- if (fn != NULL)
41319+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
41320+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41321 ret = (*fn) (filp, cmd, arg);
41322- else
41323+ } else
41324 ret = drm_ioctl(filp, cmd, arg);
41325
41326 return ret;
41327diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41328index c2ae496..30b5993 100644
41329--- a/drivers/gpu/drm/r128/r128_irq.c
41330+++ b/drivers/gpu/drm/r128/r128_irq.c
41331@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41332 if (crtc != 0)
41333 return 0;
41334
41335- return atomic_read(&dev_priv->vbl_received);
41336+ return atomic_read_unchecked(&dev_priv->vbl_received);
41337 }
41338
41339 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41340@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41341 /* VBLANK interrupt */
41342 if (status & R128_CRTC_VBLANK_INT) {
41343 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41344- atomic_inc(&dev_priv->vbl_received);
41345+ atomic_inc_unchecked(&dev_priv->vbl_received);
41346 drm_handle_vblank(dev, 0);
41347 return IRQ_HANDLED;
41348 }
41349diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41350index e806dac..f81d32f 100644
41351--- a/drivers/gpu/drm/r128/r128_state.c
41352+++ b/drivers/gpu/drm/r128/r128_state.c
41353@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41354
41355 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41356 {
41357- if (atomic_read(&dev_priv->idle_count) == 0)
41358+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41359 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41360 else
41361- atomic_set(&dev_priv->idle_count, 0);
41362+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41363 }
41364
41365 #endif
41366diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41367index 4a85bb6..aaea819 100644
41368--- a/drivers/gpu/drm/radeon/mkregtable.c
41369+++ b/drivers/gpu/drm/radeon/mkregtable.c
41370@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41371 regex_t mask_rex;
41372 regmatch_t match[4];
41373 char buf[1024];
41374- size_t end;
41375+ long end;
41376 int len;
41377 int done = 0;
41378 int r;
41379 unsigned o;
41380 struct offset *offset;
41381 char last_reg_s[10];
41382- int last_reg;
41383+ unsigned long last_reg;
41384
41385 if (regcomp
41386 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41387diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41388index 044bc98..50ced9b 100644
41389--- a/drivers/gpu/drm/radeon/radeon_device.c
41390+++ b/drivers/gpu/drm/radeon/radeon_device.c
41391@@ -1125,7 +1125,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41392 bool can_switch;
41393
41394 spin_lock(&dev->count_lock);
41395- can_switch = (dev->open_count == 0);
41396+ can_switch = (local_read(&dev->open_count) == 0);
41397 spin_unlock(&dev->count_lock);
41398 return can_switch;
41399 }
41400diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41401index dafd812..1bf20c7 100644
41402--- a/drivers/gpu/drm/radeon/radeon_drv.h
41403+++ b/drivers/gpu/drm/radeon/radeon_drv.h
41404@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
41405
41406 /* SW interrupt */
41407 wait_queue_head_t swi_queue;
41408- atomic_t swi_emitted;
41409+ atomic_unchecked_t swi_emitted;
41410 int vblank_crtc;
41411 uint32_t irq_enable_reg;
41412 uint32_t r500_disp_irq_reg;
41413diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41414index bdb0f93..5ff558f 100644
41415--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41416+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41417@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41418 request = compat_alloc_user_space(sizeof(*request));
41419 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41420 || __put_user(req32.param, &request->param)
41421- || __put_user((void __user *)(unsigned long)req32.value,
41422+ || __put_user((unsigned long)req32.value,
41423 &request->value))
41424 return -EFAULT;
41425
41426@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41427 #define compat_radeon_cp_setparam NULL
41428 #endif /* X86_64 || IA64 */
41429
41430-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41431+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41432 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41433 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41434 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41435@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41436 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41437 {
41438 unsigned int nr = DRM_IOCTL_NR(cmd);
41439- drm_ioctl_compat_t *fn = NULL;
41440 int ret;
41441
41442 if (nr < DRM_COMMAND_BASE)
41443 return drm_compat_ioctl(filp, cmd, arg);
41444
41445- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
41446- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41447-
41448- if (fn != NULL)
41449+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
41450+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41451 ret = (*fn) (filp, cmd, arg);
41452- else
41453+ } else
41454 ret = drm_ioctl(filp, cmd, arg);
41455
41456 return ret;
41457diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41458index 244b19b..c19226d 100644
41459--- a/drivers/gpu/drm/radeon/radeon_irq.c
41460+++ b/drivers/gpu/drm/radeon/radeon_irq.c
41461@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41462 unsigned int ret;
41463 RING_LOCALS;
41464
41465- atomic_inc(&dev_priv->swi_emitted);
41466- ret = atomic_read(&dev_priv->swi_emitted);
41467+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41468+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41469
41470 BEGIN_RING(4);
41471 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41472@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41473 drm_radeon_private_t *dev_priv =
41474 (drm_radeon_private_t *) dev->dev_private;
41475
41476- atomic_set(&dev_priv->swi_emitted, 0);
41477+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41478 init_waitqueue_head(&dev_priv->swi_queue);
41479
41480 dev->max_vblank_count = 0x001fffff;
41481diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41482index 956ab7f..fbd36d8 100644
41483--- a/drivers/gpu/drm/radeon/radeon_state.c
41484+++ b/drivers/gpu/drm/radeon/radeon_state.c
41485@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41486 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41487 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41488
41489- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41490+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41491 sarea_priv->nbox * sizeof(depth_boxes[0])))
41492 return -EFAULT;
41493
41494@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41495 {
41496 drm_radeon_private_t *dev_priv = dev->dev_private;
41497 drm_radeon_getparam_t *param = data;
41498- int value;
41499+ int value = 0;
41500
41501 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41502
41503diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41504index 040a2a1..eae4e54 100644
41505--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41506+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41507@@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41508 man->size = size >> PAGE_SHIFT;
41509 }
41510
41511-static struct vm_operations_struct radeon_ttm_vm_ops;
41512+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41513 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41514
41515 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41516@@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41517 }
41518 if (unlikely(ttm_vm_ops == NULL)) {
41519 ttm_vm_ops = vma->vm_ops;
41520+ pax_open_kernel();
41521 radeon_ttm_vm_ops = *ttm_vm_ops;
41522 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41523+ pax_close_kernel();
41524 }
41525 vma->vm_ops = &radeon_ttm_vm_ops;
41526 return 0;
41527diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41528index 9336006..ce78aa7 100644
41529--- a/drivers/gpu/drm/tegra/dc.c
41530+++ b/drivers/gpu/drm/tegra/dc.c
41531@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41532 }
41533
41534 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41535- dc->debugfs_files[i].data = dc;
41536+ *(void **)&dc->debugfs_files[i].data = dc;
41537
41538 err = drm_debugfs_create_files(dc->debugfs_files,
41539 ARRAY_SIZE(debugfs_files),
41540diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41541index d452faab..f8cbc6a 100644
41542--- a/drivers/gpu/drm/tegra/dsi.c
41543+++ b/drivers/gpu/drm/tegra/dsi.c
41544@@ -53,7 +53,7 @@ struct tegra_dsi {
41545 struct clk *clk_lp;
41546 struct clk *clk;
41547
41548- struct drm_info_list *debugfs_files;
41549+ drm_info_list_no_const *debugfs_files;
41550 struct drm_minor *minor;
41551 struct dentry *debugfs;
41552
41553diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41554index 6928015..c9853e7 100644
41555--- a/drivers/gpu/drm/tegra/hdmi.c
41556+++ b/drivers/gpu/drm/tegra/hdmi.c
41557@@ -59,7 +59,7 @@ struct tegra_hdmi {
41558 bool stereo;
41559 bool dvi;
41560
41561- struct drm_info_list *debugfs_files;
41562+ drm_info_list_no_const *debugfs_files;
41563 struct drm_minor *minor;
41564 struct dentry *debugfs;
41565 };
41566diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41567index c58eba33..83c2728 100644
41568--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41569+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41570@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41571 }
41572
41573 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41574- ttm_bo_man_init,
41575- ttm_bo_man_takedown,
41576- ttm_bo_man_get_node,
41577- ttm_bo_man_put_node,
41578- ttm_bo_man_debug
41579+ .init = ttm_bo_man_init,
41580+ .takedown = ttm_bo_man_takedown,
41581+ .get_node = ttm_bo_man_get_node,
41582+ .put_node = ttm_bo_man_put_node,
41583+ .debug = ttm_bo_man_debug
41584 };
41585 EXPORT_SYMBOL(ttm_bo_manager_func);
41586diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41587index dbc2def..0a9f710 100644
41588--- a/drivers/gpu/drm/ttm/ttm_memory.c
41589+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41590@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41591 zone->glob = glob;
41592 glob->zone_kernel = zone;
41593 ret = kobject_init_and_add(
41594- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41595+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41596 if (unlikely(ret != 0)) {
41597 kobject_put(&zone->kobj);
41598 return ret;
41599@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41600 zone->glob = glob;
41601 glob->zone_dma32 = zone;
41602 ret = kobject_init_and_add(
41603- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41604+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41605 if (unlikely(ret != 0)) {
41606 kobject_put(&zone->kobj);
41607 return ret;
41608diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41609index 863bef9..cba15cf 100644
41610--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41611+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41612@@ -391,9 +391,9 @@ out:
41613 static unsigned long
41614 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41615 {
41616- static atomic_t start_pool = ATOMIC_INIT(0);
41617+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41618 unsigned i;
41619- unsigned pool_offset = atomic_add_return(1, &start_pool);
41620+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41621 struct ttm_page_pool *pool;
41622 int shrink_pages = sc->nr_to_scan;
41623 unsigned long freed = 0;
41624diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41625index dbadd49..1b7457b 100644
41626--- a/drivers/gpu/drm/udl/udl_fb.c
41627+++ b/drivers/gpu/drm/udl/udl_fb.c
41628@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41629 fb_deferred_io_cleanup(info);
41630 kfree(info->fbdefio);
41631 info->fbdefio = NULL;
41632- info->fbops->fb_mmap = udl_fb_mmap;
41633 }
41634
41635 pr_warn("released /dev/fb%d user=%d count=%d\n",
41636diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41637index ad02732..144f5ed 100644
41638--- a/drivers/gpu/drm/via/via_drv.h
41639+++ b/drivers/gpu/drm/via/via_drv.h
41640@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41641 typedef uint32_t maskarray_t[5];
41642
41643 typedef struct drm_via_irq {
41644- atomic_t irq_received;
41645+ atomic_unchecked_t irq_received;
41646 uint32_t pending_mask;
41647 uint32_t enable_mask;
41648 wait_queue_head_t irq_queue;
41649@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41650 struct timeval last_vblank;
41651 int last_vblank_valid;
41652 unsigned usec_per_vblank;
41653- atomic_t vbl_received;
41654+ atomic_unchecked_t vbl_received;
41655 drm_via_state_t hc_state;
41656 char pci_buf[VIA_PCI_BUF_SIZE];
41657 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41658diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41659index 1319433..a993b0c 100644
41660--- a/drivers/gpu/drm/via/via_irq.c
41661+++ b/drivers/gpu/drm/via/via_irq.c
41662@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41663 if (crtc != 0)
41664 return 0;
41665
41666- return atomic_read(&dev_priv->vbl_received);
41667+ return atomic_read_unchecked(&dev_priv->vbl_received);
41668 }
41669
41670 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41671@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41672
41673 status = VIA_READ(VIA_REG_INTERRUPT);
41674 if (status & VIA_IRQ_VBLANK_PENDING) {
41675- atomic_inc(&dev_priv->vbl_received);
41676- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41677+ atomic_inc_unchecked(&dev_priv->vbl_received);
41678+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41679 do_gettimeofday(&cur_vblank);
41680 if (dev_priv->last_vblank_valid) {
41681 dev_priv->usec_per_vblank =
41682@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41683 dev_priv->last_vblank = cur_vblank;
41684 dev_priv->last_vblank_valid = 1;
41685 }
41686- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41687+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41688 DRM_DEBUG("US per vblank is: %u\n",
41689 dev_priv->usec_per_vblank);
41690 }
41691@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41692
41693 for (i = 0; i < dev_priv->num_irqs; ++i) {
41694 if (status & cur_irq->pending_mask) {
41695- atomic_inc(&cur_irq->irq_received);
41696+ atomic_inc_unchecked(&cur_irq->irq_received);
41697 wake_up(&cur_irq->irq_queue);
41698 handled = 1;
41699 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41700@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41701 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41702 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41703 masks[irq][4]));
41704- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41705+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41706 } else {
41707 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41708 (((cur_irq_sequence =
41709- atomic_read(&cur_irq->irq_received)) -
41710+ atomic_read_unchecked(&cur_irq->irq_received)) -
41711 *sequence) <= (1 << 23)));
41712 }
41713 *sequence = cur_irq_sequence;
41714@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41715 }
41716
41717 for (i = 0; i < dev_priv->num_irqs; ++i) {
41718- atomic_set(&cur_irq->irq_received, 0);
41719+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41720 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41721 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41722 init_waitqueue_head(&cur_irq->irq_queue);
41723@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41724 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41725 case VIA_IRQ_RELATIVE:
41726 irqwait->request.sequence +=
41727- atomic_read(&cur_irq->irq_received);
41728+ atomic_read_unchecked(&cur_irq->irq_received);
41729 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41730 case VIA_IRQ_ABSOLUTE:
41731 break;
41732diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41733index 0783155..b29e18e 100644
41734--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41735+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41736@@ -437,7 +437,7 @@ struct vmw_private {
41737 * Fencing and IRQs.
41738 */
41739
41740- atomic_t marker_seq;
41741+ atomic_unchecked_t marker_seq;
41742 wait_queue_head_t fence_queue;
41743 wait_queue_head_t fifo_queue;
41744 int fence_queue_waiters; /* Protected by hw_mutex */
41745diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41746index 6ccd993..618d592 100644
41747--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41748+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41749@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41750 (unsigned int) min,
41751 (unsigned int) fifo->capabilities);
41752
41753- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41754+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41755 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41756 vmw_marker_queue_init(&fifo->marker_queue);
41757 return vmw_fifo_send_fence(dev_priv, &dummy);
41758@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41759 if (reserveable)
41760 iowrite32(bytes, fifo_mem +
41761 SVGA_FIFO_RESERVED);
41762- return fifo_mem + (next_cmd >> 2);
41763+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41764 } else {
41765 need_bounce = true;
41766 }
41767@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41768
41769 fm = vmw_fifo_reserve(dev_priv, bytes);
41770 if (unlikely(fm == NULL)) {
41771- *seqno = atomic_read(&dev_priv->marker_seq);
41772+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41773 ret = -ENOMEM;
41774 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41775 false, 3*HZ);
41776@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41777 }
41778
41779 do {
41780- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41781+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41782 } while (*seqno == 0);
41783
41784 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41785diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41786index b1273e8..9c274fd 100644
41787--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41788+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41789@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41790 }
41791
41792 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41793- vmw_gmrid_man_init,
41794- vmw_gmrid_man_takedown,
41795- vmw_gmrid_man_get_node,
41796- vmw_gmrid_man_put_node,
41797- vmw_gmrid_man_debug
41798+ .init = vmw_gmrid_man_init,
41799+ .takedown = vmw_gmrid_man_takedown,
41800+ .get_node = vmw_gmrid_man_get_node,
41801+ .put_node = vmw_gmrid_man_put_node,
41802+ .debug = vmw_gmrid_man_debug
41803 };
41804diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41805index 47b7094..698ba09 100644
41806--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41807+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41808@@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41809 int ret;
41810
41811 num_clips = arg->num_clips;
41812- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41813+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41814
41815 if (unlikely(num_clips == 0))
41816 return 0;
41817@@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41818 int ret;
41819
41820 num_clips = arg->num_clips;
41821- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41822+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41823
41824 if (unlikely(num_clips == 0))
41825 return 0;
41826diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41827index 0c42376..6febe77 100644
41828--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41829+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41830@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41831 * emitted. Then the fence is stale and signaled.
41832 */
41833
41834- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41835+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41836 > VMW_FENCE_WRAP);
41837
41838 return ret;
41839@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41840
41841 if (fifo_idle)
41842 down_read(&fifo_state->rwsem);
41843- signal_seq = atomic_read(&dev_priv->marker_seq);
41844+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41845 ret = 0;
41846
41847 for (;;) {
41848diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41849index 8a8725c2..afed796 100644
41850--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41851+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41852@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41853 while (!vmw_lag_lt(queue, us)) {
41854 spin_lock(&queue->lock);
41855 if (list_empty(&queue->head))
41856- seqno = atomic_read(&dev_priv->marker_seq);
41857+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41858 else {
41859 marker = list_first_entry(&queue->head,
41860 struct vmw_marker, head);
41861diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41862index ec0ae2d..dc0780b 100644
41863--- a/drivers/gpu/vga/vga_switcheroo.c
41864+++ b/drivers/gpu/vga/vga_switcheroo.c
41865@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41866
41867 /* this version is for the case where the power switch is separate
41868 to the device being powered down. */
41869-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41870+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41871 {
41872 /* copy over all the bus versions */
41873 if (dev->bus && dev->bus->pm) {
41874@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41875 return ret;
41876 }
41877
41878-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41879+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41880 {
41881 /* copy over all the bus versions */
41882 if (dev->bus && dev->bus->pm) {
41883diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41884index cc32a6f..02a4b1c 100644
41885--- a/drivers/hid/hid-core.c
41886+++ b/drivers/hid/hid-core.c
41887@@ -2421,7 +2421,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41888
41889 int hid_add_device(struct hid_device *hdev)
41890 {
41891- static atomic_t id = ATOMIC_INIT(0);
41892+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41893 int ret;
41894
41895 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41896@@ -2455,7 +2455,7 @@ int hid_add_device(struct hid_device *hdev)
41897 /* XXX hack, any other cleaner solution after the driver core
41898 * is converted to allow more than 20 bytes as the device name? */
41899 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41900- hdev->vendor, hdev->product, atomic_inc_return(&id));
41901+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41902
41903 hid_debug_register(hdev, dev_name(&hdev->dev));
41904 ret = device_add(&hdev->dev);
41905diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41906index c13fb5b..55a3802 100644
41907--- a/drivers/hid/hid-wiimote-debug.c
41908+++ b/drivers/hid/hid-wiimote-debug.c
41909@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41910 else if (size == 0)
41911 return -EIO;
41912
41913- if (copy_to_user(u, buf, size))
41914+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41915 return -EFAULT;
41916
41917 *off += size;
41918diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41919index cedc6da..2c3da2a 100644
41920--- a/drivers/hid/uhid.c
41921+++ b/drivers/hid/uhid.c
41922@@ -47,7 +47,7 @@ struct uhid_device {
41923 struct mutex report_lock;
41924 wait_queue_head_t report_wait;
41925 atomic_t report_done;
41926- atomic_t report_id;
41927+ atomic_unchecked_t report_id;
41928 struct uhid_event report_buf;
41929 };
41930
41931@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41932
41933 spin_lock_irqsave(&uhid->qlock, flags);
41934 ev->type = UHID_FEATURE;
41935- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41936+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41937 ev->u.feature.rnum = rnum;
41938 ev->u.feature.rtype = report_type;
41939
41940@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41941 spin_lock_irqsave(&uhid->qlock, flags);
41942
41943 /* id for old report; drop it silently */
41944- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41945+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41946 goto unlock;
41947 if (atomic_read(&uhid->report_done))
41948 goto unlock;
41949diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41950index 69ea36f..8dbf4bb 100644
41951--- a/drivers/hv/channel.c
41952+++ b/drivers/hv/channel.c
41953@@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41954 int ret = 0;
41955 int t;
41956
41957- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41958- atomic_inc(&vmbus_connection.next_gpadl_handle);
41959+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41960+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41961
41962 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41963 if (ret)
41964diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41965index bcb4950..61dba6c 100644
41966--- a/drivers/hv/hv.c
41967+++ b/drivers/hv/hv.c
41968@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41969 u64 output_address = (output) ? virt_to_phys(output) : 0;
41970 u32 output_address_hi = output_address >> 32;
41971 u32 output_address_lo = output_address & 0xFFFFFFFF;
41972- void *hypercall_page = hv_context.hypercall_page;
41973+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41974
41975 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41976 "=a"(hv_status_lo) : "d" (control_hi),
41977@@ -154,7 +154,7 @@ int hv_init(void)
41978 /* See if the hypercall page is already set */
41979 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41980
41981- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41982+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41983
41984 if (!virtaddr)
41985 goto cleanup;
41986diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41987index 7e17a54..a50a33d 100644
41988--- a/drivers/hv/hv_balloon.c
41989+++ b/drivers/hv/hv_balloon.c
41990@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41991
41992 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41993 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41994-static atomic_t trans_id = ATOMIC_INIT(0);
41995+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41996
41997 static int dm_ring_size = (5 * PAGE_SIZE);
41998
41999@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
42000 pr_info("Memory hot add failed\n");
42001
42002 dm->state = DM_INITIALIZED;
42003- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42004+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42005 vmbus_sendpacket(dm->dev->channel, &resp,
42006 sizeof(struct dm_hot_add_response),
42007 (unsigned long)NULL,
42008@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
42009 memset(&status, 0, sizeof(struct dm_status));
42010 status.hdr.type = DM_STATUS_REPORT;
42011 status.hdr.size = sizeof(struct dm_status);
42012- status.hdr.trans_id = atomic_inc_return(&trans_id);
42013+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42014
42015 /*
42016 * The host expects the guest to report free memory.
42017@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
42018 * send the status. This can happen if we were interrupted
42019 * after we picked our transaction ID.
42020 */
42021- if (status.hdr.trans_id != atomic_read(&trans_id))
42022+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42023 return;
42024
42025 vmbus_sendpacket(dm->dev->channel, &status,
42026@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
42027 */
42028
42029 do {
42030- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42031+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42032 ret = vmbus_sendpacket(dm_device.dev->channel,
42033 bl_resp,
42034 bl_resp->hdr.size,
42035@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42036
42037 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42038 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42039- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42040+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42041 resp.hdr.size = sizeof(struct dm_unballoon_response);
42042
42043 vmbus_sendpacket(dm_device.dev->channel, &resp,
42044@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42045 memset(&version_req, 0, sizeof(struct dm_version_request));
42046 version_req.hdr.type = DM_VERSION_REQUEST;
42047 version_req.hdr.size = sizeof(struct dm_version_request);
42048- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42049+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42050 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42051 version_req.is_last_attempt = 1;
42052
42053@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
42054 memset(&version_req, 0, sizeof(struct dm_version_request));
42055 version_req.hdr.type = DM_VERSION_REQUEST;
42056 version_req.hdr.size = sizeof(struct dm_version_request);
42057- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42058+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42059 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42060 version_req.is_last_attempt = 0;
42061
42062@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
42063 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42064 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42065 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42066- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42067+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42068
42069 cap_msg.caps.cap_bits.balloon = 1;
42070 cap_msg.caps.cap_bits.hot_add = 1;
42071diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42072index e055176..c22ff1f 100644
42073--- a/drivers/hv/hyperv_vmbus.h
42074+++ b/drivers/hv/hyperv_vmbus.h
42075@@ -602,7 +602,7 @@ enum vmbus_connect_state {
42076 struct vmbus_connection {
42077 enum vmbus_connect_state conn_state;
42078
42079- atomic_t next_gpadl_handle;
42080+ atomic_unchecked_t next_gpadl_handle;
42081
42082 /*
42083 * Represents channel interrupts. Each bit position represents a
42084diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42085index 077bb1b..d433d74 100644
42086--- a/drivers/hv/vmbus_drv.c
42087+++ b/drivers/hv/vmbus_drv.c
42088@@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42089 {
42090 int ret = 0;
42091
42092- static atomic_t device_num = ATOMIC_INIT(0);
42093+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42094
42095 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42096- atomic_inc_return(&device_num));
42097+ atomic_inc_return_unchecked(&device_num));
42098
42099 child_device_obj->device.bus = &hv_bus;
42100 child_device_obj->device.parent = &hv_acpi_dev->dev;
42101diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42102index 579bdf9..75118b5 100644
42103--- a/drivers/hwmon/acpi_power_meter.c
42104+++ b/drivers/hwmon/acpi_power_meter.c
42105@@ -116,7 +116,7 @@ struct sensor_template {
42106 struct device_attribute *devattr,
42107 const char *buf, size_t count);
42108 int index;
42109-};
42110+} __do_const;
42111
42112 /* Averaging interval */
42113 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42114@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42115 struct sensor_template *attrs)
42116 {
42117 struct device *dev = &resource->acpi_dev->dev;
42118- struct sensor_device_attribute *sensors =
42119+ sensor_device_attribute_no_const *sensors =
42120 &resource->sensors[resource->num_sensors];
42121 int res = 0;
42122
42123diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42124index 3288f13..71cfb4e 100644
42125--- a/drivers/hwmon/applesmc.c
42126+++ b/drivers/hwmon/applesmc.c
42127@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42128 {
42129 struct applesmc_node_group *grp;
42130 struct applesmc_dev_attr *node;
42131- struct attribute *attr;
42132+ attribute_no_const *attr;
42133 int ret, i;
42134
42135 for (grp = groups; grp->format; grp++) {
42136diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42137index ae208f6..48b6c5b 100644
42138--- a/drivers/hwmon/asus_atk0110.c
42139+++ b/drivers/hwmon/asus_atk0110.c
42140@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42141 struct atk_sensor_data {
42142 struct list_head list;
42143 struct atk_data *data;
42144- struct device_attribute label_attr;
42145- struct device_attribute input_attr;
42146- struct device_attribute limit1_attr;
42147- struct device_attribute limit2_attr;
42148+ device_attribute_no_const label_attr;
42149+ device_attribute_no_const input_attr;
42150+ device_attribute_no_const limit1_attr;
42151+ device_attribute_no_const limit2_attr;
42152 char label_attr_name[ATTR_NAME_SIZE];
42153 char input_attr_name[ATTR_NAME_SIZE];
42154 char limit1_attr_name[ATTR_NAME_SIZE];
42155@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42156 static struct device_attribute atk_name_attr =
42157 __ATTR(name, 0444, atk_name_show, NULL);
42158
42159-static void atk_init_attribute(struct device_attribute *attr, char *name,
42160+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42161 sysfs_show_func show)
42162 {
42163 sysfs_attr_init(&attr->attr);
42164diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42165index bbb0b0d..9fe1332 100644
42166--- a/drivers/hwmon/coretemp.c
42167+++ b/drivers/hwmon/coretemp.c
42168@@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42169 return NOTIFY_OK;
42170 }
42171
42172-static struct notifier_block coretemp_cpu_notifier __refdata = {
42173+static struct notifier_block coretemp_cpu_notifier = {
42174 .notifier_call = coretemp_cpu_callback,
42175 };
42176
42177diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42178index 632f1dc..57e6a58 100644
42179--- a/drivers/hwmon/ibmaem.c
42180+++ b/drivers/hwmon/ibmaem.c
42181@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
42182 struct aem_rw_sensor_template *rw)
42183 {
42184 struct device *dev = &data->pdev->dev;
42185- struct sensor_device_attribute *sensors = data->sensors;
42186+ sensor_device_attribute_no_const *sensors = data->sensors;
42187 int err;
42188
42189 /* Set up read-only sensors */
42190diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42191index 708081b..fe2d4ab 100644
42192--- a/drivers/hwmon/iio_hwmon.c
42193+++ b/drivers/hwmon/iio_hwmon.c
42194@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42195 {
42196 struct device *dev = &pdev->dev;
42197 struct iio_hwmon_state *st;
42198- struct sensor_device_attribute *a;
42199+ sensor_device_attribute_no_const *a;
42200 int ret, i;
42201 int in_i = 1, temp_i = 1, curr_i = 1;
42202 enum iio_chan_type type;
42203diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42204index 38d5a63..cf2c2ea 100644
42205--- a/drivers/hwmon/nct6775.c
42206+++ b/drivers/hwmon/nct6775.c
42207@@ -944,10 +944,10 @@ static struct attribute_group *
42208 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42209 int repeat)
42210 {
42211- struct attribute_group *group;
42212+ attribute_group_no_const *group;
42213 struct sensor_device_attr_u *su;
42214- struct sensor_device_attribute *a;
42215- struct sensor_device_attribute_2 *a2;
42216+ sensor_device_attribute_no_const *a;
42217+ sensor_device_attribute_2_no_const *a2;
42218 struct attribute **attrs;
42219 struct sensor_device_template **t;
42220 int i, count;
42221diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42222index 291d11f..3f0dbbd 100644
42223--- a/drivers/hwmon/pmbus/pmbus_core.c
42224+++ b/drivers/hwmon/pmbus/pmbus_core.c
42225@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42226 return 0;
42227 }
42228
42229-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42230+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42231 const char *name,
42232 umode_t mode,
42233 ssize_t (*show)(struct device *dev,
42234@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42235 dev_attr->store = store;
42236 }
42237
42238-static void pmbus_attr_init(struct sensor_device_attribute *a,
42239+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42240 const char *name,
42241 umode_t mode,
42242 ssize_t (*show)(struct device *dev,
42243@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42244 u16 reg, u8 mask)
42245 {
42246 struct pmbus_boolean *boolean;
42247- struct sensor_device_attribute *a;
42248+ sensor_device_attribute_no_const *a;
42249
42250 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42251 if (!boolean)
42252@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42253 bool update, bool readonly)
42254 {
42255 struct pmbus_sensor *sensor;
42256- struct device_attribute *a;
42257+ device_attribute_no_const *a;
42258
42259 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42260 if (!sensor)
42261@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42262 const char *lstring, int index)
42263 {
42264 struct pmbus_label *label;
42265- struct device_attribute *a;
42266+ device_attribute_no_const *a;
42267
42268 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42269 if (!label)
42270diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42271index 97cd45a..ac54d8b 100644
42272--- a/drivers/hwmon/sht15.c
42273+++ b/drivers/hwmon/sht15.c
42274@@ -169,7 +169,7 @@ struct sht15_data {
42275 int supply_uv;
42276 bool supply_uv_valid;
42277 struct work_struct update_supply_work;
42278- atomic_t interrupt_handled;
42279+ atomic_unchecked_t interrupt_handled;
42280 };
42281
42282 /**
42283@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42284 ret = gpio_direction_input(data->pdata->gpio_data);
42285 if (ret)
42286 return ret;
42287- atomic_set(&data->interrupt_handled, 0);
42288+ atomic_set_unchecked(&data->interrupt_handled, 0);
42289
42290 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42291 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42292 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42293 /* Only relevant if the interrupt hasn't occurred. */
42294- if (!atomic_read(&data->interrupt_handled))
42295+ if (!atomic_read_unchecked(&data->interrupt_handled))
42296 schedule_work(&data->read_work);
42297 }
42298 ret = wait_event_timeout(data->wait_queue,
42299@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42300
42301 /* First disable the interrupt */
42302 disable_irq_nosync(irq);
42303- atomic_inc(&data->interrupt_handled);
42304+ atomic_inc_unchecked(&data->interrupt_handled);
42305 /* Then schedule a reading work struct */
42306 if (data->state != SHT15_READING_NOTHING)
42307 schedule_work(&data->read_work);
42308@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42309 * If not, then start the interrupt again - care here as could
42310 * have gone low in meantime so verify it hasn't!
42311 */
42312- atomic_set(&data->interrupt_handled, 0);
42313+ atomic_set_unchecked(&data->interrupt_handled, 0);
42314 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42315 /* If still not occurred or another handler was scheduled */
42316 if (gpio_get_value(data->pdata->gpio_data)
42317- || atomic_read(&data->interrupt_handled))
42318+ || atomic_read_unchecked(&data->interrupt_handled))
42319 return;
42320 }
42321
42322diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42323index 38944e9..ae9e5ed 100644
42324--- a/drivers/hwmon/via-cputemp.c
42325+++ b/drivers/hwmon/via-cputemp.c
42326@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42327 return NOTIFY_OK;
42328 }
42329
42330-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42331+static struct notifier_block via_cputemp_cpu_notifier = {
42332 .notifier_call = via_cputemp_cpu_callback,
42333 };
42334
42335diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42336index 41fc683..a39cfea 100644
42337--- a/drivers/i2c/busses/i2c-amd756-s4882.c
42338+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42339@@ -43,7 +43,7 @@
42340 extern struct i2c_adapter amd756_smbus;
42341
42342 static struct i2c_adapter *s4882_adapter;
42343-static struct i2c_algorithm *s4882_algo;
42344+static i2c_algorithm_no_const *s4882_algo;
42345
42346 /* Wrapper access functions for multiplexed SMBus */
42347 static DEFINE_MUTEX(amd756_lock);
42348diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42349index 721f7eb..0fd2a09 100644
42350--- a/drivers/i2c/busses/i2c-diolan-u2c.c
42351+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42352@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42353 /* usb layer */
42354
42355 /* Send command to device, and get response. */
42356-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42357+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42358 {
42359 int ret = 0;
42360 int actual;
42361diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42362index b170bdf..3c76427 100644
42363--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42364+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42365@@ -41,7 +41,7 @@
42366 extern struct i2c_adapter *nforce2_smbus;
42367
42368 static struct i2c_adapter *s4985_adapter;
42369-static struct i2c_algorithm *s4985_algo;
42370+static i2c_algorithm_no_const *s4985_algo;
42371
42372 /* Wrapper access functions for multiplexed SMBus */
42373 static DEFINE_MUTEX(nforce2_lock);
42374diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42375index 80b47e8..1a6040d9 100644
42376--- a/drivers/i2c/i2c-dev.c
42377+++ b/drivers/i2c/i2c-dev.c
42378@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42379 break;
42380 }
42381
42382- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42383+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42384 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42385 if (IS_ERR(rdwr_pa[i].buf)) {
42386 res = PTR_ERR(rdwr_pa[i].buf);
42387diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42388index 0b510ba..4fbb5085 100644
42389--- a/drivers/ide/ide-cd.c
42390+++ b/drivers/ide/ide-cd.c
42391@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42392 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42393 if ((unsigned long)buf & alignment
42394 || blk_rq_bytes(rq) & q->dma_pad_mask
42395- || object_is_on_stack(buf))
42396+ || object_starts_on_stack(buf))
42397 drive->dma = 0;
42398 }
42399 }
42400diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42401index acc911a..8700c3c 100644
42402--- a/drivers/iio/industrialio-core.c
42403+++ b/drivers/iio/industrialio-core.c
42404@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42405 }
42406
42407 static
42408-int __iio_device_attr_init(struct device_attribute *dev_attr,
42409+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42410 const char *postfix,
42411 struct iio_chan_spec const *chan,
42412 ssize_t (*readfunc)(struct device *dev,
42413diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42414index c323917..6ddea8b 100644
42415--- a/drivers/infiniband/core/cm.c
42416+++ b/drivers/infiniband/core/cm.c
42417@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42418
42419 struct cm_counter_group {
42420 struct kobject obj;
42421- atomic_long_t counter[CM_ATTR_COUNT];
42422+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42423 };
42424
42425 struct cm_counter_attribute {
42426@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42427 struct ib_mad_send_buf *msg = NULL;
42428 int ret;
42429
42430- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42431+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42432 counter[CM_REQ_COUNTER]);
42433
42434 /* Quick state check to discard duplicate REQs. */
42435@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42436 if (!cm_id_priv)
42437 return;
42438
42439- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42440+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42441 counter[CM_REP_COUNTER]);
42442 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42443 if (ret)
42444@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42445 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42446 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42447 spin_unlock_irq(&cm_id_priv->lock);
42448- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42449+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42450 counter[CM_RTU_COUNTER]);
42451 goto out;
42452 }
42453@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42454 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42455 dreq_msg->local_comm_id);
42456 if (!cm_id_priv) {
42457- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42458+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42459 counter[CM_DREQ_COUNTER]);
42460 cm_issue_drep(work->port, work->mad_recv_wc);
42461 return -EINVAL;
42462@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42463 case IB_CM_MRA_REP_RCVD:
42464 break;
42465 case IB_CM_TIMEWAIT:
42466- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42467+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42468 counter[CM_DREQ_COUNTER]);
42469 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42470 goto unlock;
42471@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42472 cm_free_msg(msg);
42473 goto deref;
42474 case IB_CM_DREQ_RCVD:
42475- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42476+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42477 counter[CM_DREQ_COUNTER]);
42478 goto unlock;
42479 default:
42480@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42481 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42482 cm_id_priv->msg, timeout)) {
42483 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42484- atomic_long_inc(&work->port->
42485+ atomic_long_inc_unchecked(&work->port->
42486 counter_group[CM_RECV_DUPLICATES].
42487 counter[CM_MRA_COUNTER]);
42488 goto out;
42489@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42490 break;
42491 case IB_CM_MRA_REQ_RCVD:
42492 case IB_CM_MRA_REP_RCVD:
42493- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42494+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42495 counter[CM_MRA_COUNTER]);
42496 /* fall through */
42497 default:
42498@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42499 case IB_CM_LAP_IDLE:
42500 break;
42501 case IB_CM_MRA_LAP_SENT:
42502- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42503+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42504 counter[CM_LAP_COUNTER]);
42505 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42506 goto unlock;
42507@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42508 cm_free_msg(msg);
42509 goto deref;
42510 case IB_CM_LAP_RCVD:
42511- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42512+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42513 counter[CM_LAP_COUNTER]);
42514 goto unlock;
42515 default:
42516@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42517 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42518 if (cur_cm_id_priv) {
42519 spin_unlock_irq(&cm.lock);
42520- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42521+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42522 counter[CM_SIDR_REQ_COUNTER]);
42523 goto out; /* Duplicate message. */
42524 }
42525@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42526 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42527 msg->retries = 1;
42528
42529- atomic_long_add(1 + msg->retries,
42530+ atomic_long_add_unchecked(1 + msg->retries,
42531 &port->counter_group[CM_XMIT].counter[attr_index]);
42532 if (msg->retries)
42533- atomic_long_add(msg->retries,
42534+ atomic_long_add_unchecked(msg->retries,
42535 &port->counter_group[CM_XMIT_RETRIES].
42536 counter[attr_index]);
42537
42538@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42539 }
42540
42541 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42542- atomic_long_inc(&port->counter_group[CM_RECV].
42543+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42544 counter[attr_id - CM_ATTR_ID_OFFSET]);
42545
42546 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42547@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42548 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42549
42550 return sprintf(buf, "%ld\n",
42551- atomic_long_read(&group->counter[cm_attr->index]));
42552+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42553 }
42554
42555 static const struct sysfs_ops cm_counter_ops = {
42556diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42557index 9f5ad7c..588cd84 100644
42558--- a/drivers/infiniband/core/fmr_pool.c
42559+++ b/drivers/infiniband/core/fmr_pool.c
42560@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42561
42562 struct task_struct *thread;
42563
42564- atomic_t req_ser;
42565- atomic_t flush_ser;
42566+ atomic_unchecked_t req_ser;
42567+ atomic_unchecked_t flush_ser;
42568
42569 wait_queue_head_t force_wait;
42570 };
42571@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42572 struct ib_fmr_pool *pool = pool_ptr;
42573
42574 do {
42575- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42576+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42577 ib_fmr_batch_release(pool);
42578
42579- atomic_inc(&pool->flush_ser);
42580+ atomic_inc_unchecked(&pool->flush_ser);
42581 wake_up_interruptible(&pool->force_wait);
42582
42583 if (pool->flush_function)
42584@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42585 }
42586
42587 set_current_state(TASK_INTERRUPTIBLE);
42588- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42589+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42590 !kthread_should_stop())
42591 schedule();
42592 __set_current_state(TASK_RUNNING);
42593@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42594 pool->dirty_watermark = params->dirty_watermark;
42595 pool->dirty_len = 0;
42596 spin_lock_init(&pool->pool_lock);
42597- atomic_set(&pool->req_ser, 0);
42598- atomic_set(&pool->flush_ser, 0);
42599+ atomic_set_unchecked(&pool->req_ser, 0);
42600+ atomic_set_unchecked(&pool->flush_ser, 0);
42601 init_waitqueue_head(&pool->force_wait);
42602
42603 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42604@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42605 }
42606 spin_unlock_irq(&pool->pool_lock);
42607
42608- serial = atomic_inc_return(&pool->req_ser);
42609+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42610 wake_up_process(pool->thread);
42611
42612 if (wait_event_interruptible(pool->force_wait,
42613- atomic_read(&pool->flush_ser) - serial >= 0))
42614+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42615 return -EINTR;
42616
42617 return 0;
42618@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42619 } else {
42620 list_add_tail(&fmr->list, &pool->dirty_list);
42621 if (++pool->dirty_len >= pool->dirty_watermark) {
42622- atomic_inc(&pool->req_ser);
42623+ atomic_inc_unchecked(&pool->req_ser);
42624 wake_up_process(pool->thread);
42625 }
42626 }
42627diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42628index 41b1195..27971a0 100644
42629--- a/drivers/infiniband/hw/cxgb4/mem.c
42630+++ b/drivers/infiniband/hw/cxgb4/mem.c
42631@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42632 int err;
42633 struct fw_ri_tpte tpt;
42634 u32 stag_idx;
42635- static atomic_t key;
42636+ static atomic_unchecked_t key;
42637
42638 if (c4iw_fatal_error(rdev))
42639 return -EIO;
42640@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42641 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42642 rdev->stats.stag.max = rdev->stats.stag.cur;
42643 mutex_unlock(&rdev->stats.lock);
42644- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42645+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42646 }
42647 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42648 __func__, stag_state, type, pdid, stag_idx);
42649diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42650index 644c2c7..ecf0879 100644
42651--- a/drivers/infiniband/hw/ipath/ipath_dma.c
42652+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42653@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42654 }
42655
42656 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42657- ipath_mapping_error,
42658- ipath_dma_map_single,
42659- ipath_dma_unmap_single,
42660- ipath_dma_map_page,
42661- ipath_dma_unmap_page,
42662- ipath_map_sg,
42663- ipath_unmap_sg,
42664- ipath_sg_dma_address,
42665- ipath_sg_dma_len,
42666- ipath_sync_single_for_cpu,
42667- ipath_sync_single_for_device,
42668- ipath_dma_alloc_coherent,
42669- ipath_dma_free_coherent
42670+ .mapping_error = ipath_mapping_error,
42671+ .map_single = ipath_dma_map_single,
42672+ .unmap_single = ipath_dma_unmap_single,
42673+ .map_page = ipath_dma_map_page,
42674+ .unmap_page = ipath_dma_unmap_page,
42675+ .map_sg = ipath_map_sg,
42676+ .unmap_sg = ipath_unmap_sg,
42677+ .dma_address = ipath_sg_dma_address,
42678+ .dma_len = ipath_sg_dma_len,
42679+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
42680+ .sync_single_for_device = ipath_sync_single_for_device,
42681+ .alloc_coherent = ipath_dma_alloc_coherent,
42682+ .free_coherent = ipath_dma_free_coherent
42683 };
42684diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42685index 79b3dbc..96e5fcc 100644
42686--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42687+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42688@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42689 struct ib_atomic_eth *ateth;
42690 struct ipath_ack_entry *e;
42691 u64 vaddr;
42692- atomic64_t *maddr;
42693+ atomic64_unchecked_t *maddr;
42694 u64 sdata;
42695 u32 rkey;
42696 u8 next;
42697@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42698 IB_ACCESS_REMOTE_ATOMIC)))
42699 goto nack_acc_unlck;
42700 /* Perform atomic OP and save result. */
42701- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42702+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42703 sdata = be64_to_cpu(ateth->swap_data);
42704 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42705 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42706- (u64) atomic64_add_return(sdata, maddr) - sdata :
42707+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42708 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42709 be64_to_cpu(ateth->compare_data),
42710 sdata);
42711diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42712index 1f95bba..9530f87 100644
42713--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42714+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42715@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42716 unsigned long flags;
42717 struct ib_wc wc;
42718 u64 sdata;
42719- atomic64_t *maddr;
42720+ atomic64_unchecked_t *maddr;
42721 enum ib_wc_status send_status;
42722
42723 /*
42724@@ -382,11 +382,11 @@ again:
42725 IB_ACCESS_REMOTE_ATOMIC)))
42726 goto acc_err;
42727 /* Perform atomic OP and save result. */
42728- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42729+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42730 sdata = wqe->wr.wr.atomic.compare_add;
42731 *(u64 *) sqp->s_sge.sge.vaddr =
42732 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42733- (u64) atomic64_add_return(sdata, maddr) - sdata :
42734+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42735 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42736 sdata, wqe->wr.wr.atomic.swap);
42737 goto send_comp;
42738diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42739index f2a3f48..673ec79 100644
42740--- a/drivers/infiniband/hw/mlx4/mad.c
42741+++ b/drivers/infiniband/hw/mlx4/mad.c
42742@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42743
42744 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42745 {
42746- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42747+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42748 cpu_to_be64(0xff00000000000000LL);
42749 }
42750
42751diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42752index 25b2cdf..099ff97 100644
42753--- a/drivers/infiniband/hw/mlx4/mcg.c
42754+++ b/drivers/infiniband/hw/mlx4/mcg.c
42755@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42756 {
42757 char name[20];
42758
42759- atomic_set(&ctx->tid, 0);
42760+ atomic_set_unchecked(&ctx->tid, 0);
42761 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42762 ctx->mcg_wq = create_singlethread_workqueue(name);
42763 if (!ctx->mcg_wq)
42764diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42765index a230683..3723f2d 100644
42766--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42767+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42768@@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
42769 struct list_head mcg_mgid0_list;
42770 struct workqueue_struct *mcg_wq;
42771 struct mlx4_ib_demux_pv_ctx **tun;
42772- atomic_t tid;
42773+ atomic_unchecked_t tid;
42774 int flushing; /* flushing the work queue */
42775 };
42776
42777diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42778index 9d3e5c1..6f166df 100644
42779--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42780+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42781@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42782 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42783 }
42784
42785-int mthca_QUERY_FW(struct mthca_dev *dev)
42786+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42787 {
42788 struct mthca_mailbox *mailbox;
42789 u32 *outbox;
42790@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42791 CMD_TIME_CLASS_B);
42792 }
42793
42794-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42795+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42796 int num_mtt)
42797 {
42798 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42799@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42800 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42801 }
42802
42803-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42804+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42805 int eq_num)
42806 {
42807 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42808@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42809 CMD_TIME_CLASS_B);
42810 }
42811
42812-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42813+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42814 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42815 void *in_mad, void *response_mad)
42816 {
42817diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42818index 87897b9..7e79542 100644
42819--- a/drivers/infiniband/hw/mthca/mthca_main.c
42820+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42821@@ -692,7 +692,7 @@ err_close:
42822 return err;
42823 }
42824
42825-static int mthca_setup_hca(struct mthca_dev *dev)
42826+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42827 {
42828 int err;
42829
42830diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42831index ed9a989..6aa5dc2 100644
42832--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42833+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42834@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42835 * through the bitmaps)
42836 */
42837
42838-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42839+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42840 {
42841 int o;
42842 int m;
42843@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42844 return key;
42845 }
42846
42847-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42848+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42849 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42850 {
42851 struct mthca_mailbox *mailbox;
42852@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42853 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42854 }
42855
42856-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42857+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42858 u64 *buffer_list, int buffer_size_shift,
42859 int list_len, u64 iova, u64 total_size,
42860 u32 access, struct mthca_mr *mr)
42861diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42862index 42dde06..1257310 100644
42863--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42864+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42865@@ -764,7 +764,7 @@ unlock:
42866 return 0;
42867 }
42868
42869-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42870+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42871 {
42872 struct mthca_dev *dev = to_mdev(ibcq->device);
42873 struct mthca_cq *cq = to_mcq(ibcq);
42874diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42875index 353c7b0..c6ce921 100644
42876--- a/drivers/infiniband/hw/nes/nes.c
42877+++ b/drivers/infiniband/hw/nes/nes.c
42878@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42879 LIST_HEAD(nes_adapter_list);
42880 static LIST_HEAD(nes_dev_list);
42881
42882-atomic_t qps_destroyed;
42883+atomic_unchecked_t qps_destroyed;
42884
42885 static unsigned int ee_flsh_adapter;
42886 static unsigned int sysfs_nonidx_addr;
42887@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42888 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42889 struct nes_adapter *nesadapter = nesdev->nesadapter;
42890
42891- atomic_inc(&qps_destroyed);
42892+ atomic_inc_unchecked(&qps_destroyed);
42893
42894 /* Free the control structures */
42895
42896diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42897index 33cc589..3bd6538 100644
42898--- a/drivers/infiniband/hw/nes/nes.h
42899+++ b/drivers/infiniband/hw/nes/nes.h
42900@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42901 extern unsigned int wqm_quanta;
42902 extern struct list_head nes_adapter_list;
42903
42904-extern atomic_t cm_connects;
42905-extern atomic_t cm_accepts;
42906-extern atomic_t cm_disconnects;
42907-extern atomic_t cm_closes;
42908-extern atomic_t cm_connecteds;
42909-extern atomic_t cm_connect_reqs;
42910-extern atomic_t cm_rejects;
42911-extern atomic_t mod_qp_timouts;
42912-extern atomic_t qps_created;
42913-extern atomic_t qps_destroyed;
42914-extern atomic_t sw_qps_destroyed;
42915+extern atomic_unchecked_t cm_connects;
42916+extern atomic_unchecked_t cm_accepts;
42917+extern atomic_unchecked_t cm_disconnects;
42918+extern atomic_unchecked_t cm_closes;
42919+extern atomic_unchecked_t cm_connecteds;
42920+extern atomic_unchecked_t cm_connect_reqs;
42921+extern atomic_unchecked_t cm_rejects;
42922+extern atomic_unchecked_t mod_qp_timouts;
42923+extern atomic_unchecked_t qps_created;
42924+extern atomic_unchecked_t qps_destroyed;
42925+extern atomic_unchecked_t sw_qps_destroyed;
42926 extern u32 mh_detected;
42927 extern u32 mh_pauses_sent;
42928 extern u32 cm_packets_sent;
42929@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42930 extern u32 cm_packets_received;
42931 extern u32 cm_packets_dropped;
42932 extern u32 cm_packets_retrans;
42933-extern atomic_t cm_listens_created;
42934-extern atomic_t cm_listens_destroyed;
42935+extern atomic_unchecked_t cm_listens_created;
42936+extern atomic_unchecked_t cm_listens_destroyed;
42937 extern u32 cm_backlog_drops;
42938-extern atomic_t cm_loopbacks;
42939-extern atomic_t cm_nodes_created;
42940-extern atomic_t cm_nodes_destroyed;
42941-extern atomic_t cm_accel_dropped_pkts;
42942-extern atomic_t cm_resets_recvd;
42943-extern atomic_t pau_qps_created;
42944-extern atomic_t pau_qps_destroyed;
42945+extern atomic_unchecked_t cm_loopbacks;
42946+extern atomic_unchecked_t cm_nodes_created;
42947+extern atomic_unchecked_t cm_nodes_destroyed;
42948+extern atomic_unchecked_t cm_accel_dropped_pkts;
42949+extern atomic_unchecked_t cm_resets_recvd;
42950+extern atomic_unchecked_t pau_qps_created;
42951+extern atomic_unchecked_t pau_qps_destroyed;
42952
42953 extern u32 int_mod_timer_init;
42954 extern u32 int_mod_cq_depth_256;
42955diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42956index 9c9f2f5..2559190 100644
42957--- a/drivers/infiniband/hw/nes/nes_cm.c
42958+++ b/drivers/infiniband/hw/nes/nes_cm.c
42959@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42960 u32 cm_packets_retrans;
42961 u32 cm_packets_created;
42962 u32 cm_packets_received;
42963-atomic_t cm_listens_created;
42964-atomic_t cm_listens_destroyed;
42965+atomic_unchecked_t cm_listens_created;
42966+atomic_unchecked_t cm_listens_destroyed;
42967 u32 cm_backlog_drops;
42968-atomic_t cm_loopbacks;
42969-atomic_t cm_nodes_created;
42970-atomic_t cm_nodes_destroyed;
42971-atomic_t cm_accel_dropped_pkts;
42972-atomic_t cm_resets_recvd;
42973+atomic_unchecked_t cm_loopbacks;
42974+atomic_unchecked_t cm_nodes_created;
42975+atomic_unchecked_t cm_nodes_destroyed;
42976+atomic_unchecked_t cm_accel_dropped_pkts;
42977+atomic_unchecked_t cm_resets_recvd;
42978
42979 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42980 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42981@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42982 /* instance of function pointers for client API */
42983 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42984 static struct nes_cm_ops nes_cm_api = {
42985- mini_cm_accelerated,
42986- mini_cm_listen,
42987- mini_cm_del_listen,
42988- mini_cm_connect,
42989- mini_cm_close,
42990- mini_cm_accept,
42991- mini_cm_reject,
42992- mini_cm_recv_pkt,
42993- mini_cm_dealloc_core,
42994- mini_cm_get,
42995- mini_cm_set
42996+ .accelerated = mini_cm_accelerated,
42997+ .listen = mini_cm_listen,
42998+ .stop_listener = mini_cm_del_listen,
42999+ .connect = mini_cm_connect,
43000+ .close = mini_cm_close,
43001+ .accept = mini_cm_accept,
43002+ .reject = mini_cm_reject,
43003+ .recv_pkt = mini_cm_recv_pkt,
43004+ .destroy_cm_core = mini_cm_dealloc_core,
43005+ .get = mini_cm_get,
43006+ .set = mini_cm_set
43007 };
43008
43009 static struct nes_cm_core *g_cm_core;
43010
43011-atomic_t cm_connects;
43012-atomic_t cm_accepts;
43013-atomic_t cm_disconnects;
43014-atomic_t cm_closes;
43015-atomic_t cm_connecteds;
43016-atomic_t cm_connect_reqs;
43017-atomic_t cm_rejects;
43018+atomic_unchecked_t cm_connects;
43019+atomic_unchecked_t cm_accepts;
43020+atomic_unchecked_t cm_disconnects;
43021+atomic_unchecked_t cm_closes;
43022+atomic_unchecked_t cm_connecteds;
43023+atomic_unchecked_t cm_connect_reqs;
43024+atomic_unchecked_t cm_rejects;
43025
43026 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43027 {
43028@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43029 kfree(listener);
43030 listener = NULL;
43031 ret = 0;
43032- atomic_inc(&cm_listens_destroyed);
43033+ atomic_inc_unchecked(&cm_listens_destroyed);
43034 } else {
43035 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43036 }
43037@@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43038 cm_node->rem_mac);
43039
43040 add_hte_node(cm_core, cm_node);
43041- atomic_inc(&cm_nodes_created);
43042+ atomic_inc_unchecked(&cm_nodes_created);
43043
43044 return cm_node;
43045 }
43046@@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43047 }
43048
43049 atomic_dec(&cm_core->node_cnt);
43050- atomic_inc(&cm_nodes_destroyed);
43051+ atomic_inc_unchecked(&cm_nodes_destroyed);
43052 nesqp = cm_node->nesqp;
43053 if (nesqp) {
43054 nesqp->cm_node = NULL;
43055@@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43056
43057 static void drop_packet(struct sk_buff *skb)
43058 {
43059- atomic_inc(&cm_accel_dropped_pkts);
43060+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43061 dev_kfree_skb_any(skb);
43062 }
43063
43064@@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43065 {
43066
43067 int reset = 0; /* whether to send reset in case of err.. */
43068- atomic_inc(&cm_resets_recvd);
43069+ atomic_inc_unchecked(&cm_resets_recvd);
43070 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43071 " refcnt=%d\n", cm_node, cm_node->state,
43072 atomic_read(&cm_node->ref_count));
43073@@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43074 rem_ref_cm_node(cm_node->cm_core, cm_node);
43075 return NULL;
43076 }
43077- atomic_inc(&cm_loopbacks);
43078+ atomic_inc_unchecked(&cm_loopbacks);
43079 loopbackremotenode->loopbackpartner = cm_node;
43080 loopbackremotenode->tcp_cntxt.rcv_wscale =
43081 NES_CM_DEFAULT_RCV_WND_SCALE;
43082@@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43083 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43084 else {
43085 rem_ref_cm_node(cm_core, cm_node);
43086- atomic_inc(&cm_accel_dropped_pkts);
43087+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43088 dev_kfree_skb_any(skb);
43089 }
43090 break;
43091@@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43092
43093 if ((cm_id) && (cm_id->event_handler)) {
43094 if (issue_disconn) {
43095- atomic_inc(&cm_disconnects);
43096+ atomic_inc_unchecked(&cm_disconnects);
43097 cm_event.event = IW_CM_EVENT_DISCONNECT;
43098 cm_event.status = disconn_status;
43099 cm_event.local_addr = cm_id->local_addr;
43100@@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43101 }
43102
43103 if (issue_close) {
43104- atomic_inc(&cm_closes);
43105+ atomic_inc_unchecked(&cm_closes);
43106 nes_disconnect(nesqp, 1);
43107
43108 cm_id->provider_data = nesqp;
43109@@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43110
43111 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43112 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43113- atomic_inc(&cm_accepts);
43114+ atomic_inc_unchecked(&cm_accepts);
43115
43116 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43117 netdev_refcnt_read(nesvnic->netdev));
43118@@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43119 struct nes_cm_core *cm_core;
43120 u8 *start_buff;
43121
43122- atomic_inc(&cm_rejects);
43123+ atomic_inc_unchecked(&cm_rejects);
43124 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43125 loopback = cm_node->loopbackpartner;
43126 cm_core = cm_node->cm_core;
43127@@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43128 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43129 ntohs(laddr->sin_port));
43130
43131- atomic_inc(&cm_connects);
43132+ atomic_inc_unchecked(&cm_connects);
43133 nesqp->active_conn = 1;
43134
43135 /* cache the cm_id in the qp */
43136@@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43137 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43138 return err;
43139 }
43140- atomic_inc(&cm_listens_created);
43141+ atomic_inc_unchecked(&cm_listens_created);
43142 }
43143
43144 cm_id->add_ref(cm_id);
43145@@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43146
43147 if (nesqp->destroyed)
43148 return;
43149- atomic_inc(&cm_connecteds);
43150+ atomic_inc_unchecked(&cm_connecteds);
43151 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43152 " local port 0x%04X. jiffies = %lu.\n",
43153 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43154@@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43155
43156 cm_id->add_ref(cm_id);
43157 ret = cm_id->event_handler(cm_id, &cm_event);
43158- atomic_inc(&cm_closes);
43159+ atomic_inc_unchecked(&cm_closes);
43160 cm_event.event = IW_CM_EVENT_CLOSE;
43161 cm_event.status = 0;
43162 cm_event.provider_data = cm_id->provider_data;
43163@@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43164 return;
43165 cm_id = cm_node->cm_id;
43166
43167- atomic_inc(&cm_connect_reqs);
43168+ atomic_inc_unchecked(&cm_connect_reqs);
43169 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43170 cm_node, cm_id, jiffies);
43171
43172@@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43173 return;
43174 cm_id = cm_node->cm_id;
43175
43176- atomic_inc(&cm_connect_reqs);
43177+ atomic_inc_unchecked(&cm_connect_reqs);
43178 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43179 cm_node, cm_id, jiffies);
43180
43181diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43182index 4166452..fc952c3 100644
43183--- a/drivers/infiniband/hw/nes/nes_mgt.c
43184+++ b/drivers/infiniband/hw/nes/nes_mgt.c
43185@@ -40,8 +40,8 @@
43186 #include "nes.h"
43187 #include "nes_mgt.h"
43188
43189-atomic_t pau_qps_created;
43190-atomic_t pau_qps_destroyed;
43191+atomic_unchecked_t pau_qps_created;
43192+atomic_unchecked_t pau_qps_destroyed;
43193
43194 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43195 {
43196@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43197 {
43198 struct sk_buff *skb;
43199 unsigned long flags;
43200- atomic_inc(&pau_qps_destroyed);
43201+ atomic_inc_unchecked(&pau_qps_destroyed);
43202
43203 /* Free packets that have not yet been forwarded */
43204 /* Lock is acquired by skb_dequeue when removing the skb */
43205@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43206 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43207 skb_queue_head_init(&nesqp->pau_list);
43208 spin_lock_init(&nesqp->pau_lock);
43209- atomic_inc(&pau_qps_created);
43210+ atomic_inc_unchecked(&pau_qps_created);
43211 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43212 }
43213
43214diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43215index 49eb511..a774366 100644
43216--- a/drivers/infiniband/hw/nes/nes_nic.c
43217+++ b/drivers/infiniband/hw/nes/nes_nic.c
43218@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43219 target_stat_values[++index] = mh_detected;
43220 target_stat_values[++index] = mh_pauses_sent;
43221 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43222- target_stat_values[++index] = atomic_read(&cm_connects);
43223- target_stat_values[++index] = atomic_read(&cm_accepts);
43224- target_stat_values[++index] = atomic_read(&cm_disconnects);
43225- target_stat_values[++index] = atomic_read(&cm_connecteds);
43226- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43227- target_stat_values[++index] = atomic_read(&cm_rejects);
43228- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43229- target_stat_values[++index] = atomic_read(&qps_created);
43230- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43231- target_stat_values[++index] = atomic_read(&qps_destroyed);
43232- target_stat_values[++index] = atomic_read(&cm_closes);
43233+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43234+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43235+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43236+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43237+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43238+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43239+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43240+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43241+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43242+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43243+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43244 target_stat_values[++index] = cm_packets_sent;
43245 target_stat_values[++index] = cm_packets_bounced;
43246 target_stat_values[++index] = cm_packets_created;
43247 target_stat_values[++index] = cm_packets_received;
43248 target_stat_values[++index] = cm_packets_dropped;
43249 target_stat_values[++index] = cm_packets_retrans;
43250- target_stat_values[++index] = atomic_read(&cm_listens_created);
43251- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43252+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43253+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43254 target_stat_values[++index] = cm_backlog_drops;
43255- target_stat_values[++index] = atomic_read(&cm_loopbacks);
43256- target_stat_values[++index] = atomic_read(&cm_nodes_created);
43257- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43258- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43259- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43260+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43261+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43262+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43263+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43264+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43265 target_stat_values[++index] = nesadapter->free_4kpbl;
43266 target_stat_values[++index] = nesadapter->free_256pbl;
43267 target_stat_values[++index] = int_mod_timer_init;
43268 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43269 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43270 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43271- target_stat_values[++index] = atomic_read(&pau_qps_created);
43272- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43273+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43274+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43275 }
43276
43277 /**
43278diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43279index eb62461..2b7fc71 100644
43280--- a/drivers/infiniband/hw/nes/nes_verbs.c
43281+++ b/drivers/infiniband/hw/nes/nes_verbs.c
43282@@ -46,9 +46,9 @@
43283
43284 #include <rdma/ib_umem.h>
43285
43286-atomic_t mod_qp_timouts;
43287-atomic_t qps_created;
43288-atomic_t sw_qps_destroyed;
43289+atomic_unchecked_t mod_qp_timouts;
43290+atomic_unchecked_t qps_created;
43291+atomic_unchecked_t sw_qps_destroyed;
43292
43293 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43294
43295@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43296 if (init_attr->create_flags)
43297 return ERR_PTR(-EINVAL);
43298
43299- atomic_inc(&qps_created);
43300+ atomic_inc_unchecked(&qps_created);
43301 switch (init_attr->qp_type) {
43302 case IB_QPT_RC:
43303 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43304@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43305 struct iw_cm_event cm_event;
43306 int ret = 0;
43307
43308- atomic_inc(&sw_qps_destroyed);
43309+ atomic_inc_unchecked(&sw_qps_destroyed);
43310 nesqp->destroyed = 1;
43311
43312 /* Blow away the connection if it exists. */
43313diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43314index 1946101..09766d2 100644
43315--- a/drivers/infiniband/hw/qib/qib.h
43316+++ b/drivers/infiniband/hw/qib/qib.h
43317@@ -52,6 +52,7 @@
43318 #include <linux/kref.h>
43319 #include <linux/sched.h>
43320 #include <linux/kthread.h>
43321+#include <linux/slab.h>
43322
43323 #include "qib_common.h"
43324 #include "qib_verbs.h"
43325diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43326index 24c41ba..102d71f 100644
43327--- a/drivers/input/gameport/gameport.c
43328+++ b/drivers/input/gameport/gameport.c
43329@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43330 */
43331 static void gameport_init_port(struct gameport *gameport)
43332 {
43333- static atomic_t gameport_no = ATOMIC_INIT(0);
43334+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43335
43336 __module_get(THIS_MODULE);
43337
43338 mutex_init(&gameport->drv_mutex);
43339 device_initialize(&gameport->dev);
43340 dev_set_name(&gameport->dev, "gameport%lu",
43341- (unsigned long)atomic_inc_return(&gameport_no) - 1);
43342+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43343 gameport->dev.bus = &gameport_bus;
43344 gameport->dev.release = gameport_release_port;
43345 if (gameport->parent)
43346diff --git a/drivers/input/input.c b/drivers/input/input.c
43347index 1c4c0db..6f7abe3 100644
43348--- a/drivers/input/input.c
43349+++ b/drivers/input/input.c
43350@@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
43351 */
43352 struct input_dev *input_allocate_device(void)
43353 {
43354- static atomic_t input_no = ATOMIC_INIT(0);
43355+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43356 struct input_dev *dev;
43357
43358 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43359@@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
43360 INIT_LIST_HEAD(&dev->node);
43361
43362 dev_set_name(&dev->dev, "input%ld",
43363- (unsigned long) atomic_inc_return(&input_no) - 1);
43364+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43365
43366 __module_get(THIS_MODULE);
43367 }
43368diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43369index 4a95b22..874c182 100644
43370--- a/drivers/input/joystick/sidewinder.c
43371+++ b/drivers/input/joystick/sidewinder.c
43372@@ -30,6 +30,7 @@
43373 #include <linux/kernel.h>
43374 #include <linux/module.h>
43375 #include <linux/slab.h>
43376+#include <linux/sched.h>
43377 #include <linux/input.h>
43378 #include <linux/gameport.h>
43379 #include <linux/jiffies.h>
43380diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43381index 603fe0d..f63decc 100644
43382--- a/drivers/input/joystick/xpad.c
43383+++ b/drivers/input/joystick/xpad.c
43384@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43385
43386 static int xpad_led_probe(struct usb_xpad *xpad)
43387 {
43388- static atomic_t led_seq = ATOMIC_INIT(0);
43389+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43390 long led_no;
43391 struct xpad_led *led;
43392 struct led_classdev *led_cdev;
43393@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43394 if (!led)
43395 return -ENOMEM;
43396
43397- led_no = (long)atomic_inc_return(&led_seq) - 1;
43398+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43399
43400 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43401 led->xpad = xpad;
43402diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43403index e204f26..8459f15 100644
43404--- a/drivers/input/misc/ims-pcu.c
43405+++ b/drivers/input/misc/ims-pcu.c
43406@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43407
43408 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43409 {
43410- static atomic_t device_no = ATOMIC_INIT(0);
43411+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43412
43413 const struct ims_pcu_device_info *info;
43414 u8 device_id;
43415@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43416 }
43417
43418 /* Device appears to be operable, complete initialization */
43419- pcu->device_no = atomic_inc_return(&device_no) - 1;
43420+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43421
43422 error = ims_pcu_setup_backlight(pcu);
43423 if (error)
43424diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43425index 2f0b39d..7370f13 100644
43426--- a/drivers/input/mouse/psmouse.h
43427+++ b/drivers/input/mouse/psmouse.h
43428@@ -116,7 +116,7 @@ struct psmouse_attribute {
43429 ssize_t (*set)(struct psmouse *psmouse, void *data,
43430 const char *buf, size_t count);
43431 bool protect;
43432-};
43433+} __do_const;
43434 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43435
43436 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43437diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43438index b604564..3f14ae4 100644
43439--- a/drivers/input/mousedev.c
43440+++ b/drivers/input/mousedev.c
43441@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43442
43443 spin_unlock_irq(&client->packet_lock);
43444
43445- if (copy_to_user(buffer, data, count))
43446+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
43447 return -EFAULT;
43448
43449 return count;
43450diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43451index 8f4c4ab..5fc8a45 100644
43452--- a/drivers/input/serio/serio.c
43453+++ b/drivers/input/serio/serio.c
43454@@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
43455 */
43456 static void serio_init_port(struct serio *serio)
43457 {
43458- static atomic_t serio_no = ATOMIC_INIT(0);
43459+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43460
43461 __module_get(THIS_MODULE);
43462
43463@@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
43464 mutex_init(&serio->drv_mutex);
43465 device_initialize(&serio->dev);
43466 dev_set_name(&serio->dev, "serio%ld",
43467- (long)atomic_inc_return(&serio_no) - 1);
43468+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
43469 serio->dev.bus = &serio_bus;
43470 serio->dev.release = serio_release_port;
43471 serio->dev.groups = serio_device_attr_groups;
43472diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43473index c9a02fe..0debc75 100644
43474--- a/drivers/input/serio/serio_raw.c
43475+++ b/drivers/input/serio/serio_raw.c
43476@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43477
43478 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43479 {
43480- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43481+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43482 struct serio_raw *serio_raw;
43483 int err;
43484
43485@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43486 }
43487
43488 snprintf(serio_raw->name, sizeof(serio_raw->name),
43489- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43490+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43491 kref_init(&serio_raw->kref);
43492 INIT_LIST_HEAD(&serio_raw->client_list);
43493 init_waitqueue_head(&serio_raw->wait);
43494diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43495index e5555fc..937986d 100644
43496--- a/drivers/iommu/iommu.c
43497+++ b/drivers/iommu/iommu.c
43498@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43499 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43500 {
43501 bus_register_notifier(bus, &iommu_bus_nb);
43502- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43503+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43504 }
43505
43506 /**
43507diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43508index 228632c9..edfe331 100644
43509--- a/drivers/iommu/irq_remapping.c
43510+++ b/drivers/iommu/irq_remapping.c
43511@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43512 void panic_if_irq_remap(const char *msg)
43513 {
43514 if (irq_remapping_enabled)
43515- panic(msg);
43516+ panic("%s", msg);
43517 }
43518
43519 static void ir_ack_apic_edge(struct irq_data *data)
43520@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43521
43522 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43523 {
43524- chip->irq_print_chip = ir_print_prefix;
43525- chip->irq_ack = ir_ack_apic_edge;
43526- chip->irq_eoi = ir_ack_apic_level;
43527- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43528+ pax_open_kernel();
43529+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43530+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43531+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43532+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43533+ pax_close_kernel();
43534 }
43535
43536 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43537diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43538index 341c601..e5f407e 100644
43539--- a/drivers/irqchip/irq-gic.c
43540+++ b/drivers/irqchip/irq-gic.c
43541@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43542 * Supported arch specific GIC irq extension.
43543 * Default make them NULL.
43544 */
43545-struct irq_chip gic_arch_extn = {
43546+irq_chip_no_const gic_arch_extn = {
43547 .irq_eoi = NULL,
43548 .irq_mask = NULL,
43549 .irq_unmask = NULL,
43550@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43551 chained_irq_exit(chip, desc);
43552 }
43553
43554-static struct irq_chip gic_chip = {
43555+static irq_chip_no_const gic_chip __read_only = {
43556 .name = "GIC",
43557 .irq_mask = gic_mask_irq,
43558 .irq_unmask = gic_unmask_irq,
43559diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43560index 8777065..a4a9967 100644
43561--- a/drivers/irqchip/irq-renesas-irqc.c
43562+++ b/drivers/irqchip/irq-renesas-irqc.c
43563@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43564 struct irqc_priv *p;
43565 struct resource *io;
43566 struct resource *irq;
43567- struct irq_chip *irq_chip;
43568+ irq_chip_no_const *irq_chip;
43569 const char *name = dev_name(&pdev->dev);
43570 int ret;
43571 int k;
43572diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43573index ac6f72b..81150f2 100644
43574--- a/drivers/isdn/capi/capi.c
43575+++ b/drivers/isdn/capi/capi.c
43576@@ -81,8 +81,8 @@ struct capiminor {
43577
43578 struct capi20_appl *ap;
43579 u32 ncci;
43580- atomic_t datahandle;
43581- atomic_t msgid;
43582+ atomic_unchecked_t datahandle;
43583+ atomic_unchecked_t msgid;
43584
43585 struct tty_port port;
43586 int ttyinstop;
43587@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43588 capimsg_setu16(s, 2, mp->ap->applid);
43589 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43590 capimsg_setu8 (s, 5, CAPI_RESP);
43591- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43592+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43593 capimsg_setu32(s, 8, mp->ncci);
43594 capimsg_setu16(s, 12, datahandle);
43595 }
43596@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43597 mp->outbytes -= len;
43598 spin_unlock_bh(&mp->outlock);
43599
43600- datahandle = atomic_inc_return(&mp->datahandle);
43601+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43602 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43603 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43604 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43605 capimsg_setu16(skb->data, 2, mp->ap->applid);
43606 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43607 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43608- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43609+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43610 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43611 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43612 capimsg_setu16(skb->data, 16, len); /* Data length */
43613diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43614index c44950d..10ac276 100644
43615--- a/drivers/isdn/gigaset/bas-gigaset.c
43616+++ b/drivers/isdn/gigaset/bas-gigaset.c
43617@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43618
43619
43620 static const struct gigaset_ops gigops = {
43621- gigaset_write_cmd,
43622- gigaset_write_room,
43623- gigaset_chars_in_buffer,
43624- gigaset_brkchars,
43625- gigaset_init_bchannel,
43626- gigaset_close_bchannel,
43627- gigaset_initbcshw,
43628- gigaset_freebcshw,
43629- gigaset_reinitbcshw,
43630- gigaset_initcshw,
43631- gigaset_freecshw,
43632- gigaset_set_modem_ctrl,
43633- gigaset_baud_rate,
43634- gigaset_set_line_ctrl,
43635- gigaset_isoc_send_skb,
43636- gigaset_isoc_input,
43637+ .write_cmd = gigaset_write_cmd,
43638+ .write_room = gigaset_write_room,
43639+ .chars_in_buffer = gigaset_chars_in_buffer,
43640+ .brkchars = gigaset_brkchars,
43641+ .init_bchannel = gigaset_init_bchannel,
43642+ .close_bchannel = gigaset_close_bchannel,
43643+ .initbcshw = gigaset_initbcshw,
43644+ .freebcshw = gigaset_freebcshw,
43645+ .reinitbcshw = gigaset_reinitbcshw,
43646+ .initcshw = gigaset_initcshw,
43647+ .freecshw = gigaset_freecshw,
43648+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43649+ .baud_rate = gigaset_baud_rate,
43650+ .set_line_ctrl = gigaset_set_line_ctrl,
43651+ .send_skb = gigaset_isoc_send_skb,
43652+ .handle_input = gigaset_isoc_input,
43653 };
43654
43655 /* bas_gigaset_init
43656diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43657index 600c79b..3752bab 100644
43658--- a/drivers/isdn/gigaset/interface.c
43659+++ b/drivers/isdn/gigaset/interface.c
43660@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43661 }
43662 tty->driver_data = cs;
43663
43664- ++cs->port.count;
43665+ atomic_inc(&cs->port.count);
43666
43667- if (cs->port.count == 1) {
43668+ if (atomic_read(&cs->port.count) == 1) {
43669 tty_port_tty_set(&cs->port, tty);
43670 cs->port.low_latency = 1;
43671 }
43672@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43673
43674 if (!cs->connected)
43675 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43676- else if (!cs->port.count)
43677+ else if (!atomic_read(&cs->port.count))
43678 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43679- else if (!--cs->port.count)
43680+ else if (!atomic_dec_return(&cs->port.count))
43681 tty_port_tty_set(&cs->port, NULL);
43682
43683 mutex_unlock(&cs->mutex);
43684diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43685index 8c91fd5..14f13ce 100644
43686--- a/drivers/isdn/gigaset/ser-gigaset.c
43687+++ b/drivers/isdn/gigaset/ser-gigaset.c
43688@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43689 }
43690
43691 static const struct gigaset_ops ops = {
43692- gigaset_write_cmd,
43693- gigaset_write_room,
43694- gigaset_chars_in_buffer,
43695- gigaset_brkchars,
43696- gigaset_init_bchannel,
43697- gigaset_close_bchannel,
43698- gigaset_initbcshw,
43699- gigaset_freebcshw,
43700- gigaset_reinitbcshw,
43701- gigaset_initcshw,
43702- gigaset_freecshw,
43703- gigaset_set_modem_ctrl,
43704- gigaset_baud_rate,
43705- gigaset_set_line_ctrl,
43706- gigaset_m10x_send_skb, /* asyncdata.c */
43707- gigaset_m10x_input, /* asyncdata.c */
43708+ .write_cmd = gigaset_write_cmd,
43709+ .write_room = gigaset_write_room,
43710+ .chars_in_buffer = gigaset_chars_in_buffer,
43711+ .brkchars = gigaset_brkchars,
43712+ .init_bchannel = gigaset_init_bchannel,
43713+ .close_bchannel = gigaset_close_bchannel,
43714+ .initbcshw = gigaset_initbcshw,
43715+ .freebcshw = gigaset_freebcshw,
43716+ .reinitbcshw = gigaset_reinitbcshw,
43717+ .initcshw = gigaset_initcshw,
43718+ .freecshw = gigaset_freecshw,
43719+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43720+ .baud_rate = gigaset_baud_rate,
43721+ .set_line_ctrl = gigaset_set_line_ctrl,
43722+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43723+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43724 };
43725
43726
43727diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43728index d0a41cb..b953e50 100644
43729--- a/drivers/isdn/gigaset/usb-gigaset.c
43730+++ b/drivers/isdn/gigaset/usb-gigaset.c
43731@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43732 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43733 memcpy(cs->hw.usb->bchars, buf, 6);
43734 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43735- 0, 0, &buf, 6, 2000);
43736+ 0, 0, buf, 6, 2000);
43737 }
43738
43739 static void gigaset_freebcshw(struct bc_state *bcs)
43740@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43741 }
43742
43743 static const struct gigaset_ops ops = {
43744- gigaset_write_cmd,
43745- gigaset_write_room,
43746- gigaset_chars_in_buffer,
43747- gigaset_brkchars,
43748- gigaset_init_bchannel,
43749- gigaset_close_bchannel,
43750- gigaset_initbcshw,
43751- gigaset_freebcshw,
43752- gigaset_reinitbcshw,
43753- gigaset_initcshw,
43754- gigaset_freecshw,
43755- gigaset_set_modem_ctrl,
43756- gigaset_baud_rate,
43757- gigaset_set_line_ctrl,
43758- gigaset_m10x_send_skb,
43759- gigaset_m10x_input,
43760+ .write_cmd = gigaset_write_cmd,
43761+ .write_room = gigaset_write_room,
43762+ .chars_in_buffer = gigaset_chars_in_buffer,
43763+ .brkchars = gigaset_brkchars,
43764+ .init_bchannel = gigaset_init_bchannel,
43765+ .close_bchannel = gigaset_close_bchannel,
43766+ .initbcshw = gigaset_initbcshw,
43767+ .freebcshw = gigaset_freebcshw,
43768+ .reinitbcshw = gigaset_reinitbcshw,
43769+ .initcshw = gigaset_initcshw,
43770+ .freecshw = gigaset_freecshw,
43771+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43772+ .baud_rate = gigaset_baud_rate,
43773+ .set_line_ctrl = gigaset_set_line_ctrl,
43774+ .send_skb = gigaset_m10x_send_skb,
43775+ .handle_input = gigaset_m10x_input,
43776 };
43777
43778 /*
43779diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43780index 4d9b195..455075c 100644
43781--- a/drivers/isdn/hardware/avm/b1.c
43782+++ b/drivers/isdn/hardware/avm/b1.c
43783@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43784 }
43785 if (left) {
43786 if (t4file->user) {
43787- if (copy_from_user(buf, dp, left))
43788+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43789 return -EFAULT;
43790 } else {
43791 memcpy(buf, dp, left);
43792@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43793 }
43794 if (left) {
43795 if (config->user) {
43796- if (copy_from_user(buf, dp, left))
43797+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43798 return -EFAULT;
43799 } else {
43800 memcpy(buf, dp, left);
43801diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43802index 9bb12ba..d4262f7 100644
43803--- a/drivers/isdn/i4l/isdn_common.c
43804+++ b/drivers/isdn/i4l/isdn_common.c
43805@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43806 } else
43807 return -EINVAL;
43808 case IIOCDBGVAR:
43809+ if (!capable(CAP_SYS_RAWIO))
43810+ return -EPERM;
43811 if (arg) {
43812 if (copy_to_user(argp, &dev, sizeof(ulong)))
43813 return -EFAULT;
43814diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43815index 91d5730..336523e 100644
43816--- a/drivers/isdn/i4l/isdn_concap.c
43817+++ b/drivers/isdn/i4l/isdn_concap.c
43818@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43819 }
43820
43821 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43822- &isdn_concap_dl_data_req,
43823- &isdn_concap_dl_connect_req,
43824- &isdn_concap_dl_disconn_req
43825+ .data_req = &isdn_concap_dl_data_req,
43826+ .connect_req = &isdn_concap_dl_connect_req,
43827+ .disconn_req = &isdn_concap_dl_disconn_req
43828 };
43829
43830 /* The following should better go into a dedicated source file such that
43831diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43832index 3c5f249..5fac4d0 100644
43833--- a/drivers/isdn/i4l/isdn_tty.c
43834+++ b/drivers/isdn/i4l/isdn_tty.c
43835@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43836
43837 #ifdef ISDN_DEBUG_MODEM_OPEN
43838 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43839- port->count);
43840+ atomic_read(&port->count));
43841 #endif
43842- port->count++;
43843+ atomic_inc(&port->count);
43844 port->tty = tty;
43845 /*
43846 * Start up serial port
43847@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43848 #endif
43849 return;
43850 }
43851- if ((tty->count == 1) && (port->count != 1)) {
43852+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43853 /*
43854 * Uh, oh. tty->count is 1, which means that the tty
43855 * structure will be freed. Info->count should always
43856@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43857 * serial port won't be shutdown.
43858 */
43859 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43860- "info->count is %d\n", port->count);
43861- port->count = 1;
43862+ "info->count is %d\n", atomic_read(&port->count));
43863+ atomic_set(&port->count, 1);
43864 }
43865- if (--port->count < 0) {
43866+ if (atomic_dec_return(&port->count) < 0) {
43867 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43868- info->line, port->count);
43869- port->count = 0;
43870+ info->line, atomic_read(&port->count));
43871+ atomic_set(&port->count, 0);
43872 }
43873- if (port->count) {
43874+ if (atomic_read(&port->count)) {
43875 #ifdef ISDN_DEBUG_MODEM_OPEN
43876 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43877 #endif
43878@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43879 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43880 return;
43881 isdn_tty_shutdown(info);
43882- port->count = 0;
43883+ atomic_set(&port->count, 0);
43884 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43885 port->tty = NULL;
43886 wake_up_interruptible(&port->open_wait);
43887@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43888 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43889 modem_info *info = &dev->mdm.info[i];
43890
43891- if (info->port.count == 0)
43892+ if (atomic_read(&info->port.count) == 0)
43893 continue;
43894 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43895 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43896diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43897index e2d4e58..40cd045 100644
43898--- a/drivers/isdn/i4l/isdn_x25iface.c
43899+++ b/drivers/isdn/i4l/isdn_x25iface.c
43900@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43901
43902
43903 static struct concap_proto_ops ix25_pops = {
43904- &isdn_x25iface_proto_new,
43905- &isdn_x25iface_proto_del,
43906- &isdn_x25iface_proto_restart,
43907- &isdn_x25iface_proto_close,
43908- &isdn_x25iface_xmit,
43909- &isdn_x25iface_receive,
43910- &isdn_x25iface_connect_ind,
43911- &isdn_x25iface_disconn_ind
43912+ .proto_new = &isdn_x25iface_proto_new,
43913+ .proto_del = &isdn_x25iface_proto_del,
43914+ .restart = &isdn_x25iface_proto_restart,
43915+ .close = &isdn_x25iface_proto_close,
43916+ .encap_and_xmit = &isdn_x25iface_xmit,
43917+ .data_ind = &isdn_x25iface_receive,
43918+ .connect_ind = &isdn_x25iface_connect_ind,
43919+ .disconn_ind = &isdn_x25iface_disconn_ind
43920 };
43921
43922 /* error message helper function */
43923diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43924index 53d487f..cae33fe 100644
43925--- a/drivers/isdn/icn/icn.c
43926+++ b/drivers/isdn/icn/icn.c
43927@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43928 if (count > len)
43929 count = len;
43930 if (user) {
43931- if (copy_from_user(msg, buf, count))
43932+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43933 return -EFAULT;
43934 } else
43935 memcpy(msg, buf, count);
43936@@ -1155,7 +1155,7 @@ icn_command(isdn_ctrl *c, icn_card *card)
43937 ulong a;
43938 ulong flags;
43939 int i;
43940- char cbuf[60];
43941+ char cbuf[80];
43942 isdn_ctrl cmd;
43943 icn_cdef cdef;
43944 char __user *arg;
43945@@ -1309,7 +1309,6 @@ icn_command(isdn_ctrl *c, icn_card *card)
43946 break;
43947 if ((c->arg & 255) < ICN_BCH) {
43948 char *p;
43949- char dial[50];
43950 char dcode[4];
43951
43952 a = c->arg;
43953@@ -1321,10 +1320,10 @@ icn_command(isdn_ctrl *c, icn_card *card)
43954 } else
43955 /* Normal Dial */
43956 strcpy(dcode, "CAL");
43957- strcpy(dial, p);
43958- sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43959- dcode, dial, c->parm.setup.si1,
43960- c->parm.setup.si2, c->parm.setup.eazmsn);
43961+ snprintf(cbuf, sizeof(cbuf),
43962+ "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43963+ dcode, p, c->parm.setup.si1,
43964+ c->parm.setup.si2, c->parm.setup.eazmsn);
43965 i = icn_writecmd(cbuf, strlen(cbuf), 0, card);
43966 }
43967 break;
43968diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43969index a4f05c5..1433bc5 100644
43970--- a/drivers/isdn/mISDN/dsp_cmx.c
43971+++ b/drivers/isdn/mISDN/dsp_cmx.c
43972@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43973 static u16 dsp_count; /* last sample count */
43974 static int dsp_count_valid; /* if we have last sample count */
43975
43976-void
43977+void __intentional_overflow(-1)
43978 dsp_cmx_send(void *arg)
43979 {
43980 struct dsp_conf *conf;
43981diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43982index d93e245..e7ece6b 100644
43983--- a/drivers/leds/leds-clevo-mail.c
43984+++ b/drivers/leds/leds-clevo-mail.c
43985@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43986 * detected as working, but in reality it is not) as low as
43987 * possible.
43988 */
43989-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43990+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43991 {
43992 .callback = clevo_mail_led_dmi_callback,
43993 .ident = "Clevo D410J",
43994diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43995index 5b8f938..b73d657 100644
43996--- a/drivers/leds/leds-ss4200.c
43997+++ b/drivers/leds/leds-ss4200.c
43998@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43999 * detected as working, but in reality it is not) as low as
44000 * possible.
44001 */
44002-static struct dmi_system_id nas_led_whitelist[] __initdata = {
44003+static struct dmi_system_id nas_led_whitelist[] __initconst = {
44004 {
44005 .callback = ss4200_led_dmi_callback,
44006 .ident = "Intel SS4200-E",
44007diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44008index 0bf1e4e..b4bf44e 100644
44009--- a/drivers/lguest/core.c
44010+++ b/drivers/lguest/core.c
44011@@ -97,9 +97,17 @@ static __init int map_switcher(void)
44012 * The end address needs +1 because __get_vm_area allocates an
44013 * extra guard page, so we need space for that.
44014 */
44015+
44016+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44017+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44018+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44019+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44020+#else
44021 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44022 VM_ALLOC, switcher_addr, switcher_addr
44023 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44024+#endif
44025+
44026 if (!switcher_vma) {
44027 err = -ENOMEM;
44028 printk("lguest: could not map switcher pages high\n");
44029@@ -124,7 +132,7 @@ static __init int map_switcher(void)
44030 * Now the Switcher is mapped at the right address, we can't fail!
44031 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44032 */
44033- memcpy(switcher_vma->addr, start_switcher_text,
44034+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44035 end_switcher_text - start_switcher_text);
44036
44037 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44038diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44039index bfb39bb..08a603b 100644
44040--- a/drivers/lguest/page_tables.c
44041+++ b/drivers/lguest/page_tables.c
44042@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44043 /*:*/
44044
44045 #ifdef CONFIG_X86_PAE
44046-static void release_pmd(pmd_t *spmd)
44047+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44048 {
44049 /* If the entry's not present, there's nothing to release. */
44050 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44051diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44052index 922a1ac..9dd0c2a 100644
44053--- a/drivers/lguest/x86/core.c
44054+++ b/drivers/lguest/x86/core.c
44055@@ -59,7 +59,7 @@ static struct {
44056 /* Offset from where switcher.S was compiled to where we've copied it */
44057 static unsigned long switcher_offset(void)
44058 {
44059- return switcher_addr - (unsigned long)start_switcher_text;
44060+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44061 }
44062
44063 /* This cpu's struct lguest_pages (after the Switcher text page) */
44064@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44065 * These copies are pretty cheap, so we do them unconditionally: */
44066 /* Save the current Host top-level page directory.
44067 */
44068+
44069+#ifdef CONFIG_PAX_PER_CPU_PGD
44070+ pages->state.host_cr3 = read_cr3();
44071+#else
44072 pages->state.host_cr3 = __pa(current->mm->pgd);
44073+#endif
44074+
44075 /*
44076 * Set up the Guest's page tables to see this CPU's pages (and no
44077 * other CPU's pages).
44078@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44079 * compiled-in switcher code and the high-mapped copy we just made.
44080 */
44081 for (i = 0; i < IDT_ENTRIES; i++)
44082- default_idt_entries[i] += switcher_offset();
44083+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44084
44085 /*
44086 * Set up the Switcher's per-cpu areas.
44087@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44088 * it will be undisturbed when we switch. To change %cs and jump we
44089 * need this structure to feed to Intel's "lcall" instruction.
44090 */
44091- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44092+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44093 lguest_entry.segment = LGUEST_CS;
44094
44095 /*
44096diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44097index 40634b0..4f5855e 100644
44098--- a/drivers/lguest/x86/switcher_32.S
44099+++ b/drivers/lguest/x86/switcher_32.S
44100@@ -87,6 +87,7 @@
44101 #include <asm/page.h>
44102 #include <asm/segment.h>
44103 #include <asm/lguest.h>
44104+#include <asm/processor-flags.h>
44105
44106 // We mark the start of the code to copy
44107 // It's placed in .text tho it's never run here
44108@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44109 // Changes type when we load it: damn Intel!
44110 // For after we switch over our page tables
44111 // That entry will be read-only: we'd crash.
44112+
44113+#ifdef CONFIG_PAX_KERNEXEC
44114+ mov %cr0, %edx
44115+ xor $X86_CR0_WP, %edx
44116+ mov %edx, %cr0
44117+#endif
44118+
44119 movl $(GDT_ENTRY_TSS*8), %edx
44120 ltr %dx
44121
44122@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44123 // Let's clear it again for our return.
44124 // The GDT descriptor of the Host
44125 // Points to the table after two "size" bytes
44126- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44127+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44128 // Clear "used" from type field (byte 5, bit 2)
44129- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44130+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44131+
44132+#ifdef CONFIG_PAX_KERNEXEC
44133+ mov %cr0, %eax
44134+ xor $X86_CR0_WP, %eax
44135+ mov %eax, %cr0
44136+#endif
44137
44138 // Once our page table's switched, the Guest is live!
44139 // The Host fades as we run this final step.
44140@@ -295,13 +309,12 @@ deliver_to_host:
44141 // I consulted gcc, and it gave
44142 // These instructions, which I gladly credit:
44143 leal (%edx,%ebx,8), %eax
44144- movzwl (%eax),%edx
44145- movl 4(%eax), %eax
44146- xorw %ax, %ax
44147- orl %eax, %edx
44148+ movl 4(%eax), %edx
44149+ movw (%eax), %dx
44150 // Now the address of the handler's in %edx
44151 // We call it now: its "iret" drops us home.
44152- jmp *%edx
44153+ ljmp $__KERNEL_CS, $1f
44154+1: jmp *%edx
44155
44156 // Every interrupt can come to us here
44157 // But we must truly tell each apart.
44158diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44159index 7ef7461..5a09dac 100644
44160--- a/drivers/md/bcache/closure.h
44161+++ b/drivers/md/bcache/closure.h
44162@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44163 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44164 struct workqueue_struct *wq)
44165 {
44166- BUG_ON(object_is_on_stack(cl));
44167+ BUG_ON(object_starts_on_stack(cl));
44168 closure_set_ip(cl);
44169 cl->fn = fn;
44170 cl->wq = wq;
44171diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44172index 4195a01..42527ac 100644
44173--- a/drivers/md/bitmap.c
44174+++ b/drivers/md/bitmap.c
44175@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44176 chunk_kb ? "KB" : "B");
44177 if (bitmap->storage.file) {
44178 seq_printf(seq, ", file: ");
44179- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44180+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44181 }
44182
44183 seq_printf(seq, "\n");
44184diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44185index 5152142..623d141 100644
44186--- a/drivers/md/dm-ioctl.c
44187+++ b/drivers/md/dm-ioctl.c
44188@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44189 cmd == DM_LIST_VERSIONS_CMD)
44190 return 0;
44191
44192- if ((cmd == DM_DEV_CREATE_CMD)) {
44193+ if (cmd == DM_DEV_CREATE_CMD) {
44194 if (!*param->name) {
44195 DMWARN("name not supplied when creating device");
44196 return -EINVAL;
44197diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44198index 7dfdb5c..4caada6 100644
44199--- a/drivers/md/dm-raid1.c
44200+++ b/drivers/md/dm-raid1.c
44201@@ -40,7 +40,7 @@ enum dm_raid1_error {
44202
44203 struct mirror {
44204 struct mirror_set *ms;
44205- atomic_t error_count;
44206+ atomic_unchecked_t error_count;
44207 unsigned long error_type;
44208 struct dm_dev *dev;
44209 sector_t offset;
44210@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44211 struct mirror *m;
44212
44213 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44214- if (!atomic_read(&m->error_count))
44215+ if (!atomic_read_unchecked(&m->error_count))
44216 return m;
44217
44218 return NULL;
44219@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44220 * simple way to tell if a device has encountered
44221 * errors.
44222 */
44223- atomic_inc(&m->error_count);
44224+ atomic_inc_unchecked(&m->error_count);
44225
44226 if (test_and_set_bit(error_type, &m->error_type))
44227 return;
44228@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44229 struct mirror *m = get_default_mirror(ms);
44230
44231 do {
44232- if (likely(!atomic_read(&m->error_count)))
44233+ if (likely(!atomic_read_unchecked(&m->error_count)))
44234 return m;
44235
44236 if (m-- == ms->mirror)
44237@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44238 {
44239 struct mirror *default_mirror = get_default_mirror(m->ms);
44240
44241- return !atomic_read(&default_mirror->error_count);
44242+ return !atomic_read_unchecked(&default_mirror->error_count);
44243 }
44244
44245 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44246@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44247 */
44248 if (likely(region_in_sync(ms, region, 1)))
44249 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44250- else if (m && atomic_read(&m->error_count))
44251+ else if (m && atomic_read_unchecked(&m->error_count))
44252 m = NULL;
44253
44254 if (likely(m))
44255@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44256 }
44257
44258 ms->mirror[mirror].ms = ms;
44259- atomic_set(&(ms->mirror[mirror].error_count), 0);
44260+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44261 ms->mirror[mirror].error_type = 0;
44262 ms->mirror[mirror].offset = offset;
44263
44264@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44265 */
44266 static char device_status_char(struct mirror *m)
44267 {
44268- if (!atomic_read(&(m->error_count)))
44269+ if (!atomic_read_unchecked(&(m->error_count)))
44270 return 'A';
44271
44272 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44273diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44274index 28a9012..9c0f6a5 100644
44275--- a/drivers/md/dm-stats.c
44276+++ b/drivers/md/dm-stats.c
44277@@ -382,7 +382,7 @@ do_sync_free:
44278 synchronize_rcu_expedited();
44279 dm_stat_free(&s->rcu_head);
44280 } else {
44281- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44282+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44283 call_rcu(&s->rcu_head, dm_stat_free);
44284 }
44285 return 0;
44286@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44287 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44288 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44289 ));
44290- ACCESS_ONCE(last->last_sector) = end_sector;
44291- ACCESS_ONCE(last->last_rw) = bi_rw;
44292+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
44293+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44294 }
44295
44296 rcu_read_lock();
44297diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44298index d1600d2..4c3af3a 100644
44299--- a/drivers/md/dm-stripe.c
44300+++ b/drivers/md/dm-stripe.c
44301@@ -21,7 +21,7 @@ struct stripe {
44302 struct dm_dev *dev;
44303 sector_t physical_start;
44304
44305- atomic_t error_count;
44306+ atomic_unchecked_t error_count;
44307 };
44308
44309 struct stripe_c {
44310@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44311 kfree(sc);
44312 return r;
44313 }
44314- atomic_set(&(sc->stripe[i].error_count), 0);
44315+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44316 }
44317
44318 ti->private = sc;
44319@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44320 DMEMIT("%d ", sc->stripes);
44321 for (i = 0; i < sc->stripes; i++) {
44322 DMEMIT("%s ", sc->stripe[i].dev->name);
44323- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44324+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44325 'D' : 'A';
44326 }
44327 buffer[i] = '\0';
44328@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44329 */
44330 for (i = 0; i < sc->stripes; i++)
44331 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44332- atomic_inc(&(sc->stripe[i].error_count));
44333- if (atomic_read(&(sc->stripe[i].error_count)) <
44334+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
44335+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44336 DM_IO_ERROR_THRESHOLD)
44337 schedule_work(&sc->trigger_event);
44338 }
44339diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44340index 6a7f2b8..fea0bde 100644
44341--- a/drivers/md/dm-table.c
44342+++ b/drivers/md/dm-table.c
44343@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
44344 static int open_dev(struct dm_dev_internal *d, dev_t dev,
44345 struct mapped_device *md)
44346 {
44347- static char *_claim_ptr = "I belong to device-mapper";
44348+ static char _claim_ptr[] = "I belong to device-mapper";
44349 struct block_device *bdev;
44350
44351 int r;
44352@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44353 if (!dev_size)
44354 return 0;
44355
44356- if ((start >= dev_size) || (start + len > dev_size)) {
44357+ if ((start >= dev_size) || (len > dev_size - start)) {
44358 DMWARN("%s: %s too small for target: "
44359 "start=%llu, len=%llu, dev_size=%llu",
44360 dm_device_name(ti->table->md), bdevname(bdev, b),
44361diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44362index b086a94..74cb67e 100644
44363--- a/drivers/md/dm-thin-metadata.c
44364+++ b/drivers/md/dm-thin-metadata.c
44365@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44366 {
44367 pmd->info.tm = pmd->tm;
44368 pmd->info.levels = 2;
44369- pmd->info.value_type.context = pmd->data_sm;
44370+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44371 pmd->info.value_type.size = sizeof(__le64);
44372 pmd->info.value_type.inc = data_block_inc;
44373 pmd->info.value_type.dec = data_block_dec;
44374@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44375
44376 pmd->bl_info.tm = pmd->tm;
44377 pmd->bl_info.levels = 1;
44378- pmd->bl_info.value_type.context = pmd->data_sm;
44379+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44380 pmd->bl_info.value_type.size = sizeof(__le64);
44381 pmd->bl_info.value_type.inc = data_block_inc;
44382 pmd->bl_info.value_type.dec = data_block_dec;
44383diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44384index 8c53b09..f1fb2b0 100644
44385--- a/drivers/md/dm.c
44386+++ b/drivers/md/dm.c
44387@@ -185,9 +185,9 @@ struct mapped_device {
44388 /*
44389 * Event handling.
44390 */
44391- atomic_t event_nr;
44392+ atomic_unchecked_t event_nr;
44393 wait_queue_head_t eventq;
44394- atomic_t uevent_seq;
44395+ atomic_unchecked_t uevent_seq;
44396 struct list_head uevent_list;
44397 spinlock_t uevent_lock; /* Protect access to uevent_list */
44398
44399@@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
44400 spin_lock_init(&md->deferred_lock);
44401 atomic_set(&md->holders, 1);
44402 atomic_set(&md->open_count, 0);
44403- atomic_set(&md->event_nr, 0);
44404- atomic_set(&md->uevent_seq, 0);
44405+ atomic_set_unchecked(&md->event_nr, 0);
44406+ atomic_set_unchecked(&md->uevent_seq, 0);
44407 INIT_LIST_HEAD(&md->uevent_list);
44408 spin_lock_init(&md->uevent_lock);
44409
44410@@ -2043,7 +2043,7 @@ static void event_callback(void *context)
44411
44412 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44413
44414- atomic_inc(&md->event_nr);
44415+ atomic_inc_unchecked(&md->event_nr);
44416 wake_up(&md->eventq);
44417 }
44418
44419@@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44420
44421 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44422 {
44423- return atomic_add_return(1, &md->uevent_seq);
44424+ return atomic_add_return_unchecked(1, &md->uevent_seq);
44425 }
44426
44427 uint32_t dm_get_event_nr(struct mapped_device *md)
44428 {
44429- return atomic_read(&md->event_nr);
44430+ return atomic_read_unchecked(&md->event_nr);
44431 }
44432
44433 int dm_wait_event(struct mapped_device *md, int event_nr)
44434 {
44435 return wait_event_interruptible(md->eventq,
44436- (event_nr != atomic_read(&md->event_nr)));
44437+ (event_nr != atomic_read_unchecked(&md->event_nr)));
44438 }
44439
44440 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44441diff --git a/drivers/md/md.c b/drivers/md/md.c
44442index 4ad5cc4..0f19664 100644
44443--- a/drivers/md/md.c
44444+++ b/drivers/md/md.c
44445@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44446 * start build, activate spare
44447 */
44448 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44449-static atomic_t md_event_count;
44450+static atomic_unchecked_t md_event_count;
44451 void md_new_event(struct mddev *mddev)
44452 {
44453- atomic_inc(&md_event_count);
44454+ atomic_inc_unchecked(&md_event_count);
44455 wake_up(&md_event_waiters);
44456 }
44457 EXPORT_SYMBOL_GPL(md_new_event);
44458@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44459 */
44460 static void md_new_event_inintr(struct mddev *mddev)
44461 {
44462- atomic_inc(&md_event_count);
44463+ atomic_inc_unchecked(&md_event_count);
44464 wake_up(&md_event_waiters);
44465 }
44466
44467@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44468 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44469 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44470 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44471- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44472+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44473
44474 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44475 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44476@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44477 else
44478 sb->resync_offset = cpu_to_le64(0);
44479
44480- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44481+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44482
44483 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44484 sb->size = cpu_to_le64(mddev->dev_sectors);
44485@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44486 static ssize_t
44487 errors_show(struct md_rdev *rdev, char *page)
44488 {
44489- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44490+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44491 }
44492
44493 static ssize_t
44494@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44495 char *e;
44496 unsigned long n = simple_strtoul(buf, &e, 10);
44497 if (*buf && (*e == 0 || *e == '\n')) {
44498- atomic_set(&rdev->corrected_errors, n);
44499+ atomic_set_unchecked(&rdev->corrected_errors, n);
44500 return len;
44501 }
44502 return -EINVAL;
44503@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44504 rdev->sb_loaded = 0;
44505 rdev->bb_page = NULL;
44506 atomic_set(&rdev->nr_pending, 0);
44507- atomic_set(&rdev->read_errors, 0);
44508- atomic_set(&rdev->corrected_errors, 0);
44509+ atomic_set_unchecked(&rdev->read_errors, 0);
44510+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44511
44512 INIT_LIST_HEAD(&rdev->same_set);
44513 init_waitqueue_head(&rdev->blocked_wait);
44514@@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44515
44516 spin_unlock(&pers_lock);
44517 seq_printf(seq, "\n");
44518- seq->poll_event = atomic_read(&md_event_count);
44519+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44520 return 0;
44521 }
44522 if (v == (void*)2) {
44523@@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44524 return error;
44525
44526 seq = file->private_data;
44527- seq->poll_event = atomic_read(&md_event_count);
44528+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44529 return error;
44530 }
44531
44532@@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44533 /* always allow read */
44534 mask = POLLIN | POLLRDNORM;
44535
44536- if (seq->poll_event != atomic_read(&md_event_count))
44537+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44538 mask |= POLLERR | POLLPRI;
44539 return mask;
44540 }
44541@@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44542 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44543 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44544 (int)part_stat_read(&disk->part0, sectors[1]) -
44545- atomic_read(&disk->sync_io);
44546+ atomic_read_unchecked(&disk->sync_io);
44547 /* sync IO will cause sync_io to increase before the disk_stats
44548 * as sync_io is counted when a request starts, and
44549 * disk_stats is counted when it completes.
44550diff --git a/drivers/md/md.h b/drivers/md/md.h
44551index 07bba96..2d6788c 100644
44552--- a/drivers/md/md.h
44553+++ b/drivers/md/md.h
44554@@ -94,13 +94,13 @@ struct md_rdev {
44555 * only maintained for arrays that
44556 * support hot removal
44557 */
44558- atomic_t read_errors; /* number of consecutive read errors that
44559+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44560 * we have tried to ignore.
44561 */
44562 struct timespec last_read_error; /* monotonic time since our
44563 * last read error
44564 */
44565- atomic_t corrected_errors; /* number of corrected read errors,
44566+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44567 * for reporting to userspace and storing
44568 * in superblock.
44569 */
44570@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44571
44572 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44573 {
44574- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44575+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44576 }
44577
44578 struct md_personality
44579diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44580index 786b689..ea8c956 100644
44581--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44582+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44583@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44584 * Flick into a mode where all blocks get allocated in the new area.
44585 */
44586 smm->begin = old_len;
44587- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44588+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44589
44590 /*
44591 * Extend.
44592@@ -710,7 +710,7 @@ out:
44593 /*
44594 * Switch back to normal behaviour.
44595 */
44596- memcpy(sm, &ops, sizeof(*sm));
44597+ memcpy((void *)sm, &ops, sizeof(*sm));
44598 return r;
44599 }
44600
44601diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44602index 3e6d115..ffecdeb 100644
44603--- a/drivers/md/persistent-data/dm-space-map.h
44604+++ b/drivers/md/persistent-data/dm-space-map.h
44605@@ -71,6 +71,7 @@ struct dm_space_map {
44606 dm_sm_threshold_fn fn,
44607 void *context);
44608 };
44609+typedef struct dm_space_map __no_const dm_space_map_no_const;
44610
44611 /*----------------------------------------------------------------*/
44612
44613diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44614index 4a6ca1c..e952750 100644
44615--- a/drivers/md/raid1.c
44616+++ b/drivers/md/raid1.c
44617@@ -1922,7 +1922,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44618 if (r1_sync_page_io(rdev, sect, s,
44619 bio->bi_io_vec[idx].bv_page,
44620 READ) != 0)
44621- atomic_add(s, &rdev->corrected_errors);
44622+ atomic_add_unchecked(s, &rdev->corrected_errors);
44623 }
44624 sectors -= s;
44625 sect += s;
44626@@ -2156,7 +2156,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44627 test_bit(In_sync, &rdev->flags)) {
44628 if (r1_sync_page_io(rdev, sect, s,
44629 conf->tmppage, READ)) {
44630- atomic_add(s, &rdev->corrected_errors);
44631+ atomic_add_unchecked(s, &rdev->corrected_errors);
44632 printk(KERN_INFO
44633 "md/raid1:%s: read error corrected "
44634 "(%d sectors at %llu on %s)\n",
44635diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44636index 33fc408..fc61709 100644
44637--- a/drivers/md/raid10.c
44638+++ b/drivers/md/raid10.c
44639@@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
44640 /* The write handler will notice the lack of
44641 * R10BIO_Uptodate and record any errors etc
44642 */
44643- atomic_add(r10_bio->sectors,
44644+ atomic_add_unchecked(r10_bio->sectors,
44645 &conf->mirrors[d].rdev->corrected_errors);
44646
44647 /* for reconstruct, we always reschedule after a read.
44648@@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44649 {
44650 struct timespec cur_time_mon;
44651 unsigned long hours_since_last;
44652- unsigned int read_errors = atomic_read(&rdev->read_errors);
44653+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44654
44655 ktime_get_ts(&cur_time_mon);
44656
44657@@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44658 * overflowing the shift of read_errors by hours_since_last.
44659 */
44660 if (hours_since_last >= 8 * sizeof(read_errors))
44661- atomic_set(&rdev->read_errors, 0);
44662+ atomic_set_unchecked(&rdev->read_errors, 0);
44663 else
44664- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44665+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44666 }
44667
44668 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44669@@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44670 return;
44671
44672 check_decay_read_errors(mddev, rdev);
44673- atomic_inc(&rdev->read_errors);
44674- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44675+ atomic_inc_unchecked(&rdev->read_errors);
44676+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44677 char b[BDEVNAME_SIZE];
44678 bdevname(rdev->bdev, b);
44679
44680@@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44681 "md/raid10:%s: %s: Raid device exceeded "
44682 "read_error threshold [cur %d:max %d]\n",
44683 mdname(mddev), b,
44684- atomic_read(&rdev->read_errors), max_read_errors);
44685+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44686 printk(KERN_NOTICE
44687 "md/raid10:%s: %s: Failing raid device\n",
44688 mdname(mddev), b);
44689@@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44690 sect +
44691 choose_data_offset(r10_bio, rdev)),
44692 bdevname(rdev->bdev, b));
44693- atomic_add(s, &rdev->corrected_errors);
44694+ atomic_add_unchecked(s, &rdev->corrected_errors);
44695 }
44696
44697 rdev_dec_pending(rdev, mddev);
44698diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44699index 16f5c21..4df20dc 100644
44700--- a/drivers/md/raid5.c
44701+++ b/drivers/md/raid5.c
44702@@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44703 mdname(conf->mddev), STRIPE_SECTORS,
44704 (unsigned long long)s,
44705 bdevname(rdev->bdev, b));
44706- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44707+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44708 clear_bit(R5_ReadError, &sh->dev[i].flags);
44709 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44710 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44711 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44712
44713- if (atomic_read(&rdev->read_errors))
44714- atomic_set(&rdev->read_errors, 0);
44715+ if (atomic_read_unchecked(&rdev->read_errors))
44716+ atomic_set_unchecked(&rdev->read_errors, 0);
44717 } else {
44718 const char *bdn = bdevname(rdev->bdev, b);
44719 int retry = 0;
44720 int set_bad = 0;
44721
44722 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44723- atomic_inc(&rdev->read_errors);
44724+ atomic_inc_unchecked(&rdev->read_errors);
44725 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44726 printk_ratelimited(
44727 KERN_WARNING
44728@@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44729 mdname(conf->mddev),
44730 (unsigned long long)s,
44731 bdn);
44732- } else if (atomic_read(&rdev->read_errors)
44733+ } else if (atomic_read_unchecked(&rdev->read_errors)
44734 > conf->max_nr_stripes)
44735 printk(KERN_WARNING
44736 "md/raid:%s: Too many read errors, failing device %s.\n",
44737diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44738index 983db75..ef9248c 100644
44739--- a/drivers/media/dvb-core/dvbdev.c
44740+++ b/drivers/media/dvb-core/dvbdev.c
44741@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44742 const struct dvb_device *template, void *priv, int type)
44743 {
44744 struct dvb_device *dvbdev;
44745- struct file_operations *dvbdevfops;
44746+ file_operations_no_const *dvbdevfops;
44747 struct device *clsdev;
44748 int minor;
44749 int id;
44750diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44751index 9b6c3bb..baeb5c7 100644
44752--- a/drivers/media/dvb-frontends/dib3000.h
44753+++ b/drivers/media/dvb-frontends/dib3000.h
44754@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44755 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44756 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44757 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44758-};
44759+} __no_const;
44760
44761 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44762 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44763diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
44764index d5a7a13..703560f 100644
44765--- a/drivers/media/media-device.c
44766+++ b/drivers/media/media-device.c
44767@@ -93,6 +93,7 @@ static long media_device_enum_entities(struct media_device *mdev,
44768 struct media_entity *ent;
44769 struct media_entity_desc u_ent;
44770
44771+ memset(&u_ent, 0, sizeof(u_ent));
44772 if (copy_from_user(&u_ent.id, &uent->id, sizeof(u_ent.id)))
44773 return -EFAULT;
44774
44775diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44776index ed8cb90..5ef7f79 100644
44777--- a/drivers/media/pci/cx88/cx88-video.c
44778+++ b/drivers/media/pci/cx88/cx88-video.c
44779@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44780
44781 /* ------------------------------------------------------------------ */
44782
44783-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44784-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44785-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44786+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44787+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44788+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44789
44790 module_param_array(video_nr, int, NULL, 0444);
44791 module_param_array(vbi_nr, int, NULL, 0444);
44792diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44793index 802642d..5534900 100644
44794--- a/drivers/media/pci/ivtv/ivtv-driver.c
44795+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44796@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44797 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44798
44799 /* ivtv instance counter */
44800-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44801+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44802
44803 /* Parameter declarations */
44804 static int cardtype[IVTV_MAX_CARDS];
44805diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44806index dfd0a21..6bbb465 100644
44807--- a/drivers/media/platform/omap/omap_vout.c
44808+++ b/drivers/media/platform/omap/omap_vout.c
44809@@ -63,7 +63,6 @@ enum omap_vout_channels {
44810 OMAP_VIDEO2,
44811 };
44812
44813-static struct videobuf_queue_ops video_vbq_ops;
44814 /* Variables configurable through module params*/
44815 static u32 video1_numbuffers = 3;
44816 static u32 video2_numbuffers = 3;
44817@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44818 {
44819 struct videobuf_queue *q;
44820 struct omap_vout_device *vout = NULL;
44821+ static struct videobuf_queue_ops video_vbq_ops = {
44822+ .buf_setup = omap_vout_buffer_setup,
44823+ .buf_prepare = omap_vout_buffer_prepare,
44824+ .buf_release = omap_vout_buffer_release,
44825+ .buf_queue = omap_vout_buffer_queue,
44826+ };
44827
44828 vout = video_drvdata(file);
44829 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44830@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44831 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44832
44833 q = &vout->vbq;
44834- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44835- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44836- video_vbq_ops.buf_release = omap_vout_buffer_release;
44837- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44838 spin_lock_init(&vout->vbq_lock);
44839
44840 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44841diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44842index fb2acc5..a2fcbdc4 100644
44843--- a/drivers/media/platform/s5p-tv/mixer.h
44844+++ b/drivers/media/platform/s5p-tv/mixer.h
44845@@ -156,7 +156,7 @@ struct mxr_layer {
44846 /** layer index (unique identifier) */
44847 int idx;
44848 /** callbacks for layer methods */
44849- struct mxr_layer_ops ops;
44850+ struct mxr_layer_ops *ops;
44851 /** format array */
44852 const struct mxr_format **fmt_array;
44853 /** size of format array */
44854diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44855index 74344c7..a39e70e 100644
44856--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44857+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44858@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44859 {
44860 struct mxr_layer *layer;
44861 int ret;
44862- struct mxr_layer_ops ops = {
44863+ static struct mxr_layer_ops ops = {
44864 .release = mxr_graph_layer_release,
44865 .buffer_set = mxr_graph_buffer_set,
44866 .stream_set = mxr_graph_stream_set,
44867diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44868index b713403..53cb5ad 100644
44869--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44870+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44871@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44872 layer->update_buf = next;
44873 }
44874
44875- layer->ops.buffer_set(layer, layer->update_buf);
44876+ layer->ops->buffer_set(layer, layer->update_buf);
44877
44878 if (done && done != layer->shadow_buf)
44879 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44880diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44881index c5059ba..2649f28 100644
44882--- a/drivers/media/platform/s5p-tv/mixer_video.c
44883+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44884@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44885 layer->geo.src.height = layer->geo.src.full_height;
44886
44887 mxr_geometry_dump(mdev, &layer->geo);
44888- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44889+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44890 mxr_geometry_dump(mdev, &layer->geo);
44891 }
44892
44893@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44894 layer->geo.dst.full_width = mbus_fmt.width;
44895 layer->geo.dst.full_height = mbus_fmt.height;
44896 layer->geo.dst.field = mbus_fmt.field;
44897- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44898+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44899
44900 mxr_geometry_dump(mdev, &layer->geo);
44901 }
44902@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44903 /* set source size to highest accepted value */
44904 geo->src.full_width = max(geo->dst.full_width, pix->width);
44905 geo->src.full_height = max(geo->dst.full_height, pix->height);
44906- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44907+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44908 mxr_geometry_dump(mdev, &layer->geo);
44909 /* set cropping to total visible screen */
44910 geo->src.width = pix->width;
44911@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44912 geo->src.x_offset = 0;
44913 geo->src.y_offset = 0;
44914 /* assure consistency of geometry */
44915- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44916+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44917 mxr_geometry_dump(mdev, &layer->geo);
44918 /* set full size to lowest possible value */
44919 geo->src.full_width = 0;
44920 geo->src.full_height = 0;
44921- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44922+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44923 mxr_geometry_dump(mdev, &layer->geo);
44924
44925 /* returning results */
44926@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44927 target->width = s->r.width;
44928 target->height = s->r.height;
44929
44930- layer->ops.fix_geometry(layer, stage, s->flags);
44931+ layer->ops->fix_geometry(layer, stage, s->flags);
44932
44933 /* retrieve update selection rectangle */
44934 res.left = target->x_offset;
44935@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44936 mxr_output_get(mdev);
44937
44938 mxr_layer_update_output(layer);
44939- layer->ops.format_set(layer);
44940+ layer->ops->format_set(layer);
44941 /* enabling layer in hardware */
44942 spin_lock_irqsave(&layer->enq_slock, flags);
44943 layer->state = MXR_LAYER_STREAMING;
44944 spin_unlock_irqrestore(&layer->enq_slock, flags);
44945
44946- layer->ops.stream_set(layer, MXR_ENABLE);
44947+ layer->ops->stream_set(layer, MXR_ENABLE);
44948 mxr_streamer_get(mdev);
44949
44950 return 0;
44951@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44952 spin_unlock_irqrestore(&layer->enq_slock, flags);
44953
44954 /* disabling layer in hardware */
44955- layer->ops.stream_set(layer, MXR_DISABLE);
44956+ layer->ops->stream_set(layer, MXR_DISABLE);
44957 /* remove one streamer */
44958 mxr_streamer_put(mdev);
44959 /* allow changes in output configuration */
44960@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44961
44962 void mxr_layer_release(struct mxr_layer *layer)
44963 {
44964- if (layer->ops.release)
44965- layer->ops.release(layer);
44966+ if (layer->ops->release)
44967+ layer->ops->release(layer);
44968 }
44969
44970 void mxr_base_layer_release(struct mxr_layer *layer)
44971@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44972
44973 layer->mdev = mdev;
44974 layer->idx = idx;
44975- layer->ops = *ops;
44976+ layer->ops = ops;
44977
44978 spin_lock_init(&layer->enq_slock);
44979 INIT_LIST_HEAD(&layer->enq_list);
44980diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44981index c9388c4..ce71ece 100644
44982--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44983+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44984@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44985 {
44986 struct mxr_layer *layer;
44987 int ret;
44988- struct mxr_layer_ops ops = {
44989+ static struct mxr_layer_ops ops = {
44990 .release = mxr_vp_layer_release,
44991 .buffer_set = mxr_vp_buffer_set,
44992 .stream_set = mxr_vp_stream_set,
44993diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44994index 2d4e73b..8b4d5b6 100644
44995--- a/drivers/media/platform/vivi.c
44996+++ b/drivers/media/platform/vivi.c
44997@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44998 MODULE_LICENSE("Dual BSD/GPL");
44999 MODULE_VERSION(VIVI_VERSION);
45000
45001-static unsigned video_nr = -1;
45002-module_param(video_nr, uint, 0644);
45003+static int video_nr = -1;
45004+module_param(video_nr, int, 0644);
45005 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
45006
45007 static unsigned n_devs = 1;
45008diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45009index 545c04c..a14bded 100644
45010--- a/drivers/media/radio/radio-cadet.c
45011+++ b/drivers/media/radio/radio-cadet.c
45012@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45013 unsigned char readbuf[RDS_BUFFER];
45014 int i = 0;
45015
45016+ if (count > RDS_BUFFER)
45017+ return -EFAULT;
45018 mutex_lock(&dev->lock);
45019 if (dev->rdsstat == 0)
45020 cadet_start_rds(dev);
45021@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45022 while (i < count && dev->rdsin != dev->rdsout)
45023 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45024
45025- if (i && copy_to_user(data, readbuf, i))
45026+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
45027 i = -EFAULT;
45028 unlock:
45029 mutex_unlock(&dev->lock);
45030diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45031index 5236035..c622c74 100644
45032--- a/drivers/media/radio/radio-maxiradio.c
45033+++ b/drivers/media/radio/radio-maxiradio.c
45034@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45035 /* TEA5757 pin mappings */
45036 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45037
45038-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45039+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45040
45041 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45042 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45043diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45044index 050b3bb..79f62b9 100644
45045--- a/drivers/media/radio/radio-shark.c
45046+++ b/drivers/media/radio/radio-shark.c
45047@@ -79,7 +79,7 @@ struct shark_device {
45048 u32 last_val;
45049 };
45050
45051-static atomic_t shark_instance = ATOMIC_INIT(0);
45052+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45053
45054 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45055 {
45056diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45057index 8654e0d..0608a64 100644
45058--- a/drivers/media/radio/radio-shark2.c
45059+++ b/drivers/media/radio/radio-shark2.c
45060@@ -74,7 +74,7 @@ struct shark_device {
45061 u8 *transfer_buffer;
45062 };
45063
45064-static atomic_t shark_instance = ATOMIC_INIT(0);
45065+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45066
45067 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45068 {
45069diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45070index 2fd9009..278cc1e 100644
45071--- a/drivers/media/radio/radio-si476x.c
45072+++ b/drivers/media/radio/radio-si476x.c
45073@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45074 struct si476x_radio *radio;
45075 struct v4l2_ctrl *ctrl;
45076
45077- static atomic_t instance = ATOMIC_INIT(0);
45078+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
45079
45080 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45081 if (!radio)
45082diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
45083index a1c641e..3007da9 100644
45084--- a/drivers/media/usb/dvb-usb/cxusb.c
45085+++ b/drivers/media/usb/dvb-usb/cxusb.c
45086@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
45087
45088 struct dib0700_adapter_state {
45089 int (*set_param_save) (struct dvb_frontend *);
45090-};
45091+} __no_const;
45092
45093 static int dib7070_set_param_override(struct dvb_frontend *fe)
45094 {
45095diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45096index ae0f56a..ec71784 100644
45097--- a/drivers/media/usb/dvb-usb/dw2102.c
45098+++ b/drivers/media/usb/dvb-usb/dw2102.c
45099@@ -118,7 +118,7 @@ struct su3000_state {
45100
45101 struct s6x0_state {
45102 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45103-};
45104+} __no_const;
45105
45106 /* debug */
45107 static int dvb_usb_dw2102_debug;
45108diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45109index b63a5e5..b16a062 100644
45110--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45111+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45112@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
45113 __u32 reserved;
45114 };
45115
45116-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45117+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45118 enum v4l2_memory memory)
45119 {
45120 void __user *up_pln;
45121@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45122 return 0;
45123 }
45124
45125-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45126+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45127 enum v4l2_memory memory)
45128 {
45129 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
45130@@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45131 * by passing a very big num_planes value */
45132 uplane = compat_alloc_user_space(num_planes *
45133 sizeof(struct v4l2_plane));
45134- kp->m.planes = uplane;
45135+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
45136
45137 while (--num_planes >= 0) {
45138 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
45139@@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45140 if (num_planes == 0)
45141 return 0;
45142
45143- uplane = kp->m.planes;
45144+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
45145 if (get_user(p, &up->m.planes))
45146 return -EFAULT;
45147 uplane32 = compat_ptr(p);
45148@@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
45149 get_user(kp->capability, &up->capability) ||
45150 get_user(kp->flags, &up->flags))
45151 return -EFAULT;
45152- kp->base = compat_ptr(tmp);
45153+ kp->base = (void __force_kernel *)compat_ptr(tmp);
45154 get_v4l2_pix_format(&kp->fmt, &up->fmt);
45155 return 0;
45156 }
45157@@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45158 n * sizeof(struct v4l2_ext_control32)))
45159 return -EFAULT;
45160 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
45161- kp->controls = kcontrols;
45162+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
45163 while (--n >= 0) {
45164 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
45165 return -EFAULT;
45166@@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45167 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
45168 {
45169 struct v4l2_ext_control32 __user *ucontrols;
45170- struct v4l2_ext_control __user *kcontrols = kp->controls;
45171+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
45172 int n = kp->count;
45173 compat_caddr_t p;
45174
45175@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
45176 put_user(kp->start_block, &up->start_block) ||
45177 put_user(kp->blocks, &up->blocks) ||
45178 put_user(tmp, &up->edid) ||
45179- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
45180+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
45181 return -EFAULT;
45182 return 0;
45183 }
45184diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
45185index 6ff002b..6b9316b 100644
45186--- a/drivers/media/v4l2-core/v4l2-ctrls.c
45187+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
45188@@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
45189 return 0;
45190
45191 case V4L2_CTRL_TYPE_STRING:
45192- len = strlen(c->string);
45193- if (len < ctrl->minimum)
45194+ len = strlen_user(c->string);
45195+ if (!len || len < ctrl->minimum)
45196 return -ERANGE;
45197 if ((len - ctrl->minimum) % ctrl->step)
45198 return -ERANGE;
45199diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
45200index 02d1b63..5fd6b16 100644
45201--- a/drivers/media/v4l2-core/v4l2-device.c
45202+++ b/drivers/media/v4l2-core/v4l2-device.c
45203@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
45204 EXPORT_SYMBOL_GPL(v4l2_device_put);
45205
45206 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
45207- atomic_t *instance)
45208+ atomic_unchecked_t *instance)
45209 {
45210- int num = atomic_inc_return(instance) - 1;
45211+ int num = atomic_inc_return_unchecked(instance) - 1;
45212 int len = strlen(basename);
45213
45214 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
45215diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
45216index 707aef7..93b8ac0 100644
45217--- a/drivers/media/v4l2-core/v4l2-ioctl.c
45218+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
45219@@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
45220 struct file *file, void *fh, void *p);
45221 } u;
45222 void (*debug)(const void *arg, bool write_only);
45223-};
45224+} __do_const;
45225+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
45226
45227 /* This control needs a priority check */
45228 #define INFO_FL_PRIO (1 << 0)
45229@@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
45230 struct video_device *vfd = video_devdata(file);
45231 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
45232 bool write_only = false;
45233- struct v4l2_ioctl_info default_info;
45234+ v4l2_ioctl_info_no_const default_info;
45235 const struct v4l2_ioctl_info *info;
45236 void *fh = file->private_data;
45237 struct v4l2_fh *vfh = NULL;
45238@@ -2197,7 +2198,7 @@ done:
45239 }
45240
45241 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45242- void * __user *user_ptr, void ***kernel_ptr)
45243+ void __user **user_ptr, void ***kernel_ptr)
45244 {
45245 int ret = 0;
45246
45247@@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45248 ret = -EINVAL;
45249 break;
45250 }
45251- *user_ptr = (void __user *)buf->m.planes;
45252+ *user_ptr = (void __force_user *)buf->m.planes;
45253 *kernel_ptr = (void *)&buf->m.planes;
45254 *array_size = sizeof(struct v4l2_plane) * buf->length;
45255 ret = 1;
45256@@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45257 ret = -EINVAL;
45258 break;
45259 }
45260- *user_ptr = (void __user *)ctrls->controls;
45261+ *user_ptr = (void __force_user *)ctrls->controls;
45262 *kernel_ptr = (void *)&ctrls->controls;
45263 *array_size = sizeof(struct v4l2_ext_control)
45264 * ctrls->count;
45265@@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
45266 }
45267
45268 if (has_array_args) {
45269- *kernel_ptr = user_ptr;
45270+ *kernel_ptr = (void __force_kernel *)user_ptr;
45271 if (copy_to_user(user_ptr, mbuf, array_size))
45272 err = -EFAULT;
45273 goto out_array_args;
45274diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
45275index 570b18a..f880314 100644
45276--- a/drivers/message/fusion/mptbase.c
45277+++ b/drivers/message/fusion/mptbase.c
45278@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45279 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
45280 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
45281
45282+#ifdef CONFIG_GRKERNSEC_HIDESYM
45283+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
45284+#else
45285 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
45286 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
45287+#endif
45288+
45289 /*
45290 * Rounding UP to nearest 4-kB boundary here...
45291 */
45292@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45293 ioc->facts.GlobalCredits);
45294
45295 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
45296+#ifdef CONFIG_GRKERNSEC_HIDESYM
45297+ NULL, NULL);
45298+#else
45299 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
45300+#endif
45301 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
45302 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
45303 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
45304diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
45305index 00d339c..2ea899d 100644
45306--- a/drivers/message/fusion/mptsas.c
45307+++ b/drivers/message/fusion/mptsas.c
45308@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
45309 return 0;
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 /* no mutex */
45330 static void
45331 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
45332@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
45333 return NULL;
45334 }
45335
45336-static inline void
45337-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45338-{
45339- if (phy_info->port_details) {
45340- phy_info->port_details->rphy = rphy;
45341- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45342- ioc->name, rphy));
45343- }
45344-
45345- if (rphy) {
45346- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45347- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45348- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45349- ioc->name, rphy, rphy->dev.release));
45350- }
45351-}
45352-
45353 static inline struct sas_port *
45354 mptsas_get_port(struct mptsas_phyinfo *phy_info)
45355 {
45356diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
45357index 727819c..ad74694 100644
45358--- a/drivers/message/fusion/mptscsih.c
45359+++ b/drivers/message/fusion/mptscsih.c
45360@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
45361
45362 h = shost_priv(SChost);
45363
45364- if (h) {
45365- if (h->info_kbuf == NULL)
45366- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45367- return h->info_kbuf;
45368- h->info_kbuf[0] = '\0';
45369+ if (!h)
45370+ return NULL;
45371
45372- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45373- h->info_kbuf[size-1] = '\0';
45374- }
45375+ if (h->info_kbuf == NULL)
45376+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45377+ return h->info_kbuf;
45378+ h->info_kbuf[0] = '\0';
45379+
45380+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45381+ h->info_kbuf[size-1] = '\0';
45382
45383 return h->info_kbuf;
45384 }
45385diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
45386index b7d87cd..3fb36da 100644
45387--- a/drivers/message/i2o/i2o_proc.c
45388+++ b/drivers/message/i2o/i2o_proc.c
45389@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
45390 "Array Controller Device"
45391 };
45392
45393-static char *chtostr(char *tmp, u8 *chars, int n)
45394-{
45395- tmp[0] = 0;
45396- return strncat(tmp, (char *)chars, n);
45397-}
45398-
45399 static int i2o_report_query_status(struct seq_file *seq, int block_status,
45400 char *group)
45401 {
45402@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
45403 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
45404 {
45405 struct i2o_controller *c = (struct i2o_controller *)seq->private;
45406- static u32 work32[5];
45407- static u8 *work8 = (u8 *) work32;
45408- static u16 *work16 = (u16 *) work32;
45409+ u32 work32[5];
45410+ u8 *work8 = (u8 *) work32;
45411+ u16 *work16 = (u16 *) work32;
45412 int token;
45413 u32 hwcap;
45414
45415@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45416 } *result;
45417
45418 i2o_exec_execute_ddm_table ddm_table;
45419- char tmp[28 + 1];
45420
45421 result = kmalloc(sizeof(*result), GFP_KERNEL);
45422 if (!result)
45423@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45424
45425 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
45426 seq_printf(seq, "%-#8x", ddm_table.module_id);
45427- seq_printf(seq, "%-29s",
45428- chtostr(tmp, ddm_table.module_name_version, 28));
45429+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45430 seq_printf(seq, "%9d ", ddm_table.data_size);
45431 seq_printf(seq, "%8d", ddm_table.code_size);
45432
45433@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45434
45435 i2o_driver_result_table *result;
45436 i2o_driver_store_table *dst;
45437- char tmp[28 + 1];
45438
45439 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45440 if (result == NULL)
45441@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45442
45443 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45444 seq_printf(seq, "%-#8x", dst->module_id);
45445- seq_printf(seq, "%-29s",
45446- chtostr(tmp, dst->module_name_version, 28));
45447- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45448+ seq_printf(seq, "%-.28s", dst->module_name_version);
45449+ seq_printf(seq, "%-.8s", dst->date);
45450 seq_printf(seq, "%8d ", dst->module_size);
45451 seq_printf(seq, "%8d ", dst->mpb_size);
45452 seq_printf(seq, "0x%04x", dst->module_flags);
45453@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45454 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45455 {
45456 struct i2o_device *d = (struct i2o_device *)seq->private;
45457- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45458+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45459 // == (allow) 512d bytes (max)
45460- static u16 *work16 = (u16 *) work32;
45461+ u16 *work16 = (u16 *) work32;
45462 int token;
45463- char tmp[16 + 1];
45464
45465 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45466
45467@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45468 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45469 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45470 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45471- seq_printf(seq, "Vendor info : %s\n",
45472- chtostr(tmp, (u8 *) (work32 + 2), 16));
45473- seq_printf(seq, "Product info : %s\n",
45474- chtostr(tmp, (u8 *) (work32 + 6), 16));
45475- seq_printf(seq, "Description : %s\n",
45476- chtostr(tmp, (u8 *) (work32 + 10), 16));
45477- seq_printf(seq, "Product rev. : %s\n",
45478- chtostr(tmp, (u8 *) (work32 + 14), 8));
45479+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45480+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45481+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45482+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45483
45484 seq_printf(seq, "Serial number : ");
45485 print_serial_number(seq, (u8 *) (work32 + 16),
45486@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45487 u8 pad[256]; // allow up to 256 byte (max) serial number
45488 } result;
45489
45490- char tmp[24 + 1];
45491-
45492 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45493
45494 if (token < 0) {
45495@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45496 }
45497
45498 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45499- seq_printf(seq, "Module name : %s\n",
45500- chtostr(tmp, result.module_name, 24));
45501- seq_printf(seq, "Module revision : %s\n",
45502- chtostr(tmp, result.module_rev, 8));
45503+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
45504+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45505
45506 seq_printf(seq, "Serial number : ");
45507 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45508@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45509 u8 instance_number[4];
45510 } result;
45511
45512- char tmp[64 + 1];
45513-
45514 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45515
45516 if (token < 0) {
45517@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45518 return 0;
45519 }
45520
45521- seq_printf(seq, "Device name : %s\n",
45522- chtostr(tmp, result.device_name, 64));
45523- seq_printf(seq, "Service name : %s\n",
45524- chtostr(tmp, result.service_name, 64));
45525- seq_printf(seq, "Physical name : %s\n",
45526- chtostr(tmp, result.physical_location, 64));
45527- seq_printf(seq, "Instance number : %s\n",
45528- chtostr(tmp, result.instance_number, 4));
45529+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
45530+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
45531+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45532+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45533
45534 return 0;
45535 }
45536@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45537 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45538 {
45539 struct i2o_device *d = (struct i2o_device *)seq->private;
45540- static u32 work32[12];
45541- static u16 *work16 = (u16 *) work32;
45542- static u8 *work8 = (u8 *) work32;
45543+ u32 work32[12];
45544+ u16 *work16 = (u16 *) work32;
45545+ u8 *work8 = (u8 *) work32;
45546 int token;
45547
45548 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45549diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45550index a8c08f3..155fe3d 100644
45551--- a/drivers/message/i2o/iop.c
45552+++ b/drivers/message/i2o/iop.c
45553@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45554
45555 spin_lock_irqsave(&c->context_list_lock, flags);
45556
45557- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45558- atomic_inc(&c->context_list_counter);
45559+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45560+ atomic_inc_unchecked(&c->context_list_counter);
45561
45562- entry->context = atomic_read(&c->context_list_counter);
45563+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45564
45565 list_add(&entry->list, &c->context_list);
45566
45567@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45568
45569 #if BITS_PER_LONG == 64
45570 spin_lock_init(&c->context_list_lock);
45571- atomic_set(&c->context_list_counter, 0);
45572+ atomic_set_unchecked(&c->context_list_counter, 0);
45573 INIT_LIST_HEAD(&c->context_list);
45574 #endif
45575
45576diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45577index d1a22aa..d0f7bf7 100644
45578--- a/drivers/mfd/ab8500-debugfs.c
45579+++ b/drivers/mfd/ab8500-debugfs.c
45580@@ -100,7 +100,7 @@ static int irq_last;
45581 static u32 *irq_count;
45582 static int num_irqs;
45583
45584-static struct device_attribute **dev_attr;
45585+static device_attribute_no_const **dev_attr;
45586 static char **event_name;
45587
45588 static u8 avg_sample = SAMPLE_16;
45589diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45590index 81b7d88..95ae998 100644
45591--- a/drivers/mfd/janz-cmodio.c
45592+++ b/drivers/mfd/janz-cmodio.c
45593@@ -13,6 +13,7 @@
45594
45595 #include <linux/kernel.h>
45596 #include <linux/module.h>
45597+#include <linux/slab.h>
45598 #include <linux/init.h>
45599 #include <linux/pci.h>
45600 #include <linux/interrupt.h>
45601diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45602index a83eed5..62a58a9 100644
45603--- a/drivers/mfd/max8925-i2c.c
45604+++ b/drivers/mfd/max8925-i2c.c
45605@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45606 const struct i2c_device_id *id)
45607 {
45608 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45609- static struct max8925_chip *chip;
45610+ struct max8925_chip *chip;
45611 struct device_node *node = client->dev.of_node;
45612
45613 if (node && !pdata) {
45614diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45615index d657331..0d9a80f 100644
45616--- a/drivers/mfd/tps65910.c
45617+++ b/drivers/mfd/tps65910.c
45618@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45619 struct tps65910_platform_data *pdata)
45620 {
45621 int ret = 0;
45622- static struct regmap_irq_chip *tps6591x_irqs_chip;
45623+ struct regmap_irq_chip *tps6591x_irqs_chip;
45624
45625 if (!irq) {
45626 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45627diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45628index 9aa6d1e..1631bfc 100644
45629--- a/drivers/mfd/twl4030-irq.c
45630+++ b/drivers/mfd/twl4030-irq.c
45631@@ -35,6 +35,7 @@
45632 #include <linux/of.h>
45633 #include <linux/irqdomain.h>
45634 #include <linux/i2c/twl.h>
45635+#include <asm/pgtable.h>
45636
45637 #include "twl-core.h"
45638
45639@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45640 * Install an irq handler for each of the SIH modules;
45641 * clone dummy irq_chip since PIH can't *do* anything
45642 */
45643- twl4030_irq_chip = dummy_irq_chip;
45644- twl4030_irq_chip.name = "twl4030";
45645+ pax_open_kernel();
45646+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45647+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45648
45649- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45650+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45651+ pax_close_kernel();
45652
45653 for (i = irq_base; i < irq_end; i++) {
45654 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45655diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45656index 464419b..64bae8d 100644
45657--- a/drivers/misc/c2port/core.c
45658+++ b/drivers/misc/c2port/core.c
45659@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45660 goto error_idr_alloc;
45661 c2dev->id = ret;
45662
45663- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45664+ pax_open_kernel();
45665+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45666+ pax_close_kernel();
45667
45668 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45669 "c2port%d", c2dev->id);
45670diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45671index 9c34e57..b981cda 100644
45672--- a/drivers/misc/eeprom/sunxi_sid.c
45673+++ b/drivers/misc/eeprom/sunxi_sid.c
45674@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45675
45676 platform_set_drvdata(pdev, sid_data);
45677
45678- sid_bin_attr.size = sid_data->keysize;
45679+ pax_open_kernel();
45680+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45681+ pax_close_kernel();
45682 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45683 return -ENODEV;
45684
45685diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45686index 36f5d52..32311c3 100644
45687--- a/drivers/misc/kgdbts.c
45688+++ b/drivers/misc/kgdbts.c
45689@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45690 char before[BREAK_INSTR_SIZE];
45691 char after[BREAK_INSTR_SIZE];
45692
45693- probe_kernel_read(before, (char *)kgdbts_break_test,
45694+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45695 BREAK_INSTR_SIZE);
45696 init_simple_test();
45697 ts.tst = plant_and_detach_test;
45698@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45699 /* Activate test with initial breakpoint */
45700 if (!is_early)
45701 kgdb_breakpoint();
45702- probe_kernel_read(after, (char *)kgdbts_break_test,
45703+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45704 BREAK_INSTR_SIZE);
45705 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45706 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45707diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45708index 036effe..b3a6336 100644
45709--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45710+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45711@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45712 * the lid is closed. This leads to interrupts as soon as a little move
45713 * is done.
45714 */
45715- atomic_inc(&lis3->count);
45716+ atomic_inc_unchecked(&lis3->count);
45717
45718 wake_up_interruptible(&lis3->misc_wait);
45719 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45720@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45721 if (lis3->pm_dev)
45722 pm_runtime_get_sync(lis3->pm_dev);
45723
45724- atomic_set(&lis3->count, 0);
45725+ atomic_set_unchecked(&lis3->count, 0);
45726 return 0;
45727 }
45728
45729@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45730 add_wait_queue(&lis3->misc_wait, &wait);
45731 while (true) {
45732 set_current_state(TASK_INTERRUPTIBLE);
45733- data = atomic_xchg(&lis3->count, 0);
45734+ data = atomic_xchg_unchecked(&lis3->count, 0);
45735 if (data)
45736 break;
45737
45738@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45739 struct lis3lv02d, miscdev);
45740
45741 poll_wait(file, &lis3->misc_wait, wait);
45742- if (atomic_read(&lis3->count))
45743+ if (atomic_read_unchecked(&lis3->count))
45744 return POLLIN | POLLRDNORM;
45745 return 0;
45746 }
45747diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45748index c439c82..1f20f57 100644
45749--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45750+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45751@@ -297,7 +297,7 @@ struct lis3lv02d {
45752 struct input_polled_dev *idev; /* input device */
45753 struct platform_device *pdev; /* platform device */
45754 struct regulator_bulk_data regulators[2];
45755- atomic_t count; /* interrupt count after last read */
45756+ atomic_unchecked_t count; /* interrupt count after last read */
45757 union axis_conversion ac; /* hw -> logical axis */
45758 int mapped_btns[3];
45759
45760diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45761index 2f30bad..c4c13d0 100644
45762--- a/drivers/misc/sgi-gru/gruhandles.c
45763+++ b/drivers/misc/sgi-gru/gruhandles.c
45764@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45765 unsigned long nsec;
45766
45767 nsec = CLKS2NSEC(clks);
45768- atomic_long_inc(&mcs_op_statistics[op].count);
45769- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45770+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45771+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45772 if (mcs_op_statistics[op].max < nsec)
45773 mcs_op_statistics[op].max = nsec;
45774 }
45775diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45776index 4f76359..cdfcb2e 100644
45777--- a/drivers/misc/sgi-gru/gruprocfs.c
45778+++ b/drivers/misc/sgi-gru/gruprocfs.c
45779@@ -32,9 +32,9 @@
45780
45781 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45782
45783-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45784+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45785 {
45786- unsigned long val = atomic_long_read(v);
45787+ unsigned long val = atomic_long_read_unchecked(v);
45788
45789 seq_printf(s, "%16lu %s\n", val, id);
45790 }
45791@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45792
45793 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45794 for (op = 0; op < mcsop_last; op++) {
45795- count = atomic_long_read(&mcs_op_statistics[op].count);
45796- total = atomic_long_read(&mcs_op_statistics[op].total);
45797+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45798+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45799 max = mcs_op_statistics[op].max;
45800 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45801 count ? total / count : 0, max);
45802diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45803index 5c3ce24..4915ccb 100644
45804--- a/drivers/misc/sgi-gru/grutables.h
45805+++ b/drivers/misc/sgi-gru/grutables.h
45806@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45807 * GRU statistics.
45808 */
45809 struct gru_stats_s {
45810- atomic_long_t vdata_alloc;
45811- atomic_long_t vdata_free;
45812- atomic_long_t gts_alloc;
45813- atomic_long_t gts_free;
45814- atomic_long_t gms_alloc;
45815- atomic_long_t gms_free;
45816- atomic_long_t gts_double_allocate;
45817- atomic_long_t assign_context;
45818- atomic_long_t assign_context_failed;
45819- atomic_long_t free_context;
45820- atomic_long_t load_user_context;
45821- atomic_long_t load_kernel_context;
45822- atomic_long_t lock_kernel_context;
45823- atomic_long_t unlock_kernel_context;
45824- atomic_long_t steal_user_context;
45825- atomic_long_t steal_kernel_context;
45826- atomic_long_t steal_context_failed;
45827- atomic_long_t nopfn;
45828- atomic_long_t asid_new;
45829- atomic_long_t asid_next;
45830- atomic_long_t asid_wrap;
45831- atomic_long_t asid_reuse;
45832- atomic_long_t intr;
45833- atomic_long_t intr_cbr;
45834- atomic_long_t intr_tfh;
45835- atomic_long_t intr_spurious;
45836- atomic_long_t intr_mm_lock_failed;
45837- atomic_long_t call_os;
45838- atomic_long_t call_os_wait_queue;
45839- atomic_long_t user_flush_tlb;
45840- atomic_long_t user_unload_context;
45841- atomic_long_t user_exception;
45842- atomic_long_t set_context_option;
45843- atomic_long_t check_context_retarget_intr;
45844- atomic_long_t check_context_unload;
45845- atomic_long_t tlb_dropin;
45846- atomic_long_t tlb_preload_page;
45847- atomic_long_t tlb_dropin_fail_no_asid;
45848- atomic_long_t tlb_dropin_fail_upm;
45849- atomic_long_t tlb_dropin_fail_invalid;
45850- atomic_long_t tlb_dropin_fail_range_active;
45851- atomic_long_t tlb_dropin_fail_idle;
45852- atomic_long_t tlb_dropin_fail_fmm;
45853- atomic_long_t tlb_dropin_fail_no_exception;
45854- atomic_long_t tfh_stale_on_fault;
45855- atomic_long_t mmu_invalidate_range;
45856- atomic_long_t mmu_invalidate_page;
45857- atomic_long_t flush_tlb;
45858- atomic_long_t flush_tlb_gru;
45859- atomic_long_t flush_tlb_gru_tgh;
45860- atomic_long_t flush_tlb_gru_zero_asid;
45861+ atomic_long_unchecked_t vdata_alloc;
45862+ atomic_long_unchecked_t vdata_free;
45863+ atomic_long_unchecked_t gts_alloc;
45864+ atomic_long_unchecked_t gts_free;
45865+ atomic_long_unchecked_t gms_alloc;
45866+ atomic_long_unchecked_t gms_free;
45867+ atomic_long_unchecked_t gts_double_allocate;
45868+ atomic_long_unchecked_t assign_context;
45869+ atomic_long_unchecked_t assign_context_failed;
45870+ atomic_long_unchecked_t free_context;
45871+ atomic_long_unchecked_t load_user_context;
45872+ atomic_long_unchecked_t load_kernel_context;
45873+ atomic_long_unchecked_t lock_kernel_context;
45874+ atomic_long_unchecked_t unlock_kernel_context;
45875+ atomic_long_unchecked_t steal_user_context;
45876+ atomic_long_unchecked_t steal_kernel_context;
45877+ atomic_long_unchecked_t steal_context_failed;
45878+ atomic_long_unchecked_t nopfn;
45879+ atomic_long_unchecked_t asid_new;
45880+ atomic_long_unchecked_t asid_next;
45881+ atomic_long_unchecked_t asid_wrap;
45882+ atomic_long_unchecked_t asid_reuse;
45883+ atomic_long_unchecked_t intr;
45884+ atomic_long_unchecked_t intr_cbr;
45885+ atomic_long_unchecked_t intr_tfh;
45886+ atomic_long_unchecked_t intr_spurious;
45887+ atomic_long_unchecked_t intr_mm_lock_failed;
45888+ atomic_long_unchecked_t call_os;
45889+ atomic_long_unchecked_t call_os_wait_queue;
45890+ atomic_long_unchecked_t user_flush_tlb;
45891+ atomic_long_unchecked_t user_unload_context;
45892+ atomic_long_unchecked_t user_exception;
45893+ atomic_long_unchecked_t set_context_option;
45894+ atomic_long_unchecked_t check_context_retarget_intr;
45895+ atomic_long_unchecked_t check_context_unload;
45896+ atomic_long_unchecked_t tlb_dropin;
45897+ atomic_long_unchecked_t tlb_preload_page;
45898+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45899+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45900+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45901+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45902+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45903+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45904+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45905+ atomic_long_unchecked_t tfh_stale_on_fault;
45906+ atomic_long_unchecked_t mmu_invalidate_range;
45907+ atomic_long_unchecked_t mmu_invalidate_page;
45908+ atomic_long_unchecked_t flush_tlb;
45909+ atomic_long_unchecked_t flush_tlb_gru;
45910+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45911+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45912
45913- atomic_long_t copy_gpa;
45914- atomic_long_t read_gpa;
45915+ atomic_long_unchecked_t copy_gpa;
45916+ atomic_long_unchecked_t read_gpa;
45917
45918- atomic_long_t mesq_receive;
45919- atomic_long_t mesq_receive_none;
45920- atomic_long_t mesq_send;
45921- atomic_long_t mesq_send_failed;
45922- atomic_long_t mesq_noop;
45923- atomic_long_t mesq_send_unexpected_error;
45924- atomic_long_t mesq_send_lb_overflow;
45925- atomic_long_t mesq_send_qlimit_reached;
45926- atomic_long_t mesq_send_amo_nacked;
45927- atomic_long_t mesq_send_put_nacked;
45928- atomic_long_t mesq_page_overflow;
45929- atomic_long_t mesq_qf_locked;
45930- atomic_long_t mesq_qf_noop_not_full;
45931- atomic_long_t mesq_qf_switch_head_failed;
45932- atomic_long_t mesq_qf_unexpected_error;
45933- atomic_long_t mesq_noop_unexpected_error;
45934- atomic_long_t mesq_noop_lb_overflow;
45935- atomic_long_t mesq_noop_qlimit_reached;
45936- atomic_long_t mesq_noop_amo_nacked;
45937- atomic_long_t mesq_noop_put_nacked;
45938- atomic_long_t mesq_noop_page_overflow;
45939+ atomic_long_unchecked_t mesq_receive;
45940+ atomic_long_unchecked_t mesq_receive_none;
45941+ atomic_long_unchecked_t mesq_send;
45942+ atomic_long_unchecked_t mesq_send_failed;
45943+ atomic_long_unchecked_t mesq_noop;
45944+ atomic_long_unchecked_t mesq_send_unexpected_error;
45945+ atomic_long_unchecked_t mesq_send_lb_overflow;
45946+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45947+ atomic_long_unchecked_t mesq_send_amo_nacked;
45948+ atomic_long_unchecked_t mesq_send_put_nacked;
45949+ atomic_long_unchecked_t mesq_page_overflow;
45950+ atomic_long_unchecked_t mesq_qf_locked;
45951+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45952+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45953+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45954+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45955+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45956+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45957+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45958+ atomic_long_unchecked_t mesq_noop_put_nacked;
45959+ atomic_long_unchecked_t mesq_noop_page_overflow;
45960
45961 };
45962
45963@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45964 tghop_invalidate, mcsop_last};
45965
45966 struct mcs_op_statistic {
45967- atomic_long_t count;
45968- atomic_long_t total;
45969+ atomic_long_unchecked_t count;
45970+ atomic_long_unchecked_t total;
45971 unsigned long max;
45972 };
45973
45974@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45975
45976 #define STAT(id) do { \
45977 if (gru_options & OPT_STATS) \
45978- atomic_long_inc(&gru_stats.id); \
45979+ atomic_long_inc_unchecked(&gru_stats.id); \
45980 } while (0)
45981
45982 #ifdef CONFIG_SGI_GRU_DEBUG
45983diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45984index c862cd4..0d176fe 100644
45985--- a/drivers/misc/sgi-xp/xp.h
45986+++ b/drivers/misc/sgi-xp/xp.h
45987@@ -288,7 +288,7 @@ struct xpc_interface {
45988 xpc_notify_func, void *);
45989 void (*received) (short, int, void *);
45990 enum xp_retval (*partid_to_nasids) (short, void *);
45991-};
45992+} __no_const;
45993
45994 extern struct xpc_interface xpc_interface;
45995
45996diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45997index 01be66d..e3a0c7e 100644
45998--- a/drivers/misc/sgi-xp/xp_main.c
45999+++ b/drivers/misc/sgi-xp/xp_main.c
46000@@ -78,13 +78,13 @@ xpc_notloaded(void)
46001 }
46002
46003 struct xpc_interface xpc_interface = {
46004- (void (*)(int))xpc_notloaded,
46005- (void (*)(int))xpc_notloaded,
46006- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46007- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46008+ .connect = (void (*)(int))xpc_notloaded,
46009+ .disconnect = (void (*)(int))xpc_notloaded,
46010+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46011+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46012 void *))xpc_notloaded,
46013- (void (*)(short, int, void *))xpc_notloaded,
46014- (enum xp_retval(*)(short, void *))xpc_notloaded
46015+ .received = (void (*)(short, int, void *))xpc_notloaded,
46016+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
46017 };
46018 EXPORT_SYMBOL_GPL(xpc_interface);
46019
46020diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
46021index b94d5f7..7f494c5 100644
46022--- a/drivers/misc/sgi-xp/xpc.h
46023+++ b/drivers/misc/sgi-xp/xpc.h
46024@@ -835,6 +835,7 @@ struct xpc_arch_operations {
46025 void (*received_payload) (struct xpc_channel *, void *);
46026 void (*notify_senders_of_disconnect) (struct xpc_channel *);
46027 };
46028+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
46029
46030 /* struct xpc_partition act_state values (for XPC HB) */
46031
46032@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
46033 /* found in xpc_main.c */
46034 extern struct device *xpc_part;
46035 extern struct device *xpc_chan;
46036-extern struct xpc_arch_operations xpc_arch_ops;
46037+extern xpc_arch_operations_no_const xpc_arch_ops;
46038 extern int xpc_disengage_timelimit;
46039 extern int xpc_disengage_timedout;
46040 extern int xpc_activate_IRQ_rcvd;
46041diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
46042index 82dc574..8539ab2 100644
46043--- a/drivers/misc/sgi-xp/xpc_main.c
46044+++ b/drivers/misc/sgi-xp/xpc_main.c
46045@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
46046 .notifier_call = xpc_system_die,
46047 };
46048
46049-struct xpc_arch_operations xpc_arch_ops;
46050+xpc_arch_operations_no_const xpc_arch_ops;
46051
46052 /*
46053 * Timer function to enforce the timelimit on the partition disengage.
46054@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
46055
46056 if (((die_args->trapnr == X86_TRAP_MF) ||
46057 (die_args->trapnr == X86_TRAP_XF)) &&
46058- !user_mode_vm(die_args->regs))
46059+ !user_mode(die_args->regs))
46060 xpc_die_deactivate();
46061
46062 break;
46063diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
46064index 7b5424f..ed1d6ac 100644
46065--- a/drivers/mmc/card/block.c
46066+++ b/drivers/mmc/card/block.c
46067@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
46068 if (idata->ic.postsleep_min_us)
46069 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
46070
46071- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
46072+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
46073 err = -EFAULT;
46074 goto cmd_rel_host;
46075 }
46076diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
46077index e5b5eeb..7bf2212 100644
46078--- a/drivers/mmc/core/mmc_ops.c
46079+++ b/drivers/mmc/core/mmc_ops.c
46080@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
46081 void *data_buf;
46082 int is_on_stack;
46083
46084- is_on_stack = object_is_on_stack(buf);
46085+ is_on_stack = object_starts_on_stack(buf);
46086 if (is_on_stack) {
46087 /*
46088 * dma onto stack is unsafe/nonportable, but callers to this
46089diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
46090index 6bf24ab..13d0293b 100644
46091--- a/drivers/mmc/host/dw_mmc.h
46092+++ b/drivers/mmc/host/dw_mmc.h
46093@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
46094 int (*parse_dt)(struct dw_mci *host);
46095 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
46096 struct dw_mci_tuning_data *tuning_data);
46097-};
46098+} __do_const;
46099 #endif /* _DW_MMC_H_ */
46100diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
46101index b931226..df6a085 100644
46102--- a/drivers/mmc/host/mmci.c
46103+++ b/drivers/mmc/host/mmci.c
46104@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
46105 }
46106
46107 if (variant->busy_detect) {
46108- mmci_ops.card_busy = mmci_card_busy;
46109+ pax_open_kernel();
46110+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
46111+ pax_close_kernel();
46112 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
46113 }
46114
46115diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
46116index b841bb7..d82712f5 100644
46117--- a/drivers/mmc/host/sdhci-esdhc-imx.c
46118+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
46119@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
46120 host->mmc->caps |= MMC_CAP_1_8V_DDR;
46121 }
46122
46123- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
46124- sdhci_esdhc_ops.platform_execute_tuning =
46125+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
46126+ pax_open_kernel();
46127+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
46128 esdhc_executing_tuning;
46129+ pax_close_kernel();
46130+ }
46131
46132 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
46133 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
46134diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
46135index 6debda9..2ba7427 100644
46136--- a/drivers/mmc/host/sdhci-s3c.c
46137+++ b/drivers/mmc/host/sdhci-s3c.c
46138@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
46139 * we can use overriding functions instead of default.
46140 */
46141 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
46142- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46143- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46144- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46145+ pax_open_kernel();
46146+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46147+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46148+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46149+ pax_close_kernel();
46150 }
46151
46152 /* It supports additional host capabilities if needed */
46153diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
46154index 096993f..f02c23b 100644
46155--- a/drivers/mtd/chips/cfi_cmdset_0020.c
46156+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
46157@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
46158 size_t totlen = 0, thislen;
46159 int ret = 0;
46160 size_t buflen = 0;
46161- static char *buffer;
46162+ char *buffer;
46163
46164 if (!ECCBUF_SIZE) {
46165 /* We should fall back to a general writev implementation.
46166diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
46167index c07cd57..61c4fbd 100644
46168--- a/drivers/mtd/nand/denali.c
46169+++ b/drivers/mtd/nand/denali.c
46170@@ -24,6 +24,7 @@
46171 #include <linux/slab.h>
46172 #include <linux/mtd/mtd.h>
46173 #include <linux/module.h>
46174+#include <linux/slab.h>
46175
46176 #include "denali.h"
46177
46178diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46179index ca6369f..0ce9fed 100644
46180--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46181+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46182@@ -369,7 +369,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
46183
46184 /* first try to map the upper buffer directly */
46185 if (virt_addr_valid(this->upper_buf) &&
46186- !object_is_on_stack(this->upper_buf)) {
46187+ !object_starts_on_stack(this->upper_buf)) {
46188 sg_init_one(sgl, this->upper_buf, this->upper_len);
46189 ret = dma_map_sg(this->dev, sgl, 1, dr);
46190 if (ret == 0)
46191diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
46192index 51b9d6a..52af9a7 100644
46193--- a/drivers/mtd/nftlmount.c
46194+++ b/drivers/mtd/nftlmount.c
46195@@ -24,6 +24,7 @@
46196 #include <asm/errno.h>
46197 #include <linux/delay.h>
46198 #include <linux/slab.h>
46199+#include <linux/sched.h>
46200 #include <linux/mtd/mtd.h>
46201 #include <linux/mtd/nand.h>
46202 #include <linux/mtd/nftl.h>
46203diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
46204index cf49c22..971b133 100644
46205--- a/drivers/mtd/sm_ftl.c
46206+++ b/drivers/mtd/sm_ftl.c
46207@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
46208 #define SM_CIS_VENDOR_OFFSET 0x59
46209 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
46210 {
46211- struct attribute_group *attr_group;
46212+ attribute_group_no_const *attr_group;
46213 struct attribute **attributes;
46214 struct sm_sysfs_attribute *vendor_attribute;
46215 char *vendor;
46216diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
46217index e5628fc..ffe54d1 100644
46218--- a/drivers/net/bonding/bond_main.c
46219+++ b/drivers/net/bonding/bond_main.c
46220@@ -4551,6 +4551,7 @@ static void __exit bonding_exit(void)
46221
46222 bond_netlink_fini();
46223 unregister_pernet_subsys(&bond_net_ops);
46224+ rtnl_link_unregister(&bond_link_ops);
46225
46226 #ifdef CONFIG_NET_POLL_CONTROLLER
46227 /*
46228diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
46229index 70651f8..7eb1bdf 100644
46230--- a/drivers/net/bonding/bond_netlink.c
46231+++ b/drivers/net/bonding/bond_netlink.c
46232@@ -542,7 +542,7 @@ nla_put_failure:
46233 return -EMSGSIZE;
46234 }
46235
46236-struct rtnl_link_ops bond_link_ops __read_mostly = {
46237+struct rtnl_link_ops bond_link_ops = {
46238 .kind = "bond",
46239 .priv_size = sizeof(struct bonding),
46240 .setup = bond_setup,
46241diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
46242index 9e7d95d..d447b88 100644
46243--- a/drivers/net/can/Kconfig
46244+++ b/drivers/net/can/Kconfig
46245@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
46246
46247 config CAN_FLEXCAN
46248 tristate "Support for Freescale FLEXCAN based chips"
46249- depends on ARM || PPC
46250+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
46251 ---help---
46252 Say Y here if you want to support for Freescale FlexCAN.
46253
46254diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
46255index 455d4c3..3353ee7 100644
46256--- a/drivers/net/ethernet/8390/ax88796.c
46257+++ b/drivers/net/ethernet/8390/ax88796.c
46258@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
46259 if (ax->plat->reg_offsets)
46260 ei_local->reg_offset = ax->plat->reg_offsets;
46261 else {
46262+ resource_size_t _mem_size = mem_size;
46263+ do_div(_mem_size, 0x18);
46264 ei_local->reg_offset = ax->reg_offsets;
46265 for (ret = 0; ret < 0x18; ret++)
46266- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
46267+ ax->reg_offsets[ret] = _mem_size * ret;
46268 }
46269
46270 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
46271diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46272index a89a40f..5a8a2ac 100644
46273--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46274+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46275@@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
46276 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
46277 {
46278 /* RX_MODE controlling object */
46279- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
46280+ bnx2x_init_rx_mode_obj(bp);
46281
46282 /* multicast configuration controlling object */
46283 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
46284diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46285index 0fb6ff2..78fd55c 100644
46286--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46287+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46288@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
46289 return rc;
46290 }
46291
46292-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46293- struct bnx2x_rx_mode_obj *o)
46294+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
46295 {
46296 if (CHIP_IS_E1x(bp)) {
46297- o->wait_comp = bnx2x_empty_rx_mode_wait;
46298- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
46299+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
46300+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
46301 } else {
46302- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
46303- o->config_rx_mode = bnx2x_set_rx_mode_e2;
46304+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
46305+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
46306 }
46307 }
46308
46309diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46310index 00d7f21..2cddec4 100644
46311--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46312+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46313@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
46314
46315 /********************* RX MODE ****************/
46316
46317-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46318- struct bnx2x_rx_mode_obj *o);
46319+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
46320
46321 /**
46322 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
46323diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
46324index 04321e5..b51cdc4 100644
46325--- a/drivers/net/ethernet/broadcom/tg3.h
46326+++ b/drivers/net/ethernet/broadcom/tg3.h
46327@@ -150,6 +150,7 @@
46328 #define CHIPREV_ID_5750_A0 0x4000
46329 #define CHIPREV_ID_5750_A1 0x4001
46330 #define CHIPREV_ID_5750_A3 0x4003
46331+#define CHIPREV_ID_5750_C1 0x4201
46332 #define CHIPREV_ID_5750_C2 0x4202
46333 #define CHIPREV_ID_5752_A0_HW 0x5000
46334 #define CHIPREV_ID_5752_A0 0x6000
46335diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
46336index 13f9636..228040f 100644
46337--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
46338+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
46339@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
46340 }
46341
46342 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
46343- bna_cb_ioceth_enable,
46344- bna_cb_ioceth_disable,
46345- bna_cb_ioceth_hbfail,
46346- bna_cb_ioceth_reset
46347+ .enable_cbfn = bna_cb_ioceth_enable,
46348+ .disable_cbfn = bna_cb_ioceth_disable,
46349+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
46350+ .reset_cbfn = bna_cb_ioceth_reset
46351 };
46352
46353 static void bna_attr_init(struct bna_ioceth *ioceth)
46354diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46355index 8cffcdf..aadf043 100644
46356--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46357+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46358@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
46359 */
46360 struct l2t_skb_cb {
46361 arp_failure_handler_func arp_failure_handler;
46362-};
46363+} __no_const;
46364
46365 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
46366
46367diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46368index 34e2488..07e2079 100644
46369--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46370+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46371@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
46372
46373 int i;
46374 struct adapter *ap = netdev2adap(dev);
46375- static const unsigned int *reg_ranges;
46376+ const unsigned int *reg_ranges;
46377 int arr_size = 0, buf_size = 0;
46378
46379 if (is_t4(ap->params.chip)) {
46380diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
46381index c05b66d..ed69872 100644
46382--- a/drivers/net/ethernet/dec/tulip/de4x5.c
46383+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
46384@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46385 for (i=0; i<ETH_ALEN; i++) {
46386 tmp.addr[i] = dev->dev_addr[i];
46387 }
46388- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46389+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46390 break;
46391
46392 case DE4X5_SET_HWADDR: /* Set the hardware address */
46393@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46394 spin_lock_irqsave(&lp->lock, flags);
46395 memcpy(&statbuf, &lp->pktStats, ioc->len);
46396 spin_unlock_irqrestore(&lp->lock, flags);
46397- if (copy_to_user(ioc->data, &statbuf, ioc->len))
46398+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
46399 return -EFAULT;
46400 break;
46401 }
46402diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
46403index 36c8061..ca5e1e0 100644
46404--- a/drivers/net/ethernet/emulex/benet/be_main.c
46405+++ b/drivers/net/ethernet/emulex/benet/be_main.c
46406@@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
46407
46408 if (wrapped)
46409 newacc += 65536;
46410- ACCESS_ONCE(*acc) = newacc;
46411+ ACCESS_ONCE_RW(*acc) = newacc;
46412 }
46413
46414 static void populate_erx_stats(struct be_adapter *adapter,
46415diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
46416index c11ecbc..13bb299 100644
46417--- a/drivers/net/ethernet/faraday/ftgmac100.c
46418+++ b/drivers/net/ethernet/faraday/ftgmac100.c
46419@@ -30,6 +30,8 @@
46420 #include <linux/netdevice.h>
46421 #include <linux/phy.h>
46422 #include <linux/platform_device.h>
46423+#include <linux/interrupt.h>
46424+#include <linux/irqreturn.h>
46425 #include <net/ip.h>
46426
46427 #include "ftgmac100.h"
46428diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46429index 8be5b40..081bc1b 100644
46430--- a/drivers/net/ethernet/faraday/ftmac100.c
46431+++ b/drivers/net/ethernet/faraday/ftmac100.c
46432@@ -31,6 +31,8 @@
46433 #include <linux/module.h>
46434 #include <linux/netdevice.h>
46435 #include <linux/platform_device.h>
46436+#include <linux/interrupt.h>
46437+#include <linux/irqreturn.h>
46438
46439 #include "ftmac100.h"
46440
46441diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46442index e33ec6c..f54cfe7 100644
46443--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46444+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46445@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46446 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46447
46448 /* Update the base adjustement value. */
46449- ACCESS_ONCE(pf->ptp_base_adj) = incval;
46450+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46451 smp_mb(); /* Force the above update. */
46452 }
46453
46454diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46455index 5184e2a..acb28c3 100644
46456--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46457+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46458@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46459 }
46460
46461 /* update the base incval used to calculate frequency adjustment */
46462- ACCESS_ONCE(adapter->base_incval) = incval;
46463+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
46464 smp_mb();
46465
46466 /* need lock to prevent incorrect read while modifying cyclecounter */
46467diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46468index 089b713..28d87ae 100644
46469--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46470+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46471@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46472 struct __vxge_hw_fifo *fifo;
46473 struct vxge_hw_fifo_config *config;
46474 u32 txdl_size, txdl_per_memblock;
46475- struct vxge_hw_mempool_cbs fifo_mp_callback;
46476+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46477+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46478+ };
46479+
46480 struct __vxge_hw_virtualpath *vpath;
46481
46482 if ((vp == NULL) || (attr == NULL)) {
46483@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46484 goto exit;
46485 }
46486
46487- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46488-
46489 fifo->mempool =
46490 __vxge_hw_mempool_create(vpath->hldev,
46491 fifo->config->memblock_size,
46492diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46493index 90a2dda..47e620e 100644
46494--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46495+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46496@@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46497 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46498 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46499 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46500- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46501+ pax_open_kernel();
46502+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46503+ pax_close_kernel();
46504 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46505 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46506 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
46507diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46508index be7d7a6..a8983f8 100644
46509--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46510+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46511@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46512 case QLCNIC_NON_PRIV_FUNC:
46513 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46514 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46515- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46516+ pax_open_kernel();
46517+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46518+ pax_close_kernel();
46519 break;
46520 case QLCNIC_PRIV_FUNC:
46521 ahw->op_mode = QLCNIC_PRIV_FUNC;
46522 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46523- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46524+ pax_open_kernel();
46525+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46526+ pax_close_kernel();
46527 break;
46528 case QLCNIC_MGMT_FUNC:
46529 ahw->op_mode = QLCNIC_MGMT_FUNC;
46530 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46531- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46532+ pax_open_kernel();
46533+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46534+ pax_close_kernel();
46535 break;
46536 default:
46537 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46538diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46539index 7763962..c3499a7 100644
46540--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46541+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46542@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46543 struct qlcnic_dump_entry *entry;
46544 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46545 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
46546- static const struct qlcnic_dump_operations *fw_dump_ops;
46547+ const struct qlcnic_dump_operations *fw_dump_ops;
46548 struct device *dev = &adapter->pdev->dev;
46549 struct qlcnic_hardware_context *ahw;
46550 void *temp_buffer;
46551diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46552index 3ff7bc3..366091b 100644
46553--- a/drivers/net/ethernet/realtek/r8169.c
46554+++ b/drivers/net/ethernet/realtek/r8169.c
46555@@ -758,22 +758,22 @@ struct rtl8169_private {
46556 struct mdio_ops {
46557 void (*write)(struct rtl8169_private *, int, int);
46558 int (*read)(struct rtl8169_private *, int);
46559- } mdio_ops;
46560+ } __no_const mdio_ops;
46561
46562 struct pll_power_ops {
46563 void (*down)(struct rtl8169_private *);
46564 void (*up)(struct rtl8169_private *);
46565- } pll_power_ops;
46566+ } __no_const pll_power_ops;
46567
46568 struct jumbo_ops {
46569 void (*enable)(struct rtl8169_private *);
46570 void (*disable)(struct rtl8169_private *);
46571- } jumbo_ops;
46572+ } __no_const jumbo_ops;
46573
46574 struct csi_ops {
46575 void (*write)(struct rtl8169_private *, int, int);
46576 u32 (*read)(struct rtl8169_private *, int);
46577- } csi_ops;
46578+ } __no_const csi_ops;
46579
46580 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46581 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46582diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46583index d7a3682..9ce272a 100644
46584--- a/drivers/net/ethernet/sfc/ptp.c
46585+++ b/drivers/net/ethernet/sfc/ptp.c
46586@@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46587 ptp->start.dma_addr);
46588
46589 /* Clear flag that signals MC ready */
46590- ACCESS_ONCE(*start) = 0;
46591+ ACCESS_ONCE_RW(*start) = 0;
46592 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46593 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46594 EFX_BUG_ON_PARANOID(rc);
46595diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46596index 50617c5..b13724c 100644
46597--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46598+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46599@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46600
46601 writel(value, ioaddr + MMC_CNTRL);
46602
46603- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46604- MMC_CNTRL, value);
46605+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46606+// MMC_CNTRL, value);
46607 }
46608
46609 /* To mask all all interrupts.*/
46610diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46611index 7b594ce..1f6c5708 100644
46612--- a/drivers/net/hyperv/hyperv_net.h
46613+++ b/drivers/net/hyperv/hyperv_net.h
46614@@ -100,7 +100,7 @@ struct rndis_device {
46615
46616 enum rndis_device_state state;
46617 bool link_state;
46618- atomic_t new_req_id;
46619+ atomic_unchecked_t new_req_id;
46620
46621 spinlock_t request_lock;
46622 struct list_head req_list;
46623diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46624index b54fd25..9bd2bae 100644
46625--- a/drivers/net/hyperv/rndis_filter.c
46626+++ b/drivers/net/hyperv/rndis_filter.c
46627@@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46628 * template
46629 */
46630 set = &rndis_msg->msg.set_req;
46631- set->req_id = atomic_inc_return(&dev->new_req_id);
46632+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46633
46634 /* Add to the request list */
46635 spin_lock_irqsave(&dev->request_lock, flags);
46636@@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46637
46638 /* Setup the rndis set */
46639 halt = &request->request_msg.msg.halt_req;
46640- halt->req_id = atomic_inc_return(&dev->new_req_id);
46641+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46642
46643 /* Ignore return since this msg is optional. */
46644 rndis_filter_send_request(dev, request);
46645diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46646index bf0d55e..82bcfbd1 100644
46647--- a/drivers/net/ieee802154/fakehard.c
46648+++ b/drivers/net/ieee802154/fakehard.c
46649@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46650 phy->transmit_power = 0xbf;
46651
46652 dev->netdev_ops = &fake_ops;
46653- dev->ml_priv = &fake_mlme;
46654+ dev->ml_priv = (void *)&fake_mlme;
46655
46656 priv = netdev_priv(dev);
46657 priv->phy = phy;
46658diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46659index 1831fb7..9c24bca 100644
46660--- a/drivers/net/macvlan.c
46661+++ b/drivers/net/macvlan.c
46662@@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46663 int macvlan_link_register(struct rtnl_link_ops *ops)
46664 {
46665 /* common fields */
46666- ops->priv_size = sizeof(struct macvlan_dev);
46667- ops->validate = macvlan_validate;
46668- ops->maxtype = IFLA_MACVLAN_MAX;
46669- ops->policy = macvlan_policy;
46670- ops->changelink = macvlan_changelink;
46671- ops->get_size = macvlan_get_size;
46672- ops->fill_info = macvlan_fill_info;
46673+ pax_open_kernel();
46674+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46675+ *(void **)&ops->validate = macvlan_validate;
46676+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46677+ *(const void **)&ops->policy = macvlan_policy;
46678+ *(void **)&ops->changelink = macvlan_changelink;
46679+ *(void **)&ops->get_size = macvlan_get_size;
46680+ *(void **)&ops->fill_info = macvlan_fill_info;
46681+ pax_close_kernel();
46682
46683 return rtnl_link_register(ops);
46684 };
46685@@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46686 return NOTIFY_DONE;
46687 }
46688
46689-static struct notifier_block macvlan_notifier_block __read_mostly = {
46690+static struct notifier_block macvlan_notifier_block = {
46691 .notifier_call = macvlan_device_event,
46692 };
46693
46694diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46695index ff111a8..c4c3ac4 100644
46696--- a/drivers/net/macvtap.c
46697+++ b/drivers/net/macvtap.c
46698@@ -1011,7 +1011,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46699 }
46700
46701 ret = 0;
46702- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46703+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46704 put_user(q->flags, &ifr->ifr_flags))
46705 ret = -EFAULT;
46706 macvtap_put_vlan(vlan);
46707@@ -1181,7 +1181,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46708 return NOTIFY_DONE;
46709 }
46710
46711-static struct notifier_block macvtap_notifier_block __read_mostly = {
46712+static struct notifier_block macvtap_notifier_block = {
46713 .notifier_call = macvtap_device_event,
46714 };
46715
46716diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46717index daec9b0..6428fcb 100644
46718--- a/drivers/net/phy/mdio-bitbang.c
46719+++ b/drivers/net/phy/mdio-bitbang.c
46720@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46721 struct mdiobb_ctrl *ctrl = bus->priv;
46722
46723 module_put(ctrl->ops->owner);
46724+ mdiobus_unregister(bus);
46725 mdiobus_free(bus);
46726 }
46727 EXPORT_SYMBOL(free_mdio_bitbang);
46728diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46729index 72ff14b..11d442d 100644
46730--- a/drivers/net/ppp/ppp_generic.c
46731+++ b/drivers/net/ppp/ppp_generic.c
46732@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46733 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46734 struct ppp_stats stats;
46735 struct ppp_comp_stats cstats;
46736- char *vers;
46737
46738 switch (cmd) {
46739 case SIOCGPPPSTATS:
46740@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46741 break;
46742
46743 case SIOCGPPPVER:
46744- vers = PPP_VERSION;
46745- if (copy_to_user(addr, vers, strlen(vers) + 1))
46746+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46747 break;
46748 err = 0;
46749 break;
46750diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46751index 1252d9c..80e660b 100644
46752--- a/drivers/net/slip/slhc.c
46753+++ b/drivers/net/slip/slhc.c
46754@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46755 register struct tcphdr *thp;
46756 register struct iphdr *ip;
46757 register struct cstate *cs;
46758- int len, hdrlen;
46759+ long len, hdrlen;
46760 unsigned char *cp = icp;
46761
46762 /* We've got a compressed packet; read the change byte */
46763diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46764index c8624a8..f0a4f6a 100644
46765--- a/drivers/net/team/team.c
46766+++ b/drivers/net/team/team.c
46767@@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
46768 return NOTIFY_DONE;
46769 }
46770
46771-static struct notifier_block team_notifier_block __read_mostly = {
46772+static struct notifier_block team_notifier_block = {
46773 .notifier_call = team_device_event,
46774 };
46775
46776diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46777index 26f8635..c237839 100644
46778--- a/drivers/net/tun.c
46779+++ b/drivers/net/tun.c
46780@@ -1876,7 +1876,7 @@ unlock:
46781 }
46782
46783 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46784- unsigned long arg, int ifreq_len)
46785+ unsigned long arg, size_t ifreq_len)
46786 {
46787 struct tun_file *tfile = file->private_data;
46788 struct tun_struct *tun;
46789@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46790 unsigned int ifindex;
46791 int ret;
46792
46793+ if (ifreq_len > sizeof ifr)
46794+ return -EFAULT;
46795+
46796 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46797 if (copy_from_user(&ifr, argp, ifreq_len))
46798 return -EFAULT;
46799diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
46800index d350d27..75d7d9d 100644
46801--- a/drivers/net/usb/cdc_ncm.c
46802+++ b/drivers/net/usb/cdc_ncm.c
46803@@ -768,7 +768,7 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
46804 skb_out->len > CDC_NCM_MIN_TX_PKT)
46805 memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0,
46806 ctx->tx_max - skb_out->len);
46807- else if ((skb_out->len % dev->maxpacket) == 0)
46808+ else if (skb_out->len < ctx->tx_max && (skb_out->len % dev->maxpacket) == 0)
46809 *skb_put(skb_out, 1) = 0; /* force short packet */
46810
46811 /* set final frame length */
46812diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46813index 660bd5e..ac59452 100644
46814--- a/drivers/net/usb/hso.c
46815+++ b/drivers/net/usb/hso.c
46816@@ -71,7 +71,7 @@
46817 #include <asm/byteorder.h>
46818 #include <linux/serial_core.h>
46819 #include <linux/serial.h>
46820-
46821+#include <asm/local.h>
46822
46823 #define MOD_AUTHOR "Option Wireless"
46824 #define MOD_DESCRIPTION "USB High Speed Option driver"
46825@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46826 struct urb *urb;
46827
46828 urb = serial->rx_urb[0];
46829- if (serial->port.count > 0) {
46830+ if (atomic_read(&serial->port.count) > 0) {
46831 count = put_rxbuf_data(urb, serial);
46832 if (count == -1)
46833 return;
46834@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46835 DUMP1(urb->transfer_buffer, urb->actual_length);
46836
46837 /* Anyone listening? */
46838- if (serial->port.count == 0)
46839+ if (atomic_read(&serial->port.count) == 0)
46840 return;
46841
46842 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46843@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46844 tty_port_tty_set(&serial->port, tty);
46845
46846 /* check for port already opened, if not set the termios */
46847- serial->port.count++;
46848- if (serial->port.count == 1) {
46849+ if (atomic_inc_return(&serial->port.count) == 1) {
46850 serial->rx_state = RX_IDLE;
46851 /* Force default termio settings */
46852 _hso_serial_set_termios(tty, NULL);
46853@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46854 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46855 if (result) {
46856 hso_stop_serial_device(serial->parent);
46857- serial->port.count--;
46858+ atomic_dec(&serial->port.count);
46859 kref_put(&serial->parent->ref, hso_serial_ref_free);
46860 }
46861 } else {
46862@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46863
46864 /* reset the rts and dtr */
46865 /* do the actual close */
46866- serial->port.count--;
46867+ atomic_dec(&serial->port.count);
46868
46869- if (serial->port.count <= 0) {
46870- serial->port.count = 0;
46871+ if (atomic_read(&serial->port.count) <= 0) {
46872+ atomic_set(&serial->port.count, 0);
46873 tty_port_tty_set(&serial->port, NULL);
46874 if (!usb_gone)
46875 hso_stop_serial_device(serial->parent);
46876@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46877
46878 /* the actual setup */
46879 spin_lock_irqsave(&serial->serial_lock, flags);
46880- if (serial->port.count)
46881+ if (atomic_read(&serial->port.count))
46882 _hso_serial_set_termios(tty, old);
46883 else
46884 tty->termios = *old;
46885@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46886 D1("Pending read interrupt on port %d\n", i);
46887 spin_lock(&serial->serial_lock);
46888 if (serial->rx_state == RX_IDLE &&
46889- serial->port.count > 0) {
46890+ atomic_read(&serial->port.count) > 0) {
46891 /* Setup and send a ctrl req read on
46892 * port i */
46893 if (!serial->rx_urb_filled[0]) {
46894@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46895 /* Start all serial ports */
46896 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46897 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46898- if (dev2ser(serial_table[i])->port.count) {
46899+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46900 result =
46901 hso_start_serial_device(serial_table[i], GFP_NOIO);
46902 hso_kick_transmit(dev2ser(serial_table[i]));
46903diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46904index adb12f3..48005ab 100644
46905--- a/drivers/net/usb/r8152.c
46906+++ b/drivers/net/usb/r8152.c
46907@@ -513,7 +513,7 @@ struct r8152 {
46908 void (*disable)(struct r8152 *);
46909 void (*down)(struct r8152 *);
46910 void (*unload)(struct r8152 *);
46911- } rtl_ops;
46912+ } __no_const rtl_ops;
46913
46914 int intr_interval;
46915 u32 msg_enable;
46916diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46917index a2515887..6d13233 100644
46918--- a/drivers/net/usb/sierra_net.c
46919+++ b/drivers/net/usb/sierra_net.c
46920@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46921 /* atomic counter partially included in MAC address to make sure 2 devices
46922 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46923 */
46924-static atomic_t iface_counter = ATOMIC_INIT(0);
46925+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46926
46927 /*
46928 * SYNC Timer Delay definition used to set the expiry time
46929@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46930 dev->net->netdev_ops = &sierra_net_device_ops;
46931
46932 /* change MAC addr to include, ifacenum, and to be unique */
46933- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46934+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46935 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46936
46937 /* we will have to manufacture ethernet headers, prepare template */
46938diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46939index d091e52..568bb179 100644
46940--- a/drivers/net/vxlan.c
46941+++ b/drivers/net/vxlan.c
46942@@ -2847,7 +2847,7 @@ nla_put_failure:
46943 return -EMSGSIZE;
46944 }
46945
46946-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46947+static struct rtnl_link_ops vxlan_link_ops = {
46948 .kind = "vxlan",
46949 .maxtype = IFLA_VXLAN_MAX,
46950 .policy = vxlan_policy,
46951@@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46952 return NOTIFY_DONE;
46953 }
46954
46955-static struct notifier_block vxlan_notifier_block __read_mostly = {
46956+static struct notifier_block vxlan_notifier_block = {
46957 .notifier_call = vxlan_lowerdev_event,
46958 };
46959
46960diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46961index 5920c99..ff2e4a5 100644
46962--- a/drivers/net/wan/lmc/lmc_media.c
46963+++ b/drivers/net/wan/lmc/lmc_media.c
46964@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46965 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46966
46967 lmc_media_t lmc_ds3_media = {
46968- lmc_ds3_init, /* special media init stuff */
46969- lmc_ds3_default, /* reset to default state */
46970- lmc_ds3_set_status, /* reset status to state provided */
46971- lmc_dummy_set_1, /* set clock source */
46972- lmc_dummy_set2_1, /* set line speed */
46973- lmc_ds3_set_100ft, /* set cable length */
46974- lmc_ds3_set_scram, /* set scrambler */
46975- lmc_ds3_get_link_status, /* get link status */
46976- lmc_dummy_set_1, /* set link status */
46977- lmc_ds3_set_crc_length, /* set CRC length */
46978- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46979- lmc_ds3_watchdog
46980+ .init = lmc_ds3_init, /* special media init stuff */
46981+ .defaults = lmc_ds3_default, /* reset to default state */
46982+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46983+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46984+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46985+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46986+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46987+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46988+ .set_link_status = lmc_dummy_set_1, /* set link status */
46989+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46990+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46991+ .watchdog = lmc_ds3_watchdog
46992 };
46993
46994 lmc_media_t lmc_hssi_media = {
46995- lmc_hssi_init, /* special media init stuff */
46996- lmc_hssi_default, /* reset to default state */
46997- lmc_hssi_set_status, /* reset status to state provided */
46998- lmc_hssi_set_clock, /* set clock source */
46999- lmc_dummy_set2_1, /* set line speed */
47000- lmc_dummy_set_1, /* set cable length */
47001- lmc_dummy_set_1, /* set scrambler */
47002- lmc_hssi_get_link_status, /* get link status */
47003- lmc_hssi_set_link_status, /* set link status */
47004- lmc_hssi_set_crc_length, /* set CRC length */
47005- lmc_dummy_set_1, /* set T1 or E1 circuit type */
47006- lmc_hssi_watchdog
47007+ .init = lmc_hssi_init, /* special media init stuff */
47008+ .defaults = lmc_hssi_default, /* reset to default state */
47009+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
47010+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
47011+ .set_speed = lmc_dummy_set2_1, /* set line speed */
47012+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
47013+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47014+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
47015+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
47016+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
47017+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
47018+ .watchdog = lmc_hssi_watchdog
47019 };
47020
47021-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
47022- lmc_ssi_default, /* reset to default state */
47023- lmc_ssi_set_status, /* reset status to state provided */
47024- lmc_ssi_set_clock, /* set clock source */
47025- lmc_ssi_set_speed, /* set line speed */
47026- lmc_dummy_set_1, /* set cable length */
47027- lmc_dummy_set_1, /* set scrambler */
47028- lmc_ssi_get_link_status, /* get link status */
47029- lmc_ssi_set_link_status, /* set link status */
47030- lmc_ssi_set_crc_length, /* set CRC length */
47031- lmc_dummy_set_1, /* set T1 or E1 circuit type */
47032- lmc_ssi_watchdog
47033+lmc_media_t lmc_ssi_media = {
47034+ .init = lmc_ssi_init, /* special media init stuff */
47035+ .defaults = lmc_ssi_default, /* reset to default state */
47036+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
47037+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
47038+ .set_speed = lmc_ssi_set_speed, /* set line speed */
47039+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
47040+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47041+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
47042+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
47043+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
47044+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
47045+ .watchdog = lmc_ssi_watchdog
47046 };
47047
47048 lmc_media_t lmc_t1_media = {
47049- lmc_t1_init, /* special media init stuff */
47050- lmc_t1_default, /* reset to default state */
47051- lmc_t1_set_status, /* reset status to state provided */
47052- lmc_t1_set_clock, /* set clock source */
47053- lmc_dummy_set2_1, /* set line speed */
47054- lmc_dummy_set_1, /* set cable length */
47055- lmc_dummy_set_1, /* set scrambler */
47056- lmc_t1_get_link_status, /* get link status */
47057- lmc_dummy_set_1, /* set link status */
47058- lmc_t1_set_crc_length, /* set CRC length */
47059- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47060- lmc_t1_watchdog
47061+ .init = lmc_t1_init, /* special media init stuff */
47062+ .defaults = lmc_t1_default, /* reset to default state */
47063+ .set_status = lmc_t1_set_status, /* reset status to state provided */
47064+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
47065+ .set_speed = lmc_dummy_set2_1, /* set line speed */
47066+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
47067+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47068+ .get_link_status = lmc_t1_get_link_status, /* get link status */
47069+ .set_link_status = lmc_dummy_set_1, /* set link status */
47070+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
47071+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47072+ .watchdog = lmc_t1_watchdog
47073 };
47074
47075 static void
47076diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
47077index feacc3b..5bac0de 100644
47078--- a/drivers/net/wan/z85230.c
47079+++ b/drivers/net/wan/z85230.c
47080@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
47081
47082 struct z8530_irqhandler z8530_sync =
47083 {
47084- z8530_rx,
47085- z8530_tx,
47086- z8530_status
47087+ .rx = z8530_rx,
47088+ .tx = z8530_tx,
47089+ .status = z8530_status
47090 };
47091
47092 EXPORT_SYMBOL(z8530_sync);
47093@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
47094 }
47095
47096 static struct z8530_irqhandler z8530_dma_sync = {
47097- z8530_dma_rx,
47098- z8530_dma_tx,
47099- z8530_dma_status
47100+ .rx = z8530_dma_rx,
47101+ .tx = z8530_dma_tx,
47102+ .status = z8530_dma_status
47103 };
47104
47105 static struct z8530_irqhandler z8530_txdma_sync = {
47106- z8530_rx,
47107- z8530_dma_tx,
47108- z8530_dma_status
47109+ .rx = z8530_rx,
47110+ .tx = z8530_dma_tx,
47111+ .status = z8530_dma_status
47112 };
47113
47114 /**
47115@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
47116
47117 struct z8530_irqhandler z8530_nop=
47118 {
47119- z8530_rx_clear,
47120- z8530_tx_clear,
47121- z8530_status_clear
47122+ .rx = z8530_rx_clear,
47123+ .tx = z8530_tx_clear,
47124+ .status = z8530_status_clear
47125 };
47126
47127
47128diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
47129index 0b60295..b8bfa5b 100644
47130--- a/drivers/net/wimax/i2400m/rx.c
47131+++ b/drivers/net/wimax/i2400m/rx.c
47132@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
47133 if (i2400m->rx_roq == NULL)
47134 goto error_roq_alloc;
47135
47136- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
47137+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
47138 GFP_KERNEL);
47139 if (rd == NULL) {
47140 result = -ENOMEM;
47141diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
47142index edf4b57..68b51c0 100644
47143--- a/drivers/net/wireless/airo.c
47144+++ b/drivers/net/wireless/airo.c
47145@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
47146 struct airo_info *ai = dev->ml_priv;
47147 int ridcode;
47148 int enabled;
47149- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47150+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47151 unsigned char *iobuf;
47152
47153 /* Only super-user can write RIDs */
47154diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
47155index 99b3bfa..9559372 100644
47156--- a/drivers/net/wireless/at76c50x-usb.c
47157+++ b/drivers/net/wireless/at76c50x-usb.c
47158@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
47159 }
47160
47161 /* Convert timeout from the DFU status to jiffies */
47162-static inline unsigned long at76_get_timeout(struct dfu_status *s)
47163+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
47164 {
47165 return msecs_to_jiffies((s->poll_timeout[2] << 16)
47166 | (s->poll_timeout[1] << 8)
47167diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
47168index edc57ab..ff49e0a 100644
47169--- a/drivers/net/wireless/ath/ath10k/htc.c
47170+++ b/drivers/net/wireless/ath/ath10k/htc.c
47171@@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
47172 /* registered target arrival callback from the HIF layer */
47173 int ath10k_htc_init(struct ath10k *ar)
47174 {
47175- struct ath10k_hif_cb htc_callbacks;
47176+ static struct ath10k_hif_cb htc_callbacks = {
47177+ .rx_completion = ath10k_htc_rx_completion_handler,
47178+ .tx_completion = ath10k_htc_tx_completion_handler,
47179+ };
47180 struct ath10k_htc_ep *ep = NULL;
47181 struct ath10k_htc *htc = &ar->htc;
47182
47183@@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
47184 ath10k_htc_reset_endpoint_states(htc);
47185
47186 /* setup HIF layer callbacks */
47187- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
47188- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
47189 htc->ar = ar;
47190
47191 /* Get HIF default pipe for HTC message exchange */
47192diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
47193index 4716d33..a688310 100644
47194--- a/drivers/net/wireless/ath/ath10k/htc.h
47195+++ b/drivers/net/wireless/ath/ath10k/htc.h
47196@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
47197
47198 struct ath10k_htc_ops {
47199 void (*target_send_suspend_complete)(struct ath10k *ar);
47200-};
47201+} __no_const;
47202
47203 struct ath10k_htc_ep_ops {
47204 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
47205 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
47206 void (*ep_tx_credits)(struct ath10k *);
47207-};
47208+} __no_const;
47209
47210 /* service connection information */
47211 struct ath10k_htc_svc_conn_req {
47212diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47213index 741b38d..b7ae41b 100644
47214--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47215+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47216@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47217 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
47218 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
47219
47220- ACCESS_ONCE(ads->ds_link) = i->link;
47221- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
47222+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
47223+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
47224
47225 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
47226 ctl6 = SM(i->keytype, AR_EncrType);
47227@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47228
47229 if ((i->is_first || i->is_last) &&
47230 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
47231- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
47232+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
47233 | set11nTries(i->rates, 1)
47234 | set11nTries(i->rates, 2)
47235 | set11nTries(i->rates, 3)
47236 | (i->dur_update ? AR_DurUpdateEna : 0)
47237 | SM(0, AR_BurstDur);
47238
47239- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
47240+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
47241 | set11nRate(i->rates, 1)
47242 | set11nRate(i->rates, 2)
47243 | set11nRate(i->rates, 3);
47244 } else {
47245- ACCESS_ONCE(ads->ds_ctl2) = 0;
47246- ACCESS_ONCE(ads->ds_ctl3) = 0;
47247+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
47248+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
47249 }
47250
47251 if (!i->is_first) {
47252- ACCESS_ONCE(ads->ds_ctl0) = 0;
47253- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47254- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47255+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
47256+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47257+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47258 return;
47259 }
47260
47261@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47262 break;
47263 }
47264
47265- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47266+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47267 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47268 | SM(i->txpower, AR_XmitPower)
47269 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47270@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47271 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
47272 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
47273
47274- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47275- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47276+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47277+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47278
47279 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
47280 return;
47281
47282- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47283+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47284 | set11nPktDurRTSCTS(i->rates, 1);
47285
47286- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47287+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47288 | set11nPktDurRTSCTS(i->rates, 3);
47289
47290- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47291+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47292 | set11nRateFlags(i->rates, 1)
47293 | set11nRateFlags(i->rates, 2)
47294 | set11nRateFlags(i->rates, 3)
47295diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47296index 729ffbf..49f50e3 100644
47297--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47298+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47299@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47300 (i->qcu << AR_TxQcuNum_S) | desc_len;
47301
47302 checksum += val;
47303- ACCESS_ONCE(ads->info) = val;
47304+ ACCESS_ONCE_RW(ads->info) = val;
47305
47306 checksum += i->link;
47307- ACCESS_ONCE(ads->link) = i->link;
47308+ ACCESS_ONCE_RW(ads->link) = i->link;
47309
47310 checksum += i->buf_addr[0];
47311- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
47312+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
47313 checksum += i->buf_addr[1];
47314- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
47315+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
47316 checksum += i->buf_addr[2];
47317- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
47318+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
47319 checksum += i->buf_addr[3];
47320- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
47321+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
47322
47323 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
47324- ACCESS_ONCE(ads->ctl3) = val;
47325+ ACCESS_ONCE_RW(ads->ctl3) = val;
47326 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
47327- ACCESS_ONCE(ads->ctl5) = val;
47328+ ACCESS_ONCE_RW(ads->ctl5) = val;
47329 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
47330- ACCESS_ONCE(ads->ctl7) = val;
47331+ ACCESS_ONCE_RW(ads->ctl7) = val;
47332 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
47333- ACCESS_ONCE(ads->ctl9) = val;
47334+ ACCESS_ONCE_RW(ads->ctl9) = val;
47335
47336 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
47337- ACCESS_ONCE(ads->ctl10) = checksum;
47338+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
47339
47340 if (i->is_first || i->is_last) {
47341- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
47342+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
47343 | set11nTries(i->rates, 1)
47344 | set11nTries(i->rates, 2)
47345 | set11nTries(i->rates, 3)
47346 | (i->dur_update ? AR_DurUpdateEna : 0)
47347 | SM(0, AR_BurstDur);
47348
47349- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
47350+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
47351 | set11nRate(i->rates, 1)
47352 | set11nRate(i->rates, 2)
47353 | set11nRate(i->rates, 3);
47354 } else {
47355- ACCESS_ONCE(ads->ctl13) = 0;
47356- ACCESS_ONCE(ads->ctl14) = 0;
47357+ ACCESS_ONCE_RW(ads->ctl13) = 0;
47358+ ACCESS_ONCE_RW(ads->ctl14) = 0;
47359 }
47360
47361 ads->ctl20 = 0;
47362@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47363
47364 ctl17 = SM(i->keytype, AR_EncrType);
47365 if (!i->is_first) {
47366- ACCESS_ONCE(ads->ctl11) = 0;
47367- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47368- ACCESS_ONCE(ads->ctl15) = 0;
47369- ACCESS_ONCE(ads->ctl16) = 0;
47370- ACCESS_ONCE(ads->ctl17) = ctl17;
47371- ACCESS_ONCE(ads->ctl18) = 0;
47372- ACCESS_ONCE(ads->ctl19) = 0;
47373+ ACCESS_ONCE_RW(ads->ctl11) = 0;
47374+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47375+ ACCESS_ONCE_RW(ads->ctl15) = 0;
47376+ ACCESS_ONCE_RW(ads->ctl16) = 0;
47377+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47378+ ACCESS_ONCE_RW(ads->ctl18) = 0;
47379+ ACCESS_ONCE_RW(ads->ctl19) = 0;
47380 return;
47381 }
47382
47383- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47384+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47385 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47386 | SM(i->txpower, AR_XmitPower)
47387 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47388@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47389 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
47390 ctl12 |= SM(val, AR_PAPRDChainMask);
47391
47392- ACCESS_ONCE(ads->ctl12) = ctl12;
47393- ACCESS_ONCE(ads->ctl17) = ctl17;
47394+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
47395+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47396
47397- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47398+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47399 | set11nPktDurRTSCTS(i->rates, 1);
47400
47401- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47402+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47403 | set11nPktDurRTSCTS(i->rates, 3);
47404
47405- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
47406+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
47407 | set11nRateFlags(i->rates, 1)
47408 | set11nRateFlags(i->rates, 2)
47409 | set11nRateFlags(i->rates, 3)
47410 | SM(i->rtscts_rate, AR_RTSCTSRate);
47411
47412- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
47413+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
47414 }
47415
47416 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
47417diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
47418index 0acd4b5..0591c91 100644
47419--- a/drivers/net/wireless/ath/ath9k/hw.h
47420+++ b/drivers/net/wireless/ath/ath9k/hw.h
47421@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
47422
47423 /* ANI */
47424 void (*ani_cache_ini_regs)(struct ath_hw *ah);
47425-};
47426+} __no_const;
47427
47428 /**
47429 * struct ath_spec_scan - parameters for Atheros spectral scan
47430@@ -706,7 +706,7 @@ struct ath_hw_ops {
47431 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47432 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47433 #endif
47434-};
47435+} __no_const;
47436
47437 struct ath_nf_limits {
47438 s16 max;
47439diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47440index 92190da..f3a4c4c 100644
47441--- a/drivers/net/wireless/b43/phy_lp.c
47442+++ b/drivers/net/wireless/b43/phy_lp.c
47443@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47444 {
47445 struct ssb_bus *bus = dev->dev->sdev->bus;
47446
47447- static const struct b206x_channel *chandata = NULL;
47448+ const struct b206x_channel *chandata = NULL;
47449 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47450 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47451 u16 old_comm15, scale;
47452diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47453index 0487461..fd9e84a 100644
47454--- a/drivers/net/wireless/iwlegacy/3945-mac.c
47455+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47456@@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47457 */
47458 if (il3945_mod_params.disable_hw_scan) {
47459 D_INFO("Disabling hw_scan\n");
47460- il3945_mac_ops.hw_scan = NULL;
47461+ pax_open_kernel();
47462+ *(void **)&il3945_mac_ops.hw_scan = NULL;
47463+ pax_close_kernel();
47464 }
47465
47466 D_INFO("*** LOAD DRIVER ***\n");
47467diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47468index d2fe259..0c4c682 100644
47469--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47470+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47471@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47472 {
47473 struct iwl_priv *priv = file->private_data;
47474 char buf[64];
47475- int buf_size;
47476+ size_t buf_size;
47477 u32 offset, len;
47478
47479 memset(buf, 0, sizeof(buf));
47480@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47481 struct iwl_priv *priv = file->private_data;
47482
47483 char buf[8];
47484- int buf_size;
47485+ size_t buf_size;
47486 u32 reset_flag;
47487
47488 memset(buf, 0, sizeof(buf));
47489@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47490 {
47491 struct iwl_priv *priv = file->private_data;
47492 char buf[8];
47493- int buf_size;
47494+ size_t buf_size;
47495 int ht40;
47496
47497 memset(buf, 0, sizeof(buf));
47498@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47499 {
47500 struct iwl_priv *priv = file->private_data;
47501 char buf[8];
47502- int buf_size;
47503+ size_t buf_size;
47504 int value;
47505
47506 memset(buf, 0, sizeof(buf));
47507@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47508 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47509 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47510
47511-static const char *fmt_value = " %-30s %10u\n";
47512-static const char *fmt_hex = " %-30s 0x%02X\n";
47513-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47514-static const char *fmt_header =
47515+static const char fmt_value[] = " %-30s %10u\n";
47516+static const char fmt_hex[] = " %-30s 0x%02X\n";
47517+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47518+static const char fmt_header[] =
47519 "%-32s current cumulative delta max\n";
47520
47521 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47522@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47523 {
47524 struct iwl_priv *priv = file->private_data;
47525 char buf[8];
47526- int buf_size;
47527+ size_t buf_size;
47528 int clear;
47529
47530 memset(buf, 0, sizeof(buf));
47531@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47532 {
47533 struct iwl_priv *priv = file->private_data;
47534 char buf[8];
47535- int buf_size;
47536+ size_t buf_size;
47537 int trace;
47538
47539 memset(buf, 0, sizeof(buf));
47540@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47541 {
47542 struct iwl_priv *priv = file->private_data;
47543 char buf[8];
47544- int buf_size;
47545+ size_t buf_size;
47546 int missed;
47547
47548 memset(buf, 0, sizeof(buf));
47549@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47550
47551 struct iwl_priv *priv = file->private_data;
47552 char buf[8];
47553- int buf_size;
47554+ size_t buf_size;
47555 int plcp;
47556
47557 memset(buf, 0, sizeof(buf));
47558@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47559
47560 struct iwl_priv *priv = file->private_data;
47561 char buf[8];
47562- int buf_size;
47563+ size_t buf_size;
47564 int flush;
47565
47566 memset(buf, 0, sizeof(buf));
47567@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47568
47569 struct iwl_priv *priv = file->private_data;
47570 char buf[8];
47571- int buf_size;
47572+ size_t buf_size;
47573 int rts;
47574
47575 if (!priv->cfg->ht_params)
47576@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47577 {
47578 struct iwl_priv *priv = file->private_data;
47579 char buf[8];
47580- int buf_size;
47581+ size_t buf_size;
47582
47583 memset(buf, 0, sizeof(buf));
47584 buf_size = min(count, sizeof(buf) - 1);
47585@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47586 struct iwl_priv *priv = file->private_data;
47587 u32 event_log_flag;
47588 char buf[8];
47589- int buf_size;
47590+ size_t buf_size;
47591
47592 /* check that the interface is up */
47593 if (!iwl_is_ready(priv))
47594@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47595 struct iwl_priv *priv = file->private_data;
47596 char buf[8];
47597 u32 calib_disabled;
47598- int buf_size;
47599+ size_t buf_size;
47600
47601 memset(buf, 0, sizeof(buf));
47602 buf_size = min(count, sizeof(buf) - 1);
47603diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47604index ea7e70c..bc0c45f 100644
47605--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47606+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47607@@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47608 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47609 {
47610 struct iwl_nvm_data *data = priv->nvm_data;
47611- char *debug_msg;
47612+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47613
47614 if (data->sku_cap_11n_enable &&
47615 !priv->cfg->ht_params) {
47616@@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47617 return -EINVAL;
47618 }
47619
47620- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47621 IWL_DEBUG_INFO(priv, debug_msg,
47622 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47623 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47624diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47625index f950780..be9df93 100644
47626--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47627+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47628@@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47629 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47630
47631 char buf[8];
47632- int buf_size;
47633+ size_t buf_size;
47634 u32 reset_flag;
47635
47636 memset(buf, 0, sizeof(buf));
47637@@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47638 {
47639 struct iwl_trans *trans = file->private_data;
47640 char buf[8];
47641- int buf_size;
47642+ size_t buf_size;
47643 int csr;
47644
47645 memset(buf, 0, sizeof(buf));
47646diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47647index 69d4c31..bd0b316 100644
47648--- a/drivers/net/wireless/mac80211_hwsim.c
47649+++ b/drivers/net/wireless/mac80211_hwsim.c
47650@@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
47651 if (channels < 1)
47652 return -EINVAL;
47653
47654- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47655- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47656- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47657- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47658- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47659- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47660- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47661- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47662- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47663- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47664- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47665- mac80211_hwsim_assign_vif_chanctx;
47666- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47667- mac80211_hwsim_unassign_vif_chanctx;
47668+ pax_open_kernel();
47669+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47670+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47671+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47672+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47673+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47674+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47675+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47676+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47677+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47678+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47679+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47680+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47681+ pax_close_kernel();
47682
47683 spin_lock_init(&hwsim_radio_lock);
47684 INIT_LIST_HEAD(&hwsim_radios);
47685diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47686index 5028557..91cf394 100644
47687--- a/drivers/net/wireless/rndis_wlan.c
47688+++ b/drivers/net/wireless/rndis_wlan.c
47689@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47690
47691 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47692
47693- if (rts_threshold < 0 || rts_threshold > 2347)
47694+ if (rts_threshold > 2347)
47695 rts_threshold = 2347;
47696
47697 tmp = cpu_to_le32(rts_threshold);
47698diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47699index e3b885d..7a7de2f 100644
47700--- a/drivers/net/wireless/rt2x00/rt2x00.h
47701+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47702@@ -375,7 +375,7 @@ struct rt2x00_intf {
47703 * for hardware which doesn't support hardware
47704 * sequence counting.
47705 */
47706- atomic_t seqno;
47707+ atomic_unchecked_t seqno;
47708 };
47709
47710 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47711diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47712index 5642ccc..01f03eb 100644
47713--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47714+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47715@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47716 * sequence counter given by mac80211.
47717 */
47718 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47719- seqno = atomic_add_return(0x10, &intf->seqno);
47720+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47721 else
47722- seqno = atomic_read(&intf->seqno);
47723+ seqno = atomic_read_unchecked(&intf->seqno);
47724
47725 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47726 hdr->seq_ctrl |= cpu_to_le16(seqno);
47727diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47728index e2b3d9c..67a5184 100644
47729--- a/drivers/net/wireless/ti/wl1251/sdio.c
47730+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47731@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47732
47733 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47734
47735- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47736- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47737+ pax_open_kernel();
47738+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47739+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47740+ pax_close_kernel();
47741
47742 wl1251_info("using dedicated interrupt line");
47743 } else {
47744- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47745- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47746+ pax_open_kernel();
47747+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47748+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47749+ pax_close_kernel();
47750
47751 wl1251_info("using SDIO interrupt");
47752 }
47753diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47754index be7129b..4161356 100644
47755--- a/drivers/net/wireless/ti/wl12xx/main.c
47756+++ b/drivers/net/wireless/ti/wl12xx/main.c
47757@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47758 sizeof(wl->conf.mem));
47759
47760 /* read data preparation is only needed by wl127x */
47761- wl->ops->prepare_read = wl127x_prepare_read;
47762+ pax_open_kernel();
47763+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47764+ pax_close_kernel();
47765
47766 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47767 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47768@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47769 sizeof(wl->conf.mem));
47770
47771 /* read data preparation is only needed by wl127x */
47772- wl->ops->prepare_read = wl127x_prepare_read;
47773+ pax_open_kernel();
47774+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47775+ pax_close_kernel();
47776
47777 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47778 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47779diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47780index ec37b16..7e34d66 100644
47781--- a/drivers/net/wireless/ti/wl18xx/main.c
47782+++ b/drivers/net/wireless/ti/wl18xx/main.c
47783@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47784 }
47785
47786 if (!checksum_param) {
47787- wl18xx_ops.set_rx_csum = NULL;
47788- wl18xx_ops.init_vif = NULL;
47789+ pax_open_kernel();
47790+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47791+ *(void **)&wl18xx_ops.init_vif = NULL;
47792+ pax_close_kernel();
47793 }
47794
47795 /* Enable 11a Band only if we have 5G antennas */
47796diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47797index a912dc0..a8225ba 100644
47798--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47799+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47800@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47801 {
47802 struct zd_usb *usb = urb->context;
47803 struct zd_usb_interrupt *intr = &usb->intr;
47804- int len;
47805+ unsigned int len;
47806 u16 int_num;
47807
47808 ZD_ASSERT(in_interrupt());
47809diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47810index 683671a..4519fc2 100644
47811--- a/drivers/nfc/nfcwilink.c
47812+++ b/drivers/nfc/nfcwilink.c
47813@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47814
47815 static int nfcwilink_probe(struct platform_device *pdev)
47816 {
47817- static struct nfcwilink *drv;
47818+ struct nfcwilink *drv;
47819 int rc;
47820 __u32 protocols;
47821
47822diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47823index d93b2b6..ae50401 100644
47824--- a/drivers/oprofile/buffer_sync.c
47825+++ b/drivers/oprofile/buffer_sync.c
47826@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47827 if (cookie == NO_COOKIE)
47828 offset = pc;
47829 if (cookie == INVALID_COOKIE) {
47830- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47831+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47832 offset = pc;
47833 }
47834 if (cookie != last_cookie) {
47835@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47836 /* add userspace sample */
47837
47838 if (!mm) {
47839- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47840+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47841 return 0;
47842 }
47843
47844 cookie = lookup_dcookie(mm, s->eip, &offset);
47845
47846 if (cookie == INVALID_COOKIE) {
47847- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47848+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47849 return 0;
47850 }
47851
47852@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47853 /* ignore backtraces if failed to add a sample */
47854 if (state == sb_bt_start) {
47855 state = sb_bt_ignore;
47856- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47857+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47858 }
47859 }
47860 release_mm(mm);
47861diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47862index c0cc4e7..44d4e54 100644
47863--- a/drivers/oprofile/event_buffer.c
47864+++ b/drivers/oprofile/event_buffer.c
47865@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47866 }
47867
47868 if (buffer_pos == buffer_size) {
47869- atomic_inc(&oprofile_stats.event_lost_overflow);
47870+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47871 return;
47872 }
47873
47874diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47875index ed2c3ec..deda85a 100644
47876--- a/drivers/oprofile/oprof.c
47877+++ b/drivers/oprofile/oprof.c
47878@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47879 if (oprofile_ops.switch_events())
47880 return;
47881
47882- atomic_inc(&oprofile_stats.multiplex_counter);
47883+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47884 start_switch_worker();
47885 }
47886
47887diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47888index ee2cfce..7f8f699 100644
47889--- a/drivers/oprofile/oprofile_files.c
47890+++ b/drivers/oprofile/oprofile_files.c
47891@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47892
47893 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47894
47895-static ssize_t timeout_read(struct file *file, char __user *buf,
47896+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47897 size_t count, loff_t *offset)
47898 {
47899 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47900diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47901index 59659ce..6c860a0 100644
47902--- a/drivers/oprofile/oprofile_stats.c
47903+++ b/drivers/oprofile/oprofile_stats.c
47904@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47905 cpu_buf->sample_invalid_eip = 0;
47906 }
47907
47908- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47909- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47910- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47911- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47912- atomic_set(&oprofile_stats.multiplex_counter, 0);
47913+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47914+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47915+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47916+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47917+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47918 }
47919
47920
47921diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47922index 1fc622b..8c48fc3 100644
47923--- a/drivers/oprofile/oprofile_stats.h
47924+++ b/drivers/oprofile/oprofile_stats.h
47925@@ -13,11 +13,11 @@
47926 #include <linux/atomic.h>
47927
47928 struct oprofile_stat_struct {
47929- atomic_t sample_lost_no_mm;
47930- atomic_t sample_lost_no_mapping;
47931- atomic_t bt_lost_no_mapping;
47932- atomic_t event_lost_overflow;
47933- atomic_t multiplex_counter;
47934+ atomic_unchecked_t sample_lost_no_mm;
47935+ atomic_unchecked_t sample_lost_no_mapping;
47936+ atomic_unchecked_t bt_lost_no_mapping;
47937+ atomic_unchecked_t event_lost_overflow;
47938+ atomic_unchecked_t multiplex_counter;
47939 };
47940
47941 extern struct oprofile_stat_struct oprofile_stats;
47942diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47943index 3f49345..c750d0b 100644
47944--- a/drivers/oprofile/oprofilefs.c
47945+++ b/drivers/oprofile/oprofilefs.c
47946@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47947
47948 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47949 {
47950- atomic_t *val = file->private_data;
47951- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47952+ atomic_unchecked_t *val = file->private_data;
47953+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47954 }
47955
47956
47957@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47958
47959
47960 int oprofilefs_create_ro_atomic(struct dentry *root,
47961- char const *name, atomic_t *val)
47962+ char const *name, atomic_unchecked_t *val)
47963 {
47964 return __oprofilefs_create_file(root, name,
47965 &atomic_ro_fops, 0444, val);
47966diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47967index 61be1d9..dec05d7 100644
47968--- a/drivers/oprofile/timer_int.c
47969+++ b/drivers/oprofile/timer_int.c
47970@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47971 return NOTIFY_OK;
47972 }
47973
47974-static struct notifier_block __refdata oprofile_cpu_notifier = {
47975+static struct notifier_block oprofile_cpu_notifier = {
47976 .notifier_call = oprofile_cpu_notify,
47977 };
47978
47979diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47980index 92ed045..62d39bd7 100644
47981--- a/drivers/parport/procfs.c
47982+++ b/drivers/parport/procfs.c
47983@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47984
47985 *ppos += len;
47986
47987- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47988+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47989 }
47990
47991 #ifdef CONFIG_PARPORT_1284
47992@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47993
47994 *ppos += len;
47995
47996- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47997+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47998 }
47999 #endif /* IEEE1284.3 support. */
48000
48001diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
48002index 8dcccff..35d701d 100644
48003--- a/drivers/pci/hotplug/acpiphp_ibm.c
48004+++ b/drivers/pci/hotplug/acpiphp_ibm.c
48005@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
48006 goto init_cleanup;
48007 }
48008
48009- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
48010+ pax_open_kernel();
48011+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
48012+ pax_close_kernel();
48013 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
48014
48015 return retval;
48016diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
48017index 7536eef..52dc8fa 100644
48018--- a/drivers/pci/hotplug/cpcihp_generic.c
48019+++ b/drivers/pci/hotplug/cpcihp_generic.c
48020@@ -73,7 +73,6 @@ static u16 port;
48021 static unsigned int enum_bit;
48022 static u8 enum_mask;
48023
48024-static struct cpci_hp_controller_ops generic_hpc_ops;
48025 static struct cpci_hp_controller generic_hpc;
48026
48027 static int __init validate_parameters(void)
48028@@ -139,6 +138,10 @@ static int query_enum(void)
48029 return ((value & enum_mask) == enum_mask);
48030 }
48031
48032+static struct cpci_hp_controller_ops generic_hpc_ops = {
48033+ .query_enum = query_enum,
48034+};
48035+
48036 static int __init cpcihp_generic_init(void)
48037 {
48038 int status;
48039@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
48040 pci_dev_put(dev);
48041
48042 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
48043- generic_hpc_ops.query_enum = query_enum;
48044 generic_hpc.ops = &generic_hpc_ops;
48045
48046 status = cpci_hp_register_controller(&generic_hpc);
48047diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
48048index e8c4a7c..7046f5c 100644
48049--- a/drivers/pci/hotplug/cpcihp_zt5550.c
48050+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
48051@@ -59,7 +59,6 @@
48052 /* local variables */
48053 static bool debug;
48054 static bool poll;
48055-static struct cpci_hp_controller_ops zt5550_hpc_ops;
48056 static struct cpci_hp_controller zt5550_hpc;
48057
48058 /* Primary cPCI bus bridge device */
48059@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
48060 return 0;
48061 }
48062
48063+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
48064+ .query_enum = zt5550_hc_query_enum,
48065+};
48066+
48067 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
48068 {
48069 int status;
48070@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
48071 dbg("returned from zt5550_hc_config");
48072
48073 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
48074- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
48075 zt5550_hpc.ops = &zt5550_hpc_ops;
48076 if(!poll) {
48077 zt5550_hpc.irq = hc_dev->irq;
48078 zt5550_hpc.irq_flags = IRQF_SHARED;
48079 zt5550_hpc.dev_id = hc_dev;
48080
48081- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48082- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48083- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48084+ pax_open_kernel();
48085+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48086+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48087+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48088+ pax_open_kernel();
48089 } else {
48090 info("using ENUM# polling mode");
48091 }
48092diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
48093index 76ba8a1..20ca857 100644
48094--- a/drivers/pci/hotplug/cpqphp_nvram.c
48095+++ b/drivers/pci/hotplug/cpqphp_nvram.c
48096@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
48097
48098 void compaq_nvram_init (void __iomem *rom_start)
48099 {
48100+
48101+#ifndef CONFIG_PAX_KERNEXEC
48102 if (rom_start) {
48103 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
48104 }
48105+#endif
48106+
48107 dbg("int15 entry = %p\n", compaq_int15_entry_point);
48108
48109 /* initialize our int15 lock */
48110diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
48111index cfa92a9..29539c5 100644
48112--- a/drivers/pci/hotplug/pci_hotplug_core.c
48113+++ b/drivers/pci/hotplug/pci_hotplug_core.c
48114@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
48115 return -EINVAL;
48116 }
48117
48118- slot->ops->owner = owner;
48119- slot->ops->mod_name = mod_name;
48120+ pax_open_kernel();
48121+ *(struct module **)&slot->ops->owner = owner;
48122+ *(const char **)&slot->ops->mod_name = mod_name;
48123+ pax_close_kernel();
48124
48125 mutex_lock(&pci_hp_mutex);
48126 /*
48127diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
48128index 53b58de..4479896 100644
48129--- a/drivers/pci/hotplug/pciehp_core.c
48130+++ b/drivers/pci/hotplug/pciehp_core.c
48131@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
48132 struct slot *slot = ctrl->slot;
48133 struct hotplug_slot *hotplug = NULL;
48134 struct hotplug_slot_info *info = NULL;
48135- struct hotplug_slot_ops *ops = NULL;
48136+ hotplug_slot_ops_no_const *ops = NULL;
48137 char name[SLOT_NAME_SIZE];
48138 int retval = -ENOMEM;
48139
48140diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
48141index 955ab79..d1df9c7 100644
48142--- a/drivers/pci/msi.c
48143+++ b/drivers/pci/msi.c
48144@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
48145 {
48146 struct attribute **msi_attrs;
48147 struct attribute *msi_attr;
48148- struct device_attribute *msi_dev_attr;
48149- struct attribute_group *msi_irq_group;
48150+ device_attribute_no_const *msi_dev_attr;
48151+ attribute_group_no_const *msi_irq_group;
48152 const struct attribute_group **msi_irq_groups;
48153 struct msi_desc *entry;
48154 int ret = -ENOMEM;
48155@@ -589,7 +589,7 @@ error_attrs:
48156 count = 0;
48157 msi_attr = msi_attrs[count];
48158 while (msi_attr) {
48159- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
48160+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
48161 kfree(msi_attr->name);
48162 kfree(msi_dev_attr);
48163 ++count;
48164diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
48165index 276ef9c..1d33a36 100644
48166--- a/drivers/pci/pci-sysfs.c
48167+++ b/drivers/pci/pci-sysfs.c
48168@@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
48169 {
48170 /* allocate attribute structure, piggyback attribute name */
48171 int name_len = write_combine ? 13 : 10;
48172- struct bin_attribute *res_attr;
48173+ bin_attribute_no_const *res_attr;
48174 int retval;
48175
48176 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
48177@@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
48178 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
48179 {
48180 int retval;
48181- struct bin_attribute *attr;
48182+ bin_attribute_no_const *attr;
48183
48184 /* If the device has VPD, try to expose it in sysfs. */
48185 if (dev->vpd) {
48186@@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
48187 {
48188 int retval;
48189 int rom_size = 0;
48190- struct bin_attribute *attr;
48191+ bin_attribute_no_const *attr;
48192
48193 if (!sysfs_initialized)
48194 return -EACCES;
48195diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
48196index 4df38df..b6bb7fe 100644
48197--- a/drivers/pci/pci.h
48198+++ b/drivers/pci/pci.h
48199@@ -93,7 +93,7 @@ struct pci_vpd_ops {
48200 struct pci_vpd {
48201 unsigned int len;
48202 const struct pci_vpd_ops *ops;
48203- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
48204+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
48205 };
48206
48207 int pci_vpd_pci22_init(struct pci_dev *dev);
48208diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
48209index e1e7026..d28dd33 100644
48210--- a/drivers/pci/pcie/aspm.c
48211+++ b/drivers/pci/pcie/aspm.c
48212@@ -27,9 +27,9 @@
48213 #define MODULE_PARAM_PREFIX "pcie_aspm."
48214
48215 /* Note: those are not register definitions */
48216-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
48217-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
48218-#define ASPM_STATE_L1 (4) /* L1 state */
48219+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
48220+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
48221+#define ASPM_STATE_L1 (4U) /* L1 state */
48222 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
48223 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
48224
48225diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
48226index 6e34498..9911975 100644
48227--- a/drivers/pci/probe.c
48228+++ b/drivers/pci/probe.c
48229@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
48230 struct pci_bus_region region, inverted_region;
48231 bool bar_too_big = false, bar_disabled = false;
48232
48233- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
48234+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
48235
48236 /* No printks while decoding is disabled! */
48237 if (!dev->mmio_always_on) {
48238diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
48239index 46d1378..30e452b 100644
48240--- a/drivers/pci/proc.c
48241+++ b/drivers/pci/proc.c
48242@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
48243 static int __init pci_proc_init(void)
48244 {
48245 struct pci_dev *dev = NULL;
48246+
48247+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48248+#ifdef CONFIG_GRKERNSEC_PROC_USER
48249+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
48250+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48251+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48252+#endif
48253+#else
48254 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
48255+#endif
48256 proc_create("devices", 0, proc_bus_pci_dir,
48257 &proc_bus_pci_dev_operations);
48258 proc_initialized = 1;
48259diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
48260index 7f3aad0..7d604bb 100644
48261--- a/drivers/platform/chrome/chromeos_laptop.c
48262+++ b/drivers/platform/chrome/chromeos_laptop.c
48263@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
48264 .callback = chromeos_laptop_dmi_matched, \
48265 .driver_data = (void *)&board_
48266
48267-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
48268+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
48269 {
48270 .ident = "Samsung Series 5 550",
48271 .matches = {
48272diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
48273index c5e082f..d6307a0 100644
48274--- a/drivers/platform/x86/asus-wmi.c
48275+++ b/drivers/platform/x86/asus-wmi.c
48276@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
48277 int err;
48278 u32 retval = -1;
48279
48280+#ifdef CONFIG_GRKERNSEC_KMEM
48281+ return -EPERM;
48282+#endif
48283+
48284 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
48285
48286 if (err < 0)
48287@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
48288 int err;
48289 u32 retval = -1;
48290
48291+#ifdef CONFIG_GRKERNSEC_KMEM
48292+ return -EPERM;
48293+#endif
48294+
48295 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
48296 &retval);
48297
48298@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
48299 union acpi_object *obj;
48300 acpi_status status;
48301
48302+#ifdef CONFIG_GRKERNSEC_KMEM
48303+ return -EPERM;
48304+#endif
48305+
48306 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
48307 1, asus->debug.method_id,
48308 &input, &output);
48309diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
48310index 62f8030..c7f2a45 100644
48311--- a/drivers/platform/x86/msi-laptop.c
48312+++ b/drivers/platform/x86/msi-laptop.c
48313@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
48314
48315 if (!quirks->ec_read_only) {
48316 /* allow userland write sysfs file */
48317- dev_attr_bluetooth.store = store_bluetooth;
48318- dev_attr_wlan.store = store_wlan;
48319- dev_attr_threeg.store = store_threeg;
48320- dev_attr_bluetooth.attr.mode |= S_IWUSR;
48321- dev_attr_wlan.attr.mode |= S_IWUSR;
48322- dev_attr_threeg.attr.mode |= S_IWUSR;
48323+ pax_open_kernel();
48324+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
48325+ *(void **)&dev_attr_wlan.store = store_wlan;
48326+ *(void **)&dev_attr_threeg.store = store_threeg;
48327+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
48328+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
48329+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
48330+ pax_close_kernel();
48331 }
48332
48333 /* disable hardware control by fn key */
48334diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
48335index 70222f2..8c8ce66 100644
48336--- a/drivers/platform/x86/msi-wmi.c
48337+++ b/drivers/platform/x86/msi-wmi.c
48338@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
48339 static void msi_wmi_notify(u32 value, void *context)
48340 {
48341 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
48342- static struct key_entry *key;
48343+ struct key_entry *key;
48344 union acpi_object *obj;
48345 acpi_status status;
48346
48347diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
48348index 8f8551a..3ace3ca 100644
48349--- a/drivers/platform/x86/sony-laptop.c
48350+++ b/drivers/platform/x86/sony-laptop.c
48351@@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
48352 }
48353
48354 /* High speed charging function */
48355-static struct device_attribute *hsc_handle;
48356+static device_attribute_no_const *hsc_handle;
48357
48358 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
48359 struct device_attribute *attr,
48360diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
48361index e2a91c8..986cc9f 100644
48362--- a/drivers/platform/x86/thinkpad_acpi.c
48363+++ b/drivers/platform/x86/thinkpad_acpi.c
48364@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
48365 return 0;
48366 }
48367
48368-void static hotkey_mask_warn_incomplete_mask(void)
48369+static void hotkey_mask_warn_incomplete_mask(void)
48370 {
48371 /* log only what the user can fix... */
48372 const u32 wantedmask = hotkey_driver_mask &
48373@@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
48374 }
48375 }
48376
48377-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48378- struct tp_nvram_state *newn,
48379- const u32 event_mask)
48380-{
48381-
48382 #define TPACPI_COMPARE_KEY(__scancode, __member) \
48383 do { \
48384 if ((event_mask & (1 << __scancode)) && \
48385@@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48386 tpacpi_hotkey_send_key(__scancode); \
48387 } while (0)
48388
48389- void issue_volchange(const unsigned int oldvol,
48390- const unsigned int newvol)
48391- {
48392- unsigned int i = oldvol;
48393+static void issue_volchange(const unsigned int oldvol,
48394+ const unsigned int newvol,
48395+ const u32 event_mask)
48396+{
48397+ unsigned int i = oldvol;
48398
48399- while (i > newvol) {
48400- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
48401- i--;
48402- }
48403- while (i < newvol) {
48404- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48405- i++;
48406- }
48407+ while (i > newvol) {
48408+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
48409+ i--;
48410 }
48411+ while (i < newvol) {
48412+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48413+ i++;
48414+ }
48415+}
48416
48417- void issue_brightnesschange(const unsigned int oldbrt,
48418- const unsigned int newbrt)
48419- {
48420- unsigned int i = oldbrt;
48421+static void issue_brightnesschange(const unsigned int oldbrt,
48422+ const unsigned int newbrt,
48423+ const u32 event_mask)
48424+{
48425+ unsigned int i = oldbrt;
48426
48427- while (i > newbrt) {
48428- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48429- i--;
48430- }
48431- while (i < newbrt) {
48432- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48433- i++;
48434- }
48435+ while (i > newbrt) {
48436+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48437+ i--;
48438+ }
48439+ while (i < newbrt) {
48440+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48441+ i++;
48442 }
48443+}
48444
48445+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48446+ struct tp_nvram_state *newn,
48447+ const u32 event_mask)
48448+{
48449 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
48450 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
48451 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
48452@@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48453 oldn->volume_level != newn->volume_level) {
48454 /* recently muted, or repeated mute keypress, or
48455 * multiple presses ending in mute */
48456- issue_volchange(oldn->volume_level, newn->volume_level);
48457+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48458 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
48459 }
48460 } else {
48461@@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48462 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48463 }
48464 if (oldn->volume_level != newn->volume_level) {
48465- issue_volchange(oldn->volume_level, newn->volume_level);
48466+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48467 } else if (oldn->volume_toggle != newn->volume_toggle) {
48468 /* repeated vol up/down keypress at end of scale ? */
48469 if (newn->volume_level == 0)
48470@@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48471 /* handle brightness */
48472 if (oldn->brightness_level != newn->brightness_level) {
48473 issue_brightnesschange(oldn->brightness_level,
48474- newn->brightness_level);
48475+ newn->brightness_level,
48476+ event_mask);
48477 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
48478 /* repeated key presses that didn't change state */
48479 if (newn->brightness_level == 0)
48480@@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48481 && !tp_features.bright_unkfw)
48482 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48483 }
48484+}
48485
48486 #undef TPACPI_COMPARE_KEY
48487 #undef TPACPI_MAY_SEND_KEY
48488-}
48489
48490 /*
48491 * Polling driver
48492diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48493index 769d265..a3a05ca 100644
48494--- a/drivers/pnp/pnpbios/bioscalls.c
48495+++ b/drivers/pnp/pnpbios/bioscalls.c
48496@@ -58,7 +58,7 @@ do { \
48497 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48498 } while(0)
48499
48500-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48501+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48502 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48503
48504 /*
48505@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48506
48507 cpu = get_cpu();
48508 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48509+
48510+ pax_open_kernel();
48511 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48512+ pax_close_kernel();
48513
48514 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48515 spin_lock_irqsave(&pnp_bios_lock, flags);
48516@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48517 :"memory");
48518 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48519
48520+ pax_open_kernel();
48521 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48522+ pax_close_kernel();
48523+
48524 put_cpu();
48525
48526 /* If we get here and this is set then the PnP BIOS faulted on us. */
48527@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48528 return status;
48529 }
48530
48531-void pnpbios_calls_init(union pnp_bios_install_struct *header)
48532+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48533 {
48534 int i;
48535
48536@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48537 pnp_bios_callpoint.offset = header->fields.pm16offset;
48538 pnp_bios_callpoint.segment = PNP_CS16;
48539
48540+ pax_open_kernel();
48541+
48542 for_each_possible_cpu(i) {
48543 struct desc_struct *gdt = get_cpu_gdt_table(i);
48544 if (!gdt)
48545@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48546 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48547 (unsigned long)__va(header->fields.pm16dseg));
48548 }
48549+
48550+ pax_close_kernel();
48551 }
48552diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48553index bacddd1..65ea100 100644
48554--- a/drivers/pnp/resource.c
48555+++ b/drivers/pnp/resource.c
48556@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48557 return 1;
48558
48559 /* check if the resource is valid */
48560- if (*irq < 0 || *irq > 15)
48561+ if (*irq > 15)
48562 return 0;
48563
48564 /* check if the resource is reserved */
48565@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48566 return 1;
48567
48568 /* check if the resource is valid */
48569- if (*dma < 0 || *dma == 4 || *dma > 7)
48570+ if (*dma == 4 || *dma > 7)
48571 return 0;
48572
48573 /* check if the resource is reserved */
48574diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48575index 0c52e2a..3421ab7 100644
48576--- a/drivers/power/pda_power.c
48577+++ b/drivers/power/pda_power.c
48578@@ -37,7 +37,11 @@ static int polling;
48579
48580 #if IS_ENABLED(CONFIG_USB_PHY)
48581 static struct usb_phy *transceiver;
48582-static struct notifier_block otg_nb;
48583+static int otg_handle_notification(struct notifier_block *nb,
48584+ unsigned long event, void *unused);
48585+static struct notifier_block otg_nb = {
48586+ .notifier_call = otg_handle_notification
48587+};
48588 #endif
48589
48590 static struct regulator *ac_draw;
48591@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48592
48593 #if IS_ENABLED(CONFIG_USB_PHY)
48594 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48595- otg_nb.notifier_call = otg_handle_notification;
48596 ret = usb_register_notifier(transceiver, &otg_nb);
48597 if (ret) {
48598 dev_err(dev, "failure to register otg notifier\n");
48599diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48600index cc439fd..8fa30df 100644
48601--- a/drivers/power/power_supply.h
48602+++ b/drivers/power/power_supply.h
48603@@ -16,12 +16,12 @@ struct power_supply;
48604
48605 #ifdef CONFIG_SYSFS
48606
48607-extern void power_supply_init_attrs(struct device_type *dev_type);
48608+extern void power_supply_init_attrs(void);
48609 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48610
48611 #else
48612
48613-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48614+static inline void power_supply_init_attrs(void) {}
48615 #define power_supply_uevent NULL
48616
48617 #endif /* CONFIG_SYSFS */
48618diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48619index 2660664..75fcb04 100644
48620--- a/drivers/power/power_supply_core.c
48621+++ b/drivers/power/power_supply_core.c
48622@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48623 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48624 EXPORT_SYMBOL_GPL(power_supply_notifier);
48625
48626-static struct device_type power_supply_dev_type;
48627+extern const struct attribute_group *power_supply_attr_groups[];
48628+static struct device_type power_supply_dev_type = {
48629+ .groups = power_supply_attr_groups,
48630+};
48631
48632 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48633 struct power_supply *supply)
48634@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48635 return PTR_ERR(power_supply_class);
48636
48637 power_supply_class->dev_uevent = power_supply_uevent;
48638- power_supply_init_attrs(&power_supply_dev_type);
48639+ power_supply_init_attrs();
48640
48641 return 0;
48642 }
48643diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48644index 44420d1..967126e 100644
48645--- a/drivers/power/power_supply_sysfs.c
48646+++ b/drivers/power/power_supply_sysfs.c
48647@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48648 .is_visible = power_supply_attr_is_visible,
48649 };
48650
48651-static const struct attribute_group *power_supply_attr_groups[] = {
48652+const struct attribute_group *power_supply_attr_groups[] = {
48653 &power_supply_attr_group,
48654 NULL,
48655 };
48656
48657-void power_supply_init_attrs(struct device_type *dev_type)
48658+void power_supply_init_attrs(void)
48659 {
48660 int i;
48661
48662- dev_type->groups = power_supply_attr_groups;
48663-
48664 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48665 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48666 }
48667diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48668index 84419af..268ede8 100644
48669--- a/drivers/powercap/powercap_sys.c
48670+++ b/drivers/powercap/powercap_sys.c
48671@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48672 struct device_attribute name_attr;
48673 };
48674
48675+static ssize_t show_constraint_name(struct device *dev,
48676+ struct device_attribute *dev_attr,
48677+ char *buf);
48678+
48679 static struct powercap_constraint_attr
48680- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48681+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48682+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48683+ .power_limit_attr = {
48684+ .attr = {
48685+ .name = NULL,
48686+ .mode = S_IWUSR | S_IRUGO
48687+ },
48688+ .show = show_constraint_power_limit_uw,
48689+ .store = store_constraint_power_limit_uw
48690+ },
48691+
48692+ .time_window_attr = {
48693+ .attr = {
48694+ .name = NULL,
48695+ .mode = S_IWUSR | S_IRUGO
48696+ },
48697+ .show = show_constraint_time_window_us,
48698+ .store = store_constraint_time_window_us
48699+ },
48700+
48701+ .max_power_attr = {
48702+ .attr = {
48703+ .name = NULL,
48704+ .mode = S_IRUGO
48705+ },
48706+ .show = show_constraint_max_power_uw,
48707+ .store = NULL
48708+ },
48709+
48710+ .min_power_attr = {
48711+ .attr = {
48712+ .name = NULL,
48713+ .mode = S_IRUGO
48714+ },
48715+ .show = show_constraint_min_power_uw,
48716+ .store = NULL
48717+ },
48718+
48719+ .max_time_window_attr = {
48720+ .attr = {
48721+ .name = NULL,
48722+ .mode = S_IRUGO
48723+ },
48724+ .show = show_constraint_max_time_window_us,
48725+ .store = NULL
48726+ },
48727+
48728+ .min_time_window_attr = {
48729+ .attr = {
48730+ .name = NULL,
48731+ .mode = S_IRUGO
48732+ },
48733+ .show = show_constraint_min_time_window_us,
48734+ .store = NULL
48735+ },
48736+
48737+ .name_attr = {
48738+ .attr = {
48739+ .name = NULL,
48740+ .mode = S_IRUGO
48741+ },
48742+ .show = show_constraint_name,
48743+ .store = NULL
48744+ }
48745+ }
48746+};
48747
48748 /* A list of powercap control_types */
48749 static LIST_HEAD(powercap_cntrl_list);
48750@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48751 }
48752
48753 static int create_constraint_attribute(int id, const char *name,
48754- int mode,
48755- struct device_attribute *dev_attr,
48756- ssize_t (*show)(struct device *,
48757- struct device_attribute *, char *),
48758- ssize_t (*store)(struct device *,
48759- struct device_attribute *,
48760- const char *, size_t)
48761- )
48762+ struct device_attribute *dev_attr)
48763 {
48764+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48765
48766- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48767- id, name);
48768- if (!dev_attr->attr.name)
48769+ if (!name)
48770 return -ENOMEM;
48771- dev_attr->attr.mode = mode;
48772- dev_attr->show = show;
48773- dev_attr->store = store;
48774+
48775+ pax_open_kernel();
48776+ *(const char **)&dev_attr->attr.name = name;
48777+ pax_close_kernel();
48778
48779 return 0;
48780 }
48781@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48782
48783 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48784 ret = create_constraint_attribute(i, "power_limit_uw",
48785- S_IWUSR | S_IRUGO,
48786- &constraint_attrs[i].power_limit_attr,
48787- show_constraint_power_limit_uw,
48788- store_constraint_power_limit_uw);
48789+ &constraint_attrs[i].power_limit_attr);
48790 if (ret)
48791 goto err_alloc;
48792 ret = create_constraint_attribute(i, "time_window_us",
48793- S_IWUSR | S_IRUGO,
48794- &constraint_attrs[i].time_window_attr,
48795- show_constraint_time_window_us,
48796- store_constraint_time_window_us);
48797+ &constraint_attrs[i].time_window_attr);
48798 if (ret)
48799 goto err_alloc;
48800- ret = create_constraint_attribute(i, "name", S_IRUGO,
48801- &constraint_attrs[i].name_attr,
48802- show_constraint_name,
48803- NULL);
48804+ ret = create_constraint_attribute(i, "name",
48805+ &constraint_attrs[i].name_attr);
48806 if (ret)
48807 goto err_alloc;
48808- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48809- &constraint_attrs[i].max_power_attr,
48810- show_constraint_max_power_uw,
48811- NULL);
48812+ ret = create_constraint_attribute(i, "max_power_uw",
48813+ &constraint_attrs[i].max_power_attr);
48814 if (ret)
48815 goto err_alloc;
48816- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48817- &constraint_attrs[i].min_power_attr,
48818- show_constraint_min_power_uw,
48819- NULL);
48820+ ret = create_constraint_attribute(i, "min_power_uw",
48821+ &constraint_attrs[i].min_power_attr);
48822 if (ret)
48823 goto err_alloc;
48824 ret = create_constraint_attribute(i, "max_time_window_us",
48825- S_IRUGO,
48826- &constraint_attrs[i].max_time_window_attr,
48827- show_constraint_max_time_window_us,
48828- NULL);
48829+ &constraint_attrs[i].max_time_window_attr);
48830 if (ret)
48831 goto err_alloc;
48832 ret = create_constraint_attribute(i, "min_time_window_us",
48833- S_IRUGO,
48834- &constraint_attrs[i].min_time_window_attr,
48835- show_constraint_min_time_window_us,
48836- NULL);
48837+ &constraint_attrs[i].min_time_window_attr);
48838 if (ret)
48839 goto err_alloc;
48840
48841@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48842 power_zone->zone_dev_attrs[count++] =
48843 &dev_attr_max_energy_range_uj.attr;
48844 if (power_zone->ops->get_energy_uj) {
48845+ pax_open_kernel();
48846 if (power_zone->ops->reset_energy_uj)
48847- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48848+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48849 else
48850- dev_attr_energy_uj.attr.mode = S_IRUGO;
48851+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48852+ pax_close_kernel();
48853 power_zone->zone_dev_attrs[count++] =
48854 &dev_attr_energy_uj.attr;
48855 }
48856diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48857index afca1bc..86840b8 100644
48858--- a/drivers/regulator/core.c
48859+++ b/drivers/regulator/core.c
48860@@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48861 {
48862 const struct regulation_constraints *constraints = NULL;
48863 const struct regulator_init_data *init_data;
48864- static atomic_t regulator_no = ATOMIC_INIT(0);
48865+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48866 struct regulator_dev *rdev;
48867 struct device *dev;
48868 int ret, i;
48869@@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48870 rdev->dev.of_node = config->of_node;
48871 rdev->dev.parent = dev;
48872 dev_set_name(&rdev->dev, "regulator.%d",
48873- atomic_inc_return(&regulator_no) - 1);
48874+ atomic_inc_return_unchecked(&regulator_no) - 1);
48875 ret = device_register(&rdev->dev);
48876 if (ret != 0) {
48877 put_device(&rdev->dev);
48878diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48879index 8d94d3d..653b623 100644
48880--- a/drivers/regulator/max8660.c
48881+++ b/drivers/regulator/max8660.c
48882@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48883 max8660->shadow_regs[MAX8660_OVER1] = 5;
48884 } else {
48885 /* Otherwise devices can be toggled via software */
48886- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48887- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48888+ pax_open_kernel();
48889+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48890+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48891+ pax_close_kernel();
48892 }
48893
48894 /*
48895diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48896index 892aa1e..ebd1b9c 100644
48897--- a/drivers/regulator/max8973-regulator.c
48898+++ b/drivers/regulator/max8973-regulator.c
48899@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48900 if (!pdata || !pdata->enable_ext_control) {
48901 max->desc.enable_reg = MAX8973_VOUT;
48902 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48903- max->ops.enable = regulator_enable_regmap;
48904- max->ops.disable = regulator_disable_regmap;
48905- max->ops.is_enabled = regulator_is_enabled_regmap;
48906+ pax_open_kernel();
48907+ *(void **)&max->ops.enable = regulator_enable_regmap;
48908+ *(void **)&max->ops.disable = regulator_disable_regmap;
48909+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48910+ pax_close_kernel();
48911 }
48912
48913 if (pdata) {
48914diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48915index f374fa5..26f0683 100644
48916--- a/drivers/regulator/mc13892-regulator.c
48917+++ b/drivers/regulator/mc13892-regulator.c
48918@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48919 }
48920 mc13xxx_unlock(mc13892);
48921
48922- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48923+ pax_open_kernel();
48924+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48925 = mc13892_vcam_set_mode;
48926- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48927+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48928 = mc13892_vcam_get_mode;
48929+ pax_close_kernel();
48930
48931 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48932 ARRAY_SIZE(mc13892_regulators));
48933diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48934index cae212f..58a3980 100644
48935--- a/drivers/rtc/rtc-cmos.c
48936+++ b/drivers/rtc/rtc-cmos.c
48937@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48938 hpet_rtc_timer_init();
48939
48940 /* export at least the first block of NVRAM */
48941- nvram.size = address_space - NVRAM_OFFSET;
48942+ pax_open_kernel();
48943+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48944+ pax_close_kernel();
48945 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48946 if (retval < 0) {
48947 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48948diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48949index d049393..bb20be0 100644
48950--- a/drivers/rtc/rtc-dev.c
48951+++ b/drivers/rtc/rtc-dev.c
48952@@ -16,6 +16,7 @@
48953 #include <linux/module.h>
48954 #include <linux/rtc.h>
48955 #include <linux/sched.h>
48956+#include <linux/grsecurity.h>
48957 #include "rtc-core.h"
48958
48959 static dev_t rtc_devt;
48960@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48961 if (copy_from_user(&tm, uarg, sizeof(tm)))
48962 return -EFAULT;
48963
48964+ gr_log_timechange();
48965+
48966 return rtc_set_time(rtc, &tm);
48967
48968 case RTC_PIE_ON:
48969diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48970index 4e75345..09f8663 100644
48971--- a/drivers/rtc/rtc-ds1307.c
48972+++ b/drivers/rtc/rtc-ds1307.c
48973@@ -107,7 +107,7 @@ struct ds1307 {
48974 u8 offset; /* register's offset */
48975 u8 regs[11];
48976 u16 nvram_offset;
48977- struct bin_attribute *nvram;
48978+ bin_attribute_no_const *nvram;
48979 enum ds_type type;
48980 unsigned long flags;
48981 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48982diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48983index 11880c1..b823aa4 100644
48984--- a/drivers/rtc/rtc-m48t59.c
48985+++ b/drivers/rtc/rtc-m48t59.c
48986@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48987 if (IS_ERR(m48t59->rtc))
48988 return PTR_ERR(m48t59->rtc);
48989
48990- m48t59_nvram_attr.size = pdata->offset;
48991+ pax_open_kernel();
48992+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48993+ pax_close_kernel();
48994
48995 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48996 if (ret)
48997diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48998index 14b5f8d..cc9bd26 100644
48999--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
49000+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
49001@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
49002 for (bit = 0; bit < 8; bit++) {
49003
49004 if ((pci_status[i] & (0x1 << bit)) != 0) {
49005- static const char *s;
49006+ const char *s;
49007
49008 s = pci_status_strings[bit];
49009 if (i == 7/*TARG*/ && bit == 3)
49010@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
49011
49012 for (bit = 0; bit < 8; bit++) {
49013
49014- if ((split_status[i] & (0x1 << bit)) != 0) {
49015- static const char *s;
49016-
49017- s = split_status_strings[bit];
49018- printk(s, ahd_name(ahd),
49019+ if ((split_status[i] & (0x1 << bit)) != 0)
49020+ printk(split_status_strings[bit], ahd_name(ahd),
49021 split_status_source[i]);
49022- }
49023
49024 if (i > 1)
49025 continue;
49026
49027- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
49028- static const char *s;
49029-
49030- s = split_status_strings[bit];
49031- printk(s, ahd_name(ahd), "SG");
49032- }
49033+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
49034+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
49035 }
49036 }
49037 /*
49038diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
49039index e693af6..2e525b6 100644
49040--- a/drivers/scsi/bfa/bfa_fcpim.h
49041+++ b/drivers/scsi/bfa/bfa_fcpim.h
49042@@ -36,7 +36,7 @@ struct bfa_iotag_s {
49043
49044 struct bfa_itn_s {
49045 bfa_isr_func_t isr;
49046-};
49047+} __no_const;
49048
49049 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
49050 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
49051diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
49052index a3ab5cc..8143622 100644
49053--- a/drivers/scsi/bfa/bfa_fcs.c
49054+++ b/drivers/scsi/bfa/bfa_fcs.c
49055@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
49056 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
49057
49058 static struct bfa_fcs_mod_s fcs_modules[] = {
49059- { bfa_fcs_port_attach, NULL, NULL },
49060- { bfa_fcs_uf_attach, NULL, NULL },
49061- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
49062- bfa_fcs_fabric_modexit },
49063+ {
49064+ .attach = bfa_fcs_port_attach,
49065+ .modinit = NULL,
49066+ .modexit = NULL
49067+ },
49068+ {
49069+ .attach = bfa_fcs_uf_attach,
49070+ .modinit = NULL,
49071+ .modexit = NULL
49072+ },
49073+ {
49074+ .attach = bfa_fcs_fabric_attach,
49075+ .modinit = bfa_fcs_fabric_modinit,
49076+ .modexit = bfa_fcs_fabric_modexit
49077+ },
49078 };
49079
49080 /*
49081diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
49082index ff75ef8..2dfe00a 100644
49083--- a/drivers/scsi/bfa/bfa_fcs_lport.c
49084+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
49085@@ -89,15 +89,26 @@ static struct {
49086 void (*offline) (struct bfa_fcs_lport_s *port);
49087 } __port_action[] = {
49088 {
49089- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
49090- bfa_fcs_lport_unknown_offline}, {
49091- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
49092- bfa_fcs_lport_fab_offline}, {
49093- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
49094- bfa_fcs_lport_n2n_offline}, {
49095- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
49096- bfa_fcs_lport_loop_offline},
49097- };
49098+ .init = bfa_fcs_lport_unknown_init,
49099+ .online = bfa_fcs_lport_unknown_online,
49100+ .offline = bfa_fcs_lport_unknown_offline
49101+ },
49102+ {
49103+ .init = bfa_fcs_lport_fab_init,
49104+ .online = bfa_fcs_lport_fab_online,
49105+ .offline = bfa_fcs_lport_fab_offline
49106+ },
49107+ {
49108+ .init = bfa_fcs_lport_n2n_init,
49109+ .online = bfa_fcs_lport_n2n_online,
49110+ .offline = bfa_fcs_lport_n2n_offline
49111+ },
49112+ {
49113+ .init = bfa_fcs_lport_loop_init,
49114+ .online = bfa_fcs_lport_loop_online,
49115+ .offline = bfa_fcs_lport_loop_offline
49116+ },
49117+};
49118
49119 /*
49120 * fcs_port_sm FCS logical port state machine
49121diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
49122index 2e28392..9d865b6 100644
49123--- a/drivers/scsi/bfa/bfa_ioc.h
49124+++ b/drivers/scsi/bfa/bfa_ioc.h
49125@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
49126 bfa_ioc_disable_cbfn_t disable_cbfn;
49127 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
49128 bfa_ioc_reset_cbfn_t reset_cbfn;
49129-};
49130+} __no_const;
49131
49132 /*
49133 * IOC event notification mechanism.
49134@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
49135 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
49136 enum bfi_ioc_state fwstate);
49137 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
49138-};
49139+} __no_const;
49140
49141 /*
49142 * Queue element to wait for room in request queue. FIFO order is
49143diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
49144index a14c784..6de6790 100644
49145--- a/drivers/scsi/bfa/bfa_modules.h
49146+++ b/drivers/scsi/bfa/bfa_modules.h
49147@@ -78,12 +78,12 @@ enum {
49148 \
49149 extern struct bfa_module_s hal_mod_ ## __mod; \
49150 struct bfa_module_s hal_mod_ ## __mod = { \
49151- bfa_ ## __mod ## _meminfo, \
49152- bfa_ ## __mod ## _attach, \
49153- bfa_ ## __mod ## _detach, \
49154- bfa_ ## __mod ## _start, \
49155- bfa_ ## __mod ## _stop, \
49156- bfa_ ## __mod ## _iocdisable, \
49157+ .meminfo = bfa_ ## __mod ## _meminfo, \
49158+ .attach = bfa_ ## __mod ## _attach, \
49159+ .detach = bfa_ ## __mod ## _detach, \
49160+ .start = bfa_ ## __mod ## _start, \
49161+ .stop = bfa_ ## __mod ## _stop, \
49162+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
49163 }
49164
49165 #define BFA_CACHELINE_SZ (256)
49166diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
49167index 045c4e1..13de803 100644
49168--- a/drivers/scsi/fcoe/fcoe_sysfs.c
49169+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
49170@@ -33,8 +33,8 @@
49171 */
49172 #include "libfcoe.h"
49173
49174-static atomic_t ctlr_num;
49175-static atomic_t fcf_num;
49176+static atomic_unchecked_t ctlr_num;
49177+static atomic_unchecked_t fcf_num;
49178
49179 /*
49180 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
49181@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
49182 if (!ctlr)
49183 goto out;
49184
49185- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
49186+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
49187 ctlr->f = f;
49188 ctlr->mode = FIP_CONN_TYPE_FABRIC;
49189 INIT_LIST_HEAD(&ctlr->fcfs);
49190@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
49191 fcf->dev.parent = &ctlr->dev;
49192 fcf->dev.bus = &fcoe_bus_type;
49193 fcf->dev.type = &fcoe_fcf_device_type;
49194- fcf->id = atomic_inc_return(&fcf_num) - 1;
49195+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
49196 fcf->state = FCOE_FCF_STATE_UNKNOWN;
49197
49198 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
49199@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
49200 {
49201 int error;
49202
49203- atomic_set(&ctlr_num, 0);
49204- atomic_set(&fcf_num, 0);
49205+ atomic_set_unchecked(&ctlr_num, 0);
49206+ atomic_set_unchecked(&fcf_num, 0);
49207
49208 error = bus_register(&fcoe_bus_type);
49209 if (error)
49210diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
49211index f28ea07..34b16d3 100644
49212--- a/drivers/scsi/hosts.c
49213+++ b/drivers/scsi/hosts.c
49214@@ -42,7 +42,7 @@
49215 #include "scsi_logging.h"
49216
49217
49218-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49219+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49220
49221
49222 static void scsi_host_cls_release(struct device *dev)
49223@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
49224 * subtract one because we increment first then return, but we need to
49225 * know what the next host number was before increment
49226 */
49227- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
49228+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
49229 shost->dma_channel = 0xff;
49230
49231 /* These three are default values which can be overridden */
49232diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
49233index 868318a..e07ef3b 100644
49234--- a/drivers/scsi/hpsa.c
49235+++ b/drivers/scsi/hpsa.c
49236@@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
49237 unsigned long flags;
49238
49239 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
49240- return h->access.command_completed(h, q);
49241+ return h->access->command_completed(h, q);
49242
49243 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
49244 a = rq->head[rq->current_entry];
49245@@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
49246 while (!list_empty(&h->reqQ)) {
49247 c = list_entry(h->reqQ.next, struct CommandList, list);
49248 /* can't do anything if fifo is full */
49249- if ((h->access.fifo_full(h))) {
49250+ if ((h->access->fifo_full(h))) {
49251 h->fifo_recently_full = 1;
49252 dev_warn(&h->pdev->dev, "fifo full\n");
49253 break;
49254@@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
49255
49256 /* Tell the controller execute command */
49257 spin_unlock_irqrestore(&h->lock, flags);
49258- h->access.submit_command(h, c);
49259+ h->access->submit_command(h, c);
49260 spin_lock_irqsave(&h->lock, flags);
49261 }
49262 spin_unlock_irqrestore(&h->lock, flags);
49263@@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
49264
49265 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
49266 {
49267- return h->access.command_completed(h, q);
49268+ return h->access->command_completed(h, q);
49269 }
49270
49271 static inline bool interrupt_pending(struct ctlr_info *h)
49272 {
49273- return h->access.intr_pending(h);
49274+ return h->access->intr_pending(h);
49275 }
49276
49277 static inline long interrupt_not_for_us(struct ctlr_info *h)
49278 {
49279- return (h->access.intr_pending(h) == 0) ||
49280+ return (h->access->intr_pending(h) == 0) ||
49281 (h->interrupts_enabled == 0);
49282 }
49283
49284@@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
49285 if (prod_index < 0)
49286 return -ENODEV;
49287 h->product_name = products[prod_index].product_name;
49288- h->access = *(products[prod_index].access);
49289+ h->access = products[prod_index].access;
49290
49291 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
49292 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
49293@@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
49294 {
49295 unsigned long flags;
49296
49297- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49298+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49299 spin_lock_irqsave(&h->lock, flags);
49300 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
49301 spin_unlock_irqrestore(&h->lock, flags);
49302@@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
49303 }
49304
49305 /* make sure the board interrupts are off */
49306- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49307+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49308
49309 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
49310 goto clean2;
49311@@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
49312 * fake ones to scoop up any residual completions.
49313 */
49314 spin_lock_irqsave(&h->lock, flags);
49315- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49316+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49317 spin_unlock_irqrestore(&h->lock, flags);
49318 free_irqs(h);
49319 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
49320@@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
49321 dev_info(&h->pdev->dev, "Board READY.\n");
49322 dev_info(&h->pdev->dev,
49323 "Waiting for stale completions to drain.\n");
49324- h->access.set_intr_mask(h, HPSA_INTR_ON);
49325+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49326 msleep(10000);
49327- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49328+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49329
49330 rc = controller_reset_failed(h->cfgtable);
49331 if (rc)
49332@@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
49333 }
49334
49335 /* Turn the interrupts on so we can service requests */
49336- h->access.set_intr_mask(h, HPSA_INTR_ON);
49337+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49338
49339 hpsa_hba_inquiry(h);
49340 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
49341@@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
49342 * To write all data in the battery backed cache to disks
49343 */
49344 hpsa_flush_cache(h);
49345- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49346+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49347 hpsa_free_irqs_and_disable_msix(h);
49348 }
49349
49350@@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
49351 return;
49352 }
49353 /* Change the access methods to the performant access methods */
49354- h->access = SA5_performant_access;
49355+ h->access = &SA5_performant_access;
49356 h->transMethod = CFGTBL_Trans_Performant;
49357 }
49358
49359diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
49360index 01c3283..4655219 100644
49361--- a/drivers/scsi/hpsa.h
49362+++ b/drivers/scsi/hpsa.h
49363@@ -79,7 +79,7 @@ struct ctlr_info {
49364 unsigned int msix_vector;
49365 unsigned int msi_vector;
49366 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
49367- struct access_method access;
49368+ struct access_method *access;
49369
49370 /* queue and queue Info */
49371 struct list_head reqQ;
49372@@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
49373 }
49374
49375 static struct access_method SA5_access = {
49376- SA5_submit_command,
49377- SA5_intr_mask,
49378- SA5_fifo_full,
49379- SA5_intr_pending,
49380- SA5_completed,
49381+ .submit_command = SA5_submit_command,
49382+ .set_intr_mask = SA5_intr_mask,
49383+ .fifo_full = SA5_fifo_full,
49384+ .intr_pending = SA5_intr_pending,
49385+ .command_completed = SA5_completed,
49386 };
49387
49388 static struct access_method SA5_performant_access = {
49389- SA5_submit_command,
49390- SA5_performant_intr_mask,
49391- SA5_fifo_full,
49392- SA5_performant_intr_pending,
49393- SA5_performant_completed,
49394+ .submit_command = SA5_submit_command,
49395+ .set_intr_mask = SA5_performant_intr_mask,
49396+ .fifo_full = SA5_fifo_full,
49397+ .intr_pending = SA5_performant_intr_pending,
49398+ .command_completed = SA5_performant_completed,
49399 };
49400
49401 struct board_type {
49402diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
49403index 1b3a094..068e683 100644
49404--- a/drivers/scsi/libfc/fc_exch.c
49405+++ b/drivers/scsi/libfc/fc_exch.c
49406@@ -101,12 +101,12 @@ struct fc_exch_mgr {
49407 u16 pool_max_index;
49408
49409 struct {
49410- atomic_t no_free_exch;
49411- atomic_t no_free_exch_xid;
49412- atomic_t xid_not_found;
49413- atomic_t xid_busy;
49414- atomic_t seq_not_found;
49415- atomic_t non_bls_resp;
49416+ atomic_unchecked_t no_free_exch;
49417+ atomic_unchecked_t no_free_exch_xid;
49418+ atomic_unchecked_t xid_not_found;
49419+ atomic_unchecked_t xid_busy;
49420+ atomic_unchecked_t seq_not_found;
49421+ atomic_unchecked_t non_bls_resp;
49422 } stats;
49423 };
49424
49425@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
49426 /* allocate memory for exchange */
49427 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
49428 if (!ep) {
49429- atomic_inc(&mp->stats.no_free_exch);
49430+ atomic_inc_unchecked(&mp->stats.no_free_exch);
49431 goto out;
49432 }
49433 memset(ep, 0, sizeof(*ep));
49434@@ -874,7 +874,7 @@ out:
49435 return ep;
49436 err:
49437 spin_unlock_bh(&pool->lock);
49438- atomic_inc(&mp->stats.no_free_exch_xid);
49439+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49440 mempool_free(ep, mp->ep_pool);
49441 return NULL;
49442 }
49443@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49444 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49445 ep = fc_exch_find(mp, xid);
49446 if (!ep) {
49447- atomic_inc(&mp->stats.xid_not_found);
49448+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49449 reject = FC_RJT_OX_ID;
49450 goto out;
49451 }
49452@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49453 ep = fc_exch_find(mp, xid);
49454 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49455 if (ep) {
49456- atomic_inc(&mp->stats.xid_busy);
49457+ atomic_inc_unchecked(&mp->stats.xid_busy);
49458 reject = FC_RJT_RX_ID;
49459 goto rel;
49460 }
49461@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49462 }
49463 xid = ep->xid; /* get our XID */
49464 } else if (!ep) {
49465- atomic_inc(&mp->stats.xid_not_found);
49466+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49467 reject = FC_RJT_RX_ID; /* XID not found */
49468 goto out;
49469 }
49470@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49471 } else {
49472 sp = &ep->seq;
49473 if (sp->id != fh->fh_seq_id) {
49474- atomic_inc(&mp->stats.seq_not_found);
49475+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49476 if (f_ctl & FC_FC_END_SEQ) {
49477 /*
49478 * Update sequence_id based on incoming last
49479@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49480
49481 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49482 if (!ep) {
49483- atomic_inc(&mp->stats.xid_not_found);
49484+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49485 goto out;
49486 }
49487 if (ep->esb_stat & ESB_ST_COMPLETE) {
49488- atomic_inc(&mp->stats.xid_not_found);
49489+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49490 goto rel;
49491 }
49492 if (ep->rxid == FC_XID_UNKNOWN)
49493 ep->rxid = ntohs(fh->fh_rx_id);
49494 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49495- atomic_inc(&mp->stats.xid_not_found);
49496+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49497 goto rel;
49498 }
49499 if (ep->did != ntoh24(fh->fh_s_id) &&
49500 ep->did != FC_FID_FLOGI) {
49501- atomic_inc(&mp->stats.xid_not_found);
49502+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49503 goto rel;
49504 }
49505 sof = fr_sof(fp);
49506@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49507 sp->ssb_stat |= SSB_ST_RESP;
49508 sp->id = fh->fh_seq_id;
49509 } else if (sp->id != fh->fh_seq_id) {
49510- atomic_inc(&mp->stats.seq_not_found);
49511+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49512 goto rel;
49513 }
49514
49515@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49516 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49517
49518 if (!sp)
49519- atomic_inc(&mp->stats.xid_not_found);
49520+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49521 else
49522- atomic_inc(&mp->stats.non_bls_resp);
49523+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
49524
49525 fc_frame_free(fp);
49526 }
49527@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49528
49529 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49530 mp = ema->mp;
49531- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49532+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49533 st->fc_no_free_exch_xid +=
49534- atomic_read(&mp->stats.no_free_exch_xid);
49535- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49536- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49537- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49538- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49539+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49540+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49541+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49542+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49543+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49544 }
49545 }
49546 EXPORT_SYMBOL(fc_exch_update_stats);
49547diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49548index d289583..b745eec 100644
49549--- a/drivers/scsi/libsas/sas_ata.c
49550+++ b/drivers/scsi/libsas/sas_ata.c
49551@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49552 .postreset = ata_std_postreset,
49553 .error_handler = ata_std_error_handler,
49554 .post_internal_cmd = sas_ata_post_internal,
49555- .qc_defer = ata_std_qc_defer,
49556+ .qc_defer = ata_std_qc_defer,
49557 .qc_prep = ata_noop_qc_prep,
49558 .qc_issue = sas_ata_qc_issue,
49559 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49560diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49561index 4e1b75c..0bbdfa9 100644
49562--- a/drivers/scsi/lpfc/lpfc.h
49563+++ b/drivers/scsi/lpfc/lpfc.h
49564@@ -432,7 +432,7 @@ struct lpfc_vport {
49565 struct dentry *debug_nodelist;
49566 struct dentry *vport_debugfs_root;
49567 struct lpfc_debugfs_trc *disc_trc;
49568- atomic_t disc_trc_cnt;
49569+ atomic_unchecked_t disc_trc_cnt;
49570 #endif
49571 uint8_t stat_data_enabled;
49572 uint8_t stat_data_blocked;
49573@@ -865,8 +865,8 @@ struct lpfc_hba {
49574 struct timer_list fabric_block_timer;
49575 unsigned long bit_flags;
49576 #define FABRIC_COMANDS_BLOCKED 0
49577- atomic_t num_rsrc_err;
49578- atomic_t num_cmd_success;
49579+ atomic_unchecked_t num_rsrc_err;
49580+ atomic_unchecked_t num_cmd_success;
49581 unsigned long last_rsrc_error_time;
49582 unsigned long last_ramp_down_time;
49583 unsigned long last_ramp_up_time;
49584@@ -902,7 +902,7 @@ struct lpfc_hba {
49585
49586 struct dentry *debug_slow_ring_trc;
49587 struct lpfc_debugfs_trc *slow_ring_trc;
49588- atomic_t slow_ring_trc_cnt;
49589+ atomic_unchecked_t slow_ring_trc_cnt;
49590 /* iDiag debugfs sub-directory */
49591 struct dentry *idiag_root;
49592 struct dentry *idiag_pci_cfg;
49593diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49594index b800cc9..16b6a91 100644
49595--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49596+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49597@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49598
49599 #include <linux/debugfs.h>
49600
49601-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49602+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49603 static unsigned long lpfc_debugfs_start_time = 0L;
49604
49605 /* iDiag */
49606@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49607 lpfc_debugfs_enable = 0;
49608
49609 len = 0;
49610- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49611+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49612 (lpfc_debugfs_max_disc_trc - 1);
49613 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49614 dtp = vport->disc_trc + i;
49615@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49616 lpfc_debugfs_enable = 0;
49617
49618 len = 0;
49619- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49620+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49621 (lpfc_debugfs_max_slow_ring_trc - 1);
49622 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49623 dtp = phba->slow_ring_trc + i;
49624@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49625 !vport || !vport->disc_trc)
49626 return;
49627
49628- index = atomic_inc_return(&vport->disc_trc_cnt) &
49629+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49630 (lpfc_debugfs_max_disc_trc - 1);
49631 dtp = vport->disc_trc + index;
49632 dtp->fmt = fmt;
49633 dtp->data1 = data1;
49634 dtp->data2 = data2;
49635 dtp->data3 = data3;
49636- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49637+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49638 dtp->jif = jiffies;
49639 #endif
49640 return;
49641@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49642 !phba || !phba->slow_ring_trc)
49643 return;
49644
49645- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49646+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49647 (lpfc_debugfs_max_slow_ring_trc - 1);
49648 dtp = phba->slow_ring_trc + index;
49649 dtp->fmt = fmt;
49650 dtp->data1 = data1;
49651 dtp->data2 = data2;
49652 dtp->data3 = data3;
49653- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49654+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49655 dtp->jif = jiffies;
49656 #endif
49657 return;
49658@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49659 "slow_ring buffer\n");
49660 goto debug_failed;
49661 }
49662- atomic_set(&phba->slow_ring_trc_cnt, 0);
49663+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49664 memset(phba->slow_ring_trc, 0,
49665 (sizeof(struct lpfc_debugfs_trc) *
49666 lpfc_debugfs_max_slow_ring_trc));
49667@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49668 "buffer\n");
49669 goto debug_failed;
49670 }
49671- atomic_set(&vport->disc_trc_cnt, 0);
49672+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49673
49674 snprintf(name, sizeof(name), "discovery_trace");
49675 vport->debug_disc_trc =
49676diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49677index 68c94cc..8c27be5 100644
49678--- a/drivers/scsi/lpfc/lpfc_init.c
49679+++ b/drivers/scsi/lpfc/lpfc_init.c
49680@@ -10949,8 +10949,10 @@ lpfc_init(void)
49681 "misc_register returned with status %d", error);
49682
49683 if (lpfc_enable_npiv) {
49684- lpfc_transport_functions.vport_create = lpfc_vport_create;
49685- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49686+ pax_open_kernel();
49687+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49688+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49689+ pax_close_kernel();
49690 }
49691 lpfc_transport_template =
49692 fc_attach_transport(&lpfc_transport_functions);
49693diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49694index b2ede05..aaf482ca 100644
49695--- a/drivers/scsi/lpfc/lpfc_scsi.c
49696+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49697@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49698 uint32_t evt_posted;
49699
49700 spin_lock_irqsave(&phba->hbalock, flags);
49701- atomic_inc(&phba->num_rsrc_err);
49702+ atomic_inc_unchecked(&phba->num_rsrc_err);
49703 phba->last_rsrc_error_time = jiffies;
49704
49705 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49706@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49707 unsigned long flags;
49708 struct lpfc_hba *phba = vport->phba;
49709 uint32_t evt_posted;
49710- atomic_inc(&phba->num_cmd_success);
49711+ atomic_inc_unchecked(&phba->num_cmd_success);
49712
49713 if (vport->cfg_lun_queue_depth <= queue_depth)
49714 return;
49715@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49716 unsigned long num_rsrc_err, num_cmd_success;
49717 int i;
49718
49719- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49720- num_cmd_success = atomic_read(&phba->num_cmd_success);
49721+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49722+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49723
49724 /*
49725 * The error and success command counters are global per
49726@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49727 }
49728 }
49729 lpfc_destroy_vport_work_array(phba, vports);
49730- atomic_set(&phba->num_rsrc_err, 0);
49731- atomic_set(&phba->num_cmd_success, 0);
49732+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49733+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49734 }
49735
49736 /**
49737@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49738 }
49739 }
49740 lpfc_destroy_vport_work_array(phba, vports);
49741- atomic_set(&phba->num_rsrc_err, 0);
49742- atomic_set(&phba->num_cmd_success, 0);
49743+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49744+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49745 }
49746
49747 /**
49748diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49749index 6fd7d40..b444223 100644
49750--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49751+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49752@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49753 {
49754 struct scsi_device *sdev = to_scsi_device(dev);
49755 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49756- static struct _raid_device *raid_device;
49757+ struct _raid_device *raid_device;
49758 unsigned long flags;
49759 Mpi2RaidVolPage0_t vol_pg0;
49760 Mpi2ConfigReply_t mpi_reply;
49761@@ -1609,7 +1609,7 @@ _scsih_get_state(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@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49771 struct fw_event_work *fw_event)
49772 {
49773 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49774- static struct _raid_device *raid_device;
49775+ struct _raid_device *raid_device;
49776 unsigned long flags;
49777 u16 handle;
49778
49779@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49780 u64 sas_address;
49781 struct _sas_device *sas_device;
49782 struct _sas_node *expander_device;
49783- static struct _raid_device *raid_device;
49784+ struct _raid_device *raid_device;
49785 u8 retry_count;
49786 unsigned long flags;
49787
49788diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49789index be8ce54..94ed33a 100644
49790--- a/drivers/scsi/pmcraid.c
49791+++ b/drivers/scsi/pmcraid.c
49792@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49793 res->scsi_dev = scsi_dev;
49794 scsi_dev->hostdata = res;
49795 res->change_detected = 0;
49796- atomic_set(&res->read_failures, 0);
49797- atomic_set(&res->write_failures, 0);
49798+ atomic_set_unchecked(&res->read_failures, 0);
49799+ atomic_set_unchecked(&res->write_failures, 0);
49800 rc = 0;
49801 }
49802 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49803@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49804
49805 /* If this was a SCSI read/write command keep count of errors */
49806 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49807- atomic_inc(&res->read_failures);
49808+ atomic_inc_unchecked(&res->read_failures);
49809 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49810- atomic_inc(&res->write_failures);
49811+ atomic_inc_unchecked(&res->write_failures);
49812
49813 if (!RES_IS_GSCSI(res->cfg_entry) &&
49814 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49815@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49816 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49817 * hrrq_id assigned here in queuecommand
49818 */
49819- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49820+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49821 pinstance->num_hrrq;
49822 cmd->cmd_done = pmcraid_io_done;
49823
49824@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
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
49832 if (request_size) {
49833@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49834
49835 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49836 /* add resources only after host is added into system */
49837- if (!atomic_read(&pinstance->expose_resources))
49838+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49839 return;
49840
49841 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49842@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49843 init_waitqueue_head(&pinstance->reset_wait_q);
49844
49845 atomic_set(&pinstance->outstanding_cmds, 0);
49846- atomic_set(&pinstance->last_message_id, 0);
49847- atomic_set(&pinstance->expose_resources, 0);
49848+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49849+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49850
49851 INIT_LIST_HEAD(&pinstance->free_res_q);
49852 INIT_LIST_HEAD(&pinstance->used_res_q);
49853@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49854 /* Schedule worker thread to handle CCN and take care of adding and
49855 * removing devices to OS
49856 */
49857- atomic_set(&pinstance->expose_resources, 1);
49858+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49859 schedule_work(&pinstance->worker_q);
49860 return rc;
49861
49862diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49863index e1d150f..6c6df44 100644
49864--- a/drivers/scsi/pmcraid.h
49865+++ b/drivers/scsi/pmcraid.h
49866@@ -748,7 +748,7 @@ struct pmcraid_instance {
49867 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49868
49869 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49870- atomic_t last_message_id;
49871+ atomic_unchecked_t last_message_id;
49872
49873 /* configuration table */
49874 struct pmcraid_config_table *cfg_table;
49875@@ -777,7 +777,7 @@ struct pmcraid_instance {
49876 atomic_t outstanding_cmds;
49877
49878 /* should add/delete resources to mid-layer now ?*/
49879- atomic_t expose_resources;
49880+ atomic_unchecked_t expose_resources;
49881
49882
49883
49884@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49885 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49886 };
49887 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49888- atomic_t read_failures; /* count of failed READ commands */
49889- atomic_t write_failures; /* count of failed WRITE commands */
49890+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49891+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49892
49893 /* To indicate add/delete/modify during CCN */
49894 u8 change_detected;
49895diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49896index 4a0d7c9..3d658d7 100644
49897--- a/drivers/scsi/qla2xxx/qla_attr.c
49898+++ b/drivers/scsi/qla2xxx/qla_attr.c
49899@@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49900 return 0;
49901 }
49902
49903-struct fc_function_template qla2xxx_transport_functions = {
49904+fc_function_template_no_const qla2xxx_transport_functions = {
49905
49906 .show_host_node_name = 1,
49907 .show_host_port_name = 1,
49908@@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49909 .bsg_timeout = qla24xx_bsg_timeout,
49910 };
49911
49912-struct fc_function_template qla2xxx_transport_vport_functions = {
49913+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49914
49915 .show_host_node_name = 1,
49916 .show_host_port_name = 1,
49917diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49918index 1f42662..bf9836c 100644
49919--- a/drivers/scsi/qla2xxx/qla_gbl.h
49920+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49921@@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49922 struct device_attribute;
49923 extern struct device_attribute *qla2x00_host_attrs[];
49924 struct fc_function_template;
49925-extern struct fc_function_template qla2xxx_transport_functions;
49926-extern struct fc_function_template qla2xxx_transport_vport_functions;
49927+extern fc_function_template_no_const qla2xxx_transport_functions;
49928+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49929 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49930 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49931 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49932diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49933index 83cb612..9b7b08c 100644
49934--- a/drivers/scsi/qla2xxx/qla_os.c
49935+++ b/drivers/scsi/qla2xxx/qla_os.c
49936@@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49937 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49938 /* Ok, a 64bit DMA mask is applicable. */
49939 ha->flags.enable_64bit_addressing = 1;
49940- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49941- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49942+ pax_open_kernel();
49943+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49944+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49945+ pax_close_kernel();
49946 return;
49947 }
49948 }
49949diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49950index aa67bb9..06d0e2a 100644
49951--- a/drivers/scsi/qla4xxx/ql4_def.h
49952+++ b/drivers/scsi/qla4xxx/ql4_def.h
49953@@ -303,7 +303,7 @@ struct ddb_entry {
49954 * (4000 only) */
49955 atomic_t relogin_timer; /* Max Time to wait for
49956 * relogin to complete */
49957- atomic_t relogin_retry_count; /* Num of times relogin has been
49958+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49959 * retried */
49960 uint32_t default_time2wait; /* Default Min time between
49961 * relogins (+aens) */
49962diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49963index c21adc3..1b4155f 100644
49964--- a/drivers/scsi/qla4xxx/ql4_os.c
49965+++ b/drivers/scsi/qla4xxx/ql4_os.c
49966@@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49967 */
49968 if (!iscsi_is_session_online(cls_sess)) {
49969 /* Reset retry relogin timer */
49970- atomic_inc(&ddb_entry->relogin_retry_count);
49971+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49972 DEBUG2(ql4_printk(KERN_INFO, ha,
49973 "%s: index[%d] relogin timed out-retrying"
49974 " relogin (%d), retry (%d)\n", __func__,
49975 ddb_entry->fw_ddb_index,
49976- atomic_read(&ddb_entry->relogin_retry_count),
49977+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49978 ddb_entry->default_time2wait + 4));
49979 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49980 atomic_set(&ddb_entry->retry_relogin_timer,
49981@@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49982
49983 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49984 atomic_set(&ddb_entry->relogin_timer, 0);
49985- atomic_set(&ddb_entry->relogin_retry_count, 0);
49986+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49987 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49988 ddb_entry->default_relogin_timeout =
49989 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49990diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49991index d8afec8..3ec7152 100644
49992--- a/drivers/scsi/scsi.c
49993+++ b/drivers/scsi/scsi.c
49994@@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49995 struct Scsi_Host *host = cmd->device->host;
49996 int rtn = 0;
49997
49998- atomic_inc(&cmd->device->iorequest_cnt);
49999+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
50000
50001 /* check if the device is still usable */
50002 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
50003diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
50004index 62ec84b..93159d8 100644
50005--- a/drivers/scsi/scsi_lib.c
50006+++ b/drivers/scsi/scsi_lib.c
50007@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
50008 shost = sdev->host;
50009 scsi_init_cmd_errh(cmd);
50010 cmd->result = DID_NO_CONNECT << 16;
50011- atomic_inc(&cmd->device->iorequest_cnt);
50012+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
50013
50014 /*
50015 * SCSI request completion path will do scsi_device_unbusy(),
50016@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
50017
50018 INIT_LIST_HEAD(&cmd->eh_entry);
50019
50020- atomic_inc(&cmd->device->iodone_cnt);
50021+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
50022 if (cmd->result)
50023- atomic_inc(&cmd->device->ioerr_cnt);
50024+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
50025
50026 disposition = scsi_decide_disposition(cmd);
50027 if (disposition != SUCCESS &&
50028diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
50029index 9117d0b..d289a7a 100644
50030--- a/drivers/scsi/scsi_sysfs.c
50031+++ b/drivers/scsi/scsi_sysfs.c
50032@@ -739,7 +739,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
50033 char *buf) \
50034 { \
50035 struct scsi_device *sdev = to_scsi_device(dev); \
50036- unsigned long long count = atomic_read(&sdev->field); \
50037+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
50038 return snprintf(buf, 20, "0x%llx\n", count); \
50039 } \
50040 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
50041diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
50042index 84a1fdf..693b0d6 100644
50043--- a/drivers/scsi/scsi_tgt_lib.c
50044+++ b/drivers/scsi/scsi_tgt_lib.c
50045@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
50046 int err;
50047
50048 dprintk("%lx %u\n", uaddr, len);
50049- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
50050+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
50051 if (err) {
50052 /*
50053 * TODO: need to fixup sg_tablesize, max_segment_size,
50054diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
50055index 4628fd5..a94a1c2 100644
50056--- a/drivers/scsi/scsi_transport_fc.c
50057+++ b/drivers/scsi/scsi_transport_fc.c
50058@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
50059 * Netlink Infrastructure
50060 */
50061
50062-static atomic_t fc_event_seq;
50063+static atomic_unchecked_t fc_event_seq;
50064
50065 /**
50066 * fc_get_event_number - Obtain the next sequential FC event number
50067@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
50068 u32
50069 fc_get_event_number(void)
50070 {
50071- return atomic_add_return(1, &fc_event_seq);
50072+ return atomic_add_return_unchecked(1, &fc_event_seq);
50073 }
50074 EXPORT_SYMBOL(fc_get_event_number);
50075
50076@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
50077 {
50078 int error;
50079
50080- atomic_set(&fc_event_seq, 0);
50081+ atomic_set_unchecked(&fc_event_seq, 0);
50082
50083 error = transport_class_register(&fc_host_class);
50084 if (error)
50085@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
50086 char *cp;
50087
50088 *val = simple_strtoul(buf, &cp, 0);
50089- if ((*cp && (*cp != '\n')) || (*val < 0))
50090+ if (*cp && (*cp != '\n'))
50091 return -EINVAL;
50092 /*
50093 * Check for overflow; dev_loss_tmo is u32
50094diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
50095index fd8ffe6..fd0bebf 100644
50096--- a/drivers/scsi/scsi_transport_iscsi.c
50097+++ b/drivers/scsi/scsi_transport_iscsi.c
50098@@ -79,7 +79,7 @@ struct iscsi_internal {
50099 struct transport_container session_cont;
50100 };
50101
50102-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
50103+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
50104 static struct workqueue_struct *iscsi_eh_timer_workq;
50105
50106 static DEFINE_IDA(iscsi_sess_ida);
50107@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
50108 int err;
50109
50110 ihost = shost->shost_data;
50111- session->sid = atomic_add_return(1, &iscsi_session_nr);
50112+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
50113
50114 if (target_id == ISCSI_MAX_TARGET) {
50115 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
50116@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
50117 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
50118 ISCSI_TRANSPORT_VERSION);
50119
50120- atomic_set(&iscsi_session_nr, 0);
50121+ atomic_set_unchecked(&iscsi_session_nr, 0);
50122
50123 err = class_register(&iscsi_transport_class);
50124 if (err)
50125diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
50126index d47ffc8..30f46a9 100644
50127--- a/drivers/scsi/scsi_transport_srp.c
50128+++ b/drivers/scsi/scsi_transport_srp.c
50129@@ -36,7 +36,7 @@
50130 #include "scsi_transport_srp_internal.h"
50131
50132 struct srp_host_attrs {
50133- atomic_t next_port_id;
50134+ atomic_unchecked_t next_port_id;
50135 };
50136 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
50137
50138@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
50139 struct Scsi_Host *shost = dev_to_shost(dev);
50140 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
50141
50142- atomic_set(&srp_host->next_port_id, 0);
50143+ atomic_set_unchecked(&srp_host->next_port_id, 0);
50144 return 0;
50145 }
50146
50147@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
50148 rport_fast_io_fail_timedout);
50149 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
50150
50151- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
50152+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
50153 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
50154
50155 transport_setup_device(&rport->dev);
50156diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
50157index 36d1a23..3f33303 100644
50158--- a/drivers/scsi/sd.c
50159+++ b/drivers/scsi/sd.c
50160@@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
50161 sdkp->disk = gd;
50162 sdkp->index = index;
50163 atomic_set(&sdkp->openers, 0);
50164- atomic_set(&sdkp->device->ioerr_cnt, 0);
50165+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
50166
50167 if (!sdp->request_queue->rq_timeout) {
50168 if (sdp->type != TYPE_MOD)
50169diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
50170index df5e961..df6b97f 100644
50171--- a/drivers/scsi/sg.c
50172+++ b/drivers/scsi/sg.c
50173@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
50174 sdp->disk->disk_name,
50175 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
50176 NULL,
50177- (char *)arg);
50178+ (char __user *)arg);
50179 case BLKTRACESTART:
50180 return blk_trace_startstop(sdp->device->request_queue, 1);
50181 case BLKTRACESTOP:
50182diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
50183index d0b28bb..a263613 100644
50184--- a/drivers/spi/spi.c
50185+++ b/drivers/spi/spi.c
50186@@ -1971,7 +1971,7 @@ int spi_bus_unlock(struct spi_master *master)
50187 EXPORT_SYMBOL_GPL(spi_bus_unlock);
50188
50189 /* portable code must never pass more than 32 bytes */
50190-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
50191+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
50192
50193 static u8 *buf;
50194
50195diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
50196index 2c61783..4d49e4e 100644
50197--- a/drivers/staging/android/timed_output.c
50198+++ b/drivers/staging/android/timed_output.c
50199@@ -25,7 +25,7 @@
50200 #include "timed_output.h"
50201
50202 static struct class *timed_output_class;
50203-static atomic_t device_count;
50204+static atomic_unchecked_t device_count;
50205
50206 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
50207 char *buf)
50208@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
50209 timed_output_class = class_create(THIS_MODULE, "timed_output");
50210 if (IS_ERR(timed_output_class))
50211 return PTR_ERR(timed_output_class);
50212- atomic_set(&device_count, 0);
50213+ atomic_set_unchecked(&device_count, 0);
50214 timed_output_class->dev_groups = timed_output_groups;
50215 }
50216
50217@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
50218 if (ret < 0)
50219 return ret;
50220
50221- tdev->index = atomic_inc_return(&device_count);
50222+ tdev->index = atomic_inc_return_unchecked(&device_count);
50223 tdev->dev = device_create(timed_output_class, NULL,
50224 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
50225 if (IS_ERR(tdev->dev))
50226diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
50227index fe47cd3..19a1bd1 100644
50228--- a/drivers/staging/gdm724x/gdm_tty.c
50229+++ b/drivers/staging/gdm724x/gdm_tty.c
50230@@ -44,7 +44,7 @@
50231 #define gdm_tty_send_control(n, r, v, d, l) (\
50232 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
50233
50234-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
50235+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
50236
50237 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
50238 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
50239diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
50240index 236ed66..dd9cd74 100644
50241--- a/drivers/staging/imx-drm/imx-drm-core.c
50242+++ b/drivers/staging/imx-drm/imx-drm-core.c
50243@@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
50244 goto err_busy;
50245 }
50246
50247- if (imxdrm->drm->open_count) {
50248+ if (local_read(&imxdrm->drm->open_count)) {
50249 ret = -EBUSY;
50250 goto err_busy;
50251 }
50252@@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
50253
50254 mutex_lock(&imxdrm->mutex);
50255
50256- if (imxdrm->drm->open_count) {
50257+ if (local_read(&imxdrm->drm->open_count)) {
50258 ret = -EBUSY;
50259 goto err_busy;
50260 }
50261@@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
50262
50263 mutex_lock(&imxdrm->mutex);
50264
50265- if (imxdrm->drm->open_count) {
50266+ if (local_read(&imxdrm->drm->open_count)) {
50267 ret = -EBUSY;
50268 goto err_busy;
50269 }
50270diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
50271index 3f8020c..649fded 100644
50272--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
50273+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
50274@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
50275 return 0;
50276 }
50277
50278-sfw_test_client_ops_t brw_test_client;
50279-void brw_init_test_client(void)
50280-{
50281- brw_test_client.tso_init = brw_client_init;
50282- brw_test_client.tso_fini = brw_client_fini;
50283- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
50284- brw_test_client.tso_done_rpc = brw_client_done_rpc;
50285+sfw_test_client_ops_t brw_test_client = {
50286+ .tso_init = brw_client_init,
50287+ .tso_fini = brw_client_fini,
50288+ .tso_prep_rpc = brw_client_prep_rpc,
50289+ .tso_done_rpc = brw_client_done_rpc,
50290 };
50291
50292 srpc_service_t brw_test_service;
50293diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
50294index 050723a..fa6fdf1 100644
50295--- a/drivers/staging/lustre/lnet/selftest/framework.c
50296+++ b/drivers/staging/lustre/lnet/selftest/framework.c
50297@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
50298
50299 extern sfw_test_client_ops_t ping_test_client;
50300 extern srpc_service_t ping_test_service;
50301-extern void ping_init_test_client(void);
50302 extern void ping_init_test_service(void);
50303
50304 extern sfw_test_client_ops_t brw_test_client;
50305 extern srpc_service_t brw_test_service;
50306-extern void brw_init_test_client(void);
50307 extern void brw_init_test_service(void);
50308
50309
50310@@ -1684,12 +1682,10 @@ sfw_startup (void)
50311 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
50312 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
50313
50314- brw_init_test_client();
50315 brw_init_test_service();
50316 rc = sfw_register_test(&brw_test_service, &brw_test_client);
50317 LASSERT (rc == 0);
50318
50319- ping_init_test_client();
50320 ping_init_test_service();
50321 rc = sfw_register_test(&ping_test_service, &ping_test_client);
50322 LASSERT (rc == 0);
50323diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
50324index 750cac4..e4d751f 100644
50325--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
50326+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
50327@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
50328 return 0;
50329 }
50330
50331-sfw_test_client_ops_t ping_test_client;
50332-void ping_init_test_client(void)
50333-{
50334- ping_test_client.tso_init = ping_client_init;
50335- ping_test_client.tso_fini = ping_client_fini;
50336- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
50337- ping_test_client.tso_done_rpc = ping_client_done_rpc;
50338-}
50339+sfw_test_client_ops_t ping_test_client = {
50340+ .tso_init = ping_client_init,
50341+ .tso_fini = ping_client_fini,
50342+ .tso_prep_rpc = ping_client_prep_rpc,
50343+ .tso_done_rpc = ping_client_done_rpc,
50344+};
50345
50346 srpc_service_t ping_test_service;
50347 void ping_init_test_service(void)
50348diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50349index ec4bb5e..740c6dd 100644
50350--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
50351+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50352@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
50353 ldlm_completion_callback lcs_completion;
50354 ldlm_blocking_callback lcs_blocking;
50355 ldlm_glimpse_callback lcs_glimpse;
50356-};
50357+} __no_const;
50358
50359 /* ldlm_lockd.c */
50360 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
50361diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
50362index c3470ce..2bef527 100644
50363--- a/drivers/staging/lustre/lustre/include/obd.h
50364+++ b/drivers/staging/lustre/lustre/include/obd.h
50365@@ -1426,7 +1426,7 @@ struct md_ops {
50366 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
50367 * wrapper function in include/linux/obd_class.h.
50368 */
50369-};
50370+} __no_const;
50371
50372 struct lsm_operations {
50373 void (*lsm_free)(struct lov_stripe_md *);
50374diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50375index c9aae13..60ea292 100644
50376--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50377+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50378@@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
50379 int added = (mode == LCK_NL);
50380 int overlaps = 0;
50381 int splitted = 0;
50382- const struct ldlm_callback_suite null_cbs = { NULL };
50383+ const struct ldlm_callback_suite null_cbs = { };
50384
50385 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
50386 LPU64" end "LPU64"\n", *flags,
50387diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50388index e947b91..f408990 100644
50389--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50390+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50391@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
50392 int LL_PROC_PROTO(proc_console_max_delay_cs)
50393 {
50394 int rc, max_delay_cs;
50395- ctl_table_t dummy = *table;
50396+ ctl_table_no_const dummy = *table;
50397 cfs_duration_t d;
50398
50399 dummy.data = &max_delay_cs;
50400@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
50401 int LL_PROC_PROTO(proc_console_min_delay_cs)
50402 {
50403 int rc, min_delay_cs;
50404- ctl_table_t dummy = *table;
50405+ ctl_table_no_const dummy = *table;
50406 cfs_duration_t d;
50407
50408 dummy.data = &min_delay_cs;
50409@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
50410 int LL_PROC_PROTO(proc_console_backoff)
50411 {
50412 int rc, backoff;
50413- ctl_table_t dummy = *table;
50414+ ctl_table_no_const dummy = *table;
50415
50416 dummy.data = &backoff;
50417 dummy.proc_handler = &proc_dointvec;
50418diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
50419index 24ae26d..9d09cab 100644
50420--- a/drivers/staging/lustre/lustre/libcfs/module.c
50421+++ b/drivers/staging/lustre/lustre/libcfs/module.c
50422@@ -313,11 +313,11 @@ out:
50423
50424
50425 struct cfs_psdev_ops libcfs_psdev_ops = {
50426- libcfs_psdev_open,
50427- libcfs_psdev_release,
50428- NULL,
50429- NULL,
50430- libcfs_ioctl
50431+ .p_open = libcfs_psdev_open,
50432+ .p_close = libcfs_psdev_release,
50433+ .p_read = NULL,
50434+ .p_write = NULL,
50435+ .p_ioctl = libcfs_ioctl
50436 };
50437
50438 extern int insert_proc(void);
50439diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50440index 52b7731..d604da0 100644
50441--- a/drivers/staging/lustre/lustre/llite/dir.c
50442+++ b/drivers/staging/lustre/lustre/llite/dir.c
50443@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50444 int mode;
50445 int err;
50446
50447- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50448+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50449 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50450 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50451 lump);
50452diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50453index 480b7c4..6846324 100644
50454--- a/drivers/staging/media/solo6x10/solo6x10-core.c
50455+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50456@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50457
50458 static int solo_sysfs_init(struct solo_dev *solo_dev)
50459 {
50460- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50461+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50462 struct device *dev = &solo_dev->dev;
50463 const char *driver;
50464 int i;
50465diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50466index 1db18c7..35e6afc 100644
50467--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50468+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50469@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50470
50471 int solo_g723_init(struct solo_dev *solo_dev)
50472 {
50473- static struct snd_device_ops ops = { NULL };
50474+ static struct snd_device_ops ops = { };
50475 struct snd_card *card;
50476 struct snd_kcontrol_new kctl;
50477 char name[32];
50478diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50479index 7f2f247..d999137 100644
50480--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50481+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50482@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50483
50484 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50485 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50486- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50487+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50488 if (p2m_id < 0)
50489 p2m_id = -p2m_id;
50490 }
50491diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50492index 8964f8b..36eb087 100644
50493--- a/drivers/staging/media/solo6x10/solo6x10.h
50494+++ b/drivers/staging/media/solo6x10/solo6x10.h
50495@@ -237,7 +237,7 @@ struct solo_dev {
50496
50497 /* P2M DMA Engine */
50498 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50499- atomic_t p2m_count;
50500+ atomic_unchecked_t p2m_count;
50501 int p2m_jiffies;
50502 unsigned int p2m_timeouts;
50503
50504diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50505index a0f4868..139f1fb 100644
50506--- a/drivers/staging/octeon/ethernet-rx.c
50507+++ b/drivers/staging/octeon/ethernet-rx.c
50508@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50509 /* Increment RX stats for virtual ports */
50510 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50511 #ifdef CONFIG_64BIT
50512- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50513- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50514+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50515+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50516 #else
50517- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50518- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50519+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50520+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50521 #endif
50522 }
50523 netif_receive_skb(skb);
50524@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50525 dev->name);
50526 */
50527 #ifdef CONFIG_64BIT
50528- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50529+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50530 #else
50531- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50532+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50533 #endif
50534 dev_kfree_skb_irq(skb);
50535 }
50536diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50537index 089dc4b..c9a687e 100644
50538--- a/drivers/staging/octeon/ethernet.c
50539+++ b/drivers/staging/octeon/ethernet.c
50540@@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50541 * since the RX tasklet also increments it.
50542 */
50543 #ifdef CONFIG_64BIT
50544- atomic64_add(rx_status.dropped_packets,
50545- (atomic64_t *)&priv->stats.rx_dropped);
50546+ atomic64_add_unchecked(rx_status.dropped_packets,
50547+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50548 #else
50549- atomic_add(rx_status.dropped_packets,
50550- (atomic_t *)&priv->stats.rx_dropped);
50551+ atomic_add_unchecked(rx_status.dropped_packets,
50552+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
50553 #endif
50554 }
50555
50556diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50557index c274b34..f84de76 100644
50558--- a/drivers/staging/rtl8188eu/include/hal_intf.h
50559+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50560@@ -271,7 +271,7 @@ struct hal_ops {
50561 s32 (*c2h_handler)(struct adapter *padapter,
50562 struct c2h_evt_hdr *c2h_evt);
50563 c2h_id_filter c2h_id_filter_ccx;
50564-};
50565+} __no_const;
50566
50567 enum rt_eeprom_type {
50568 EEPROM_93C46,
50569diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50570index 3d1dfcc..ff5620a 100644
50571--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50572+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50573@@ -126,7 +126,7 @@ struct _io_ops {
50574 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50575 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50576 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50577-};
50578+} __no_const;
50579
50580 struct io_req {
50581 struct list_head list;
50582diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50583index dc23395..cf7e9b1 100644
50584--- a/drivers/staging/rtl8712/rtl871x_io.h
50585+++ b/drivers/staging/rtl8712/rtl871x_io.h
50586@@ -108,7 +108,7 @@ struct _io_ops {
50587 u8 *pmem);
50588 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50589 u8 *pmem);
50590-};
50591+} __no_const;
50592
50593 struct io_req {
50594 struct list_head list;
50595diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50596index 1f5088b..0e59820 100644
50597--- a/drivers/staging/sbe-2t3e3/netdev.c
50598+++ b/drivers/staging/sbe-2t3e3/netdev.c
50599@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50600 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50601
50602 if (rlen)
50603- if (copy_to_user(data, &resp, rlen))
50604+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50605 return -EFAULT;
50606
50607 return 0;
50608diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50609index a863a98..d272795 100644
50610--- a/drivers/staging/usbip/vhci.h
50611+++ b/drivers/staging/usbip/vhci.h
50612@@ -83,7 +83,7 @@ struct vhci_hcd {
50613 unsigned resuming:1;
50614 unsigned long re_timeout;
50615
50616- atomic_t seqnum;
50617+ atomic_unchecked_t seqnum;
50618
50619 /*
50620 * NOTE:
50621diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50622index 72391ef..7c6717a 100644
50623--- a/drivers/staging/usbip/vhci_hcd.c
50624+++ b/drivers/staging/usbip/vhci_hcd.c
50625@@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
50626
50627 spin_lock(&vdev->priv_lock);
50628
50629- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50630+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50631 if (priv->seqnum == 0xffff)
50632 dev_info(&urb->dev->dev, "seqnum max\n");
50633
50634@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50635 return -ENOMEM;
50636 }
50637
50638- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50639+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50640 if (unlink->seqnum == 0xffff)
50641 pr_info("seqnum max\n");
50642
50643@@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
50644 vdev->rhport = rhport;
50645 }
50646
50647- atomic_set(&vhci->seqnum, 0);
50648+ atomic_set_unchecked(&vhci->seqnum, 0);
50649 spin_lock_init(&vhci->lock);
50650
50651 hcd->power_budget = 0; /* no limit */
50652diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50653index d07fcb5..358e1e1 100644
50654--- a/drivers/staging/usbip/vhci_rx.c
50655+++ b/drivers/staging/usbip/vhci_rx.c
50656@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50657 if (!urb) {
50658 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50659 pr_info("max seqnum %d\n",
50660- atomic_read(&the_controller->seqnum));
50661+ atomic_read_unchecked(&the_controller->seqnum));
50662 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50663 return;
50664 }
50665diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50666index 6eecd53..29317c6 100644
50667--- a/drivers/staging/vt6655/hostap.c
50668+++ b/drivers/staging/vt6655/hostap.c
50669@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50670 *
50671 */
50672
50673+static net_device_ops_no_const apdev_netdev_ops;
50674+
50675 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50676 {
50677 PSDevice apdev_priv;
50678 struct net_device *dev = pDevice->dev;
50679 int ret;
50680- const struct net_device_ops apdev_netdev_ops = {
50681- .ndo_start_xmit = pDevice->tx_80211,
50682- };
50683
50684 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50685
50686@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50687 *apdev_priv = *pDevice;
50688 eth_hw_addr_inherit(pDevice->apdev, dev);
50689
50690+ /* only half broken now */
50691+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50692 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50693
50694 pDevice->apdev->type = ARPHRD_IEEE80211;
50695diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50696index 67ba48b..24e602f 100644
50697--- a/drivers/staging/vt6656/hostap.c
50698+++ b/drivers/staging/vt6656/hostap.c
50699@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50700 *
50701 */
50702
50703+static net_device_ops_no_const apdev_netdev_ops;
50704+
50705 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50706 {
50707 struct vnt_private *apdev_priv;
50708 struct net_device *dev = pDevice->dev;
50709 int ret;
50710- const struct net_device_ops apdev_netdev_ops = {
50711- .ndo_start_xmit = pDevice->tx_80211,
50712- };
50713
50714 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50715
50716@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50717 *apdev_priv = *pDevice;
50718 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50719
50720+ /* only half broken now */
50721+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50722 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50723
50724 pDevice->apdev->type = ARPHRD_IEEE80211;
50725diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50726index 24884ca..26c8220 100644
50727--- a/drivers/target/sbp/sbp_target.c
50728+++ b/drivers/target/sbp/sbp_target.c
50729@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50730
50731 #define SESSION_MAINTENANCE_INTERVAL HZ
50732
50733-static atomic_t login_id = ATOMIC_INIT(0);
50734+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50735
50736 static void session_maintenance_work(struct work_struct *);
50737 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50738@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50739 login->lun = se_lun;
50740 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50741 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50742- login->login_id = atomic_inc_return(&login_id);
50743+ login->login_id = atomic_inc_return_unchecked(&login_id);
50744
50745 login->tgt_agt = sbp_target_agent_register(login);
50746 if (IS_ERR(login->tgt_agt)) {
50747diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50748index 65001e1..2ebfbb9 100644
50749--- a/drivers/target/target_core_device.c
50750+++ b/drivers/target/target_core_device.c
50751@@ -1520,7 +1520,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50752 spin_lock_init(&dev->se_tmr_lock);
50753 spin_lock_init(&dev->qf_cmd_lock);
50754 sema_init(&dev->caw_sem, 1);
50755- atomic_set(&dev->dev_ordered_id, 0);
50756+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50757 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50758 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50759 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50760diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50761index 2956250..b10f722 100644
50762--- a/drivers/target/target_core_transport.c
50763+++ b/drivers/target/target_core_transport.c
50764@@ -1136,7 +1136,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50765 * Used to determine when ORDERED commands should go from
50766 * Dormant to Active status.
50767 */
50768- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50769+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50770 smp_mb__after_atomic_inc();
50771 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50772 cmd->se_ordered_id, cmd->sam_task_attr,
50773diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50774index 04b1be7..5eff86d 100644
50775--- a/drivers/thermal/of-thermal.c
50776+++ b/drivers/thermal/of-thermal.c
50777@@ -30,6 +30,7 @@
50778 #include <linux/err.h>
50779 #include <linux/export.h>
50780 #include <linux/string.h>
50781+#include <linux/mm.h>
50782
50783 #include "thermal_core.h"
50784
50785@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50786 tz->get_trend = get_trend;
50787 tz->sensor_data = data;
50788
50789- tzd->ops->get_temp = of_thermal_get_temp;
50790- tzd->ops->get_trend = of_thermal_get_trend;
50791+ pax_open_kernel();
50792+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50793+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50794+ pax_close_kernel();
50795 mutex_unlock(&tzd->lock);
50796
50797 return tzd;
50798@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50799 return;
50800
50801 mutex_lock(&tzd->lock);
50802- tzd->ops->get_temp = NULL;
50803- tzd->ops->get_trend = NULL;
50804+ pax_open_kernel();
50805+ *(void **)&tzd->ops->get_temp = NULL;
50806+ *(void **)&tzd->ops->get_trend = NULL;
50807+ pax_close_kernel();
50808
50809 tz->get_temp = NULL;
50810 tz->get_trend = NULL;
50811diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50812index a57bb5a..1f727d33 100644
50813--- a/drivers/tty/cyclades.c
50814+++ b/drivers/tty/cyclades.c
50815@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50816 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50817 info->port.count);
50818 #endif
50819- info->port.count++;
50820+ atomic_inc(&info->port.count);
50821 #ifdef CY_DEBUG_COUNT
50822 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50823- current->pid, info->port.count);
50824+ current->pid, atomic_read(&info->port.count));
50825 #endif
50826
50827 /*
50828@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50829 for (j = 0; j < cy_card[i].nports; j++) {
50830 info = &cy_card[i].ports[j];
50831
50832- if (info->port.count) {
50833+ if (atomic_read(&info->port.count)) {
50834 /* XXX is the ldisc num worth this? */
50835 struct tty_struct *tty;
50836 struct tty_ldisc *ld;
50837diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50838index 0ff7fda..dbc7d52 100644
50839--- a/drivers/tty/hvc/hvc_console.c
50840+++ b/drivers/tty/hvc/hvc_console.c
50841@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50842
50843 spin_lock_irqsave(&hp->port.lock, flags);
50844 /* Check and then increment for fast path open. */
50845- if (hp->port.count++ > 0) {
50846+ if (atomic_inc_return(&hp->port.count) > 1) {
50847 spin_unlock_irqrestore(&hp->port.lock, flags);
50848 hvc_kick();
50849 return 0;
50850@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50851
50852 spin_lock_irqsave(&hp->port.lock, flags);
50853
50854- if (--hp->port.count == 0) {
50855+ if (atomic_dec_return(&hp->port.count) == 0) {
50856 spin_unlock_irqrestore(&hp->port.lock, flags);
50857 /* We are done with the tty pointer now. */
50858 tty_port_tty_set(&hp->port, NULL);
50859@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50860 */
50861 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50862 } else {
50863- if (hp->port.count < 0)
50864+ if (atomic_read(&hp->port.count) < 0)
50865 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50866- hp->vtermno, hp->port.count);
50867+ hp->vtermno, atomic_read(&hp->port.count));
50868 spin_unlock_irqrestore(&hp->port.lock, flags);
50869 }
50870 }
50871@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50872 * open->hangup case this can be called after the final close so prevent
50873 * that from happening for now.
50874 */
50875- if (hp->port.count <= 0) {
50876+ if (atomic_read(&hp->port.count) <= 0) {
50877 spin_unlock_irqrestore(&hp->port.lock, flags);
50878 return;
50879 }
50880
50881- hp->port.count = 0;
50882+ atomic_set(&hp->port.count, 0);
50883 spin_unlock_irqrestore(&hp->port.lock, flags);
50884 tty_port_tty_set(&hp->port, NULL);
50885
50886@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50887 return -EPIPE;
50888
50889 /* FIXME what's this (unprotected) check for? */
50890- if (hp->port.count <= 0)
50891+ if (atomic_read(&hp->port.count) <= 0)
50892 return -EIO;
50893
50894 spin_lock_irqsave(&hp->lock, flags);
50895diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50896index 81e939e..95ead10 100644
50897--- a/drivers/tty/hvc/hvcs.c
50898+++ b/drivers/tty/hvc/hvcs.c
50899@@ -83,6 +83,7 @@
50900 #include <asm/hvcserver.h>
50901 #include <asm/uaccess.h>
50902 #include <asm/vio.h>
50903+#include <asm/local.h>
50904
50905 /*
50906 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50907@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50908
50909 spin_lock_irqsave(&hvcsd->lock, flags);
50910
50911- if (hvcsd->port.count > 0) {
50912+ if (atomic_read(&hvcsd->port.count) > 0) {
50913 spin_unlock_irqrestore(&hvcsd->lock, flags);
50914 printk(KERN_INFO "HVCS: vterm state unchanged. "
50915 "The hvcs device node is still in use.\n");
50916@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50917 }
50918 }
50919
50920- hvcsd->port.count = 0;
50921+ atomic_set(&hvcsd->port.count, 0);
50922 hvcsd->port.tty = tty;
50923 tty->driver_data = hvcsd;
50924
50925@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50926 unsigned long flags;
50927
50928 spin_lock_irqsave(&hvcsd->lock, flags);
50929- hvcsd->port.count++;
50930+ atomic_inc(&hvcsd->port.count);
50931 hvcsd->todo_mask |= HVCS_SCHED_READ;
50932 spin_unlock_irqrestore(&hvcsd->lock, flags);
50933
50934@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50935 hvcsd = tty->driver_data;
50936
50937 spin_lock_irqsave(&hvcsd->lock, flags);
50938- if (--hvcsd->port.count == 0) {
50939+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50940
50941 vio_disable_interrupts(hvcsd->vdev);
50942
50943@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50944
50945 free_irq(irq, hvcsd);
50946 return;
50947- } else if (hvcsd->port.count < 0) {
50948+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50949 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50950 " is missmanaged.\n",
50951- hvcsd->vdev->unit_address, hvcsd->port.count);
50952+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50953 }
50954
50955 spin_unlock_irqrestore(&hvcsd->lock, flags);
50956@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50957
50958 spin_lock_irqsave(&hvcsd->lock, flags);
50959 /* Preserve this so that we know how many kref refs to put */
50960- temp_open_count = hvcsd->port.count;
50961+ temp_open_count = atomic_read(&hvcsd->port.count);
50962
50963 /*
50964 * Don't kref put inside the spinlock because the destruction
50965@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50966 tty->driver_data = NULL;
50967 hvcsd->port.tty = NULL;
50968
50969- hvcsd->port.count = 0;
50970+ atomic_set(&hvcsd->port.count, 0);
50971
50972 /* This will drop any buffered data on the floor which is OK in a hangup
50973 * scenario. */
50974@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50975 * the middle of a write operation? This is a crummy place to do this
50976 * but we want to keep it all in the spinlock.
50977 */
50978- if (hvcsd->port.count <= 0) {
50979+ if (atomic_read(&hvcsd->port.count) <= 0) {
50980 spin_unlock_irqrestore(&hvcsd->lock, flags);
50981 return -ENODEV;
50982 }
50983@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50984 {
50985 struct hvcs_struct *hvcsd = tty->driver_data;
50986
50987- if (!hvcsd || hvcsd->port.count <= 0)
50988+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50989 return 0;
50990
50991 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50992diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50993index 4190199..06d5bfa 100644
50994--- a/drivers/tty/hvc/hvsi.c
50995+++ b/drivers/tty/hvc/hvsi.c
50996@@ -85,7 +85,7 @@ struct hvsi_struct {
50997 int n_outbuf;
50998 uint32_t vtermno;
50999 uint32_t virq;
51000- atomic_t seqno; /* HVSI packet sequence number */
51001+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
51002 uint16_t mctrl;
51003 uint8_t state; /* HVSI protocol state */
51004 uint8_t flags;
51005@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
51006
51007 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
51008 packet.hdr.len = sizeof(struct hvsi_query_response);
51009- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51010+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51011 packet.verb = VSV_SEND_VERSION_NUMBER;
51012 packet.u.version = HVSI_VERSION;
51013 packet.query_seqno = query_seqno+1;
51014@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
51015
51016 packet.hdr.type = VS_QUERY_PACKET_HEADER;
51017 packet.hdr.len = sizeof(struct hvsi_query);
51018- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51019+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51020 packet.verb = verb;
51021
51022 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
51023@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
51024 int wrote;
51025
51026 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
51027- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51028+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51029 packet.hdr.len = sizeof(struct hvsi_control);
51030 packet.verb = VSV_SET_MODEM_CTL;
51031 packet.mask = HVSI_TSDTR;
51032@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
51033 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
51034
51035 packet.hdr.type = VS_DATA_PACKET_HEADER;
51036- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51037+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51038 packet.hdr.len = count + sizeof(struct hvsi_header);
51039 memcpy(&packet.data, buf, count);
51040
51041@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
51042 struct hvsi_control packet __ALIGNED__;
51043
51044 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
51045- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51046+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51047 packet.hdr.len = 6;
51048 packet.verb = VSV_CLOSE_PROTOCOL;
51049
51050@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
51051
51052 tty_port_tty_set(&hp->port, tty);
51053 spin_lock_irqsave(&hp->lock, flags);
51054- hp->port.count++;
51055+ atomic_inc(&hp->port.count);
51056 atomic_set(&hp->seqno, 0);
51057 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
51058 spin_unlock_irqrestore(&hp->lock, flags);
51059@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51060
51061 spin_lock_irqsave(&hp->lock, flags);
51062
51063- if (--hp->port.count == 0) {
51064+ if (atomic_dec_return(&hp->port.count) == 0) {
51065 tty_port_tty_set(&hp->port, NULL);
51066 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
51067
51068@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51069
51070 spin_lock_irqsave(&hp->lock, flags);
51071 }
51072- } else if (hp->port.count < 0)
51073+ } else if (atomic_read(&hp->port.count) < 0)
51074 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
51075- hp - hvsi_ports, hp->port.count);
51076+ hp - hvsi_ports, atomic_read(&hp->port.count));
51077
51078 spin_unlock_irqrestore(&hp->lock, flags);
51079 }
51080@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
51081 tty_port_tty_set(&hp->port, NULL);
51082
51083 spin_lock_irqsave(&hp->lock, flags);
51084- hp->port.count = 0;
51085+ atomic_set(&hp->port.count, 0);
51086 hp->n_outbuf = 0;
51087 spin_unlock_irqrestore(&hp->lock, flags);
51088 }
51089diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
51090index 7ae6c29..05c6dba 100644
51091--- a/drivers/tty/hvc/hvsi_lib.c
51092+++ b/drivers/tty/hvc/hvsi_lib.c
51093@@ -8,7 +8,7 @@
51094
51095 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
51096 {
51097- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
51098+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
51099
51100 /* Assumes that always succeeds, works in practice */
51101 return pv->put_chars(pv->termno, (char *)packet, packet->len);
51102@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
51103
51104 /* Reset state */
51105 pv->established = 0;
51106- atomic_set(&pv->seqno, 0);
51107+ atomic_set_unchecked(&pv->seqno, 0);
51108
51109 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
51110
51111diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
51112index 17ee3bf..8d2520d 100644
51113--- a/drivers/tty/ipwireless/tty.c
51114+++ b/drivers/tty/ipwireless/tty.c
51115@@ -28,6 +28,7 @@
51116 #include <linux/tty_driver.h>
51117 #include <linux/tty_flip.h>
51118 #include <linux/uaccess.h>
51119+#include <asm/local.h>
51120
51121 #include "tty.h"
51122 #include "network.h"
51123@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51124 mutex_unlock(&tty->ipw_tty_mutex);
51125 return -ENODEV;
51126 }
51127- if (tty->port.count == 0)
51128+ if (atomic_read(&tty->port.count) == 0)
51129 tty->tx_bytes_queued = 0;
51130
51131- tty->port.count++;
51132+ atomic_inc(&tty->port.count);
51133
51134 tty->port.tty = linux_tty;
51135 linux_tty->driver_data = tty;
51136@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51137
51138 static void do_ipw_close(struct ipw_tty *tty)
51139 {
51140- tty->port.count--;
51141-
51142- if (tty->port.count == 0) {
51143+ if (atomic_dec_return(&tty->port.count) == 0) {
51144 struct tty_struct *linux_tty = tty->port.tty;
51145
51146 if (linux_tty != NULL) {
51147@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
51148 return;
51149
51150 mutex_lock(&tty->ipw_tty_mutex);
51151- if (tty->port.count == 0) {
51152+ if (atomic_read(&tty->port.count) == 0) {
51153 mutex_unlock(&tty->ipw_tty_mutex);
51154 return;
51155 }
51156@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
51157
51158 mutex_lock(&tty->ipw_tty_mutex);
51159
51160- if (!tty->port.count) {
51161+ if (!atomic_read(&tty->port.count)) {
51162 mutex_unlock(&tty->ipw_tty_mutex);
51163 return;
51164 }
51165@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
51166 return -ENODEV;
51167
51168 mutex_lock(&tty->ipw_tty_mutex);
51169- if (!tty->port.count) {
51170+ if (!atomic_read(&tty->port.count)) {
51171 mutex_unlock(&tty->ipw_tty_mutex);
51172 return -EINVAL;
51173 }
51174@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
51175 if (!tty)
51176 return -ENODEV;
51177
51178- if (!tty->port.count)
51179+ if (!atomic_read(&tty->port.count))
51180 return -EINVAL;
51181
51182 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
51183@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
51184 if (!tty)
51185 return 0;
51186
51187- if (!tty->port.count)
51188+ if (!atomic_read(&tty->port.count))
51189 return 0;
51190
51191 return tty->tx_bytes_queued;
51192@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
51193 if (!tty)
51194 return -ENODEV;
51195
51196- if (!tty->port.count)
51197+ if (!atomic_read(&tty->port.count))
51198 return -EINVAL;
51199
51200 return get_control_lines(tty);
51201@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
51202 if (!tty)
51203 return -ENODEV;
51204
51205- if (!tty->port.count)
51206+ if (!atomic_read(&tty->port.count))
51207 return -EINVAL;
51208
51209 return set_control_lines(tty, set, clear);
51210@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
51211 if (!tty)
51212 return -ENODEV;
51213
51214- if (!tty->port.count)
51215+ if (!atomic_read(&tty->port.count))
51216 return -EINVAL;
51217
51218 /* FIXME: Exactly how is the tty object locked here .. */
51219@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
51220 * are gone */
51221 mutex_lock(&ttyj->ipw_tty_mutex);
51222 }
51223- while (ttyj->port.count)
51224+ while (atomic_read(&ttyj->port.count))
51225 do_ipw_close(ttyj);
51226 ipwireless_disassociate_network_ttys(network,
51227 ttyj->channel_idx);
51228diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
51229index 1deaca4..c8582d4 100644
51230--- a/drivers/tty/moxa.c
51231+++ b/drivers/tty/moxa.c
51232@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
51233 }
51234
51235 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
51236- ch->port.count++;
51237+ atomic_inc(&ch->port.count);
51238 tty->driver_data = ch;
51239 tty_port_tty_set(&ch->port, tty);
51240 mutex_lock(&ch->port.mutex);
51241diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
51242index 2ebe47b..3205833 100644
51243--- a/drivers/tty/n_gsm.c
51244+++ b/drivers/tty/n_gsm.c
51245@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
51246 spin_lock_init(&dlci->lock);
51247 mutex_init(&dlci->mutex);
51248 dlci->fifo = &dlci->_fifo;
51249- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
51250+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
51251 kfree(dlci);
51252 return NULL;
51253 }
51254@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
51255 struct gsm_dlci *dlci = tty->driver_data;
51256 struct tty_port *port = &dlci->port;
51257
51258- port->count++;
51259+ atomic_inc(&port->count);
51260 tty_port_tty_set(port, tty);
51261
51262 dlci->modem_rx = 0;
51263diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
51264index e36d1f5..9938e3e 100644
51265--- a/drivers/tty/n_tty.c
51266+++ b/drivers/tty/n_tty.c
51267@@ -115,7 +115,7 @@ struct n_tty_data {
51268 int minimum_to_wake;
51269
51270 /* consumer-published */
51271- size_t read_tail;
51272+ size_t read_tail __intentional_overflow(-1);
51273 size_t line_start;
51274
51275 /* protected by output lock */
51276@@ -2519,6 +2519,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
51277 {
51278 *ops = tty_ldisc_N_TTY;
51279 ops->owner = NULL;
51280- ops->refcount = ops->flags = 0;
51281+ atomic_set(&ops->refcount, 0);
51282+ ops->flags = 0;
51283 }
51284 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
51285diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
51286index 25c9bc7..24077b7 100644
51287--- a/drivers/tty/pty.c
51288+++ b/drivers/tty/pty.c
51289@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
51290 panic("Couldn't register Unix98 pts driver");
51291
51292 /* Now create the /dev/ptmx special device */
51293+ pax_open_kernel();
51294 tty_default_fops(&ptmx_fops);
51295- ptmx_fops.open = ptmx_open;
51296+ *(void **)&ptmx_fops.open = ptmx_open;
51297+ pax_close_kernel();
51298
51299 cdev_init(&ptmx_cdev, &ptmx_fops);
51300 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
51301diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
51302index 383c4c7..d408e21 100644
51303--- a/drivers/tty/rocket.c
51304+++ b/drivers/tty/rocket.c
51305@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51306 tty->driver_data = info;
51307 tty_port_tty_set(port, tty);
51308
51309- if (port->count++ == 0) {
51310+ if (atomic_inc_return(&port->count) == 1) {
51311 atomic_inc(&rp_num_ports_open);
51312
51313 #ifdef ROCKET_DEBUG_OPEN
51314@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51315 #endif
51316 }
51317 #ifdef ROCKET_DEBUG_OPEN
51318- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
51319+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
51320 #endif
51321
51322 /*
51323@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
51324 spin_unlock_irqrestore(&info->port.lock, flags);
51325 return;
51326 }
51327- if (info->port.count)
51328+ if (atomic_read(&info->port.count))
51329 atomic_dec(&rp_num_ports_open);
51330 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
51331 spin_unlock_irqrestore(&info->port.lock, flags);
51332diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
51333index 1274499..f541382 100644
51334--- a/drivers/tty/serial/ioc4_serial.c
51335+++ b/drivers/tty/serial/ioc4_serial.c
51336@@ -437,7 +437,7 @@ struct ioc4_soft {
51337 } is_intr_info[MAX_IOC4_INTR_ENTS];
51338
51339 /* Number of entries active in the above array */
51340- atomic_t is_num_intrs;
51341+ atomic_unchecked_t is_num_intrs;
51342 } is_intr_type[IOC4_NUM_INTR_TYPES];
51343
51344 /* is_ir_lock must be held while
51345@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
51346 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
51347 || (type == IOC4_OTHER_INTR_TYPE)));
51348
51349- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
51350+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
51351 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
51352
51353 /* Save off the lower level interrupt handler */
51354@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
51355
51356 soft = arg;
51357 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
51358- num_intrs = (int)atomic_read(
51359+ num_intrs = (int)atomic_read_unchecked(
51360 &soft->is_intr_type[intr_type].is_num_intrs);
51361
51362 this_mir = this_ir = pending_intrs(soft, intr_type);
51363diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
51364index a260cde..6b2b5ce 100644
51365--- a/drivers/tty/serial/kgdboc.c
51366+++ b/drivers/tty/serial/kgdboc.c
51367@@ -24,8 +24,9 @@
51368 #define MAX_CONFIG_LEN 40
51369
51370 static struct kgdb_io kgdboc_io_ops;
51371+static struct kgdb_io kgdboc_io_ops_console;
51372
51373-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
51374+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
51375 static int configured = -1;
51376
51377 static char config[MAX_CONFIG_LEN];
51378@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
51379 kgdboc_unregister_kbd();
51380 if (configured == 1)
51381 kgdb_unregister_io_module(&kgdboc_io_ops);
51382+ else if (configured == 2)
51383+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
51384 }
51385
51386 static int configure_kgdboc(void)
51387@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
51388 int err;
51389 char *cptr = config;
51390 struct console *cons;
51391+ int is_console = 0;
51392
51393 err = kgdboc_option_setup(config);
51394 if (err || !strlen(config) || isspace(config[0]))
51395 goto noconfig;
51396
51397 err = -ENODEV;
51398- kgdboc_io_ops.is_console = 0;
51399 kgdb_tty_driver = NULL;
51400
51401 kgdboc_use_kms = 0;
51402@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51403 int idx;
51404 if (cons->device && cons->device(cons, &idx) == p &&
51405 idx == tty_line) {
51406- kgdboc_io_ops.is_console = 1;
51407+ is_console = 1;
51408 break;
51409 }
51410 cons = cons->next;
51411@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51412 kgdb_tty_line = tty_line;
51413
51414 do_register:
51415- err = kgdb_register_io_module(&kgdboc_io_ops);
51416+ if (is_console) {
51417+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
51418+ configured = 2;
51419+ } else {
51420+ err = kgdb_register_io_module(&kgdboc_io_ops);
51421+ configured = 1;
51422+ }
51423 if (err)
51424 goto noconfig;
51425
51426@@ -205,8 +214,6 @@ do_register:
51427 if (err)
51428 goto nmi_con_failed;
51429
51430- configured = 1;
51431-
51432 return 0;
51433
51434 nmi_con_failed:
51435@@ -223,7 +230,7 @@ noconfig:
51436 static int __init init_kgdboc(void)
51437 {
51438 /* Already configured? */
51439- if (configured == 1)
51440+ if (configured >= 1)
51441 return 0;
51442
51443 return configure_kgdboc();
51444@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51445 if (config[len - 1] == '\n')
51446 config[len - 1] = '\0';
51447
51448- if (configured == 1)
51449+ if (configured >= 1)
51450 cleanup_kgdboc();
51451
51452 /* Go and configure with the new params. */
51453@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51454 .post_exception = kgdboc_post_exp_handler,
51455 };
51456
51457+static struct kgdb_io kgdboc_io_ops_console = {
51458+ .name = "kgdboc",
51459+ .read_char = kgdboc_get_char,
51460+ .write_char = kgdboc_put_char,
51461+ .pre_exception = kgdboc_pre_exp_handler,
51462+ .post_exception = kgdboc_post_exp_handler,
51463+ .is_console = 1
51464+};
51465+
51466 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51467 /* This is only available if kgdboc is a built in for early debugging */
51468 static int __init kgdboc_early_init(char *opt)
51469diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51470index b5d779c..3622cfe 100644
51471--- a/drivers/tty/serial/msm_serial.c
51472+++ b/drivers/tty/serial/msm_serial.c
51473@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
51474 .cons = MSM_CONSOLE,
51475 };
51476
51477-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51478+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51479
51480 static const struct of_device_id msm_uartdm_table[] = {
51481 { .compatible = "qcom,msm-uartdm" },
51482@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51483 int irq;
51484
51485 if (pdev->id == -1)
51486- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51487+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51488
51489 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51490 return -ENXIO;
51491diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51492index 9cd706d..6ff2de7 100644
51493--- a/drivers/tty/serial/samsung.c
51494+++ b/drivers/tty/serial/samsung.c
51495@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51496 }
51497 }
51498
51499+static int s3c64xx_serial_startup(struct uart_port *port);
51500 static int s3c24xx_serial_startup(struct uart_port *port)
51501 {
51502 struct s3c24xx_uart_port *ourport = to_ourport(port);
51503 int ret;
51504
51505+ /* Startup sequence is different for s3c64xx and higher SoC's */
51506+ if (s3c24xx_serial_has_interrupt_mask(port))
51507+ return s3c64xx_serial_startup(port);
51508+
51509 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51510 port->mapbase, port->membase);
51511
51512@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51513 /* setup info for port */
51514 port->dev = &platdev->dev;
51515
51516- /* Startup sequence is different for s3c64xx and higher SoC's */
51517- if (s3c24xx_serial_has_interrupt_mask(port))
51518- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51519-
51520 port->uartclk = 1;
51521
51522 if (cfg->uart_flags & UPF_CONS_FLOW) {
51523diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51524index ece2049..fba2524 100644
51525--- a/drivers/tty/serial/serial_core.c
51526+++ b/drivers/tty/serial/serial_core.c
51527@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
51528 uart_flush_buffer(tty);
51529 uart_shutdown(tty, state);
51530 spin_lock_irqsave(&port->lock, flags);
51531- port->count = 0;
51532+ atomic_set(&port->count, 0);
51533 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51534 spin_unlock_irqrestore(&port->lock, flags);
51535 tty_port_tty_set(port, NULL);
51536@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51537 goto end;
51538 }
51539
51540- port->count++;
51541+ atomic_inc(&port->count);
51542 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51543 retval = -ENXIO;
51544 goto err_dec_count;
51545@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51546 /*
51547 * Make sure the device is in D0 state.
51548 */
51549- if (port->count == 1)
51550+ if (atomic_read(&port->count) == 1)
51551 uart_change_pm(state, UART_PM_STATE_ON);
51552
51553 /*
51554@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51555 end:
51556 return retval;
51557 err_dec_count:
51558- port->count--;
51559+ atomic_inc(&port->count);
51560 mutex_unlock(&port->mutex);
51561 goto end;
51562 }
51563diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51564index 5ae14b4..2c1288f 100644
51565--- a/drivers/tty/synclink.c
51566+++ b/drivers/tty/synclink.c
51567@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51568
51569 if (debug_level >= DEBUG_LEVEL_INFO)
51570 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51571- __FILE__,__LINE__, info->device_name, info->port.count);
51572+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51573
51574 if (tty_port_close_start(&info->port, tty, filp) == 0)
51575 goto cleanup;
51576@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51577 cleanup:
51578 if (debug_level >= DEBUG_LEVEL_INFO)
51579 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51580- tty->driver->name, info->port.count);
51581+ tty->driver->name, atomic_read(&info->port.count));
51582
51583 } /* end of mgsl_close() */
51584
51585@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51586
51587 mgsl_flush_buffer(tty);
51588 shutdown(info);
51589-
51590- info->port.count = 0;
51591+
51592+ atomic_set(&info->port.count, 0);
51593 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51594 info->port.tty = NULL;
51595
51596@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51597
51598 if (debug_level >= DEBUG_LEVEL_INFO)
51599 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51600- __FILE__,__LINE__, tty->driver->name, port->count );
51601+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51602
51603 spin_lock_irqsave(&info->irq_spinlock, flags);
51604 if (!tty_hung_up_p(filp)) {
51605 extra_count = true;
51606- port->count--;
51607+ atomic_dec(&port->count);
51608 }
51609 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51610 port->blocked_open++;
51611@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51612
51613 if (debug_level >= DEBUG_LEVEL_INFO)
51614 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51615- __FILE__,__LINE__, tty->driver->name, port->count );
51616+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51617
51618 tty_unlock(tty);
51619 schedule();
51620@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51621
51622 /* FIXME: Racy on hangup during close wait */
51623 if (extra_count)
51624- port->count++;
51625+ atomic_inc(&port->count);
51626 port->blocked_open--;
51627
51628 if (debug_level >= DEBUG_LEVEL_INFO)
51629 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51630- __FILE__,__LINE__, tty->driver->name, port->count );
51631+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51632
51633 if (!retval)
51634 port->flags |= ASYNC_NORMAL_ACTIVE;
51635@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51636
51637 if (debug_level >= DEBUG_LEVEL_INFO)
51638 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51639- __FILE__,__LINE__,tty->driver->name, info->port.count);
51640+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51641
51642 /* If port is closing, signal caller to try again */
51643 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51644@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51645 spin_unlock_irqrestore(&info->netlock, flags);
51646 goto cleanup;
51647 }
51648- info->port.count++;
51649+ atomic_inc(&info->port.count);
51650 spin_unlock_irqrestore(&info->netlock, flags);
51651
51652- if (info->port.count == 1) {
51653+ if (atomic_read(&info->port.count) == 1) {
51654 /* 1st open on this device, init hardware */
51655 retval = startup(info);
51656 if (retval < 0)
51657@@ -3446,8 +3446,8 @@ cleanup:
51658 if (retval) {
51659 if (tty->count == 1)
51660 info->port.tty = NULL; /* tty layer will release tty struct */
51661- if(info->port.count)
51662- info->port.count--;
51663+ if (atomic_read(&info->port.count))
51664+ atomic_dec(&info->port.count);
51665 }
51666
51667 return retval;
51668@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51669 unsigned short new_crctype;
51670
51671 /* return error if TTY interface open */
51672- if (info->port.count)
51673+ if (atomic_read(&info->port.count))
51674 return -EBUSY;
51675
51676 switch (encoding)
51677@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51678
51679 /* arbitrate between network and tty opens */
51680 spin_lock_irqsave(&info->netlock, flags);
51681- if (info->port.count != 0 || info->netcount != 0) {
51682+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51683 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51684 spin_unlock_irqrestore(&info->netlock, flags);
51685 return -EBUSY;
51686@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51687 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51688
51689 /* return error if TTY interface open */
51690- if (info->port.count)
51691+ if (atomic_read(&info->port.count))
51692 return -EBUSY;
51693
51694 if (cmd != SIOCWANDEV)
51695diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51696index c359a91..959fc26 100644
51697--- a/drivers/tty/synclink_gt.c
51698+++ b/drivers/tty/synclink_gt.c
51699@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51700 tty->driver_data = info;
51701 info->port.tty = tty;
51702
51703- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51704+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51705
51706 /* If port is closing, signal caller to try again */
51707 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51708@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51709 mutex_unlock(&info->port.mutex);
51710 goto cleanup;
51711 }
51712- info->port.count++;
51713+ atomic_inc(&info->port.count);
51714 spin_unlock_irqrestore(&info->netlock, flags);
51715
51716- if (info->port.count == 1) {
51717+ if (atomic_read(&info->port.count) == 1) {
51718 /* 1st open on this device, init hardware */
51719 retval = startup(info);
51720 if (retval < 0) {
51721@@ -715,8 +715,8 @@ cleanup:
51722 if (retval) {
51723 if (tty->count == 1)
51724 info->port.tty = NULL; /* tty layer will release tty struct */
51725- if(info->port.count)
51726- info->port.count--;
51727+ if(atomic_read(&info->port.count))
51728+ atomic_dec(&info->port.count);
51729 }
51730
51731 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51732@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51733
51734 if (sanity_check(info, tty->name, "close"))
51735 return;
51736- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51737+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51738
51739 if (tty_port_close_start(&info->port, tty, filp) == 0)
51740 goto cleanup;
51741@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51742 tty_port_close_end(&info->port, tty);
51743 info->port.tty = NULL;
51744 cleanup:
51745- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51746+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51747 }
51748
51749 static void hangup(struct tty_struct *tty)
51750@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51751 shutdown(info);
51752
51753 spin_lock_irqsave(&info->port.lock, flags);
51754- info->port.count = 0;
51755+ atomic_set(&info->port.count, 0);
51756 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51757 info->port.tty = NULL;
51758 spin_unlock_irqrestore(&info->port.lock, flags);
51759@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51760 unsigned short new_crctype;
51761
51762 /* return error if TTY interface open */
51763- if (info->port.count)
51764+ if (atomic_read(&info->port.count))
51765 return -EBUSY;
51766
51767 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51768@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51769
51770 /* arbitrate between network and tty opens */
51771 spin_lock_irqsave(&info->netlock, flags);
51772- if (info->port.count != 0 || info->netcount != 0) {
51773+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51774 DBGINFO(("%s hdlc_open busy\n", dev->name));
51775 spin_unlock_irqrestore(&info->netlock, flags);
51776 return -EBUSY;
51777@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51778 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51779
51780 /* return error if TTY interface open */
51781- if (info->port.count)
51782+ if (atomic_read(&info->port.count))
51783 return -EBUSY;
51784
51785 if (cmd != SIOCWANDEV)
51786@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51787 if (port == NULL)
51788 continue;
51789 spin_lock(&port->lock);
51790- if ((port->port.count || port->netcount) &&
51791+ if ((atomic_read(&port->port.count) || port->netcount) &&
51792 port->pending_bh && !port->bh_running &&
51793 !port->bh_requested) {
51794 DBGISR(("%s bh queued\n", port->device_name));
51795@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51796 spin_lock_irqsave(&info->lock, flags);
51797 if (!tty_hung_up_p(filp)) {
51798 extra_count = true;
51799- port->count--;
51800+ atomic_dec(&port->count);
51801 }
51802 spin_unlock_irqrestore(&info->lock, flags);
51803 port->blocked_open++;
51804@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51805 remove_wait_queue(&port->open_wait, &wait);
51806
51807 if (extra_count)
51808- port->count++;
51809+ atomic_inc(&port->count);
51810 port->blocked_open--;
51811
51812 if (!retval)
51813diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51814index 144202e..4ccb07d 100644
51815--- a/drivers/tty/synclinkmp.c
51816+++ b/drivers/tty/synclinkmp.c
51817@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51818
51819 if (debug_level >= DEBUG_LEVEL_INFO)
51820 printk("%s(%d):%s open(), old ref count = %d\n",
51821- __FILE__,__LINE__,tty->driver->name, info->port.count);
51822+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51823
51824 /* If port is closing, signal caller to try again */
51825 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51826@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51827 spin_unlock_irqrestore(&info->netlock, flags);
51828 goto cleanup;
51829 }
51830- info->port.count++;
51831+ atomic_inc(&info->port.count);
51832 spin_unlock_irqrestore(&info->netlock, flags);
51833
51834- if (info->port.count == 1) {
51835+ if (atomic_read(&info->port.count) == 1) {
51836 /* 1st open on this device, init hardware */
51837 retval = startup(info);
51838 if (retval < 0)
51839@@ -796,8 +796,8 @@ cleanup:
51840 if (retval) {
51841 if (tty->count == 1)
51842 info->port.tty = NULL; /* tty layer will release tty struct */
51843- if(info->port.count)
51844- info->port.count--;
51845+ if(atomic_read(&info->port.count))
51846+ atomic_dec(&info->port.count);
51847 }
51848
51849 return retval;
51850@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51851
51852 if (debug_level >= DEBUG_LEVEL_INFO)
51853 printk("%s(%d):%s close() entry, count=%d\n",
51854- __FILE__,__LINE__, info->device_name, info->port.count);
51855+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51856
51857 if (tty_port_close_start(&info->port, tty, filp) == 0)
51858 goto cleanup;
51859@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51860 cleanup:
51861 if (debug_level >= DEBUG_LEVEL_INFO)
51862 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51863- tty->driver->name, info->port.count);
51864+ tty->driver->name, atomic_read(&info->port.count));
51865 }
51866
51867 /* Called by tty_hangup() when a hangup is signaled.
51868@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51869 shutdown(info);
51870
51871 spin_lock_irqsave(&info->port.lock, flags);
51872- info->port.count = 0;
51873+ atomic_set(&info->port.count, 0);
51874 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51875 info->port.tty = NULL;
51876 spin_unlock_irqrestore(&info->port.lock, flags);
51877@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51878 unsigned short new_crctype;
51879
51880 /* return error if TTY interface open */
51881- if (info->port.count)
51882+ if (atomic_read(&info->port.count))
51883 return -EBUSY;
51884
51885 switch (encoding)
51886@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51887
51888 /* arbitrate between network and tty opens */
51889 spin_lock_irqsave(&info->netlock, flags);
51890- if (info->port.count != 0 || info->netcount != 0) {
51891+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51892 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51893 spin_unlock_irqrestore(&info->netlock, flags);
51894 return -EBUSY;
51895@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51896 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51897
51898 /* return error if TTY interface open */
51899- if (info->port.count)
51900+ if (atomic_read(&info->port.count))
51901 return -EBUSY;
51902
51903 if (cmd != SIOCWANDEV)
51904@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51905 * do not request bottom half processing if the
51906 * device is not open in a normal mode.
51907 */
51908- if ( port && (port->port.count || port->netcount) &&
51909+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51910 port->pending_bh && !port->bh_running &&
51911 !port->bh_requested ) {
51912 if ( debug_level >= DEBUG_LEVEL_ISR )
51913@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51914
51915 if (debug_level >= DEBUG_LEVEL_INFO)
51916 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51917- __FILE__,__LINE__, tty->driver->name, port->count );
51918+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51919
51920 spin_lock_irqsave(&info->lock, flags);
51921 if (!tty_hung_up_p(filp)) {
51922 extra_count = true;
51923- port->count--;
51924+ atomic_dec(&port->count);
51925 }
51926 spin_unlock_irqrestore(&info->lock, flags);
51927 port->blocked_open++;
51928@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51929
51930 if (debug_level >= DEBUG_LEVEL_INFO)
51931 printk("%s(%d):%s block_til_ready() count=%d\n",
51932- __FILE__,__LINE__, tty->driver->name, port->count );
51933+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51934
51935 tty_unlock(tty);
51936 schedule();
51937@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51938 remove_wait_queue(&port->open_wait, &wait);
51939
51940 if (extra_count)
51941- port->count++;
51942+ atomic_inc(&port->count);
51943 port->blocked_open--;
51944
51945 if (debug_level >= DEBUG_LEVEL_INFO)
51946 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51947- __FILE__,__LINE__, tty->driver->name, port->count );
51948+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51949
51950 if (!retval)
51951 port->flags |= ASYNC_NORMAL_ACTIVE;
51952diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51953index ce396ec..04a37be 100644
51954--- a/drivers/tty/sysrq.c
51955+++ b/drivers/tty/sysrq.c
51956@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51957 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51958 size_t count, loff_t *ppos)
51959 {
51960- if (count) {
51961+ if (count && capable(CAP_SYS_ADMIN)) {
51962 char c;
51963
51964 if (get_user(c, buf))
51965diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51966index d3448a9..28e8db0 100644
51967--- a/drivers/tty/tty_io.c
51968+++ b/drivers/tty/tty_io.c
51969@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51970
51971 void tty_default_fops(struct file_operations *fops)
51972 {
51973- *fops = tty_fops;
51974+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51975 }
51976
51977 /*
51978diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51979index 2d822aa..a566234 100644
51980--- a/drivers/tty/tty_ldisc.c
51981+++ b/drivers/tty/tty_ldisc.c
51982@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51983 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51984 tty_ldiscs[disc] = new_ldisc;
51985 new_ldisc->num = disc;
51986- new_ldisc->refcount = 0;
51987+ atomic_set(&new_ldisc->refcount, 0);
51988 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51989
51990 return ret;
51991@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51992 return -EINVAL;
51993
51994 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51995- if (tty_ldiscs[disc]->refcount)
51996+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51997 ret = -EBUSY;
51998 else
51999 tty_ldiscs[disc] = NULL;
52000@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
52001 if (ldops) {
52002 ret = ERR_PTR(-EAGAIN);
52003 if (try_module_get(ldops->owner)) {
52004- ldops->refcount++;
52005+ atomic_inc(&ldops->refcount);
52006 ret = ldops;
52007 }
52008 }
52009@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
52010 unsigned long flags;
52011
52012 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52013- ldops->refcount--;
52014+ atomic_dec(&ldops->refcount);
52015 module_put(ldops->owner);
52016 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
52017 }
52018diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
52019index 3f746c8..2f2fcaa 100644
52020--- a/drivers/tty/tty_port.c
52021+++ b/drivers/tty/tty_port.c
52022@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
52023 unsigned long flags;
52024
52025 spin_lock_irqsave(&port->lock, flags);
52026- port->count = 0;
52027+ atomic_set(&port->count, 0);
52028 port->flags &= ~ASYNC_NORMAL_ACTIVE;
52029 tty = port->tty;
52030 if (tty)
52031@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
52032 /* The port lock protects the port counts */
52033 spin_lock_irqsave(&port->lock, flags);
52034 if (!tty_hung_up_p(filp))
52035- port->count--;
52036+ atomic_dec(&port->count);
52037 port->blocked_open++;
52038 spin_unlock_irqrestore(&port->lock, flags);
52039
52040@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
52041 we must not mess that up further */
52042 spin_lock_irqsave(&port->lock, flags);
52043 if (!tty_hung_up_p(filp))
52044- port->count++;
52045+ atomic_inc(&port->count);
52046 port->blocked_open--;
52047 if (retval == 0)
52048 port->flags |= ASYNC_NORMAL_ACTIVE;
52049@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
52050 return 0;
52051 }
52052
52053- if (tty->count == 1 && port->count != 1) {
52054+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
52055 printk(KERN_WARNING
52056 "tty_port_close_start: tty->count = 1 port count = %d.\n",
52057- port->count);
52058- port->count = 1;
52059+ atomic_read(&port->count));
52060+ atomic_set(&port->count, 1);
52061 }
52062- if (--port->count < 0) {
52063+ if (atomic_dec_return(&port->count) < 0) {
52064 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
52065- port->count);
52066- port->count = 0;
52067+ atomic_read(&port->count));
52068+ atomic_set(&port->count, 0);
52069 }
52070
52071- if (port->count) {
52072+ if (atomic_read(&port->count)) {
52073 spin_unlock_irqrestore(&port->lock, flags);
52074 return 0;
52075 }
52076@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
52077 {
52078 spin_lock_irq(&port->lock);
52079 if (!tty_hung_up_p(filp))
52080- ++port->count;
52081+ atomic_inc(&port->count);
52082 spin_unlock_irq(&port->lock);
52083 tty_port_tty_set(port, tty);
52084
52085diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
52086index d0e3a44..5f8b754 100644
52087--- a/drivers/tty/vt/keyboard.c
52088+++ b/drivers/tty/vt/keyboard.c
52089@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
52090 kbd->kbdmode == VC_OFF) &&
52091 value != KVAL(K_SAK))
52092 return; /* SAK is allowed even in raw mode */
52093+
52094+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52095+ {
52096+ void *func = fn_handler[value];
52097+ if (func == fn_show_state || func == fn_show_ptregs ||
52098+ func == fn_show_mem)
52099+ return;
52100+ }
52101+#endif
52102+
52103 fn_handler[value](vc);
52104 }
52105
52106@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52107 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
52108 return -EFAULT;
52109
52110- if (!capable(CAP_SYS_TTY_CONFIG))
52111- perm = 0;
52112-
52113 switch (cmd) {
52114 case KDGKBENT:
52115 /* Ensure another thread doesn't free it under us */
52116@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52117 spin_unlock_irqrestore(&kbd_event_lock, flags);
52118 return put_user(val, &user_kbe->kb_value);
52119 case KDSKBENT:
52120+ if (!capable(CAP_SYS_TTY_CONFIG))
52121+ perm = 0;
52122+
52123 if (!perm)
52124 return -EPERM;
52125 if (!i && v == K_NOSUCHMAP) {
52126@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52127 int i, j, k;
52128 int ret;
52129
52130- if (!capable(CAP_SYS_TTY_CONFIG))
52131- perm = 0;
52132-
52133 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
52134 if (!kbs) {
52135 ret = -ENOMEM;
52136@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52137 kfree(kbs);
52138 return ((p && *p) ? -EOVERFLOW : 0);
52139 case KDSKBSENT:
52140+ if (!capable(CAP_SYS_TTY_CONFIG))
52141+ perm = 0;
52142+
52143 if (!perm) {
52144 ret = -EPERM;
52145 goto reterr;
52146diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
52147index a673e5b..36e5d32 100644
52148--- a/drivers/uio/uio.c
52149+++ b/drivers/uio/uio.c
52150@@ -25,6 +25,7 @@
52151 #include <linux/kobject.h>
52152 #include <linux/cdev.h>
52153 #include <linux/uio_driver.h>
52154+#include <asm/local.h>
52155
52156 #define UIO_MAX_DEVICES (1U << MINORBITS)
52157
52158@@ -32,7 +33,7 @@ struct uio_device {
52159 struct module *owner;
52160 struct device *dev;
52161 int minor;
52162- atomic_t event;
52163+ atomic_unchecked_t event;
52164 struct fasync_struct *async_queue;
52165 wait_queue_head_t wait;
52166 struct uio_info *info;
52167@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
52168 struct device_attribute *attr, char *buf)
52169 {
52170 struct uio_device *idev = dev_get_drvdata(dev);
52171- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
52172+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
52173 }
52174 static DEVICE_ATTR_RO(event);
52175
52176@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
52177 {
52178 struct uio_device *idev = info->uio_dev;
52179
52180- atomic_inc(&idev->event);
52181+ atomic_inc_unchecked(&idev->event);
52182 wake_up_interruptible(&idev->wait);
52183 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
52184 }
52185@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
52186 }
52187
52188 listener->dev = idev;
52189- listener->event_count = atomic_read(&idev->event);
52190+ listener->event_count = atomic_read_unchecked(&idev->event);
52191 filep->private_data = listener;
52192
52193 if (idev->info->open) {
52194@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
52195 return -EIO;
52196
52197 poll_wait(filep, &idev->wait, wait);
52198- if (listener->event_count != atomic_read(&idev->event))
52199+ if (listener->event_count != atomic_read_unchecked(&idev->event))
52200 return POLLIN | POLLRDNORM;
52201 return 0;
52202 }
52203@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
52204 do {
52205 set_current_state(TASK_INTERRUPTIBLE);
52206
52207- event_count = atomic_read(&idev->event);
52208+ event_count = atomic_read_unchecked(&idev->event);
52209 if (event_count != listener->event_count) {
52210 if (copy_to_user(buf, &event_count, count))
52211 retval = -EFAULT;
52212@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
52213 static int uio_find_mem_index(struct vm_area_struct *vma)
52214 {
52215 struct uio_device *idev = vma->vm_private_data;
52216+ unsigned long size;
52217
52218 if (vma->vm_pgoff < MAX_UIO_MAPS) {
52219- if (idev->info->mem[vma->vm_pgoff].size == 0)
52220+ size = idev->info->mem[vma->vm_pgoff].size;
52221+ if (size == 0)
52222+ return -1;
52223+ if (vma->vm_end - vma->vm_start > size)
52224 return -1;
52225 return (int)vma->vm_pgoff;
52226 }
52227@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
52228 idev->owner = owner;
52229 idev->info = info;
52230 init_waitqueue_head(&idev->wait);
52231- atomic_set(&idev->event, 0);
52232+ atomic_set_unchecked(&idev->event, 0);
52233
52234 ret = uio_get_minor(idev);
52235 if (ret)
52236diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
52237index 813d4d3..a71934f 100644
52238--- a/drivers/usb/atm/cxacru.c
52239+++ b/drivers/usb/atm/cxacru.c
52240@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
52241 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
52242 if (ret < 2)
52243 return -EINVAL;
52244- if (index < 0 || index > 0x7f)
52245+ if (index > 0x7f)
52246 return -EINVAL;
52247 pos += tmp;
52248
52249diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
52250index dada014..1d0d517 100644
52251--- a/drivers/usb/atm/usbatm.c
52252+++ b/drivers/usb/atm/usbatm.c
52253@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52254 if (printk_ratelimit())
52255 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
52256 __func__, vpi, vci);
52257- atomic_inc(&vcc->stats->rx_err);
52258+ atomic_inc_unchecked(&vcc->stats->rx_err);
52259 return;
52260 }
52261
52262@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52263 if (length > ATM_MAX_AAL5_PDU) {
52264 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
52265 __func__, length, vcc);
52266- atomic_inc(&vcc->stats->rx_err);
52267+ atomic_inc_unchecked(&vcc->stats->rx_err);
52268 goto out;
52269 }
52270
52271@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52272 if (sarb->len < pdu_length) {
52273 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
52274 __func__, pdu_length, sarb->len, vcc);
52275- atomic_inc(&vcc->stats->rx_err);
52276+ atomic_inc_unchecked(&vcc->stats->rx_err);
52277 goto out;
52278 }
52279
52280 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
52281 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
52282 __func__, vcc);
52283- atomic_inc(&vcc->stats->rx_err);
52284+ atomic_inc_unchecked(&vcc->stats->rx_err);
52285 goto out;
52286 }
52287
52288@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52289 if (printk_ratelimit())
52290 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
52291 __func__, length);
52292- atomic_inc(&vcc->stats->rx_drop);
52293+ atomic_inc_unchecked(&vcc->stats->rx_drop);
52294 goto out;
52295 }
52296
52297@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52298
52299 vcc->push(vcc, skb);
52300
52301- atomic_inc(&vcc->stats->rx);
52302+ atomic_inc_unchecked(&vcc->stats->rx);
52303 out:
52304 skb_trim(sarb, 0);
52305 }
52306@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
52307 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
52308
52309 usbatm_pop(vcc, skb);
52310- atomic_inc(&vcc->stats->tx);
52311+ atomic_inc_unchecked(&vcc->stats->tx);
52312
52313 skb = skb_dequeue(&instance->sndqueue);
52314 }
52315@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
52316 if (!left--)
52317 return sprintf(page,
52318 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
52319- atomic_read(&atm_dev->stats.aal5.tx),
52320- atomic_read(&atm_dev->stats.aal5.tx_err),
52321- atomic_read(&atm_dev->stats.aal5.rx),
52322- atomic_read(&atm_dev->stats.aal5.rx_err),
52323- atomic_read(&atm_dev->stats.aal5.rx_drop));
52324+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
52325+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
52326+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
52327+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
52328+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
52329
52330 if (!left--) {
52331 if (instance->disconnected)
52332diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
52333index 2a3bbdf..91d72cf 100644
52334--- a/drivers/usb/core/devices.c
52335+++ b/drivers/usb/core/devices.c
52336@@ -126,7 +126,7 @@ static const char format_endpt[] =
52337 * time it gets called.
52338 */
52339 static struct device_connect_event {
52340- atomic_t count;
52341+ atomic_unchecked_t count;
52342 wait_queue_head_t wait;
52343 } device_event = {
52344 .count = ATOMIC_INIT(1),
52345@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
52346
52347 void usbfs_conn_disc_event(void)
52348 {
52349- atomic_add(2, &device_event.count);
52350+ atomic_add_unchecked(2, &device_event.count);
52351 wake_up(&device_event.wait);
52352 }
52353
52354@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
52355
52356 poll_wait(file, &device_event.wait, wait);
52357
52358- event_count = atomic_read(&device_event.count);
52359+ event_count = atomic_read_unchecked(&device_event.count);
52360 if (file->f_version != event_count) {
52361 file->f_version = event_count;
52362 return POLLIN | POLLRDNORM;
52363diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
52364index 90e18f6..5eeda46 100644
52365--- a/drivers/usb/core/devio.c
52366+++ b/drivers/usb/core/devio.c
52367@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52368 struct dev_state *ps = file->private_data;
52369 struct usb_device *dev = ps->dev;
52370 ssize_t ret = 0;
52371- unsigned len;
52372+ size_t len;
52373 loff_t pos;
52374 int i;
52375
52376@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52377 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
52378 struct usb_config_descriptor *config =
52379 (struct usb_config_descriptor *)dev->rawdescriptors[i];
52380- unsigned int length = le16_to_cpu(config->wTotalLength);
52381+ size_t length = le16_to_cpu(config->wTotalLength);
52382
52383 if (*ppos < pos + length) {
52384
52385 /* The descriptor may claim to be longer than it
52386 * really is. Here is the actual allocated length. */
52387- unsigned alloclen =
52388+ size_t alloclen =
52389 le16_to_cpu(dev->config[i].desc.wTotalLength);
52390
52391- len = length - (*ppos - pos);
52392+ len = length + pos - *ppos;
52393 if (len > nbytes)
52394 len = nbytes;
52395
52396 /* Simply don't write (skip over) unallocated parts */
52397 if (alloclen > (*ppos - pos)) {
52398- alloclen -= (*ppos - pos);
52399+ alloclen = alloclen + pos - *ppos;
52400 if (copy_to_user(buf,
52401 dev->rawdescriptors[i] + (*ppos - pos),
52402 min(len, alloclen))) {
52403diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52404index 2518c32..1c201bb 100644
52405--- a/drivers/usb/core/hcd.c
52406+++ b/drivers/usb/core/hcd.c
52407@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52408 */
52409 usb_get_urb(urb);
52410 atomic_inc(&urb->use_count);
52411- atomic_inc(&urb->dev->urbnum);
52412+ atomic_inc_unchecked(&urb->dev->urbnum);
52413 usbmon_urb_submit(&hcd->self, urb);
52414
52415 /* NOTE requirements on root-hub callers (usbfs and the hub
52416@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52417 urb->hcpriv = NULL;
52418 INIT_LIST_HEAD(&urb->urb_list);
52419 atomic_dec(&urb->use_count);
52420- atomic_dec(&urb->dev->urbnum);
52421+ atomic_dec_unchecked(&urb->dev->urbnum);
52422 if (atomic_read(&urb->reject))
52423 wake_up(&usb_kill_urb_queue);
52424 usb_put_urb(urb);
52425diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52426index d498d03..e26f959 100644
52427--- a/drivers/usb/core/hub.c
52428+++ b/drivers/usb/core/hub.c
52429@@ -27,6 +27,7 @@
52430 #include <linux/freezer.h>
52431 #include <linux/random.h>
52432 #include <linux/pm_qos.h>
52433+#include <linux/grsecurity.h>
52434
52435 #include <asm/uaccess.h>
52436 #include <asm/byteorder.h>
52437@@ -4472,6 +4473,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52438 goto done;
52439 return;
52440 }
52441+
52442+ if (gr_handle_new_usb())
52443+ goto done;
52444+
52445 if (hub_is_superspeed(hub->hdev))
52446 unit_load = 150;
52447 else
52448diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52449index f829a1a..e6c334a 100644
52450--- a/drivers/usb/core/message.c
52451+++ b/drivers/usb/core/message.c
52452@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52453 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52454 * error number.
52455 */
52456-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52457+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52458 __u8 requesttype, __u16 value, __u16 index, void *data,
52459 __u16 size, int timeout)
52460 {
52461@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52462 * If successful, 0. Otherwise a negative error number. The number of actual
52463 * bytes transferred will be stored in the @actual_length paramater.
52464 */
52465-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52466+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52467 void *data, int len, int *actual_length, int timeout)
52468 {
52469 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52470@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52471 * bytes transferred will be stored in the @actual_length parameter.
52472 *
52473 */
52474-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52475+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52476 void *data, int len, int *actual_length, int timeout)
52477 {
52478 struct urb *urb;
52479diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52480index 1236c60..d47a51c 100644
52481--- a/drivers/usb/core/sysfs.c
52482+++ b/drivers/usb/core/sysfs.c
52483@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52484 struct usb_device *udev;
52485
52486 udev = to_usb_device(dev);
52487- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52488+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52489 }
52490 static DEVICE_ATTR_RO(urbnum);
52491
52492diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52493index 4d11449..f4ccabf 100644
52494--- a/drivers/usb/core/usb.c
52495+++ b/drivers/usb/core/usb.c
52496@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52497 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52498 dev->state = USB_STATE_ATTACHED;
52499 dev->lpm_disable_count = 1;
52500- atomic_set(&dev->urbnum, 0);
52501+ atomic_set_unchecked(&dev->urbnum, 0);
52502
52503 INIT_LIST_HEAD(&dev->ep0.urb_list);
52504 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52505diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52506index 2da0a5a..4870e09 100644
52507--- a/drivers/usb/dwc3/gadget.c
52508+++ b/drivers/usb/dwc3/gadget.c
52509@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52510 if (!usb_endpoint_xfer_isoc(desc))
52511 return 0;
52512
52513- memset(&trb_link, 0, sizeof(trb_link));
52514-
52515 /* Link TRB for ISOC. The HWO bit is never reset */
52516 trb_st_hw = &dep->trb_pool[0];
52517
52518diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52519index 8cfc319..4868255 100644
52520--- a/drivers/usb/early/ehci-dbgp.c
52521+++ b/drivers/usb/early/ehci-dbgp.c
52522@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52523
52524 #ifdef CONFIG_KGDB
52525 static struct kgdb_io kgdbdbgp_io_ops;
52526-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52527+static struct kgdb_io kgdbdbgp_io_ops_console;
52528+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52529 #else
52530 #define dbgp_kgdb_mode (0)
52531 #endif
52532@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52533 .write_char = kgdbdbgp_write_char,
52534 };
52535
52536+static struct kgdb_io kgdbdbgp_io_ops_console = {
52537+ .name = "kgdbdbgp",
52538+ .read_char = kgdbdbgp_read_char,
52539+ .write_char = kgdbdbgp_write_char,
52540+ .is_console = 1
52541+};
52542+
52543 static int kgdbdbgp_wait_time;
52544
52545 static int __init kgdbdbgp_parse_config(char *str)
52546@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52547 ptr++;
52548 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52549 }
52550- kgdb_register_io_module(&kgdbdbgp_io_ops);
52551- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52552+ if (early_dbgp_console.index != -1)
52553+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52554+ else
52555+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52556
52557 return 0;
52558 }
52559diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52560index 2b4c82d..06a8ee6 100644
52561--- a/drivers/usb/gadget/f_uac1.c
52562+++ b/drivers/usb/gadget/f_uac1.c
52563@@ -13,6 +13,7 @@
52564 #include <linux/kernel.h>
52565 #include <linux/device.h>
52566 #include <linux/atomic.h>
52567+#include <linux/module.h>
52568
52569 #include "u_uac1.h"
52570
52571diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52572index ad0aca8..8ff84865 100644
52573--- a/drivers/usb/gadget/u_serial.c
52574+++ b/drivers/usb/gadget/u_serial.c
52575@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52576 spin_lock_irq(&port->port_lock);
52577
52578 /* already open? Great. */
52579- if (port->port.count) {
52580+ if (atomic_read(&port->port.count)) {
52581 status = 0;
52582- port->port.count++;
52583+ atomic_inc(&port->port.count);
52584
52585 /* currently opening/closing? wait ... */
52586 } else if (port->openclose) {
52587@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52588 tty->driver_data = port;
52589 port->port.tty = tty;
52590
52591- port->port.count = 1;
52592+ atomic_set(&port->port.count, 1);
52593 port->openclose = false;
52594
52595 /* if connected, start the I/O stream */
52596@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52597
52598 spin_lock_irq(&port->port_lock);
52599
52600- if (port->port.count != 1) {
52601- if (port->port.count == 0)
52602+ if (atomic_read(&port->port.count) != 1) {
52603+ if (atomic_read(&port->port.count) == 0)
52604 WARN_ON(1);
52605 else
52606- --port->port.count;
52607+ atomic_dec(&port->port.count);
52608 goto exit;
52609 }
52610
52611@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52612 * and sleep if necessary
52613 */
52614 port->openclose = true;
52615- port->port.count = 0;
52616+ atomic_set(&port->port.count, 0);
52617
52618 gser = port->port_usb;
52619 if (gser && gser->disconnect)
52620@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52621 int cond;
52622
52623 spin_lock_irq(&port->port_lock);
52624- cond = (port->port.count == 0) && !port->openclose;
52625+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52626 spin_unlock_irq(&port->port_lock);
52627 return cond;
52628 }
52629@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52630 /* if it's already open, start I/O ... and notify the serial
52631 * protocol about open/close status (connect/disconnect).
52632 */
52633- if (port->port.count) {
52634+ if (atomic_read(&port->port.count)) {
52635 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52636 gs_start_io(port);
52637 if (gser->connect)
52638@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52639
52640 port->port_usb = NULL;
52641 gser->ioport = NULL;
52642- if (port->port.count > 0 || port->openclose) {
52643+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52644 wake_up_interruptible(&port->drain_wait);
52645 if (port->port.tty)
52646 tty_hangup(port->port.tty);
52647@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52648
52649 /* finally, free any unused/unusable I/O buffers */
52650 spin_lock_irqsave(&port->port_lock, flags);
52651- if (port->port.count == 0 && !port->openclose)
52652+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52653 gs_buf_free(&port->port_write_buf);
52654 gs_free_requests(gser->out, &port->read_pool, NULL);
52655 gs_free_requests(gser->out, &port->read_queue, NULL);
52656diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52657index 7a55fea..cc0ed4f 100644
52658--- a/drivers/usb/gadget/u_uac1.c
52659+++ b/drivers/usb/gadget/u_uac1.c
52660@@ -16,6 +16,7 @@
52661 #include <linux/ctype.h>
52662 #include <linux/random.h>
52663 #include <linux/syscalls.h>
52664+#include <linux/module.h>
52665
52666 #include "u_uac1.h"
52667
52668diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52669index 7ae0c4d..35521b7 100644
52670--- a/drivers/usb/host/ehci-hub.c
52671+++ b/drivers/usb/host/ehci-hub.c
52672@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52673 urb->transfer_flags = URB_DIR_IN;
52674 usb_get_urb(urb);
52675 atomic_inc(&urb->use_count);
52676- atomic_inc(&urb->dev->urbnum);
52677+ atomic_inc_unchecked(&urb->dev->urbnum);
52678 urb->setup_dma = dma_map_single(
52679 hcd->self.controller,
52680 urb->setup_packet,
52681@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52682 urb->status = -EINPROGRESS;
52683 usb_get_urb(urb);
52684 atomic_inc(&urb->use_count);
52685- atomic_inc(&urb->dev->urbnum);
52686+ atomic_inc_unchecked(&urb->dev->urbnum);
52687 retval = submit_single_step_set_feature(hcd, urb, 0);
52688 if (!retval && !wait_for_completion_timeout(&done,
52689 msecs_to_jiffies(2000))) {
52690diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52691index ba6a5d6..f88f7f3 100644
52692--- a/drivers/usb/misc/appledisplay.c
52693+++ b/drivers/usb/misc/appledisplay.c
52694@@ -83,7 +83,7 @@ struct appledisplay {
52695 spinlock_t lock;
52696 };
52697
52698-static atomic_t count_displays = ATOMIC_INIT(0);
52699+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52700 static struct workqueue_struct *wq;
52701
52702 static void appledisplay_complete(struct urb *urb)
52703@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52704
52705 /* Register backlight device */
52706 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52707- atomic_inc_return(&count_displays) - 1);
52708+ atomic_inc_return_unchecked(&count_displays) - 1);
52709 memset(&props, 0, sizeof(struct backlight_properties));
52710 props.type = BACKLIGHT_RAW;
52711 props.max_brightness = 0xff;
52712diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52713index 8d7fc48..01c4986 100644
52714--- a/drivers/usb/serial/console.c
52715+++ b/drivers/usb/serial/console.c
52716@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52717
52718 info->port = port;
52719
52720- ++port->port.count;
52721+ atomic_inc(&port->port.count);
52722 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52723 if (serial->type->set_termios) {
52724 /*
52725@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52726 }
52727 /* Now that any required fake tty operations are completed restore
52728 * the tty port count */
52729- --port->port.count;
52730+ atomic_dec(&port->port.count);
52731 /* The console is special in terms of closing the device so
52732 * indicate this port is now acting as a system console. */
52733 port->port.console = 1;
52734@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52735 free_tty:
52736 kfree(tty);
52737 reset_open_count:
52738- port->port.count = 0;
52739+ atomic_set(&port->port.count, 0);
52740 usb_autopm_put_interface(serial->interface);
52741 error_get_interface:
52742 usb_serial_put(serial);
52743@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52744 static void usb_console_write(struct console *co,
52745 const char *buf, unsigned count)
52746 {
52747- static struct usbcons_info *info = &usbcons_info;
52748+ struct usbcons_info *info = &usbcons_info;
52749 struct usb_serial_port *port = info->port;
52750 struct usb_serial *serial;
52751 int retval = -ENODEV;
52752diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52753index 75f70f0..d467e1a 100644
52754--- a/drivers/usb/storage/usb.h
52755+++ b/drivers/usb/storage/usb.h
52756@@ -63,7 +63,7 @@ struct us_unusual_dev {
52757 __u8 useProtocol;
52758 __u8 useTransport;
52759 int (*initFunction)(struct us_data *);
52760-};
52761+} __do_const;
52762
52763
52764 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52765diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52766index a2ef84b..aa7c2b8 100644
52767--- a/drivers/usb/wusbcore/wa-hc.h
52768+++ b/drivers/usb/wusbcore/wa-hc.h
52769@@ -225,7 +225,7 @@ struct wahc {
52770 spinlock_t xfer_list_lock;
52771 struct work_struct xfer_enqueue_work;
52772 struct work_struct xfer_error_work;
52773- atomic_t xfer_id_count;
52774+ atomic_unchecked_t xfer_id_count;
52775
52776 kernel_ulong_t quirks;
52777 };
52778@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52779 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52780 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52781 wa->dto_in_use = 0;
52782- atomic_set(&wa->xfer_id_count, 1);
52783+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52784 }
52785
52786 /**
52787diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52788index 3cd96e9..bd7c58d 100644
52789--- a/drivers/usb/wusbcore/wa-xfer.c
52790+++ b/drivers/usb/wusbcore/wa-xfer.c
52791@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52792 */
52793 static void wa_xfer_id_init(struct wa_xfer *xfer)
52794 {
52795- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52796+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52797 }
52798
52799 /* Return the xfer's ID. */
52800diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52801index 21271d8..45b55a0 100644
52802--- a/drivers/vfio/vfio.c
52803+++ b/drivers/vfio/vfio.c
52804@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52805 return 0;
52806
52807 /* TODO Prevent device auto probing */
52808- WARN("Device %s added to live group %d!\n", dev_name(dev),
52809+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52810 iommu_group_id(group->iommu_group));
52811
52812 return 0;
52813diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52814index 5174eba..451e6bc 100644
52815--- a/drivers/vhost/vringh.c
52816+++ b/drivers/vhost/vringh.c
52817@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52818 /* Userspace access helpers: in this case, addresses are really userspace. */
52819 static inline int getu16_user(u16 *val, const u16 *p)
52820 {
52821- return get_user(*val, (__force u16 __user *)p);
52822+ return get_user(*val, (u16 __force_user *)p);
52823 }
52824
52825 static inline int putu16_user(u16 *p, u16 val)
52826 {
52827- return put_user(val, (__force u16 __user *)p);
52828+ return put_user(val, (u16 __force_user *)p);
52829 }
52830
52831 static inline int copydesc_user(void *dst, const void *src, size_t len)
52832 {
52833- return copy_from_user(dst, (__force void __user *)src, len) ?
52834+ return copy_from_user(dst, (void __force_user *)src, len) ?
52835 -EFAULT : 0;
52836 }
52837
52838@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52839 const struct vring_used_elem *src,
52840 unsigned int num)
52841 {
52842- return copy_to_user((__force void __user *)dst, src,
52843+ return copy_to_user((void __force_user *)dst, src,
52844 sizeof(*dst) * num) ? -EFAULT : 0;
52845 }
52846
52847 static inline int xfer_from_user(void *src, void *dst, size_t len)
52848 {
52849- return copy_from_user(dst, (__force void __user *)src, len) ?
52850+ return copy_from_user(dst, (void __force_user *)src, len) ?
52851 -EFAULT : 0;
52852 }
52853
52854 static inline int xfer_to_user(void *dst, void *src, size_t len)
52855 {
52856- return copy_to_user((__force void __user *)dst, src, len) ?
52857+ return copy_to_user((void __force_user *)dst, src, len) ?
52858 -EFAULT : 0;
52859 }
52860
52861@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52862 vrh->last_used_idx = 0;
52863 vrh->vring.num = num;
52864 /* vring expects kernel addresses, but only used via accessors. */
52865- vrh->vring.desc = (__force struct vring_desc *)desc;
52866- vrh->vring.avail = (__force struct vring_avail *)avail;
52867- vrh->vring.used = (__force struct vring_used *)used;
52868+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52869+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52870+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52871 return 0;
52872 }
52873 EXPORT_SYMBOL(vringh_init_user);
52874@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52875
52876 static inline int putu16_kern(u16 *p, u16 val)
52877 {
52878- ACCESS_ONCE(*p) = val;
52879+ ACCESS_ONCE_RW(*p) = val;
52880 return 0;
52881 }
52882
52883diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52884index 1b0b233..6f34c2c 100644
52885--- a/drivers/video/arcfb.c
52886+++ b/drivers/video/arcfb.c
52887@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52888 return -ENOSPC;
52889
52890 err = 0;
52891- if ((count + p) > fbmemlength) {
52892+ if (count > (fbmemlength - p)) {
52893 count = fbmemlength - p;
52894 err = -ENOSPC;
52895 }
52896diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52897index 52108be..c7c110d 100644
52898--- a/drivers/video/aty/aty128fb.c
52899+++ b/drivers/video/aty/aty128fb.c
52900@@ -149,7 +149,7 @@ enum {
52901 };
52902
52903 /* Must match above enum */
52904-static char * const r128_family[] = {
52905+static const char * const r128_family[] = {
52906 "AGP",
52907 "PCI",
52908 "PRO AGP",
52909diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52910index 28fafbf..ae91651 100644
52911--- a/drivers/video/aty/atyfb_base.c
52912+++ b/drivers/video/aty/atyfb_base.c
52913@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52914 par->accel_flags = var->accel_flags; /* hack */
52915
52916 if (var->accel_flags) {
52917- info->fbops->fb_sync = atyfb_sync;
52918+ pax_open_kernel();
52919+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52920+ pax_close_kernel();
52921 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52922 } else {
52923- info->fbops->fb_sync = NULL;
52924+ pax_open_kernel();
52925+ *(void **)&info->fbops->fb_sync = NULL;
52926+ pax_close_kernel();
52927 info->flags |= FBINFO_HWACCEL_DISABLED;
52928 }
52929
52930diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52931index 0fe02e2..ab01b26 100644
52932--- a/drivers/video/aty/mach64_cursor.c
52933+++ b/drivers/video/aty/mach64_cursor.c
52934@@ -8,6 +8,7 @@
52935 #include "../fb_draw.h"
52936
52937 #include <asm/io.h>
52938+#include <asm/pgtable.h>
52939
52940 #ifdef __sparc__
52941 #include <asm/fbio.h>
52942@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
52943 info->sprite.buf_align = 16; /* and 64 lines tall. */
52944 info->sprite.flags = FB_PIXMAP_IO;
52945
52946- info->fbops->fb_cursor = atyfb_cursor;
52947+ pax_open_kernel();
52948+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52949+ pax_close_kernel();
52950
52951 return 0;
52952 }
52953diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52954index 84a110a..96312c3 100644
52955--- a/drivers/video/backlight/kb3886_bl.c
52956+++ b/drivers/video/backlight/kb3886_bl.c
52957@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52958 static unsigned long kb3886bl_flags;
52959 #define KB3886BL_SUSPENDED 0x01
52960
52961-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52962+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52963 {
52964 .ident = "Sahara Touch-iT",
52965 .matches = {
52966diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52967index 900aa4e..6d49418 100644
52968--- a/drivers/video/fb_defio.c
52969+++ b/drivers/video/fb_defio.c
52970@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52971
52972 BUG_ON(!fbdefio);
52973 mutex_init(&fbdefio->lock);
52974- info->fbops->fb_mmap = fb_deferred_io_mmap;
52975+ pax_open_kernel();
52976+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52977+ pax_close_kernel();
52978 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52979 INIT_LIST_HEAD(&fbdefio->pagelist);
52980 if (fbdefio->delay == 0) /* set a default of 1 s */
52981@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52982 page->mapping = NULL;
52983 }
52984
52985- info->fbops->fb_mmap = NULL;
52986+ *(void **)&info->fbops->fb_mmap = NULL;
52987 mutex_destroy(&fbdefio->lock);
52988 }
52989 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52990diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52991index 7309ac7..be3c49c 100644
52992--- a/drivers/video/fbmem.c
52993+++ b/drivers/video/fbmem.c
52994@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52995 image->dx += image->width + 8;
52996 }
52997 } else if (rotate == FB_ROTATE_UD) {
52998- for (x = 0; x < num && image->dx >= 0; x++) {
52999+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
53000 info->fbops->fb_imageblit(info, image);
53001 image->dx -= image->width + 8;
53002 }
53003@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
53004 image->dy += image->height + 8;
53005 }
53006 } else if (rotate == FB_ROTATE_CCW) {
53007- for (x = 0; x < num && image->dy >= 0; x++) {
53008+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
53009 info->fbops->fb_imageblit(info, image);
53010 image->dy -= image->height + 8;
53011 }
53012@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
53013 return -EFAULT;
53014 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
53015 return -EINVAL;
53016- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
53017+ if (con2fb.framebuffer >= FB_MAX)
53018 return -EINVAL;
53019 if (!registered_fb[con2fb.framebuffer])
53020 request_module("fb%d", con2fb.framebuffer);
53021@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
53022 __u32 data;
53023 int err;
53024
53025- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
53026+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
53027
53028 data = (__u32) (unsigned long) fix->smem_start;
53029 err |= put_user(data, &fix32->smem_start);
53030diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
53031index 130708f..cdac1a9 100644
53032--- a/drivers/video/hyperv_fb.c
53033+++ b/drivers/video/hyperv_fb.c
53034@@ -233,7 +233,7 @@ static uint screen_fb_size;
53035 static inline int synthvid_send(struct hv_device *hdev,
53036 struct synthvid_msg *msg)
53037 {
53038- static atomic64_t request_id = ATOMIC64_INIT(0);
53039+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
53040 int ret;
53041
53042 msg->pipe_hdr.type = PIPE_MSG_DATA;
53043@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
53044
53045 ret = vmbus_sendpacket(hdev->channel, msg,
53046 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
53047- atomic64_inc_return(&request_id),
53048+ atomic64_inc_return_unchecked(&request_id),
53049 VM_PKT_DATA_INBAND, 0);
53050
53051 if (ret)
53052diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
53053index 7672d2e..b56437f 100644
53054--- a/drivers/video/i810/i810_accel.c
53055+++ b/drivers/video/i810/i810_accel.c
53056@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
53057 }
53058 }
53059 printk("ringbuffer lockup!!!\n");
53060+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
53061 i810_report_error(mmio);
53062 par->dev_flags |= LOCKUP;
53063 info->pixmap.scan_align = 1;
53064diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53065index 3c14e43..2630570 100644
53066--- a/drivers/video/logo/logo_linux_clut224.ppm
53067+++ b/drivers/video/logo/logo_linux_clut224.ppm
53068@@ -2,1603 +2,1123 @@ P3
53069 # Standard 224-color Linux logo
53070 80 80
53071 255
53072- 0 0 0 0 0 0 0 0 0 0 0 0
53073- 0 0 0 0 0 0 0 0 0 0 0 0
53074- 0 0 0 0 0 0 0 0 0 0 0 0
53075- 0 0 0 0 0 0 0 0 0 0 0 0
53076- 0 0 0 0 0 0 0 0 0 0 0 0
53077- 0 0 0 0 0 0 0 0 0 0 0 0
53078- 0 0 0 0 0 0 0 0 0 0 0 0
53079- 0 0 0 0 0 0 0 0 0 0 0 0
53080- 0 0 0 0 0 0 0 0 0 0 0 0
53081- 6 6 6 6 6 6 10 10 10 10 10 10
53082- 10 10 10 6 6 6 6 6 6 6 6 6
53083- 0 0 0 0 0 0 0 0 0 0 0 0
53084- 0 0 0 0 0 0 0 0 0 0 0 0
53085- 0 0 0 0 0 0 0 0 0 0 0 0
53086- 0 0 0 0 0 0 0 0 0 0 0 0
53087- 0 0 0 0 0 0 0 0 0 0 0 0
53088- 0 0 0 0 0 0 0 0 0 0 0 0
53089- 0 0 0 0 0 0 0 0 0 0 0 0
53090- 0 0 0 0 0 0 0 0 0 0 0 0
53091- 0 0 0 0 0 0 0 0 0 0 0 0
53092- 0 0 0 0 0 0 0 0 0 0 0 0
53093- 0 0 0 0 0 0 0 0 0 0 0 0
53094- 0 0 0 0 0 0 0 0 0 0 0 0
53095- 0 0 0 0 0 0 0 0 0 0 0 0
53096- 0 0 0 0 0 0 0 0 0 0 0 0
53097- 0 0 0 0 0 0 0 0 0 0 0 0
53098- 0 0 0 0 0 0 0 0 0 0 0 0
53099- 0 0 0 0 0 0 0 0 0 0 0 0
53100- 0 0 0 6 6 6 10 10 10 14 14 14
53101- 22 22 22 26 26 26 30 30 30 34 34 34
53102- 30 30 30 30 30 30 26 26 26 18 18 18
53103- 14 14 14 10 10 10 6 6 6 0 0 0
53104- 0 0 0 0 0 0 0 0 0 0 0 0
53105- 0 0 0 0 0 0 0 0 0 0 0 0
53106- 0 0 0 0 0 0 0 0 0 0 0 0
53107- 0 0 0 0 0 0 0 0 0 0 0 0
53108- 0 0 0 0 0 0 0 0 0 0 0 0
53109- 0 0 0 0 0 0 0 0 0 0 0 0
53110- 0 0 0 0 0 0 0 0 0 0 0 0
53111- 0 0 0 0 0 0 0 0 0 0 0 0
53112- 0 0 0 0 0 0 0 0 0 0 0 0
53113- 0 0 0 0 0 1 0 0 1 0 0 0
53114- 0 0 0 0 0 0 0 0 0 0 0 0
53115- 0 0 0 0 0 0 0 0 0 0 0 0
53116- 0 0 0 0 0 0 0 0 0 0 0 0
53117- 0 0 0 0 0 0 0 0 0 0 0 0
53118- 0 0 0 0 0 0 0 0 0 0 0 0
53119- 0 0 0 0 0 0 0 0 0 0 0 0
53120- 6 6 6 14 14 14 26 26 26 42 42 42
53121- 54 54 54 66 66 66 78 78 78 78 78 78
53122- 78 78 78 74 74 74 66 66 66 54 54 54
53123- 42 42 42 26 26 26 18 18 18 10 10 10
53124- 6 6 6 0 0 0 0 0 0 0 0 0
53125- 0 0 0 0 0 0 0 0 0 0 0 0
53126- 0 0 0 0 0 0 0 0 0 0 0 0
53127- 0 0 0 0 0 0 0 0 0 0 0 0
53128- 0 0 0 0 0 0 0 0 0 0 0 0
53129- 0 0 0 0 0 0 0 0 0 0 0 0
53130- 0 0 0 0 0 0 0 0 0 0 0 0
53131- 0 0 0 0 0 0 0 0 0 0 0 0
53132- 0 0 0 0 0 0 0 0 0 0 0 0
53133- 0 0 1 0 0 0 0 0 0 0 0 0
53134- 0 0 0 0 0 0 0 0 0 0 0 0
53135- 0 0 0 0 0 0 0 0 0 0 0 0
53136- 0 0 0 0 0 0 0 0 0 0 0 0
53137- 0 0 0 0 0 0 0 0 0 0 0 0
53138- 0 0 0 0 0 0 0 0 0 0 0 0
53139- 0 0 0 0 0 0 0 0 0 10 10 10
53140- 22 22 22 42 42 42 66 66 66 86 86 86
53141- 66 66 66 38 38 38 38 38 38 22 22 22
53142- 26 26 26 34 34 34 54 54 54 66 66 66
53143- 86 86 86 70 70 70 46 46 46 26 26 26
53144- 14 14 14 6 6 6 0 0 0 0 0 0
53145- 0 0 0 0 0 0 0 0 0 0 0 0
53146- 0 0 0 0 0 0 0 0 0 0 0 0
53147- 0 0 0 0 0 0 0 0 0 0 0 0
53148- 0 0 0 0 0 0 0 0 0 0 0 0
53149- 0 0 0 0 0 0 0 0 0 0 0 0
53150- 0 0 0 0 0 0 0 0 0 0 0 0
53151- 0 0 0 0 0 0 0 0 0 0 0 0
53152- 0 0 0 0 0 0 0 0 0 0 0 0
53153- 0 0 1 0 0 1 0 0 1 0 0 0
53154- 0 0 0 0 0 0 0 0 0 0 0 0
53155- 0 0 0 0 0 0 0 0 0 0 0 0
53156- 0 0 0 0 0 0 0 0 0 0 0 0
53157- 0 0 0 0 0 0 0 0 0 0 0 0
53158- 0 0 0 0 0 0 0 0 0 0 0 0
53159- 0 0 0 0 0 0 10 10 10 26 26 26
53160- 50 50 50 82 82 82 58 58 58 6 6 6
53161- 2 2 6 2 2 6 2 2 6 2 2 6
53162- 2 2 6 2 2 6 2 2 6 2 2 6
53163- 6 6 6 54 54 54 86 86 86 66 66 66
53164- 38 38 38 18 18 18 6 6 6 0 0 0
53165- 0 0 0 0 0 0 0 0 0 0 0 0
53166- 0 0 0 0 0 0 0 0 0 0 0 0
53167- 0 0 0 0 0 0 0 0 0 0 0 0
53168- 0 0 0 0 0 0 0 0 0 0 0 0
53169- 0 0 0 0 0 0 0 0 0 0 0 0
53170- 0 0 0 0 0 0 0 0 0 0 0 0
53171- 0 0 0 0 0 0 0 0 0 0 0 0
53172- 0 0 0 0 0 0 0 0 0 0 0 0
53173- 0 0 0 0 0 0 0 0 0 0 0 0
53174- 0 0 0 0 0 0 0 0 0 0 0 0
53175- 0 0 0 0 0 0 0 0 0 0 0 0
53176- 0 0 0 0 0 0 0 0 0 0 0 0
53177- 0 0 0 0 0 0 0 0 0 0 0 0
53178- 0 0 0 0 0 0 0 0 0 0 0 0
53179- 0 0 0 6 6 6 22 22 22 50 50 50
53180- 78 78 78 34 34 34 2 2 6 2 2 6
53181- 2 2 6 2 2 6 2 2 6 2 2 6
53182- 2 2 6 2 2 6 2 2 6 2 2 6
53183- 2 2 6 2 2 6 6 6 6 70 70 70
53184- 78 78 78 46 46 46 22 22 22 6 6 6
53185- 0 0 0 0 0 0 0 0 0 0 0 0
53186- 0 0 0 0 0 0 0 0 0 0 0 0
53187- 0 0 0 0 0 0 0 0 0 0 0 0
53188- 0 0 0 0 0 0 0 0 0 0 0 0
53189- 0 0 0 0 0 0 0 0 0 0 0 0
53190- 0 0 0 0 0 0 0 0 0 0 0 0
53191- 0 0 0 0 0 0 0 0 0 0 0 0
53192- 0 0 0 0 0 0 0 0 0 0 0 0
53193- 0 0 1 0 0 1 0 0 1 0 0 0
53194- 0 0 0 0 0 0 0 0 0 0 0 0
53195- 0 0 0 0 0 0 0 0 0 0 0 0
53196- 0 0 0 0 0 0 0 0 0 0 0 0
53197- 0 0 0 0 0 0 0 0 0 0 0 0
53198- 0 0 0 0 0 0 0 0 0 0 0 0
53199- 6 6 6 18 18 18 42 42 42 82 82 82
53200- 26 26 26 2 2 6 2 2 6 2 2 6
53201- 2 2 6 2 2 6 2 2 6 2 2 6
53202- 2 2 6 2 2 6 2 2 6 14 14 14
53203- 46 46 46 34 34 34 6 6 6 2 2 6
53204- 42 42 42 78 78 78 42 42 42 18 18 18
53205- 6 6 6 0 0 0 0 0 0 0 0 0
53206- 0 0 0 0 0 0 0 0 0 0 0 0
53207- 0 0 0 0 0 0 0 0 0 0 0 0
53208- 0 0 0 0 0 0 0 0 0 0 0 0
53209- 0 0 0 0 0 0 0 0 0 0 0 0
53210- 0 0 0 0 0 0 0 0 0 0 0 0
53211- 0 0 0 0 0 0 0 0 0 0 0 0
53212- 0 0 0 0 0 0 0 0 0 0 0 0
53213- 0 0 1 0 0 0 0 0 1 0 0 0
53214- 0 0 0 0 0 0 0 0 0 0 0 0
53215- 0 0 0 0 0 0 0 0 0 0 0 0
53216- 0 0 0 0 0 0 0 0 0 0 0 0
53217- 0 0 0 0 0 0 0 0 0 0 0 0
53218- 0 0 0 0 0 0 0 0 0 0 0 0
53219- 10 10 10 30 30 30 66 66 66 58 58 58
53220- 2 2 6 2 2 6 2 2 6 2 2 6
53221- 2 2 6 2 2 6 2 2 6 2 2 6
53222- 2 2 6 2 2 6 2 2 6 26 26 26
53223- 86 86 86 101 101 101 46 46 46 10 10 10
53224- 2 2 6 58 58 58 70 70 70 34 34 34
53225- 10 10 10 0 0 0 0 0 0 0 0 0
53226- 0 0 0 0 0 0 0 0 0 0 0 0
53227- 0 0 0 0 0 0 0 0 0 0 0 0
53228- 0 0 0 0 0 0 0 0 0 0 0 0
53229- 0 0 0 0 0 0 0 0 0 0 0 0
53230- 0 0 0 0 0 0 0 0 0 0 0 0
53231- 0 0 0 0 0 0 0 0 0 0 0 0
53232- 0 0 0 0 0 0 0 0 0 0 0 0
53233- 0 0 1 0 0 1 0 0 1 0 0 0
53234- 0 0 0 0 0 0 0 0 0 0 0 0
53235- 0 0 0 0 0 0 0 0 0 0 0 0
53236- 0 0 0 0 0 0 0 0 0 0 0 0
53237- 0 0 0 0 0 0 0 0 0 0 0 0
53238- 0 0 0 0 0 0 0 0 0 0 0 0
53239- 14 14 14 42 42 42 86 86 86 10 10 10
53240- 2 2 6 2 2 6 2 2 6 2 2 6
53241- 2 2 6 2 2 6 2 2 6 2 2 6
53242- 2 2 6 2 2 6 2 2 6 30 30 30
53243- 94 94 94 94 94 94 58 58 58 26 26 26
53244- 2 2 6 6 6 6 78 78 78 54 54 54
53245- 22 22 22 6 6 6 0 0 0 0 0 0
53246- 0 0 0 0 0 0 0 0 0 0 0 0
53247- 0 0 0 0 0 0 0 0 0 0 0 0
53248- 0 0 0 0 0 0 0 0 0 0 0 0
53249- 0 0 0 0 0 0 0 0 0 0 0 0
53250- 0 0 0 0 0 0 0 0 0 0 0 0
53251- 0 0 0 0 0 0 0 0 0 0 0 0
53252- 0 0 0 0 0 0 0 0 0 0 0 0
53253- 0 0 0 0 0 0 0 0 0 0 0 0
53254- 0 0 0 0 0 0 0 0 0 0 0 0
53255- 0 0 0 0 0 0 0 0 0 0 0 0
53256- 0 0 0 0 0 0 0 0 0 0 0 0
53257- 0 0 0 0 0 0 0 0 0 0 0 0
53258- 0 0 0 0 0 0 0 0 0 6 6 6
53259- 22 22 22 62 62 62 62 62 62 2 2 6
53260- 2 2 6 2 2 6 2 2 6 2 2 6
53261- 2 2 6 2 2 6 2 2 6 2 2 6
53262- 2 2 6 2 2 6 2 2 6 26 26 26
53263- 54 54 54 38 38 38 18 18 18 10 10 10
53264- 2 2 6 2 2 6 34 34 34 82 82 82
53265- 38 38 38 14 14 14 0 0 0 0 0 0
53266- 0 0 0 0 0 0 0 0 0 0 0 0
53267- 0 0 0 0 0 0 0 0 0 0 0 0
53268- 0 0 0 0 0 0 0 0 0 0 0 0
53269- 0 0 0 0 0 0 0 0 0 0 0 0
53270- 0 0 0 0 0 0 0 0 0 0 0 0
53271- 0 0 0 0 0 0 0 0 0 0 0 0
53272- 0 0 0 0 0 0 0 0 0 0 0 0
53273- 0 0 0 0 0 1 0 0 1 0 0 0
53274- 0 0 0 0 0 0 0 0 0 0 0 0
53275- 0 0 0 0 0 0 0 0 0 0 0 0
53276- 0 0 0 0 0 0 0 0 0 0 0 0
53277- 0 0 0 0 0 0 0 0 0 0 0 0
53278- 0 0 0 0 0 0 0 0 0 6 6 6
53279- 30 30 30 78 78 78 30 30 30 2 2 6
53280- 2 2 6 2 2 6 2 2 6 2 2 6
53281- 2 2 6 2 2 6 2 2 6 2 2 6
53282- 2 2 6 2 2 6 2 2 6 10 10 10
53283- 10 10 10 2 2 6 2 2 6 2 2 6
53284- 2 2 6 2 2 6 2 2 6 78 78 78
53285- 50 50 50 18 18 18 6 6 6 0 0 0
53286- 0 0 0 0 0 0 0 0 0 0 0 0
53287- 0 0 0 0 0 0 0 0 0 0 0 0
53288- 0 0 0 0 0 0 0 0 0 0 0 0
53289- 0 0 0 0 0 0 0 0 0 0 0 0
53290- 0 0 0 0 0 0 0 0 0 0 0 0
53291- 0 0 0 0 0 0 0 0 0 0 0 0
53292- 0 0 0 0 0 0 0 0 0 0 0 0
53293- 0 0 1 0 0 0 0 0 0 0 0 0
53294- 0 0 0 0 0 0 0 0 0 0 0 0
53295- 0 0 0 0 0 0 0 0 0 0 0 0
53296- 0 0 0 0 0 0 0 0 0 0 0 0
53297- 0 0 0 0 0 0 0 0 0 0 0 0
53298- 0 0 0 0 0 0 0 0 0 10 10 10
53299- 38 38 38 86 86 86 14 14 14 2 2 6
53300- 2 2 6 2 2 6 2 2 6 2 2 6
53301- 2 2 6 2 2 6 2 2 6 2 2 6
53302- 2 2 6 2 2 6 2 2 6 2 2 6
53303- 2 2 6 2 2 6 2 2 6 2 2 6
53304- 2 2 6 2 2 6 2 2 6 54 54 54
53305- 66 66 66 26 26 26 6 6 6 0 0 0
53306- 0 0 0 0 0 0 0 0 0 0 0 0
53307- 0 0 0 0 0 0 0 0 0 0 0 0
53308- 0 0 0 0 0 0 0 0 0 0 0 0
53309- 0 0 0 0 0 0 0 0 0 0 0 0
53310- 0 0 0 0 0 0 0 0 0 0 0 0
53311- 0 0 0 0 0 0 0 0 0 0 0 0
53312- 0 0 0 0 0 0 0 0 0 0 0 0
53313- 0 0 0 0 0 1 0 0 1 0 0 0
53314- 0 0 0 0 0 0 0 0 0 0 0 0
53315- 0 0 0 0 0 0 0 0 0 0 0 0
53316- 0 0 0 0 0 0 0 0 0 0 0 0
53317- 0 0 0 0 0 0 0 0 0 0 0 0
53318- 0 0 0 0 0 0 0 0 0 14 14 14
53319- 42 42 42 82 82 82 2 2 6 2 2 6
53320- 2 2 6 6 6 6 10 10 10 2 2 6
53321- 2 2 6 2 2 6 2 2 6 2 2 6
53322- 2 2 6 2 2 6 2 2 6 6 6 6
53323- 14 14 14 10 10 10 2 2 6 2 2 6
53324- 2 2 6 2 2 6 2 2 6 18 18 18
53325- 82 82 82 34 34 34 10 10 10 0 0 0
53326- 0 0 0 0 0 0 0 0 0 0 0 0
53327- 0 0 0 0 0 0 0 0 0 0 0 0
53328- 0 0 0 0 0 0 0 0 0 0 0 0
53329- 0 0 0 0 0 0 0 0 0 0 0 0
53330- 0 0 0 0 0 0 0 0 0 0 0 0
53331- 0 0 0 0 0 0 0 0 0 0 0 0
53332- 0 0 0 0 0 0 0 0 0 0 0 0
53333- 0 0 1 0 0 0 0 0 0 0 0 0
53334- 0 0 0 0 0 0 0 0 0 0 0 0
53335- 0 0 0 0 0 0 0 0 0 0 0 0
53336- 0 0 0 0 0 0 0 0 0 0 0 0
53337- 0 0 0 0 0 0 0 0 0 0 0 0
53338- 0 0 0 0 0 0 0 0 0 14 14 14
53339- 46 46 46 86 86 86 2 2 6 2 2 6
53340- 6 6 6 6 6 6 22 22 22 34 34 34
53341- 6 6 6 2 2 6 2 2 6 2 2 6
53342- 2 2 6 2 2 6 18 18 18 34 34 34
53343- 10 10 10 50 50 50 22 22 22 2 2 6
53344- 2 2 6 2 2 6 2 2 6 10 10 10
53345- 86 86 86 42 42 42 14 14 14 0 0 0
53346- 0 0 0 0 0 0 0 0 0 0 0 0
53347- 0 0 0 0 0 0 0 0 0 0 0 0
53348- 0 0 0 0 0 0 0 0 0 0 0 0
53349- 0 0 0 0 0 0 0 0 0 0 0 0
53350- 0 0 0 0 0 0 0 0 0 0 0 0
53351- 0 0 0 0 0 0 0 0 0 0 0 0
53352- 0 0 0 0 0 0 0 0 0 0 0 0
53353- 0 0 1 0 0 1 0 0 1 0 0 0
53354- 0 0 0 0 0 0 0 0 0 0 0 0
53355- 0 0 0 0 0 0 0 0 0 0 0 0
53356- 0 0 0 0 0 0 0 0 0 0 0 0
53357- 0 0 0 0 0 0 0 0 0 0 0 0
53358- 0 0 0 0 0 0 0 0 0 14 14 14
53359- 46 46 46 86 86 86 2 2 6 2 2 6
53360- 38 38 38 116 116 116 94 94 94 22 22 22
53361- 22 22 22 2 2 6 2 2 6 2 2 6
53362- 14 14 14 86 86 86 138 138 138 162 162 162
53363-154 154 154 38 38 38 26 26 26 6 6 6
53364- 2 2 6 2 2 6 2 2 6 2 2 6
53365- 86 86 86 46 46 46 14 14 14 0 0 0
53366- 0 0 0 0 0 0 0 0 0 0 0 0
53367- 0 0 0 0 0 0 0 0 0 0 0 0
53368- 0 0 0 0 0 0 0 0 0 0 0 0
53369- 0 0 0 0 0 0 0 0 0 0 0 0
53370- 0 0 0 0 0 0 0 0 0 0 0 0
53371- 0 0 0 0 0 0 0 0 0 0 0 0
53372- 0 0 0 0 0 0 0 0 0 0 0 0
53373- 0 0 0 0 0 0 0 0 0 0 0 0
53374- 0 0 0 0 0 0 0 0 0 0 0 0
53375- 0 0 0 0 0 0 0 0 0 0 0 0
53376- 0 0 0 0 0 0 0 0 0 0 0 0
53377- 0 0 0 0 0 0 0 0 0 0 0 0
53378- 0 0 0 0 0 0 0 0 0 14 14 14
53379- 46 46 46 86 86 86 2 2 6 14 14 14
53380-134 134 134 198 198 198 195 195 195 116 116 116
53381- 10 10 10 2 2 6 2 2 6 6 6 6
53382-101 98 89 187 187 187 210 210 210 218 218 218
53383-214 214 214 134 134 134 14 14 14 6 6 6
53384- 2 2 6 2 2 6 2 2 6 2 2 6
53385- 86 86 86 50 50 50 18 18 18 6 6 6
53386- 0 0 0 0 0 0 0 0 0 0 0 0
53387- 0 0 0 0 0 0 0 0 0 0 0 0
53388- 0 0 0 0 0 0 0 0 0 0 0 0
53389- 0 0 0 0 0 0 0 0 0 0 0 0
53390- 0 0 0 0 0 0 0 0 0 0 0 0
53391- 0 0 0 0 0 0 0 0 0 0 0 0
53392- 0 0 0 0 0 0 0 0 1 0 0 0
53393- 0 0 1 0 0 1 0 0 1 0 0 0
53394- 0 0 0 0 0 0 0 0 0 0 0 0
53395- 0 0 0 0 0 0 0 0 0 0 0 0
53396- 0 0 0 0 0 0 0 0 0 0 0 0
53397- 0 0 0 0 0 0 0 0 0 0 0 0
53398- 0 0 0 0 0 0 0 0 0 14 14 14
53399- 46 46 46 86 86 86 2 2 6 54 54 54
53400-218 218 218 195 195 195 226 226 226 246 246 246
53401- 58 58 58 2 2 6 2 2 6 30 30 30
53402-210 210 210 253 253 253 174 174 174 123 123 123
53403-221 221 221 234 234 234 74 74 74 2 2 6
53404- 2 2 6 2 2 6 2 2 6 2 2 6
53405- 70 70 70 58 58 58 22 22 22 6 6 6
53406- 0 0 0 0 0 0 0 0 0 0 0 0
53407- 0 0 0 0 0 0 0 0 0 0 0 0
53408- 0 0 0 0 0 0 0 0 0 0 0 0
53409- 0 0 0 0 0 0 0 0 0 0 0 0
53410- 0 0 0 0 0 0 0 0 0 0 0 0
53411- 0 0 0 0 0 0 0 0 0 0 0 0
53412- 0 0 0 0 0 0 0 0 0 0 0 0
53413- 0 0 0 0 0 0 0 0 0 0 0 0
53414- 0 0 0 0 0 0 0 0 0 0 0 0
53415- 0 0 0 0 0 0 0 0 0 0 0 0
53416- 0 0 0 0 0 0 0 0 0 0 0 0
53417- 0 0 0 0 0 0 0 0 0 0 0 0
53418- 0 0 0 0 0 0 0 0 0 14 14 14
53419- 46 46 46 82 82 82 2 2 6 106 106 106
53420-170 170 170 26 26 26 86 86 86 226 226 226
53421-123 123 123 10 10 10 14 14 14 46 46 46
53422-231 231 231 190 190 190 6 6 6 70 70 70
53423- 90 90 90 238 238 238 158 158 158 2 2 6
53424- 2 2 6 2 2 6 2 2 6 2 2 6
53425- 70 70 70 58 58 58 22 22 22 6 6 6
53426- 0 0 0 0 0 0 0 0 0 0 0 0
53427- 0 0 0 0 0 0 0 0 0 0 0 0
53428- 0 0 0 0 0 0 0 0 0 0 0 0
53429- 0 0 0 0 0 0 0 0 0 0 0 0
53430- 0 0 0 0 0 0 0 0 0 0 0 0
53431- 0 0 0 0 0 0 0 0 0 0 0 0
53432- 0 0 0 0 0 0 0 0 1 0 0 0
53433- 0 0 1 0 0 1 0 0 1 0 0 0
53434- 0 0 0 0 0 0 0 0 0 0 0 0
53435- 0 0 0 0 0 0 0 0 0 0 0 0
53436- 0 0 0 0 0 0 0 0 0 0 0 0
53437- 0 0 0 0 0 0 0 0 0 0 0 0
53438- 0 0 0 0 0 0 0 0 0 14 14 14
53439- 42 42 42 86 86 86 6 6 6 116 116 116
53440-106 106 106 6 6 6 70 70 70 149 149 149
53441-128 128 128 18 18 18 38 38 38 54 54 54
53442-221 221 221 106 106 106 2 2 6 14 14 14
53443- 46 46 46 190 190 190 198 198 198 2 2 6
53444- 2 2 6 2 2 6 2 2 6 2 2 6
53445- 74 74 74 62 62 62 22 22 22 6 6 6
53446- 0 0 0 0 0 0 0 0 0 0 0 0
53447- 0 0 0 0 0 0 0 0 0 0 0 0
53448- 0 0 0 0 0 0 0 0 0 0 0 0
53449- 0 0 0 0 0 0 0 0 0 0 0 0
53450- 0 0 0 0 0 0 0 0 0 0 0 0
53451- 0 0 0 0 0 0 0 0 0 0 0 0
53452- 0 0 0 0 0 0 0 0 1 0 0 0
53453- 0 0 1 0 0 0 0 0 1 0 0 0
53454- 0 0 0 0 0 0 0 0 0 0 0 0
53455- 0 0 0 0 0 0 0 0 0 0 0 0
53456- 0 0 0 0 0 0 0 0 0 0 0 0
53457- 0 0 0 0 0 0 0 0 0 0 0 0
53458- 0 0 0 0 0 0 0 0 0 14 14 14
53459- 42 42 42 94 94 94 14 14 14 101 101 101
53460-128 128 128 2 2 6 18 18 18 116 116 116
53461-118 98 46 121 92 8 121 92 8 98 78 10
53462-162 162 162 106 106 106 2 2 6 2 2 6
53463- 2 2 6 195 195 195 195 195 195 6 6 6
53464- 2 2 6 2 2 6 2 2 6 2 2 6
53465- 74 74 74 62 62 62 22 22 22 6 6 6
53466- 0 0 0 0 0 0 0 0 0 0 0 0
53467- 0 0 0 0 0 0 0 0 0 0 0 0
53468- 0 0 0 0 0 0 0 0 0 0 0 0
53469- 0 0 0 0 0 0 0 0 0 0 0 0
53470- 0 0 0 0 0 0 0 0 0 0 0 0
53471- 0 0 0 0 0 0 0 0 0 0 0 0
53472- 0 0 0 0 0 0 0 0 1 0 0 1
53473- 0 0 1 0 0 0 0 0 1 0 0 0
53474- 0 0 0 0 0 0 0 0 0 0 0 0
53475- 0 0 0 0 0 0 0 0 0 0 0 0
53476- 0 0 0 0 0 0 0 0 0 0 0 0
53477- 0 0 0 0 0 0 0 0 0 0 0 0
53478- 0 0 0 0 0 0 0 0 0 10 10 10
53479- 38 38 38 90 90 90 14 14 14 58 58 58
53480-210 210 210 26 26 26 54 38 6 154 114 10
53481-226 170 11 236 186 11 225 175 15 184 144 12
53482-215 174 15 175 146 61 37 26 9 2 2 6
53483- 70 70 70 246 246 246 138 138 138 2 2 6
53484- 2 2 6 2 2 6 2 2 6 2 2 6
53485- 70 70 70 66 66 66 26 26 26 6 6 6
53486- 0 0 0 0 0 0 0 0 0 0 0 0
53487- 0 0 0 0 0 0 0 0 0 0 0 0
53488- 0 0 0 0 0 0 0 0 0 0 0 0
53489- 0 0 0 0 0 0 0 0 0 0 0 0
53490- 0 0 0 0 0 0 0 0 0 0 0 0
53491- 0 0 0 0 0 0 0 0 0 0 0 0
53492- 0 0 0 0 0 0 0 0 0 0 0 0
53493- 0 0 0 0 0 0 0 0 0 0 0 0
53494- 0 0 0 0 0 0 0 0 0 0 0 0
53495- 0 0 0 0 0 0 0 0 0 0 0 0
53496- 0 0 0 0 0 0 0 0 0 0 0 0
53497- 0 0 0 0 0 0 0 0 0 0 0 0
53498- 0 0 0 0 0 0 0 0 0 10 10 10
53499- 38 38 38 86 86 86 14 14 14 10 10 10
53500-195 195 195 188 164 115 192 133 9 225 175 15
53501-239 182 13 234 190 10 232 195 16 232 200 30
53502-245 207 45 241 208 19 232 195 16 184 144 12
53503-218 194 134 211 206 186 42 42 42 2 2 6
53504- 2 2 6 2 2 6 2 2 6 2 2 6
53505- 50 50 50 74 74 74 30 30 30 6 6 6
53506- 0 0 0 0 0 0 0 0 0 0 0 0
53507- 0 0 0 0 0 0 0 0 0 0 0 0
53508- 0 0 0 0 0 0 0 0 0 0 0 0
53509- 0 0 0 0 0 0 0 0 0 0 0 0
53510- 0 0 0 0 0 0 0 0 0 0 0 0
53511- 0 0 0 0 0 0 0 0 0 0 0 0
53512- 0 0 0 0 0 0 0 0 0 0 0 0
53513- 0 0 0 0 0 0 0 0 0 0 0 0
53514- 0 0 0 0 0 0 0 0 0 0 0 0
53515- 0 0 0 0 0 0 0 0 0 0 0 0
53516- 0 0 0 0 0 0 0 0 0 0 0 0
53517- 0 0 0 0 0 0 0 0 0 0 0 0
53518- 0 0 0 0 0 0 0 0 0 10 10 10
53519- 34 34 34 86 86 86 14 14 14 2 2 6
53520-121 87 25 192 133 9 219 162 10 239 182 13
53521-236 186 11 232 195 16 241 208 19 244 214 54
53522-246 218 60 246 218 38 246 215 20 241 208 19
53523-241 208 19 226 184 13 121 87 25 2 2 6
53524- 2 2 6 2 2 6 2 2 6 2 2 6
53525- 50 50 50 82 82 82 34 34 34 10 10 10
53526- 0 0 0 0 0 0 0 0 0 0 0 0
53527- 0 0 0 0 0 0 0 0 0 0 0 0
53528- 0 0 0 0 0 0 0 0 0 0 0 0
53529- 0 0 0 0 0 0 0 0 0 0 0 0
53530- 0 0 0 0 0 0 0 0 0 0 0 0
53531- 0 0 0 0 0 0 0 0 0 0 0 0
53532- 0 0 0 0 0 0 0 0 0 0 0 0
53533- 0 0 0 0 0 0 0 0 0 0 0 0
53534- 0 0 0 0 0 0 0 0 0 0 0 0
53535- 0 0 0 0 0 0 0 0 0 0 0 0
53536- 0 0 0 0 0 0 0 0 0 0 0 0
53537- 0 0 0 0 0 0 0 0 0 0 0 0
53538- 0 0 0 0 0 0 0 0 0 10 10 10
53539- 34 34 34 82 82 82 30 30 30 61 42 6
53540-180 123 7 206 145 10 230 174 11 239 182 13
53541-234 190 10 238 202 15 241 208 19 246 218 74
53542-246 218 38 246 215 20 246 215 20 246 215 20
53543-226 184 13 215 174 15 184 144 12 6 6 6
53544- 2 2 6 2 2 6 2 2 6 2 2 6
53545- 26 26 26 94 94 94 42 42 42 14 14 14
53546- 0 0 0 0 0 0 0 0 0 0 0 0
53547- 0 0 0 0 0 0 0 0 0 0 0 0
53548- 0 0 0 0 0 0 0 0 0 0 0 0
53549- 0 0 0 0 0 0 0 0 0 0 0 0
53550- 0 0 0 0 0 0 0 0 0 0 0 0
53551- 0 0 0 0 0 0 0 0 0 0 0 0
53552- 0 0 0 0 0 0 0 0 0 0 0 0
53553- 0 0 0 0 0 0 0 0 0 0 0 0
53554- 0 0 0 0 0 0 0 0 0 0 0 0
53555- 0 0 0 0 0 0 0 0 0 0 0 0
53556- 0 0 0 0 0 0 0 0 0 0 0 0
53557- 0 0 0 0 0 0 0 0 0 0 0 0
53558- 0 0 0 0 0 0 0 0 0 10 10 10
53559- 30 30 30 78 78 78 50 50 50 104 69 6
53560-192 133 9 216 158 10 236 178 12 236 186 11
53561-232 195 16 241 208 19 244 214 54 245 215 43
53562-246 215 20 246 215 20 241 208 19 198 155 10
53563-200 144 11 216 158 10 156 118 10 2 2 6
53564- 2 2 6 2 2 6 2 2 6 2 2 6
53565- 6 6 6 90 90 90 54 54 54 18 18 18
53566- 6 6 6 0 0 0 0 0 0 0 0 0
53567- 0 0 0 0 0 0 0 0 0 0 0 0
53568- 0 0 0 0 0 0 0 0 0 0 0 0
53569- 0 0 0 0 0 0 0 0 0 0 0 0
53570- 0 0 0 0 0 0 0 0 0 0 0 0
53571- 0 0 0 0 0 0 0 0 0 0 0 0
53572- 0 0 0 0 0 0 0 0 0 0 0 0
53573- 0 0 0 0 0 0 0 0 0 0 0 0
53574- 0 0 0 0 0 0 0 0 0 0 0 0
53575- 0 0 0 0 0 0 0 0 0 0 0 0
53576- 0 0 0 0 0 0 0 0 0 0 0 0
53577- 0 0 0 0 0 0 0 0 0 0 0 0
53578- 0 0 0 0 0 0 0 0 0 10 10 10
53579- 30 30 30 78 78 78 46 46 46 22 22 22
53580-137 92 6 210 162 10 239 182 13 238 190 10
53581-238 202 15 241 208 19 246 215 20 246 215 20
53582-241 208 19 203 166 17 185 133 11 210 150 10
53583-216 158 10 210 150 10 102 78 10 2 2 6
53584- 6 6 6 54 54 54 14 14 14 2 2 6
53585- 2 2 6 62 62 62 74 74 74 30 30 30
53586- 10 10 10 0 0 0 0 0 0 0 0 0
53587- 0 0 0 0 0 0 0 0 0 0 0 0
53588- 0 0 0 0 0 0 0 0 0 0 0 0
53589- 0 0 0 0 0 0 0 0 0 0 0 0
53590- 0 0 0 0 0 0 0 0 0 0 0 0
53591- 0 0 0 0 0 0 0 0 0 0 0 0
53592- 0 0 0 0 0 0 0 0 0 0 0 0
53593- 0 0 0 0 0 0 0 0 0 0 0 0
53594- 0 0 0 0 0 0 0 0 0 0 0 0
53595- 0 0 0 0 0 0 0 0 0 0 0 0
53596- 0 0 0 0 0 0 0 0 0 0 0 0
53597- 0 0 0 0 0 0 0 0 0 0 0 0
53598- 0 0 0 0 0 0 0 0 0 10 10 10
53599- 34 34 34 78 78 78 50 50 50 6 6 6
53600- 94 70 30 139 102 15 190 146 13 226 184 13
53601-232 200 30 232 195 16 215 174 15 190 146 13
53602-168 122 10 192 133 9 210 150 10 213 154 11
53603-202 150 34 182 157 106 101 98 89 2 2 6
53604- 2 2 6 78 78 78 116 116 116 58 58 58
53605- 2 2 6 22 22 22 90 90 90 46 46 46
53606- 18 18 18 6 6 6 0 0 0 0 0 0
53607- 0 0 0 0 0 0 0 0 0 0 0 0
53608- 0 0 0 0 0 0 0 0 0 0 0 0
53609- 0 0 0 0 0 0 0 0 0 0 0 0
53610- 0 0 0 0 0 0 0 0 0 0 0 0
53611- 0 0 0 0 0 0 0 0 0 0 0 0
53612- 0 0 0 0 0 0 0 0 0 0 0 0
53613- 0 0 0 0 0 0 0 0 0 0 0 0
53614- 0 0 0 0 0 0 0 0 0 0 0 0
53615- 0 0 0 0 0 0 0 0 0 0 0 0
53616- 0 0 0 0 0 0 0 0 0 0 0 0
53617- 0 0 0 0 0 0 0 0 0 0 0 0
53618- 0 0 0 0 0 0 0 0 0 10 10 10
53619- 38 38 38 86 86 86 50 50 50 6 6 6
53620-128 128 128 174 154 114 156 107 11 168 122 10
53621-198 155 10 184 144 12 197 138 11 200 144 11
53622-206 145 10 206 145 10 197 138 11 188 164 115
53623-195 195 195 198 198 198 174 174 174 14 14 14
53624- 2 2 6 22 22 22 116 116 116 116 116 116
53625- 22 22 22 2 2 6 74 74 74 70 70 70
53626- 30 30 30 10 10 10 0 0 0 0 0 0
53627- 0 0 0 0 0 0 0 0 0 0 0 0
53628- 0 0 0 0 0 0 0 0 0 0 0 0
53629- 0 0 0 0 0 0 0 0 0 0 0 0
53630- 0 0 0 0 0 0 0 0 0 0 0 0
53631- 0 0 0 0 0 0 0 0 0 0 0 0
53632- 0 0 0 0 0 0 0 0 0 0 0 0
53633- 0 0 0 0 0 0 0 0 0 0 0 0
53634- 0 0 0 0 0 0 0 0 0 0 0 0
53635- 0 0 0 0 0 0 0 0 0 0 0 0
53636- 0 0 0 0 0 0 0 0 0 0 0 0
53637- 0 0 0 0 0 0 0 0 0 0 0 0
53638- 0 0 0 0 0 0 6 6 6 18 18 18
53639- 50 50 50 101 101 101 26 26 26 10 10 10
53640-138 138 138 190 190 190 174 154 114 156 107 11
53641-197 138 11 200 144 11 197 138 11 192 133 9
53642-180 123 7 190 142 34 190 178 144 187 187 187
53643-202 202 202 221 221 221 214 214 214 66 66 66
53644- 2 2 6 2 2 6 50 50 50 62 62 62
53645- 6 6 6 2 2 6 10 10 10 90 90 90
53646- 50 50 50 18 18 18 6 6 6 0 0 0
53647- 0 0 0 0 0 0 0 0 0 0 0 0
53648- 0 0 0 0 0 0 0 0 0 0 0 0
53649- 0 0 0 0 0 0 0 0 0 0 0 0
53650- 0 0 0 0 0 0 0 0 0 0 0 0
53651- 0 0 0 0 0 0 0 0 0 0 0 0
53652- 0 0 0 0 0 0 0 0 0 0 0 0
53653- 0 0 0 0 0 0 0 0 0 0 0 0
53654- 0 0 0 0 0 0 0 0 0 0 0 0
53655- 0 0 0 0 0 0 0 0 0 0 0 0
53656- 0 0 0 0 0 0 0 0 0 0 0 0
53657- 0 0 0 0 0 0 0 0 0 0 0 0
53658- 0 0 0 0 0 0 10 10 10 34 34 34
53659- 74 74 74 74 74 74 2 2 6 6 6 6
53660-144 144 144 198 198 198 190 190 190 178 166 146
53661-154 121 60 156 107 11 156 107 11 168 124 44
53662-174 154 114 187 187 187 190 190 190 210 210 210
53663-246 246 246 253 253 253 253 253 253 182 182 182
53664- 6 6 6 2 2 6 2 2 6 2 2 6
53665- 2 2 6 2 2 6 2 2 6 62 62 62
53666- 74 74 74 34 34 34 14 14 14 0 0 0
53667- 0 0 0 0 0 0 0 0 0 0 0 0
53668- 0 0 0 0 0 0 0 0 0 0 0 0
53669- 0 0 0 0 0 0 0 0 0 0 0 0
53670- 0 0 0 0 0 0 0 0 0 0 0 0
53671- 0 0 0 0 0 0 0 0 0 0 0 0
53672- 0 0 0 0 0 0 0 0 0 0 0 0
53673- 0 0 0 0 0 0 0 0 0 0 0 0
53674- 0 0 0 0 0 0 0 0 0 0 0 0
53675- 0 0 0 0 0 0 0 0 0 0 0 0
53676- 0 0 0 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 10 10 10 22 22 22 54 54 54
53679- 94 94 94 18 18 18 2 2 6 46 46 46
53680-234 234 234 221 221 221 190 190 190 190 190 190
53681-190 190 190 187 187 187 187 187 187 190 190 190
53682-190 190 190 195 195 195 214 214 214 242 242 242
53683-253 253 253 253 253 253 253 253 253 253 253 253
53684- 82 82 82 2 2 6 2 2 6 2 2 6
53685- 2 2 6 2 2 6 2 2 6 14 14 14
53686- 86 86 86 54 54 54 22 22 22 6 6 6
53687- 0 0 0 0 0 0 0 0 0 0 0 0
53688- 0 0 0 0 0 0 0 0 0 0 0 0
53689- 0 0 0 0 0 0 0 0 0 0 0 0
53690- 0 0 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- 6 6 6 18 18 18 46 46 46 90 90 90
53699- 46 46 46 18 18 18 6 6 6 182 182 182
53700-253 253 253 246 246 246 206 206 206 190 190 190
53701-190 190 190 190 190 190 190 190 190 190 190 190
53702-206 206 206 231 231 231 250 250 250 253 253 253
53703-253 253 253 253 253 253 253 253 253 253 253 253
53704-202 202 202 14 14 14 2 2 6 2 2 6
53705- 2 2 6 2 2 6 2 2 6 2 2 6
53706- 42 42 42 86 86 86 42 42 42 18 18 18
53707- 6 6 6 0 0 0 0 0 0 0 0 0
53708- 0 0 0 0 0 0 0 0 0 0 0 0
53709- 0 0 0 0 0 0 0 0 0 0 0 0
53710- 0 0 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 6 6 6
53718- 14 14 14 38 38 38 74 74 74 66 66 66
53719- 2 2 6 6 6 6 90 90 90 250 250 250
53720-253 253 253 253 253 253 238 238 238 198 198 198
53721-190 190 190 190 190 190 195 195 195 221 221 221
53722-246 246 246 253 253 253 253 253 253 253 253 253
53723-253 253 253 253 253 253 253 253 253 253 253 253
53724-253 253 253 82 82 82 2 2 6 2 2 6
53725- 2 2 6 2 2 6 2 2 6 2 2 6
53726- 2 2 6 78 78 78 70 70 70 34 34 34
53727- 14 14 14 6 6 6 0 0 0 0 0 0
53728- 0 0 0 0 0 0 0 0 0 0 0 0
53729- 0 0 0 0 0 0 0 0 0 0 0 0
53730- 0 0 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 14 14 14
53738- 34 34 34 66 66 66 78 78 78 6 6 6
53739- 2 2 6 18 18 18 218 218 218 253 253 253
53740-253 253 253 253 253 253 253 253 253 246 246 246
53741-226 226 226 231 231 231 246 246 246 253 253 253
53742-253 253 253 253 253 253 253 253 253 253 253 253
53743-253 253 253 253 253 253 253 253 253 253 253 253
53744-253 253 253 178 178 178 2 2 6 2 2 6
53745- 2 2 6 2 2 6 2 2 6 2 2 6
53746- 2 2 6 18 18 18 90 90 90 62 62 62
53747- 30 30 30 10 10 10 0 0 0 0 0 0
53748- 0 0 0 0 0 0 0 0 0 0 0 0
53749- 0 0 0 0 0 0 0 0 0 0 0 0
53750- 0 0 0 0 0 0 0 0 0 0 0 0
53751- 0 0 0 0 0 0 0 0 0 0 0 0
53752- 0 0 0 0 0 0 0 0 0 0 0 0
53753- 0 0 0 0 0 0 0 0 0 0 0 0
53754- 0 0 0 0 0 0 0 0 0 0 0 0
53755- 0 0 0 0 0 0 0 0 0 0 0 0
53756- 0 0 0 0 0 0 0 0 0 0 0 0
53757- 0 0 0 0 0 0 10 10 10 26 26 26
53758- 58 58 58 90 90 90 18 18 18 2 2 6
53759- 2 2 6 110 110 110 253 253 253 253 253 253
53760-253 253 253 253 253 253 253 253 253 253 253 253
53761-250 250 250 253 253 253 253 253 253 253 253 253
53762-253 253 253 253 253 253 253 253 253 253 253 253
53763-253 253 253 253 253 253 253 253 253 253 253 253
53764-253 253 253 231 231 231 18 18 18 2 2 6
53765- 2 2 6 2 2 6 2 2 6 2 2 6
53766- 2 2 6 2 2 6 18 18 18 94 94 94
53767- 54 54 54 26 26 26 10 10 10 0 0 0
53768- 0 0 0 0 0 0 0 0 0 0 0 0
53769- 0 0 0 0 0 0 0 0 0 0 0 0
53770- 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
53778- 90 90 90 26 26 26 2 2 6 2 2 6
53779- 14 14 14 195 195 195 250 250 250 253 253 253
53780-253 253 253 253 253 253 253 253 253 253 253 253
53781-253 253 253 253 253 253 253 253 253 253 253 253
53782-253 253 253 253 253 253 253 253 253 253 253 253
53783-253 253 253 253 253 253 253 253 253 253 253 253
53784-250 250 250 242 242 242 54 54 54 2 2 6
53785- 2 2 6 2 2 6 2 2 6 2 2 6
53786- 2 2 6 2 2 6 2 2 6 38 38 38
53787- 86 86 86 50 50 50 22 22 22 6 6 6
53788- 0 0 0 0 0 0 0 0 0 0 0 0
53789- 0 0 0 0 0 0 0 0 0 0 0 0
53790- 0 0 0 0 0 0 0 0 0 0 0 0
53791- 0 0 0 0 0 0 0 0 0 0 0 0
53792- 0 0 0 0 0 0 0 0 0 0 0 0
53793- 0 0 0 0 0 0 0 0 0 0 0 0
53794- 0 0 0 0 0 0 0 0 0 0 0 0
53795- 0 0 0 0 0 0 0 0 0 0 0 0
53796- 0 0 0 0 0 0 0 0 0 0 0 0
53797- 6 6 6 14 14 14 38 38 38 82 82 82
53798- 34 34 34 2 2 6 2 2 6 2 2 6
53799- 42 42 42 195 195 195 246 246 246 253 253 253
53800-253 253 253 253 253 253 253 253 253 250 250 250
53801-242 242 242 242 242 242 250 250 250 253 253 253
53802-253 253 253 253 253 253 253 253 253 253 253 253
53803-253 253 253 250 250 250 246 246 246 238 238 238
53804-226 226 226 231 231 231 101 101 101 6 6 6
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- 38 38 38 82 82 82 42 42 42 14 14 14
53808- 6 6 6 0 0 0 0 0 0 0 0 0
53809- 0 0 0 0 0 0 0 0 0 0 0 0
53810- 0 0 0 0 0 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- 10 10 10 26 26 26 62 62 62 66 66 66
53818- 2 2 6 2 2 6 2 2 6 6 6 6
53819- 70 70 70 170 170 170 206 206 206 234 234 234
53820-246 246 246 250 250 250 250 250 250 238 238 238
53821-226 226 226 231 231 231 238 238 238 250 250 250
53822-250 250 250 250 250 250 246 246 246 231 231 231
53823-214 214 214 206 206 206 202 202 202 202 202 202
53824-198 198 198 202 202 202 182 182 182 18 18 18
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 62 62 62 66 66 66 30 30 30
53828- 10 10 10 0 0 0 0 0 0 0 0 0
53829- 0 0 0 0 0 0 0 0 0 0 0 0
53830- 0 0 0 0 0 0 0 0 0 0 0 0
53831- 0 0 0 0 0 0 0 0 0 0 0 0
53832- 0 0 0 0 0 0 0 0 0 0 0 0
53833- 0 0 0 0 0 0 0 0 0 0 0 0
53834- 0 0 0 0 0 0 0 0 0 0 0 0
53835- 0 0 0 0 0 0 0 0 0 0 0 0
53836- 0 0 0 0 0 0 0 0 0 0 0 0
53837- 14 14 14 42 42 42 82 82 82 18 18 18
53838- 2 2 6 2 2 6 2 2 6 10 10 10
53839- 94 94 94 182 182 182 218 218 218 242 242 242
53840-250 250 250 253 253 253 253 253 253 250 250 250
53841-234 234 234 253 253 253 253 253 253 253 253 253
53842-253 253 253 253 253 253 253 253 253 246 246 246
53843-238 238 238 226 226 226 210 210 210 202 202 202
53844-195 195 195 195 195 195 210 210 210 158 158 158
53845- 6 6 6 14 14 14 50 50 50 14 14 14
53846- 2 2 6 2 2 6 2 2 6 2 2 6
53847- 2 2 6 6 6 6 86 86 86 46 46 46
53848- 18 18 18 6 6 6 0 0 0 0 0 0
53849- 0 0 0 0 0 0 0 0 0 0 0 0
53850- 0 0 0 0 0 0 0 0 0 0 0 0
53851- 0 0 0 0 0 0 0 0 0 0 0 0
53852- 0 0 0 0 0 0 0 0 0 0 0 0
53853- 0 0 0 0 0 0 0 0 0 0 0 0
53854- 0 0 0 0 0 0 0 0 0 0 0 0
53855- 0 0 0 0 0 0 0 0 0 0 0 0
53856- 0 0 0 0 0 0 0 0 0 6 6 6
53857- 22 22 22 54 54 54 70 70 70 2 2 6
53858- 2 2 6 10 10 10 2 2 6 22 22 22
53859-166 166 166 231 231 231 250 250 250 253 253 253
53860-253 253 253 253 253 253 253 253 253 250 250 250
53861-242 242 242 253 253 253 253 253 253 253 253 253
53862-253 253 253 253 253 253 253 253 253 253 253 253
53863-253 253 253 253 253 253 253 253 253 246 246 246
53864-231 231 231 206 206 206 198 198 198 226 226 226
53865- 94 94 94 2 2 6 6 6 6 38 38 38
53866- 30 30 30 2 2 6 2 2 6 2 2 6
53867- 2 2 6 2 2 6 62 62 62 66 66 66
53868- 26 26 26 10 10 10 0 0 0 0 0 0
53869- 0 0 0 0 0 0 0 0 0 0 0 0
53870- 0 0 0 0 0 0 0 0 0 0 0 0
53871- 0 0 0 0 0 0 0 0 0 0 0 0
53872- 0 0 0 0 0 0 0 0 0 0 0 0
53873- 0 0 0 0 0 0 0 0 0 0 0 0
53874- 0 0 0 0 0 0 0 0 0 0 0 0
53875- 0 0 0 0 0 0 0 0 0 0 0 0
53876- 0 0 0 0 0 0 0 0 0 10 10 10
53877- 30 30 30 74 74 74 50 50 50 2 2 6
53878- 26 26 26 26 26 26 2 2 6 106 106 106
53879-238 238 238 253 253 253 253 253 253 253 253 253
53880-253 253 253 253 253 253 253 253 253 253 253 253
53881-253 253 253 253 253 253 253 253 253 253 253 253
53882-253 253 253 253 253 253 253 253 253 253 253 253
53883-253 253 253 253 253 253 253 253 253 253 253 253
53884-253 253 253 246 246 246 218 218 218 202 202 202
53885-210 210 210 14 14 14 2 2 6 2 2 6
53886- 30 30 30 22 22 22 2 2 6 2 2 6
53887- 2 2 6 2 2 6 18 18 18 86 86 86
53888- 42 42 42 14 14 14 0 0 0 0 0 0
53889- 0 0 0 0 0 0 0 0 0 0 0 0
53890- 0 0 0 0 0 0 0 0 0 0 0 0
53891- 0 0 0 0 0 0 0 0 0 0 0 0
53892- 0 0 0 0 0 0 0 0 0 0 0 0
53893- 0 0 0 0 0 0 0 0 0 0 0 0
53894- 0 0 0 0 0 0 0 0 0 0 0 0
53895- 0 0 0 0 0 0 0 0 0 0 0 0
53896- 0 0 0 0 0 0 0 0 0 14 14 14
53897- 42 42 42 90 90 90 22 22 22 2 2 6
53898- 42 42 42 2 2 6 18 18 18 218 218 218
53899-253 253 253 253 253 253 253 253 253 253 253 253
53900-253 253 253 253 253 253 253 253 253 253 253 253
53901-253 253 253 253 253 253 253 253 253 253 253 253
53902-253 253 253 253 253 253 253 253 253 253 253 253
53903-253 253 253 253 253 253 253 253 253 253 253 253
53904-253 253 253 253 253 253 250 250 250 221 221 221
53905-218 218 218 101 101 101 2 2 6 14 14 14
53906- 18 18 18 38 38 38 10 10 10 2 2 6
53907- 2 2 6 2 2 6 2 2 6 78 78 78
53908- 58 58 58 22 22 22 6 6 6 0 0 0
53909- 0 0 0 0 0 0 0 0 0 0 0 0
53910- 0 0 0 0 0 0 0 0 0 0 0 0
53911- 0 0 0 0 0 0 0 0 0 0 0 0
53912- 0 0 0 0 0 0 0 0 0 0 0 0
53913- 0 0 0 0 0 0 0 0 0 0 0 0
53914- 0 0 0 0 0 0 0 0 0 0 0 0
53915- 0 0 0 0 0 0 0 0 0 0 0 0
53916- 0 0 0 0 0 0 6 6 6 18 18 18
53917- 54 54 54 82 82 82 2 2 6 26 26 26
53918- 22 22 22 2 2 6 123 123 123 253 253 253
53919-253 253 253 253 253 253 253 253 253 253 253 253
53920-253 253 253 253 253 253 253 253 253 253 253 253
53921-253 253 253 253 253 253 253 253 253 253 253 253
53922-253 253 253 253 253 253 253 253 253 253 253 253
53923-253 253 253 253 253 253 253 253 253 253 253 253
53924-253 253 253 253 253 253 253 253 253 250 250 250
53925-238 238 238 198 198 198 6 6 6 38 38 38
53926- 58 58 58 26 26 26 38 38 38 2 2 6
53927- 2 2 6 2 2 6 2 2 6 46 46 46
53928- 78 78 78 30 30 30 10 10 10 0 0 0
53929- 0 0 0 0 0 0 0 0 0 0 0 0
53930- 0 0 0 0 0 0 0 0 0 0 0 0
53931- 0 0 0 0 0 0 0 0 0 0 0 0
53932- 0 0 0 0 0 0 0 0 0 0 0 0
53933- 0 0 0 0 0 0 0 0 0 0 0 0
53934- 0 0 0 0 0 0 0 0 0 0 0 0
53935- 0 0 0 0 0 0 0 0 0 0 0 0
53936- 0 0 0 0 0 0 10 10 10 30 30 30
53937- 74 74 74 58 58 58 2 2 6 42 42 42
53938- 2 2 6 22 22 22 231 231 231 253 253 253
53939-253 253 253 253 253 253 253 253 253 253 253 253
53940-253 253 253 253 253 253 253 253 253 250 250 250
53941-253 253 253 253 253 253 253 253 253 253 253 253
53942-253 253 253 253 253 253 253 253 253 253 253 253
53943-253 253 253 253 253 253 253 253 253 253 253 253
53944-253 253 253 253 253 253 253 253 253 253 253 253
53945-253 253 253 246 246 246 46 46 46 38 38 38
53946- 42 42 42 14 14 14 38 38 38 14 14 14
53947- 2 2 6 2 2 6 2 2 6 6 6 6
53948- 86 86 86 46 46 46 14 14 14 0 0 0
53949- 0 0 0 0 0 0 0 0 0 0 0 0
53950- 0 0 0 0 0 0 0 0 0 0 0 0
53951- 0 0 0 0 0 0 0 0 0 0 0 0
53952- 0 0 0 0 0 0 0 0 0 0 0 0
53953- 0 0 0 0 0 0 0 0 0 0 0 0
53954- 0 0 0 0 0 0 0 0 0 0 0 0
53955- 0 0 0 0 0 0 0 0 0 0 0 0
53956- 0 0 0 6 6 6 14 14 14 42 42 42
53957- 90 90 90 18 18 18 18 18 18 26 26 26
53958- 2 2 6 116 116 116 253 253 253 253 253 253
53959-253 253 253 253 253 253 253 253 253 253 253 253
53960-253 253 253 253 253 253 250 250 250 238 238 238
53961-253 253 253 253 253 253 253 253 253 253 253 253
53962-253 253 253 253 253 253 253 253 253 253 253 253
53963-253 253 253 253 253 253 253 253 253 253 253 253
53964-253 253 253 253 253 253 253 253 253 253 253 253
53965-253 253 253 253 253 253 94 94 94 6 6 6
53966- 2 2 6 2 2 6 10 10 10 34 34 34
53967- 2 2 6 2 2 6 2 2 6 2 2 6
53968- 74 74 74 58 58 58 22 22 22 6 6 6
53969- 0 0 0 0 0 0 0 0 0 0 0 0
53970- 0 0 0 0 0 0 0 0 0 0 0 0
53971- 0 0 0 0 0 0 0 0 0 0 0 0
53972- 0 0 0 0 0 0 0 0 0 0 0 0
53973- 0 0 0 0 0 0 0 0 0 0 0 0
53974- 0 0 0 0 0 0 0 0 0 0 0 0
53975- 0 0 0 0 0 0 0 0 0 0 0 0
53976- 0 0 0 10 10 10 26 26 26 66 66 66
53977- 82 82 82 2 2 6 38 38 38 6 6 6
53978- 14 14 14 210 210 210 253 253 253 253 253 253
53979-253 253 253 253 253 253 253 253 253 253 253 253
53980-253 253 253 253 253 253 246 246 246 242 242 242
53981-253 253 253 253 253 253 253 253 253 253 253 253
53982-253 253 253 253 253 253 253 253 253 253 253 253
53983-253 253 253 253 253 253 253 253 253 253 253 253
53984-253 253 253 253 253 253 253 253 253 253 253 253
53985-253 253 253 253 253 253 144 144 144 2 2 6
53986- 2 2 6 2 2 6 2 2 6 46 46 46
53987- 2 2 6 2 2 6 2 2 6 2 2 6
53988- 42 42 42 74 74 74 30 30 30 10 10 10
53989- 0 0 0 0 0 0 0 0 0 0 0 0
53990- 0 0 0 0 0 0 0 0 0 0 0 0
53991- 0 0 0 0 0 0 0 0 0 0 0 0
53992- 0 0 0 0 0 0 0 0 0 0 0 0
53993- 0 0 0 0 0 0 0 0 0 0 0 0
53994- 0 0 0 0 0 0 0 0 0 0 0 0
53995- 0 0 0 0 0 0 0 0 0 0 0 0
53996- 6 6 6 14 14 14 42 42 42 90 90 90
53997- 26 26 26 6 6 6 42 42 42 2 2 6
53998- 74 74 74 250 250 250 253 253 253 253 253 253
53999-253 253 253 253 253 253 253 253 253 253 253 253
54000-253 253 253 253 253 253 242 242 242 242 242 242
54001-253 253 253 253 253 253 253 253 253 253 253 253
54002-253 253 253 253 253 253 253 253 253 253 253 253
54003-253 253 253 253 253 253 253 253 253 253 253 253
54004-253 253 253 253 253 253 253 253 253 253 253 253
54005-253 253 253 253 253 253 182 182 182 2 2 6
54006- 2 2 6 2 2 6 2 2 6 46 46 46
54007- 2 2 6 2 2 6 2 2 6 2 2 6
54008- 10 10 10 86 86 86 38 38 38 10 10 10
54009- 0 0 0 0 0 0 0 0 0 0 0 0
54010- 0 0 0 0 0 0 0 0 0 0 0 0
54011- 0 0 0 0 0 0 0 0 0 0 0 0
54012- 0 0 0 0 0 0 0 0 0 0 0 0
54013- 0 0 0 0 0 0 0 0 0 0 0 0
54014- 0 0 0 0 0 0 0 0 0 0 0 0
54015- 0 0 0 0 0 0 0 0 0 0 0 0
54016- 10 10 10 26 26 26 66 66 66 82 82 82
54017- 2 2 6 22 22 22 18 18 18 2 2 6
54018-149 149 149 253 253 253 253 253 253 253 253 253
54019-253 253 253 253 253 253 253 253 253 253 253 253
54020-253 253 253 253 253 253 234 234 234 242 242 242
54021-253 253 253 253 253 253 253 253 253 253 253 253
54022-253 253 253 253 253 253 253 253 253 253 253 253
54023-253 253 253 253 253 253 253 253 253 253 253 253
54024-253 253 253 253 253 253 253 253 253 253 253 253
54025-253 253 253 253 253 253 206 206 206 2 2 6
54026- 2 2 6 2 2 6 2 2 6 38 38 38
54027- 2 2 6 2 2 6 2 2 6 2 2 6
54028- 6 6 6 86 86 86 46 46 46 14 14 14
54029- 0 0 0 0 0 0 0 0 0 0 0 0
54030- 0 0 0 0 0 0 0 0 0 0 0 0
54031- 0 0 0 0 0 0 0 0 0 0 0 0
54032- 0 0 0 0 0 0 0 0 0 0 0 0
54033- 0 0 0 0 0 0 0 0 0 0 0 0
54034- 0 0 0 0 0 0 0 0 0 0 0 0
54035- 0 0 0 0 0 0 0 0 0 6 6 6
54036- 18 18 18 46 46 46 86 86 86 18 18 18
54037- 2 2 6 34 34 34 10 10 10 6 6 6
54038-210 210 210 253 253 253 253 253 253 253 253 253
54039-253 253 253 253 253 253 253 253 253 253 253 253
54040-253 253 253 253 253 253 234 234 234 242 242 242
54041-253 253 253 253 253 253 253 253 253 253 253 253
54042-253 253 253 253 253 253 253 253 253 253 253 253
54043-253 253 253 253 253 253 253 253 253 253 253 253
54044-253 253 253 253 253 253 253 253 253 253 253 253
54045-253 253 253 253 253 253 221 221 221 6 6 6
54046- 2 2 6 2 2 6 6 6 6 30 30 30
54047- 2 2 6 2 2 6 2 2 6 2 2 6
54048- 2 2 6 82 82 82 54 54 54 18 18 18
54049- 6 6 6 0 0 0 0 0 0 0 0 0
54050- 0 0 0 0 0 0 0 0 0 0 0 0
54051- 0 0 0 0 0 0 0 0 0 0 0 0
54052- 0 0 0 0 0 0 0 0 0 0 0 0
54053- 0 0 0 0 0 0 0 0 0 0 0 0
54054- 0 0 0 0 0 0 0 0 0 0 0 0
54055- 0 0 0 0 0 0 0 0 0 10 10 10
54056- 26 26 26 66 66 66 62 62 62 2 2 6
54057- 2 2 6 38 38 38 10 10 10 26 26 26
54058-238 238 238 253 253 253 253 253 253 253 253 253
54059-253 253 253 253 253 253 253 253 253 253 253 253
54060-253 253 253 253 253 253 231 231 231 238 238 238
54061-253 253 253 253 253 253 253 253 253 253 253 253
54062-253 253 253 253 253 253 253 253 253 253 253 253
54063-253 253 253 253 253 253 253 253 253 253 253 253
54064-253 253 253 253 253 253 253 253 253 253 253 253
54065-253 253 253 253 253 253 231 231 231 6 6 6
54066- 2 2 6 2 2 6 10 10 10 30 30 30
54067- 2 2 6 2 2 6 2 2 6 2 2 6
54068- 2 2 6 66 66 66 58 58 58 22 22 22
54069- 6 6 6 0 0 0 0 0 0 0 0 0
54070- 0 0 0 0 0 0 0 0 0 0 0 0
54071- 0 0 0 0 0 0 0 0 0 0 0 0
54072- 0 0 0 0 0 0 0 0 0 0 0 0
54073- 0 0 0 0 0 0 0 0 0 0 0 0
54074- 0 0 0 0 0 0 0 0 0 0 0 0
54075- 0 0 0 0 0 0 0 0 0 10 10 10
54076- 38 38 38 78 78 78 6 6 6 2 2 6
54077- 2 2 6 46 46 46 14 14 14 42 42 42
54078-246 246 246 253 253 253 253 253 253 253 253 253
54079-253 253 253 253 253 253 253 253 253 253 253 253
54080-253 253 253 253 253 253 231 231 231 242 242 242
54081-253 253 253 253 253 253 253 253 253 253 253 253
54082-253 253 253 253 253 253 253 253 253 253 253 253
54083-253 253 253 253 253 253 253 253 253 253 253 253
54084-253 253 253 253 253 253 253 253 253 253 253 253
54085-253 253 253 253 253 253 234 234 234 10 10 10
54086- 2 2 6 2 2 6 22 22 22 14 14 14
54087- 2 2 6 2 2 6 2 2 6 2 2 6
54088- 2 2 6 66 66 66 62 62 62 22 22 22
54089- 6 6 6 0 0 0 0 0 0 0 0 0
54090- 0 0 0 0 0 0 0 0 0 0 0 0
54091- 0 0 0 0 0 0 0 0 0 0 0 0
54092- 0 0 0 0 0 0 0 0 0 0 0 0
54093- 0 0 0 0 0 0 0 0 0 0 0 0
54094- 0 0 0 0 0 0 0 0 0 0 0 0
54095- 0 0 0 0 0 0 6 6 6 18 18 18
54096- 50 50 50 74 74 74 2 2 6 2 2 6
54097- 14 14 14 70 70 70 34 34 34 62 62 62
54098-250 250 250 253 253 253 253 253 253 253 253 253
54099-253 253 253 253 253 253 253 253 253 253 253 253
54100-253 253 253 253 253 253 231 231 231 246 246 246
54101-253 253 253 253 253 253 253 253 253 253 253 253
54102-253 253 253 253 253 253 253 253 253 253 253 253
54103-253 253 253 253 253 253 253 253 253 253 253 253
54104-253 253 253 253 253 253 253 253 253 253 253 253
54105-253 253 253 253 253 253 234 234 234 14 14 14
54106- 2 2 6 2 2 6 30 30 30 2 2 6
54107- 2 2 6 2 2 6 2 2 6 2 2 6
54108- 2 2 6 66 66 66 62 62 62 22 22 22
54109- 6 6 6 0 0 0 0 0 0 0 0 0
54110- 0 0 0 0 0 0 0 0 0 0 0 0
54111- 0 0 0 0 0 0 0 0 0 0 0 0
54112- 0 0 0 0 0 0 0 0 0 0 0 0
54113- 0 0 0 0 0 0 0 0 0 0 0 0
54114- 0 0 0 0 0 0 0 0 0 0 0 0
54115- 0 0 0 0 0 0 6 6 6 18 18 18
54116- 54 54 54 62 62 62 2 2 6 2 2 6
54117- 2 2 6 30 30 30 46 46 46 70 70 70
54118-250 250 250 253 253 253 253 253 253 253 253 253
54119-253 253 253 253 253 253 253 253 253 253 253 253
54120-253 253 253 253 253 253 231 231 231 246 246 246
54121-253 253 253 253 253 253 253 253 253 253 253 253
54122-253 253 253 253 253 253 253 253 253 253 253 253
54123-253 253 253 253 253 253 253 253 253 253 253 253
54124-253 253 253 253 253 253 253 253 253 253 253 253
54125-253 253 253 253 253 253 226 226 226 10 10 10
54126- 2 2 6 6 6 6 30 30 30 2 2 6
54127- 2 2 6 2 2 6 2 2 6 2 2 6
54128- 2 2 6 66 66 66 58 58 58 22 22 22
54129- 6 6 6 0 0 0 0 0 0 0 0 0
54130- 0 0 0 0 0 0 0 0 0 0 0 0
54131- 0 0 0 0 0 0 0 0 0 0 0 0
54132- 0 0 0 0 0 0 0 0 0 0 0 0
54133- 0 0 0 0 0 0 0 0 0 0 0 0
54134- 0 0 0 0 0 0 0 0 0 0 0 0
54135- 0 0 0 0 0 0 6 6 6 22 22 22
54136- 58 58 58 62 62 62 2 2 6 2 2 6
54137- 2 2 6 2 2 6 30 30 30 78 78 78
54138-250 250 250 253 253 253 253 253 253 253 253 253
54139-253 253 253 253 253 253 253 253 253 253 253 253
54140-253 253 253 253 253 253 231 231 231 246 246 246
54141-253 253 253 253 253 253 253 253 253 253 253 253
54142-253 253 253 253 253 253 253 253 253 253 253 253
54143-253 253 253 253 253 253 253 253 253 253 253 253
54144-253 253 253 253 253 253 253 253 253 253 253 253
54145-253 253 253 253 253 253 206 206 206 2 2 6
54146- 22 22 22 34 34 34 18 14 6 22 22 22
54147- 26 26 26 18 18 18 6 6 6 2 2 6
54148- 2 2 6 82 82 82 54 54 54 18 18 18
54149- 6 6 6 0 0 0 0 0 0 0 0 0
54150- 0 0 0 0 0 0 0 0 0 0 0 0
54151- 0 0 0 0 0 0 0 0 0 0 0 0
54152- 0 0 0 0 0 0 0 0 0 0 0 0
54153- 0 0 0 0 0 0 0 0 0 0 0 0
54154- 0 0 0 0 0 0 0 0 0 0 0 0
54155- 0 0 0 0 0 0 6 6 6 26 26 26
54156- 62 62 62 106 106 106 74 54 14 185 133 11
54157-210 162 10 121 92 8 6 6 6 62 62 62
54158-238 238 238 253 253 253 253 253 253 253 253 253
54159-253 253 253 253 253 253 253 253 253 253 253 253
54160-253 253 253 253 253 253 231 231 231 246 246 246
54161-253 253 253 253 253 253 253 253 253 253 253 253
54162-253 253 253 253 253 253 253 253 253 253 253 253
54163-253 253 253 253 253 253 253 253 253 253 253 253
54164-253 253 253 253 253 253 253 253 253 253 253 253
54165-253 253 253 253 253 253 158 158 158 18 18 18
54166- 14 14 14 2 2 6 2 2 6 2 2 6
54167- 6 6 6 18 18 18 66 66 66 38 38 38
54168- 6 6 6 94 94 94 50 50 50 18 18 18
54169- 6 6 6 0 0 0 0 0 0 0 0 0
54170- 0 0 0 0 0 0 0 0 0 0 0 0
54171- 0 0 0 0 0 0 0 0 0 0 0 0
54172- 0 0 0 0 0 0 0 0 0 0 0 0
54173- 0 0 0 0 0 0 0 0 0 0 0 0
54174- 0 0 0 0 0 0 0 0 0 6 6 6
54175- 10 10 10 10 10 10 18 18 18 38 38 38
54176- 78 78 78 142 134 106 216 158 10 242 186 14
54177-246 190 14 246 190 14 156 118 10 10 10 10
54178- 90 90 90 238 238 238 253 253 253 253 253 253
54179-253 253 253 253 253 253 253 253 253 253 253 253
54180-253 253 253 253 253 253 231 231 231 250 250 250
54181-253 253 253 253 253 253 253 253 253 253 253 253
54182-253 253 253 253 253 253 253 253 253 253 253 253
54183-253 253 253 253 253 253 253 253 253 253 253 253
54184-253 253 253 253 253 253 253 253 253 246 230 190
54185-238 204 91 238 204 91 181 142 44 37 26 9
54186- 2 2 6 2 2 6 2 2 6 2 2 6
54187- 2 2 6 2 2 6 38 38 38 46 46 46
54188- 26 26 26 106 106 106 54 54 54 18 18 18
54189- 6 6 6 0 0 0 0 0 0 0 0 0
54190- 0 0 0 0 0 0 0 0 0 0 0 0
54191- 0 0 0 0 0 0 0 0 0 0 0 0
54192- 0 0 0 0 0 0 0 0 0 0 0 0
54193- 0 0 0 0 0 0 0 0 0 0 0 0
54194- 0 0 0 6 6 6 14 14 14 22 22 22
54195- 30 30 30 38 38 38 50 50 50 70 70 70
54196-106 106 106 190 142 34 226 170 11 242 186 14
54197-246 190 14 246 190 14 246 190 14 154 114 10
54198- 6 6 6 74 74 74 226 226 226 253 253 253
54199-253 253 253 253 253 253 253 253 253 253 253 253
54200-253 253 253 253 253 253 231 231 231 250 250 250
54201-253 253 253 253 253 253 253 253 253 253 253 253
54202-253 253 253 253 253 253 253 253 253 253 253 253
54203-253 253 253 253 253 253 253 253 253 253 253 253
54204-253 253 253 253 253 253 253 253 253 228 184 62
54205-241 196 14 241 208 19 232 195 16 38 30 10
54206- 2 2 6 2 2 6 2 2 6 2 2 6
54207- 2 2 6 6 6 6 30 30 30 26 26 26
54208-203 166 17 154 142 90 66 66 66 26 26 26
54209- 6 6 6 0 0 0 0 0 0 0 0 0
54210- 0 0 0 0 0 0 0 0 0 0 0 0
54211- 0 0 0 0 0 0 0 0 0 0 0 0
54212- 0 0 0 0 0 0 0 0 0 0 0 0
54213- 0 0 0 0 0 0 0 0 0 0 0 0
54214- 6 6 6 18 18 18 38 38 38 58 58 58
54215- 78 78 78 86 86 86 101 101 101 123 123 123
54216-175 146 61 210 150 10 234 174 13 246 186 14
54217-246 190 14 246 190 14 246 190 14 238 190 10
54218-102 78 10 2 2 6 46 46 46 198 198 198
54219-253 253 253 253 253 253 253 253 253 253 253 253
54220-253 253 253 253 253 253 234 234 234 242 242 242
54221-253 253 253 253 253 253 253 253 253 253 253 253
54222-253 253 253 253 253 253 253 253 253 253 253 253
54223-253 253 253 253 253 253 253 253 253 253 253 253
54224-253 253 253 253 253 253 253 253 253 224 178 62
54225-242 186 14 241 196 14 210 166 10 22 18 6
54226- 2 2 6 2 2 6 2 2 6 2 2 6
54227- 2 2 6 2 2 6 6 6 6 121 92 8
54228-238 202 15 232 195 16 82 82 82 34 34 34
54229- 10 10 10 0 0 0 0 0 0 0 0 0
54230- 0 0 0 0 0 0 0 0 0 0 0 0
54231- 0 0 0 0 0 0 0 0 0 0 0 0
54232- 0 0 0 0 0 0 0 0 0 0 0 0
54233- 0 0 0 0 0 0 0 0 0 0 0 0
54234- 14 14 14 38 38 38 70 70 70 154 122 46
54235-190 142 34 200 144 11 197 138 11 197 138 11
54236-213 154 11 226 170 11 242 186 14 246 190 14
54237-246 190 14 246 190 14 246 190 14 246 190 14
54238-225 175 15 46 32 6 2 2 6 22 22 22
54239-158 158 158 250 250 250 253 253 253 253 253 253
54240-253 253 253 253 253 253 253 253 253 253 253 253
54241-253 253 253 253 253 253 253 253 253 253 253 253
54242-253 253 253 253 253 253 253 253 253 253 253 253
54243-253 253 253 253 253 253 253 253 253 253 253 253
54244-253 253 253 250 250 250 242 242 242 224 178 62
54245-239 182 13 236 186 11 213 154 11 46 32 6
54246- 2 2 6 2 2 6 2 2 6 2 2 6
54247- 2 2 6 2 2 6 61 42 6 225 175 15
54248-238 190 10 236 186 11 112 100 78 42 42 42
54249- 14 14 14 0 0 0 0 0 0 0 0 0
54250- 0 0 0 0 0 0 0 0 0 0 0 0
54251- 0 0 0 0 0 0 0 0 0 0 0 0
54252- 0 0 0 0 0 0 0 0 0 0 0 0
54253- 0 0 0 0 0 0 0 0 0 6 6 6
54254- 22 22 22 54 54 54 154 122 46 213 154 11
54255-226 170 11 230 174 11 226 170 11 226 170 11
54256-236 178 12 242 186 14 246 190 14 246 190 14
54257-246 190 14 246 190 14 246 190 14 246 190 14
54258-241 196 14 184 144 12 10 10 10 2 2 6
54259- 6 6 6 116 116 116 242 242 242 253 253 253
54260-253 253 253 253 253 253 253 253 253 253 253 253
54261-253 253 253 253 253 253 253 253 253 253 253 253
54262-253 253 253 253 253 253 253 253 253 253 253 253
54263-253 253 253 253 253 253 253 253 253 253 253 253
54264-253 253 253 231 231 231 198 198 198 214 170 54
54265-236 178 12 236 178 12 210 150 10 137 92 6
54266- 18 14 6 2 2 6 2 2 6 2 2 6
54267- 6 6 6 70 47 6 200 144 11 236 178 12
54268-239 182 13 239 182 13 124 112 88 58 58 58
54269- 22 22 22 6 6 6 0 0 0 0 0 0
54270- 0 0 0 0 0 0 0 0 0 0 0 0
54271- 0 0 0 0 0 0 0 0 0 0 0 0
54272- 0 0 0 0 0 0 0 0 0 0 0 0
54273- 0 0 0 0 0 0 0 0 0 10 10 10
54274- 30 30 30 70 70 70 180 133 36 226 170 11
54275-239 182 13 242 186 14 242 186 14 246 186 14
54276-246 190 14 246 190 14 246 190 14 246 190 14
54277-246 190 14 246 190 14 246 190 14 246 190 14
54278-246 190 14 232 195 16 98 70 6 2 2 6
54279- 2 2 6 2 2 6 66 66 66 221 221 221
54280-253 253 253 253 253 253 253 253 253 253 253 253
54281-253 253 253 253 253 253 253 253 253 253 253 253
54282-253 253 253 253 253 253 253 253 253 253 253 253
54283-253 253 253 253 253 253 253 253 253 253 253 253
54284-253 253 253 206 206 206 198 198 198 214 166 58
54285-230 174 11 230 174 11 216 158 10 192 133 9
54286-163 110 8 116 81 8 102 78 10 116 81 8
54287-167 114 7 197 138 11 226 170 11 239 182 13
54288-242 186 14 242 186 14 162 146 94 78 78 78
54289- 34 34 34 14 14 14 6 6 6 0 0 0
54290- 0 0 0 0 0 0 0 0 0 0 0 0
54291- 0 0 0 0 0 0 0 0 0 0 0 0
54292- 0 0 0 0 0 0 0 0 0 0 0 0
54293- 0 0 0 0 0 0 0 0 0 6 6 6
54294- 30 30 30 78 78 78 190 142 34 226 170 11
54295-239 182 13 246 190 14 246 190 14 246 190 14
54296-246 190 14 246 190 14 246 190 14 246 190 14
54297-246 190 14 246 190 14 246 190 14 246 190 14
54298-246 190 14 241 196 14 203 166 17 22 18 6
54299- 2 2 6 2 2 6 2 2 6 38 38 38
54300-218 218 218 253 253 253 253 253 253 253 253 253
54301-253 253 253 253 253 253 253 253 253 253 253 253
54302-253 253 253 253 253 253 253 253 253 253 253 253
54303-253 253 253 253 253 253 253 253 253 253 253 253
54304-250 250 250 206 206 206 198 198 198 202 162 69
54305-226 170 11 236 178 12 224 166 10 210 150 10
54306-200 144 11 197 138 11 192 133 9 197 138 11
54307-210 150 10 226 170 11 242 186 14 246 190 14
54308-246 190 14 246 186 14 225 175 15 124 112 88
54309- 62 62 62 30 30 30 14 14 14 6 6 6
54310- 0 0 0 0 0 0 0 0 0 0 0 0
54311- 0 0 0 0 0 0 0 0 0 0 0 0
54312- 0 0 0 0 0 0 0 0 0 0 0 0
54313- 0 0 0 0 0 0 0 0 0 10 10 10
54314- 30 30 30 78 78 78 174 135 50 224 166 10
54315-239 182 13 246 190 14 246 190 14 246 190 14
54316-246 190 14 246 190 14 246 190 14 246 190 14
54317-246 190 14 246 190 14 246 190 14 246 190 14
54318-246 190 14 246 190 14 241 196 14 139 102 15
54319- 2 2 6 2 2 6 2 2 6 2 2 6
54320- 78 78 78 250 250 250 253 253 253 253 253 253
54321-253 253 253 253 253 253 253 253 253 253 253 253
54322-253 253 253 253 253 253 253 253 253 253 253 253
54323-253 253 253 253 253 253 253 253 253 253 253 253
54324-250 250 250 214 214 214 198 198 198 190 150 46
54325-219 162 10 236 178 12 234 174 13 224 166 10
54326-216 158 10 213 154 11 213 154 11 216 158 10
54327-226 170 11 239 182 13 246 190 14 246 190 14
54328-246 190 14 246 190 14 242 186 14 206 162 42
54329-101 101 101 58 58 58 30 30 30 14 14 14
54330- 6 6 6 0 0 0 0 0 0 0 0 0
54331- 0 0 0 0 0 0 0 0 0 0 0 0
54332- 0 0 0 0 0 0 0 0 0 0 0 0
54333- 0 0 0 0 0 0 0 0 0 10 10 10
54334- 30 30 30 74 74 74 174 135 50 216 158 10
54335-236 178 12 246 190 14 246 190 14 246 190 14
54336-246 190 14 246 190 14 246 190 14 246 190 14
54337-246 190 14 246 190 14 246 190 14 246 190 14
54338-246 190 14 246 190 14 241 196 14 226 184 13
54339- 61 42 6 2 2 6 2 2 6 2 2 6
54340- 22 22 22 238 238 238 253 253 253 253 253 253
54341-253 253 253 253 253 253 253 253 253 253 253 253
54342-253 253 253 253 253 253 253 253 253 253 253 253
54343-253 253 253 253 253 253 253 253 253 253 253 253
54344-253 253 253 226 226 226 187 187 187 180 133 36
54345-216 158 10 236 178 12 239 182 13 236 178 12
54346-230 174 11 226 170 11 226 170 11 230 174 11
54347-236 178 12 242 186 14 246 190 14 246 190 14
54348-246 190 14 246 190 14 246 186 14 239 182 13
54349-206 162 42 106 106 106 66 66 66 34 34 34
54350- 14 14 14 6 6 6 0 0 0 0 0 0
54351- 0 0 0 0 0 0 0 0 0 0 0 0
54352- 0 0 0 0 0 0 0 0 0 0 0 0
54353- 0 0 0 0 0 0 0 0 0 6 6 6
54354- 26 26 26 70 70 70 163 133 67 213 154 11
54355-236 178 12 246 190 14 246 190 14 246 190 14
54356-246 190 14 246 190 14 246 190 14 246 190 14
54357-246 190 14 246 190 14 246 190 14 246 190 14
54358-246 190 14 246 190 14 246 190 14 241 196 14
54359-190 146 13 18 14 6 2 2 6 2 2 6
54360- 46 46 46 246 246 246 253 253 253 253 253 253
54361-253 253 253 253 253 253 253 253 253 253 253 253
54362-253 253 253 253 253 253 253 253 253 253 253 253
54363-253 253 253 253 253 253 253 253 253 253 253 253
54364-253 253 253 221 221 221 86 86 86 156 107 11
54365-216 158 10 236 178 12 242 186 14 246 186 14
54366-242 186 14 239 182 13 239 182 13 242 186 14
54367-242 186 14 246 186 14 246 190 14 246 190 14
54368-246 190 14 246 190 14 246 190 14 246 190 14
54369-242 186 14 225 175 15 142 122 72 66 66 66
54370- 30 30 30 10 10 10 0 0 0 0 0 0
54371- 0 0 0 0 0 0 0 0 0 0 0 0
54372- 0 0 0 0 0 0 0 0 0 0 0 0
54373- 0 0 0 0 0 0 0 0 0 6 6 6
54374- 26 26 26 70 70 70 163 133 67 210 150 10
54375-236 178 12 246 190 14 246 190 14 246 190 14
54376-246 190 14 246 190 14 246 190 14 246 190 14
54377-246 190 14 246 190 14 246 190 14 246 190 14
54378-246 190 14 246 190 14 246 190 14 246 190 14
54379-232 195 16 121 92 8 34 34 34 106 106 106
54380-221 221 221 253 253 253 253 253 253 253 253 253
54381-253 253 253 253 253 253 253 253 253 253 253 253
54382-253 253 253 253 253 253 253 253 253 253 253 253
54383-253 253 253 253 253 253 253 253 253 253 253 253
54384-242 242 242 82 82 82 18 14 6 163 110 8
54385-216 158 10 236 178 12 242 186 14 246 190 14
54386-246 190 14 246 190 14 246 190 14 246 190 14
54387-246 190 14 246 190 14 246 190 14 246 190 14
54388-246 190 14 246 190 14 246 190 14 246 190 14
54389-246 190 14 246 190 14 242 186 14 163 133 67
54390- 46 46 46 18 18 18 6 6 6 0 0 0
54391- 0 0 0 0 0 0 0 0 0 0 0 0
54392- 0 0 0 0 0 0 0 0 0 0 0 0
54393- 0 0 0 0 0 0 0 0 0 10 10 10
54394- 30 30 30 78 78 78 163 133 67 210 150 10
54395-236 178 12 246 186 14 246 190 14 246 190 14
54396-246 190 14 246 190 14 246 190 14 246 190 14
54397-246 190 14 246 190 14 246 190 14 246 190 14
54398-246 190 14 246 190 14 246 190 14 246 190 14
54399-241 196 14 215 174 15 190 178 144 253 253 253
54400-253 253 253 253 253 253 253 253 253 253 253 253
54401-253 253 253 253 253 253 253 253 253 253 253 253
54402-253 253 253 253 253 253 253 253 253 253 253 253
54403-253 253 253 253 253 253 253 253 253 218 218 218
54404- 58 58 58 2 2 6 22 18 6 167 114 7
54405-216 158 10 236 178 12 246 186 14 246 190 14
54406-246 190 14 246 190 14 246 190 14 246 190 14
54407-246 190 14 246 190 14 246 190 14 246 190 14
54408-246 190 14 246 190 14 246 190 14 246 190 14
54409-246 190 14 246 186 14 242 186 14 190 150 46
54410- 54 54 54 22 22 22 6 6 6 0 0 0
54411- 0 0 0 0 0 0 0 0 0 0 0 0
54412- 0 0 0 0 0 0 0 0 0 0 0 0
54413- 0 0 0 0 0 0 0 0 0 14 14 14
54414- 38 38 38 86 86 86 180 133 36 213 154 11
54415-236 178 12 246 186 14 246 190 14 246 190 14
54416-246 190 14 246 190 14 246 190 14 246 190 14
54417-246 190 14 246 190 14 246 190 14 246 190 14
54418-246 190 14 246 190 14 246 190 14 246 190 14
54419-246 190 14 232 195 16 190 146 13 214 214 214
54420-253 253 253 253 253 253 253 253 253 253 253 253
54421-253 253 253 253 253 253 253 253 253 253 253 253
54422-253 253 253 253 253 253 253 253 253 253 253 253
54423-253 253 253 250 250 250 170 170 170 26 26 26
54424- 2 2 6 2 2 6 37 26 9 163 110 8
54425-219 162 10 239 182 13 246 186 14 246 190 14
54426-246 190 14 246 190 14 246 190 14 246 190 14
54427-246 190 14 246 190 14 246 190 14 246 190 14
54428-246 190 14 246 190 14 246 190 14 246 190 14
54429-246 186 14 236 178 12 224 166 10 142 122 72
54430- 46 46 46 18 18 18 6 6 6 0 0 0
54431- 0 0 0 0 0 0 0 0 0 0 0 0
54432- 0 0 0 0 0 0 0 0 0 0 0 0
54433- 0 0 0 0 0 0 6 6 6 18 18 18
54434- 50 50 50 109 106 95 192 133 9 224 166 10
54435-242 186 14 246 190 14 246 190 14 246 190 14
54436-246 190 14 246 190 14 246 190 14 246 190 14
54437-246 190 14 246 190 14 246 190 14 246 190 14
54438-246 190 14 246 190 14 246 190 14 246 190 14
54439-242 186 14 226 184 13 210 162 10 142 110 46
54440-226 226 226 253 253 253 253 253 253 253 253 253
54441-253 253 253 253 253 253 253 253 253 253 253 253
54442-253 253 253 253 253 253 253 253 253 253 253 253
54443-198 198 198 66 66 66 2 2 6 2 2 6
54444- 2 2 6 2 2 6 50 34 6 156 107 11
54445-219 162 10 239 182 13 246 186 14 246 190 14
54446-246 190 14 246 190 14 246 190 14 246 190 14
54447-246 190 14 246 190 14 246 190 14 246 190 14
54448-246 190 14 246 190 14 246 190 14 242 186 14
54449-234 174 13 213 154 11 154 122 46 66 66 66
54450- 30 30 30 10 10 10 0 0 0 0 0 0
54451- 0 0 0 0 0 0 0 0 0 0 0 0
54452- 0 0 0 0 0 0 0 0 0 0 0 0
54453- 0 0 0 0 0 0 6 6 6 22 22 22
54454- 58 58 58 154 121 60 206 145 10 234 174 13
54455-242 186 14 246 186 14 246 190 14 246 190 14
54456-246 190 14 246 190 14 246 190 14 246 190 14
54457-246 190 14 246 190 14 246 190 14 246 190 14
54458-246 190 14 246 190 14 246 190 14 246 190 14
54459-246 186 14 236 178 12 210 162 10 163 110 8
54460- 61 42 6 138 138 138 218 218 218 250 250 250
54461-253 253 253 253 253 253 253 253 253 250 250 250
54462-242 242 242 210 210 210 144 144 144 66 66 66
54463- 6 6 6 2 2 6 2 2 6 2 2 6
54464- 2 2 6 2 2 6 61 42 6 163 110 8
54465-216 158 10 236 178 12 246 190 14 246 190 14
54466-246 190 14 246 190 14 246 190 14 246 190 14
54467-246 190 14 246 190 14 246 190 14 246 190 14
54468-246 190 14 239 182 13 230 174 11 216 158 10
54469-190 142 34 124 112 88 70 70 70 38 38 38
54470- 18 18 18 6 6 6 0 0 0 0 0 0
54471- 0 0 0 0 0 0 0 0 0 0 0 0
54472- 0 0 0 0 0 0 0 0 0 0 0 0
54473- 0 0 0 0 0 0 6 6 6 22 22 22
54474- 62 62 62 168 124 44 206 145 10 224 166 10
54475-236 178 12 239 182 13 242 186 14 242 186 14
54476-246 186 14 246 190 14 246 190 14 246 190 14
54477-246 190 14 246 190 14 246 190 14 246 190 14
54478-246 190 14 246 190 14 246 190 14 246 190 14
54479-246 190 14 236 178 12 216 158 10 175 118 6
54480- 80 54 7 2 2 6 6 6 6 30 30 30
54481- 54 54 54 62 62 62 50 50 50 38 38 38
54482- 14 14 14 2 2 6 2 2 6 2 2 6
54483- 2 2 6 2 2 6 2 2 6 2 2 6
54484- 2 2 6 6 6 6 80 54 7 167 114 7
54485-213 154 11 236 178 12 246 190 14 246 190 14
54486-246 190 14 246 190 14 246 190 14 246 190 14
54487-246 190 14 242 186 14 239 182 13 239 182 13
54488-230 174 11 210 150 10 174 135 50 124 112 88
54489- 82 82 82 54 54 54 34 34 34 18 18 18
54490- 6 6 6 0 0 0 0 0 0 0 0 0
54491- 0 0 0 0 0 0 0 0 0 0 0 0
54492- 0 0 0 0 0 0 0 0 0 0 0 0
54493- 0 0 0 0 0 0 6 6 6 18 18 18
54494- 50 50 50 158 118 36 192 133 9 200 144 11
54495-216 158 10 219 162 10 224 166 10 226 170 11
54496-230 174 11 236 178 12 239 182 13 239 182 13
54497-242 186 14 246 186 14 246 190 14 246 190 14
54498-246 190 14 246 190 14 246 190 14 246 190 14
54499-246 186 14 230 174 11 210 150 10 163 110 8
54500-104 69 6 10 10 10 2 2 6 2 2 6
54501- 2 2 6 2 2 6 2 2 6 2 2 6
54502- 2 2 6 2 2 6 2 2 6 2 2 6
54503- 2 2 6 2 2 6 2 2 6 2 2 6
54504- 2 2 6 6 6 6 91 60 6 167 114 7
54505-206 145 10 230 174 11 242 186 14 246 190 14
54506-246 190 14 246 190 14 246 186 14 242 186 14
54507-239 182 13 230 174 11 224 166 10 213 154 11
54508-180 133 36 124 112 88 86 86 86 58 58 58
54509- 38 38 38 22 22 22 10 10 10 6 6 6
54510- 0 0 0 0 0 0 0 0 0 0 0 0
54511- 0 0 0 0 0 0 0 0 0 0 0 0
54512- 0 0 0 0 0 0 0 0 0 0 0 0
54513- 0 0 0 0 0 0 0 0 0 14 14 14
54514- 34 34 34 70 70 70 138 110 50 158 118 36
54515-167 114 7 180 123 7 192 133 9 197 138 11
54516-200 144 11 206 145 10 213 154 11 219 162 10
54517-224 166 10 230 174 11 239 182 13 242 186 14
54518-246 186 14 246 186 14 246 186 14 246 186 14
54519-239 182 13 216 158 10 185 133 11 152 99 6
54520-104 69 6 18 14 6 2 2 6 2 2 6
54521- 2 2 6 2 2 6 2 2 6 2 2 6
54522- 2 2 6 2 2 6 2 2 6 2 2 6
54523- 2 2 6 2 2 6 2 2 6 2 2 6
54524- 2 2 6 6 6 6 80 54 7 152 99 6
54525-192 133 9 219 162 10 236 178 12 239 182 13
54526-246 186 14 242 186 14 239 182 13 236 178 12
54527-224 166 10 206 145 10 192 133 9 154 121 60
54528- 94 94 94 62 62 62 42 42 42 22 22 22
54529- 14 14 14 6 6 6 0 0 0 0 0 0
54530- 0 0 0 0 0 0 0 0 0 0 0 0
54531- 0 0 0 0 0 0 0 0 0 0 0 0
54532- 0 0 0 0 0 0 0 0 0 0 0 0
54533- 0 0 0 0 0 0 0 0 0 6 6 6
54534- 18 18 18 34 34 34 58 58 58 78 78 78
54535-101 98 89 124 112 88 142 110 46 156 107 11
54536-163 110 8 167 114 7 175 118 6 180 123 7
54537-185 133 11 197 138 11 210 150 10 219 162 10
54538-226 170 11 236 178 12 236 178 12 234 174 13
54539-219 162 10 197 138 11 163 110 8 130 83 6
54540- 91 60 6 10 10 10 2 2 6 2 2 6
54541- 18 18 18 38 38 38 38 38 38 38 38 38
54542- 38 38 38 38 38 38 38 38 38 38 38 38
54543- 38 38 38 38 38 38 26 26 26 2 2 6
54544- 2 2 6 6 6 6 70 47 6 137 92 6
54545-175 118 6 200 144 11 219 162 10 230 174 11
54546-234 174 13 230 174 11 219 162 10 210 150 10
54547-192 133 9 163 110 8 124 112 88 82 82 82
54548- 50 50 50 30 30 30 14 14 14 6 6 6
54549- 0 0 0 0 0 0 0 0 0 0 0 0
54550- 0 0 0 0 0 0 0 0 0 0 0 0
54551- 0 0 0 0 0 0 0 0 0 0 0 0
54552- 0 0 0 0 0 0 0 0 0 0 0 0
54553- 0 0 0 0 0 0 0 0 0 0 0 0
54554- 6 6 6 14 14 14 22 22 22 34 34 34
54555- 42 42 42 58 58 58 74 74 74 86 86 86
54556-101 98 89 122 102 70 130 98 46 121 87 25
54557-137 92 6 152 99 6 163 110 8 180 123 7
54558-185 133 11 197 138 11 206 145 10 200 144 11
54559-180 123 7 156 107 11 130 83 6 104 69 6
54560- 50 34 6 54 54 54 110 110 110 101 98 89
54561- 86 86 86 82 82 82 78 78 78 78 78 78
54562- 78 78 78 78 78 78 78 78 78 78 78 78
54563- 78 78 78 82 82 82 86 86 86 94 94 94
54564-106 106 106 101 101 101 86 66 34 124 80 6
54565-156 107 11 180 123 7 192 133 9 200 144 11
54566-206 145 10 200 144 11 192 133 9 175 118 6
54567-139 102 15 109 106 95 70 70 70 42 42 42
54568- 22 22 22 10 10 10 0 0 0 0 0 0
54569- 0 0 0 0 0 0 0 0 0 0 0 0
54570- 0 0 0 0 0 0 0 0 0 0 0 0
54571- 0 0 0 0 0 0 0 0 0 0 0 0
54572- 0 0 0 0 0 0 0 0 0 0 0 0
54573- 0 0 0 0 0 0 0 0 0 0 0 0
54574- 0 0 0 0 0 0 6 6 6 10 10 10
54575- 14 14 14 22 22 22 30 30 30 38 38 38
54576- 50 50 50 62 62 62 74 74 74 90 90 90
54577-101 98 89 112 100 78 121 87 25 124 80 6
54578-137 92 6 152 99 6 152 99 6 152 99 6
54579-138 86 6 124 80 6 98 70 6 86 66 30
54580-101 98 89 82 82 82 58 58 58 46 46 46
54581- 38 38 38 34 34 34 34 34 34 34 34 34
54582- 34 34 34 34 34 34 34 34 34 34 34 34
54583- 34 34 34 34 34 34 38 38 38 42 42 42
54584- 54 54 54 82 82 82 94 86 76 91 60 6
54585-134 86 6 156 107 11 167 114 7 175 118 6
54586-175 118 6 167 114 7 152 99 6 121 87 25
54587-101 98 89 62 62 62 34 34 34 18 18 18
54588- 6 6 6 0 0 0 0 0 0 0 0 0
54589- 0 0 0 0 0 0 0 0 0 0 0 0
54590- 0 0 0 0 0 0 0 0 0 0 0 0
54591- 0 0 0 0 0 0 0 0 0 0 0 0
54592- 0 0 0 0 0 0 0 0 0 0 0 0
54593- 0 0 0 0 0 0 0 0 0 0 0 0
54594- 0 0 0 0 0 0 0 0 0 0 0 0
54595- 0 0 0 6 6 6 6 6 6 10 10 10
54596- 18 18 18 22 22 22 30 30 30 42 42 42
54597- 50 50 50 66 66 66 86 86 86 101 98 89
54598-106 86 58 98 70 6 104 69 6 104 69 6
54599-104 69 6 91 60 6 82 62 34 90 90 90
54600- 62 62 62 38 38 38 22 22 22 14 14 14
54601- 10 10 10 10 10 10 10 10 10 10 10 10
54602- 10 10 10 10 10 10 6 6 6 10 10 10
54603- 10 10 10 10 10 10 10 10 10 14 14 14
54604- 22 22 22 42 42 42 70 70 70 89 81 66
54605- 80 54 7 104 69 6 124 80 6 137 92 6
54606-134 86 6 116 81 8 100 82 52 86 86 86
54607- 58 58 58 30 30 30 14 14 14 6 6 6
54608- 0 0 0 0 0 0 0 0 0 0 0 0
54609- 0 0 0 0 0 0 0 0 0 0 0 0
54610- 0 0 0 0 0 0 0 0 0 0 0 0
54611- 0 0 0 0 0 0 0 0 0 0 0 0
54612- 0 0 0 0 0 0 0 0 0 0 0 0
54613- 0 0 0 0 0 0 0 0 0 0 0 0
54614- 0 0 0 0 0 0 0 0 0 0 0 0
54615- 0 0 0 0 0 0 0 0 0 0 0 0
54616- 0 0 0 6 6 6 10 10 10 14 14 14
54617- 18 18 18 26 26 26 38 38 38 54 54 54
54618- 70 70 70 86 86 86 94 86 76 89 81 66
54619- 89 81 66 86 86 86 74 74 74 50 50 50
54620- 30 30 30 14 14 14 6 6 6 0 0 0
54621- 0 0 0 0 0 0 0 0 0 0 0 0
54622- 0 0 0 0 0 0 0 0 0 0 0 0
54623- 0 0 0 0 0 0 0 0 0 0 0 0
54624- 6 6 6 18 18 18 34 34 34 58 58 58
54625- 82 82 82 89 81 66 89 81 66 89 81 66
54626- 94 86 66 94 86 76 74 74 74 50 50 50
54627- 26 26 26 14 14 14 6 6 6 0 0 0
54628- 0 0 0 0 0 0 0 0 0 0 0 0
54629- 0 0 0 0 0 0 0 0 0 0 0 0
54630- 0 0 0 0 0 0 0 0 0 0 0 0
54631- 0 0 0 0 0 0 0 0 0 0 0 0
54632- 0 0 0 0 0 0 0 0 0 0 0 0
54633- 0 0 0 0 0 0 0 0 0 0 0 0
54634- 0 0 0 0 0 0 0 0 0 0 0 0
54635- 0 0 0 0 0 0 0 0 0 0 0 0
54636- 0 0 0 0 0 0 0 0 0 0 0 0
54637- 6 6 6 6 6 6 14 14 14 18 18 18
54638- 30 30 30 38 38 38 46 46 46 54 54 54
54639- 50 50 50 42 42 42 30 30 30 18 18 18
54640- 10 10 10 0 0 0 0 0 0 0 0 0
54641- 0 0 0 0 0 0 0 0 0 0 0 0
54642- 0 0 0 0 0 0 0 0 0 0 0 0
54643- 0 0 0 0 0 0 0 0 0 0 0 0
54644- 0 0 0 6 6 6 14 14 14 26 26 26
54645- 38 38 38 50 50 50 58 58 58 58 58 58
54646- 54 54 54 42 42 42 30 30 30 18 18 18
54647- 10 10 10 0 0 0 0 0 0 0 0 0
54648- 0 0 0 0 0 0 0 0 0 0 0 0
54649- 0 0 0 0 0 0 0 0 0 0 0 0
54650- 0 0 0 0 0 0 0 0 0 0 0 0
54651- 0 0 0 0 0 0 0 0 0 0 0 0
54652- 0 0 0 0 0 0 0 0 0 0 0 0
54653- 0 0 0 0 0 0 0 0 0 0 0 0
54654- 0 0 0 0 0 0 0 0 0 0 0 0
54655- 0 0 0 0 0 0 0 0 0 0 0 0
54656- 0 0 0 0 0 0 0 0 0 0 0 0
54657- 0 0 0 0 0 0 0 0 0 6 6 6
54658- 6 6 6 10 10 10 14 14 14 18 18 18
54659- 18 18 18 14 14 14 10 10 10 6 6 6
54660- 0 0 0 0 0 0 0 0 0 0 0 0
54661- 0 0 0 0 0 0 0 0 0 0 0 0
54662- 0 0 0 0 0 0 0 0 0 0 0 0
54663- 0 0 0 0 0 0 0 0 0 0 0 0
54664- 0 0 0 0 0 0 0 0 0 6 6 6
54665- 14 14 14 18 18 18 22 22 22 22 22 22
54666- 18 18 18 14 14 14 10 10 10 6 6 6
54667- 0 0 0 0 0 0 0 0 0 0 0 0
54668- 0 0 0 0 0 0 0 0 0 0 0 0
54669- 0 0 0 0 0 0 0 0 0 0 0 0
54670- 0 0 0 0 0 0 0 0 0 0 0 0
54671- 0 0 0 0 0 0 0 0 0 0 0 0
54672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54685+4 4 4 4 4 4
54686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54699+4 4 4 4 4 4
54700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54713+4 4 4 4 4 4
54714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54727+4 4 4 4 4 4
54728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54741+4 4 4 4 4 4
54742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54755+4 4 4 4 4 4
54756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54760+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54761+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54765+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54766+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54767+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54769+4 4 4 4 4 4
54770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54774+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54775+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54776+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54779+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54780+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54781+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54782+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54783+4 4 4 4 4 4
54784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54788+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54789+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54790+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54793+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54794+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54795+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54796+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54797+4 4 4 4 4 4
54798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54801+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54802+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54803+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54804+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54806+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54807+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54808+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54809+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54810+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54811+4 4 4 4 4 4
54812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54815+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54816+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54817+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54818+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54819+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54820+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54821+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54822+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54823+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54824+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54825+4 4 4 4 4 4
54826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54829+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54830+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54831+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54832+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54833+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54834+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54835+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54836+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54837+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54838+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54839+4 4 4 4 4 4
54840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54842+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54843+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54844+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54845+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54846+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54847+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54848+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54849+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54850+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54851+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54852+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54853+4 4 4 4 4 4
54854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54856+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54857+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54858+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54859+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54860+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54861+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54862+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54863+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54864+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54865+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54866+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54867+4 4 4 4 4 4
54868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54870+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54871+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54872+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54873+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54874+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54875+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54876+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54877+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54878+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54879+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54880+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54881+4 4 4 4 4 4
54882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54884+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54885+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54886+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54887+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54888+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54889+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54890+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54891+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54892+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54893+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54894+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54895+4 4 4 4 4 4
54896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54897+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54898+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54899+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54900+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54901+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54902+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54903+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54904+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54905+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54906+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54907+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54908+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54909+4 4 4 4 4 4
54910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54911+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54912+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54913+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54914+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54915+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54916+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54917+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54918+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54919+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54920+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54921+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54922+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54923+0 0 0 4 4 4
54924+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54925+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54926+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54927+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54928+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54929+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54930+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54931+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54932+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54933+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54934+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54935+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54936+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54937+2 0 0 0 0 0
54938+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54939+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54940+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54941+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54942+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54943+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54944+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54945+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54946+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54947+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54948+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54949+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54950+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54951+37 38 37 0 0 0
54952+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54953+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54954+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54955+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54956+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54957+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54958+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54959+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54960+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54961+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54962+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54963+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54964+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54965+85 115 134 4 0 0
54966+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54967+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54968+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54969+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54970+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54971+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54972+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54973+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54974+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54975+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54976+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54977+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54978+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54979+60 73 81 4 0 0
54980+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54981+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54982+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54983+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54984+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54985+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54986+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54987+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54988+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54989+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54990+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54991+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54992+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54993+16 19 21 4 0 0
54994+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54995+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54996+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54997+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54998+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54999+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55000+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55001+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55002+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55003+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55004+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55005+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55006+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55007+4 0 0 4 3 3
55008+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55009+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55010+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55012+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55013+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55014+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55015+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55016+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55017+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55018+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55019+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55020+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55021+3 2 2 4 4 4
55022+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55023+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55024+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55025+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55026+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55027+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55028+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55029+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55030+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55031+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55032+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55033+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55034+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55035+4 4 4 4 4 4
55036+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55037+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55038+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55039+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55040+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55041+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55042+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55043+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55044+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55045+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55046+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55047+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55048+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55049+4 4 4 4 4 4
55050+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55051+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55052+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55053+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55054+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55055+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55056+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55057+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55058+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55059+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55060+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55061+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55062+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55063+5 5 5 5 5 5
55064+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55065+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55066+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55067+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55068+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55069+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55070+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55071+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55072+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55073+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55074+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55075+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55076+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55077+5 5 5 4 4 4
55078+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55079+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55080+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55081+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55082+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55083+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55084+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55085+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55086+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55087+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55088+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55089+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55091+4 4 4 4 4 4
55092+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55093+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55094+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55095+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55096+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55097+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55098+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55099+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55100+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55101+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55102+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55103+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55105+4 4 4 4 4 4
55106+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55107+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55108+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55109+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55110+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55111+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55112+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55113+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55114+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55115+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55116+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55119+4 4 4 4 4 4
55120+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55121+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55122+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55123+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55124+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55125+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55126+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55127+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55128+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55129+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55130+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55133+4 4 4 4 4 4
55134+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55135+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55136+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55137+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55138+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55139+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55140+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55141+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55142+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55143+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55144+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55147+4 4 4 4 4 4
55148+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55149+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55150+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55151+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55152+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55153+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55154+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55155+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55156+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55157+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55158+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55161+4 4 4 4 4 4
55162+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55163+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55164+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55165+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55166+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55167+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55168+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55169+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55170+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55171+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55172+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55175+4 4 4 4 4 4
55176+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55177+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55178+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55179+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55180+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55181+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55182+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55183+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55184+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55185+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55186+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55189+4 4 4 4 4 4
55190+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55191+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55192+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55193+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55194+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55195+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55196+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55197+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55198+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55199+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55200+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55203+4 4 4 4 4 4
55204+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55205+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55206+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55207+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55208+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55209+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55210+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55211+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55212+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55213+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55214+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55217+4 4 4 4 4 4
55218+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55219+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55220+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55221+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55222+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55223+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55224+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55225+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55226+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55227+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55228+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55231+4 4 4 4 4 4
55232+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55233+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55234+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55235+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55236+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55237+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55238+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55239+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55240+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55241+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55242+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55245+4 4 4 4 4 4
55246+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55247+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55248+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55249+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55250+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55251+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55252+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55253+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55254+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55255+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55256+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
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
55260+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55261+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55262+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55263+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55264+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55265+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55266+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55267+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55268+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55269+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55270+0 0 0 3 3 3 5 5 5 4 4 4 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
55274+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55275+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55276+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55277+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55278+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55279+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55280+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55281+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55282+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55283+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55284+0 0 0 3 3 3 5 5 5 4 4 4 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
55288+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55289+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55290+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55291+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55292+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55293+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55294+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55295+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55296+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55297+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55298+0 0 0 3 3 3 5 5 5 4 4 4 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
55302+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55303+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55304+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55305+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55306+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55307+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55308+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55309+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55310+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55311+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55312+0 0 0 3 3 3 5 5 5 4 4 4 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
55316+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55317+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55318+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55319+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55320+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55321+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55322+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55323+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55324+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55325+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55326+0 0 0 3 3 3 5 5 5 4 4 4 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
55330+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55331+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55332+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55333+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55334+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55335+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55336+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55337+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55338+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55339+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55340+0 0 0 3 3 3 5 5 5 4 4 4 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
55344+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55345+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55346+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55347+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55348+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55349+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55350+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55351+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55352+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55353+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55354+0 0 0 3 3 3 5 5 5 4 4 4 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
55358+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55359+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55360+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55361+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55362+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55363+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55364+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55365+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55366+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55367+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55368+0 0 0 3 3 3 5 5 5 4 4 4 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
55372+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55373+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55374+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55375+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55376+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55377+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55378+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55379+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55380+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55381+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55382+0 0 0 3 3 3 5 5 5 4 4 4 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
55386+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55387+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55388+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55389+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55390+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55391+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55392+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55393+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55394+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55395+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55396+0 0 0 3 3 3 5 5 5 4 4 4 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
55400+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55401+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55402+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55403+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55404+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55405+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55406+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55407+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55408+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55409+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55410+0 0 0 3 3 3 5 5 5 4 4 4 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
55414+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55415+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55416+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55417+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55418+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55419+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55420+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55421+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55422+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55423+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55424+0 0 0 3 3 3 5 5 5 4 4 4 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
55428+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55429+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55430+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55431+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55432+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55433+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55434+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55435+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55436+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55437+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55438+0 0 0 3 3 3 5 5 5 4 4 4 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
55442+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55443+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55444+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55445+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55446+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55447+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55448+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55449+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55450+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55451+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55452+0 0 0 4 4 4 4 4 4 4 4 4 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 4 4 4
55456+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55457+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55458+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55459+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55460+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55461+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55462+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55463+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55464+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55465+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55466+4 3 3 5 5 5 4 4 4 4 4 4 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+4 4 4 4 4 4
55470+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55471+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55472+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55473+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55474+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55475+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55476+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55477+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55478+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55479+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55480+5 5 5 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
55483+4 4 4 4 4 4
55484+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55485+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55486+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55487+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55488+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55489+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55490+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55491+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55492+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55493+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55494+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55497+4 4 4 4 4 4
55498+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55499+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55500+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55501+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55502+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55503+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55504+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55505+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55506+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55507+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55511+4 4 4 4 4 4
55512+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55513+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55514+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55515+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55516+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55517+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55518+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55519+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55520+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55521+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55523+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55525+4 4 4 4 4 4
55526+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55527+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55528+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55529+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55530+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55531+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55532+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55533+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55534+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55535+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55539+4 4 4 4 4 4
55540+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55541+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55542+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55543+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55544+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55545+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55546+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55547+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55548+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55553+4 4 4 4 4 4
55554+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55555+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55556+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55557+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55558+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55559+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55560+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55561+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55562+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55567+4 4 4 4 4 4
55568+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55569+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55570+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55571+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55572+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55573+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55574+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55575+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55576+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55581+4 4 4 4 4 4
55582+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55583+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55584+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55585+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55586+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55587+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55588+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55589+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55595+4 4 4 4 4 4
55596+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55597+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55598+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55599+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55600+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55601+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55602+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55603+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55609+4 4 4 4 4 4
55610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55611+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55612+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55613+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55614+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55615+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55616+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55617+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55623+4 4 4 4 4 4
55624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55625+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55626+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55627+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55628+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55629+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55630+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55631+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55637+4 4 4 4 4 4
55638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55639+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55640+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55641+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55642+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55643+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55644+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55645+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55651+4 4 4 4 4 4
55652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55654+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55655+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55656+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55657+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55658+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55659+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55665+4 4 4 4 4 4
55666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55669+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55670+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55671+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55672+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55679+4 4 4 4 4 4
55680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55683+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55684+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55685+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55686+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55693+4 4 4 4 4 4
55694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55697+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55698+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55699+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55700+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55707+4 4 4 4 4 4
55708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55711+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55712+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55713+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55714+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
55715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55721+4 4 4 4 4 4
55722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55726+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55727+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55728+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55735+4 4 4 4 4 4
55736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55740+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55741+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55742+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55749+4 4 4 4 4 4
55750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55754+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55755+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55756+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55763+4 4 4 4 4 4
55764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55768+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55769+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55777+4 4 4 4 4 4
55778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55782+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55783+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55791+4 4 4 4 4 4
55792diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55793index a01147f..5d896f8 100644
55794--- a/drivers/video/matrox/matroxfb_DAC1064.c
55795+++ b/drivers/video/matrox/matroxfb_DAC1064.c
55796@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55797
55798 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55799 struct matrox_switch matrox_mystique = {
55800- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55801+ .preinit = MGA1064_preinit,
55802+ .reset = MGA1064_reset,
55803+ .init = MGA1064_init,
55804+ .restore = MGA1064_restore,
55805 };
55806 EXPORT_SYMBOL(matrox_mystique);
55807 #endif
55808
55809 #ifdef CONFIG_FB_MATROX_G
55810 struct matrox_switch matrox_G100 = {
55811- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55812+ .preinit = MGAG100_preinit,
55813+ .reset = MGAG100_reset,
55814+ .init = MGAG100_init,
55815+ .restore = MGAG100_restore,
55816 };
55817 EXPORT_SYMBOL(matrox_G100);
55818 #endif
55819diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55820index 195ad7c..09743fc 100644
55821--- a/drivers/video/matrox/matroxfb_Ti3026.c
55822+++ b/drivers/video/matrox/matroxfb_Ti3026.c
55823@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55824 }
55825
55826 struct matrox_switch matrox_millennium = {
55827- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55828+ .preinit = Ti3026_preinit,
55829+ .reset = Ti3026_reset,
55830+ .init = Ti3026_init,
55831+ .restore = Ti3026_restore
55832 };
55833 EXPORT_SYMBOL(matrox_millennium);
55834 #endif
55835diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55836index fe92eed..106e085 100644
55837--- a/drivers/video/mb862xx/mb862xxfb_accel.c
55838+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55839@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55840 struct mb862xxfb_par *par = info->par;
55841
55842 if (info->var.bits_per_pixel == 32) {
55843- info->fbops->fb_fillrect = cfb_fillrect;
55844- info->fbops->fb_copyarea = cfb_copyarea;
55845- info->fbops->fb_imageblit = cfb_imageblit;
55846+ pax_open_kernel();
55847+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55848+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55849+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55850+ pax_close_kernel();
55851 } else {
55852 outreg(disp, GC_L0EM, 3);
55853- info->fbops->fb_fillrect = mb86290fb_fillrect;
55854- info->fbops->fb_copyarea = mb86290fb_copyarea;
55855- info->fbops->fb_imageblit = mb86290fb_imageblit;
55856+ pax_open_kernel();
55857+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55858+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55859+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55860+ pax_close_kernel();
55861 }
55862 outreg(draw, GDC_REG_DRAW_BASE, 0);
55863 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55864diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55865index def0412..fed6529 100644
55866--- a/drivers/video/nvidia/nvidia.c
55867+++ b/drivers/video/nvidia/nvidia.c
55868@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55869 info->fix.line_length = (info->var.xres_virtual *
55870 info->var.bits_per_pixel) >> 3;
55871 if (info->var.accel_flags) {
55872- info->fbops->fb_imageblit = nvidiafb_imageblit;
55873- info->fbops->fb_fillrect = nvidiafb_fillrect;
55874- info->fbops->fb_copyarea = nvidiafb_copyarea;
55875- info->fbops->fb_sync = nvidiafb_sync;
55876+ pax_open_kernel();
55877+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55878+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55879+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55880+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55881+ pax_close_kernel();
55882 info->pixmap.scan_align = 4;
55883 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55884 info->flags |= FBINFO_READS_FAST;
55885 NVResetGraphics(info);
55886 } else {
55887- info->fbops->fb_imageblit = cfb_imageblit;
55888- info->fbops->fb_fillrect = cfb_fillrect;
55889- info->fbops->fb_copyarea = cfb_copyarea;
55890- info->fbops->fb_sync = NULL;
55891+ pax_open_kernel();
55892+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55893+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55894+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55895+ *(void **)&info->fbops->fb_sync = NULL;
55896+ pax_close_kernel();
55897 info->pixmap.scan_align = 1;
55898 info->flags |= FBINFO_HWACCEL_DISABLED;
55899 info->flags &= ~FBINFO_READS_FAST;
55900@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55901 info->pixmap.size = 8 * 1024;
55902 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55903
55904- if (!hwcur)
55905- info->fbops->fb_cursor = NULL;
55906+ if (!hwcur) {
55907+ pax_open_kernel();
55908+ *(void **)&info->fbops->fb_cursor = NULL;
55909+ pax_close_kernel();
55910+ }
55911
55912 info->var.accel_flags = (!noaccel);
55913
55914diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55915index 669a81f..e216d76 100644
55916--- a/drivers/video/omap2/dss/display.c
55917+++ b/drivers/video/omap2/dss/display.c
55918@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55919 snprintf(dssdev->alias, sizeof(dssdev->alias),
55920 "display%d", disp_num_counter++);
55921
55922+ pax_open_kernel();
55923 if (drv && drv->get_resolution == NULL)
55924- drv->get_resolution = omapdss_default_get_resolution;
55925+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55926 if (drv && drv->get_recommended_bpp == NULL)
55927- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55928+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55929 if (drv && drv->get_timings == NULL)
55930- drv->get_timings = omapdss_default_get_timings;
55931+ *(void **)&drv->get_timings = omapdss_default_get_timings;
55932+ pax_close_kernel();
55933
55934 mutex_lock(&panel_list_mutex);
55935 list_add_tail(&dssdev->panel_list, &panel_list);
55936diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55937index 83433cb..71e9b98 100644
55938--- a/drivers/video/s1d13xxxfb.c
55939+++ b/drivers/video/s1d13xxxfb.c
55940@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55941
55942 switch(prod_id) {
55943 case S1D13506_PROD_ID: /* activate acceleration */
55944- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55945- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55946+ pax_open_kernel();
55947+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55948+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55949+ pax_close_kernel();
55950 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55951 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55952 break;
55953diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
55954index 2bcc84a..29dd1ea 100644
55955--- a/drivers/video/sh_mobile_lcdcfb.c
55956+++ b/drivers/video/sh_mobile_lcdcfb.c
55957@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55958 }
55959
55960 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55961- lcdc_sys_write_index,
55962- lcdc_sys_write_data,
55963- lcdc_sys_read_data,
55964+ .write_index = lcdc_sys_write_index,
55965+ .write_data = lcdc_sys_write_data,
55966+ .read_data = lcdc_sys_read_data,
55967 };
55968
55969 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55970diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55971index d513ed6..90b0de9 100644
55972--- a/drivers/video/smscufx.c
55973+++ b/drivers/video/smscufx.c
55974@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55975 fb_deferred_io_cleanup(info);
55976 kfree(info->fbdefio);
55977 info->fbdefio = NULL;
55978- info->fbops->fb_mmap = ufx_ops_mmap;
55979+ pax_open_kernel();
55980+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55981+ pax_close_kernel();
55982 }
55983
55984 pr_debug("released /dev/fb%d user=%d count=%d",
55985diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55986index 77b890e..458e666 100644
55987--- a/drivers/video/udlfb.c
55988+++ b/drivers/video/udlfb.c
55989@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55990 dlfb_urb_completion(urb);
55991
55992 error:
55993- atomic_add(bytes_sent, &dev->bytes_sent);
55994- atomic_add(bytes_identical, &dev->bytes_identical);
55995- atomic_add(width*height*2, &dev->bytes_rendered);
55996+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55997+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55998+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55999 end_cycles = get_cycles();
56000- atomic_add(((unsigned int) ((end_cycles - start_cycles)
56001+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56002 >> 10)), /* Kcycles */
56003 &dev->cpu_kcycles_used);
56004
56005@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
56006 dlfb_urb_completion(urb);
56007
56008 error:
56009- atomic_add(bytes_sent, &dev->bytes_sent);
56010- atomic_add(bytes_identical, &dev->bytes_identical);
56011- atomic_add(bytes_rendered, &dev->bytes_rendered);
56012+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56013+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56014+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
56015 end_cycles = get_cycles();
56016- atomic_add(((unsigned int) ((end_cycles - start_cycles)
56017+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56018 >> 10)), /* Kcycles */
56019 &dev->cpu_kcycles_used);
56020 }
56021@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
56022 fb_deferred_io_cleanup(info);
56023 kfree(info->fbdefio);
56024 info->fbdefio = NULL;
56025- info->fbops->fb_mmap = dlfb_ops_mmap;
56026+ pax_open_kernel();
56027+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
56028+ pax_close_kernel();
56029 }
56030
56031 pr_warn("released /dev/fb%d user=%d count=%d\n",
56032@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
56033 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56034 struct dlfb_data *dev = fb_info->par;
56035 return snprintf(buf, PAGE_SIZE, "%u\n",
56036- atomic_read(&dev->bytes_rendered));
56037+ atomic_read_unchecked(&dev->bytes_rendered));
56038 }
56039
56040 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56041@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56042 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56043 struct dlfb_data *dev = fb_info->par;
56044 return snprintf(buf, PAGE_SIZE, "%u\n",
56045- atomic_read(&dev->bytes_identical));
56046+ atomic_read_unchecked(&dev->bytes_identical));
56047 }
56048
56049 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56050@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56051 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56052 struct dlfb_data *dev = fb_info->par;
56053 return snprintf(buf, PAGE_SIZE, "%u\n",
56054- atomic_read(&dev->bytes_sent));
56055+ atomic_read_unchecked(&dev->bytes_sent));
56056 }
56057
56058 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56059@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56060 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56061 struct dlfb_data *dev = fb_info->par;
56062 return snprintf(buf, PAGE_SIZE, "%u\n",
56063- atomic_read(&dev->cpu_kcycles_used));
56064+ atomic_read_unchecked(&dev->cpu_kcycles_used));
56065 }
56066
56067 static ssize_t edid_show(
56068@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
56069 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56070 struct dlfb_data *dev = fb_info->par;
56071
56072- atomic_set(&dev->bytes_rendered, 0);
56073- atomic_set(&dev->bytes_identical, 0);
56074- atomic_set(&dev->bytes_sent, 0);
56075- atomic_set(&dev->cpu_kcycles_used, 0);
56076+ atomic_set_unchecked(&dev->bytes_rendered, 0);
56077+ atomic_set_unchecked(&dev->bytes_identical, 0);
56078+ atomic_set_unchecked(&dev->bytes_sent, 0);
56079+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
56080
56081 return count;
56082 }
56083diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
56084index 256fba7..6e75516 100644
56085--- a/drivers/video/uvesafb.c
56086+++ b/drivers/video/uvesafb.c
56087@@ -19,6 +19,7 @@
56088 #include <linux/io.h>
56089 #include <linux/mutex.h>
56090 #include <linux/slab.h>
56091+#include <linux/moduleloader.h>
56092 #include <video/edid.h>
56093 #include <video/uvesafb.h>
56094 #ifdef CONFIG_X86
56095@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
56096 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
56097 par->pmi_setpal = par->ypan = 0;
56098 } else {
56099+
56100+#ifdef CONFIG_PAX_KERNEXEC
56101+#ifdef CONFIG_MODULES
56102+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
56103+#endif
56104+ if (!par->pmi_code) {
56105+ par->pmi_setpal = par->ypan = 0;
56106+ return 0;
56107+ }
56108+#endif
56109+
56110 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
56111 + task->t.regs.edi);
56112+
56113+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56114+ pax_open_kernel();
56115+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
56116+ pax_close_kernel();
56117+
56118+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
56119+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
56120+#else
56121 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
56122 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
56123+#endif
56124+
56125 printk(KERN_INFO "uvesafb: protected mode interface info at "
56126 "%04x:%04x\n",
56127 (u16)task->t.regs.es, (u16)task->t.regs.edi);
56128@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
56129 par->ypan = ypan;
56130
56131 if (par->pmi_setpal || par->ypan) {
56132+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
56133 if (__supported_pte_mask & _PAGE_NX) {
56134 par->pmi_setpal = par->ypan = 0;
56135 printk(KERN_WARNING "uvesafb: NX protection is active, "
56136 "better not use the PMI.\n");
56137- } else {
56138+ } else
56139+#endif
56140 uvesafb_vbe_getpmi(task, par);
56141- }
56142 }
56143 #else
56144 /* The protected mode interface is not available on non-x86. */
56145@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56146 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
56147
56148 /* Disable blanking if the user requested so. */
56149- if (!blank)
56150- info->fbops->fb_blank = NULL;
56151+ if (!blank) {
56152+ pax_open_kernel();
56153+ *(void **)&info->fbops->fb_blank = NULL;
56154+ pax_close_kernel();
56155+ }
56156
56157 /*
56158 * Find out how much IO memory is required for the mode with
56159@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56160 info->flags = FBINFO_FLAG_DEFAULT |
56161 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
56162
56163- if (!par->ypan)
56164- info->fbops->fb_pan_display = NULL;
56165+ if (!par->ypan) {
56166+ pax_open_kernel();
56167+ *(void **)&info->fbops->fb_pan_display = NULL;
56168+ pax_close_kernel();
56169+ }
56170 }
56171
56172 static void uvesafb_init_mtrr(struct fb_info *info)
56173@@ -1792,6 +1822,11 @@ out_mode:
56174 out:
56175 kfree(par->vbe_modes);
56176
56177+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56178+ if (par->pmi_code)
56179+ module_free_exec(NULL, par->pmi_code);
56180+#endif
56181+
56182 framebuffer_release(info);
56183 return err;
56184 }
56185@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
56186 kfree(par->vbe_modes);
56187 kfree(par->vbe_state_orig);
56188 kfree(par->vbe_state_saved);
56189+
56190+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56191+ if (par->pmi_code)
56192+ module_free_exec(NULL, par->pmi_code);
56193+#endif
56194+
56195 }
56196
56197 framebuffer_release(info);
56198diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
56199index 1c7da3b..56ea0bd 100644
56200--- a/drivers/video/vesafb.c
56201+++ b/drivers/video/vesafb.c
56202@@ -9,6 +9,7 @@
56203 */
56204
56205 #include <linux/module.h>
56206+#include <linux/moduleloader.h>
56207 #include <linux/kernel.h>
56208 #include <linux/errno.h>
56209 #include <linux/string.h>
56210@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
56211 static int vram_total; /* Set total amount of memory */
56212 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
56213 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
56214-static void (*pmi_start)(void) __read_mostly;
56215-static void (*pmi_pal) (void) __read_mostly;
56216+static void (*pmi_start)(void) __read_only;
56217+static void (*pmi_pal) (void) __read_only;
56218 static int depth __read_mostly;
56219 static int vga_compat __read_mostly;
56220 /* --------------------------------------------------------------------- */
56221@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
56222 unsigned int size_remap;
56223 unsigned int size_total;
56224 char *option = NULL;
56225+ void *pmi_code = NULL;
56226
56227 /* ignore error return of fb_get_options */
56228 fb_get_options("vesafb", &option);
56229@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
56230 size_remap = size_total;
56231 vesafb_fix.smem_len = size_remap;
56232
56233-#ifndef __i386__
56234- screen_info.vesapm_seg = 0;
56235-#endif
56236-
56237 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
56238 printk(KERN_WARNING
56239 "vesafb: cannot reserve video memory at 0x%lx\n",
56240@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
56241 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
56242 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
56243
56244+#ifdef __i386__
56245+
56246+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56247+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
56248+ if (!pmi_code)
56249+#elif !defined(CONFIG_PAX_KERNEXEC)
56250+ if (0)
56251+#endif
56252+
56253+#endif
56254+ screen_info.vesapm_seg = 0;
56255+
56256 if (screen_info.vesapm_seg) {
56257- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
56258- screen_info.vesapm_seg,screen_info.vesapm_off);
56259+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
56260+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
56261 }
56262
56263 if (screen_info.vesapm_seg < 0xc000)
56264@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
56265
56266 if (ypan || pmi_setpal) {
56267 unsigned short *pmi_base;
56268+
56269 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
56270- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
56271- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
56272+
56273+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56274+ pax_open_kernel();
56275+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
56276+#else
56277+ pmi_code = pmi_base;
56278+#endif
56279+
56280+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
56281+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
56282+
56283+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56284+ pmi_start = ktva_ktla(pmi_start);
56285+ pmi_pal = ktva_ktla(pmi_pal);
56286+ pax_close_kernel();
56287+#endif
56288+
56289 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
56290 if (pmi_base[3]) {
56291 printk(KERN_INFO "vesafb: pmi: ports = ");
56292@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
56293 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
56294 (ypan ? FBINFO_HWACCEL_YPAN : 0);
56295
56296- if (!ypan)
56297- info->fbops->fb_pan_display = NULL;
56298+ if (!ypan) {
56299+ pax_open_kernel();
56300+ *(void **)&info->fbops->fb_pan_display = NULL;
56301+ pax_close_kernel();
56302+ }
56303
56304 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
56305 err = -ENOMEM;
56306@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
56307 fb_info(info, "%s frame buffer device\n", info->fix.id);
56308 return 0;
56309 err:
56310+
56311+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56312+ module_free_exec(NULL, pmi_code);
56313+#endif
56314+
56315 if (info->screen_base)
56316 iounmap(info->screen_base);
56317 framebuffer_release(info);
56318diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
56319index 88714ae..16c2e11 100644
56320--- a/drivers/video/via/via_clock.h
56321+++ b/drivers/video/via/via_clock.h
56322@@ -56,7 +56,7 @@ struct via_clock {
56323
56324 void (*set_engine_pll_state)(u8 state);
56325 void (*set_engine_pll)(struct via_pll_config config);
56326-};
56327+} __no_const;
56328
56329
56330 static inline u32 get_pll_internal_frequency(u32 ref_freq,
56331diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
56332index fef20db..d28b1ab 100644
56333--- a/drivers/xen/xenfs/xenstored.c
56334+++ b/drivers/xen/xenfs/xenstored.c
56335@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
56336 static int xsd_kva_open(struct inode *inode, struct file *file)
56337 {
56338 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
56339+#ifdef CONFIG_GRKERNSEC_HIDESYM
56340+ NULL);
56341+#else
56342 xen_store_interface);
56343+#endif
56344+
56345 if (!file->private_data)
56346 return -ENOMEM;
56347 return 0;
56348diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
56349index c71e886..61d3d44b 100644
56350--- a/fs/9p/vfs_addr.c
56351+++ b/fs/9p/vfs_addr.c
56352@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
56353
56354 retval = v9fs_file_write_internal(inode,
56355 v9inode->writeback_fid,
56356- (__force const char __user *)buffer,
56357+ (const char __force_user *)buffer,
56358 len, &offset, 0);
56359 if (retval > 0)
56360 retval = 0;
56361diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
56362index bb7991c..481e21a 100644
56363--- a/fs/9p/vfs_inode.c
56364+++ b/fs/9p/vfs_inode.c
56365@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56366 void
56367 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56368 {
56369- char *s = nd_get_link(nd);
56370+ const char *s = nd_get_link(nd);
56371
56372 p9_debug(P9_DEBUG_VFS, " %s %s\n",
56373 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
56374diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
56375index 370b24c..ff0be7b 100644
56376--- a/fs/Kconfig.binfmt
56377+++ b/fs/Kconfig.binfmt
56378@@ -103,7 +103,7 @@ config HAVE_AOUT
56379
56380 config BINFMT_AOUT
56381 tristate "Kernel support for a.out and ECOFF binaries"
56382- depends on HAVE_AOUT
56383+ depends on HAVE_AOUT && BROKEN
56384 ---help---
56385 A.out (Assembler.OUTput) is a set of formats for libraries and
56386 executables used in the earliest versions of UNIX. Linux used
56387diff --git a/fs/affs/super.c b/fs/affs/super.c
56388index d098731..9a5b19d 100644
56389--- a/fs/affs/super.c
56390+++ b/fs/affs/super.c
56391@@ -336,8 +336,6 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
56392 &blocksize,&sbi->s_prefix,
56393 sbi->s_volume, &mount_flags)) {
56394 printk(KERN_ERR "AFFS: Error parsing options\n");
56395- kfree(sbi->s_prefix);
56396- kfree(sbi);
56397 return -EINVAL;
56398 }
56399 /* N.B. after this point s_prefix must be released */
56400diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56401index ce25d75..dc09eeb 100644
56402--- a/fs/afs/inode.c
56403+++ b/fs/afs/inode.c
56404@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56405 struct afs_vnode *vnode;
56406 struct super_block *sb;
56407 struct inode *inode;
56408- static atomic_t afs_autocell_ino;
56409+ static atomic_unchecked_t afs_autocell_ino;
56410
56411 _enter("{%x:%u},%*.*s,",
56412 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56413@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56414 data.fid.unique = 0;
56415 data.fid.vnode = 0;
56416
56417- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56418+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56419 afs_iget5_autocell_test, afs_iget5_set,
56420 &data);
56421 if (!inode) {
56422diff --git a/fs/aio.c b/fs/aio.c
56423index 12a3de0e..25949c1 100644
56424--- a/fs/aio.c
56425+++ b/fs/aio.c
56426@@ -375,7 +375,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56427 size += sizeof(struct io_event) * nr_events;
56428
56429 nr_pages = PFN_UP(size);
56430- if (nr_pages < 0)
56431+ if (nr_pages <= 0)
56432 return -EINVAL;
56433
56434 file = aio_private_file(ctx, nr_pages);
56435@@ -1299,10 +1299,8 @@ rw_common:
56436 &iovec, compat)
56437 : aio_setup_single_vector(req, rw, buf, &nr_segs,
56438 iovec);
56439- if (ret)
56440- return ret;
56441-
56442- ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
56443+ if (!ret)
56444+ ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
56445 if (ret < 0) {
56446 if (iovec != &inline_vec)
56447 kfree(iovec);
56448diff --git a/fs/attr.c b/fs/attr.c
56449index 5d4e59d..fd02418 100644
56450--- a/fs/attr.c
56451+++ b/fs/attr.c
56452@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56453 unsigned long limit;
56454
56455 limit = rlimit(RLIMIT_FSIZE);
56456+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56457 if (limit != RLIM_INFINITY && offset > limit)
56458 goto out_sig;
56459 if (offset > inode->i_sb->s_maxbytes)
56460diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56461index 116fd38..c04182da 100644
56462--- a/fs/autofs4/waitq.c
56463+++ b/fs/autofs4/waitq.c
56464@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56465 {
56466 unsigned long sigpipe, flags;
56467 mm_segment_t fs;
56468- const char *data = (const char *)addr;
56469+ const char __user *data = (const char __force_user *)addr;
56470 ssize_t wr = 0;
56471
56472 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56473@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56474 return 1;
56475 }
56476
56477+#ifdef CONFIG_GRKERNSEC_HIDESYM
56478+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56479+#endif
56480+
56481 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56482 enum autofs_notify notify)
56483 {
56484@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56485
56486 /* If this is a direct mount request create a dummy name */
56487 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56488+#ifdef CONFIG_GRKERNSEC_HIDESYM
56489+ /* this name does get written to userland via autofs4_write() */
56490+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56491+#else
56492 qstr.len = sprintf(name, "%p", dentry);
56493+#endif
56494 else {
56495 qstr.len = autofs4_getpath(sbi, dentry, &name);
56496 if (!qstr.len) {
56497diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56498index 2722387..56059b5 100644
56499--- a/fs/befs/endian.h
56500+++ b/fs/befs/endian.h
56501@@ -11,7 +11,7 @@
56502
56503 #include <asm/byteorder.h>
56504
56505-static inline u64
56506+static inline u64 __intentional_overflow(-1)
56507 fs64_to_cpu(const struct super_block *sb, fs64 n)
56508 {
56509 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56510@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56511 return (__force fs64)cpu_to_be64(n);
56512 }
56513
56514-static inline u32
56515+static inline u32 __intentional_overflow(-1)
56516 fs32_to_cpu(const struct super_block *sb, fs32 n)
56517 {
56518 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56519@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56520 return (__force fs32)cpu_to_be32(n);
56521 }
56522
56523-static inline u16
56524+static inline u16 __intentional_overflow(-1)
56525 fs16_to_cpu(const struct super_block *sb, fs16 n)
56526 {
56527 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56528diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56529index ca0ba15..0fa3257 100644
56530--- a/fs/binfmt_aout.c
56531+++ b/fs/binfmt_aout.c
56532@@ -16,6 +16,7 @@
56533 #include <linux/string.h>
56534 #include <linux/fs.h>
56535 #include <linux/file.h>
56536+#include <linux/security.h>
56537 #include <linux/stat.h>
56538 #include <linux/fcntl.h>
56539 #include <linux/ptrace.h>
56540@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56541 #endif
56542 # define START_STACK(u) ((void __user *)u.start_stack)
56543
56544+ memset(&dump, 0, sizeof(dump));
56545+
56546 fs = get_fs();
56547 set_fs(KERNEL_DS);
56548 has_dumped = 1;
56549@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56550
56551 /* If the size of the dump file exceeds the rlimit, then see what would happen
56552 if we wrote the stack, but not the data area. */
56553+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56554 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56555 dump.u_dsize = 0;
56556
56557 /* Make sure we have enough room to write the stack and data areas. */
56558+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56559 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56560 dump.u_ssize = 0;
56561
56562@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56563 rlim = rlimit(RLIMIT_DATA);
56564 if (rlim >= RLIM_INFINITY)
56565 rlim = ~0;
56566+
56567+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56568 if (ex.a_data + ex.a_bss > rlim)
56569 return -ENOMEM;
56570
56571@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56572
56573 install_exec_creds(bprm);
56574
56575+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56576+ current->mm->pax_flags = 0UL;
56577+#endif
56578+
56579+#ifdef CONFIG_PAX_PAGEEXEC
56580+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56581+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56582+
56583+#ifdef CONFIG_PAX_EMUTRAMP
56584+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56585+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56586+#endif
56587+
56588+#ifdef CONFIG_PAX_MPROTECT
56589+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56590+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56591+#endif
56592+
56593+ }
56594+#endif
56595+
56596 if (N_MAGIC(ex) == OMAGIC) {
56597 unsigned long text_addr, map_size;
56598 loff_t pos;
56599@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56600 }
56601
56602 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56603- PROT_READ | PROT_WRITE | PROT_EXEC,
56604+ PROT_READ | PROT_WRITE,
56605 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56606 fd_offset + ex.a_text);
56607 if (error != N_DATADDR(ex)) {
56608diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56609index 67be295..83e2f86 100644
56610--- a/fs/binfmt_elf.c
56611+++ b/fs/binfmt_elf.c
56612@@ -34,6 +34,7 @@
56613 #include <linux/utsname.h>
56614 #include <linux/coredump.h>
56615 #include <linux/sched.h>
56616+#include <linux/xattr.h>
56617 #include <asm/uaccess.h>
56618 #include <asm/param.h>
56619 #include <asm/page.h>
56620@@ -48,7 +49,7 @@
56621 static int load_elf_binary(struct linux_binprm *bprm);
56622 static int load_elf_library(struct file *);
56623 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56624- int, int, unsigned long);
56625+ int, int, unsigned long) __intentional_overflow(-1);
56626
56627 /*
56628 * If we don't support core dumping, then supply a NULL so we
56629@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56630 #define elf_core_dump NULL
56631 #endif
56632
56633+#ifdef CONFIG_PAX_MPROTECT
56634+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56635+#endif
56636+
56637+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56638+static void elf_handle_mmap(struct file *file);
56639+#endif
56640+
56641 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56642 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56643 #else
56644@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56645 .load_binary = load_elf_binary,
56646 .load_shlib = load_elf_library,
56647 .core_dump = elf_core_dump,
56648+
56649+#ifdef CONFIG_PAX_MPROTECT
56650+ .handle_mprotect= elf_handle_mprotect,
56651+#endif
56652+
56653+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56654+ .handle_mmap = elf_handle_mmap,
56655+#endif
56656+
56657 .min_coredump = ELF_EXEC_PAGESIZE,
56658 };
56659
56660@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56661
56662 static int set_brk(unsigned long start, unsigned long end)
56663 {
56664+ unsigned long e = end;
56665+
56666 start = ELF_PAGEALIGN(start);
56667 end = ELF_PAGEALIGN(end);
56668 if (end > start) {
56669@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56670 if (BAD_ADDR(addr))
56671 return addr;
56672 }
56673- current->mm->start_brk = current->mm->brk = end;
56674+ current->mm->start_brk = current->mm->brk = e;
56675 return 0;
56676 }
56677
56678@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56679 elf_addr_t __user *u_rand_bytes;
56680 const char *k_platform = ELF_PLATFORM;
56681 const char *k_base_platform = ELF_BASE_PLATFORM;
56682- unsigned char k_rand_bytes[16];
56683+ u32 k_rand_bytes[4];
56684 int items;
56685 elf_addr_t *elf_info;
56686 int ei_index = 0;
56687 const struct cred *cred = current_cred();
56688 struct vm_area_struct *vma;
56689+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56690
56691 /*
56692 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56693@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56694 * Generate 16 random bytes for userspace PRNG seeding.
56695 */
56696 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56697- u_rand_bytes = (elf_addr_t __user *)
56698- STACK_ALLOC(p, sizeof(k_rand_bytes));
56699+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56700+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56701+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56702+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56703+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56704+ u_rand_bytes = (elf_addr_t __user *) p;
56705 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56706 return -EFAULT;
56707
56708@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56709 return -EFAULT;
56710 current->mm->env_end = p;
56711
56712+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56713+
56714 /* Put the elf_info on the stack in the right place. */
56715 sp = (elf_addr_t __user *)envp + 1;
56716- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56717+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56718 return -EFAULT;
56719 return 0;
56720 }
56721@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56722 an ELF header */
56723
56724 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56725- struct file *interpreter, unsigned long *interp_map_addr,
56726- unsigned long no_base)
56727+ struct file *interpreter, unsigned long no_base)
56728 {
56729 struct elf_phdr *elf_phdata;
56730 struct elf_phdr *eppnt;
56731- unsigned long load_addr = 0;
56732+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56733 int load_addr_set = 0;
56734 unsigned long last_bss = 0, elf_bss = 0;
56735- unsigned long error = ~0UL;
56736+ unsigned long error = -EINVAL;
56737 unsigned long total_size;
56738 int retval, i, size;
56739
56740@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56741 goto out_close;
56742 }
56743
56744+#ifdef CONFIG_PAX_SEGMEXEC
56745+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56746+ pax_task_size = SEGMEXEC_TASK_SIZE;
56747+#endif
56748+
56749 eppnt = elf_phdata;
56750 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56751 if (eppnt->p_type == PT_LOAD) {
56752@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56753 map_addr = elf_map(interpreter, load_addr + vaddr,
56754 eppnt, elf_prot, elf_type, total_size);
56755 total_size = 0;
56756- if (!*interp_map_addr)
56757- *interp_map_addr = map_addr;
56758 error = map_addr;
56759 if (BAD_ADDR(map_addr))
56760 goto out_close;
56761@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56762 k = load_addr + eppnt->p_vaddr;
56763 if (BAD_ADDR(k) ||
56764 eppnt->p_filesz > eppnt->p_memsz ||
56765- eppnt->p_memsz > TASK_SIZE ||
56766- TASK_SIZE - eppnt->p_memsz < k) {
56767+ eppnt->p_memsz > pax_task_size ||
56768+ pax_task_size - eppnt->p_memsz < k) {
56769 error = -ENOMEM;
56770 goto out_close;
56771 }
56772@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56773 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56774
56775 /* Map the last of the bss segment */
56776- error = vm_brk(elf_bss, last_bss - elf_bss);
56777- if (BAD_ADDR(error))
56778- goto out_close;
56779+ if (last_bss > elf_bss) {
56780+ error = vm_brk(elf_bss, last_bss - elf_bss);
56781+ if (BAD_ADDR(error))
56782+ goto out_close;
56783+ }
56784 }
56785
56786 error = load_addr;
56787@@ -538,6 +569,336 @@ out:
56788 return error;
56789 }
56790
56791+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56792+#ifdef CONFIG_PAX_SOFTMODE
56793+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56794+{
56795+ unsigned long pax_flags = 0UL;
56796+
56797+#ifdef CONFIG_PAX_PAGEEXEC
56798+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56799+ pax_flags |= MF_PAX_PAGEEXEC;
56800+#endif
56801+
56802+#ifdef CONFIG_PAX_SEGMEXEC
56803+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56804+ pax_flags |= MF_PAX_SEGMEXEC;
56805+#endif
56806+
56807+#ifdef CONFIG_PAX_EMUTRAMP
56808+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56809+ pax_flags |= MF_PAX_EMUTRAMP;
56810+#endif
56811+
56812+#ifdef CONFIG_PAX_MPROTECT
56813+ if (elf_phdata->p_flags & PF_MPROTECT)
56814+ pax_flags |= MF_PAX_MPROTECT;
56815+#endif
56816+
56817+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56818+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56819+ pax_flags |= MF_PAX_RANDMMAP;
56820+#endif
56821+
56822+ return pax_flags;
56823+}
56824+#endif
56825+
56826+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56827+{
56828+ unsigned long pax_flags = 0UL;
56829+
56830+#ifdef CONFIG_PAX_PAGEEXEC
56831+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56832+ pax_flags |= MF_PAX_PAGEEXEC;
56833+#endif
56834+
56835+#ifdef CONFIG_PAX_SEGMEXEC
56836+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56837+ pax_flags |= MF_PAX_SEGMEXEC;
56838+#endif
56839+
56840+#ifdef CONFIG_PAX_EMUTRAMP
56841+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56842+ pax_flags |= MF_PAX_EMUTRAMP;
56843+#endif
56844+
56845+#ifdef CONFIG_PAX_MPROTECT
56846+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56847+ pax_flags |= MF_PAX_MPROTECT;
56848+#endif
56849+
56850+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56851+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56852+ pax_flags |= MF_PAX_RANDMMAP;
56853+#endif
56854+
56855+ return pax_flags;
56856+}
56857+#endif
56858+
56859+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56860+#ifdef CONFIG_PAX_SOFTMODE
56861+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56862+{
56863+ unsigned long pax_flags = 0UL;
56864+
56865+#ifdef CONFIG_PAX_PAGEEXEC
56866+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56867+ pax_flags |= MF_PAX_PAGEEXEC;
56868+#endif
56869+
56870+#ifdef CONFIG_PAX_SEGMEXEC
56871+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56872+ pax_flags |= MF_PAX_SEGMEXEC;
56873+#endif
56874+
56875+#ifdef CONFIG_PAX_EMUTRAMP
56876+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56877+ pax_flags |= MF_PAX_EMUTRAMP;
56878+#endif
56879+
56880+#ifdef CONFIG_PAX_MPROTECT
56881+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56882+ pax_flags |= MF_PAX_MPROTECT;
56883+#endif
56884+
56885+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56886+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56887+ pax_flags |= MF_PAX_RANDMMAP;
56888+#endif
56889+
56890+ return pax_flags;
56891+}
56892+#endif
56893+
56894+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56895+{
56896+ unsigned long pax_flags = 0UL;
56897+
56898+#ifdef CONFIG_PAX_PAGEEXEC
56899+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56900+ pax_flags |= MF_PAX_PAGEEXEC;
56901+#endif
56902+
56903+#ifdef CONFIG_PAX_SEGMEXEC
56904+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56905+ pax_flags |= MF_PAX_SEGMEXEC;
56906+#endif
56907+
56908+#ifdef CONFIG_PAX_EMUTRAMP
56909+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56910+ pax_flags |= MF_PAX_EMUTRAMP;
56911+#endif
56912+
56913+#ifdef CONFIG_PAX_MPROTECT
56914+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56915+ pax_flags |= MF_PAX_MPROTECT;
56916+#endif
56917+
56918+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56919+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56920+ pax_flags |= MF_PAX_RANDMMAP;
56921+#endif
56922+
56923+ return pax_flags;
56924+}
56925+#endif
56926+
56927+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56928+static unsigned long pax_parse_defaults(void)
56929+{
56930+ unsigned long pax_flags = 0UL;
56931+
56932+#ifdef CONFIG_PAX_SOFTMODE
56933+ if (pax_softmode)
56934+ return pax_flags;
56935+#endif
56936+
56937+#ifdef CONFIG_PAX_PAGEEXEC
56938+ pax_flags |= MF_PAX_PAGEEXEC;
56939+#endif
56940+
56941+#ifdef CONFIG_PAX_SEGMEXEC
56942+ pax_flags |= MF_PAX_SEGMEXEC;
56943+#endif
56944+
56945+#ifdef CONFIG_PAX_MPROTECT
56946+ pax_flags |= MF_PAX_MPROTECT;
56947+#endif
56948+
56949+#ifdef CONFIG_PAX_RANDMMAP
56950+ if (randomize_va_space)
56951+ pax_flags |= MF_PAX_RANDMMAP;
56952+#endif
56953+
56954+ return pax_flags;
56955+}
56956+
56957+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56958+{
56959+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56960+
56961+#ifdef CONFIG_PAX_EI_PAX
56962+
56963+#ifdef CONFIG_PAX_SOFTMODE
56964+ if (pax_softmode)
56965+ return pax_flags;
56966+#endif
56967+
56968+ pax_flags = 0UL;
56969+
56970+#ifdef CONFIG_PAX_PAGEEXEC
56971+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56972+ pax_flags |= MF_PAX_PAGEEXEC;
56973+#endif
56974+
56975+#ifdef CONFIG_PAX_SEGMEXEC
56976+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56977+ pax_flags |= MF_PAX_SEGMEXEC;
56978+#endif
56979+
56980+#ifdef CONFIG_PAX_EMUTRAMP
56981+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56982+ pax_flags |= MF_PAX_EMUTRAMP;
56983+#endif
56984+
56985+#ifdef CONFIG_PAX_MPROTECT
56986+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56987+ pax_flags |= MF_PAX_MPROTECT;
56988+#endif
56989+
56990+#ifdef CONFIG_PAX_ASLR
56991+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56992+ pax_flags |= MF_PAX_RANDMMAP;
56993+#endif
56994+
56995+#endif
56996+
56997+ return pax_flags;
56998+
56999+}
57000+
57001+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
57002+{
57003+
57004+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57005+ unsigned long i;
57006+
57007+ for (i = 0UL; i < elf_ex->e_phnum; i++)
57008+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
57009+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
57010+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
57011+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
57012+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
57013+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
57014+ return PAX_PARSE_FLAGS_FALLBACK;
57015+
57016+#ifdef CONFIG_PAX_SOFTMODE
57017+ if (pax_softmode)
57018+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
57019+ else
57020+#endif
57021+
57022+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
57023+ break;
57024+ }
57025+#endif
57026+
57027+ return PAX_PARSE_FLAGS_FALLBACK;
57028+}
57029+
57030+static unsigned long pax_parse_xattr_pax(struct file * const file)
57031+{
57032+
57033+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
57034+ ssize_t xattr_size, i;
57035+ unsigned char xattr_value[sizeof("pemrs") - 1];
57036+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
57037+
57038+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
57039+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
57040+ return PAX_PARSE_FLAGS_FALLBACK;
57041+
57042+ for (i = 0; i < xattr_size; i++)
57043+ switch (xattr_value[i]) {
57044+ default:
57045+ return PAX_PARSE_FLAGS_FALLBACK;
57046+
57047+#define parse_flag(option1, option2, flag) \
57048+ case option1: \
57049+ if (pax_flags_hardmode & MF_PAX_##flag) \
57050+ return PAX_PARSE_FLAGS_FALLBACK;\
57051+ pax_flags_hardmode |= MF_PAX_##flag; \
57052+ break; \
57053+ case option2: \
57054+ if (pax_flags_softmode & MF_PAX_##flag) \
57055+ return PAX_PARSE_FLAGS_FALLBACK;\
57056+ pax_flags_softmode |= MF_PAX_##flag; \
57057+ break;
57058+
57059+ parse_flag('p', 'P', PAGEEXEC);
57060+ parse_flag('e', 'E', EMUTRAMP);
57061+ parse_flag('m', 'M', MPROTECT);
57062+ parse_flag('r', 'R', RANDMMAP);
57063+ parse_flag('s', 'S', SEGMEXEC);
57064+
57065+#undef parse_flag
57066+ }
57067+
57068+ if (pax_flags_hardmode & pax_flags_softmode)
57069+ return PAX_PARSE_FLAGS_FALLBACK;
57070+
57071+#ifdef CONFIG_PAX_SOFTMODE
57072+ if (pax_softmode)
57073+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
57074+ else
57075+#endif
57076+
57077+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
57078+#else
57079+ return PAX_PARSE_FLAGS_FALLBACK;
57080+#endif
57081+
57082+}
57083+
57084+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
57085+{
57086+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
57087+
57088+ pax_flags = pax_parse_defaults();
57089+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
57090+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
57091+ xattr_pax_flags = pax_parse_xattr_pax(file);
57092+
57093+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57094+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57095+ pt_pax_flags != xattr_pax_flags)
57096+ return -EINVAL;
57097+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57098+ pax_flags = xattr_pax_flags;
57099+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57100+ pax_flags = pt_pax_flags;
57101+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57102+ pax_flags = ei_pax_flags;
57103+
57104+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
57105+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57106+ if ((__supported_pte_mask & _PAGE_NX))
57107+ pax_flags &= ~MF_PAX_SEGMEXEC;
57108+ else
57109+ pax_flags &= ~MF_PAX_PAGEEXEC;
57110+ }
57111+#endif
57112+
57113+ if (0 > pax_check_flags(&pax_flags))
57114+ return -EINVAL;
57115+
57116+ current->mm->pax_flags = pax_flags;
57117+ return 0;
57118+}
57119+#endif
57120+
57121 /*
57122 * These are the functions used to load ELF style executables and shared
57123 * libraries. There is no binary dependent code anywhere else.
57124@@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
57125 {
57126 unsigned int random_variable = 0;
57127
57128+#ifdef CONFIG_PAX_RANDUSTACK
57129+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
57130+ return stack_top - current->mm->delta_stack;
57131+#endif
57132+
57133 if ((current->flags & PF_RANDOMIZE) &&
57134 !(current->personality & ADDR_NO_RANDOMIZE)) {
57135 random_variable = get_random_int() & STACK_RND_MASK;
57136@@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57137 unsigned long load_addr = 0, load_bias = 0;
57138 int load_addr_set = 0;
57139 char * elf_interpreter = NULL;
57140- unsigned long error;
57141+ unsigned long error = 0;
57142 struct elf_phdr *elf_ppnt, *elf_phdata;
57143 unsigned long elf_bss, elf_brk;
57144 int retval, i;
57145@@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
57146 unsigned long start_code, end_code, start_data, end_data;
57147 unsigned long reloc_func_desc __maybe_unused = 0;
57148 int executable_stack = EXSTACK_DEFAULT;
57149- unsigned long def_flags = 0;
57150 struct pt_regs *regs = current_pt_regs();
57151 struct {
57152 struct elfhdr elf_ex;
57153 struct elfhdr interp_elf_ex;
57154 } *loc;
57155+ unsigned long pax_task_size;
57156
57157 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
57158 if (!loc) {
57159@@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
57160 goto out_free_dentry;
57161
57162 /* OK, This is the point of no return */
57163- current->mm->def_flags = def_flags;
57164+ current->mm->def_flags = 0;
57165
57166 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
57167 may depend on the personality. */
57168 SET_PERSONALITY(loc->elf_ex);
57169+
57170+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57171+ current->mm->pax_flags = 0UL;
57172+#endif
57173+
57174+#ifdef CONFIG_PAX_DLRESOLVE
57175+ current->mm->call_dl_resolve = 0UL;
57176+#endif
57177+
57178+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
57179+ current->mm->call_syscall = 0UL;
57180+#endif
57181+
57182+#ifdef CONFIG_PAX_ASLR
57183+ current->mm->delta_mmap = 0UL;
57184+ current->mm->delta_stack = 0UL;
57185+#endif
57186+
57187+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57188+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
57189+ send_sig(SIGKILL, current, 0);
57190+ goto out_free_dentry;
57191+ }
57192+#endif
57193+
57194+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57195+ pax_set_initial_flags(bprm);
57196+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
57197+ if (pax_set_initial_flags_func)
57198+ (pax_set_initial_flags_func)(bprm);
57199+#endif
57200+
57201+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
57202+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
57203+ current->mm->context.user_cs_limit = PAGE_SIZE;
57204+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
57205+ }
57206+#endif
57207+
57208+#ifdef CONFIG_PAX_SEGMEXEC
57209+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
57210+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
57211+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
57212+ pax_task_size = SEGMEXEC_TASK_SIZE;
57213+ current->mm->def_flags |= VM_NOHUGEPAGE;
57214+ } else
57215+#endif
57216+
57217+ pax_task_size = TASK_SIZE;
57218+
57219+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
57220+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57221+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
57222+ put_cpu();
57223+ }
57224+#endif
57225+
57226+#ifdef CONFIG_PAX_ASLR
57227+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57228+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
57229+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
57230+ }
57231+#endif
57232+
57233+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57234+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57235+ executable_stack = EXSTACK_DISABLE_X;
57236+ current->personality &= ~READ_IMPLIES_EXEC;
57237+ } else
57238+#endif
57239+
57240 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
57241 current->personality |= READ_IMPLIES_EXEC;
57242
57243@@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
57244 #else
57245 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
57246 #endif
57247+
57248+#ifdef CONFIG_PAX_RANDMMAP
57249+ /* PaX: randomize base address at the default exe base if requested */
57250+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
57251+#ifdef CONFIG_SPARC64
57252+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
57253+#else
57254+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
57255+#endif
57256+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
57257+ elf_flags |= MAP_FIXED;
57258+ }
57259+#endif
57260+
57261 }
57262
57263 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
57264@@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
57265 * allowed task size. Note that p_filesz must always be
57266 * <= p_memsz so it is only necessary to check p_memsz.
57267 */
57268- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57269- elf_ppnt->p_memsz > TASK_SIZE ||
57270- TASK_SIZE - elf_ppnt->p_memsz < k) {
57271+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57272+ elf_ppnt->p_memsz > pax_task_size ||
57273+ pax_task_size - elf_ppnt->p_memsz < k) {
57274 /* set_brk can never work. Avoid overflows. */
57275 send_sig(SIGKILL, current, 0);
57276 retval = -EINVAL;
57277@@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
57278 goto out_free_dentry;
57279 }
57280 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
57281- send_sig(SIGSEGV, current, 0);
57282- retval = -EFAULT; /* Nobody gets to see this, but.. */
57283- goto out_free_dentry;
57284+ /*
57285+ * This bss-zeroing can fail if the ELF
57286+ * file specifies odd protections. So
57287+ * we don't check the return value
57288+ */
57289 }
57290
57291+#ifdef CONFIG_PAX_RANDMMAP
57292+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57293+ unsigned long start, size, flags;
57294+ vm_flags_t vm_flags;
57295+
57296+ start = ELF_PAGEALIGN(elf_brk);
57297+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
57298+ flags = MAP_FIXED | MAP_PRIVATE;
57299+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
57300+
57301+ down_write(&current->mm->mmap_sem);
57302+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
57303+ retval = -ENOMEM;
57304+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
57305+// if (current->personality & ADDR_NO_RANDOMIZE)
57306+// vm_flags |= VM_READ | VM_MAYREAD;
57307+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
57308+ retval = IS_ERR_VALUE(start) ? start : 0;
57309+ }
57310+ up_write(&current->mm->mmap_sem);
57311+ if (retval == 0)
57312+ retval = set_brk(start + size, start + size + PAGE_SIZE);
57313+ if (retval < 0) {
57314+ send_sig(SIGKILL, current, 0);
57315+ goto out_free_dentry;
57316+ }
57317+ }
57318+#endif
57319+
57320 if (elf_interpreter) {
57321- unsigned long interp_map_addr = 0;
57322-
57323 elf_entry = load_elf_interp(&loc->interp_elf_ex,
57324 interpreter,
57325- &interp_map_addr,
57326 load_bias);
57327 if (!IS_ERR((void *)elf_entry)) {
57328 /*
57329@@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
57330 * Decide what to dump of a segment, part, all or none.
57331 */
57332 static unsigned long vma_dump_size(struct vm_area_struct *vma,
57333- unsigned long mm_flags)
57334+ unsigned long mm_flags, long signr)
57335 {
57336 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
57337
57338@@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
57339 if (vma->vm_file == NULL)
57340 return 0;
57341
57342- if (FILTER(MAPPED_PRIVATE))
57343+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
57344 goto whole;
57345
57346 /*
57347@@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
57348 {
57349 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
57350 int i = 0;
57351- do
57352+ do {
57353 i += 2;
57354- while (auxv[i - 2] != AT_NULL);
57355+ } while (auxv[i - 2] != AT_NULL);
57356 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
57357 }
57358
57359@@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
57360 {
57361 mm_segment_t old_fs = get_fs();
57362 set_fs(KERNEL_DS);
57363- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
57364+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
57365 set_fs(old_fs);
57366 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
57367 }
57368@@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
57369 }
57370
57371 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
57372- unsigned long mm_flags)
57373+ struct coredump_params *cprm)
57374 {
57375 struct vm_area_struct *vma;
57376 size_t size = 0;
57377
57378 for (vma = first_vma(current, gate_vma); vma != NULL;
57379 vma = next_vma(vma, gate_vma))
57380- size += vma_dump_size(vma, mm_flags);
57381+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57382 return size;
57383 }
57384
57385@@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57386
57387 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
57388
57389- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
57390+ offset += elf_core_vma_data_size(gate_vma, cprm);
57391 offset += elf_core_extra_data_size();
57392 e_shoff = offset;
57393
57394@@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57395 phdr.p_offset = offset;
57396 phdr.p_vaddr = vma->vm_start;
57397 phdr.p_paddr = 0;
57398- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
57399+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57400 phdr.p_memsz = vma->vm_end - vma->vm_start;
57401 offset += phdr.p_filesz;
57402 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57403@@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57404 unsigned long addr;
57405 unsigned long end;
57406
57407- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57408+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57409
57410 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57411 struct page *page;
57412@@ -2199,6 +2678,167 @@ out:
57413
57414 #endif /* CONFIG_ELF_CORE */
57415
57416+#ifdef CONFIG_PAX_MPROTECT
57417+/* PaX: non-PIC ELF libraries need relocations on their executable segments
57418+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57419+ * we'll remove VM_MAYWRITE for good on RELRO segments.
57420+ *
57421+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57422+ * basis because we want to allow the common case and not the special ones.
57423+ */
57424+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57425+{
57426+ struct elfhdr elf_h;
57427+ struct elf_phdr elf_p;
57428+ unsigned long i;
57429+ unsigned long oldflags;
57430+ bool is_textrel_rw, is_textrel_rx, is_relro;
57431+
57432+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57433+ return;
57434+
57435+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57436+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57437+
57438+#ifdef CONFIG_PAX_ELFRELOCS
57439+ /* possible TEXTREL */
57440+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57441+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57442+#else
57443+ is_textrel_rw = false;
57444+ is_textrel_rx = false;
57445+#endif
57446+
57447+ /* possible RELRO */
57448+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57449+
57450+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57451+ return;
57452+
57453+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57454+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57455+
57456+#ifdef CONFIG_PAX_ETEXECRELOCS
57457+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57458+#else
57459+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57460+#endif
57461+
57462+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57463+ !elf_check_arch(&elf_h) ||
57464+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57465+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57466+ return;
57467+
57468+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57469+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57470+ return;
57471+ switch (elf_p.p_type) {
57472+ case PT_DYNAMIC:
57473+ if (!is_textrel_rw && !is_textrel_rx)
57474+ continue;
57475+ i = 0UL;
57476+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57477+ elf_dyn dyn;
57478+
57479+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57480+ break;
57481+ if (dyn.d_tag == DT_NULL)
57482+ break;
57483+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57484+ gr_log_textrel(vma);
57485+ if (is_textrel_rw)
57486+ vma->vm_flags |= VM_MAYWRITE;
57487+ else
57488+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57489+ vma->vm_flags &= ~VM_MAYWRITE;
57490+ break;
57491+ }
57492+ i++;
57493+ }
57494+ is_textrel_rw = false;
57495+ is_textrel_rx = false;
57496+ continue;
57497+
57498+ case PT_GNU_RELRO:
57499+ if (!is_relro)
57500+ continue;
57501+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57502+ vma->vm_flags &= ~VM_MAYWRITE;
57503+ is_relro = false;
57504+ continue;
57505+
57506+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57507+ case PT_PAX_FLAGS: {
57508+ const char *msg_mprotect = "", *msg_emutramp = "";
57509+ char *buffer_lib, *buffer_exe;
57510+
57511+ if (elf_p.p_flags & PF_NOMPROTECT)
57512+ msg_mprotect = "MPROTECT disabled";
57513+
57514+#ifdef CONFIG_PAX_EMUTRAMP
57515+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57516+ msg_emutramp = "EMUTRAMP enabled";
57517+#endif
57518+
57519+ if (!msg_mprotect[0] && !msg_emutramp[0])
57520+ continue;
57521+
57522+ if (!printk_ratelimit())
57523+ continue;
57524+
57525+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57526+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57527+ if (buffer_lib && buffer_exe) {
57528+ char *path_lib, *path_exe;
57529+
57530+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57531+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57532+
57533+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57534+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57535+
57536+ }
57537+ free_page((unsigned long)buffer_exe);
57538+ free_page((unsigned long)buffer_lib);
57539+ continue;
57540+ }
57541+#endif
57542+
57543+ }
57544+ }
57545+}
57546+#endif
57547+
57548+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57549+
57550+extern int grsec_enable_log_rwxmaps;
57551+
57552+static void elf_handle_mmap(struct file *file)
57553+{
57554+ struct elfhdr elf_h;
57555+ struct elf_phdr elf_p;
57556+ unsigned long i;
57557+
57558+ if (!grsec_enable_log_rwxmaps)
57559+ return;
57560+
57561+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57562+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57563+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57564+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57565+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57566+ return;
57567+
57568+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57569+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57570+ return;
57571+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57572+ gr_log_ptgnustack(file);
57573+ }
57574+}
57575+#endif
57576+
57577 static int __init init_elf_binfmt(void)
57578 {
57579 register_binfmt(&elf_format);
57580diff --git a/fs/bio.c b/fs/bio.c
57581index 8754e7b..0669094 100644
57582--- a/fs/bio.c
57583+++ b/fs/bio.c
57584@@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57585 /*
57586 * Overflow, abort
57587 */
57588- if (end < start)
57589+ if (end < start || end - start > INT_MAX - nr_pages)
57590 return ERR_PTR(-EINVAL);
57591
57592 nr_pages += end - start;
57593@@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57594 /*
57595 * Overflow, abort
57596 */
57597- if (end < start)
57598+ if (end < start || end - start > INT_MAX - nr_pages)
57599 return ERR_PTR(-EINVAL);
57600
57601 nr_pages += end - start;
57602@@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57603 const int read = bio_data_dir(bio) == READ;
57604 struct bio_map_data *bmd = bio->bi_private;
57605 int i;
57606- char *p = bmd->sgvecs[0].iov_base;
57607+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57608
57609 bio_for_each_segment_all(bvec, bio, i) {
57610 char *addr = page_address(bvec->bv_page);
57611diff --git a/fs/block_dev.c b/fs/block_dev.c
57612index 1e86823..8e34695 100644
57613--- a/fs/block_dev.c
57614+++ b/fs/block_dev.c
57615@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57616 else if (bdev->bd_contains == bdev)
57617 return true; /* is a whole device which isn't held */
57618
57619- else if (whole->bd_holder == bd_may_claim)
57620+ else if (whole->bd_holder == (void *)bd_may_claim)
57621 return true; /* is a partition of a device that is being partitioned */
57622 else if (whole->bd_holder != NULL)
57623 return false; /* is a partition of a held device */
57624diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57625index cbd3a7d..c6a2881 100644
57626--- a/fs/btrfs/ctree.c
57627+++ b/fs/btrfs/ctree.c
57628@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57629 free_extent_buffer(buf);
57630 add_root_to_dirty_list(root);
57631 } else {
57632- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57633- parent_start = parent->start;
57634- else
57635+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57636+ if (parent)
57637+ parent_start = parent->start;
57638+ else
57639+ parent_start = 0;
57640+ } else
57641 parent_start = 0;
57642
57643 WARN_ON(trans->transid != btrfs_header_generation(parent));
57644diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57645index 451b00c..a2cccee 100644
57646--- a/fs/btrfs/delayed-inode.c
57647+++ b/fs/btrfs/delayed-inode.c
57648@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57649
57650 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57651 {
57652- int seq = atomic_inc_return(&delayed_root->items_seq);
57653+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57654 if ((atomic_dec_return(&delayed_root->items) <
57655 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57656 waitqueue_active(&delayed_root->wait))
57657@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57658
57659 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57660 {
57661- int val = atomic_read(&delayed_root->items_seq);
57662+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57663
57664 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57665 return 1;
57666@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57667 int seq;
57668 int ret;
57669
57670- seq = atomic_read(&delayed_root->items_seq);
57671+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57672
57673 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57674 if (ret)
57675diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57676index f70119f..ab5894d 100644
57677--- a/fs/btrfs/delayed-inode.h
57678+++ b/fs/btrfs/delayed-inode.h
57679@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57680 */
57681 struct list_head prepare_list;
57682 atomic_t items; /* for delayed items */
57683- atomic_t items_seq; /* for delayed items */
57684+ atomic_unchecked_t items_seq; /* for delayed items */
57685 int nodes; /* for delayed nodes */
57686 wait_queue_head_t wait;
57687 };
57688@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57689 struct btrfs_delayed_root *delayed_root)
57690 {
57691 atomic_set(&delayed_root->items, 0);
57692- atomic_set(&delayed_root->items_seq, 0);
57693+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57694 delayed_root->nodes = 0;
57695 spin_lock_init(&delayed_root->lock);
57696 init_waitqueue_head(&delayed_root->wait);
57697diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57698index a6d8efa..2f062cf 100644
57699--- a/fs/btrfs/ioctl.c
57700+++ b/fs/btrfs/ioctl.c
57701@@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57702 for (i = 0; i < num_types; i++) {
57703 struct btrfs_space_info *tmp;
57704
57705+ /* Don't copy in more than we allocated */
57706 if (!slot_count)
57707 break;
57708
57709+ slot_count--;
57710+
57711 info = NULL;
57712 rcu_read_lock();
57713 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57714@@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57715 memcpy(dest, &space, sizeof(space));
57716 dest++;
57717 space_args.total_spaces++;
57718- slot_count--;
57719 }
57720- if (!slot_count)
57721- break;
57722 }
57723 up_read(&info->groups_sem);
57724 }
57725diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57726index d04db81..96e54f1 100644
57727--- a/fs/btrfs/super.c
57728+++ b/fs/btrfs/super.c
57729@@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57730 function, line, errstr);
57731 return;
57732 }
57733- ACCESS_ONCE(trans->transaction->aborted) = errno;
57734+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57735 /* Wake up anybody who may be waiting on this transaction */
57736 wake_up(&root->fs_info->transaction_wait);
57737 wake_up(&root->fs_info->transaction_blocked_wait);
57738diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57739index 865f4cf..f321e86 100644
57740--- a/fs/btrfs/sysfs.c
57741+++ b/fs/btrfs/sysfs.c
57742@@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57743 for (set = 0; set < FEAT_MAX; set++) {
57744 int i;
57745 struct attribute *attrs[2];
57746- struct attribute_group agroup = {
57747+ attribute_group_no_const agroup = {
57748 .name = "features",
57749 .attrs = attrs,
57750 };
57751diff --git a/fs/buffer.c b/fs/buffer.c
57752index 27265a8..289f488 100644
57753--- a/fs/buffer.c
57754+++ b/fs/buffer.c
57755@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57756 bh_cachep = kmem_cache_create("buffer_head",
57757 sizeof(struct buffer_head), 0,
57758 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57759- SLAB_MEM_SPREAD),
57760+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57761 NULL);
57762
57763 /*
57764diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57765index 622f469..e8d2d55 100644
57766--- a/fs/cachefiles/bind.c
57767+++ b/fs/cachefiles/bind.c
57768@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57769 args);
57770
57771 /* start by checking things over */
57772- ASSERT(cache->fstop_percent >= 0 &&
57773- cache->fstop_percent < cache->fcull_percent &&
57774+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57775 cache->fcull_percent < cache->frun_percent &&
57776 cache->frun_percent < 100);
57777
57778- ASSERT(cache->bstop_percent >= 0 &&
57779- cache->bstop_percent < cache->bcull_percent &&
57780+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57781 cache->bcull_percent < cache->brun_percent &&
57782 cache->brun_percent < 100);
57783
57784diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57785index 0a1467b..6a53245 100644
57786--- a/fs/cachefiles/daemon.c
57787+++ b/fs/cachefiles/daemon.c
57788@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57789 if (n > buflen)
57790 return -EMSGSIZE;
57791
57792- if (copy_to_user(_buffer, buffer, n) != 0)
57793+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57794 return -EFAULT;
57795
57796 return n;
57797@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57798 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57799 return -EIO;
57800
57801- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57802+ if (datalen > PAGE_SIZE - 1)
57803 return -EOPNOTSUPP;
57804
57805 /* drag the command string into the kernel so we can parse it */
57806@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57807 if (args[0] != '%' || args[1] != '\0')
57808 return -EINVAL;
57809
57810- if (fstop < 0 || fstop >= cache->fcull_percent)
57811+ if (fstop >= cache->fcull_percent)
57812 return cachefiles_daemon_range_error(cache, args);
57813
57814 cache->fstop_percent = fstop;
57815@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57816 if (args[0] != '%' || args[1] != '\0')
57817 return -EINVAL;
57818
57819- if (bstop < 0 || bstop >= cache->bcull_percent)
57820+ if (bstop >= cache->bcull_percent)
57821 return cachefiles_daemon_range_error(cache, args);
57822
57823 cache->bstop_percent = bstop;
57824diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57825index 5349473..d6c0b93 100644
57826--- a/fs/cachefiles/internal.h
57827+++ b/fs/cachefiles/internal.h
57828@@ -59,7 +59,7 @@ struct cachefiles_cache {
57829 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57830 struct rb_root active_nodes; /* active nodes (can't be culled) */
57831 rwlock_t active_lock; /* lock for active_nodes */
57832- atomic_t gravecounter; /* graveyard uniquifier */
57833+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57834 unsigned frun_percent; /* when to stop culling (% files) */
57835 unsigned fcull_percent; /* when to start culling (% files) */
57836 unsigned fstop_percent; /* when to stop allocating (% files) */
57837@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57838 * proc.c
57839 */
57840 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57841-extern atomic_t cachefiles_lookup_histogram[HZ];
57842-extern atomic_t cachefiles_mkdir_histogram[HZ];
57843-extern atomic_t cachefiles_create_histogram[HZ];
57844+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57845+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57846+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57847
57848 extern int __init cachefiles_proc_init(void);
57849 extern void cachefiles_proc_cleanup(void);
57850 static inline
57851-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57852+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57853 {
57854 unsigned long jif = jiffies - start_jif;
57855 if (jif >= HZ)
57856 jif = HZ - 1;
57857- atomic_inc(&histogram[jif]);
57858+ atomic_inc_unchecked(&histogram[jif]);
57859 }
57860
57861 #else
57862diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57863index ca65f39..48921e3 100644
57864--- a/fs/cachefiles/namei.c
57865+++ b/fs/cachefiles/namei.c
57866@@ -317,7 +317,7 @@ try_again:
57867 /* first step is to make up a grave dentry in the graveyard */
57868 sprintf(nbuffer, "%08x%08x",
57869 (uint32_t) get_seconds(),
57870- (uint32_t) atomic_inc_return(&cache->gravecounter));
57871+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57872
57873 /* do the multiway lock magic */
57874 trap = lock_rename(cache->graveyard, dir);
57875diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57876index eccd339..4c1d995 100644
57877--- a/fs/cachefiles/proc.c
57878+++ b/fs/cachefiles/proc.c
57879@@ -14,9 +14,9 @@
57880 #include <linux/seq_file.h>
57881 #include "internal.h"
57882
57883-atomic_t cachefiles_lookup_histogram[HZ];
57884-atomic_t cachefiles_mkdir_histogram[HZ];
57885-atomic_t cachefiles_create_histogram[HZ];
57886+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57887+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57888+atomic_unchecked_t cachefiles_create_histogram[HZ];
57889
57890 /*
57891 * display the latency histogram
57892@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57893 return 0;
57894 default:
57895 index = (unsigned long) v - 3;
57896- x = atomic_read(&cachefiles_lookup_histogram[index]);
57897- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57898- z = atomic_read(&cachefiles_create_histogram[index]);
57899+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57900+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57901+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57902 if (x == 0 && y == 0 && z == 0)
57903 return 0;
57904
57905diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57906index ebaff36..7e3ea26 100644
57907--- a/fs/cachefiles/rdwr.c
57908+++ b/fs/cachefiles/rdwr.c
57909@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57910 old_fs = get_fs();
57911 set_fs(KERNEL_DS);
57912 ret = file->f_op->write(
57913- file, (const void __user *) data, len, &pos);
57914+ file, (const void __force_user *) data, len, &pos);
57915 set_fs(old_fs);
57916 kunmap(page);
57917 file_end_write(file);
57918diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57919index 45eda6d..9126f7f 100644
57920--- a/fs/ceph/dir.c
57921+++ b/fs/ceph/dir.c
57922@@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57923 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57924 struct ceph_mds_client *mdsc = fsc->mdsc;
57925 unsigned frag = fpos_frag(ctx->pos);
57926- int off = fpos_off(ctx->pos);
57927+ unsigned int off = fpos_off(ctx->pos);
57928 int err;
57929 u32 ftype;
57930 struct ceph_mds_reply_info_parsed *rinfo;
57931diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57932index 10a4ccb..92dbc5e 100644
57933--- a/fs/ceph/super.c
57934+++ b/fs/ceph/super.c
57935@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57936 /*
57937 * construct our own bdi so we can control readahead, etc.
57938 */
57939-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57940+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57941
57942 static int ceph_register_bdi(struct super_block *sb,
57943 struct ceph_fs_client *fsc)
57944@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57945 default_backing_dev_info.ra_pages;
57946
57947 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57948- atomic_long_inc_return(&bdi_seq));
57949+ atomic_long_inc_return_unchecked(&bdi_seq));
57950 if (!err)
57951 sb->s_bdi = &fsc->backing_dev_info;
57952 return err;
57953diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57954index f3ac415..3d2420c 100644
57955--- a/fs/cifs/cifs_debug.c
57956+++ b/fs/cifs/cifs_debug.c
57957@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57958
57959 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57960 #ifdef CONFIG_CIFS_STATS2
57961- atomic_set(&totBufAllocCount, 0);
57962- atomic_set(&totSmBufAllocCount, 0);
57963+ atomic_set_unchecked(&totBufAllocCount, 0);
57964+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57965 #endif /* CONFIG_CIFS_STATS2 */
57966 spin_lock(&cifs_tcp_ses_lock);
57967 list_for_each(tmp1, &cifs_tcp_ses_list) {
57968@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57969 tcon = list_entry(tmp3,
57970 struct cifs_tcon,
57971 tcon_list);
57972- atomic_set(&tcon->num_smbs_sent, 0);
57973+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57974 if (server->ops->clear_stats)
57975 server->ops->clear_stats(tcon);
57976 }
57977@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57978 smBufAllocCount.counter, cifs_min_small);
57979 #ifdef CONFIG_CIFS_STATS2
57980 seq_printf(m, "Total Large %d Small %d Allocations\n",
57981- atomic_read(&totBufAllocCount),
57982- atomic_read(&totSmBufAllocCount));
57983+ atomic_read_unchecked(&totBufAllocCount),
57984+ atomic_read_unchecked(&totSmBufAllocCount));
57985 #endif /* CONFIG_CIFS_STATS2 */
57986
57987 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57988@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57989 if (tcon->need_reconnect)
57990 seq_puts(m, "\tDISCONNECTED ");
57991 seq_printf(m, "\nSMBs: %d",
57992- atomic_read(&tcon->num_smbs_sent));
57993+ atomic_read_unchecked(&tcon->num_smbs_sent));
57994 if (server->ops->print_stats)
57995 server->ops->print_stats(m, tcon);
57996 }
57997diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57998index 849f613..eae6dec 100644
57999--- a/fs/cifs/cifsfs.c
58000+++ b/fs/cifs/cifsfs.c
58001@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
58002 */
58003 cifs_req_cachep = kmem_cache_create("cifs_request",
58004 CIFSMaxBufSize + max_hdr_size, 0,
58005- SLAB_HWCACHE_ALIGN, NULL);
58006+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
58007 if (cifs_req_cachep == NULL)
58008 return -ENOMEM;
58009
58010@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
58011 efficient to alloc 1 per page off the slab compared to 17K (5page)
58012 alloc of large cifs buffers even when page debugging is on */
58013 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
58014- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
58015+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
58016 NULL);
58017 if (cifs_sm_req_cachep == NULL) {
58018 mempool_destroy(cifs_req_poolp);
58019@@ -1168,8 +1168,8 @@ init_cifs(void)
58020 atomic_set(&bufAllocCount, 0);
58021 atomic_set(&smBufAllocCount, 0);
58022 #ifdef CONFIG_CIFS_STATS2
58023- atomic_set(&totBufAllocCount, 0);
58024- atomic_set(&totSmBufAllocCount, 0);
58025+ atomic_set_unchecked(&totBufAllocCount, 0);
58026+ atomic_set_unchecked(&totSmBufAllocCount, 0);
58027 #endif /* CONFIG_CIFS_STATS2 */
58028
58029 atomic_set(&midCount, 0);
58030diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
58031index c0f3718..6afed7d 100644
58032--- a/fs/cifs/cifsglob.h
58033+++ b/fs/cifs/cifsglob.h
58034@@ -804,35 +804,35 @@ struct cifs_tcon {
58035 __u16 Flags; /* optional support bits */
58036 enum statusEnum tidStatus;
58037 #ifdef CONFIG_CIFS_STATS
58038- atomic_t num_smbs_sent;
58039+ atomic_unchecked_t num_smbs_sent;
58040 union {
58041 struct {
58042- atomic_t num_writes;
58043- atomic_t num_reads;
58044- atomic_t num_flushes;
58045- atomic_t num_oplock_brks;
58046- atomic_t num_opens;
58047- atomic_t num_closes;
58048- atomic_t num_deletes;
58049- atomic_t num_mkdirs;
58050- atomic_t num_posixopens;
58051- atomic_t num_posixmkdirs;
58052- atomic_t num_rmdirs;
58053- atomic_t num_renames;
58054- atomic_t num_t2renames;
58055- atomic_t num_ffirst;
58056- atomic_t num_fnext;
58057- atomic_t num_fclose;
58058- atomic_t num_hardlinks;
58059- atomic_t num_symlinks;
58060- atomic_t num_locks;
58061- atomic_t num_acl_get;
58062- atomic_t num_acl_set;
58063+ atomic_unchecked_t num_writes;
58064+ atomic_unchecked_t num_reads;
58065+ atomic_unchecked_t num_flushes;
58066+ atomic_unchecked_t num_oplock_brks;
58067+ atomic_unchecked_t num_opens;
58068+ atomic_unchecked_t num_closes;
58069+ atomic_unchecked_t num_deletes;
58070+ atomic_unchecked_t num_mkdirs;
58071+ atomic_unchecked_t num_posixopens;
58072+ atomic_unchecked_t num_posixmkdirs;
58073+ atomic_unchecked_t num_rmdirs;
58074+ atomic_unchecked_t num_renames;
58075+ atomic_unchecked_t num_t2renames;
58076+ atomic_unchecked_t num_ffirst;
58077+ atomic_unchecked_t num_fnext;
58078+ atomic_unchecked_t num_fclose;
58079+ atomic_unchecked_t num_hardlinks;
58080+ atomic_unchecked_t num_symlinks;
58081+ atomic_unchecked_t num_locks;
58082+ atomic_unchecked_t num_acl_get;
58083+ atomic_unchecked_t num_acl_set;
58084 } cifs_stats;
58085 #ifdef CONFIG_CIFS_SMB2
58086 struct {
58087- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58088- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58089+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58090+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58091 } smb2_stats;
58092 #endif /* CONFIG_CIFS_SMB2 */
58093 } stats;
58094@@ -1162,7 +1162,7 @@ convert_delimiter(char *path, char delim)
58095 }
58096
58097 #ifdef CONFIG_CIFS_STATS
58098-#define cifs_stats_inc atomic_inc
58099+#define cifs_stats_inc atomic_inc_unchecked
58100
58101 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
58102 unsigned int bytes)
58103@@ -1528,8 +1528,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
58104 /* Various Debug counters */
58105 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
58106 #ifdef CONFIG_CIFS_STATS2
58107-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
58108-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
58109+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
58110+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
58111 #endif
58112 GLOBAL_EXTERN atomic_t smBufAllocCount;
58113 GLOBAL_EXTERN atomic_t midCount;
58114diff --git a/fs/cifs/file.c b/fs/cifs/file.c
58115index 834fce7..8a314b5 100644
58116--- a/fs/cifs/file.c
58117+++ b/fs/cifs/file.c
58118@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
58119 index = mapping->writeback_index; /* Start from prev offset */
58120 end = -1;
58121 } else {
58122- index = wbc->range_start >> PAGE_CACHE_SHIFT;
58123- end = wbc->range_end >> PAGE_CACHE_SHIFT;
58124- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
58125+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
58126 range_whole = true;
58127+ index = 0;
58128+ end = ULONG_MAX;
58129+ } else {
58130+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
58131+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
58132+ }
58133 scanned = true;
58134 }
58135 retry:
58136diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
58137index 2f9f379..43f8025 100644
58138--- a/fs/cifs/misc.c
58139+++ b/fs/cifs/misc.c
58140@@ -170,7 +170,7 @@ cifs_buf_get(void)
58141 memset(ret_buf, 0, buf_size + 3);
58142 atomic_inc(&bufAllocCount);
58143 #ifdef CONFIG_CIFS_STATS2
58144- atomic_inc(&totBufAllocCount);
58145+ atomic_inc_unchecked(&totBufAllocCount);
58146 #endif /* CONFIG_CIFS_STATS2 */
58147 }
58148
58149@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
58150 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
58151 atomic_inc(&smBufAllocCount);
58152 #ifdef CONFIG_CIFS_STATS2
58153- atomic_inc(&totSmBufAllocCount);
58154+ atomic_inc_unchecked(&totSmBufAllocCount);
58155 #endif /* CONFIG_CIFS_STATS2 */
58156
58157 }
58158diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
58159index 526fb89..ecdbf5a 100644
58160--- a/fs/cifs/smb1ops.c
58161+++ b/fs/cifs/smb1ops.c
58162@@ -616,27 +616,27 @@ static void
58163 cifs_clear_stats(struct cifs_tcon *tcon)
58164 {
58165 #ifdef CONFIG_CIFS_STATS
58166- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
58167- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
58168- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
58169- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58170- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
58171- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
58172- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58173- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
58174- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
58175- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
58176- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
58177- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
58178- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
58179- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
58180- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
58181- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
58182- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
58183- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
58184- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
58185- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
58186- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
58187+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
58188+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
58189+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
58190+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58191+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
58192+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
58193+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58194+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
58195+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
58196+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
58197+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
58198+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
58199+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
58200+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
58201+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
58202+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
58203+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
58204+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
58205+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
58206+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
58207+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
58208 #endif
58209 }
58210
58211@@ -645,36 +645,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58212 {
58213 #ifdef CONFIG_CIFS_STATS
58214 seq_printf(m, " Oplocks breaks: %d",
58215- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
58216+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
58217 seq_printf(m, "\nReads: %d Bytes: %llu",
58218- atomic_read(&tcon->stats.cifs_stats.num_reads),
58219+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
58220 (long long)(tcon->bytes_read));
58221 seq_printf(m, "\nWrites: %d Bytes: %llu",
58222- atomic_read(&tcon->stats.cifs_stats.num_writes),
58223+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
58224 (long long)(tcon->bytes_written));
58225 seq_printf(m, "\nFlushes: %d",
58226- atomic_read(&tcon->stats.cifs_stats.num_flushes));
58227+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
58228 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
58229- atomic_read(&tcon->stats.cifs_stats.num_locks),
58230- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
58231- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
58232+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
58233+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
58234+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
58235 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
58236- atomic_read(&tcon->stats.cifs_stats.num_opens),
58237- atomic_read(&tcon->stats.cifs_stats.num_closes),
58238- atomic_read(&tcon->stats.cifs_stats.num_deletes));
58239+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
58240+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
58241+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
58242 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
58243- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
58244- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
58245+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
58246+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
58247 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
58248- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
58249- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
58250+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
58251+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
58252 seq_printf(m, "\nRenames: %d T2 Renames %d",
58253- atomic_read(&tcon->stats.cifs_stats.num_renames),
58254- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
58255+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
58256+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
58257 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
58258- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
58259- atomic_read(&tcon->stats.cifs_stats.num_fnext),
58260- atomic_read(&tcon->stats.cifs_stats.num_fclose));
58261+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
58262+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
58263+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
58264 #endif
58265 }
58266
58267diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
58268index 192f51a..539307e 100644
58269--- a/fs/cifs/smb2ops.c
58270+++ b/fs/cifs/smb2ops.c
58271@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
58272 #ifdef CONFIG_CIFS_STATS
58273 int i;
58274 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
58275- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58276- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58277+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58278+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58279 }
58280 #endif
58281 }
58282@@ -405,65 +405,65 @@ static void
58283 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58284 {
58285 #ifdef CONFIG_CIFS_STATS
58286- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58287- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58288+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58289+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58290 seq_printf(m, "\nNegotiates: %d sent %d failed",
58291- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
58292- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
58293+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
58294+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
58295 seq_printf(m, "\nSessionSetups: %d sent %d failed",
58296- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
58297- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
58298+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
58299+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
58300 seq_printf(m, "\nLogoffs: %d sent %d failed",
58301- atomic_read(&sent[SMB2_LOGOFF_HE]),
58302- atomic_read(&failed[SMB2_LOGOFF_HE]));
58303+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
58304+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
58305 seq_printf(m, "\nTreeConnects: %d sent %d failed",
58306- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
58307- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
58308+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
58309+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
58310 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
58311- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
58312- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
58313+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
58314+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
58315 seq_printf(m, "\nCreates: %d sent %d failed",
58316- atomic_read(&sent[SMB2_CREATE_HE]),
58317- atomic_read(&failed[SMB2_CREATE_HE]));
58318+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
58319+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
58320 seq_printf(m, "\nCloses: %d sent %d failed",
58321- atomic_read(&sent[SMB2_CLOSE_HE]),
58322- atomic_read(&failed[SMB2_CLOSE_HE]));
58323+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
58324+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
58325 seq_printf(m, "\nFlushes: %d sent %d failed",
58326- atomic_read(&sent[SMB2_FLUSH_HE]),
58327- atomic_read(&failed[SMB2_FLUSH_HE]));
58328+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
58329+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
58330 seq_printf(m, "\nReads: %d sent %d failed",
58331- atomic_read(&sent[SMB2_READ_HE]),
58332- atomic_read(&failed[SMB2_READ_HE]));
58333+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
58334+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
58335 seq_printf(m, "\nWrites: %d sent %d failed",
58336- atomic_read(&sent[SMB2_WRITE_HE]),
58337- atomic_read(&failed[SMB2_WRITE_HE]));
58338+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
58339+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
58340 seq_printf(m, "\nLocks: %d sent %d failed",
58341- atomic_read(&sent[SMB2_LOCK_HE]),
58342- atomic_read(&failed[SMB2_LOCK_HE]));
58343+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
58344+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
58345 seq_printf(m, "\nIOCTLs: %d sent %d failed",
58346- atomic_read(&sent[SMB2_IOCTL_HE]),
58347- atomic_read(&failed[SMB2_IOCTL_HE]));
58348+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
58349+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
58350 seq_printf(m, "\nCancels: %d sent %d failed",
58351- atomic_read(&sent[SMB2_CANCEL_HE]),
58352- atomic_read(&failed[SMB2_CANCEL_HE]));
58353+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
58354+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
58355 seq_printf(m, "\nEchos: %d sent %d failed",
58356- atomic_read(&sent[SMB2_ECHO_HE]),
58357- atomic_read(&failed[SMB2_ECHO_HE]));
58358+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
58359+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
58360 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
58361- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
58362- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
58363+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
58364+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58365 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58366- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58367- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58368+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58369+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58370 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58371- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58372- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58373+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58374+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58375 seq_printf(m, "\nSetInfos: %d sent %d failed",
58376- atomic_read(&sent[SMB2_SET_INFO_HE]),
58377- atomic_read(&failed[SMB2_SET_INFO_HE]));
58378+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58379+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58380 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58381- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58382- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58383+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58384+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58385 #endif
58386 }
58387
58388diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58389index 8603447..f9caeee 100644
58390--- a/fs/cifs/smb2pdu.c
58391+++ b/fs/cifs/smb2pdu.c
58392@@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58393 default:
58394 cifs_dbg(VFS, "info level %u isn't supported\n",
58395 srch_inf->info_level);
58396- rc = -EINVAL;
58397- goto qdir_exit;
58398+ return -EINVAL;
58399 }
58400
58401 req->FileIndex = cpu_to_le32(index);
58402diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58403index 1da168c..8bc7ff6 100644
58404--- a/fs/coda/cache.c
58405+++ b/fs/coda/cache.c
58406@@ -24,7 +24,7 @@
58407 #include "coda_linux.h"
58408 #include "coda_cache.h"
58409
58410-static atomic_t permission_epoch = ATOMIC_INIT(0);
58411+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58412
58413 /* replace or extend an acl cache hit */
58414 void coda_cache_enter(struct inode *inode, int mask)
58415@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58416 struct coda_inode_info *cii = ITOC(inode);
58417
58418 spin_lock(&cii->c_lock);
58419- cii->c_cached_epoch = atomic_read(&permission_epoch);
58420+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58421 if (!uid_eq(cii->c_uid, current_fsuid())) {
58422 cii->c_uid = current_fsuid();
58423 cii->c_cached_perm = mask;
58424@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58425 {
58426 struct coda_inode_info *cii = ITOC(inode);
58427 spin_lock(&cii->c_lock);
58428- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58429+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58430 spin_unlock(&cii->c_lock);
58431 }
58432
58433 /* remove all acl caches */
58434 void coda_cache_clear_all(struct super_block *sb)
58435 {
58436- atomic_inc(&permission_epoch);
58437+ atomic_inc_unchecked(&permission_epoch);
58438 }
58439
58440
58441@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58442 spin_lock(&cii->c_lock);
58443 hit = (mask & cii->c_cached_perm) == mask &&
58444 uid_eq(cii->c_uid, current_fsuid()) &&
58445- cii->c_cached_epoch == atomic_read(&permission_epoch);
58446+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58447 spin_unlock(&cii->c_lock);
58448
58449 return hit;
58450diff --git a/fs/compat.c b/fs/compat.c
58451index 6af20de..fec3fbb 100644
58452--- a/fs/compat.c
58453+++ b/fs/compat.c
58454@@ -54,7 +54,7 @@
58455 #include <asm/ioctls.h>
58456 #include "internal.h"
58457
58458-int compat_log = 1;
58459+int compat_log = 0;
58460
58461 int compat_printk(const char *fmt, ...)
58462 {
58463@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
58464
58465 set_fs(KERNEL_DS);
58466 /* The __user pointer cast is valid because of the set_fs() */
58467- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58468+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58469 set_fs(oldfs);
58470 /* truncating is ok because it's a user address */
58471 if (!ret)
58472@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58473 goto out;
58474
58475 ret = -EINVAL;
58476- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58477+ if (nr_segs > UIO_MAXIOV)
58478 goto out;
58479 if (nr_segs > fast_segs) {
58480 ret = -ENOMEM;
58481@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
58482 struct compat_readdir_callback {
58483 struct dir_context ctx;
58484 struct compat_old_linux_dirent __user *dirent;
58485+ struct file * file;
58486 int result;
58487 };
58488
58489@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58490 buf->result = -EOVERFLOW;
58491 return -EOVERFLOW;
58492 }
58493+
58494+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58495+ return 0;
58496+
58497 buf->result++;
58498 dirent = buf->dirent;
58499 if (!access_ok(VERIFY_WRITE, dirent,
58500@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
58501 if (!f.file)
58502 return -EBADF;
58503
58504+ buf.file = f.file;
58505 error = iterate_dir(f.file, &buf.ctx);
58506 if (buf.result)
58507 error = buf.result;
58508@@ -901,6 +907,7 @@ struct compat_getdents_callback {
58509 struct dir_context ctx;
58510 struct compat_linux_dirent __user *current_dir;
58511 struct compat_linux_dirent __user *previous;
58512+ struct file * file;
58513 int count;
58514 int error;
58515 };
58516@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58517 buf->error = -EOVERFLOW;
58518 return -EOVERFLOW;
58519 }
58520+
58521+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58522+ return 0;
58523+
58524 dirent = buf->previous;
58525 if (dirent) {
58526 if (__put_user(offset, &dirent->d_off))
58527@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
58528 if (!f.file)
58529 return -EBADF;
58530
58531+ buf.file = f.file;
58532 error = iterate_dir(f.file, &buf.ctx);
58533 if (error >= 0)
58534 error = buf.error;
58535@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
58536 struct dir_context ctx;
58537 struct linux_dirent64 __user *current_dir;
58538 struct linux_dirent64 __user *previous;
58539+ struct file * file;
58540 int count;
58541 int error;
58542 };
58543@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58544 buf->error = -EINVAL; /* only used if we fail.. */
58545 if (reclen > buf->count)
58546 return -EINVAL;
58547+
58548+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58549+ return 0;
58550+
58551 dirent = buf->previous;
58552
58553 if (dirent) {
58554@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
58555 if (!f.file)
58556 return -EBADF;
58557
58558+ buf.file = f.file;
58559 error = iterate_dir(f.file, &buf.ctx);
58560 if (error >= 0)
58561 error = buf.error;
58562diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58563index a81147e..20bf2b5 100644
58564--- a/fs/compat_binfmt_elf.c
58565+++ b/fs/compat_binfmt_elf.c
58566@@ -30,11 +30,13 @@
58567 #undef elf_phdr
58568 #undef elf_shdr
58569 #undef elf_note
58570+#undef elf_dyn
58571 #undef elf_addr_t
58572 #define elfhdr elf32_hdr
58573 #define elf_phdr elf32_phdr
58574 #define elf_shdr elf32_shdr
58575 #define elf_note elf32_note
58576+#define elf_dyn Elf32_Dyn
58577 #define elf_addr_t Elf32_Addr
58578
58579 /*
58580diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58581index 3881610..ab3df0b 100644
58582--- a/fs/compat_ioctl.c
58583+++ b/fs/compat_ioctl.c
58584@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58585 return -EFAULT;
58586 if (__get_user(udata, &ss32->iomem_base))
58587 return -EFAULT;
58588- ss.iomem_base = compat_ptr(udata);
58589+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58590 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58591 __get_user(ss.port_high, &ss32->port_high))
58592 return -EFAULT;
58593@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58594 for (i = 0; i < nmsgs; i++) {
58595 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58596 return -EFAULT;
58597- if (get_user(datap, &umsgs[i].buf) ||
58598- put_user(compat_ptr(datap), &tmsgs[i].buf))
58599+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58600+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58601 return -EFAULT;
58602 }
58603 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58604@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58605 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58606 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58607 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58608- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58609+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58610 return -EFAULT;
58611
58612 return ioctl_preallocate(file, p);
58613@@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58614 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58615 {
58616 unsigned int a, b;
58617- a = *(unsigned int *)p;
58618- b = *(unsigned int *)q;
58619+ a = *(const unsigned int *)p;
58620+ b = *(const unsigned int *)q;
58621 if (a > b)
58622 return 1;
58623 if (a < b)
58624diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58625index e081acb..911df21 100644
58626--- a/fs/configfs/dir.c
58627+++ b/fs/configfs/dir.c
58628@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58629 }
58630 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58631 struct configfs_dirent *next;
58632- const char *name;
58633+ const unsigned char * name;
58634+ char d_name[sizeof(next->s_dentry->d_iname)];
58635 int len;
58636 struct inode *inode = NULL;
58637
58638@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58639 continue;
58640
58641 name = configfs_get_name(next);
58642- len = strlen(name);
58643+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58644+ len = next->s_dentry->d_name.len;
58645+ memcpy(d_name, name, len);
58646+ name = d_name;
58647+ } else
58648+ len = strlen(name);
58649
58650 /*
58651 * We'll have a dentry and an inode for
58652diff --git a/fs/coredump.c b/fs/coredump.c
58653index e3ad709..836c55f 100644
58654--- a/fs/coredump.c
58655+++ b/fs/coredump.c
58656@@ -73,10 +73,15 @@ static int expand_corename(struct core_name *cn, int size)
58657 static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
58658 {
58659 int free, need;
58660+ va_list arg_copy;
58661
58662 again:
58663 free = cn->size - cn->used;
58664- need = vsnprintf(cn->corename + cn->used, free, fmt, arg);
58665+
58666+ va_copy(arg_copy, arg);
58667+ need = vsnprintf(cn->corename + cn->used, free, fmt, arg_copy);
58668+ va_end(arg_copy);
58669+
58670 if (need < free) {
58671 cn->used += need;
58672 return 0;
58673@@ -437,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58674 struct pipe_inode_info *pipe = file->private_data;
58675
58676 pipe_lock(pipe);
58677- pipe->readers++;
58678- pipe->writers--;
58679+ atomic_inc(&pipe->readers);
58680+ atomic_dec(&pipe->writers);
58681 wake_up_interruptible_sync(&pipe->wait);
58682 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58683 pipe_unlock(pipe);
58684@@ -447,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58685 * We actually want wait_event_freezable() but then we need
58686 * to clear TIF_SIGPENDING and improve dump_interrupted().
58687 */
58688- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58689+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58690
58691 pipe_lock(pipe);
58692- pipe->readers--;
58693- pipe->writers++;
58694+ atomic_dec(&pipe->readers);
58695+ atomic_inc(&pipe->writers);
58696 pipe_unlock(pipe);
58697 }
58698
58699@@ -498,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58700 struct files_struct *displaced;
58701 bool need_nonrelative = false;
58702 bool core_dumped = false;
58703- static atomic_t core_dump_count = ATOMIC_INIT(0);
58704+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58705+ long signr = siginfo->si_signo;
58706+ int dumpable;
58707 struct coredump_params cprm = {
58708 .siginfo = siginfo,
58709 .regs = signal_pt_regs(),
58710@@ -511,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58711 .mm_flags = mm->flags,
58712 };
58713
58714- audit_core_dumps(siginfo->si_signo);
58715+ audit_core_dumps(signr);
58716+
58717+ dumpable = __get_dumpable(cprm.mm_flags);
58718+
58719+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58720+ gr_handle_brute_attach(dumpable);
58721
58722 binfmt = mm->binfmt;
58723 if (!binfmt || !binfmt->core_dump)
58724 goto fail;
58725- if (!__get_dumpable(cprm.mm_flags))
58726+ if (!dumpable)
58727 goto fail;
58728
58729 cred = prepare_creds();
58730@@ -535,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58731 need_nonrelative = true;
58732 }
58733
58734- retval = coredump_wait(siginfo->si_signo, &core_state);
58735+ retval = coredump_wait(signr, &core_state);
58736 if (retval < 0)
58737 goto fail_creds;
58738
58739@@ -578,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58740 }
58741 cprm.limit = RLIM_INFINITY;
58742
58743- dump_count = atomic_inc_return(&core_dump_count);
58744+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58745 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58746 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58747 task_tgid_vnr(current), current->comm);
58748@@ -610,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58749 } else {
58750 struct inode *inode;
58751
58752+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58753+
58754 if (cprm.limit < binfmt->min_coredump)
58755 goto fail_unlock;
58756
58757@@ -668,7 +682,7 @@ close_fail:
58758 filp_close(cprm.file, NULL);
58759 fail_dropcount:
58760 if (ispipe)
58761- atomic_dec(&core_dump_count);
58762+ atomic_dec_unchecked(&core_dump_count);
58763 fail_unlock:
58764 kfree(cn.corename);
58765 coredump_finish(mm, core_dumped);
58766@@ -689,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58767 struct file *file = cprm->file;
58768 loff_t pos = file->f_pos;
58769 ssize_t n;
58770+
58771+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58772 if (cprm->written + nr > cprm->limit)
58773 return 0;
58774 while (nr) {
58775diff --git a/fs/dcache.c b/fs/dcache.c
58776index ca02c13..7e2b581 100644
58777--- a/fs/dcache.c
58778+++ b/fs/dcache.c
58779@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58780 */
58781 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58782 if (name->len > DNAME_INLINE_LEN-1) {
58783- dname = kmalloc(name->len + 1, GFP_KERNEL);
58784+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58785 if (!dname) {
58786 kmem_cache_free(dentry_cache, dentry);
58787 return NULL;
58788@@ -3431,7 +3431,8 @@ void __init vfs_caches_init(unsigned long mempages)
58789 mempages -= reserve;
58790
58791 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58792- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58793+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58794+ SLAB_NO_SANITIZE, NULL);
58795
58796 dcache_init();
58797 inode_init();
58798diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58799index 9c0444c..628490c 100644
58800--- a/fs/debugfs/inode.c
58801+++ b/fs/debugfs/inode.c
58802@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58803 */
58804 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58805 {
58806+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58807+ return __create_file(name, S_IFDIR | S_IRWXU,
58808+#else
58809 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58810+#endif
58811 parent, NULL, NULL);
58812 }
58813 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58814diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58815index b167ca4..a224e19 100644
58816--- a/fs/ecryptfs/inode.c
58817+++ b/fs/ecryptfs/inode.c
58818@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58819 old_fs = get_fs();
58820 set_fs(get_ds());
58821 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58822- (char __user *)lower_buf,
58823+ (char __force_user *)lower_buf,
58824 PATH_MAX);
58825 set_fs(old_fs);
58826 if (rc < 0)
58827diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58828index e4141f2..d8263e8 100644
58829--- a/fs/ecryptfs/miscdev.c
58830+++ b/fs/ecryptfs/miscdev.c
58831@@ -304,7 +304,7 @@ check_list:
58832 goto out_unlock_msg_ctx;
58833 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58834 if (msg_ctx->msg) {
58835- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58836+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58837 goto out_unlock_msg_ctx;
58838 i += packet_length_size;
58839 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58840diff --git a/fs/exec.c b/fs/exec.c
58841index 3d78fcc..cd4f983 100644
58842--- a/fs/exec.c
58843+++ b/fs/exec.c
58844@@ -55,8 +55,20 @@
58845 #include <linux/pipe_fs_i.h>
58846 #include <linux/oom.h>
58847 #include <linux/compat.h>
58848+#include <linux/random.h>
58849+#include <linux/seq_file.h>
58850+#include <linux/coredump.h>
58851+#include <linux/mman.h>
58852+
58853+#ifdef CONFIG_PAX_REFCOUNT
58854+#include <linux/kallsyms.h>
58855+#include <linux/kdebug.h>
58856+#endif
58857+
58858+#include <trace/events/fs.h>
58859
58860 #include <asm/uaccess.h>
58861+#include <asm/sections.h>
58862 #include <asm/mmu_context.h>
58863 #include <asm/tlb.h>
58864
58865@@ -65,19 +77,34 @@
58866
58867 #include <trace/events/sched.h>
58868
58869+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58870+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58871+{
58872+ 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");
58873+}
58874+#endif
58875+
58876+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58877+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58878+EXPORT_SYMBOL(pax_set_initial_flags_func);
58879+#endif
58880+
58881 int suid_dumpable = 0;
58882
58883 static LIST_HEAD(formats);
58884 static DEFINE_RWLOCK(binfmt_lock);
58885
58886+extern int gr_process_kernel_exec_ban(void);
58887+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58888+
58889 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58890 {
58891 BUG_ON(!fmt);
58892 if (WARN_ON(!fmt->load_binary))
58893 return;
58894 write_lock(&binfmt_lock);
58895- insert ? list_add(&fmt->lh, &formats) :
58896- list_add_tail(&fmt->lh, &formats);
58897+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58898+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58899 write_unlock(&binfmt_lock);
58900 }
58901
58902@@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
58903 void unregister_binfmt(struct linux_binfmt * fmt)
58904 {
58905 write_lock(&binfmt_lock);
58906- list_del(&fmt->lh);
58907+ pax_list_del((struct list_head *)&fmt->lh);
58908 write_unlock(&binfmt_lock);
58909 }
58910
58911@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58912 int write)
58913 {
58914 struct page *page;
58915- int ret;
58916
58917-#ifdef CONFIG_STACK_GROWSUP
58918- if (write) {
58919- ret = expand_downwards(bprm->vma, pos);
58920- if (ret < 0)
58921- return NULL;
58922- }
58923-#endif
58924- ret = get_user_pages(current, bprm->mm, pos,
58925- 1, write, 1, &page, NULL);
58926- if (ret <= 0)
58927+ if (0 > expand_downwards(bprm->vma, pos))
58928+ return NULL;
58929+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58930 return NULL;
58931
58932 if (write) {
58933@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58934 if (size <= ARG_MAX)
58935 return page;
58936
58937+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58938+ // only allow 512KB for argv+env on suid/sgid binaries
58939+ // to prevent easy ASLR exhaustion
58940+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58941+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58942+ (size > (512 * 1024))) {
58943+ put_page(page);
58944+ return NULL;
58945+ }
58946+#endif
58947+
58948 /*
58949 * Limit to 1/4-th the stack size for the argv+env strings.
58950 * This ensures that:
58951@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58952 vma->vm_end = STACK_TOP_MAX;
58953 vma->vm_start = vma->vm_end - PAGE_SIZE;
58954 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58955+
58956+#ifdef CONFIG_PAX_SEGMEXEC
58957+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58958+#endif
58959+
58960 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58961 INIT_LIST_HEAD(&vma->anon_vma_chain);
58962
58963@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58964 mm->stack_vm = mm->total_vm = 1;
58965 up_write(&mm->mmap_sem);
58966 bprm->p = vma->vm_end - sizeof(void *);
58967+
58968+#ifdef CONFIG_PAX_RANDUSTACK
58969+ if (randomize_va_space)
58970+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58971+#endif
58972+
58973 return 0;
58974 err:
58975 up_write(&mm->mmap_sem);
58976@@ -396,7 +437,7 @@ struct user_arg_ptr {
58977 } ptr;
58978 };
58979
58980-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58981+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58982 {
58983 const char __user *native;
58984
58985@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58986 compat_uptr_t compat;
58987
58988 if (get_user(compat, argv.ptr.compat + nr))
58989- return ERR_PTR(-EFAULT);
58990+ return (const char __force_user *)ERR_PTR(-EFAULT);
58991
58992 return compat_ptr(compat);
58993 }
58994 #endif
58995
58996 if (get_user(native, argv.ptr.native + nr))
58997- return ERR_PTR(-EFAULT);
58998+ return (const char __force_user *)ERR_PTR(-EFAULT);
58999
59000 return native;
59001 }
59002@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
59003 if (!p)
59004 break;
59005
59006- if (IS_ERR(p))
59007+ if (IS_ERR((const char __force_kernel *)p))
59008 return -EFAULT;
59009
59010 if (i >= max)
59011@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
59012
59013 ret = -EFAULT;
59014 str = get_user_arg_ptr(argv, argc);
59015- if (IS_ERR(str))
59016+ if (IS_ERR((const char __force_kernel *)str))
59017 goto out;
59018
59019 len = strnlen_user(str, MAX_ARG_STRLEN);
59020@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
59021 int r;
59022 mm_segment_t oldfs = get_fs();
59023 struct user_arg_ptr argv = {
59024- .ptr.native = (const char __user *const __user *)__argv,
59025+ .ptr.native = (const char __user * const __force_user *)__argv,
59026 };
59027
59028 set_fs(KERNEL_DS);
59029@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
59030 unsigned long new_end = old_end - shift;
59031 struct mmu_gather tlb;
59032
59033- BUG_ON(new_start > new_end);
59034+ if (new_start >= new_end || new_start < mmap_min_addr)
59035+ return -ENOMEM;
59036
59037 /*
59038 * ensure there are no vmas between where we want to go
59039@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
59040 if (vma != find_vma(mm, new_start))
59041 return -EFAULT;
59042
59043+#ifdef CONFIG_PAX_SEGMEXEC
59044+ BUG_ON(pax_find_mirror_vma(vma));
59045+#endif
59046+
59047 /*
59048 * cover the whole range: [new_start, old_end)
59049 */
59050@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59051 stack_top = arch_align_stack(stack_top);
59052 stack_top = PAGE_ALIGN(stack_top);
59053
59054- if (unlikely(stack_top < mmap_min_addr) ||
59055- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
59056- return -ENOMEM;
59057-
59058 stack_shift = vma->vm_end - stack_top;
59059
59060 bprm->p -= stack_shift;
59061@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
59062 bprm->exec -= stack_shift;
59063
59064 down_write(&mm->mmap_sem);
59065+
59066+ /* Move stack pages down in memory. */
59067+ if (stack_shift) {
59068+ ret = shift_arg_pages(vma, stack_shift);
59069+ if (ret)
59070+ goto out_unlock;
59071+ }
59072+
59073 vm_flags = VM_STACK_FLAGS;
59074
59075+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59076+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59077+ vm_flags &= ~VM_EXEC;
59078+
59079+#ifdef CONFIG_PAX_MPROTECT
59080+ if (mm->pax_flags & MF_PAX_MPROTECT)
59081+ vm_flags &= ~VM_MAYEXEC;
59082+#endif
59083+
59084+ }
59085+#endif
59086+
59087 /*
59088 * Adjust stack execute permissions; explicitly enable for
59089 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
59090@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59091 goto out_unlock;
59092 BUG_ON(prev != vma);
59093
59094- /* Move stack pages down in memory. */
59095- if (stack_shift) {
59096- ret = shift_arg_pages(vma, stack_shift);
59097- if (ret)
59098- goto out_unlock;
59099- }
59100-
59101 /* mprotect_fixup is overkill to remove the temporary stack flags */
59102 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
59103
59104@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
59105 #endif
59106 current->mm->start_stack = bprm->p;
59107 ret = expand_stack(vma, stack_base);
59108+
59109+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
59110+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
59111+ unsigned long size;
59112+ vm_flags_t vm_flags;
59113+
59114+ size = STACK_TOP - vma->vm_end;
59115+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
59116+
59117+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
59118+
59119+#ifdef CONFIG_X86
59120+ if (!ret) {
59121+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
59122+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
59123+ }
59124+#endif
59125+
59126+ }
59127+#endif
59128+
59129 if (ret)
59130 ret = -EFAULT;
59131
59132@@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
59133
59134 fsnotify_open(file);
59135
59136+ trace_open_exec(name->name);
59137+
59138 err = deny_write_access(file);
59139 if (err)
59140 goto exit;
59141@@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
59142 old_fs = get_fs();
59143 set_fs(get_ds());
59144 /* The cast to a user pointer is valid due to the set_fs() */
59145- result = vfs_read(file, (void __user *)addr, count, &pos);
59146+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
59147 set_fs(old_fs);
59148 return result;
59149 }
59150@@ -846,6 +924,7 @@ static int exec_mmap(struct mm_struct *mm)
59151 tsk->mm = mm;
59152 tsk->active_mm = mm;
59153 activate_mm(active_mm, mm);
59154+ populate_stack();
59155 task_unlock(tsk);
59156 if (old_mm) {
59157 up_read(&old_mm->mmap_sem);
59158@@ -1258,7 +1337,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
59159 }
59160 rcu_read_unlock();
59161
59162- if (p->fs->users > n_fs)
59163+ if (atomic_read(&p->fs->users) > n_fs)
59164 bprm->unsafe |= LSM_UNSAFE_SHARE;
59165 else
59166 p->fs->in_exec = 1;
59167@@ -1434,6 +1513,31 @@ static int exec_binprm(struct linux_binprm *bprm)
59168 return ret;
59169 }
59170
59171+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59172+static DEFINE_PER_CPU(u64, exec_counter);
59173+static int __init init_exec_counters(void)
59174+{
59175+ unsigned int cpu;
59176+
59177+ for_each_possible_cpu(cpu) {
59178+ per_cpu(exec_counter, cpu) = (u64)cpu;
59179+ }
59180+
59181+ return 0;
59182+}
59183+early_initcall(init_exec_counters);
59184+static inline void increment_exec_counter(void)
59185+{
59186+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
59187+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
59188+}
59189+#else
59190+static inline void increment_exec_counter(void) {}
59191+#endif
59192+
59193+extern void gr_handle_exec_args(struct linux_binprm *bprm,
59194+ struct user_arg_ptr argv);
59195+
59196 /*
59197 * sys_execve() executes a new program.
59198 */
59199@@ -1441,6 +1545,11 @@ static int do_execve_common(struct filename *filename,
59200 struct user_arg_ptr argv,
59201 struct user_arg_ptr envp)
59202 {
59203+#ifdef CONFIG_GRKERNSEC
59204+ struct file *old_exec_file;
59205+ struct acl_subject_label *old_acl;
59206+ struct rlimit old_rlim[RLIM_NLIMITS];
59207+#endif
59208 struct linux_binprm *bprm;
59209 struct file *file;
59210 struct files_struct *displaced;
59211@@ -1449,6 +1558,8 @@ static int do_execve_common(struct filename *filename,
59212 if (IS_ERR(filename))
59213 return PTR_ERR(filename);
59214
59215+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
59216+
59217 /*
59218 * We move the actual failure in case of RLIMIT_NPROC excess from
59219 * set*uid() to execve() because too many poorly written programs
59220@@ -1486,11 +1597,21 @@ static int do_execve_common(struct filename *filename,
59221 if (IS_ERR(file))
59222 goto out_unmark;
59223
59224+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
59225+ retval = -EPERM;
59226+ goto out_unmark;
59227+ }
59228+
59229 sched_exec();
59230
59231 bprm->file = file;
59232 bprm->filename = bprm->interp = filename->name;
59233
59234+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
59235+ retval = -EACCES;
59236+ goto out_unmark;
59237+ }
59238+
59239 retval = bprm_mm_init(bprm);
59240 if (retval)
59241 goto out_unmark;
59242@@ -1507,24 +1628,70 @@ static int do_execve_common(struct filename *filename,
59243 if (retval < 0)
59244 goto out;
59245
59246+#ifdef CONFIG_GRKERNSEC
59247+ old_acl = current->acl;
59248+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
59249+ old_exec_file = current->exec_file;
59250+ get_file(file);
59251+ current->exec_file = file;
59252+#endif
59253+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59254+ /* limit suid stack to 8MB
59255+ * we saved the old limits above and will restore them if this exec fails
59256+ */
59257+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
59258+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
59259+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
59260+#endif
59261+
59262+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
59263+ retval = -EPERM;
59264+ goto out_fail;
59265+ }
59266+
59267+ if (!gr_tpe_allow(file)) {
59268+ retval = -EACCES;
59269+ goto out_fail;
59270+ }
59271+
59272+ if (gr_check_crash_exec(file)) {
59273+ retval = -EACCES;
59274+ goto out_fail;
59275+ }
59276+
59277+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
59278+ bprm->unsafe);
59279+ if (retval < 0)
59280+ goto out_fail;
59281+
59282 retval = copy_strings_kernel(1, &bprm->filename, bprm);
59283 if (retval < 0)
59284- goto out;
59285+ goto out_fail;
59286
59287 bprm->exec = bprm->p;
59288 retval = copy_strings(bprm->envc, envp, bprm);
59289 if (retval < 0)
59290- goto out;
59291+ goto out_fail;
59292
59293 retval = copy_strings(bprm->argc, argv, bprm);
59294 if (retval < 0)
59295- goto out;
59296+ goto out_fail;
59297+
59298+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
59299+
59300+ gr_handle_exec_args(bprm, argv);
59301
59302 retval = exec_binprm(bprm);
59303 if (retval < 0)
59304- goto out;
59305+ goto out_fail;
59306+#ifdef CONFIG_GRKERNSEC
59307+ if (old_exec_file)
59308+ fput(old_exec_file);
59309+#endif
59310
59311 /* execve succeeded */
59312+
59313+ increment_exec_counter();
59314 current->fs->in_exec = 0;
59315 current->in_execve = 0;
59316 acct_update_integrals(current);
59317@@ -1535,6 +1702,14 @@ static int do_execve_common(struct filename *filename,
59318 put_files_struct(displaced);
59319 return retval;
59320
59321+out_fail:
59322+#ifdef CONFIG_GRKERNSEC
59323+ current->acl = old_acl;
59324+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
59325+ fput(current->exec_file);
59326+ current->exec_file = old_exec_file;
59327+#endif
59328+
59329 out:
59330 if (bprm->mm) {
59331 acct_arg_size(bprm, 0);
59332@@ -1626,3 +1801,296 @@ asmlinkage long compat_sys_execve(const char __user * filename,
59333 return compat_do_execve(getname(filename), argv, envp);
59334 }
59335 #endif
59336+
59337+int pax_check_flags(unsigned long *flags)
59338+{
59339+ int retval = 0;
59340+
59341+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
59342+ if (*flags & MF_PAX_SEGMEXEC)
59343+ {
59344+ *flags &= ~MF_PAX_SEGMEXEC;
59345+ retval = -EINVAL;
59346+ }
59347+#endif
59348+
59349+ if ((*flags & MF_PAX_PAGEEXEC)
59350+
59351+#ifdef CONFIG_PAX_PAGEEXEC
59352+ && (*flags & MF_PAX_SEGMEXEC)
59353+#endif
59354+
59355+ )
59356+ {
59357+ *flags &= ~MF_PAX_PAGEEXEC;
59358+ retval = -EINVAL;
59359+ }
59360+
59361+ if ((*flags & MF_PAX_MPROTECT)
59362+
59363+#ifdef CONFIG_PAX_MPROTECT
59364+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59365+#endif
59366+
59367+ )
59368+ {
59369+ *flags &= ~MF_PAX_MPROTECT;
59370+ retval = -EINVAL;
59371+ }
59372+
59373+ if ((*flags & MF_PAX_EMUTRAMP)
59374+
59375+#ifdef CONFIG_PAX_EMUTRAMP
59376+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59377+#endif
59378+
59379+ )
59380+ {
59381+ *flags &= ~MF_PAX_EMUTRAMP;
59382+ retval = -EINVAL;
59383+ }
59384+
59385+ return retval;
59386+}
59387+
59388+EXPORT_SYMBOL(pax_check_flags);
59389+
59390+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59391+char *pax_get_path(const struct path *path, char *buf, int buflen)
59392+{
59393+ char *pathname = d_path(path, buf, buflen);
59394+
59395+ if (IS_ERR(pathname))
59396+ goto toolong;
59397+
59398+ pathname = mangle_path(buf, pathname, "\t\n\\");
59399+ if (!pathname)
59400+ goto toolong;
59401+
59402+ *pathname = 0;
59403+ return buf;
59404+
59405+toolong:
59406+ return "<path too long>";
59407+}
59408+EXPORT_SYMBOL(pax_get_path);
59409+
59410+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59411+{
59412+ struct task_struct *tsk = current;
59413+ struct mm_struct *mm = current->mm;
59414+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59415+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59416+ char *path_exec = NULL;
59417+ char *path_fault = NULL;
59418+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
59419+ siginfo_t info = { };
59420+
59421+ if (buffer_exec && buffer_fault) {
59422+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59423+
59424+ down_read(&mm->mmap_sem);
59425+ vma = mm->mmap;
59426+ while (vma && (!vma_exec || !vma_fault)) {
59427+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59428+ vma_exec = vma;
59429+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59430+ vma_fault = vma;
59431+ vma = vma->vm_next;
59432+ }
59433+ if (vma_exec)
59434+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59435+ if (vma_fault) {
59436+ start = vma_fault->vm_start;
59437+ end = vma_fault->vm_end;
59438+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59439+ if (vma_fault->vm_file)
59440+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59441+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59442+ path_fault = "<heap>";
59443+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59444+ path_fault = "<stack>";
59445+ else
59446+ path_fault = "<anonymous mapping>";
59447+ }
59448+ up_read(&mm->mmap_sem);
59449+ }
59450+ if (tsk->signal->curr_ip)
59451+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59452+ else
59453+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59454+ 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),
59455+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59456+ free_page((unsigned long)buffer_exec);
59457+ free_page((unsigned long)buffer_fault);
59458+ pax_report_insns(regs, pc, sp);
59459+ info.si_signo = SIGKILL;
59460+ info.si_errno = 0;
59461+ info.si_code = SI_KERNEL;
59462+ info.si_pid = 0;
59463+ info.si_uid = 0;
59464+ do_coredump(&info);
59465+}
59466+#endif
59467+
59468+#ifdef CONFIG_PAX_REFCOUNT
59469+void pax_report_refcount_overflow(struct pt_regs *regs)
59470+{
59471+ if (current->signal->curr_ip)
59472+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59473+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
59474+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59475+ else
59476+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59477+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59478+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59479+ preempt_disable();
59480+ show_regs(regs);
59481+ preempt_enable();
59482+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59483+}
59484+#endif
59485+
59486+#ifdef CONFIG_PAX_USERCOPY
59487+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59488+static noinline int check_stack_object(const void *obj, unsigned long len)
59489+{
59490+ const void * const stack = task_stack_page(current);
59491+ const void * const stackend = stack + THREAD_SIZE;
59492+
59493+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59494+ const void *frame = NULL;
59495+ const void *oldframe;
59496+#endif
59497+
59498+ if (obj + len < obj)
59499+ return -1;
59500+
59501+ if (obj + len <= stack || stackend <= obj)
59502+ return 0;
59503+
59504+ if (obj < stack || stackend < obj + len)
59505+ return -1;
59506+
59507+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59508+ oldframe = __builtin_frame_address(1);
59509+ if (oldframe)
59510+ frame = __builtin_frame_address(2);
59511+ /*
59512+ low ----------------------------------------------> high
59513+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
59514+ ^----------------^
59515+ allow copies only within here
59516+ */
59517+ while (stack <= frame && frame < stackend) {
59518+ /* if obj + len extends past the last frame, this
59519+ check won't pass and the next frame will be 0,
59520+ causing us to bail out and correctly report
59521+ the copy as invalid
59522+ */
59523+ if (obj + len <= frame)
59524+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59525+ oldframe = frame;
59526+ frame = *(const void * const *)frame;
59527+ }
59528+ return -1;
59529+#else
59530+ return 1;
59531+#endif
59532+}
59533+
59534+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59535+{
59536+ if (current->signal->curr_ip)
59537+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59538+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59539+ else
59540+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59541+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59542+ dump_stack();
59543+ gr_handle_kernel_exploit();
59544+ do_group_exit(SIGKILL);
59545+}
59546+#endif
59547+
59548+#ifdef CONFIG_PAX_USERCOPY
59549+
59550+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59551+{
59552+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59553+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59554+#ifdef CONFIG_MODULES
59555+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59556+#else
59557+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59558+#endif
59559+
59560+#else
59561+ unsigned long textlow = (unsigned long)_stext;
59562+ unsigned long texthigh = (unsigned long)_etext;
59563+
59564+#ifdef CONFIG_X86_64
59565+ /* check against linear mapping as well */
59566+ if (high > (unsigned long)__va(__pa(textlow)) &&
59567+ low < (unsigned long)__va(__pa(texthigh)))
59568+ return true;
59569+#endif
59570+
59571+#endif
59572+
59573+ if (high <= textlow || low >= texthigh)
59574+ return false;
59575+ else
59576+ return true;
59577+}
59578+#endif
59579+
59580+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
59581+{
59582+
59583+#ifdef CONFIG_PAX_USERCOPY
59584+ const char *type;
59585+
59586+ if (!n)
59587+ return;
59588+
59589+ type = check_heap_object(ptr, n);
59590+ if (!type) {
59591+ int ret = check_stack_object(ptr, n);
59592+ if (ret == 1 || ret == 2)
59593+ return;
59594+ if (ret == 0) {
59595+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59596+ type = "<kernel text>";
59597+ else
59598+ return;
59599+ } else
59600+ type = "<process stack>";
59601+ }
59602+
59603+ pax_report_usercopy(ptr, n, to_user, type);
59604+#endif
59605+
59606+}
59607+EXPORT_SYMBOL(__check_object_size);
59608+
59609+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59610+void pax_track_stack(void)
59611+{
59612+ unsigned long sp = (unsigned long)&sp;
59613+ if (sp < current_thread_info()->lowest_stack &&
59614+ sp > (unsigned long)task_stack_page(current))
59615+ current_thread_info()->lowest_stack = sp;
59616+}
59617+EXPORT_SYMBOL(pax_track_stack);
59618+#endif
59619+
59620+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59621+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59622+{
59623+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59624+ dump_stack();
59625+ do_group_exit(SIGKILL);
59626+}
59627+EXPORT_SYMBOL(report_size_overflow);
59628+#endif
59629diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59630index 9f9992b..8b59411 100644
59631--- a/fs/ext2/balloc.c
59632+++ b/fs/ext2/balloc.c
59633@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59634
59635 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59636 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59637- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59638+ if (free_blocks < root_blocks + 1 &&
59639 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59640 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59641- !in_group_p (sbi->s_resgid))) {
59642+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59643 return 0;
59644 }
59645 return 1;
59646diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59647index 9142614..97484fa 100644
59648--- a/fs/ext2/xattr.c
59649+++ b/fs/ext2/xattr.c
59650@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59651 struct buffer_head *bh = NULL;
59652 struct ext2_xattr_entry *entry;
59653 char *end;
59654- size_t rest = buffer_size;
59655+ size_t rest = buffer_size, total_size = 0;
59656 int error;
59657
59658 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59659@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59660 buffer += size;
59661 }
59662 rest -= size;
59663+ total_size += size;
59664 }
59665 }
59666- error = buffer_size - rest; /* total size */
59667+ error = total_size;
59668
59669 cleanup:
59670 brelse(bh);
59671diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59672index 22548f5..41521d8 100644
59673--- a/fs/ext3/balloc.c
59674+++ b/fs/ext3/balloc.c
59675@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59676
59677 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59678 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59679- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59680+ if (free_blocks < root_blocks + 1 &&
59681 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59682 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59683- !in_group_p (sbi->s_resgid))) {
59684+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59685 return 0;
59686 }
59687 return 1;
59688diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59689index c6874be..f8a6ae8 100644
59690--- a/fs/ext3/xattr.c
59691+++ b/fs/ext3/xattr.c
59692@@ -330,7 +330,7 @@ static int
59693 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59694 char *buffer, size_t buffer_size)
59695 {
59696- size_t rest = buffer_size;
59697+ size_t rest = buffer_size, total_size = 0;
59698
59699 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59700 const struct xattr_handler *handler =
59701@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59702 buffer += size;
59703 }
59704 rest -= size;
59705+ total_size += size;
59706 }
59707 }
59708- return buffer_size - rest;
59709+ return total_size;
59710 }
59711
59712 static int
59713diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59714index 6ea7b14..8fa16d9 100644
59715--- a/fs/ext4/balloc.c
59716+++ b/fs/ext4/balloc.c
59717@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59718 /* Hm, nope. Are (enough) root reserved clusters available? */
59719 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59720 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59721- capable(CAP_SYS_RESOURCE) ||
59722- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59723+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59724+ capable_nolog(CAP_SYS_RESOURCE)) {
59725
59726 if (free_clusters >= (nclusters + dirty_clusters +
59727 resv_clusters))
59728diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59729index 3a603a8..9b868ba 100644
59730--- a/fs/ext4/ext4.h
59731+++ b/fs/ext4/ext4.h
59732@@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59733 unsigned long s_mb_last_start;
59734
59735 /* stats for buddy allocator */
59736- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59737- atomic_t s_bal_success; /* we found long enough chunks */
59738- atomic_t s_bal_allocated; /* in blocks */
59739- atomic_t s_bal_ex_scanned; /* total extents scanned */
59740- atomic_t s_bal_goals; /* goal hits */
59741- atomic_t s_bal_breaks; /* too long searches */
59742- atomic_t s_bal_2orders; /* 2^order hits */
59743+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59744+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59745+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59746+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59747+ atomic_unchecked_t s_bal_goals; /* goal hits */
59748+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59749+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59750 spinlock_t s_bal_lock;
59751 unsigned long s_mb_buddies_generated;
59752 unsigned long long s_mb_generation_time;
59753- atomic_t s_mb_lost_chunks;
59754- atomic_t s_mb_preallocated;
59755- atomic_t s_mb_discarded;
59756+ atomic_unchecked_t s_mb_lost_chunks;
59757+ atomic_unchecked_t s_mb_preallocated;
59758+ atomic_unchecked_t s_mb_discarded;
59759 atomic_t s_lock_busy;
59760
59761 /* locality groups */
59762diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59763index 04a5c75..09894fa 100644
59764--- a/fs/ext4/mballoc.c
59765+++ b/fs/ext4/mballoc.c
59766@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59767 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59768
59769 if (EXT4_SB(sb)->s_mb_stats)
59770- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59771+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59772
59773 break;
59774 }
59775@@ -2189,7 +2189,7 @@ repeat:
59776 ac->ac_status = AC_STATUS_CONTINUE;
59777 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59778 cr = 3;
59779- atomic_inc(&sbi->s_mb_lost_chunks);
59780+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59781 goto repeat;
59782 }
59783 }
59784@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59785 if (sbi->s_mb_stats) {
59786 ext4_msg(sb, KERN_INFO,
59787 "mballoc: %u blocks %u reqs (%u success)",
59788- atomic_read(&sbi->s_bal_allocated),
59789- atomic_read(&sbi->s_bal_reqs),
59790- atomic_read(&sbi->s_bal_success));
59791+ atomic_read_unchecked(&sbi->s_bal_allocated),
59792+ atomic_read_unchecked(&sbi->s_bal_reqs),
59793+ atomic_read_unchecked(&sbi->s_bal_success));
59794 ext4_msg(sb, KERN_INFO,
59795 "mballoc: %u extents scanned, %u goal hits, "
59796 "%u 2^N hits, %u breaks, %u lost",
59797- atomic_read(&sbi->s_bal_ex_scanned),
59798- atomic_read(&sbi->s_bal_goals),
59799- atomic_read(&sbi->s_bal_2orders),
59800- atomic_read(&sbi->s_bal_breaks),
59801- atomic_read(&sbi->s_mb_lost_chunks));
59802+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59803+ atomic_read_unchecked(&sbi->s_bal_goals),
59804+ atomic_read_unchecked(&sbi->s_bal_2orders),
59805+ atomic_read_unchecked(&sbi->s_bal_breaks),
59806+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59807 ext4_msg(sb, KERN_INFO,
59808 "mballoc: %lu generated and it took %Lu",
59809 sbi->s_mb_buddies_generated,
59810 sbi->s_mb_generation_time);
59811 ext4_msg(sb, KERN_INFO,
59812 "mballoc: %u preallocated, %u discarded",
59813- atomic_read(&sbi->s_mb_preallocated),
59814- atomic_read(&sbi->s_mb_discarded));
59815+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59816+ atomic_read_unchecked(&sbi->s_mb_discarded));
59817 }
59818
59819 free_percpu(sbi->s_locality_groups);
59820@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59821 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59822
59823 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59824- atomic_inc(&sbi->s_bal_reqs);
59825- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59826+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59827+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59828 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59829- atomic_inc(&sbi->s_bal_success);
59830- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59831+ atomic_inc_unchecked(&sbi->s_bal_success);
59832+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59833 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59834 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59835- atomic_inc(&sbi->s_bal_goals);
59836+ atomic_inc_unchecked(&sbi->s_bal_goals);
59837 if (ac->ac_found > sbi->s_mb_max_to_scan)
59838- atomic_inc(&sbi->s_bal_breaks);
59839+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59840 }
59841
59842 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59843@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59844 trace_ext4_mb_new_inode_pa(ac, pa);
59845
59846 ext4_mb_use_inode_pa(ac, pa);
59847- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59848+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59849
59850 ei = EXT4_I(ac->ac_inode);
59851 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59852@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59853 trace_ext4_mb_new_group_pa(ac, pa);
59854
59855 ext4_mb_use_group_pa(ac, pa);
59856- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59857+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59858
59859 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59860 lg = ac->ac_lg;
59861@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59862 * from the bitmap and continue.
59863 */
59864 }
59865- atomic_add(free, &sbi->s_mb_discarded);
59866+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59867
59868 return err;
59869 }
59870@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59871 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59872 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59873 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59874- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59875+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59876 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59877
59878 return 0;
59879diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59880index 04434ad..6404663 100644
59881--- a/fs/ext4/mmp.c
59882+++ b/fs/ext4/mmp.c
59883@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59884 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59885 const char *function, unsigned int line, const char *msg)
59886 {
59887- __ext4_warning(sb, function, line, msg);
59888+ __ext4_warning(sb, function, line, "%s", msg);
59889 __ext4_warning(sb, function, line,
59890 "MMP failure info: last update time: %llu, last update "
59891 "node: %s, last update device: %s\n",
59892diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59893index 710fed2..a82e4e8 100644
59894--- a/fs/ext4/super.c
59895+++ b/fs/ext4/super.c
59896@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59897 }
59898
59899 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59900-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59901+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59902 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59903
59904 #ifdef CONFIG_QUOTA
59905@@ -2450,7 +2450,7 @@ struct ext4_attr {
59906 int offset;
59907 int deprecated_val;
59908 } u;
59909-};
59910+} __do_const;
59911
59912 static int parse_strtoull(const char *buf,
59913 unsigned long long max, unsigned long long *value)
59914diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59915index 55e611c..cfad16d 100644
59916--- a/fs/ext4/xattr.c
59917+++ b/fs/ext4/xattr.c
59918@@ -381,7 +381,7 @@ static int
59919 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59920 char *buffer, size_t buffer_size)
59921 {
59922- size_t rest = buffer_size;
59923+ size_t rest = buffer_size, total_size = 0;
59924
59925 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59926 const struct xattr_handler *handler =
59927@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59928 buffer += size;
59929 }
59930 rest -= size;
59931+ total_size += size;
59932 }
59933 }
59934- return buffer_size - rest;
59935+ return total_size;
59936 }
59937
59938 static int
59939diff --git a/fs/fcntl.c b/fs/fcntl.c
59940index ef68665..5deacdc 100644
59941--- a/fs/fcntl.c
59942+++ b/fs/fcntl.c
59943@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59944 if (err)
59945 return err;
59946
59947+ if (gr_handle_chroot_fowner(pid, type))
59948+ return -ENOENT;
59949+ if (gr_check_protected_task_fowner(pid, type))
59950+ return -EACCES;
59951+
59952 f_modown(filp, pid, type, force);
59953 return 0;
59954 }
59955diff --git a/fs/fhandle.c b/fs/fhandle.c
59956index 999ff5c..41f4109 100644
59957--- a/fs/fhandle.c
59958+++ b/fs/fhandle.c
59959@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59960 } else
59961 retval = 0;
59962 /* copy the mount id */
59963- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59964- sizeof(*mnt_id)) ||
59965+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59966 copy_to_user(ufh, handle,
59967 sizeof(struct file_handle) + handle_bytes))
59968 retval = -EFAULT;
59969diff --git a/fs/file.c b/fs/file.c
59970index eb56a13..ccee850 100644
59971--- a/fs/file.c
59972+++ b/fs/file.c
59973@@ -16,6 +16,7 @@
59974 #include <linux/slab.h>
59975 #include <linux/vmalloc.h>
59976 #include <linux/file.h>
59977+#include <linux/security.h>
59978 #include <linux/fdtable.h>
59979 #include <linux/bitops.h>
59980 #include <linux/interrupt.h>
59981@@ -141,7 +142,7 @@ out:
59982 * Return <0 error code on error; 1 on successful completion.
59983 * The files->file_lock should be held on entry, and will be held on exit.
59984 */
59985-static int expand_fdtable(struct files_struct *files, int nr)
59986+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59987 __releases(files->file_lock)
59988 __acquires(files->file_lock)
59989 {
59990@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59991 * expanded and execution may have blocked.
59992 * The files->file_lock should be held on entry, and will be held on exit.
59993 */
59994-static int expand_files(struct files_struct *files, int nr)
59995+static int expand_files(struct files_struct *files, unsigned int nr)
59996 {
59997 struct fdtable *fdt;
59998
59999@@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
60000 if (!file)
60001 return __close_fd(files, fd);
60002
60003+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
60004 if (fd >= rlimit(RLIMIT_NOFILE))
60005 return -EBADF;
60006
60007@@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
60008 if (unlikely(oldfd == newfd))
60009 return -EINVAL;
60010
60011+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
60012 if (newfd >= rlimit(RLIMIT_NOFILE))
60013 return -EBADF;
60014
60015@@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
60016 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
60017 {
60018 int err;
60019+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
60020 if (from >= rlimit(RLIMIT_NOFILE))
60021 return -EINVAL;
60022 err = alloc_fd(from, flags);
60023diff --git a/fs/filesystems.c b/fs/filesystems.c
60024index 92567d9..fcd8cbf 100644
60025--- a/fs/filesystems.c
60026+++ b/fs/filesystems.c
60027@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
60028 int len = dot ? dot - name : strlen(name);
60029
60030 fs = __get_fs_type(name, len);
60031+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60032+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
60033+#else
60034 if (!fs && (request_module("fs-%.*s", len, name) == 0))
60035+#endif
60036 fs = __get_fs_type(name, len);
60037
60038 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
60039diff --git a/fs/fs_struct.c b/fs/fs_struct.c
60040index 7dca743..543d620 100644
60041--- a/fs/fs_struct.c
60042+++ b/fs/fs_struct.c
60043@@ -4,6 +4,7 @@
60044 #include <linux/path.h>
60045 #include <linux/slab.h>
60046 #include <linux/fs_struct.h>
60047+#include <linux/grsecurity.h>
60048 #include "internal.h"
60049
60050 /*
60051@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
60052 write_seqcount_begin(&fs->seq);
60053 old_root = fs->root;
60054 fs->root = *path;
60055+ gr_set_chroot_entries(current, path);
60056 write_seqcount_end(&fs->seq);
60057 spin_unlock(&fs->lock);
60058 if (old_root.dentry)
60059@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
60060 int hits = 0;
60061 spin_lock(&fs->lock);
60062 write_seqcount_begin(&fs->seq);
60063+ /* this root replacement is only done by pivot_root,
60064+ leave grsec's chroot tagging alone for this task
60065+ so that a pivoted root isn't treated as a chroot
60066+ */
60067 hits += replace_path(&fs->root, old_root, new_root);
60068 hits += replace_path(&fs->pwd, old_root, new_root);
60069 write_seqcount_end(&fs->seq);
60070@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
60071 task_lock(tsk);
60072 spin_lock(&fs->lock);
60073 tsk->fs = NULL;
60074- kill = !--fs->users;
60075+ gr_clear_chroot_entries(tsk);
60076+ kill = !atomic_dec_return(&fs->users);
60077 spin_unlock(&fs->lock);
60078 task_unlock(tsk);
60079 if (kill)
60080@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60081 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
60082 /* We don't need to lock fs - think why ;-) */
60083 if (fs) {
60084- fs->users = 1;
60085+ atomic_set(&fs->users, 1);
60086 fs->in_exec = 0;
60087 spin_lock_init(&fs->lock);
60088 seqcount_init(&fs->seq);
60089@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60090 spin_lock(&old->lock);
60091 fs->root = old->root;
60092 path_get(&fs->root);
60093+ /* instead of calling gr_set_chroot_entries here,
60094+ we call it from every caller of this function
60095+ */
60096 fs->pwd = old->pwd;
60097 path_get(&fs->pwd);
60098 spin_unlock(&old->lock);
60099@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
60100
60101 task_lock(current);
60102 spin_lock(&fs->lock);
60103- kill = !--fs->users;
60104+ kill = !atomic_dec_return(&fs->users);
60105 current->fs = new_fs;
60106+ gr_set_chroot_entries(current, &new_fs->root);
60107 spin_unlock(&fs->lock);
60108 task_unlock(current);
60109
60110@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
60111
60112 int current_umask(void)
60113 {
60114- return current->fs->umask;
60115+ return current->fs->umask | gr_acl_umask();
60116 }
60117 EXPORT_SYMBOL(current_umask);
60118
60119 /* to be mentioned only in INIT_TASK */
60120 struct fs_struct init_fs = {
60121- .users = 1,
60122+ .users = ATOMIC_INIT(1),
60123 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
60124 .seq = SEQCNT_ZERO(init_fs.seq),
60125 .umask = 0022,
60126diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
60127index 29d7feb..303644d 100644
60128--- a/fs/fscache/cookie.c
60129+++ b/fs/fscache/cookie.c
60130@@ -19,7 +19,7 @@
60131
60132 struct kmem_cache *fscache_cookie_jar;
60133
60134-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
60135+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
60136
60137 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
60138 static int fscache_alloc_object(struct fscache_cache *cache,
60139@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
60140 parent ? (char *) parent->def->name : "<no-parent>",
60141 def->name, netfs_data, enable);
60142
60143- fscache_stat(&fscache_n_acquires);
60144+ fscache_stat_unchecked(&fscache_n_acquires);
60145
60146 /* if there's no parent cookie, then we don't create one here either */
60147 if (!parent) {
60148- fscache_stat(&fscache_n_acquires_null);
60149+ fscache_stat_unchecked(&fscache_n_acquires_null);
60150 _leave(" [no parent]");
60151 return NULL;
60152 }
60153@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60154 /* allocate and initialise a cookie */
60155 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
60156 if (!cookie) {
60157- fscache_stat(&fscache_n_acquires_oom);
60158+ fscache_stat_unchecked(&fscache_n_acquires_oom);
60159 _leave(" [ENOMEM]");
60160 return NULL;
60161 }
60162@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
60163
60164 switch (cookie->def->type) {
60165 case FSCACHE_COOKIE_TYPE_INDEX:
60166- fscache_stat(&fscache_n_cookie_index);
60167+ fscache_stat_unchecked(&fscache_n_cookie_index);
60168 break;
60169 case FSCACHE_COOKIE_TYPE_DATAFILE:
60170- fscache_stat(&fscache_n_cookie_data);
60171+ fscache_stat_unchecked(&fscache_n_cookie_data);
60172 break;
60173 default:
60174- fscache_stat(&fscache_n_cookie_special);
60175+ fscache_stat_unchecked(&fscache_n_cookie_special);
60176 break;
60177 }
60178
60179@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60180 } else {
60181 atomic_dec(&parent->n_children);
60182 __fscache_cookie_put(cookie);
60183- fscache_stat(&fscache_n_acquires_nobufs);
60184+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
60185 _leave(" = NULL");
60186 return NULL;
60187 }
60188@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60189 }
60190 }
60191
60192- fscache_stat(&fscache_n_acquires_ok);
60193+ fscache_stat_unchecked(&fscache_n_acquires_ok);
60194 _leave(" = %p", cookie);
60195 return cookie;
60196 }
60197@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
60198 cache = fscache_select_cache_for_object(cookie->parent);
60199 if (!cache) {
60200 up_read(&fscache_addremove_sem);
60201- fscache_stat(&fscache_n_acquires_no_cache);
60202+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
60203 _leave(" = -ENOMEDIUM [no cache]");
60204 return -ENOMEDIUM;
60205 }
60206@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
60207 object = cache->ops->alloc_object(cache, cookie);
60208 fscache_stat_d(&fscache_n_cop_alloc_object);
60209 if (IS_ERR(object)) {
60210- fscache_stat(&fscache_n_object_no_alloc);
60211+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
60212 ret = PTR_ERR(object);
60213 goto error;
60214 }
60215
60216- fscache_stat(&fscache_n_object_alloc);
60217+ fscache_stat_unchecked(&fscache_n_object_alloc);
60218
60219- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
60220+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
60221
60222 _debug("ALLOC OBJ%x: %s {%lx}",
60223 object->debug_id, cookie->def->name, object->events);
60224@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
60225
60226 _enter("{%s}", cookie->def->name);
60227
60228- fscache_stat(&fscache_n_invalidates);
60229+ fscache_stat_unchecked(&fscache_n_invalidates);
60230
60231 /* Only permit invalidation of data files. Invalidating an index will
60232 * require the caller to release all its attachments to the tree rooted
60233@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
60234 {
60235 struct fscache_object *object;
60236
60237- fscache_stat(&fscache_n_updates);
60238+ fscache_stat_unchecked(&fscache_n_updates);
60239
60240 if (!cookie) {
60241- fscache_stat(&fscache_n_updates_null);
60242+ fscache_stat_unchecked(&fscache_n_updates_null);
60243 _leave(" [no cookie]");
60244 return;
60245 }
60246@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
60247 */
60248 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
60249 {
60250- fscache_stat(&fscache_n_relinquishes);
60251+ fscache_stat_unchecked(&fscache_n_relinquishes);
60252 if (retire)
60253- fscache_stat(&fscache_n_relinquishes_retire);
60254+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
60255
60256 if (!cookie) {
60257- fscache_stat(&fscache_n_relinquishes_null);
60258+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
60259 _leave(" [no cookie]");
60260 return;
60261 }
60262@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
60263 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
60264 goto inconsistent;
60265
60266- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60267+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60268
60269 __fscache_use_cookie(cookie);
60270 if (fscache_submit_op(object, op) < 0)
60271diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
60272index 4226f66..0fb3f45 100644
60273--- a/fs/fscache/internal.h
60274+++ b/fs/fscache/internal.h
60275@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
60276 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
60277 extern int fscache_wait_for_operation_activation(struct fscache_object *,
60278 struct fscache_operation *,
60279- atomic_t *,
60280- atomic_t *,
60281+ atomic_unchecked_t *,
60282+ atomic_unchecked_t *,
60283 void (*)(struct fscache_operation *));
60284 extern void fscache_invalidate_writes(struct fscache_cookie *);
60285
60286@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
60287 * stats.c
60288 */
60289 #ifdef CONFIG_FSCACHE_STATS
60290-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60291-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60292+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60293+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60294
60295-extern atomic_t fscache_n_op_pend;
60296-extern atomic_t fscache_n_op_run;
60297-extern atomic_t fscache_n_op_enqueue;
60298-extern atomic_t fscache_n_op_deferred_release;
60299-extern atomic_t fscache_n_op_release;
60300-extern atomic_t fscache_n_op_gc;
60301-extern atomic_t fscache_n_op_cancelled;
60302-extern atomic_t fscache_n_op_rejected;
60303+extern atomic_unchecked_t fscache_n_op_pend;
60304+extern atomic_unchecked_t fscache_n_op_run;
60305+extern atomic_unchecked_t fscache_n_op_enqueue;
60306+extern atomic_unchecked_t fscache_n_op_deferred_release;
60307+extern atomic_unchecked_t fscache_n_op_release;
60308+extern atomic_unchecked_t fscache_n_op_gc;
60309+extern atomic_unchecked_t fscache_n_op_cancelled;
60310+extern atomic_unchecked_t fscache_n_op_rejected;
60311
60312-extern atomic_t fscache_n_attr_changed;
60313-extern atomic_t fscache_n_attr_changed_ok;
60314-extern atomic_t fscache_n_attr_changed_nobufs;
60315-extern atomic_t fscache_n_attr_changed_nomem;
60316-extern atomic_t fscache_n_attr_changed_calls;
60317+extern atomic_unchecked_t fscache_n_attr_changed;
60318+extern atomic_unchecked_t fscache_n_attr_changed_ok;
60319+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
60320+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
60321+extern atomic_unchecked_t fscache_n_attr_changed_calls;
60322
60323-extern atomic_t fscache_n_allocs;
60324-extern atomic_t fscache_n_allocs_ok;
60325-extern atomic_t fscache_n_allocs_wait;
60326-extern atomic_t fscache_n_allocs_nobufs;
60327-extern atomic_t fscache_n_allocs_intr;
60328-extern atomic_t fscache_n_allocs_object_dead;
60329-extern atomic_t fscache_n_alloc_ops;
60330-extern atomic_t fscache_n_alloc_op_waits;
60331+extern atomic_unchecked_t fscache_n_allocs;
60332+extern atomic_unchecked_t fscache_n_allocs_ok;
60333+extern atomic_unchecked_t fscache_n_allocs_wait;
60334+extern atomic_unchecked_t fscache_n_allocs_nobufs;
60335+extern atomic_unchecked_t fscache_n_allocs_intr;
60336+extern atomic_unchecked_t fscache_n_allocs_object_dead;
60337+extern atomic_unchecked_t fscache_n_alloc_ops;
60338+extern atomic_unchecked_t fscache_n_alloc_op_waits;
60339
60340-extern atomic_t fscache_n_retrievals;
60341-extern atomic_t fscache_n_retrievals_ok;
60342-extern atomic_t fscache_n_retrievals_wait;
60343-extern atomic_t fscache_n_retrievals_nodata;
60344-extern atomic_t fscache_n_retrievals_nobufs;
60345-extern atomic_t fscache_n_retrievals_intr;
60346-extern atomic_t fscache_n_retrievals_nomem;
60347-extern atomic_t fscache_n_retrievals_object_dead;
60348-extern atomic_t fscache_n_retrieval_ops;
60349-extern atomic_t fscache_n_retrieval_op_waits;
60350+extern atomic_unchecked_t fscache_n_retrievals;
60351+extern atomic_unchecked_t fscache_n_retrievals_ok;
60352+extern atomic_unchecked_t fscache_n_retrievals_wait;
60353+extern atomic_unchecked_t fscache_n_retrievals_nodata;
60354+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
60355+extern atomic_unchecked_t fscache_n_retrievals_intr;
60356+extern atomic_unchecked_t fscache_n_retrievals_nomem;
60357+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
60358+extern atomic_unchecked_t fscache_n_retrieval_ops;
60359+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
60360
60361-extern atomic_t fscache_n_stores;
60362-extern atomic_t fscache_n_stores_ok;
60363-extern atomic_t fscache_n_stores_again;
60364-extern atomic_t fscache_n_stores_nobufs;
60365-extern atomic_t fscache_n_stores_oom;
60366-extern atomic_t fscache_n_store_ops;
60367-extern atomic_t fscache_n_store_calls;
60368-extern atomic_t fscache_n_store_pages;
60369-extern atomic_t fscache_n_store_radix_deletes;
60370-extern atomic_t fscache_n_store_pages_over_limit;
60371+extern atomic_unchecked_t fscache_n_stores;
60372+extern atomic_unchecked_t fscache_n_stores_ok;
60373+extern atomic_unchecked_t fscache_n_stores_again;
60374+extern atomic_unchecked_t fscache_n_stores_nobufs;
60375+extern atomic_unchecked_t fscache_n_stores_oom;
60376+extern atomic_unchecked_t fscache_n_store_ops;
60377+extern atomic_unchecked_t fscache_n_store_calls;
60378+extern atomic_unchecked_t fscache_n_store_pages;
60379+extern atomic_unchecked_t fscache_n_store_radix_deletes;
60380+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60381
60382-extern atomic_t fscache_n_store_vmscan_not_storing;
60383-extern atomic_t fscache_n_store_vmscan_gone;
60384-extern atomic_t fscache_n_store_vmscan_busy;
60385-extern atomic_t fscache_n_store_vmscan_cancelled;
60386-extern atomic_t fscache_n_store_vmscan_wait;
60387+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60388+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60389+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60390+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60391+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60392
60393-extern atomic_t fscache_n_marks;
60394-extern atomic_t fscache_n_uncaches;
60395+extern atomic_unchecked_t fscache_n_marks;
60396+extern atomic_unchecked_t fscache_n_uncaches;
60397
60398-extern atomic_t fscache_n_acquires;
60399-extern atomic_t fscache_n_acquires_null;
60400-extern atomic_t fscache_n_acquires_no_cache;
60401-extern atomic_t fscache_n_acquires_ok;
60402-extern atomic_t fscache_n_acquires_nobufs;
60403-extern atomic_t fscache_n_acquires_oom;
60404+extern atomic_unchecked_t fscache_n_acquires;
60405+extern atomic_unchecked_t fscache_n_acquires_null;
60406+extern atomic_unchecked_t fscache_n_acquires_no_cache;
60407+extern atomic_unchecked_t fscache_n_acquires_ok;
60408+extern atomic_unchecked_t fscache_n_acquires_nobufs;
60409+extern atomic_unchecked_t fscache_n_acquires_oom;
60410
60411-extern atomic_t fscache_n_invalidates;
60412-extern atomic_t fscache_n_invalidates_run;
60413+extern atomic_unchecked_t fscache_n_invalidates;
60414+extern atomic_unchecked_t fscache_n_invalidates_run;
60415
60416-extern atomic_t fscache_n_updates;
60417-extern atomic_t fscache_n_updates_null;
60418-extern atomic_t fscache_n_updates_run;
60419+extern atomic_unchecked_t fscache_n_updates;
60420+extern atomic_unchecked_t fscache_n_updates_null;
60421+extern atomic_unchecked_t fscache_n_updates_run;
60422
60423-extern atomic_t fscache_n_relinquishes;
60424-extern atomic_t fscache_n_relinquishes_null;
60425-extern atomic_t fscache_n_relinquishes_waitcrt;
60426-extern atomic_t fscache_n_relinquishes_retire;
60427+extern atomic_unchecked_t fscache_n_relinquishes;
60428+extern atomic_unchecked_t fscache_n_relinquishes_null;
60429+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60430+extern atomic_unchecked_t fscache_n_relinquishes_retire;
60431
60432-extern atomic_t fscache_n_cookie_index;
60433-extern atomic_t fscache_n_cookie_data;
60434-extern atomic_t fscache_n_cookie_special;
60435+extern atomic_unchecked_t fscache_n_cookie_index;
60436+extern atomic_unchecked_t fscache_n_cookie_data;
60437+extern atomic_unchecked_t fscache_n_cookie_special;
60438
60439-extern atomic_t fscache_n_object_alloc;
60440-extern atomic_t fscache_n_object_no_alloc;
60441-extern atomic_t fscache_n_object_lookups;
60442-extern atomic_t fscache_n_object_lookups_negative;
60443-extern atomic_t fscache_n_object_lookups_positive;
60444-extern atomic_t fscache_n_object_lookups_timed_out;
60445-extern atomic_t fscache_n_object_created;
60446-extern atomic_t fscache_n_object_avail;
60447-extern atomic_t fscache_n_object_dead;
60448+extern atomic_unchecked_t fscache_n_object_alloc;
60449+extern atomic_unchecked_t fscache_n_object_no_alloc;
60450+extern atomic_unchecked_t fscache_n_object_lookups;
60451+extern atomic_unchecked_t fscache_n_object_lookups_negative;
60452+extern atomic_unchecked_t fscache_n_object_lookups_positive;
60453+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60454+extern atomic_unchecked_t fscache_n_object_created;
60455+extern atomic_unchecked_t fscache_n_object_avail;
60456+extern atomic_unchecked_t fscache_n_object_dead;
60457
60458-extern atomic_t fscache_n_checkaux_none;
60459-extern atomic_t fscache_n_checkaux_okay;
60460-extern atomic_t fscache_n_checkaux_update;
60461-extern atomic_t fscache_n_checkaux_obsolete;
60462+extern atomic_unchecked_t fscache_n_checkaux_none;
60463+extern atomic_unchecked_t fscache_n_checkaux_okay;
60464+extern atomic_unchecked_t fscache_n_checkaux_update;
60465+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60466
60467 extern atomic_t fscache_n_cop_alloc_object;
60468 extern atomic_t fscache_n_cop_lookup_object;
60469@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60470 atomic_inc(stat);
60471 }
60472
60473+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60474+{
60475+ atomic_inc_unchecked(stat);
60476+}
60477+
60478 static inline void fscache_stat_d(atomic_t *stat)
60479 {
60480 atomic_dec(stat);
60481@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60482
60483 #define __fscache_stat(stat) (NULL)
60484 #define fscache_stat(stat) do {} while (0)
60485+#define fscache_stat_unchecked(stat) do {} while (0)
60486 #define fscache_stat_d(stat) do {} while (0)
60487 #endif
60488
60489diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60490index d3b4539..ed0c659 100644
60491--- a/fs/fscache/object.c
60492+++ b/fs/fscache/object.c
60493@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60494 _debug("LOOKUP \"%s\" in \"%s\"",
60495 cookie->def->name, object->cache->tag->name);
60496
60497- fscache_stat(&fscache_n_object_lookups);
60498+ fscache_stat_unchecked(&fscache_n_object_lookups);
60499 fscache_stat(&fscache_n_cop_lookup_object);
60500 ret = object->cache->ops->lookup_object(object);
60501 fscache_stat_d(&fscache_n_cop_lookup_object);
60502@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60503 if (ret == -ETIMEDOUT) {
60504 /* probably stuck behind another object, so move this one to
60505 * the back of the queue */
60506- fscache_stat(&fscache_n_object_lookups_timed_out);
60507+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60508 _leave(" [timeout]");
60509 return NO_TRANSIT;
60510 }
60511@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60512 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60513
60514 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60515- fscache_stat(&fscache_n_object_lookups_negative);
60516+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60517
60518 /* Allow write requests to begin stacking up and read requests to begin
60519 * returning ENODATA.
60520@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60521 /* if we were still looking up, then we must have a positive lookup
60522 * result, in which case there may be data available */
60523 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60524- fscache_stat(&fscache_n_object_lookups_positive);
60525+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60526
60527 /* We do (presumably) have data */
60528 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60529@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60530 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60531 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60532 } else {
60533- fscache_stat(&fscache_n_object_created);
60534+ fscache_stat_unchecked(&fscache_n_object_created);
60535 }
60536
60537 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60538@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60539 fscache_stat_d(&fscache_n_cop_lookup_complete);
60540
60541 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60542- fscache_stat(&fscache_n_object_avail);
60543+ fscache_stat_unchecked(&fscache_n_object_avail);
60544
60545 _leave("");
60546 return transit_to(JUMPSTART_DEPS);
60547@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60548
60549 /* this just shifts the object release to the work processor */
60550 fscache_put_object(object);
60551- fscache_stat(&fscache_n_object_dead);
60552+ fscache_stat_unchecked(&fscache_n_object_dead);
60553
60554 _leave("");
60555 return transit_to(OBJECT_DEAD);
60556@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60557 enum fscache_checkaux result;
60558
60559 if (!object->cookie->def->check_aux) {
60560- fscache_stat(&fscache_n_checkaux_none);
60561+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60562 return FSCACHE_CHECKAUX_OKAY;
60563 }
60564
60565@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60566 switch (result) {
60567 /* entry okay as is */
60568 case FSCACHE_CHECKAUX_OKAY:
60569- fscache_stat(&fscache_n_checkaux_okay);
60570+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60571 break;
60572
60573 /* entry requires update */
60574 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60575- fscache_stat(&fscache_n_checkaux_update);
60576+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60577 break;
60578
60579 /* entry requires deletion */
60580 case FSCACHE_CHECKAUX_OBSOLETE:
60581- fscache_stat(&fscache_n_checkaux_obsolete);
60582+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60583 break;
60584
60585 default:
60586@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60587 {
60588 const struct fscache_state *s;
60589
60590- fscache_stat(&fscache_n_invalidates_run);
60591+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60592 fscache_stat(&fscache_n_cop_invalidate_object);
60593 s = _fscache_invalidate_object(object, event);
60594 fscache_stat_d(&fscache_n_cop_invalidate_object);
60595@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60596 {
60597 _enter("{OBJ%x},%d", object->debug_id, event);
60598
60599- fscache_stat(&fscache_n_updates_run);
60600+ fscache_stat_unchecked(&fscache_n_updates_run);
60601 fscache_stat(&fscache_n_cop_update_object);
60602 object->cache->ops->update_object(object);
60603 fscache_stat_d(&fscache_n_cop_update_object);
60604diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60605index 318071a..379938b 100644
60606--- a/fs/fscache/operation.c
60607+++ b/fs/fscache/operation.c
60608@@ -17,7 +17,7 @@
60609 #include <linux/slab.h>
60610 #include "internal.h"
60611
60612-atomic_t fscache_op_debug_id;
60613+atomic_unchecked_t fscache_op_debug_id;
60614 EXPORT_SYMBOL(fscache_op_debug_id);
60615
60616 /**
60617@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60618 ASSERTCMP(atomic_read(&op->usage), >, 0);
60619 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60620
60621- fscache_stat(&fscache_n_op_enqueue);
60622+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60623 switch (op->flags & FSCACHE_OP_TYPE) {
60624 case FSCACHE_OP_ASYNC:
60625 _debug("queue async");
60626@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60627 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60628 if (op->processor)
60629 fscache_enqueue_operation(op);
60630- fscache_stat(&fscache_n_op_run);
60631+ fscache_stat_unchecked(&fscache_n_op_run);
60632 }
60633
60634 /*
60635@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60636 if (object->n_in_progress > 0) {
60637 atomic_inc(&op->usage);
60638 list_add_tail(&op->pend_link, &object->pending_ops);
60639- fscache_stat(&fscache_n_op_pend);
60640+ fscache_stat_unchecked(&fscache_n_op_pend);
60641 } else if (!list_empty(&object->pending_ops)) {
60642 atomic_inc(&op->usage);
60643 list_add_tail(&op->pend_link, &object->pending_ops);
60644- fscache_stat(&fscache_n_op_pend);
60645+ fscache_stat_unchecked(&fscache_n_op_pend);
60646 fscache_start_operations(object);
60647 } else {
60648 ASSERTCMP(object->n_in_progress, ==, 0);
60649@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60650 object->n_exclusive++; /* reads and writes must wait */
60651 atomic_inc(&op->usage);
60652 list_add_tail(&op->pend_link, &object->pending_ops);
60653- fscache_stat(&fscache_n_op_pend);
60654+ fscache_stat_unchecked(&fscache_n_op_pend);
60655 ret = 0;
60656 } else {
60657 /* If we're in any other state, there must have been an I/O
60658@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60659 if (object->n_exclusive > 0) {
60660 atomic_inc(&op->usage);
60661 list_add_tail(&op->pend_link, &object->pending_ops);
60662- fscache_stat(&fscache_n_op_pend);
60663+ fscache_stat_unchecked(&fscache_n_op_pend);
60664 } else if (!list_empty(&object->pending_ops)) {
60665 atomic_inc(&op->usage);
60666 list_add_tail(&op->pend_link, &object->pending_ops);
60667- fscache_stat(&fscache_n_op_pend);
60668+ fscache_stat_unchecked(&fscache_n_op_pend);
60669 fscache_start_operations(object);
60670 } else {
60671 ASSERTCMP(object->n_exclusive, ==, 0);
60672@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60673 object->n_ops++;
60674 atomic_inc(&op->usage);
60675 list_add_tail(&op->pend_link, &object->pending_ops);
60676- fscache_stat(&fscache_n_op_pend);
60677+ fscache_stat_unchecked(&fscache_n_op_pend);
60678 ret = 0;
60679 } else if (fscache_object_is_dying(object)) {
60680- fscache_stat(&fscache_n_op_rejected);
60681+ fscache_stat_unchecked(&fscache_n_op_rejected);
60682 op->state = FSCACHE_OP_ST_CANCELLED;
60683 ret = -ENOBUFS;
60684 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60685@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60686 ret = -EBUSY;
60687 if (op->state == FSCACHE_OP_ST_PENDING) {
60688 ASSERT(!list_empty(&op->pend_link));
60689- fscache_stat(&fscache_n_op_cancelled);
60690+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60691 list_del_init(&op->pend_link);
60692 if (do_cancel)
60693 do_cancel(op);
60694@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60695 while (!list_empty(&object->pending_ops)) {
60696 op = list_entry(object->pending_ops.next,
60697 struct fscache_operation, pend_link);
60698- fscache_stat(&fscache_n_op_cancelled);
60699+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60700 list_del_init(&op->pend_link);
60701
60702 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60703@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60704 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60705 op->state = FSCACHE_OP_ST_DEAD;
60706
60707- fscache_stat(&fscache_n_op_release);
60708+ fscache_stat_unchecked(&fscache_n_op_release);
60709
60710 if (op->release) {
60711 op->release(op);
60712@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60713 * lock, and defer it otherwise */
60714 if (!spin_trylock(&object->lock)) {
60715 _debug("defer put");
60716- fscache_stat(&fscache_n_op_deferred_release);
60717+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60718
60719 cache = object->cache;
60720 spin_lock(&cache->op_gc_list_lock);
60721@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60722
60723 _debug("GC DEFERRED REL OBJ%x OP%x",
60724 object->debug_id, op->debug_id);
60725- fscache_stat(&fscache_n_op_gc);
60726+ fscache_stat_unchecked(&fscache_n_op_gc);
60727
60728 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60729 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60730diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60731index 7f5c658..6c1e164 100644
60732--- a/fs/fscache/page.c
60733+++ b/fs/fscache/page.c
60734@@ -61,7 +61,7 @@ try_again:
60735 val = radix_tree_lookup(&cookie->stores, page->index);
60736 if (!val) {
60737 rcu_read_unlock();
60738- fscache_stat(&fscache_n_store_vmscan_not_storing);
60739+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60740 __fscache_uncache_page(cookie, page);
60741 return true;
60742 }
60743@@ -91,11 +91,11 @@ try_again:
60744 spin_unlock(&cookie->stores_lock);
60745
60746 if (xpage) {
60747- fscache_stat(&fscache_n_store_vmscan_cancelled);
60748- fscache_stat(&fscache_n_store_radix_deletes);
60749+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60750+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60751 ASSERTCMP(xpage, ==, page);
60752 } else {
60753- fscache_stat(&fscache_n_store_vmscan_gone);
60754+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60755 }
60756
60757 wake_up_bit(&cookie->flags, 0);
60758@@ -110,11 +110,11 @@ page_busy:
60759 * sleeping on memory allocation, so we may need to impose a timeout
60760 * too. */
60761 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60762- fscache_stat(&fscache_n_store_vmscan_busy);
60763+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60764 return false;
60765 }
60766
60767- fscache_stat(&fscache_n_store_vmscan_wait);
60768+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60769 __fscache_wait_on_page_write(cookie, page);
60770 gfp &= ~__GFP_WAIT;
60771 goto try_again;
60772@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60773 FSCACHE_COOKIE_STORING_TAG);
60774 if (!radix_tree_tag_get(&cookie->stores, page->index,
60775 FSCACHE_COOKIE_PENDING_TAG)) {
60776- fscache_stat(&fscache_n_store_radix_deletes);
60777+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60778 xpage = radix_tree_delete(&cookie->stores, page->index);
60779 }
60780 spin_unlock(&cookie->stores_lock);
60781@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60782
60783 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60784
60785- fscache_stat(&fscache_n_attr_changed_calls);
60786+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60787
60788 if (fscache_object_is_active(object)) {
60789 fscache_stat(&fscache_n_cop_attr_changed);
60790@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60791
60792 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60793
60794- fscache_stat(&fscache_n_attr_changed);
60795+ fscache_stat_unchecked(&fscache_n_attr_changed);
60796
60797 op = kzalloc(sizeof(*op), GFP_KERNEL);
60798 if (!op) {
60799- fscache_stat(&fscache_n_attr_changed_nomem);
60800+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60801 _leave(" = -ENOMEM");
60802 return -ENOMEM;
60803 }
60804@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60805 if (fscache_submit_exclusive_op(object, op) < 0)
60806 goto nobufs;
60807 spin_unlock(&cookie->lock);
60808- fscache_stat(&fscache_n_attr_changed_ok);
60809+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60810 fscache_put_operation(op);
60811 _leave(" = 0");
60812 return 0;
60813@@ -225,7 +225,7 @@ nobufs:
60814 kfree(op);
60815 if (wake_cookie)
60816 __fscache_wake_unused_cookie(cookie);
60817- fscache_stat(&fscache_n_attr_changed_nobufs);
60818+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60819 _leave(" = %d", -ENOBUFS);
60820 return -ENOBUFS;
60821 }
60822@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60823 /* allocate a retrieval operation and attempt to submit it */
60824 op = kzalloc(sizeof(*op), GFP_NOIO);
60825 if (!op) {
60826- fscache_stat(&fscache_n_retrievals_nomem);
60827+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60828 return NULL;
60829 }
60830
60831@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60832 return 0;
60833 }
60834
60835- fscache_stat(&fscache_n_retrievals_wait);
60836+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60837
60838 jif = jiffies;
60839 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60840 fscache_wait_bit_interruptible,
60841 TASK_INTERRUPTIBLE) != 0) {
60842- fscache_stat(&fscache_n_retrievals_intr);
60843+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60844 _leave(" = -ERESTARTSYS");
60845 return -ERESTARTSYS;
60846 }
60847@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60848 */
60849 int fscache_wait_for_operation_activation(struct fscache_object *object,
60850 struct fscache_operation *op,
60851- atomic_t *stat_op_waits,
60852- atomic_t *stat_object_dead,
60853+ atomic_unchecked_t *stat_op_waits,
60854+ atomic_unchecked_t *stat_object_dead,
60855 void (*do_cancel)(struct fscache_operation *))
60856 {
60857 int ret;
60858@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60859
60860 _debug(">>> WT");
60861 if (stat_op_waits)
60862- fscache_stat(stat_op_waits);
60863+ fscache_stat_unchecked(stat_op_waits);
60864 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60865 fscache_wait_bit_interruptible,
60866 TASK_INTERRUPTIBLE) != 0) {
60867@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60868 check_if_dead:
60869 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60870 if (stat_object_dead)
60871- fscache_stat(stat_object_dead);
60872+ fscache_stat_unchecked(stat_object_dead);
60873 _leave(" = -ENOBUFS [cancelled]");
60874 return -ENOBUFS;
60875 }
60876@@ -366,7 +366,7 @@ check_if_dead:
60877 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60878 fscache_cancel_op(op, do_cancel);
60879 if (stat_object_dead)
60880- fscache_stat(stat_object_dead);
60881+ fscache_stat_unchecked(stat_object_dead);
60882 return -ENOBUFS;
60883 }
60884 return 0;
60885@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60886
60887 _enter("%p,%p,,,", cookie, page);
60888
60889- fscache_stat(&fscache_n_retrievals);
60890+ fscache_stat_unchecked(&fscache_n_retrievals);
60891
60892 if (hlist_empty(&cookie->backing_objects))
60893 goto nobufs;
60894@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60895 goto nobufs_unlock_dec;
60896 spin_unlock(&cookie->lock);
60897
60898- fscache_stat(&fscache_n_retrieval_ops);
60899+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60900
60901 /* pin the netfs read context in case we need to do the actual netfs
60902 * read because we've encountered a cache read failure */
60903@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60904
60905 error:
60906 if (ret == -ENOMEM)
60907- fscache_stat(&fscache_n_retrievals_nomem);
60908+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60909 else if (ret == -ERESTARTSYS)
60910- fscache_stat(&fscache_n_retrievals_intr);
60911+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60912 else if (ret == -ENODATA)
60913- fscache_stat(&fscache_n_retrievals_nodata);
60914+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60915 else if (ret < 0)
60916- fscache_stat(&fscache_n_retrievals_nobufs);
60917+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60918 else
60919- fscache_stat(&fscache_n_retrievals_ok);
60920+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60921
60922 fscache_put_retrieval(op);
60923 _leave(" = %d", ret);
60924@@ -490,7 +490,7 @@ nobufs_unlock:
60925 __fscache_wake_unused_cookie(cookie);
60926 kfree(op);
60927 nobufs:
60928- fscache_stat(&fscache_n_retrievals_nobufs);
60929+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60930 _leave(" = -ENOBUFS");
60931 return -ENOBUFS;
60932 }
60933@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60934
60935 _enter("%p,,%d,,,", cookie, *nr_pages);
60936
60937- fscache_stat(&fscache_n_retrievals);
60938+ fscache_stat_unchecked(&fscache_n_retrievals);
60939
60940 if (hlist_empty(&cookie->backing_objects))
60941 goto nobufs;
60942@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60943 goto nobufs_unlock_dec;
60944 spin_unlock(&cookie->lock);
60945
60946- fscache_stat(&fscache_n_retrieval_ops);
60947+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60948
60949 /* pin the netfs read context in case we need to do the actual netfs
60950 * read because we've encountered a cache read failure */
60951@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60952
60953 error:
60954 if (ret == -ENOMEM)
60955- fscache_stat(&fscache_n_retrievals_nomem);
60956+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60957 else if (ret == -ERESTARTSYS)
60958- fscache_stat(&fscache_n_retrievals_intr);
60959+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60960 else if (ret == -ENODATA)
60961- fscache_stat(&fscache_n_retrievals_nodata);
60962+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60963 else if (ret < 0)
60964- fscache_stat(&fscache_n_retrievals_nobufs);
60965+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60966 else
60967- fscache_stat(&fscache_n_retrievals_ok);
60968+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60969
60970 fscache_put_retrieval(op);
60971 _leave(" = %d", ret);
60972@@ -621,7 +621,7 @@ nobufs_unlock:
60973 if (wake_cookie)
60974 __fscache_wake_unused_cookie(cookie);
60975 nobufs:
60976- fscache_stat(&fscache_n_retrievals_nobufs);
60977+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60978 _leave(" = -ENOBUFS");
60979 return -ENOBUFS;
60980 }
60981@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60982
60983 _enter("%p,%p,,,", cookie, page);
60984
60985- fscache_stat(&fscache_n_allocs);
60986+ fscache_stat_unchecked(&fscache_n_allocs);
60987
60988 if (hlist_empty(&cookie->backing_objects))
60989 goto nobufs;
60990@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60991 goto nobufs_unlock_dec;
60992 spin_unlock(&cookie->lock);
60993
60994- fscache_stat(&fscache_n_alloc_ops);
60995+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60996
60997 ret = fscache_wait_for_operation_activation(
60998 object, &op->op,
60999@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
61000
61001 error:
61002 if (ret == -ERESTARTSYS)
61003- fscache_stat(&fscache_n_allocs_intr);
61004+ fscache_stat_unchecked(&fscache_n_allocs_intr);
61005 else if (ret < 0)
61006- fscache_stat(&fscache_n_allocs_nobufs);
61007+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61008 else
61009- fscache_stat(&fscache_n_allocs_ok);
61010+ fscache_stat_unchecked(&fscache_n_allocs_ok);
61011
61012 fscache_put_retrieval(op);
61013 _leave(" = %d", ret);
61014@@ -715,7 +715,7 @@ nobufs_unlock:
61015 if (wake_cookie)
61016 __fscache_wake_unused_cookie(cookie);
61017 nobufs:
61018- fscache_stat(&fscache_n_allocs_nobufs);
61019+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61020 _leave(" = -ENOBUFS");
61021 return -ENOBUFS;
61022 }
61023@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61024
61025 spin_lock(&cookie->stores_lock);
61026
61027- fscache_stat(&fscache_n_store_calls);
61028+ fscache_stat_unchecked(&fscache_n_store_calls);
61029
61030 /* find a page to store */
61031 page = NULL;
61032@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61033 page = results[0];
61034 _debug("gang %d [%lx]", n, page->index);
61035 if (page->index > op->store_limit) {
61036- fscache_stat(&fscache_n_store_pages_over_limit);
61037+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
61038 goto superseded;
61039 }
61040
61041@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61042 spin_unlock(&cookie->stores_lock);
61043 spin_unlock(&object->lock);
61044
61045- fscache_stat(&fscache_n_store_pages);
61046+ fscache_stat_unchecked(&fscache_n_store_pages);
61047 fscache_stat(&fscache_n_cop_write_page);
61048 ret = object->cache->ops->write_page(op, page);
61049 fscache_stat_d(&fscache_n_cop_write_page);
61050@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61051 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61052 ASSERT(PageFsCache(page));
61053
61054- fscache_stat(&fscache_n_stores);
61055+ fscache_stat_unchecked(&fscache_n_stores);
61056
61057 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
61058 _leave(" = -ENOBUFS [invalidating]");
61059@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61060 spin_unlock(&cookie->stores_lock);
61061 spin_unlock(&object->lock);
61062
61063- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
61064+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61065 op->store_limit = object->store_limit;
61066
61067 __fscache_use_cookie(cookie);
61068@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61069
61070 spin_unlock(&cookie->lock);
61071 radix_tree_preload_end();
61072- fscache_stat(&fscache_n_store_ops);
61073- fscache_stat(&fscache_n_stores_ok);
61074+ fscache_stat_unchecked(&fscache_n_store_ops);
61075+ fscache_stat_unchecked(&fscache_n_stores_ok);
61076
61077 /* the work queue now carries its own ref on the object */
61078 fscache_put_operation(&op->op);
61079@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61080 return 0;
61081
61082 already_queued:
61083- fscache_stat(&fscache_n_stores_again);
61084+ fscache_stat_unchecked(&fscache_n_stores_again);
61085 already_pending:
61086 spin_unlock(&cookie->stores_lock);
61087 spin_unlock(&object->lock);
61088 spin_unlock(&cookie->lock);
61089 radix_tree_preload_end();
61090 kfree(op);
61091- fscache_stat(&fscache_n_stores_ok);
61092+ fscache_stat_unchecked(&fscache_n_stores_ok);
61093 _leave(" = 0");
61094 return 0;
61095
61096@@ -1024,14 +1024,14 @@ nobufs:
61097 kfree(op);
61098 if (wake_cookie)
61099 __fscache_wake_unused_cookie(cookie);
61100- fscache_stat(&fscache_n_stores_nobufs);
61101+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
61102 _leave(" = -ENOBUFS");
61103 return -ENOBUFS;
61104
61105 nomem_free:
61106 kfree(op);
61107 nomem:
61108- fscache_stat(&fscache_n_stores_oom);
61109+ fscache_stat_unchecked(&fscache_n_stores_oom);
61110 _leave(" = -ENOMEM");
61111 return -ENOMEM;
61112 }
61113@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
61114 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61115 ASSERTCMP(page, !=, NULL);
61116
61117- fscache_stat(&fscache_n_uncaches);
61118+ fscache_stat_unchecked(&fscache_n_uncaches);
61119
61120 /* cache withdrawal may beat us to it */
61121 if (!PageFsCache(page))
61122@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
61123 struct fscache_cookie *cookie = op->op.object->cookie;
61124
61125 #ifdef CONFIG_FSCACHE_STATS
61126- atomic_inc(&fscache_n_marks);
61127+ atomic_inc_unchecked(&fscache_n_marks);
61128 #endif
61129
61130 _debug("- mark %p{%lx}", page, page->index);
61131diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
61132index 40d13c7..ddf52b9 100644
61133--- a/fs/fscache/stats.c
61134+++ b/fs/fscache/stats.c
61135@@ -18,99 +18,99 @@
61136 /*
61137 * operation counters
61138 */
61139-atomic_t fscache_n_op_pend;
61140-atomic_t fscache_n_op_run;
61141-atomic_t fscache_n_op_enqueue;
61142-atomic_t fscache_n_op_requeue;
61143-atomic_t fscache_n_op_deferred_release;
61144-atomic_t fscache_n_op_release;
61145-atomic_t fscache_n_op_gc;
61146-atomic_t fscache_n_op_cancelled;
61147-atomic_t fscache_n_op_rejected;
61148+atomic_unchecked_t fscache_n_op_pend;
61149+atomic_unchecked_t fscache_n_op_run;
61150+atomic_unchecked_t fscache_n_op_enqueue;
61151+atomic_unchecked_t fscache_n_op_requeue;
61152+atomic_unchecked_t fscache_n_op_deferred_release;
61153+atomic_unchecked_t fscache_n_op_release;
61154+atomic_unchecked_t fscache_n_op_gc;
61155+atomic_unchecked_t fscache_n_op_cancelled;
61156+atomic_unchecked_t fscache_n_op_rejected;
61157
61158-atomic_t fscache_n_attr_changed;
61159-atomic_t fscache_n_attr_changed_ok;
61160-atomic_t fscache_n_attr_changed_nobufs;
61161-atomic_t fscache_n_attr_changed_nomem;
61162-atomic_t fscache_n_attr_changed_calls;
61163+atomic_unchecked_t fscache_n_attr_changed;
61164+atomic_unchecked_t fscache_n_attr_changed_ok;
61165+atomic_unchecked_t fscache_n_attr_changed_nobufs;
61166+atomic_unchecked_t fscache_n_attr_changed_nomem;
61167+atomic_unchecked_t fscache_n_attr_changed_calls;
61168
61169-atomic_t fscache_n_allocs;
61170-atomic_t fscache_n_allocs_ok;
61171-atomic_t fscache_n_allocs_wait;
61172-atomic_t fscache_n_allocs_nobufs;
61173-atomic_t fscache_n_allocs_intr;
61174-atomic_t fscache_n_allocs_object_dead;
61175-atomic_t fscache_n_alloc_ops;
61176-atomic_t fscache_n_alloc_op_waits;
61177+atomic_unchecked_t fscache_n_allocs;
61178+atomic_unchecked_t fscache_n_allocs_ok;
61179+atomic_unchecked_t fscache_n_allocs_wait;
61180+atomic_unchecked_t fscache_n_allocs_nobufs;
61181+atomic_unchecked_t fscache_n_allocs_intr;
61182+atomic_unchecked_t fscache_n_allocs_object_dead;
61183+atomic_unchecked_t fscache_n_alloc_ops;
61184+atomic_unchecked_t fscache_n_alloc_op_waits;
61185
61186-atomic_t fscache_n_retrievals;
61187-atomic_t fscache_n_retrievals_ok;
61188-atomic_t fscache_n_retrievals_wait;
61189-atomic_t fscache_n_retrievals_nodata;
61190-atomic_t fscache_n_retrievals_nobufs;
61191-atomic_t fscache_n_retrievals_intr;
61192-atomic_t fscache_n_retrievals_nomem;
61193-atomic_t fscache_n_retrievals_object_dead;
61194-atomic_t fscache_n_retrieval_ops;
61195-atomic_t fscache_n_retrieval_op_waits;
61196+atomic_unchecked_t fscache_n_retrievals;
61197+atomic_unchecked_t fscache_n_retrievals_ok;
61198+atomic_unchecked_t fscache_n_retrievals_wait;
61199+atomic_unchecked_t fscache_n_retrievals_nodata;
61200+atomic_unchecked_t fscache_n_retrievals_nobufs;
61201+atomic_unchecked_t fscache_n_retrievals_intr;
61202+atomic_unchecked_t fscache_n_retrievals_nomem;
61203+atomic_unchecked_t fscache_n_retrievals_object_dead;
61204+atomic_unchecked_t fscache_n_retrieval_ops;
61205+atomic_unchecked_t fscache_n_retrieval_op_waits;
61206
61207-atomic_t fscache_n_stores;
61208-atomic_t fscache_n_stores_ok;
61209-atomic_t fscache_n_stores_again;
61210-atomic_t fscache_n_stores_nobufs;
61211-atomic_t fscache_n_stores_oom;
61212-atomic_t fscache_n_store_ops;
61213-atomic_t fscache_n_store_calls;
61214-atomic_t fscache_n_store_pages;
61215-atomic_t fscache_n_store_radix_deletes;
61216-atomic_t fscache_n_store_pages_over_limit;
61217+atomic_unchecked_t fscache_n_stores;
61218+atomic_unchecked_t fscache_n_stores_ok;
61219+atomic_unchecked_t fscache_n_stores_again;
61220+atomic_unchecked_t fscache_n_stores_nobufs;
61221+atomic_unchecked_t fscache_n_stores_oom;
61222+atomic_unchecked_t fscache_n_store_ops;
61223+atomic_unchecked_t fscache_n_store_calls;
61224+atomic_unchecked_t fscache_n_store_pages;
61225+atomic_unchecked_t fscache_n_store_radix_deletes;
61226+atomic_unchecked_t fscache_n_store_pages_over_limit;
61227
61228-atomic_t fscache_n_store_vmscan_not_storing;
61229-atomic_t fscache_n_store_vmscan_gone;
61230-atomic_t fscache_n_store_vmscan_busy;
61231-atomic_t fscache_n_store_vmscan_cancelled;
61232-atomic_t fscache_n_store_vmscan_wait;
61233+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
61234+atomic_unchecked_t fscache_n_store_vmscan_gone;
61235+atomic_unchecked_t fscache_n_store_vmscan_busy;
61236+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
61237+atomic_unchecked_t fscache_n_store_vmscan_wait;
61238
61239-atomic_t fscache_n_marks;
61240-atomic_t fscache_n_uncaches;
61241+atomic_unchecked_t fscache_n_marks;
61242+atomic_unchecked_t fscache_n_uncaches;
61243
61244-atomic_t fscache_n_acquires;
61245-atomic_t fscache_n_acquires_null;
61246-atomic_t fscache_n_acquires_no_cache;
61247-atomic_t fscache_n_acquires_ok;
61248-atomic_t fscache_n_acquires_nobufs;
61249-atomic_t fscache_n_acquires_oom;
61250+atomic_unchecked_t fscache_n_acquires;
61251+atomic_unchecked_t fscache_n_acquires_null;
61252+atomic_unchecked_t fscache_n_acquires_no_cache;
61253+atomic_unchecked_t fscache_n_acquires_ok;
61254+atomic_unchecked_t fscache_n_acquires_nobufs;
61255+atomic_unchecked_t fscache_n_acquires_oom;
61256
61257-atomic_t fscache_n_invalidates;
61258-atomic_t fscache_n_invalidates_run;
61259+atomic_unchecked_t fscache_n_invalidates;
61260+atomic_unchecked_t fscache_n_invalidates_run;
61261
61262-atomic_t fscache_n_updates;
61263-atomic_t fscache_n_updates_null;
61264-atomic_t fscache_n_updates_run;
61265+atomic_unchecked_t fscache_n_updates;
61266+atomic_unchecked_t fscache_n_updates_null;
61267+atomic_unchecked_t fscache_n_updates_run;
61268
61269-atomic_t fscache_n_relinquishes;
61270-atomic_t fscache_n_relinquishes_null;
61271-atomic_t fscache_n_relinquishes_waitcrt;
61272-atomic_t fscache_n_relinquishes_retire;
61273+atomic_unchecked_t fscache_n_relinquishes;
61274+atomic_unchecked_t fscache_n_relinquishes_null;
61275+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
61276+atomic_unchecked_t fscache_n_relinquishes_retire;
61277
61278-atomic_t fscache_n_cookie_index;
61279-atomic_t fscache_n_cookie_data;
61280-atomic_t fscache_n_cookie_special;
61281+atomic_unchecked_t fscache_n_cookie_index;
61282+atomic_unchecked_t fscache_n_cookie_data;
61283+atomic_unchecked_t fscache_n_cookie_special;
61284
61285-atomic_t fscache_n_object_alloc;
61286-atomic_t fscache_n_object_no_alloc;
61287-atomic_t fscache_n_object_lookups;
61288-atomic_t fscache_n_object_lookups_negative;
61289-atomic_t fscache_n_object_lookups_positive;
61290-atomic_t fscache_n_object_lookups_timed_out;
61291-atomic_t fscache_n_object_created;
61292-atomic_t fscache_n_object_avail;
61293-atomic_t fscache_n_object_dead;
61294+atomic_unchecked_t fscache_n_object_alloc;
61295+atomic_unchecked_t fscache_n_object_no_alloc;
61296+atomic_unchecked_t fscache_n_object_lookups;
61297+atomic_unchecked_t fscache_n_object_lookups_negative;
61298+atomic_unchecked_t fscache_n_object_lookups_positive;
61299+atomic_unchecked_t fscache_n_object_lookups_timed_out;
61300+atomic_unchecked_t fscache_n_object_created;
61301+atomic_unchecked_t fscache_n_object_avail;
61302+atomic_unchecked_t fscache_n_object_dead;
61303
61304-atomic_t fscache_n_checkaux_none;
61305-atomic_t fscache_n_checkaux_okay;
61306-atomic_t fscache_n_checkaux_update;
61307-atomic_t fscache_n_checkaux_obsolete;
61308+atomic_unchecked_t fscache_n_checkaux_none;
61309+atomic_unchecked_t fscache_n_checkaux_okay;
61310+atomic_unchecked_t fscache_n_checkaux_update;
61311+atomic_unchecked_t fscache_n_checkaux_obsolete;
61312
61313 atomic_t fscache_n_cop_alloc_object;
61314 atomic_t fscache_n_cop_lookup_object;
61315@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
61316 seq_puts(m, "FS-Cache statistics\n");
61317
61318 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
61319- atomic_read(&fscache_n_cookie_index),
61320- atomic_read(&fscache_n_cookie_data),
61321- atomic_read(&fscache_n_cookie_special));
61322+ atomic_read_unchecked(&fscache_n_cookie_index),
61323+ atomic_read_unchecked(&fscache_n_cookie_data),
61324+ atomic_read_unchecked(&fscache_n_cookie_special));
61325
61326 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
61327- atomic_read(&fscache_n_object_alloc),
61328- atomic_read(&fscache_n_object_no_alloc),
61329- atomic_read(&fscache_n_object_avail),
61330- atomic_read(&fscache_n_object_dead));
61331+ atomic_read_unchecked(&fscache_n_object_alloc),
61332+ atomic_read_unchecked(&fscache_n_object_no_alloc),
61333+ atomic_read_unchecked(&fscache_n_object_avail),
61334+ atomic_read_unchecked(&fscache_n_object_dead));
61335 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
61336- atomic_read(&fscache_n_checkaux_none),
61337- atomic_read(&fscache_n_checkaux_okay),
61338- atomic_read(&fscache_n_checkaux_update),
61339- atomic_read(&fscache_n_checkaux_obsolete));
61340+ atomic_read_unchecked(&fscache_n_checkaux_none),
61341+ atomic_read_unchecked(&fscache_n_checkaux_okay),
61342+ atomic_read_unchecked(&fscache_n_checkaux_update),
61343+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
61344
61345 seq_printf(m, "Pages : mrk=%u unc=%u\n",
61346- atomic_read(&fscache_n_marks),
61347- atomic_read(&fscache_n_uncaches));
61348+ atomic_read_unchecked(&fscache_n_marks),
61349+ atomic_read_unchecked(&fscache_n_uncaches));
61350
61351 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
61352 " oom=%u\n",
61353- atomic_read(&fscache_n_acquires),
61354- atomic_read(&fscache_n_acquires_null),
61355- atomic_read(&fscache_n_acquires_no_cache),
61356- atomic_read(&fscache_n_acquires_ok),
61357- atomic_read(&fscache_n_acquires_nobufs),
61358- atomic_read(&fscache_n_acquires_oom));
61359+ atomic_read_unchecked(&fscache_n_acquires),
61360+ atomic_read_unchecked(&fscache_n_acquires_null),
61361+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
61362+ atomic_read_unchecked(&fscache_n_acquires_ok),
61363+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
61364+ atomic_read_unchecked(&fscache_n_acquires_oom));
61365
61366 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
61367- atomic_read(&fscache_n_object_lookups),
61368- atomic_read(&fscache_n_object_lookups_negative),
61369- atomic_read(&fscache_n_object_lookups_positive),
61370- atomic_read(&fscache_n_object_created),
61371- atomic_read(&fscache_n_object_lookups_timed_out));
61372+ atomic_read_unchecked(&fscache_n_object_lookups),
61373+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
61374+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
61375+ atomic_read_unchecked(&fscache_n_object_created),
61376+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61377
61378 seq_printf(m, "Invals : n=%u run=%u\n",
61379- atomic_read(&fscache_n_invalidates),
61380- atomic_read(&fscache_n_invalidates_run));
61381+ atomic_read_unchecked(&fscache_n_invalidates),
61382+ atomic_read_unchecked(&fscache_n_invalidates_run));
61383
61384 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61385- atomic_read(&fscache_n_updates),
61386- atomic_read(&fscache_n_updates_null),
61387- atomic_read(&fscache_n_updates_run));
61388+ atomic_read_unchecked(&fscache_n_updates),
61389+ atomic_read_unchecked(&fscache_n_updates_null),
61390+ atomic_read_unchecked(&fscache_n_updates_run));
61391
61392 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61393- atomic_read(&fscache_n_relinquishes),
61394- atomic_read(&fscache_n_relinquishes_null),
61395- atomic_read(&fscache_n_relinquishes_waitcrt),
61396- atomic_read(&fscache_n_relinquishes_retire));
61397+ atomic_read_unchecked(&fscache_n_relinquishes),
61398+ atomic_read_unchecked(&fscache_n_relinquishes_null),
61399+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61400+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
61401
61402 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61403- atomic_read(&fscache_n_attr_changed),
61404- atomic_read(&fscache_n_attr_changed_ok),
61405- atomic_read(&fscache_n_attr_changed_nobufs),
61406- atomic_read(&fscache_n_attr_changed_nomem),
61407- atomic_read(&fscache_n_attr_changed_calls));
61408+ atomic_read_unchecked(&fscache_n_attr_changed),
61409+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
61410+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61411+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61412+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
61413
61414 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61415- atomic_read(&fscache_n_allocs),
61416- atomic_read(&fscache_n_allocs_ok),
61417- atomic_read(&fscache_n_allocs_wait),
61418- atomic_read(&fscache_n_allocs_nobufs),
61419- atomic_read(&fscache_n_allocs_intr));
61420+ atomic_read_unchecked(&fscache_n_allocs),
61421+ atomic_read_unchecked(&fscache_n_allocs_ok),
61422+ atomic_read_unchecked(&fscache_n_allocs_wait),
61423+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
61424+ atomic_read_unchecked(&fscache_n_allocs_intr));
61425 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61426- atomic_read(&fscache_n_alloc_ops),
61427- atomic_read(&fscache_n_alloc_op_waits),
61428- atomic_read(&fscache_n_allocs_object_dead));
61429+ atomic_read_unchecked(&fscache_n_alloc_ops),
61430+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
61431+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
61432
61433 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61434 " int=%u oom=%u\n",
61435- atomic_read(&fscache_n_retrievals),
61436- atomic_read(&fscache_n_retrievals_ok),
61437- atomic_read(&fscache_n_retrievals_wait),
61438- atomic_read(&fscache_n_retrievals_nodata),
61439- atomic_read(&fscache_n_retrievals_nobufs),
61440- atomic_read(&fscache_n_retrievals_intr),
61441- atomic_read(&fscache_n_retrievals_nomem));
61442+ atomic_read_unchecked(&fscache_n_retrievals),
61443+ atomic_read_unchecked(&fscache_n_retrievals_ok),
61444+ atomic_read_unchecked(&fscache_n_retrievals_wait),
61445+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
61446+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61447+ atomic_read_unchecked(&fscache_n_retrievals_intr),
61448+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
61449 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61450- atomic_read(&fscache_n_retrieval_ops),
61451- atomic_read(&fscache_n_retrieval_op_waits),
61452- atomic_read(&fscache_n_retrievals_object_dead));
61453+ atomic_read_unchecked(&fscache_n_retrieval_ops),
61454+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61455+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61456
61457 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61458- atomic_read(&fscache_n_stores),
61459- atomic_read(&fscache_n_stores_ok),
61460- atomic_read(&fscache_n_stores_again),
61461- atomic_read(&fscache_n_stores_nobufs),
61462- atomic_read(&fscache_n_stores_oom));
61463+ atomic_read_unchecked(&fscache_n_stores),
61464+ atomic_read_unchecked(&fscache_n_stores_ok),
61465+ atomic_read_unchecked(&fscache_n_stores_again),
61466+ atomic_read_unchecked(&fscache_n_stores_nobufs),
61467+ atomic_read_unchecked(&fscache_n_stores_oom));
61468 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61469- atomic_read(&fscache_n_store_ops),
61470- atomic_read(&fscache_n_store_calls),
61471- atomic_read(&fscache_n_store_pages),
61472- atomic_read(&fscache_n_store_radix_deletes),
61473- atomic_read(&fscache_n_store_pages_over_limit));
61474+ atomic_read_unchecked(&fscache_n_store_ops),
61475+ atomic_read_unchecked(&fscache_n_store_calls),
61476+ atomic_read_unchecked(&fscache_n_store_pages),
61477+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
61478+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61479
61480 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61481- atomic_read(&fscache_n_store_vmscan_not_storing),
61482- atomic_read(&fscache_n_store_vmscan_gone),
61483- atomic_read(&fscache_n_store_vmscan_busy),
61484- atomic_read(&fscache_n_store_vmscan_cancelled),
61485- atomic_read(&fscache_n_store_vmscan_wait));
61486+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61487+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61488+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61489+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61490+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61491
61492 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61493- atomic_read(&fscache_n_op_pend),
61494- atomic_read(&fscache_n_op_run),
61495- atomic_read(&fscache_n_op_enqueue),
61496- atomic_read(&fscache_n_op_cancelled),
61497- atomic_read(&fscache_n_op_rejected));
61498+ atomic_read_unchecked(&fscache_n_op_pend),
61499+ atomic_read_unchecked(&fscache_n_op_run),
61500+ atomic_read_unchecked(&fscache_n_op_enqueue),
61501+ atomic_read_unchecked(&fscache_n_op_cancelled),
61502+ atomic_read_unchecked(&fscache_n_op_rejected));
61503 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61504- atomic_read(&fscache_n_op_deferred_release),
61505- atomic_read(&fscache_n_op_release),
61506- atomic_read(&fscache_n_op_gc));
61507+ atomic_read_unchecked(&fscache_n_op_deferred_release),
61508+ atomic_read_unchecked(&fscache_n_op_release),
61509+ atomic_read_unchecked(&fscache_n_op_gc));
61510
61511 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61512 atomic_read(&fscache_n_cop_alloc_object),
61513diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61514index b96a49b..9bfdc47 100644
61515--- a/fs/fuse/cuse.c
61516+++ b/fs/fuse/cuse.c
61517@@ -606,10 +606,12 @@ static int __init cuse_init(void)
61518 INIT_LIST_HEAD(&cuse_conntbl[i]);
61519
61520 /* inherit and extend fuse_dev_operations */
61521- cuse_channel_fops = fuse_dev_operations;
61522- cuse_channel_fops.owner = THIS_MODULE;
61523- cuse_channel_fops.open = cuse_channel_open;
61524- cuse_channel_fops.release = cuse_channel_release;
61525+ pax_open_kernel();
61526+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61527+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61528+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
61529+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
61530+ pax_close_kernel();
61531
61532 cuse_class = class_create(THIS_MODULE, "cuse");
61533 if (IS_ERR(cuse_class))
61534diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61535index 0a648bb..8d463f1 100644
61536--- a/fs/fuse/dev.c
61537+++ b/fs/fuse/dev.c
61538@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61539 ret = 0;
61540 pipe_lock(pipe);
61541
61542- if (!pipe->readers) {
61543+ if (!atomic_read(&pipe->readers)) {
61544 send_sig(SIGPIPE, current, 0);
61545 if (!ret)
61546 ret = -EPIPE;
61547@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61548 page_nr++;
61549 ret += buf->len;
61550
61551- if (pipe->files)
61552+ if (atomic_read(&pipe->files))
61553 do_wakeup = 1;
61554 }
61555
61556diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61557index 1d1292c..bba17ea 100644
61558--- a/fs/fuse/dir.c
61559+++ b/fs/fuse/dir.c
61560@@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
61561 return link;
61562 }
61563
61564-static void free_link(char *link)
61565+static void free_link(const char *link)
61566 {
61567 if (!IS_ERR(link))
61568 free_page((unsigned long) link);
61569diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61570index fe649d3..c679164 100644
61571--- a/fs/hostfs/hostfs_kern.c
61572+++ b/fs/hostfs/hostfs_kern.c
61573@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61574
61575 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61576 {
61577- char *s = nd_get_link(nd);
61578+ const char *s = nd_get_link(nd);
61579 if (!IS_ERR(s))
61580 __putname(s);
61581 }
61582diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61583index d19b30a..ef89c36 100644
61584--- a/fs/hugetlbfs/inode.c
61585+++ b/fs/hugetlbfs/inode.c
61586@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61587 struct mm_struct *mm = current->mm;
61588 struct vm_area_struct *vma;
61589 struct hstate *h = hstate_file(file);
61590+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61591 struct vm_unmapped_area_info info;
61592
61593 if (len & ~huge_page_mask(h))
61594@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61595 return addr;
61596 }
61597
61598+#ifdef CONFIG_PAX_RANDMMAP
61599+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61600+#endif
61601+
61602 if (addr) {
61603 addr = ALIGN(addr, huge_page_size(h));
61604 vma = find_vma(mm, addr);
61605- if (TASK_SIZE - len >= addr &&
61606- (!vma || addr + len <= vma->vm_start))
61607+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61608 return addr;
61609 }
61610
61611 info.flags = 0;
61612 info.length = len;
61613 info.low_limit = TASK_UNMAPPED_BASE;
61614+
61615+#ifdef CONFIG_PAX_RANDMMAP
61616+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61617+ info.low_limit += mm->delta_mmap;
61618+#endif
61619+
61620 info.high_limit = TASK_SIZE;
61621 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61622 info.align_offset = 0;
61623@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61624 };
61625 MODULE_ALIAS_FS("hugetlbfs");
61626
61627-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61628+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61629
61630 static int can_do_hugetlb_shm(void)
61631 {
61632diff --git a/fs/inode.c b/fs/inode.c
61633index 4bcdad3..1883822 100644
61634--- a/fs/inode.c
61635+++ b/fs/inode.c
61636@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61637
61638 #ifdef CONFIG_SMP
61639 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61640- static atomic_t shared_last_ino;
61641- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61642+ static atomic_unchecked_t shared_last_ino;
61643+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61644
61645 res = next - LAST_INO_BATCH;
61646 }
61647diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61648index 4a6cf28..d3a29d3 100644
61649--- a/fs/jffs2/erase.c
61650+++ b/fs/jffs2/erase.c
61651@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61652 struct jffs2_unknown_node marker = {
61653 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61654 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61655- .totlen = cpu_to_je32(c->cleanmarker_size)
61656+ .totlen = cpu_to_je32(c->cleanmarker_size),
61657+ .hdr_crc = cpu_to_je32(0)
61658 };
61659
61660 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61661diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61662index a6597d6..41b30ec 100644
61663--- a/fs/jffs2/wbuf.c
61664+++ b/fs/jffs2/wbuf.c
61665@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61666 {
61667 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61668 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61669- .totlen = constant_cpu_to_je32(8)
61670+ .totlen = constant_cpu_to_je32(8),
61671+ .hdr_crc = constant_cpu_to_je32(0)
61672 };
61673
61674 /*
61675diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61676index e2b7483..855bca3 100644
61677--- a/fs/jfs/super.c
61678+++ b/fs/jfs/super.c
61679@@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
61680
61681 jfs_inode_cachep =
61682 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61683- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61684+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61685 init_once);
61686 if (jfs_inode_cachep == NULL)
61687 return -ENOMEM;
61688diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61689index 39c0143..d54fad4 100644
61690--- a/fs/kernfs/dir.c
61691+++ b/fs/kernfs/dir.c
61692@@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
61693 *
61694 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61695 */
61696-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61697+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61698 {
61699 unsigned long hash = init_name_hash();
61700 unsigned int len = strlen(name);
61701diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61702index dbf397b..d624b48 100644
61703--- a/fs/kernfs/file.c
61704+++ b/fs/kernfs/file.c
61705@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61706
61707 struct kernfs_open_node {
61708 atomic_t refcnt;
61709- atomic_t event;
61710+ atomic_unchecked_t event;
61711 wait_queue_head_t poll;
61712 struct list_head files; /* goes through kernfs_open_file.list */
61713 };
61714@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61715 {
61716 struct kernfs_open_file *of = sf->private;
61717
61718- of->event = atomic_read(&of->kn->attr.open->event);
61719+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61720
61721 return of->kn->attr.ops->seq_show(sf, v);
61722 }
61723@@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61724 return ret;
61725 }
61726
61727-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61728- void *buf, int len, int write)
61729+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61730+ void *buf, size_t len, int write)
61731 {
61732 struct file *file = vma->vm_file;
61733 struct kernfs_open_file *of = kernfs_of(file);
61734- int ret;
61735+ ssize_t ret;
61736
61737 if (!of->vm_ops)
61738 return -EINVAL;
61739@@ -557,7 +557,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61740 return -ENOMEM;
61741
61742 atomic_set(&new_on->refcnt, 0);
61743- atomic_set(&new_on->event, 1);
61744+ atomic_set_unchecked(&new_on->event, 1);
61745 init_waitqueue_head(&new_on->poll);
61746 INIT_LIST_HEAD(&new_on->files);
61747 goto retry;
61748@@ -754,7 +754,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61749
61750 kernfs_put_active(kn);
61751
61752- if (of->event != atomic_read(&on->event))
61753+ if (of->event != atomic_read_unchecked(&on->event))
61754 goto trigger;
61755
61756 return DEFAULT_POLLMASK;
61757@@ -779,7 +779,7 @@ void kernfs_notify(struct kernfs_node *kn)
61758 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61759 on = kn->attr.open;
61760 if (on) {
61761- atomic_inc(&on->event);
61762+ atomic_inc_unchecked(&on->event);
61763 wake_up_interruptible(&on->poll);
61764 }
61765 }
61766diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61767index 4d45705..b35e0bd 100644
61768--- a/fs/kernfs/symlink.c
61769+++ b/fs/kernfs/symlink.c
61770@@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61771 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61772 void *cookie)
61773 {
61774- char *page = nd_get_link(nd);
61775+ const char *page = nd_get_link(nd);
61776 if (!IS_ERR(page))
61777 free_page((unsigned long)page);
61778 }
61779diff --git a/fs/libfs.c b/fs/libfs.c
61780index a184424..944ddce 100644
61781--- a/fs/libfs.c
61782+++ b/fs/libfs.c
61783@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61784
61785 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61786 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61787+ char d_name[sizeof(next->d_iname)];
61788+ const unsigned char *name;
61789+
61790 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61791 if (!simple_positive(next)) {
61792 spin_unlock(&next->d_lock);
61793@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61794
61795 spin_unlock(&next->d_lock);
61796 spin_unlock(&dentry->d_lock);
61797- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61798+ name = next->d_name.name;
61799+ if (name == next->d_iname) {
61800+ memcpy(d_name, name, next->d_name.len);
61801+ name = d_name;
61802+ }
61803+ if (!dir_emit(ctx, name, next->d_name.len,
61804 next->d_inode->i_ino, dt_type(next->d_inode)))
61805 return 0;
61806 spin_lock(&dentry->d_lock);
61807@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61808 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61809 void *cookie)
61810 {
61811- char *s = nd_get_link(nd);
61812+ const char *s = nd_get_link(nd);
61813 if (!IS_ERR(s))
61814 kfree(s);
61815 }
61816diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61817index acd3947..1f896e2 100644
61818--- a/fs/lockd/clntproc.c
61819+++ b/fs/lockd/clntproc.c
61820@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61821 /*
61822 * Cookie counter for NLM requests
61823 */
61824-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61825+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61826
61827 void nlmclnt_next_cookie(struct nlm_cookie *c)
61828 {
61829- u32 cookie = atomic_inc_return(&nlm_cookie);
61830+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61831
61832 memcpy(c->data, &cookie, 4);
61833 c->len=4;
61834diff --git a/fs/locks.c b/fs/locks.c
61835index 4dd39b9..12d6aaf 100644
61836--- a/fs/locks.c
61837+++ b/fs/locks.c
61838@@ -2218,16 +2218,16 @@ void locks_remove_flock(struct file *filp)
61839 return;
61840
61841 if (filp->f_op->flock) {
61842- struct file_lock fl = {
61843+ struct file_lock flock = {
61844 .fl_pid = current->tgid,
61845 .fl_file = filp,
61846 .fl_flags = FL_FLOCK,
61847 .fl_type = F_UNLCK,
61848 .fl_end = OFFSET_MAX,
61849 };
61850- filp->f_op->flock(filp, F_SETLKW, &fl);
61851- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61852- fl.fl_ops->fl_release_private(&fl);
61853+ filp->f_op->flock(filp, F_SETLKW, &flock);
61854+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61855+ flock.fl_ops->fl_release_private(&flock);
61856 }
61857
61858 spin_lock(&inode->i_lock);
61859diff --git a/fs/mount.h b/fs/mount.h
61860index b29e42f..5ea7fdf 100644
61861--- a/fs/mount.h
61862+++ b/fs/mount.h
61863@@ -11,7 +11,7 @@ struct mnt_namespace {
61864 u64 seq; /* Sequence number to prevent loops */
61865 wait_queue_head_t poll;
61866 int event;
61867-};
61868+} __randomize_layout;
61869
61870 struct mnt_pcp {
61871 int mnt_count;
61872@@ -57,7 +57,7 @@ struct mount {
61873 int mnt_expiry_mark; /* true if marked for expiry */
61874 int mnt_pinned;
61875 struct path mnt_ex_mountpoint;
61876-};
61877+} __randomize_layout;
61878
61879 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61880
61881diff --git a/fs/namei.c b/fs/namei.c
61882index 4b491b4..a0166f9 100644
61883--- a/fs/namei.c
61884+++ b/fs/namei.c
61885@@ -330,16 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61886 if (ret != -EACCES)
61887 return ret;
61888
61889+#ifdef CONFIG_GRKERNSEC
61890+ /* we'll block if we have to log due to a denied capability use */
61891+ if (mask & MAY_NOT_BLOCK)
61892+ return -ECHILD;
61893+#endif
61894+
61895 if (S_ISDIR(inode->i_mode)) {
61896 /* DACs are overridable for directories */
61897- if (inode_capable(inode, CAP_DAC_OVERRIDE))
61898- return 0;
61899 if (!(mask & MAY_WRITE))
61900- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61901+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61902+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61903 return 0;
61904+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
61905+ return 0;
61906 return -EACCES;
61907 }
61908 /*
61909+ * Searching includes executable on directories, else just read.
61910+ */
61911+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61912+ if (mask == MAY_READ)
61913+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61914+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61915+ return 0;
61916+
61917+ /*
61918 * Read/write DACs are always overridable.
61919 * Executable DACs are overridable when there is
61920 * at least one exec bit set.
61921@@ -348,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61922 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61923 return 0;
61924
61925- /*
61926- * Searching includes executable on directories, else just read.
61927- */
61928- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61929- if (mask == MAY_READ)
61930- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61931- return 0;
61932-
61933 return -EACCES;
61934 }
61935
61936@@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61937 {
61938 struct dentry *dentry = link->dentry;
61939 int error;
61940- char *s;
61941+ const char *s;
61942
61943 BUG_ON(nd->flags & LOOKUP_RCU);
61944
61945@@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61946 if (error)
61947 goto out_put_nd_path;
61948
61949+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61950+ dentry->d_inode, dentry, nd->path.mnt)) {
61951+ error = -EACCES;
61952+ goto out_put_nd_path;
61953+ }
61954+
61955 nd->last_type = LAST_BIND;
61956 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61957 error = PTR_ERR(*p);
61958@@ -1590,6 +1604,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61959 if (res)
61960 break;
61961 res = walk_component(nd, path, LOOKUP_FOLLOW);
61962+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61963+ res = -EACCES;
61964 put_link(nd, &link, cookie);
61965 } while (res > 0);
61966
61967@@ -1663,7 +1679,7 @@ EXPORT_SYMBOL(full_name_hash);
61968 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61969 {
61970 unsigned long a, b, adata, bdata, mask, hash, len;
61971- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61972+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61973
61974 hash = a = 0;
61975 len = -sizeof(unsigned long);
61976@@ -1947,6 +1963,8 @@ static int path_lookupat(int dfd, const char *name,
61977 if (err)
61978 break;
61979 err = lookup_last(nd, &path);
61980+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61981+ err = -EACCES;
61982 put_link(nd, &link, cookie);
61983 }
61984 }
61985@@ -1954,6 +1972,13 @@ static int path_lookupat(int dfd, const char *name,
61986 if (!err)
61987 err = complete_walk(nd);
61988
61989+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61990+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61991+ path_put(&nd->path);
61992+ err = -ENOENT;
61993+ }
61994+ }
61995+
61996 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61997 if (!d_is_directory(nd->path.dentry)) {
61998 path_put(&nd->path);
61999@@ -1981,8 +2006,15 @@ static int filename_lookup(int dfd, struct filename *name,
62000 retval = path_lookupat(dfd, name->name,
62001 flags | LOOKUP_REVAL, nd);
62002
62003- if (likely(!retval))
62004+ if (likely(!retval)) {
62005 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
62006+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
62007+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
62008+ path_put(&nd->path);
62009+ return -ENOENT;
62010+ }
62011+ }
62012+ }
62013 return retval;
62014 }
62015
62016@@ -2556,6 +2588,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
62017 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
62018 return -EPERM;
62019
62020+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
62021+ return -EPERM;
62022+ if (gr_handle_rawio(inode))
62023+ return -EPERM;
62024+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
62025+ return -EACCES;
62026+
62027 return 0;
62028 }
62029
62030@@ -2787,7 +2826,7 @@ looked_up:
62031 * cleared otherwise prior to returning.
62032 */
62033 static int lookup_open(struct nameidata *nd, struct path *path,
62034- struct file *file,
62035+ struct path *link, struct file *file,
62036 const struct open_flags *op,
62037 bool got_write, int *opened)
62038 {
62039@@ -2822,6 +2861,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62040 /* Negative dentry, just create the file */
62041 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
62042 umode_t mode = op->mode;
62043+
62044+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
62045+ error = -EACCES;
62046+ goto out_dput;
62047+ }
62048+
62049+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
62050+ error = -EACCES;
62051+ goto out_dput;
62052+ }
62053+
62054 if (!IS_POSIXACL(dir->d_inode))
62055 mode &= ~current_umask();
62056 /*
62057@@ -2843,6 +2893,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62058 nd->flags & LOOKUP_EXCL);
62059 if (error)
62060 goto out_dput;
62061+ else
62062+ gr_handle_create(dentry, nd->path.mnt);
62063 }
62064 out_no_open:
62065 path->dentry = dentry;
62066@@ -2857,7 +2909,7 @@ out_dput:
62067 /*
62068 * Handle the last step of open()
62069 */
62070-static int do_last(struct nameidata *nd, struct path *path,
62071+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
62072 struct file *file, const struct open_flags *op,
62073 int *opened, struct filename *name)
62074 {
62075@@ -2907,6 +2959,15 @@ static int do_last(struct nameidata *nd, struct path *path,
62076 if (error)
62077 return error;
62078
62079+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
62080+ error = -ENOENT;
62081+ goto out;
62082+ }
62083+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62084+ error = -EACCES;
62085+ goto out;
62086+ }
62087+
62088 audit_inode(name, dir, LOOKUP_PARENT);
62089 error = -EISDIR;
62090 /* trailing slashes? */
62091@@ -2926,7 +2987,7 @@ retry_lookup:
62092 */
62093 }
62094 mutex_lock(&dir->d_inode->i_mutex);
62095- error = lookup_open(nd, path, file, op, got_write, opened);
62096+ error = lookup_open(nd, path, link, file, op, got_write, opened);
62097 mutex_unlock(&dir->d_inode->i_mutex);
62098
62099 if (error <= 0) {
62100@@ -2950,11 +3011,28 @@ retry_lookup:
62101 goto finish_open_created;
62102 }
62103
62104+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
62105+ error = -ENOENT;
62106+ goto exit_dput;
62107+ }
62108+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
62109+ error = -EACCES;
62110+ goto exit_dput;
62111+ }
62112+
62113 /*
62114 * create/update audit record if it already exists.
62115 */
62116- if (d_is_positive(path->dentry))
62117+ if (d_is_positive(path->dentry)) {
62118+ /* only check if O_CREAT is specified, all other checks need to go
62119+ into may_open */
62120+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
62121+ error = -EACCES;
62122+ goto exit_dput;
62123+ }
62124+
62125 audit_inode(name, path->dentry, 0);
62126+ }
62127
62128 /*
62129 * If atomic_open() acquired write access it is dropped now due to
62130@@ -2995,6 +3073,11 @@ finish_lookup:
62131 }
62132 }
62133 BUG_ON(inode != path->dentry->d_inode);
62134+ /* if we're resolving a symlink to another symlink */
62135+ if (link && gr_handle_symlink_owner(link, inode)) {
62136+ error = -EACCES;
62137+ goto out;
62138+ }
62139 return 1;
62140 }
62141
62142@@ -3004,7 +3087,6 @@ finish_lookup:
62143 save_parent.dentry = nd->path.dentry;
62144 save_parent.mnt = mntget(path->mnt);
62145 nd->path.dentry = path->dentry;
62146-
62147 }
62148 nd->inode = inode;
62149 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
62150@@ -3014,7 +3096,18 @@ finish_open:
62151 path_put(&save_parent);
62152 return error;
62153 }
62154+
62155+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62156+ error = -ENOENT;
62157+ goto out;
62158+ }
62159+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62160+ error = -EACCES;
62161+ goto out;
62162+ }
62163+
62164 audit_inode(name, nd->path.dentry, 0);
62165+
62166 error = -EISDIR;
62167 if ((open_flag & O_CREAT) &&
62168 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
62169@@ -3178,7 +3271,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62170 if (unlikely(error))
62171 goto out;
62172
62173- error = do_last(nd, &path, file, op, &opened, pathname);
62174+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
62175 while (unlikely(error > 0)) { /* trailing symlink */
62176 struct path link = path;
62177 void *cookie;
62178@@ -3196,7 +3289,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62179 error = follow_link(&link, nd, &cookie);
62180 if (unlikely(error))
62181 break;
62182- error = do_last(nd, &path, file, op, &opened, pathname);
62183+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
62184 put_link(nd, &link, cookie);
62185 }
62186 out:
62187@@ -3296,9 +3389,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
62188 goto unlock;
62189
62190 error = -EEXIST;
62191- if (d_is_positive(dentry))
62192+ if (d_is_positive(dentry)) {
62193+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
62194+ error = -ENOENT;
62195 goto fail;
62196-
62197+ }
62198 /*
62199 * Special case - lookup gave negative, but... we had foo/bar/
62200 * From the vfs_mknod() POV we just have a negative dentry -
62201@@ -3350,6 +3445,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
62202 }
62203 EXPORT_SYMBOL(user_path_create);
62204
62205+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
62206+{
62207+ struct filename *tmp = getname(pathname);
62208+ struct dentry *res;
62209+ if (IS_ERR(tmp))
62210+ return ERR_CAST(tmp);
62211+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
62212+ if (IS_ERR(res))
62213+ putname(tmp);
62214+ else
62215+ *to = tmp;
62216+ return res;
62217+}
62218+
62219 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
62220 {
62221 int error = may_create(dir, dentry);
62222@@ -3412,6 +3521,17 @@ retry:
62223
62224 if (!IS_POSIXACL(path.dentry->d_inode))
62225 mode &= ~current_umask();
62226+
62227+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
62228+ error = -EPERM;
62229+ goto out;
62230+ }
62231+
62232+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
62233+ error = -EACCES;
62234+ goto out;
62235+ }
62236+
62237 error = security_path_mknod(&path, dentry, mode, dev);
62238 if (error)
62239 goto out;
62240@@ -3428,6 +3548,8 @@ retry:
62241 break;
62242 }
62243 out:
62244+ if (!error)
62245+ gr_handle_create(dentry, path.mnt);
62246 done_path_create(&path, dentry);
62247 if (retry_estale(error, lookup_flags)) {
62248 lookup_flags |= LOOKUP_REVAL;
62249@@ -3480,9 +3602,16 @@ retry:
62250
62251 if (!IS_POSIXACL(path.dentry->d_inode))
62252 mode &= ~current_umask();
62253+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
62254+ error = -EACCES;
62255+ goto out;
62256+ }
62257 error = security_path_mkdir(&path, dentry, mode);
62258 if (!error)
62259 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
62260+ if (!error)
62261+ gr_handle_create(dentry, path.mnt);
62262+out:
62263 done_path_create(&path, dentry);
62264 if (retry_estale(error, lookup_flags)) {
62265 lookup_flags |= LOOKUP_REVAL;
62266@@ -3563,6 +3692,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
62267 struct filename *name;
62268 struct dentry *dentry;
62269 struct nameidata nd;
62270+ ino_t saved_ino = 0;
62271+ dev_t saved_dev = 0;
62272 unsigned int lookup_flags = 0;
62273 retry:
62274 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62275@@ -3595,10 +3726,21 @@ retry:
62276 error = -ENOENT;
62277 goto exit3;
62278 }
62279+
62280+ saved_ino = dentry->d_inode->i_ino;
62281+ saved_dev = gr_get_dev_from_dentry(dentry);
62282+
62283+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
62284+ error = -EACCES;
62285+ goto exit3;
62286+ }
62287+
62288 error = security_path_rmdir(&nd.path, dentry);
62289 if (error)
62290 goto exit3;
62291 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
62292+ if (!error && (saved_dev || saved_ino))
62293+ gr_handle_delete(saved_ino, saved_dev);
62294 exit3:
62295 dput(dentry);
62296 exit2:
62297@@ -3688,6 +3830,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
62298 struct nameidata nd;
62299 struct inode *inode = NULL;
62300 struct inode *delegated_inode = NULL;
62301+ ino_t saved_ino = 0;
62302+ dev_t saved_dev = 0;
62303 unsigned int lookup_flags = 0;
62304 retry:
62305 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62306@@ -3714,10 +3858,22 @@ retry_deleg:
62307 if (d_is_negative(dentry))
62308 goto slashes;
62309 ihold(inode);
62310+
62311+ if (inode->i_nlink <= 1) {
62312+ saved_ino = inode->i_ino;
62313+ saved_dev = gr_get_dev_from_dentry(dentry);
62314+ }
62315+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
62316+ error = -EACCES;
62317+ goto exit2;
62318+ }
62319+
62320 error = security_path_unlink(&nd.path, dentry);
62321 if (error)
62322 goto exit2;
62323 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
62324+ if (!error && (saved_ino || saved_dev))
62325+ gr_handle_delete(saved_ino, saved_dev);
62326 exit2:
62327 dput(dentry);
62328 }
62329@@ -3805,9 +3961,17 @@ retry:
62330 if (IS_ERR(dentry))
62331 goto out_putname;
62332
62333+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
62334+ error = -EACCES;
62335+ goto out;
62336+ }
62337+
62338 error = security_path_symlink(&path, dentry, from->name);
62339 if (!error)
62340 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
62341+ if (!error)
62342+ gr_handle_create(dentry, path.mnt);
62343+out:
62344 done_path_create(&path, dentry);
62345 if (retry_estale(error, lookup_flags)) {
62346 lookup_flags |= LOOKUP_REVAL;
62347@@ -3910,6 +4074,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
62348 struct dentry *new_dentry;
62349 struct path old_path, new_path;
62350 struct inode *delegated_inode = NULL;
62351+ struct filename *to = NULL;
62352 int how = 0;
62353 int error;
62354
62355@@ -3933,7 +4098,7 @@ retry:
62356 if (error)
62357 return error;
62358
62359- new_dentry = user_path_create(newdfd, newname, &new_path,
62360+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62361 (how & LOOKUP_REVAL));
62362 error = PTR_ERR(new_dentry);
62363 if (IS_ERR(new_dentry))
62364@@ -3945,11 +4110,28 @@ retry:
62365 error = may_linkat(&old_path);
62366 if (unlikely(error))
62367 goto out_dput;
62368+
62369+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62370+ old_path.dentry->d_inode,
62371+ old_path.dentry->d_inode->i_mode, to)) {
62372+ error = -EACCES;
62373+ goto out_dput;
62374+ }
62375+
62376+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62377+ old_path.dentry, old_path.mnt, to)) {
62378+ error = -EACCES;
62379+ goto out_dput;
62380+ }
62381+
62382 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62383 if (error)
62384 goto out_dput;
62385 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62386+ if (!error)
62387+ gr_handle_create(new_dentry, new_path.mnt);
62388 out_dput:
62389+ putname(to);
62390 done_path_create(&new_path, new_dentry);
62391 if (delegated_inode) {
62392 error = break_deleg_wait(&delegated_inode);
62393@@ -4236,6 +4418,12 @@ retry_deleg:
62394 if (new_dentry == trap)
62395 goto exit5;
62396
62397+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62398+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
62399+ to);
62400+ if (error)
62401+ goto exit5;
62402+
62403 error = security_path_rename(&oldnd.path, old_dentry,
62404 &newnd.path, new_dentry);
62405 if (error)
62406@@ -4243,6 +4431,9 @@ retry_deleg:
62407 error = vfs_rename(old_dir->d_inode, old_dentry,
62408 new_dir->d_inode, new_dentry,
62409 &delegated_inode);
62410+ if (!error)
62411+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62412+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
62413 exit5:
62414 dput(new_dentry);
62415 exit4:
62416@@ -4279,6 +4470,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62417
62418 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
62419 {
62420+ char tmpbuf[64];
62421+ const char *newlink;
62422 int len;
62423
62424 len = PTR_ERR(link);
62425@@ -4288,7 +4481,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
62426 len = strlen(link);
62427 if (len > (unsigned) buflen)
62428 len = buflen;
62429- if (copy_to_user(buffer, link, len))
62430+
62431+ if (len < sizeof(tmpbuf)) {
62432+ memcpy(tmpbuf, link, len);
62433+ newlink = tmpbuf;
62434+ } else
62435+ newlink = link;
62436+
62437+ if (copy_to_user(buffer, newlink, len))
62438 len = -EFAULT;
62439 out:
62440 return len;
62441diff --git a/fs/namespace.c b/fs/namespace.c
62442index 65233a5..82ac953 100644
62443--- a/fs/namespace.c
62444+++ b/fs/namespace.c
62445@@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
62446 if (!(sb->s_flags & MS_RDONLY))
62447 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62448 up_write(&sb->s_umount);
62449+
62450+ gr_log_remount(mnt->mnt_devname, retval);
62451+
62452 return retval;
62453 }
62454
62455@@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
62456 }
62457 unlock_mount_hash();
62458 namespace_unlock();
62459+
62460+ gr_log_unmount(mnt->mnt_devname, retval);
62461+
62462 return retval;
62463 }
62464
62465@@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
62466 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62467 */
62468
62469-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62470+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62471 {
62472 struct path path;
62473 struct mount *mnt;
62474@@ -1422,7 +1428,7 @@ out:
62475 /*
62476 * The 2.0 compatible umount. No flags.
62477 */
62478-SYSCALL_DEFINE1(oldumount, char __user *, name)
62479+SYSCALL_DEFINE1(oldumount, const char __user *, name)
62480 {
62481 return sys_umount(name, 0);
62482 }
62483@@ -2431,6 +2437,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62484 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62485 MS_STRICTATIME);
62486
62487+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62488+ retval = -EPERM;
62489+ goto dput_out;
62490+ }
62491+
62492+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62493+ retval = -EPERM;
62494+ goto dput_out;
62495+ }
62496+
62497 if (flags & MS_REMOUNT)
62498 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62499 data_page);
62500@@ -2445,6 +2461,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62501 dev_name, data_page);
62502 dput_out:
62503 path_put(&path);
62504+
62505+ gr_log_mount(dev_name, dir_name, retval);
62506+
62507 return retval;
62508 }
62509
62510@@ -2462,7 +2481,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62511 * number incrementing at 10Ghz will take 12,427 years to wrap which
62512 * is effectively never, so we can ignore the possibility.
62513 */
62514-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62515+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62516
62517 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62518 {
62519@@ -2477,7 +2496,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62520 kfree(new_ns);
62521 return ERR_PTR(ret);
62522 }
62523- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62524+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62525 atomic_set(&new_ns->count, 1);
62526 new_ns->root = NULL;
62527 INIT_LIST_HEAD(&new_ns->list);
62528@@ -2487,7 +2506,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62529 return new_ns;
62530 }
62531
62532-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62533+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62534 struct user_namespace *user_ns, struct fs_struct *new_fs)
62535 {
62536 struct mnt_namespace *new_ns;
62537@@ -2608,8 +2627,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62538 }
62539 EXPORT_SYMBOL(mount_subtree);
62540
62541-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62542- char __user *, type, unsigned long, flags, void __user *, data)
62543+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62544+ const char __user *, type, unsigned long, flags, void __user *, data)
62545 {
62546 int ret;
62547 char *kernel_type;
62548@@ -2722,6 +2741,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62549 if (error)
62550 goto out2;
62551
62552+ if (gr_handle_chroot_pivot()) {
62553+ error = -EPERM;
62554+ goto out2;
62555+ }
62556+
62557 get_fs_root(current->fs, &root);
62558 old_mp = lock_mount(&old);
62559 error = PTR_ERR(old_mp);
62560@@ -2990,7 +3014,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62561 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62562 return -EPERM;
62563
62564- if (fs->users != 1)
62565+ if (atomic_read(&fs->users) != 1)
62566 return -EINVAL;
62567
62568 get_mnt_ns(mnt_ns);
62569diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62570index f4ccfe6..a5cf064 100644
62571--- a/fs/nfs/callback_xdr.c
62572+++ b/fs/nfs/callback_xdr.c
62573@@ -51,7 +51,7 @@ struct callback_op {
62574 callback_decode_arg_t decode_args;
62575 callback_encode_res_t encode_res;
62576 long res_maxsize;
62577-};
62578+} __do_const;
62579
62580 static struct callback_op callback_ops[];
62581
62582diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62583index 360114a..ac6e265 100644
62584--- a/fs/nfs/inode.c
62585+++ b/fs/nfs/inode.c
62586@@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62587 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62588 }
62589
62590-static atomic_long_t nfs_attr_generation_counter;
62591+static atomic_long_unchecked_t nfs_attr_generation_counter;
62592
62593 static unsigned long nfs_read_attr_generation_counter(void)
62594 {
62595- return atomic_long_read(&nfs_attr_generation_counter);
62596+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62597 }
62598
62599 unsigned long nfs_inc_attr_generation_counter(void)
62600 {
62601- return atomic_long_inc_return(&nfs_attr_generation_counter);
62602+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62603 }
62604
62605 void nfs_fattr_init(struct nfs_fattr *fattr)
62606diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62607index 9a914e8..e89c0ea 100644
62608--- a/fs/nfsd/nfs4proc.c
62609+++ b/fs/nfsd/nfs4proc.c
62610@@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62611 nfsd4op_rsize op_rsize_bop;
62612 stateid_getter op_get_currentstateid;
62613 stateid_setter op_set_currentstateid;
62614-};
62615+} __do_const;
62616
62617 static struct nfsd4_operation nfsd4_ops[];
62618
62619diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62620index 16e8fa7..b0803f6 100644
62621--- a/fs/nfsd/nfs4xdr.c
62622+++ b/fs/nfsd/nfs4xdr.c
62623@@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62624
62625 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62626
62627-static nfsd4_dec nfsd4_dec_ops[] = {
62628+static const nfsd4_dec nfsd4_dec_ops[] = {
62629 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62630 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62631 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62632diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62633index f8f060f..c4ba09a 100644
62634--- a/fs/nfsd/nfscache.c
62635+++ b/fs/nfsd/nfscache.c
62636@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62637 {
62638 struct svc_cacherep *rp = rqstp->rq_cacherep;
62639 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62640- int len;
62641+ long len;
62642 size_t bufsize = 0;
62643
62644 if (!rp)
62645 return;
62646
62647- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62648- len >>= 2;
62649+ if (statp) {
62650+ len = (char*)statp - (char*)resv->iov_base;
62651+ len = resv->iov_len - len;
62652+ len >>= 2;
62653+ }
62654
62655 /* Don't cache excessive amounts of data and XDR failures */
62656 if (!statp || len > (256 >> 2)) {
62657diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62658index eea5ad1..5a84ac7 100644
62659--- a/fs/nfsd/vfs.c
62660+++ b/fs/nfsd/vfs.c
62661@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62662 } else {
62663 oldfs = get_fs();
62664 set_fs(KERNEL_DS);
62665- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62666+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62667 set_fs(oldfs);
62668 }
62669
62670@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62671
62672 /* Write the data. */
62673 oldfs = get_fs(); set_fs(KERNEL_DS);
62674- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62675+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62676 set_fs(oldfs);
62677 if (host_err < 0)
62678 goto out_nfserr;
62679@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62680 */
62681
62682 oldfs = get_fs(); set_fs(KERNEL_DS);
62683- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62684+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62685 set_fs(oldfs);
62686
62687 if (host_err < 0)
62688diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62689index 52ccd34..43a53b1 100644
62690--- a/fs/nls/nls_base.c
62691+++ b/fs/nls/nls_base.c
62692@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62693
62694 int __register_nls(struct nls_table *nls, struct module *owner)
62695 {
62696- struct nls_table ** tmp = &tables;
62697+ struct nls_table *tmp = tables;
62698
62699 if (nls->next)
62700 return -EBUSY;
62701
62702- nls->owner = owner;
62703+ pax_open_kernel();
62704+ *(void **)&nls->owner = owner;
62705+ pax_close_kernel();
62706 spin_lock(&nls_lock);
62707- while (*tmp) {
62708- if (nls == *tmp) {
62709+ while (tmp) {
62710+ if (nls == tmp) {
62711 spin_unlock(&nls_lock);
62712 return -EBUSY;
62713 }
62714- tmp = &(*tmp)->next;
62715+ tmp = tmp->next;
62716 }
62717- nls->next = tables;
62718+ pax_open_kernel();
62719+ *(struct nls_table **)&nls->next = tables;
62720+ pax_close_kernel();
62721 tables = nls;
62722 spin_unlock(&nls_lock);
62723 return 0;
62724@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62725
62726 int unregister_nls(struct nls_table * nls)
62727 {
62728- struct nls_table ** tmp = &tables;
62729+ struct nls_table * const * tmp = &tables;
62730
62731 spin_lock(&nls_lock);
62732 while (*tmp) {
62733 if (nls == *tmp) {
62734- *tmp = nls->next;
62735+ pax_open_kernel();
62736+ *(struct nls_table **)tmp = nls->next;
62737+ pax_close_kernel();
62738 spin_unlock(&nls_lock);
62739 return 0;
62740 }
62741diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62742index 162b3f1..6076a7c 100644
62743--- a/fs/nls/nls_euc-jp.c
62744+++ b/fs/nls/nls_euc-jp.c
62745@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62746 p_nls = load_nls("cp932");
62747
62748 if (p_nls) {
62749- table.charset2upper = p_nls->charset2upper;
62750- table.charset2lower = p_nls->charset2lower;
62751+ pax_open_kernel();
62752+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62753+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62754+ pax_close_kernel();
62755 return register_nls(&table);
62756 }
62757
62758diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62759index a80a741..7b96e1b 100644
62760--- a/fs/nls/nls_koi8-ru.c
62761+++ b/fs/nls/nls_koi8-ru.c
62762@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62763 p_nls = load_nls("koi8-u");
62764
62765 if (p_nls) {
62766- table.charset2upper = p_nls->charset2upper;
62767- table.charset2lower = p_nls->charset2lower;
62768+ pax_open_kernel();
62769+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62770+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62771+ pax_close_kernel();
62772 return register_nls(&table);
62773 }
62774
62775diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62776index 287a22c..4e56e4e 100644
62777--- a/fs/notify/fanotify/fanotify_user.c
62778+++ b/fs/notify/fanotify/fanotify_user.c
62779@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62780
62781 fd = fanotify_event_metadata.fd;
62782 ret = -EFAULT;
62783- if (copy_to_user(buf, &fanotify_event_metadata,
62784- fanotify_event_metadata.event_len))
62785+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62786+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62787 goto out_close_fd;
62788
62789 ret = prepare_for_access_response(group, event, fd);
62790@@ -742,6 +742,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
62791 oevent->path.mnt = NULL;
62792 oevent->path.dentry = NULL;
62793
62794+ if (force_o_largefile())
62795+ event_f_flags |= O_LARGEFILE;
62796 group->fanotify_data.f_flags = event_f_flags;
62797 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62798 oevent->response = 0;
62799diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62800index 1e58402..bb2d6f4 100644
62801--- a/fs/notify/notification.c
62802+++ b/fs/notify/notification.c
62803@@ -48,7 +48,7 @@
62804 #include <linux/fsnotify_backend.h>
62805 #include "fsnotify.h"
62806
62807-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62808+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62809
62810 /**
62811 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62812@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62813 */
62814 u32 fsnotify_get_cookie(void)
62815 {
62816- return atomic_inc_return(&fsnotify_sync_cookie);
62817+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62818 }
62819 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62820
62821diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62822index 9e38daf..5727cae 100644
62823--- a/fs/ntfs/dir.c
62824+++ b/fs/ntfs/dir.c
62825@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62826 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62827 ~(s64)(ndir->itype.index.block_size - 1)));
62828 /* Bounds checks. */
62829- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62830+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62831 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62832 "inode 0x%lx or driver bug.", vdir->i_ino);
62833 goto err_out;
62834diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62835index db9bd8a..8338fb6 100644
62836--- a/fs/ntfs/file.c
62837+++ b/fs/ntfs/file.c
62838@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62839 char *addr;
62840 size_t total = 0;
62841 unsigned len;
62842- int left;
62843+ unsigned left;
62844
62845 do {
62846 len = PAGE_CACHE_SIZE - ofs;
62847diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62848index 82650d5..db37dcf 100644
62849--- a/fs/ntfs/super.c
62850+++ b/fs/ntfs/super.c
62851@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62852 if (!silent)
62853 ntfs_error(sb, "Primary boot sector is invalid.");
62854 } else if (!silent)
62855- ntfs_error(sb, read_err_str, "primary");
62856+ ntfs_error(sb, read_err_str, "%s", "primary");
62857 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62858 if (bh_primary)
62859 brelse(bh_primary);
62860@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62861 goto hotfix_primary_boot_sector;
62862 brelse(bh_backup);
62863 } else if (!silent)
62864- ntfs_error(sb, read_err_str, "backup");
62865+ ntfs_error(sb, read_err_str, "%s", "backup");
62866 /* Try to read NT3.51- backup boot sector. */
62867 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62868 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62869@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62870 "sector.");
62871 brelse(bh_backup);
62872 } else if (!silent)
62873- ntfs_error(sb, read_err_str, "backup");
62874+ ntfs_error(sb, read_err_str, "%s", "backup");
62875 /* We failed. Cleanup and return. */
62876 if (bh_primary)
62877 brelse(bh_primary);
62878diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62879index 0440134..d52c93a 100644
62880--- a/fs/ocfs2/localalloc.c
62881+++ b/fs/ocfs2/localalloc.c
62882@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62883 goto bail;
62884 }
62885
62886- atomic_inc(&osb->alloc_stats.moves);
62887+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62888
62889 bail:
62890 if (handle)
62891diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62892index 553f53c..aaf5133 100644
62893--- a/fs/ocfs2/ocfs2.h
62894+++ b/fs/ocfs2/ocfs2.h
62895@@ -235,11 +235,11 @@ enum ocfs2_vol_state
62896
62897 struct ocfs2_alloc_stats
62898 {
62899- atomic_t moves;
62900- atomic_t local_data;
62901- atomic_t bitmap_data;
62902- atomic_t bg_allocs;
62903- atomic_t bg_extends;
62904+ atomic_unchecked_t moves;
62905+ atomic_unchecked_t local_data;
62906+ atomic_unchecked_t bitmap_data;
62907+ atomic_unchecked_t bg_allocs;
62908+ atomic_unchecked_t bg_extends;
62909 };
62910
62911 enum ocfs2_local_alloc_state
62912diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62913index 47ae266..6e8b793 100644
62914--- a/fs/ocfs2/suballoc.c
62915+++ b/fs/ocfs2/suballoc.c
62916@@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62917 mlog_errno(status);
62918 goto bail;
62919 }
62920- atomic_inc(&osb->alloc_stats.bg_extends);
62921+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62922
62923 /* You should never ask for this much metadata */
62924 BUG_ON(bits_wanted >
62925@@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62926 mlog_errno(status);
62927 goto bail;
62928 }
62929- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62930+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62931
62932 *suballoc_loc = res.sr_bg_blkno;
62933 *suballoc_bit_start = res.sr_bit_offset;
62934@@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62935 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62936 res->sr_bits);
62937
62938- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62939+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62940
62941 BUG_ON(res->sr_bits != 1);
62942
62943@@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62944 mlog_errno(status);
62945 goto bail;
62946 }
62947- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62948+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62949
62950 BUG_ON(res.sr_bits != 1);
62951
62952@@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62953 cluster_start,
62954 num_clusters);
62955 if (!status)
62956- atomic_inc(&osb->alloc_stats.local_data);
62957+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62958 } else {
62959 if (min_clusters > (osb->bitmap_cpg - 1)) {
62960 /* The only paths asking for contiguousness
62961@@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62962 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62963 res.sr_bg_blkno,
62964 res.sr_bit_offset);
62965- atomic_inc(&osb->alloc_stats.bitmap_data);
62966+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62967 *num_clusters = res.sr_bits;
62968 }
62969 }
62970diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62971index 49d84f8..4807e0b 100644
62972--- a/fs/ocfs2/super.c
62973+++ b/fs/ocfs2/super.c
62974@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62975 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62976 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62977 "Stats",
62978- atomic_read(&osb->alloc_stats.bitmap_data),
62979- atomic_read(&osb->alloc_stats.local_data),
62980- atomic_read(&osb->alloc_stats.bg_allocs),
62981- atomic_read(&osb->alloc_stats.moves),
62982- atomic_read(&osb->alloc_stats.bg_extends));
62983+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62984+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62985+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62986+ atomic_read_unchecked(&osb->alloc_stats.moves),
62987+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62988
62989 out += snprintf(buf + out, len - out,
62990 "%10s => State: %u Descriptor: %llu Size: %u bits "
62991@@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62992 spin_lock_init(&osb->osb_xattr_lock);
62993 ocfs2_init_steal_slots(osb);
62994
62995- atomic_set(&osb->alloc_stats.moves, 0);
62996- atomic_set(&osb->alloc_stats.local_data, 0);
62997- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62998- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62999- atomic_set(&osb->alloc_stats.bg_extends, 0);
63000+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
63001+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
63002+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
63003+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
63004+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
63005
63006 /* Copy the blockcheck stats from the superblock probe */
63007 osb->osb_ecc_stats = *stats;
63008diff --git a/fs/open.c b/fs/open.c
63009index b9ed8b2..0d5c7a0 100644
63010--- a/fs/open.c
63011+++ b/fs/open.c
63012@@ -32,6 +32,8 @@
63013 #include <linux/dnotify.h>
63014 #include <linux/compat.h>
63015
63016+#define CREATE_TRACE_POINTS
63017+#include <trace/events/fs.h>
63018 #include "internal.h"
63019
63020 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
63021@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
63022 error = locks_verify_truncate(inode, NULL, length);
63023 if (!error)
63024 error = security_path_truncate(path);
63025+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
63026+ error = -EACCES;
63027 if (!error)
63028 error = do_truncate(path->dentry, length, 0, NULL);
63029
63030@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
63031 error = locks_verify_truncate(inode, f.file, length);
63032 if (!error)
63033 error = security_path_truncate(&f.file->f_path);
63034+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
63035+ error = -EACCES;
63036 if (!error)
63037 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
63038 sb_end_write(inode->i_sb);
63039@@ -361,6 +367,9 @@ retry:
63040 if (__mnt_is_readonly(path.mnt))
63041 res = -EROFS;
63042
63043+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
63044+ res = -EACCES;
63045+
63046 out_path_release:
63047 path_put(&path);
63048 if (retry_estale(res, lookup_flags)) {
63049@@ -392,6 +401,8 @@ retry:
63050 if (error)
63051 goto dput_and_out;
63052
63053+ gr_log_chdir(path.dentry, path.mnt);
63054+
63055 set_fs_pwd(current->fs, &path);
63056
63057 dput_and_out:
63058@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
63059 goto out_putf;
63060
63061 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
63062+
63063+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
63064+ error = -EPERM;
63065+
63066+ if (!error)
63067+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
63068+
63069 if (!error)
63070 set_fs_pwd(current->fs, &f.file->f_path);
63071 out_putf:
63072@@ -450,7 +468,13 @@ retry:
63073 if (error)
63074 goto dput_and_out;
63075
63076+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
63077+ goto dput_and_out;
63078+
63079 set_fs_root(current->fs, &path);
63080+
63081+ gr_handle_chroot_chdir(&path);
63082+
63083 error = 0;
63084 dput_and_out:
63085 path_put(&path);
63086@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
63087 return error;
63088 retry_deleg:
63089 mutex_lock(&inode->i_mutex);
63090+
63091+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
63092+ error = -EACCES;
63093+ goto out_unlock;
63094+ }
63095+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
63096+ error = -EACCES;
63097+ goto out_unlock;
63098+ }
63099+
63100 error = security_path_chmod(path, mode);
63101 if (error)
63102 goto out_unlock;
63103@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
63104 uid = make_kuid(current_user_ns(), user);
63105 gid = make_kgid(current_user_ns(), group);
63106
63107+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
63108+ return -EACCES;
63109+
63110 newattrs.ia_valid = ATTR_CTIME;
63111 if (user != (uid_t) -1) {
63112 if (!uid_valid(uid))
63113@@ -994,6 +1031,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
63114 } else {
63115 fsnotify_open(f);
63116 fd_install(fd, f);
63117+ trace_do_sys_open(tmp->name, flags, mode);
63118 }
63119 }
63120 putname(tmp);
63121diff --git a/fs/pipe.c b/fs/pipe.c
63122index 78fd0d0..f71fc09 100644
63123--- a/fs/pipe.c
63124+++ b/fs/pipe.c
63125@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
63126
63127 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
63128 {
63129- if (pipe->files)
63130+ if (atomic_read(&pipe->files))
63131 mutex_lock_nested(&pipe->mutex, subclass);
63132 }
63133
63134@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
63135
63136 void pipe_unlock(struct pipe_inode_info *pipe)
63137 {
63138- if (pipe->files)
63139+ if (atomic_read(&pipe->files))
63140 mutex_unlock(&pipe->mutex);
63141 }
63142 EXPORT_SYMBOL(pipe_unlock);
63143@@ -449,9 +449,9 @@ redo:
63144 }
63145 if (bufs) /* More to do? */
63146 continue;
63147- if (!pipe->writers)
63148+ if (!atomic_read(&pipe->writers))
63149 break;
63150- if (!pipe->waiting_writers) {
63151+ if (!atomic_read(&pipe->waiting_writers)) {
63152 /* syscall merging: Usually we must not sleep
63153 * if O_NONBLOCK is set, or if we got some data.
63154 * But if a writer sleeps in kernel space, then
63155@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
63156 ret = 0;
63157 __pipe_lock(pipe);
63158
63159- if (!pipe->readers) {
63160+ if (!atomic_read(&pipe->readers)) {
63161 send_sig(SIGPIPE, current, 0);
63162 ret = -EPIPE;
63163 goto out;
63164@@ -562,7 +562,7 @@ redo1:
63165 for (;;) {
63166 int bufs;
63167
63168- if (!pipe->readers) {
63169+ if (!atomic_read(&pipe->readers)) {
63170 send_sig(SIGPIPE, current, 0);
63171 if (!ret)
63172 ret = -EPIPE;
63173@@ -653,9 +653,9 @@ redo2:
63174 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63175 do_wakeup = 0;
63176 }
63177- pipe->waiting_writers++;
63178+ atomic_inc(&pipe->waiting_writers);
63179 pipe_wait(pipe);
63180- pipe->waiting_writers--;
63181+ atomic_dec(&pipe->waiting_writers);
63182 }
63183 out:
63184 __pipe_unlock(pipe);
63185@@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63186 mask = 0;
63187 if (filp->f_mode & FMODE_READ) {
63188 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
63189- if (!pipe->writers && filp->f_version != pipe->w_counter)
63190+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
63191 mask |= POLLHUP;
63192 }
63193
63194@@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63195 * Most Unices do not set POLLERR for FIFOs but on Linux they
63196 * behave exactly like pipes for poll().
63197 */
63198- if (!pipe->readers)
63199+ if (!atomic_read(&pipe->readers))
63200 mask |= POLLERR;
63201 }
63202
63203@@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
63204 int kill = 0;
63205
63206 spin_lock(&inode->i_lock);
63207- if (!--pipe->files) {
63208+ if (atomic_dec_and_test(&pipe->files)) {
63209 inode->i_pipe = NULL;
63210 kill = 1;
63211 }
63212@@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
63213
63214 __pipe_lock(pipe);
63215 if (file->f_mode & FMODE_READ)
63216- pipe->readers--;
63217+ atomic_dec(&pipe->readers);
63218 if (file->f_mode & FMODE_WRITE)
63219- pipe->writers--;
63220+ atomic_dec(&pipe->writers);
63221
63222- if (pipe->readers || pipe->writers) {
63223+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
63224 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
63225 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63226 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
63227@@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
63228 kfree(pipe);
63229 }
63230
63231-static struct vfsmount *pipe_mnt __read_mostly;
63232+struct vfsmount *pipe_mnt __read_mostly;
63233
63234 /*
63235 * pipefs_dname() is called from d_path().
63236@@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
63237 goto fail_iput;
63238
63239 inode->i_pipe = pipe;
63240- pipe->files = 2;
63241- pipe->readers = pipe->writers = 1;
63242+ atomic_set(&pipe->files, 2);
63243+ atomic_set(&pipe->readers, 1);
63244+ atomic_set(&pipe->writers, 1);
63245 inode->i_fop = &pipefifo_fops;
63246
63247 /*
63248@@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
63249 spin_lock(&inode->i_lock);
63250 if (inode->i_pipe) {
63251 pipe = inode->i_pipe;
63252- pipe->files++;
63253+ atomic_inc(&pipe->files);
63254 spin_unlock(&inode->i_lock);
63255 } else {
63256 spin_unlock(&inode->i_lock);
63257 pipe = alloc_pipe_info();
63258 if (!pipe)
63259 return -ENOMEM;
63260- pipe->files = 1;
63261+ atomic_set(&pipe->files, 1);
63262 spin_lock(&inode->i_lock);
63263 if (unlikely(inode->i_pipe)) {
63264- inode->i_pipe->files++;
63265+ atomic_inc(&inode->i_pipe->files);
63266 spin_unlock(&inode->i_lock);
63267 free_pipe_info(pipe);
63268 pipe = inode->i_pipe;
63269@@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
63270 * opened, even when there is no process writing the FIFO.
63271 */
63272 pipe->r_counter++;
63273- if (pipe->readers++ == 0)
63274+ if (atomic_inc_return(&pipe->readers) == 1)
63275 wake_up_partner(pipe);
63276
63277- if (!is_pipe && !pipe->writers) {
63278+ if (!is_pipe && !atomic_read(&pipe->writers)) {
63279 if ((filp->f_flags & O_NONBLOCK)) {
63280 /* suppress POLLHUP until we have
63281 * seen a writer */
63282@@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
63283 * errno=ENXIO when there is no process reading the FIFO.
63284 */
63285 ret = -ENXIO;
63286- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
63287+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
63288 goto err;
63289
63290 pipe->w_counter++;
63291- if (!pipe->writers++)
63292+ if (atomic_inc_return(&pipe->writers) == 1)
63293 wake_up_partner(pipe);
63294
63295- if (!is_pipe && !pipe->readers) {
63296+ if (!is_pipe && !atomic_read(&pipe->readers)) {
63297 if (wait_for_partner(pipe, &pipe->r_counter))
63298 goto err_wr;
63299 }
63300@@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
63301 * the process can at least talk to itself.
63302 */
63303
63304- pipe->readers++;
63305- pipe->writers++;
63306+ atomic_inc(&pipe->readers);
63307+ atomic_inc(&pipe->writers);
63308 pipe->r_counter++;
63309 pipe->w_counter++;
63310- if (pipe->readers == 1 || pipe->writers == 1)
63311+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
63312 wake_up_partner(pipe);
63313 break;
63314
63315@@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
63316 return 0;
63317
63318 err_rd:
63319- if (!--pipe->readers)
63320+ if (atomic_dec_and_test(&pipe->readers))
63321 wake_up_interruptible(&pipe->wait);
63322 ret = -ERESTARTSYS;
63323 goto err;
63324
63325 err_wr:
63326- if (!--pipe->writers)
63327+ if (atomic_dec_and_test(&pipe->writers))
63328 wake_up_interruptible(&pipe->wait);
63329 ret = -ERESTARTSYS;
63330 goto err;
63331diff --git a/fs/posix_acl.c b/fs/posix_acl.c
63332index 9e363e4..d936d15 100644
63333--- a/fs/posix_acl.c
63334+++ b/fs/posix_acl.c
63335@@ -20,6 +20,7 @@
63336 #include <linux/xattr.h>
63337 #include <linux/export.h>
63338 #include <linux/user_namespace.h>
63339+#include <linux/grsecurity.h>
63340
63341 struct posix_acl **acl_by_type(struct inode *inode, int type)
63342 {
63343@@ -271,7 +272,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
63344 }
63345 }
63346 if (mode_p)
63347- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63348+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63349 return not_equiv;
63350 }
63351 EXPORT_SYMBOL(posix_acl_equiv_mode);
63352@@ -421,7 +422,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
63353 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
63354 }
63355
63356- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63357+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63358 return not_equiv;
63359 }
63360
63361@@ -479,6 +480,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
63362 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63363 int err = -ENOMEM;
63364 if (clone) {
63365+ *mode_p &= ~gr_acl_umask();
63366+
63367 err = posix_acl_create_masq(clone, mode_p);
63368 if (err < 0) {
63369 posix_acl_release(clone);
63370@@ -653,11 +656,12 @@ struct posix_acl *
63371 posix_acl_from_xattr(struct user_namespace *user_ns,
63372 const void *value, size_t size)
63373 {
63374- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63375- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63376+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63377+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63378 int count;
63379 struct posix_acl *acl;
63380 struct posix_acl_entry *acl_e;
63381+ umode_t umask = gr_acl_umask();
63382
63383 if (!value)
63384 return NULL;
63385@@ -683,12 +687,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63386
63387 switch(acl_e->e_tag) {
63388 case ACL_USER_OBJ:
63389+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63390+ break;
63391 case ACL_GROUP_OBJ:
63392 case ACL_MASK:
63393+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63394+ break;
63395 case ACL_OTHER:
63396+ acl_e->e_perm &= ~(umask & S_IRWXO);
63397 break;
63398
63399 case ACL_USER:
63400+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63401 acl_e->e_uid =
63402 make_kuid(user_ns,
63403 le32_to_cpu(entry->e_id));
63404@@ -696,6 +706,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63405 goto fail;
63406 break;
63407 case ACL_GROUP:
63408+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63409 acl_e->e_gid =
63410 make_kgid(user_ns,
63411 le32_to_cpu(entry->e_id));
63412diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63413index 2183fcf..3c32a98 100644
63414--- a/fs/proc/Kconfig
63415+++ b/fs/proc/Kconfig
63416@@ -30,7 +30,7 @@ config PROC_FS
63417
63418 config PROC_KCORE
63419 bool "/proc/kcore support" if !ARM
63420- depends on PROC_FS && MMU
63421+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63422 help
63423 Provides a virtual ELF core file of the live kernel. This can
63424 be read with gdb and other ELF tools. No modifications can be
63425@@ -38,8 +38,8 @@ config PROC_KCORE
63426
63427 config PROC_VMCORE
63428 bool "/proc/vmcore support"
63429- depends on PROC_FS && CRASH_DUMP
63430- default y
63431+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63432+ default n
63433 help
63434 Exports the dump image of crashed kernel in ELF format.
63435
63436@@ -63,8 +63,8 @@ config PROC_SYSCTL
63437 limited in memory.
63438
63439 config PROC_PAGE_MONITOR
63440- default y
63441- depends on PROC_FS && MMU
63442+ default n
63443+ depends on PROC_FS && MMU && !GRKERNSEC
63444 bool "Enable /proc page monitoring" if EXPERT
63445 help
63446 Various /proc files exist to monitor process memory utilization:
63447diff --git a/fs/proc/array.c b/fs/proc/array.c
63448index 656e401..b5b86b9 100644
63449--- a/fs/proc/array.c
63450+++ b/fs/proc/array.c
63451@@ -60,6 +60,7 @@
63452 #include <linux/tty.h>
63453 #include <linux/string.h>
63454 #include <linux/mman.h>
63455+#include <linux/grsecurity.h>
63456 #include <linux/proc_fs.h>
63457 #include <linux/ioport.h>
63458 #include <linux/uaccess.h>
63459@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63460 seq_putc(m, '\n');
63461 }
63462
63463+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63464+static inline void task_pax(struct seq_file *m, struct task_struct *p)
63465+{
63466+ if (p->mm)
63467+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63468+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63469+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63470+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63471+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63472+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63473+ else
63474+ seq_printf(m, "PaX:\t-----\n");
63475+}
63476+#endif
63477+
63478 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63479 struct pid *pid, struct task_struct *task)
63480 {
63481@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63482 task_cpus_allowed(m, task);
63483 cpuset_task_status_allowed(m, task);
63484 task_context_switch_counts(m, task);
63485+
63486+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63487+ task_pax(m, task);
63488+#endif
63489+
63490+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63491+ task_grsec_rbac(m, task);
63492+#endif
63493+
63494 return 0;
63495 }
63496
63497+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63498+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63499+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63500+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63501+#endif
63502+
63503 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63504 struct pid *pid, struct task_struct *task, int whole)
63505 {
63506@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63507 char tcomm[sizeof(task->comm)];
63508 unsigned long flags;
63509
63510+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63511+ if (current->exec_id != m->exec_id) {
63512+ gr_log_badprocpid("stat");
63513+ return 0;
63514+ }
63515+#endif
63516+
63517 state = *get_task_state(task);
63518 vsize = eip = esp = 0;
63519 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63520@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63521 gtime = task_gtime(task);
63522 }
63523
63524+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63525+ if (PAX_RAND_FLAGS(mm)) {
63526+ eip = 0;
63527+ esp = 0;
63528+ wchan = 0;
63529+ }
63530+#endif
63531+#ifdef CONFIG_GRKERNSEC_HIDESYM
63532+ wchan = 0;
63533+ eip =0;
63534+ esp =0;
63535+#endif
63536+
63537 /* scale priority and nice values from timeslices to -20..20 */
63538 /* to make it look like a "normal" Unix priority/nice value */
63539 priority = task_prio(task);
63540@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63541 seq_put_decimal_ull(m, ' ', vsize);
63542 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63543 seq_put_decimal_ull(m, ' ', rsslim);
63544+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63545+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63546+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63547+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63548+#else
63549 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63550 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63551 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63552+#endif
63553 seq_put_decimal_ull(m, ' ', esp);
63554 seq_put_decimal_ull(m, ' ', eip);
63555 /* The signal information here is obsolete.
63556@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63557 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63558 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63559
63560- if (mm && permitted) {
63561+ if (mm && permitted
63562+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63563+ && !PAX_RAND_FLAGS(mm)
63564+#endif
63565+ ) {
63566 seq_put_decimal_ull(m, ' ', mm->start_data);
63567 seq_put_decimal_ull(m, ' ', mm->end_data);
63568 seq_put_decimal_ull(m, ' ', mm->start_brk);
63569@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63570 struct pid *pid, struct task_struct *task)
63571 {
63572 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63573- struct mm_struct *mm = get_task_mm(task);
63574+ struct mm_struct *mm;
63575
63576+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63577+ if (current->exec_id != m->exec_id) {
63578+ gr_log_badprocpid("statm");
63579+ return 0;
63580+ }
63581+#endif
63582+ mm = get_task_mm(task);
63583 if (mm) {
63584 size = task_statm(mm, &shared, &text, &data, &resident);
63585 mmput(mm);
63586@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63587 return 0;
63588 }
63589
63590+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63591+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63592+{
63593+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63594+}
63595+#endif
63596+
63597 #ifdef CONFIG_CHECKPOINT_RESTORE
63598 static struct pid *
63599 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63600diff --git a/fs/proc/base.c b/fs/proc/base.c
63601index b976062..584d0bc 100644
63602--- a/fs/proc/base.c
63603+++ b/fs/proc/base.c
63604@@ -113,6 +113,14 @@ struct pid_entry {
63605 union proc_op op;
63606 };
63607
63608+struct getdents_callback {
63609+ struct linux_dirent __user * current_dir;
63610+ struct linux_dirent __user * previous;
63611+ struct file * file;
63612+ int count;
63613+ int error;
63614+};
63615+
63616 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63617 .name = (NAME), \
63618 .len = sizeof(NAME) - 1, \
63619@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
63620 if (!mm->arg_end)
63621 goto out_mm; /* Shh! No looking before we're done */
63622
63623+ if (gr_acl_handle_procpidmem(task))
63624+ goto out_mm;
63625+
63626 len = mm->arg_end - mm->arg_start;
63627
63628 if (len > PAGE_SIZE)
63629@@ -237,12 +248,28 @@ out:
63630 return res;
63631 }
63632
63633+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63634+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63635+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63636+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63637+#endif
63638+
63639 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63640 {
63641 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63642 int res = PTR_ERR(mm);
63643 if (mm && !IS_ERR(mm)) {
63644 unsigned int nwords = 0;
63645+
63646+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63647+ /* allow if we're currently ptracing this task */
63648+ if (PAX_RAND_FLAGS(mm) &&
63649+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63650+ mmput(mm);
63651+ return 0;
63652+ }
63653+#endif
63654+
63655 do {
63656 nwords += 2;
63657 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63658@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63659 }
63660
63661
63662-#ifdef CONFIG_KALLSYMS
63663+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63664 /*
63665 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63666 * Returns the resolved symbol. If that fails, simply return the address.
63667@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
63668 mutex_unlock(&task->signal->cred_guard_mutex);
63669 }
63670
63671-#ifdef CONFIG_STACKTRACE
63672+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63673
63674 #define MAX_STACK_TRACE_DEPTH 64
63675
63676@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63677 return count;
63678 }
63679
63680-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63681+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63682 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63683 {
63684 long nr;
63685@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63686 /************************************************************************/
63687
63688 /* permission checks */
63689-static int proc_fd_access_allowed(struct inode *inode)
63690+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63691 {
63692 struct task_struct *task;
63693 int allowed = 0;
63694@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63695 */
63696 task = get_proc_task(inode);
63697 if (task) {
63698- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63699+ if (log)
63700+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63701+ else
63702+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63703 put_task_struct(task);
63704 }
63705 return allowed;
63706@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63707 struct task_struct *task,
63708 int hide_pid_min)
63709 {
63710+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63711+ return false;
63712+
63713+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63714+ rcu_read_lock();
63715+ {
63716+ const struct cred *tmpcred = current_cred();
63717+ const struct cred *cred = __task_cred(task);
63718+
63719+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63720+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63721+ || in_group_p(grsec_proc_gid)
63722+#endif
63723+ ) {
63724+ rcu_read_unlock();
63725+ return true;
63726+ }
63727+ }
63728+ rcu_read_unlock();
63729+
63730+ if (!pid->hide_pid)
63731+ return false;
63732+#endif
63733+
63734 if (pid->hide_pid < hide_pid_min)
63735 return true;
63736 if (in_group_p(pid->pid_gid))
63737 return true;
63738+
63739 return ptrace_may_access(task, PTRACE_MODE_READ);
63740 }
63741
63742@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63743 put_task_struct(task);
63744
63745 if (!has_perms) {
63746+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63747+ {
63748+#else
63749 if (pid->hide_pid == 2) {
63750+#endif
63751 /*
63752 * Let's make getdents(), stat(), and open()
63753 * consistent with each other. If a process
63754@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63755 if (!task)
63756 return -ESRCH;
63757
63758+ if (gr_acl_handle_procpidmem(task)) {
63759+ put_task_struct(task);
63760+ return -EPERM;
63761+ }
63762+
63763 mm = mm_access(task, mode);
63764 put_task_struct(task);
63765
63766@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63767
63768 file->private_data = mm;
63769
63770+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63771+ file->f_version = current->exec_id;
63772+#endif
63773+
63774 return 0;
63775 }
63776
63777@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63778 ssize_t copied;
63779 char *page;
63780
63781+#ifdef CONFIG_GRKERNSEC
63782+ if (write)
63783+ return -EPERM;
63784+#endif
63785+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63786+ if (file->f_version != current->exec_id) {
63787+ gr_log_badprocpid("mem");
63788+ return 0;
63789+ }
63790+#endif
63791+
63792 if (!mm)
63793 return 0;
63794
63795@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63796 goto free;
63797
63798 while (count > 0) {
63799- int this_len = min_t(int, count, PAGE_SIZE);
63800+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63801
63802 if (write && copy_from_user(page, buf, this_len)) {
63803 copied = -EFAULT;
63804@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63805 if (!mm)
63806 return 0;
63807
63808+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63809+ if (file->f_version != current->exec_id) {
63810+ gr_log_badprocpid("environ");
63811+ return 0;
63812+ }
63813+#endif
63814+
63815 page = (char *)__get_free_page(GFP_TEMPORARY);
63816 if (!page)
63817 return -ENOMEM;
63818@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63819 goto free;
63820 while (count > 0) {
63821 size_t this_len, max_len;
63822- int retval;
63823+ ssize_t retval;
63824
63825 if (src >= (mm->env_end - mm->env_start))
63826 break;
63827@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63828 int error = -EACCES;
63829
63830 /* Are we allowed to snoop on the tasks file descriptors? */
63831- if (!proc_fd_access_allowed(inode))
63832+ if (!proc_fd_access_allowed(inode, 0))
63833 goto out;
63834
63835 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63836@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63837 struct path path;
63838
63839 /* Are we allowed to snoop on the tasks file descriptors? */
63840- if (!proc_fd_access_allowed(inode))
63841- goto out;
63842+ /* logging this is needed for learning on chromium to work properly,
63843+ but we don't want to flood the logs from 'ps' which does a readlink
63844+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63845+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63846+ */
63847+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63848+ if (!proc_fd_access_allowed(inode,0))
63849+ goto out;
63850+ } else {
63851+ if (!proc_fd_access_allowed(inode,1))
63852+ goto out;
63853+ }
63854
63855 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63856 if (error)
63857@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63858 rcu_read_lock();
63859 cred = __task_cred(task);
63860 inode->i_uid = cred->euid;
63861+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63862+ inode->i_gid = grsec_proc_gid;
63863+#else
63864 inode->i_gid = cred->egid;
63865+#endif
63866 rcu_read_unlock();
63867 }
63868 security_task_to_inode(task, inode);
63869@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63870 return -ENOENT;
63871 }
63872 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63873+#ifdef CONFIG_GRKERNSEC_PROC_USER
63874+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63875+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63876+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63877+#endif
63878 task_dumpable(task)) {
63879 cred = __task_cred(task);
63880 stat->uid = cred->euid;
63881+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63882+ stat->gid = grsec_proc_gid;
63883+#else
63884 stat->gid = cred->egid;
63885+#endif
63886 }
63887 }
63888 rcu_read_unlock();
63889@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63890
63891 if (task) {
63892 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63893+#ifdef CONFIG_GRKERNSEC_PROC_USER
63894+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63895+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63896+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63897+#endif
63898 task_dumpable(task)) {
63899 rcu_read_lock();
63900 cred = __task_cred(task);
63901 inode->i_uid = cred->euid;
63902+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63903+ inode->i_gid = grsec_proc_gid;
63904+#else
63905 inode->i_gid = cred->egid;
63906+#endif
63907 rcu_read_unlock();
63908 } else {
63909 inode->i_uid = GLOBAL_ROOT_UID;
63910@@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63911 if (!task)
63912 goto out_no_task;
63913
63914+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63915+ goto out;
63916+
63917 /*
63918 * Yes, it does not scale. And it should not. Don't add
63919 * new entries into /proc/<tgid>/ without very good reasons.
63920@@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63921 if (!task)
63922 return -ENOENT;
63923
63924+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63925+ goto out;
63926+
63927 if (!dir_emit_dots(file, ctx))
63928 goto out;
63929
63930@@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63931 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63932 #endif
63933 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63934-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63935+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63936 INF("syscall", S_IRUGO, proc_pid_syscall),
63937 #endif
63938 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63939@@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63940 #ifdef CONFIG_SECURITY
63941 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63942 #endif
63943-#ifdef CONFIG_KALLSYMS
63944+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63945 INF("wchan", S_IRUGO, proc_pid_wchan),
63946 #endif
63947-#ifdef CONFIG_STACKTRACE
63948+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63949 ONE("stack", S_IRUGO, proc_pid_stack),
63950 #endif
63951 #ifdef CONFIG_SCHEDSTATS
63952@@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63953 #ifdef CONFIG_HARDWALL
63954 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63955 #endif
63956+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63957+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63958+#endif
63959 #ifdef CONFIG_USER_NS
63960 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63961 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63962@@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
63963 if (!inode)
63964 goto out;
63965
63966+#ifdef CONFIG_GRKERNSEC_PROC_USER
63967+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63968+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63969+ inode->i_gid = grsec_proc_gid;
63970+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63971+#else
63972 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63973+#endif
63974 inode->i_op = &proc_tgid_base_inode_operations;
63975 inode->i_fop = &proc_tgid_base_operations;
63976 inode->i_flags|=S_IMMUTABLE;
63977@@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63978 if (!task)
63979 goto out;
63980
63981+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63982+ goto out_put_task;
63983+
63984 result = proc_pid_instantiate(dir, dentry, task, NULL);
63985+out_put_task:
63986 put_task_struct(task);
63987 out:
63988 return ERR_PTR(result);
63989@@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
63990 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63991 #endif
63992 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63993-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63994+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63995 INF("syscall", S_IRUGO, proc_pid_syscall),
63996 #endif
63997 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63998@@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
63999 #ifdef CONFIG_SECURITY
64000 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
64001 #endif
64002-#ifdef CONFIG_KALLSYMS
64003+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64004 INF("wchan", S_IRUGO, proc_pid_wchan),
64005 #endif
64006-#ifdef CONFIG_STACKTRACE
64007+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64008 ONE("stack", S_IRUGO, proc_pid_stack),
64009 #endif
64010 #ifdef CONFIG_SCHEDSTATS
64011diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
64012index cbd82df..c0407d2 100644
64013--- a/fs/proc/cmdline.c
64014+++ b/fs/proc/cmdline.c
64015@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
64016
64017 static int __init proc_cmdline_init(void)
64018 {
64019+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64020+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
64021+#else
64022 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
64023+#endif
64024 return 0;
64025 }
64026 fs_initcall(proc_cmdline_init);
64027diff --git a/fs/proc/devices.c b/fs/proc/devices.c
64028index 50493ed..248166b 100644
64029--- a/fs/proc/devices.c
64030+++ b/fs/proc/devices.c
64031@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
64032
64033 static int __init proc_devices_init(void)
64034 {
64035+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64036+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
64037+#else
64038 proc_create("devices", 0, NULL, &proc_devinfo_operations);
64039+#endif
64040 return 0;
64041 }
64042 fs_initcall(proc_devices_init);
64043diff --git a/fs/proc/fd.c b/fs/proc/fd.c
64044index 985ea88..d118a0a 100644
64045--- a/fs/proc/fd.c
64046+++ b/fs/proc/fd.c
64047@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
64048 if (!task)
64049 return -ENOENT;
64050
64051- files = get_files_struct(task);
64052+ if (!gr_acl_handle_procpidmem(task))
64053+ files = get_files_struct(task);
64054 put_task_struct(task);
64055
64056 if (files) {
64057@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
64058 */
64059 int proc_fd_permission(struct inode *inode, int mask)
64060 {
64061+ struct task_struct *task;
64062 int rv = generic_permission(inode, mask);
64063- if (rv == 0)
64064- return 0;
64065+
64066 if (task_tgid(current) == proc_pid(inode))
64067 rv = 0;
64068+
64069+ task = get_proc_task(inode);
64070+ if (task == NULL)
64071+ return rv;
64072+
64073+ if (gr_acl_handle_procpidmem(task))
64074+ rv = -EACCES;
64075+
64076+ put_task_struct(task);
64077+
64078 return rv;
64079 }
64080
64081diff --git a/fs/proc/generic.c b/fs/proc/generic.c
64082index b7f268e..3bea6b7 100644
64083--- a/fs/proc/generic.c
64084+++ b/fs/proc/generic.c
64085@@ -23,6 +23,7 @@
64086 #include <linux/bitops.h>
64087 #include <linux/spinlock.h>
64088 #include <linux/completion.h>
64089+#include <linux/grsecurity.h>
64090 #include <asm/uaccess.h>
64091
64092 #include "internal.h"
64093@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
64094 return proc_lookup_de(PDE(dir), dir, dentry);
64095 }
64096
64097+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
64098+ unsigned int flags)
64099+{
64100+ if (gr_proc_is_restricted())
64101+ return ERR_PTR(-EACCES);
64102+
64103+ return proc_lookup_de(PDE(dir), dir, dentry);
64104+}
64105+
64106 /*
64107 * This returns non-zero if at EOF, so that the /proc
64108 * root directory can use this and check if it should
64109@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
64110 return proc_readdir_de(PDE(inode), file, ctx);
64111 }
64112
64113+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
64114+{
64115+ struct inode *inode = file_inode(file);
64116+
64117+ if (gr_proc_is_restricted())
64118+ return -EACCES;
64119+
64120+ return proc_readdir_de(PDE(inode), file, ctx);
64121+}
64122+
64123 /*
64124 * These are the generic /proc directory operations. They
64125 * use the in-memory "struct proc_dir_entry" tree to parse
64126@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
64127 .iterate = proc_readdir,
64128 };
64129
64130+static const struct file_operations proc_dir_restricted_operations = {
64131+ .llseek = generic_file_llseek,
64132+ .read = generic_read_dir,
64133+ .iterate = proc_readdir_restrict,
64134+};
64135+
64136 /*
64137 * proc directories can do almost nothing..
64138 */
64139@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
64140 .setattr = proc_notify_change,
64141 };
64142
64143+static const struct inode_operations proc_dir_restricted_inode_operations = {
64144+ .lookup = proc_lookup_restrict,
64145+ .getattr = proc_getattr,
64146+ .setattr = proc_notify_change,
64147+};
64148+
64149 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
64150 {
64151 struct proc_dir_entry *tmp;
64152@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
64153 return ret;
64154
64155 if (S_ISDIR(dp->mode)) {
64156- dp->proc_fops = &proc_dir_operations;
64157- dp->proc_iops = &proc_dir_inode_operations;
64158+ if (dp->restricted) {
64159+ dp->proc_fops = &proc_dir_restricted_operations;
64160+ dp->proc_iops = &proc_dir_restricted_inode_operations;
64161+ } else {
64162+ dp->proc_fops = &proc_dir_operations;
64163+ dp->proc_iops = &proc_dir_inode_operations;
64164+ }
64165 dir->nlink++;
64166 } else if (S_ISLNK(dp->mode)) {
64167 dp->proc_iops = &proc_link_inode_operations;
64168@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
64169 }
64170 EXPORT_SYMBOL_GPL(proc_mkdir_data);
64171
64172+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
64173+ struct proc_dir_entry *parent, void *data)
64174+{
64175+ struct proc_dir_entry *ent;
64176+
64177+ if (mode == 0)
64178+ mode = S_IRUGO | S_IXUGO;
64179+
64180+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
64181+ if (ent) {
64182+ ent->data = data;
64183+ ent->restricted = 1;
64184+ if (proc_register(parent, ent) < 0) {
64185+ kfree(ent);
64186+ ent = NULL;
64187+ }
64188+ }
64189+ return ent;
64190+}
64191+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
64192+
64193 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
64194 struct proc_dir_entry *parent)
64195 {
64196@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
64197 }
64198 EXPORT_SYMBOL(proc_mkdir);
64199
64200+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
64201+ struct proc_dir_entry *parent)
64202+{
64203+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
64204+}
64205+EXPORT_SYMBOL(proc_mkdir_restrict);
64206+
64207 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
64208 struct proc_dir_entry *parent,
64209 const struct file_operations *proc_fops,
64210diff --git a/fs/proc/inode.c b/fs/proc/inode.c
64211index 124fc43..8afbb02 100644
64212--- a/fs/proc/inode.c
64213+++ b/fs/proc/inode.c
64214@@ -23,11 +23,17 @@
64215 #include <linux/slab.h>
64216 #include <linux/mount.h>
64217 #include <linux/magic.h>
64218+#include <linux/grsecurity.h>
64219
64220 #include <asm/uaccess.h>
64221
64222 #include "internal.h"
64223
64224+#ifdef CONFIG_PROC_SYSCTL
64225+extern const struct inode_operations proc_sys_inode_operations;
64226+extern const struct inode_operations proc_sys_dir_operations;
64227+#endif
64228+
64229 static void proc_evict_inode(struct inode *inode)
64230 {
64231 struct proc_dir_entry *de;
64232@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
64233 ns = PROC_I(inode)->ns.ns;
64234 if (ns_ops && ns)
64235 ns_ops->put(ns);
64236+
64237+#ifdef CONFIG_PROC_SYSCTL
64238+ if (inode->i_op == &proc_sys_inode_operations ||
64239+ inode->i_op == &proc_sys_dir_operations)
64240+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
64241+#endif
64242+
64243 }
64244
64245 static struct kmem_cache * proc_inode_cachep;
64246@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
64247 if (de->mode) {
64248 inode->i_mode = de->mode;
64249 inode->i_uid = de->uid;
64250+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64251+ inode->i_gid = grsec_proc_gid;
64252+#else
64253 inode->i_gid = de->gid;
64254+#endif
64255 }
64256 if (de->size)
64257 inode->i_size = de->size;
64258diff --git a/fs/proc/internal.h b/fs/proc/internal.h
64259index 651d09a..6a4b495 100644
64260--- a/fs/proc/internal.h
64261+++ b/fs/proc/internal.h
64262@@ -46,9 +46,10 @@ struct proc_dir_entry {
64263 struct completion *pde_unload_completion;
64264 struct list_head pde_openers; /* who did ->open, but not ->release */
64265 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
64266+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
64267 u8 namelen;
64268 char name[];
64269-};
64270+} __randomize_layout;
64271
64272 union proc_op {
64273 int (*proc_get_link)(struct dentry *, struct path *);
64274@@ -67,7 +68,7 @@ struct proc_inode {
64275 struct ctl_table *sysctl_entry;
64276 struct proc_ns ns;
64277 struct inode vfs_inode;
64278-};
64279+} __randomize_layout;
64280
64281 /*
64282 * General functions
64283@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
64284 struct pid *, struct task_struct *);
64285 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
64286 struct pid *, struct task_struct *);
64287+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64288+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
64289+#endif
64290
64291 /*
64292 * base.c
64293@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
64294 extern spinlock_t proc_subdir_lock;
64295
64296 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
64297+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
64298 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
64299 struct dentry *);
64300 extern int proc_readdir(struct file *, struct dir_context *);
64301+extern int proc_readdir_restrict(struct file *, struct dir_context *);
64302 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
64303
64304 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
64305diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
64306index a352d57..cb94a5c 100644
64307--- a/fs/proc/interrupts.c
64308+++ b/fs/proc/interrupts.c
64309@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
64310
64311 static int __init proc_interrupts_init(void)
64312 {
64313+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64314+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
64315+#else
64316 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
64317+#endif
64318 return 0;
64319 }
64320 fs_initcall(proc_interrupts_init);
64321diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
64322index 39e6ef3..2f9cb5e 100644
64323--- a/fs/proc/kcore.c
64324+++ b/fs/proc/kcore.c
64325@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64326 * the addresses in the elf_phdr on our list.
64327 */
64328 start = kc_offset_to_vaddr(*fpos - elf_buflen);
64329- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
64330+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
64331+ if (tsz > buflen)
64332 tsz = buflen;
64333-
64334+
64335 while (buflen) {
64336 struct kcore_list *m;
64337
64338@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64339 kfree(elf_buf);
64340 } else {
64341 if (kern_addr_valid(start)) {
64342- unsigned long n;
64343+ char *elf_buf;
64344+ mm_segment_t oldfs;
64345
64346- n = copy_to_user(buffer, (char *)start, tsz);
64347- /*
64348- * We cannot distinguish between fault on source
64349- * and fault on destination. When this happens
64350- * we clear too and hope it will trigger the
64351- * EFAULT again.
64352- */
64353- if (n) {
64354- if (clear_user(buffer + tsz - n,
64355- n))
64356+ elf_buf = kmalloc(tsz, GFP_KERNEL);
64357+ if (!elf_buf)
64358+ return -ENOMEM;
64359+ oldfs = get_fs();
64360+ set_fs(KERNEL_DS);
64361+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
64362+ set_fs(oldfs);
64363+ if (copy_to_user(buffer, elf_buf, tsz)) {
64364+ kfree(elf_buf);
64365 return -EFAULT;
64366+ }
64367 }
64368+ set_fs(oldfs);
64369+ kfree(elf_buf);
64370 } else {
64371 if (clear_user(buffer, tsz))
64372 return -EFAULT;
64373@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64374
64375 static int open_kcore(struct inode *inode, struct file *filp)
64376 {
64377+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64378+ return -EPERM;
64379+#endif
64380 if (!capable(CAP_SYS_RAWIO))
64381 return -EPERM;
64382 if (kcore_need_update)
64383diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64384index 136e548..1f88922 100644
64385--- a/fs/proc/meminfo.c
64386+++ b/fs/proc/meminfo.c
64387@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64388 vmi.used >> 10,
64389 vmi.largest_chunk >> 10
64390 #ifdef CONFIG_MEMORY_FAILURE
64391- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64392+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64393 #endif
64394 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64395 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64396diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64397index d4a3574..b421ce9 100644
64398--- a/fs/proc/nommu.c
64399+++ b/fs/proc/nommu.c
64400@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64401
64402 if (file) {
64403 seq_pad(m, ' ');
64404- seq_path(m, &file->f_path, "");
64405+ seq_path(m, &file->f_path, "\n\\");
64406 }
64407
64408 seq_putc(m, '\n');
64409diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64410index 4677bb7..94067cd 100644
64411--- a/fs/proc/proc_net.c
64412+++ b/fs/proc/proc_net.c
64413@@ -23,6 +23,7 @@
64414 #include <linux/nsproxy.h>
64415 #include <net/net_namespace.h>
64416 #include <linux/seq_file.h>
64417+#include <linux/grsecurity.h>
64418
64419 #include "internal.h"
64420
64421@@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
64422 return maybe_get_net(PDE_NET(PDE(inode)));
64423 }
64424
64425+extern const struct seq_operations dev_seq_ops;
64426+
64427 int seq_open_net(struct inode *ino, struct file *f,
64428 const struct seq_operations *ops, int size)
64429 {
64430@@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
64431
64432 BUG_ON(size < sizeof(*p));
64433
64434+ /* only permit access to /proc/net/dev */
64435+ if (ops != &dev_seq_ops && gr_proc_is_restricted())
64436+ return -EACCES;
64437+
64438 net = get_proc_net(ino);
64439 if (net == NULL)
64440 return -ENXIO;
64441@@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
64442 int err;
64443 struct net *net;
64444
64445+ if (gr_proc_is_restricted())
64446+ return -EACCES;
64447+
64448 err = -ENXIO;
64449 net = get_proc_net(inode);
64450 if (net == NULL)
64451diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64452index 7129046..6914844 100644
64453--- a/fs/proc/proc_sysctl.c
64454+++ b/fs/proc/proc_sysctl.c
64455@@ -11,13 +11,21 @@
64456 #include <linux/namei.h>
64457 #include <linux/mm.h>
64458 #include <linux/module.h>
64459+#include <linux/nsproxy.h>
64460+#ifdef CONFIG_GRKERNSEC
64461+#include <net/net_namespace.h>
64462+#endif
64463 #include "internal.h"
64464
64465+extern int gr_handle_chroot_sysctl(const int op);
64466+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64467+ const int op);
64468+
64469 static const struct dentry_operations proc_sys_dentry_operations;
64470 static const struct file_operations proc_sys_file_operations;
64471-static const struct inode_operations proc_sys_inode_operations;
64472+const struct inode_operations proc_sys_inode_operations;
64473 static const struct file_operations proc_sys_dir_file_operations;
64474-static const struct inode_operations proc_sys_dir_operations;
64475+const struct inode_operations proc_sys_dir_operations;
64476
64477 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64478 {
64479@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64480
64481 err = NULL;
64482 d_set_d_op(dentry, &proc_sys_dentry_operations);
64483+
64484+ gr_handle_proc_create(dentry, inode);
64485+
64486 d_add(dentry, inode);
64487
64488 out:
64489@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64490 struct inode *inode = file_inode(filp);
64491 struct ctl_table_header *head = grab_header(inode);
64492 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64493+ int op = write ? MAY_WRITE : MAY_READ;
64494 ssize_t error;
64495 size_t res;
64496
64497@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64498 * and won't be until we finish.
64499 */
64500 error = -EPERM;
64501- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64502+ if (sysctl_perm(head, table, op))
64503 goto out;
64504
64505 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64506@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64507 if (!table->proc_handler)
64508 goto out;
64509
64510+#ifdef CONFIG_GRKERNSEC
64511+ error = -EPERM;
64512+ if (gr_handle_chroot_sysctl(op))
64513+ goto out;
64514+ dget(filp->f_path.dentry);
64515+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64516+ dput(filp->f_path.dentry);
64517+ goto out;
64518+ }
64519+ dput(filp->f_path.dentry);
64520+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64521+ goto out;
64522+ if (write) {
64523+ if (current->nsproxy->net_ns != table->extra2) {
64524+ if (!capable(CAP_SYS_ADMIN))
64525+ goto out;
64526+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64527+ goto out;
64528+ }
64529+#endif
64530+
64531 /* careful: calling conventions are nasty here */
64532 res = count;
64533 error = table->proc_handler(table, write, buf, &res, ppos);
64534@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64535 return false;
64536 } else {
64537 d_set_d_op(child, &proc_sys_dentry_operations);
64538+
64539+ gr_handle_proc_create(child, inode);
64540+
64541 d_add(child, inode);
64542 }
64543 } else {
64544@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64545 if ((*pos)++ < ctx->pos)
64546 return true;
64547
64548+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64549+ return 0;
64550+
64551 if (unlikely(S_ISLNK(table->mode)))
64552 res = proc_sys_link_fill_cache(file, ctx, head, table);
64553 else
64554@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64555 if (IS_ERR(head))
64556 return PTR_ERR(head);
64557
64558+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64559+ return -ENOENT;
64560+
64561 generic_fillattr(inode, stat);
64562 if (table)
64563 stat->mode = (stat->mode & S_IFMT) | table->mode;
64564@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64565 .llseek = generic_file_llseek,
64566 };
64567
64568-static const struct inode_operations proc_sys_inode_operations = {
64569+const struct inode_operations proc_sys_inode_operations = {
64570 .permission = proc_sys_permission,
64571 .setattr = proc_sys_setattr,
64572 .getattr = proc_sys_getattr,
64573 };
64574
64575-static const struct inode_operations proc_sys_dir_operations = {
64576+const struct inode_operations proc_sys_dir_operations = {
64577 .lookup = proc_sys_lookup,
64578 .permission = proc_sys_permission,
64579 .setattr = proc_sys_setattr,
64580@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64581 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64582 const char *name, int namelen)
64583 {
64584- struct ctl_table *table;
64585+ ctl_table_no_const *table;
64586 struct ctl_dir *new;
64587 struct ctl_node *node;
64588 char *new_name;
64589@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64590 return NULL;
64591
64592 node = (struct ctl_node *)(new + 1);
64593- table = (struct ctl_table *)(node + 1);
64594+ table = (ctl_table_no_const *)(node + 1);
64595 new_name = (char *)(table + 2);
64596 memcpy(new_name, name, namelen);
64597 new_name[namelen] = '\0';
64598@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64599 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64600 struct ctl_table_root *link_root)
64601 {
64602- struct ctl_table *link_table, *entry, *link;
64603+ ctl_table_no_const *link_table, *link;
64604+ struct ctl_table *entry;
64605 struct ctl_table_header *links;
64606 struct ctl_node *node;
64607 char *link_name;
64608@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64609 return NULL;
64610
64611 node = (struct ctl_node *)(links + 1);
64612- link_table = (struct ctl_table *)(node + nr_entries);
64613+ link_table = (ctl_table_no_const *)(node + nr_entries);
64614 link_name = (char *)&link_table[nr_entries + 1];
64615
64616 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64617@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64618 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64619 struct ctl_table *table)
64620 {
64621- struct ctl_table *ctl_table_arg = NULL;
64622- struct ctl_table *entry, *files;
64623+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64624+ struct ctl_table *entry;
64625 int nr_files = 0;
64626 int nr_dirs = 0;
64627 int err = -ENOMEM;
64628@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64629 nr_files++;
64630 }
64631
64632- files = table;
64633 /* If there are mixed files and directories we need a new table */
64634 if (nr_dirs && nr_files) {
64635- struct ctl_table *new;
64636+ ctl_table_no_const *new;
64637 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64638 GFP_KERNEL);
64639 if (!files)
64640@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64641 /* Register everything except a directory full of subdirectories */
64642 if (nr_files || !nr_dirs) {
64643 struct ctl_table_header *header;
64644- header = __register_sysctl_table(set, path, files);
64645+ header = __register_sysctl_table(set, path, files ? files : table);
64646 if (!header) {
64647 kfree(ctl_table_arg);
64648 goto out;
64649diff --git a/fs/proc/root.c b/fs/proc/root.c
64650index 87dbcbe..55e1b4d 100644
64651--- a/fs/proc/root.c
64652+++ b/fs/proc/root.c
64653@@ -186,7 +186,15 @@ void __init proc_root_init(void)
64654 #ifdef CONFIG_PROC_DEVICETREE
64655 proc_device_tree_init();
64656 #endif
64657+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64658+#ifdef CONFIG_GRKERNSEC_PROC_USER
64659+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64660+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64661+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64662+#endif
64663+#else
64664 proc_mkdir("bus", NULL);
64665+#endif
64666 proc_sys_init();
64667 }
64668
64669diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64670index 6f599c6..bd00271 100644
64671--- a/fs/proc/stat.c
64672+++ b/fs/proc/stat.c
64673@@ -11,6 +11,7 @@
64674 #include <linux/irqnr.h>
64675 #include <asm/cputime.h>
64676 #include <linux/tick.h>
64677+#include <linux/grsecurity.h>
64678
64679 #ifndef arch_irq_stat_cpu
64680 #define arch_irq_stat_cpu(cpu) 0
64681@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64682 u64 sum_softirq = 0;
64683 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64684 struct timespec boottime;
64685+ int unrestricted = 1;
64686+
64687+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64688+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64689+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64690+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64691+ && !in_group_p(grsec_proc_gid)
64692+#endif
64693+ )
64694+ unrestricted = 0;
64695+#endif
64696+#endif
64697
64698 user = nice = system = idle = iowait =
64699 irq = softirq = steal = 0;
64700@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64701 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64702 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64703 idle += get_idle_time(i);
64704- iowait += get_iowait_time(i);
64705- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64706- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64707- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64708- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64709- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64710- sum += kstat_cpu_irqs_sum(i);
64711- sum += arch_irq_stat_cpu(i);
64712+ if (unrestricted) {
64713+ iowait += get_iowait_time(i);
64714+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64715+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64716+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64717+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64718+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64719+ sum += kstat_cpu_irqs_sum(i);
64720+ sum += arch_irq_stat_cpu(i);
64721+ for (j = 0; j < NR_SOFTIRQS; j++) {
64722+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64723
64724- for (j = 0; j < NR_SOFTIRQS; j++) {
64725- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64726-
64727- per_softirq_sums[j] += softirq_stat;
64728- sum_softirq += softirq_stat;
64729+ per_softirq_sums[j] += softirq_stat;
64730+ sum_softirq += softirq_stat;
64731+ }
64732 }
64733 }
64734- sum += arch_irq_stat();
64735+ if (unrestricted)
64736+ sum += arch_irq_stat();
64737
64738 seq_puts(p, "cpu ");
64739 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64740@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64741 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64742 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64743 idle = get_idle_time(i);
64744- iowait = get_iowait_time(i);
64745- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64746- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64747- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64748- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64749- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64750+ if (unrestricted) {
64751+ iowait = get_iowait_time(i);
64752+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64753+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64754+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64755+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64756+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64757+ }
64758 seq_printf(p, "cpu%d", i);
64759 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64760 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64761@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64762
64763 /* sum again ? it could be updated? */
64764 for_each_irq_nr(j)
64765- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64766+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64767
64768 seq_printf(p,
64769 "\nctxt %llu\n"
64770@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64771 "processes %lu\n"
64772 "procs_running %lu\n"
64773 "procs_blocked %lu\n",
64774- nr_context_switches(),
64775+ unrestricted ? nr_context_switches() : 0ULL,
64776 (unsigned long)jif,
64777- total_forks,
64778- nr_running(),
64779- nr_iowait());
64780+ unrestricted ? total_forks : 0UL,
64781+ unrestricted ? nr_running() : 0UL,
64782+ unrestricted ? nr_iowait() : 0UL);
64783
64784 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64785
64786diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64787index fb52b54..5fc7c14 100644
64788--- a/fs/proc/task_mmu.c
64789+++ b/fs/proc/task_mmu.c
64790@@ -12,12 +12,19 @@
64791 #include <linux/swap.h>
64792 #include <linux/swapops.h>
64793 #include <linux/mmu_notifier.h>
64794+#include <linux/grsecurity.h>
64795
64796 #include <asm/elf.h>
64797 #include <asm/uaccess.h>
64798 #include <asm/tlbflush.h>
64799 #include "internal.h"
64800
64801+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64802+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64803+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
64804+ _mm->pax_flags & MF_PAX_SEGMEXEC))
64805+#endif
64806+
64807 void task_mem(struct seq_file *m, struct mm_struct *mm)
64808 {
64809 unsigned long data, text, lib, swap;
64810@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64811 "VmExe:\t%8lu kB\n"
64812 "VmLib:\t%8lu kB\n"
64813 "VmPTE:\t%8lu kB\n"
64814- "VmSwap:\t%8lu kB\n",
64815- hiwater_vm << (PAGE_SHIFT-10),
64816+ "VmSwap:\t%8lu kB\n"
64817+
64818+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64819+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64820+#endif
64821+
64822+ ,hiwater_vm << (PAGE_SHIFT-10),
64823 total_vm << (PAGE_SHIFT-10),
64824 mm->locked_vm << (PAGE_SHIFT-10),
64825 mm->pinned_vm << (PAGE_SHIFT-10),
64826@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64827 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64828 (PTRS_PER_PTE * sizeof(pte_t) *
64829 atomic_long_read(&mm->nr_ptes)) >> 10,
64830- swap << (PAGE_SHIFT-10));
64831+ swap << (PAGE_SHIFT-10)
64832+
64833+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64834+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64835+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64836+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64837+#else
64838+ , mm->context.user_cs_base
64839+ , mm->context.user_cs_limit
64840+#endif
64841+#endif
64842+
64843+ );
64844 }
64845
64846 unsigned long task_vsize(struct mm_struct *mm)
64847@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64848 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64849 }
64850
64851- /* We don't show the stack guard page in /proc/maps */
64852+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64853+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64854+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64855+#else
64856 start = vma->vm_start;
64857- if (stack_guard_page_start(vma, start))
64858- start += PAGE_SIZE;
64859 end = vma->vm_end;
64860- if (stack_guard_page_end(vma, end))
64861- end -= PAGE_SIZE;
64862+#endif
64863
64864 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64865 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64866@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64867 flags & VM_WRITE ? 'w' : '-',
64868 flags & VM_EXEC ? 'x' : '-',
64869 flags & VM_MAYSHARE ? 's' : 'p',
64870+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64871+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64872+#else
64873 pgoff,
64874+#endif
64875 MAJOR(dev), MINOR(dev), ino);
64876
64877 /*
64878@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64879 */
64880 if (file) {
64881 seq_pad(m, ' ');
64882- seq_path(m, &file->f_path, "\n");
64883+ seq_path(m, &file->f_path, "\n\\");
64884 goto done;
64885 }
64886
64887@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64888 * Thread stack in /proc/PID/task/TID/maps or
64889 * the main process stack.
64890 */
64891- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64892- vma->vm_end >= mm->start_stack)) {
64893+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64894+ (vma->vm_start <= mm->start_stack &&
64895+ vma->vm_end >= mm->start_stack)) {
64896 name = "[stack]";
64897 } else {
64898 /* Thread stack in /proc/PID/maps */
64899@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64900 struct proc_maps_private *priv = m->private;
64901 struct task_struct *task = priv->task;
64902
64903+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64904+ if (current->exec_id != m->exec_id) {
64905+ gr_log_badprocpid("maps");
64906+ return 0;
64907+ }
64908+#endif
64909+
64910 show_map_vma(m, vma, is_pid);
64911
64912 if (m->count < m->size) /* vma is copied successfully */
64913@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64914 .private = &mss,
64915 };
64916
64917+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64918+ if (current->exec_id != m->exec_id) {
64919+ gr_log_badprocpid("smaps");
64920+ return 0;
64921+ }
64922+#endif
64923 memset(&mss, 0, sizeof mss);
64924- mss.vma = vma;
64925- /* mmap_sem is held in m_start */
64926- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64927- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64928-
64929+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64930+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64931+#endif
64932+ mss.vma = vma;
64933+ /* mmap_sem is held in m_start */
64934+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64935+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64936+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64937+ }
64938+#endif
64939 show_map_vma(m, vma, is_pid);
64940
64941 seq_printf(m,
64942@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64943 "KernelPageSize: %8lu kB\n"
64944 "MMUPageSize: %8lu kB\n"
64945 "Locked: %8lu kB\n",
64946+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64947+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64948+#else
64949 (vma->vm_end - vma->vm_start) >> 10,
64950+#endif
64951 mss.resident >> 10,
64952 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64953 mss.shared_clean >> 10,
64954@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64955 char buffer[64];
64956 int nid;
64957
64958+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64959+ if (current->exec_id != m->exec_id) {
64960+ gr_log_badprocpid("numa_maps");
64961+ return 0;
64962+ }
64963+#endif
64964+
64965 if (!mm)
64966 return 0;
64967
64968@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64969 mpol_to_str(buffer, sizeof(buffer), pol);
64970 mpol_cond_put(pol);
64971
64972+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64973+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64974+#else
64975 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64976+#endif
64977
64978 if (file) {
64979 seq_printf(m, " file=");
64980- seq_path(m, &file->f_path, "\n\t= ");
64981+ seq_path(m, &file->f_path, "\n\t\\= ");
64982 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64983 seq_printf(m, " heap");
64984 } else {
64985diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64986index 678455d..ebd3245 100644
64987--- a/fs/proc/task_nommu.c
64988+++ b/fs/proc/task_nommu.c
64989@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64990 else
64991 bytes += kobjsize(mm);
64992
64993- if (current->fs && current->fs->users > 1)
64994+ if (current->fs && atomic_read(&current->fs->users) > 1)
64995 sbytes += kobjsize(current->fs);
64996 else
64997 bytes += kobjsize(current->fs);
64998@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64999
65000 if (file) {
65001 seq_pad(m, ' ');
65002- seq_path(m, &file->f_path, "");
65003+ seq_path(m, &file->f_path, "\n\\");
65004 } else if (mm) {
65005 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
65006
65007diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
65008index 88d4585..c10bfeb 100644
65009--- a/fs/proc/vmcore.c
65010+++ b/fs/proc/vmcore.c
65011@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
65012 nr_bytes = count;
65013
65014 /* If pfn is not ram, return zeros for sparse dump files */
65015- if (pfn_is_ram(pfn) == 0)
65016- memset(buf, 0, nr_bytes);
65017- else {
65018+ if (pfn_is_ram(pfn) == 0) {
65019+ if (userbuf) {
65020+ if (clear_user((char __force_user *)buf, nr_bytes))
65021+ return -EFAULT;
65022+ } else
65023+ memset(buf, 0, nr_bytes);
65024+ } else {
65025 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
65026 offset, userbuf);
65027 if (tmp < 0)
65028@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
65029 static int copy_to(void *target, void *src, size_t size, int userbuf)
65030 {
65031 if (userbuf) {
65032- if (copy_to_user((char __user *) target, src, size))
65033+ if (copy_to_user((char __force_user *) target, src, size))
65034 return -EFAULT;
65035 } else {
65036 memcpy(target, src, size);
65037@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65038 if (*fpos < m->offset + m->size) {
65039 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
65040 start = m->paddr + *fpos - m->offset;
65041- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
65042+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
65043 if (tmp < 0)
65044 return tmp;
65045 buflen -= tsz;
65046@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65047 static ssize_t read_vmcore(struct file *file, char __user *buffer,
65048 size_t buflen, loff_t *fpos)
65049 {
65050- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
65051+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
65052 }
65053
65054 /*
65055diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
65056index b00fcc9..e0c6381 100644
65057--- a/fs/qnx6/qnx6.h
65058+++ b/fs/qnx6/qnx6.h
65059@@ -74,7 +74,7 @@ enum {
65060 BYTESEX_BE,
65061 };
65062
65063-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65064+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65065 {
65066 if (sbi->s_bytesex == BYTESEX_LE)
65067 return le64_to_cpu((__force __le64)n);
65068@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
65069 return (__force __fs64)cpu_to_be64(n);
65070 }
65071
65072-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65073+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65074 {
65075 if (sbi->s_bytesex == BYTESEX_LE)
65076 return le32_to_cpu((__force __le32)n);
65077diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
65078index 72d2917..c917c12 100644
65079--- a/fs/quota/netlink.c
65080+++ b/fs/quota/netlink.c
65081@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
65082 void quota_send_warning(struct kqid qid, dev_t dev,
65083 const char warntype)
65084 {
65085- static atomic_t seq;
65086+ static atomic_unchecked_t seq;
65087 struct sk_buff *skb;
65088 void *msg_head;
65089 int ret;
65090@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
65091 "VFS: Not enough memory to send quota warning.\n");
65092 return;
65093 }
65094- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
65095+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
65096 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
65097 if (!msg_head) {
65098 printk(KERN_ERR
65099diff --git a/fs/read_write.c b/fs/read_write.c
65100index 28cc9c8..208e4fb 100644
65101--- a/fs/read_write.c
65102+++ b/fs/read_write.c
65103@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
65104
65105 old_fs = get_fs();
65106 set_fs(get_ds());
65107- p = (__force const char __user *)buf;
65108+ p = (const char __force_user *)buf;
65109 if (count > MAX_RW_COUNT)
65110 count = MAX_RW_COUNT;
65111 if (file->f_op->write)
65112diff --git a/fs/readdir.c b/fs/readdir.c
65113index 5b53d99..a6c3049 100644
65114--- a/fs/readdir.c
65115+++ b/fs/readdir.c
65116@@ -17,6 +17,7 @@
65117 #include <linux/security.h>
65118 #include <linux/syscalls.h>
65119 #include <linux/unistd.h>
65120+#include <linux/namei.h>
65121
65122 #include <asm/uaccess.h>
65123
65124@@ -69,6 +70,7 @@ struct old_linux_dirent {
65125 struct readdir_callback {
65126 struct dir_context ctx;
65127 struct old_linux_dirent __user * dirent;
65128+ struct file * file;
65129 int result;
65130 };
65131
65132@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
65133 buf->result = -EOVERFLOW;
65134 return -EOVERFLOW;
65135 }
65136+
65137+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65138+ return 0;
65139+
65140 buf->result++;
65141 dirent = buf->dirent;
65142 if (!access_ok(VERIFY_WRITE, dirent,
65143@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
65144 if (!f.file)
65145 return -EBADF;
65146
65147+ buf.file = f.file;
65148 error = iterate_dir(f.file, &buf.ctx);
65149 if (buf.result)
65150 error = buf.result;
65151@@ -142,6 +149,7 @@ struct getdents_callback {
65152 struct dir_context ctx;
65153 struct linux_dirent __user * current_dir;
65154 struct linux_dirent __user * previous;
65155+ struct file * file;
65156 int count;
65157 int error;
65158 };
65159@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
65160 buf->error = -EOVERFLOW;
65161 return -EOVERFLOW;
65162 }
65163+
65164+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65165+ return 0;
65166+
65167 dirent = buf->previous;
65168 if (dirent) {
65169 if (__put_user(offset, &dirent->d_off))
65170@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
65171 if (!f.file)
65172 return -EBADF;
65173
65174+ buf.file = f.file;
65175 error = iterate_dir(f.file, &buf.ctx);
65176 if (error >= 0)
65177 error = buf.error;
65178@@ -226,6 +239,7 @@ struct getdents_callback64 {
65179 struct dir_context ctx;
65180 struct linux_dirent64 __user * current_dir;
65181 struct linux_dirent64 __user * previous;
65182+ struct file *file;
65183 int count;
65184 int error;
65185 };
65186@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
65187 buf->error = -EINVAL; /* only used if we fail.. */
65188 if (reclen > buf->count)
65189 return -EINVAL;
65190+
65191+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65192+ return 0;
65193+
65194 dirent = buf->previous;
65195 if (dirent) {
65196 if (__put_user(offset, &dirent->d_off))
65197@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
65198 if (!f.file)
65199 return -EBADF;
65200
65201+ buf.file = f.file;
65202 error = iterate_dir(f.file, &buf.ctx);
65203 if (error >= 0)
65204 error = buf.error;
65205diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
65206index 9a3c68c..767933e 100644
65207--- a/fs/reiserfs/do_balan.c
65208+++ b/fs/reiserfs/do_balan.c
65209@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
65210 return;
65211 }
65212
65213- atomic_inc(&(fs_generation(tb->tb_sb)));
65214+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
65215 do_balance_starts(tb);
65216
65217 /* balance leaf returns 0 except if combining L R and S into
65218diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
65219index ee382ef..f4eb6eb5 100644
65220--- a/fs/reiserfs/item_ops.c
65221+++ b/fs/reiserfs/item_ops.c
65222@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
65223 }
65224
65225 static struct item_operations errcatch_ops = {
65226- errcatch_bytes_number,
65227- errcatch_decrement_key,
65228- errcatch_is_left_mergeable,
65229- errcatch_print_item,
65230- errcatch_check_item,
65231+ .bytes_number = errcatch_bytes_number,
65232+ .decrement_key = errcatch_decrement_key,
65233+ .is_left_mergeable = errcatch_is_left_mergeable,
65234+ .print_item = errcatch_print_item,
65235+ .check_item = errcatch_check_item,
65236
65237- errcatch_create_vi,
65238- errcatch_check_left,
65239- errcatch_check_right,
65240- errcatch_part_size,
65241- errcatch_unit_num,
65242- errcatch_print_vi
65243+ .create_vi = errcatch_create_vi,
65244+ .check_left = errcatch_check_left,
65245+ .check_right = errcatch_check_right,
65246+ .part_size = errcatch_part_size,
65247+ .unit_num = errcatch_unit_num,
65248+ .print_vi = errcatch_print_vi
65249 };
65250
65251 //////////////////////////////////////////////////////////////////////////////
65252diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
65253index 02b0b7d..c85018b 100644
65254--- a/fs/reiserfs/procfs.c
65255+++ b/fs/reiserfs/procfs.c
65256@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
65257 "SMALL_TAILS " : "NO_TAILS ",
65258 replay_only(sb) ? "REPLAY_ONLY " : "",
65259 convert_reiserfs(sb) ? "CONV " : "",
65260- atomic_read(&r->s_generation_counter),
65261+ atomic_read_unchecked(&r->s_generation_counter),
65262 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
65263 SF(s_do_balance), SF(s_unneeded_left_neighbor),
65264 SF(s_good_search_by_key_reada), SF(s_bmaps),
65265diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
65266index 8d06adf..7e1c9f8 100644
65267--- a/fs/reiserfs/reiserfs.h
65268+++ b/fs/reiserfs/reiserfs.h
65269@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
65270 /* Comment? -Hans */
65271 wait_queue_head_t s_wait;
65272 /* To be obsoleted soon by per buffer seals.. -Hans */
65273- atomic_t s_generation_counter; // increased by one every time the
65274+ atomic_unchecked_t s_generation_counter; // increased by one every time the
65275 // tree gets re-balanced
65276 unsigned long s_properties; /* File system properties. Currently holds
65277 on-disk FS format */
65278@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
65279 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
65280
65281 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
65282-#define get_generation(s) atomic_read (&fs_generation(s))
65283+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
65284 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
65285 #define __fs_changed(gen,s) (gen != get_generation (s))
65286 #define fs_changed(gen,s) \
65287diff --git a/fs/select.c b/fs/select.c
65288index 467bb1c..cf9d65a 100644
65289--- a/fs/select.c
65290+++ b/fs/select.c
65291@@ -20,6 +20,7 @@
65292 #include <linux/export.h>
65293 #include <linux/slab.h>
65294 #include <linux/poll.h>
65295+#include <linux/security.h>
65296 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
65297 #include <linux/file.h>
65298 #include <linux/fdtable.h>
65299@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
65300 struct poll_list *walk = head;
65301 unsigned long todo = nfds;
65302
65303+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
65304 if (nfds > rlimit(RLIMIT_NOFILE))
65305 return -EINVAL;
65306
65307diff --git a/fs/seq_file.c b/fs/seq_file.c
65308index 1d641bb..c2f4743 100644
65309--- a/fs/seq_file.c
65310+++ b/fs/seq_file.c
65311@@ -10,6 +10,8 @@
65312 #include <linux/seq_file.h>
65313 #include <linux/slab.h>
65314 #include <linux/cred.h>
65315+#include <linux/sched.h>
65316+#include <linux/grsecurity.h>
65317
65318 #include <asm/uaccess.h>
65319 #include <asm/page.h>
65320@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
65321 #ifdef CONFIG_USER_NS
65322 p->user_ns = file->f_cred->user_ns;
65323 #endif
65324+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65325+ p->exec_id = current->exec_id;
65326+#endif
65327
65328 /*
65329 * Wrappers around seq_open(e.g. swaps_open) need to be
65330@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
65331 }
65332 EXPORT_SYMBOL(seq_open);
65333
65334+
65335+int seq_open_restrict(struct file *file, const struct seq_operations *op)
65336+{
65337+ if (gr_proc_is_restricted())
65338+ return -EACCES;
65339+
65340+ return seq_open(file, op);
65341+}
65342+EXPORT_SYMBOL(seq_open_restrict);
65343+
65344 static int traverse(struct seq_file *m, loff_t offset)
65345 {
65346 loff_t pos = 0, index;
65347@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
65348 return 0;
65349 }
65350 if (!m->buf) {
65351- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65352+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65353 if (!m->buf)
65354 return -ENOMEM;
65355 }
65356@@ -137,7 +152,7 @@ Eoverflow:
65357 m->op->stop(m, p);
65358 kfree(m->buf);
65359 m->count = 0;
65360- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65361+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65362 return !m->buf ? -ENOMEM : -EAGAIN;
65363 }
65364
65365@@ -153,7 +168,7 @@ Eoverflow:
65366 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65367 {
65368 struct seq_file *m = file->private_data;
65369- size_t copied = 0;
65370+ ssize_t copied = 0;
65371 loff_t pos;
65372 size_t n;
65373 void *p;
65374@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65375
65376 /* grab buffer if we didn't have one */
65377 if (!m->buf) {
65378- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65379+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65380 if (!m->buf)
65381 goto Enomem;
65382 }
65383@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65384 m->op->stop(m, p);
65385 kfree(m->buf);
65386 m->count = 0;
65387- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65388+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65389 if (!m->buf)
65390 goto Enomem;
65391 m->version = 0;
65392@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65393 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65394 void *data)
65395 {
65396- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65397+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65398 int res = -ENOMEM;
65399
65400 if (op) {
65401@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65402 }
65403 EXPORT_SYMBOL(single_open_size);
65404
65405+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65406+ void *data)
65407+{
65408+ if (gr_proc_is_restricted())
65409+ return -EACCES;
65410+
65411+ return single_open(file, show, data);
65412+}
65413+EXPORT_SYMBOL(single_open_restrict);
65414+
65415+
65416 int single_release(struct inode *inode, struct file *file)
65417 {
65418 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65419diff --git a/fs/splice.c b/fs/splice.c
65420index 12028fa..a6f2619 100644
65421--- a/fs/splice.c
65422+++ b/fs/splice.c
65423@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65424 pipe_lock(pipe);
65425
65426 for (;;) {
65427- if (!pipe->readers) {
65428+ if (!atomic_read(&pipe->readers)) {
65429 send_sig(SIGPIPE, current, 0);
65430 if (!ret)
65431 ret = -EPIPE;
65432@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65433 page_nr++;
65434 ret += buf->len;
65435
65436- if (pipe->files)
65437+ if (atomic_read(&pipe->files))
65438 do_wakeup = 1;
65439
65440 if (!--spd->nr_pages)
65441@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65442 do_wakeup = 0;
65443 }
65444
65445- pipe->waiting_writers++;
65446+ atomic_inc(&pipe->waiting_writers);
65447 pipe_wait(pipe);
65448- pipe->waiting_writers--;
65449+ atomic_dec(&pipe->waiting_writers);
65450 }
65451
65452 pipe_unlock(pipe);
65453@@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65454 old_fs = get_fs();
65455 set_fs(get_ds());
65456 /* The cast to a user pointer is valid due to the set_fs() */
65457- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65458+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65459 set_fs(old_fs);
65460
65461 return res;
65462@@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65463 old_fs = get_fs();
65464 set_fs(get_ds());
65465 /* The cast to a user pointer is valid due to the set_fs() */
65466- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65467+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65468 set_fs(old_fs);
65469
65470 return res;
65471@@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65472 goto err;
65473
65474 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65475- vec[i].iov_base = (void __user *) page_address(page);
65476+ vec[i].iov_base = (void __force_user *) page_address(page);
65477 vec[i].iov_len = this_len;
65478 spd.pages[i] = page;
65479 spd.nr_pages++;
65480@@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65481 ops->release(pipe, buf);
65482 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65483 pipe->nrbufs--;
65484- if (pipe->files)
65485+ if (atomic_read(&pipe->files))
65486 sd->need_wakeup = true;
65487 }
65488
65489@@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65490 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65491 {
65492 while (!pipe->nrbufs) {
65493- if (!pipe->writers)
65494+ if (!atomic_read(&pipe->writers))
65495 return 0;
65496
65497- if (!pipe->waiting_writers && sd->num_spliced)
65498+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65499 return 0;
65500
65501 if (sd->flags & SPLICE_F_NONBLOCK)
65502@@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65503 * out of the pipe right after the splice_to_pipe(). So set
65504 * PIPE_READERS appropriately.
65505 */
65506- pipe->readers = 1;
65507+ atomic_set(&pipe->readers, 1);
65508
65509 current->splice_pipe = pipe;
65510 }
65511@@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65512
65513 partial[buffers].offset = off;
65514 partial[buffers].len = plen;
65515+ partial[buffers].private = 0;
65516
65517 off = 0;
65518 len -= plen;
65519@@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65520 ret = -ERESTARTSYS;
65521 break;
65522 }
65523- if (!pipe->writers)
65524+ if (!atomic_read(&pipe->writers))
65525 break;
65526- if (!pipe->waiting_writers) {
65527+ if (!atomic_read(&pipe->waiting_writers)) {
65528 if (flags & SPLICE_F_NONBLOCK) {
65529 ret = -EAGAIN;
65530 break;
65531@@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65532 pipe_lock(pipe);
65533
65534 while (pipe->nrbufs >= pipe->buffers) {
65535- if (!pipe->readers) {
65536+ if (!atomic_read(&pipe->readers)) {
65537 send_sig(SIGPIPE, current, 0);
65538 ret = -EPIPE;
65539 break;
65540@@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65541 ret = -ERESTARTSYS;
65542 break;
65543 }
65544- pipe->waiting_writers++;
65545+ atomic_inc(&pipe->waiting_writers);
65546 pipe_wait(pipe);
65547- pipe->waiting_writers--;
65548+ atomic_dec(&pipe->waiting_writers);
65549 }
65550
65551 pipe_unlock(pipe);
65552@@ -1880,14 +1881,14 @@ retry:
65553 pipe_double_lock(ipipe, opipe);
65554
65555 do {
65556- if (!opipe->readers) {
65557+ if (!atomic_read(&opipe->readers)) {
65558 send_sig(SIGPIPE, current, 0);
65559 if (!ret)
65560 ret = -EPIPE;
65561 break;
65562 }
65563
65564- if (!ipipe->nrbufs && !ipipe->writers)
65565+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65566 break;
65567
65568 /*
65569@@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65570 pipe_double_lock(ipipe, opipe);
65571
65572 do {
65573- if (!opipe->readers) {
65574+ if (!atomic_read(&opipe->readers)) {
65575 send_sig(SIGPIPE, current, 0);
65576 if (!ret)
65577 ret = -EPIPE;
65578@@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65579 * return EAGAIN if we have the potential of some data in the
65580 * future, otherwise just return 0
65581 */
65582- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65583+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65584 ret = -EAGAIN;
65585
65586 pipe_unlock(ipipe);
65587diff --git a/fs/stat.c b/fs/stat.c
65588index ae0c3ce..9ee641c 100644
65589--- a/fs/stat.c
65590+++ b/fs/stat.c
65591@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65592 stat->gid = inode->i_gid;
65593 stat->rdev = inode->i_rdev;
65594 stat->size = i_size_read(inode);
65595- stat->atime = inode->i_atime;
65596- stat->mtime = inode->i_mtime;
65597+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65598+ stat->atime = inode->i_ctime;
65599+ stat->mtime = inode->i_ctime;
65600+ } else {
65601+ stat->atime = inode->i_atime;
65602+ stat->mtime = inode->i_mtime;
65603+ }
65604 stat->ctime = inode->i_ctime;
65605 stat->blksize = (1 << inode->i_blkbits);
65606 stat->blocks = inode->i_blocks;
65607@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65608 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65609 {
65610 struct inode *inode = path->dentry->d_inode;
65611+ int retval;
65612
65613- if (inode->i_op->getattr)
65614- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65615+ if (inode->i_op->getattr) {
65616+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65617+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65618+ stat->atime = stat->ctime;
65619+ stat->mtime = stat->ctime;
65620+ }
65621+ return retval;
65622+ }
65623
65624 generic_fillattr(inode, stat);
65625 return 0;
65626diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65627index ee0d761..b346c58 100644
65628--- a/fs/sysfs/dir.c
65629+++ b/fs/sysfs/dir.c
65630@@ -62,9 +62,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65631 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65632 {
65633 struct kernfs_node *parent, *kn;
65634+ const char *name;
65635+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65636+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65637+ const char *parent_name;
65638+#endif
65639
65640 BUG_ON(!kobj);
65641
65642+ name = kobject_name(kobj);
65643+
65644 if (kobj->parent)
65645 parent = kobj->parent->sd;
65646 else
65647@@ -73,11 +80,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65648 if (!parent)
65649 return -ENOENT;
65650
65651- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65652- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65653+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65654+ parent_name = parent->name;
65655+ mode = S_IRWXU;
65656+
65657+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65658+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65659+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65660+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65661+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65662+#endif
65663+
65664+ kn = kernfs_create_dir_ns(parent, name,
65665+ mode, kobj, ns);
65666 if (IS_ERR(kn)) {
65667 if (PTR_ERR(kn) == -EEXIST)
65668- sysfs_warn_dup(parent, kobject_name(kobj));
65669+ sysfs_warn_dup(parent, name);
65670 return PTR_ERR(kn);
65671 }
65672
65673diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
65674index 810cf6e..5fd2bf1 100644
65675--- a/fs/sysfs/file.c
65676+++ b/fs/sysfs/file.c
65677@@ -47,12 +47,13 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
65678 ssize_t count;
65679 char *buf;
65680
65681- /* acquire buffer and ensure that it's >= PAGE_SIZE */
65682+ /* acquire buffer and ensure that it's >= PAGE_SIZE and clear */
65683 count = seq_get_buf(sf, &buf);
65684 if (count < PAGE_SIZE) {
65685 seq_commit(sf, -1);
65686 return 0;
65687 }
65688+ memset(buf, 0, PAGE_SIZE);
65689
65690 /*
65691 * Invoke show(). Control may reach here via seq file lseek even
65692diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65693index 69d4889..a810bd4 100644
65694--- a/fs/sysv/sysv.h
65695+++ b/fs/sysv/sysv.h
65696@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65697 #endif
65698 }
65699
65700-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65701+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65702 {
65703 if (sbi->s_bytesex == BYTESEX_PDP)
65704 return PDP_swab((__force __u32)n);
65705diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65706index e18b988..f1d4ad0f 100644
65707--- a/fs/ubifs/io.c
65708+++ b/fs/ubifs/io.c
65709@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65710 return err;
65711 }
65712
65713-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65714+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65715 {
65716 int err;
65717
65718diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65719index c175b4d..8f36a16 100644
65720--- a/fs/udf/misc.c
65721+++ b/fs/udf/misc.c
65722@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65723
65724 u8 udf_tag_checksum(const struct tag *t)
65725 {
65726- u8 *data = (u8 *)t;
65727+ const u8 *data = (const u8 *)t;
65728 u8 checksum = 0;
65729 int i;
65730 for (i = 0; i < sizeof(struct tag); ++i)
65731diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65732index 8d974c4..b82f6ec 100644
65733--- a/fs/ufs/swab.h
65734+++ b/fs/ufs/swab.h
65735@@ -22,7 +22,7 @@ enum {
65736 BYTESEX_BE
65737 };
65738
65739-static inline u64
65740+static inline u64 __intentional_overflow(-1)
65741 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65742 {
65743 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65744@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65745 return (__force __fs64)cpu_to_be64(n);
65746 }
65747
65748-static inline u32
65749+static inline u32 __intentional_overflow(-1)
65750 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65751 {
65752 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65753diff --git a/fs/utimes.c b/fs/utimes.c
65754index aa138d6..5f3a811 100644
65755--- a/fs/utimes.c
65756+++ b/fs/utimes.c
65757@@ -1,6 +1,7 @@
65758 #include <linux/compiler.h>
65759 #include <linux/file.h>
65760 #include <linux/fs.h>
65761+#include <linux/security.h>
65762 #include <linux/linkage.h>
65763 #include <linux/mount.h>
65764 #include <linux/namei.h>
65765@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65766 }
65767 }
65768 retry_deleg:
65769+
65770+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65771+ error = -EACCES;
65772+ goto mnt_drop_write_and_out;
65773+ }
65774+
65775 mutex_lock(&inode->i_mutex);
65776 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65777 mutex_unlock(&inode->i_mutex);
65778diff --git a/fs/xattr.c b/fs/xattr.c
65779index 3377dff..f394815 100644
65780--- a/fs/xattr.c
65781+++ b/fs/xattr.c
65782@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65783 return rc;
65784 }
65785
65786+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65787+ssize_t
65788+pax_getxattr(struct dentry *dentry, void *value, size_t size)
65789+{
65790+ struct inode *inode = dentry->d_inode;
65791+ ssize_t error;
65792+
65793+ error = inode_permission(inode, MAY_EXEC);
65794+ if (error)
65795+ return error;
65796+
65797+ if (inode->i_op->getxattr)
65798+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65799+ else
65800+ error = -EOPNOTSUPP;
65801+
65802+ return error;
65803+}
65804+EXPORT_SYMBOL(pax_getxattr);
65805+#endif
65806+
65807 ssize_t
65808 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65809 {
65810@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65811 * Extended attribute SET operations
65812 */
65813 static long
65814-setxattr(struct dentry *d, const char __user *name, const void __user *value,
65815+setxattr(struct path *path, const char __user *name, const void __user *value,
65816 size_t size, int flags)
65817 {
65818 int error;
65819@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65820 posix_acl_fix_xattr_from_user(kvalue, size);
65821 }
65822
65823- error = vfs_setxattr(d, kname, kvalue, size, flags);
65824+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65825+ error = -EACCES;
65826+ goto out;
65827+ }
65828+
65829+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65830 out:
65831 if (vvalue)
65832 vfree(vvalue);
65833@@ -377,7 +403,7 @@ retry:
65834 return error;
65835 error = mnt_want_write(path.mnt);
65836 if (!error) {
65837- error = setxattr(path.dentry, name, value, size, flags);
65838+ error = setxattr(&path, name, value, size, flags);
65839 mnt_drop_write(path.mnt);
65840 }
65841 path_put(&path);
65842@@ -401,7 +427,7 @@ retry:
65843 return error;
65844 error = mnt_want_write(path.mnt);
65845 if (!error) {
65846- error = setxattr(path.dentry, name, value, size, flags);
65847+ error = setxattr(&path, name, value, size, flags);
65848 mnt_drop_write(path.mnt);
65849 }
65850 path_put(&path);
65851@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65852 const void __user *,value, size_t, size, int, flags)
65853 {
65854 struct fd f = fdget(fd);
65855- struct dentry *dentry;
65856 int error = -EBADF;
65857
65858 if (!f.file)
65859 return error;
65860- dentry = f.file->f_path.dentry;
65861- audit_inode(NULL, dentry, 0);
65862+ audit_inode(NULL, f.file->f_path.dentry, 0);
65863 error = mnt_want_write_file(f.file);
65864 if (!error) {
65865- error = setxattr(dentry, name, value, size, flags);
65866+ error = setxattr(&f.file->f_path, name, value, size, flags);
65867 mnt_drop_write_file(f.file);
65868 }
65869 fdput(f);
65870@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65871 * Extended attribute REMOVE operations
65872 */
65873 static long
65874-removexattr(struct dentry *d, const char __user *name)
65875+removexattr(struct path *path, const char __user *name)
65876 {
65877 int error;
65878 char kname[XATTR_NAME_MAX + 1];
65879@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65880 if (error < 0)
65881 return error;
65882
65883- return vfs_removexattr(d, kname);
65884+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65885+ return -EACCES;
65886+
65887+ return vfs_removexattr(path->dentry, kname);
65888 }
65889
65890 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65891@@ -652,7 +679,7 @@ retry:
65892 return error;
65893 error = mnt_want_write(path.mnt);
65894 if (!error) {
65895- error = removexattr(path.dentry, name);
65896+ error = removexattr(&path, name);
65897 mnt_drop_write(path.mnt);
65898 }
65899 path_put(&path);
65900@@ -675,7 +702,7 @@ retry:
65901 return error;
65902 error = mnt_want_write(path.mnt);
65903 if (!error) {
65904- error = removexattr(path.dentry, name);
65905+ error = removexattr(&path, name);
65906 mnt_drop_write(path.mnt);
65907 }
65908 path_put(&path);
65909@@ -689,16 +716,16 @@ retry:
65910 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65911 {
65912 struct fd f = fdget(fd);
65913- struct dentry *dentry;
65914+ struct path *path;
65915 int error = -EBADF;
65916
65917 if (!f.file)
65918 return error;
65919- dentry = f.file->f_path.dentry;
65920- audit_inode(NULL, dentry, 0);
65921+ path = &f.file->f_path;
65922+ audit_inode(NULL, path->dentry, 0);
65923 error = mnt_want_write_file(f.file);
65924 if (!error) {
65925- error = removexattr(dentry, name);
65926+ error = removexattr(path, name);
65927 mnt_drop_write_file(f.file);
65928 }
65929 fdput(f);
65930diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65931index 152543c..d80c361 100644
65932--- a/fs/xfs/xfs_bmap.c
65933+++ b/fs/xfs/xfs_bmap.c
65934@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65935
65936 #else
65937 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65938-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65939+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65940 #endif /* DEBUG */
65941
65942 /*
65943diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65944index aead369..0dfecfd 100644
65945--- a/fs/xfs/xfs_dir2_readdir.c
65946+++ b/fs/xfs/xfs_dir2_readdir.c
65947@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65948 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65949 filetype = dp->d_ops->sf_get_ftype(sfep);
65950 ctx->pos = off & 0x7fffffff;
65951- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65952+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65953+ char name[sfep->namelen];
65954+ memcpy(name, sfep->name, sfep->namelen);
65955+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65956+ return 0;
65957+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65958 xfs_dir3_get_dtype(mp, filetype)))
65959 return 0;
65960 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65961diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65962index bcfe612..aa399c0 100644
65963--- a/fs/xfs/xfs_ioctl.c
65964+++ b/fs/xfs/xfs_ioctl.c
65965@@ -122,7 +122,7 @@ xfs_find_handle(
65966 }
65967
65968 error = -EFAULT;
65969- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65970+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65971 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65972 goto out_put;
65973
65974diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65975new file mode 100644
65976index 0000000..a14eb52
65977--- /dev/null
65978+++ b/grsecurity/Kconfig
65979@@ -0,0 +1,1174 @@
65980+#
65981+# grecurity configuration
65982+#
65983+menu "Memory Protections"
65984+depends on GRKERNSEC
65985+
65986+config GRKERNSEC_KMEM
65987+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65988+ default y if GRKERNSEC_CONFIG_AUTO
65989+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65990+ help
65991+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65992+ be written to or read from to modify or leak the contents of the running
65993+ kernel. /dev/port will also not be allowed to be opened, writing to
65994+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65995+ If you have module support disabled, enabling this will close up several
65996+ ways that are currently used to insert malicious code into the running
65997+ kernel.
65998+
65999+ Even with this feature enabled, we still highly recommend that
66000+ you use the RBAC system, as it is still possible for an attacker to
66001+ modify the running kernel through other more obscure methods.
66002+
66003+ It is highly recommended that you say Y here if you meet all the
66004+ conditions above.
66005+
66006+config GRKERNSEC_VM86
66007+ bool "Restrict VM86 mode"
66008+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66009+ depends on X86_32
66010+
66011+ help
66012+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
66013+ make use of a special execution mode on 32bit x86 processors called
66014+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
66015+ video cards and will still work with this option enabled. The purpose
66016+ of the option is to prevent exploitation of emulation errors in
66017+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
66018+ Nearly all users should be able to enable this option.
66019+
66020+config GRKERNSEC_IO
66021+ bool "Disable privileged I/O"
66022+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66023+ depends on X86
66024+ select RTC_CLASS
66025+ select RTC_INTF_DEV
66026+ select RTC_DRV_CMOS
66027+
66028+ help
66029+ If you say Y here, all ioperm and iopl calls will return an error.
66030+ Ioperm and iopl can be used to modify the running kernel.
66031+ Unfortunately, some programs need this access to operate properly,
66032+ the most notable of which are XFree86 and hwclock. hwclock can be
66033+ remedied by having RTC support in the kernel, so real-time
66034+ clock support is enabled if this option is enabled, to ensure
66035+ that hwclock operates correctly. If hwclock still does not work,
66036+ either update udev or symlink /dev/rtc to /dev/rtc0.
66037+
66038+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
66039+ you may not be able to boot into a graphical environment with this
66040+ option enabled. In this case, you should use the RBAC system instead.
66041+
66042+config GRKERNSEC_JIT_HARDEN
66043+ bool "Harden BPF JIT against spray attacks"
66044+ default y if GRKERNSEC_CONFIG_AUTO
66045+ depends on BPF_JIT && X86
66046+ help
66047+ If you say Y here, the native code generated by the kernel's Berkeley
66048+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
66049+ attacks that attempt to fit attacker-beneficial instructions in
66050+ 32bit immediate fields of JIT-generated native instructions. The
66051+ attacker will generally aim to cause an unintended instruction sequence
66052+ of JIT-generated native code to execute by jumping into the middle of
66053+ a generated instruction. This feature effectively randomizes the 32bit
66054+ immediate constants present in the generated code to thwart such attacks.
66055+
66056+ If you're using KERNEXEC, it's recommended that you enable this option
66057+ to supplement the hardening of the kernel.
66058+
66059+config GRKERNSEC_PERF_HARDEN
66060+ bool "Disable unprivileged PERF_EVENTS usage by default"
66061+ default y if GRKERNSEC_CONFIG_AUTO
66062+ depends on PERF_EVENTS
66063+ help
66064+ If you say Y here, the range of acceptable values for the
66065+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
66066+ default to a new value: 3. When the sysctl is set to this value, no
66067+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
66068+
66069+ Though PERF_EVENTS can be used legitimately for performance monitoring
66070+ and low-level application profiling, it is forced on regardless of
66071+ configuration, has been at fault for several vulnerabilities, and
66072+ creates new opportunities for side channels and other information leaks.
66073+
66074+ This feature puts PERF_EVENTS into a secure default state and permits
66075+ the administrator to change out of it temporarily if unprivileged
66076+ application profiling is needed.
66077+
66078+config GRKERNSEC_RAND_THREADSTACK
66079+ bool "Insert random gaps between thread stacks"
66080+ default y if GRKERNSEC_CONFIG_AUTO
66081+ depends on PAX_RANDMMAP && !PPC
66082+ help
66083+ If you say Y here, a random-sized gap will be enforced between allocated
66084+ thread stacks. Glibc's NPTL and other threading libraries that
66085+ pass MAP_STACK to the kernel for thread stack allocation are supported.
66086+ The implementation currently provides 8 bits of entropy for the gap.
66087+
66088+ Many distributions do not compile threaded remote services with the
66089+ -fstack-check argument to GCC, causing the variable-sized stack-based
66090+ allocator, alloca(), to not probe the stack on allocation. This
66091+ permits an unbounded alloca() to skip over any guard page and potentially
66092+ modify another thread's stack reliably. An enforced random gap
66093+ reduces the reliability of such an attack and increases the chance
66094+ that such a read/write to another thread's stack instead lands in
66095+ an unmapped area, causing a crash and triggering grsecurity's
66096+ anti-bruteforcing logic.
66097+
66098+config GRKERNSEC_PROC_MEMMAP
66099+ bool "Harden ASLR against information leaks and entropy reduction"
66100+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
66101+ depends on PAX_NOEXEC || PAX_ASLR
66102+ help
66103+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
66104+ give no information about the addresses of its mappings if
66105+ PaX features that rely on random addresses are enabled on the task.
66106+ In addition to sanitizing this information and disabling other
66107+ dangerous sources of information, this option causes reads of sensitive
66108+ /proc/<pid> entries where the file descriptor was opened in a different
66109+ task than the one performing the read. Such attempts are logged.
66110+ This option also limits argv/env strings for suid/sgid binaries
66111+ to 512KB to prevent a complete exhaustion of the stack entropy provided
66112+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
66113+ binaries to prevent alternative mmap layouts from being abused.
66114+
66115+ If you use PaX it is essential that you say Y here as it closes up
66116+ several holes that make full ASLR useless locally.
66117+
66118+
66119+config GRKERNSEC_KSTACKOVERFLOW
66120+ bool "Prevent kernel stack overflows"
66121+ default y if GRKERNSEC_CONFIG_AUTO
66122+ depends on !IA64 && 64BIT
66123+ help
66124+ If you say Y here, the kernel's process stacks will be allocated
66125+ with vmalloc instead of the kernel's default allocator. This
66126+ introduces guard pages that in combination with the alloca checking
66127+ of the STACKLEAK feature prevents all forms of kernel process stack
66128+ overflow abuse. Note that this is different from kernel stack
66129+ buffer overflows.
66130+
66131+config GRKERNSEC_BRUTE
66132+ bool "Deter exploit bruteforcing"
66133+ default y if GRKERNSEC_CONFIG_AUTO
66134+ help
66135+ If you say Y here, attempts to bruteforce exploits against forking
66136+ daemons such as apache or sshd, as well as against suid/sgid binaries
66137+ will be deterred. When a child of a forking daemon is killed by PaX
66138+ or crashes due to an illegal instruction or other suspicious signal,
66139+ the parent process will be delayed 30 seconds upon every subsequent
66140+ fork until the administrator is able to assess the situation and
66141+ restart the daemon.
66142+ In the suid/sgid case, the attempt is logged, the user has all their
66143+ existing instances of the suid/sgid binary terminated and will
66144+ be unable to execute any suid/sgid binaries for 15 minutes.
66145+
66146+ It is recommended that you also enable signal logging in the auditing
66147+ section so that logs are generated when a process triggers a suspicious
66148+ signal.
66149+ If the sysctl option is enabled, a sysctl option with name
66150+ "deter_bruteforce" is created.
66151+
66152+config GRKERNSEC_MODHARDEN
66153+ bool "Harden module auto-loading"
66154+ default y if GRKERNSEC_CONFIG_AUTO
66155+ depends on MODULES
66156+ help
66157+ If you say Y here, module auto-loading in response to use of some
66158+ feature implemented by an unloaded module will be restricted to
66159+ root users. Enabling this option helps defend against attacks
66160+ by unprivileged users who abuse the auto-loading behavior to
66161+ cause a vulnerable module to load that is then exploited.
66162+
66163+ If this option prevents a legitimate use of auto-loading for a
66164+ non-root user, the administrator can execute modprobe manually
66165+ with the exact name of the module mentioned in the alert log.
66166+ Alternatively, the administrator can add the module to the list
66167+ of modules loaded at boot by modifying init scripts.
66168+
66169+ Modification of init scripts will most likely be needed on
66170+ Ubuntu servers with encrypted home directory support enabled,
66171+ as the first non-root user logging in will cause the ecb(aes),
66172+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
66173+
66174+config GRKERNSEC_HIDESYM
66175+ bool "Hide kernel symbols"
66176+ default y if GRKERNSEC_CONFIG_AUTO
66177+ select PAX_USERCOPY_SLABS
66178+ help
66179+ If you say Y here, getting information on loaded modules, and
66180+ displaying all kernel symbols through a syscall will be restricted
66181+ to users with CAP_SYS_MODULE. For software compatibility reasons,
66182+ /proc/kallsyms will be restricted to the root user. The RBAC
66183+ system can hide that entry even from root.
66184+
66185+ This option also prevents leaking of kernel addresses through
66186+ several /proc entries.
66187+
66188+ Note that this option is only effective provided the following
66189+ conditions are met:
66190+ 1) The kernel using grsecurity is not precompiled by some distribution
66191+ 2) You have also enabled GRKERNSEC_DMESG
66192+ 3) You are using the RBAC system and hiding other files such as your
66193+ kernel image and System.map. Alternatively, enabling this option
66194+ causes the permissions on /boot, /lib/modules, and the kernel
66195+ source directory to change at compile time to prevent
66196+ reading by non-root users.
66197+ If the above conditions are met, this option will aid in providing a
66198+ useful protection against local kernel exploitation of overflows
66199+ and arbitrary read/write vulnerabilities.
66200+
66201+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
66202+ in addition to this feature.
66203+
66204+config GRKERNSEC_RANDSTRUCT
66205+ bool "Randomize layout of sensitive kernel structures"
66206+ default y if GRKERNSEC_CONFIG_AUTO
66207+ select GRKERNSEC_HIDESYM
66208+ select MODVERSIONS if MODULES
66209+ help
66210+ If you say Y here, the layouts of a number of sensitive kernel
66211+ structures (task, fs, cred, etc) and all structures composed entirely
66212+ of function pointers (aka "ops" structs) will be randomized at compile-time.
66213+ This can introduce the requirement of an additional infoleak
66214+ vulnerability for exploits targeting these structure types.
66215+
66216+ Enabling this feature will introduce some performance impact, slightly
66217+ increase memory usage, and prevent the use of forensic tools like
66218+ Volatility against the system (unless the kernel source tree isn't
66219+ cleaned after kernel installation).
66220+
66221+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
66222+ It remains after a make clean to allow for external modules to be compiled
66223+ with the existing seed and will be removed by a make mrproper or
66224+ make distclean.
66225+
66226+ Note that the implementation requires gcc 4.6.4. or newer. You may need
66227+ to install the supporting headers explicitly in addition to the normal
66228+ gcc package.
66229+
66230+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
66231+ bool "Use cacheline-aware structure randomization"
66232+ depends on GRKERNSEC_RANDSTRUCT
66233+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
66234+ help
66235+ If you say Y here, the RANDSTRUCT randomization will make a best effort
66236+ at restricting randomization to cacheline-sized groups of elements. It
66237+ will further not randomize bitfields in structures. This reduces the
66238+ performance hit of RANDSTRUCT at the cost of weakened randomization.
66239+
66240+config GRKERNSEC_KERN_LOCKOUT
66241+ bool "Active kernel exploit response"
66242+ default y if GRKERNSEC_CONFIG_AUTO
66243+ depends on X86 || ARM || PPC || SPARC
66244+ help
66245+ If you say Y here, when a PaX alert is triggered due to suspicious
66246+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
66247+ or an OOPS occurs due to bad memory accesses, instead of just
66248+ terminating the offending process (and potentially allowing
66249+ a subsequent exploit from the same user), we will take one of two
66250+ actions:
66251+ If the user was root, we will panic the system
66252+ If the user was non-root, we will log the attempt, terminate
66253+ all processes owned by the user, then prevent them from creating
66254+ any new processes until the system is restarted
66255+ This deters repeated kernel exploitation/bruteforcing attempts
66256+ and is useful for later forensics.
66257+
66258+config GRKERNSEC_OLD_ARM_USERLAND
66259+ bool "Old ARM userland compatibility"
66260+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
66261+ help
66262+ If you say Y here, stubs of executable code to perform such operations
66263+ as "compare-exchange" will be placed at fixed locations in the ARM vector
66264+ table. This is unfortunately needed for old ARM userland meant to run
66265+ across a wide range of processors. Without this option enabled,
66266+ the get_tls and data memory barrier stubs will be emulated by the kernel,
66267+ which is enough for Linaro userlands or other userlands designed for v6
66268+ and newer ARM CPUs. It's recommended that you try without this option enabled
66269+ first, and only enable it if your userland does not boot (it will likely fail
66270+ at init time).
66271+
66272+endmenu
66273+menu "Role Based Access Control Options"
66274+depends on GRKERNSEC
66275+
66276+config GRKERNSEC_RBAC_DEBUG
66277+ bool
66278+
66279+config GRKERNSEC_NO_RBAC
66280+ bool "Disable RBAC system"
66281+ help
66282+ If you say Y here, the /dev/grsec device will be removed from the kernel,
66283+ preventing the RBAC system from being enabled. You should only say Y
66284+ here if you have no intention of using the RBAC system, so as to prevent
66285+ an attacker with root access from misusing the RBAC system to hide files
66286+ and processes when loadable module support and /dev/[k]mem have been
66287+ locked down.
66288+
66289+config GRKERNSEC_ACL_HIDEKERN
66290+ bool "Hide kernel processes"
66291+ help
66292+ If you say Y here, all kernel threads will be hidden to all
66293+ processes but those whose subject has the "view hidden processes"
66294+ flag.
66295+
66296+config GRKERNSEC_ACL_MAXTRIES
66297+ int "Maximum tries before password lockout"
66298+ default 3
66299+ help
66300+ This option enforces the maximum number of times a user can attempt
66301+ to authorize themselves with the grsecurity RBAC system before being
66302+ denied the ability to attempt authorization again for a specified time.
66303+ The lower the number, the harder it will be to brute-force a password.
66304+
66305+config GRKERNSEC_ACL_TIMEOUT
66306+ int "Time to wait after max password tries, in seconds"
66307+ default 30
66308+ help
66309+ This option specifies the time the user must wait after attempting to
66310+ authorize to the RBAC system with the maximum number of invalid
66311+ passwords. The higher the number, the harder it will be to brute-force
66312+ a password.
66313+
66314+endmenu
66315+menu "Filesystem Protections"
66316+depends on GRKERNSEC
66317+
66318+config GRKERNSEC_PROC
66319+ bool "Proc restrictions"
66320+ default y if GRKERNSEC_CONFIG_AUTO
66321+ help
66322+ If you say Y here, the permissions of the /proc filesystem
66323+ will be altered to enhance system security and privacy. You MUST
66324+ choose either a user only restriction or a user and group restriction.
66325+ Depending upon the option you choose, you can either restrict users to
66326+ see only the processes they themselves run, or choose a group that can
66327+ view all processes and files normally restricted to root if you choose
66328+ the "restrict to user only" option. NOTE: If you're running identd or
66329+ ntpd as a non-root user, you will have to run it as the group you
66330+ specify here.
66331+
66332+config GRKERNSEC_PROC_USER
66333+ bool "Restrict /proc to user only"
66334+ depends on GRKERNSEC_PROC
66335+ help
66336+ If you say Y here, non-root users will only be able to view their own
66337+ processes, and restricts them from viewing network-related information,
66338+ and viewing kernel symbol and module information.
66339+
66340+config GRKERNSEC_PROC_USERGROUP
66341+ bool "Allow special group"
66342+ default y if GRKERNSEC_CONFIG_AUTO
66343+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
66344+ help
66345+ If you say Y here, you will be able to select a group that will be
66346+ able to view all processes and network-related information. If you've
66347+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
66348+ remain hidden. This option is useful if you want to run identd as
66349+ a non-root user. The group you select may also be chosen at boot time
66350+ via "grsec_proc_gid=" on the kernel commandline.
66351+
66352+config GRKERNSEC_PROC_GID
66353+ int "GID for special group"
66354+ depends on GRKERNSEC_PROC_USERGROUP
66355+ default 1001
66356+
66357+config GRKERNSEC_PROC_ADD
66358+ bool "Additional restrictions"
66359+ default y if GRKERNSEC_CONFIG_AUTO
66360+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
66361+ help
66362+ If you say Y here, additional restrictions will be placed on
66363+ /proc that keep normal users from viewing device information and
66364+ slabinfo information that could be useful for exploits.
66365+
66366+config GRKERNSEC_LINK
66367+ bool "Linking restrictions"
66368+ default y if GRKERNSEC_CONFIG_AUTO
66369+ help
66370+ If you say Y here, /tmp race exploits will be prevented, since users
66371+ will no longer be able to follow symlinks owned by other users in
66372+ world-writable +t directories (e.g. /tmp), unless the owner of the
66373+ symlink is the owner of the directory. users will also not be
66374+ able to hardlink to files they do not own. If the sysctl option is
66375+ enabled, a sysctl option with name "linking_restrictions" is created.
66376+
66377+config GRKERNSEC_SYMLINKOWN
66378+ bool "Kernel-enforced SymlinksIfOwnerMatch"
66379+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66380+ help
66381+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
66382+ that prevents it from being used as a security feature. As Apache
66383+ verifies the symlink by performing a stat() against the target of
66384+ the symlink before it is followed, an attacker can setup a symlink
66385+ to point to a same-owned file, then replace the symlink with one
66386+ that targets another user's file just after Apache "validates" the
66387+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
66388+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
66389+ will be in place for the group you specify. If the sysctl option
66390+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
66391+ created.
66392+
66393+config GRKERNSEC_SYMLINKOWN_GID
66394+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66395+ depends on GRKERNSEC_SYMLINKOWN
66396+ default 1006
66397+ help
66398+ Setting this GID determines what group kernel-enforced
66399+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66400+ is enabled, a sysctl option with name "symlinkown_gid" is created.
66401+
66402+config GRKERNSEC_FIFO
66403+ bool "FIFO restrictions"
66404+ default y if GRKERNSEC_CONFIG_AUTO
66405+ help
66406+ If you say Y here, users will not be able to write to FIFOs they don't
66407+ own in world-writable +t directories (e.g. /tmp), unless the owner of
66408+ the FIFO is the same owner of the directory it's held in. If the sysctl
66409+ option is enabled, a sysctl option with name "fifo_restrictions" is
66410+ created.
66411+
66412+config GRKERNSEC_SYSFS_RESTRICT
66413+ bool "Sysfs/debugfs restriction"
66414+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66415+ depends on SYSFS
66416+ help
66417+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66418+ any filesystem normally mounted under it (e.g. debugfs) will be
66419+ mostly accessible only by root. These filesystems generally provide access
66420+ to hardware and debug information that isn't appropriate for unprivileged
66421+ users of the system. Sysfs and debugfs have also become a large source
66422+ of new vulnerabilities, ranging from infoleaks to local compromise.
66423+ There has been very little oversight with an eye toward security involved
66424+ in adding new exporters of information to these filesystems, so their
66425+ use is discouraged.
66426+ For reasons of compatibility, a few directories have been whitelisted
66427+ for access by non-root users:
66428+ /sys/fs/selinux
66429+ /sys/fs/fuse
66430+ /sys/devices/system/cpu
66431+
66432+config GRKERNSEC_ROFS
66433+ bool "Runtime read-only mount protection"
66434+ depends on SYSCTL
66435+ help
66436+ If you say Y here, a sysctl option with name "romount_protect" will
66437+ be created. By setting this option to 1 at runtime, filesystems
66438+ will be protected in the following ways:
66439+ * No new writable mounts will be allowed
66440+ * Existing read-only mounts won't be able to be remounted read/write
66441+ * Write operations will be denied on all block devices
66442+ This option acts independently of grsec_lock: once it is set to 1,
66443+ it cannot be turned off. Therefore, please be mindful of the resulting
66444+ behavior if this option is enabled in an init script on a read-only
66445+ filesystem.
66446+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66447+ and GRKERNSEC_IO should be enabled and module loading disabled via
66448+ config or at runtime.
66449+ This feature is mainly intended for secure embedded systems.
66450+
66451+
66452+config GRKERNSEC_DEVICE_SIDECHANNEL
66453+ bool "Eliminate stat/notify-based device sidechannels"
66454+ default y if GRKERNSEC_CONFIG_AUTO
66455+ help
66456+ If you say Y here, timing analyses on block or character
66457+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66458+ will be thwarted for unprivileged users. If a process without
66459+ CAP_MKNOD stats such a device, the last access and last modify times
66460+ will match the device's create time. No access or modify events
66461+ will be triggered through inotify/dnotify/fanotify for such devices.
66462+ This feature will prevent attacks that may at a minimum
66463+ allow an attacker to determine the administrator's password length.
66464+
66465+config GRKERNSEC_CHROOT
66466+ bool "Chroot jail restrictions"
66467+ default y if GRKERNSEC_CONFIG_AUTO
66468+ help
66469+ If you say Y here, you will be able to choose several options that will
66470+ make breaking out of a chrooted jail much more difficult. If you
66471+ encounter no software incompatibilities with the following options, it
66472+ is recommended that you enable each one.
66473+
66474+ Note that the chroot restrictions are not intended to apply to "chroots"
66475+ to directories that are simple bind mounts of the global root filesystem.
66476+ For several other reasons, a user shouldn't expect any significant
66477+ security by performing such a chroot.
66478+
66479+config GRKERNSEC_CHROOT_MOUNT
66480+ bool "Deny mounts"
66481+ default y if GRKERNSEC_CONFIG_AUTO
66482+ depends on GRKERNSEC_CHROOT
66483+ help
66484+ If you say Y here, processes inside a chroot will not be able to
66485+ mount or remount filesystems. If the sysctl option is enabled, a
66486+ sysctl option with name "chroot_deny_mount" is created.
66487+
66488+config GRKERNSEC_CHROOT_DOUBLE
66489+ bool "Deny double-chroots"
66490+ default y if GRKERNSEC_CONFIG_AUTO
66491+ depends on GRKERNSEC_CHROOT
66492+ help
66493+ If you say Y here, processes inside a chroot will not be able to chroot
66494+ again outside the chroot. This is a widely used method of breaking
66495+ out of a chroot jail and should not be allowed. If the sysctl
66496+ option is enabled, a sysctl option with name
66497+ "chroot_deny_chroot" is created.
66498+
66499+config GRKERNSEC_CHROOT_PIVOT
66500+ bool "Deny pivot_root in chroot"
66501+ default y if GRKERNSEC_CONFIG_AUTO
66502+ depends on GRKERNSEC_CHROOT
66503+ help
66504+ If you say Y here, processes inside a chroot will not be able to use
66505+ a function called pivot_root() that was introduced in Linux 2.3.41. It
66506+ works similar to chroot in that it changes the root filesystem. This
66507+ function could be misused in a chrooted process to attempt to break out
66508+ of the chroot, and therefore should not be allowed. If the sysctl
66509+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
66510+ created.
66511+
66512+config GRKERNSEC_CHROOT_CHDIR
66513+ bool "Enforce chdir(\"/\") on all chroots"
66514+ default y if GRKERNSEC_CONFIG_AUTO
66515+ depends on GRKERNSEC_CHROOT
66516+ help
66517+ If you say Y here, the current working directory of all newly-chrooted
66518+ applications will be set to the the root directory of the chroot.
66519+ The man page on chroot(2) states:
66520+ Note that this call does not change the current working
66521+ directory, so that `.' can be outside the tree rooted at
66522+ `/'. In particular, the super-user can escape from a
66523+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66524+
66525+ It is recommended that you say Y here, since it's not known to break
66526+ any software. If the sysctl option is enabled, a sysctl option with
66527+ name "chroot_enforce_chdir" is created.
66528+
66529+config GRKERNSEC_CHROOT_CHMOD
66530+ bool "Deny (f)chmod +s"
66531+ default y if GRKERNSEC_CONFIG_AUTO
66532+ depends on GRKERNSEC_CHROOT
66533+ help
66534+ If you say Y here, processes inside a chroot will not be able to chmod
66535+ or fchmod files to make them have suid or sgid bits. This protects
66536+ against another published method of breaking a chroot. If the sysctl
66537+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
66538+ created.
66539+
66540+config GRKERNSEC_CHROOT_FCHDIR
66541+ bool "Deny fchdir out of chroot"
66542+ default y if GRKERNSEC_CONFIG_AUTO
66543+ depends on GRKERNSEC_CHROOT
66544+ help
66545+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
66546+ to a file descriptor of the chrooting process that points to a directory
66547+ outside the filesystem will be stopped. If the sysctl option
66548+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
66549+
66550+config GRKERNSEC_CHROOT_MKNOD
66551+ bool "Deny mknod"
66552+ default y if GRKERNSEC_CONFIG_AUTO
66553+ depends on GRKERNSEC_CHROOT
66554+ help
66555+ If you say Y here, processes inside a chroot will not be allowed to
66556+ mknod. The problem with using mknod inside a chroot is that it
66557+ would allow an attacker to create a device entry that is the same
66558+ as one on the physical root of your system, which could range from
66559+ anything from the console device to a device for your harddrive (which
66560+ they could then use to wipe the drive or steal data). It is recommended
66561+ that you say Y here, unless you run into software incompatibilities.
66562+ If the sysctl option is enabled, a sysctl option with name
66563+ "chroot_deny_mknod" is created.
66564+
66565+config GRKERNSEC_CHROOT_SHMAT
66566+ bool "Deny shmat() out of chroot"
66567+ default y if GRKERNSEC_CONFIG_AUTO
66568+ depends on GRKERNSEC_CHROOT
66569+ help
66570+ If you say Y here, processes inside a chroot will not be able to attach
66571+ to shared memory segments that were created outside of the chroot jail.
66572+ It is recommended that you say Y here. If the sysctl option is enabled,
66573+ a sysctl option with name "chroot_deny_shmat" is created.
66574+
66575+config GRKERNSEC_CHROOT_UNIX
66576+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
66577+ default y if GRKERNSEC_CONFIG_AUTO
66578+ depends on GRKERNSEC_CHROOT
66579+ help
66580+ If you say Y here, processes inside a chroot will not be able to
66581+ connect to abstract (meaning not belonging to a filesystem) Unix
66582+ domain sockets that were bound outside of a chroot. It is recommended
66583+ that you say Y here. If the sysctl option is enabled, a sysctl option
66584+ with name "chroot_deny_unix" is created.
66585+
66586+config GRKERNSEC_CHROOT_FINDTASK
66587+ bool "Protect outside processes"
66588+ default y if GRKERNSEC_CONFIG_AUTO
66589+ depends on GRKERNSEC_CHROOT
66590+ help
66591+ If you say Y here, processes inside a chroot will not be able to
66592+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66593+ getsid, or view any process outside of the chroot. If the sysctl
66594+ option is enabled, a sysctl option with name "chroot_findtask" is
66595+ created.
66596+
66597+config GRKERNSEC_CHROOT_NICE
66598+ bool "Restrict priority changes"
66599+ default y if GRKERNSEC_CONFIG_AUTO
66600+ depends on GRKERNSEC_CHROOT
66601+ help
66602+ If you say Y here, processes inside a chroot will not be able to raise
66603+ the priority of processes in the chroot, or alter the priority of
66604+ processes outside the chroot. This provides more security than simply
66605+ removing CAP_SYS_NICE from the process' capability set. If the
66606+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66607+ is created.
66608+
66609+config GRKERNSEC_CHROOT_SYSCTL
66610+ bool "Deny sysctl writes"
66611+ default y if GRKERNSEC_CONFIG_AUTO
66612+ depends on GRKERNSEC_CHROOT
66613+ help
66614+ If you say Y here, an attacker in a chroot will not be able to
66615+ write to sysctl entries, either by sysctl(2) or through a /proc
66616+ interface. It is strongly recommended that you say Y here. If the
66617+ sysctl option is enabled, a sysctl option with name
66618+ "chroot_deny_sysctl" is created.
66619+
66620+config GRKERNSEC_CHROOT_CAPS
66621+ bool "Capability restrictions"
66622+ default y if GRKERNSEC_CONFIG_AUTO
66623+ depends on GRKERNSEC_CHROOT
66624+ help
66625+ If you say Y here, the capabilities on all processes within a
66626+ chroot jail will be lowered to stop module insertion, raw i/o,
66627+ system and net admin tasks, rebooting the system, modifying immutable
66628+ files, modifying IPC owned by another, and changing the system time.
66629+ This is left an option because it can break some apps. Disable this
66630+ if your chrooted apps are having problems performing those kinds of
66631+ tasks. If the sysctl option is enabled, a sysctl option with
66632+ name "chroot_caps" is created.
66633+
66634+config GRKERNSEC_CHROOT_INITRD
66635+ bool "Exempt initrd tasks from restrictions"
66636+ default y if GRKERNSEC_CONFIG_AUTO
66637+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66638+ help
66639+ If you say Y here, tasks started prior to init will be exempted from
66640+ grsecurity's chroot restrictions. This option is mainly meant to
66641+ resolve Plymouth's performing privileged operations unnecessarily
66642+ in a chroot.
66643+
66644+endmenu
66645+menu "Kernel Auditing"
66646+depends on GRKERNSEC
66647+
66648+config GRKERNSEC_AUDIT_GROUP
66649+ bool "Single group for auditing"
66650+ help
66651+ If you say Y here, the exec and chdir logging features will only operate
66652+ on a group you specify. This option is recommended if you only want to
66653+ watch certain users instead of having a large amount of logs from the
66654+ entire system. If the sysctl option is enabled, a sysctl option with
66655+ name "audit_group" is created.
66656+
66657+config GRKERNSEC_AUDIT_GID
66658+ int "GID for auditing"
66659+ depends on GRKERNSEC_AUDIT_GROUP
66660+ default 1007
66661+
66662+config GRKERNSEC_EXECLOG
66663+ bool "Exec logging"
66664+ help
66665+ If you say Y here, all execve() calls will be logged (since the
66666+ other exec*() calls are frontends to execve(), all execution
66667+ will be logged). Useful for shell-servers that like to keep track
66668+ of their users. If the sysctl option is enabled, a sysctl option with
66669+ name "exec_logging" is created.
66670+ WARNING: This option when enabled will produce a LOT of logs, especially
66671+ on an active system.
66672+
66673+config GRKERNSEC_RESLOG
66674+ bool "Resource logging"
66675+ default y if GRKERNSEC_CONFIG_AUTO
66676+ help
66677+ If you say Y here, all attempts to overstep resource limits will
66678+ be logged with the resource name, the requested size, and the current
66679+ limit. It is highly recommended that you say Y here. If the sysctl
66680+ option is enabled, a sysctl option with name "resource_logging" is
66681+ created. If the RBAC system is enabled, the sysctl value is ignored.
66682+
66683+config GRKERNSEC_CHROOT_EXECLOG
66684+ bool "Log execs within chroot"
66685+ help
66686+ If you say Y here, all executions inside a chroot jail will be logged
66687+ to syslog. This can cause a large amount of logs if certain
66688+ applications (eg. djb's daemontools) are installed on the system, and
66689+ is therefore left as an option. If the sysctl option is enabled, a
66690+ sysctl option with name "chroot_execlog" is created.
66691+
66692+config GRKERNSEC_AUDIT_PTRACE
66693+ bool "Ptrace logging"
66694+ help
66695+ If you say Y here, all attempts to attach to a process via ptrace
66696+ will be logged. If the sysctl option is enabled, a sysctl option
66697+ with name "audit_ptrace" is created.
66698+
66699+config GRKERNSEC_AUDIT_CHDIR
66700+ bool "Chdir logging"
66701+ help
66702+ If you say Y here, all chdir() calls will be logged. If the sysctl
66703+ option is enabled, a sysctl option with name "audit_chdir" is created.
66704+
66705+config GRKERNSEC_AUDIT_MOUNT
66706+ bool "(Un)Mount logging"
66707+ help
66708+ If you say Y here, all mounts and unmounts will be logged. If the
66709+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66710+ created.
66711+
66712+config GRKERNSEC_SIGNAL
66713+ bool "Signal logging"
66714+ default y if GRKERNSEC_CONFIG_AUTO
66715+ help
66716+ If you say Y here, certain important signals will be logged, such as
66717+ SIGSEGV, which will as a result inform you of when a error in a program
66718+ occurred, which in some cases could mean a possible exploit attempt.
66719+ If the sysctl option is enabled, a sysctl option with name
66720+ "signal_logging" is created.
66721+
66722+config GRKERNSEC_FORKFAIL
66723+ bool "Fork failure logging"
66724+ help
66725+ If you say Y here, all failed fork() attempts will be logged.
66726+ This could suggest a fork bomb, or someone attempting to overstep
66727+ their process limit. If the sysctl option is enabled, a sysctl option
66728+ with name "forkfail_logging" is created.
66729+
66730+config GRKERNSEC_TIME
66731+ bool "Time change logging"
66732+ default y if GRKERNSEC_CONFIG_AUTO
66733+ help
66734+ If you say Y here, any changes of the system clock will be logged.
66735+ If the sysctl option is enabled, a sysctl option with name
66736+ "timechange_logging" is created.
66737+
66738+config GRKERNSEC_PROC_IPADDR
66739+ bool "/proc/<pid>/ipaddr support"
66740+ default y if GRKERNSEC_CONFIG_AUTO
66741+ help
66742+ If you say Y here, a new entry will be added to each /proc/<pid>
66743+ directory that contains the IP address of the person using the task.
66744+ The IP is carried across local TCP and AF_UNIX stream sockets.
66745+ This information can be useful for IDS/IPSes to perform remote response
66746+ to a local attack. The entry is readable by only the owner of the
66747+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66748+ the RBAC system), and thus does not create privacy concerns.
66749+
66750+config GRKERNSEC_RWXMAP_LOG
66751+ bool 'Denied RWX mmap/mprotect logging'
66752+ default y if GRKERNSEC_CONFIG_AUTO
66753+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66754+ help
66755+ If you say Y here, calls to mmap() and mprotect() with explicit
66756+ usage of PROT_WRITE and PROT_EXEC together will be logged when
66757+ denied by the PAX_MPROTECT feature. This feature will also
66758+ log other problematic scenarios that can occur when PAX_MPROTECT
66759+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
66760+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66761+ is created.
66762+
66763+endmenu
66764+
66765+menu "Executable Protections"
66766+depends on GRKERNSEC
66767+
66768+config GRKERNSEC_DMESG
66769+ bool "Dmesg(8) restriction"
66770+ default y if GRKERNSEC_CONFIG_AUTO
66771+ help
66772+ If you say Y here, non-root users will not be able to use dmesg(8)
66773+ to view the contents of the kernel's circular log buffer.
66774+ The kernel's log buffer often contains kernel addresses and other
66775+ identifying information useful to an attacker in fingerprinting a
66776+ system for a targeted exploit.
66777+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
66778+ created.
66779+
66780+config GRKERNSEC_HARDEN_PTRACE
66781+ bool "Deter ptrace-based process snooping"
66782+ default y if GRKERNSEC_CONFIG_AUTO
66783+ help
66784+ If you say Y here, TTY sniffers and other malicious monitoring
66785+ programs implemented through ptrace will be defeated. If you
66786+ have been using the RBAC system, this option has already been
66787+ enabled for several years for all users, with the ability to make
66788+ fine-grained exceptions.
66789+
66790+ This option only affects the ability of non-root users to ptrace
66791+ processes that are not a descendent of the ptracing process.
66792+ This means that strace ./binary and gdb ./binary will still work,
66793+ but attaching to arbitrary processes will not. If the sysctl
66794+ option is enabled, a sysctl option with name "harden_ptrace" is
66795+ created.
66796+
66797+config GRKERNSEC_PTRACE_READEXEC
66798+ bool "Require read access to ptrace sensitive binaries"
66799+ default y if GRKERNSEC_CONFIG_AUTO
66800+ help
66801+ If you say Y here, unprivileged users will not be able to ptrace unreadable
66802+ binaries. This option is useful in environments that
66803+ remove the read bits (e.g. file mode 4711) from suid binaries to
66804+ prevent infoleaking of their contents. This option adds
66805+ consistency to the use of that file mode, as the binary could normally
66806+ be read out when run without privileges while ptracing.
66807+
66808+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66809+ is created.
66810+
66811+config GRKERNSEC_SETXID
66812+ bool "Enforce consistent multithreaded privileges"
66813+ default y if GRKERNSEC_CONFIG_AUTO
66814+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66815+ help
66816+ If you say Y here, a change from a root uid to a non-root uid
66817+ in a multithreaded application will cause the resulting uids,
66818+ gids, supplementary groups, and capabilities in that thread
66819+ to be propagated to the other threads of the process. In most
66820+ cases this is unnecessary, as glibc will emulate this behavior
66821+ on behalf of the application. Other libcs do not act in the
66822+ same way, allowing the other threads of the process to continue
66823+ running with root privileges. If the sysctl option is enabled,
66824+ a sysctl option with name "consistent_setxid" is created.
66825+
66826+config GRKERNSEC_HARDEN_IPC
66827+ bool "Disallow access to overly-permissive IPC objects"
66828+ default y if GRKERNSEC_CONFIG_AUTO
66829+ depends on SYSVIPC
66830+ help
66831+ If you say Y here, access to overly-permissive IPC objects (shared
66832+ memory, message queues, and semaphores) will be denied for processes
66833+ given the following criteria beyond normal permission checks:
66834+ 1) If the IPC object is world-accessible and the euid doesn't match
66835+ that of the creator or current uid for the IPC object
66836+ 2) If the IPC object is group-accessible and the egid doesn't
66837+ match that of the creator or current gid for the IPC object
66838+ It's a common error to grant too much permission to these objects,
66839+ with impact ranging from denial of service and information leaking to
66840+ privilege escalation. This feature was developed in response to
66841+ research by Tim Brown:
66842+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66843+ who found hundreds of such insecure usages. Processes with
66844+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66845+ If the sysctl option is enabled, a sysctl option with name
66846+ "harden_ipc" is created.
66847+
66848+config GRKERNSEC_TPE
66849+ bool "Trusted Path Execution (TPE)"
66850+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66851+ help
66852+ If you say Y here, you will be able to choose a gid to add to the
66853+ supplementary groups of users you want to mark as "untrusted."
66854+ These users will not be able to execute any files that are not in
66855+ root-owned directories writable only by root. If the sysctl option
66856+ is enabled, a sysctl option with name "tpe" is created.
66857+
66858+config GRKERNSEC_TPE_ALL
66859+ bool "Partially restrict all non-root users"
66860+ depends on GRKERNSEC_TPE
66861+ help
66862+ If you say Y here, all non-root users will be covered under
66863+ a weaker TPE restriction. This is separate from, and in addition to,
66864+ the main TPE options that you have selected elsewhere. Thus, if a
66865+ "trusted" GID is chosen, this restriction applies to even that GID.
66866+ Under this restriction, all non-root users will only be allowed to
66867+ execute files in directories they own that are not group or
66868+ world-writable, or in directories owned by root and writable only by
66869+ root. If the sysctl option is enabled, a sysctl option with name
66870+ "tpe_restrict_all" is created.
66871+
66872+config GRKERNSEC_TPE_INVERT
66873+ bool "Invert GID option"
66874+ depends on GRKERNSEC_TPE
66875+ help
66876+ If you say Y here, the group you specify in the TPE configuration will
66877+ decide what group TPE restrictions will be *disabled* for. This
66878+ option is useful if you want TPE restrictions to be applied to most
66879+ users on the system. If the sysctl option is enabled, a sysctl option
66880+ with name "tpe_invert" is created. Unlike other sysctl options, this
66881+ entry will default to on for backward-compatibility.
66882+
66883+config GRKERNSEC_TPE_GID
66884+ int
66885+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66886+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66887+
66888+config GRKERNSEC_TPE_UNTRUSTED_GID
66889+ int "GID for TPE-untrusted users"
66890+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66891+ default 1005
66892+ help
66893+ Setting this GID determines what group TPE restrictions will be
66894+ *enabled* for. If the sysctl option is enabled, a sysctl option
66895+ with name "tpe_gid" is created.
66896+
66897+config GRKERNSEC_TPE_TRUSTED_GID
66898+ int "GID for TPE-trusted users"
66899+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66900+ default 1005
66901+ help
66902+ Setting this GID determines what group TPE restrictions will be
66903+ *disabled* for. If the sysctl option is enabled, a sysctl option
66904+ with name "tpe_gid" is created.
66905+
66906+endmenu
66907+menu "Network Protections"
66908+depends on GRKERNSEC
66909+
66910+config GRKERNSEC_RANDNET
66911+ bool "Larger entropy pools"
66912+ default y if GRKERNSEC_CONFIG_AUTO
66913+ help
66914+ If you say Y here, the entropy pools used for many features of Linux
66915+ and grsecurity will be doubled in size. Since several grsecurity
66916+ features use additional randomness, it is recommended that you say Y
66917+ here. Saying Y here has a similar effect as modifying
66918+ /proc/sys/kernel/random/poolsize.
66919+
66920+config GRKERNSEC_BLACKHOLE
66921+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66922+ default y if GRKERNSEC_CONFIG_AUTO
66923+ depends on NET
66924+ help
66925+ If you say Y here, neither TCP resets nor ICMP
66926+ destination-unreachable packets will be sent in response to packets
66927+ sent to ports for which no associated listening process exists.
66928+ This feature supports both IPV4 and IPV6 and exempts the
66929+ loopback interface from blackholing. Enabling this feature
66930+ makes a host more resilient to DoS attacks and reduces network
66931+ visibility against scanners.
66932+
66933+ The blackhole feature as-implemented is equivalent to the FreeBSD
66934+ blackhole feature, as it prevents RST responses to all packets, not
66935+ just SYNs. Under most application behavior this causes no
66936+ problems, but applications (like haproxy) may not close certain
66937+ connections in a way that cleanly terminates them on the remote
66938+ end, leaving the remote host in LAST_ACK state. Because of this
66939+ side-effect and to prevent intentional LAST_ACK DoSes, this
66940+ feature also adds automatic mitigation against such attacks.
66941+ The mitigation drastically reduces the amount of time a socket
66942+ can spend in LAST_ACK state. If you're using haproxy and not
66943+ all servers it connects to have this option enabled, consider
66944+ disabling this feature on the haproxy host.
66945+
66946+ If the sysctl option is enabled, two sysctl options with names
66947+ "ip_blackhole" and "lastack_retries" will be created.
66948+ While "ip_blackhole" takes the standard zero/non-zero on/off
66949+ toggle, "lastack_retries" uses the same kinds of values as
66950+ "tcp_retries1" and "tcp_retries2". The default value of 4
66951+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66952+ state.
66953+
66954+config GRKERNSEC_NO_SIMULT_CONNECT
66955+ bool "Disable TCP Simultaneous Connect"
66956+ default y if GRKERNSEC_CONFIG_AUTO
66957+ depends on NET
66958+ help
66959+ If you say Y here, a feature by Willy Tarreau will be enabled that
66960+ removes a weakness in Linux's strict implementation of TCP that
66961+ allows two clients to connect to each other without either entering
66962+ a listening state. The weakness allows an attacker to easily prevent
66963+ a client from connecting to a known server provided the source port
66964+ for the connection is guessed correctly.
66965+
66966+ As the weakness could be used to prevent an antivirus or IPS from
66967+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66968+ it should be eliminated by enabling this option. Though Linux is
66969+ one of few operating systems supporting simultaneous connect, it
66970+ has no legitimate use in practice and is rarely supported by firewalls.
66971+
66972+config GRKERNSEC_SOCKET
66973+ bool "Socket restrictions"
66974+ depends on NET
66975+ help
66976+ If you say Y here, you will be able to choose from several options.
66977+ If you assign a GID on your system and add it to the supplementary
66978+ groups of users you want to restrict socket access to, this patch
66979+ will perform up to three things, based on the option(s) you choose.
66980+
66981+config GRKERNSEC_SOCKET_ALL
66982+ bool "Deny any sockets to group"
66983+ depends on GRKERNSEC_SOCKET
66984+ help
66985+ If you say Y here, you will be able to choose a GID of whose users will
66986+ be unable to connect to other hosts from your machine or run server
66987+ applications from your machine. If the sysctl option is enabled, a
66988+ sysctl option with name "socket_all" is created.
66989+
66990+config GRKERNSEC_SOCKET_ALL_GID
66991+ int "GID to deny all sockets for"
66992+ depends on GRKERNSEC_SOCKET_ALL
66993+ default 1004
66994+ help
66995+ Here you can choose the GID to disable socket access for. Remember to
66996+ add the users you want socket access disabled for to the GID
66997+ specified here. If the sysctl option is enabled, a sysctl option
66998+ with name "socket_all_gid" is created.
66999+
67000+config GRKERNSEC_SOCKET_CLIENT
67001+ bool "Deny client sockets to group"
67002+ depends on GRKERNSEC_SOCKET
67003+ help
67004+ If you say Y here, you will be able to choose a GID of whose users will
67005+ be unable to connect to other hosts from your machine, but will be
67006+ able to run servers. If this option is enabled, all users in the group
67007+ you specify will have to use passive mode when initiating ftp transfers
67008+ from the shell on your machine. If the sysctl option is enabled, a
67009+ sysctl option with name "socket_client" is created.
67010+
67011+config GRKERNSEC_SOCKET_CLIENT_GID
67012+ int "GID to deny client sockets for"
67013+ depends on GRKERNSEC_SOCKET_CLIENT
67014+ default 1003
67015+ help
67016+ Here you can choose the GID to disable client socket access for.
67017+ Remember to add the users you want client socket access disabled for to
67018+ the GID specified here. If the sysctl option is enabled, a sysctl
67019+ option with name "socket_client_gid" is created.
67020+
67021+config GRKERNSEC_SOCKET_SERVER
67022+ bool "Deny server sockets to group"
67023+ depends on GRKERNSEC_SOCKET
67024+ help
67025+ If you say Y here, you will be able to choose a GID of whose users will
67026+ be unable to run server applications from your machine. If the sysctl
67027+ option is enabled, a sysctl option with name "socket_server" is created.
67028+
67029+config GRKERNSEC_SOCKET_SERVER_GID
67030+ int "GID to deny server sockets for"
67031+ depends on GRKERNSEC_SOCKET_SERVER
67032+ default 1002
67033+ help
67034+ Here you can choose the GID to disable server socket access for.
67035+ Remember to add the users you want server socket access disabled for to
67036+ the GID specified here. If the sysctl option is enabled, a sysctl
67037+ option with name "socket_server_gid" is created.
67038+
67039+endmenu
67040+
67041+menu "Physical Protections"
67042+depends on GRKERNSEC
67043+
67044+config GRKERNSEC_DENYUSB
67045+ bool "Deny new USB connections after toggle"
67046+ default y if GRKERNSEC_CONFIG_AUTO
67047+ depends on SYSCTL && USB_SUPPORT
67048+ help
67049+ If you say Y here, a new sysctl option with name "deny_new_usb"
67050+ will be created. Setting its value to 1 will prevent any new
67051+ USB devices from being recognized by the OS. Any attempted USB
67052+ device insertion will be logged. This option is intended to be
67053+ used against custom USB devices designed to exploit vulnerabilities
67054+ in various USB device drivers.
67055+
67056+ For greatest effectiveness, this sysctl should be set after any
67057+ relevant init scripts. This option is safe to enable in distros
67058+ as each user can choose whether or not to toggle the sysctl.
67059+
67060+config GRKERNSEC_DENYUSB_FORCE
67061+ bool "Reject all USB devices not connected at boot"
67062+ select USB
67063+ depends on GRKERNSEC_DENYUSB
67064+ help
67065+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
67066+ that doesn't involve a sysctl entry. This option should only be
67067+ enabled if you're sure you want to deny all new USB connections
67068+ at runtime and don't want to modify init scripts. This should not
67069+ be enabled by distros. It forces the core USB code to be built
67070+ into the kernel image so that all devices connected at boot time
67071+ can be recognized and new USB device connections can be prevented
67072+ prior to init running.
67073+
67074+endmenu
67075+
67076+menu "Sysctl Support"
67077+depends on GRKERNSEC && SYSCTL
67078+
67079+config GRKERNSEC_SYSCTL
67080+ bool "Sysctl support"
67081+ default y if GRKERNSEC_CONFIG_AUTO
67082+ help
67083+ If you say Y here, you will be able to change the options that
67084+ grsecurity runs with at bootup, without having to recompile your
67085+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
67086+ to enable (1) or disable (0) various features. All the sysctl entries
67087+ are mutable until the "grsec_lock" entry is set to a non-zero value.
67088+ All features enabled in the kernel configuration are disabled at boot
67089+ if you do not say Y to the "Turn on features by default" option.
67090+ All options should be set at startup, and the grsec_lock entry should
67091+ be set to a non-zero value after all the options are set.
67092+ *THIS IS EXTREMELY IMPORTANT*
67093+
67094+config GRKERNSEC_SYSCTL_DISTRO
67095+ bool "Extra sysctl support for distro makers (READ HELP)"
67096+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
67097+ help
67098+ If you say Y here, additional sysctl options will be created
67099+ for features that affect processes running as root. Therefore,
67100+ it is critical when using this option that the grsec_lock entry be
67101+ enabled after boot. Only distros with prebuilt kernel packages
67102+ with this option enabled that can ensure grsec_lock is enabled
67103+ after boot should use this option.
67104+ *Failure to set grsec_lock after boot makes all grsec features
67105+ this option covers useless*
67106+
67107+ Currently this option creates the following sysctl entries:
67108+ "Disable Privileged I/O": "disable_priv_io"
67109+
67110+config GRKERNSEC_SYSCTL_ON
67111+ bool "Turn on features by default"
67112+ default y if GRKERNSEC_CONFIG_AUTO
67113+ depends on GRKERNSEC_SYSCTL
67114+ help
67115+ If you say Y here, instead of having all features enabled in the
67116+ kernel configuration disabled at boot time, the features will be
67117+ enabled at boot time. It is recommended you say Y here unless
67118+ there is some reason you would want all sysctl-tunable features to
67119+ be disabled by default. As mentioned elsewhere, it is important
67120+ to enable the grsec_lock entry once you have finished modifying
67121+ the sysctl entries.
67122+
67123+endmenu
67124+menu "Logging Options"
67125+depends on GRKERNSEC
67126+
67127+config GRKERNSEC_FLOODTIME
67128+ int "Seconds in between log messages (minimum)"
67129+ default 10
67130+ help
67131+ This option allows you to enforce the number of seconds between
67132+ grsecurity log messages. The default should be suitable for most
67133+ people, however, if you choose to change it, choose a value small enough
67134+ to allow informative logs to be produced, but large enough to
67135+ prevent flooding.
67136+
67137+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
67138+ any rate limiting on grsecurity log messages.
67139+
67140+config GRKERNSEC_FLOODBURST
67141+ int "Number of messages in a burst (maximum)"
67142+ default 6
67143+ help
67144+ This option allows you to choose the maximum number of messages allowed
67145+ within the flood time interval you chose in a separate option. The
67146+ default should be suitable for most people, however if you find that
67147+ many of your logs are being interpreted as flooding, you may want to
67148+ raise this value.
67149+
67150+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
67151+ any rate limiting on grsecurity log messages.
67152+
67153+endmenu
67154diff --git a/grsecurity/Makefile b/grsecurity/Makefile
67155new file mode 100644
67156index 0000000..30ababb
67157--- /dev/null
67158+++ b/grsecurity/Makefile
67159@@ -0,0 +1,54 @@
67160+# grsecurity – access control and security hardening for Linux
67161+# All code in this directory and various hooks located throughout the Linux kernel are
67162+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
67163+# http://www.grsecurity.net spender@grsecurity.net
67164+#
67165+# This program is free software; you can redistribute it and/or
67166+# modify it under the terms of the GNU General Public License version 2
67167+# as published by the Free Software Foundation.
67168+#
67169+# This program is distributed in the hope that it will be useful,
67170+# but WITHOUT ANY WARRANTY; without even the implied warranty of
67171+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67172+# GNU General Public License for more details.
67173+#
67174+# You should have received a copy of the GNU General Public License
67175+# along with this program; if not, write to the Free Software
67176+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
67177+
67178+KBUILD_CFLAGS += -Werror
67179+
67180+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
67181+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
67182+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
67183+ grsec_usb.o grsec_ipc.o grsec_proc.o
67184+
67185+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
67186+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
67187+ gracl_learn.o grsec_log.o gracl_policy.o
67188+ifdef CONFIG_COMPAT
67189+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
67190+endif
67191+
67192+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
67193+
67194+ifdef CONFIG_NET
67195+obj-y += grsec_sock.o
67196+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
67197+endif
67198+
67199+ifndef CONFIG_GRKERNSEC
67200+obj-y += grsec_disabled.o
67201+endif
67202+
67203+ifdef CONFIG_GRKERNSEC_HIDESYM
67204+extra-y := grsec_hidesym.o
67205+$(obj)/grsec_hidesym.o:
67206+ @-chmod -f 500 /boot
67207+ @-chmod -f 500 /lib/modules
67208+ @-chmod -f 500 /lib64/modules
67209+ @-chmod -f 500 /lib32/modules
67210+ @-chmod -f 700 .
67211+ @-chmod -f 700 $(objtree)
67212+ @echo ' grsec: protected kernel image paths'
67213+endif
67214diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
67215new file mode 100644
67216index 0000000..e56396f
67217--- /dev/null
67218+++ b/grsecurity/gracl.c
67219@@ -0,0 +1,2679 @@
67220+#include <linux/kernel.h>
67221+#include <linux/module.h>
67222+#include <linux/sched.h>
67223+#include <linux/mm.h>
67224+#include <linux/file.h>
67225+#include <linux/fs.h>
67226+#include <linux/namei.h>
67227+#include <linux/mount.h>
67228+#include <linux/tty.h>
67229+#include <linux/proc_fs.h>
67230+#include <linux/lglock.h>
67231+#include <linux/slab.h>
67232+#include <linux/vmalloc.h>
67233+#include <linux/types.h>
67234+#include <linux/sysctl.h>
67235+#include <linux/netdevice.h>
67236+#include <linux/ptrace.h>
67237+#include <linux/gracl.h>
67238+#include <linux/gralloc.h>
67239+#include <linux/security.h>
67240+#include <linux/grinternal.h>
67241+#include <linux/pid_namespace.h>
67242+#include <linux/stop_machine.h>
67243+#include <linux/fdtable.h>
67244+#include <linux/percpu.h>
67245+#include <linux/lglock.h>
67246+#include <linux/hugetlb.h>
67247+#include <linux/posix-timers.h>
67248+#include <linux/prefetch.h>
67249+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67250+#include <linux/magic.h>
67251+#include <linux/pagemap.h>
67252+#include "../fs/btrfs/async-thread.h"
67253+#include "../fs/btrfs/ctree.h"
67254+#include "../fs/btrfs/btrfs_inode.h"
67255+#endif
67256+#include "../fs/mount.h"
67257+
67258+#include <asm/uaccess.h>
67259+#include <asm/errno.h>
67260+#include <asm/mman.h>
67261+
67262+#define FOR_EACH_ROLE_START(role) \
67263+ role = running_polstate.role_list; \
67264+ while (role) {
67265+
67266+#define FOR_EACH_ROLE_END(role) \
67267+ role = role->prev; \
67268+ }
67269+
67270+extern struct path gr_real_root;
67271+
67272+static struct gr_policy_state running_polstate;
67273+struct gr_policy_state *polstate = &running_polstate;
67274+extern struct gr_alloc_state *current_alloc_state;
67275+
67276+extern char *gr_shared_page[4];
67277+DEFINE_RWLOCK(gr_inode_lock);
67278+
67279+static unsigned int gr_status __read_only = GR_STATUS_INIT;
67280+
67281+#ifdef CONFIG_NET
67282+extern struct vfsmount *sock_mnt;
67283+#endif
67284+
67285+extern struct vfsmount *pipe_mnt;
67286+extern struct vfsmount *shm_mnt;
67287+
67288+#ifdef CONFIG_HUGETLBFS
67289+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
67290+#endif
67291+
67292+extern u16 acl_sp_role_value;
67293+extern struct acl_object_label *fakefs_obj_rw;
67294+extern struct acl_object_label *fakefs_obj_rwx;
67295+
67296+int gr_acl_is_enabled(void)
67297+{
67298+ return (gr_status & GR_READY);
67299+}
67300+
67301+void gr_enable_rbac_system(void)
67302+{
67303+ pax_open_kernel();
67304+ gr_status |= GR_READY;
67305+ pax_close_kernel();
67306+}
67307+
67308+int gr_rbac_disable(void *unused)
67309+{
67310+ pax_open_kernel();
67311+ gr_status &= ~GR_READY;
67312+ pax_close_kernel();
67313+
67314+ return 0;
67315+}
67316+
67317+static inline dev_t __get_dev(const struct dentry *dentry)
67318+{
67319+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67320+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67321+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67322+ else
67323+#endif
67324+ return dentry->d_sb->s_dev;
67325+}
67326+
67327+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67328+{
67329+ return __get_dev(dentry);
67330+}
67331+
67332+static char gr_task_roletype_to_char(struct task_struct *task)
67333+{
67334+ switch (task->role->roletype &
67335+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
67336+ GR_ROLE_SPECIAL)) {
67337+ case GR_ROLE_DEFAULT:
67338+ return 'D';
67339+ case GR_ROLE_USER:
67340+ return 'U';
67341+ case GR_ROLE_GROUP:
67342+ return 'G';
67343+ case GR_ROLE_SPECIAL:
67344+ return 'S';
67345+ }
67346+
67347+ return 'X';
67348+}
67349+
67350+char gr_roletype_to_char(void)
67351+{
67352+ return gr_task_roletype_to_char(current);
67353+}
67354+
67355+__inline__ int
67356+gr_acl_tpe_check(void)
67357+{
67358+ if (unlikely(!(gr_status & GR_READY)))
67359+ return 0;
67360+ if (current->role->roletype & GR_ROLE_TPE)
67361+ return 1;
67362+ else
67363+ return 0;
67364+}
67365+
67366+int
67367+gr_handle_rawio(const struct inode *inode)
67368+{
67369+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67370+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
67371+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
67372+ !capable(CAP_SYS_RAWIO))
67373+ return 1;
67374+#endif
67375+ return 0;
67376+}
67377+
67378+int
67379+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
67380+{
67381+ if (likely(lena != lenb))
67382+ return 0;
67383+
67384+ return !memcmp(a, b, lena);
67385+}
67386+
67387+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
67388+{
67389+ *buflen -= namelen;
67390+ if (*buflen < 0)
67391+ return -ENAMETOOLONG;
67392+ *buffer -= namelen;
67393+ memcpy(*buffer, str, namelen);
67394+ return 0;
67395+}
67396+
67397+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67398+{
67399+ return prepend(buffer, buflen, name->name, name->len);
67400+}
67401+
67402+static int prepend_path(const struct path *path, struct path *root,
67403+ char **buffer, int *buflen)
67404+{
67405+ struct dentry *dentry = path->dentry;
67406+ struct vfsmount *vfsmnt = path->mnt;
67407+ struct mount *mnt = real_mount(vfsmnt);
67408+ bool slash = false;
67409+ int error = 0;
67410+
67411+ while (dentry != root->dentry || vfsmnt != root->mnt) {
67412+ struct dentry * parent;
67413+
67414+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67415+ /* Global root? */
67416+ if (!mnt_has_parent(mnt)) {
67417+ goto out;
67418+ }
67419+ dentry = mnt->mnt_mountpoint;
67420+ mnt = mnt->mnt_parent;
67421+ vfsmnt = &mnt->mnt;
67422+ continue;
67423+ }
67424+ parent = dentry->d_parent;
67425+ prefetch(parent);
67426+ spin_lock(&dentry->d_lock);
67427+ error = prepend_name(buffer, buflen, &dentry->d_name);
67428+ spin_unlock(&dentry->d_lock);
67429+ if (!error)
67430+ error = prepend(buffer, buflen, "/", 1);
67431+ if (error)
67432+ break;
67433+
67434+ slash = true;
67435+ dentry = parent;
67436+ }
67437+
67438+out:
67439+ if (!error && !slash)
67440+ error = prepend(buffer, buflen, "/", 1);
67441+
67442+ return error;
67443+}
67444+
67445+/* this must be called with mount_lock and rename_lock held */
67446+
67447+static char *__our_d_path(const struct path *path, struct path *root,
67448+ char *buf, int buflen)
67449+{
67450+ char *res = buf + buflen;
67451+ int error;
67452+
67453+ prepend(&res, &buflen, "\0", 1);
67454+ error = prepend_path(path, root, &res, &buflen);
67455+ if (error)
67456+ return ERR_PTR(error);
67457+
67458+ return res;
67459+}
67460+
67461+static char *
67462+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67463+{
67464+ char *retval;
67465+
67466+ retval = __our_d_path(path, root, buf, buflen);
67467+ if (unlikely(IS_ERR(retval)))
67468+ retval = strcpy(buf, "<path too long>");
67469+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67470+ retval[1] = '\0';
67471+
67472+ return retval;
67473+}
67474+
67475+static char *
67476+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67477+ char *buf, int buflen)
67478+{
67479+ struct path path;
67480+ char *res;
67481+
67482+ path.dentry = (struct dentry *)dentry;
67483+ path.mnt = (struct vfsmount *)vfsmnt;
67484+
67485+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67486+ by the RBAC system */
67487+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
67488+
67489+ return res;
67490+}
67491+
67492+static char *
67493+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67494+ char *buf, int buflen)
67495+{
67496+ char *res;
67497+ struct path path;
67498+ struct path root;
67499+ struct task_struct *reaper = init_pid_ns.child_reaper;
67500+
67501+ path.dentry = (struct dentry *)dentry;
67502+ path.mnt = (struct vfsmount *)vfsmnt;
67503+
67504+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67505+ get_fs_root(reaper->fs, &root);
67506+
67507+ read_seqlock_excl(&mount_lock);
67508+ write_seqlock(&rename_lock);
67509+ res = gen_full_path(&path, &root, buf, buflen);
67510+ write_sequnlock(&rename_lock);
67511+ read_sequnlock_excl(&mount_lock);
67512+
67513+ path_put(&root);
67514+ return res;
67515+}
67516+
67517+char *
67518+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67519+{
67520+ char *ret;
67521+ read_seqlock_excl(&mount_lock);
67522+ write_seqlock(&rename_lock);
67523+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67524+ PAGE_SIZE);
67525+ write_sequnlock(&rename_lock);
67526+ read_sequnlock_excl(&mount_lock);
67527+ return ret;
67528+}
67529+
67530+static char *
67531+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67532+{
67533+ char *ret;
67534+ char *buf;
67535+ int buflen;
67536+
67537+ read_seqlock_excl(&mount_lock);
67538+ write_seqlock(&rename_lock);
67539+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67540+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67541+ buflen = (int)(ret - buf);
67542+ if (buflen >= 5)
67543+ prepend(&ret, &buflen, "/proc", 5);
67544+ else
67545+ ret = strcpy(buf, "<path too long>");
67546+ write_sequnlock(&rename_lock);
67547+ read_sequnlock_excl(&mount_lock);
67548+ return ret;
67549+}
67550+
67551+char *
67552+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67553+{
67554+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67555+ PAGE_SIZE);
67556+}
67557+
67558+char *
67559+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67560+{
67561+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67562+ PAGE_SIZE);
67563+}
67564+
67565+char *
67566+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67567+{
67568+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67569+ PAGE_SIZE);
67570+}
67571+
67572+char *
67573+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67574+{
67575+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67576+ PAGE_SIZE);
67577+}
67578+
67579+char *
67580+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67581+{
67582+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67583+ PAGE_SIZE);
67584+}
67585+
67586+__inline__ __u32
67587+to_gr_audit(const __u32 reqmode)
67588+{
67589+ /* masks off auditable permission flags, then shifts them to create
67590+ auditing flags, and adds the special case of append auditing if
67591+ we're requesting write */
67592+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67593+}
67594+
67595+struct acl_role_label *
67596+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67597+ const gid_t gid)
67598+{
67599+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67600+ struct acl_role_label *match;
67601+ struct role_allowed_ip *ipp;
67602+ unsigned int x;
67603+ u32 curr_ip = task->signal->saved_ip;
67604+
67605+ match = state->acl_role_set.r_hash[index];
67606+
67607+ while (match) {
67608+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67609+ for (x = 0; x < match->domain_child_num; x++) {
67610+ if (match->domain_children[x] == uid)
67611+ goto found;
67612+ }
67613+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67614+ break;
67615+ match = match->next;
67616+ }
67617+found:
67618+ if (match == NULL) {
67619+ try_group:
67620+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67621+ match = state->acl_role_set.r_hash[index];
67622+
67623+ while (match) {
67624+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67625+ for (x = 0; x < match->domain_child_num; x++) {
67626+ if (match->domain_children[x] == gid)
67627+ goto found2;
67628+ }
67629+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67630+ break;
67631+ match = match->next;
67632+ }
67633+found2:
67634+ if (match == NULL)
67635+ match = state->default_role;
67636+ if (match->allowed_ips == NULL)
67637+ return match;
67638+ else {
67639+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67640+ if (likely
67641+ ((ntohl(curr_ip) & ipp->netmask) ==
67642+ (ntohl(ipp->addr) & ipp->netmask)))
67643+ return match;
67644+ }
67645+ match = state->default_role;
67646+ }
67647+ } else if (match->allowed_ips == NULL) {
67648+ return match;
67649+ } else {
67650+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67651+ if (likely
67652+ ((ntohl(curr_ip) & ipp->netmask) ==
67653+ (ntohl(ipp->addr) & ipp->netmask)))
67654+ return match;
67655+ }
67656+ goto try_group;
67657+ }
67658+
67659+ return match;
67660+}
67661+
67662+static struct acl_role_label *
67663+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67664+ const gid_t gid)
67665+{
67666+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67667+}
67668+
67669+struct acl_subject_label *
67670+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67671+ const struct acl_role_label *role)
67672+{
67673+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67674+ struct acl_subject_label *match;
67675+
67676+ match = role->subj_hash[index];
67677+
67678+ while (match && (match->inode != ino || match->device != dev ||
67679+ (match->mode & GR_DELETED))) {
67680+ match = match->next;
67681+ }
67682+
67683+ if (match && !(match->mode & GR_DELETED))
67684+ return match;
67685+ else
67686+ return NULL;
67687+}
67688+
67689+struct acl_subject_label *
67690+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67691+ const struct acl_role_label *role)
67692+{
67693+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67694+ struct acl_subject_label *match;
67695+
67696+ match = role->subj_hash[index];
67697+
67698+ while (match && (match->inode != ino || match->device != dev ||
67699+ !(match->mode & GR_DELETED))) {
67700+ match = match->next;
67701+ }
67702+
67703+ if (match && (match->mode & GR_DELETED))
67704+ return match;
67705+ else
67706+ return NULL;
67707+}
67708+
67709+static struct acl_object_label *
67710+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67711+ const struct acl_subject_label *subj)
67712+{
67713+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67714+ struct acl_object_label *match;
67715+
67716+ match = subj->obj_hash[index];
67717+
67718+ while (match && (match->inode != ino || match->device != dev ||
67719+ (match->mode & GR_DELETED))) {
67720+ match = match->next;
67721+ }
67722+
67723+ if (match && !(match->mode & GR_DELETED))
67724+ return match;
67725+ else
67726+ return NULL;
67727+}
67728+
67729+static struct acl_object_label *
67730+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67731+ const struct acl_subject_label *subj)
67732+{
67733+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67734+ struct acl_object_label *match;
67735+
67736+ match = subj->obj_hash[index];
67737+
67738+ while (match && (match->inode != ino || match->device != dev ||
67739+ !(match->mode & GR_DELETED))) {
67740+ match = match->next;
67741+ }
67742+
67743+ if (match && (match->mode & GR_DELETED))
67744+ return match;
67745+
67746+ match = subj->obj_hash[index];
67747+
67748+ while (match && (match->inode != ino || match->device != dev ||
67749+ (match->mode & GR_DELETED))) {
67750+ match = match->next;
67751+ }
67752+
67753+ if (match && !(match->mode & GR_DELETED))
67754+ return match;
67755+ else
67756+ return NULL;
67757+}
67758+
67759+struct name_entry *
67760+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67761+{
67762+ unsigned int len = strlen(name);
67763+ unsigned int key = full_name_hash(name, len);
67764+ unsigned int index = key % state->name_set.n_size;
67765+ struct name_entry *match;
67766+
67767+ match = state->name_set.n_hash[index];
67768+
67769+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67770+ match = match->next;
67771+
67772+ return match;
67773+}
67774+
67775+static struct name_entry *
67776+lookup_name_entry(const char *name)
67777+{
67778+ return __lookup_name_entry(&running_polstate, name);
67779+}
67780+
67781+static struct name_entry *
67782+lookup_name_entry_create(const char *name)
67783+{
67784+ unsigned int len = strlen(name);
67785+ unsigned int key = full_name_hash(name, len);
67786+ unsigned int index = key % running_polstate.name_set.n_size;
67787+ struct name_entry *match;
67788+
67789+ match = running_polstate.name_set.n_hash[index];
67790+
67791+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67792+ !match->deleted))
67793+ match = match->next;
67794+
67795+ if (match && match->deleted)
67796+ return match;
67797+
67798+ match = running_polstate.name_set.n_hash[index];
67799+
67800+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67801+ match->deleted))
67802+ match = match->next;
67803+
67804+ if (match && !match->deleted)
67805+ return match;
67806+ else
67807+ return NULL;
67808+}
67809+
67810+static struct inodev_entry *
67811+lookup_inodev_entry(const ino_t ino, const dev_t dev)
67812+{
67813+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67814+ struct inodev_entry *match;
67815+
67816+ match = running_polstate.inodev_set.i_hash[index];
67817+
67818+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67819+ match = match->next;
67820+
67821+ return match;
67822+}
67823+
67824+void
67825+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67826+{
67827+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67828+ state->inodev_set.i_size);
67829+ struct inodev_entry **curr;
67830+
67831+ entry->prev = NULL;
67832+
67833+ curr = &state->inodev_set.i_hash[index];
67834+ if (*curr != NULL)
67835+ (*curr)->prev = entry;
67836+
67837+ entry->next = *curr;
67838+ *curr = entry;
67839+
67840+ return;
67841+}
67842+
67843+static void
67844+insert_inodev_entry(struct inodev_entry *entry)
67845+{
67846+ __insert_inodev_entry(&running_polstate, entry);
67847+}
67848+
67849+void
67850+insert_acl_obj_label(struct acl_object_label *obj,
67851+ struct acl_subject_label *subj)
67852+{
67853+ unsigned int index =
67854+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67855+ struct acl_object_label **curr;
67856+
67857+ obj->prev = NULL;
67858+
67859+ curr = &subj->obj_hash[index];
67860+ if (*curr != NULL)
67861+ (*curr)->prev = obj;
67862+
67863+ obj->next = *curr;
67864+ *curr = obj;
67865+
67866+ return;
67867+}
67868+
67869+void
67870+insert_acl_subj_label(struct acl_subject_label *obj,
67871+ struct acl_role_label *role)
67872+{
67873+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67874+ struct acl_subject_label **curr;
67875+
67876+ obj->prev = NULL;
67877+
67878+ curr = &role->subj_hash[index];
67879+ if (*curr != NULL)
67880+ (*curr)->prev = obj;
67881+
67882+ obj->next = *curr;
67883+ *curr = obj;
67884+
67885+ return;
67886+}
67887+
67888+/* derived from glibc fnmatch() 0: match, 1: no match*/
67889+
67890+static int
67891+glob_match(const char *p, const char *n)
67892+{
67893+ char c;
67894+
67895+ while ((c = *p++) != '\0') {
67896+ switch (c) {
67897+ case '?':
67898+ if (*n == '\0')
67899+ return 1;
67900+ else if (*n == '/')
67901+ return 1;
67902+ break;
67903+ case '\\':
67904+ if (*n != c)
67905+ return 1;
67906+ break;
67907+ case '*':
67908+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67909+ if (*n == '/')
67910+ return 1;
67911+ else if (c == '?') {
67912+ if (*n == '\0')
67913+ return 1;
67914+ else
67915+ ++n;
67916+ }
67917+ }
67918+ if (c == '\0') {
67919+ return 0;
67920+ } else {
67921+ const char *endp;
67922+
67923+ if ((endp = strchr(n, '/')) == NULL)
67924+ endp = n + strlen(n);
67925+
67926+ if (c == '[') {
67927+ for (--p; n < endp; ++n)
67928+ if (!glob_match(p, n))
67929+ return 0;
67930+ } else if (c == '/') {
67931+ while (*n != '\0' && *n != '/')
67932+ ++n;
67933+ if (*n == '/' && !glob_match(p, n + 1))
67934+ return 0;
67935+ } else {
67936+ for (--p; n < endp; ++n)
67937+ if (*n == c && !glob_match(p, n))
67938+ return 0;
67939+ }
67940+
67941+ return 1;
67942+ }
67943+ case '[':
67944+ {
67945+ int not;
67946+ char cold;
67947+
67948+ if (*n == '\0' || *n == '/')
67949+ return 1;
67950+
67951+ not = (*p == '!' || *p == '^');
67952+ if (not)
67953+ ++p;
67954+
67955+ c = *p++;
67956+ for (;;) {
67957+ unsigned char fn = (unsigned char)*n;
67958+
67959+ if (c == '\0')
67960+ return 1;
67961+ else {
67962+ if (c == fn)
67963+ goto matched;
67964+ cold = c;
67965+ c = *p++;
67966+
67967+ if (c == '-' && *p != ']') {
67968+ unsigned char cend = *p++;
67969+
67970+ if (cend == '\0')
67971+ return 1;
67972+
67973+ if (cold <= fn && fn <= cend)
67974+ goto matched;
67975+
67976+ c = *p++;
67977+ }
67978+ }
67979+
67980+ if (c == ']')
67981+ break;
67982+ }
67983+ if (!not)
67984+ return 1;
67985+ break;
67986+ matched:
67987+ while (c != ']') {
67988+ if (c == '\0')
67989+ return 1;
67990+
67991+ c = *p++;
67992+ }
67993+ if (not)
67994+ return 1;
67995+ }
67996+ break;
67997+ default:
67998+ if (c != *n)
67999+ return 1;
68000+ }
68001+
68002+ ++n;
68003+ }
68004+
68005+ if (*n == '\0')
68006+ return 0;
68007+
68008+ if (*n == '/')
68009+ return 0;
68010+
68011+ return 1;
68012+}
68013+
68014+static struct acl_object_label *
68015+chk_glob_label(struct acl_object_label *globbed,
68016+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
68017+{
68018+ struct acl_object_label *tmp;
68019+
68020+ if (*path == NULL)
68021+ *path = gr_to_filename_nolock(dentry, mnt);
68022+
68023+ tmp = globbed;
68024+
68025+ while (tmp) {
68026+ if (!glob_match(tmp->filename, *path))
68027+ return tmp;
68028+ tmp = tmp->next;
68029+ }
68030+
68031+ return NULL;
68032+}
68033+
68034+static struct acl_object_label *
68035+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68036+ const ino_t curr_ino, const dev_t curr_dev,
68037+ const struct acl_subject_label *subj, char **path, const int checkglob)
68038+{
68039+ struct acl_subject_label *tmpsubj;
68040+ struct acl_object_label *retval;
68041+ struct acl_object_label *retval2;
68042+
68043+ tmpsubj = (struct acl_subject_label *) subj;
68044+ read_lock(&gr_inode_lock);
68045+ do {
68046+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
68047+ if (retval) {
68048+ if (checkglob && retval->globbed) {
68049+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
68050+ if (retval2)
68051+ retval = retval2;
68052+ }
68053+ break;
68054+ }
68055+ } while ((tmpsubj = tmpsubj->parent_subject));
68056+ read_unlock(&gr_inode_lock);
68057+
68058+ return retval;
68059+}
68060+
68061+static __inline__ struct acl_object_label *
68062+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68063+ struct dentry *curr_dentry,
68064+ const struct acl_subject_label *subj, char **path, const int checkglob)
68065+{
68066+ int newglob = checkglob;
68067+ ino_t inode;
68068+ dev_t device;
68069+
68070+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
68071+ as we don't want a / * rule to match instead of the / object
68072+ don't do this for create lookups that call this function though, since they're looking up
68073+ on the parent and thus need globbing checks on all paths
68074+ */
68075+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
68076+ newglob = GR_NO_GLOB;
68077+
68078+ spin_lock(&curr_dentry->d_lock);
68079+ inode = curr_dentry->d_inode->i_ino;
68080+ device = __get_dev(curr_dentry);
68081+ spin_unlock(&curr_dentry->d_lock);
68082+
68083+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
68084+}
68085+
68086+#ifdef CONFIG_HUGETLBFS
68087+static inline bool
68088+is_hugetlbfs_mnt(const struct vfsmount *mnt)
68089+{
68090+ int i;
68091+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
68092+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
68093+ return true;
68094+ }
68095+
68096+ return false;
68097+}
68098+#endif
68099+
68100+static struct acl_object_label *
68101+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68102+ const struct acl_subject_label *subj, char *path, const int checkglob)
68103+{
68104+ struct dentry *dentry = (struct dentry *) l_dentry;
68105+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68106+ struct mount *real_mnt = real_mount(mnt);
68107+ struct acl_object_label *retval;
68108+ struct dentry *parent;
68109+
68110+ read_seqlock_excl(&mount_lock);
68111+ write_seqlock(&rename_lock);
68112+
68113+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
68114+#ifdef CONFIG_NET
68115+ mnt == sock_mnt ||
68116+#endif
68117+#ifdef CONFIG_HUGETLBFS
68118+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
68119+#endif
68120+ /* ignore Eric Biederman */
68121+ IS_PRIVATE(l_dentry->d_inode))) {
68122+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
68123+ goto out;
68124+ }
68125+
68126+ for (;;) {
68127+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68128+ break;
68129+
68130+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68131+ if (!mnt_has_parent(real_mnt))
68132+ break;
68133+
68134+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68135+ if (retval != NULL)
68136+ goto out;
68137+
68138+ dentry = real_mnt->mnt_mountpoint;
68139+ real_mnt = real_mnt->mnt_parent;
68140+ mnt = &real_mnt->mnt;
68141+ continue;
68142+ }
68143+
68144+ parent = dentry->d_parent;
68145+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68146+ if (retval != NULL)
68147+ goto out;
68148+
68149+ dentry = parent;
68150+ }
68151+
68152+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68153+
68154+ /* gr_real_root is pinned so we don't have to hold a reference */
68155+ if (retval == NULL)
68156+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
68157+out:
68158+ write_sequnlock(&rename_lock);
68159+ read_sequnlock_excl(&mount_lock);
68160+
68161+ BUG_ON(retval == NULL);
68162+
68163+ return retval;
68164+}
68165+
68166+static __inline__ struct acl_object_label *
68167+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68168+ const struct acl_subject_label *subj)
68169+{
68170+ char *path = NULL;
68171+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
68172+}
68173+
68174+static __inline__ struct acl_object_label *
68175+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68176+ const struct acl_subject_label *subj)
68177+{
68178+ char *path = NULL;
68179+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
68180+}
68181+
68182+static __inline__ struct acl_object_label *
68183+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68184+ const struct acl_subject_label *subj, char *path)
68185+{
68186+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
68187+}
68188+
68189+struct acl_subject_label *
68190+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68191+ const struct acl_role_label *role)
68192+{
68193+ struct dentry *dentry = (struct dentry *) l_dentry;
68194+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68195+ struct mount *real_mnt = real_mount(mnt);
68196+ struct acl_subject_label *retval;
68197+ struct dentry *parent;
68198+
68199+ read_seqlock_excl(&mount_lock);
68200+ write_seqlock(&rename_lock);
68201+
68202+ for (;;) {
68203+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68204+ break;
68205+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68206+ if (!mnt_has_parent(real_mnt))
68207+ break;
68208+
68209+ spin_lock(&dentry->d_lock);
68210+ read_lock(&gr_inode_lock);
68211+ retval =
68212+ lookup_acl_subj_label(dentry->d_inode->i_ino,
68213+ __get_dev(dentry), role);
68214+ read_unlock(&gr_inode_lock);
68215+ spin_unlock(&dentry->d_lock);
68216+ if (retval != NULL)
68217+ goto out;
68218+
68219+ dentry = real_mnt->mnt_mountpoint;
68220+ real_mnt = real_mnt->mnt_parent;
68221+ mnt = &real_mnt->mnt;
68222+ continue;
68223+ }
68224+
68225+ spin_lock(&dentry->d_lock);
68226+ read_lock(&gr_inode_lock);
68227+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68228+ __get_dev(dentry), role);
68229+ read_unlock(&gr_inode_lock);
68230+ parent = dentry->d_parent;
68231+ spin_unlock(&dentry->d_lock);
68232+
68233+ if (retval != NULL)
68234+ goto out;
68235+
68236+ dentry = parent;
68237+ }
68238+
68239+ spin_lock(&dentry->d_lock);
68240+ read_lock(&gr_inode_lock);
68241+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68242+ __get_dev(dentry), role);
68243+ read_unlock(&gr_inode_lock);
68244+ spin_unlock(&dentry->d_lock);
68245+
68246+ if (unlikely(retval == NULL)) {
68247+ /* gr_real_root is pinned, we don't need to hold a reference */
68248+ read_lock(&gr_inode_lock);
68249+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
68250+ __get_dev(gr_real_root.dentry), role);
68251+ read_unlock(&gr_inode_lock);
68252+ }
68253+out:
68254+ write_sequnlock(&rename_lock);
68255+ read_sequnlock_excl(&mount_lock);
68256+
68257+ BUG_ON(retval == NULL);
68258+
68259+ return retval;
68260+}
68261+
68262+void
68263+assign_special_role(const char *rolename)
68264+{
68265+ struct acl_object_label *obj;
68266+ struct acl_role_label *r;
68267+ struct acl_role_label *assigned = NULL;
68268+ struct task_struct *tsk;
68269+ struct file *filp;
68270+
68271+ FOR_EACH_ROLE_START(r)
68272+ if (!strcmp(rolename, r->rolename) &&
68273+ (r->roletype & GR_ROLE_SPECIAL)) {
68274+ assigned = r;
68275+ break;
68276+ }
68277+ FOR_EACH_ROLE_END(r)
68278+
68279+ if (!assigned)
68280+ return;
68281+
68282+ read_lock(&tasklist_lock);
68283+ read_lock(&grsec_exec_file_lock);
68284+
68285+ tsk = current->real_parent;
68286+ if (tsk == NULL)
68287+ goto out_unlock;
68288+
68289+ filp = tsk->exec_file;
68290+ if (filp == NULL)
68291+ goto out_unlock;
68292+
68293+ tsk->is_writable = 0;
68294+ tsk->inherited = 0;
68295+
68296+ tsk->acl_sp_role = 1;
68297+ tsk->acl_role_id = ++acl_sp_role_value;
68298+ tsk->role = assigned;
68299+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
68300+
68301+ /* ignore additional mmap checks for processes that are writable
68302+ by the default ACL */
68303+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68304+ if (unlikely(obj->mode & GR_WRITE))
68305+ tsk->is_writable = 1;
68306+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
68307+ if (unlikely(obj->mode & GR_WRITE))
68308+ tsk->is_writable = 1;
68309+
68310+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68311+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
68312+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
68313+#endif
68314+
68315+out_unlock:
68316+ read_unlock(&grsec_exec_file_lock);
68317+ read_unlock(&tasklist_lock);
68318+ return;
68319+}
68320+
68321+
68322+static void
68323+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
68324+{
68325+ struct task_struct *task = current;
68326+ const struct cred *cred = current_cred();
68327+
68328+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
68329+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68330+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68331+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
68332+
68333+ return;
68334+}
68335+
68336+static void
68337+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
68338+{
68339+ struct task_struct *task = current;
68340+ const struct cred *cred = current_cred();
68341+
68342+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68343+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68344+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68345+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
68346+
68347+ return;
68348+}
68349+
68350+static void
68351+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
68352+{
68353+ struct task_struct *task = current;
68354+ const struct cred *cred = current_cred();
68355+
68356+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68357+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68358+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68359+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
68360+
68361+ return;
68362+}
68363+
68364+static void
68365+gr_set_proc_res(struct task_struct *task)
68366+{
68367+ struct acl_subject_label *proc;
68368+ unsigned short i;
68369+
68370+ proc = task->acl;
68371+
68372+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
68373+ return;
68374+
68375+ for (i = 0; i < RLIM_NLIMITS; i++) {
68376+ if (!(proc->resmask & (1U << i)))
68377+ continue;
68378+
68379+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
68380+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
68381+
68382+ if (i == RLIMIT_CPU)
68383+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
68384+ }
68385+
68386+ return;
68387+}
68388+
68389+/* both of the below must be called with
68390+ rcu_read_lock();
68391+ read_lock(&tasklist_lock);
68392+ read_lock(&grsec_exec_file_lock);
68393+*/
68394+
68395+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68396+{
68397+ char *tmpname;
68398+ struct acl_subject_label *tmpsubj;
68399+ struct file *filp;
68400+ struct name_entry *nmatch;
68401+
68402+ filp = task->exec_file;
68403+ if (filp == NULL)
68404+ return NULL;
68405+
68406+ /* the following is to apply the correct subject
68407+ on binaries running when the RBAC system
68408+ is enabled, when the binaries have been
68409+ replaced or deleted since their execution
68410+ -----
68411+ when the RBAC system starts, the inode/dev
68412+ from exec_file will be one the RBAC system
68413+ is unaware of. It only knows the inode/dev
68414+ of the present file on disk, or the absence
68415+ of it.
68416+ */
68417+
68418+ if (filename)
68419+ nmatch = __lookup_name_entry(state, filename);
68420+ else {
68421+ preempt_disable();
68422+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68423+
68424+ nmatch = __lookup_name_entry(state, tmpname);
68425+ preempt_enable();
68426+ }
68427+ tmpsubj = NULL;
68428+ if (nmatch) {
68429+ if (nmatch->deleted)
68430+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68431+ else
68432+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68433+ }
68434+ /* this also works for the reload case -- if we don't match a potentially inherited subject
68435+ then we fall back to a normal lookup based on the binary's ino/dev
68436+ */
68437+ if (tmpsubj == NULL)
68438+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68439+
68440+ return tmpsubj;
68441+}
68442+
68443+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68444+{
68445+ return __gr_get_subject_for_task(&running_polstate, task, filename);
68446+}
68447+
68448+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68449+{
68450+ struct acl_object_label *obj;
68451+ struct file *filp;
68452+
68453+ filp = task->exec_file;
68454+
68455+ task->acl = subj;
68456+ task->is_writable = 0;
68457+ /* ignore additional mmap checks for processes that are writable
68458+ by the default ACL */
68459+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68460+ if (unlikely(obj->mode & GR_WRITE))
68461+ task->is_writable = 1;
68462+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68463+ if (unlikely(obj->mode & GR_WRITE))
68464+ task->is_writable = 1;
68465+
68466+ gr_set_proc_res(task);
68467+
68468+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68469+ 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);
68470+#endif
68471+}
68472+
68473+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68474+{
68475+ __gr_apply_subject_to_task(&running_polstate, task, subj);
68476+}
68477+
68478+__u32
68479+gr_search_file(const struct dentry * dentry, const __u32 mode,
68480+ const struct vfsmount * mnt)
68481+{
68482+ __u32 retval = mode;
68483+ struct acl_subject_label *curracl;
68484+ struct acl_object_label *currobj;
68485+
68486+ if (unlikely(!(gr_status & GR_READY)))
68487+ return (mode & ~GR_AUDITS);
68488+
68489+ curracl = current->acl;
68490+
68491+ currobj = chk_obj_label(dentry, mnt, curracl);
68492+ retval = currobj->mode & mode;
68493+
68494+ /* if we're opening a specified transfer file for writing
68495+ (e.g. /dev/initctl), then transfer our role to init
68496+ */
68497+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68498+ current->role->roletype & GR_ROLE_PERSIST)) {
68499+ struct task_struct *task = init_pid_ns.child_reaper;
68500+
68501+ if (task->role != current->role) {
68502+ struct acl_subject_label *subj;
68503+
68504+ task->acl_sp_role = 0;
68505+ task->acl_role_id = current->acl_role_id;
68506+ task->role = current->role;
68507+ rcu_read_lock();
68508+ read_lock(&grsec_exec_file_lock);
68509+ subj = gr_get_subject_for_task(task, NULL);
68510+ gr_apply_subject_to_task(task, subj);
68511+ read_unlock(&grsec_exec_file_lock);
68512+ rcu_read_unlock();
68513+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68514+ }
68515+ }
68516+
68517+ if (unlikely
68518+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68519+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68520+ __u32 new_mode = mode;
68521+
68522+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68523+
68524+ retval = new_mode;
68525+
68526+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68527+ new_mode |= GR_INHERIT;
68528+
68529+ if (!(mode & GR_NOLEARN))
68530+ gr_log_learn(dentry, mnt, new_mode);
68531+ }
68532+
68533+ return retval;
68534+}
68535+
68536+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68537+ const struct dentry *parent,
68538+ const struct vfsmount *mnt)
68539+{
68540+ struct name_entry *match;
68541+ struct acl_object_label *matchpo;
68542+ struct acl_subject_label *curracl;
68543+ char *path;
68544+
68545+ if (unlikely(!(gr_status & GR_READY)))
68546+ return NULL;
68547+
68548+ preempt_disable();
68549+ path = gr_to_filename_rbac(new_dentry, mnt);
68550+ match = lookup_name_entry_create(path);
68551+
68552+ curracl = current->acl;
68553+
68554+ if (match) {
68555+ read_lock(&gr_inode_lock);
68556+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68557+ read_unlock(&gr_inode_lock);
68558+
68559+ if (matchpo) {
68560+ preempt_enable();
68561+ return matchpo;
68562+ }
68563+ }
68564+
68565+ // lookup parent
68566+
68567+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68568+
68569+ preempt_enable();
68570+ return matchpo;
68571+}
68572+
68573+__u32
68574+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68575+ const struct vfsmount * mnt, const __u32 mode)
68576+{
68577+ struct acl_object_label *matchpo;
68578+ __u32 retval;
68579+
68580+ if (unlikely(!(gr_status & GR_READY)))
68581+ return (mode & ~GR_AUDITS);
68582+
68583+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
68584+
68585+ retval = matchpo->mode & mode;
68586+
68587+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68588+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68589+ __u32 new_mode = mode;
68590+
68591+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68592+
68593+ gr_log_learn(new_dentry, mnt, new_mode);
68594+ return new_mode;
68595+ }
68596+
68597+ return retval;
68598+}
68599+
68600+__u32
68601+gr_check_link(const struct dentry * new_dentry,
68602+ const struct dentry * parent_dentry,
68603+ const struct vfsmount * parent_mnt,
68604+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68605+{
68606+ struct acl_object_label *obj;
68607+ __u32 oldmode, newmode;
68608+ __u32 needmode;
68609+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68610+ GR_DELETE | GR_INHERIT;
68611+
68612+ if (unlikely(!(gr_status & GR_READY)))
68613+ return (GR_CREATE | GR_LINK);
68614+
68615+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68616+ oldmode = obj->mode;
68617+
68618+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68619+ newmode = obj->mode;
68620+
68621+ needmode = newmode & checkmodes;
68622+
68623+ // old name for hardlink must have at least the permissions of the new name
68624+ if ((oldmode & needmode) != needmode)
68625+ goto bad;
68626+
68627+ // if old name had restrictions/auditing, make sure the new name does as well
68628+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68629+
68630+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68631+ if (is_privileged_binary(old_dentry))
68632+ needmode |= GR_SETID;
68633+
68634+ if ((newmode & needmode) != needmode)
68635+ goto bad;
68636+
68637+ // enforce minimum permissions
68638+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68639+ return newmode;
68640+bad:
68641+ needmode = oldmode;
68642+ if (is_privileged_binary(old_dentry))
68643+ needmode |= GR_SETID;
68644+
68645+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68646+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68647+ return (GR_CREATE | GR_LINK);
68648+ } else if (newmode & GR_SUPPRESS)
68649+ return GR_SUPPRESS;
68650+ else
68651+ return 0;
68652+}
68653+
68654+int
68655+gr_check_hidden_task(const struct task_struct *task)
68656+{
68657+ if (unlikely(!(gr_status & GR_READY)))
68658+ return 0;
68659+
68660+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68661+ return 1;
68662+
68663+ return 0;
68664+}
68665+
68666+int
68667+gr_check_protected_task(const struct task_struct *task)
68668+{
68669+ if (unlikely(!(gr_status & GR_READY) || !task))
68670+ return 0;
68671+
68672+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68673+ task->acl != current->acl)
68674+ return 1;
68675+
68676+ return 0;
68677+}
68678+
68679+int
68680+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68681+{
68682+ struct task_struct *p;
68683+ int ret = 0;
68684+
68685+ if (unlikely(!(gr_status & GR_READY) || !pid))
68686+ return ret;
68687+
68688+ read_lock(&tasklist_lock);
68689+ do_each_pid_task(pid, type, p) {
68690+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68691+ p->acl != current->acl) {
68692+ ret = 1;
68693+ goto out;
68694+ }
68695+ } while_each_pid_task(pid, type, p);
68696+out:
68697+ read_unlock(&tasklist_lock);
68698+
68699+ return ret;
68700+}
68701+
68702+void
68703+gr_copy_label(struct task_struct *tsk)
68704+{
68705+ struct task_struct *p = current;
68706+
68707+ tsk->inherited = p->inherited;
68708+ tsk->acl_sp_role = 0;
68709+ tsk->acl_role_id = p->acl_role_id;
68710+ tsk->acl = p->acl;
68711+ tsk->role = p->role;
68712+ tsk->signal->used_accept = 0;
68713+ tsk->signal->curr_ip = p->signal->curr_ip;
68714+ tsk->signal->saved_ip = p->signal->saved_ip;
68715+ if (p->exec_file)
68716+ get_file(p->exec_file);
68717+ tsk->exec_file = p->exec_file;
68718+ tsk->is_writable = p->is_writable;
68719+ if (unlikely(p->signal->used_accept)) {
68720+ p->signal->curr_ip = 0;
68721+ p->signal->saved_ip = 0;
68722+ }
68723+
68724+ return;
68725+}
68726+
68727+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68728+
68729+int
68730+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68731+{
68732+ unsigned int i;
68733+ __u16 num;
68734+ uid_t *uidlist;
68735+ uid_t curuid;
68736+ int realok = 0;
68737+ int effectiveok = 0;
68738+ int fsok = 0;
68739+ uid_t globalreal, globaleffective, globalfs;
68740+
68741+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68742+ struct user_struct *user;
68743+
68744+ if (!uid_valid(real))
68745+ goto skipit;
68746+
68747+ /* find user based on global namespace */
68748+
68749+ globalreal = GR_GLOBAL_UID(real);
68750+
68751+ user = find_user(make_kuid(&init_user_ns, globalreal));
68752+ if (user == NULL)
68753+ goto skipit;
68754+
68755+ if (gr_process_kernel_setuid_ban(user)) {
68756+ /* for find_user */
68757+ free_uid(user);
68758+ return 1;
68759+ }
68760+
68761+ /* for find_user */
68762+ free_uid(user);
68763+
68764+skipit:
68765+#endif
68766+
68767+ if (unlikely(!(gr_status & GR_READY)))
68768+ return 0;
68769+
68770+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68771+ gr_log_learn_uid_change(real, effective, fs);
68772+
68773+ num = current->acl->user_trans_num;
68774+ uidlist = current->acl->user_transitions;
68775+
68776+ if (uidlist == NULL)
68777+ return 0;
68778+
68779+ if (!uid_valid(real)) {
68780+ realok = 1;
68781+ globalreal = (uid_t)-1;
68782+ } else {
68783+ globalreal = GR_GLOBAL_UID(real);
68784+ }
68785+ if (!uid_valid(effective)) {
68786+ effectiveok = 1;
68787+ globaleffective = (uid_t)-1;
68788+ } else {
68789+ globaleffective = GR_GLOBAL_UID(effective);
68790+ }
68791+ if (!uid_valid(fs)) {
68792+ fsok = 1;
68793+ globalfs = (uid_t)-1;
68794+ } else {
68795+ globalfs = GR_GLOBAL_UID(fs);
68796+ }
68797+
68798+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
68799+ for (i = 0; i < num; i++) {
68800+ curuid = uidlist[i];
68801+ if (globalreal == curuid)
68802+ realok = 1;
68803+ if (globaleffective == curuid)
68804+ effectiveok = 1;
68805+ if (globalfs == curuid)
68806+ fsok = 1;
68807+ }
68808+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
68809+ for (i = 0; i < num; i++) {
68810+ curuid = uidlist[i];
68811+ if (globalreal == curuid)
68812+ break;
68813+ if (globaleffective == curuid)
68814+ break;
68815+ if (globalfs == curuid)
68816+ break;
68817+ }
68818+ /* not in deny list */
68819+ if (i == num) {
68820+ realok = 1;
68821+ effectiveok = 1;
68822+ fsok = 1;
68823+ }
68824+ }
68825+
68826+ if (realok && effectiveok && fsok)
68827+ return 0;
68828+ else {
68829+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68830+ return 1;
68831+ }
68832+}
68833+
68834+int
68835+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68836+{
68837+ unsigned int i;
68838+ __u16 num;
68839+ gid_t *gidlist;
68840+ gid_t curgid;
68841+ int realok = 0;
68842+ int effectiveok = 0;
68843+ int fsok = 0;
68844+ gid_t globalreal, globaleffective, globalfs;
68845+
68846+ if (unlikely(!(gr_status & GR_READY)))
68847+ return 0;
68848+
68849+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68850+ gr_log_learn_gid_change(real, effective, fs);
68851+
68852+ num = current->acl->group_trans_num;
68853+ gidlist = current->acl->group_transitions;
68854+
68855+ if (gidlist == NULL)
68856+ return 0;
68857+
68858+ if (!gid_valid(real)) {
68859+ realok = 1;
68860+ globalreal = (gid_t)-1;
68861+ } else {
68862+ globalreal = GR_GLOBAL_GID(real);
68863+ }
68864+ if (!gid_valid(effective)) {
68865+ effectiveok = 1;
68866+ globaleffective = (gid_t)-1;
68867+ } else {
68868+ globaleffective = GR_GLOBAL_GID(effective);
68869+ }
68870+ if (!gid_valid(fs)) {
68871+ fsok = 1;
68872+ globalfs = (gid_t)-1;
68873+ } else {
68874+ globalfs = GR_GLOBAL_GID(fs);
68875+ }
68876+
68877+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68878+ for (i = 0; i < num; i++) {
68879+ curgid = gidlist[i];
68880+ if (globalreal == curgid)
68881+ realok = 1;
68882+ if (globaleffective == curgid)
68883+ effectiveok = 1;
68884+ if (globalfs == curgid)
68885+ fsok = 1;
68886+ }
68887+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68888+ for (i = 0; i < num; i++) {
68889+ curgid = gidlist[i];
68890+ if (globalreal == curgid)
68891+ break;
68892+ if (globaleffective == curgid)
68893+ break;
68894+ if (globalfs == curgid)
68895+ break;
68896+ }
68897+ /* not in deny list */
68898+ if (i == num) {
68899+ realok = 1;
68900+ effectiveok = 1;
68901+ fsok = 1;
68902+ }
68903+ }
68904+
68905+ if (realok && effectiveok && fsok)
68906+ return 0;
68907+ else {
68908+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68909+ return 1;
68910+ }
68911+}
68912+
68913+extern int gr_acl_is_capable(const int cap);
68914+
68915+void
68916+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68917+{
68918+ struct acl_role_label *role = task->role;
68919+ struct acl_subject_label *subj = NULL;
68920+ struct acl_object_label *obj;
68921+ struct file *filp;
68922+ uid_t uid;
68923+ gid_t gid;
68924+
68925+ if (unlikely(!(gr_status & GR_READY)))
68926+ return;
68927+
68928+ uid = GR_GLOBAL_UID(kuid);
68929+ gid = GR_GLOBAL_GID(kgid);
68930+
68931+ filp = task->exec_file;
68932+
68933+ /* kernel process, we'll give them the kernel role */
68934+ if (unlikely(!filp)) {
68935+ task->role = running_polstate.kernel_role;
68936+ task->acl = running_polstate.kernel_role->root_label;
68937+ return;
68938+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68939+ /* save the current ip at time of role lookup so that the proper
68940+ IP will be learned for role_allowed_ip */
68941+ task->signal->saved_ip = task->signal->curr_ip;
68942+ role = lookup_acl_role_label(task, uid, gid);
68943+ }
68944+
68945+ /* don't change the role if we're not a privileged process */
68946+ if (role && task->role != role &&
68947+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68948+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68949+ return;
68950+
68951+ /* perform subject lookup in possibly new role
68952+ we can use this result below in the case where role == task->role
68953+ */
68954+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68955+
68956+ /* if we changed uid/gid, but result in the same role
68957+ and are using inheritance, don't lose the inherited subject
68958+ if current subject is other than what normal lookup
68959+ would result in, we arrived via inheritance, don't
68960+ lose subject
68961+ */
68962+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68963+ (subj == task->acl)))
68964+ task->acl = subj;
68965+
68966+ /* leave task->inherited unaffected */
68967+
68968+ task->role = role;
68969+
68970+ task->is_writable = 0;
68971+
68972+ /* ignore additional mmap checks for processes that are writable
68973+ by the default ACL */
68974+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68975+ if (unlikely(obj->mode & GR_WRITE))
68976+ task->is_writable = 1;
68977+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68978+ if (unlikely(obj->mode & GR_WRITE))
68979+ task->is_writable = 1;
68980+
68981+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68982+ 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);
68983+#endif
68984+
68985+ gr_set_proc_res(task);
68986+
68987+ return;
68988+}
68989+
68990+int
68991+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68992+ const int unsafe_flags)
68993+{
68994+ struct task_struct *task = current;
68995+ struct acl_subject_label *newacl;
68996+ struct acl_object_label *obj;
68997+ __u32 retmode;
68998+
68999+ if (unlikely(!(gr_status & GR_READY)))
69000+ return 0;
69001+
69002+ newacl = chk_subj_label(dentry, mnt, task->role);
69003+
69004+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
69005+ did an exec
69006+ */
69007+ rcu_read_lock();
69008+ read_lock(&tasklist_lock);
69009+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
69010+ (task->parent->acl->mode & GR_POVERRIDE))) {
69011+ read_unlock(&tasklist_lock);
69012+ rcu_read_unlock();
69013+ goto skip_check;
69014+ }
69015+ read_unlock(&tasklist_lock);
69016+ rcu_read_unlock();
69017+
69018+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
69019+ !(task->role->roletype & GR_ROLE_GOD) &&
69020+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
69021+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
69022+ if (unsafe_flags & LSM_UNSAFE_SHARE)
69023+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
69024+ else
69025+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
69026+ return -EACCES;
69027+ }
69028+
69029+skip_check:
69030+
69031+ obj = chk_obj_label(dentry, mnt, task->acl);
69032+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
69033+
69034+ if (!(task->acl->mode & GR_INHERITLEARN) &&
69035+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
69036+ if (obj->nested)
69037+ task->acl = obj->nested;
69038+ else
69039+ task->acl = newacl;
69040+ task->inherited = 0;
69041+ } else {
69042+ task->inherited = 1;
69043+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
69044+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
69045+ }
69046+
69047+ task->is_writable = 0;
69048+
69049+ /* ignore additional mmap checks for processes that are writable
69050+ by the default ACL */
69051+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
69052+ if (unlikely(obj->mode & GR_WRITE))
69053+ task->is_writable = 1;
69054+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
69055+ if (unlikely(obj->mode & GR_WRITE))
69056+ task->is_writable = 1;
69057+
69058+ gr_set_proc_res(task);
69059+
69060+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69061+ 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);
69062+#endif
69063+ return 0;
69064+}
69065+
69066+/* always called with valid inodev ptr */
69067+static void
69068+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
69069+{
69070+ struct acl_object_label *matchpo;
69071+ struct acl_subject_label *matchps;
69072+ struct acl_subject_label *subj;
69073+ struct acl_role_label *role;
69074+ unsigned int x;
69075+
69076+ FOR_EACH_ROLE_START(role)
69077+ FOR_EACH_SUBJECT_START(role, subj, x)
69078+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69079+ matchpo->mode |= GR_DELETED;
69080+ FOR_EACH_SUBJECT_END(subj,x)
69081+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
69082+ /* nested subjects aren't in the role's subj_hash table */
69083+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69084+ matchpo->mode |= GR_DELETED;
69085+ FOR_EACH_NESTED_SUBJECT_END(subj)
69086+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
69087+ matchps->mode |= GR_DELETED;
69088+ FOR_EACH_ROLE_END(role)
69089+
69090+ inodev->nentry->deleted = 1;
69091+
69092+ return;
69093+}
69094+
69095+void
69096+gr_handle_delete(const ino_t ino, const dev_t dev)
69097+{
69098+ struct inodev_entry *inodev;
69099+
69100+ if (unlikely(!(gr_status & GR_READY)))
69101+ return;
69102+
69103+ write_lock(&gr_inode_lock);
69104+ inodev = lookup_inodev_entry(ino, dev);
69105+ if (inodev != NULL)
69106+ do_handle_delete(inodev, ino, dev);
69107+ write_unlock(&gr_inode_lock);
69108+
69109+ return;
69110+}
69111+
69112+static void
69113+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
69114+ const ino_t newinode, const dev_t newdevice,
69115+ struct acl_subject_label *subj)
69116+{
69117+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
69118+ struct acl_object_label *match;
69119+
69120+ match = subj->obj_hash[index];
69121+
69122+ while (match && (match->inode != oldinode ||
69123+ match->device != olddevice ||
69124+ !(match->mode & GR_DELETED)))
69125+ match = match->next;
69126+
69127+ if (match && (match->inode == oldinode)
69128+ && (match->device == olddevice)
69129+ && (match->mode & GR_DELETED)) {
69130+ if (match->prev == NULL) {
69131+ subj->obj_hash[index] = match->next;
69132+ if (match->next != NULL)
69133+ match->next->prev = NULL;
69134+ } else {
69135+ match->prev->next = match->next;
69136+ if (match->next != NULL)
69137+ match->next->prev = match->prev;
69138+ }
69139+ match->prev = NULL;
69140+ match->next = NULL;
69141+ match->inode = newinode;
69142+ match->device = newdevice;
69143+ match->mode &= ~GR_DELETED;
69144+
69145+ insert_acl_obj_label(match, subj);
69146+ }
69147+
69148+ return;
69149+}
69150+
69151+static void
69152+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
69153+ const ino_t newinode, const dev_t newdevice,
69154+ struct acl_role_label *role)
69155+{
69156+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
69157+ struct acl_subject_label *match;
69158+
69159+ match = role->subj_hash[index];
69160+
69161+ while (match && (match->inode != oldinode ||
69162+ match->device != olddevice ||
69163+ !(match->mode & GR_DELETED)))
69164+ match = match->next;
69165+
69166+ if (match && (match->inode == oldinode)
69167+ && (match->device == olddevice)
69168+ && (match->mode & GR_DELETED)) {
69169+ if (match->prev == NULL) {
69170+ role->subj_hash[index] = match->next;
69171+ if (match->next != NULL)
69172+ match->next->prev = NULL;
69173+ } else {
69174+ match->prev->next = match->next;
69175+ if (match->next != NULL)
69176+ match->next->prev = match->prev;
69177+ }
69178+ match->prev = NULL;
69179+ match->next = NULL;
69180+ match->inode = newinode;
69181+ match->device = newdevice;
69182+ match->mode &= ~GR_DELETED;
69183+
69184+ insert_acl_subj_label(match, role);
69185+ }
69186+
69187+ return;
69188+}
69189+
69190+static void
69191+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
69192+ const ino_t newinode, const dev_t newdevice)
69193+{
69194+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
69195+ struct inodev_entry *match;
69196+
69197+ match = running_polstate.inodev_set.i_hash[index];
69198+
69199+ while (match && (match->nentry->inode != oldinode ||
69200+ match->nentry->device != olddevice || !match->nentry->deleted))
69201+ match = match->next;
69202+
69203+ if (match && (match->nentry->inode == oldinode)
69204+ && (match->nentry->device == olddevice) &&
69205+ match->nentry->deleted) {
69206+ if (match->prev == NULL) {
69207+ running_polstate.inodev_set.i_hash[index] = match->next;
69208+ if (match->next != NULL)
69209+ match->next->prev = NULL;
69210+ } else {
69211+ match->prev->next = match->next;
69212+ if (match->next != NULL)
69213+ match->next->prev = match->prev;
69214+ }
69215+ match->prev = NULL;
69216+ match->next = NULL;
69217+ match->nentry->inode = newinode;
69218+ match->nentry->device = newdevice;
69219+ match->nentry->deleted = 0;
69220+
69221+ insert_inodev_entry(match);
69222+ }
69223+
69224+ return;
69225+}
69226+
69227+static void
69228+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
69229+{
69230+ struct acl_subject_label *subj;
69231+ struct acl_role_label *role;
69232+ unsigned int x;
69233+
69234+ FOR_EACH_ROLE_START(role)
69235+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
69236+
69237+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
69238+ if ((subj->inode == ino) && (subj->device == dev)) {
69239+ subj->inode = ino;
69240+ subj->device = dev;
69241+ }
69242+ /* nested subjects aren't in the role's subj_hash table */
69243+ update_acl_obj_label(matchn->inode, matchn->device,
69244+ ino, dev, subj);
69245+ FOR_EACH_NESTED_SUBJECT_END(subj)
69246+ FOR_EACH_SUBJECT_START(role, subj, x)
69247+ update_acl_obj_label(matchn->inode, matchn->device,
69248+ ino, dev, subj);
69249+ FOR_EACH_SUBJECT_END(subj,x)
69250+ FOR_EACH_ROLE_END(role)
69251+
69252+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
69253+
69254+ return;
69255+}
69256+
69257+static void
69258+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
69259+ const struct vfsmount *mnt)
69260+{
69261+ ino_t ino = dentry->d_inode->i_ino;
69262+ dev_t dev = __get_dev(dentry);
69263+
69264+ __do_handle_create(matchn, ino, dev);
69265+
69266+ return;
69267+}
69268+
69269+void
69270+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69271+{
69272+ struct name_entry *matchn;
69273+
69274+ if (unlikely(!(gr_status & GR_READY)))
69275+ return;
69276+
69277+ preempt_disable();
69278+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
69279+
69280+ if (unlikely((unsigned long)matchn)) {
69281+ write_lock(&gr_inode_lock);
69282+ do_handle_create(matchn, dentry, mnt);
69283+ write_unlock(&gr_inode_lock);
69284+ }
69285+ preempt_enable();
69286+
69287+ return;
69288+}
69289+
69290+void
69291+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69292+{
69293+ struct name_entry *matchn;
69294+
69295+ if (unlikely(!(gr_status & GR_READY)))
69296+ return;
69297+
69298+ preempt_disable();
69299+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
69300+
69301+ if (unlikely((unsigned long)matchn)) {
69302+ write_lock(&gr_inode_lock);
69303+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
69304+ write_unlock(&gr_inode_lock);
69305+ }
69306+ preempt_enable();
69307+
69308+ return;
69309+}
69310+
69311+void
69312+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69313+ struct dentry *old_dentry,
69314+ struct dentry *new_dentry,
69315+ struct vfsmount *mnt, const __u8 replace)
69316+{
69317+ struct name_entry *matchn;
69318+ struct inodev_entry *inodev;
69319+ struct inode *inode = new_dentry->d_inode;
69320+ ino_t old_ino = old_dentry->d_inode->i_ino;
69321+ dev_t old_dev = __get_dev(old_dentry);
69322+
69323+ /* vfs_rename swaps the name and parent link for old_dentry and
69324+ new_dentry
69325+ at this point, old_dentry has the new name, parent link, and inode
69326+ for the renamed file
69327+ if a file is being replaced by a rename, new_dentry has the inode
69328+ and name for the replaced file
69329+ */
69330+
69331+ if (unlikely(!(gr_status & GR_READY)))
69332+ return;
69333+
69334+ preempt_disable();
69335+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
69336+
69337+ /* we wouldn't have to check d_inode if it weren't for
69338+ NFS silly-renaming
69339+ */
69340+
69341+ write_lock(&gr_inode_lock);
69342+ if (unlikely(replace && inode)) {
69343+ ino_t new_ino = inode->i_ino;
69344+ dev_t new_dev = __get_dev(new_dentry);
69345+
69346+ inodev = lookup_inodev_entry(new_ino, new_dev);
69347+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
69348+ do_handle_delete(inodev, new_ino, new_dev);
69349+ }
69350+
69351+ inodev = lookup_inodev_entry(old_ino, old_dev);
69352+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
69353+ do_handle_delete(inodev, old_ino, old_dev);
69354+
69355+ if (unlikely((unsigned long)matchn))
69356+ do_handle_create(matchn, old_dentry, mnt);
69357+
69358+ write_unlock(&gr_inode_lock);
69359+ preempt_enable();
69360+
69361+ return;
69362+}
69363+
69364+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
69365+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
69366+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69367+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69368+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69369+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69370+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69371+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69372+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69373+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69374+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69375+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69376+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69377+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69378+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69379+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69380+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69381+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69382+};
69383+
69384+void
69385+gr_learn_resource(const struct task_struct *task,
69386+ const int res, const unsigned long wanted, const int gt)
69387+{
69388+ struct acl_subject_label *acl;
69389+ const struct cred *cred;
69390+
69391+ if (unlikely((gr_status & GR_READY) &&
69392+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69393+ goto skip_reslog;
69394+
69395+ gr_log_resource(task, res, wanted, gt);
69396+skip_reslog:
69397+
69398+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69399+ return;
69400+
69401+ acl = task->acl;
69402+
69403+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69404+ !(acl->resmask & (1U << (unsigned short) res))))
69405+ return;
69406+
69407+ if (wanted >= acl->res[res].rlim_cur) {
69408+ unsigned long res_add;
69409+
69410+ res_add = wanted + res_learn_bumps[res];
69411+
69412+ acl->res[res].rlim_cur = res_add;
69413+
69414+ if (wanted > acl->res[res].rlim_max)
69415+ acl->res[res].rlim_max = res_add;
69416+
69417+ /* only log the subject filename, since resource logging is supported for
69418+ single-subject learning only */
69419+ rcu_read_lock();
69420+ cred = __task_cred(task);
69421+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69422+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69423+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69424+ "", (unsigned long) res, &task->signal->saved_ip);
69425+ rcu_read_unlock();
69426+ }
69427+
69428+ return;
69429+}
69430+EXPORT_SYMBOL_GPL(gr_learn_resource);
69431+#endif
69432+
69433+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69434+void
69435+pax_set_initial_flags(struct linux_binprm *bprm)
69436+{
69437+ struct task_struct *task = current;
69438+ struct acl_subject_label *proc;
69439+ unsigned long flags;
69440+
69441+ if (unlikely(!(gr_status & GR_READY)))
69442+ return;
69443+
69444+ flags = pax_get_flags(task);
69445+
69446+ proc = task->acl;
69447+
69448+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69449+ flags &= ~MF_PAX_PAGEEXEC;
69450+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69451+ flags &= ~MF_PAX_SEGMEXEC;
69452+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69453+ flags &= ~MF_PAX_RANDMMAP;
69454+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69455+ flags &= ~MF_PAX_EMUTRAMP;
69456+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69457+ flags &= ~MF_PAX_MPROTECT;
69458+
69459+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69460+ flags |= MF_PAX_PAGEEXEC;
69461+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69462+ flags |= MF_PAX_SEGMEXEC;
69463+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69464+ flags |= MF_PAX_RANDMMAP;
69465+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69466+ flags |= MF_PAX_EMUTRAMP;
69467+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69468+ flags |= MF_PAX_MPROTECT;
69469+
69470+ pax_set_flags(task, flags);
69471+
69472+ return;
69473+}
69474+#endif
69475+
69476+int
69477+gr_handle_proc_ptrace(struct task_struct *task)
69478+{
69479+ struct file *filp;
69480+ struct task_struct *tmp = task;
69481+ struct task_struct *curtemp = current;
69482+ __u32 retmode;
69483+
69484+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69485+ if (unlikely(!(gr_status & GR_READY)))
69486+ return 0;
69487+#endif
69488+
69489+ read_lock(&tasklist_lock);
69490+ read_lock(&grsec_exec_file_lock);
69491+ filp = task->exec_file;
69492+
69493+ while (task_pid_nr(tmp) > 0) {
69494+ if (tmp == curtemp)
69495+ break;
69496+ tmp = tmp->real_parent;
69497+ }
69498+
69499+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69500+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69501+ read_unlock(&grsec_exec_file_lock);
69502+ read_unlock(&tasklist_lock);
69503+ return 1;
69504+ }
69505+
69506+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69507+ if (!(gr_status & GR_READY)) {
69508+ read_unlock(&grsec_exec_file_lock);
69509+ read_unlock(&tasklist_lock);
69510+ return 0;
69511+ }
69512+#endif
69513+
69514+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69515+ read_unlock(&grsec_exec_file_lock);
69516+ read_unlock(&tasklist_lock);
69517+
69518+ if (retmode & GR_NOPTRACE)
69519+ return 1;
69520+
69521+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69522+ && (current->acl != task->acl || (current->acl != current->role->root_label
69523+ && task_pid_nr(current) != task_pid_nr(task))))
69524+ return 1;
69525+
69526+ return 0;
69527+}
69528+
69529+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69530+{
69531+ if (unlikely(!(gr_status & GR_READY)))
69532+ return;
69533+
69534+ if (!(current->role->roletype & GR_ROLE_GOD))
69535+ return;
69536+
69537+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69538+ p->role->rolename, gr_task_roletype_to_char(p),
69539+ p->acl->filename);
69540+}
69541+
69542+int
69543+gr_handle_ptrace(struct task_struct *task, const long request)
69544+{
69545+ struct task_struct *tmp = task;
69546+ struct task_struct *curtemp = current;
69547+ __u32 retmode;
69548+
69549+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69550+ if (unlikely(!(gr_status & GR_READY)))
69551+ return 0;
69552+#endif
69553+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69554+ read_lock(&tasklist_lock);
69555+ while (task_pid_nr(tmp) > 0) {
69556+ if (tmp == curtemp)
69557+ break;
69558+ tmp = tmp->real_parent;
69559+ }
69560+
69561+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69562+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69563+ read_unlock(&tasklist_lock);
69564+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69565+ return 1;
69566+ }
69567+ read_unlock(&tasklist_lock);
69568+ }
69569+
69570+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69571+ if (!(gr_status & GR_READY))
69572+ return 0;
69573+#endif
69574+
69575+ read_lock(&grsec_exec_file_lock);
69576+ if (unlikely(!task->exec_file)) {
69577+ read_unlock(&grsec_exec_file_lock);
69578+ return 0;
69579+ }
69580+
69581+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69582+ read_unlock(&grsec_exec_file_lock);
69583+
69584+ if (retmode & GR_NOPTRACE) {
69585+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69586+ return 1;
69587+ }
69588+
69589+ if (retmode & GR_PTRACERD) {
69590+ switch (request) {
69591+ case PTRACE_SEIZE:
69592+ case PTRACE_POKETEXT:
69593+ case PTRACE_POKEDATA:
69594+ case PTRACE_POKEUSR:
69595+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69596+ case PTRACE_SETREGS:
69597+ case PTRACE_SETFPREGS:
69598+#endif
69599+#ifdef CONFIG_X86
69600+ case PTRACE_SETFPXREGS:
69601+#endif
69602+#ifdef CONFIG_ALTIVEC
69603+ case PTRACE_SETVRREGS:
69604+#endif
69605+ return 1;
69606+ default:
69607+ return 0;
69608+ }
69609+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
69610+ !(current->role->roletype & GR_ROLE_GOD) &&
69611+ (current->acl != task->acl)) {
69612+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69613+ return 1;
69614+ }
69615+
69616+ return 0;
69617+}
69618+
69619+static int is_writable_mmap(const struct file *filp)
69620+{
69621+ struct task_struct *task = current;
69622+ struct acl_object_label *obj, *obj2;
69623+
69624+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69625+ !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))) {
69626+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69627+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69628+ task->role->root_label);
69629+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69630+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69631+ return 1;
69632+ }
69633+ }
69634+ return 0;
69635+}
69636+
69637+int
69638+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69639+{
69640+ __u32 mode;
69641+
69642+ if (unlikely(!file || !(prot & PROT_EXEC)))
69643+ return 1;
69644+
69645+ if (is_writable_mmap(file))
69646+ return 0;
69647+
69648+ mode =
69649+ gr_search_file(file->f_path.dentry,
69650+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69651+ file->f_path.mnt);
69652+
69653+ if (!gr_tpe_allow(file))
69654+ return 0;
69655+
69656+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69657+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69658+ return 0;
69659+ } else if (unlikely(!(mode & GR_EXEC))) {
69660+ return 0;
69661+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69662+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69663+ return 1;
69664+ }
69665+
69666+ return 1;
69667+}
69668+
69669+int
69670+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69671+{
69672+ __u32 mode;
69673+
69674+ if (unlikely(!file || !(prot & PROT_EXEC)))
69675+ return 1;
69676+
69677+ if (is_writable_mmap(file))
69678+ return 0;
69679+
69680+ mode =
69681+ gr_search_file(file->f_path.dentry,
69682+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69683+ file->f_path.mnt);
69684+
69685+ if (!gr_tpe_allow(file))
69686+ return 0;
69687+
69688+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69689+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69690+ return 0;
69691+ } else if (unlikely(!(mode & GR_EXEC))) {
69692+ return 0;
69693+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69694+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69695+ return 1;
69696+ }
69697+
69698+ return 1;
69699+}
69700+
69701+void
69702+gr_acl_handle_psacct(struct task_struct *task, const long code)
69703+{
69704+ unsigned long runtime, cputime;
69705+ cputime_t utime, stime;
69706+ unsigned int wday, cday;
69707+ __u8 whr, chr;
69708+ __u8 wmin, cmin;
69709+ __u8 wsec, csec;
69710+ struct timespec timeval;
69711+
69712+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69713+ !(task->acl->mode & GR_PROCACCT)))
69714+ return;
69715+
69716+ do_posix_clock_monotonic_gettime(&timeval);
69717+ runtime = timeval.tv_sec - task->start_time.tv_sec;
69718+ wday = runtime / (60 * 60 * 24);
69719+ runtime -= wday * (60 * 60 * 24);
69720+ whr = runtime / (60 * 60);
69721+ runtime -= whr * (60 * 60);
69722+ wmin = runtime / 60;
69723+ runtime -= wmin * 60;
69724+ wsec = runtime;
69725+
69726+ task_cputime(task, &utime, &stime);
69727+ cputime = cputime_to_secs(utime + stime);
69728+ cday = cputime / (60 * 60 * 24);
69729+ cputime -= cday * (60 * 60 * 24);
69730+ chr = cputime / (60 * 60);
69731+ cputime -= chr * (60 * 60);
69732+ cmin = cputime / 60;
69733+ cputime -= cmin * 60;
69734+ csec = cputime;
69735+
69736+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69737+
69738+ return;
69739+}
69740+
69741+#ifdef CONFIG_TASKSTATS
69742+int gr_is_taskstats_denied(int pid)
69743+{
69744+ struct task_struct *task;
69745+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69746+ const struct cred *cred;
69747+#endif
69748+ int ret = 0;
69749+
69750+ /* restrict taskstats viewing to un-chrooted root users
69751+ who have the 'view' subject flag if the RBAC system is enabled
69752+ */
69753+
69754+ rcu_read_lock();
69755+ read_lock(&tasklist_lock);
69756+ task = find_task_by_vpid(pid);
69757+ if (task) {
69758+#ifdef CONFIG_GRKERNSEC_CHROOT
69759+ if (proc_is_chrooted(task))
69760+ ret = -EACCES;
69761+#endif
69762+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69763+ cred = __task_cred(task);
69764+#ifdef CONFIG_GRKERNSEC_PROC_USER
69765+ if (gr_is_global_nonroot(cred->uid))
69766+ ret = -EACCES;
69767+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69768+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69769+ ret = -EACCES;
69770+#endif
69771+#endif
69772+ if (gr_status & GR_READY) {
69773+ if (!(task->acl->mode & GR_VIEW))
69774+ ret = -EACCES;
69775+ }
69776+ } else
69777+ ret = -ENOENT;
69778+
69779+ read_unlock(&tasklist_lock);
69780+ rcu_read_unlock();
69781+
69782+ return ret;
69783+}
69784+#endif
69785+
69786+/* AUXV entries are filled via a descendant of search_binary_handler
69787+ after we've already applied the subject for the target
69788+*/
69789+int gr_acl_enable_at_secure(void)
69790+{
69791+ if (unlikely(!(gr_status & GR_READY)))
69792+ return 0;
69793+
69794+ if (current->acl->mode & GR_ATSECURE)
69795+ return 1;
69796+
69797+ return 0;
69798+}
69799+
69800+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69801+{
69802+ struct task_struct *task = current;
69803+ struct dentry *dentry = file->f_path.dentry;
69804+ struct vfsmount *mnt = file->f_path.mnt;
69805+ struct acl_object_label *obj, *tmp;
69806+ struct acl_subject_label *subj;
69807+ unsigned int bufsize;
69808+ int is_not_root;
69809+ char *path;
69810+ dev_t dev = __get_dev(dentry);
69811+
69812+ if (unlikely(!(gr_status & GR_READY)))
69813+ return 1;
69814+
69815+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69816+ return 1;
69817+
69818+ /* ignore Eric Biederman */
69819+ if (IS_PRIVATE(dentry->d_inode))
69820+ return 1;
69821+
69822+ subj = task->acl;
69823+ read_lock(&gr_inode_lock);
69824+ do {
69825+ obj = lookup_acl_obj_label(ino, dev, subj);
69826+ if (obj != NULL) {
69827+ read_unlock(&gr_inode_lock);
69828+ return (obj->mode & GR_FIND) ? 1 : 0;
69829+ }
69830+ } while ((subj = subj->parent_subject));
69831+ read_unlock(&gr_inode_lock);
69832+
69833+ /* this is purely an optimization since we're looking for an object
69834+ for the directory we're doing a readdir on
69835+ if it's possible for any globbed object to match the entry we're
69836+ filling into the directory, then the object we find here will be
69837+ an anchor point with attached globbed objects
69838+ */
69839+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69840+ if (obj->globbed == NULL)
69841+ return (obj->mode & GR_FIND) ? 1 : 0;
69842+
69843+ is_not_root = ((obj->filename[0] == '/') &&
69844+ (obj->filename[1] == '\0')) ? 0 : 1;
69845+ bufsize = PAGE_SIZE - namelen - is_not_root;
69846+
69847+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69848+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69849+ return 1;
69850+
69851+ preempt_disable();
69852+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69853+ bufsize);
69854+
69855+ bufsize = strlen(path);
69856+
69857+ /* if base is "/", don't append an additional slash */
69858+ if (is_not_root)
69859+ *(path + bufsize) = '/';
69860+ memcpy(path + bufsize + is_not_root, name, namelen);
69861+ *(path + bufsize + namelen + is_not_root) = '\0';
69862+
69863+ tmp = obj->globbed;
69864+ while (tmp) {
69865+ if (!glob_match(tmp->filename, path)) {
69866+ preempt_enable();
69867+ return (tmp->mode & GR_FIND) ? 1 : 0;
69868+ }
69869+ tmp = tmp->next;
69870+ }
69871+ preempt_enable();
69872+ return (obj->mode & GR_FIND) ? 1 : 0;
69873+}
69874+
69875+void gr_put_exec_file(struct task_struct *task)
69876+{
69877+ struct file *filp;
69878+
69879+ write_lock(&grsec_exec_file_lock);
69880+ filp = task->exec_file;
69881+ task->exec_file = NULL;
69882+ write_unlock(&grsec_exec_file_lock);
69883+
69884+ if (filp)
69885+ fput(filp);
69886+
69887+ return;
69888+}
69889+
69890+
69891+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69892+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69893+#endif
69894+#ifdef CONFIG_SECURITY
69895+EXPORT_SYMBOL_GPL(gr_check_user_change);
69896+EXPORT_SYMBOL_GPL(gr_check_group_change);
69897+#endif
69898+
69899diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69900new file mode 100644
69901index 0000000..18ffbbd
69902--- /dev/null
69903+++ b/grsecurity/gracl_alloc.c
69904@@ -0,0 +1,105 @@
69905+#include <linux/kernel.h>
69906+#include <linux/mm.h>
69907+#include <linux/slab.h>
69908+#include <linux/vmalloc.h>
69909+#include <linux/gracl.h>
69910+#include <linux/grsecurity.h>
69911+
69912+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69913+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69914+
69915+static __inline__ int
69916+alloc_pop(void)
69917+{
69918+ if (current_alloc_state->alloc_stack_next == 1)
69919+ return 0;
69920+
69921+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69922+
69923+ current_alloc_state->alloc_stack_next--;
69924+
69925+ return 1;
69926+}
69927+
69928+static __inline__ int
69929+alloc_push(void *buf)
69930+{
69931+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69932+ return 1;
69933+
69934+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69935+
69936+ current_alloc_state->alloc_stack_next++;
69937+
69938+ return 0;
69939+}
69940+
69941+void *
69942+acl_alloc(unsigned long len)
69943+{
69944+ void *ret = NULL;
69945+
69946+ if (!len || len > PAGE_SIZE)
69947+ goto out;
69948+
69949+ ret = kmalloc(len, GFP_KERNEL);
69950+
69951+ if (ret) {
69952+ if (alloc_push(ret)) {
69953+ kfree(ret);
69954+ ret = NULL;
69955+ }
69956+ }
69957+
69958+out:
69959+ return ret;
69960+}
69961+
69962+void *
69963+acl_alloc_num(unsigned long num, unsigned long len)
69964+{
69965+ if (!len || (num > (PAGE_SIZE / len)))
69966+ return NULL;
69967+
69968+ return acl_alloc(num * len);
69969+}
69970+
69971+void
69972+acl_free_all(void)
69973+{
69974+ if (!current_alloc_state->alloc_stack)
69975+ return;
69976+
69977+ while (alloc_pop()) ;
69978+
69979+ if (current_alloc_state->alloc_stack) {
69980+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69981+ kfree(current_alloc_state->alloc_stack);
69982+ else
69983+ vfree(current_alloc_state->alloc_stack);
69984+ }
69985+
69986+ current_alloc_state->alloc_stack = NULL;
69987+ current_alloc_state->alloc_stack_size = 1;
69988+ current_alloc_state->alloc_stack_next = 1;
69989+
69990+ return;
69991+}
69992+
69993+int
69994+acl_alloc_stack_init(unsigned long size)
69995+{
69996+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69997+ current_alloc_state->alloc_stack =
69998+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69999+ else
70000+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
70001+
70002+ current_alloc_state->alloc_stack_size = size;
70003+ current_alloc_state->alloc_stack_next = 1;
70004+
70005+ if (!current_alloc_state->alloc_stack)
70006+ return 0;
70007+ else
70008+ return 1;
70009+}
70010diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
70011new file mode 100644
70012index 0000000..bdd51ea
70013--- /dev/null
70014+++ b/grsecurity/gracl_cap.c
70015@@ -0,0 +1,110 @@
70016+#include <linux/kernel.h>
70017+#include <linux/module.h>
70018+#include <linux/sched.h>
70019+#include <linux/gracl.h>
70020+#include <linux/grsecurity.h>
70021+#include <linux/grinternal.h>
70022+
70023+extern const char *captab_log[];
70024+extern int captab_log_entries;
70025+
70026+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
70027+{
70028+ struct acl_subject_label *curracl;
70029+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70030+ kernel_cap_t cap_audit = __cap_empty_set;
70031+
70032+ if (!gr_acl_is_enabled())
70033+ return 1;
70034+
70035+ curracl = task->acl;
70036+
70037+ cap_drop = curracl->cap_lower;
70038+ cap_mask = curracl->cap_mask;
70039+ cap_audit = curracl->cap_invert_audit;
70040+
70041+ while ((curracl = curracl->parent_subject)) {
70042+ /* if the cap isn't specified in the current computed mask but is specified in the
70043+ current level subject, and is lowered in the current level subject, then add
70044+ it to the set of dropped capabilities
70045+ otherwise, add the current level subject's mask to the current computed mask
70046+ */
70047+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70048+ cap_raise(cap_mask, cap);
70049+ if (cap_raised(curracl->cap_lower, cap))
70050+ cap_raise(cap_drop, cap);
70051+ if (cap_raised(curracl->cap_invert_audit, cap))
70052+ cap_raise(cap_audit, cap);
70053+ }
70054+ }
70055+
70056+ if (!cap_raised(cap_drop, cap)) {
70057+ if (cap_raised(cap_audit, cap))
70058+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
70059+ return 1;
70060+ }
70061+
70062+ curracl = task->acl;
70063+
70064+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
70065+ && cap_raised(cred->cap_effective, cap)) {
70066+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
70067+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
70068+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
70069+ gr_to_filename(task->exec_file->f_path.dentry,
70070+ task->exec_file->f_path.mnt) : curracl->filename,
70071+ curracl->filename, 0UL,
70072+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
70073+ return 1;
70074+ }
70075+
70076+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
70077+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
70078+
70079+ return 0;
70080+}
70081+
70082+int
70083+gr_acl_is_capable(const int cap)
70084+{
70085+ return gr_task_acl_is_capable(current, current_cred(), cap);
70086+}
70087+
70088+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
70089+{
70090+ struct acl_subject_label *curracl;
70091+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70092+
70093+ if (!gr_acl_is_enabled())
70094+ return 1;
70095+
70096+ curracl = task->acl;
70097+
70098+ cap_drop = curracl->cap_lower;
70099+ cap_mask = curracl->cap_mask;
70100+
70101+ while ((curracl = curracl->parent_subject)) {
70102+ /* if the cap isn't specified in the current computed mask but is specified in the
70103+ current level subject, and is lowered in the current level subject, then add
70104+ it to the set of dropped capabilities
70105+ otherwise, add the current level subject's mask to the current computed mask
70106+ */
70107+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70108+ cap_raise(cap_mask, cap);
70109+ if (cap_raised(curracl->cap_lower, cap))
70110+ cap_raise(cap_drop, cap);
70111+ }
70112+ }
70113+
70114+ if (!cap_raised(cap_drop, cap))
70115+ return 1;
70116+
70117+ return 0;
70118+}
70119+
70120+int
70121+gr_acl_is_capable_nolog(const int cap)
70122+{
70123+ return gr_task_acl_is_capable_nolog(current, cap);
70124+}
70125+
70126diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
70127new file mode 100644
70128index 0000000..ca25605
70129--- /dev/null
70130+++ b/grsecurity/gracl_compat.c
70131@@ -0,0 +1,270 @@
70132+#include <linux/kernel.h>
70133+#include <linux/gracl.h>
70134+#include <linux/compat.h>
70135+#include <linux/gracl_compat.h>
70136+
70137+#include <asm/uaccess.h>
70138+
70139+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
70140+{
70141+ struct gr_arg_wrapper_compat uwrapcompat;
70142+
70143+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
70144+ return -EFAULT;
70145+
70146+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
70147+ (uwrapcompat.version != 0x2901)) ||
70148+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
70149+ return -EINVAL;
70150+
70151+ uwrap->arg = compat_ptr(uwrapcompat.arg);
70152+ uwrap->version = uwrapcompat.version;
70153+ uwrap->size = sizeof(struct gr_arg);
70154+
70155+ return 0;
70156+}
70157+
70158+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
70159+{
70160+ struct gr_arg_compat argcompat;
70161+
70162+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
70163+ return -EFAULT;
70164+
70165+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
70166+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
70167+ arg->role_db.num_roles = argcompat.role_db.num_roles;
70168+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
70169+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
70170+ arg->role_db.num_objects = argcompat.role_db.num_objects;
70171+
70172+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
70173+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
70174+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
70175+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
70176+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
70177+ arg->segv_device = argcompat.segv_device;
70178+ arg->segv_inode = argcompat.segv_inode;
70179+ arg->segv_uid = argcompat.segv_uid;
70180+ arg->num_sprole_pws = argcompat.num_sprole_pws;
70181+ arg->mode = argcompat.mode;
70182+
70183+ return 0;
70184+}
70185+
70186+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
70187+{
70188+ struct acl_object_label_compat objcompat;
70189+
70190+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
70191+ return -EFAULT;
70192+
70193+ obj->filename = compat_ptr(objcompat.filename);
70194+ obj->inode = objcompat.inode;
70195+ obj->device = objcompat.device;
70196+ obj->mode = objcompat.mode;
70197+
70198+ obj->nested = compat_ptr(objcompat.nested);
70199+ obj->globbed = compat_ptr(objcompat.globbed);
70200+
70201+ obj->prev = compat_ptr(objcompat.prev);
70202+ obj->next = compat_ptr(objcompat.next);
70203+
70204+ return 0;
70205+}
70206+
70207+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70208+{
70209+ unsigned int i;
70210+ struct acl_subject_label_compat subjcompat;
70211+
70212+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
70213+ return -EFAULT;
70214+
70215+ subj->filename = compat_ptr(subjcompat.filename);
70216+ subj->inode = subjcompat.inode;
70217+ subj->device = subjcompat.device;
70218+ subj->mode = subjcompat.mode;
70219+ subj->cap_mask = subjcompat.cap_mask;
70220+ subj->cap_lower = subjcompat.cap_lower;
70221+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
70222+
70223+ for (i = 0; i < GR_NLIMITS; i++) {
70224+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
70225+ subj->res[i].rlim_cur = RLIM_INFINITY;
70226+ else
70227+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
70228+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
70229+ subj->res[i].rlim_max = RLIM_INFINITY;
70230+ else
70231+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
70232+ }
70233+ subj->resmask = subjcompat.resmask;
70234+
70235+ subj->user_trans_type = subjcompat.user_trans_type;
70236+ subj->group_trans_type = subjcompat.group_trans_type;
70237+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
70238+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
70239+ subj->user_trans_num = subjcompat.user_trans_num;
70240+ subj->group_trans_num = subjcompat.group_trans_num;
70241+
70242+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
70243+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
70244+ subj->ip_type = subjcompat.ip_type;
70245+ subj->ips = compat_ptr(subjcompat.ips);
70246+ subj->ip_num = subjcompat.ip_num;
70247+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
70248+
70249+ subj->crashes = subjcompat.crashes;
70250+ subj->expires = subjcompat.expires;
70251+
70252+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
70253+ subj->hash = compat_ptr(subjcompat.hash);
70254+ subj->prev = compat_ptr(subjcompat.prev);
70255+ subj->next = compat_ptr(subjcompat.next);
70256+
70257+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
70258+ subj->obj_hash_size = subjcompat.obj_hash_size;
70259+ subj->pax_flags = subjcompat.pax_flags;
70260+
70261+ return 0;
70262+}
70263+
70264+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
70265+{
70266+ struct acl_role_label_compat rolecompat;
70267+
70268+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
70269+ return -EFAULT;
70270+
70271+ role->rolename = compat_ptr(rolecompat.rolename);
70272+ role->uidgid = rolecompat.uidgid;
70273+ role->roletype = rolecompat.roletype;
70274+
70275+ role->auth_attempts = rolecompat.auth_attempts;
70276+ role->expires = rolecompat.expires;
70277+
70278+ role->root_label = compat_ptr(rolecompat.root_label);
70279+ role->hash = compat_ptr(rolecompat.hash);
70280+
70281+ role->prev = compat_ptr(rolecompat.prev);
70282+ role->next = compat_ptr(rolecompat.next);
70283+
70284+ role->transitions = compat_ptr(rolecompat.transitions);
70285+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
70286+ role->domain_children = compat_ptr(rolecompat.domain_children);
70287+ role->domain_child_num = rolecompat.domain_child_num;
70288+
70289+ role->umask = rolecompat.umask;
70290+
70291+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
70292+ role->subj_hash_size = rolecompat.subj_hash_size;
70293+
70294+ return 0;
70295+}
70296+
70297+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70298+{
70299+ struct role_allowed_ip_compat roleip_compat;
70300+
70301+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
70302+ return -EFAULT;
70303+
70304+ roleip->addr = roleip_compat.addr;
70305+ roleip->netmask = roleip_compat.netmask;
70306+
70307+ roleip->prev = compat_ptr(roleip_compat.prev);
70308+ roleip->next = compat_ptr(roleip_compat.next);
70309+
70310+ return 0;
70311+}
70312+
70313+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
70314+{
70315+ struct role_transition_compat trans_compat;
70316+
70317+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
70318+ return -EFAULT;
70319+
70320+ trans->rolename = compat_ptr(trans_compat.rolename);
70321+
70322+ trans->prev = compat_ptr(trans_compat.prev);
70323+ trans->next = compat_ptr(trans_compat.next);
70324+
70325+ return 0;
70326+
70327+}
70328+
70329+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70330+{
70331+ struct gr_hash_struct_compat hash_compat;
70332+
70333+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
70334+ return -EFAULT;
70335+
70336+ hash->table = compat_ptr(hash_compat.table);
70337+ hash->nametable = compat_ptr(hash_compat.nametable);
70338+ hash->first = compat_ptr(hash_compat.first);
70339+
70340+ hash->table_size = hash_compat.table_size;
70341+ hash->used_size = hash_compat.used_size;
70342+
70343+ hash->type = hash_compat.type;
70344+
70345+ return 0;
70346+}
70347+
70348+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
70349+{
70350+ compat_uptr_t ptrcompat;
70351+
70352+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
70353+ return -EFAULT;
70354+
70355+ *(void **)ptr = compat_ptr(ptrcompat);
70356+
70357+ return 0;
70358+}
70359+
70360+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70361+{
70362+ struct acl_ip_label_compat ip_compat;
70363+
70364+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
70365+ return -EFAULT;
70366+
70367+ ip->iface = compat_ptr(ip_compat.iface);
70368+ ip->addr = ip_compat.addr;
70369+ ip->netmask = ip_compat.netmask;
70370+ ip->low = ip_compat.low;
70371+ ip->high = ip_compat.high;
70372+ ip->mode = ip_compat.mode;
70373+ ip->type = ip_compat.type;
70374+
70375+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70376+
70377+ ip->prev = compat_ptr(ip_compat.prev);
70378+ ip->next = compat_ptr(ip_compat.next);
70379+
70380+ return 0;
70381+}
70382+
70383+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70384+{
70385+ struct sprole_pw_compat pw_compat;
70386+
70387+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70388+ return -EFAULT;
70389+
70390+ pw->rolename = compat_ptr(pw_compat.rolename);
70391+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70392+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70393+
70394+ return 0;
70395+}
70396+
70397+size_t get_gr_arg_wrapper_size_compat(void)
70398+{
70399+ return sizeof(struct gr_arg_wrapper_compat);
70400+}
70401+
70402diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70403new file mode 100644
70404index 0000000..a89b1f4
70405--- /dev/null
70406+++ b/grsecurity/gracl_fs.c
70407@@ -0,0 +1,437 @@
70408+#include <linux/kernel.h>
70409+#include <linux/sched.h>
70410+#include <linux/types.h>
70411+#include <linux/fs.h>
70412+#include <linux/file.h>
70413+#include <linux/stat.h>
70414+#include <linux/grsecurity.h>
70415+#include <linux/grinternal.h>
70416+#include <linux/gracl.h>
70417+
70418+umode_t
70419+gr_acl_umask(void)
70420+{
70421+ if (unlikely(!gr_acl_is_enabled()))
70422+ return 0;
70423+
70424+ return current->role->umask;
70425+}
70426+
70427+__u32
70428+gr_acl_handle_hidden_file(const struct dentry * dentry,
70429+ const struct vfsmount * mnt)
70430+{
70431+ __u32 mode;
70432+
70433+ if (unlikely(d_is_negative(dentry)))
70434+ return GR_FIND;
70435+
70436+ mode =
70437+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70438+
70439+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70440+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70441+ return mode;
70442+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70443+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70444+ return 0;
70445+ } else if (unlikely(!(mode & GR_FIND)))
70446+ return 0;
70447+
70448+ return GR_FIND;
70449+}
70450+
70451+__u32
70452+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70453+ int acc_mode)
70454+{
70455+ __u32 reqmode = GR_FIND;
70456+ __u32 mode;
70457+
70458+ if (unlikely(d_is_negative(dentry)))
70459+ return reqmode;
70460+
70461+ if (acc_mode & MAY_APPEND)
70462+ reqmode |= GR_APPEND;
70463+ else if (acc_mode & MAY_WRITE)
70464+ reqmode |= GR_WRITE;
70465+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70466+ reqmode |= GR_READ;
70467+
70468+ mode =
70469+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70470+ mnt);
70471+
70472+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70473+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70474+ reqmode & GR_READ ? " reading" : "",
70475+ reqmode & GR_WRITE ? " writing" : reqmode &
70476+ GR_APPEND ? " appending" : "");
70477+ return reqmode;
70478+ } else
70479+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70480+ {
70481+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70482+ reqmode & GR_READ ? " reading" : "",
70483+ reqmode & GR_WRITE ? " writing" : reqmode &
70484+ GR_APPEND ? " appending" : "");
70485+ return 0;
70486+ } else if (unlikely((mode & reqmode) != reqmode))
70487+ return 0;
70488+
70489+ return reqmode;
70490+}
70491+
70492+__u32
70493+gr_acl_handle_creat(const struct dentry * dentry,
70494+ const struct dentry * p_dentry,
70495+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70496+ const int imode)
70497+{
70498+ __u32 reqmode = GR_WRITE | GR_CREATE;
70499+ __u32 mode;
70500+
70501+ if (acc_mode & MAY_APPEND)
70502+ reqmode |= GR_APPEND;
70503+ // if a directory was required or the directory already exists, then
70504+ // don't count this open as a read
70505+ if ((acc_mode & MAY_READ) &&
70506+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70507+ reqmode |= GR_READ;
70508+ if ((open_flags & O_CREAT) &&
70509+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70510+ reqmode |= GR_SETID;
70511+
70512+ mode =
70513+ gr_check_create(dentry, p_dentry, p_mnt,
70514+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70515+
70516+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70517+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70518+ reqmode & GR_READ ? " reading" : "",
70519+ reqmode & GR_WRITE ? " writing" : reqmode &
70520+ GR_APPEND ? " appending" : "");
70521+ return reqmode;
70522+ } else
70523+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70524+ {
70525+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70526+ reqmode & GR_READ ? " reading" : "",
70527+ reqmode & GR_WRITE ? " writing" : reqmode &
70528+ GR_APPEND ? " appending" : "");
70529+ return 0;
70530+ } else if (unlikely((mode & reqmode) != reqmode))
70531+ return 0;
70532+
70533+ return reqmode;
70534+}
70535+
70536+__u32
70537+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70538+ const int fmode)
70539+{
70540+ __u32 mode, reqmode = GR_FIND;
70541+
70542+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70543+ reqmode |= GR_EXEC;
70544+ if (fmode & S_IWOTH)
70545+ reqmode |= GR_WRITE;
70546+ if (fmode & S_IROTH)
70547+ reqmode |= GR_READ;
70548+
70549+ mode =
70550+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70551+ mnt);
70552+
70553+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70554+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70555+ reqmode & GR_READ ? " reading" : "",
70556+ reqmode & GR_WRITE ? " writing" : "",
70557+ reqmode & GR_EXEC ? " executing" : "");
70558+ return reqmode;
70559+ } else
70560+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70561+ {
70562+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70563+ reqmode & GR_READ ? " reading" : "",
70564+ reqmode & GR_WRITE ? " writing" : "",
70565+ reqmode & GR_EXEC ? " executing" : "");
70566+ return 0;
70567+ } else if (unlikely((mode & reqmode) != reqmode))
70568+ return 0;
70569+
70570+ return reqmode;
70571+}
70572+
70573+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70574+{
70575+ __u32 mode;
70576+
70577+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70578+
70579+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70580+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70581+ return mode;
70582+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70583+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70584+ return 0;
70585+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70586+ return 0;
70587+
70588+ return (reqmode);
70589+}
70590+
70591+__u32
70592+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70593+{
70594+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70595+}
70596+
70597+__u32
70598+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70599+{
70600+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70601+}
70602+
70603+__u32
70604+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70605+{
70606+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70607+}
70608+
70609+__u32
70610+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70611+{
70612+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70613+}
70614+
70615+__u32
70616+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70617+ umode_t *modeptr)
70618+{
70619+ umode_t mode;
70620+
70621+ *modeptr &= ~gr_acl_umask();
70622+ mode = *modeptr;
70623+
70624+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70625+ return 1;
70626+
70627+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70628+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70629+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70630+ GR_CHMOD_ACL_MSG);
70631+ } else {
70632+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70633+ }
70634+}
70635+
70636+__u32
70637+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70638+{
70639+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70640+}
70641+
70642+__u32
70643+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70644+{
70645+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70646+}
70647+
70648+__u32
70649+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70650+{
70651+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70652+}
70653+
70654+__u32
70655+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70656+{
70657+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70658+}
70659+
70660+__u32
70661+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70662+{
70663+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70664+ GR_UNIXCONNECT_ACL_MSG);
70665+}
70666+
70667+/* hardlinks require at minimum create and link permission,
70668+ any additional privilege required is based on the
70669+ privilege of the file being linked to
70670+*/
70671+__u32
70672+gr_acl_handle_link(const struct dentry * new_dentry,
70673+ const struct dentry * parent_dentry,
70674+ const struct vfsmount * parent_mnt,
70675+ const struct dentry * old_dentry,
70676+ const struct vfsmount * old_mnt, const struct filename *to)
70677+{
70678+ __u32 mode;
70679+ __u32 needmode = GR_CREATE | GR_LINK;
70680+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70681+
70682+ mode =
70683+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70684+ old_mnt);
70685+
70686+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70687+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70688+ return mode;
70689+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70690+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70691+ return 0;
70692+ } else if (unlikely((mode & needmode) != needmode))
70693+ return 0;
70694+
70695+ return 1;
70696+}
70697+
70698+__u32
70699+gr_acl_handle_symlink(const struct dentry * new_dentry,
70700+ const struct dentry * parent_dentry,
70701+ const struct vfsmount * parent_mnt, const struct filename *from)
70702+{
70703+ __u32 needmode = GR_WRITE | GR_CREATE;
70704+ __u32 mode;
70705+
70706+ mode =
70707+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
70708+ GR_CREATE | GR_AUDIT_CREATE |
70709+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70710+
70711+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70712+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70713+ return mode;
70714+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70715+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70716+ return 0;
70717+ } else if (unlikely((mode & needmode) != needmode))
70718+ return 0;
70719+
70720+ return (GR_WRITE | GR_CREATE);
70721+}
70722+
70723+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)
70724+{
70725+ __u32 mode;
70726+
70727+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70728+
70729+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70730+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70731+ return mode;
70732+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70733+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70734+ return 0;
70735+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70736+ return 0;
70737+
70738+ return (reqmode);
70739+}
70740+
70741+__u32
70742+gr_acl_handle_mknod(const struct dentry * new_dentry,
70743+ const struct dentry * parent_dentry,
70744+ const struct vfsmount * parent_mnt,
70745+ const int mode)
70746+{
70747+ __u32 reqmode = GR_WRITE | GR_CREATE;
70748+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70749+ reqmode |= GR_SETID;
70750+
70751+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70752+ reqmode, GR_MKNOD_ACL_MSG);
70753+}
70754+
70755+__u32
70756+gr_acl_handle_mkdir(const struct dentry *new_dentry,
70757+ const struct dentry *parent_dentry,
70758+ const struct vfsmount *parent_mnt)
70759+{
70760+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70761+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70762+}
70763+
70764+#define RENAME_CHECK_SUCCESS(old, new) \
70765+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70766+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70767+
70768+int
70769+gr_acl_handle_rename(struct dentry *new_dentry,
70770+ struct dentry *parent_dentry,
70771+ const struct vfsmount *parent_mnt,
70772+ struct dentry *old_dentry,
70773+ struct inode *old_parent_inode,
70774+ struct vfsmount *old_mnt, const struct filename *newname)
70775+{
70776+ __u32 comp1, comp2;
70777+ int error = 0;
70778+
70779+ if (unlikely(!gr_acl_is_enabled()))
70780+ return 0;
70781+
70782+ if (d_is_negative(new_dentry)) {
70783+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70784+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70785+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70786+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70787+ GR_DELETE | GR_AUDIT_DELETE |
70788+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70789+ GR_SUPPRESS, old_mnt);
70790+ } else {
70791+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70792+ GR_CREATE | GR_DELETE |
70793+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70794+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70795+ GR_SUPPRESS, parent_mnt);
70796+ comp2 =
70797+ gr_search_file(old_dentry,
70798+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70799+ GR_DELETE | GR_AUDIT_DELETE |
70800+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70801+ }
70802+
70803+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70804+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70805+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70806+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70807+ && !(comp2 & GR_SUPPRESS)) {
70808+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70809+ error = -EACCES;
70810+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70811+ error = -EACCES;
70812+
70813+ return error;
70814+}
70815+
70816+void
70817+gr_acl_handle_exit(void)
70818+{
70819+ u16 id;
70820+ char *rolename;
70821+
70822+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70823+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70824+ id = current->acl_role_id;
70825+ rolename = current->role->rolename;
70826+ gr_set_acls(1);
70827+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70828+ }
70829+
70830+ gr_put_exec_file(current);
70831+ return;
70832+}
70833+
70834+int
70835+gr_acl_handle_procpidmem(const struct task_struct *task)
70836+{
70837+ if (unlikely(!gr_acl_is_enabled()))
70838+ return 0;
70839+
70840+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70841+ return -EACCES;
70842+
70843+ return 0;
70844+}
70845diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70846new file mode 100644
70847index 0000000..f056b81
70848--- /dev/null
70849+++ b/grsecurity/gracl_ip.c
70850@@ -0,0 +1,386 @@
70851+#include <linux/kernel.h>
70852+#include <asm/uaccess.h>
70853+#include <asm/errno.h>
70854+#include <net/sock.h>
70855+#include <linux/file.h>
70856+#include <linux/fs.h>
70857+#include <linux/net.h>
70858+#include <linux/in.h>
70859+#include <linux/skbuff.h>
70860+#include <linux/ip.h>
70861+#include <linux/udp.h>
70862+#include <linux/types.h>
70863+#include <linux/sched.h>
70864+#include <linux/netdevice.h>
70865+#include <linux/inetdevice.h>
70866+#include <linux/gracl.h>
70867+#include <linux/grsecurity.h>
70868+#include <linux/grinternal.h>
70869+
70870+#define GR_BIND 0x01
70871+#define GR_CONNECT 0x02
70872+#define GR_INVERT 0x04
70873+#define GR_BINDOVERRIDE 0x08
70874+#define GR_CONNECTOVERRIDE 0x10
70875+#define GR_SOCK_FAMILY 0x20
70876+
70877+static const char * gr_protocols[IPPROTO_MAX] = {
70878+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70879+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70880+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70881+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70882+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70883+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70884+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70885+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70886+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70887+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70888+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70889+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70890+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70891+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70892+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70893+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70894+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70895+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70896+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70897+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70898+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70899+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70900+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70901+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70902+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70903+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70904+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70905+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70906+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70907+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70908+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70909+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70910+ };
70911+
70912+static const char * gr_socktypes[SOCK_MAX] = {
70913+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70914+ "unknown:7", "unknown:8", "unknown:9", "packet"
70915+ };
70916+
70917+static const char * gr_sockfamilies[AF_MAX+1] = {
70918+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70919+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70920+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70921+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70922+ };
70923+
70924+const char *
70925+gr_proto_to_name(unsigned char proto)
70926+{
70927+ return gr_protocols[proto];
70928+}
70929+
70930+const char *
70931+gr_socktype_to_name(unsigned char type)
70932+{
70933+ return gr_socktypes[type];
70934+}
70935+
70936+const char *
70937+gr_sockfamily_to_name(unsigned char family)
70938+{
70939+ return gr_sockfamilies[family];
70940+}
70941+
70942+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70943+
70944+int
70945+gr_search_socket(const int domain, const int type, const int protocol)
70946+{
70947+ struct acl_subject_label *curr;
70948+ const struct cred *cred = current_cred();
70949+
70950+ if (unlikely(!gr_acl_is_enabled()))
70951+ goto exit;
70952+
70953+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70954+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70955+ goto exit; // let the kernel handle it
70956+
70957+ curr = current->acl;
70958+
70959+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70960+ /* the family is allowed, if this is PF_INET allow it only if
70961+ the extra sock type/protocol checks pass */
70962+ if (domain == PF_INET)
70963+ goto inet_check;
70964+ goto exit;
70965+ } else {
70966+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70967+ __u32 fakeip = 0;
70968+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70969+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70970+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70971+ gr_to_filename(current->exec_file->f_path.dentry,
70972+ current->exec_file->f_path.mnt) :
70973+ curr->filename, curr->filename,
70974+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70975+ &current->signal->saved_ip);
70976+ goto exit;
70977+ }
70978+ goto exit_fail;
70979+ }
70980+
70981+inet_check:
70982+ /* the rest of this checking is for IPv4 only */
70983+ if (!curr->ips)
70984+ goto exit;
70985+
70986+ if ((curr->ip_type & (1U << type)) &&
70987+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70988+ goto exit;
70989+
70990+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70991+ /* we don't place acls on raw sockets , and sometimes
70992+ dgram/ip sockets are opened for ioctl and not
70993+ bind/connect, so we'll fake a bind learn log */
70994+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70995+ __u32 fakeip = 0;
70996+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70997+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70998+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70999+ gr_to_filename(current->exec_file->f_path.dentry,
71000+ current->exec_file->f_path.mnt) :
71001+ curr->filename, curr->filename,
71002+ &fakeip, 0, type,
71003+ protocol, GR_CONNECT, &current->signal->saved_ip);
71004+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
71005+ __u32 fakeip = 0;
71006+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71007+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71008+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71009+ gr_to_filename(current->exec_file->f_path.dentry,
71010+ current->exec_file->f_path.mnt) :
71011+ curr->filename, curr->filename,
71012+ &fakeip, 0, type,
71013+ protocol, GR_BIND, &current->signal->saved_ip);
71014+ }
71015+ /* we'll log when they use connect or bind */
71016+ goto exit;
71017+ }
71018+
71019+exit_fail:
71020+ if (domain == PF_INET)
71021+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
71022+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
71023+ else if (rcu_access_pointer(net_families[domain]) != NULL)
71024+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
71025+ gr_socktype_to_name(type), protocol);
71026+
71027+ return 0;
71028+exit:
71029+ return 1;
71030+}
71031+
71032+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)
71033+{
71034+ if ((ip->mode & mode) &&
71035+ (ip_port >= ip->low) &&
71036+ (ip_port <= ip->high) &&
71037+ ((ntohl(ip_addr) & our_netmask) ==
71038+ (ntohl(our_addr) & our_netmask))
71039+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
71040+ && (ip->type & (1U << type))) {
71041+ if (ip->mode & GR_INVERT)
71042+ return 2; // specifically denied
71043+ else
71044+ return 1; // allowed
71045+ }
71046+
71047+ return 0; // not specifically allowed, may continue parsing
71048+}
71049+
71050+static int
71051+gr_search_connectbind(const int full_mode, struct sock *sk,
71052+ struct sockaddr_in *addr, const int type)
71053+{
71054+ char iface[IFNAMSIZ] = {0};
71055+ struct acl_subject_label *curr;
71056+ struct acl_ip_label *ip;
71057+ struct inet_sock *isk;
71058+ struct net_device *dev;
71059+ struct in_device *idev;
71060+ unsigned long i;
71061+ int ret;
71062+ int mode = full_mode & (GR_BIND | GR_CONNECT);
71063+ __u32 ip_addr = 0;
71064+ __u32 our_addr;
71065+ __u32 our_netmask;
71066+ char *p;
71067+ __u16 ip_port = 0;
71068+ const struct cred *cred = current_cred();
71069+
71070+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
71071+ return 0;
71072+
71073+ curr = current->acl;
71074+ isk = inet_sk(sk);
71075+
71076+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
71077+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
71078+ addr->sin_addr.s_addr = curr->inaddr_any_override;
71079+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
71080+ struct sockaddr_in saddr;
71081+ int err;
71082+
71083+ saddr.sin_family = AF_INET;
71084+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
71085+ saddr.sin_port = isk->inet_sport;
71086+
71087+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71088+ if (err)
71089+ return err;
71090+
71091+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71092+ if (err)
71093+ return err;
71094+ }
71095+
71096+ if (!curr->ips)
71097+ return 0;
71098+
71099+ ip_addr = addr->sin_addr.s_addr;
71100+ ip_port = ntohs(addr->sin_port);
71101+
71102+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71103+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71104+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71105+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71106+ gr_to_filename(current->exec_file->f_path.dentry,
71107+ current->exec_file->f_path.mnt) :
71108+ curr->filename, curr->filename,
71109+ &ip_addr, ip_port, type,
71110+ sk->sk_protocol, mode, &current->signal->saved_ip);
71111+ return 0;
71112+ }
71113+
71114+ for (i = 0; i < curr->ip_num; i++) {
71115+ ip = *(curr->ips + i);
71116+ if (ip->iface != NULL) {
71117+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
71118+ p = strchr(iface, ':');
71119+ if (p != NULL)
71120+ *p = '\0';
71121+ dev = dev_get_by_name(sock_net(sk), iface);
71122+ if (dev == NULL)
71123+ continue;
71124+ idev = in_dev_get(dev);
71125+ if (idev == NULL) {
71126+ dev_put(dev);
71127+ continue;
71128+ }
71129+ rcu_read_lock();
71130+ for_ifa(idev) {
71131+ if (!strcmp(ip->iface, ifa->ifa_label)) {
71132+ our_addr = ifa->ifa_address;
71133+ our_netmask = 0xffffffff;
71134+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71135+ if (ret == 1) {
71136+ rcu_read_unlock();
71137+ in_dev_put(idev);
71138+ dev_put(dev);
71139+ return 0;
71140+ } else if (ret == 2) {
71141+ rcu_read_unlock();
71142+ in_dev_put(idev);
71143+ dev_put(dev);
71144+ goto denied;
71145+ }
71146+ }
71147+ } endfor_ifa(idev);
71148+ rcu_read_unlock();
71149+ in_dev_put(idev);
71150+ dev_put(dev);
71151+ } else {
71152+ our_addr = ip->addr;
71153+ our_netmask = ip->netmask;
71154+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71155+ if (ret == 1)
71156+ return 0;
71157+ else if (ret == 2)
71158+ goto denied;
71159+ }
71160+ }
71161+
71162+denied:
71163+ if (mode == GR_BIND)
71164+ 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));
71165+ else if (mode == GR_CONNECT)
71166+ 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));
71167+
71168+ return -EACCES;
71169+}
71170+
71171+int
71172+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
71173+{
71174+ /* always allow disconnection of dgram sockets with connect */
71175+ if (addr->sin_family == AF_UNSPEC)
71176+ return 0;
71177+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
71178+}
71179+
71180+int
71181+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
71182+{
71183+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
71184+}
71185+
71186+int gr_search_listen(struct socket *sock)
71187+{
71188+ struct sock *sk = sock->sk;
71189+ struct sockaddr_in addr;
71190+
71191+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71192+ addr.sin_port = inet_sk(sk)->inet_sport;
71193+
71194+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71195+}
71196+
71197+int gr_search_accept(struct socket *sock)
71198+{
71199+ struct sock *sk = sock->sk;
71200+ struct sockaddr_in addr;
71201+
71202+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71203+ addr.sin_port = inet_sk(sk)->inet_sport;
71204+
71205+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71206+}
71207+
71208+int
71209+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
71210+{
71211+ if (addr)
71212+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
71213+ else {
71214+ struct sockaddr_in sin;
71215+ const struct inet_sock *inet = inet_sk(sk);
71216+
71217+ sin.sin_addr.s_addr = inet->inet_daddr;
71218+ sin.sin_port = inet->inet_dport;
71219+
71220+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71221+ }
71222+}
71223+
71224+int
71225+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
71226+{
71227+ struct sockaddr_in sin;
71228+
71229+ if (unlikely(skb->len < sizeof (struct udphdr)))
71230+ return 0; // skip this packet
71231+
71232+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
71233+ sin.sin_port = udp_hdr(skb)->source;
71234+
71235+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71236+}
71237diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
71238new file mode 100644
71239index 0000000..25f54ef
71240--- /dev/null
71241+++ b/grsecurity/gracl_learn.c
71242@@ -0,0 +1,207 @@
71243+#include <linux/kernel.h>
71244+#include <linux/mm.h>
71245+#include <linux/sched.h>
71246+#include <linux/poll.h>
71247+#include <linux/string.h>
71248+#include <linux/file.h>
71249+#include <linux/types.h>
71250+#include <linux/vmalloc.h>
71251+#include <linux/grinternal.h>
71252+
71253+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
71254+ size_t count, loff_t *ppos);
71255+extern int gr_acl_is_enabled(void);
71256+
71257+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
71258+static int gr_learn_attached;
71259+
71260+/* use a 512k buffer */
71261+#define LEARN_BUFFER_SIZE (512 * 1024)
71262+
71263+static DEFINE_SPINLOCK(gr_learn_lock);
71264+static DEFINE_MUTEX(gr_learn_user_mutex);
71265+
71266+/* we need to maintain two buffers, so that the kernel context of grlearn
71267+ uses a semaphore around the userspace copying, and the other kernel contexts
71268+ use a spinlock when copying into the buffer, since they cannot sleep
71269+*/
71270+static char *learn_buffer;
71271+static char *learn_buffer_user;
71272+static int learn_buffer_len;
71273+static int learn_buffer_user_len;
71274+
71275+static ssize_t
71276+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
71277+{
71278+ DECLARE_WAITQUEUE(wait, current);
71279+ ssize_t retval = 0;
71280+
71281+ add_wait_queue(&learn_wait, &wait);
71282+ set_current_state(TASK_INTERRUPTIBLE);
71283+ do {
71284+ mutex_lock(&gr_learn_user_mutex);
71285+ spin_lock(&gr_learn_lock);
71286+ if (learn_buffer_len)
71287+ break;
71288+ spin_unlock(&gr_learn_lock);
71289+ mutex_unlock(&gr_learn_user_mutex);
71290+ if (file->f_flags & O_NONBLOCK) {
71291+ retval = -EAGAIN;
71292+ goto out;
71293+ }
71294+ if (signal_pending(current)) {
71295+ retval = -ERESTARTSYS;
71296+ goto out;
71297+ }
71298+
71299+ schedule();
71300+ } while (1);
71301+
71302+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
71303+ learn_buffer_user_len = learn_buffer_len;
71304+ retval = learn_buffer_len;
71305+ learn_buffer_len = 0;
71306+
71307+ spin_unlock(&gr_learn_lock);
71308+
71309+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
71310+ retval = -EFAULT;
71311+
71312+ mutex_unlock(&gr_learn_user_mutex);
71313+out:
71314+ set_current_state(TASK_RUNNING);
71315+ remove_wait_queue(&learn_wait, &wait);
71316+ return retval;
71317+}
71318+
71319+static unsigned int
71320+poll_learn(struct file * file, poll_table * wait)
71321+{
71322+ poll_wait(file, &learn_wait, wait);
71323+
71324+ if (learn_buffer_len)
71325+ return (POLLIN | POLLRDNORM);
71326+
71327+ return 0;
71328+}
71329+
71330+void
71331+gr_clear_learn_entries(void)
71332+{
71333+ char *tmp;
71334+
71335+ mutex_lock(&gr_learn_user_mutex);
71336+ spin_lock(&gr_learn_lock);
71337+ tmp = learn_buffer;
71338+ learn_buffer = NULL;
71339+ spin_unlock(&gr_learn_lock);
71340+ if (tmp)
71341+ vfree(tmp);
71342+ if (learn_buffer_user != NULL) {
71343+ vfree(learn_buffer_user);
71344+ learn_buffer_user = NULL;
71345+ }
71346+ learn_buffer_len = 0;
71347+ mutex_unlock(&gr_learn_user_mutex);
71348+
71349+ return;
71350+}
71351+
71352+void
71353+gr_add_learn_entry(const char *fmt, ...)
71354+{
71355+ va_list args;
71356+ unsigned int len;
71357+
71358+ if (!gr_learn_attached)
71359+ return;
71360+
71361+ spin_lock(&gr_learn_lock);
71362+
71363+ /* leave a gap at the end so we know when it's "full" but don't have to
71364+ compute the exact length of the string we're trying to append
71365+ */
71366+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71367+ spin_unlock(&gr_learn_lock);
71368+ wake_up_interruptible(&learn_wait);
71369+ return;
71370+ }
71371+ if (learn_buffer == NULL) {
71372+ spin_unlock(&gr_learn_lock);
71373+ return;
71374+ }
71375+
71376+ va_start(args, fmt);
71377+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71378+ va_end(args);
71379+
71380+ learn_buffer_len += len + 1;
71381+
71382+ spin_unlock(&gr_learn_lock);
71383+ wake_up_interruptible(&learn_wait);
71384+
71385+ return;
71386+}
71387+
71388+static int
71389+open_learn(struct inode *inode, struct file *file)
71390+{
71391+ if (file->f_mode & FMODE_READ && gr_learn_attached)
71392+ return -EBUSY;
71393+ if (file->f_mode & FMODE_READ) {
71394+ int retval = 0;
71395+ mutex_lock(&gr_learn_user_mutex);
71396+ if (learn_buffer == NULL)
71397+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71398+ if (learn_buffer_user == NULL)
71399+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71400+ if (learn_buffer == NULL) {
71401+ retval = -ENOMEM;
71402+ goto out_error;
71403+ }
71404+ if (learn_buffer_user == NULL) {
71405+ retval = -ENOMEM;
71406+ goto out_error;
71407+ }
71408+ learn_buffer_len = 0;
71409+ learn_buffer_user_len = 0;
71410+ gr_learn_attached = 1;
71411+out_error:
71412+ mutex_unlock(&gr_learn_user_mutex);
71413+ return retval;
71414+ }
71415+ return 0;
71416+}
71417+
71418+static int
71419+close_learn(struct inode *inode, struct file *file)
71420+{
71421+ if (file->f_mode & FMODE_READ) {
71422+ char *tmp = NULL;
71423+ mutex_lock(&gr_learn_user_mutex);
71424+ spin_lock(&gr_learn_lock);
71425+ tmp = learn_buffer;
71426+ learn_buffer = NULL;
71427+ spin_unlock(&gr_learn_lock);
71428+ if (tmp)
71429+ vfree(tmp);
71430+ if (learn_buffer_user != NULL) {
71431+ vfree(learn_buffer_user);
71432+ learn_buffer_user = NULL;
71433+ }
71434+ learn_buffer_len = 0;
71435+ learn_buffer_user_len = 0;
71436+ gr_learn_attached = 0;
71437+ mutex_unlock(&gr_learn_user_mutex);
71438+ }
71439+
71440+ return 0;
71441+}
71442+
71443+const struct file_operations grsec_fops = {
71444+ .read = read_learn,
71445+ .write = write_grsec_handler,
71446+ .open = open_learn,
71447+ .release = close_learn,
71448+ .poll = poll_learn,
71449+};
71450diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71451new file mode 100644
71452index 0000000..361a099
71453--- /dev/null
71454+++ b/grsecurity/gracl_policy.c
71455@@ -0,0 +1,1782 @@
71456+#include <linux/kernel.h>
71457+#include <linux/module.h>
71458+#include <linux/sched.h>
71459+#include <linux/mm.h>
71460+#include <linux/file.h>
71461+#include <linux/fs.h>
71462+#include <linux/namei.h>
71463+#include <linux/mount.h>
71464+#include <linux/tty.h>
71465+#include <linux/proc_fs.h>
71466+#include <linux/lglock.h>
71467+#include <linux/slab.h>
71468+#include <linux/vmalloc.h>
71469+#include <linux/types.h>
71470+#include <linux/sysctl.h>
71471+#include <linux/netdevice.h>
71472+#include <linux/ptrace.h>
71473+#include <linux/gracl.h>
71474+#include <linux/gralloc.h>
71475+#include <linux/security.h>
71476+#include <linux/grinternal.h>
71477+#include <linux/pid_namespace.h>
71478+#include <linux/stop_machine.h>
71479+#include <linux/fdtable.h>
71480+#include <linux/percpu.h>
71481+#include <linux/lglock.h>
71482+#include <linux/hugetlb.h>
71483+#include <linux/posix-timers.h>
71484+#include "../fs/mount.h"
71485+
71486+#include <asm/uaccess.h>
71487+#include <asm/errno.h>
71488+#include <asm/mman.h>
71489+
71490+extern struct gr_policy_state *polstate;
71491+
71492+#define FOR_EACH_ROLE_START(role) \
71493+ role = polstate->role_list; \
71494+ while (role) {
71495+
71496+#define FOR_EACH_ROLE_END(role) \
71497+ role = role->prev; \
71498+ }
71499+
71500+struct path gr_real_root;
71501+
71502+extern struct gr_alloc_state *current_alloc_state;
71503+
71504+u16 acl_sp_role_value;
71505+
71506+static DEFINE_MUTEX(gr_dev_mutex);
71507+
71508+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71509+extern void gr_clear_learn_entries(void);
71510+
71511+static struct gr_arg gr_usermode;
71512+static unsigned char gr_system_salt[GR_SALT_LEN];
71513+static unsigned char gr_system_sum[GR_SHA_LEN];
71514+
71515+static unsigned int gr_auth_attempts = 0;
71516+static unsigned long gr_auth_expires = 0UL;
71517+
71518+struct acl_object_label *fakefs_obj_rw;
71519+struct acl_object_label *fakefs_obj_rwx;
71520+
71521+extern int gr_init_uidset(void);
71522+extern void gr_free_uidset(void);
71523+extern void gr_remove_uid(uid_t uid);
71524+extern int gr_find_uid(uid_t uid);
71525+
71526+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71527+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71528+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71529+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71530+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);
71531+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71532+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71533+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71534+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71535+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71536+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71537+extern void assign_special_role(const char *rolename);
71538+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71539+extern int gr_rbac_disable(void *unused);
71540+extern void gr_enable_rbac_system(void);
71541+
71542+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71543+{
71544+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71545+ return -EFAULT;
71546+
71547+ return 0;
71548+}
71549+
71550+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71551+{
71552+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71553+ return -EFAULT;
71554+
71555+ return 0;
71556+}
71557+
71558+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71559+{
71560+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71561+ return -EFAULT;
71562+
71563+ return 0;
71564+}
71565+
71566+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71567+{
71568+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71569+ return -EFAULT;
71570+
71571+ return 0;
71572+}
71573+
71574+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71575+{
71576+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71577+ return -EFAULT;
71578+
71579+ return 0;
71580+}
71581+
71582+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71583+{
71584+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71585+ return -EFAULT;
71586+
71587+ return 0;
71588+}
71589+
71590+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71591+{
71592+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71593+ return -EFAULT;
71594+
71595+ return 0;
71596+}
71597+
71598+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71599+{
71600+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71601+ return -EFAULT;
71602+
71603+ return 0;
71604+}
71605+
71606+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71607+{
71608+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71609+ return -EFAULT;
71610+
71611+ return 0;
71612+}
71613+
71614+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71615+{
71616+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71617+ return -EFAULT;
71618+
71619+ if (((uwrap->version != GRSECURITY_VERSION) &&
71620+ (uwrap->version != 0x2901)) ||
71621+ (uwrap->size != sizeof(struct gr_arg)))
71622+ return -EINVAL;
71623+
71624+ return 0;
71625+}
71626+
71627+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71628+{
71629+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71630+ return -EFAULT;
71631+
71632+ return 0;
71633+}
71634+
71635+static size_t get_gr_arg_wrapper_size_normal(void)
71636+{
71637+ return sizeof(struct gr_arg_wrapper);
71638+}
71639+
71640+#ifdef CONFIG_COMPAT
71641+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71642+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71643+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71644+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71645+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71646+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71647+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71648+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71649+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71650+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71651+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71652+extern size_t get_gr_arg_wrapper_size_compat(void);
71653+
71654+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71655+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71656+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71657+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71658+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71659+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71660+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71661+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71662+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71663+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71664+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71665+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71666+
71667+#else
71668+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71669+#define copy_gr_arg copy_gr_arg_normal
71670+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71671+#define copy_acl_object_label copy_acl_object_label_normal
71672+#define copy_acl_subject_label copy_acl_subject_label_normal
71673+#define copy_acl_role_label copy_acl_role_label_normal
71674+#define copy_acl_ip_label copy_acl_ip_label_normal
71675+#define copy_pointer_from_array copy_pointer_from_array_normal
71676+#define copy_sprole_pw copy_sprole_pw_normal
71677+#define copy_role_transition copy_role_transition_normal
71678+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71679+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71680+#endif
71681+
71682+static struct acl_subject_label *
71683+lookup_subject_map(const struct acl_subject_label *userp)
71684+{
71685+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71686+ struct subject_map *match;
71687+
71688+ match = polstate->subj_map_set.s_hash[index];
71689+
71690+ while (match && match->user != userp)
71691+ match = match->next;
71692+
71693+ if (match != NULL)
71694+ return match->kernel;
71695+ else
71696+ return NULL;
71697+}
71698+
71699+static void
71700+insert_subj_map_entry(struct subject_map *subjmap)
71701+{
71702+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71703+ struct subject_map **curr;
71704+
71705+ subjmap->prev = NULL;
71706+
71707+ curr = &polstate->subj_map_set.s_hash[index];
71708+ if (*curr != NULL)
71709+ (*curr)->prev = subjmap;
71710+
71711+ subjmap->next = *curr;
71712+ *curr = subjmap;
71713+
71714+ return;
71715+}
71716+
71717+static void
71718+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71719+{
71720+ unsigned int index =
71721+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71722+ struct acl_role_label **curr;
71723+ struct acl_role_label *tmp, *tmp2;
71724+
71725+ curr = &polstate->acl_role_set.r_hash[index];
71726+
71727+ /* simple case, slot is empty, just set it to our role */
71728+ if (*curr == NULL) {
71729+ *curr = role;
71730+ } else {
71731+ /* example:
71732+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
71733+ 2 -> 3
71734+ */
71735+ /* first check to see if we can already be reached via this slot */
71736+ tmp = *curr;
71737+ while (tmp && tmp != role)
71738+ tmp = tmp->next;
71739+ if (tmp == role) {
71740+ /* we don't need to add ourselves to this slot's chain */
71741+ return;
71742+ }
71743+ /* we need to add ourselves to this chain, two cases */
71744+ if (role->next == NULL) {
71745+ /* simple case, append the current chain to our role */
71746+ role->next = *curr;
71747+ *curr = role;
71748+ } else {
71749+ /* 1 -> 2 -> 3 -> 4
71750+ 2 -> 3 -> 4
71751+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71752+ */
71753+ /* trickier case: walk our role's chain until we find
71754+ the role for the start of the current slot's chain */
71755+ tmp = role;
71756+ tmp2 = *curr;
71757+ while (tmp->next && tmp->next != tmp2)
71758+ tmp = tmp->next;
71759+ if (tmp->next == tmp2) {
71760+ /* from example above, we found 3, so just
71761+ replace this slot's chain with ours */
71762+ *curr = role;
71763+ } else {
71764+ /* we didn't find a subset of our role's chain
71765+ in the current slot's chain, so append their
71766+ chain to ours, and set us as the first role in
71767+ the slot's chain
71768+
71769+ we could fold this case with the case above,
71770+ but making it explicit for clarity
71771+ */
71772+ tmp->next = tmp2;
71773+ *curr = role;
71774+ }
71775+ }
71776+ }
71777+
71778+ return;
71779+}
71780+
71781+static void
71782+insert_acl_role_label(struct acl_role_label *role)
71783+{
71784+ int i;
71785+
71786+ if (polstate->role_list == NULL) {
71787+ polstate->role_list = role;
71788+ role->prev = NULL;
71789+ } else {
71790+ role->prev = polstate->role_list;
71791+ polstate->role_list = role;
71792+ }
71793+
71794+ /* used for hash chains */
71795+ role->next = NULL;
71796+
71797+ if (role->roletype & GR_ROLE_DOMAIN) {
71798+ for (i = 0; i < role->domain_child_num; i++)
71799+ __insert_acl_role_label(role, role->domain_children[i]);
71800+ } else
71801+ __insert_acl_role_label(role, role->uidgid);
71802+}
71803+
71804+static int
71805+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71806+{
71807+ struct name_entry **curr, *nentry;
71808+ struct inodev_entry *ientry;
71809+ unsigned int len = strlen(name);
71810+ unsigned int key = full_name_hash(name, len);
71811+ unsigned int index = key % polstate->name_set.n_size;
71812+
71813+ curr = &polstate->name_set.n_hash[index];
71814+
71815+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71816+ curr = &((*curr)->next);
71817+
71818+ if (*curr != NULL)
71819+ return 1;
71820+
71821+ nentry = acl_alloc(sizeof (struct name_entry));
71822+ if (nentry == NULL)
71823+ return 0;
71824+ ientry = acl_alloc(sizeof (struct inodev_entry));
71825+ if (ientry == NULL)
71826+ return 0;
71827+ ientry->nentry = nentry;
71828+
71829+ nentry->key = key;
71830+ nentry->name = name;
71831+ nentry->inode = inode;
71832+ nentry->device = device;
71833+ nentry->len = len;
71834+ nentry->deleted = deleted;
71835+
71836+ nentry->prev = NULL;
71837+ curr = &polstate->name_set.n_hash[index];
71838+ if (*curr != NULL)
71839+ (*curr)->prev = nentry;
71840+ nentry->next = *curr;
71841+ *curr = nentry;
71842+
71843+ /* insert us into the table searchable by inode/dev */
71844+ __insert_inodev_entry(polstate, ientry);
71845+
71846+ return 1;
71847+}
71848+
71849+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71850+
71851+static void *
71852+create_table(__u32 * len, int elementsize)
71853+{
71854+ unsigned int table_sizes[] = {
71855+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71856+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71857+ 4194301, 8388593, 16777213, 33554393, 67108859
71858+ };
71859+ void *newtable = NULL;
71860+ unsigned int pwr = 0;
71861+
71862+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71863+ table_sizes[pwr] <= *len)
71864+ pwr++;
71865+
71866+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71867+ return newtable;
71868+
71869+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71870+ newtable =
71871+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71872+ else
71873+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71874+
71875+ *len = table_sizes[pwr];
71876+
71877+ return newtable;
71878+}
71879+
71880+static int
71881+init_variables(const struct gr_arg *arg, bool reload)
71882+{
71883+ struct task_struct *reaper = init_pid_ns.child_reaper;
71884+ unsigned int stacksize;
71885+
71886+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71887+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71888+ polstate->name_set.n_size = arg->role_db.num_objects;
71889+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71890+
71891+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71892+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71893+ return 1;
71894+
71895+ if (!reload) {
71896+ if (!gr_init_uidset())
71897+ return 1;
71898+ }
71899+
71900+ /* set up the stack that holds allocation info */
71901+
71902+ stacksize = arg->role_db.num_pointers + 5;
71903+
71904+ if (!acl_alloc_stack_init(stacksize))
71905+ return 1;
71906+
71907+ if (!reload) {
71908+ /* grab reference for the real root dentry and vfsmount */
71909+ get_fs_root(reaper->fs, &gr_real_root);
71910+
71911+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71912+ 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);
71913+#endif
71914+
71915+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71916+ if (fakefs_obj_rw == NULL)
71917+ return 1;
71918+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71919+
71920+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71921+ if (fakefs_obj_rwx == NULL)
71922+ return 1;
71923+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71924+ }
71925+
71926+ polstate->subj_map_set.s_hash =
71927+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71928+ polstate->acl_role_set.r_hash =
71929+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71930+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71931+ polstate->inodev_set.i_hash =
71932+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71933+
71934+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71935+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71936+ return 1;
71937+
71938+ memset(polstate->subj_map_set.s_hash, 0,
71939+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71940+ memset(polstate->acl_role_set.r_hash, 0,
71941+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71942+ memset(polstate->name_set.n_hash, 0,
71943+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71944+ memset(polstate->inodev_set.i_hash, 0,
71945+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71946+
71947+ return 0;
71948+}
71949+
71950+/* free information not needed after startup
71951+ currently contains user->kernel pointer mappings for subjects
71952+*/
71953+
71954+static void
71955+free_init_variables(void)
71956+{
71957+ __u32 i;
71958+
71959+ if (polstate->subj_map_set.s_hash) {
71960+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71961+ if (polstate->subj_map_set.s_hash[i]) {
71962+ kfree(polstate->subj_map_set.s_hash[i]);
71963+ polstate->subj_map_set.s_hash[i] = NULL;
71964+ }
71965+ }
71966+
71967+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71968+ PAGE_SIZE)
71969+ kfree(polstate->subj_map_set.s_hash);
71970+ else
71971+ vfree(polstate->subj_map_set.s_hash);
71972+ }
71973+
71974+ return;
71975+}
71976+
71977+static void
71978+free_variables(bool reload)
71979+{
71980+ struct acl_subject_label *s;
71981+ struct acl_role_label *r;
71982+ struct task_struct *task, *task2;
71983+ unsigned int x;
71984+
71985+ if (!reload) {
71986+ gr_clear_learn_entries();
71987+
71988+ read_lock(&tasklist_lock);
71989+ do_each_thread(task2, task) {
71990+ task->acl_sp_role = 0;
71991+ task->acl_role_id = 0;
71992+ task->inherited = 0;
71993+ task->acl = NULL;
71994+ task->role = NULL;
71995+ } while_each_thread(task2, task);
71996+ read_unlock(&tasklist_lock);
71997+
71998+ kfree(fakefs_obj_rw);
71999+ fakefs_obj_rw = NULL;
72000+ kfree(fakefs_obj_rwx);
72001+ fakefs_obj_rwx = NULL;
72002+
72003+ /* release the reference to the real root dentry and vfsmount */
72004+ path_put(&gr_real_root);
72005+ memset(&gr_real_root, 0, sizeof(gr_real_root));
72006+ }
72007+
72008+ /* free all object hash tables */
72009+
72010+ FOR_EACH_ROLE_START(r)
72011+ if (r->subj_hash == NULL)
72012+ goto next_role;
72013+ FOR_EACH_SUBJECT_START(r, s, x)
72014+ if (s->obj_hash == NULL)
72015+ break;
72016+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
72017+ kfree(s->obj_hash);
72018+ else
72019+ vfree(s->obj_hash);
72020+ FOR_EACH_SUBJECT_END(s, x)
72021+ FOR_EACH_NESTED_SUBJECT_START(r, s)
72022+ if (s->obj_hash == NULL)
72023+ break;
72024+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
72025+ kfree(s->obj_hash);
72026+ else
72027+ vfree(s->obj_hash);
72028+ FOR_EACH_NESTED_SUBJECT_END(s)
72029+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
72030+ kfree(r->subj_hash);
72031+ else
72032+ vfree(r->subj_hash);
72033+ r->subj_hash = NULL;
72034+next_role:
72035+ FOR_EACH_ROLE_END(r)
72036+
72037+ acl_free_all();
72038+
72039+ if (polstate->acl_role_set.r_hash) {
72040+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
72041+ PAGE_SIZE)
72042+ kfree(polstate->acl_role_set.r_hash);
72043+ else
72044+ vfree(polstate->acl_role_set.r_hash);
72045+ }
72046+ if (polstate->name_set.n_hash) {
72047+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
72048+ PAGE_SIZE)
72049+ kfree(polstate->name_set.n_hash);
72050+ else
72051+ vfree(polstate->name_set.n_hash);
72052+ }
72053+
72054+ if (polstate->inodev_set.i_hash) {
72055+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
72056+ PAGE_SIZE)
72057+ kfree(polstate->inodev_set.i_hash);
72058+ else
72059+ vfree(polstate->inodev_set.i_hash);
72060+ }
72061+
72062+ if (!reload)
72063+ gr_free_uidset();
72064+
72065+ memset(&polstate->name_set, 0, sizeof (struct name_db));
72066+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
72067+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
72068+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
72069+
72070+ polstate->default_role = NULL;
72071+ polstate->kernel_role = NULL;
72072+ polstate->role_list = NULL;
72073+
72074+ return;
72075+}
72076+
72077+static struct acl_subject_label *
72078+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
72079+
72080+static int alloc_and_copy_string(char **name, unsigned int maxlen)
72081+{
72082+ unsigned int len = strnlen_user(*name, maxlen);
72083+ char *tmp;
72084+
72085+ if (!len || len >= maxlen)
72086+ return -EINVAL;
72087+
72088+ if ((tmp = (char *) acl_alloc(len)) == NULL)
72089+ return -ENOMEM;
72090+
72091+ if (copy_from_user(tmp, *name, len))
72092+ return -EFAULT;
72093+
72094+ tmp[len-1] = '\0';
72095+ *name = tmp;
72096+
72097+ return 0;
72098+}
72099+
72100+static int
72101+copy_user_glob(struct acl_object_label *obj)
72102+{
72103+ struct acl_object_label *g_tmp, **guser;
72104+ int error;
72105+
72106+ if (obj->globbed == NULL)
72107+ return 0;
72108+
72109+ guser = &obj->globbed;
72110+ while (*guser) {
72111+ g_tmp = (struct acl_object_label *)
72112+ acl_alloc(sizeof (struct acl_object_label));
72113+ if (g_tmp == NULL)
72114+ return -ENOMEM;
72115+
72116+ if (copy_acl_object_label(g_tmp, *guser))
72117+ return -EFAULT;
72118+
72119+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
72120+ if (error)
72121+ return error;
72122+
72123+ *guser = g_tmp;
72124+ guser = &(g_tmp->next);
72125+ }
72126+
72127+ return 0;
72128+}
72129+
72130+static int
72131+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
72132+ struct acl_role_label *role)
72133+{
72134+ struct acl_object_label *o_tmp;
72135+ int ret;
72136+
72137+ while (userp) {
72138+ if ((o_tmp = (struct acl_object_label *)
72139+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
72140+ return -ENOMEM;
72141+
72142+ if (copy_acl_object_label(o_tmp, userp))
72143+ return -EFAULT;
72144+
72145+ userp = o_tmp->prev;
72146+
72147+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
72148+ if (ret)
72149+ return ret;
72150+
72151+ insert_acl_obj_label(o_tmp, subj);
72152+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
72153+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
72154+ return -ENOMEM;
72155+
72156+ ret = copy_user_glob(o_tmp);
72157+ if (ret)
72158+ return ret;
72159+
72160+ if (o_tmp->nested) {
72161+ int already_copied;
72162+
72163+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
72164+ if (IS_ERR(o_tmp->nested))
72165+ return PTR_ERR(o_tmp->nested);
72166+
72167+ /* insert into nested subject list if we haven't copied this one yet
72168+ to prevent duplicate entries */
72169+ if (!already_copied) {
72170+ o_tmp->nested->next = role->hash->first;
72171+ role->hash->first = o_tmp->nested;
72172+ }
72173+ }
72174+ }
72175+
72176+ return 0;
72177+}
72178+
72179+static __u32
72180+count_user_subjs(struct acl_subject_label *userp)
72181+{
72182+ struct acl_subject_label s_tmp;
72183+ __u32 num = 0;
72184+
72185+ while (userp) {
72186+ if (copy_acl_subject_label(&s_tmp, userp))
72187+ break;
72188+
72189+ userp = s_tmp.prev;
72190+ }
72191+
72192+ return num;
72193+}
72194+
72195+static int
72196+copy_user_allowedips(struct acl_role_label *rolep)
72197+{
72198+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
72199+
72200+ ruserip = rolep->allowed_ips;
72201+
72202+ while (ruserip) {
72203+ rlast = rtmp;
72204+
72205+ if ((rtmp = (struct role_allowed_ip *)
72206+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
72207+ return -ENOMEM;
72208+
72209+ if (copy_role_allowed_ip(rtmp, ruserip))
72210+ return -EFAULT;
72211+
72212+ ruserip = rtmp->prev;
72213+
72214+ if (!rlast) {
72215+ rtmp->prev = NULL;
72216+ rolep->allowed_ips = rtmp;
72217+ } else {
72218+ rlast->next = rtmp;
72219+ rtmp->prev = rlast;
72220+ }
72221+
72222+ if (!ruserip)
72223+ rtmp->next = NULL;
72224+ }
72225+
72226+ return 0;
72227+}
72228+
72229+static int
72230+copy_user_transitions(struct acl_role_label *rolep)
72231+{
72232+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
72233+ int error;
72234+
72235+ rusertp = rolep->transitions;
72236+
72237+ while (rusertp) {
72238+ rlast = rtmp;
72239+
72240+ if ((rtmp = (struct role_transition *)
72241+ acl_alloc(sizeof (struct role_transition))) == NULL)
72242+ return -ENOMEM;
72243+
72244+ if (copy_role_transition(rtmp, rusertp))
72245+ return -EFAULT;
72246+
72247+ rusertp = rtmp->prev;
72248+
72249+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
72250+ if (error)
72251+ return error;
72252+
72253+ if (!rlast) {
72254+ rtmp->prev = NULL;
72255+ rolep->transitions = rtmp;
72256+ } else {
72257+ rlast->next = rtmp;
72258+ rtmp->prev = rlast;
72259+ }
72260+
72261+ if (!rusertp)
72262+ rtmp->next = NULL;
72263+ }
72264+
72265+ return 0;
72266+}
72267+
72268+static __u32 count_user_objs(const struct acl_object_label __user *userp)
72269+{
72270+ struct acl_object_label o_tmp;
72271+ __u32 num = 0;
72272+
72273+ while (userp) {
72274+ if (copy_acl_object_label(&o_tmp, userp))
72275+ break;
72276+
72277+ userp = o_tmp.prev;
72278+ num++;
72279+ }
72280+
72281+ return num;
72282+}
72283+
72284+static struct acl_subject_label *
72285+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
72286+{
72287+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
72288+ __u32 num_objs;
72289+ struct acl_ip_label **i_tmp, *i_utmp2;
72290+ struct gr_hash_struct ghash;
72291+ struct subject_map *subjmap;
72292+ unsigned int i_num;
72293+ int err;
72294+
72295+ if (already_copied != NULL)
72296+ *already_copied = 0;
72297+
72298+ s_tmp = lookup_subject_map(userp);
72299+
72300+ /* we've already copied this subject into the kernel, just return
72301+ the reference to it, and don't copy it over again
72302+ */
72303+ if (s_tmp) {
72304+ if (already_copied != NULL)
72305+ *already_copied = 1;
72306+ return(s_tmp);
72307+ }
72308+
72309+ if ((s_tmp = (struct acl_subject_label *)
72310+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
72311+ return ERR_PTR(-ENOMEM);
72312+
72313+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
72314+ if (subjmap == NULL)
72315+ return ERR_PTR(-ENOMEM);
72316+
72317+ subjmap->user = userp;
72318+ subjmap->kernel = s_tmp;
72319+ insert_subj_map_entry(subjmap);
72320+
72321+ if (copy_acl_subject_label(s_tmp, userp))
72322+ return ERR_PTR(-EFAULT);
72323+
72324+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
72325+ if (err)
72326+ return ERR_PTR(err);
72327+
72328+ if (!strcmp(s_tmp->filename, "/"))
72329+ role->root_label = s_tmp;
72330+
72331+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
72332+ return ERR_PTR(-EFAULT);
72333+
72334+ /* copy user and group transition tables */
72335+
72336+ if (s_tmp->user_trans_num) {
72337+ uid_t *uidlist;
72338+
72339+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
72340+ if (uidlist == NULL)
72341+ return ERR_PTR(-ENOMEM);
72342+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
72343+ return ERR_PTR(-EFAULT);
72344+
72345+ s_tmp->user_transitions = uidlist;
72346+ }
72347+
72348+ if (s_tmp->group_trans_num) {
72349+ gid_t *gidlist;
72350+
72351+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
72352+ if (gidlist == NULL)
72353+ return ERR_PTR(-ENOMEM);
72354+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
72355+ return ERR_PTR(-EFAULT);
72356+
72357+ s_tmp->group_transitions = gidlist;
72358+ }
72359+
72360+ /* set up object hash table */
72361+ num_objs = count_user_objs(ghash.first);
72362+
72363+ s_tmp->obj_hash_size = num_objs;
72364+ s_tmp->obj_hash =
72365+ (struct acl_object_label **)
72366+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72367+
72368+ if (!s_tmp->obj_hash)
72369+ return ERR_PTR(-ENOMEM);
72370+
72371+ memset(s_tmp->obj_hash, 0,
72372+ s_tmp->obj_hash_size *
72373+ sizeof (struct acl_object_label *));
72374+
72375+ /* add in objects */
72376+ err = copy_user_objs(ghash.first, s_tmp, role);
72377+
72378+ if (err)
72379+ return ERR_PTR(err);
72380+
72381+ /* set pointer for parent subject */
72382+ if (s_tmp->parent_subject) {
72383+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72384+
72385+ if (IS_ERR(s_tmp2))
72386+ return s_tmp2;
72387+
72388+ s_tmp->parent_subject = s_tmp2;
72389+ }
72390+
72391+ /* add in ip acls */
72392+
72393+ if (!s_tmp->ip_num) {
72394+ s_tmp->ips = NULL;
72395+ goto insert;
72396+ }
72397+
72398+ i_tmp =
72399+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72400+ sizeof (struct acl_ip_label *));
72401+
72402+ if (!i_tmp)
72403+ return ERR_PTR(-ENOMEM);
72404+
72405+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72406+ *(i_tmp + i_num) =
72407+ (struct acl_ip_label *)
72408+ acl_alloc(sizeof (struct acl_ip_label));
72409+ if (!*(i_tmp + i_num))
72410+ return ERR_PTR(-ENOMEM);
72411+
72412+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72413+ return ERR_PTR(-EFAULT);
72414+
72415+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72416+ return ERR_PTR(-EFAULT);
72417+
72418+ if ((*(i_tmp + i_num))->iface == NULL)
72419+ continue;
72420+
72421+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72422+ if (err)
72423+ return ERR_PTR(err);
72424+ }
72425+
72426+ s_tmp->ips = i_tmp;
72427+
72428+insert:
72429+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72430+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72431+ return ERR_PTR(-ENOMEM);
72432+
72433+ return s_tmp;
72434+}
72435+
72436+static int
72437+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72438+{
72439+ struct acl_subject_label s_pre;
72440+ struct acl_subject_label * ret;
72441+ int err;
72442+
72443+ while (userp) {
72444+ if (copy_acl_subject_label(&s_pre, userp))
72445+ return -EFAULT;
72446+
72447+ ret = do_copy_user_subj(userp, role, NULL);
72448+
72449+ err = PTR_ERR(ret);
72450+ if (IS_ERR(ret))
72451+ return err;
72452+
72453+ insert_acl_subj_label(ret, role);
72454+
72455+ userp = s_pre.prev;
72456+ }
72457+
72458+ return 0;
72459+}
72460+
72461+static int
72462+copy_user_acl(struct gr_arg *arg)
72463+{
72464+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72465+ struct acl_subject_label *subj_list;
72466+ struct sprole_pw *sptmp;
72467+ struct gr_hash_struct *ghash;
72468+ uid_t *domainlist;
72469+ unsigned int r_num;
72470+ int err = 0;
72471+ __u16 i;
72472+ __u32 num_subjs;
72473+
72474+ /* we need a default and kernel role */
72475+ if (arg->role_db.num_roles < 2)
72476+ return -EINVAL;
72477+
72478+ /* copy special role authentication info from userspace */
72479+
72480+ polstate->num_sprole_pws = arg->num_sprole_pws;
72481+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72482+
72483+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72484+ return -ENOMEM;
72485+
72486+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72487+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72488+ if (!sptmp)
72489+ return -ENOMEM;
72490+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72491+ return -EFAULT;
72492+
72493+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72494+ if (err)
72495+ return err;
72496+
72497+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72498+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72499+#endif
72500+
72501+ polstate->acl_special_roles[i] = sptmp;
72502+ }
72503+
72504+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72505+
72506+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72507+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
72508+
72509+ if (!r_tmp)
72510+ return -ENOMEM;
72511+
72512+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72513+ return -EFAULT;
72514+
72515+ if (copy_acl_role_label(r_tmp, r_utmp2))
72516+ return -EFAULT;
72517+
72518+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72519+ if (err)
72520+ return err;
72521+
72522+ if (!strcmp(r_tmp->rolename, "default")
72523+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72524+ polstate->default_role = r_tmp;
72525+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72526+ polstate->kernel_role = r_tmp;
72527+ }
72528+
72529+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72530+ return -ENOMEM;
72531+
72532+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
72533+ return -EFAULT;
72534+
72535+ r_tmp->hash = ghash;
72536+
72537+ num_subjs = count_user_subjs(r_tmp->hash->first);
72538+
72539+ r_tmp->subj_hash_size = num_subjs;
72540+ r_tmp->subj_hash =
72541+ (struct acl_subject_label **)
72542+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72543+
72544+ if (!r_tmp->subj_hash)
72545+ return -ENOMEM;
72546+
72547+ err = copy_user_allowedips(r_tmp);
72548+ if (err)
72549+ return err;
72550+
72551+ /* copy domain info */
72552+ if (r_tmp->domain_children != NULL) {
72553+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72554+ if (domainlist == NULL)
72555+ return -ENOMEM;
72556+
72557+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72558+ return -EFAULT;
72559+
72560+ r_tmp->domain_children = domainlist;
72561+ }
72562+
72563+ err = copy_user_transitions(r_tmp);
72564+ if (err)
72565+ return err;
72566+
72567+ memset(r_tmp->subj_hash, 0,
72568+ r_tmp->subj_hash_size *
72569+ sizeof (struct acl_subject_label *));
72570+
72571+ /* acquire the list of subjects, then NULL out
72572+ the list prior to parsing the subjects for this role,
72573+ as during this parsing the list is replaced with a list
72574+ of *nested* subjects for the role
72575+ */
72576+ subj_list = r_tmp->hash->first;
72577+
72578+ /* set nested subject list to null */
72579+ r_tmp->hash->first = NULL;
72580+
72581+ err = copy_user_subjs(subj_list, r_tmp);
72582+
72583+ if (err)
72584+ return err;
72585+
72586+ insert_acl_role_label(r_tmp);
72587+ }
72588+
72589+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72590+ return -EINVAL;
72591+
72592+ return err;
72593+}
72594+
72595+static int gracl_reload_apply_policies(void *reload)
72596+{
72597+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72598+ struct task_struct *task, *task2;
72599+ struct acl_role_label *role, *rtmp;
72600+ struct acl_subject_label *subj;
72601+ const struct cred *cred;
72602+ int role_applied;
72603+ int ret = 0;
72604+
72605+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72606+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72607+
72608+ /* first make sure we'll be able to apply the new policy cleanly */
72609+ do_each_thread(task2, task) {
72610+ if (task->exec_file == NULL)
72611+ continue;
72612+ role_applied = 0;
72613+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72614+ /* preserve special roles */
72615+ FOR_EACH_ROLE_START(role)
72616+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72617+ rtmp = task->role;
72618+ task->role = role;
72619+ role_applied = 1;
72620+ break;
72621+ }
72622+ FOR_EACH_ROLE_END(role)
72623+ }
72624+ if (!role_applied) {
72625+ cred = __task_cred(task);
72626+ rtmp = task->role;
72627+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72628+ }
72629+ /* this handles non-nested inherited subjects, nested subjects will still
72630+ be dropped currently */
72631+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72632+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72633+ /* change the role back so that we've made no modifications to the policy */
72634+ task->role = rtmp;
72635+
72636+ if (subj == NULL || task->tmpacl == NULL) {
72637+ ret = -EINVAL;
72638+ goto out;
72639+ }
72640+ } while_each_thread(task2, task);
72641+
72642+ /* now actually apply the policy */
72643+
72644+ do_each_thread(task2, task) {
72645+ if (task->exec_file) {
72646+ role_applied = 0;
72647+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72648+ /* preserve special roles */
72649+ FOR_EACH_ROLE_START(role)
72650+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72651+ task->role = role;
72652+ role_applied = 1;
72653+ break;
72654+ }
72655+ FOR_EACH_ROLE_END(role)
72656+ }
72657+ if (!role_applied) {
72658+ cred = __task_cred(task);
72659+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72660+ }
72661+ /* this handles non-nested inherited subjects, nested subjects will still
72662+ be dropped currently */
72663+ if (!reload_state->oldmode && task->inherited)
72664+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72665+ else {
72666+ /* looked up and tagged to the task previously */
72667+ subj = task->tmpacl;
72668+ }
72669+ /* subj will be non-null */
72670+ __gr_apply_subject_to_task(polstate, task, subj);
72671+ if (reload_state->oldmode) {
72672+ task->acl_role_id = 0;
72673+ task->acl_sp_role = 0;
72674+ task->inherited = 0;
72675+ }
72676+ } else {
72677+ // it's a kernel process
72678+ task->role = polstate->kernel_role;
72679+ task->acl = polstate->kernel_role->root_label;
72680+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72681+ task->acl->mode &= ~GR_PROCFIND;
72682+#endif
72683+ }
72684+ } while_each_thread(task2, task);
72685+
72686+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72687+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72688+
72689+out:
72690+
72691+ return ret;
72692+}
72693+
72694+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72695+{
72696+ struct gr_reload_state new_reload_state = { };
72697+ int err;
72698+
72699+ new_reload_state.oldpolicy_ptr = polstate;
72700+ new_reload_state.oldalloc_ptr = current_alloc_state;
72701+ new_reload_state.oldmode = oldmode;
72702+
72703+ current_alloc_state = &new_reload_state.newalloc;
72704+ polstate = &new_reload_state.newpolicy;
72705+
72706+ /* everything relevant is now saved off, copy in the new policy */
72707+ if (init_variables(args, true)) {
72708+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72709+ err = -ENOMEM;
72710+ goto error;
72711+ }
72712+
72713+ err = copy_user_acl(args);
72714+ free_init_variables();
72715+ if (err)
72716+ goto error;
72717+ /* the new policy is copied in, with the old policy available via saved_state
72718+ first go through applying roles, making sure to preserve special roles
72719+ then apply new subjects, making sure to preserve inherited and nested subjects,
72720+ though currently only inherited subjects will be preserved
72721+ */
72722+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72723+ if (err)
72724+ goto error;
72725+
72726+ /* we've now applied the new policy, so restore the old policy state to free it */
72727+ polstate = &new_reload_state.oldpolicy;
72728+ current_alloc_state = &new_reload_state.oldalloc;
72729+ free_variables(true);
72730+
72731+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72732+ to running_polstate/current_alloc_state inside stop_machine
72733+ */
72734+ err = 0;
72735+ goto out;
72736+error:
72737+ /* on error of loading the new policy, we'll just keep the previous
72738+ policy set around
72739+ */
72740+ free_variables(true);
72741+
72742+ /* doesn't affect runtime, but maintains consistent state */
72743+out:
72744+ polstate = new_reload_state.oldpolicy_ptr;
72745+ current_alloc_state = new_reload_state.oldalloc_ptr;
72746+
72747+ return err;
72748+}
72749+
72750+static int
72751+gracl_init(struct gr_arg *args)
72752+{
72753+ int error = 0;
72754+
72755+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72756+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72757+
72758+ if (init_variables(args, false)) {
72759+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72760+ error = -ENOMEM;
72761+ goto out;
72762+ }
72763+
72764+ error = copy_user_acl(args);
72765+ free_init_variables();
72766+ if (error)
72767+ goto out;
72768+
72769+ error = gr_set_acls(0);
72770+ if (error)
72771+ goto out;
72772+
72773+ gr_enable_rbac_system();
72774+
72775+ return 0;
72776+
72777+out:
72778+ free_variables(false);
72779+ return error;
72780+}
72781+
72782+static int
72783+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72784+ unsigned char **sum)
72785+{
72786+ struct acl_role_label *r;
72787+ struct role_allowed_ip *ipp;
72788+ struct role_transition *trans;
72789+ unsigned int i;
72790+ int found = 0;
72791+ u32 curr_ip = current->signal->curr_ip;
72792+
72793+ current->signal->saved_ip = curr_ip;
72794+
72795+ /* check transition table */
72796+
72797+ for (trans = current->role->transitions; trans; trans = trans->next) {
72798+ if (!strcmp(rolename, trans->rolename)) {
72799+ found = 1;
72800+ break;
72801+ }
72802+ }
72803+
72804+ if (!found)
72805+ return 0;
72806+
72807+ /* handle special roles that do not require authentication
72808+ and check ip */
72809+
72810+ FOR_EACH_ROLE_START(r)
72811+ if (!strcmp(rolename, r->rolename) &&
72812+ (r->roletype & GR_ROLE_SPECIAL)) {
72813+ found = 0;
72814+ if (r->allowed_ips != NULL) {
72815+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72816+ if ((ntohl(curr_ip) & ipp->netmask) ==
72817+ (ntohl(ipp->addr) & ipp->netmask))
72818+ found = 1;
72819+ }
72820+ } else
72821+ found = 2;
72822+ if (!found)
72823+ return 0;
72824+
72825+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72826+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72827+ *salt = NULL;
72828+ *sum = NULL;
72829+ return 1;
72830+ }
72831+ }
72832+ FOR_EACH_ROLE_END(r)
72833+
72834+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72835+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72836+ *salt = polstate->acl_special_roles[i]->salt;
72837+ *sum = polstate->acl_special_roles[i]->sum;
72838+ return 1;
72839+ }
72840+ }
72841+
72842+ return 0;
72843+}
72844+
72845+int gr_check_secure_terminal(struct task_struct *task)
72846+{
72847+ struct task_struct *p, *p2, *p3;
72848+ struct files_struct *files;
72849+ struct fdtable *fdt;
72850+ struct file *our_file = NULL, *file;
72851+ int i;
72852+
72853+ if (task->signal->tty == NULL)
72854+ return 1;
72855+
72856+ files = get_files_struct(task);
72857+ if (files != NULL) {
72858+ rcu_read_lock();
72859+ fdt = files_fdtable(files);
72860+ for (i=0; i < fdt->max_fds; i++) {
72861+ file = fcheck_files(files, i);
72862+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72863+ get_file(file);
72864+ our_file = file;
72865+ }
72866+ }
72867+ rcu_read_unlock();
72868+ put_files_struct(files);
72869+ }
72870+
72871+ if (our_file == NULL)
72872+ return 1;
72873+
72874+ read_lock(&tasklist_lock);
72875+ do_each_thread(p2, p) {
72876+ files = get_files_struct(p);
72877+ if (files == NULL ||
72878+ (p->signal && p->signal->tty == task->signal->tty)) {
72879+ if (files != NULL)
72880+ put_files_struct(files);
72881+ continue;
72882+ }
72883+ rcu_read_lock();
72884+ fdt = files_fdtable(files);
72885+ for (i=0; i < fdt->max_fds; i++) {
72886+ file = fcheck_files(files, i);
72887+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72888+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72889+ p3 = task;
72890+ while (task_pid_nr(p3) > 0) {
72891+ if (p3 == p)
72892+ break;
72893+ p3 = p3->real_parent;
72894+ }
72895+ if (p3 == p)
72896+ break;
72897+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72898+ gr_handle_alertkill(p);
72899+ rcu_read_unlock();
72900+ put_files_struct(files);
72901+ read_unlock(&tasklist_lock);
72902+ fput(our_file);
72903+ return 0;
72904+ }
72905+ }
72906+ rcu_read_unlock();
72907+ put_files_struct(files);
72908+ } while_each_thread(p2, p);
72909+ read_unlock(&tasklist_lock);
72910+
72911+ fput(our_file);
72912+ return 1;
72913+}
72914+
72915+ssize_t
72916+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72917+{
72918+ struct gr_arg_wrapper uwrap;
72919+ unsigned char *sprole_salt = NULL;
72920+ unsigned char *sprole_sum = NULL;
72921+ int error = 0;
72922+ int error2 = 0;
72923+ size_t req_count = 0;
72924+ unsigned char oldmode = 0;
72925+
72926+ mutex_lock(&gr_dev_mutex);
72927+
72928+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72929+ error = -EPERM;
72930+ goto out;
72931+ }
72932+
72933+#ifdef CONFIG_COMPAT
72934+ pax_open_kernel();
72935+ if (is_compat_task()) {
72936+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72937+ copy_gr_arg = &copy_gr_arg_compat;
72938+ copy_acl_object_label = &copy_acl_object_label_compat;
72939+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72940+ copy_acl_role_label = &copy_acl_role_label_compat;
72941+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72942+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72943+ copy_role_transition = &copy_role_transition_compat;
72944+ copy_sprole_pw = &copy_sprole_pw_compat;
72945+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72946+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72947+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72948+ } else {
72949+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72950+ copy_gr_arg = &copy_gr_arg_normal;
72951+ copy_acl_object_label = &copy_acl_object_label_normal;
72952+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72953+ copy_acl_role_label = &copy_acl_role_label_normal;
72954+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72955+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72956+ copy_role_transition = &copy_role_transition_normal;
72957+ copy_sprole_pw = &copy_sprole_pw_normal;
72958+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72959+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72960+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72961+ }
72962+ pax_close_kernel();
72963+#endif
72964+
72965+ req_count = get_gr_arg_wrapper_size();
72966+
72967+ if (count != req_count) {
72968+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72969+ error = -EINVAL;
72970+ goto out;
72971+ }
72972+
72973+
72974+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72975+ gr_auth_expires = 0;
72976+ gr_auth_attempts = 0;
72977+ }
72978+
72979+ error = copy_gr_arg_wrapper(buf, &uwrap);
72980+ if (error)
72981+ goto out;
72982+
72983+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72984+ if (error)
72985+ goto out;
72986+
72987+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72988+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72989+ time_after(gr_auth_expires, get_seconds())) {
72990+ error = -EBUSY;
72991+ goto out;
72992+ }
72993+
72994+ /* if non-root trying to do anything other than use a special role,
72995+ do not attempt authentication, do not count towards authentication
72996+ locking
72997+ */
72998+
72999+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
73000+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
73001+ gr_is_global_nonroot(current_uid())) {
73002+ error = -EPERM;
73003+ goto out;
73004+ }
73005+
73006+ /* ensure pw and special role name are null terminated */
73007+
73008+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
73009+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
73010+
73011+ /* Okay.
73012+ * We have our enough of the argument structure..(we have yet
73013+ * to copy_from_user the tables themselves) . Copy the tables
73014+ * only if we need them, i.e. for loading operations. */
73015+
73016+ switch (gr_usermode.mode) {
73017+ case GR_STATUS:
73018+ if (gr_acl_is_enabled()) {
73019+ error = 1;
73020+ if (!gr_check_secure_terminal(current))
73021+ error = 3;
73022+ } else
73023+ error = 2;
73024+ goto out;
73025+ case GR_SHUTDOWN:
73026+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
73027+ stop_machine(gr_rbac_disable, NULL, NULL);
73028+ free_variables(false);
73029+ memset(&gr_usermode, 0, sizeof(gr_usermode));
73030+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
73031+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
73032+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
73033+ } else if (gr_acl_is_enabled()) {
73034+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
73035+ error = -EPERM;
73036+ } else {
73037+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
73038+ error = -EAGAIN;
73039+ }
73040+ break;
73041+ case GR_ENABLE:
73042+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
73043+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
73044+ else {
73045+ if (gr_acl_is_enabled())
73046+ error = -EAGAIN;
73047+ else
73048+ error = error2;
73049+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
73050+ }
73051+ break;
73052+ case GR_OLDRELOAD:
73053+ oldmode = 1;
73054+ case GR_RELOAD:
73055+ if (!gr_acl_is_enabled()) {
73056+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
73057+ error = -EAGAIN;
73058+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
73059+ error2 = gracl_reload(&gr_usermode, oldmode);
73060+ if (!error2)
73061+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
73062+ else {
73063+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73064+ error = error2;
73065+ }
73066+ } else {
73067+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73068+ error = -EPERM;
73069+ }
73070+ break;
73071+ case GR_SEGVMOD:
73072+ if (unlikely(!gr_acl_is_enabled())) {
73073+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
73074+ error = -EAGAIN;
73075+ break;
73076+ }
73077+
73078+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
73079+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
73080+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
73081+ struct acl_subject_label *segvacl;
73082+ segvacl =
73083+ lookup_acl_subj_label(gr_usermode.segv_inode,
73084+ gr_usermode.segv_device,
73085+ current->role);
73086+ if (segvacl) {
73087+ segvacl->crashes = 0;
73088+ segvacl->expires = 0;
73089+ }
73090+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
73091+ gr_remove_uid(gr_usermode.segv_uid);
73092+ }
73093+ } else {
73094+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
73095+ error = -EPERM;
73096+ }
73097+ break;
73098+ case GR_SPROLE:
73099+ case GR_SPROLEPAM:
73100+ if (unlikely(!gr_acl_is_enabled())) {
73101+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
73102+ error = -EAGAIN;
73103+ break;
73104+ }
73105+
73106+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
73107+ current->role->expires = 0;
73108+ current->role->auth_attempts = 0;
73109+ }
73110+
73111+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73112+ time_after(current->role->expires, get_seconds())) {
73113+ error = -EBUSY;
73114+ goto out;
73115+ }
73116+
73117+ if (lookup_special_role_auth
73118+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
73119+ && ((!sprole_salt && !sprole_sum)
73120+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
73121+ char *p = "";
73122+ assign_special_role(gr_usermode.sp_role);
73123+ read_lock(&tasklist_lock);
73124+ if (current->real_parent)
73125+ p = current->real_parent->role->rolename;
73126+ read_unlock(&tasklist_lock);
73127+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
73128+ p, acl_sp_role_value);
73129+ } else {
73130+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
73131+ error = -EPERM;
73132+ if(!(current->role->auth_attempts++))
73133+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73134+
73135+ goto out;
73136+ }
73137+ break;
73138+ case GR_UNSPROLE:
73139+ if (unlikely(!gr_acl_is_enabled())) {
73140+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
73141+ error = -EAGAIN;
73142+ break;
73143+ }
73144+
73145+ if (current->role->roletype & GR_ROLE_SPECIAL) {
73146+ char *p = "";
73147+ int i = 0;
73148+
73149+ read_lock(&tasklist_lock);
73150+ if (current->real_parent) {
73151+ p = current->real_parent->role->rolename;
73152+ i = current->real_parent->acl_role_id;
73153+ }
73154+ read_unlock(&tasklist_lock);
73155+
73156+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
73157+ gr_set_acls(1);
73158+ } else {
73159+ error = -EPERM;
73160+ goto out;
73161+ }
73162+ break;
73163+ default:
73164+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
73165+ error = -EINVAL;
73166+ break;
73167+ }
73168+
73169+ if (error != -EPERM)
73170+ goto out;
73171+
73172+ if(!(gr_auth_attempts++))
73173+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73174+
73175+ out:
73176+ mutex_unlock(&gr_dev_mutex);
73177+
73178+ if (!error)
73179+ error = req_count;
73180+
73181+ return error;
73182+}
73183+
73184+int
73185+gr_set_acls(const int type)
73186+{
73187+ struct task_struct *task, *task2;
73188+ struct acl_role_label *role = current->role;
73189+ struct acl_subject_label *subj;
73190+ __u16 acl_role_id = current->acl_role_id;
73191+ const struct cred *cred;
73192+ int ret;
73193+
73194+ rcu_read_lock();
73195+ read_lock(&tasklist_lock);
73196+ read_lock(&grsec_exec_file_lock);
73197+ do_each_thread(task2, task) {
73198+ /* check to see if we're called from the exit handler,
73199+ if so, only replace ACLs that have inherited the admin
73200+ ACL */
73201+
73202+ if (type && (task->role != role ||
73203+ task->acl_role_id != acl_role_id))
73204+ continue;
73205+
73206+ task->acl_role_id = 0;
73207+ task->acl_sp_role = 0;
73208+ task->inherited = 0;
73209+
73210+ if (task->exec_file) {
73211+ cred = __task_cred(task);
73212+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
73213+ subj = __gr_get_subject_for_task(polstate, task, NULL);
73214+ if (subj == NULL) {
73215+ ret = -EINVAL;
73216+ read_unlock(&grsec_exec_file_lock);
73217+ read_unlock(&tasklist_lock);
73218+ rcu_read_unlock();
73219+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
73220+ return ret;
73221+ }
73222+ __gr_apply_subject_to_task(polstate, task, subj);
73223+ } else {
73224+ // it's a kernel process
73225+ task->role = polstate->kernel_role;
73226+ task->acl = polstate->kernel_role->root_label;
73227+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
73228+ task->acl->mode &= ~GR_PROCFIND;
73229+#endif
73230+ }
73231+ } while_each_thread(task2, task);
73232+ read_unlock(&grsec_exec_file_lock);
73233+ read_unlock(&tasklist_lock);
73234+ rcu_read_unlock();
73235+
73236+ return 0;
73237+}
73238diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
73239new file mode 100644
73240index 0000000..39645c9
73241--- /dev/null
73242+++ b/grsecurity/gracl_res.c
73243@@ -0,0 +1,68 @@
73244+#include <linux/kernel.h>
73245+#include <linux/sched.h>
73246+#include <linux/gracl.h>
73247+#include <linux/grinternal.h>
73248+
73249+static const char *restab_log[] = {
73250+ [RLIMIT_CPU] = "RLIMIT_CPU",
73251+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
73252+ [RLIMIT_DATA] = "RLIMIT_DATA",
73253+ [RLIMIT_STACK] = "RLIMIT_STACK",
73254+ [RLIMIT_CORE] = "RLIMIT_CORE",
73255+ [RLIMIT_RSS] = "RLIMIT_RSS",
73256+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
73257+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
73258+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
73259+ [RLIMIT_AS] = "RLIMIT_AS",
73260+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
73261+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
73262+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
73263+ [RLIMIT_NICE] = "RLIMIT_NICE",
73264+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
73265+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
73266+ [GR_CRASH_RES] = "RLIMIT_CRASH"
73267+};
73268+
73269+void
73270+gr_log_resource(const struct task_struct *task,
73271+ const int res, const unsigned long wanted, const int gt)
73272+{
73273+ const struct cred *cred;
73274+ unsigned long rlim;
73275+
73276+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
73277+ return;
73278+
73279+ // not yet supported resource
73280+ if (unlikely(!restab_log[res]))
73281+ return;
73282+
73283+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
73284+ rlim = task_rlimit_max(task, res);
73285+ else
73286+ rlim = task_rlimit(task, res);
73287+
73288+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
73289+ return;
73290+
73291+ rcu_read_lock();
73292+ cred = __task_cred(task);
73293+
73294+ if (res == RLIMIT_NPROC &&
73295+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
73296+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
73297+ goto out_rcu_unlock;
73298+ else if (res == RLIMIT_MEMLOCK &&
73299+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
73300+ goto out_rcu_unlock;
73301+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
73302+ goto out_rcu_unlock;
73303+ rcu_read_unlock();
73304+
73305+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
73306+
73307+ return;
73308+out_rcu_unlock:
73309+ rcu_read_unlock();
73310+ return;
73311+}
73312diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
73313new file mode 100644
73314index 0000000..2040e61
73315--- /dev/null
73316+++ b/grsecurity/gracl_segv.c
73317@@ -0,0 +1,313 @@
73318+#include <linux/kernel.h>
73319+#include <linux/mm.h>
73320+#include <asm/uaccess.h>
73321+#include <asm/errno.h>
73322+#include <asm/mman.h>
73323+#include <net/sock.h>
73324+#include <linux/file.h>
73325+#include <linux/fs.h>
73326+#include <linux/net.h>
73327+#include <linux/in.h>
73328+#include <linux/slab.h>
73329+#include <linux/types.h>
73330+#include <linux/sched.h>
73331+#include <linux/timer.h>
73332+#include <linux/gracl.h>
73333+#include <linux/grsecurity.h>
73334+#include <linux/grinternal.h>
73335+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73336+#include <linux/magic.h>
73337+#include <linux/pagemap.h>
73338+#include "../fs/btrfs/async-thread.h"
73339+#include "../fs/btrfs/ctree.h"
73340+#include "../fs/btrfs/btrfs_inode.h"
73341+#endif
73342+
73343+static struct crash_uid *uid_set;
73344+static unsigned short uid_used;
73345+static DEFINE_SPINLOCK(gr_uid_lock);
73346+extern rwlock_t gr_inode_lock;
73347+extern struct acl_subject_label *
73348+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
73349+ struct acl_role_label *role);
73350+
73351+static inline dev_t __get_dev(const struct dentry *dentry)
73352+{
73353+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73354+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
73355+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
73356+ else
73357+#endif
73358+ return dentry->d_sb->s_dev;
73359+}
73360+
73361+int
73362+gr_init_uidset(void)
73363+{
73364+ uid_set =
73365+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73366+ uid_used = 0;
73367+
73368+ return uid_set ? 1 : 0;
73369+}
73370+
73371+void
73372+gr_free_uidset(void)
73373+{
73374+ if (uid_set) {
73375+ struct crash_uid *tmpset;
73376+ spin_lock(&gr_uid_lock);
73377+ tmpset = uid_set;
73378+ uid_set = NULL;
73379+ uid_used = 0;
73380+ spin_unlock(&gr_uid_lock);
73381+ if (tmpset)
73382+ kfree(tmpset);
73383+ }
73384+
73385+ return;
73386+}
73387+
73388+int
73389+gr_find_uid(const uid_t uid)
73390+{
73391+ struct crash_uid *tmp = uid_set;
73392+ uid_t buid;
73393+ int low = 0, high = uid_used - 1, mid;
73394+
73395+ while (high >= low) {
73396+ mid = (low + high) >> 1;
73397+ buid = tmp[mid].uid;
73398+ if (buid == uid)
73399+ return mid;
73400+ if (buid > uid)
73401+ high = mid - 1;
73402+ if (buid < uid)
73403+ low = mid + 1;
73404+ }
73405+
73406+ return -1;
73407+}
73408+
73409+static __inline__ void
73410+gr_insertsort(void)
73411+{
73412+ unsigned short i, j;
73413+ struct crash_uid index;
73414+
73415+ for (i = 1; i < uid_used; i++) {
73416+ index = uid_set[i];
73417+ j = i;
73418+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73419+ uid_set[j] = uid_set[j - 1];
73420+ j--;
73421+ }
73422+ uid_set[j] = index;
73423+ }
73424+
73425+ return;
73426+}
73427+
73428+static __inline__ void
73429+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73430+{
73431+ int loc;
73432+ uid_t uid = GR_GLOBAL_UID(kuid);
73433+
73434+ if (uid_used == GR_UIDTABLE_MAX)
73435+ return;
73436+
73437+ loc = gr_find_uid(uid);
73438+
73439+ if (loc >= 0) {
73440+ uid_set[loc].expires = expires;
73441+ return;
73442+ }
73443+
73444+ uid_set[uid_used].uid = uid;
73445+ uid_set[uid_used].expires = expires;
73446+ uid_used++;
73447+
73448+ gr_insertsort();
73449+
73450+ return;
73451+}
73452+
73453+void
73454+gr_remove_uid(const unsigned short loc)
73455+{
73456+ unsigned short i;
73457+
73458+ for (i = loc + 1; i < uid_used; i++)
73459+ uid_set[i - 1] = uid_set[i];
73460+
73461+ uid_used--;
73462+
73463+ return;
73464+}
73465+
73466+int
73467+gr_check_crash_uid(const kuid_t kuid)
73468+{
73469+ int loc;
73470+ int ret = 0;
73471+ uid_t uid;
73472+
73473+ if (unlikely(!gr_acl_is_enabled()))
73474+ return 0;
73475+
73476+ uid = GR_GLOBAL_UID(kuid);
73477+
73478+ spin_lock(&gr_uid_lock);
73479+ loc = gr_find_uid(uid);
73480+
73481+ if (loc < 0)
73482+ goto out_unlock;
73483+
73484+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
73485+ gr_remove_uid(loc);
73486+ else
73487+ ret = 1;
73488+
73489+out_unlock:
73490+ spin_unlock(&gr_uid_lock);
73491+ return ret;
73492+}
73493+
73494+static __inline__ int
73495+proc_is_setxid(const struct cred *cred)
73496+{
73497+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73498+ !uid_eq(cred->uid, cred->fsuid))
73499+ return 1;
73500+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73501+ !gid_eq(cred->gid, cred->fsgid))
73502+ return 1;
73503+
73504+ return 0;
73505+}
73506+
73507+extern int gr_fake_force_sig(int sig, struct task_struct *t);
73508+
73509+void
73510+gr_handle_crash(struct task_struct *task, const int sig)
73511+{
73512+ struct acl_subject_label *curr;
73513+ struct task_struct *tsk, *tsk2;
73514+ const struct cred *cred;
73515+ const struct cred *cred2;
73516+
73517+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73518+ return;
73519+
73520+ if (unlikely(!gr_acl_is_enabled()))
73521+ return;
73522+
73523+ curr = task->acl;
73524+
73525+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
73526+ return;
73527+
73528+ if (time_before_eq(curr->expires, get_seconds())) {
73529+ curr->expires = 0;
73530+ curr->crashes = 0;
73531+ }
73532+
73533+ curr->crashes++;
73534+
73535+ if (!curr->expires)
73536+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73537+
73538+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73539+ time_after(curr->expires, get_seconds())) {
73540+ rcu_read_lock();
73541+ cred = __task_cred(task);
73542+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73543+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73544+ spin_lock(&gr_uid_lock);
73545+ gr_insert_uid(cred->uid, curr->expires);
73546+ spin_unlock(&gr_uid_lock);
73547+ curr->expires = 0;
73548+ curr->crashes = 0;
73549+ read_lock(&tasklist_lock);
73550+ do_each_thread(tsk2, tsk) {
73551+ cred2 = __task_cred(tsk);
73552+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
73553+ gr_fake_force_sig(SIGKILL, tsk);
73554+ } while_each_thread(tsk2, tsk);
73555+ read_unlock(&tasklist_lock);
73556+ } else {
73557+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73558+ read_lock(&tasklist_lock);
73559+ read_lock(&grsec_exec_file_lock);
73560+ do_each_thread(tsk2, tsk) {
73561+ if (likely(tsk != task)) {
73562+ // if this thread has the same subject as the one that triggered
73563+ // RES_CRASH and it's the same binary, kill it
73564+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73565+ gr_fake_force_sig(SIGKILL, tsk);
73566+ }
73567+ } while_each_thread(tsk2, tsk);
73568+ read_unlock(&grsec_exec_file_lock);
73569+ read_unlock(&tasklist_lock);
73570+ }
73571+ rcu_read_unlock();
73572+ }
73573+
73574+ return;
73575+}
73576+
73577+int
73578+gr_check_crash_exec(const struct file *filp)
73579+{
73580+ struct acl_subject_label *curr;
73581+
73582+ if (unlikely(!gr_acl_is_enabled()))
73583+ return 0;
73584+
73585+ read_lock(&gr_inode_lock);
73586+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73587+ __get_dev(filp->f_path.dentry),
73588+ current->role);
73589+ read_unlock(&gr_inode_lock);
73590+
73591+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73592+ (!curr->crashes && !curr->expires))
73593+ return 0;
73594+
73595+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73596+ time_after(curr->expires, get_seconds()))
73597+ return 1;
73598+ else if (time_before_eq(curr->expires, get_seconds())) {
73599+ curr->crashes = 0;
73600+ curr->expires = 0;
73601+ }
73602+
73603+ return 0;
73604+}
73605+
73606+void
73607+gr_handle_alertkill(struct task_struct *task)
73608+{
73609+ struct acl_subject_label *curracl;
73610+ __u32 curr_ip;
73611+ struct task_struct *p, *p2;
73612+
73613+ if (unlikely(!gr_acl_is_enabled()))
73614+ return;
73615+
73616+ curracl = task->acl;
73617+ curr_ip = task->signal->curr_ip;
73618+
73619+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73620+ read_lock(&tasklist_lock);
73621+ do_each_thread(p2, p) {
73622+ if (p->signal->curr_ip == curr_ip)
73623+ gr_fake_force_sig(SIGKILL, p);
73624+ } while_each_thread(p2, p);
73625+ read_unlock(&tasklist_lock);
73626+ } else if (curracl->mode & GR_KILLPROC)
73627+ gr_fake_force_sig(SIGKILL, task);
73628+
73629+ return;
73630+}
73631diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73632new file mode 100644
73633index 0000000..98011b0
73634--- /dev/null
73635+++ b/grsecurity/gracl_shm.c
73636@@ -0,0 +1,40 @@
73637+#include <linux/kernel.h>
73638+#include <linux/mm.h>
73639+#include <linux/sched.h>
73640+#include <linux/file.h>
73641+#include <linux/ipc.h>
73642+#include <linux/gracl.h>
73643+#include <linux/grsecurity.h>
73644+#include <linux/grinternal.h>
73645+
73646+int
73647+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73648+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73649+{
73650+ struct task_struct *task;
73651+
73652+ if (!gr_acl_is_enabled())
73653+ return 1;
73654+
73655+ rcu_read_lock();
73656+ read_lock(&tasklist_lock);
73657+
73658+ task = find_task_by_vpid(shm_cprid);
73659+
73660+ if (unlikely(!task))
73661+ task = find_task_by_vpid(shm_lapid);
73662+
73663+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73664+ (task_pid_nr(task) == shm_lapid)) &&
73665+ (task->acl->mode & GR_PROTSHM) &&
73666+ (task->acl != current->acl))) {
73667+ read_unlock(&tasklist_lock);
73668+ rcu_read_unlock();
73669+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73670+ return 0;
73671+ }
73672+ read_unlock(&tasklist_lock);
73673+ rcu_read_unlock();
73674+
73675+ return 1;
73676+}
73677diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73678new file mode 100644
73679index 0000000..bc0be01
73680--- /dev/null
73681+++ b/grsecurity/grsec_chdir.c
73682@@ -0,0 +1,19 @@
73683+#include <linux/kernel.h>
73684+#include <linux/sched.h>
73685+#include <linux/fs.h>
73686+#include <linux/file.h>
73687+#include <linux/grsecurity.h>
73688+#include <linux/grinternal.h>
73689+
73690+void
73691+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73692+{
73693+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73694+ if ((grsec_enable_chdir && grsec_enable_group &&
73695+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73696+ !grsec_enable_group)) {
73697+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73698+ }
73699+#endif
73700+ return;
73701+}
73702diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73703new file mode 100644
73704index 0000000..651d6c2
73705--- /dev/null
73706+++ b/grsecurity/grsec_chroot.c
73707@@ -0,0 +1,370 @@
73708+#include <linux/kernel.h>
73709+#include <linux/module.h>
73710+#include <linux/sched.h>
73711+#include <linux/file.h>
73712+#include <linux/fs.h>
73713+#include <linux/mount.h>
73714+#include <linux/types.h>
73715+#include "../fs/mount.h"
73716+#include <linux/grsecurity.h>
73717+#include <linux/grinternal.h>
73718+
73719+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73720+int gr_init_ran;
73721+#endif
73722+
73723+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73724+{
73725+#ifdef CONFIG_GRKERNSEC
73726+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73727+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73728+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73729+ && gr_init_ran
73730+#endif
73731+ )
73732+ task->gr_is_chrooted = 1;
73733+ else {
73734+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73735+ if (task_pid_nr(task) == 1 && !gr_init_ran)
73736+ gr_init_ran = 1;
73737+#endif
73738+ task->gr_is_chrooted = 0;
73739+ }
73740+
73741+ task->gr_chroot_dentry = path->dentry;
73742+#endif
73743+ return;
73744+}
73745+
73746+void gr_clear_chroot_entries(struct task_struct *task)
73747+{
73748+#ifdef CONFIG_GRKERNSEC
73749+ task->gr_is_chrooted = 0;
73750+ task->gr_chroot_dentry = NULL;
73751+#endif
73752+ return;
73753+}
73754+
73755+int
73756+gr_handle_chroot_unix(const pid_t pid)
73757+{
73758+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73759+ struct task_struct *p;
73760+
73761+ if (unlikely(!grsec_enable_chroot_unix))
73762+ return 1;
73763+
73764+ if (likely(!proc_is_chrooted(current)))
73765+ return 1;
73766+
73767+ rcu_read_lock();
73768+ read_lock(&tasklist_lock);
73769+ p = find_task_by_vpid_unrestricted(pid);
73770+ if (unlikely(p && !have_same_root(current, p))) {
73771+ read_unlock(&tasklist_lock);
73772+ rcu_read_unlock();
73773+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73774+ return 0;
73775+ }
73776+ read_unlock(&tasklist_lock);
73777+ rcu_read_unlock();
73778+#endif
73779+ return 1;
73780+}
73781+
73782+int
73783+gr_handle_chroot_nice(void)
73784+{
73785+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73786+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73787+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73788+ return -EPERM;
73789+ }
73790+#endif
73791+ return 0;
73792+}
73793+
73794+int
73795+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73796+{
73797+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73798+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73799+ && proc_is_chrooted(current)) {
73800+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73801+ return -EACCES;
73802+ }
73803+#endif
73804+ return 0;
73805+}
73806+
73807+int
73808+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73809+{
73810+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73811+ struct task_struct *p;
73812+ int ret = 0;
73813+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73814+ return ret;
73815+
73816+ read_lock(&tasklist_lock);
73817+ do_each_pid_task(pid, type, p) {
73818+ if (!have_same_root(current, p)) {
73819+ ret = 1;
73820+ goto out;
73821+ }
73822+ } while_each_pid_task(pid, type, p);
73823+out:
73824+ read_unlock(&tasklist_lock);
73825+ return ret;
73826+#endif
73827+ return 0;
73828+}
73829+
73830+int
73831+gr_pid_is_chrooted(struct task_struct *p)
73832+{
73833+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73834+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73835+ return 0;
73836+
73837+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73838+ !have_same_root(current, p)) {
73839+ return 1;
73840+ }
73841+#endif
73842+ return 0;
73843+}
73844+
73845+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73846+
73847+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73848+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73849+{
73850+ struct path path, currentroot;
73851+ int ret = 0;
73852+
73853+ path.dentry = (struct dentry *)u_dentry;
73854+ path.mnt = (struct vfsmount *)u_mnt;
73855+ get_fs_root(current->fs, &currentroot);
73856+ if (path_is_under(&path, &currentroot))
73857+ ret = 1;
73858+ path_put(&currentroot);
73859+
73860+ return ret;
73861+}
73862+#endif
73863+
73864+int
73865+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73866+{
73867+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73868+ if (!grsec_enable_chroot_fchdir)
73869+ return 1;
73870+
73871+ if (!proc_is_chrooted(current))
73872+ return 1;
73873+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73874+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73875+ return 0;
73876+ }
73877+#endif
73878+ return 1;
73879+}
73880+
73881+int
73882+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73883+ const time_t shm_createtime)
73884+{
73885+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73886+ struct task_struct *p;
73887+ time_t starttime;
73888+
73889+ if (unlikely(!grsec_enable_chroot_shmat))
73890+ return 1;
73891+
73892+ if (likely(!proc_is_chrooted(current)))
73893+ return 1;
73894+
73895+ rcu_read_lock();
73896+ read_lock(&tasklist_lock);
73897+
73898+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73899+ starttime = p->start_time.tv_sec;
73900+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73901+ if (have_same_root(current, p)) {
73902+ goto allow;
73903+ } else {
73904+ read_unlock(&tasklist_lock);
73905+ rcu_read_unlock();
73906+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73907+ return 0;
73908+ }
73909+ }
73910+ /* creator exited, pid reuse, fall through to next check */
73911+ }
73912+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73913+ if (unlikely(!have_same_root(current, p))) {
73914+ read_unlock(&tasklist_lock);
73915+ rcu_read_unlock();
73916+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73917+ return 0;
73918+ }
73919+ }
73920+
73921+allow:
73922+ read_unlock(&tasklist_lock);
73923+ rcu_read_unlock();
73924+#endif
73925+ return 1;
73926+}
73927+
73928+void
73929+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73930+{
73931+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73932+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73933+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73934+#endif
73935+ return;
73936+}
73937+
73938+int
73939+gr_handle_chroot_mknod(const struct dentry *dentry,
73940+ const struct vfsmount *mnt, const int mode)
73941+{
73942+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73943+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73944+ proc_is_chrooted(current)) {
73945+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73946+ return -EPERM;
73947+ }
73948+#endif
73949+ return 0;
73950+}
73951+
73952+int
73953+gr_handle_chroot_mount(const struct dentry *dentry,
73954+ const struct vfsmount *mnt, const char *dev_name)
73955+{
73956+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73957+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73958+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73959+ return -EPERM;
73960+ }
73961+#endif
73962+ return 0;
73963+}
73964+
73965+int
73966+gr_handle_chroot_pivot(void)
73967+{
73968+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73969+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73970+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73971+ return -EPERM;
73972+ }
73973+#endif
73974+ return 0;
73975+}
73976+
73977+int
73978+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73979+{
73980+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73981+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73982+ !gr_is_outside_chroot(dentry, mnt)) {
73983+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73984+ return -EPERM;
73985+ }
73986+#endif
73987+ return 0;
73988+}
73989+
73990+extern const char *captab_log[];
73991+extern int captab_log_entries;
73992+
73993+int
73994+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73995+{
73996+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73997+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73998+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73999+ if (cap_raised(chroot_caps, cap)) {
74000+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
74001+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
74002+ }
74003+ return 0;
74004+ }
74005+ }
74006+#endif
74007+ return 1;
74008+}
74009+
74010+int
74011+gr_chroot_is_capable(const int cap)
74012+{
74013+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74014+ return gr_task_chroot_is_capable(current, current_cred(), cap);
74015+#endif
74016+ return 1;
74017+}
74018+
74019+int
74020+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
74021+{
74022+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74023+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
74024+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
74025+ if (cap_raised(chroot_caps, cap)) {
74026+ return 0;
74027+ }
74028+ }
74029+#endif
74030+ return 1;
74031+}
74032+
74033+int
74034+gr_chroot_is_capable_nolog(const int cap)
74035+{
74036+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74037+ return gr_task_chroot_is_capable_nolog(current, cap);
74038+#endif
74039+ return 1;
74040+}
74041+
74042+int
74043+gr_handle_chroot_sysctl(const int op)
74044+{
74045+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74046+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
74047+ proc_is_chrooted(current))
74048+ return -EACCES;
74049+#endif
74050+ return 0;
74051+}
74052+
74053+void
74054+gr_handle_chroot_chdir(const struct path *path)
74055+{
74056+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74057+ if (grsec_enable_chroot_chdir)
74058+ set_fs_pwd(current->fs, path);
74059+#endif
74060+ return;
74061+}
74062+
74063+int
74064+gr_handle_chroot_chmod(const struct dentry *dentry,
74065+ const struct vfsmount *mnt, const int mode)
74066+{
74067+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74068+ /* allow chmod +s on directories, but not files */
74069+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
74070+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
74071+ proc_is_chrooted(current)) {
74072+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
74073+ return -EPERM;
74074+ }
74075+#endif
74076+ return 0;
74077+}
74078diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
74079new file mode 100644
74080index 0000000..4d6fce8
74081--- /dev/null
74082+++ b/grsecurity/grsec_disabled.c
74083@@ -0,0 +1,433 @@
74084+#include <linux/kernel.h>
74085+#include <linux/module.h>
74086+#include <linux/sched.h>
74087+#include <linux/file.h>
74088+#include <linux/fs.h>
74089+#include <linux/kdev_t.h>
74090+#include <linux/net.h>
74091+#include <linux/in.h>
74092+#include <linux/ip.h>
74093+#include <linux/skbuff.h>
74094+#include <linux/sysctl.h>
74095+
74096+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
74097+void
74098+pax_set_initial_flags(struct linux_binprm *bprm)
74099+{
74100+ return;
74101+}
74102+#endif
74103+
74104+#ifdef CONFIG_SYSCTL
74105+__u32
74106+gr_handle_sysctl(const struct ctl_table * table, const int op)
74107+{
74108+ return 0;
74109+}
74110+#endif
74111+
74112+#ifdef CONFIG_TASKSTATS
74113+int gr_is_taskstats_denied(int pid)
74114+{
74115+ return 0;
74116+}
74117+#endif
74118+
74119+int
74120+gr_acl_is_enabled(void)
74121+{
74122+ return 0;
74123+}
74124+
74125+void
74126+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
74127+{
74128+ return;
74129+}
74130+
74131+int
74132+gr_handle_rawio(const struct inode *inode)
74133+{
74134+ return 0;
74135+}
74136+
74137+void
74138+gr_acl_handle_psacct(struct task_struct *task, const long code)
74139+{
74140+ return;
74141+}
74142+
74143+int
74144+gr_handle_ptrace(struct task_struct *task, const long request)
74145+{
74146+ return 0;
74147+}
74148+
74149+int
74150+gr_handle_proc_ptrace(struct task_struct *task)
74151+{
74152+ return 0;
74153+}
74154+
74155+int
74156+gr_set_acls(const int type)
74157+{
74158+ return 0;
74159+}
74160+
74161+int
74162+gr_check_hidden_task(const struct task_struct *tsk)
74163+{
74164+ return 0;
74165+}
74166+
74167+int
74168+gr_check_protected_task(const struct task_struct *task)
74169+{
74170+ return 0;
74171+}
74172+
74173+int
74174+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
74175+{
74176+ return 0;
74177+}
74178+
74179+void
74180+gr_copy_label(struct task_struct *tsk)
74181+{
74182+ return;
74183+}
74184+
74185+void
74186+gr_set_pax_flags(struct task_struct *task)
74187+{
74188+ return;
74189+}
74190+
74191+int
74192+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
74193+ const int unsafe_share)
74194+{
74195+ return 0;
74196+}
74197+
74198+void
74199+gr_handle_delete(const ino_t ino, const dev_t dev)
74200+{
74201+ return;
74202+}
74203+
74204+void
74205+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
74206+{
74207+ return;
74208+}
74209+
74210+void
74211+gr_handle_crash(struct task_struct *task, const int sig)
74212+{
74213+ return;
74214+}
74215+
74216+int
74217+gr_check_crash_exec(const struct file *filp)
74218+{
74219+ return 0;
74220+}
74221+
74222+int
74223+gr_check_crash_uid(const kuid_t uid)
74224+{
74225+ return 0;
74226+}
74227+
74228+void
74229+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74230+ struct dentry *old_dentry,
74231+ struct dentry *new_dentry,
74232+ struct vfsmount *mnt, const __u8 replace)
74233+{
74234+ return;
74235+}
74236+
74237+int
74238+gr_search_socket(const int family, const int type, const int protocol)
74239+{
74240+ return 1;
74241+}
74242+
74243+int
74244+gr_search_connectbind(const int mode, const struct socket *sock,
74245+ const struct sockaddr_in *addr)
74246+{
74247+ return 0;
74248+}
74249+
74250+void
74251+gr_handle_alertkill(struct task_struct *task)
74252+{
74253+ return;
74254+}
74255+
74256+__u32
74257+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
74258+{
74259+ return 1;
74260+}
74261+
74262+__u32
74263+gr_acl_handle_hidden_file(const struct dentry * dentry,
74264+ const struct vfsmount * mnt)
74265+{
74266+ return 1;
74267+}
74268+
74269+__u32
74270+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74271+ int acc_mode)
74272+{
74273+ return 1;
74274+}
74275+
74276+__u32
74277+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74278+{
74279+ return 1;
74280+}
74281+
74282+__u32
74283+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
74284+{
74285+ return 1;
74286+}
74287+
74288+int
74289+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
74290+ unsigned int *vm_flags)
74291+{
74292+ return 1;
74293+}
74294+
74295+__u32
74296+gr_acl_handle_truncate(const struct dentry * dentry,
74297+ const struct vfsmount * mnt)
74298+{
74299+ return 1;
74300+}
74301+
74302+__u32
74303+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
74304+{
74305+ return 1;
74306+}
74307+
74308+__u32
74309+gr_acl_handle_access(const struct dentry * dentry,
74310+ const struct vfsmount * mnt, const int fmode)
74311+{
74312+ return 1;
74313+}
74314+
74315+__u32
74316+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
74317+ umode_t *mode)
74318+{
74319+ return 1;
74320+}
74321+
74322+__u32
74323+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
74324+{
74325+ return 1;
74326+}
74327+
74328+__u32
74329+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
74330+{
74331+ return 1;
74332+}
74333+
74334+__u32
74335+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
74336+{
74337+ return 1;
74338+}
74339+
74340+void
74341+grsecurity_init(void)
74342+{
74343+ return;
74344+}
74345+
74346+umode_t gr_acl_umask(void)
74347+{
74348+ return 0;
74349+}
74350+
74351+__u32
74352+gr_acl_handle_mknod(const struct dentry * new_dentry,
74353+ const struct dentry * parent_dentry,
74354+ const struct vfsmount * parent_mnt,
74355+ const int mode)
74356+{
74357+ return 1;
74358+}
74359+
74360+__u32
74361+gr_acl_handle_mkdir(const struct dentry * new_dentry,
74362+ const struct dentry * parent_dentry,
74363+ const struct vfsmount * parent_mnt)
74364+{
74365+ return 1;
74366+}
74367+
74368+__u32
74369+gr_acl_handle_symlink(const struct dentry * new_dentry,
74370+ const struct dentry * parent_dentry,
74371+ const struct vfsmount * parent_mnt, const struct filename *from)
74372+{
74373+ return 1;
74374+}
74375+
74376+__u32
74377+gr_acl_handle_link(const struct dentry * new_dentry,
74378+ const struct dentry * parent_dentry,
74379+ const struct vfsmount * parent_mnt,
74380+ const struct dentry * old_dentry,
74381+ const struct vfsmount * old_mnt, const struct filename *to)
74382+{
74383+ return 1;
74384+}
74385+
74386+int
74387+gr_acl_handle_rename(const struct dentry *new_dentry,
74388+ const struct dentry *parent_dentry,
74389+ const struct vfsmount *parent_mnt,
74390+ const struct dentry *old_dentry,
74391+ const struct inode *old_parent_inode,
74392+ const struct vfsmount *old_mnt, const struct filename *newname)
74393+{
74394+ return 0;
74395+}
74396+
74397+int
74398+gr_acl_handle_filldir(const struct file *file, const char *name,
74399+ const int namelen, const ino_t ino)
74400+{
74401+ return 1;
74402+}
74403+
74404+int
74405+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74406+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
74407+{
74408+ return 1;
74409+}
74410+
74411+int
74412+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74413+{
74414+ return 0;
74415+}
74416+
74417+int
74418+gr_search_accept(const struct socket *sock)
74419+{
74420+ return 0;
74421+}
74422+
74423+int
74424+gr_search_listen(const struct socket *sock)
74425+{
74426+ return 0;
74427+}
74428+
74429+int
74430+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74431+{
74432+ return 0;
74433+}
74434+
74435+__u32
74436+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74437+{
74438+ return 1;
74439+}
74440+
74441+__u32
74442+gr_acl_handle_creat(const struct dentry * dentry,
74443+ const struct dentry * p_dentry,
74444+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74445+ const int imode)
74446+{
74447+ return 1;
74448+}
74449+
74450+void
74451+gr_acl_handle_exit(void)
74452+{
74453+ return;
74454+}
74455+
74456+int
74457+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74458+{
74459+ return 1;
74460+}
74461+
74462+void
74463+gr_set_role_label(const kuid_t uid, const kgid_t gid)
74464+{
74465+ return;
74466+}
74467+
74468+int
74469+gr_acl_handle_procpidmem(const struct task_struct *task)
74470+{
74471+ return 0;
74472+}
74473+
74474+int
74475+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74476+{
74477+ return 0;
74478+}
74479+
74480+int
74481+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74482+{
74483+ return 0;
74484+}
74485+
74486+int
74487+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74488+{
74489+ return 0;
74490+}
74491+
74492+int
74493+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74494+{
74495+ return 0;
74496+}
74497+
74498+int gr_acl_enable_at_secure(void)
74499+{
74500+ return 0;
74501+}
74502+
74503+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74504+{
74505+ return dentry->d_sb->s_dev;
74506+}
74507+
74508+void gr_put_exec_file(struct task_struct *task)
74509+{
74510+ return;
74511+}
74512+
74513+#ifdef CONFIG_SECURITY
74514+EXPORT_SYMBOL_GPL(gr_check_user_change);
74515+EXPORT_SYMBOL_GPL(gr_check_group_change);
74516+#endif
74517diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74518new file mode 100644
74519index 0000000..f35f454
74520--- /dev/null
74521+++ b/grsecurity/grsec_exec.c
74522@@ -0,0 +1,187 @@
74523+#include <linux/kernel.h>
74524+#include <linux/sched.h>
74525+#include <linux/file.h>
74526+#include <linux/binfmts.h>
74527+#include <linux/fs.h>
74528+#include <linux/types.h>
74529+#include <linux/grdefs.h>
74530+#include <linux/grsecurity.h>
74531+#include <linux/grinternal.h>
74532+#include <linux/capability.h>
74533+#include <linux/module.h>
74534+#include <linux/compat.h>
74535+
74536+#include <asm/uaccess.h>
74537+
74538+#ifdef CONFIG_GRKERNSEC_EXECLOG
74539+static char gr_exec_arg_buf[132];
74540+static DEFINE_MUTEX(gr_exec_arg_mutex);
74541+#endif
74542+
74543+struct user_arg_ptr {
74544+#ifdef CONFIG_COMPAT
74545+ bool is_compat;
74546+#endif
74547+ union {
74548+ const char __user *const __user *native;
74549+#ifdef CONFIG_COMPAT
74550+ const compat_uptr_t __user *compat;
74551+#endif
74552+ } ptr;
74553+};
74554+
74555+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74556+
74557+void
74558+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74559+{
74560+#ifdef CONFIG_GRKERNSEC_EXECLOG
74561+ char *grarg = gr_exec_arg_buf;
74562+ unsigned int i, x, execlen = 0;
74563+ char c;
74564+
74565+ if (!((grsec_enable_execlog && grsec_enable_group &&
74566+ in_group_p(grsec_audit_gid))
74567+ || (grsec_enable_execlog && !grsec_enable_group)))
74568+ return;
74569+
74570+ mutex_lock(&gr_exec_arg_mutex);
74571+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
74572+
74573+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
74574+ const char __user *p;
74575+ unsigned int len;
74576+
74577+ p = get_user_arg_ptr(argv, i);
74578+ if (IS_ERR(p))
74579+ goto log;
74580+
74581+ len = strnlen_user(p, 128 - execlen);
74582+ if (len > 128 - execlen)
74583+ len = 128 - execlen;
74584+ else if (len > 0)
74585+ len--;
74586+ if (copy_from_user(grarg + execlen, p, len))
74587+ goto log;
74588+
74589+ /* rewrite unprintable characters */
74590+ for (x = 0; x < len; x++) {
74591+ c = *(grarg + execlen + x);
74592+ if (c < 32 || c > 126)
74593+ *(grarg + execlen + x) = ' ';
74594+ }
74595+
74596+ execlen += len;
74597+ *(grarg + execlen) = ' ';
74598+ *(grarg + execlen + 1) = '\0';
74599+ execlen++;
74600+ }
74601+
74602+ log:
74603+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74604+ bprm->file->f_path.mnt, grarg);
74605+ mutex_unlock(&gr_exec_arg_mutex);
74606+#endif
74607+ return;
74608+}
74609+
74610+#ifdef CONFIG_GRKERNSEC
74611+extern int gr_acl_is_capable(const int cap);
74612+extern int gr_acl_is_capable_nolog(const int cap);
74613+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74614+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74615+extern int gr_chroot_is_capable(const int cap);
74616+extern int gr_chroot_is_capable_nolog(const int cap);
74617+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74618+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74619+#endif
74620+
74621+const char *captab_log[] = {
74622+ "CAP_CHOWN",
74623+ "CAP_DAC_OVERRIDE",
74624+ "CAP_DAC_READ_SEARCH",
74625+ "CAP_FOWNER",
74626+ "CAP_FSETID",
74627+ "CAP_KILL",
74628+ "CAP_SETGID",
74629+ "CAP_SETUID",
74630+ "CAP_SETPCAP",
74631+ "CAP_LINUX_IMMUTABLE",
74632+ "CAP_NET_BIND_SERVICE",
74633+ "CAP_NET_BROADCAST",
74634+ "CAP_NET_ADMIN",
74635+ "CAP_NET_RAW",
74636+ "CAP_IPC_LOCK",
74637+ "CAP_IPC_OWNER",
74638+ "CAP_SYS_MODULE",
74639+ "CAP_SYS_RAWIO",
74640+ "CAP_SYS_CHROOT",
74641+ "CAP_SYS_PTRACE",
74642+ "CAP_SYS_PACCT",
74643+ "CAP_SYS_ADMIN",
74644+ "CAP_SYS_BOOT",
74645+ "CAP_SYS_NICE",
74646+ "CAP_SYS_RESOURCE",
74647+ "CAP_SYS_TIME",
74648+ "CAP_SYS_TTY_CONFIG",
74649+ "CAP_MKNOD",
74650+ "CAP_LEASE",
74651+ "CAP_AUDIT_WRITE",
74652+ "CAP_AUDIT_CONTROL",
74653+ "CAP_SETFCAP",
74654+ "CAP_MAC_OVERRIDE",
74655+ "CAP_MAC_ADMIN",
74656+ "CAP_SYSLOG",
74657+ "CAP_WAKE_ALARM"
74658+};
74659+
74660+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74661+
74662+int gr_is_capable(const int cap)
74663+{
74664+#ifdef CONFIG_GRKERNSEC
74665+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74666+ return 1;
74667+ return 0;
74668+#else
74669+ return 1;
74670+#endif
74671+}
74672+
74673+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74674+{
74675+#ifdef CONFIG_GRKERNSEC
74676+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74677+ return 1;
74678+ return 0;
74679+#else
74680+ return 1;
74681+#endif
74682+}
74683+
74684+int gr_is_capable_nolog(const int cap)
74685+{
74686+#ifdef CONFIG_GRKERNSEC
74687+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74688+ return 1;
74689+ return 0;
74690+#else
74691+ return 1;
74692+#endif
74693+}
74694+
74695+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74696+{
74697+#ifdef CONFIG_GRKERNSEC
74698+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74699+ return 1;
74700+ return 0;
74701+#else
74702+ return 1;
74703+#endif
74704+}
74705+
74706+EXPORT_SYMBOL_GPL(gr_is_capable);
74707+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74708+EXPORT_SYMBOL_GPL(gr_task_is_capable);
74709+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74710diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74711new file mode 100644
74712index 0000000..06cc6ea
74713--- /dev/null
74714+++ b/grsecurity/grsec_fifo.c
74715@@ -0,0 +1,24 @@
74716+#include <linux/kernel.h>
74717+#include <linux/sched.h>
74718+#include <linux/fs.h>
74719+#include <linux/file.h>
74720+#include <linux/grinternal.h>
74721+
74722+int
74723+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74724+ const struct dentry *dir, const int flag, const int acc_mode)
74725+{
74726+#ifdef CONFIG_GRKERNSEC_FIFO
74727+ const struct cred *cred = current_cred();
74728+
74729+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74730+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74731+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74732+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74733+ if (!inode_permission(dentry->d_inode, acc_mode))
74734+ 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));
74735+ return -EACCES;
74736+ }
74737+#endif
74738+ return 0;
74739+}
74740diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74741new file mode 100644
74742index 0000000..8ca18bf
74743--- /dev/null
74744+++ b/grsecurity/grsec_fork.c
74745@@ -0,0 +1,23 @@
74746+#include <linux/kernel.h>
74747+#include <linux/sched.h>
74748+#include <linux/grsecurity.h>
74749+#include <linux/grinternal.h>
74750+#include <linux/errno.h>
74751+
74752+void
74753+gr_log_forkfail(const int retval)
74754+{
74755+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74756+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74757+ switch (retval) {
74758+ case -EAGAIN:
74759+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74760+ break;
74761+ case -ENOMEM:
74762+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74763+ break;
74764+ }
74765+ }
74766+#endif
74767+ return;
74768+}
74769diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74770new file mode 100644
74771index 0000000..ae6c028
74772--- /dev/null
74773+++ b/grsecurity/grsec_init.c
74774@@ -0,0 +1,272 @@
74775+#include <linux/kernel.h>
74776+#include <linux/sched.h>
74777+#include <linux/mm.h>
74778+#include <linux/gracl.h>
74779+#include <linux/slab.h>
74780+#include <linux/vmalloc.h>
74781+#include <linux/percpu.h>
74782+#include <linux/module.h>
74783+
74784+int grsec_enable_ptrace_readexec;
74785+int grsec_enable_setxid;
74786+int grsec_enable_symlinkown;
74787+kgid_t grsec_symlinkown_gid;
74788+int grsec_enable_brute;
74789+int grsec_enable_link;
74790+int grsec_enable_dmesg;
74791+int grsec_enable_harden_ptrace;
74792+int grsec_enable_harden_ipc;
74793+int grsec_enable_fifo;
74794+int grsec_enable_execlog;
74795+int grsec_enable_signal;
74796+int grsec_enable_forkfail;
74797+int grsec_enable_audit_ptrace;
74798+int grsec_enable_time;
74799+int grsec_enable_group;
74800+kgid_t grsec_audit_gid;
74801+int grsec_enable_chdir;
74802+int grsec_enable_mount;
74803+int grsec_enable_rofs;
74804+int grsec_deny_new_usb;
74805+int grsec_enable_chroot_findtask;
74806+int grsec_enable_chroot_mount;
74807+int grsec_enable_chroot_shmat;
74808+int grsec_enable_chroot_fchdir;
74809+int grsec_enable_chroot_double;
74810+int grsec_enable_chroot_pivot;
74811+int grsec_enable_chroot_chdir;
74812+int grsec_enable_chroot_chmod;
74813+int grsec_enable_chroot_mknod;
74814+int grsec_enable_chroot_nice;
74815+int grsec_enable_chroot_execlog;
74816+int grsec_enable_chroot_caps;
74817+int grsec_enable_chroot_sysctl;
74818+int grsec_enable_chroot_unix;
74819+int grsec_enable_tpe;
74820+kgid_t grsec_tpe_gid;
74821+int grsec_enable_blackhole;
74822+#ifdef CONFIG_IPV6_MODULE
74823+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74824+#endif
74825+int grsec_lastack_retries;
74826+int grsec_enable_tpe_all;
74827+int grsec_enable_tpe_invert;
74828+int grsec_enable_socket_all;
74829+kgid_t grsec_socket_all_gid;
74830+int grsec_enable_socket_client;
74831+kgid_t grsec_socket_client_gid;
74832+int grsec_enable_socket_server;
74833+kgid_t grsec_socket_server_gid;
74834+int grsec_resource_logging;
74835+int grsec_disable_privio;
74836+int grsec_enable_log_rwxmaps;
74837+int grsec_lock;
74838+
74839+DEFINE_SPINLOCK(grsec_alert_lock);
74840+unsigned long grsec_alert_wtime = 0;
74841+unsigned long grsec_alert_fyet = 0;
74842+
74843+DEFINE_SPINLOCK(grsec_audit_lock);
74844+
74845+DEFINE_RWLOCK(grsec_exec_file_lock);
74846+
74847+char *gr_shared_page[4];
74848+
74849+char *gr_alert_log_fmt;
74850+char *gr_audit_log_fmt;
74851+char *gr_alert_log_buf;
74852+char *gr_audit_log_buf;
74853+
74854+void __init
74855+grsecurity_init(void)
74856+{
74857+ int j;
74858+ /* create the per-cpu shared pages */
74859+
74860+#ifdef CONFIG_X86
74861+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74862+#endif
74863+
74864+ for (j = 0; j < 4; j++) {
74865+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74866+ if (gr_shared_page[j] == NULL) {
74867+ panic("Unable to allocate grsecurity shared page");
74868+ return;
74869+ }
74870+ }
74871+
74872+ /* allocate log buffers */
74873+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74874+ if (!gr_alert_log_fmt) {
74875+ panic("Unable to allocate grsecurity alert log format buffer");
74876+ return;
74877+ }
74878+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74879+ if (!gr_audit_log_fmt) {
74880+ panic("Unable to allocate grsecurity audit log format buffer");
74881+ return;
74882+ }
74883+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74884+ if (!gr_alert_log_buf) {
74885+ panic("Unable to allocate grsecurity alert log buffer");
74886+ return;
74887+ }
74888+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74889+ if (!gr_audit_log_buf) {
74890+ panic("Unable to allocate grsecurity audit log buffer");
74891+ return;
74892+ }
74893+
74894+#ifdef CONFIG_GRKERNSEC_IO
74895+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74896+ grsec_disable_privio = 1;
74897+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74898+ grsec_disable_privio = 1;
74899+#else
74900+ grsec_disable_privio = 0;
74901+#endif
74902+#endif
74903+
74904+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74905+ /* for backward compatibility, tpe_invert always defaults to on if
74906+ enabled in the kernel
74907+ */
74908+ grsec_enable_tpe_invert = 1;
74909+#endif
74910+
74911+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74912+#ifndef CONFIG_GRKERNSEC_SYSCTL
74913+ grsec_lock = 1;
74914+#endif
74915+
74916+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74917+ grsec_enable_log_rwxmaps = 1;
74918+#endif
74919+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74920+ grsec_enable_group = 1;
74921+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74922+#endif
74923+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74924+ grsec_enable_ptrace_readexec = 1;
74925+#endif
74926+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74927+ grsec_enable_chdir = 1;
74928+#endif
74929+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74930+ grsec_enable_harden_ptrace = 1;
74931+#endif
74932+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74933+ grsec_enable_harden_ipc = 1;
74934+#endif
74935+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74936+ grsec_enable_mount = 1;
74937+#endif
74938+#ifdef CONFIG_GRKERNSEC_LINK
74939+ grsec_enable_link = 1;
74940+#endif
74941+#ifdef CONFIG_GRKERNSEC_BRUTE
74942+ grsec_enable_brute = 1;
74943+#endif
74944+#ifdef CONFIG_GRKERNSEC_DMESG
74945+ grsec_enable_dmesg = 1;
74946+#endif
74947+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74948+ grsec_enable_blackhole = 1;
74949+ grsec_lastack_retries = 4;
74950+#endif
74951+#ifdef CONFIG_GRKERNSEC_FIFO
74952+ grsec_enable_fifo = 1;
74953+#endif
74954+#ifdef CONFIG_GRKERNSEC_EXECLOG
74955+ grsec_enable_execlog = 1;
74956+#endif
74957+#ifdef CONFIG_GRKERNSEC_SETXID
74958+ grsec_enable_setxid = 1;
74959+#endif
74960+#ifdef CONFIG_GRKERNSEC_SIGNAL
74961+ grsec_enable_signal = 1;
74962+#endif
74963+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74964+ grsec_enable_forkfail = 1;
74965+#endif
74966+#ifdef CONFIG_GRKERNSEC_TIME
74967+ grsec_enable_time = 1;
74968+#endif
74969+#ifdef CONFIG_GRKERNSEC_RESLOG
74970+ grsec_resource_logging = 1;
74971+#endif
74972+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74973+ grsec_enable_chroot_findtask = 1;
74974+#endif
74975+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74976+ grsec_enable_chroot_unix = 1;
74977+#endif
74978+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74979+ grsec_enable_chroot_mount = 1;
74980+#endif
74981+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74982+ grsec_enable_chroot_fchdir = 1;
74983+#endif
74984+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74985+ grsec_enable_chroot_shmat = 1;
74986+#endif
74987+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74988+ grsec_enable_audit_ptrace = 1;
74989+#endif
74990+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74991+ grsec_enable_chroot_double = 1;
74992+#endif
74993+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74994+ grsec_enable_chroot_pivot = 1;
74995+#endif
74996+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74997+ grsec_enable_chroot_chdir = 1;
74998+#endif
74999+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75000+ grsec_enable_chroot_chmod = 1;
75001+#endif
75002+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75003+ grsec_enable_chroot_mknod = 1;
75004+#endif
75005+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75006+ grsec_enable_chroot_nice = 1;
75007+#endif
75008+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75009+ grsec_enable_chroot_execlog = 1;
75010+#endif
75011+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75012+ grsec_enable_chroot_caps = 1;
75013+#endif
75014+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75015+ grsec_enable_chroot_sysctl = 1;
75016+#endif
75017+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75018+ grsec_enable_symlinkown = 1;
75019+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
75020+#endif
75021+#ifdef CONFIG_GRKERNSEC_TPE
75022+ grsec_enable_tpe = 1;
75023+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
75024+#ifdef CONFIG_GRKERNSEC_TPE_ALL
75025+ grsec_enable_tpe_all = 1;
75026+#endif
75027+#endif
75028+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75029+ grsec_enable_socket_all = 1;
75030+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
75031+#endif
75032+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75033+ grsec_enable_socket_client = 1;
75034+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
75035+#endif
75036+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75037+ grsec_enable_socket_server = 1;
75038+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
75039+#endif
75040+#endif
75041+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
75042+ grsec_deny_new_usb = 1;
75043+#endif
75044+
75045+ return;
75046+}
75047diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
75048new file mode 100644
75049index 0000000..1773300
75050--- /dev/null
75051+++ b/grsecurity/grsec_ipc.c
75052@@ -0,0 +1,48 @@
75053+#include <linux/kernel.h>
75054+#include <linux/mm.h>
75055+#include <linux/sched.h>
75056+#include <linux/file.h>
75057+#include <linux/ipc.h>
75058+#include <linux/ipc_namespace.h>
75059+#include <linux/grsecurity.h>
75060+#include <linux/grinternal.h>
75061+
75062+int
75063+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
75064+{
75065+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75066+ int write;
75067+ int orig_granted_mode;
75068+ kuid_t euid;
75069+ kgid_t egid;
75070+
75071+ if (!grsec_enable_harden_ipc)
75072+ return 1;
75073+
75074+ euid = current_euid();
75075+ egid = current_egid();
75076+
75077+ write = requested_mode & 00002;
75078+ orig_granted_mode = ipcp->mode;
75079+
75080+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
75081+ orig_granted_mode >>= 6;
75082+ else {
75083+ /* if likely wrong permissions, lock to user */
75084+ if (orig_granted_mode & 0007)
75085+ orig_granted_mode = 0;
75086+ /* otherwise do a egid-only check */
75087+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
75088+ orig_granted_mode >>= 3;
75089+ /* otherwise, no access */
75090+ else
75091+ orig_granted_mode = 0;
75092+ }
75093+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
75094+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
75095+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
75096+ return 0;
75097+ }
75098+#endif
75099+ return 1;
75100+}
75101diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
75102new file mode 100644
75103index 0000000..5e05e20
75104--- /dev/null
75105+++ b/grsecurity/grsec_link.c
75106@@ -0,0 +1,58 @@
75107+#include <linux/kernel.h>
75108+#include <linux/sched.h>
75109+#include <linux/fs.h>
75110+#include <linux/file.h>
75111+#include <linux/grinternal.h>
75112+
75113+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
75114+{
75115+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75116+ const struct inode *link_inode = link->dentry->d_inode;
75117+
75118+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
75119+ /* ignore root-owned links, e.g. /proc/self */
75120+ gr_is_global_nonroot(link_inode->i_uid) && target &&
75121+ !uid_eq(link_inode->i_uid, target->i_uid)) {
75122+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
75123+ return 1;
75124+ }
75125+#endif
75126+ return 0;
75127+}
75128+
75129+int
75130+gr_handle_follow_link(const struct inode *parent,
75131+ const struct inode *inode,
75132+ const struct dentry *dentry, const struct vfsmount *mnt)
75133+{
75134+#ifdef CONFIG_GRKERNSEC_LINK
75135+ const struct cred *cred = current_cred();
75136+
75137+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
75138+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
75139+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
75140+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
75141+ return -EACCES;
75142+ }
75143+#endif
75144+ return 0;
75145+}
75146+
75147+int
75148+gr_handle_hardlink(const struct dentry *dentry,
75149+ const struct vfsmount *mnt,
75150+ struct inode *inode, const int mode, const struct filename *to)
75151+{
75152+#ifdef CONFIG_GRKERNSEC_LINK
75153+ const struct cred *cred = current_cred();
75154+
75155+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
75156+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
75157+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
75158+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
75159+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
75160+ return -EPERM;
75161+ }
75162+#endif
75163+ return 0;
75164+}
75165diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
75166new file mode 100644
75167index 0000000..dbe0a6b
75168--- /dev/null
75169+++ b/grsecurity/grsec_log.c
75170@@ -0,0 +1,341 @@
75171+#include <linux/kernel.h>
75172+#include <linux/sched.h>
75173+#include <linux/file.h>
75174+#include <linux/tty.h>
75175+#include <linux/fs.h>
75176+#include <linux/mm.h>
75177+#include <linux/grinternal.h>
75178+
75179+#ifdef CONFIG_TREE_PREEMPT_RCU
75180+#define DISABLE_PREEMPT() preempt_disable()
75181+#define ENABLE_PREEMPT() preempt_enable()
75182+#else
75183+#define DISABLE_PREEMPT()
75184+#define ENABLE_PREEMPT()
75185+#endif
75186+
75187+#define BEGIN_LOCKS(x) \
75188+ DISABLE_PREEMPT(); \
75189+ rcu_read_lock(); \
75190+ read_lock(&tasklist_lock); \
75191+ read_lock(&grsec_exec_file_lock); \
75192+ if (x != GR_DO_AUDIT) \
75193+ spin_lock(&grsec_alert_lock); \
75194+ else \
75195+ spin_lock(&grsec_audit_lock)
75196+
75197+#define END_LOCKS(x) \
75198+ if (x != GR_DO_AUDIT) \
75199+ spin_unlock(&grsec_alert_lock); \
75200+ else \
75201+ spin_unlock(&grsec_audit_lock); \
75202+ read_unlock(&grsec_exec_file_lock); \
75203+ read_unlock(&tasklist_lock); \
75204+ rcu_read_unlock(); \
75205+ ENABLE_PREEMPT(); \
75206+ if (x == GR_DONT_AUDIT) \
75207+ gr_handle_alertkill(current)
75208+
75209+enum {
75210+ FLOODING,
75211+ NO_FLOODING
75212+};
75213+
75214+extern char *gr_alert_log_fmt;
75215+extern char *gr_audit_log_fmt;
75216+extern char *gr_alert_log_buf;
75217+extern char *gr_audit_log_buf;
75218+
75219+static int gr_log_start(int audit)
75220+{
75221+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
75222+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
75223+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75224+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
75225+ unsigned long curr_secs = get_seconds();
75226+
75227+ if (audit == GR_DO_AUDIT)
75228+ goto set_fmt;
75229+
75230+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
75231+ grsec_alert_wtime = curr_secs;
75232+ grsec_alert_fyet = 0;
75233+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
75234+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
75235+ grsec_alert_fyet++;
75236+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
75237+ grsec_alert_wtime = curr_secs;
75238+ grsec_alert_fyet++;
75239+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
75240+ return FLOODING;
75241+ }
75242+ else return FLOODING;
75243+
75244+set_fmt:
75245+#endif
75246+ memset(buf, 0, PAGE_SIZE);
75247+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
75248+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
75249+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75250+ } else if (current->signal->curr_ip) {
75251+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
75252+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
75253+ } else if (gr_acl_is_enabled()) {
75254+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
75255+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75256+ } else {
75257+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
75258+ strcpy(buf, fmt);
75259+ }
75260+
75261+ return NO_FLOODING;
75262+}
75263+
75264+static void gr_log_middle(int audit, const char *msg, va_list ap)
75265+ __attribute__ ((format (printf, 2, 0)));
75266+
75267+static void gr_log_middle(int audit, const char *msg, va_list ap)
75268+{
75269+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75270+ unsigned int len = strlen(buf);
75271+
75272+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75273+
75274+ return;
75275+}
75276+
75277+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75278+ __attribute__ ((format (printf, 2, 3)));
75279+
75280+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75281+{
75282+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75283+ unsigned int len = strlen(buf);
75284+ va_list ap;
75285+
75286+ va_start(ap, msg);
75287+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75288+ va_end(ap);
75289+
75290+ return;
75291+}
75292+
75293+static void gr_log_end(int audit, int append_default)
75294+{
75295+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75296+ if (append_default) {
75297+ struct task_struct *task = current;
75298+ struct task_struct *parent = task->real_parent;
75299+ const struct cred *cred = __task_cred(task);
75300+ const struct cred *pcred = __task_cred(parent);
75301+ unsigned int len = strlen(buf);
75302+
75303+ 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));
75304+ }
75305+
75306+ printk("%s\n", buf);
75307+
75308+ return;
75309+}
75310+
75311+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
75312+{
75313+ int logtype;
75314+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
75315+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
75316+ void *voidptr = NULL;
75317+ int num1 = 0, num2 = 0;
75318+ unsigned long ulong1 = 0, ulong2 = 0;
75319+ struct dentry *dentry = NULL;
75320+ struct vfsmount *mnt = NULL;
75321+ struct file *file = NULL;
75322+ struct task_struct *task = NULL;
75323+ struct vm_area_struct *vma = NULL;
75324+ const struct cred *cred, *pcred;
75325+ va_list ap;
75326+
75327+ BEGIN_LOCKS(audit);
75328+ logtype = gr_log_start(audit);
75329+ if (logtype == FLOODING) {
75330+ END_LOCKS(audit);
75331+ return;
75332+ }
75333+ va_start(ap, argtypes);
75334+ switch (argtypes) {
75335+ case GR_TTYSNIFF:
75336+ task = va_arg(ap, struct task_struct *);
75337+ 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));
75338+ break;
75339+ case GR_SYSCTL_HIDDEN:
75340+ str1 = va_arg(ap, char *);
75341+ gr_log_middle_varargs(audit, msg, result, str1);
75342+ break;
75343+ case GR_RBAC:
75344+ dentry = va_arg(ap, struct dentry *);
75345+ mnt = va_arg(ap, struct vfsmount *);
75346+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75347+ break;
75348+ case GR_RBAC_STR:
75349+ dentry = va_arg(ap, struct dentry *);
75350+ mnt = va_arg(ap, struct vfsmount *);
75351+ str1 = va_arg(ap, char *);
75352+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75353+ break;
75354+ case GR_STR_RBAC:
75355+ str1 = va_arg(ap, char *);
75356+ dentry = va_arg(ap, struct dentry *);
75357+ mnt = va_arg(ap, struct vfsmount *);
75358+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75359+ break;
75360+ case GR_RBAC_MODE2:
75361+ dentry = va_arg(ap, struct dentry *);
75362+ mnt = va_arg(ap, struct vfsmount *);
75363+ str1 = va_arg(ap, char *);
75364+ str2 = va_arg(ap, char *);
75365+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75366+ break;
75367+ case GR_RBAC_MODE3:
75368+ dentry = va_arg(ap, struct dentry *);
75369+ mnt = va_arg(ap, struct vfsmount *);
75370+ str1 = va_arg(ap, char *);
75371+ str2 = va_arg(ap, char *);
75372+ str3 = va_arg(ap, char *);
75373+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75374+ break;
75375+ case GR_FILENAME:
75376+ dentry = va_arg(ap, struct dentry *);
75377+ mnt = va_arg(ap, struct vfsmount *);
75378+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75379+ break;
75380+ case GR_STR_FILENAME:
75381+ str1 = va_arg(ap, char *);
75382+ dentry = va_arg(ap, struct dentry *);
75383+ mnt = va_arg(ap, struct vfsmount *);
75384+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75385+ break;
75386+ case GR_FILENAME_STR:
75387+ dentry = va_arg(ap, struct dentry *);
75388+ mnt = va_arg(ap, struct vfsmount *);
75389+ str1 = va_arg(ap, char *);
75390+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75391+ break;
75392+ case GR_FILENAME_TWO_INT:
75393+ dentry = va_arg(ap, struct dentry *);
75394+ mnt = va_arg(ap, struct vfsmount *);
75395+ num1 = va_arg(ap, int);
75396+ num2 = va_arg(ap, int);
75397+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75398+ break;
75399+ case GR_FILENAME_TWO_INT_STR:
75400+ dentry = va_arg(ap, struct dentry *);
75401+ mnt = va_arg(ap, struct vfsmount *);
75402+ num1 = va_arg(ap, int);
75403+ num2 = va_arg(ap, int);
75404+ str1 = va_arg(ap, char *);
75405+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75406+ break;
75407+ case GR_TEXTREL:
75408+ file = va_arg(ap, struct file *);
75409+ ulong1 = va_arg(ap, unsigned long);
75410+ ulong2 = va_arg(ap, unsigned long);
75411+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75412+ break;
75413+ case GR_PTRACE:
75414+ task = va_arg(ap, struct task_struct *);
75415+ 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));
75416+ break;
75417+ case GR_RESOURCE:
75418+ task = va_arg(ap, struct task_struct *);
75419+ cred = __task_cred(task);
75420+ pcred = __task_cred(task->real_parent);
75421+ ulong1 = va_arg(ap, unsigned long);
75422+ str1 = va_arg(ap, char *);
75423+ ulong2 = va_arg(ap, unsigned long);
75424+ 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));
75425+ break;
75426+ case GR_CAP:
75427+ task = va_arg(ap, struct task_struct *);
75428+ cred = __task_cred(task);
75429+ pcred = __task_cred(task->real_parent);
75430+ str1 = va_arg(ap, char *);
75431+ 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));
75432+ break;
75433+ case GR_SIG:
75434+ str1 = va_arg(ap, char *);
75435+ voidptr = va_arg(ap, void *);
75436+ gr_log_middle_varargs(audit, msg, str1, voidptr);
75437+ break;
75438+ case GR_SIG2:
75439+ task = va_arg(ap, struct task_struct *);
75440+ cred = __task_cred(task);
75441+ pcred = __task_cred(task->real_parent);
75442+ num1 = va_arg(ap, int);
75443+ 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));
75444+ break;
75445+ case GR_CRASH1:
75446+ task = va_arg(ap, struct task_struct *);
75447+ cred = __task_cred(task);
75448+ pcred = __task_cred(task->real_parent);
75449+ ulong1 = va_arg(ap, unsigned long);
75450+ 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);
75451+ break;
75452+ case GR_CRASH2:
75453+ task = va_arg(ap, struct task_struct *);
75454+ cred = __task_cred(task);
75455+ pcred = __task_cred(task->real_parent);
75456+ ulong1 = va_arg(ap, unsigned long);
75457+ 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);
75458+ break;
75459+ case GR_RWXMAP:
75460+ file = va_arg(ap, struct file *);
75461+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75462+ break;
75463+ case GR_RWXMAPVMA:
75464+ vma = va_arg(ap, struct vm_area_struct *);
75465+ if (vma->vm_file)
75466+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75467+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75468+ str1 = "<stack>";
75469+ else if (vma->vm_start <= current->mm->brk &&
75470+ vma->vm_end >= current->mm->start_brk)
75471+ str1 = "<heap>";
75472+ else
75473+ str1 = "<anonymous mapping>";
75474+ gr_log_middle_varargs(audit, msg, str1);
75475+ break;
75476+ case GR_PSACCT:
75477+ {
75478+ unsigned int wday, cday;
75479+ __u8 whr, chr;
75480+ __u8 wmin, cmin;
75481+ __u8 wsec, csec;
75482+ char cur_tty[64] = { 0 };
75483+ char parent_tty[64] = { 0 };
75484+
75485+ task = va_arg(ap, struct task_struct *);
75486+ wday = va_arg(ap, unsigned int);
75487+ cday = va_arg(ap, unsigned int);
75488+ whr = va_arg(ap, int);
75489+ chr = va_arg(ap, int);
75490+ wmin = va_arg(ap, int);
75491+ cmin = va_arg(ap, int);
75492+ wsec = va_arg(ap, int);
75493+ csec = va_arg(ap, int);
75494+ ulong1 = va_arg(ap, unsigned long);
75495+ cred = __task_cred(task);
75496+ pcred = __task_cred(task->real_parent);
75497+
75498+ 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));
75499+ }
75500+ break;
75501+ default:
75502+ gr_log_middle(audit, msg, ap);
75503+ }
75504+ va_end(ap);
75505+ // these don't need DEFAULTSECARGS printed on the end
75506+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75507+ gr_log_end(audit, 0);
75508+ else
75509+ gr_log_end(audit, 1);
75510+ END_LOCKS(audit);
75511+}
75512diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75513new file mode 100644
75514index 0000000..0e39d8c
75515--- /dev/null
75516+++ b/grsecurity/grsec_mem.c
75517@@ -0,0 +1,48 @@
75518+#include <linux/kernel.h>
75519+#include <linux/sched.h>
75520+#include <linux/mm.h>
75521+#include <linux/mman.h>
75522+#include <linux/module.h>
75523+#include <linux/grinternal.h>
75524+
75525+void gr_handle_msr_write(void)
75526+{
75527+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75528+ return;
75529+}
75530+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75531+
75532+void
75533+gr_handle_ioperm(void)
75534+{
75535+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75536+ return;
75537+}
75538+
75539+void
75540+gr_handle_iopl(void)
75541+{
75542+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75543+ return;
75544+}
75545+
75546+void
75547+gr_handle_mem_readwrite(u64 from, u64 to)
75548+{
75549+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75550+ return;
75551+}
75552+
75553+void
75554+gr_handle_vm86(void)
75555+{
75556+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75557+ return;
75558+}
75559+
75560+void
75561+gr_log_badprocpid(const char *entry)
75562+{
75563+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75564+ return;
75565+}
75566diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75567new file mode 100644
75568index 0000000..cd9e124
75569--- /dev/null
75570+++ b/grsecurity/grsec_mount.c
75571@@ -0,0 +1,65 @@
75572+#include <linux/kernel.h>
75573+#include <linux/sched.h>
75574+#include <linux/mount.h>
75575+#include <linux/major.h>
75576+#include <linux/grsecurity.h>
75577+#include <linux/grinternal.h>
75578+
75579+void
75580+gr_log_remount(const char *devname, const int retval)
75581+{
75582+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75583+ if (grsec_enable_mount && (retval >= 0))
75584+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75585+#endif
75586+ return;
75587+}
75588+
75589+void
75590+gr_log_unmount(const char *devname, const int retval)
75591+{
75592+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75593+ if (grsec_enable_mount && (retval >= 0))
75594+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75595+#endif
75596+ return;
75597+}
75598+
75599+void
75600+gr_log_mount(const char *from, const char *to, const int retval)
75601+{
75602+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75603+ if (grsec_enable_mount && (retval >= 0))
75604+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75605+#endif
75606+ return;
75607+}
75608+
75609+int
75610+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75611+{
75612+#ifdef CONFIG_GRKERNSEC_ROFS
75613+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75614+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75615+ return -EPERM;
75616+ } else
75617+ return 0;
75618+#endif
75619+ return 0;
75620+}
75621+
75622+int
75623+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75624+{
75625+#ifdef CONFIG_GRKERNSEC_ROFS
75626+ struct inode *inode = dentry->d_inode;
75627+
75628+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75629+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75630+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75631+ return -EPERM;
75632+ } else
75633+ return 0;
75634+#endif
75635+ return 0;
75636+}
75637diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75638new file mode 100644
75639index 0000000..6ee9d50
75640--- /dev/null
75641+++ b/grsecurity/grsec_pax.c
75642@@ -0,0 +1,45 @@
75643+#include <linux/kernel.h>
75644+#include <linux/sched.h>
75645+#include <linux/mm.h>
75646+#include <linux/file.h>
75647+#include <linux/grinternal.h>
75648+#include <linux/grsecurity.h>
75649+
75650+void
75651+gr_log_textrel(struct vm_area_struct * vma)
75652+{
75653+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75654+ if (grsec_enable_log_rwxmaps)
75655+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75656+#endif
75657+ return;
75658+}
75659+
75660+void gr_log_ptgnustack(struct file *file)
75661+{
75662+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75663+ if (grsec_enable_log_rwxmaps)
75664+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75665+#endif
75666+ return;
75667+}
75668+
75669+void
75670+gr_log_rwxmmap(struct file *file)
75671+{
75672+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75673+ if (grsec_enable_log_rwxmaps)
75674+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75675+#endif
75676+ return;
75677+}
75678+
75679+void
75680+gr_log_rwxmprotect(struct vm_area_struct *vma)
75681+{
75682+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75683+ if (grsec_enable_log_rwxmaps)
75684+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75685+#endif
75686+ return;
75687+}
75688diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75689new file mode 100644
75690index 0000000..2005a3a
75691--- /dev/null
75692+++ b/grsecurity/grsec_proc.c
75693@@ -0,0 +1,20 @@
75694+#include <linux/kernel.h>
75695+#include <linux/sched.h>
75696+#include <linux/grsecurity.h>
75697+#include <linux/grinternal.h>
75698+
75699+int gr_proc_is_restricted(void)
75700+{
75701+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75702+ const struct cred *cred = current_cred();
75703+#endif
75704+
75705+#ifdef CONFIG_GRKERNSEC_PROC_USER
75706+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75707+ return -EACCES;
75708+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75709+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75710+ return -EACCES;
75711+#endif
75712+ return 0;
75713+}
75714diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75715new file mode 100644
75716index 0000000..f7f29aa
75717--- /dev/null
75718+++ b/grsecurity/grsec_ptrace.c
75719@@ -0,0 +1,30 @@
75720+#include <linux/kernel.h>
75721+#include <linux/sched.h>
75722+#include <linux/grinternal.h>
75723+#include <linux/security.h>
75724+
75725+void
75726+gr_audit_ptrace(struct task_struct *task)
75727+{
75728+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75729+ if (grsec_enable_audit_ptrace)
75730+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75731+#endif
75732+ return;
75733+}
75734+
75735+int
75736+gr_ptrace_readexec(struct file *file, int unsafe_flags)
75737+{
75738+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75739+ const struct dentry *dentry = file->f_path.dentry;
75740+ const struct vfsmount *mnt = file->f_path.mnt;
75741+
75742+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75743+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75744+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75745+ return -EACCES;
75746+ }
75747+#endif
75748+ return 0;
75749+}
75750diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75751new file mode 100644
75752index 0000000..3860c7e
75753--- /dev/null
75754+++ b/grsecurity/grsec_sig.c
75755@@ -0,0 +1,236 @@
75756+#include <linux/kernel.h>
75757+#include <linux/sched.h>
75758+#include <linux/fs.h>
75759+#include <linux/delay.h>
75760+#include <linux/grsecurity.h>
75761+#include <linux/grinternal.h>
75762+#include <linux/hardirq.h>
75763+
75764+char *signames[] = {
75765+ [SIGSEGV] = "Segmentation fault",
75766+ [SIGILL] = "Illegal instruction",
75767+ [SIGABRT] = "Abort",
75768+ [SIGBUS] = "Invalid alignment/Bus error"
75769+};
75770+
75771+void
75772+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75773+{
75774+#ifdef CONFIG_GRKERNSEC_SIGNAL
75775+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75776+ (sig == SIGABRT) || (sig == SIGBUS))) {
75777+ if (task_pid_nr(t) == task_pid_nr(current)) {
75778+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75779+ } else {
75780+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75781+ }
75782+ }
75783+#endif
75784+ return;
75785+}
75786+
75787+int
75788+gr_handle_signal(const struct task_struct *p, const int sig)
75789+{
75790+#ifdef CONFIG_GRKERNSEC
75791+ /* ignore the 0 signal for protected task checks */
75792+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75793+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75794+ return -EPERM;
75795+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75796+ return -EPERM;
75797+ }
75798+#endif
75799+ return 0;
75800+}
75801+
75802+#ifdef CONFIG_GRKERNSEC
75803+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75804+
75805+int gr_fake_force_sig(int sig, struct task_struct *t)
75806+{
75807+ unsigned long int flags;
75808+ int ret, blocked, ignored;
75809+ struct k_sigaction *action;
75810+
75811+ spin_lock_irqsave(&t->sighand->siglock, flags);
75812+ action = &t->sighand->action[sig-1];
75813+ ignored = action->sa.sa_handler == SIG_IGN;
75814+ blocked = sigismember(&t->blocked, sig);
75815+ if (blocked || ignored) {
75816+ action->sa.sa_handler = SIG_DFL;
75817+ if (blocked) {
75818+ sigdelset(&t->blocked, sig);
75819+ recalc_sigpending_and_wake(t);
75820+ }
75821+ }
75822+ if (action->sa.sa_handler == SIG_DFL)
75823+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
75824+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75825+
75826+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
75827+
75828+ return ret;
75829+}
75830+#endif
75831+
75832+#define GR_USER_BAN_TIME (15 * 60)
75833+#define GR_DAEMON_BRUTE_TIME (30 * 60)
75834+
75835+void gr_handle_brute_attach(int dumpable)
75836+{
75837+#ifdef CONFIG_GRKERNSEC_BRUTE
75838+ struct task_struct *p = current;
75839+ kuid_t uid = GLOBAL_ROOT_UID;
75840+ int daemon = 0;
75841+
75842+ if (!grsec_enable_brute)
75843+ return;
75844+
75845+ rcu_read_lock();
75846+ read_lock(&tasklist_lock);
75847+ read_lock(&grsec_exec_file_lock);
75848+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75849+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75850+ p->real_parent->brute = 1;
75851+ daemon = 1;
75852+ } else {
75853+ const struct cred *cred = __task_cred(p), *cred2;
75854+ struct task_struct *tsk, *tsk2;
75855+
75856+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75857+ struct user_struct *user;
75858+
75859+ uid = cred->uid;
75860+
75861+ /* this is put upon execution past expiration */
75862+ user = find_user(uid);
75863+ if (user == NULL)
75864+ goto unlock;
75865+ user->suid_banned = 1;
75866+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75867+ if (user->suid_ban_expires == ~0UL)
75868+ user->suid_ban_expires--;
75869+
75870+ /* only kill other threads of the same binary, from the same user */
75871+ do_each_thread(tsk2, tsk) {
75872+ cred2 = __task_cred(tsk);
75873+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75874+ gr_fake_force_sig(SIGKILL, tsk);
75875+ } while_each_thread(tsk2, tsk);
75876+ }
75877+ }
75878+unlock:
75879+ read_unlock(&grsec_exec_file_lock);
75880+ read_unlock(&tasklist_lock);
75881+ rcu_read_unlock();
75882+
75883+ if (gr_is_global_nonroot(uid))
75884+ 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);
75885+ else if (daemon)
75886+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75887+
75888+#endif
75889+ return;
75890+}
75891+
75892+void gr_handle_brute_check(void)
75893+{
75894+#ifdef CONFIG_GRKERNSEC_BRUTE
75895+ struct task_struct *p = current;
75896+
75897+ if (unlikely(p->brute)) {
75898+ if (!grsec_enable_brute)
75899+ p->brute = 0;
75900+ else if (time_before(get_seconds(), p->brute_expires))
75901+ msleep(30 * 1000);
75902+ }
75903+#endif
75904+ return;
75905+}
75906+
75907+void gr_handle_kernel_exploit(void)
75908+{
75909+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75910+ const struct cred *cred;
75911+ struct task_struct *tsk, *tsk2;
75912+ struct user_struct *user;
75913+ kuid_t uid;
75914+
75915+ if (in_irq() || in_serving_softirq() || in_nmi())
75916+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75917+
75918+ uid = current_uid();
75919+
75920+ if (gr_is_global_root(uid))
75921+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75922+ else {
75923+ /* kill all the processes of this user, hold a reference
75924+ to their creds struct, and prevent them from creating
75925+ another process until system reset
75926+ */
75927+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75928+ GR_GLOBAL_UID(uid));
75929+ /* we intentionally leak this ref */
75930+ user = get_uid(current->cred->user);
75931+ if (user)
75932+ user->kernel_banned = 1;
75933+
75934+ /* kill all processes of this user */
75935+ read_lock(&tasklist_lock);
75936+ do_each_thread(tsk2, tsk) {
75937+ cred = __task_cred(tsk);
75938+ if (uid_eq(cred->uid, uid))
75939+ gr_fake_force_sig(SIGKILL, tsk);
75940+ } while_each_thread(tsk2, tsk);
75941+ read_unlock(&tasklist_lock);
75942+ }
75943+#endif
75944+}
75945+
75946+#ifdef CONFIG_GRKERNSEC_BRUTE
75947+static bool suid_ban_expired(struct user_struct *user)
75948+{
75949+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75950+ user->suid_banned = 0;
75951+ user->suid_ban_expires = 0;
75952+ free_uid(user);
75953+ return true;
75954+ }
75955+
75956+ return false;
75957+}
75958+#endif
75959+
75960+int gr_process_kernel_exec_ban(void)
75961+{
75962+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75963+ if (unlikely(current->cred->user->kernel_banned))
75964+ return -EPERM;
75965+#endif
75966+ return 0;
75967+}
75968+
75969+int gr_process_kernel_setuid_ban(struct user_struct *user)
75970+{
75971+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75972+ if (unlikely(user->kernel_banned))
75973+ gr_fake_force_sig(SIGKILL, current);
75974+#endif
75975+ return 0;
75976+}
75977+
75978+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75979+{
75980+#ifdef CONFIG_GRKERNSEC_BRUTE
75981+ struct user_struct *user = current->cred->user;
75982+ if (unlikely(user->suid_banned)) {
75983+ if (suid_ban_expired(user))
75984+ return 0;
75985+ /* disallow execution of suid binaries only */
75986+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75987+ return -EPERM;
75988+ }
75989+#endif
75990+ return 0;
75991+}
75992diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75993new file mode 100644
75994index 0000000..c0aef3a
75995--- /dev/null
75996+++ b/grsecurity/grsec_sock.c
75997@@ -0,0 +1,244 @@
75998+#include <linux/kernel.h>
75999+#include <linux/module.h>
76000+#include <linux/sched.h>
76001+#include <linux/file.h>
76002+#include <linux/net.h>
76003+#include <linux/in.h>
76004+#include <linux/ip.h>
76005+#include <net/sock.h>
76006+#include <net/inet_sock.h>
76007+#include <linux/grsecurity.h>
76008+#include <linux/grinternal.h>
76009+#include <linux/gracl.h>
76010+
76011+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
76012+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
76013+
76014+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
76015+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
76016+
76017+#ifdef CONFIG_UNIX_MODULE
76018+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
76019+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
76020+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
76021+EXPORT_SYMBOL_GPL(gr_handle_create);
76022+#endif
76023+
76024+#ifdef CONFIG_GRKERNSEC
76025+#define gr_conn_table_size 32749
76026+struct conn_table_entry {
76027+ struct conn_table_entry *next;
76028+ struct signal_struct *sig;
76029+};
76030+
76031+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
76032+DEFINE_SPINLOCK(gr_conn_table_lock);
76033+
76034+extern const char * gr_socktype_to_name(unsigned char type);
76035+extern const char * gr_proto_to_name(unsigned char proto);
76036+extern const char * gr_sockfamily_to_name(unsigned char family);
76037+
76038+static __inline__ int
76039+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
76040+{
76041+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
76042+}
76043+
76044+static __inline__ int
76045+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
76046+ __u16 sport, __u16 dport)
76047+{
76048+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
76049+ sig->gr_sport == sport && sig->gr_dport == dport))
76050+ return 1;
76051+ else
76052+ return 0;
76053+}
76054+
76055+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
76056+{
76057+ struct conn_table_entry **match;
76058+ unsigned int index;
76059+
76060+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76061+ sig->gr_sport, sig->gr_dport,
76062+ gr_conn_table_size);
76063+
76064+ newent->sig = sig;
76065+
76066+ match = &gr_conn_table[index];
76067+ newent->next = *match;
76068+ *match = newent;
76069+
76070+ return;
76071+}
76072+
76073+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
76074+{
76075+ struct conn_table_entry *match, *last = NULL;
76076+ unsigned int index;
76077+
76078+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76079+ sig->gr_sport, sig->gr_dport,
76080+ gr_conn_table_size);
76081+
76082+ match = gr_conn_table[index];
76083+ while (match && !conn_match(match->sig,
76084+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
76085+ sig->gr_dport)) {
76086+ last = match;
76087+ match = match->next;
76088+ }
76089+
76090+ if (match) {
76091+ if (last)
76092+ last->next = match->next;
76093+ else
76094+ gr_conn_table[index] = NULL;
76095+ kfree(match);
76096+ }
76097+
76098+ return;
76099+}
76100+
76101+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
76102+ __u16 sport, __u16 dport)
76103+{
76104+ struct conn_table_entry *match;
76105+ unsigned int index;
76106+
76107+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
76108+
76109+ match = gr_conn_table[index];
76110+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
76111+ match = match->next;
76112+
76113+ if (match)
76114+ return match->sig;
76115+ else
76116+ return NULL;
76117+}
76118+
76119+#endif
76120+
76121+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
76122+{
76123+#ifdef CONFIG_GRKERNSEC
76124+ struct signal_struct *sig = task->signal;
76125+ struct conn_table_entry *newent;
76126+
76127+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
76128+ if (newent == NULL)
76129+ return;
76130+ /* no bh lock needed since we are called with bh disabled */
76131+ spin_lock(&gr_conn_table_lock);
76132+ gr_del_task_from_ip_table_nolock(sig);
76133+ sig->gr_saddr = inet->inet_rcv_saddr;
76134+ sig->gr_daddr = inet->inet_daddr;
76135+ sig->gr_sport = inet->inet_sport;
76136+ sig->gr_dport = inet->inet_dport;
76137+ gr_add_to_task_ip_table_nolock(sig, newent);
76138+ spin_unlock(&gr_conn_table_lock);
76139+#endif
76140+ return;
76141+}
76142+
76143+void gr_del_task_from_ip_table(struct task_struct *task)
76144+{
76145+#ifdef CONFIG_GRKERNSEC
76146+ spin_lock_bh(&gr_conn_table_lock);
76147+ gr_del_task_from_ip_table_nolock(task->signal);
76148+ spin_unlock_bh(&gr_conn_table_lock);
76149+#endif
76150+ return;
76151+}
76152+
76153+void
76154+gr_attach_curr_ip(const struct sock *sk)
76155+{
76156+#ifdef CONFIG_GRKERNSEC
76157+ struct signal_struct *p, *set;
76158+ const struct inet_sock *inet = inet_sk(sk);
76159+
76160+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
76161+ return;
76162+
76163+ set = current->signal;
76164+
76165+ spin_lock_bh(&gr_conn_table_lock);
76166+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
76167+ inet->inet_dport, inet->inet_sport);
76168+ if (unlikely(p != NULL)) {
76169+ set->curr_ip = p->curr_ip;
76170+ set->used_accept = 1;
76171+ gr_del_task_from_ip_table_nolock(p);
76172+ spin_unlock_bh(&gr_conn_table_lock);
76173+ return;
76174+ }
76175+ spin_unlock_bh(&gr_conn_table_lock);
76176+
76177+ set->curr_ip = inet->inet_daddr;
76178+ set->used_accept = 1;
76179+#endif
76180+ return;
76181+}
76182+
76183+int
76184+gr_handle_sock_all(const int family, const int type, const int protocol)
76185+{
76186+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76187+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
76188+ (family != AF_UNIX)) {
76189+ if (family == AF_INET)
76190+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
76191+ else
76192+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
76193+ return -EACCES;
76194+ }
76195+#endif
76196+ return 0;
76197+}
76198+
76199+int
76200+gr_handle_sock_server(const struct sockaddr *sck)
76201+{
76202+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76203+ if (grsec_enable_socket_server &&
76204+ in_group_p(grsec_socket_server_gid) &&
76205+ sck && (sck->sa_family != AF_UNIX) &&
76206+ (sck->sa_family != AF_LOCAL)) {
76207+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76208+ return -EACCES;
76209+ }
76210+#endif
76211+ return 0;
76212+}
76213+
76214+int
76215+gr_handle_sock_server_other(const struct sock *sck)
76216+{
76217+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76218+ if (grsec_enable_socket_server &&
76219+ in_group_p(grsec_socket_server_gid) &&
76220+ sck && (sck->sk_family != AF_UNIX) &&
76221+ (sck->sk_family != AF_LOCAL)) {
76222+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76223+ return -EACCES;
76224+ }
76225+#endif
76226+ return 0;
76227+}
76228+
76229+int
76230+gr_handle_sock_client(const struct sockaddr *sck)
76231+{
76232+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76233+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
76234+ sck && (sck->sa_family != AF_UNIX) &&
76235+ (sck->sa_family != AF_LOCAL)) {
76236+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
76237+ return -EACCES;
76238+ }
76239+#endif
76240+ return 0;
76241+}
76242diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
76243new file mode 100644
76244index 0000000..8159888
76245--- /dev/null
76246+++ b/grsecurity/grsec_sysctl.c
76247@@ -0,0 +1,479 @@
76248+#include <linux/kernel.h>
76249+#include <linux/sched.h>
76250+#include <linux/sysctl.h>
76251+#include <linux/grsecurity.h>
76252+#include <linux/grinternal.h>
76253+
76254+int
76255+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
76256+{
76257+#ifdef CONFIG_GRKERNSEC_SYSCTL
76258+ if (dirname == NULL || name == NULL)
76259+ return 0;
76260+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
76261+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
76262+ return -EACCES;
76263+ }
76264+#endif
76265+ return 0;
76266+}
76267+
76268+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
76269+static int __maybe_unused __read_only one = 1;
76270+#endif
76271+
76272+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
76273+ defined(CONFIG_GRKERNSEC_DENYUSB)
76274+struct ctl_table grsecurity_table[] = {
76275+#ifdef CONFIG_GRKERNSEC_SYSCTL
76276+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
76277+#ifdef CONFIG_GRKERNSEC_IO
76278+ {
76279+ .procname = "disable_priv_io",
76280+ .data = &grsec_disable_privio,
76281+ .maxlen = sizeof(int),
76282+ .mode = 0600,
76283+ .proc_handler = &proc_dointvec,
76284+ },
76285+#endif
76286+#endif
76287+#ifdef CONFIG_GRKERNSEC_LINK
76288+ {
76289+ .procname = "linking_restrictions",
76290+ .data = &grsec_enable_link,
76291+ .maxlen = sizeof(int),
76292+ .mode = 0600,
76293+ .proc_handler = &proc_dointvec,
76294+ },
76295+#endif
76296+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76297+ {
76298+ .procname = "enforce_symlinksifowner",
76299+ .data = &grsec_enable_symlinkown,
76300+ .maxlen = sizeof(int),
76301+ .mode = 0600,
76302+ .proc_handler = &proc_dointvec,
76303+ },
76304+ {
76305+ .procname = "symlinkown_gid",
76306+ .data = &grsec_symlinkown_gid,
76307+ .maxlen = sizeof(int),
76308+ .mode = 0600,
76309+ .proc_handler = &proc_dointvec,
76310+ },
76311+#endif
76312+#ifdef CONFIG_GRKERNSEC_BRUTE
76313+ {
76314+ .procname = "deter_bruteforce",
76315+ .data = &grsec_enable_brute,
76316+ .maxlen = sizeof(int),
76317+ .mode = 0600,
76318+ .proc_handler = &proc_dointvec,
76319+ },
76320+#endif
76321+#ifdef CONFIG_GRKERNSEC_FIFO
76322+ {
76323+ .procname = "fifo_restrictions",
76324+ .data = &grsec_enable_fifo,
76325+ .maxlen = sizeof(int),
76326+ .mode = 0600,
76327+ .proc_handler = &proc_dointvec,
76328+ },
76329+#endif
76330+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76331+ {
76332+ .procname = "ptrace_readexec",
76333+ .data = &grsec_enable_ptrace_readexec,
76334+ .maxlen = sizeof(int),
76335+ .mode = 0600,
76336+ .proc_handler = &proc_dointvec,
76337+ },
76338+#endif
76339+#ifdef CONFIG_GRKERNSEC_SETXID
76340+ {
76341+ .procname = "consistent_setxid",
76342+ .data = &grsec_enable_setxid,
76343+ .maxlen = sizeof(int),
76344+ .mode = 0600,
76345+ .proc_handler = &proc_dointvec,
76346+ },
76347+#endif
76348+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76349+ {
76350+ .procname = "ip_blackhole",
76351+ .data = &grsec_enable_blackhole,
76352+ .maxlen = sizeof(int),
76353+ .mode = 0600,
76354+ .proc_handler = &proc_dointvec,
76355+ },
76356+ {
76357+ .procname = "lastack_retries",
76358+ .data = &grsec_lastack_retries,
76359+ .maxlen = sizeof(int),
76360+ .mode = 0600,
76361+ .proc_handler = &proc_dointvec,
76362+ },
76363+#endif
76364+#ifdef CONFIG_GRKERNSEC_EXECLOG
76365+ {
76366+ .procname = "exec_logging",
76367+ .data = &grsec_enable_execlog,
76368+ .maxlen = sizeof(int),
76369+ .mode = 0600,
76370+ .proc_handler = &proc_dointvec,
76371+ },
76372+#endif
76373+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76374+ {
76375+ .procname = "rwxmap_logging",
76376+ .data = &grsec_enable_log_rwxmaps,
76377+ .maxlen = sizeof(int),
76378+ .mode = 0600,
76379+ .proc_handler = &proc_dointvec,
76380+ },
76381+#endif
76382+#ifdef CONFIG_GRKERNSEC_SIGNAL
76383+ {
76384+ .procname = "signal_logging",
76385+ .data = &grsec_enable_signal,
76386+ .maxlen = sizeof(int),
76387+ .mode = 0600,
76388+ .proc_handler = &proc_dointvec,
76389+ },
76390+#endif
76391+#ifdef CONFIG_GRKERNSEC_FORKFAIL
76392+ {
76393+ .procname = "forkfail_logging",
76394+ .data = &grsec_enable_forkfail,
76395+ .maxlen = sizeof(int),
76396+ .mode = 0600,
76397+ .proc_handler = &proc_dointvec,
76398+ },
76399+#endif
76400+#ifdef CONFIG_GRKERNSEC_TIME
76401+ {
76402+ .procname = "timechange_logging",
76403+ .data = &grsec_enable_time,
76404+ .maxlen = sizeof(int),
76405+ .mode = 0600,
76406+ .proc_handler = &proc_dointvec,
76407+ },
76408+#endif
76409+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76410+ {
76411+ .procname = "chroot_deny_shmat",
76412+ .data = &grsec_enable_chroot_shmat,
76413+ .maxlen = sizeof(int),
76414+ .mode = 0600,
76415+ .proc_handler = &proc_dointvec,
76416+ },
76417+#endif
76418+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76419+ {
76420+ .procname = "chroot_deny_unix",
76421+ .data = &grsec_enable_chroot_unix,
76422+ .maxlen = sizeof(int),
76423+ .mode = 0600,
76424+ .proc_handler = &proc_dointvec,
76425+ },
76426+#endif
76427+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76428+ {
76429+ .procname = "chroot_deny_mount",
76430+ .data = &grsec_enable_chroot_mount,
76431+ .maxlen = sizeof(int),
76432+ .mode = 0600,
76433+ .proc_handler = &proc_dointvec,
76434+ },
76435+#endif
76436+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76437+ {
76438+ .procname = "chroot_deny_fchdir",
76439+ .data = &grsec_enable_chroot_fchdir,
76440+ .maxlen = sizeof(int),
76441+ .mode = 0600,
76442+ .proc_handler = &proc_dointvec,
76443+ },
76444+#endif
76445+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76446+ {
76447+ .procname = "chroot_deny_chroot",
76448+ .data = &grsec_enable_chroot_double,
76449+ .maxlen = sizeof(int),
76450+ .mode = 0600,
76451+ .proc_handler = &proc_dointvec,
76452+ },
76453+#endif
76454+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76455+ {
76456+ .procname = "chroot_deny_pivot",
76457+ .data = &grsec_enable_chroot_pivot,
76458+ .maxlen = sizeof(int),
76459+ .mode = 0600,
76460+ .proc_handler = &proc_dointvec,
76461+ },
76462+#endif
76463+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76464+ {
76465+ .procname = "chroot_enforce_chdir",
76466+ .data = &grsec_enable_chroot_chdir,
76467+ .maxlen = sizeof(int),
76468+ .mode = 0600,
76469+ .proc_handler = &proc_dointvec,
76470+ },
76471+#endif
76472+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76473+ {
76474+ .procname = "chroot_deny_chmod",
76475+ .data = &grsec_enable_chroot_chmod,
76476+ .maxlen = sizeof(int),
76477+ .mode = 0600,
76478+ .proc_handler = &proc_dointvec,
76479+ },
76480+#endif
76481+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76482+ {
76483+ .procname = "chroot_deny_mknod",
76484+ .data = &grsec_enable_chroot_mknod,
76485+ .maxlen = sizeof(int),
76486+ .mode = 0600,
76487+ .proc_handler = &proc_dointvec,
76488+ },
76489+#endif
76490+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76491+ {
76492+ .procname = "chroot_restrict_nice",
76493+ .data = &grsec_enable_chroot_nice,
76494+ .maxlen = sizeof(int),
76495+ .mode = 0600,
76496+ .proc_handler = &proc_dointvec,
76497+ },
76498+#endif
76499+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76500+ {
76501+ .procname = "chroot_execlog",
76502+ .data = &grsec_enable_chroot_execlog,
76503+ .maxlen = sizeof(int),
76504+ .mode = 0600,
76505+ .proc_handler = &proc_dointvec,
76506+ },
76507+#endif
76508+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76509+ {
76510+ .procname = "chroot_caps",
76511+ .data = &grsec_enable_chroot_caps,
76512+ .maxlen = sizeof(int),
76513+ .mode = 0600,
76514+ .proc_handler = &proc_dointvec,
76515+ },
76516+#endif
76517+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76518+ {
76519+ .procname = "chroot_deny_sysctl",
76520+ .data = &grsec_enable_chroot_sysctl,
76521+ .maxlen = sizeof(int),
76522+ .mode = 0600,
76523+ .proc_handler = &proc_dointvec,
76524+ },
76525+#endif
76526+#ifdef CONFIG_GRKERNSEC_TPE
76527+ {
76528+ .procname = "tpe",
76529+ .data = &grsec_enable_tpe,
76530+ .maxlen = sizeof(int),
76531+ .mode = 0600,
76532+ .proc_handler = &proc_dointvec,
76533+ },
76534+ {
76535+ .procname = "tpe_gid",
76536+ .data = &grsec_tpe_gid,
76537+ .maxlen = sizeof(int),
76538+ .mode = 0600,
76539+ .proc_handler = &proc_dointvec,
76540+ },
76541+#endif
76542+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76543+ {
76544+ .procname = "tpe_invert",
76545+ .data = &grsec_enable_tpe_invert,
76546+ .maxlen = sizeof(int),
76547+ .mode = 0600,
76548+ .proc_handler = &proc_dointvec,
76549+ },
76550+#endif
76551+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76552+ {
76553+ .procname = "tpe_restrict_all",
76554+ .data = &grsec_enable_tpe_all,
76555+ .maxlen = sizeof(int),
76556+ .mode = 0600,
76557+ .proc_handler = &proc_dointvec,
76558+ },
76559+#endif
76560+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76561+ {
76562+ .procname = "socket_all",
76563+ .data = &grsec_enable_socket_all,
76564+ .maxlen = sizeof(int),
76565+ .mode = 0600,
76566+ .proc_handler = &proc_dointvec,
76567+ },
76568+ {
76569+ .procname = "socket_all_gid",
76570+ .data = &grsec_socket_all_gid,
76571+ .maxlen = sizeof(int),
76572+ .mode = 0600,
76573+ .proc_handler = &proc_dointvec,
76574+ },
76575+#endif
76576+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76577+ {
76578+ .procname = "socket_client",
76579+ .data = &grsec_enable_socket_client,
76580+ .maxlen = sizeof(int),
76581+ .mode = 0600,
76582+ .proc_handler = &proc_dointvec,
76583+ },
76584+ {
76585+ .procname = "socket_client_gid",
76586+ .data = &grsec_socket_client_gid,
76587+ .maxlen = sizeof(int),
76588+ .mode = 0600,
76589+ .proc_handler = &proc_dointvec,
76590+ },
76591+#endif
76592+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76593+ {
76594+ .procname = "socket_server",
76595+ .data = &grsec_enable_socket_server,
76596+ .maxlen = sizeof(int),
76597+ .mode = 0600,
76598+ .proc_handler = &proc_dointvec,
76599+ },
76600+ {
76601+ .procname = "socket_server_gid",
76602+ .data = &grsec_socket_server_gid,
76603+ .maxlen = sizeof(int),
76604+ .mode = 0600,
76605+ .proc_handler = &proc_dointvec,
76606+ },
76607+#endif
76608+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76609+ {
76610+ .procname = "audit_group",
76611+ .data = &grsec_enable_group,
76612+ .maxlen = sizeof(int),
76613+ .mode = 0600,
76614+ .proc_handler = &proc_dointvec,
76615+ },
76616+ {
76617+ .procname = "audit_gid",
76618+ .data = &grsec_audit_gid,
76619+ .maxlen = sizeof(int),
76620+ .mode = 0600,
76621+ .proc_handler = &proc_dointvec,
76622+ },
76623+#endif
76624+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76625+ {
76626+ .procname = "audit_chdir",
76627+ .data = &grsec_enable_chdir,
76628+ .maxlen = sizeof(int),
76629+ .mode = 0600,
76630+ .proc_handler = &proc_dointvec,
76631+ },
76632+#endif
76633+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76634+ {
76635+ .procname = "audit_mount",
76636+ .data = &grsec_enable_mount,
76637+ .maxlen = sizeof(int),
76638+ .mode = 0600,
76639+ .proc_handler = &proc_dointvec,
76640+ },
76641+#endif
76642+#ifdef CONFIG_GRKERNSEC_DMESG
76643+ {
76644+ .procname = "dmesg",
76645+ .data = &grsec_enable_dmesg,
76646+ .maxlen = sizeof(int),
76647+ .mode = 0600,
76648+ .proc_handler = &proc_dointvec,
76649+ },
76650+#endif
76651+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76652+ {
76653+ .procname = "chroot_findtask",
76654+ .data = &grsec_enable_chroot_findtask,
76655+ .maxlen = sizeof(int),
76656+ .mode = 0600,
76657+ .proc_handler = &proc_dointvec,
76658+ },
76659+#endif
76660+#ifdef CONFIG_GRKERNSEC_RESLOG
76661+ {
76662+ .procname = "resource_logging",
76663+ .data = &grsec_resource_logging,
76664+ .maxlen = sizeof(int),
76665+ .mode = 0600,
76666+ .proc_handler = &proc_dointvec,
76667+ },
76668+#endif
76669+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76670+ {
76671+ .procname = "audit_ptrace",
76672+ .data = &grsec_enable_audit_ptrace,
76673+ .maxlen = sizeof(int),
76674+ .mode = 0600,
76675+ .proc_handler = &proc_dointvec,
76676+ },
76677+#endif
76678+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76679+ {
76680+ .procname = "harden_ptrace",
76681+ .data = &grsec_enable_harden_ptrace,
76682+ .maxlen = sizeof(int),
76683+ .mode = 0600,
76684+ .proc_handler = &proc_dointvec,
76685+ },
76686+#endif
76687+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76688+ {
76689+ .procname = "harden_ipc",
76690+ .data = &grsec_enable_harden_ipc,
76691+ .maxlen = sizeof(int),
76692+ .mode = 0600,
76693+ .proc_handler = &proc_dointvec,
76694+ },
76695+#endif
76696+ {
76697+ .procname = "grsec_lock",
76698+ .data = &grsec_lock,
76699+ .maxlen = sizeof(int),
76700+ .mode = 0600,
76701+ .proc_handler = &proc_dointvec,
76702+ },
76703+#endif
76704+#ifdef CONFIG_GRKERNSEC_ROFS
76705+ {
76706+ .procname = "romount_protect",
76707+ .data = &grsec_enable_rofs,
76708+ .maxlen = sizeof(int),
76709+ .mode = 0600,
76710+ .proc_handler = &proc_dointvec_minmax,
76711+ .extra1 = &one,
76712+ .extra2 = &one,
76713+ },
76714+#endif
76715+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76716+ {
76717+ .procname = "deny_new_usb",
76718+ .data = &grsec_deny_new_usb,
76719+ .maxlen = sizeof(int),
76720+ .mode = 0600,
76721+ .proc_handler = &proc_dointvec,
76722+ },
76723+#endif
76724+ { }
76725+};
76726+#endif
76727diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76728new file mode 100644
76729index 0000000..61b514e
76730--- /dev/null
76731+++ b/grsecurity/grsec_time.c
76732@@ -0,0 +1,16 @@
76733+#include <linux/kernel.h>
76734+#include <linux/sched.h>
76735+#include <linux/grinternal.h>
76736+#include <linux/module.h>
76737+
76738+void
76739+gr_log_timechange(void)
76740+{
76741+#ifdef CONFIG_GRKERNSEC_TIME
76742+ if (grsec_enable_time)
76743+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76744+#endif
76745+ return;
76746+}
76747+
76748+EXPORT_SYMBOL_GPL(gr_log_timechange);
76749diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76750new file mode 100644
76751index 0000000..ee57dcf
76752--- /dev/null
76753+++ b/grsecurity/grsec_tpe.c
76754@@ -0,0 +1,73 @@
76755+#include <linux/kernel.h>
76756+#include <linux/sched.h>
76757+#include <linux/file.h>
76758+#include <linux/fs.h>
76759+#include <linux/grinternal.h>
76760+
76761+extern int gr_acl_tpe_check(void);
76762+
76763+int
76764+gr_tpe_allow(const struct file *file)
76765+{
76766+#ifdef CONFIG_GRKERNSEC
76767+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76768+ const struct cred *cred = current_cred();
76769+ char *msg = NULL;
76770+ char *msg2 = NULL;
76771+
76772+ // never restrict root
76773+ if (gr_is_global_root(cred->uid))
76774+ return 1;
76775+
76776+ if (grsec_enable_tpe) {
76777+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76778+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76779+ msg = "not being in trusted group";
76780+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76781+ msg = "being in untrusted group";
76782+#else
76783+ if (in_group_p(grsec_tpe_gid))
76784+ msg = "being in untrusted group";
76785+#endif
76786+ }
76787+ if (!msg && gr_acl_tpe_check())
76788+ msg = "being in untrusted role";
76789+
76790+ // not in any affected group/role
76791+ if (!msg)
76792+ goto next_check;
76793+
76794+ if (gr_is_global_nonroot(inode->i_uid))
76795+ msg2 = "file in non-root-owned directory";
76796+ else if (inode->i_mode & S_IWOTH)
76797+ msg2 = "file in world-writable directory";
76798+ else if (inode->i_mode & S_IWGRP)
76799+ msg2 = "file in group-writable directory";
76800+
76801+ if (msg && msg2) {
76802+ char fullmsg[70] = {0};
76803+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76804+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76805+ return 0;
76806+ }
76807+ msg = NULL;
76808+next_check:
76809+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76810+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76811+ return 1;
76812+
76813+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76814+ msg = "directory not owned by user";
76815+ else if (inode->i_mode & S_IWOTH)
76816+ msg = "file in world-writable directory";
76817+ else if (inode->i_mode & S_IWGRP)
76818+ msg = "file in group-writable directory";
76819+
76820+ if (msg) {
76821+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76822+ return 0;
76823+ }
76824+#endif
76825+#endif
76826+ return 1;
76827+}
76828diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76829new file mode 100644
76830index 0000000..ae02d8e
76831--- /dev/null
76832+++ b/grsecurity/grsec_usb.c
76833@@ -0,0 +1,15 @@
76834+#include <linux/kernel.h>
76835+#include <linux/grinternal.h>
76836+#include <linux/module.h>
76837+
76838+int gr_handle_new_usb(void)
76839+{
76840+#ifdef CONFIG_GRKERNSEC_DENYUSB
76841+ if (grsec_deny_new_usb) {
76842+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76843+ return 1;
76844+ }
76845+#endif
76846+ return 0;
76847+}
76848+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76849diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76850new file mode 100644
76851index 0000000..9f7b1ac
76852--- /dev/null
76853+++ b/grsecurity/grsum.c
76854@@ -0,0 +1,61 @@
76855+#include <linux/err.h>
76856+#include <linux/kernel.h>
76857+#include <linux/sched.h>
76858+#include <linux/mm.h>
76859+#include <linux/scatterlist.h>
76860+#include <linux/crypto.h>
76861+#include <linux/gracl.h>
76862+
76863+
76864+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76865+#error "crypto and sha256 must be built into the kernel"
76866+#endif
76867+
76868+int
76869+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76870+{
76871+ char *p;
76872+ struct crypto_hash *tfm;
76873+ struct hash_desc desc;
76874+ struct scatterlist sg;
76875+ unsigned char temp_sum[GR_SHA_LEN];
76876+ volatile int retval = 0;
76877+ volatile int dummy = 0;
76878+ unsigned int i;
76879+
76880+ sg_init_table(&sg, 1);
76881+
76882+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76883+ if (IS_ERR(tfm)) {
76884+ /* should never happen, since sha256 should be built in */
76885+ return 1;
76886+ }
76887+
76888+ desc.tfm = tfm;
76889+ desc.flags = 0;
76890+
76891+ crypto_hash_init(&desc);
76892+
76893+ p = salt;
76894+ sg_set_buf(&sg, p, GR_SALT_LEN);
76895+ crypto_hash_update(&desc, &sg, sg.length);
76896+
76897+ p = entry->pw;
76898+ sg_set_buf(&sg, p, strlen(p));
76899+
76900+ crypto_hash_update(&desc, &sg, sg.length);
76901+
76902+ crypto_hash_final(&desc, temp_sum);
76903+
76904+ memset(entry->pw, 0, GR_PW_LEN);
76905+
76906+ for (i = 0; i < GR_SHA_LEN; i++)
76907+ if (sum[i] != temp_sum[i])
76908+ retval = 1;
76909+ else
76910+ dummy = 1; // waste a cycle
76911+
76912+ crypto_free_hash(tfm);
76913+
76914+ return retval;
76915+}
76916diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76917index 77ff547..181834f 100644
76918--- a/include/asm-generic/4level-fixup.h
76919+++ b/include/asm-generic/4level-fixup.h
76920@@ -13,8 +13,10 @@
76921 #define pmd_alloc(mm, pud, address) \
76922 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76923 NULL: pmd_offset(pud, address))
76924+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76925
76926 #define pud_alloc(mm, pgd, address) (pgd)
76927+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76928 #define pud_offset(pgd, start) (pgd)
76929 #define pud_none(pud) 0
76930 #define pud_bad(pud) 0
76931diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76932index b7babf0..97f4c4f 100644
76933--- a/include/asm-generic/atomic-long.h
76934+++ b/include/asm-generic/atomic-long.h
76935@@ -22,6 +22,12 @@
76936
76937 typedef atomic64_t atomic_long_t;
76938
76939+#ifdef CONFIG_PAX_REFCOUNT
76940+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76941+#else
76942+typedef atomic64_t atomic_long_unchecked_t;
76943+#endif
76944+
76945 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76946
76947 static inline long atomic_long_read(atomic_long_t *l)
76948@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76949 return (long)atomic64_read(v);
76950 }
76951
76952+#ifdef CONFIG_PAX_REFCOUNT
76953+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76954+{
76955+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76956+
76957+ return (long)atomic64_read_unchecked(v);
76958+}
76959+#endif
76960+
76961 static inline void atomic_long_set(atomic_long_t *l, long i)
76962 {
76963 atomic64_t *v = (atomic64_t *)l;
76964@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76965 atomic64_set(v, i);
76966 }
76967
76968+#ifdef CONFIG_PAX_REFCOUNT
76969+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76970+{
76971+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76972+
76973+ atomic64_set_unchecked(v, i);
76974+}
76975+#endif
76976+
76977 static inline void atomic_long_inc(atomic_long_t *l)
76978 {
76979 atomic64_t *v = (atomic64_t *)l;
76980@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76981 atomic64_inc(v);
76982 }
76983
76984+#ifdef CONFIG_PAX_REFCOUNT
76985+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76986+{
76987+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76988+
76989+ atomic64_inc_unchecked(v);
76990+}
76991+#endif
76992+
76993 static inline void atomic_long_dec(atomic_long_t *l)
76994 {
76995 atomic64_t *v = (atomic64_t *)l;
76996@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76997 atomic64_dec(v);
76998 }
76999
77000+#ifdef CONFIG_PAX_REFCOUNT
77001+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77002+{
77003+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77004+
77005+ atomic64_dec_unchecked(v);
77006+}
77007+#endif
77008+
77009 static inline void atomic_long_add(long i, atomic_long_t *l)
77010 {
77011 atomic64_t *v = (atomic64_t *)l;
77012@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77013 atomic64_add(i, v);
77014 }
77015
77016+#ifdef CONFIG_PAX_REFCOUNT
77017+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77018+{
77019+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77020+
77021+ atomic64_add_unchecked(i, v);
77022+}
77023+#endif
77024+
77025 static inline void atomic_long_sub(long i, atomic_long_t *l)
77026 {
77027 atomic64_t *v = (atomic64_t *)l;
77028@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77029 atomic64_sub(i, v);
77030 }
77031
77032+#ifdef CONFIG_PAX_REFCOUNT
77033+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77034+{
77035+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77036+
77037+ atomic64_sub_unchecked(i, v);
77038+}
77039+#endif
77040+
77041 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77042 {
77043 atomic64_t *v = (atomic64_t *)l;
77044@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
77045 return atomic64_add_negative(i, v);
77046 }
77047
77048-static inline long atomic_long_add_return(long i, atomic_long_t *l)
77049+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
77050 {
77051 atomic64_t *v = (atomic64_t *)l;
77052
77053 return (long)atomic64_add_return(i, v);
77054 }
77055
77056+#ifdef CONFIG_PAX_REFCOUNT
77057+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77058+{
77059+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77060+
77061+ return (long)atomic64_add_return_unchecked(i, v);
77062+}
77063+#endif
77064+
77065 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77066 {
77067 atomic64_t *v = (atomic64_t *)l;
77068@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77069 return (long)atomic64_inc_return(v);
77070 }
77071
77072+#ifdef CONFIG_PAX_REFCOUNT
77073+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77074+{
77075+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77076+
77077+ return (long)atomic64_inc_return_unchecked(v);
77078+}
77079+#endif
77080+
77081 static inline long atomic_long_dec_return(atomic_long_t *l)
77082 {
77083 atomic64_t *v = (atomic64_t *)l;
77084@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77085
77086 typedef atomic_t atomic_long_t;
77087
77088+#ifdef CONFIG_PAX_REFCOUNT
77089+typedef atomic_unchecked_t atomic_long_unchecked_t;
77090+#else
77091+typedef atomic_t atomic_long_unchecked_t;
77092+#endif
77093+
77094 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
77095 static inline long atomic_long_read(atomic_long_t *l)
77096 {
77097@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77098 return (long)atomic_read(v);
77099 }
77100
77101+#ifdef CONFIG_PAX_REFCOUNT
77102+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77103+{
77104+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77105+
77106+ return (long)atomic_read_unchecked(v);
77107+}
77108+#endif
77109+
77110 static inline void atomic_long_set(atomic_long_t *l, long i)
77111 {
77112 atomic_t *v = (atomic_t *)l;
77113@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77114 atomic_set(v, i);
77115 }
77116
77117+#ifdef CONFIG_PAX_REFCOUNT
77118+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77119+{
77120+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77121+
77122+ atomic_set_unchecked(v, i);
77123+}
77124+#endif
77125+
77126 static inline void atomic_long_inc(atomic_long_t *l)
77127 {
77128 atomic_t *v = (atomic_t *)l;
77129@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77130 atomic_inc(v);
77131 }
77132
77133+#ifdef CONFIG_PAX_REFCOUNT
77134+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77135+{
77136+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77137+
77138+ atomic_inc_unchecked(v);
77139+}
77140+#endif
77141+
77142 static inline void atomic_long_dec(atomic_long_t *l)
77143 {
77144 atomic_t *v = (atomic_t *)l;
77145@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77146 atomic_dec(v);
77147 }
77148
77149+#ifdef CONFIG_PAX_REFCOUNT
77150+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77151+{
77152+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77153+
77154+ atomic_dec_unchecked(v);
77155+}
77156+#endif
77157+
77158 static inline void atomic_long_add(long i, atomic_long_t *l)
77159 {
77160 atomic_t *v = (atomic_t *)l;
77161@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77162 atomic_add(i, v);
77163 }
77164
77165+#ifdef CONFIG_PAX_REFCOUNT
77166+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77167+{
77168+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77169+
77170+ atomic_add_unchecked(i, v);
77171+}
77172+#endif
77173+
77174 static inline void atomic_long_sub(long i, atomic_long_t *l)
77175 {
77176 atomic_t *v = (atomic_t *)l;
77177@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77178 atomic_sub(i, v);
77179 }
77180
77181+#ifdef CONFIG_PAX_REFCOUNT
77182+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77183+{
77184+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77185+
77186+ atomic_sub_unchecked(i, v);
77187+}
77188+#endif
77189+
77190 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77191 {
77192 atomic_t *v = (atomic_t *)l;
77193@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
77194 return (long)atomic_add_return(i, v);
77195 }
77196
77197+#ifdef CONFIG_PAX_REFCOUNT
77198+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77199+{
77200+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77201+
77202+ return (long)atomic_add_return_unchecked(i, v);
77203+}
77204+
77205+#endif
77206+
77207 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77208 {
77209 atomic_t *v = (atomic_t *)l;
77210@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77211 return (long)atomic_inc_return(v);
77212 }
77213
77214+#ifdef CONFIG_PAX_REFCOUNT
77215+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77216+{
77217+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77218+
77219+ return (long)atomic_inc_return_unchecked(v);
77220+}
77221+#endif
77222+
77223 static inline long atomic_long_dec_return(atomic_long_t *l)
77224 {
77225 atomic_t *v = (atomic_t *)l;
77226@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77227
77228 #endif /* BITS_PER_LONG == 64 */
77229
77230+#ifdef CONFIG_PAX_REFCOUNT
77231+static inline void pax_refcount_needs_these_functions(void)
77232+{
77233+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
77234+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
77235+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
77236+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
77237+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
77238+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
77239+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
77240+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
77241+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
77242+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
77243+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
77244+#ifdef CONFIG_X86
77245+ atomic_clear_mask_unchecked(0, NULL);
77246+ atomic_set_mask_unchecked(0, NULL);
77247+#endif
77248+
77249+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
77250+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
77251+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
77252+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
77253+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
77254+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
77255+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
77256+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
77257+}
77258+#else
77259+#define atomic_read_unchecked(v) atomic_read(v)
77260+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
77261+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
77262+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
77263+#define atomic_inc_unchecked(v) atomic_inc(v)
77264+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
77265+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
77266+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
77267+#define atomic_dec_unchecked(v) atomic_dec(v)
77268+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
77269+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
77270+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
77271+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
77272+
77273+#define atomic_long_read_unchecked(v) atomic_long_read(v)
77274+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
77275+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
77276+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
77277+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
77278+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
77279+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
77280+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
77281+#endif
77282+
77283 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
77284diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
77285index 33bd2de..f31bff97 100644
77286--- a/include/asm-generic/atomic.h
77287+++ b/include/asm-generic/atomic.h
77288@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
77289 * Atomically clears the bits set in @mask from @v
77290 */
77291 #ifndef atomic_clear_mask
77292-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
77293+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
77294 {
77295 unsigned long flags;
77296
77297diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
77298index b18ce4f..2ee2843 100644
77299--- a/include/asm-generic/atomic64.h
77300+++ b/include/asm-generic/atomic64.h
77301@@ -16,6 +16,8 @@ typedef struct {
77302 long long counter;
77303 } atomic64_t;
77304
77305+typedef atomic64_t atomic64_unchecked_t;
77306+
77307 #define ATOMIC64_INIT(i) { (i) }
77308
77309 extern long long atomic64_read(const atomic64_t *v);
77310@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
77311 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
77312 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
77313
77314+#define atomic64_read_unchecked(v) atomic64_read(v)
77315+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
77316+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
77317+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
77318+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
77319+#define atomic64_inc_unchecked(v) atomic64_inc(v)
77320+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
77321+#define atomic64_dec_unchecked(v) atomic64_dec(v)
77322+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
77323+
77324 #endif /* _ASM_GENERIC_ATOMIC64_H */
77325diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77326index a60a7cc..0fe12f2 100644
77327--- a/include/asm-generic/bitops/__fls.h
77328+++ b/include/asm-generic/bitops/__fls.h
77329@@ -9,7 +9,7 @@
77330 *
77331 * Undefined if no set bit exists, so code should check against 0 first.
77332 */
77333-static __always_inline unsigned long __fls(unsigned long word)
77334+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77335 {
77336 int num = BITS_PER_LONG - 1;
77337
77338diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77339index 0576d1f..dad6c71 100644
77340--- a/include/asm-generic/bitops/fls.h
77341+++ b/include/asm-generic/bitops/fls.h
77342@@ -9,7 +9,7 @@
77343 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77344 */
77345
77346-static __always_inline int fls(int x)
77347+static __always_inline int __intentional_overflow(-1) fls(int x)
77348 {
77349 int r = 32;
77350
77351diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77352index b097cf8..3d40e14 100644
77353--- a/include/asm-generic/bitops/fls64.h
77354+++ b/include/asm-generic/bitops/fls64.h
77355@@ -15,7 +15,7 @@
77356 * at position 64.
77357 */
77358 #if BITS_PER_LONG == 32
77359-static __always_inline int fls64(__u64 x)
77360+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77361 {
77362 __u32 h = x >> 32;
77363 if (h)
77364@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77365 return fls(x);
77366 }
77367 #elif BITS_PER_LONG == 64
77368-static __always_inline int fls64(__u64 x)
77369+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77370 {
77371 if (x == 0)
77372 return 0;
77373diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77374index 1bfcfe5..e04c5c9 100644
77375--- a/include/asm-generic/cache.h
77376+++ b/include/asm-generic/cache.h
77377@@ -6,7 +6,7 @@
77378 * cache lines need to provide their own cache.h.
77379 */
77380
77381-#define L1_CACHE_SHIFT 5
77382-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77383+#define L1_CACHE_SHIFT 5UL
77384+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77385
77386 #endif /* __ASM_GENERIC_CACHE_H */
77387diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77388index 0d68a1e..b74a761 100644
77389--- a/include/asm-generic/emergency-restart.h
77390+++ b/include/asm-generic/emergency-restart.h
77391@@ -1,7 +1,7 @@
77392 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77393 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77394
77395-static inline void machine_emergency_restart(void)
77396+static inline __noreturn void machine_emergency_restart(void)
77397 {
77398 machine_restart(NULL);
77399 }
77400diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77401index 90f99c7..00ce236 100644
77402--- a/include/asm-generic/kmap_types.h
77403+++ b/include/asm-generic/kmap_types.h
77404@@ -2,9 +2,9 @@
77405 #define _ASM_GENERIC_KMAP_TYPES_H
77406
77407 #ifdef __WITH_KM_FENCE
77408-# define KM_TYPE_NR 41
77409+# define KM_TYPE_NR 42
77410 #else
77411-# define KM_TYPE_NR 20
77412+# define KM_TYPE_NR 21
77413 #endif
77414
77415 #endif
77416diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77417index 9ceb03b..62b0b8f 100644
77418--- a/include/asm-generic/local.h
77419+++ b/include/asm-generic/local.h
77420@@ -23,24 +23,37 @@ typedef struct
77421 atomic_long_t a;
77422 } local_t;
77423
77424+typedef struct {
77425+ atomic_long_unchecked_t a;
77426+} local_unchecked_t;
77427+
77428 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77429
77430 #define local_read(l) atomic_long_read(&(l)->a)
77431+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77432 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77433+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77434 #define local_inc(l) atomic_long_inc(&(l)->a)
77435+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77436 #define local_dec(l) atomic_long_dec(&(l)->a)
77437+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77438 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77439+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77440 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77441+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77442
77443 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77444 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77445 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77446 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77447 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77448+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77449 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77450 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77451+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77452
77453 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77454+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77455 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77456 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77457 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77458diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77459index 725612b..9cc513a 100644
77460--- a/include/asm-generic/pgtable-nopmd.h
77461+++ b/include/asm-generic/pgtable-nopmd.h
77462@@ -1,14 +1,19 @@
77463 #ifndef _PGTABLE_NOPMD_H
77464 #define _PGTABLE_NOPMD_H
77465
77466-#ifndef __ASSEMBLY__
77467-
77468 #include <asm-generic/pgtable-nopud.h>
77469
77470-struct mm_struct;
77471-
77472 #define __PAGETABLE_PMD_FOLDED
77473
77474+#define PMD_SHIFT PUD_SHIFT
77475+#define PTRS_PER_PMD 1
77476+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77477+#define PMD_MASK (~(PMD_SIZE-1))
77478+
77479+#ifndef __ASSEMBLY__
77480+
77481+struct mm_struct;
77482+
77483 /*
77484 * Having the pmd type consist of a pud gets the size right, and allows
77485 * us to conceptually access the pud entry that this pmd is folded into
77486@@ -16,11 +21,6 @@ struct mm_struct;
77487 */
77488 typedef struct { pud_t pud; } pmd_t;
77489
77490-#define PMD_SHIFT PUD_SHIFT
77491-#define PTRS_PER_PMD 1
77492-#define PMD_SIZE (1UL << PMD_SHIFT)
77493-#define PMD_MASK (~(PMD_SIZE-1))
77494-
77495 /*
77496 * The "pud_xxx()" functions here are trivial for a folded two-level
77497 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77498diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77499index 810431d..0ec4804f 100644
77500--- a/include/asm-generic/pgtable-nopud.h
77501+++ b/include/asm-generic/pgtable-nopud.h
77502@@ -1,10 +1,15 @@
77503 #ifndef _PGTABLE_NOPUD_H
77504 #define _PGTABLE_NOPUD_H
77505
77506-#ifndef __ASSEMBLY__
77507-
77508 #define __PAGETABLE_PUD_FOLDED
77509
77510+#define PUD_SHIFT PGDIR_SHIFT
77511+#define PTRS_PER_PUD 1
77512+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77513+#define PUD_MASK (~(PUD_SIZE-1))
77514+
77515+#ifndef __ASSEMBLY__
77516+
77517 /*
77518 * Having the pud type consist of a pgd gets the size right, and allows
77519 * us to conceptually access the pgd entry that this pud is folded into
77520@@ -12,11 +17,6 @@
77521 */
77522 typedef struct { pgd_t pgd; } pud_t;
77523
77524-#define PUD_SHIFT PGDIR_SHIFT
77525-#define PTRS_PER_PUD 1
77526-#define PUD_SIZE (1UL << PUD_SHIFT)
77527-#define PUD_MASK (~(PUD_SIZE-1))
77528-
77529 /*
77530 * The "pgd_xxx()" functions here are trivial for a folded two-level
77531 * setup: the pud is never bad, and a pud always exists (as it's folded
77532@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77533 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77534
77535 #define pgd_populate(mm, pgd, pud) do { } while (0)
77536+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77537 /*
77538 * (puds are folded into pgds so this doesn't get actually called,
77539 * but the define is needed for a generic inline function.)
77540diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77541index 34c7bdc..38d4f3b 100644
77542--- a/include/asm-generic/pgtable.h
77543+++ b/include/asm-generic/pgtable.h
77544@@ -787,6 +787,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77545 }
77546 #endif /* CONFIG_NUMA_BALANCING */
77547
77548+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77549+#ifdef CONFIG_PAX_KERNEXEC
77550+#error KERNEXEC requires pax_open_kernel
77551+#else
77552+static inline unsigned long pax_open_kernel(void) { return 0; }
77553+#endif
77554+#endif
77555+
77556+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77557+#ifdef CONFIG_PAX_KERNEXEC
77558+#error KERNEXEC requires pax_close_kernel
77559+#else
77560+static inline unsigned long pax_close_kernel(void) { return 0; }
77561+#endif
77562+#endif
77563+
77564 #endif /* CONFIG_MMU */
77565
77566 #endif /* !__ASSEMBLY__ */
77567diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77568index 72d8803..cb9749c 100644
77569--- a/include/asm-generic/uaccess.h
77570+++ b/include/asm-generic/uaccess.h
77571@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77572 return __clear_user(to, n);
77573 }
77574
77575+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77576+#ifdef CONFIG_PAX_MEMORY_UDEREF
77577+#error UDEREF requires pax_open_userland
77578+#else
77579+static inline unsigned long pax_open_userland(void) { return 0; }
77580+#endif
77581+#endif
77582+
77583+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77584+#ifdef CONFIG_PAX_MEMORY_UDEREF
77585+#error UDEREF requires pax_close_userland
77586+#else
77587+static inline unsigned long pax_close_userland(void) { return 0; }
77588+#endif
77589+#endif
77590+
77591 #endif /* __ASM_GENERIC_UACCESS_H */
77592diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77593index bc2121f..2f41f9a 100644
77594--- a/include/asm-generic/vmlinux.lds.h
77595+++ b/include/asm-generic/vmlinux.lds.h
77596@@ -232,6 +232,7 @@
77597 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77598 VMLINUX_SYMBOL(__start_rodata) = .; \
77599 *(.rodata) *(.rodata.*) \
77600+ *(.data..read_only) \
77601 *(__vermagic) /* Kernel version magic */ \
77602 . = ALIGN(8); \
77603 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77604@@ -716,17 +717,18 @@
77605 * section in the linker script will go there too. @phdr should have
77606 * a leading colon.
77607 *
77608- * Note that this macros defines __per_cpu_load as an absolute symbol.
77609+ * Note that this macros defines per_cpu_load as an absolute symbol.
77610 * If there is no need to put the percpu section at a predetermined
77611 * address, use PERCPU_SECTION.
77612 */
77613 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77614- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77615- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77616+ per_cpu_load = .; \
77617+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77618 - LOAD_OFFSET) { \
77619+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77620 PERCPU_INPUT(cacheline) \
77621 } phdr \
77622- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77623+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77624
77625 /**
77626 * PERCPU_SECTION - define output section for percpu area, simple version
77627diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77628index e73c19e..5b89e00 100644
77629--- a/include/crypto/algapi.h
77630+++ b/include/crypto/algapi.h
77631@@ -34,7 +34,7 @@ struct crypto_type {
77632 unsigned int maskclear;
77633 unsigned int maskset;
77634 unsigned int tfmsize;
77635-};
77636+} __do_const;
77637
77638 struct crypto_instance {
77639 struct crypto_alg alg;
77640diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77641index 04a7f31..668d424 100644
77642--- a/include/drm/drmP.h
77643+++ b/include/drm/drmP.h
77644@@ -67,6 +67,7 @@
77645 #include <linux/workqueue.h>
77646 #include <linux/poll.h>
77647 #include <asm/pgalloc.h>
77648+#include <asm/local.h>
77649 #include <drm/drm.h>
77650 #include <drm/drm_sarea.h>
77651 #include <drm/drm_vma_manager.h>
77652@@ -297,10 +298,12 @@ do { \
77653 * \param cmd command.
77654 * \param arg argument.
77655 */
77656-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77657+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77658+ struct drm_file *file_priv);
77659+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77660 struct drm_file *file_priv);
77661
77662-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77663+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77664 unsigned long arg);
77665
77666 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77667@@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77668 struct drm_ioctl_desc {
77669 unsigned int cmd;
77670 int flags;
77671- drm_ioctl_t *func;
77672+ drm_ioctl_t func;
77673 unsigned int cmd_drv;
77674 const char *name;
77675-};
77676+} __do_const;
77677
77678 /**
77679 * Creates a driver or general drm_ioctl_desc array entry for the given
77680@@ -1022,7 +1025,8 @@ struct drm_info_list {
77681 int (*show)(struct seq_file*, void*); /** show callback */
77682 u32 driver_features; /**< Required driver features for this entry */
77683 void *data;
77684-};
77685+} __do_const;
77686+typedef struct drm_info_list __no_const drm_info_list_no_const;
77687
77688 /**
77689 * debugfs node structure. This structure represents a debugfs file.
77690@@ -1106,7 +1110,7 @@ struct drm_device {
77691
77692 /** \name Usage Counters */
77693 /*@{ */
77694- int open_count; /**< Outstanding files open */
77695+ local_t open_count; /**< Outstanding files open */
77696 int buf_use; /**< Buffers in use -- cannot alloc */
77697 atomic_t buf_alloc; /**< Buffer allocation in progress */
77698 /*@} */
77699diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77700index b1388b5..e1d1163 100644
77701--- a/include/drm/drm_crtc_helper.h
77702+++ b/include/drm/drm_crtc_helper.h
77703@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77704 struct drm_connector *connector);
77705 /* disable encoder when not in use - more explicit than dpms off */
77706 void (*disable)(struct drm_encoder *encoder);
77707-};
77708+} __no_const;
77709
77710 /**
77711 * drm_connector_helper_funcs - helper operations for connectors
77712diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77713index 940ece4..8cb727f 100644
77714--- a/include/drm/i915_pciids.h
77715+++ b/include/drm/i915_pciids.h
77716@@ -37,7 +37,7 @@
77717 */
77718 #define INTEL_VGA_DEVICE(id, info) { \
77719 0x8086, id, \
77720- ~0, ~0, \
77721+ PCI_ANY_ID, PCI_ANY_ID, \
77722 0x030000, 0xff0000, \
77723 (unsigned long) info }
77724
77725diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77726index 72dcbe8..8db58d7 100644
77727--- a/include/drm/ttm/ttm_memory.h
77728+++ b/include/drm/ttm/ttm_memory.h
77729@@ -48,7 +48,7 @@
77730
77731 struct ttm_mem_shrink {
77732 int (*do_shrink) (struct ttm_mem_shrink *);
77733-};
77734+} __no_const;
77735
77736 /**
77737 * struct ttm_mem_global - Global memory accounting structure.
77738diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77739index 49a8284..9643967 100644
77740--- a/include/drm/ttm/ttm_page_alloc.h
77741+++ b/include/drm/ttm/ttm_page_alloc.h
77742@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77743 */
77744 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77745
77746+struct device;
77747 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77748 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77749
77750diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77751index 4b840e8..155d235 100644
77752--- a/include/keys/asymmetric-subtype.h
77753+++ b/include/keys/asymmetric-subtype.h
77754@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77755 /* Verify the signature on a key of this subtype (optional) */
77756 int (*verify_signature)(const struct key *key,
77757 const struct public_key_signature *sig);
77758-};
77759+} __do_const;
77760
77761 /**
77762 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77763diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77764index c1da539..1dcec55 100644
77765--- a/include/linux/atmdev.h
77766+++ b/include/linux/atmdev.h
77767@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77768 #endif
77769
77770 struct k_atm_aal_stats {
77771-#define __HANDLE_ITEM(i) atomic_t i
77772+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77773 __AAL_STAT_ITEMS
77774 #undef __HANDLE_ITEM
77775 };
77776@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77777 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77778 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77779 struct module *owner;
77780-};
77781+} __do_const ;
77782
77783 struct atmphy_ops {
77784 int (*start)(struct atm_dev *dev);
77785diff --git a/include/linux/audit.h b/include/linux/audit.h
77786index ec1464d..833274b 100644
77787--- a/include/linux/audit.h
77788+++ b/include/linux/audit.h
77789@@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
77790 extern unsigned int audit_serial(void);
77791 extern int auditsc_get_stamp(struct audit_context *ctx,
77792 struct timespec *t, unsigned int *serial);
77793-extern int audit_set_loginuid(kuid_t loginuid);
77794+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77795
77796 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77797 {
77798diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77799index b4a745d..e3c0942 100644
77800--- a/include/linux/binfmts.h
77801+++ b/include/linux/binfmts.h
77802@@ -45,7 +45,7 @@ struct linux_binprm {
77803 unsigned interp_data;
77804 unsigned long loader, exec;
77805 char tcomm[TASK_COMM_LEN];
77806-};
77807+} __randomize_layout;
77808
77809 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77810 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77811@@ -74,8 +74,10 @@ struct linux_binfmt {
77812 int (*load_binary)(struct linux_binprm *);
77813 int (*load_shlib)(struct file *);
77814 int (*core_dump)(struct coredump_params *cprm);
77815+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77816+ void (*handle_mmap)(struct file *);
77817 unsigned long min_coredump; /* minimal dump size */
77818-};
77819+} __do_const __randomize_layout;
77820
77821 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77822
77823diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77824index be5fd38..d71192a 100644
77825--- a/include/linux/bitops.h
77826+++ b/include/linux/bitops.h
77827@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77828 * @word: value to rotate
77829 * @shift: bits to roll
77830 */
77831-static inline __u32 rol32(__u32 word, unsigned int shift)
77832+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77833 {
77834 return (word << shift) | (word >> (32 - shift));
77835 }
77836@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77837 * @word: value to rotate
77838 * @shift: bits to roll
77839 */
77840-static inline __u32 ror32(__u32 word, unsigned int shift)
77841+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77842 {
77843 return (word >> shift) | (word << (32 - shift));
77844 }
77845@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77846 return (__s32)(value << shift) >> shift;
77847 }
77848
77849-static inline unsigned fls_long(unsigned long l)
77850+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77851 {
77852 if (sizeof(l) == 4)
77853 return fls(l);
77854diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77855index 4afa4f8..1ed7824 100644
77856--- a/include/linux/blkdev.h
77857+++ b/include/linux/blkdev.h
77858@@ -1572,7 +1572,7 @@ struct block_device_operations {
77859 /* this callback is with swap_lock and sometimes page table lock held */
77860 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77861 struct module *owner;
77862-};
77863+} __do_const;
77864
77865 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77866 unsigned long);
77867diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77868index afc1343..9735539 100644
77869--- a/include/linux/blktrace_api.h
77870+++ b/include/linux/blktrace_api.h
77871@@ -25,7 +25,7 @@ struct blk_trace {
77872 struct dentry *dropped_file;
77873 struct dentry *msg_file;
77874 struct list_head running_list;
77875- atomic_t dropped;
77876+ atomic_unchecked_t dropped;
77877 };
77878
77879 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77880diff --git a/include/linux/cache.h b/include/linux/cache.h
77881index 17e7e82..1d7da26 100644
77882--- a/include/linux/cache.h
77883+++ b/include/linux/cache.h
77884@@ -16,6 +16,14 @@
77885 #define __read_mostly
77886 #endif
77887
77888+#ifndef __read_only
77889+#ifdef CONFIG_PAX_KERNEXEC
77890+#error KERNEXEC requires __read_only
77891+#else
77892+#define __read_only __read_mostly
77893+#endif
77894+#endif
77895+
77896 #ifndef ____cacheline_aligned
77897 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77898 #endif
77899diff --git a/include/linux/capability.h b/include/linux/capability.h
77900index a6ee1f9..e1ca49d 100644
77901--- a/include/linux/capability.h
77902+++ b/include/linux/capability.h
77903@@ -212,8 +212,13 @@ extern bool capable(int cap);
77904 extern bool ns_capable(struct user_namespace *ns, int cap);
77905 extern bool inode_capable(const struct inode *inode, int cap);
77906 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77907+extern bool capable_nolog(int cap);
77908+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77909+extern bool inode_capable_nolog(const struct inode *inode, int cap);
77910
77911 /* audit system wants to get cap info from files as well */
77912 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77913
77914+extern int is_privileged_binary(const struct dentry *dentry);
77915+
77916 #endif /* !_LINUX_CAPABILITY_H */
77917diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77918index 8609d57..86e4d79 100644
77919--- a/include/linux/cdrom.h
77920+++ b/include/linux/cdrom.h
77921@@ -87,7 +87,6 @@ struct cdrom_device_ops {
77922
77923 /* driver specifications */
77924 const int capability; /* capability flags */
77925- int n_minors; /* number of active minor devices */
77926 /* handle uniform packets for scsi type devices (scsi,atapi) */
77927 int (*generic_packet) (struct cdrom_device_info *,
77928 struct packet_command *);
77929diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77930index 4ce9056..86caac6 100644
77931--- a/include/linux/cleancache.h
77932+++ b/include/linux/cleancache.h
77933@@ -31,7 +31,7 @@ struct cleancache_ops {
77934 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77935 void (*invalidate_inode)(int, struct cleancache_filekey);
77936 void (*invalidate_fs)(int);
77937-};
77938+} __no_const;
77939
77940 extern struct cleancache_ops *
77941 cleancache_register_ops(struct cleancache_ops *ops);
77942diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77943index 939533d..cf0a57c 100644
77944--- a/include/linux/clk-provider.h
77945+++ b/include/linux/clk-provider.h
77946@@ -166,6 +166,7 @@ struct clk_ops {
77947 unsigned long parent_accuracy);
77948 void (*init)(struct clk_hw *hw);
77949 };
77950+typedef struct clk_ops __no_const clk_ops_no_const;
77951
77952 /**
77953 * struct clk_init_data - holds init data that's common to all clocks and is
77954diff --git a/include/linux/compat.h b/include/linux/compat.h
77955index 3f448c6..df3ce1d 100644
77956--- a/include/linux/compat.h
77957+++ b/include/linux/compat.h
77958@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77959 compat_size_t __user *len_ptr);
77960
77961 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77962-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77963+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77964 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77965 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77966 compat_ssize_t msgsz, int msgflg);
77967@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77968 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77969 compat_ulong_t addr, compat_ulong_t data);
77970 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77971- compat_long_t addr, compat_long_t data);
77972+ compat_ulong_t addr, compat_ulong_t data);
77973
77974 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77975 /*
77976diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77977index 2507fd2..55203f8 100644
77978--- a/include/linux/compiler-gcc4.h
77979+++ b/include/linux/compiler-gcc4.h
77980@@ -39,9 +39,34 @@
77981 # define __compiletime_warning(message) __attribute__((warning(message)))
77982 # define __compiletime_error(message) __attribute__((error(message)))
77983 #endif /* __CHECKER__ */
77984+
77985+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77986+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77987+#define __bos0(ptr) __bos((ptr), 0)
77988+#define __bos1(ptr) __bos((ptr), 1)
77989 #endif /* GCC_VERSION >= 40300 */
77990
77991 #if GCC_VERSION >= 40500
77992+
77993+#ifdef RANDSTRUCT_PLUGIN
77994+#define __randomize_layout __attribute__((randomize_layout))
77995+#define __no_randomize_layout __attribute__((no_randomize_layout))
77996+#endif
77997+
77998+#ifdef CONSTIFY_PLUGIN
77999+#define __no_const __attribute__((no_const))
78000+#define __do_const __attribute__((do_const))
78001+#endif
78002+
78003+#ifdef SIZE_OVERFLOW_PLUGIN
78004+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
78005+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
78006+#endif
78007+
78008+#ifdef LATENT_ENTROPY_PLUGIN
78009+#define __latent_entropy __attribute__((latent_entropy))
78010+#endif
78011+
78012 /*
78013 * Mark a position in code as unreachable. This can be used to
78014 * suppress control flow warnings after asm blocks that transfer
78015diff --git a/include/linux/compiler.h b/include/linux/compiler.h
78016index 2472740..4857634 100644
78017--- a/include/linux/compiler.h
78018+++ b/include/linux/compiler.h
78019@@ -5,11 +5,14 @@
78020
78021 #ifdef __CHECKER__
78022 # define __user __attribute__((noderef, address_space(1)))
78023+# define __force_user __force __user
78024 # define __kernel __attribute__((address_space(0)))
78025+# define __force_kernel __force __kernel
78026 # define __safe __attribute__((safe))
78027 # define __force __attribute__((force))
78028 # define __nocast __attribute__((nocast))
78029 # define __iomem __attribute__((noderef, address_space(2)))
78030+# define __force_iomem __force __iomem
78031 # define __must_hold(x) __attribute__((context(x,1,1)))
78032 # define __acquires(x) __attribute__((context(x,0,1)))
78033 # define __releases(x) __attribute__((context(x,1,0)))
78034@@ -17,20 +20,37 @@
78035 # define __release(x) __context__(x,-1)
78036 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
78037 # define __percpu __attribute__((noderef, address_space(3)))
78038+# define __force_percpu __force __percpu
78039 #ifdef CONFIG_SPARSE_RCU_POINTER
78040 # define __rcu __attribute__((noderef, address_space(4)))
78041+# define __force_rcu __force __rcu
78042 #else
78043 # define __rcu
78044+# define __force_rcu
78045 #endif
78046 extern void __chk_user_ptr(const volatile void __user *);
78047 extern void __chk_io_ptr(const volatile void __iomem *);
78048 #else
78049-# define __user
78050-# define __kernel
78051+# ifdef CHECKER_PLUGIN
78052+//# define __user
78053+//# define __force_user
78054+//# define __kernel
78055+//# define __force_kernel
78056+# else
78057+# ifdef STRUCTLEAK_PLUGIN
78058+# define __user __attribute__((user))
78059+# else
78060+# define __user
78061+# endif
78062+# define __force_user
78063+# define __kernel
78064+# define __force_kernel
78065+# endif
78066 # define __safe
78067 # define __force
78068 # define __nocast
78069 # define __iomem
78070+# define __force_iomem
78071 # define __chk_user_ptr(x) (void)0
78072 # define __chk_io_ptr(x) (void)0
78073 # define __builtin_warning(x, y...) (1)
78074@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
78075 # define __release(x) (void)0
78076 # define __cond_lock(x,c) (c)
78077 # define __percpu
78078+# define __force_percpu
78079 # define __rcu
78080+# define __force_rcu
78081 #endif
78082
78083 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
78084@@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78085 # define __attribute_const__ /* unimplemented */
78086 #endif
78087
78088+#ifndef __randomize_layout
78089+# define __randomize_layout
78090+#endif
78091+
78092+#ifndef __no_randomize_layout
78093+# define __no_randomize_layout
78094+#endif
78095+
78096+#ifndef __no_const
78097+# define __no_const
78098+#endif
78099+
78100+#ifndef __do_const
78101+# define __do_const
78102+#endif
78103+
78104+#ifndef __size_overflow
78105+# define __size_overflow(...)
78106+#endif
78107+
78108+#ifndef __intentional_overflow
78109+# define __intentional_overflow(...)
78110+#endif
78111+
78112+#ifndef __latent_entropy
78113+# define __latent_entropy
78114+#endif
78115+
78116 /*
78117 * Tell gcc if a function is cold. The compiler will assume any path
78118 * directly leading to the call is unlikely.
78119@@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78120 #define __cold
78121 #endif
78122
78123+#ifndef __alloc_size
78124+#define __alloc_size(...)
78125+#endif
78126+
78127+#ifndef __bos
78128+#define __bos(ptr, arg)
78129+#endif
78130+
78131+#ifndef __bos0
78132+#define __bos0(ptr)
78133+#endif
78134+
78135+#ifndef __bos1
78136+#define __bos1(ptr)
78137+#endif
78138+
78139 /* Simple shorthand for a section definition */
78140 #ifndef __section
78141 # define __section(S) __attribute__ ((__section__(#S)))
78142@@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78143 * use is to mediate communication between process-level code and irq/NMI
78144 * handlers, all running on the same CPU.
78145 */
78146-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
78147+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
78148+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
78149
78150 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
78151 #ifdef CONFIG_KPROBES
78152diff --git a/include/linux/completion.h b/include/linux/completion.h
78153index 5d5aaae..0ea9b84 100644
78154--- a/include/linux/completion.h
78155+++ b/include/linux/completion.h
78156@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
78157
78158 extern void wait_for_completion(struct completion *);
78159 extern void wait_for_completion_io(struct completion *);
78160-extern int wait_for_completion_interruptible(struct completion *x);
78161-extern int wait_for_completion_killable(struct completion *x);
78162+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
78163+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
78164 extern unsigned long wait_for_completion_timeout(struct completion *x,
78165- unsigned long timeout);
78166+ unsigned long timeout) __intentional_overflow(-1);
78167 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
78168- unsigned long timeout);
78169+ unsigned long timeout) __intentional_overflow(-1);
78170 extern long wait_for_completion_interruptible_timeout(
78171- struct completion *x, unsigned long timeout);
78172+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78173 extern long wait_for_completion_killable_timeout(
78174- struct completion *x, unsigned long timeout);
78175+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78176 extern bool try_wait_for_completion(struct completion *x);
78177 extern bool completion_done(struct completion *x);
78178
78179diff --git a/include/linux/configfs.h b/include/linux/configfs.h
78180index 34025df..d94bbbc 100644
78181--- a/include/linux/configfs.h
78182+++ b/include/linux/configfs.h
78183@@ -125,7 +125,7 @@ struct configfs_attribute {
78184 const char *ca_name;
78185 struct module *ca_owner;
78186 umode_t ca_mode;
78187-};
78188+} __do_const;
78189
78190 /*
78191 * Users often need to create attribute structures for their configurable
78192diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
78193index 4d89e0e..5281847 100644
78194--- a/include/linux/cpufreq.h
78195+++ b/include/linux/cpufreq.h
78196@@ -191,6 +191,7 @@ struct global_attr {
78197 ssize_t (*store)(struct kobject *a, struct attribute *b,
78198 const char *c, size_t count);
78199 };
78200+typedef struct global_attr __no_const global_attr_no_const;
78201
78202 #define define_one_global_ro(_name) \
78203 static struct global_attr _name = \
78204@@ -232,7 +233,7 @@ struct cpufreq_driver {
78205 bool boost_supported;
78206 bool boost_enabled;
78207 int (*set_boost) (int state);
78208-};
78209+} __do_const;
78210
78211 /* flags */
78212 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
78213diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
78214index 50fcbb0..9d2dbd9 100644
78215--- a/include/linux/cpuidle.h
78216+++ b/include/linux/cpuidle.h
78217@@ -50,7 +50,8 @@ struct cpuidle_state {
78218 int index);
78219
78220 int (*enter_dead) (struct cpuidle_device *dev, int index);
78221-};
78222+} __do_const;
78223+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
78224
78225 /* Idle State Flags */
78226 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
78227@@ -192,7 +193,7 @@ struct cpuidle_governor {
78228 void (*reflect) (struct cpuidle_device *dev, int index);
78229
78230 struct module *owner;
78231-};
78232+} __do_const;
78233
78234 #ifdef CONFIG_CPU_IDLE
78235 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
78236diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
78237index d08e4d2..95fad61 100644
78238--- a/include/linux/cpumask.h
78239+++ b/include/linux/cpumask.h
78240@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78241 }
78242
78243 /* Valid inputs for n are -1 and 0. */
78244-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78245+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78246 {
78247 return n+1;
78248 }
78249
78250-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78251+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78252 {
78253 return n+1;
78254 }
78255
78256-static inline unsigned int cpumask_next_and(int n,
78257+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
78258 const struct cpumask *srcp,
78259 const struct cpumask *andp)
78260 {
78261@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78262 *
78263 * Returns >= nr_cpu_ids if no further cpus set.
78264 */
78265-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78266+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78267 {
78268 /* -1 is a legal arg here. */
78269 if (n != -1)
78270@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78271 *
78272 * Returns >= nr_cpu_ids if no further cpus unset.
78273 */
78274-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78275+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78276 {
78277 /* -1 is a legal arg here. */
78278 if (n != -1)
78279@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78280 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
78281 }
78282
78283-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
78284+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
78285 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
78286
78287 /**
78288diff --git a/include/linux/cred.h b/include/linux/cred.h
78289index 04421e8..117e17a 100644
78290--- a/include/linux/cred.h
78291+++ b/include/linux/cred.h
78292@@ -35,7 +35,7 @@ struct group_info {
78293 int nblocks;
78294 kgid_t small_block[NGROUPS_SMALL];
78295 kgid_t *blocks[0];
78296-};
78297+} __randomize_layout;
78298
78299 /**
78300 * get_group_info - Get a reference to a group info structure
78301@@ -136,7 +136,7 @@ struct cred {
78302 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
78303 struct group_info *group_info; /* supplementary groups for euid/fsgid */
78304 struct rcu_head rcu; /* RCU deletion hook */
78305-};
78306+} __randomize_layout;
78307
78308 extern void __put_cred(struct cred *);
78309 extern void exit_creds(struct task_struct *);
78310@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78311 static inline void validate_process_creds(void)
78312 {
78313 }
78314+static inline void validate_task_creds(struct task_struct *task)
78315+{
78316+}
78317 #endif
78318
78319 /**
78320diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78321index b92eadf..b4ecdc1 100644
78322--- a/include/linux/crypto.h
78323+++ b/include/linux/crypto.h
78324@@ -373,7 +373,7 @@ struct cipher_tfm {
78325 const u8 *key, unsigned int keylen);
78326 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78327 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78328-};
78329+} __no_const;
78330
78331 struct hash_tfm {
78332 int (*init)(struct hash_desc *desc);
78333@@ -394,13 +394,13 @@ struct compress_tfm {
78334 int (*cot_decompress)(struct crypto_tfm *tfm,
78335 const u8 *src, unsigned int slen,
78336 u8 *dst, unsigned int *dlen);
78337-};
78338+} __no_const;
78339
78340 struct rng_tfm {
78341 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78342 unsigned int dlen);
78343 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78344-};
78345+} __no_const;
78346
78347 #define crt_ablkcipher crt_u.ablkcipher
78348 #define crt_aead crt_u.aead
78349diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78350index 653589e..4ef254a 100644
78351--- a/include/linux/ctype.h
78352+++ b/include/linux/ctype.h
78353@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78354 * Fast implementation of tolower() for internal usage. Do not use in your
78355 * code.
78356 */
78357-static inline char _tolower(const char c)
78358+static inline unsigned char _tolower(const unsigned char c)
78359 {
78360 return c | 0x20;
78361 }
78362diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78363index bf72e9a..4ca7927 100644
78364--- a/include/linux/dcache.h
78365+++ b/include/linux/dcache.h
78366@@ -133,7 +133,7 @@ struct dentry {
78367 } d_u;
78368 struct list_head d_subdirs; /* our children */
78369 struct hlist_node d_alias; /* inode alias list */
78370-};
78371+} __randomize_layout;
78372
78373 /*
78374 * dentry->d_lock spinlock nesting subclasses:
78375diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78376index 7925bf0..d5143d2 100644
78377--- a/include/linux/decompress/mm.h
78378+++ b/include/linux/decompress/mm.h
78379@@ -77,7 +77,7 @@ static void free(void *where)
78380 * warnings when not needed (indeed large_malloc / large_free are not
78381 * needed by inflate */
78382
78383-#define malloc(a) kmalloc(a, GFP_KERNEL)
78384+#define malloc(a) kmalloc((a), GFP_KERNEL)
78385 #define free(a) kfree(a)
78386
78387 #define large_malloc(a) vmalloc(a)
78388diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78389index d48dc00..211ee54 100644
78390--- a/include/linux/devfreq.h
78391+++ b/include/linux/devfreq.h
78392@@ -114,7 +114,7 @@ struct devfreq_governor {
78393 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78394 int (*event_handler)(struct devfreq *devfreq,
78395 unsigned int event, void *data);
78396-};
78397+} __do_const;
78398
78399 /**
78400 * struct devfreq - Device devfreq structure
78401diff --git a/include/linux/device.h b/include/linux/device.h
78402index 952b010..d5b7691 100644
78403--- a/include/linux/device.h
78404+++ b/include/linux/device.h
78405@@ -310,7 +310,7 @@ struct subsys_interface {
78406 struct list_head node;
78407 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78408 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78409-};
78410+} __do_const;
78411
78412 int subsys_interface_register(struct subsys_interface *sif);
78413 void subsys_interface_unregister(struct subsys_interface *sif);
78414@@ -506,7 +506,7 @@ struct device_type {
78415 void (*release)(struct device *dev);
78416
78417 const struct dev_pm_ops *pm;
78418-};
78419+} __do_const;
78420
78421 /* interface for exporting device attributes */
78422 struct device_attribute {
78423@@ -516,11 +516,12 @@ struct device_attribute {
78424 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78425 const char *buf, size_t count);
78426 };
78427+typedef struct device_attribute __no_const device_attribute_no_const;
78428
78429 struct dev_ext_attribute {
78430 struct device_attribute attr;
78431 void *var;
78432-};
78433+} __do_const;
78434
78435 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78436 char *buf);
78437diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78438index fd4aee2..1f28db9 100644
78439--- a/include/linux/dma-mapping.h
78440+++ b/include/linux/dma-mapping.h
78441@@ -54,7 +54,7 @@ struct dma_map_ops {
78442 u64 (*get_required_mask)(struct device *dev);
78443 #endif
78444 int is_phys;
78445-};
78446+} __do_const;
78447
78448 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78449
78450diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78451index c5c92d5..6a5c2b2 100644
78452--- a/include/linux/dmaengine.h
78453+++ b/include/linux/dmaengine.h
78454@@ -1150,9 +1150,9 @@ struct dma_pinned_list {
78455 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78456 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78457
78458-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78459+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78460 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78461-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78462+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78463 struct dma_pinned_list *pinned_list, struct page *page,
78464 unsigned int offset, size_t len);
78465
78466diff --git a/include/linux/efi.h b/include/linux/efi.h
78467index 0a819e7..8ed47f1 100644
78468--- a/include/linux/efi.h
78469+++ b/include/linux/efi.h
78470@@ -768,6 +768,7 @@ struct efivar_operations {
78471 efi_set_variable_t *set_variable;
78472 efi_query_variable_store_t *query_variable_store;
78473 };
78474+typedef struct efivar_operations __no_const efivar_operations_no_const;
78475
78476 struct efivars {
78477 /*
78478diff --git a/include/linux/elf.h b/include/linux/elf.h
78479index 67a5fa7..b817372 100644
78480--- a/include/linux/elf.h
78481+++ b/include/linux/elf.h
78482@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78483 #define elf_note elf32_note
78484 #define elf_addr_t Elf32_Off
78485 #define Elf_Half Elf32_Half
78486+#define elf_dyn Elf32_Dyn
78487
78488 #else
78489
78490@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78491 #define elf_note elf64_note
78492 #define elf_addr_t Elf64_Off
78493 #define Elf_Half Elf64_Half
78494+#define elf_dyn Elf64_Dyn
78495
78496 #endif
78497
78498diff --git a/include/linux/err.h b/include/linux/err.h
78499index 15f92e0..e825a8e 100644
78500--- a/include/linux/err.h
78501+++ b/include/linux/err.h
78502@@ -19,12 +19,12 @@
78503
78504 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78505
78506-static inline void * __must_check ERR_PTR(long error)
78507+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78508 {
78509 return (void *) error;
78510 }
78511
78512-static inline long __must_check PTR_ERR(__force const void *ptr)
78513+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78514 {
78515 return (long) ptr;
78516 }
78517diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78518index 21c59af..6057a03 100644
78519--- a/include/linux/extcon.h
78520+++ b/include/linux/extcon.h
78521@@ -135,7 +135,7 @@ struct extcon_dev {
78522 /* /sys/class/extcon/.../mutually_exclusive/... */
78523 struct attribute_group attr_g_muex;
78524 struct attribute **attrs_muex;
78525- struct device_attribute *d_attrs_muex;
78526+ device_attribute_no_const *d_attrs_muex;
78527 };
78528
78529 /**
78530diff --git a/include/linux/fb.h b/include/linux/fb.h
78531index fe6ac95..898d41d 100644
78532--- a/include/linux/fb.h
78533+++ b/include/linux/fb.h
78534@@ -304,7 +304,7 @@ struct fb_ops {
78535 /* called at KDB enter and leave time to prepare the console */
78536 int (*fb_debug_enter)(struct fb_info *info);
78537 int (*fb_debug_leave)(struct fb_info *info);
78538-};
78539+} __do_const;
78540
78541 #ifdef CONFIG_FB_TILEBLITTING
78542 #define FB_TILE_CURSOR_NONE 0
78543diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78544index 70e8e21..1939916 100644
78545--- a/include/linux/fdtable.h
78546+++ b/include/linux/fdtable.h
78547@@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78548 void put_files_struct(struct files_struct *fs);
78549 void reset_files_struct(struct files_struct *);
78550 int unshare_files(struct files_struct **);
78551-struct files_struct *dup_fd(struct files_struct *, int *);
78552+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78553 void do_close_on_exec(struct files_struct *);
78554 int iterate_fd(struct files_struct *, unsigned,
78555 int (*)(const void *, struct file *, unsigned),
78556diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78557index 8293262..2b3b8bd 100644
78558--- a/include/linux/frontswap.h
78559+++ b/include/linux/frontswap.h
78560@@ -11,7 +11,7 @@ struct frontswap_ops {
78561 int (*load)(unsigned, pgoff_t, struct page *);
78562 void (*invalidate_page)(unsigned, pgoff_t);
78563 void (*invalidate_area)(unsigned);
78564-};
78565+} __no_const;
78566
78567 extern bool frontswap_enabled;
78568 extern struct frontswap_ops *
78569diff --git a/include/linux/fs.h b/include/linux/fs.h
78570index 23b2a35..8764ab7 100644
78571--- a/include/linux/fs.h
78572+++ b/include/linux/fs.h
78573@@ -426,7 +426,7 @@ struct address_space {
78574 spinlock_t private_lock; /* for use by the address_space */
78575 struct list_head private_list; /* ditto */
78576 void *private_data; /* ditto */
78577-} __attribute__((aligned(sizeof(long))));
78578+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78579 /*
78580 * On most architectures that alignment is already the case; but
78581 * must be enforced here for CRIS, to let the least significant bit
78582@@ -469,7 +469,7 @@ struct block_device {
78583 int bd_fsfreeze_count;
78584 /* Mutex for freeze */
78585 struct mutex bd_fsfreeze_mutex;
78586-};
78587+} __randomize_layout;
78588
78589 /*
78590 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78591@@ -613,7 +613,7 @@ struct inode {
78592 atomic_t i_readcount; /* struct files open RO */
78593 #endif
78594 void *i_private; /* fs or device private pointer */
78595-};
78596+} __randomize_layout;
78597
78598 static inline int inode_unhashed(struct inode *inode)
78599 {
78600@@ -812,7 +812,7 @@ struct file {
78601 #ifdef CONFIG_DEBUG_WRITECOUNT
78602 unsigned long f_mnt_write_state;
78603 #endif
78604-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78605+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78606
78607 struct file_handle {
78608 __u32 handle_bytes;
78609@@ -982,7 +982,7 @@ struct file_lock {
78610 int state; /* state of grant or error if -ve */
78611 } afs;
78612 } fl_u;
78613-};
78614+} __randomize_layout;
78615
78616 /* The following constant reflects the upper bound of the file/locking space */
78617 #ifndef OFFSET_MAX
78618@@ -1329,7 +1329,7 @@ struct super_block {
78619 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78620 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78621 struct rcu_head rcu;
78622-};
78623+} __randomize_layout;
78624
78625 extern struct timespec current_fs_time(struct super_block *sb);
78626
78627@@ -1551,7 +1551,8 @@ struct file_operations {
78628 long (*fallocate)(struct file *file, int mode, loff_t offset,
78629 loff_t len);
78630 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78631-};
78632+} __do_const __randomize_layout;
78633+typedef struct file_operations __no_const file_operations_no_const;
78634
78635 struct inode_operations {
78636 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78637@@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
78638 return !IS_DEADDIR(inode);
78639 }
78640
78641+static inline bool is_sidechannel_device(const struct inode *inode)
78642+{
78643+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78644+ umode_t mode = inode->i_mode;
78645+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78646+#else
78647+ return false;
78648+#endif
78649+}
78650+
78651 #endif /* _LINUX_FS_H */
78652diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78653index 0efc3e6..fd23610 100644
78654--- a/include/linux/fs_struct.h
78655+++ b/include/linux/fs_struct.h
78656@@ -6,13 +6,13 @@
78657 #include <linux/seqlock.h>
78658
78659 struct fs_struct {
78660- int users;
78661+ atomic_t users;
78662 spinlock_t lock;
78663 seqcount_t seq;
78664 int umask;
78665 int in_exec;
78666 struct path root, pwd;
78667-};
78668+} __randomize_layout;
78669
78670 extern struct kmem_cache *fs_cachep;
78671
78672diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78673index 7714849..a4a5c7a 100644
78674--- a/include/linux/fscache-cache.h
78675+++ b/include/linux/fscache-cache.h
78676@@ -113,7 +113,7 @@ struct fscache_operation {
78677 fscache_operation_release_t release;
78678 };
78679
78680-extern atomic_t fscache_op_debug_id;
78681+extern atomic_unchecked_t fscache_op_debug_id;
78682 extern void fscache_op_work_func(struct work_struct *work);
78683
78684 extern void fscache_enqueue_operation(struct fscache_operation *);
78685@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78686 INIT_WORK(&op->work, fscache_op_work_func);
78687 atomic_set(&op->usage, 1);
78688 op->state = FSCACHE_OP_ST_INITIALISED;
78689- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78690+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78691 op->processor = processor;
78692 op->release = release;
78693 INIT_LIST_HEAD(&op->pend_link);
78694diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78695index 115bb81..e7b812b 100644
78696--- a/include/linux/fscache.h
78697+++ b/include/linux/fscache.h
78698@@ -152,7 +152,7 @@ struct fscache_cookie_def {
78699 * - this is mandatory for any object that may have data
78700 */
78701 void (*now_uncached)(void *cookie_netfs_data);
78702-};
78703+} __do_const;
78704
78705 /*
78706 * fscache cached network filesystem type
78707diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78708index 1c804b0..1432c2b 100644
78709--- a/include/linux/fsnotify.h
78710+++ b/include/linux/fsnotify.h
78711@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78712 struct inode *inode = file_inode(file);
78713 __u32 mask = FS_ACCESS;
78714
78715+ if (is_sidechannel_device(inode))
78716+ return;
78717+
78718 if (S_ISDIR(inode->i_mode))
78719 mask |= FS_ISDIR;
78720
78721@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78722 struct inode *inode = file_inode(file);
78723 __u32 mask = FS_MODIFY;
78724
78725+ if (is_sidechannel_device(inode))
78726+ return;
78727+
78728 if (S_ISDIR(inode->i_mode))
78729 mask |= FS_ISDIR;
78730
78731@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78732 */
78733 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78734 {
78735- return kstrdup(name, GFP_KERNEL);
78736+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78737 }
78738
78739 /*
78740diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78741index 9f3c275..8bdff5d 100644
78742--- a/include/linux/genhd.h
78743+++ b/include/linux/genhd.h
78744@@ -194,7 +194,7 @@ struct gendisk {
78745 struct kobject *slave_dir;
78746
78747 struct timer_rand_state *random;
78748- atomic_t sync_io; /* RAID */
78749+ atomic_unchecked_t sync_io; /* RAID */
78750 struct disk_events *ev;
78751 #ifdef CONFIG_BLK_DEV_INTEGRITY
78752 struct blk_integrity *integrity;
78753@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78754 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78755
78756 /* drivers/char/random.c */
78757-extern void add_disk_randomness(struct gendisk *disk);
78758+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78759 extern void rand_initialize_disk(struct gendisk *disk);
78760
78761 static inline sector_t get_start_sect(struct block_device *bdev)
78762diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78763index c0894dd..2fbf10c 100644
78764--- a/include/linux/genl_magic_func.h
78765+++ b/include/linux/genl_magic_func.h
78766@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78767 },
78768
78769 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78770-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78771+static struct genl_ops ZZZ_genl_ops[] = {
78772 #include GENL_MAGIC_INCLUDE_FILE
78773 };
78774
78775diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78776index 39b81dc..819dc51 100644
78777--- a/include/linux/gfp.h
78778+++ b/include/linux/gfp.h
78779@@ -36,6 +36,13 @@ struct vm_area_struct;
78780 #define ___GFP_NO_KSWAPD 0x400000u
78781 #define ___GFP_OTHER_NODE 0x800000u
78782 #define ___GFP_WRITE 0x1000000u
78783+
78784+#ifdef CONFIG_PAX_USERCOPY_SLABS
78785+#define ___GFP_USERCOPY 0x2000000u
78786+#else
78787+#define ___GFP_USERCOPY 0
78788+#endif
78789+
78790 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78791
78792 /*
78793@@ -93,6 +100,7 @@ struct vm_area_struct;
78794 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78795 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78796 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78797+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78798
78799 /*
78800 * This may seem redundant, but it's a way of annotating false positives vs.
78801@@ -100,7 +108,7 @@ struct vm_area_struct;
78802 */
78803 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78804
78805-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78806+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78807 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78808
78809 /* This equals 0, but use constants in case they ever change */
78810@@ -158,6 +166,8 @@ struct vm_area_struct;
78811 /* 4GB DMA on some platforms */
78812 #define GFP_DMA32 __GFP_DMA32
78813
78814+#define GFP_USERCOPY __GFP_USERCOPY
78815+
78816 /* Convert GFP flags to their corresponding migrate type */
78817 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78818 {
78819diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78820new file mode 100644
78821index 0000000..edb2cb6
78822--- /dev/null
78823+++ b/include/linux/gracl.h
78824@@ -0,0 +1,340 @@
78825+#ifndef GR_ACL_H
78826+#define GR_ACL_H
78827+
78828+#include <linux/grdefs.h>
78829+#include <linux/resource.h>
78830+#include <linux/capability.h>
78831+#include <linux/dcache.h>
78832+#include <asm/resource.h>
78833+
78834+/* Major status information */
78835+
78836+#define GR_VERSION "grsecurity 3.0"
78837+#define GRSECURITY_VERSION 0x3000
78838+
78839+enum {
78840+ GR_SHUTDOWN = 0,
78841+ GR_ENABLE = 1,
78842+ GR_SPROLE = 2,
78843+ GR_OLDRELOAD = 3,
78844+ GR_SEGVMOD = 4,
78845+ GR_STATUS = 5,
78846+ GR_UNSPROLE = 6,
78847+ GR_PASSSET = 7,
78848+ GR_SPROLEPAM = 8,
78849+ GR_RELOAD = 9,
78850+};
78851+
78852+/* Password setup definitions
78853+ * kernel/grhash.c */
78854+enum {
78855+ GR_PW_LEN = 128,
78856+ GR_SALT_LEN = 16,
78857+ GR_SHA_LEN = 32,
78858+};
78859+
78860+enum {
78861+ GR_SPROLE_LEN = 64,
78862+};
78863+
78864+enum {
78865+ GR_NO_GLOB = 0,
78866+ GR_REG_GLOB,
78867+ GR_CREATE_GLOB
78868+};
78869+
78870+#define GR_NLIMITS 32
78871+
78872+/* Begin Data Structures */
78873+
78874+struct sprole_pw {
78875+ unsigned char *rolename;
78876+ unsigned char salt[GR_SALT_LEN];
78877+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78878+};
78879+
78880+struct name_entry {
78881+ __u32 key;
78882+ ino_t inode;
78883+ dev_t device;
78884+ char *name;
78885+ __u16 len;
78886+ __u8 deleted;
78887+ struct name_entry *prev;
78888+ struct name_entry *next;
78889+};
78890+
78891+struct inodev_entry {
78892+ struct name_entry *nentry;
78893+ struct inodev_entry *prev;
78894+ struct inodev_entry *next;
78895+};
78896+
78897+struct acl_role_db {
78898+ struct acl_role_label **r_hash;
78899+ __u32 r_size;
78900+};
78901+
78902+struct inodev_db {
78903+ struct inodev_entry **i_hash;
78904+ __u32 i_size;
78905+};
78906+
78907+struct name_db {
78908+ struct name_entry **n_hash;
78909+ __u32 n_size;
78910+};
78911+
78912+struct crash_uid {
78913+ uid_t uid;
78914+ unsigned long expires;
78915+};
78916+
78917+struct gr_hash_struct {
78918+ void **table;
78919+ void **nametable;
78920+ void *first;
78921+ __u32 table_size;
78922+ __u32 used_size;
78923+ int type;
78924+};
78925+
78926+/* Userspace Grsecurity ACL data structures */
78927+
78928+struct acl_subject_label {
78929+ char *filename;
78930+ ino_t inode;
78931+ dev_t device;
78932+ __u32 mode;
78933+ kernel_cap_t cap_mask;
78934+ kernel_cap_t cap_lower;
78935+ kernel_cap_t cap_invert_audit;
78936+
78937+ struct rlimit res[GR_NLIMITS];
78938+ __u32 resmask;
78939+
78940+ __u8 user_trans_type;
78941+ __u8 group_trans_type;
78942+ uid_t *user_transitions;
78943+ gid_t *group_transitions;
78944+ __u16 user_trans_num;
78945+ __u16 group_trans_num;
78946+
78947+ __u32 sock_families[2];
78948+ __u32 ip_proto[8];
78949+ __u32 ip_type;
78950+ struct acl_ip_label **ips;
78951+ __u32 ip_num;
78952+ __u32 inaddr_any_override;
78953+
78954+ __u32 crashes;
78955+ unsigned long expires;
78956+
78957+ struct acl_subject_label *parent_subject;
78958+ struct gr_hash_struct *hash;
78959+ struct acl_subject_label *prev;
78960+ struct acl_subject_label *next;
78961+
78962+ struct acl_object_label **obj_hash;
78963+ __u32 obj_hash_size;
78964+ __u16 pax_flags;
78965+};
78966+
78967+struct role_allowed_ip {
78968+ __u32 addr;
78969+ __u32 netmask;
78970+
78971+ struct role_allowed_ip *prev;
78972+ struct role_allowed_ip *next;
78973+};
78974+
78975+struct role_transition {
78976+ char *rolename;
78977+
78978+ struct role_transition *prev;
78979+ struct role_transition *next;
78980+};
78981+
78982+struct acl_role_label {
78983+ char *rolename;
78984+ uid_t uidgid;
78985+ __u16 roletype;
78986+
78987+ __u16 auth_attempts;
78988+ unsigned long expires;
78989+
78990+ struct acl_subject_label *root_label;
78991+ struct gr_hash_struct *hash;
78992+
78993+ struct acl_role_label *prev;
78994+ struct acl_role_label *next;
78995+
78996+ struct role_transition *transitions;
78997+ struct role_allowed_ip *allowed_ips;
78998+ uid_t *domain_children;
78999+ __u16 domain_child_num;
79000+
79001+ umode_t umask;
79002+
79003+ struct acl_subject_label **subj_hash;
79004+ __u32 subj_hash_size;
79005+};
79006+
79007+struct user_acl_role_db {
79008+ struct acl_role_label **r_table;
79009+ __u32 num_pointers; /* Number of allocations to track */
79010+ __u32 num_roles; /* Number of roles */
79011+ __u32 num_domain_children; /* Number of domain children */
79012+ __u32 num_subjects; /* Number of subjects */
79013+ __u32 num_objects; /* Number of objects */
79014+};
79015+
79016+struct acl_object_label {
79017+ char *filename;
79018+ ino_t inode;
79019+ dev_t device;
79020+ __u32 mode;
79021+
79022+ struct acl_subject_label *nested;
79023+ struct acl_object_label *globbed;
79024+
79025+ /* next two structures not used */
79026+
79027+ struct acl_object_label *prev;
79028+ struct acl_object_label *next;
79029+};
79030+
79031+struct acl_ip_label {
79032+ char *iface;
79033+ __u32 addr;
79034+ __u32 netmask;
79035+ __u16 low, high;
79036+ __u8 mode;
79037+ __u32 type;
79038+ __u32 proto[8];
79039+
79040+ /* next two structures not used */
79041+
79042+ struct acl_ip_label *prev;
79043+ struct acl_ip_label *next;
79044+};
79045+
79046+struct gr_arg {
79047+ struct user_acl_role_db role_db;
79048+ unsigned char pw[GR_PW_LEN];
79049+ unsigned char salt[GR_SALT_LEN];
79050+ unsigned char sum[GR_SHA_LEN];
79051+ unsigned char sp_role[GR_SPROLE_LEN];
79052+ struct sprole_pw *sprole_pws;
79053+ dev_t segv_device;
79054+ ino_t segv_inode;
79055+ uid_t segv_uid;
79056+ __u16 num_sprole_pws;
79057+ __u16 mode;
79058+};
79059+
79060+struct gr_arg_wrapper {
79061+ struct gr_arg *arg;
79062+ __u32 version;
79063+ __u32 size;
79064+};
79065+
79066+struct subject_map {
79067+ struct acl_subject_label *user;
79068+ struct acl_subject_label *kernel;
79069+ struct subject_map *prev;
79070+ struct subject_map *next;
79071+};
79072+
79073+struct acl_subj_map_db {
79074+ struct subject_map **s_hash;
79075+ __u32 s_size;
79076+};
79077+
79078+struct gr_policy_state {
79079+ struct sprole_pw **acl_special_roles;
79080+ __u16 num_sprole_pws;
79081+ struct acl_role_label *kernel_role;
79082+ struct acl_role_label *role_list;
79083+ struct acl_role_label *default_role;
79084+ struct acl_role_db acl_role_set;
79085+ struct acl_subj_map_db subj_map_set;
79086+ struct name_db name_set;
79087+ struct inodev_db inodev_set;
79088+};
79089+
79090+struct gr_alloc_state {
79091+ unsigned long alloc_stack_next;
79092+ unsigned long alloc_stack_size;
79093+ void **alloc_stack;
79094+};
79095+
79096+struct gr_reload_state {
79097+ struct gr_policy_state oldpolicy;
79098+ struct gr_alloc_state oldalloc;
79099+ struct gr_policy_state newpolicy;
79100+ struct gr_alloc_state newalloc;
79101+ struct gr_policy_state *oldpolicy_ptr;
79102+ struct gr_alloc_state *oldalloc_ptr;
79103+ unsigned char oldmode;
79104+};
79105+
79106+/* End Data Structures Section */
79107+
79108+/* Hash functions generated by empirical testing by Brad Spengler
79109+ Makes good use of the low bits of the inode. Generally 0-1 times
79110+ in loop for successful match. 0-3 for unsuccessful match.
79111+ Shift/add algorithm with modulus of table size and an XOR*/
79112+
79113+static __inline__ unsigned int
79114+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
79115+{
79116+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
79117+}
79118+
79119+ static __inline__ unsigned int
79120+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
79121+{
79122+ return ((const unsigned long)userp % sz);
79123+}
79124+
79125+static __inline__ unsigned int
79126+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
79127+{
79128+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
79129+}
79130+
79131+static __inline__ unsigned int
79132+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
79133+{
79134+ return full_name_hash((const unsigned char *)name, len) % sz;
79135+}
79136+
79137+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
79138+ subj = NULL; \
79139+ iter = 0; \
79140+ while (iter < role->subj_hash_size) { \
79141+ if (subj == NULL) \
79142+ subj = role->subj_hash[iter]; \
79143+ if (subj == NULL) { \
79144+ iter++; \
79145+ continue; \
79146+ }
79147+
79148+#define FOR_EACH_SUBJECT_END(subj,iter) \
79149+ subj = subj->next; \
79150+ if (subj == NULL) \
79151+ iter++; \
79152+ }
79153+
79154+
79155+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
79156+ subj = role->hash->first; \
79157+ while (subj != NULL) {
79158+
79159+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
79160+ subj = subj->next; \
79161+ }
79162+
79163+#endif
79164+
79165diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
79166new file mode 100644
79167index 0000000..33ebd1f
79168--- /dev/null
79169+++ b/include/linux/gracl_compat.h
79170@@ -0,0 +1,156 @@
79171+#ifndef GR_ACL_COMPAT_H
79172+#define GR_ACL_COMPAT_H
79173+
79174+#include <linux/resource.h>
79175+#include <asm/resource.h>
79176+
79177+struct sprole_pw_compat {
79178+ compat_uptr_t rolename;
79179+ unsigned char salt[GR_SALT_LEN];
79180+ unsigned char sum[GR_SHA_LEN];
79181+};
79182+
79183+struct gr_hash_struct_compat {
79184+ compat_uptr_t table;
79185+ compat_uptr_t nametable;
79186+ compat_uptr_t first;
79187+ __u32 table_size;
79188+ __u32 used_size;
79189+ int type;
79190+};
79191+
79192+struct acl_subject_label_compat {
79193+ compat_uptr_t filename;
79194+ compat_ino_t inode;
79195+ __u32 device;
79196+ __u32 mode;
79197+ kernel_cap_t cap_mask;
79198+ kernel_cap_t cap_lower;
79199+ kernel_cap_t cap_invert_audit;
79200+
79201+ struct compat_rlimit res[GR_NLIMITS];
79202+ __u32 resmask;
79203+
79204+ __u8 user_trans_type;
79205+ __u8 group_trans_type;
79206+ compat_uptr_t user_transitions;
79207+ compat_uptr_t group_transitions;
79208+ __u16 user_trans_num;
79209+ __u16 group_trans_num;
79210+
79211+ __u32 sock_families[2];
79212+ __u32 ip_proto[8];
79213+ __u32 ip_type;
79214+ compat_uptr_t ips;
79215+ __u32 ip_num;
79216+ __u32 inaddr_any_override;
79217+
79218+ __u32 crashes;
79219+ compat_ulong_t expires;
79220+
79221+ compat_uptr_t parent_subject;
79222+ compat_uptr_t hash;
79223+ compat_uptr_t prev;
79224+ compat_uptr_t next;
79225+
79226+ compat_uptr_t obj_hash;
79227+ __u32 obj_hash_size;
79228+ __u16 pax_flags;
79229+};
79230+
79231+struct role_allowed_ip_compat {
79232+ __u32 addr;
79233+ __u32 netmask;
79234+
79235+ compat_uptr_t prev;
79236+ compat_uptr_t next;
79237+};
79238+
79239+struct role_transition_compat {
79240+ compat_uptr_t rolename;
79241+
79242+ compat_uptr_t prev;
79243+ compat_uptr_t next;
79244+};
79245+
79246+struct acl_role_label_compat {
79247+ compat_uptr_t rolename;
79248+ uid_t uidgid;
79249+ __u16 roletype;
79250+
79251+ __u16 auth_attempts;
79252+ compat_ulong_t expires;
79253+
79254+ compat_uptr_t root_label;
79255+ compat_uptr_t hash;
79256+
79257+ compat_uptr_t prev;
79258+ compat_uptr_t next;
79259+
79260+ compat_uptr_t transitions;
79261+ compat_uptr_t allowed_ips;
79262+ compat_uptr_t domain_children;
79263+ __u16 domain_child_num;
79264+
79265+ umode_t umask;
79266+
79267+ compat_uptr_t subj_hash;
79268+ __u32 subj_hash_size;
79269+};
79270+
79271+struct user_acl_role_db_compat {
79272+ compat_uptr_t r_table;
79273+ __u32 num_pointers;
79274+ __u32 num_roles;
79275+ __u32 num_domain_children;
79276+ __u32 num_subjects;
79277+ __u32 num_objects;
79278+};
79279+
79280+struct acl_object_label_compat {
79281+ compat_uptr_t filename;
79282+ compat_ino_t inode;
79283+ __u32 device;
79284+ __u32 mode;
79285+
79286+ compat_uptr_t nested;
79287+ compat_uptr_t globbed;
79288+
79289+ compat_uptr_t prev;
79290+ compat_uptr_t next;
79291+};
79292+
79293+struct acl_ip_label_compat {
79294+ compat_uptr_t iface;
79295+ __u32 addr;
79296+ __u32 netmask;
79297+ __u16 low, high;
79298+ __u8 mode;
79299+ __u32 type;
79300+ __u32 proto[8];
79301+
79302+ compat_uptr_t prev;
79303+ compat_uptr_t next;
79304+};
79305+
79306+struct gr_arg_compat {
79307+ struct user_acl_role_db_compat role_db;
79308+ unsigned char pw[GR_PW_LEN];
79309+ unsigned char salt[GR_SALT_LEN];
79310+ unsigned char sum[GR_SHA_LEN];
79311+ unsigned char sp_role[GR_SPROLE_LEN];
79312+ compat_uptr_t sprole_pws;
79313+ __u32 segv_device;
79314+ compat_ino_t segv_inode;
79315+ uid_t segv_uid;
79316+ __u16 num_sprole_pws;
79317+ __u16 mode;
79318+};
79319+
79320+struct gr_arg_wrapper_compat {
79321+ compat_uptr_t arg;
79322+ __u32 version;
79323+ __u32 size;
79324+};
79325+
79326+#endif
79327diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79328new file mode 100644
79329index 0000000..323ecf2
79330--- /dev/null
79331+++ b/include/linux/gralloc.h
79332@@ -0,0 +1,9 @@
79333+#ifndef __GRALLOC_H
79334+#define __GRALLOC_H
79335+
79336+void acl_free_all(void);
79337+int acl_alloc_stack_init(unsigned long size);
79338+void *acl_alloc(unsigned long len);
79339+void *acl_alloc_num(unsigned long num, unsigned long len);
79340+
79341+#endif
79342diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79343new file mode 100644
79344index 0000000..be66033
79345--- /dev/null
79346+++ b/include/linux/grdefs.h
79347@@ -0,0 +1,140 @@
79348+#ifndef GRDEFS_H
79349+#define GRDEFS_H
79350+
79351+/* Begin grsecurity status declarations */
79352+
79353+enum {
79354+ GR_READY = 0x01,
79355+ GR_STATUS_INIT = 0x00 // disabled state
79356+};
79357+
79358+/* Begin ACL declarations */
79359+
79360+/* Role flags */
79361+
79362+enum {
79363+ GR_ROLE_USER = 0x0001,
79364+ GR_ROLE_GROUP = 0x0002,
79365+ GR_ROLE_DEFAULT = 0x0004,
79366+ GR_ROLE_SPECIAL = 0x0008,
79367+ GR_ROLE_AUTH = 0x0010,
79368+ GR_ROLE_NOPW = 0x0020,
79369+ GR_ROLE_GOD = 0x0040,
79370+ GR_ROLE_LEARN = 0x0080,
79371+ GR_ROLE_TPE = 0x0100,
79372+ GR_ROLE_DOMAIN = 0x0200,
79373+ GR_ROLE_PAM = 0x0400,
79374+ GR_ROLE_PERSIST = 0x0800
79375+};
79376+
79377+/* ACL Subject and Object mode flags */
79378+enum {
79379+ GR_DELETED = 0x80000000
79380+};
79381+
79382+/* ACL Object-only mode flags */
79383+enum {
79384+ GR_READ = 0x00000001,
79385+ GR_APPEND = 0x00000002,
79386+ GR_WRITE = 0x00000004,
79387+ GR_EXEC = 0x00000008,
79388+ GR_FIND = 0x00000010,
79389+ GR_INHERIT = 0x00000020,
79390+ GR_SETID = 0x00000040,
79391+ GR_CREATE = 0x00000080,
79392+ GR_DELETE = 0x00000100,
79393+ GR_LINK = 0x00000200,
79394+ GR_AUDIT_READ = 0x00000400,
79395+ GR_AUDIT_APPEND = 0x00000800,
79396+ GR_AUDIT_WRITE = 0x00001000,
79397+ GR_AUDIT_EXEC = 0x00002000,
79398+ GR_AUDIT_FIND = 0x00004000,
79399+ GR_AUDIT_INHERIT= 0x00008000,
79400+ GR_AUDIT_SETID = 0x00010000,
79401+ GR_AUDIT_CREATE = 0x00020000,
79402+ GR_AUDIT_DELETE = 0x00040000,
79403+ GR_AUDIT_LINK = 0x00080000,
79404+ GR_PTRACERD = 0x00100000,
79405+ GR_NOPTRACE = 0x00200000,
79406+ GR_SUPPRESS = 0x00400000,
79407+ GR_NOLEARN = 0x00800000,
79408+ GR_INIT_TRANSFER= 0x01000000
79409+};
79410+
79411+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79412+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79413+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79414+
79415+/* ACL subject-only mode flags */
79416+enum {
79417+ GR_KILL = 0x00000001,
79418+ GR_VIEW = 0x00000002,
79419+ GR_PROTECTED = 0x00000004,
79420+ GR_LEARN = 0x00000008,
79421+ GR_OVERRIDE = 0x00000010,
79422+ /* just a placeholder, this mode is only used in userspace */
79423+ GR_DUMMY = 0x00000020,
79424+ GR_PROTSHM = 0x00000040,
79425+ GR_KILLPROC = 0x00000080,
79426+ GR_KILLIPPROC = 0x00000100,
79427+ /* just a placeholder, this mode is only used in userspace */
79428+ GR_NOTROJAN = 0x00000200,
79429+ GR_PROTPROCFD = 0x00000400,
79430+ GR_PROCACCT = 0x00000800,
79431+ GR_RELAXPTRACE = 0x00001000,
79432+ //GR_NESTED = 0x00002000,
79433+ GR_INHERITLEARN = 0x00004000,
79434+ GR_PROCFIND = 0x00008000,
79435+ GR_POVERRIDE = 0x00010000,
79436+ GR_KERNELAUTH = 0x00020000,
79437+ GR_ATSECURE = 0x00040000,
79438+ GR_SHMEXEC = 0x00080000
79439+};
79440+
79441+enum {
79442+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79443+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79444+ GR_PAX_ENABLE_MPROTECT = 0x0004,
79445+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
79446+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79447+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79448+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79449+ GR_PAX_DISABLE_MPROTECT = 0x0400,
79450+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
79451+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79452+};
79453+
79454+enum {
79455+ GR_ID_USER = 0x01,
79456+ GR_ID_GROUP = 0x02,
79457+};
79458+
79459+enum {
79460+ GR_ID_ALLOW = 0x01,
79461+ GR_ID_DENY = 0x02,
79462+};
79463+
79464+#define GR_CRASH_RES 31
79465+#define GR_UIDTABLE_MAX 500
79466+
79467+/* begin resource learning section */
79468+enum {
79469+ GR_RLIM_CPU_BUMP = 60,
79470+ GR_RLIM_FSIZE_BUMP = 50000,
79471+ GR_RLIM_DATA_BUMP = 10000,
79472+ GR_RLIM_STACK_BUMP = 1000,
79473+ GR_RLIM_CORE_BUMP = 10000,
79474+ GR_RLIM_RSS_BUMP = 500000,
79475+ GR_RLIM_NPROC_BUMP = 1,
79476+ GR_RLIM_NOFILE_BUMP = 5,
79477+ GR_RLIM_MEMLOCK_BUMP = 50000,
79478+ GR_RLIM_AS_BUMP = 500000,
79479+ GR_RLIM_LOCKS_BUMP = 2,
79480+ GR_RLIM_SIGPENDING_BUMP = 5,
79481+ GR_RLIM_MSGQUEUE_BUMP = 10000,
79482+ GR_RLIM_NICE_BUMP = 1,
79483+ GR_RLIM_RTPRIO_BUMP = 1,
79484+ GR_RLIM_RTTIME_BUMP = 1000000
79485+};
79486+
79487+#endif
79488diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79489new file mode 100644
79490index 0000000..d25522e
79491--- /dev/null
79492+++ b/include/linux/grinternal.h
79493@@ -0,0 +1,229 @@
79494+#ifndef __GRINTERNAL_H
79495+#define __GRINTERNAL_H
79496+
79497+#ifdef CONFIG_GRKERNSEC
79498+
79499+#include <linux/fs.h>
79500+#include <linux/mnt_namespace.h>
79501+#include <linux/nsproxy.h>
79502+#include <linux/gracl.h>
79503+#include <linux/grdefs.h>
79504+#include <linux/grmsg.h>
79505+
79506+void gr_add_learn_entry(const char *fmt, ...)
79507+ __attribute__ ((format (printf, 1, 2)));
79508+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79509+ const struct vfsmount *mnt);
79510+__u32 gr_check_create(const struct dentry *new_dentry,
79511+ const struct dentry *parent,
79512+ const struct vfsmount *mnt, const __u32 mode);
79513+int gr_check_protected_task(const struct task_struct *task);
79514+__u32 to_gr_audit(const __u32 reqmode);
79515+int gr_set_acls(const int type);
79516+int gr_acl_is_enabled(void);
79517+char gr_roletype_to_char(void);
79518+
79519+void gr_handle_alertkill(struct task_struct *task);
79520+char *gr_to_filename(const struct dentry *dentry,
79521+ const struct vfsmount *mnt);
79522+char *gr_to_filename1(const struct dentry *dentry,
79523+ const struct vfsmount *mnt);
79524+char *gr_to_filename2(const struct dentry *dentry,
79525+ const struct vfsmount *mnt);
79526+char *gr_to_filename3(const struct dentry *dentry,
79527+ const struct vfsmount *mnt);
79528+
79529+extern int grsec_enable_ptrace_readexec;
79530+extern int grsec_enable_harden_ptrace;
79531+extern int grsec_enable_link;
79532+extern int grsec_enable_fifo;
79533+extern int grsec_enable_execve;
79534+extern int grsec_enable_shm;
79535+extern int grsec_enable_execlog;
79536+extern int grsec_enable_signal;
79537+extern int grsec_enable_audit_ptrace;
79538+extern int grsec_enable_forkfail;
79539+extern int grsec_enable_time;
79540+extern int grsec_enable_rofs;
79541+extern int grsec_deny_new_usb;
79542+extern int grsec_enable_chroot_shmat;
79543+extern int grsec_enable_chroot_mount;
79544+extern int grsec_enable_chroot_double;
79545+extern int grsec_enable_chroot_pivot;
79546+extern int grsec_enable_chroot_chdir;
79547+extern int grsec_enable_chroot_chmod;
79548+extern int grsec_enable_chroot_mknod;
79549+extern int grsec_enable_chroot_fchdir;
79550+extern int grsec_enable_chroot_nice;
79551+extern int grsec_enable_chroot_execlog;
79552+extern int grsec_enable_chroot_caps;
79553+extern int grsec_enable_chroot_sysctl;
79554+extern int grsec_enable_chroot_unix;
79555+extern int grsec_enable_symlinkown;
79556+extern kgid_t grsec_symlinkown_gid;
79557+extern int grsec_enable_tpe;
79558+extern kgid_t grsec_tpe_gid;
79559+extern int grsec_enable_tpe_all;
79560+extern int grsec_enable_tpe_invert;
79561+extern int grsec_enable_socket_all;
79562+extern kgid_t grsec_socket_all_gid;
79563+extern int grsec_enable_socket_client;
79564+extern kgid_t grsec_socket_client_gid;
79565+extern int grsec_enable_socket_server;
79566+extern kgid_t grsec_socket_server_gid;
79567+extern kgid_t grsec_audit_gid;
79568+extern int grsec_enable_group;
79569+extern int grsec_enable_log_rwxmaps;
79570+extern int grsec_enable_mount;
79571+extern int grsec_enable_chdir;
79572+extern int grsec_resource_logging;
79573+extern int grsec_enable_blackhole;
79574+extern int grsec_lastack_retries;
79575+extern int grsec_enable_brute;
79576+extern int grsec_enable_harden_ipc;
79577+extern int grsec_lock;
79578+
79579+extern spinlock_t grsec_alert_lock;
79580+extern unsigned long grsec_alert_wtime;
79581+extern unsigned long grsec_alert_fyet;
79582+
79583+extern spinlock_t grsec_audit_lock;
79584+
79585+extern rwlock_t grsec_exec_file_lock;
79586+
79587+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79588+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79589+ (tsk)->exec_file->f_path.mnt) : "/")
79590+
79591+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79592+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79593+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79594+
79595+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79596+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
79597+ (tsk)->exec_file->f_path.mnt) : "/")
79598+
79599+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79600+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79601+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79602+
79603+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79604+
79605+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79606+
79607+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79608+{
79609+ if (file1 && file2) {
79610+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
79611+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
79612+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79613+ return true;
79614+ }
79615+
79616+ return false;
79617+}
79618+
79619+#define GR_CHROOT_CAPS {{ \
79620+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79621+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79622+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79623+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79624+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79625+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79626+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79627+
79628+#define security_learn(normal_msg,args...) \
79629+({ \
79630+ read_lock(&grsec_exec_file_lock); \
79631+ gr_add_learn_entry(normal_msg "\n", ## args); \
79632+ read_unlock(&grsec_exec_file_lock); \
79633+})
79634+
79635+enum {
79636+ GR_DO_AUDIT,
79637+ GR_DONT_AUDIT,
79638+ /* used for non-audit messages that we shouldn't kill the task on */
79639+ GR_DONT_AUDIT_GOOD
79640+};
79641+
79642+enum {
79643+ GR_TTYSNIFF,
79644+ GR_RBAC,
79645+ GR_RBAC_STR,
79646+ GR_STR_RBAC,
79647+ GR_RBAC_MODE2,
79648+ GR_RBAC_MODE3,
79649+ GR_FILENAME,
79650+ GR_SYSCTL_HIDDEN,
79651+ GR_NOARGS,
79652+ GR_ONE_INT,
79653+ GR_ONE_INT_TWO_STR,
79654+ GR_ONE_STR,
79655+ GR_STR_INT,
79656+ GR_TWO_STR_INT,
79657+ GR_TWO_INT,
79658+ GR_TWO_U64,
79659+ GR_THREE_INT,
79660+ GR_FIVE_INT_TWO_STR,
79661+ GR_TWO_STR,
79662+ GR_THREE_STR,
79663+ GR_FOUR_STR,
79664+ GR_STR_FILENAME,
79665+ GR_FILENAME_STR,
79666+ GR_FILENAME_TWO_INT,
79667+ GR_FILENAME_TWO_INT_STR,
79668+ GR_TEXTREL,
79669+ GR_PTRACE,
79670+ GR_RESOURCE,
79671+ GR_CAP,
79672+ GR_SIG,
79673+ GR_SIG2,
79674+ GR_CRASH1,
79675+ GR_CRASH2,
79676+ GR_PSACCT,
79677+ GR_RWXMAP,
79678+ GR_RWXMAPVMA
79679+};
79680+
79681+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79682+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79683+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79684+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79685+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79686+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79687+#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)
79688+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79689+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79690+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79691+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79692+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79693+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79694+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79695+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79696+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79697+#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)
79698+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79699+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79700+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79701+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79702+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79703+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79704+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79705+#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)
79706+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79707+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79708+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79709+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79710+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79711+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79712+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79713+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79714+#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)
79715+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79716+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79717+
79718+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79719+
79720+#endif
79721+
79722+#endif
79723diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79724new file mode 100644
79725index 0000000..ba93581
79726--- /dev/null
79727+++ b/include/linux/grmsg.h
79728@@ -0,0 +1,116 @@
79729+#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"
79730+#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"
79731+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79732+#define GR_STOPMOD_MSG "denied modification of module state by "
79733+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79734+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79735+#define GR_IOPERM_MSG "denied use of ioperm() by "
79736+#define GR_IOPL_MSG "denied use of iopl() by "
79737+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79738+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79739+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79740+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79741+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79742+#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"
79743+#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"
79744+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79745+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79746+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79747+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79748+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79749+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79750+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79751+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79752+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79753+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79754+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79755+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79756+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79757+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79758+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79759+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79760+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79761+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79762+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79763+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79764+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79765+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79766+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79767+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79768+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79769+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79770+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79771+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79772+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79773+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79774+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79775+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79776+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79777+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79778+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79779+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79780+#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"
79781+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79782+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79783+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79784+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79785+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79786+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79787+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79788+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79789+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79790+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79791+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79792+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79793+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79794+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79795+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79796+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79797+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79798+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79799+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79800+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79801+#define GR_FAILFORK_MSG "failed fork with errno %s by "
79802+#define GR_NICE_CHROOT_MSG "denied priority change by "
79803+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79804+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79805+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79806+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79807+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79808+#define GR_TIME_MSG "time set by "
79809+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79810+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79811+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79812+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79813+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79814+#define GR_BIND_MSG "denied bind() by "
79815+#define GR_CONNECT_MSG "denied connect() by "
79816+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79817+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79818+#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"
79819+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79820+#define GR_CAP_ACL_MSG "use of %s denied for "
79821+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79822+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79823+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79824+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79825+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79826+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79827+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79828+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79829+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79830+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79831+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79832+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79833+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79834+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79835+#define GR_VM86_MSG "denied use of vm86 by "
79836+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79837+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79838+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79839+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79840+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79841+#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 "
79842+#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 "
79843+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79844+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79845diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79846new file mode 100644
79847index 0000000..f2d8c6c
79848--- /dev/null
79849+++ b/include/linux/grsecurity.h
79850@@ -0,0 +1,248 @@
79851+#ifndef GR_SECURITY_H
79852+#define GR_SECURITY_H
79853+#include <linux/fs.h>
79854+#include <linux/fs_struct.h>
79855+#include <linux/binfmts.h>
79856+#include <linux/gracl.h>
79857+
79858+/* notify of brain-dead configs */
79859+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79860+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79861+#endif
79862+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79863+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79864+#endif
79865+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79866+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79867+#endif
79868+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79869+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79870+#endif
79871+
79872+int gr_handle_new_usb(void);
79873+
79874+void gr_handle_brute_attach(int dumpable);
79875+void gr_handle_brute_check(void);
79876+void gr_handle_kernel_exploit(void);
79877+
79878+char gr_roletype_to_char(void);
79879+
79880+int gr_proc_is_restricted(void);
79881+
79882+int gr_acl_enable_at_secure(void);
79883+
79884+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79885+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79886+
79887+void gr_del_task_from_ip_table(struct task_struct *p);
79888+
79889+int gr_pid_is_chrooted(struct task_struct *p);
79890+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79891+int gr_handle_chroot_nice(void);
79892+int gr_handle_chroot_sysctl(const int op);
79893+int gr_handle_chroot_setpriority(struct task_struct *p,
79894+ const int niceval);
79895+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79896+int gr_handle_chroot_chroot(const struct dentry *dentry,
79897+ const struct vfsmount *mnt);
79898+void gr_handle_chroot_chdir(const struct path *path);
79899+int gr_handle_chroot_chmod(const struct dentry *dentry,
79900+ const struct vfsmount *mnt, const int mode);
79901+int gr_handle_chroot_mknod(const struct dentry *dentry,
79902+ const struct vfsmount *mnt, const int mode);
79903+int gr_handle_chroot_mount(const struct dentry *dentry,
79904+ const struct vfsmount *mnt,
79905+ const char *dev_name);
79906+int gr_handle_chroot_pivot(void);
79907+int gr_handle_chroot_unix(const pid_t pid);
79908+
79909+int gr_handle_rawio(const struct inode *inode);
79910+
79911+void gr_handle_ioperm(void);
79912+void gr_handle_iopl(void);
79913+void gr_handle_msr_write(void);
79914+
79915+umode_t gr_acl_umask(void);
79916+
79917+int gr_tpe_allow(const struct file *file);
79918+
79919+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79920+void gr_clear_chroot_entries(struct task_struct *task);
79921+
79922+void gr_log_forkfail(const int retval);
79923+void gr_log_timechange(void);
79924+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79925+void gr_log_chdir(const struct dentry *dentry,
79926+ const struct vfsmount *mnt);
79927+void gr_log_chroot_exec(const struct dentry *dentry,
79928+ const struct vfsmount *mnt);
79929+void gr_log_remount(const char *devname, const int retval);
79930+void gr_log_unmount(const char *devname, const int retval);
79931+void gr_log_mount(const char *from, const char *to, const int retval);
79932+void gr_log_textrel(struct vm_area_struct *vma);
79933+void gr_log_ptgnustack(struct file *file);
79934+void gr_log_rwxmmap(struct file *file);
79935+void gr_log_rwxmprotect(struct vm_area_struct *vma);
79936+
79937+int gr_handle_follow_link(const struct inode *parent,
79938+ const struct inode *inode,
79939+ const struct dentry *dentry,
79940+ const struct vfsmount *mnt);
79941+int gr_handle_fifo(const struct dentry *dentry,
79942+ const struct vfsmount *mnt,
79943+ const struct dentry *dir, const int flag,
79944+ const int acc_mode);
79945+int gr_handle_hardlink(const struct dentry *dentry,
79946+ const struct vfsmount *mnt,
79947+ struct inode *inode,
79948+ const int mode, const struct filename *to);
79949+
79950+int gr_is_capable(const int cap);
79951+int gr_is_capable_nolog(const int cap);
79952+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79953+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79954+
79955+void gr_copy_label(struct task_struct *tsk);
79956+void gr_handle_crash(struct task_struct *task, const int sig);
79957+int gr_handle_signal(const struct task_struct *p, const int sig);
79958+int gr_check_crash_uid(const kuid_t uid);
79959+int gr_check_protected_task(const struct task_struct *task);
79960+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79961+int gr_acl_handle_mmap(const struct file *file,
79962+ const unsigned long prot);
79963+int gr_acl_handle_mprotect(const struct file *file,
79964+ const unsigned long prot);
79965+int gr_check_hidden_task(const struct task_struct *tsk);
79966+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79967+ const struct vfsmount *mnt);
79968+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79969+ const struct vfsmount *mnt);
79970+__u32 gr_acl_handle_access(const struct dentry *dentry,
79971+ const struct vfsmount *mnt, const int fmode);
79972+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79973+ const struct vfsmount *mnt, umode_t *mode);
79974+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79975+ const struct vfsmount *mnt);
79976+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79977+ const struct vfsmount *mnt);
79978+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79979+ const struct vfsmount *mnt);
79980+int gr_handle_ptrace(struct task_struct *task, const long request);
79981+int gr_handle_proc_ptrace(struct task_struct *task);
79982+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79983+ const struct vfsmount *mnt);
79984+int gr_check_crash_exec(const struct file *filp);
79985+int gr_acl_is_enabled(void);
79986+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79987+ const kgid_t gid);
79988+int gr_set_proc_label(const struct dentry *dentry,
79989+ const struct vfsmount *mnt,
79990+ const int unsafe_flags);
79991+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79992+ const struct vfsmount *mnt);
79993+__u32 gr_acl_handle_open(const struct dentry *dentry,
79994+ const struct vfsmount *mnt, int acc_mode);
79995+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79996+ const struct dentry *p_dentry,
79997+ const struct vfsmount *p_mnt,
79998+ int open_flags, int acc_mode, const int imode);
79999+void gr_handle_create(const struct dentry *dentry,
80000+ const struct vfsmount *mnt);
80001+void gr_handle_proc_create(const struct dentry *dentry,
80002+ const struct inode *inode);
80003+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
80004+ const struct dentry *parent_dentry,
80005+ const struct vfsmount *parent_mnt,
80006+ const int mode);
80007+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
80008+ const struct dentry *parent_dentry,
80009+ const struct vfsmount *parent_mnt);
80010+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
80011+ const struct vfsmount *mnt);
80012+void gr_handle_delete(const ino_t ino, const dev_t dev);
80013+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
80014+ const struct vfsmount *mnt);
80015+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
80016+ const struct dentry *parent_dentry,
80017+ const struct vfsmount *parent_mnt,
80018+ const struct filename *from);
80019+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
80020+ const struct dentry *parent_dentry,
80021+ const struct vfsmount *parent_mnt,
80022+ const struct dentry *old_dentry,
80023+ const struct vfsmount *old_mnt, const struct filename *to);
80024+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
80025+int gr_acl_handle_rename(struct dentry *new_dentry,
80026+ struct dentry *parent_dentry,
80027+ const struct vfsmount *parent_mnt,
80028+ struct dentry *old_dentry,
80029+ struct inode *old_parent_inode,
80030+ struct vfsmount *old_mnt, const struct filename *newname);
80031+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
80032+ struct dentry *old_dentry,
80033+ struct dentry *new_dentry,
80034+ struct vfsmount *mnt, const __u8 replace);
80035+__u32 gr_check_link(const struct dentry *new_dentry,
80036+ const struct dentry *parent_dentry,
80037+ const struct vfsmount *parent_mnt,
80038+ const struct dentry *old_dentry,
80039+ const struct vfsmount *old_mnt);
80040+int gr_acl_handle_filldir(const struct file *file, const char *name,
80041+ const unsigned int namelen, const ino_t ino);
80042+
80043+__u32 gr_acl_handle_unix(const struct dentry *dentry,
80044+ const struct vfsmount *mnt);
80045+void gr_acl_handle_exit(void);
80046+void gr_acl_handle_psacct(struct task_struct *task, const long code);
80047+int gr_acl_handle_procpidmem(const struct task_struct *task);
80048+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
80049+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
80050+void gr_audit_ptrace(struct task_struct *task);
80051+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
80052+void gr_put_exec_file(struct task_struct *task);
80053+
80054+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
80055+
80056+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
80057+extern void gr_learn_resource(const struct task_struct *task, const int res,
80058+ const unsigned long wanted, const int gt);
80059+#else
80060+static inline void gr_learn_resource(const struct task_struct *task, const int res,
80061+ const unsigned long wanted, const int gt)
80062+{
80063+}
80064+#endif
80065+
80066+#ifdef CONFIG_GRKERNSEC_RESLOG
80067+extern void gr_log_resource(const struct task_struct *task, const int res,
80068+ const unsigned long wanted, const int gt);
80069+#else
80070+static inline void gr_log_resource(const struct task_struct *task, const int res,
80071+ const unsigned long wanted, const int gt)
80072+{
80073+}
80074+#endif
80075+
80076+#ifdef CONFIG_GRKERNSEC
80077+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
80078+void gr_handle_vm86(void);
80079+void gr_handle_mem_readwrite(u64 from, u64 to);
80080+
80081+void gr_log_badprocpid(const char *entry);
80082+
80083+extern int grsec_enable_dmesg;
80084+extern int grsec_disable_privio;
80085+
80086+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80087+extern kgid_t grsec_proc_gid;
80088+#endif
80089+
80090+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
80091+extern int grsec_enable_chroot_findtask;
80092+#endif
80093+#ifdef CONFIG_GRKERNSEC_SETXID
80094+extern int grsec_enable_setxid;
80095+#endif
80096+#endif
80097+
80098+#endif
80099diff --git a/include/linux/grsock.h b/include/linux/grsock.h
80100new file mode 100644
80101index 0000000..e7ffaaf
80102--- /dev/null
80103+++ b/include/linux/grsock.h
80104@@ -0,0 +1,19 @@
80105+#ifndef __GRSOCK_H
80106+#define __GRSOCK_H
80107+
80108+extern void gr_attach_curr_ip(const struct sock *sk);
80109+extern int gr_handle_sock_all(const int family, const int type,
80110+ const int protocol);
80111+extern int gr_handle_sock_server(const struct sockaddr *sck);
80112+extern int gr_handle_sock_server_other(const struct sock *sck);
80113+extern int gr_handle_sock_client(const struct sockaddr *sck);
80114+extern int gr_search_connect(struct socket * sock,
80115+ struct sockaddr_in * addr);
80116+extern int gr_search_bind(struct socket * sock,
80117+ struct sockaddr_in * addr);
80118+extern int gr_search_listen(struct socket * sock);
80119+extern int gr_search_accept(struct socket * sock);
80120+extern int gr_search_socket(const int domain, const int type,
80121+ const int protocol);
80122+
80123+#endif
80124diff --git a/include/linux/hash.h b/include/linux/hash.h
80125index bd1754c..8240892 100644
80126--- a/include/linux/hash.h
80127+++ b/include/linux/hash.h
80128@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
80129 struct fast_hash_ops {
80130 u32 (*hash)(const void *data, u32 len, u32 seed);
80131 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
80132-};
80133+} __no_const;
80134
80135 /**
80136 * arch_fast_hash - Caclulates a hash over a given buffer that can have
80137diff --git a/include/linux/highmem.h b/include/linux/highmem.h
80138index 7fb31da..08b5114 100644
80139--- a/include/linux/highmem.h
80140+++ b/include/linux/highmem.h
80141@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
80142 kunmap_atomic(kaddr);
80143 }
80144
80145+static inline void sanitize_highpage(struct page *page)
80146+{
80147+ void *kaddr;
80148+ unsigned long flags;
80149+
80150+ local_irq_save(flags);
80151+ kaddr = kmap_atomic(page);
80152+ clear_page(kaddr);
80153+ kunmap_atomic(kaddr);
80154+ local_irq_restore(flags);
80155+}
80156+
80157 static inline void zero_user_segments(struct page *page,
80158 unsigned start1, unsigned end1,
80159 unsigned start2, unsigned end2)
80160diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
80161index 1c7b89a..7dda400 100644
80162--- a/include/linux/hwmon-sysfs.h
80163+++ b/include/linux/hwmon-sysfs.h
80164@@ -25,7 +25,8 @@
80165 struct sensor_device_attribute{
80166 struct device_attribute dev_attr;
80167 int index;
80168-};
80169+} __do_const;
80170+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
80171 #define to_sensor_dev_attr(_dev_attr) \
80172 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
80173
80174@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
80175 struct device_attribute dev_attr;
80176 u8 index;
80177 u8 nr;
80178-};
80179+} __do_const;
80180+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
80181 #define to_sensor_dev_attr_2(_dev_attr) \
80182 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
80183
80184diff --git a/include/linux/i2c.h b/include/linux/i2c.h
80185index deddeb8..bcaf62d 100644
80186--- a/include/linux/i2c.h
80187+++ b/include/linux/i2c.h
80188@@ -378,6 +378,7 @@ struct i2c_algorithm {
80189 /* To determine what the adapter supports */
80190 u32 (*functionality) (struct i2c_adapter *);
80191 };
80192+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
80193
80194 /**
80195 * struct i2c_bus_recovery_info - I2C bus recovery information
80196diff --git a/include/linux/i2o.h b/include/linux/i2o.h
80197index d23c3c2..eb63c81 100644
80198--- a/include/linux/i2o.h
80199+++ b/include/linux/i2o.h
80200@@ -565,7 +565,7 @@ struct i2o_controller {
80201 struct i2o_device *exec; /* Executive */
80202 #if BITS_PER_LONG == 64
80203 spinlock_t context_list_lock; /* lock for context_list */
80204- atomic_t context_list_counter; /* needed for unique contexts */
80205+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
80206 struct list_head context_list; /* list of context id's
80207 and pointers */
80208 #endif
80209diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
80210index aff7ad8..3942bbd 100644
80211--- a/include/linux/if_pppox.h
80212+++ b/include/linux/if_pppox.h
80213@@ -76,7 +76,7 @@ struct pppox_proto {
80214 int (*ioctl)(struct socket *sock, unsigned int cmd,
80215 unsigned long arg);
80216 struct module *owner;
80217-};
80218+} __do_const;
80219
80220 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
80221 extern void unregister_pppox_proto(int proto_num);
80222diff --git a/include/linux/init.h b/include/linux/init.h
80223index e168880..d9b489d 100644
80224--- a/include/linux/init.h
80225+++ b/include/linux/init.h
80226@@ -37,9 +37,17 @@
80227 * section.
80228 */
80229
80230+#define add_init_latent_entropy __latent_entropy
80231+
80232+#ifdef CONFIG_MEMORY_HOTPLUG
80233+#define add_meminit_latent_entropy
80234+#else
80235+#define add_meminit_latent_entropy __latent_entropy
80236+#endif
80237+
80238 /* These are for everybody (although not all archs will actually
80239 discard it in modules) */
80240-#define __init __section(.init.text) __cold notrace
80241+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
80242 #define __initdata __section(.init.data)
80243 #define __initconst __constsection(.init.rodata)
80244 #define __exitdata __section(.exit.data)
80245@@ -100,7 +108,7 @@
80246 #define __cpuexitconst
80247
80248 /* Used for MEMORY_HOTPLUG */
80249-#define __meminit __section(.meminit.text) __cold notrace
80250+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
80251 #define __meminitdata __section(.meminit.data)
80252 #define __meminitconst __constsection(.meminit.rodata)
80253 #define __memexit __section(.memexit.text) __exitused __cold notrace
80254diff --git a/include/linux/init_task.h b/include/linux/init_task.h
80255index 6df7f9f..d0bf699 100644
80256--- a/include/linux/init_task.h
80257+++ b/include/linux/init_task.h
80258@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
80259
80260 #define INIT_TASK_COMM "swapper"
80261
80262+#ifdef CONFIG_X86
80263+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
80264+#else
80265+#define INIT_TASK_THREAD_INFO
80266+#endif
80267+
80268 #ifdef CONFIG_RT_MUTEXES
80269 # define INIT_RT_MUTEXES(tsk) \
80270 .pi_waiters = RB_ROOT, \
80271@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
80272 RCU_POINTER_INITIALIZER(cred, &init_cred), \
80273 .comm = INIT_TASK_COMM, \
80274 .thread = INIT_THREAD, \
80275+ INIT_TASK_THREAD_INFO \
80276 .fs = &init_fs, \
80277 .files = &init_files, \
80278 .signal = &init_signals, \
80279diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
80280index a2678d3..e411b1b 100644
80281--- a/include/linux/interrupt.h
80282+++ b/include/linux/interrupt.h
80283@@ -373,8 +373,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
80284
80285 struct softirq_action
80286 {
80287- void (*action)(struct softirq_action *);
80288-};
80289+ void (*action)(void);
80290+} __no_const;
80291
80292 asmlinkage void do_softirq(void);
80293 asmlinkage void __do_softirq(void);
80294@@ -388,7 +388,7 @@ static inline void do_softirq_own_stack(void)
80295 }
80296 #endif
80297
80298-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80299+extern void open_softirq(int nr, void (*action)(void));
80300 extern void softirq_init(void);
80301 extern void __raise_softirq_irqoff(unsigned int nr);
80302
80303diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80304index b96a5b2..2732d1c 100644
80305--- a/include/linux/iommu.h
80306+++ b/include/linux/iommu.h
80307@@ -131,7 +131,7 @@ struct iommu_ops {
80308 u32 (*domain_get_windows)(struct iommu_domain *domain);
80309
80310 unsigned long pgsize_bitmap;
80311-};
80312+} __do_const;
80313
80314 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80315 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80316diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80317index 89b7c24..382af74 100644
80318--- a/include/linux/ioport.h
80319+++ b/include/linux/ioport.h
80320@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80321 int adjust_resource(struct resource *res, resource_size_t start,
80322 resource_size_t size);
80323 resource_size_t resource_alignment(struct resource *res);
80324-static inline resource_size_t resource_size(const struct resource *res)
80325+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80326 {
80327 return res->end - res->start + 1;
80328 }
80329diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80330index 35e7eca..6afb7ad 100644
80331--- a/include/linux/ipc_namespace.h
80332+++ b/include/linux/ipc_namespace.h
80333@@ -69,7 +69,7 @@ struct ipc_namespace {
80334 struct user_namespace *user_ns;
80335
80336 unsigned int proc_inum;
80337-};
80338+} __randomize_layout;
80339
80340 extern struct ipc_namespace init_ipc_ns;
80341 extern atomic_t nr_ipc_ns;
80342diff --git a/include/linux/irq.h b/include/linux/irq.h
80343index 7dc1003..407327b 100644
80344--- a/include/linux/irq.h
80345+++ b/include/linux/irq.h
80346@@ -338,7 +338,8 @@ struct irq_chip {
80347 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
80348
80349 unsigned long flags;
80350-};
80351+} __do_const;
80352+typedef struct irq_chip __no_const irq_chip_no_const;
80353
80354 /*
80355 * irq_chip specific flags
80356diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80357index 0ceb389..eed3fb8 100644
80358--- a/include/linux/irqchip/arm-gic.h
80359+++ b/include/linux/irqchip/arm-gic.h
80360@@ -73,9 +73,11 @@
80361
80362 #ifndef __ASSEMBLY__
80363
80364+#include <linux/irq.h>
80365+
80366 struct device_node;
80367
80368-extern struct irq_chip gic_arch_extn;
80369+extern irq_chip_no_const gic_arch_extn;
80370
80371 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80372 u32 offset, struct device_node *);
80373diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80374index 1f44466..b481806 100644
80375--- a/include/linux/jiffies.h
80376+++ b/include/linux/jiffies.h
80377@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80378 /*
80379 * Convert various time units to each other:
80380 */
80381-extern unsigned int jiffies_to_msecs(const unsigned long j);
80382-extern unsigned int jiffies_to_usecs(const unsigned long j);
80383+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80384+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80385
80386-static inline u64 jiffies_to_nsecs(const unsigned long j)
80387+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80388 {
80389 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80390 }
80391
80392-extern unsigned long msecs_to_jiffies(const unsigned int m);
80393-extern unsigned long usecs_to_jiffies(const unsigned int u);
80394+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80395+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80396 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80397 extern void jiffies_to_timespec(const unsigned long jiffies,
80398- struct timespec *value);
80399-extern unsigned long timeval_to_jiffies(const struct timeval *value);
80400+ struct timespec *value) __intentional_overflow(-1);
80401+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80402 extern void jiffies_to_timeval(const unsigned long jiffies,
80403 struct timeval *value);
80404
80405diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80406index 6883e19..e854fcb 100644
80407--- a/include/linux/kallsyms.h
80408+++ b/include/linux/kallsyms.h
80409@@ -15,7 +15,8 @@
80410
80411 struct module;
80412
80413-#ifdef CONFIG_KALLSYMS
80414+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80415+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80416 /* Lookup the address for a symbol. Returns 0 if not found. */
80417 unsigned long kallsyms_lookup_name(const char *name);
80418
80419@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80420 /* Stupid that this does nothing, but I didn't create this mess. */
80421 #define __print_symbol(fmt, addr)
80422 #endif /*CONFIG_KALLSYMS*/
80423+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80424+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80425+extern unsigned long kallsyms_lookup_name(const char *name);
80426+extern void __print_symbol(const char *fmt, unsigned long address);
80427+extern int sprint_backtrace(char *buffer, unsigned long address);
80428+extern int sprint_symbol(char *buffer, unsigned long address);
80429+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80430+const char *kallsyms_lookup(unsigned long addr,
80431+ unsigned long *symbolsize,
80432+ unsigned long *offset,
80433+ char **modname, char *namebuf);
80434+extern int kallsyms_lookup_size_offset(unsigned long addr,
80435+ unsigned long *symbolsize,
80436+ unsigned long *offset);
80437+#endif
80438
80439 /* This macro allows us to keep printk typechecking */
80440 static __printf(1, 2)
80441diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80442index a74c3a8..28d3f21 100644
80443--- a/include/linux/key-type.h
80444+++ b/include/linux/key-type.h
80445@@ -131,7 +131,7 @@ struct key_type {
80446 /* internal fields */
80447 struct list_head link; /* link in types list */
80448 struct lock_class_key lock_class; /* key->sem lock class */
80449-};
80450+} __do_const;
80451
80452 extern struct key_type key_type_keyring;
80453
80454diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80455index 6b06d37..c134867 100644
80456--- a/include/linux/kgdb.h
80457+++ b/include/linux/kgdb.h
80458@@ -52,7 +52,7 @@ extern int kgdb_connected;
80459 extern int kgdb_io_module_registered;
80460
80461 extern atomic_t kgdb_setting_breakpoint;
80462-extern atomic_t kgdb_cpu_doing_single_step;
80463+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80464
80465 extern struct task_struct *kgdb_usethread;
80466 extern struct task_struct *kgdb_contthread;
80467@@ -254,7 +254,7 @@ struct kgdb_arch {
80468 void (*correct_hw_break)(void);
80469
80470 void (*enable_nmi)(bool on);
80471-};
80472+} __do_const;
80473
80474 /**
80475 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80476@@ -279,7 +279,7 @@ struct kgdb_io {
80477 void (*pre_exception) (void);
80478 void (*post_exception) (void);
80479 int is_console;
80480-};
80481+} __do_const;
80482
80483 extern struct kgdb_arch arch_kgdb_ops;
80484
80485diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80486index 0555cc6..40116ce 100644
80487--- a/include/linux/kmod.h
80488+++ b/include/linux/kmod.h
80489@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80490 * usually useless though. */
80491 extern __printf(2, 3)
80492 int __request_module(bool wait, const char *name, ...);
80493+extern __printf(3, 4)
80494+int ___request_module(bool wait, char *param_name, const char *name, ...);
80495 #define request_module(mod...) __request_module(true, mod)
80496 #define request_module_nowait(mod...) __request_module(false, mod)
80497 #define try_then_request_module(x, mod...) \
80498@@ -57,6 +59,9 @@ struct subprocess_info {
80499 struct work_struct work;
80500 struct completion *complete;
80501 char *path;
80502+#ifdef CONFIG_GRKERNSEC
80503+ char *origpath;
80504+#endif
80505 char **argv;
80506 char **envp;
80507 int wait;
80508diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80509index 926afb6..58dd6e5 100644
80510--- a/include/linux/kobject.h
80511+++ b/include/linux/kobject.h
80512@@ -116,7 +116,7 @@ struct kobj_type {
80513 struct attribute **default_attrs;
80514 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80515 const void *(*namespace)(struct kobject *kobj);
80516-};
80517+} __do_const;
80518
80519 struct kobj_uevent_env {
80520 char *envp[UEVENT_NUM_ENVP];
80521@@ -139,6 +139,7 @@ struct kobj_attribute {
80522 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80523 const char *buf, size_t count);
80524 };
80525+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80526
80527 extern const struct sysfs_ops kobj_sysfs_ops;
80528
80529@@ -166,7 +167,7 @@ struct kset {
80530 spinlock_t list_lock;
80531 struct kobject kobj;
80532 const struct kset_uevent_ops *uevent_ops;
80533-};
80534+} __randomize_layout;
80535
80536 extern void kset_init(struct kset *kset);
80537 extern int __must_check kset_register(struct kset *kset);
80538diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80539index df32d25..fb52e27 100644
80540--- a/include/linux/kobject_ns.h
80541+++ b/include/linux/kobject_ns.h
80542@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80543 const void *(*netlink_ns)(struct sock *sk);
80544 const void *(*initial_ns)(void);
80545 void (*drop_ns)(void *);
80546-};
80547+} __do_const;
80548
80549 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80550 int kobj_ns_type_registered(enum kobj_ns_type type);
80551diff --git a/include/linux/kref.h b/include/linux/kref.h
80552index 484604d..0f6c5b6 100644
80553--- a/include/linux/kref.h
80554+++ b/include/linux/kref.h
80555@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80556 static inline int kref_sub(struct kref *kref, unsigned int count,
80557 void (*release)(struct kref *kref))
80558 {
80559- WARN_ON(release == NULL);
80560+ BUG_ON(release == NULL);
80561
80562 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80563 release(kref);
80564diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80565index b8e9a43..632678d 100644
80566--- a/include/linux/kvm_host.h
80567+++ b/include/linux/kvm_host.h
80568@@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
80569 {
80570 }
80571 #endif
80572-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80573+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80574 struct module *module);
80575 void kvm_exit(void);
80576
80577@@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80578 struct kvm_guest_debug *dbg);
80579 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80580
80581-int kvm_arch_init(void *opaque);
80582+int kvm_arch_init(const void *opaque);
80583 void kvm_arch_exit(void);
80584
80585 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80586diff --git a/include/linux/libata.h b/include/linux/libata.h
80587index 3fee55e..42565b7 100644
80588--- a/include/linux/libata.h
80589+++ b/include/linux/libata.h
80590@@ -976,7 +976,7 @@ struct ata_port_operations {
80591 * fields must be pointers.
80592 */
80593 const struct ata_port_operations *inherits;
80594-};
80595+} __do_const;
80596
80597 struct ata_port_info {
80598 unsigned long flags;
80599diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80600index a6a42dd..6c5ebce 100644
80601--- a/include/linux/linkage.h
80602+++ b/include/linux/linkage.h
80603@@ -36,6 +36,7 @@
80604 #endif
80605
80606 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80607+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80608 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80609
80610 /*
80611diff --git a/include/linux/list.h b/include/linux/list.h
80612index ef95941..82db65a 100644
80613--- a/include/linux/list.h
80614+++ b/include/linux/list.h
80615@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80616 extern void list_del(struct list_head *entry);
80617 #endif
80618
80619+extern void __pax_list_add(struct list_head *new,
80620+ struct list_head *prev,
80621+ struct list_head *next);
80622+static inline void pax_list_add(struct list_head *new, struct list_head *head)
80623+{
80624+ __pax_list_add(new, head, head->next);
80625+}
80626+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80627+{
80628+ __pax_list_add(new, head->prev, head);
80629+}
80630+extern void pax_list_del(struct list_head *entry);
80631+
80632 /**
80633 * list_replace - replace old entry by new one
80634 * @old : the element to be replaced
80635@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80636 INIT_LIST_HEAD(entry);
80637 }
80638
80639+extern void pax_list_del_init(struct list_head *entry);
80640+
80641 /**
80642 * list_move - delete from one list and add as another's head
80643 * @list: the entry to move
80644diff --git a/include/linux/math64.h b/include/linux/math64.h
80645index c45c089..298841c 100644
80646--- a/include/linux/math64.h
80647+++ b/include/linux/math64.h
80648@@ -15,7 +15,7 @@
80649 * This is commonly provided by 32bit archs to provide an optimized 64bit
80650 * divide.
80651 */
80652-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80653+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80654 {
80655 *remainder = dividend % divisor;
80656 return dividend / divisor;
80657@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80658 /**
80659 * div64_u64 - unsigned 64bit divide with 64bit divisor
80660 */
80661-static inline u64 div64_u64(u64 dividend, u64 divisor)
80662+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80663 {
80664 return dividend / divisor;
80665 }
80666@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80667 #define div64_ul(x, y) div_u64((x), (y))
80668
80669 #ifndef div_u64_rem
80670-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80671+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80672 {
80673 *remainder = do_div(dividend, divisor);
80674 return dividend;
80675@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80676 #endif
80677
80678 #ifndef div64_u64
80679-extern u64 div64_u64(u64 dividend, u64 divisor);
80680+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80681 #endif
80682
80683 #ifndef div64_s64
80684@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80685 * divide.
80686 */
80687 #ifndef div_u64
80688-static inline u64 div_u64(u64 dividend, u32 divisor)
80689+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80690 {
80691 u32 remainder;
80692 return div_u64_rem(dividend, divisor, &remainder);
80693diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80694index 5f1ea75..5125ac5 100644
80695--- a/include/linux/mempolicy.h
80696+++ b/include/linux/mempolicy.h
80697@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80698 }
80699
80700 #define vma_policy(vma) ((vma)->vm_policy)
80701+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80702+{
80703+ vma->vm_policy = pol;
80704+}
80705
80706 static inline void mpol_get(struct mempolicy *pol)
80707 {
80708@@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80709 }
80710
80711 #define vma_policy(vma) NULL
80712+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80713+{
80714+}
80715
80716 static inline int
80717 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80718diff --git a/include/linux/mm.h b/include/linux/mm.h
80719index c1b7414..5ea2ad8 100644
80720--- a/include/linux/mm.h
80721+++ b/include/linux/mm.h
80722@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80723 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80724 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80725 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80726+
80727+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80728+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80729+#endif
80730+
80731 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80732
80733 #ifdef CONFIG_MEM_SOFT_DIRTY
80734@@ -229,8 +234,8 @@ struct vm_operations_struct {
80735 /* called by access_process_vm when get_user_pages() fails, typically
80736 * for use by special VMAs that can switch between memory and hardware
80737 */
80738- int (*access)(struct vm_area_struct *vma, unsigned long addr,
80739- void *buf, int len, int write);
80740+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80741+ void *buf, size_t len, int write);
80742 #ifdef CONFIG_NUMA
80743 /*
80744 * set_policy() op must add a reference to any non-NULL @new mempolicy
80745@@ -260,6 +265,7 @@ struct vm_operations_struct {
80746 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80747 unsigned long size, pgoff_t pgoff);
80748 };
80749+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80750
80751 struct mmu_gather;
80752 struct inode;
80753@@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80754 unsigned long *pfn);
80755 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80756 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80757-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80758- void *buf, int len, int write);
80759+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80760+ void *buf, size_t len, int write);
80761
80762 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80763 loff_t const holebegin, loff_t const holelen)
80764@@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80765 }
80766 #endif
80767
80768-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80769-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80770- void *buf, int len, int write);
80771+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80772+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80773+ void *buf, size_t len, int write);
80774
80775 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80776 unsigned long start, unsigned long nr_pages,
80777@@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
80778 int set_page_dirty_lock(struct page *page);
80779 int clear_page_dirty_for_io(struct page *page);
80780
80781-/* Is the vma a continuation of the stack vma above it? */
80782-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80783-{
80784- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80785-}
80786-
80787-static inline int stack_guard_page_start(struct vm_area_struct *vma,
80788- unsigned long addr)
80789-{
80790- return (vma->vm_flags & VM_GROWSDOWN) &&
80791- (vma->vm_start == addr) &&
80792- !vma_growsdown(vma->vm_prev, addr);
80793-}
80794-
80795-/* Is the vma a continuation of the stack vma below it? */
80796-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80797-{
80798- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80799-}
80800-
80801-static inline int stack_guard_page_end(struct vm_area_struct *vma,
80802- unsigned long addr)
80803-{
80804- return (vma->vm_flags & VM_GROWSUP) &&
80805- (vma->vm_end == addr) &&
80806- !vma_growsup(vma->vm_next, addr);
80807-}
80808-
80809 extern pid_t
80810 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80811
80812@@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80813 }
80814 #endif
80815
80816+#ifdef CONFIG_MMU
80817+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80818+#else
80819+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80820+{
80821+ return __pgprot(0);
80822+}
80823+#endif
80824+
80825 int vma_wants_writenotify(struct vm_area_struct *vma);
80826
80827 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80828@@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80829 {
80830 return 0;
80831 }
80832+
80833+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80834+ unsigned long address)
80835+{
80836+ return 0;
80837+}
80838 #else
80839 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80840+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80841 #endif
80842
80843 #ifdef __PAGETABLE_PMD_FOLDED
80844@@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80845 {
80846 return 0;
80847 }
80848+
80849+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80850+ unsigned long address)
80851+{
80852+ return 0;
80853+}
80854 #else
80855 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80856+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80857 #endif
80858
80859 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80860@@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80861 NULL: pud_offset(pgd, address);
80862 }
80863
80864+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80865+{
80866+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80867+ NULL: pud_offset(pgd, address);
80868+}
80869+
80870 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80871 {
80872 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80873 NULL: pmd_offset(pud, address);
80874 }
80875+
80876+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80877+{
80878+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80879+ NULL: pmd_offset(pud, address);
80880+}
80881 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80882
80883 #if USE_SPLIT_PTE_PTLOCKS
80884@@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80885 unsigned long addr, unsigned long len,
80886 unsigned long flags, struct page **pages);
80887
80888-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80889+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80890
80891 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80892 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80893@@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80894 unsigned long len, unsigned long prot, unsigned long flags,
80895 unsigned long pgoff, unsigned long *populate);
80896 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80897+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80898
80899 #ifdef CONFIG_MMU
80900 extern int __mm_populate(unsigned long addr, unsigned long len,
80901@@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
80902 unsigned long high_limit;
80903 unsigned long align_mask;
80904 unsigned long align_offset;
80905+ unsigned long threadstack_offset;
80906 };
80907
80908-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80909-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80910+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80911+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80912
80913 /*
80914 * Search for an unmapped address range.
80915@@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80916 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80917 */
80918 static inline unsigned long
80919-vm_unmapped_area(struct vm_unmapped_area_info *info)
80920+vm_unmapped_area(const struct vm_unmapped_area_info *info)
80921 {
80922 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80923 return unmapped_area(info);
80924@@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80925 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80926 struct vm_area_struct **pprev);
80927
80928+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80929+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80930+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80931+
80932 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80933 NULL if none. Assume start_addr < end_addr. */
80934 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80935@@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80936 return vma;
80937 }
80938
80939-#ifdef CONFIG_MMU
80940-pgprot_t vm_get_page_prot(unsigned long vm_flags);
80941-#else
80942-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80943-{
80944- return __pgprot(0);
80945-}
80946-#endif
80947-
80948 #ifdef CONFIG_NUMA_BALANCING
80949 unsigned long change_prot_numa(struct vm_area_struct *vma,
80950 unsigned long start, unsigned long end);
80951@@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80952 static inline void vm_stat_account(struct mm_struct *mm,
80953 unsigned long flags, struct file *file, long pages)
80954 {
80955+
80956+#ifdef CONFIG_PAX_RANDMMAP
80957+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80958+#endif
80959+
80960 mm->total_vm += pages;
80961 }
80962 #endif /* CONFIG_PROC_FS */
80963@@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
80964 extern int sysctl_memory_failure_early_kill;
80965 extern int sysctl_memory_failure_recovery;
80966 extern void shake_page(struct page *p, int access);
80967-extern atomic_long_t num_poisoned_pages;
80968+extern atomic_long_unchecked_t num_poisoned_pages;
80969 extern int soft_offline_page(struct page *page, int flags);
80970
80971 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80972@@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
80973 static inline void setup_nr_node_ids(void) {}
80974 #endif
80975
80976+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80977+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80978+#else
80979+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80980+#endif
80981+
80982 #endif /* __KERNEL__ */
80983 #endif /* _LINUX_MM_H */
80984diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80985index 290901a..e99b01c 100644
80986--- a/include/linux/mm_types.h
80987+++ b/include/linux/mm_types.h
80988@@ -307,7 +307,9 @@ struct vm_area_struct {
80989 #ifdef CONFIG_NUMA
80990 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80991 #endif
80992-};
80993+
80994+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80995+} __randomize_layout;
80996
80997 struct core_thread {
80998 struct task_struct *task;
80999@@ -453,7 +455,25 @@ struct mm_struct {
81000 bool tlb_flush_pending;
81001 #endif
81002 struct uprobes_state uprobes_state;
81003-};
81004+
81005+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81006+ unsigned long pax_flags;
81007+#endif
81008+
81009+#ifdef CONFIG_PAX_DLRESOLVE
81010+ unsigned long call_dl_resolve;
81011+#endif
81012+
81013+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
81014+ unsigned long call_syscall;
81015+#endif
81016+
81017+#ifdef CONFIG_PAX_ASLR
81018+ unsigned long delta_mmap; /* randomized offset */
81019+ unsigned long delta_stack; /* randomized offset */
81020+#endif
81021+
81022+} __randomize_layout;
81023
81024 static inline void mm_init_cpumask(struct mm_struct *mm)
81025 {
81026diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
81027index c5d5278..f0b68c8 100644
81028--- a/include/linux/mmiotrace.h
81029+++ b/include/linux/mmiotrace.h
81030@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
81031 /* Called from ioremap.c */
81032 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
81033 void __iomem *addr);
81034-extern void mmiotrace_iounmap(volatile void __iomem *addr);
81035+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
81036
81037 /* For anyone to insert markers. Remember trailing newline. */
81038 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
81039@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
81040 {
81041 }
81042
81043-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
81044+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
81045 {
81046 }
81047
81048diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
81049index 9b61b9b..52147d6b 100644
81050--- a/include/linux/mmzone.h
81051+++ b/include/linux/mmzone.h
81052@@ -396,7 +396,7 @@ struct zone {
81053 unsigned long flags; /* zone flags, see below */
81054
81055 /* Zone statistics */
81056- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81057+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81058
81059 /*
81060 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
81061diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
81062index 45e9214..a7227d6 100644
81063--- a/include/linux/mod_devicetable.h
81064+++ b/include/linux/mod_devicetable.h
81065@@ -13,7 +13,7 @@
81066 typedef unsigned long kernel_ulong_t;
81067 #endif
81068
81069-#define PCI_ANY_ID (~0)
81070+#define PCI_ANY_ID ((__u16)~0)
81071
81072 struct pci_device_id {
81073 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
81074@@ -139,7 +139,7 @@ struct usb_device_id {
81075 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
81076 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
81077
81078-#define HID_ANY_ID (~0)
81079+#define HID_ANY_ID (~0U)
81080 #define HID_BUS_ANY 0xffff
81081 #define HID_GROUP_ANY 0x0000
81082
81083@@ -467,7 +467,7 @@ struct dmi_system_id {
81084 const char *ident;
81085 struct dmi_strmatch matches[4];
81086 void *driver_data;
81087-};
81088+} __do_const;
81089 /*
81090 * struct dmi_device_id appears during expansion of
81091 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
81092diff --git a/include/linux/module.h b/include/linux/module.h
81093index eaf60ff..641979a 100644
81094--- a/include/linux/module.h
81095+++ b/include/linux/module.h
81096@@ -17,9 +17,11 @@
81097 #include <linux/moduleparam.h>
81098 #include <linux/tracepoint.h>
81099 #include <linux/export.h>
81100+#include <linux/fs.h>
81101
81102 #include <linux/percpu.h>
81103 #include <asm/module.h>
81104+#include <asm/pgtable.h>
81105
81106 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
81107 #define MODULE_SIG_STRING "~Module signature appended~\n"
81108@@ -42,7 +44,7 @@ struct module_kobject {
81109 struct kobject *drivers_dir;
81110 struct module_param_attrs *mp;
81111 struct completion *kobj_completion;
81112-};
81113+} __randomize_layout;
81114
81115 struct module_attribute {
81116 struct attribute attr;
81117@@ -54,12 +56,13 @@ struct module_attribute {
81118 int (*test)(struct module *);
81119 void (*free)(struct module *);
81120 };
81121+typedef struct module_attribute __no_const module_attribute_no_const;
81122
81123 struct module_version_attribute {
81124 struct module_attribute mattr;
81125 const char *module_name;
81126 const char *version;
81127-} __attribute__ ((__aligned__(sizeof(void *))));
81128+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
81129
81130 extern ssize_t __modver_version_show(struct module_attribute *,
81131 struct module_kobject *, char *);
81132@@ -238,7 +241,7 @@ struct module {
81133
81134 /* Sysfs stuff. */
81135 struct module_kobject mkobj;
81136- struct module_attribute *modinfo_attrs;
81137+ module_attribute_no_const *modinfo_attrs;
81138 const char *version;
81139 const char *srcversion;
81140 struct kobject *holders_dir;
81141@@ -287,19 +290,16 @@ struct module {
81142 int (*init)(void);
81143
81144 /* If this is non-NULL, vfree after init() returns */
81145- void *module_init;
81146+ void *module_init_rx, *module_init_rw;
81147
81148 /* Here is the actual code + data, vfree'd on unload. */
81149- void *module_core;
81150+ void *module_core_rx, *module_core_rw;
81151
81152 /* Here are the sizes of the init and core sections */
81153- unsigned int init_size, core_size;
81154+ unsigned int init_size_rw, core_size_rw;
81155
81156 /* The size of the executable code in each section. */
81157- unsigned int init_text_size, core_text_size;
81158-
81159- /* Size of RO sections of the module (text+rodata) */
81160- unsigned int init_ro_size, core_ro_size;
81161+ unsigned int init_size_rx, core_size_rx;
81162
81163 /* Arch-specific module values */
81164 struct mod_arch_specific arch;
81165@@ -355,6 +355,10 @@ struct module {
81166 #ifdef CONFIG_EVENT_TRACING
81167 struct ftrace_event_call **trace_events;
81168 unsigned int num_trace_events;
81169+ struct file_operations trace_id;
81170+ struct file_operations trace_enable;
81171+ struct file_operations trace_format;
81172+ struct file_operations trace_filter;
81173 #endif
81174 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
81175 unsigned int num_ftrace_callsites;
81176@@ -378,7 +382,7 @@ struct module {
81177 ctor_fn_t *ctors;
81178 unsigned int num_ctors;
81179 #endif
81180-};
81181+} __randomize_layout;
81182 #ifndef MODULE_ARCH_INIT
81183 #define MODULE_ARCH_INIT {}
81184 #endif
81185@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
81186 bool is_module_percpu_address(unsigned long addr);
81187 bool is_module_text_address(unsigned long addr);
81188
81189+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
81190+{
81191+
81192+#ifdef CONFIG_PAX_KERNEXEC
81193+ if (ktla_ktva(addr) >= (unsigned long)start &&
81194+ ktla_ktva(addr) < (unsigned long)start + size)
81195+ return 1;
81196+#endif
81197+
81198+ return ((void *)addr >= start && (void *)addr < start + size);
81199+}
81200+
81201+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
81202+{
81203+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
81204+}
81205+
81206+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
81207+{
81208+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
81209+}
81210+
81211+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
81212+{
81213+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
81214+}
81215+
81216+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
81217+{
81218+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
81219+}
81220+
81221 static inline int within_module_core(unsigned long addr, const struct module *mod)
81222 {
81223- return (unsigned long)mod->module_core <= addr &&
81224- addr < (unsigned long)mod->module_core + mod->core_size;
81225+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
81226 }
81227
81228 static inline int within_module_init(unsigned long addr, const struct module *mod)
81229 {
81230- return (unsigned long)mod->module_init <= addr &&
81231- addr < (unsigned long)mod->module_init + mod->init_size;
81232+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
81233 }
81234
81235 /* Search for module by name: must hold module_mutex. */
81236diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
81237index 560ca53..ef621ef 100644
81238--- a/include/linux/moduleloader.h
81239+++ b/include/linux/moduleloader.h
81240@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
81241 sections. Returns NULL on failure. */
81242 void *module_alloc(unsigned long size);
81243
81244+#ifdef CONFIG_PAX_KERNEXEC
81245+void *module_alloc_exec(unsigned long size);
81246+#else
81247+#define module_alloc_exec(x) module_alloc(x)
81248+#endif
81249+
81250 /* Free memory returned from module_alloc. */
81251 void module_free(struct module *mod, void *module_region);
81252
81253+#ifdef CONFIG_PAX_KERNEXEC
81254+void module_free_exec(struct module *mod, void *module_region);
81255+#else
81256+#define module_free_exec(x, y) module_free((x), (y))
81257+#endif
81258+
81259 /*
81260 * Apply the given relocation to the (simplified) ELF. Return -error
81261 * or 0.
81262@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
81263 unsigned int relsec,
81264 struct module *me)
81265 {
81266+#ifdef CONFIG_MODULES
81267 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81268+#endif
81269 return -ENOEXEC;
81270 }
81271 #endif
81272@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
81273 unsigned int relsec,
81274 struct module *me)
81275 {
81276+#ifdef CONFIG_MODULES
81277 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81278+#endif
81279 return -ENOEXEC;
81280 }
81281 #endif
81282diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
81283index c3eb102..073c4a6 100644
81284--- a/include/linux/moduleparam.h
81285+++ b/include/linux/moduleparam.h
81286@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
81287 * @len is usually just sizeof(string).
81288 */
81289 #define module_param_string(name, string, len, perm) \
81290- static const struct kparam_string __param_string_##name \
81291+ static const struct kparam_string __param_string_##name __used \
81292 = { len, string }; \
81293 __module_param_call(MODULE_PARAM_PREFIX, name, \
81294 &param_ops_string, \
81295@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
81296 */
81297 #define module_param_array_named(name, array, type, nump, perm) \
81298 param_check_##type(name, &(array)[0]); \
81299- static const struct kparam_array __param_arr_##name \
81300+ static const struct kparam_array __param_arr_##name __used \
81301 = { .max = ARRAY_SIZE(array), .num = nump, \
81302 .ops = &param_ops_##type, \
81303 .elemsize = sizeof(array[0]), .elem = array }; \
81304diff --git a/include/linux/mount.h b/include/linux/mount.h
81305index 839bac2..a96b37c 100644
81306--- a/include/linux/mount.h
81307+++ b/include/linux/mount.h
81308@@ -59,7 +59,7 @@ struct vfsmount {
81309 struct dentry *mnt_root; /* root of the mounted tree */
81310 struct super_block *mnt_sb; /* pointer to superblock */
81311 int mnt_flags;
81312-};
81313+} __randomize_layout;
81314
81315 struct file; /* forward dec */
81316
81317diff --git a/include/linux/namei.h b/include/linux/namei.h
81318index 492de72..1bddcd4 100644
81319--- a/include/linux/namei.h
81320+++ b/include/linux/namei.h
81321@@ -19,7 +19,7 @@ struct nameidata {
81322 unsigned seq, m_seq;
81323 int last_type;
81324 unsigned depth;
81325- char *saved_names[MAX_NESTED_LINKS + 1];
81326+ const char *saved_names[MAX_NESTED_LINKS + 1];
81327 };
81328
81329 /*
81330@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81331
81332 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81333
81334-static inline void nd_set_link(struct nameidata *nd, char *path)
81335+static inline void nd_set_link(struct nameidata *nd, const char *path)
81336 {
81337 nd->saved_names[nd->depth] = path;
81338 }
81339
81340-static inline char *nd_get_link(struct nameidata *nd)
81341+static inline const char *nd_get_link(const struct nameidata *nd)
81342 {
81343 return nd->saved_names[nd->depth];
81344 }
81345diff --git a/include/linux/net.h b/include/linux/net.h
81346index 94734a6..d8d6931 100644
81347--- a/include/linux/net.h
81348+++ b/include/linux/net.h
81349@@ -192,7 +192,7 @@ struct net_proto_family {
81350 int (*create)(struct net *net, struct socket *sock,
81351 int protocol, int kern);
81352 struct module *owner;
81353-};
81354+} __do_const;
81355
81356 struct iovec;
81357 struct kvec;
81358diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81359index daafd95..74c5d1e 100644
81360--- a/include/linux/netdevice.h
81361+++ b/include/linux/netdevice.h
81362@@ -1146,6 +1146,7 @@ struct net_device_ops {
81363 struct net_device *dev,
81364 void *priv);
81365 };
81366+typedef struct net_device_ops __no_const net_device_ops_no_const;
81367
81368 /*
81369 * The DEVICE structure.
81370@@ -1228,7 +1229,7 @@ struct net_device {
81371 int iflink;
81372
81373 struct net_device_stats stats;
81374- atomic_long_t rx_dropped; /* dropped packets by core network
81375+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
81376 * Do not use this in drivers.
81377 */
81378
81379diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81380index 2077489..a15e561 100644
81381--- a/include/linux/netfilter.h
81382+++ b/include/linux/netfilter.h
81383@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81384 #endif
81385 /* Use the module struct to lock set/get code in place */
81386 struct module *owner;
81387-};
81388+} __do_const;
81389
81390 /* Function to register/unregister hook points. */
81391 int nf_register_hook(struct nf_hook_ops *reg);
81392diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81393index 28c7436..2d6156a 100644
81394--- a/include/linux/netfilter/nfnetlink.h
81395+++ b/include/linux/netfilter/nfnetlink.h
81396@@ -19,7 +19,7 @@ struct nfnl_callback {
81397 const struct nlattr * const cda[]);
81398 const struct nla_policy *policy; /* netlink attribute policy */
81399 const u_int16_t attr_count; /* number of nlattr's */
81400-};
81401+} __do_const;
81402
81403 struct nfnetlink_subsystem {
81404 const char *name;
81405diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81406new file mode 100644
81407index 0000000..33f4af8
81408--- /dev/null
81409+++ b/include/linux/netfilter/xt_gradm.h
81410@@ -0,0 +1,9 @@
81411+#ifndef _LINUX_NETFILTER_XT_GRADM_H
81412+#define _LINUX_NETFILTER_XT_GRADM_H 1
81413+
81414+struct xt_gradm_mtinfo {
81415+ __u16 flags;
81416+ __u16 invflags;
81417+};
81418+
81419+#endif
81420diff --git a/include/linux/nls.h b/include/linux/nls.h
81421index 520681b..1d67ed2 100644
81422--- a/include/linux/nls.h
81423+++ b/include/linux/nls.h
81424@@ -31,7 +31,7 @@ struct nls_table {
81425 const unsigned char *charset2upper;
81426 struct module *owner;
81427 struct nls_table *next;
81428-};
81429+} __do_const;
81430
81431 /* this value hold the maximum octet of charset */
81432 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81433diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81434index d14a4c3..a078786 100644
81435--- a/include/linux/notifier.h
81436+++ b/include/linux/notifier.h
81437@@ -54,7 +54,8 @@ struct notifier_block {
81438 notifier_fn_t notifier_call;
81439 struct notifier_block __rcu *next;
81440 int priority;
81441-};
81442+} __do_const;
81443+typedef struct notifier_block __no_const notifier_block_no_const;
81444
81445 struct atomic_notifier_head {
81446 spinlock_t lock;
81447diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81448index b2a0f15..4d7da32 100644
81449--- a/include/linux/oprofile.h
81450+++ b/include/linux/oprofile.h
81451@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81452 int oprofilefs_create_ro_ulong(struct dentry * root,
81453 char const * name, ulong * val);
81454
81455-/** Create a file for read-only access to an atomic_t. */
81456+/** Create a file for read-only access to an atomic_unchecked_t. */
81457 int oprofilefs_create_ro_atomic(struct dentry * root,
81458- char const * name, atomic_t * val);
81459+ char const * name, atomic_unchecked_t * val);
81460
81461 /** create a directory */
81462 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81463diff --git a/include/linux/padata.h b/include/linux/padata.h
81464index 4386946..f50c615 100644
81465--- a/include/linux/padata.h
81466+++ b/include/linux/padata.h
81467@@ -129,7 +129,7 @@ struct parallel_data {
81468 struct padata_serial_queue __percpu *squeue;
81469 atomic_t reorder_objects;
81470 atomic_t refcnt;
81471- atomic_t seq_nr;
81472+ atomic_unchecked_t seq_nr;
81473 struct padata_cpumask cpumask;
81474 spinlock_t lock ____cacheline_aligned;
81475 unsigned int processed;
81476diff --git a/include/linux/path.h b/include/linux/path.h
81477index d137218..be0c176 100644
81478--- a/include/linux/path.h
81479+++ b/include/linux/path.h
81480@@ -1,13 +1,15 @@
81481 #ifndef _LINUX_PATH_H
81482 #define _LINUX_PATH_H
81483
81484+#include <linux/compiler.h>
81485+
81486 struct dentry;
81487 struct vfsmount;
81488
81489 struct path {
81490 struct vfsmount *mnt;
81491 struct dentry *dentry;
81492-};
81493+} __randomize_layout;
81494
81495 extern void path_get(const struct path *);
81496 extern void path_put(const struct path *);
81497diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81498index 5f2e559..7d59314 100644
81499--- a/include/linux/pci_hotplug.h
81500+++ b/include/linux/pci_hotplug.h
81501@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81502 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81503 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81504 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81505-};
81506+} __do_const;
81507+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81508
81509 /**
81510 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81511diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81512index e56b07f..aef789b 100644
81513--- a/include/linux/perf_event.h
81514+++ b/include/linux/perf_event.h
81515@@ -328,8 +328,8 @@ struct perf_event {
81516
81517 enum perf_event_active_state state;
81518 unsigned int attach_state;
81519- local64_t count;
81520- atomic64_t child_count;
81521+ local64_t count; /* PaX: fix it one day */
81522+ atomic64_unchecked_t child_count;
81523
81524 /*
81525 * These are the total time in nanoseconds that the event
81526@@ -380,8 +380,8 @@ struct perf_event {
81527 * These accumulate total time (in nanoseconds) that children
81528 * events have been enabled and running, respectively.
81529 */
81530- atomic64_t child_total_time_enabled;
81531- atomic64_t child_total_time_running;
81532+ atomic64_unchecked_t child_total_time_enabled;
81533+ atomic64_unchecked_t child_total_time_running;
81534
81535 /*
81536 * Protect attach/detach and child_list:
81537@@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81538 entry->ip[entry->nr++] = ip;
81539 }
81540
81541-extern int sysctl_perf_event_paranoid;
81542+extern int sysctl_perf_event_legitimately_concerned;
81543 extern int sysctl_perf_event_mlock;
81544 extern int sysctl_perf_event_sample_rate;
81545 extern int sysctl_perf_cpu_time_max_percent;
81546@@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81547 loff_t *ppos);
81548
81549
81550+static inline bool perf_paranoid_any(void)
81551+{
81552+ return sysctl_perf_event_legitimately_concerned > 2;
81553+}
81554+
81555 static inline bool perf_paranoid_tracepoint_raw(void)
81556 {
81557- return sysctl_perf_event_paranoid > -1;
81558+ return sysctl_perf_event_legitimately_concerned > -1;
81559 }
81560
81561 static inline bool perf_paranoid_cpu(void)
81562 {
81563- return sysctl_perf_event_paranoid > 0;
81564+ return sysctl_perf_event_legitimately_concerned > 0;
81565 }
81566
81567 static inline bool perf_paranoid_kernel(void)
81568 {
81569- return sysctl_perf_event_paranoid > 1;
81570+ return sysctl_perf_event_legitimately_concerned > 1;
81571 }
81572
81573 extern void perf_event_init(void);
81574@@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
81575 struct device_attribute attr;
81576 u64 id;
81577 const char *event_str;
81578-};
81579+} __do_const;
81580
81581 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81582 static struct perf_pmu_events_attr _var = { \
81583diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81584index 7246ef3..1539ea4 100644
81585--- a/include/linux/pid_namespace.h
81586+++ b/include/linux/pid_namespace.h
81587@@ -43,7 +43,7 @@ struct pid_namespace {
81588 int hide_pid;
81589 int reboot; /* group exit code if this pidns was rebooted */
81590 unsigned int proc_inum;
81591-};
81592+} __randomize_layout;
81593
81594 extern struct pid_namespace init_pid_ns;
81595
81596diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81597index ab57526..94598804 100644
81598--- a/include/linux/pipe_fs_i.h
81599+++ b/include/linux/pipe_fs_i.h
81600@@ -47,10 +47,10 @@ struct pipe_inode_info {
81601 struct mutex mutex;
81602 wait_queue_head_t wait;
81603 unsigned int nrbufs, curbuf, buffers;
81604- unsigned int readers;
81605- unsigned int writers;
81606- unsigned int files;
81607- unsigned int waiting_writers;
81608+ atomic_t readers;
81609+ atomic_t writers;
81610+ atomic_t files;
81611+ atomic_t waiting_writers;
81612 unsigned int r_counter;
81613 unsigned int w_counter;
81614 struct page *tmp_page;
81615diff --git a/include/linux/pm.h b/include/linux/pm.h
81616index 8c6583a..febb84c 100644
81617--- a/include/linux/pm.h
81618+++ b/include/linux/pm.h
81619@@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81620 struct dev_pm_domain {
81621 struct dev_pm_ops ops;
81622 };
81623+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81624
81625 /*
81626 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81627diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81628index 7c1d252..0e7061d 100644
81629--- a/include/linux/pm_domain.h
81630+++ b/include/linux/pm_domain.h
81631@@ -44,11 +44,11 @@ struct gpd_dev_ops {
81632 int (*thaw_early)(struct device *dev);
81633 int (*thaw)(struct device *dev);
81634 bool (*active_wakeup)(struct device *dev);
81635-};
81636+} __no_const;
81637
81638 struct gpd_cpu_data {
81639 unsigned int saved_exit_latency;
81640- struct cpuidle_state *idle_state;
81641+ cpuidle_state_no_const *idle_state;
81642 };
81643
81644 struct generic_pm_domain {
81645diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81646index 16c9a62..f9f0838 100644
81647--- a/include/linux/pm_runtime.h
81648+++ b/include/linux/pm_runtime.h
81649@@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81650
81651 static inline void pm_runtime_mark_last_busy(struct device *dev)
81652 {
81653- ACCESS_ONCE(dev->power.last_busy) = jiffies;
81654+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81655 }
81656
81657 #else /* !CONFIG_PM_RUNTIME */
81658diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81659index 195aafc..49a7bc2 100644
81660--- a/include/linux/pnp.h
81661+++ b/include/linux/pnp.h
81662@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81663 struct pnp_fixup {
81664 char id[7];
81665 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81666-};
81667+} __do_const;
81668
81669 /* config parameters */
81670 #define PNP_CONFIG_NORMAL 0x0001
81671diff --git a/include/linux/poison.h b/include/linux/poison.h
81672index 2110a81..13a11bb 100644
81673--- a/include/linux/poison.h
81674+++ b/include/linux/poison.h
81675@@ -19,8 +19,8 @@
81676 * under normal circumstances, used to verify that nobody uses
81677 * non-initialized list entries.
81678 */
81679-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81680-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81681+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81682+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81683
81684 /********** include/linux/timer.h **********/
81685 /*
81686diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81687index d8b187c3..9a9257a 100644
81688--- a/include/linux/power/smartreflex.h
81689+++ b/include/linux/power/smartreflex.h
81690@@ -238,7 +238,7 @@ struct omap_sr_class_data {
81691 int (*notify)(struct omap_sr *sr, u32 status);
81692 u8 notify_flags;
81693 u8 class_type;
81694-};
81695+} __do_const;
81696
81697 /**
81698 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81699diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81700index 4ea1d37..80f4b33 100644
81701--- a/include/linux/ppp-comp.h
81702+++ b/include/linux/ppp-comp.h
81703@@ -84,7 +84,7 @@ struct compressor {
81704 struct module *owner;
81705 /* Extra skb space needed by the compressor algorithm */
81706 unsigned int comp_extra;
81707-};
81708+} __do_const;
81709
81710 /*
81711 * The return value from decompress routine is the length of the
81712diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81713index de83b4e..c4b997d 100644
81714--- a/include/linux/preempt.h
81715+++ b/include/linux/preempt.h
81716@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81717 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81718 #endif
81719
81720+#define raw_preempt_count_add(val) __preempt_count_add(val)
81721+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81722+
81723 #define __preempt_count_inc() __preempt_count_add(1)
81724 #define __preempt_count_dec() __preempt_count_sub(1)
81725
81726 #define preempt_count_inc() preempt_count_add(1)
81727+#define raw_preempt_count_inc() raw_preempt_count_add(1)
81728 #define preempt_count_dec() preempt_count_sub(1)
81729+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81730
81731 #ifdef CONFIG_PREEMPT_COUNT
81732
81733@@ -41,6 +46,12 @@ do { \
81734 barrier(); \
81735 } while (0)
81736
81737+#define raw_preempt_disable() \
81738+do { \
81739+ raw_preempt_count_inc(); \
81740+ barrier(); \
81741+} while (0)
81742+
81743 #define sched_preempt_enable_no_resched() \
81744 do { \
81745 barrier(); \
81746@@ -49,6 +60,12 @@ do { \
81747
81748 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81749
81750+#define raw_preempt_enable_no_resched() \
81751+do { \
81752+ barrier(); \
81753+ raw_preempt_count_dec(); \
81754+} while (0)
81755+
81756 #ifdef CONFIG_PREEMPT
81757 #define preempt_enable() \
81758 do { \
81759@@ -113,8 +130,10 @@ do { \
81760 * region.
81761 */
81762 #define preempt_disable() barrier()
81763+#define raw_preempt_disable() barrier()
81764 #define sched_preempt_enable_no_resched() barrier()
81765 #define preempt_enable_no_resched() barrier()
81766+#define raw_preempt_enable_no_resched() barrier()
81767 #define preempt_enable() barrier()
81768 #define preempt_check_resched() do { } while (0)
81769
81770@@ -128,11 +147,13 @@ do { \
81771 /*
81772 * Modules have no business playing preemption tricks.
81773 */
81774+#ifndef CONFIG_PAX_KERNEXEC
81775 #undef sched_preempt_enable_no_resched
81776 #undef preempt_enable_no_resched
81777 #undef preempt_enable_no_resched_notrace
81778 #undef preempt_check_resched
81779 #endif
81780+#endif
81781
81782 #define preempt_set_need_resched() \
81783 do { \
81784diff --git a/include/linux/printk.h b/include/linux/printk.h
81785index fa47e27..c08e034 100644
81786--- a/include/linux/printk.h
81787+++ b/include/linux/printk.h
81788@@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
81789 void early_printk(const char *s, ...) { }
81790 #endif
81791
81792+extern int kptr_restrict;
81793+
81794 #ifdef CONFIG_PRINTK
81795 asmlinkage __printf(5, 0)
81796 int vprintk_emit(int facility, int level,
81797@@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81798
81799 extern int printk_delay_msec;
81800 extern int dmesg_restrict;
81801-extern int kptr_restrict;
81802
81803 extern void wake_up_klogd(void);
81804
81805diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81806index 608e60a..bbcb1a0 100644
81807--- a/include/linux/proc_fs.h
81808+++ b/include/linux/proc_fs.h
81809@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81810 extern struct proc_dir_entry *proc_symlink(const char *,
81811 struct proc_dir_entry *, const char *);
81812 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81813+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81814 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81815 struct proc_dir_entry *, void *);
81816+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81817+ struct proc_dir_entry *, void *);
81818 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81819 struct proc_dir_entry *);
81820
81821@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81822 return proc_create_data(name, mode, parent, proc_fops, NULL);
81823 }
81824
81825+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81826+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81827+{
81828+#ifdef CONFIG_GRKERNSEC_PROC_USER
81829+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81830+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81831+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81832+#else
81833+ return proc_create_data(name, mode, parent, proc_fops, NULL);
81834+#endif
81835+}
81836+
81837+
81838 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81839 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81840 extern void *PDE_DATA(const struct inode *);
81841@@ -73,7 +89,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81842 static inline struct proc_dir_entry *proc_net_mkdir(
81843 struct net *net, const char *name, struct proc_dir_entry *parent)
81844 {
81845- return proc_mkdir_data(name, 0, parent, net);
81846+ return proc_mkdir_data_restrict(name, 0, parent, net);
81847 }
81848
81849 #endif /* _LINUX_PROC_FS_H */
81850diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81851index 34a1e10..70f6bde 100644
81852--- a/include/linux/proc_ns.h
81853+++ b/include/linux/proc_ns.h
81854@@ -14,7 +14,7 @@ struct proc_ns_operations {
81855 void (*put)(void *ns);
81856 int (*install)(struct nsproxy *nsproxy, void *ns);
81857 unsigned int (*inum)(void *ns);
81858-};
81859+} __do_const __randomize_layout;
81860
81861 struct proc_ns {
81862 void *ns;
81863diff --git a/include/linux/quota.h b/include/linux/quota.h
81864index cc7494a..1e27036 100644
81865--- a/include/linux/quota.h
81866+++ b/include/linux/quota.h
81867@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81868
81869 extern bool qid_eq(struct kqid left, struct kqid right);
81870 extern bool qid_lt(struct kqid left, struct kqid right);
81871-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81872+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81873 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81874 extern bool qid_valid(struct kqid qid);
81875
81876diff --git a/include/linux/random.h b/include/linux/random.h
81877index 1cfce0e..b0b9235 100644
81878--- a/include/linux/random.h
81879+++ b/include/linux/random.h
81880@@ -9,9 +9,19 @@
81881 #include <uapi/linux/random.h>
81882
81883 extern void add_device_randomness(const void *, unsigned int);
81884+
81885+static inline void add_latent_entropy(void)
81886+{
81887+
81888+#ifdef LATENT_ENTROPY_PLUGIN
81889+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81890+#endif
81891+
81892+}
81893+
81894 extern void add_input_randomness(unsigned int type, unsigned int code,
81895- unsigned int value);
81896-extern void add_interrupt_randomness(int irq, int irq_flags);
81897+ unsigned int value) __latent_entropy;
81898+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81899
81900 extern void get_random_bytes(void *buf, int nbytes);
81901 extern void get_random_bytes_arch(void *buf, int nbytes);
81902@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81903 extern const struct file_operations random_fops, urandom_fops;
81904 #endif
81905
81906-unsigned int get_random_int(void);
81907+unsigned int __intentional_overflow(-1) get_random_int(void);
81908 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81909
81910-u32 prandom_u32(void);
81911+u32 prandom_u32(void) __intentional_overflow(-1);
81912 void prandom_bytes(void *buf, int nbytes);
81913 void prandom_seed(u32 seed);
81914 void prandom_reseed_late(void);
81915@@ -37,6 +47,11 @@ struct rnd_state {
81916 u32 prandom_u32_state(struct rnd_state *state);
81917 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81918
81919+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81920+{
81921+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81922+}
81923+
81924 /**
81925 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81926 * @ep_ro: right open interval endpoint
81927diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81928index fea49b5..2ac22bb 100644
81929--- a/include/linux/rbtree_augmented.h
81930+++ b/include/linux/rbtree_augmented.h
81931@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81932 old->rbaugmented = rbcompute(old); \
81933 } \
81934 rbstatic const struct rb_augment_callbacks rbname = { \
81935- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81936+ .propagate = rbname ## _propagate, \
81937+ .copy = rbname ## _copy, \
81938+ .rotate = rbname ## _rotate \
81939 };
81940
81941
81942diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81943index dbaf990..52e07b8 100644
81944--- a/include/linux/rculist.h
81945+++ b/include/linux/rculist.h
81946@@ -29,8 +29,8 @@
81947 */
81948 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81949 {
81950- ACCESS_ONCE(list->next) = list;
81951- ACCESS_ONCE(list->prev) = list;
81952+ ACCESS_ONCE_RW(list->next) = list;
81953+ ACCESS_ONCE_RW(list->prev) = list;
81954 }
81955
81956 /*
81957@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81958 struct list_head *prev, struct list_head *next);
81959 #endif
81960
81961+void __pax_list_add_rcu(struct list_head *new,
81962+ struct list_head *prev, struct list_head *next);
81963+
81964 /**
81965 * list_add_rcu - add a new entry to rcu-protected list
81966 * @new: new entry to be added
81967@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81968 __list_add_rcu(new, head, head->next);
81969 }
81970
81971+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81972+{
81973+ __pax_list_add_rcu(new, head, head->next);
81974+}
81975+
81976 /**
81977 * list_add_tail_rcu - add a new entry to rcu-protected list
81978 * @new: new entry to be added
81979@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81980 __list_add_rcu(new, head->prev, head);
81981 }
81982
81983+static inline void pax_list_add_tail_rcu(struct list_head *new,
81984+ struct list_head *head)
81985+{
81986+ __pax_list_add_rcu(new, head->prev, head);
81987+}
81988+
81989 /**
81990 * list_del_rcu - deletes entry from list without re-initialization
81991 * @entry: the element to delete from the list.
81992@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81993 entry->prev = LIST_POISON2;
81994 }
81995
81996+extern void pax_list_del_rcu(struct list_head *entry);
81997+
81998 /**
81999 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
82000 * @n: the element to delete from the hash list.
82001diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
82002index 72bf3a0..853347f 100644
82003--- a/include/linux/rcupdate.h
82004+++ b/include/linux/rcupdate.h
82005@@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
82006 #define rcu_assign_pointer(p, v) \
82007 do { \
82008 smp_wmb(); \
82009- ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
82010+ ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
82011 } while (0)
82012
82013
82014diff --git a/include/linux/reboot.h b/include/linux/reboot.h
82015index 9e7db9e..7d4fd72 100644
82016--- a/include/linux/reboot.h
82017+++ b/include/linux/reboot.h
82018@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
82019 */
82020
82021 extern void migrate_to_reboot_cpu(void);
82022-extern void machine_restart(char *cmd);
82023-extern void machine_halt(void);
82024-extern void machine_power_off(void);
82025+extern void machine_restart(char *cmd) __noreturn;
82026+extern void machine_halt(void) __noreturn;
82027+extern void machine_power_off(void) __noreturn;
82028
82029 extern void machine_shutdown(void);
82030 struct pt_regs;
82031@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
82032 */
82033
82034 extern void kernel_restart_prepare(char *cmd);
82035-extern void kernel_restart(char *cmd);
82036-extern void kernel_halt(void);
82037-extern void kernel_power_off(void);
82038+extern void kernel_restart(char *cmd) __noreturn;
82039+extern void kernel_halt(void) __noreturn;
82040+extern void kernel_power_off(void) __noreturn;
82041
82042 extern int C_A_D; /* for sysctl */
82043 void ctrl_alt_del(void);
82044@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
82045 * Emergency restart, callable from an interrupt handler.
82046 */
82047
82048-extern void emergency_restart(void);
82049+extern void emergency_restart(void) __noreturn;
82050 #include <asm/emergency-restart.h>
82051
82052 #endif /* _LINUX_REBOOT_H */
82053diff --git a/include/linux/regset.h b/include/linux/regset.h
82054index 8e0c9fe..ac4d221 100644
82055--- a/include/linux/regset.h
82056+++ b/include/linux/regset.h
82057@@ -161,7 +161,8 @@ struct user_regset {
82058 unsigned int align;
82059 unsigned int bias;
82060 unsigned int core_note_type;
82061-};
82062+} __do_const;
82063+typedef struct user_regset __no_const user_regset_no_const;
82064
82065 /**
82066 * struct user_regset_view - available regsets
82067diff --git a/include/linux/relay.h b/include/linux/relay.h
82068index d7c8359..818daf5 100644
82069--- a/include/linux/relay.h
82070+++ b/include/linux/relay.h
82071@@ -157,7 +157,7 @@ struct rchan_callbacks
82072 * The callback should return 0 if successful, negative if not.
82073 */
82074 int (*remove_buf_file)(struct dentry *dentry);
82075-};
82076+} __no_const;
82077
82078 /*
82079 * CONFIG_RELAY kernel API, kernel/relay.c
82080diff --git a/include/linux/rio.h b/include/linux/rio.h
82081index b71d573..2f940bd 100644
82082--- a/include/linux/rio.h
82083+++ b/include/linux/rio.h
82084@@ -355,7 +355,7 @@ struct rio_ops {
82085 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
82086 u64 rstart, u32 size, u32 flags);
82087 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
82088-};
82089+} __no_const;
82090
82091 #define RIO_RESOURCE_MEM 0x00000100
82092 #define RIO_RESOURCE_DOORBELL 0x00000200
82093diff --git a/include/linux/rmap.h b/include/linux/rmap.h
82094index b66c211..13d2915 100644
82095--- a/include/linux/rmap.h
82096+++ b/include/linux/rmap.h
82097@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
82098 void anon_vma_init(void); /* create anon_vma_cachep */
82099 int anon_vma_prepare(struct vm_area_struct *);
82100 void unlink_anon_vmas(struct vm_area_struct *);
82101-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
82102-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
82103+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
82104+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
82105
82106 static inline void anon_vma_merge(struct vm_area_struct *vma,
82107 struct vm_area_struct *next)
82108diff --git a/include/linux/sched.h b/include/linux/sched.h
82109index a781dec..2c03225 100644
82110--- a/include/linux/sched.h
82111+++ b/include/linux/sched.h
82112@@ -129,6 +129,7 @@ struct fs_struct;
82113 struct perf_event_context;
82114 struct blk_plug;
82115 struct filename;
82116+struct linux_binprm;
82117
82118 /*
82119 * List of flags we want to share for kernel threads,
82120@@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
82121 extern int in_sched_functions(unsigned long addr);
82122
82123 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
82124-extern signed long schedule_timeout(signed long timeout);
82125+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
82126 extern signed long schedule_timeout_interruptible(signed long timeout);
82127 extern signed long schedule_timeout_killable(signed long timeout);
82128 extern signed long schedule_timeout_uninterruptible(signed long timeout);
82129@@ -380,6 +381,19 @@ struct nsproxy;
82130 struct user_namespace;
82131
82132 #ifdef CONFIG_MMU
82133+
82134+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82135+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
82136+#else
82137+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82138+{
82139+ return 0;
82140+}
82141+#endif
82142+
82143+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
82144+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
82145+
82146 extern void arch_pick_mmap_layout(struct mm_struct *mm);
82147 extern unsigned long
82148 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
82149@@ -677,6 +691,17 @@ struct signal_struct {
82150 #ifdef CONFIG_TASKSTATS
82151 struct taskstats *stats;
82152 #endif
82153+
82154+#ifdef CONFIG_GRKERNSEC
82155+ u32 curr_ip;
82156+ u32 saved_ip;
82157+ u32 gr_saddr;
82158+ u32 gr_daddr;
82159+ u16 gr_sport;
82160+ u16 gr_dport;
82161+ u8 used_accept:1;
82162+#endif
82163+
82164 #ifdef CONFIG_AUDIT
82165 unsigned audit_tty;
82166 unsigned audit_tty_log_passwd;
82167@@ -703,7 +728,7 @@ struct signal_struct {
82168 struct mutex cred_guard_mutex; /* guard against foreign influences on
82169 * credential calculations
82170 * (notably. ptrace) */
82171-};
82172+} __randomize_layout;
82173
82174 /*
82175 * Bits in flags field of signal_struct.
82176@@ -757,6 +782,14 @@ struct user_struct {
82177 struct key *session_keyring; /* UID's default session keyring */
82178 #endif
82179
82180+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
82181+ unsigned char kernel_banned;
82182+#endif
82183+#ifdef CONFIG_GRKERNSEC_BRUTE
82184+ unsigned char suid_banned;
82185+ unsigned long suid_ban_expires;
82186+#endif
82187+
82188 /* Hash table maintenance information */
82189 struct hlist_node uidhash_node;
82190 kuid_t uid;
82191@@ -764,7 +797,7 @@ struct user_struct {
82192 #ifdef CONFIG_PERF_EVENTS
82193 atomic_long_t locked_vm;
82194 #endif
82195-};
82196+} __randomize_layout;
82197
82198 extern int uids_sysfs_init(void);
82199
82200@@ -1286,8 +1319,8 @@ struct task_struct {
82201 struct list_head thread_node;
82202
82203 struct completion *vfork_done; /* for vfork() */
82204- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
82205- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82206+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
82207+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82208
82209 cputime_t utime, stime, utimescaled, stimescaled;
82210 cputime_t gtime;
82211@@ -1312,11 +1345,6 @@ struct task_struct {
82212 struct task_cputime cputime_expires;
82213 struct list_head cpu_timers[3];
82214
82215-/* process credentials */
82216- const struct cred __rcu *real_cred; /* objective and real subjective task
82217- * credentials (COW) */
82218- const struct cred __rcu *cred; /* effective (overridable) subjective task
82219- * credentials (COW) */
82220 char comm[TASK_COMM_LEN]; /* executable name excluding path
82221 - access with [gs]et_task_comm (which lock
82222 it with task_lock())
82223@@ -1333,6 +1361,10 @@ struct task_struct {
82224 #endif
82225 /* CPU-specific state of this task */
82226 struct thread_struct thread;
82227+/* thread_info moved to task_struct */
82228+#ifdef CONFIG_X86
82229+ struct thread_info tinfo;
82230+#endif
82231 /* filesystem information */
82232 struct fs_struct *fs;
82233 /* open file information */
82234@@ -1409,6 +1441,10 @@ struct task_struct {
82235 gfp_t lockdep_reclaim_gfp;
82236 #endif
82237
82238+/* process credentials */
82239+ const struct cred __rcu *real_cred; /* objective and real subjective task
82240+ * credentials (COW) */
82241+
82242 /* journalling filesystem info */
82243 void *journal_info;
82244
82245@@ -1447,6 +1483,10 @@ struct task_struct {
82246 /* cg_list protected by css_set_lock and tsk->alloc_lock */
82247 struct list_head cg_list;
82248 #endif
82249+
82250+ const struct cred __rcu *cred; /* effective (overridable) subjective task
82251+ * credentials (COW) */
82252+
82253 #ifdef CONFIG_FUTEX
82254 struct robust_list_head __user *robust_list;
82255 #ifdef CONFIG_COMPAT
82256@@ -1581,7 +1621,78 @@ struct task_struct {
82257 unsigned int sequential_io;
82258 unsigned int sequential_io_avg;
82259 #endif
82260-};
82261+
82262+#ifdef CONFIG_GRKERNSEC
82263+ /* grsecurity */
82264+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82265+ u64 exec_id;
82266+#endif
82267+#ifdef CONFIG_GRKERNSEC_SETXID
82268+ const struct cred *delayed_cred;
82269+#endif
82270+ struct dentry *gr_chroot_dentry;
82271+ struct acl_subject_label *acl;
82272+ struct acl_subject_label *tmpacl;
82273+ struct acl_role_label *role;
82274+ struct file *exec_file;
82275+ unsigned long brute_expires;
82276+ u16 acl_role_id;
82277+ u8 inherited;
82278+ /* is this the task that authenticated to the special role */
82279+ u8 acl_sp_role;
82280+ u8 is_writable;
82281+ u8 brute;
82282+ u8 gr_is_chrooted;
82283+#endif
82284+
82285+} __randomize_layout;
82286+
82287+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82288+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82289+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82290+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82291+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82292+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82293+
82294+#ifdef CONFIG_PAX_SOFTMODE
82295+extern int pax_softmode;
82296+#endif
82297+
82298+extern int pax_check_flags(unsigned long *);
82299+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82300+
82301+/* if tsk != current then task_lock must be held on it */
82302+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82303+static inline unsigned long pax_get_flags(struct task_struct *tsk)
82304+{
82305+ if (likely(tsk->mm))
82306+ return tsk->mm->pax_flags;
82307+ else
82308+ return 0UL;
82309+}
82310+
82311+/* if tsk != current then task_lock must be held on it */
82312+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82313+{
82314+ if (likely(tsk->mm)) {
82315+ tsk->mm->pax_flags = flags;
82316+ return 0;
82317+ }
82318+ return -EINVAL;
82319+}
82320+#endif
82321+
82322+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82323+extern void pax_set_initial_flags(struct linux_binprm *bprm);
82324+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82325+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82326+#endif
82327+
82328+struct path;
82329+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82330+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82331+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82332+extern void pax_report_refcount_overflow(struct pt_regs *regs);
82333
82334 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82335 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82336@@ -1658,7 +1769,7 @@ struct pid_namespace;
82337 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82338 struct pid_namespace *ns);
82339
82340-static inline pid_t task_pid_nr(struct task_struct *tsk)
82341+static inline pid_t task_pid_nr(const struct task_struct *tsk)
82342 {
82343 return tsk->pid;
82344 }
82345@@ -1988,6 +2099,25 @@ extern u64 sched_clock_cpu(int cpu);
82346
82347 extern void sched_clock_init(void);
82348
82349+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82350+static inline void populate_stack(void)
82351+{
82352+ struct task_struct *curtask = current;
82353+ int c;
82354+ int *ptr = curtask->stack;
82355+ int *end = curtask->stack + THREAD_SIZE;
82356+
82357+ while (ptr < end) {
82358+ c = *(volatile int *)ptr;
82359+ ptr += PAGE_SIZE/sizeof(int);
82360+ }
82361+}
82362+#else
82363+static inline void populate_stack(void)
82364+{
82365+}
82366+#endif
82367+
82368 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
82369 static inline void sched_clock_tick(void)
82370 {
82371@@ -2112,7 +2242,9 @@ void yield(void);
82372 extern struct exec_domain default_exec_domain;
82373
82374 union thread_union {
82375+#ifndef CONFIG_X86
82376 struct thread_info thread_info;
82377+#endif
82378 unsigned long stack[THREAD_SIZE/sizeof(long)];
82379 };
82380
82381@@ -2145,6 +2277,7 @@ extern struct pid_namespace init_pid_ns;
82382 */
82383
82384 extern struct task_struct *find_task_by_vpid(pid_t nr);
82385+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82386 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82387 struct pid_namespace *ns);
82388
82389@@ -2307,7 +2440,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82390 extern void exit_itimers(struct signal_struct *);
82391 extern void flush_itimer_signals(void);
82392
82393-extern void do_group_exit(int);
82394+extern __noreturn void do_group_exit(int);
82395
82396 extern int allow_signal(int);
82397 extern int disallow_signal(int);
82398@@ -2508,9 +2641,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82399
82400 #endif
82401
82402-static inline int object_is_on_stack(void *obj)
82403+static inline int object_starts_on_stack(void *obj)
82404 {
82405- void *stack = task_stack_page(current);
82406+ const void *stack = task_stack_page(current);
82407
82408 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82409 }
82410diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82411index 8045a55..c959cd5 100644
82412--- a/include/linux/sched/sysctl.h
82413+++ b/include/linux/sched/sysctl.h
82414@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82415 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82416
82417 extern int sysctl_max_map_count;
82418+extern unsigned long sysctl_heap_stack_gap;
82419
82420 extern unsigned int sysctl_sched_latency;
82421 extern unsigned int sysctl_sched_min_granularity;
82422diff --git a/include/linux/security.h b/include/linux/security.h
82423index 2fc42d1..4d802f2 100644
82424--- a/include/linux/security.h
82425+++ b/include/linux/security.h
82426@@ -27,6 +27,7 @@
82427 #include <linux/slab.h>
82428 #include <linux/err.h>
82429 #include <linux/string.h>
82430+#include <linux/grsecurity.h>
82431
82432 struct linux_binprm;
82433 struct cred;
82434@@ -116,8 +117,6 @@ struct seq_file;
82435
82436 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82437
82438-void reset_security_ops(void);
82439-
82440 #ifdef CONFIG_MMU
82441 extern unsigned long mmap_min_addr;
82442 extern unsigned long dac_mmap_min_addr;
82443@@ -1719,7 +1718,7 @@ struct security_operations {
82444 struct audit_context *actx);
82445 void (*audit_rule_free) (void *lsmrule);
82446 #endif /* CONFIG_AUDIT */
82447-};
82448+} __randomize_layout;
82449
82450 /* prototypes */
82451 extern int security_init(void);
82452diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82453index dc368b8..e895209 100644
82454--- a/include/linux/semaphore.h
82455+++ b/include/linux/semaphore.h
82456@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82457 }
82458
82459 extern void down(struct semaphore *sem);
82460-extern int __must_check down_interruptible(struct semaphore *sem);
82461+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82462 extern int __must_check down_killable(struct semaphore *sem);
82463 extern int __must_check down_trylock(struct semaphore *sem);
82464 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82465diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82466index 52e0097..383f21d 100644
82467--- a/include/linux/seq_file.h
82468+++ b/include/linux/seq_file.h
82469@@ -27,6 +27,9 @@ struct seq_file {
82470 struct mutex lock;
82471 const struct seq_operations *op;
82472 int poll_event;
82473+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82474+ u64 exec_id;
82475+#endif
82476 #ifdef CONFIG_USER_NS
82477 struct user_namespace *user_ns;
82478 #endif
82479@@ -39,6 +42,7 @@ struct seq_operations {
82480 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82481 int (*show) (struct seq_file *m, void *v);
82482 };
82483+typedef struct seq_operations __no_const seq_operations_no_const;
82484
82485 #define SEQ_SKIP 1
82486
82487@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82488
82489 char *mangle_path(char *s, const char *p, const char *esc);
82490 int seq_open(struct file *, const struct seq_operations *);
82491+int seq_open_restrict(struct file *, const struct seq_operations *);
82492 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82493 loff_t seq_lseek(struct file *, loff_t, int);
82494 int seq_release(struct inode *, struct file *);
82495@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82496 }
82497
82498 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82499+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82500 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82501 int single_release(struct inode *, struct file *);
82502 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82503diff --git a/include/linux/shm.h b/include/linux/shm.h
82504index 1e2cd2e..0288750 100644
82505--- a/include/linux/shm.h
82506+++ b/include/linux/shm.h
82507@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82508
82509 /* The task created the shm object. NULL if the task is dead. */
82510 struct task_struct *shm_creator;
82511+#ifdef CONFIG_GRKERNSEC
82512+ time_t shm_createtime;
82513+ pid_t shm_lapid;
82514+#endif
82515 };
82516
82517 /* shm_mode upper byte flags */
82518diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82519index 15ede6a..80161c3 100644
82520--- a/include/linux/skbuff.h
82521+++ b/include/linux/skbuff.h
82522@@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82523 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82524 int node);
82525 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82526-static inline struct sk_buff *alloc_skb(unsigned int size,
82527+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82528 gfp_t priority)
82529 {
82530 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82531@@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82532 return skb->inner_transport_header - skb->inner_network_header;
82533 }
82534
82535-static inline int skb_network_offset(const struct sk_buff *skb)
82536+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82537 {
82538 return skb_network_header(skb) - skb->data;
82539 }
82540@@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82541 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82542 */
82543 #ifndef NET_SKB_PAD
82544-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82545+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82546 #endif
82547
82548 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82549@@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82550 int *err);
82551 unsigned int datagram_poll(struct file *file, struct socket *sock,
82552 struct poll_table_struct *wait);
82553-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82554+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82555 struct iovec *to, int size);
82556 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82557 struct iovec *iov);
82558@@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
82559 nf_bridge_put(skb->nf_bridge);
82560 skb->nf_bridge = NULL;
82561 #endif
82562+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82563+ skb->nf_trace = 0;
82564+#endif
82565 }
82566
82567 static inline void nf_reset_trace(struct sk_buff *skb)
82568diff --git a/include/linux/slab.h b/include/linux/slab.h
82569index b5b2df6..69f5734 100644
82570--- a/include/linux/slab.h
82571+++ b/include/linux/slab.h
82572@@ -14,15 +14,29 @@
82573 #include <linux/gfp.h>
82574 #include <linux/types.h>
82575 #include <linux/workqueue.h>
82576-
82577+#include <linux/err.h>
82578
82579 /*
82580 * Flags to pass to kmem_cache_create().
82581 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82582 */
82583 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82584+
82585+#ifdef CONFIG_PAX_USERCOPY_SLABS
82586+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82587+#else
82588+#define SLAB_USERCOPY 0x00000000UL
82589+#endif
82590+
82591 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82592 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82593+
82594+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82595+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82596+#else
82597+#define SLAB_NO_SANITIZE 0x00000000UL
82598+#endif
82599+
82600 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82601 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82602 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82603@@ -98,10 +112,13 @@
82604 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82605 * Both make kfree a no-op.
82606 */
82607-#define ZERO_SIZE_PTR ((void *)16)
82608+#define ZERO_SIZE_PTR \
82609+({ \
82610+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82611+ (void *)(-MAX_ERRNO-1L); \
82612+})
82613
82614-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82615- (unsigned long)ZERO_SIZE_PTR)
82616+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82617
82618 #include <linux/kmemleak.h>
82619
82620@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82621 void kfree(const void *);
82622 void kzfree(const void *);
82623 size_t ksize(const void *);
82624+const char *check_heap_object(const void *ptr, unsigned long n);
82625+bool is_usercopy_object(const void *ptr);
82626
82627 /*
82628 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82629@@ -174,7 +193,7 @@ struct kmem_cache {
82630 unsigned int align; /* Alignment as calculated */
82631 unsigned long flags; /* Active flags on the slab */
82632 const char *name; /* Slab name for sysfs */
82633- int refcount; /* Use counter */
82634+ atomic_t refcount; /* Use counter */
82635 void (*ctor)(void *); /* Called on object slot creation */
82636 struct list_head list; /* List of all slab caches on the system */
82637 };
82638@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82639 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82640 #endif
82641
82642+#ifdef CONFIG_PAX_USERCOPY_SLABS
82643+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82644+#endif
82645+
82646 /*
82647 * Figure out which kmalloc slab an allocation of a certain size
82648 * belongs to.
82649@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82650 * 2 = 120 .. 192 bytes
82651 * n = 2^(n-1) .. 2^n -1
82652 */
82653-static __always_inline int kmalloc_index(size_t size)
82654+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82655 {
82656 if (!size)
82657 return 0;
82658@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
82659 }
82660 #endif /* !CONFIG_SLOB */
82661
82662-void *__kmalloc(size_t size, gfp_t flags);
82663+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82664 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82665
82666 #ifdef CONFIG_NUMA
82667-void *__kmalloc_node(size_t size, gfp_t flags, int node);
82668+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82669 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82670 #else
82671 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82672diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82673index 8235dfb..47ce586 100644
82674--- a/include/linux/slab_def.h
82675+++ b/include/linux/slab_def.h
82676@@ -38,7 +38,7 @@ struct kmem_cache {
82677 /* 4) cache creation/removal */
82678 const char *name;
82679 struct list_head list;
82680- int refcount;
82681+ atomic_t refcount;
82682 int object_size;
82683 int align;
82684
82685@@ -54,10 +54,14 @@ struct kmem_cache {
82686 unsigned long node_allocs;
82687 unsigned long node_frees;
82688 unsigned long node_overflow;
82689- atomic_t allochit;
82690- atomic_t allocmiss;
82691- atomic_t freehit;
82692- atomic_t freemiss;
82693+ atomic_unchecked_t allochit;
82694+ atomic_unchecked_t allocmiss;
82695+ atomic_unchecked_t freehit;
82696+ atomic_unchecked_t freemiss;
82697+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82698+ atomic_unchecked_t sanitized;
82699+ atomic_unchecked_t not_sanitized;
82700+#endif
82701
82702 /*
82703 * If debugging is enabled, then the allocator can add additional
82704diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82705index f56bfa9..8378a26 100644
82706--- a/include/linux/slub_def.h
82707+++ b/include/linux/slub_def.h
82708@@ -74,7 +74,7 @@ struct kmem_cache {
82709 struct kmem_cache_order_objects max;
82710 struct kmem_cache_order_objects min;
82711 gfp_t allocflags; /* gfp flags to use on each alloc */
82712- int refcount; /* Refcount for slab cache destroy */
82713+ atomic_t refcount; /* Refcount for slab cache destroy */
82714 void (*ctor)(void *);
82715 int inuse; /* Offset to metadata */
82716 int align; /* Alignment */
82717diff --git a/include/linux/smp.h b/include/linux/smp.h
82718index 6ae004e..2743532 100644
82719--- a/include/linux/smp.h
82720+++ b/include/linux/smp.h
82721@@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
82722 #endif
82723
82724 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82725+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82726 #define put_cpu() preempt_enable()
82727+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82728
82729 /*
82730 * Callback to arch code if there's nosmp or maxcpus=0 on the
82731diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82732index 54f91d3..be2c379 100644
82733--- a/include/linux/sock_diag.h
82734+++ b/include/linux/sock_diag.h
82735@@ -11,7 +11,7 @@ struct sock;
82736 struct sock_diag_handler {
82737 __u8 family;
82738 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82739-};
82740+} __do_const;
82741
82742 int sock_diag_register(const struct sock_diag_handler *h);
82743 void sock_diag_unregister(const struct sock_diag_handler *h);
82744diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82745index 680f9a3..f13aeb0 100644
82746--- a/include/linux/sonet.h
82747+++ b/include/linux/sonet.h
82748@@ -7,7 +7,7 @@
82749 #include <uapi/linux/sonet.h>
82750
82751 struct k_sonet_stats {
82752-#define __HANDLE_ITEM(i) atomic_t i
82753+#define __HANDLE_ITEM(i) atomic_unchecked_t i
82754 __SONET_ITEMS
82755 #undef __HANDLE_ITEM
82756 };
82757diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82758index 07d8e53..dc934c9 100644
82759--- a/include/linux/sunrpc/addr.h
82760+++ b/include/linux/sunrpc/addr.h
82761@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82762 {
82763 switch (sap->sa_family) {
82764 case AF_INET:
82765- return ntohs(((struct sockaddr_in *)sap)->sin_port);
82766+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82767 case AF_INET6:
82768- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82769+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82770 }
82771 return 0;
82772 }
82773@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82774 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82775 const struct sockaddr *src)
82776 {
82777- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82778+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82779 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82780
82781 dsin->sin_family = ssin->sin_family;
82782@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82783 if (sa->sa_family != AF_INET6)
82784 return 0;
82785
82786- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82787+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82788 }
82789
82790 #endif /* _LINUX_SUNRPC_ADDR_H */
82791diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82792index 8af2804..c7414ef 100644
82793--- a/include/linux/sunrpc/clnt.h
82794+++ b/include/linux/sunrpc/clnt.h
82795@@ -97,7 +97,7 @@ struct rpc_procinfo {
82796 unsigned int p_timer; /* Which RTT timer to use */
82797 u32 p_statidx; /* Which procedure to account */
82798 const char * p_name; /* name of procedure */
82799-};
82800+} __do_const;
82801
82802 #ifdef __KERNEL__
82803
82804diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82805index 04e7632..2e2a8a3 100644
82806--- a/include/linux/sunrpc/svc.h
82807+++ b/include/linux/sunrpc/svc.h
82808@@ -412,7 +412,7 @@ struct svc_procedure {
82809 unsigned int pc_count; /* call count */
82810 unsigned int pc_cachetype; /* cache info (NFS) */
82811 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82812-};
82813+} __do_const;
82814
82815 /*
82816 * Function prototypes.
82817diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82818index 0b8e3e6..33e0a01 100644
82819--- a/include/linux/sunrpc/svc_rdma.h
82820+++ b/include/linux/sunrpc/svc_rdma.h
82821@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82822 extern unsigned int svcrdma_max_requests;
82823 extern unsigned int svcrdma_max_req_size;
82824
82825-extern atomic_t rdma_stat_recv;
82826-extern atomic_t rdma_stat_read;
82827-extern atomic_t rdma_stat_write;
82828-extern atomic_t rdma_stat_sq_starve;
82829-extern atomic_t rdma_stat_rq_starve;
82830-extern atomic_t rdma_stat_rq_poll;
82831-extern atomic_t rdma_stat_rq_prod;
82832-extern atomic_t rdma_stat_sq_poll;
82833-extern atomic_t rdma_stat_sq_prod;
82834+extern atomic_unchecked_t rdma_stat_recv;
82835+extern atomic_unchecked_t rdma_stat_read;
82836+extern atomic_unchecked_t rdma_stat_write;
82837+extern atomic_unchecked_t rdma_stat_sq_starve;
82838+extern atomic_unchecked_t rdma_stat_rq_starve;
82839+extern atomic_unchecked_t rdma_stat_rq_poll;
82840+extern atomic_unchecked_t rdma_stat_rq_prod;
82841+extern atomic_unchecked_t rdma_stat_sq_poll;
82842+extern atomic_unchecked_t rdma_stat_sq_prod;
82843
82844 #define RPCRDMA_VERSION 1
82845
82846diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82847index 8d71d65..f79586e 100644
82848--- a/include/linux/sunrpc/svcauth.h
82849+++ b/include/linux/sunrpc/svcauth.h
82850@@ -120,7 +120,7 @@ struct auth_ops {
82851 int (*release)(struct svc_rqst *rq);
82852 void (*domain_release)(struct auth_domain *);
82853 int (*set_client)(struct svc_rqst *rq);
82854-};
82855+} __do_const;
82856
82857 #define SVC_GARBAGE 1
82858 #define SVC_SYSERR 2
82859diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82860index a5ffd32..0935dea 100644
82861--- a/include/linux/swiotlb.h
82862+++ b/include/linux/swiotlb.h
82863@@ -60,7 +60,8 @@ extern void
82864
82865 extern void
82866 swiotlb_free_coherent(struct device *hwdev, size_t size,
82867- void *vaddr, dma_addr_t dma_handle);
82868+ void *vaddr, dma_addr_t dma_handle,
82869+ struct dma_attrs *attrs);
82870
82871 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82872 unsigned long offset, size_t size,
82873diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82874index a747a77..9e14df7 100644
82875--- a/include/linux/syscalls.h
82876+++ b/include/linux/syscalls.h
82877@@ -98,8 +98,14 @@ struct sigaltstack;
82878 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82879
82880 #define __SC_DECL(t, a) t a
82881+#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))
82882 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82883-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82884+#define __SC_LONG(t, a) __typeof( \
82885+ __builtin_choose_expr( \
82886+ sizeof(t) > sizeof(int), \
82887+ (t) 0, \
82888+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82889+ )) a
82890 #define __SC_CAST(t, a) (t) a
82891 #define __SC_ARGS(t, a) a
82892 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82893@@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
82894 asmlinkage long sys_fsync(unsigned int fd);
82895 asmlinkage long sys_fdatasync(unsigned int fd);
82896 asmlinkage long sys_bdflush(int func, long data);
82897-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82898- char __user *type, unsigned long flags,
82899+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82900+ const char __user *type, unsigned long flags,
82901 void __user *data);
82902-asmlinkage long sys_umount(char __user *name, int flags);
82903-asmlinkage long sys_oldumount(char __user *name);
82904+asmlinkage long sys_umount(const char __user *name, int flags);
82905+asmlinkage long sys_oldumount(const char __user *name);
82906 asmlinkage long sys_truncate(const char __user *path, long length);
82907 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82908 asmlinkage long sys_stat(const char __user *filename,
82909@@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82910 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82911 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82912 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82913- struct sockaddr __user *, int);
82914+ struct sockaddr __user *, int) __intentional_overflow(0);
82915 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82916 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82917 unsigned int vlen, unsigned flags);
82918diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82919index 27b3b0b..e093dd9 100644
82920--- a/include/linux/syscore_ops.h
82921+++ b/include/linux/syscore_ops.h
82922@@ -16,7 +16,7 @@ struct syscore_ops {
82923 int (*suspend)(void);
82924 void (*resume)(void);
82925 void (*shutdown)(void);
82926-};
82927+} __do_const;
82928
82929 extern void register_syscore_ops(struct syscore_ops *ops);
82930 extern void unregister_syscore_ops(struct syscore_ops *ops);
82931diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82932index 14a8ff2..fa95f3a 100644
82933--- a/include/linux/sysctl.h
82934+++ b/include/linux/sysctl.h
82935@@ -34,13 +34,13 @@ struct ctl_table_root;
82936 struct ctl_table_header;
82937 struct ctl_dir;
82938
82939-typedef struct ctl_table ctl_table;
82940-
82941 typedef int proc_handler (struct ctl_table *ctl, int write,
82942 void __user *buffer, size_t *lenp, loff_t *ppos);
82943
82944 extern int proc_dostring(struct ctl_table *, int,
82945 void __user *, size_t *, loff_t *);
82946+extern int proc_dostring_modpriv(struct ctl_table *, int,
82947+ void __user *, size_t *, loff_t *);
82948 extern int proc_dointvec(struct ctl_table *, int,
82949 void __user *, size_t *, loff_t *);
82950 extern int proc_dointvec_minmax(struct ctl_table *, int,
82951@@ -115,7 +115,9 @@ struct ctl_table
82952 struct ctl_table_poll *poll;
82953 void *extra1;
82954 void *extra2;
82955-};
82956+} __do_const __randomize_layout;
82957+typedef struct ctl_table __no_const ctl_table_no_const;
82958+typedef struct ctl_table ctl_table;
82959
82960 struct ctl_node {
82961 struct rb_node node;
82962diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82963index 30b2ebe..37412ef 100644
82964--- a/include/linux/sysfs.h
82965+++ b/include/linux/sysfs.h
82966@@ -34,7 +34,8 @@ struct attribute {
82967 struct lock_class_key *key;
82968 struct lock_class_key skey;
82969 #endif
82970-};
82971+} __do_const;
82972+typedef struct attribute __no_const attribute_no_const;
82973
82974 /**
82975 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82976@@ -63,7 +64,8 @@ struct attribute_group {
82977 struct attribute *, int);
82978 struct attribute **attrs;
82979 struct bin_attribute **bin_attrs;
82980-};
82981+} __do_const;
82982+typedef struct attribute_group __no_const attribute_group_no_const;
82983
82984 /**
82985 * Use these macros to make defining attributes easier. See include/linux/device.h
82986@@ -127,7 +129,8 @@ struct bin_attribute {
82987 char *, loff_t, size_t);
82988 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82989 struct vm_area_struct *vma);
82990-};
82991+} __do_const;
82992+typedef struct bin_attribute __no_const bin_attribute_no_const;
82993
82994 /**
82995 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82996diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82997index 387fa7d..3fcde6b 100644
82998--- a/include/linux/sysrq.h
82999+++ b/include/linux/sysrq.h
83000@@ -16,6 +16,7 @@
83001
83002 #include <linux/errno.h>
83003 #include <linux/types.h>
83004+#include <linux/compiler.h>
83005
83006 /* Possible values of bitmask for enabling sysrq functions */
83007 /* 0x0001 is reserved for enable everything */
83008@@ -33,7 +34,7 @@ struct sysrq_key_op {
83009 char *help_msg;
83010 char *action_msg;
83011 int enable_mask;
83012-};
83013+} __do_const;
83014
83015 #ifdef CONFIG_MAGIC_SYSRQ
83016
83017diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
83018index fddbe20..e4cce53 100644
83019--- a/include/linux/thread_info.h
83020+++ b/include/linux/thread_info.h
83021@@ -161,6 +161,25 @@ static inline bool test_and_clear_restore_sigmask(void)
83022 #error "no set_restore_sigmask() provided and default one won't work"
83023 #endif
83024
83025+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
83026+
83027+#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
83028+extern void pax_check_alloca(unsigned long size);
83029+#endif
83030+
83031+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
83032+{
83033+#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
83034+ /* always check if we've overflowed the stack in a copy*user */
83035+ pax_check_alloca(sizeof(unsigned long));
83036+#endif
83037+
83038+#ifndef CONFIG_PAX_USERCOPY_DEBUG
83039+ if (!__builtin_constant_p(n))
83040+#endif
83041+ __check_object_size(ptr, n, to_user);
83042+}
83043+
83044 #endif /* __KERNEL__ */
83045
83046 #endif /* _LINUX_THREAD_INFO_H */
83047diff --git a/include/linux/tty.h b/include/linux/tty.h
83048index b90b5c2..e23a512 100644
83049--- a/include/linux/tty.h
83050+++ b/include/linux/tty.h
83051@@ -202,7 +202,7 @@ struct tty_port {
83052 const struct tty_port_operations *ops; /* Port operations */
83053 spinlock_t lock; /* Lock protecting tty field */
83054 int blocked_open; /* Waiting to open */
83055- int count; /* Usage count */
83056+ atomic_t count; /* Usage count */
83057 wait_queue_head_t open_wait; /* Open waiters */
83058 wait_queue_head_t close_wait; /* Close waiters */
83059 wait_queue_head_t delta_msr_wait; /* Modem status change */
83060@@ -284,7 +284,7 @@ struct tty_struct {
83061 /* If the tty has a pending do_SAK, queue it here - akpm */
83062 struct work_struct SAK_work;
83063 struct tty_port *port;
83064-};
83065+} __randomize_layout;
83066
83067 /* Each of a tty's open files has private_data pointing to tty_file_private */
83068 struct tty_file_private {
83069@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
83070 struct tty_struct *tty, struct file *filp);
83071 static inline int tty_port_users(struct tty_port *port)
83072 {
83073- return port->count + port->blocked_open;
83074+ return atomic_read(&port->count) + port->blocked_open;
83075 }
83076
83077 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
83078diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
83079index 756a609..89db85e 100644
83080--- a/include/linux/tty_driver.h
83081+++ b/include/linux/tty_driver.h
83082@@ -285,7 +285,7 @@ struct tty_operations {
83083 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
83084 #endif
83085 const struct file_operations *proc_fops;
83086-};
83087+} __do_const __randomize_layout;
83088
83089 struct tty_driver {
83090 int magic; /* magic number for this structure */
83091@@ -319,7 +319,7 @@ struct tty_driver {
83092
83093 const struct tty_operations *ops;
83094 struct list_head tty_drivers;
83095-};
83096+} __randomize_layout;
83097
83098 extern struct list_head tty_drivers;
83099
83100diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
83101index b8347c2..85d8b0f 100644
83102--- a/include/linux/tty_ldisc.h
83103+++ b/include/linux/tty_ldisc.h
83104@@ -213,7 +213,7 @@ struct tty_ldisc_ops {
83105
83106 struct module *owner;
83107
83108- int refcount;
83109+ atomic_t refcount;
83110 };
83111
83112 struct tty_ldisc {
83113diff --git a/include/linux/types.h b/include/linux/types.h
83114index 4d118ba..c3ee9bf 100644
83115--- a/include/linux/types.h
83116+++ b/include/linux/types.h
83117@@ -176,10 +176,26 @@ typedef struct {
83118 int counter;
83119 } atomic_t;
83120
83121+#ifdef CONFIG_PAX_REFCOUNT
83122+typedef struct {
83123+ int counter;
83124+} atomic_unchecked_t;
83125+#else
83126+typedef atomic_t atomic_unchecked_t;
83127+#endif
83128+
83129 #ifdef CONFIG_64BIT
83130 typedef struct {
83131 long counter;
83132 } atomic64_t;
83133+
83134+#ifdef CONFIG_PAX_REFCOUNT
83135+typedef struct {
83136+ long counter;
83137+} atomic64_unchecked_t;
83138+#else
83139+typedef atomic64_t atomic64_unchecked_t;
83140+#endif
83141 #endif
83142
83143 struct list_head {
83144diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
83145index ecd3319..8a36ded 100644
83146--- a/include/linux/uaccess.h
83147+++ b/include/linux/uaccess.h
83148@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
83149 long ret; \
83150 mm_segment_t old_fs = get_fs(); \
83151 \
83152- set_fs(KERNEL_DS); \
83153 pagefault_disable(); \
83154- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
83155- pagefault_enable(); \
83156+ set_fs(KERNEL_DS); \
83157+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
83158 set_fs(old_fs); \
83159+ pagefault_enable(); \
83160 ret; \
83161 })
83162
83163diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
83164index 2d1f9b6..d7a9fce 100644
83165--- a/include/linux/uidgid.h
83166+++ b/include/linux/uidgid.h
83167@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
83168
83169 #endif /* CONFIG_USER_NS */
83170
83171+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
83172+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
83173+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
83174+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
83175+
83176 #endif /* _LINUX_UIDGID_H */
83177diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
83178index 99c1b4d..562e6f3 100644
83179--- a/include/linux/unaligned/access_ok.h
83180+++ b/include/linux/unaligned/access_ok.h
83181@@ -4,34 +4,34 @@
83182 #include <linux/kernel.h>
83183 #include <asm/byteorder.h>
83184
83185-static inline u16 get_unaligned_le16(const void *p)
83186+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
83187 {
83188- return le16_to_cpup((__le16 *)p);
83189+ return le16_to_cpup((const __le16 *)p);
83190 }
83191
83192-static inline u32 get_unaligned_le32(const void *p)
83193+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
83194 {
83195- return le32_to_cpup((__le32 *)p);
83196+ return le32_to_cpup((const __le32 *)p);
83197 }
83198
83199-static inline u64 get_unaligned_le64(const void *p)
83200+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
83201 {
83202- return le64_to_cpup((__le64 *)p);
83203+ return le64_to_cpup((const __le64 *)p);
83204 }
83205
83206-static inline u16 get_unaligned_be16(const void *p)
83207+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
83208 {
83209- return be16_to_cpup((__be16 *)p);
83210+ return be16_to_cpup((const __be16 *)p);
83211 }
83212
83213-static inline u32 get_unaligned_be32(const void *p)
83214+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
83215 {
83216- return be32_to_cpup((__be32 *)p);
83217+ return be32_to_cpup((const __be32 *)p);
83218 }
83219
83220-static inline u64 get_unaligned_be64(const void *p)
83221+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
83222 {
83223- return be64_to_cpup((__be64 *)p);
83224+ return be64_to_cpup((const __be64 *)p);
83225 }
83226
83227 static inline void put_unaligned_le16(u16 val, void *p)
83228diff --git a/include/linux/usb.h b/include/linux/usb.h
83229index 7f6eb85..656e806 100644
83230--- a/include/linux/usb.h
83231+++ b/include/linux/usb.h
83232@@ -563,7 +563,7 @@ struct usb_device {
83233 int maxchild;
83234
83235 u32 quirks;
83236- atomic_t urbnum;
83237+ atomic_unchecked_t urbnum;
83238
83239 unsigned long active_duration;
83240
83241@@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
83242
83243 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
83244 __u8 request, __u8 requesttype, __u16 value, __u16 index,
83245- void *data, __u16 size, int timeout);
83246+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
83247 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
83248 void *data, int len, int *actual_length, int timeout);
83249 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
83250diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
83251index e452ba6..78f8e80 100644
83252--- a/include/linux/usb/renesas_usbhs.h
83253+++ b/include/linux/usb/renesas_usbhs.h
83254@@ -39,7 +39,7 @@ enum {
83255 */
83256 struct renesas_usbhs_driver_callback {
83257 int (*notify_hotplug)(struct platform_device *pdev);
83258-};
83259+} __no_const;
83260
83261 /*
83262 * callback functions for platform
83263diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83264index 4836ba3..603f6ee 100644
83265--- a/include/linux/user_namespace.h
83266+++ b/include/linux/user_namespace.h
83267@@ -33,7 +33,7 @@ struct user_namespace {
83268 struct key *persistent_keyring_register;
83269 struct rw_semaphore persistent_keyring_register_sem;
83270 #endif
83271-};
83272+} __randomize_layout;
83273
83274 extern struct user_namespace init_user_ns;
83275
83276diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83277index 239e277..22a5cf5 100644
83278--- a/include/linux/utsname.h
83279+++ b/include/linux/utsname.h
83280@@ -24,7 +24,7 @@ struct uts_namespace {
83281 struct new_utsname name;
83282 struct user_namespace *user_ns;
83283 unsigned int proc_inum;
83284-};
83285+} __randomize_layout;
83286 extern struct uts_namespace init_uts_ns;
83287
83288 #ifdef CONFIG_UTS_NS
83289diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83290index 6f8fbcf..4efc177 100644
83291--- a/include/linux/vermagic.h
83292+++ b/include/linux/vermagic.h
83293@@ -25,9 +25,42 @@
83294 #define MODULE_ARCH_VERMAGIC ""
83295 #endif
83296
83297+#ifdef CONFIG_PAX_REFCOUNT
83298+#define MODULE_PAX_REFCOUNT "REFCOUNT "
83299+#else
83300+#define MODULE_PAX_REFCOUNT ""
83301+#endif
83302+
83303+#ifdef CONSTIFY_PLUGIN
83304+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83305+#else
83306+#define MODULE_CONSTIFY_PLUGIN ""
83307+#endif
83308+
83309+#ifdef STACKLEAK_PLUGIN
83310+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83311+#else
83312+#define MODULE_STACKLEAK_PLUGIN ""
83313+#endif
83314+
83315+#ifdef RANDSTRUCT_PLUGIN
83316+#include <generated/randomize_layout_hash.h>
83317+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83318+#else
83319+#define MODULE_RANDSTRUCT_PLUGIN
83320+#endif
83321+
83322+#ifdef CONFIG_GRKERNSEC
83323+#define MODULE_GRSEC "GRSEC "
83324+#else
83325+#define MODULE_GRSEC ""
83326+#endif
83327+
83328 #define VERMAGIC_STRING \
83329 UTS_RELEASE " " \
83330 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83331 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83332- MODULE_ARCH_VERMAGIC
83333+ MODULE_ARCH_VERMAGIC \
83334+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83335+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83336
83337diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83338index 502073a..a7de024 100644
83339--- a/include/linux/vga_switcheroo.h
83340+++ b/include/linux/vga_switcheroo.h
83341@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83342
83343 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83344
83345-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83346-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83347+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83348+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83349 #else
83350
83351 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83352@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83353
83354 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83355
83356-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83357-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83358+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83359+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83360
83361 #endif
83362 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83363diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83364index 4b8a891..05f2361 100644
83365--- a/include/linux/vmalloc.h
83366+++ b/include/linux/vmalloc.h
83367@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83368 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83369 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83370 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83371+
83372+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83373+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83374+#endif
83375+
83376 /* bits [20..32] reserved for arch specific ioremap internals */
83377
83378 /*
83379@@ -72,6 +77,7 @@ extern void *vzalloc_node(unsigned long size, int node);
83380 extern void *vmalloc_exec(unsigned long size);
83381 extern void *vmalloc_32(unsigned long size);
83382 extern void *vmalloc_32_user(unsigned long size);
83383+extern void *vmalloc_stack(int node);
83384 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
83385 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
83386 unsigned long start, unsigned long end, gfp_t gfp_mask,
83387@@ -142,7 +148,7 @@ extern void free_vm_area(struct vm_struct *area);
83388
83389 /* for /dev/kmem */
83390 extern long vread(char *buf, char *addr, unsigned long count);
83391-extern long vwrite(char *buf, char *addr, unsigned long count);
83392+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83393
83394 /*
83395 * Internals. Dont't use..
83396diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83397index 67ce70c..d540954 100644
83398--- a/include/linux/vmstat.h
83399+++ b/include/linux/vmstat.h
83400@@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
83401 /*
83402 * Zone based page accounting with per cpu differentials.
83403 */
83404-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83405+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83406
83407 static inline void zone_page_state_add(long x, struct zone *zone,
83408 enum zone_stat_item item)
83409 {
83410- atomic_long_add(x, &zone->vm_stat[item]);
83411- atomic_long_add(x, &vm_stat[item]);
83412+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83413+ atomic_long_add_unchecked(x, &vm_stat[item]);
83414 }
83415
83416-static inline unsigned long global_page_state(enum zone_stat_item item)
83417+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83418 {
83419- long x = atomic_long_read(&vm_stat[item]);
83420+ long x = atomic_long_read_unchecked(&vm_stat[item]);
83421 #ifdef CONFIG_SMP
83422 if (x < 0)
83423 x = 0;
83424@@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83425 return x;
83426 }
83427
83428-static inline unsigned long zone_page_state(struct zone *zone,
83429+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83430 enum zone_stat_item item)
83431 {
83432- long x = atomic_long_read(&zone->vm_stat[item]);
83433+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83434 #ifdef CONFIG_SMP
83435 if (x < 0)
83436 x = 0;
83437@@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83438 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83439 enum zone_stat_item item)
83440 {
83441- long x = atomic_long_read(&zone->vm_stat[item]);
83442+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83443
83444 #ifdef CONFIG_SMP
83445 int cpu;
83446@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
83447
83448 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83449 {
83450- atomic_long_inc(&zone->vm_stat[item]);
83451- atomic_long_inc(&vm_stat[item]);
83452+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
83453+ atomic_long_inc_unchecked(&vm_stat[item]);
83454 }
83455
83456 static inline void __inc_zone_page_state(struct page *page,
83457@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
83458
83459 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83460 {
83461- atomic_long_dec(&zone->vm_stat[item]);
83462- atomic_long_dec(&vm_stat[item]);
83463+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
83464+ atomic_long_dec_unchecked(&vm_stat[item]);
83465 }
83466
83467 static inline void __dec_zone_page_state(struct page *page,
83468diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83469index 91b0a68..0e9adf6 100644
83470--- a/include/linux/xattr.h
83471+++ b/include/linux/xattr.h
83472@@ -28,7 +28,7 @@ struct xattr_handler {
83473 size_t size, int handler_flags);
83474 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83475 size_t size, int flags, int handler_flags);
83476-};
83477+} __do_const;
83478
83479 struct xattr {
83480 const char *name;
83481@@ -37,6 +37,9 @@ struct xattr {
83482 };
83483
83484 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83485+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83486+ssize_t pax_getxattr(struct dentry *, void *, size_t);
83487+#endif
83488 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83489 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83490 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83491diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83492index 9c5a6b4..09c9438 100644
83493--- a/include/linux/zlib.h
83494+++ b/include/linux/zlib.h
83495@@ -31,6 +31,7 @@
83496 #define _ZLIB_H
83497
83498 #include <linux/zconf.h>
83499+#include <linux/compiler.h>
83500
83501 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83502 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83503@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83504
83505 /* basic functions */
83506
83507-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83508+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83509 /*
83510 Returns the number of bytes that needs to be allocated for a per-
83511 stream workspace with the specified parameters. A pointer to this
83512diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83513index c768c9f..bdcaa5a 100644
83514--- a/include/media/v4l2-dev.h
83515+++ b/include/media/v4l2-dev.h
83516@@ -76,7 +76,7 @@ struct v4l2_file_operations {
83517 int (*mmap) (struct file *, struct vm_area_struct *);
83518 int (*open) (struct file *);
83519 int (*release) (struct file *);
83520-};
83521+} __do_const;
83522
83523 /*
83524 * Newer version of video_device, handled by videodev2.c
83525diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83526index c9b1593..a572459 100644
83527--- a/include/media/v4l2-device.h
83528+++ b/include/media/v4l2-device.h
83529@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83530 this function returns 0. If the name ends with a digit (e.g. cx18),
83531 then the name will be set to cx18-0 since cx180 looks really odd. */
83532 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83533- atomic_t *instance);
83534+ atomic_unchecked_t *instance);
83535
83536 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83537 Since the parent disappears this ensures that v4l2_dev doesn't have an
83538diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83539index 9a36d92..0aafe2a 100644
83540--- a/include/net/9p/transport.h
83541+++ b/include/net/9p/transport.h
83542@@ -60,7 +60,7 @@ struct p9_trans_module {
83543 int (*cancel) (struct p9_client *, struct p9_req_t *req);
83544 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83545 char *, char *, int , int, int, int);
83546-};
83547+} __do_const;
83548
83549 void v9fs_register_trans(struct p9_trans_module *m);
83550 void v9fs_unregister_trans(struct p9_trans_module *m);
83551diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83552index a175ba4..196eb82 100644
83553--- a/include/net/af_unix.h
83554+++ b/include/net/af_unix.h
83555@@ -36,7 +36,7 @@ struct unix_skb_parms {
83556 u32 secid; /* Security ID */
83557 #endif
83558 u32 consumed;
83559-};
83560+} __randomize_layout;
83561
83562 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83563 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83564diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83565index dbc4a89..4a59b5d 100644
83566--- a/include/net/bluetooth/l2cap.h
83567+++ b/include/net/bluetooth/l2cap.h
83568@@ -600,7 +600,7 @@ struct l2cap_ops {
83569 long (*get_sndtimeo) (struct l2cap_chan *chan);
83570 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83571 unsigned long len, int nb);
83572-};
83573+} __do_const;
83574
83575 struct l2cap_conn {
83576 struct hci_conn *hcon;
83577diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83578index f2ae33d..c457cf0 100644
83579--- a/include/net/caif/cfctrl.h
83580+++ b/include/net/caif/cfctrl.h
83581@@ -52,7 +52,7 @@ struct cfctrl_rsp {
83582 void (*radioset_rsp)(void);
83583 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83584 struct cflayer *client_layer);
83585-};
83586+} __no_const;
83587
83588 /* Link Setup Parameters for CAIF-Links. */
83589 struct cfctrl_link_param {
83590@@ -101,8 +101,8 @@ struct cfctrl_request_info {
83591 struct cfctrl {
83592 struct cfsrvl serv;
83593 struct cfctrl_rsp res;
83594- atomic_t req_seq_no;
83595- atomic_t rsp_seq_no;
83596+ atomic_unchecked_t req_seq_no;
83597+ atomic_unchecked_t rsp_seq_no;
83598 struct list_head list;
83599 /* Protects from simultaneous access to first_req list */
83600 spinlock_t info_list_lock;
83601diff --git a/include/net/flow.h b/include/net/flow.h
83602index d23e7fa..e188307 100644
83603--- a/include/net/flow.h
83604+++ b/include/net/flow.h
83605@@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
83606
83607 void flow_cache_flush(void);
83608 void flow_cache_flush_deferred(void);
83609-extern atomic_t flow_cache_genid;
83610+extern atomic_unchecked_t flow_cache_genid;
83611
83612 #endif
83613diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83614index 93695f0..766d71c 100644
83615--- a/include/net/genetlink.h
83616+++ b/include/net/genetlink.h
83617@@ -120,7 +120,7 @@ struct genl_ops {
83618 u8 cmd;
83619 u8 internal_flags;
83620 u8 flags;
83621-};
83622+} __do_const;
83623
83624 int __genl_register_family(struct genl_family *family);
83625
83626diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83627index 734d9b5..48a9a4b 100644
83628--- a/include/net/gro_cells.h
83629+++ b/include/net/gro_cells.h
83630@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83631 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83632
83633 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83634- atomic_long_inc(&dev->rx_dropped);
83635+ atomic_long_inc_unchecked(&dev->rx_dropped);
83636 kfree_skb(skb);
83637 return;
83638 }
83639diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83640index c55aeed..b3393f4 100644
83641--- a/include/net/inet_connection_sock.h
83642+++ b/include/net/inet_connection_sock.h
83643@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83644 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83645 int (*bind_conflict)(const struct sock *sk,
83646 const struct inet_bind_bucket *tb, bool relax);
83647-};
83648+} __do_const;
83649
83650 /** inet_connection_sock - INET connection oriented sock
83651 *
83652diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83653index 6efe73c..fa94270 100644
83654--- a/include/net/inetpeer.h
83655+++ b/include/net/inetpeer.h
83656@@ -47,8 +47,8 @@ struct inet_peer {
83657 */
83658 union {
83659 struct {
83660- atomic_t rid; /* Frag reception counter */
83661- atomic_t ip_id_count; /* IP ID for the next packet */
83662+ atomic_unchecked_t rid; /* Frag reception counter */
83663+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83664 };
83665 struct rcu_head rcu;
83666 struct inet_peer *gc_next;
83667@@ -177,16 +177,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
83668 /* can be called with or without local BH being disabled */
83669 static inline int inet_getid(struct inet_peer *p, int more)
83670 {
83671- int old, new;
83672+ int id;
83673 more++;
83674 inet_peer_refcheck(p);
83675- do {
83676- old = atomic_read(&p->ip_id_count);
83677- new = old + more;
83678- if (!new)
83679- new = 1;
83680- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
83681- return new;
83682+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
83683+ if (!id)
83684+ id = atomic_inc_return_unchecked(&p->ip_id_count);
83685+ return id;
83686 }
83687
83688 #endif /* _NET_INETPEER_H */
83689diff --git a/include/net/ip.h b/include/net/ip.h
83690index 23be0fd..0cb3e2c 100644
83691--- a/include/net/ip.h
83692+++ b/include/net/ip.h
83693@@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83694
83695 void inet_get_local_port_range(struct net *net, int *low, int *high);
83696
83697-extern unsigned long *sysctl_local_reserved_ports;
83698+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83699 static inline int inet_is_reserved_local_port(int port)
83700 {
83701 return test_bit(port, sysctl_local_reserved_ports);
83702diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83703index 9922093..a1755d6 100644
83704--- a/include/net/ip_fib.h
83705+++ b/include/net/ip_fib.h
83706@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83707
83708 #define FIB_RES_SADDR(net, res) \
83709 ((FIB_RES_NH(res).nh_saddr_genid == \
83710- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83711+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83712 FIB_RES_NH(res).nh_saddr : \
83713 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83714 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83715diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83716index 5679d92..2e7a690 100644
83717--- a/include/net/ip_vs.h
83718+++ b/include/net/ip_vs.h
83719@@ -558,7 +558,7 @@ struct ip_vs_conn {
83720 struct ip_vs_conn *control; /* Master control connection */
83721 atomic_t n_control; /* Number of controlled ones */
83722 struct ip_vs_dest *dest; /* real server */
83723- atomic_t in_pkts; /* incoming packet counter */
83724+ atomic_unchecked_t in_pkts; /* incoming packet counter */
83725
83726 /* packet transmitter for different forwarding methods. If it
83727 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83728@@ -705,7 +705,7 @@ struct ip_vs_dest {
83729 __be16 port; /* port number of the server */
83730 union nf_inet_addr addr; /* IP address of the server */
83731 volatile unsigned int flags; /* dest status flags */
83732- atomic_t conn_flags; /* flags to copy to conn */
83733+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
83734 atomic_t weight; /* server weight */
83735
83736 atomic_t refcnt; /* reference counter */
83737@@ -960,11 +960,11 @@ struct netns_ipvs {
83738 /* ip_vs_lblc */
83739 int sysctl_lblc_expiration;
83740 struct ctl_table_header *lblc_ctl_header;
83741- struct ctl_table *lblc_ctl_table;
83742+ ctl_table_no_const *lblc_ctl_table;
83743 /* ip_vs_lblcr */
83744 int sysctl_lblcr_expiration;
83745 struct ctl_table_header *lblcr_ctl_header;
83746- struct ctl_table *lblcr_ctl_table;
83747+ ctl_table_no_const *lblcr_ctl_table;
83748 /* ip_vs_est */
83749 struct list_head est_list; /* estimator list */
83750 spinlock_t est_lock;
83751diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83752index 8d4f588..2e37ad2 100644
83753--- a/include/net/irda/ircomm_tty.h
83754+++ b/include/net/irda/ircomm_tty.h
83755@@ -33,6 +33,7 @@
83756 #include <linux/termios.h>
83757 #include <linux/timer.h>
83758 #include <linux/tty.h> /* struct tty_struct */
83759+#include <asm/local.h>
83760
83761 #include <net/irda/irias_object.h>
83762 #include <net/irda/ircomm_core.h>
83763diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83764index 714cc9a..ea05f3e 100644
83765--- a/include/net/iucv/af_iucv.h
83766+++ b/include/net/iucv/af_iucv.h
83767@@ -149,7 +149,7 @@ struct iucv_skb_cb {
83768 struct iucv_sock_list {
83769 struct hlist_head head;
83770 rwlock_t lock;
83771- atomic_t autobind_name;
83772+ atomic_unchecked_t autobind_name;
83773 };
83774
83775 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83776diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83777index f3be818..bf46196 100644
83778--- a/include/net/llc_c_ac.h
83779+++ b/include/net/llc_c_ac.h
83780@@ -87,7 +87,7 @@
83781 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83782 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83783
83784-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83785+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83786
83787 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83788 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83789diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83790index 3948cf1..83b28c4 100644
83791--- a/include/net/llc_c_ev.h
83792+++ b/include/net/llc_c_ev.h
83793@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83794 return (struct llc_conn_state_ev *)skb->cb;
83795 }
83796
83797-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83798-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83799+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83800+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83801
83802 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83803 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83804diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83805index 0e79cfb..f46db31 100644
83806--- a/include/net/llc_c_st.h
83807+++ b/include/net/llc_c_st.h
83808@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83809 u8 next_state;
83810 llc_conn_ev_qfyr_t *ev_qualifiers;
83811 llc_conn_action_t *ev_actions;
83812-};
83813+} __do_const;
83814
83815 struct llc_conn_state {
83816 u8 current_state;
83817diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83818index a61b98c..aade1eb 100644
83819--- a/include/net/llc_s_ac.h
83820+++ b/include/net/llc_s_ac.h
83821@@ -23,7 +23,7 @@
83822 #define SAP_ACT_TEST_IND 9
83823
83824 /* All action functions must look like this */
83825-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83826+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83827
83828 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83829 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83830diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83831index 567c681..cd73ac0 100644
83832--- a/include/net/llc_s_st.h
83833+++ b/include/net/llc_s_st.h
83834@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83835 llc_sap_ev_t ev;
83836 u8 next_state;
83837 llc_sap_action_t *ev_actions;
83838-};
83839+} __do_const;
83840
83841 struct llc_sap_state {
83842 u8 curr_state;
83843diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83844index f4ab2fb..71a85ba 100644
83845--- a/include/net/mac80211.h
83846+++ b/include/net/mac80211.h
83847@@ -4476,7 +4476,7 @@ struct rate_control_ops {
83848 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83849 struct dentry *dir);
83850 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83851-};
83852+} __do_const;
83853
83854 static inline int rate_supported(struct ieee80211_sta *sta,
83855 enum ieee80211_band band,
83856diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83857index 7277caf..fd095bc 100644
83858--- a/include/net/neighbour.h
83859+++ b/include/net/neighbour.h
83860@@ -163,7 +163,7 @@ struct neigh_ops {
83861 void (*error_report)(struct neighbour *, struct sk_buff *);
83862 int (*output)(struct neighbour *, struct sk_buff *);
83863 int (*connected_output)(struct neighbour *, struct sk_buff *);
83864-};
83865+} __do_const;
83866
83867 struct pneigh_entry {
83868 struct pneigh_entry *next;
83869@@ -203,7 +203,6 @@ struct neigh_table {
83870 void (*proxy_redo)(struct sk_buff *skb);
83871 char *id;
83872 struct neigh_parms parms;
83873- /* HACK. gc_* should follow parms without a gap! */
83874 int gc_interval;
83875 int gc_thresh1;
83876 int gc_thresh2;
83877@@ -218,7 +217,7 @@ struct neigh_table {
83878 struct neigh_statistics __percpu *stats;
83879 struct neigh_hash_table __rcu *nht;
83880 struct pneigh_entry **phash_buckets;
83881-};
83882+} __randomize_layout;
83883
83884 static inline int neigh_parms_family(struct neigh_parms *p)
83885 {
83886diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83887index 991dcd9..ab58d00 100644
83888--- a/include/net/net_namespace.h
83889+++ b/include/net/net_namespace.h
83890@@ -124,8 +124,8 @@ struct net {
83891 struct netns_ipvs *ipvs;
83892 #endif
83893 struct sock *diag_nlsk;
83894- atomic_t fnhe_genid;
83895-};
83896+ atomic_unchecked_t fnhe_genid;
83897+} __randomize_layout;
83898
83899 /*
83900 * ifindex generation is per-net namespace, and loopback is
83901@@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83902 #define __net_init __init
83903 #define __net_exit __exit_refok
83904 #define __net_initdata __initdata
83905+#ifdef CONSTIFY_PLUGIN
83906 #define __net_initconst __initconst
83907+#else
83908+#define __net_initconst __initdata
83909+#endif
83910 #endif
83911
83912 struct pernet_operations {
83913@@ -299,7 +303,7 @@ struct pernet_operations {
83914 void (*exit_batch)(struct list_head *net_exit_list);
83915 int *id;
83916 size_t size;
83917-};
83918+} __do_const;
83919
83920 /*
83921 * Use these carefully. If you implement a network device and it
83922@@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83923
83924 static inline int rt_genid_ipv4(struct net *net)
83925 {
83926- return atomic_read(&net->ipv4.rt_genid);
83927+ return atomic_read_unchecked(&net->ipv4.rt_genid);
83928 }
83929
83930 static inline void rt_genid_bump_ipv4(struct net *net)
83931 {
83932- atomic_inc(&net->ipv4.rt_genid);
83933+ atomic_inc_unchecked(&net->ipv4.rt_genid);
83934 }
83935
83936 #if IS_ENABLED(CONFIG_IPV6)
83937 static inline int rt_genid_ipv6(struct net *net)
83938 {
83939- return atomic_read(&net->ipv6.rt_genid);
83940+ return atomic_read_unchecked(&net->ipv6.rt_genid);
83941 }
83942
83943 static inline void rt_genid_bump_ipv6(struct net *net)
83944 {
83945- atomic_inc(&net->ipv6.rt_genid);
83946+ atomic_inc_unchecked(&net->ipv6.rt_genid);
83947 }
83948 #else
83949 static inline int rt_genid_ipv6(struct net *net)
83950@@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
83951
83952 static inline int fnhe_genid(struct net *net)
83953 {
83954- return atomic_read(&net->fnhe_genid);
83955+ return atomic_read_unchecked(&net->fnhe_genid);
83956 }
83957
83958 static inline void fnhe_genid_bump(struct net *net)
83959 {
83960- atomic_inc(&net->fnhe_genid);
83961+ atomic_inc_unchecked(&net->fnhe_genid);
83962 }
83963
83964 #endif /* __NET_NET_NAMESPACE_H */
83965diff --git a/include/net/netdma.h b/include/net/netdma.h
83966index 8ba8ce2..99b7fff 100644
83967--- a/include/net/netdma.h
83968+++ b/include/net/netdma.h
83969@@ -24,7 +24,7 @@
83970 #include <linux/dmaengine.h>
83971 #include <linux/skbuff.h>
83972
83973-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83974+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83975 struct sk_buff *skb, int offset, struct iovec *to,
83976 size_t len, struct dma_pinned_list *pinned_list);
83977
83978diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
83979index 956b175..55d1504 100644
83980--- a/include/net/netfilter/nf_conntrack_extend.h
83981+++ b/include/net/netfilter/nf_conntrack_extend.h
83982@@ -47,8 +47,8 @@ enum nf_ct_ext_id {
83983 /* Extensions: optional stuff which isn't permanently in struct. */
83984 struct nf_ct_ext {
83985 struct rcu_head rcu;
83986- u8 offset[NF_CT_EXT_NUM];
83987- u8 len;
83988+ u16 offset[NF_CT_EXT_NUM];
83989+ u16 len;
83990 char data[0];
83991 };
83992
83993diff --git a/include/net/netlink.h b/include/net/netlink.h
83994index 2b47eaa..6d5bcc2 100644
83995--- a/include/net/netlink.h
83996+++ b/include/net/netlink.h
83997@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83998 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83999 {
84000 if (mark)
84001- skb_trim(skb, (unsigned char *) mark - skb->data);
84002+ skb_trim(skb, (const unsigned char *) mark - skb->data);
84003 }
84004
84005 /**
84006diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
84007index fbcc7fa..03c7e51 100644
84008--- a/include/net/netns/conntrack.h
84009+++ b/include/net/netns/conntrack.h
84010@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
84011 struct nf_proto_net {
84012 #ifdef CONFIG_SYSCTL
84013 struct ctl_table_header *ctl_table_header;
84014- struct ctl_table *ctl_table;
84015+ ctl_table_no_const *ctl_table;
84016 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
84017 struct ctl_table_header *ctl_compat_header;
84018- struct ctl_table *ctl_compat_table;
84019+ ctl_table_no_const *ctl_compat_table;
84020 #endif
84021 #endif
84022 unsigned int users;
84023@@ -58,7 +58,7 @@ struct nf_ip_net {
84024 struct nf_icmp_net icmpv6;
84025 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
84026 struct ctl_table_header *ctl_table_header;
84027- struct ctl_table *ctl_table;
84028+ ctl_table_no_const *ctl_table;
84029 #endif
84030 };
84031
84032diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
84033index 80f500a..f0c23c2 100644
84034--- a/include/net/netns/ipv4.h
84035+++ b/include/net/netns/ipv4.h
84036@@ -74,7 +74,7 @@ struct netns_ipv4 {
84037
84038 kgid_t sysctl_ping_group_range[2];
84039
84040- atomic_t dev_addr_genid;
84041+ atomic_unchecked_t dev_addr_genid;
84042
84043 #ifdef CONFIG_IP_MROUTE
84044 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
84045@@ -84,6 +84,6 @@ struct netns_ipv4 {
84046 struct fib_rules_ops *mr_rules_ops;
84047 #endif
84048 #endif
84049- atomic_t rt_genid;
84050+ atomic_unchecked_t rt_genid;
84051 };
84052 #endif
84053diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
84054index 21edaf1..4c5faae 100644
84055--- a/include/net/netns/ipv6.h
84056+++ b/include/net/netns/ipv6.h
84057@@ -73,8 +73,8 @@ struct netns_ipv6 {
84058 struct fib_rules_ops *mr6_rules_ops;
84059 #endif
84060 #endif
84061- atomic_t dev_addr_genid;
84062- atomic_t rt_genid;
84063+ atomic_unchecked_t dev_addr_genid;
84064+ atomic_unchecked_t rt_genid;
84065 };
84066
84067 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
84068diff --git a/include/net/ping.h b/include/net/ping.h
84069index 026479b..d9b2829 100644
84070--- a/include/net/ping.h
84071+++ b/include/net/ping.h
84072@@ -54,7 +54,7 @@ struct ping_iter_state {
84073
84074 extern struct proto ping_prot;
84075 #if IS_ENABLED(CONFIG_IPV6)
84076-extern struct pingv6_ops pingv6_ops;
84077+extern struct pingv6_ops *pingv6_ops;
84078 #endif
84079
84080 struct pingfakehdr {
84081diff --git a/include/net/protocol.h b/include/net/protocol.h
84082index a7e986b..dc67bce 100644
84083--- a/include/net/protocol.h
84084+++ b/include/net/protocol.h
84085@@ -49,7 +49,7 @@ struct net_protocol {
84086 * socket lookup?
84087 */
84088 icmp_strict_tag_validation:1;
84089-};
84090+} __do_const;
84091
84092 #if IS_ENABLED(CONFIG_IPV6)
84093 struct inet6_protocol {
84094@@ -62,7 +62,7 @@ struct inet6_protocol {
84095 u8 type, u8 code, int offset,
84096 __be32 info);
84097 unsigned int flags; /* INET6_PROTO_xxx */
84098-};
84099+} __do_const;
84100
84101 #define INET6_PROTO_NOPOLICY 0x1
84102 #define INET6_PROTO_FINAL 0x2
84103diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
84104index 661e45d..54c39df 100644
84105--- a/include/net/rtnetlink.h
84106+++ b/include/net/rtnetlink.h
84107@@ -93,7 +93,7 @@ struct rtnl_link_ops {
84108 int (*fill_slave_info)(struct sk_buff *skb,
84109 const struct net_device *dev,
84110 const struct net_device *slave_dev);
84111-};
84112+} __do_const;
84113
84114 int __rtnl_link_register(struct rtnl_link_ops *ops);
84115 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
84116diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
84117index 4a5b9a3..ca27d73 100644
84118--- a/include/net/sctp/checksum.h
84119+++ b/include/net/sctp/checksum.h
84120@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
84121 unsigned int offset)
84122 {
84123 struct sctphdr *sh = sctp_hdr(skb);
84124- __le32 ret, old = sh->checksum;
84125- const struct skb_checksum_ops ops = {
84126+ __le32 ret, old = sh->checksum;
84127+ static const struct skb_checksum_ops ops = {
84128 .update = sctp_csum_update,
84129 .combine = sctp_csum_combine,
84130 };
84131diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
84132index 7f4eeb3..37e8fe1 100644
84133--- a/include/net/sctp/sm.h
84134+++ b/include/net/sctp/sm.h
84135@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
84136 typedef struct {
84137 sctp_state_fn_t *fn;
84138 const char *name;
84139-} sctp_sm_table_entry_t;
84140+} __do_const sctp_sm_table_entry_t;
84141
84142 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
84143 * currently in use.
84144@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
84145 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
84146
84147 /* Extern declarations for major data structures. */
84148-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84149+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84150
84151
84152 /* Get the size of a DATA chunk payload. */
84153diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
84154index 6ee76c8..45f2609 100644
84155--- a/include/net/sctp/structs.h
84156+++ b/include/net/sctp/structs.h
84157@@ -507,7 +507,7 @@ struct sctp_pf {
84158 struct sctp_association *asoc);
84159 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
84160 struct sctp_af *af;
84161-};
84162+} __do_const;
84163
84164
84165 /* Structure to track chunk fragments that have been acked, but peer
84166diff --git a/include/net/sock.h b/include/net/sock.h
84167index b9586a1..b2948c0 100644
84168--- a/include/net/sock.h
84169+++ b/include/net/sock.h
84170@@ -348,7 +348,7 @@ struct sock {
84171 unsigned int sk_napi_id;
84172 unsigned int sk_ll_usec;
84173 #endif
84174- atomic_t sk_drops;
84175+ atomic_unchecked_t sk_drops;
84176 int sk_rcvbuf;
84177
84178 struct sk_filter __rcu *sk_filter;
84179@@ -1036,7 +1036,7 @@ struct proto {
84180 void (*destroy_cgroup)(struct mem_cgroup *memcg);
84181 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
84182 #endif
84183-};
84184+} __randomize_layout;
84185
84186 /*
84187 * Bits in struct cg_proto.flags
84188@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
84189 return ret >> PAGE_SHIFT;
84190 }
84191
84192-static inline long
84193+static inline long __intentional_overflow(-1)
84194 sk_memory_allocated(const struct sock *sk)
84195 {
84196 struct proto *prot = sk->sk_prot;
84197@@ -1368,7 +1368,7 @@ struct sock_iocb {
84198 struct scm_cookie *scm;
84199 struct msghdr *msg, async_msg;
84200 struct kiocb *kiocb;
84201-};
84202+} __randomize_layout;
84203
84204 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
84205 {
84206@@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
84207 }
84208
84209 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
84210- char __user *from, char *to,
84211+ char __user *from, unsigned char *to,
84212 int copy, int offset)
84213 {
84214 if (skb->ip_summed == CHECKSUM_NONE) {
84215@@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
84216 }
84217 }
84218
84219-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84220+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84221
84222 /**
84223 * sk_page_frag - return an appropriate page_frag
84224diff --git a/include/net/tcp.h b/include/net/tcp.h
84225index 743acce..44a58b0 100644
84226--- a/include/net/tcp.h
84227+++ b/include/net/tcp.h
84228@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
84229 void tcp_xmit_retransmit_queue(struct sock *);
84230 void tcp_simple_retransmit(struct sock *);
84231 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
84232-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84233+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84234
84235 void tcp_send_probe0(struct sock *);
84236 void tcp_send_partial(struct sock *);
84237@@ -710,8 +710,8 @@ struct tcp_skb_cb {
84238 struct inet6_skb_parm h6;
84239 #endif
84240 } header; /* For incoming frames */
84241- __u32 seq; /* Starting sequence number */
84242- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
84243+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
84244+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
84245 __u32 when; /* used to compute rtt's */
84246 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
84247
84248@@ -725,7 +725,7 @@ struct tcp_skb_cb {
84249
84250 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
84251 /* 1 byte hole */
84252- __u32 ack_seq; /* Sequence number ACK'd */
84253+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
84254 };
84255
84256 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
84257diff --git a/include/net/xfrm.h b/include/net/xfrm.h
84258index fb5654a..4457522 100644
84259--- a/include/net/xfrm.h
84260+++ b/include/net/xfrm.h
84261@@ -286,7 +286,6 @@ struct xfrm_dst;
84262 struct xfrm_policy_afinfo {
84263 unsigned short family;
84264 struct dst_ops *dst_ops;
84265- void (*garbage_collect)(struct net *net);
84266 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84267 const xfrm_address_t *saddr,
84268 const xfrm_address_t *daddr);
84269@@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
84270 struct net_device *dev,
84271 const struct flowi *fl);
84272 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84273-};
84274+} __do_const;
84275
84276 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84277 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84278@@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
84279 int (*transport_finish)(struct sk_buff *skb,
84280 int async);
84281 void (*local_error)(struct sk_buff *skb, u32 mtu);
84282-};
84283+} __do_const;
84284
84285 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84286 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84287@@ -428,7 +427,7 @@ struct xfrm_mode {
84288 struct module *owner;
84289 unsigned int encap;
84290 int flags;
84291-};
84292+} __do_const;
84293
84294 /* Flags for xfrm_mode. */
84295 enum {
84296@@ -525,7 +524,7 @@ struct xfrm_policy {
84297 struct timer_list timer;
84298
84299 struct flow_cache_object flo;
84300- atomic_t genid;
84301+ atomic_unchecked_t genid;
84302 u32 priority;
84303 u32 index;
84304 struct xfrm_mark mark;
84305@@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84306 }
84307
84308 void xfrm_garbage_collect(struct net *net);
84309+void xfrm_garbage_collect_deferred(struct net *net);
84310
84311 #else
84312
84313@@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84314 static inline void xfrm_garbage_collect(struct net *net)
84315 {
84316 }
84317+static inline void xfrm_garbage_collect_deferred(struct net *net)
84318+{
84319+}
84320 #endif
84321
84322 static __inline__
84323diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84324index 1017e0b..227aa4d 100644
84325--- a/include/rdma/iw_cm.h
84326+++ b/include/rdma/iw_cm.h
84327@@ -122,7 +122,7 @@ struct iw_cm_verbs {
84328 int backlog);
84329
84330 int (*destroy_listen)(struct iw_cm_id *cm_id);
84331-};
84332+} __no_const;
84333
84334 /**
84335 * iw_create_cm_id - Create an IW CM identifier.
84336diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84337index 52beadf..598734c 100644
84338--- a/include/scsi/libfc.h
84339+++ b/include/scsi/libfc.h
84340@@ -771,6 +771,7 @@ struct libfc_function_template {
84341 */
84342 void (*disc_stop_final) (struct fc_lport *);
84343 };
84344+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84345
84346 /**
84347 * struct fc_disc - Discovery context
84348@@ -875,7 +876,7 @@ struct fc_lport {
84349 struct fc_vport *vport;
84350
84351 /* Operational Information */
84352- struct libfc_function_template tt;
84353+ libfc_function_template_no_const tt;
84354 u8 link_up;
84355 u8 qfull;
84356 enum fc_lport_state state;
84357diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84358index d65fbec..f80fef2 100644
84359--- a/include/scsi/scsi_device.h
84360+++ b/include/scsi/scsi_device.h
84361@@ -180,9 +180,9 @@ struct scsi_device {
84362 unsigned int max_device_blocked; /* what device_blocked counts down from */
84363 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84364
84365- atomic_t iorequest_cnt;
84366- atomic_t iodone_cnt;
84367- atomic_t ioerr_cnt;
84368+ atomic_unchecked_t iorequest_cnt;
84369+ atomic_unchecked_t iodone_cnt;
84370+ atomic_unchecked_t ioerr_cnt;
84371
84372 struct device sdev_gendev,
84373 sdev_dev;
84374diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84375index b797e8f..8e2c3aa 100644
84376--- a/include/scsi/scsi_transport_fc.h
84377+++ b/include/scsi/scsi_transport_fc.h
84378@@ -751,7 +751,8 @@ struct fc_function_template {
84379 unsigned long show_host_system_hostname:1;
84380
84381 unsigned long disable_target_scan:1;
84382-};
84383+} __do_const;
84384+typedef struct fc_function_template __no_const fc_function_template_no_const;
84385
84386
84387 /**
84388diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84389index ae6c3b8..fd748ac 100644
84390--- a/include/sound/compress_driver.h
84391+++ b/include/sound/compress_driver.h
84392@@ -128,7 +128,7 @@ struct snd_compr_ops {
84393 struct snd_compr_caps *caps);
84394 int (*get_codec_caps) (struct snd_compr_stream *stream,
84395 struct snd_compr_codec_caps *codec);
84396-};
84397+} __no_const;
84398
84399 /**
84400 * struct snd_compr: Compressed device
84401diff --git a/include/sound/soc.h b/include/sound/soc.h
84402index 9a00147..d814573 100644
84403--- a/include/sound/soc.h
84404+++ b/include/sound/soc.h
84405@@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
84406 /* probe ordering - for components with runtime dependencies */
84407 int probe_order;
84408 int remove_order;
84409-};
84410+} __do_const;
84411
84412 /* SoC platform interface */
84413 struct snd_soc_platform_driver {
84414@@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
84415 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84416 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84417 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84418-};
84419+} __do_const;
84420
84421 struct snd_soc_platform {
84422 const char *name;
84423diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84424index 1772fad..282e3e2 100644
84425--- a/include/target/target_core_base.h
84426+++ b/include/target/target_core_base.h
84427@@ -754,7 +754,7 @@ struct se_device {
84428 atomic_long_t write_bytes;
84429 /* Active commands on this virtual SE device */
84430 atomic_t simple_cmds;
84431- atomic_t dev_ordered_id;
84432+ atomic_unchecked_t dev_ordered_id;
84433 atomic_t dev_ordered_sync;
84434 atomic_t dev_qf_count;
84435 int export_count;
84436diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84437new file mode 100644
84438index 0000000..fb634b7
84439--- /dev/null
84440+++ b/include/trace/events/fs.h
84441@@ -0,0 +1,53 @@
84442+#undef TRACE_SYSTEM
84443+#define TRACE_SYSTEM fs
84444+
84445+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84446+#define _TRACE_FS_H
84447+
84448+#include <linux/fs.h>
84449+#include <linux/tracepoint.h>
84450+
84451+TRACE_EVENT(do_sys_open,
84452+
84453+ TP_PROTO(const char *filename, int flags, int mode),
84454+
84455+ TP_ARGS(filename, flags, mode),
84456+
84457+ TP_STRUCT__entry(
84458+ __string( filename, filename )
84459+ __field( int, flags )
84460+ __field( int, mode )
84461+ ),
84462+
84463+ TP_fast_assign(
84464+ __assign_str(filename, filename);
84465+ __entry->flags = flags;
84466+ __entry->mode = mode;
84467+ ),
84468+
84469+ TP_printk("\"%s\" %x %o",
84470+ __get_str(filename), __entry->flags, __entry->mode)
84471+);
84472+
84473+TRACE_EVENT(open_exec,
84474+
84475+ TP_PROTO(const char *filename),
84476+
84477+ TP_ARGS(filename),
84478+
84479+ TP_STRUCT__entry(
84480+ __string( filename, filename )
84481+ ),
84482+
84483+ TP_fast_assign(
84484+ __assign_str(filename, filename);
84485+ ),
84486+
84487+ TP_printk("\"%s\"",
84488+ __get_str(filename))
84489+);
84490+
84491+#endif /* _TRACE_FS_H */
84492+
84493+/* This part must be outside protection */
84494+#include <trace/define_trace.h>
84495diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84496index 1c09820..7f5ec79 100644
84497--- a/include/trace/events/irq.h
84498+++ b/include/trace/events/irq.h
84499@@ -36,7 +36,7 @@ struct softirq_action;
84500 */
84501 TRACE_EVENT(irq_handler_entry,
84502
84503- TP_PROTO(int irq, struct irqaction *action),
84504+ TP_PROTO(int irq, const struct irqaction *action),
84505
84506 TP_ARGS(irq, action),
84507
84508@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84509 */
84510 TRACE_EVENT(irq_handler_exit,
84511
84512- TP_PROTO(int irq, struct irqaction *action, int ret),
84513+ TP_PROTO(int irq, const struct irqaction *action, int ret),
84514
84515 TP_ARGS(irq, action, ret),
84516
84517diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84518index 7caf44c..23c6f27 100644
84519--- a/include/uapi/linux/a.out.h
84520+++ b/include/uapi/linux/a.out.h
84521@@ -39,6 +39,14 @@ enum machine_type {
84522 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84523 };
84524
84525+/* Constants for the N_FLAGS field */
84526+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84527+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84528+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84529+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84530+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84531+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84532+
84533 #if !defined (N_MAGIC)
84534 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84535 #endif
84536diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84537index 22b6ad3..aeba37e 100644
84538--- a/include/uapi/linux/bcache.h
84539+++ b/include/uapi/linux/bcache.h
84540@@ -5,6 +5,7 @@
84541 * Bcache on disk data structures
84542 */
84543
84544+#include <linux/compiler.h>
84545 #include <asm/types.h>
84546
84547 #define BITMASK(name, type, field, offset, size) \
84548@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84549 /* Btree keys - all units are in sectors */
84550
84551 struct bkey {
84552- __u64 high;
84553- __u64 low;
84554+ __u64 high __intentional_overflow(-1);
84555+ __u64 low __intentional_overflow(-1);
84556 __u64 ptr[];
84557 };
84558
84559diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84560index d876736..ccce5c0 100644
84561--- a/include/uapi/linux/byteorder/little_endian.h
84562+++ b/include/uapi/linux/byteorder/little_endian.h
84563@@ -42,51 +42,51 @@
84564
84565 static inline __le64 __cpu_to_le64p(const __u64 *p)
84566 {
84567- return (__force __le64)*p;
84568+ return (__force const __le64)*p;
84569 }
84570-static inline __u64 __le64_to_cpup(const __le64 *p)
84571+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84572 {
84573- return (__force __u64)*p;
84574+ return (__force const __u64)*p;
84575 }
84576 static inline __le32 __cpu_to_le32p(const __u32 *p)
84577 {
84578- return (__force __le32)*p;
84579+ return (__force const __le32)*p;
84580 }
84581 static inline __u32 __le32_to_cpup(const __le32 *p)
84582 {
84583- return (__force __u32)*p;
84584+ return (__force const __u32)*p;
84585 }
84586 static inline __le16 __cpu_to_le16p(const __u16 *p)
84587 {
84588- return (__force __le16)*p;
84589+ return (__force const __le16)*p;
84590 }
84591 static inline __u16 __le16_to_cpup(const __le16 *p)
84592 {
84593- return (__force __u16)*p;
84594+ return (__force const __u16)*p;
84595 }
84596 static inline __be64 __cpu_to_be64p(const __u64 *p)
84597 {
84598- return (__force __be64)__swab64p(p);
84599+ return (__force const __be64)__swab64p(p);
84600 }
84601 static inline __u64 __be64_to_cpup(const __be64 *p)
84602 {
84603- return __swab64p((__u64 *)p);
84604+ return __swab64p((const __u64 *)p);
84605 }
84606 static inline __be32 __cpu_to_be32p(const __u32 *p)
84607 {
84608- return (__force __be32)__swab32p(p);
84609+ return (__force const __be32)__swab32p(p);
84610 }
84611-static inline __u32 __be32_to_cpup(const __be32 *p)
84612+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84613 {
84614- return __swab32p((__u32 *)p);
84615+ return __swab32p((const __u32 *)p);
84616 }
84617 static inline __be16 __cpu_to_be16p(const __u16 *p)
84618 {
84619- return (__force __be16)__swab16p(p);
84620+ return (__force const __be16)__swab16p(p);
84621 }
84622 static inline __u16 __be16_to_cpup(const __be16 *p)
84623 {
84624- return __swab16p((__u16 *)p);
84625+ return __swab16p((const __u16 *)p);
84626 }
84627 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84628 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84629diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84630index ef6103b..d4e65dd 100644
84631--- a/include/uapi/linux/elf.h
84632+++ b/include/uapi/linux/elf.h
84633@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84634 #define PT_GNU_EH_FRAME 0x6474e550
84635
84636 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84637+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84638+
84639+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84640+
84641+/* Constants for the e_flags field */
84642+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84643+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84644+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84645+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84646+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84647+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84648
84649 /*
84650 * Extended Numbering
84651@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84652 #define DT_DEBUG 21
84653 #define DT_TEXTREL 22
84654 #define DT_JMPREL 23
84655+#define DT_FLAGS 30
84656+ #define DF_TEXTREL 0x00000004
84657 #define DT_ENCODING 32
84658 #define OLD_DT_LOOS 0x60000000
84659 #define DT_LOOS 0x6000000d
84660@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84661 #define PF_W 0x2
84662 #define PF_X 0x1
84663
84664+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84665+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84666+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84667+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84668+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84669+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84670+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84671+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84672+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84673+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84674+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84675+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84676+
84677 typedef struct elf32_phdr{
84678 Elf32_Word p_type;
84679 Elf32_Off p_offset;
84680@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84681 #define EI_OSABI 7
84682 #define EI_PAD 8
84683
84684+#define EI_PAX 14
84685+
84686 #define ELFMAG0 0x7f /* EI_MAG */
84687 #define ELFMAG1 'E'
84688 #define ELFMAG2 'L'
84689diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84690index aa169c4..6a2771d 100644
84691--- a/include/uapi/linux/personality.h
84692+++ b/include/uapi/linux/personality.h
84693@@ -30,6 +30,7 @@ enum {
84694 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84695 ADDR_NO_RANDOMIZE | \
84696 ADDR_COMPAT_LAYOUT | \
84697+ ADDR_LIMIT_3GB | \
84698 MMAP_PAGE_ZERO)
84699
84700 /*
84701diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84702index 7530e74..e714828 100644
84703--- a/include/uapi/linux/screen_info.h
84704+++ b/include/uapi/linux/screen_info.h
84705@@ -43,7 +43,8 @@ struct screen_info {
84706 __u16 pages; /* 0x32 */
84707 __u16 vesa_attributes; /* 0x34 */
84708 __u32 capabilities; /* 0x36 */
84709- __u8 _reserved[6]; /* 0x3a */
84710+ __u16 vesapm_size; /* 0x3a */
84711+ __u8 _reserved[4]; /* 0x3c */
84712 } __attribute__((packed));
84713
84714 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84715diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84716index 0e011eb..82681b1 100644
84717--- a/include/uapi/linux/swab.h
84718+++ b/include/uapi/linux/swab.h
84719@@ -43,7 +43,7 @@
84720 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84721 */
84722
84723-static inline __attribute_const__ __u16 __fswab16(__u16 val)
84724+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84725 {
84726 #ifdef __HAVE_BUILTIN_BSWAP16__
84727 return __builtin_bswap16(val);
84728@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84729 #endif
84730 }
84731
84732-static inline __attribute_const__ __u32 __fswab32(__u32 val)
84733+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84734 {
84735 #ifdef __HAVE_BUILTIN_BSWAP32__
84736 return __builtin_bswap32(val);
84737@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84738 #endif
84739 }
84740
84741-static inline __attribute_const__ __u64 __fswab64(__u64 val)
84742+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84743 {
84744 #ifdef __HAVE_BUILTIN_BSWAP64__
84745 return __builtin_bswap64(val);
84746diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84747index 6d67213..552fdd9 100644
84748--- a/include/uapi/linux/sysctl.h
84749+++ b/include/uapi/linux/sysctl.h
84750@@ -155,8 +155,6 @@ enum
84751 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84752 };
84753
84754-
84755-
84756 /* CTL_VM names: */
84757 enum
84758 {
84759diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84760index fe94bb9..c9e51c2 100644
84761--- a/include/uapi/linux/videodev2.h
84762+++ b/include/uapi/linux/videodev2.h
84763@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
84764 union {
84765 __s32 value;
84766 __s64 value64;
84767- char *string;
84768+ char __user *string;
84769 };
84770 } __attribute__ ((packed));
84771
84772diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84773index c38355c..17a57bc 100644
84774--- a/include/uapi/linux/xattr.h
84775+++ b/include/uapi/linux/xattr.h
84776@@ -73,5 +73,9 @@
84777 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84778 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84779
84780+/* User namespace */
84781+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84782+#define XATTR_PAX_FLAGS_SUFFIX "flags"
84783+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84784
84785 #endif /* _UAPI_LINUX_XATTR_H */
84786diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84787index f9466fa..f4e2b81 100644
84788--- a/include/video/udlfb.h
84789+++ b/include/video/udlfb.h
84790@@ -53,10 +53,10 @@ struct dlfb_data {
84791 u32 pseudo_palette[256];
84792 int blank_mode; /*one of FB_BLANK_ */
84793 /* blit-only rendering path metrics, exposed through sysfs */
84794- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84795- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84796- atomic_t bytes_sent; /* to usb, after compression including overhead */
84797- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84798+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84799+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84800+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84801+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84802 };
84803
84804 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84805diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84806index 30f5362..8ed8ac9 100644
84807--- a/include/video/uvesafb.h
84808+++ b/include/video/uvesafb.h
84809@@ -122,6 +122,7 @@ struct uvesafb_par {
84810 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84811 u8 pmi_setpal; /* PMI for palette changes */
84812 u16 *pmi_base; /* protected mode interface location */
84813+ u8 *pmi_code; /* protected mode code location */
84814 void *pmi_start;
84815 void *pmi_pal;
84816 u8 *vbe_state_orig; /*
84817diff --git a/init/Kconfig b/init/Kconfig
84818index d56cb03..7e6d5dc 100644
84819--- a/init/Kconfig
84820+++ b/init/Kconfig
84821@@ -1079,6 +1079,7 @@ endif # CGROUPS
84822
84823 config CHECKPOINT_RESTORE
84824 bool "Checkpoint/restore support" if EXPERT
84825+ depends on !GRKERNSEC
84826 default n
84827 help
84828 Enables additional kernel features in a sake of checkpoint/restore.
84829@@ -1545,7 +1546,7 @@ config SLUB_DEBUG
84830
84831 config COMPAT_BRK
84832 bool "Disable heap randomization"
84833- default y
84834+ default n
84835 help
84836 Randomizing heap placement makes heap exploits harder, but it
84837 also breaks ancient binaries (including anything libc5 based).
84838@@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
84839 config STOP_MACHINE
84840 bool
84841 default y
84842- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84843+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84844 help
84845 Need stop_machine() primitive.
84846
84847diff --git a/init/Makefile b/init/Makefile
84848index 7bc47ee..6da2dc7 100644
84849--- a/init/Makefile
84850+++ b/init/Makefile
84851@@ -2,6 +2,9 @@
84852 # Makefile for the linux kernel.
84853 #
84854
84855+ccflags-y := $(GCC_PLUGINS_CFLAGS)
84856+asflags-y := $(GCC_PLUGINS_AFLAGS)
84857+
84858 obj-y := main.o version.o mounts.o
84859 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84860 obj-y += noinitramfs.o
84861diff --git a/init/do_mounts.c b/init/do_mounts.c
84862index 8e5addc..c96ea61 100644
84863--- a/init/do_mounts.c
84864+++ b/init/do_mounts.c
84865@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84866 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84867 {
84868 struct super_block *s;
84869- int err = sys_mount(name, "/root", fs, flags, data);
84870+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84871 if (err)
84872 return err;
84873
84874- sys_chdir("/root");
84875+ sys_chdir((const char __force_user *)"/root");
84876 s = current->fs->pwd.dentry->d_sb;
84877 ROOT_DEV = s->s_dev;
84878 printk(KERN_INFO
84879@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84880 va_start(args, fmt);
84881 vsprintf(buf, fmt, args);
84882 va_end(args);
84883- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84884+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84885 if (fd >= 0) {
84886 sys_ioctl(fd, FDEJECT, 0);
84887 sys_close(fd);
84888 }
84889 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84890- fd = sys_open("/dev/console", O_RDWR, 0);
84891+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84892 if (fd >= 0) {
84893 sys_ioctl(fd, TCGETS, (long)&termios);
84894 termios.c_lflag &= ~ICANON;
84895 sys_ioctl(fd, TCSETSF, (long)&termios);
84896- sys_read(fd, &c, 1);
84897+ sys_read(fd, (char __user *)&c, 1);
84898 termios.c_lflag |= ICANON;
84899 sys_ioctl(fd, TCSETSF, (long)&termios);
84900 sys_close(fd);
84901@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84902 mount_root();
84903 out:
84904 devtmpfs_mount("dev");
84905- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84906- sys_chroot(".");
84907+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84908+ sys_chroot((const char __force_user *)".");
84909 }
84910
84911 static bool is_tmpfs;
84912diff --git a/init/do_mounts.h b/init/do_mounts.h
84913index f5b978a..69dbfe8 100644
84914--- a/init/do_mounts.h
84915+++ b/init/do_mounts.h
84916@@ -15,15 +15,15 @@ extern int root_mountflags;
84917
84918 static inline int create_dev(char *name, dev_t dev)
84919 {
84920- sys_unlink(name);
84921- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84922+ sys_unlink((char __force_user *)name);
84923+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84924 }
84925
84926 #if BITS_PER_LONG == 32
84927 static inline u32 bstat(char *name)
84928 {
84929 struct stat64 stat;
84930- if (sys_stat64(name, &stat) != 0)
84931+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84932 return 0;
84933 if (!S_ISBLK(stat.st_mode))
84934 return 0;
84935@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84936 static inline u32 bstat(char *name)
84937 {
84938 struct stat stat;
84939- if (sys_newstat(name, &stat) != 0)
84940+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84941 return 0;
84942 if (!S_ISBLK(stat.st_mode))
84943 return 0;
84944diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84945index 3e0878e..8a9d7a0 100644
84946--- a/init/do_mounts_initrd.c
84947+++ b/init/do_mounts_initrd.c
84948@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84949 {
84950 sys_unshare(CLONE_FS | CLONE_FILES);
84951 /* stdin/stdout/stderr for /linuxrc */
84952- sys_open("/dev/console", O_RDWR, 0);
84953+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84954 sys_dup(0);
84955 sys_dup(0);
84956 /* move initrd over / and chdir/chroot in initrd root */
84957- sys_chdir("/root");
84958- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84959- sys_chroot(".");
84960+ sys_chdir((const char __force_user *)"/root");
84961+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84962+ sys_chroot((const char __force_user *)".");
84963 sys_setsid();
84964 return 0;
84965 }
84966@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84967 create_dev("/dev/root.old", Root_RAM0);
84968 /* mount initrd on rootfs' /root */
84969 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84970- sys_mkdir("/old", 0700);
84971- sys_chdir("/old");
84972+ sys_mkdir((const char __force_user *)"/old", 0700);
84973+ sys_chdir((const char __force_user *)"/old");
84974
84975 /* try loading default modules from initrd */
84976 load_default_modules();
84977@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84978 current->flags &= ~PF_FREEZER_SKIP;
84979
84980 /* move initrd to rootfs' /old */
84981- sys_mount("..", ".", NULL, MS_MOVE, NULL);
84982+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84983 /* switch root and cwd back to / of rootfs */
84984- sys_chroot("..");
84985+ sys_chroot((const char __force_user *)"..");
84986
84987 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84988- sys_chdir("/old");
84989+ sys_chdir((const char __force_user *)"/old");
84990 return;
84991 }
84992
84993- sys_chdir("/");
84994+ sys_chdir((const char __force_user *)"/");
84995 ROOT_DEV = new_decode_dev(real_root_dev);
84996 mount_root();
84997
84998 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84999- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
85000+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
85001 if (!error)
85002 printk("okay\n");
85003 else {
85004- int fd = sys_open("/dev/root.old", O_RDWR, 0);
85005+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
85006 if (error == -ENOENT)
85007 printk("/initrd does not exist. Ignored.\n");
85008 else
85009 printk("failed\n");
85010 printk(KERN_NOTICE "Unmounting old root\n");
85011- sys_umount("/old", MNT_DETACH);
85012+ sys_umount((char __force_user *)"/old", MNT_DETACH);
85013 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
85014 if (fd < 0) {
85015 error = fd;
85016@@ -127,11 +127,11 @@ int __init initrd_load(void)
85017 * mounted in the normal path.
85018 */
85019 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
85020- sys_unlink("/initrd.image");
85021+ sys_unlink((const char __force_user *)"/initrd.image");
85022 handle_initrd();
85023 return 1;
85024 }
85025 }
85026- sys_unlink("/initrd.image");
85027+ sys_unlink((const char __force_user *)"/initrd.image");
85028 return 0;
85029 }
85030diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
85031index 8cb6db5..d729f50 100644
85032--- a/init/do_mounts_md.c
85033+++ b/init/do_mounts_md.c
85034@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
85035 partitioned ? "_d" : "", minor,
85036 md_setup_args[ent].device_names);
85037
85038- fd = sys_open(name, 0, 0);
85039+ fd = sys_open((char __force_user *)name, 0, 0);
85040 if (fd < 0) {
85041 printk(KERN_ERR "md: open failed - cannot start "
85042 "array %s\n", name);
85043@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
85044 * array without it
85045 */
85046 sys_close(fd);
85047- fd = sys_open(name, 0, 0);
85048+ fd = sys_open((char __force_user *)name, 0, 0);
85049 sys_ioctl(fd, BLKRRPART, 0);
85050 }
85051 sys_close(fd);
85052@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
85053
85054 wait_for_device_probe();
85055
85056- fd = sys_open("/dev/md0", 0, 0);
85057+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
85058 if (fd >= 0) {
85059 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
85060 sys_close(fd);
85061diff --git a/init/init_task.c b/init/init_task.c
85062index ba0a7f36..2bcf1d5 100644
85063--- a/init/init_task.c
85064+++ b/init/init_task.c
85065@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
85066 * Initial thread structure. Alignment of this is handled by a special
85067 * linker map entry.
85068 */
85069+#ifdef CONFIG_X86
85070+union thread_union init_thread_union __init_task_data;
85071+#else
85072 union thread_union init_thread_union __init_task_data =
85073 { INIT_THREAD_INFO(init_task) };
85074+#endif
85075diff --git a/init/initramfs.c b/init/initramfs.c
85076index 93b6139..8d628b7 100644
85077--- a/init/initramfs.c
85078+++ b/init/initramfs.c
85079@@ -84,7 +84,7 @@ static void __init free_hash(void)
85080 }
85081 }
85082
85083-static long __init do_utime(char *filename, time_t mtime)
85084+static long __init do_utime(char __force_user *filename, time_t mtime)
85085 {
85086 struct timespec t[2];
85087
85088@@ -119,7 +119,7 @@ static void __init dir_utime(void)
85089 struct dir_entry *de, *tmp;
85090 list_for_each_entry_safe(de, tmp, &dir_list, list) {
85091 list_del(&de->list);
85092- do_utime(de->name, de->mtime);
85093+ do_utime((char __force_user *)de->name, de->mtime);
85094 kfree(de->name);
85095 kfree(de);
85096 }
85097@@ -281,7 +281,7 @@ static int __init maybe_link(void)
85098 if (nlink >= 2) {
85099 char *old = find_link(major, minor, ino, mode, collected);
85100 if (old)
85101- return (sys_link(old, collected) < 0) ? -1 : 1;
85102+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
85103 }
85104 return 0;
85105 }
85106@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
85107 {
85108 struct stat st;
85109
85110- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
85111+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
85112 if (S_ISDIR(st.st_mode))
85113- sys_rmdir(path);
85114+ sys_rmdir((char __force_user *)path);
85115 else
85116- sys_unlink(path);
85117+ sys_unlink((char __force_user *)path);
85118 }
85119 }
85120
85121@@ -315,7 +315,7 @@ static int __init do_name(void)
85122 int openflags = O_WRONLY|O_CREAT;
85123 if (ml != 1)
85124 openflags |= O_TRUNC;
85125- wfd = sys_open(collected, openflags, mode);
85126+ wfd = sys_open((char __force_user *)collected, openflags, mode);
85127
85128 if (wfd >= 0) {
85129 sys_fchown(wfd, uid, gid);
85130@@ -327,17 +327,17 @@ static int __init do_name(void)
85131 }
85132 }
85133 } else if (S_ISDIR(mode)) {
85134- sys_mkdir(collected, mode);
85135- sys_chown(collected, uid, gid);
85136- sys_chmod(collected, mode);
85137+ sys_mkdir((char __force_user *)collected, mode);
85138+ sys_chown((char __force_user *)collected, uid, gid);
85139+ sys_chmod((char __force_user *)collected, mode);
85140 dir_add(collected, mtime);
85141 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
85142 S_ISFIFO(mode) || S_ISSOCK(mode)) {
85143 if (maybe_link() == 0) {
85144- sys_mknod(collected, mode, rdev);
85145- sys_chown(collected, uid, gid);
85146- sys_chmod(collected, mode);
85147- do_utime(collected, mtime);
85148+ sys_mknod((char __force_user *)collected, mode, rdev);
85149+ sys_chown((char __force_user *)collected, uid, gid);
85150+ sys_chmod((char __force_user *)collected, mode);
85151+ do_utime((char __force_user *)collected, mtime);
85152 }
85153 }
85154 return 0;
85155@@ -346,15 +346,15 @@ static int __init do_name(void)
85156 static int __init do_copy(void)
85157 {
85158 if (count >= body_len) {
85159- sys_write(wfd, victim, body_len);
85160+ sys_write(wfd, (char __force_user *)victim, body_len);
85161 sys_close(wfd);
85162- do_utime(vcollected, mtime);
85163+ do_utime((char __force_user *)vcollected, mtime);
85164 kfree(vcollected);
85165 eat(body_len);
85166 state = SkipIt;
85167 return 0;
85168 } else {
85169- sys_write(wfd, victim, count);
85170+ sys_write(wfd, (char __force_user *)victim, count);
85171 body_len -= count;
85172 eat(count);
85173 return 1;
85174@@ -365,9 +365,9 @@ static int __init do_symlink(void)
85175 {
85176 collected[N_ALIGN(name_len) + body_len] = '\0';
85177 clean_path(collected, 0);
85178- sys_symlink(collected + N_ALIGN(name_len), collected);
85179- sys_lchown(collected, uid, gid);
85180- do_utime(collected, mtime);
85181+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
85182+ sys_lchown((char __force_user *)collected, uid, gid);
85183+ do_utime((char __force_user *)collected, mtime);
85184 state = SkipIt;
85185 next_state = Reset;
85186 return 0;
85187diff --git a/init/main.c b/init/main.c
85188index 9c7fd4c..650b4f1 100644
85189--- a/init/main.c
85190+++ b/init/main.c
85191@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
85192 static inline void mark_rodata_ro(void) { }
85193 #endif
85194
85195+extern void grsecurity_init(void);
85196+
85197 /*
85198 * Debug helper: via this flag we know that we are in 'early bootup code'
85199 * where only the boot processor is running with IRQ disabled. This means
85200@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
85201
85202 __setup("reset_devices", set_reset_devices);
85203
85204+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85205+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
85206+static int __init setup_grsec_proc_gid(char *str)
85207+{
85208+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
85209+ return 1;
85210+}
85211+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
85212+#endif
85213+
85214+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
85215+unsigned long pax_user_shadow_base __read_only;
85216+EXPORT_SYMBOL(pax_user_shadow_base);
85217+extern char pax_enter_kernel_user[];
85218+extern char pax_exit_kernel_user[];
85219+#endif
85220+
85221+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
85222+static int __init setup_pax_nouderef(char *str)
85223+{
85224+#ifdef CONFIG_X86_32
85225+ unsigned int cpu;
85226+ struct desc_struct *gdt;
85227+
85228+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
85229+ gdt = get_cpu_gdt_table(cpu);
85230+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
85231+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
85232+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
85233+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
85234+ }
85235+ loadsegment(ds, __KERNEL_DS);
85236+ loadsegment(es, __KERNEL_DS);
85237+ loadsegment(ss, __KERNEL_DS);
85238+#else
85239+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
85240+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
85241+ clone_pgd_mask = ~(pgdval_t)0UL;
85242+ pax_user_shadow_base = 0UL;
85243+ setup_clear_cpu_cap(X86_FEATURE_PCID);
85244+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
85245+#endif
85246+
85247+ return 0;
85248+}
85249+early_param("pax_nouderef", setup_pax_nouderef);
85250+
85251+#ifdef CONFIG_X86_64
85252+static int __init setup_pax_weakuderef(char *str)
85253+{
85254+ if (clone_pgd_mask != ~(pgdval_t)0UL)
85255+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
85256+ return 1;
85257+}
85258+__setup("pax_weakuderef", setup_pax_weakuderef);
85259+#endif
85260+#endif
85261+
85262+#ifdef CONFIG_PAX_SOFTMODE
85263+int pax_softmode;
85264+
85265+static int __init setup_pax_softmode(char *str)
85266+{
85267+ get_option(&str, &pax_softmode);
85268+ return 1;
85269+}
85270+__setup("pax_softmode=", setup_pax_softmode);
85271+#endif
85272+
85273 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85274 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85275 static const char *panic_later, *panic_param;
85276@@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85277 {
85278 int count = preempt_count();
85279 int ret;
85280- char msgbuf[64];
85281+ const char *msg1 = "", *msg2 = "";
85282
85283 if (initcall_debug)
85284 ret = do_one_initcall_debug(fn);
85285 else
85286 ret = fn();
85287
85288- msgbuf[0] = 0;
85289-
85290 if (preempt_count() != count) {
85291- sprintf(msgbuf, "preemption imbalance ");
85292+ msg1 = " preemption imbalance";
85293 preempt_count_set(count);
85294 }
85295 if (irqs_disabled()) {
85296- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85297+ msg2 = " disabled interrupts";
85298 local_irq_enable();
85299 }
85300- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85301+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85302
85303+ add_latent_entropy();
85304 return ret;
85305 }
85306
85307@@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
85308 {
85309 argv_init[0] = init_filename;
85310 return do_execve(getname_kernel(init_filename),
85311- (const char __user *const __user *)argv_init,
85312- (const char __user *const __user *)envp_init);
85313+ (const char __user *const __force_user *)argv_init,
85314+ (const char __user *const __force_user *)envp_init);
85315 }
85316
85317 static int try_to_run_init_process(const char *init_filename)
85318@@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
85319 return ret;
85320 }
85321
85322+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85323+extern int gr_init_ran;
85324+#endif
85325+
85326 static noinline void __init kernel_init_freeable(void);
85327
85328 static int __ref kernel_init(void *unused)
85329@@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
85330 ramdisk_execute_command, ret);
85331 }
85332
85333+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85334+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
85335+ gr_init_ran = 1;
85336+#endif
85337+
85338 /*
85339 * We try each of these until one succeeds.
85340 *
85341@@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
85342 do_basic_setup();
85343
85344 /* Open the /dev/console on the rootfs, this should never fail */
85345- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85346+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85347 pr_err("Warning: unable to open an initial console.\n");
85348
85349 (void) sys_dup(0);
85350@@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
85351 if (!ramdisk_execute_command)
85352 ramdisk_execute_command = "/init";
85353
85354- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85355+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85356 ramdisk_execute_command = NULL;
85357 prepare_namespace();
85358 }
85359
85360+ grsecurity_init();
85361+
85362 /*
85363 * Ok, we have completed the initial bootup, and
85364 * we're essentially up and running. Get rid of the
85365diff --git a/ipc/compat.c b/ipc/compat.c
85366index f486b00..442867f 100644
85367--- a/ipc/compat.c
85368+++ b/ipc/compat.c
85369@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85370 COMPAT_SHMLBA);
85371 if (err < 0)
85372 return err;
85373- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85374+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85375 }
85376 case SHMDT:
85377 return sys_shmdt(compat_ptr(ptr));
85378diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85379index 1702864..797fa84 100644
85380--- a/ipc/ipc_sysctl.c
85381+++ b/ipc/ipc_sysctl.c
85382@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85383 static int proc_ipc_dointvec(ctl_table *table, int write,
85384 void __user *buffer, size_t *lenp, loff_t *ppos)
85385 {
85386- struct ctl_table ipc_table;
85387+ ctl_table_no_const ipc_table;
85388
85389 memcpy(&ipc_table, table, sizeof(ipc_table));
85390 ipc_table.data = get_ipc(table);
85391@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85392 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85393 void __user *buffer, size_t *lenp, loff_t *ppos)
85394 {
85395- struct ctl_table ipc_table;
85396+ ctl_table_no_const ipc_table;
85397
85398 memcpy(&ipc_table, table, sizeof(ipc_table));
85399 ipc_table.data = get_ipc(table);
85400@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85401 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85402 void __user *buffer, size_t *lenp, loff_t *ppos)
85403 {
85404- struct ctl_table ipc_table;
85405+ ctl_table_no_const ipc_table;
85406 size_t lenp_bef = *lenp;
85407 int rc;
85408
85409@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85410 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85411 void __user *buffer, size_t *lenp, loff_t *ppos)
85412 {
85413- struct ctl_table ipc_table;
85414+ ctl_table_no_const ipc_table;
85415 memcpy(&ipc_table, table, sizeof(ipc_table));
85416 ipc_table.data = get_ipc(table);
85417
85418@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85419 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85420 void __user *buffer, size_t *lenp, loff_t *ppos)
85421 {
85422- struct ctl_table ipc_table;
85423+ ctl_table_no_const ipc_table;
85424 size_t lenp_bef = *lenp;
85425 int oldval;
85426 int rc;
85427diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85428index 5bb8bfe..a38ec05 100644
85429--- a/ipc/mq_sysctl.c
85430+++ b/ipc/mq_sysctl.c
85431@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85432 static int proc_mq_dointvec(ctl_table *table, int write,
85433 void __user *buffer, size_t *lenp, loff_t *ppos)
85434 {
85435- struct ctl_table mq_table;
85436+ ctl_table_no_const mq_table;
85437 memcpy(&mq_table, table, sizeof(mq_table));
85438 mq_table.data = get_mq(table);
85439
85440@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85441 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85442 void __user *buffer, size_t *lenp, loff_t *ppos)
85443 {
85444- struct ctl_table mq_table;
85445+ ctl_table_no_const mq_table;
85446 memcpy(&mq_table, table, sizeof(mq_table));
85447 mq_table.data = get_mq(table);
85448
85449diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85450index c3b3117..1efa933 100644
85451--- a/ipc/mqueue.c
85452+++ b/ipc/mqueue.c
85453@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85454 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85455 info->attr.mq_msgsize);
85456
85457+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85458 spin_lock(&mq_lock);
85459 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85460 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85461diff --git a/ipc/msg.c b/ipc/msg.c
85462index 6498531..b0ff3c8 100644
85463--- a/ipc/msg.c
85464+++ b/ipc/msg.c
85465@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85466 return security_msg_queue_associate(msq, msgflg);
85467 }
85468
85469+static struct ipc_ops msg_ops = {
85470+ .getnew = newque,
85471+ .associate = msg_security,
85472+ .more_checks = NULL
85473+};
85474+
85475 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85476 {
85477 struct ipc_namespace *ns;
85478- struct ipc_ops msg_ops;
85479 struct ipc_params msg_params;
85480
85481 ns = current->nsproxy->ipc_ns;
85482
85483- msg_ops.getnew = newque;
85484- msg_ops.associate = msg_security;
85485- msg_ops.more_checks = NULL;
85486-
85487 msg_params.key = key;
85488 msg_params.flg = msgflg;
85489
85490diff --git a/ipc/sem.c b/ipc/sem.c
85491index bee5554..e9af81dd 100644
85492--- a/ipc/sem.c
85493+++ b/ipc/sem.c
85494@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85495 return 0;
85496 }
85497
85498+static struct ipc_ops sem_ops = {
85499+ .getnew = newary,
85500+ .associate = sem_security,
85501+ .more_checks = sem_more_checks
85502+};
85503+
85504 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85505 {
85506 struct ipc_namespace *ns;
85507- struct ipc_ops sem_ops;
85508 struct ipc_params sem_params;
85509
85510 ns = current->nsproxy->ipc_ns;
85511@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85512 if (nsems < 0 || nsems > ns->sc_semmsl)
85513 return -EINVAL;
85514
85515- sem_ops.getnew = newary;
85516- sem_ops.associate = sem_security;
85517- sem_ops.more_checks = sem_more_checks;
85518-
85519 sem_params.key = key;
85520 sem_params.flg = semflg;
85521 sem_params.u.nsems = nsems;
85522diff --git a/ipc/shm.c b/ipc/shm.c
85523index 7645961..afc7f02 100644
85524--- a/ipc/shm.c
85525+++ b/ipc/shm.c
85526@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85527 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85528 #endif
85529
85530+#ifdef CONFIG_GRKERNSEC
85531+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85532+ const time_t shm_createtime, const kuid_t cuid,
85533+ const int shmid);
85534+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85535+ const time_t shm_createtime);
85536+#endif
85537+
85538 void shm_init_ns(struct ipc_namespace *ns)
85539 {
85540 ns->shm_ctlmax = SHMMAX;
85541@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85542 shp->shm_lprid = 0;
85543 shp->shm_atim = shp->shm_dtim = 0;
85544 shp->shm_ctim = get_seconds();
85545+#ifdef CONFIG_GRKERNSEC
85546+ {
85547+ struct timespec timeval;
85548+ do_posix_clock_monotonic_gettime(&timeval);
85549+
85550+ shp->shm_createtime = timeval.tv_sec;
85551+ }
85552+#endif
85553 shp->shm_segsz = size;
85554 shp->shm_nattch = 0;
85555 shp->shm_file = file;
85556@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85557 return 0;
85558 }
85559
85560+static struct ipc_ops shm_ops = {
85561+ .getnew = newseg,
85562+ .associate = shm_security,
85563+ .more_checks = shm_more_checks
85564+};
85565+
85566 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85567 {
85568 struct ipc_namespace *ns;
85569- struct ipc_ops shm_ops;
85570 struct ipc_params shm_params;
85571
85572 ns = current->nsproxy->ipc_ns;
85573
85574- shm_ops.getnew = newseg;
85575- shm_ops.associate = shm_security;
85576- shm_ops.more_checks = shm_more_checks;
85577-
85578 shm_params.key = key;
85579 shm_params.flg = shmflg;
85580 shm_params.u.size = size;
85581@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85582 f_mode = FMODE_READ | FMODE_WRITE;
85583 }
85584 if (shmflg & SHM_EXEC) {
85585+
85586+#ifdef CONFIG_PAX_MPROTECT
85587+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
85588+ goto out;
85589+#endif
85590+
85591 prot |= PROT_EXEC;
85592 acc_mode |= S_IXUGO;
85593 }
85594@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85595 if (err)
85596 goto out_unlock;
85597
85598+#ifdef CONFIG_GRKERNSEC
85599+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85600+ shp->shm_perm.cuid, shmid) ||
85601+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85602+ err = -EACCES;
85603+ goto out_unlock;
85604+ }
85605+#endif
85606+
85607 ipc_lock_object(&shp->shm_perm);
85608
85609 /* check if shm_destroy() is tearing down shp */
85610@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85611 path = shp->shm_file->f_path;
85612 path_get(&path);
85613 shp->shm_nattch++;
85614+#ifdef CONFIG_GRKERNSEC
85615+ shp->shm_lapid = current->pid;
85616+#endif
85617 size = i_size_read(path.dentry->d_inode);
85618 ipc_unlock_object(&shp->shm_perm);
85619 rcu_read_unlock();
85620diff --git a/ipc/util.c b/ipc/util.c
85621index e1b4c6d..8174204 100644
85622--- a/ipc/util.c
85623+++ b/ipc/util.c
85624@@ -71,6 +71,8 @@ struct ipc_proc_iface {
85625 int (*show)(struct seq_file *, void *);
85626 };
85627
85628+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85629+
85630 static void ipc_memory_notifier(struct work_struct *work)
85631 {
85632 ipcns_notify(IPCNS_MEMCHANGED);
85633@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85634 granted_mode >>= 6;
85635 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85636 granted_mode >>= 3;
85637+
85638+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85639+ return -1;
85640+
85641 /* is there some bit set in requested_mode but not in granted_mode? */
85642 if ((requested_mode & ~granted_mode & 0007) &&
85643 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85644diff --git a/kernel/acct.c b/kernel/acct.c
85645index 8d6e145..33e0b1e 100644
85646--- a/kernel/acct.c
85647+++ b/kernel/acct.c
85648@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85649 */
85650 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85651 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85652- file->f_op->write(file, (char *)&ac,
85653+ file->f_op->write(file, (char __force_user *)&ac,
85654 sizeof(acct_t), &file->f_pos);
85655 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85656 set_fs(fs);
85657diff --git a/kernel/audit.c b/kernel/audit.c
85658index 95a20f3..e1cb300 100644
85659--- a/kernel/audit.c
85660+++ b/kernel/audit.c
85661@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85662 3) suppressed due to audit_rate_limit
85663 4) suppressed due to audit_backlog_limit
85664 */
85665-static atomic_t audit_lost = ATOMIC_INIT(0);
85666+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85667
85668 /* The netlink socket. */
85669 static struct sock *audit_sock;
85670@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85671 unsigned long now;
85672 int print;
85673
85674- atomic_inc(&audit_lost);
85675+ atomic_inc_unchecked(&audit_lost);
85676
85677 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85678
85679@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85680 if (print) {
85681 if (printk_ratelimit())
85682 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85683- atomic_read(&audit_lost),
85684+ atomic_read_unchecked(&audit_lost),
85685 audit_rate_limit,
85686 audit_backlog_limit);
85687 audit_panic(message);
85688@@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85689 s.pid = audit_pid;
85690 s.rate_limit = audit_rate_limit;
85691 s.backlog_limit = audit_backlog_limit;
85692- s.lost = atomic_read(&audit_lost);
85693+ s.lost = atomic_read_unchecked(&audit_lost);
85694 s.backlog = skb_queue_len(&audit_skb_queue);
85695 s.version = AUDIT_VERSION_LATEST;
85696 s.backlog_wait_time = audit_backlog_wait_time;
85697diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85698index 7aef2f4..db6ced2 100644
85699--- a/kernel/auditsc.c
85700+++ b/kernel/auditsc.c
85701@@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85702 }
85703
85704 /* global counter which is incremented every time something logs in */
85705-static atomic_t session_id = ATOMIC_INIT(0);
85706+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85707
85708 static int audit_set_loginuid_perm(kuid_t loginuid)
85709 {
85710@@ -2014,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
85711
85712 /* are we setting or clearing? */
85713 if (uid_valid(loginuid))
85714- sessionid = (unsigned int)atomic_inc_return(&session_id);
85715+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85716
85717 task->sessionid = sessionid;
85718 task->loginuid = loginuid;
85719diff --git a/kernel/capability.c b/kernel/capability.c
85720index 34019c5..363f279 100644
85721--- a/kernel/capability.c
85722+++ b/kernel/capability.c
85723@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85724 * before modification is attempted and the application
85725 * fails.
85726 */
85727+ if (tocopy > ARRAY_SIZE(kdata))
85728+ return -EFAULT;
85729+
85730 if (copy_to_user(dataptr, kdata, tocopy
85731 * sizeof(struct __user_cap_data_struct))) {
85732 return -EFAULT;
85733@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
85734 int ret;
85735
85736 rcu_read_lock();
85737- ret = security_capable(__task_cred(t), ns, cap);
85738+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85739+ gr_task_is_capable(t, __task_cred(t), cap);
85740 rcu_read_unlock();
85741
85742- return (ret == 0);
85743+ return ret;
85744 }
85745
85746 /**
85747@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85748 int ret;
85749
85750 rcu_read_lock();
85751- ret = security_capable_noaudit(__task_cred(t), ns, cap);
85752+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85753 rcu_read_unlock();
85754
85755- return (ret == 0);
85756+ return ret;
85757 }
85758
85759 /**
85760@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85761 BUG();
85762 }
85763
85764- if (security_capable(current_cred(), ns, cap) == 0) {
85765+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85766 current->flags |= PF_SUPERPRIV;
85767 return true;
85768 }
85769@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85770 }
85771 EXPORT_SYMBOL(ns_capable);
85772
85773+bool ns_capable_nolog(struct user_namespace *ns, int cap)
85774+{
85775+ if (unlikely(!cap_valid(cap))) {
85776+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85777+ BUG();
85778+ }
85779+
85780+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85781+ current->flags |= PF_SUPERPRIV;
85782+ return true;
85783+ }
85784+ return false;
85785+}
85786+EXPORT_SYMBOL(ns_capable_nolog);
85787+
85788 /**
85789 * file_ns_capable - Determine if the file's opener had a capability in effect
85790 * @file: The file we want to check
85791@@ -432,6 +451,12 @@ bool capable(int cap)
85792 }
85793 EXPORT_SYMBOL(capable);
85794
85795+bool capable_nolog(int cap)
85796+{
85797+ return ns_capable_nolog(&init_user_ns, cap);
85798+}
85799+EXPORT_SYMBOL(capable_nolog);
85800+
85801 /**
85802 * inode_capable - Check superior capability over inode
85803 * @inode: The inode in question
85804@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
85805 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85806 }
85807 EXPORT_SYMBOL(inode_capable);
85808+
85809+bool inode_capable_nolog(const struct inode *inode, int cap)
85810+{
85811+ struct user_namespace *ns = current_user_ns();
85812+
85813+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85814+}
85815+EXPORT_SYMBOL(inode_capable_nolog);
85816diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85817index 0c753dd..dd7d3d6 100644
85818--- a/kernel/cgroup.c
85819+++ b/kernel/cgroup.c
85820@@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85821 struct css_set *cset = link->cset;
85822 struct task_struct *task;
85823 int count = 0;
85824- seq_printf(seq, "css_set %p\n", cset);
85825+ seq_printf(seq, "css_set %pK\n", cset);
85826 list_for_each_entry(task, &cset->tasks, cg_list) {
85827 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
85828 seq_puts(seq, " ...\n");
85829diff --git a/kernel/compat.c b/kernel/compat.c
85830index 0a09e48..b46b3d78 100644
85831--- a/kernel/compat.c
85832+++ b/kernel/compat.c
85833@@ -13,6 +13,7 @@
85834
85835 #include <linux/linkage.h>
85836 #include <linux/compat.h>
85837+#include <linux/module.h>
85838 #include <linux/errno.h>
85839 #include <linux/time.h>
85840 #include <linux/signal.h>
85841@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85842 mm_segment_t oldfs;
85843 long ret;
85844
85845- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85846+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85847 oldfs = get_fs();
85848 set_fs(KERNEL_DS);
85849 ret = hrtimer_nanosleep_restart(restart);
85850@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
85851 oldfs = get_fs();
85852 set_fs(KERNEL_DS);
85853 ret = hrtimer_nanosleep(&tu,
85854- rmtp ? (struct timespec __user *)&rmt : NULL,
85855+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
85856 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85857 set_fs(oldfs);
85858
85859@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
85860 mm_segment_t old_fs = get_fs();
85861
85862 set_fs(KERNEL_DS);
85863- ret = sys_sigpending((old_sigset_t __user *) &s);
85864+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
85865 set_fs(old_fs);
85866 if (ret == 0)
85867 ret = put_user(s, set);
85868@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
85869 mm_segment_t old_fs = get_fs();
85870
85871 set_fs(KERNEL_DS);
85872- ret = sys_old_getrlimit(resource, &r);
85873+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85874 set_fs(old_fs);
85875
85876 if (!ret) {
85877@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85878 set_fs (KERNEL_DS);
85879 ret = sys_wait4(pid,
85880 (stat_addr ?
85881- (unsigned int __user *) &status : NULL),
85882- options, (struct rusage __user *) &r);
85883+ (unsigned int __force_user *) &status : NULL),
85884+ options, (struct rusage __force_user *) &r);
85885 set_fs (old_fs);
85886
85887 if (ret > 0) {
85888@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85889 memset(&info, 0, sizeof(info));
85890
85891 set_fs(KERNEL_DS);
85892- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85893- uru ? (struct rusage __user *)&ru : NULL);
85894+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85895+ uru ? (struct rusage __force_user *)&ru : NULL);
85896 set_fs(old_fs);
85897
85898 if ((ret < 0) || (info.si_signo == 0))
85899@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
85900 oldfs = get_fs();
85901 set_fs(KERNEL_DS);
85902 err = sys_timer_settime(timer_id, flags,
85903- (struct itimerspec __user *) &newts,
85904- (struct itimerspec __user *) &oldts);
85905+ (struct itimerspec __force_user *) &newts,
85906+ (struct itimerspec __force_user *) &oldts);
85907 set_fs(oldfs);
85908 if (!err && old && put_compat_itimerspec(old, &oldts))
85909 return -EFAULT;
85910@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
85911 oldfs = get_fs();
85912 set_fs(KERNEL_DS);
85913 err = sys_timer_gettime(timer_id,
85914- (struct itimerspec __user *) &ts);
85915+ (struct itimerspec __force_user *) &ts);
85916 set_fs(oldfs);
85917 if (!err && put_compat_itimerspec(setting, &ts))
85918 return -EFAULT;
85919@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
85920 oldfs = get_fs();
85921 set_fs(KERNEL_DS);
85922 err = sys_clock_settime(which_clock,
85923- (struct timespec __user *) &ts);
85924+ (struct timespec __force_user *) &ts);
85925 set_fs(oldfs);
85926 return err;
85927 }
85928@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
85929 oldfs = get_fs();
85930 set_fs(KERNEL_DS);
85931 err = sys_clock_gettime(which_clock,
85932- (struct timespec __user *) &ts);
85933+ (struct timespec __force_user *) &ts);
85934 set_fs(oldfs);
85935 if (!err && put_compat_timespec(&ts, tp))
85936 return -EFAULT;
85937@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
85938
85939 oldfs = get_fs();
85940 set_fs(KERNEL_DS);
85941- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85942+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85943 set_fs(oldfs);
85944
85945 err = compat_put_timex(utp, &txc);
85946@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
85947 oldfs = get_fs();
85948 set_fs(KERNEL_DS);
85949 err = sys_clock_getres(which_clock,
85950- (struct timespec __user *) &ts);
85951+ (struct timespec __force_user *) &ts);
85952 set_fs(oldfs);
85953 if (!err && tp && put_compat_timespec(&ts, tp))
85954 return -EFAULT;
85955@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85956 long err;
85957 mm_segment_t oldfs;
85958 struct timespec tu;
85959- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
85960+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85961
85962- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85963+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85964 oldfs = get_fs();
85965 set_fs(KERNEL_DS);
85966 err = clock_nanosleep_restart(restart);
85967@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
85968 oldfs = get_fs();
85969 set_fs(KERNEL_DS);
85970 err = sys_clock_nanosleep(which_clock, flags,
85971- (struct timespec __user *) &in,
85972- (struct timespec __user *) &out);
85973+ (struct timespec __force_user *) &in,
85974+ (struct timespec __force_user *) &out);
85975 set_fs(oldfs);
85976
85977 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85978@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85979 mm_segment_t old_fs = get_fs();
85980
85981 set_fs(KERNEL_DS);
85982- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85983+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85984 set_fs(old_fs);
85985 if (put_compat_timespec(&t, interval))
85986 return -EFAULT;
85987diff --git a/kernel/configs.c b/kernel/configs.c
85988index c18b1f1..b9a0132 100644
85989--- a/kernel/configs.c
85990+++ b/kernel/configs.c
85991@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85992 struct proc_dir_entry *entry;
85993
85994 /* create the current config file */
85995+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85996+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85997+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85998+ &ikconfig_file_ops);
85999+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86000+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
86001+ &ikconfig_file_ops);
86002+#endif
86003+#else
86004 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
86005 &ikconfig_file_ops);
86006+#endif
86007+
86008 if (!entry)
86009 return -ENOMEM;
86010
86011diff --git a/kernel/cred.c b/kernel/cred.c
86012index e0573a4..3874e41 100644
86013--- a/kernel/cred.c
86014+++ b/kernel/cred.c
86015@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
86016 validate_creds(cred);
86017 alter_cred_subscribers(cred, -1);
86018 put_cred(cred);
86019+
86020+#ifdef CONFIG_GRKERNSEC_SETXID
86021+ cred = (struct cred *) tsk->delayed_cred;
86022+ if (cred != NULL) {
86023+ tsk->delayed_cred = NULL;
86024+ validate_creds(cred);
86025+ alter_cred_subscribers(cred, -1);
86026+ put_cred(cred);
86027+ }
86028+#endif
86029 }
86030
86031 /**
86032@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
86033 * Always returns 0 thus allowing this function to be tail-called at the end
86034 * of, say, sys_setgid().
86035 */
86036-int commit_creds(struct cred *new)
86037+static int __commit_creds(struct cred *new)
86038 {
86039 struct task_struct *task = current;
86040 const struct cred *old = task->real_cred;
86041@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
86042
86043 get_cred(new); /* we will require a ref for the subj creds too */
86044
86045+ gr_set_role_label(task, new->uid, new->gid);
86046+
86047 /* dumpability changes */
86048 if (!uid_eq(old->euid, new->euid) ||
86049 !gid_eq(old->egid, new->egid) ||
86050@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
86051 put_cred(old);
86052 return 0;
86053 }
86054+#ifdef CONFIG_GRKERNSEC_SETXID
86055+extern int set_user(struct cred *new);
86056+
86057+void gr_delayed_cred_worker(void)
86058+{
86059+ const struct cred *new = current->delayed_cred;
86060+ struct cred *ncred;
86061+
86062+ current->delayed_cred = NULL;
86063+
86064+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
86065+ // from doing get_cred on it when queueing this
86066+ put_cred(new);
86067+ return;
86068+ } else if (new == NULL)
86069+ return;
86070+
86071+ ncred = prepare_creds();
86072+ if (!ncred)
86073+ goto die;
86074+ // uids
86075+ ncred->uid = new->uid;
86076+ ncred->euid = new->euid;
86077+ ncred->suid = new->suid;
86078+ ncred->fsuid = new->fsuid;
86079+ // gids
86080+ ncred->gid = new->gid;
86081+ ncred->egid = new->egid;
86082+ ncred->sgid = new->sgid;
86083+ ncred->fsgid = new->fsgid;
86084+ // groups
86085+ if (set_groups(ncred, new->group_info) < 0) {
86086+ abort_creds(ncred);
86087+ goto die;
86088+ }
86089+ // caps
86090+ ncred->securebits = new->securebits;
86091+ ncred->cap_inheritable = new->cap_inheritable;
86092+ ncred->cap_permitted = new->cap_permitted;
86093+ ncred->cap_effective = new->cap_effective;
86094+ ncred->cap_bset = new->cap_bset;
86095+
86096+ if (set_user(ncred)) {
86097+ abort_creds(ncred);
86098+ goto die;
86099+ }
86100+
86101+ // from doing get_cred on it when queueing this
86102+ put_cred(new);
86103+
86104+ __commit_creds(ncred);
86105+ return;
86106+die:
86107+ // from doing get_cred on it when queueing this
86108+ put_cred(new);
86109+ do_group_exit(SIGKILL);
86110+}
86111+#endif
86112+
86113+int commit_creds(struct cred *new)
86114+{
86115+#ifdef CONFIG_GRKERNSEC_SETXID
86116+ int ret;
86117+ int schedule_it = 0;
86118+ struct task_struct *t;
86119+
86120+ /* we won't get called with tasklist_lock held for writing
86121+ and interrupts disabled as the cred struct in that case is
86122+ init_cred
86123+ */
86124+ if (grsec_enable_setxid && !current_is_single_threaded() &&
86125+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
86126+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
86127+ schedule_it = 1;
86128+ }
86129+ ret = __commit_creds(new);
86130+ if (schedule_it) {
86131+ rcu_read_lock();
86132+ read_lock(&tasklist_lock);
86133+ for (t = next_thread(current); t != current;
86134+ t = next_thread(t)) {
86135+ if (t->delayed_cred == NULL) {
86136+ t->delayed_cred = get_cred(new);
86137+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
86138+ set_tsk_need_resched(t);
86139+ }
86140+ }
86141+ read_unlock(&tasklist_lock);
86142+ rcu_read_unlock();
86143+ }
86144+ return ret;
86145+#else
86146+ return __commit_creds(new);
86147+#endif
86148+}
86149+
86150 EXPORT_SYMBOL(commit_creds);
86151
86152 /**
86153diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
86154index 334b398..9145fb1 100644
86155--- a/kernel/debug/debug_core.c
86156+++ b/kernel/debug/debug_core.c
86157@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
86158 */
86159 static atomic_t masters_in_kgdb;
86160 static atomic_t slaves_in_kgdb;
86161-static atomic_t kgdb_break_tasklet_var;
86162+static atomic_unchecked_t kgdb_break_tasklet_var;
86163 atomic_t kgdb_setting_breakpoint;
86164
86165 struct task_struct *kgdb_usethread;
86166@@ -133,7 +133,7 @@ int kgdb_single_step;
86167 static pid_t kgdb_sstep_pid;
86168
86169 /* to keep track of the CPU which is doing the single stepping*/
86170-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86171+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86172
86173 /*
86174 * If you are debugging a problem where roundup (the collection of
86175@@ -541,7 +541,7 @@ return_normal:
86176 * kernel will only try for the value of sstep_tries before
86177 * giving up and continuing on.
86178 */
86179- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
86180+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
86181 (kgdb_info[cpu].task &&
86182 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
86183 atomic_set(&kgdb_active, -1);
86184@@ -639,8 +639,8 @@ cpu_master_loop:
86185 }
86186
86187 kgdb_restore:
86188- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
86189- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
86190+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
86191+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
86192 if (kgdb_info[sstep_cpu].task)
86193 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
86194 else
86195@@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
86196 static void kgdb_tasklet_bpt(unsigned long ing)
86197 {
86198 kgdb_breakpoint();
86199- atomic_set(&kgdb_break_tasklet_var, 0);
86200+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
86201 }
86202
86203 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
86204
86205 void kgdb_schedule_breakpoint(void)
86206 {
86207- if (atomic_read(&kgdb_break_tasklet_var) ||
86208+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
86209 atomic_read(&kgdb_active) != -1 ||
86210 atomic_read(&kgdb_setting_breakpoint))
86211 return;
86212- atomic_inc(&kgdb_break_tasklet_var);
86213+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
86214 tasklet_schedule(&kgdb_tasklet_breakpoint);
86215 }
86216 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
86217diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
86218index 0b097c8..11dd5c5 100644
86219--- a/kernel/debug/kdb/kdb_main.c
86220+++ b/kernel/debug/kdb/kdb_main.c
86221@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
86222 continue;
86223
86224 kdb_printf("%-20s%8u 0x%p ", mod->name,
86225- mod->core_size, (void *)mod);
86226+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
86227 #ifdef CONFIG_MODULE_UNLOAD
86228 kdb_printf("%4ld ", module_refcount(mod));
86229 #endif
86230@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
86231 kdb_printf(" (Loading)");
86232 else
86233 kdb_printf(" (Live)");
86234- kdb_printf(" 0x%p", mod->module_core);
86235+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
86236
86237 #ifdef CONFIG_MODULE_UNLOAD
86238 {
86239diff --git a/kernel/events/core.c b/kernel/events/core.c
86240index fa0b2d4..67a1c7a 100644
86241--- a/kernel/events/core.c
86242+++ b/kernel/events/core.c
86243@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
86244 * 0 - disallow raw tracepoint access for unpriv
86245 * 1 - disallow cpu events for unpriv
86246 * 2 - disallow kernel profiling for unpriv
86247+ * 3 - disallow all unpriv perf event use
86248 */
86249-int sysctl_perf_event_paranoid __read_mostly = 1;
86250+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86251+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
86252+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
86253+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
86254+#else
86255+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
86256+#endif
86257
86258 /* Minimum for 512 kiB + 1 user control page */
86259 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
86260@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
86261
86262 tmp *= sysctl_perf_cpu_time_max_percent;
86263 do_div(tmp, 100);
86264- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
86265+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86266 }
86267
86268 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86269@@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86270 update_perf_cpu_limits();
86271 }
86272
86273-static atomic64_t perf_event_id;
86274+static atomic64_unchecked_t perf_event_id;
86275
86276 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86277 enum event_type_t event_type);
86278@@ -2986,7 +2993,7 @@ static void __perf_event_read(void *info)
86279
86280 static inline u64 perf_event_count(struct perf_event *event)
86281 {
86282- return local64_read(&event->count) + atomic64_read(&event->child_count);
86283+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86284 }
86285
86286 static u64 perf_event_read(struct perf_event *event)
86287@@ -3354,9 +3361,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86288 mutex_lock(&event->child_mutex);
86289 total += perf_event_read(event);
86290 *enabled += event->total_time_enabled +
86291- atomic64_read(&event->child_total_time_enabled);
86292+ atomic64_read_unchecked(&event->child_total_time_enabled);
86293 *running += event->total_time_running +
86294- atomic64_read(&event->child_total_time_running);
86295+ atomic64_read_unchecked(&event->child_total_time_running);
86296
86297 list_for_each_entry(child, &event->child_list, child_list) {
86298 total += perf_event_read(child);
86299@@ -3785,10 +3792,10 @@ void perf_event_update_userpage(struct perf_event *event)
86300 userpg->offset -= local64_read(&event->hw.prev_count);
86301
86302 userpg->time_enabled = enabled +
86303- atomic64_read(&event->child_total_time_enabled);
86304+ atomic64_read_unchecked(&event->child_total_time_enabled);
86305
86306 userpg->time_running = running +
86307- atomic64_read(&event->child_total_time_running);
86308+ atomic64_read_unchecked(&event->child_total_time_running);
86309
86310 arch_perf_update_userpage(userpg, now);
86311
86312@@ -4339,7 +4346,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86313
86314 /* Data. */
86315 sp = perf_user_stack_pointer(regs);
86316- rem = __output_copy_user(handle, (void *) sp, dump_size);
86317+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86318 dyn_size = dump_size - rem;
86319
86320 perf_output_skip(handle, rem);
86321@@ -4430,11 +4437,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86322 values[n++] = perf_event_count(event);
86323 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86324 values[n++] = enabled +
86325- atomic64_read(&event->child_total_time_enabled);
86326+ atomic64_read_unchecked(&event->child_total_time_enabled);
86327 }
86328 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86329 values[n++] = running +
86330- atomic64_read(&event->child_total_time_running);
86331+ atomic64_read_unchecked(&event->child_total_time_running);
86332 }
86333 if (read_format & PERF_FORMAT_ID)
86334 values[n++] = primary_event_id(event);
86335@@ -6704,7 +6711,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86336 event->parent = parent_event;
86337
86338 event->ns = get_pid_ns(task_active_pid_ns(current));
86339- event->id = atomic64_inc_return(&perf_event_id);
86340+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
86341
86342 event->state = PERF_EVENT_STATE_INACTIVE;
86343
86344@@ -7004,6 +7011,11 @@ SYSCALL_DEFINE5(perf_event_open,
86345 if (flags & ~PERF_FLAG_ALL)
86346 return -EINVAL;
86347
86348+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86349+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86350+ return -EACCES;
86351+#endif
86352+
86353 err = perf_copy_attr(attr_uptr, &attr);
86354 if (err)
86355 return err;
86356@@ -7339,10 +7351,10 @@ static void sync_child_event(struct perf_event *child_event,
86357 /*
86358 * Add back the child's count to the parent's count:
86359 */
86360- atomic64_add(child_val, &parent_event->child_count);
86361- atomic64_add(child_event->total_time_enabled,
86362+ atomic64_add_unchecked(child_val, &parent_event->child_count);
86363+ atomic64_add_unchecked(child_event->total_time_enabled,
86364 &parent_event->child_total_time_enabled);
86365- atomic64_add(child_event->total_time_running,
86366+ atomic64_add_unchecked(child_event->total_time_running,
86367 &parent_event->child_total_time_running);
86368
86369 /*
86370diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86371index 569b2187..19940d9 100644
86372--- a/kernel/events/internal.h
86373+++ b/kernel/events/internal.h
86374@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86375 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86376 }
86377
86378-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86379+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86380 static inline unsigned long \
86381 func_name(struct perf_output_handle *handle, \
86382- const void *buf, unsigned long len) \
86383+ const void user *buf, unsigned long len) \
86384 { \
86385 unsigned long size, written; \
86386 \
86387@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86388 return 0;
86389 }
86390
86391-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86392+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86393
86394 static inline unsigned long
86395 memcpy_skip(void *dst, const void *src, unsigned long n)
86396@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86397 return 0;
86398 }
86399
86400-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86401+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86402
86403 #ifndef arch_perf_out_copy_user
86404 #define arch_perf_out_copy_user arch_perf_out_copy_user
86405@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86406 }
86407 #endif
86408
86409-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86410+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86411
86412 /* Callchain handling */
86413 extern struct perf_callchain_entry *
86414diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86415index 307d87c..6466cbe 100644
86416--- a/kernel/events/uprobes.c
86417+++ b/kernel/events/uprobes.c
86418@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86419 {
86420 struct page *page;
86421 uprobe_opcode_t opcode;
86422- int result;
86423+ long result;
86424
86425 pagefault_disable();
86426 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86427diff --git a/kernel/exit.c b/kernel/exit.c
86428index 81b3d67..ef189a4 100644
86429--- a/kernel/exit.c
86430+++ b/kernel/exit.c
86431@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86432 struct task_struct *leader;
86433 int zap_leader;
86434 repeat:
86435+#ifdef CONFIG_NET
86436+ gr_del_task_from_ip_table(p);
86437+#endif
86438+
86439 /* don't need to get the RCU readlock here - the process is dead and
86440 * can't be modifying its own credentials. But shut RCU-lockdep up */
86441 rcu_read_lock();
86442@@ -330,7 +334,7 @@ int allow_signal(int sig)
86443 * know it'll be handled, so that they don't get converted to
86444 * SIGKILL or just silently dropped.
86445 */
86446- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86447+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86448 recalc_sigpending();
86449 spin_unlock_irq(&current->sighand->siglock);
86450 return 0;
86451@@ -706,6 +710,8 @@ void do_exit(long code)
86452 struct task_struct *tsk = current;
86453 int group_dead;
86454
86455+ set_fs(USER_DS);
86456+
86457 profile_task_exit(tsk);
86458
86459 WARN_ON(blk_needs_flush_plug(tsk));
86460@@ -722,7 +728,6 @@ void do_exit(long code)
86461 * mm_release()->clear_child_tid() from writing to a user-controlled
86462 * kernel address.
86463 */
86464- set_fs(USER_DS);
86465
86466 ptrace_event(PTRACE_EVENT_EXIT, code);
86467
86468@@ -781,6 +786,9 @@ void do_exit(long code)
86469 tsk->exit_code = code;
86470 taskstats_exit(tsk, group_dead);
86471
86472+ gr_acl_handle_psacct(tsk, code);
86473+ gr_acl_handle_exit();
86474+
86475 exit_mm(tsk);
86476
86477 if (group_dead)
86478@@ -900,7 +908,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86479 * Take down every thread in the group. This is called by fatal signals
86480 * as well as by sys_exit_group (below).
86481 */
86482-void
86483+__noreturn void
86484 do_group_exit(int exit_code)
86485 {
86486 struct signal_struct *sig = current->signal;
86487diff --git a/kernel/fork.c b/kernel/fork.c
86488index a17621c..d9e4b37 100644
86489--- a/kernel/fork.c
86490+++ b/kernel/fork.c
86491@@ -137,6 +137,18 @@ void __weak arch_release_thread_info(struct thread_info *ti)
86492 {
86493 }
86494
86495+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86496+static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
86497+ int node)
86498+{
86499+ return vmalloc_stack(node);
86500+}
86501+
86502+static inline void free_thread_info(struct thread_info *ti)
86503+{
86504+ vfree(ti);
86505+}
86506+#else
86507 #ifndef CONFIG_ARCH_THREAD_INFO_ALLOCATOR
86508
86509 /*
86510@@ -179,6 +191,7 @@ void thread_info_cache_init(void)
86511 }
86512 # endif
86513 #endif
86514+#endif
86515
86516 /* SLAB cache for signal_struct structures (tsk->signal) */
86517 static struct kmem_cache *signal_cachep;
86518@@ -200,9 +213,11 @@ static struct kmem_cache *mm_cachep;
86519
86520 static void account_kernel_stack(struct thread_info *ti, int account)
86521 {
86522+#ifndef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86523 struct zone *zone = page_zone(virt_to_page(ti));
86524
86525 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
86526+#endif
86527 }
86528
86529 void free_task(struct task_struct *tsk)
86530@@ -319,7 +334,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86531 *stackend = STACK_END_MAGIC; /* for overflow detection */
86532
86533 #ifdef CONFIG_CC_STACKPROTECTOR
86534- tsk->stack_canary = get_random_int();
86535+ tsk->stack_canary = pax_get_random_long();
86536 #endif
86537
86538 /*
86539@@ -345,12 +360,80 @@ free_tsk:
86540 }
86541
86542 #ifdef CONFIG_MMU
86543-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86544+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86545+{
86546+ struct vm_area_struct *tmp;
86547+ unsigned long charge;
86548+ struct file *file;
86549+ int retval;
86550+
86551+ charge = 0;
86552+ if (mpnt->vm_flags & VM_ACCOUNT) {
86553+ unsigned long len = vma_pages(mpnt);
86554+
86555+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86556+ goto fail_nomem;
86557+ charge = len;
86558+ }
86559+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86560+ if (!tmp)
86561+ goto fail_nomem;
86562+ *tmp = *mpnt;
86563+ tmp->vm_mm = mm;
86564+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
86565+ retval = vma_dup_policy(mpnt, tmp);
86566+ if (retval)
86567+ goto fail_nomem_policy;
86568+ if (anon_vma_fork(tmp, mpnt))
86569+ goto fail_nomem_anon_vma_fork;
86570+ tmp->vm_flags &= ~VM_LOCKED;
86571+ tmp->vm_next = tmp->vm_prev = NULL;
86572+ tmp->vm_mirror = NULL;
86573+ file = tmp->vm_file;
86574+ if (file) {
86575+ struct inode *inode = file_inode(file);
86576+ struct address_space *mapping = file->f_mapping;
86577+
86578+ get_file(file);
86579+ if (tmp->vm_flags & VM_DENYWRITE)
86580+ atomic_dec(&inode->i_writecount);
86581+ mutex_lock(&mapping->i_mmap_mutex);
86582+ if (tmp->vm_flags & VM_SHARED)
86583+ mapping->i_mmap_writable++;
86584+ flush_dcache_mmap_lock(mapping);
86585+ /* insert tmp into the share list, just after mpnt */
86586+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86587+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86588+ else
86589+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86590+ flush_dcache_mmap_unlock(mapping);
86591+ mutex_unlock(&mapping->i_mmap_mutex);
86592+ }
86593+
86594+ /*
86595+ * Clear hugetlb-related page reserves for children. This only
86596+ * affects MAP_PRIVATE mappings. Faults generated by the child
86597+ * are not guaranteed to succeed, even if read-only
86598+ */
86599+ if (is_vm_hugetlb_page(tmp))
86600+ reset_vma_resv_huge_pages(tmp);
86601+
86602+ return tmp;
86603+
86604+fail_nomem_anon_vma_fork:
86605+ mpol_put(vma_policy(tmp));
86606+fail_nomem_policy:
86607+ kmem_cache_free(vm_area_cachep, tmp);
86608+fail_nomem:
86609+ vm_unacct_memory(charge);
86610+ return NULL;
86611+}
86612+
86613+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86614 {
86615 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86616 struct rb_node **rb_link, *rb_parent;
86617 int retval;
86618- unsigned long charge;
86619
86620 uprobe_start_dup_mmap();
86621 down_write(&oldmm->mmap_sem);
86622@@ -379,55 +462,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86623
86624 prev = NULL;
86625 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86626- struct file *file;
86627-
86628 if (mpnt->vm_flags & VM_DONTCOPY) {
86629 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86630 -vma_pages(mpnt));
86631 continue;
86632 }
86633- charge = 0;
86634- if (mpnt->vm_flags & VM_ACCOUNT) {
86635- unsigned long len = vma_pages(mpnt);
86636-
86637- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86638- goto fail_nomem;
86639- charge = len;
86640- }
86641- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86642- if (!tmp)
86643- goto fail_nomem;
86644- *tmp = *mpnt;
86645- INIT_LIST_HEAD(&tmp->anon_vma_chain);
86646- retval = vma_dup_policy(mpnt, tmp);
86647- if (retval)
86648- goto fail_nomem_policy;
86649- tmp->vm_mm = mm;
86650- if (anon_vma_fork(tmp, mpnt))
86651- goto fail_nomem_anon_vma_fork;
86652- tmp->vm_flags &= ~VM_LOCKED;
86653- tmp->vm_next = tmp->vm_prev = NULL;
86654- file = tmp->vm_file;
86655- if (file) {
86656- struct inode *inode = file_inode(file);
86657- struct address_space *mapping = file->f_mapping;
86658-
86659- get_file(file);
86660- if (tmp->vm_flags & VM_DENYWRITE)
86661- atomic_dec(&inode->i_writecount);
86662- mutex_lock(&mapping->i_mmap_mutex);
86663- if (tmp->vm_flags & VM_SHARED)
86664- mapping->i_mmap_writable++;
86665- flush_dcache_mmap_lock(mapping);
86666- /* insert tmp into the share list, just after mpnt */
86667- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86668- vma_nonlinear_insert(tmp,
86669- &mapping->i_mmap_nonlinear);
86670- else
86671- vma_interval_tree_insert_after(tmp, mpnt,
86672- &mapping->i_mmap);
86673- flush_dcache_mmap_unlock(mapping);
86674- mutex_unlock(&mapping->i_mmap_mutex);
86675+ tmp = dup_vma(mm, oldmm, mpnt);
86676+ if (!tmp) {
86677+ retval = -ENOMEM;
86678+ goto out;
86679 }
86680
86681 /*
86682@@ -459,6 +502,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86683 if (retval)
86684 goto out;
86685 }
86686+
86687+#ifdef CONFIG_PAX_SEGMEXEC
86688+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86689+ struct vm_area_struct *mpnt_m;
86690+
86691+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86692+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86693+
86694+ if (!mpnt->vm_mirror)
86695+ continue;
86696+
86697+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86698+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86699+ mpnt->vm_mirror = mpnt_m;
86700+ } else {
86701+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86702+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86703+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86704+ mpnt->vm_mirror->vm_mirror = mpnt;
86705+ }
86706+ }
86707+ BUG_ON(mpnt_m);
86708+ }
86709+#endif
86710+
86711 /* a new mm has just been created */
86712 arch_dup_mmap(oldmm, mm);
86713 retval = 0;
86714@@ -468,14 +536,6 @@ out:
86715 up_write(&oldmm->mmap_sem);
86716 uprobe_end_dup_mmap();
86717 return retval;
86718-fail_nomem_anon_vma_fork:
86719- mpol_put(vma_policy(tmp));
86720-fail_nomem_policy:
86721- kmem_cache_free(vm_area_cachep, tmp);
86722-fail_nomem:
86723- retval = -ENOMEM;
86724- vm_unacct_memory(charge);
86725- goto out;
86726 }
86727
86728 static inline int mm_alloc_pgd(struct mm_struct *mm)
86729@@ -689,8 +749,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86730 return ERR_PTR(err);
86731
86732 mm = get_task_mm(task);
86733- if (mm && mm != current->mm &&
86734- !ptrace_may_access(task, mode)) {
86735+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86736+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86737 mmput(mm);
86738 mm = ERR_PTR(-EACCES);
86739 }
86740@@ -906,13 +966,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86741 spin_unlock(&fs->lock);
86742 return -EAGAIN;
86743 }
86744- fs->users++;
86745+ atomic_inc(&fs->users);
86746 spin_unlock(&fs->lock);
86747 return 0;
86748 }
86749 tsk->fs = copy_fs_struct(fs);
86750 if (!tsk->fs)
86751 return -ENOMEM;
86752+ /* Carry through gr_chroot_dentry and is_chrooted instead
86753+ of recomputing it here. Already copied when the task struct
86754+ is duplicated. This allows pivot_root to not be treated as
86755+ a chroot
86756+ */
86757+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
86758+
86759 return 0;
86760 }
86761
86762@@ -1130,7 +1197,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86763 * parts of the process environment (as per the clone
86764 * flags). The actual kick-off is left to the caller.
86765 */
86766-static struct task_struct *copy_process(unsigned long clone_flags,
86767+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86768 unsigned long stack_start,
86769 unsigned long stack_size,
86770 int __user *child_tidptr,
86771@@ -1202,6 +1269,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86772 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86773 #endif
86774 retval = -EAGAIN;
86775+
86776+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86777+
86778 if (atomic_read(&p->real_cred->user->processes) >=
86779 task_rlimit(p, RLIMIT_NPROC)) {
86780 if (p->real_cred->user != INIT_USER &&
86781@@ -1449,6 +1519,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86782 goto bad_fork_free_pid;
86783 }
86784
86785+ /* synchronizes with gr_set_acls()
86786+ we need to call this past the point of no return for fork()
86787+ */
86788+ gr_copy_label(p);
86789+
86790 if (likely(p->pid)) {
86791 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86792
86793@@ -1537,6 +1612,8 @@ bad_fork_cleanup_count:
86794 bad_fork_free:
86795 free_task(p);
86796 fork_out:
86797+ gr_log_forkfail(retval);
86798+
86799 return ERR_PTR(retval);
86800 }
86801
86802@@ -1598,6 +1675,7 @@ long do_fork(unsigned long clone_flags,
86803
86804 p = copy_process(clone_flags, stack_start, stack_size,
86805 child_tidptr, NULL, trace);
86806+ add_latent_entropy();
86807 /*
86808 * Do this prior waking up the new thread - the thread pointer
86809 * might get invalid after that point, if the thread exits quickly.
86810@@ -1612,6 +1690,8 @@ long do_fork(unsigned long clone_flags,
86811 if (clone_flags & CLONE_PARENT_SETTID)
86812 put_user(nr, parent_tidptr);
86813
86814+ gr_handle_brute_check();
86815+
86816 if (clone_flags & CLONE_VFORK) {
86817 p->vfork_done = &vfork;
86818 init_completion(&vfork);
86819@@ -1728,7 +1808,7 @@ void __init proc_caches_init(void)
86820 mm_cachep = kmem_cache_create("mm_struct",
86821 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86822 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86823- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86824+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86825 mmap_init();
86826 nsproxy_cache_init();
86827 }
86828@@ -1768,7 +1848,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86829 return 0;
86830
86831 /* don't need lock here; in the worst case we'll do useless copy */
86832- if (fs->users == 1)
86833+ if (atomic_read(&fs->users) == 1)
86834 return 0;
86835
86836 *new_fsp = copy_fs_struct(fs);
86837@@ -1875,7 +1955,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86838 fs = current->fs;
86839 spin_lock(&fs->lock);
86840 current->fs = new_fs;
86841- if (--fs->users)
86842+ gr_set_chroot_entries(current, &current->fs->root);
86843+ if (atomic_dec_return(&fs->users))
86844 new_fs = NULL;
86845 else
86846 new_fs = fs;
86847diff --git a/kernel/futex.c b/kernel/futex.c
86848index 6801b37..bb6becca 100644
86849--- a/kernel/futex.c
86850+++ b/kernel/futex.c
86851@@ -54,6 +54,7 @@
86852 #include <linux/mount.h>
86853 #include <linux/pagemap.h>
86854 #include <linux/syscalls.h>
86855+#include <linux/ptrace.h>
86856 #include <linux/signal.h>
86857 #include <linux/export.h>
86858 #include <linux/magic.h>
86859@@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86860 struct page *page, *page_head;
86861 int err, ro = 0;
86862
86863+#ifdef CONFIG_PAX_SEGMEXEC
86864+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86865+ return -EFAULT;
86866+#endif
86867+
86868 /*
86869 * The futex address must be "naturally" aligned.
86870 */
86871@@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86872
86873 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86874 {
86875- int ret;
86876+ unsigned long ret;
86877
86878 pagefault_disable();
86879 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86880@@ -2886,6 +2892,7 @@ static void __init futex_detect_cmpxchg(void)
86881 {
86882 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86883 u32 curval;
86884+ mm_segment_t oldfs;
86885
86886 /*
86887 * This will fail and we want it. Some arch implementations do
86888@@ -2897,8 +2904,11 @@ static void __init futex_detect_cmpxchg(void)
86889 * implementation, the non-functional ones will return
86890 * -ENOSYS.
86891 */
86892+ oldfs = get_fs();
86893+ set_fs(USER_DS);
86894 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86895 futex_cmpxchg_enabled = 1;
86896+ set_fs(oldfs);
86897 #endif
86898 }
86899
86900diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86901index f9f44fd..29885e4 100644
86902--- a/kernel/futex_compat.c
86903+++ b/kernel/futex_compat.c
86904@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86905 return 0;
86906 }
86907
86908-static void __user *futex_uaddr(struct robust_list __user *entry,
86909+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86910 compat_long_t futex_offset)
86911 {
86912 compat_uptr_t base = ptr_to_compat(entry);
86913diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86914index f45b75b..bfac6d5 100644
86915--- a/kernel/gcov/base.c
86916+++ b/kernel/gcov/base.c
86917@@ -108,11 +108,6 @@ void gcov_enable_events(void)
86918 }
86919
86920 #ifdef CONFIG_MODULES
86921-static inline int within(void *addr, void *start, unsigned long size)
86922-{
86923- return ((addr >= start) && (addr < start + size));
86924-}
86925-
86926 /* Update list and generate events when modules are unloaded. */
86927 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86928 void *data)
86929@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86930
86931 /* Remove entries located in module from linked list. */
86932 while ((info = gcov_info_next(info))) {
86933- if (within(info, mod->module_core, mod->core_size)) {
86934+ if (within_module_core_rw((unsigned long)info, mod)) {
86935 gcov_info_unlink(prev, info);
86936 if (gcov_events_enabled)
86937 gcov_event(GCOV_REMOVE, info);
86938diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86939index 0909436..6037d22 100644
86940--- a/kernel/hrtimer.c
86941+++ b/kernel/hrtimer.c
86942@@ -1439,7 +1439,7 @@ void hrtimer_peek_ahead_timers(void)
86943 local_irq_restore(flags);
86944 }
86945
86946-static void run_hrtimer_softirq(struct softirq_action *h)
86947+static __latent_entropy void run_hrtimer_softirq(void)
86948 {
86949 hrtimer_peek_ahead_timers();
86950 }
86951diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86952index 55fcce6..0e4cf34 100644
86953--- a/kernel/irq_work.c
86954+++ b/kernel/irq_work.c
86955@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86956 return NOTIFY_OK;
86957 }
86958
86959-static struct notifier_block cpu_notify;
86960+static struct notifier_block cpu_notify = {
86961+ .notifier_call = irq_work_cpu_notify,
86962+ .priority = 0,
86963+};
86964
86965 static __init int irq_work_init_cpu_notifier(void)
86966 {
86967- cpu_notify.notifier_call = irq_work_cpu_notify;
86968- cpu_notify.priority = 0;
86969 register_cpu_notifier(&cpu_notify);
86970 return 0;
86971 }
86972diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86973index 9019f15..9a3c42e 100644
86974--- a/kernel/jump_label.c
86975+++ b/kernel/jump_label.c
86976@@ -14,6 +14,7 @@
86977 #include <linux/err.h>
86978 #include <linux/static_key.h>
86979 #include <linux/jump_label_ratelimit.h>
86980+#include <linux/mm.h>
86981
86982 #ifdef HAVE_JUMP_LABEL
86983
86984@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86985
86986 size = (((unsigned long)stop - (unsigned long)start)
86987 / sizeof(struct jump_entry));
86988+ pax_open_kernel();
86989 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86990+ pax_close_kernel();
86991 }
86992
86993 static void jump_label_update(struct static_key *key, int enable);
86994@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86995 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86996 struct jump_entry *iter;
86997
86998+ pax_open_kernel();
86999 for (iter = iter_start; iter < iter_stop; iter++) {
87000 if (within_module_init(iter->code, mod))
87001 iter->code = 0;
87002 }
87003+ pax_close_kernel();
87004 }
87005
87006 static int
87007diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
87008index 3127ad5..159d880 100644
87009--- a/kernel/kallsyms.c
87010+++ b/kernel/kallsyms.c
87011@@ -11,6 +11,9 @@
87012 * Changed the compression method from stem compression to "table lookup"
87013 * compression (see scripts/kallsyms.c for a more complete description)
87014 */
87015+#ifdef CONFIG_GRKERNSEC_HIDESYM
87016+#define __INCLUDED_BY_HIDESYM 1
87017+#endif
87018 #include <linux/kallsyms.h>
87019 #include <linux/module.h>
87020 #include <linux/init.h>
87021@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
87022
87023 static inline int is_kernel_inittext(unsigned long addr)
87024 {
87025+ if (system_state != SYSTEM_BOOTING)
87026+ return 0;
87027+
87028 if (addr >= (unsigned long)_sinittext
87029 && addr <= (unsigned long)_einittext)
87030 return 1;
87031 return 0;
87032 }
87033
87034+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87035+#ifdef CONFIG_MODULES
87036+static inline int is_module_text(unsigned long addr)
87037+{
87038+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
87039+ return 1;
87040+
87041+ addr = ktla_ktva(addr);
87042+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
87043+}
87044+#else
87045+static inline int is_module_text(unsigned long addr)
87046+{
87047+ return 0;
87048+}
87049+#endif
87050+#endif
87051+
87052 static inline int is_kernel_text(unsigned long addr)
87053 {
87054 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
87055@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
87056
87057 static inline int is_kernel(unsigned long addr)
87058 {
87059+
87060+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87061+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
87062+ return 1;
87063+
87064+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
87065+#else
87066 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
87067+#endif
87068+
87069 return 1;
87070 return in_gate_area_no_mm(addr);
87071 }
87072
87073 static int is_ksym_addr(unsigned long addr)
87074 {
87075+
87076+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87077+ if (is_module_text(addr))
87078+ return 0;
87079+#endif
87080+
87081 if (all_var)
87082 return is_kernel(addr);
87083
87084@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
87085
87086 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
87087 {
87088- iter->name[0] = '\0';
87089 iter->nameoff = get_symbol_offset(new_pos);
87090 iter->pos = new_pos;
87091 }
87092@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
87093 {
87094 struct kallsym_iter *iter = m->private;
87095
87096+#ifdef CONFIG_GRKERNSEC_HIDESYM
87097+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
87098+ return 0;
87099+#endif
87100+
87101 /* Some debugging symbols have no name. Ignore them. */
87102 if (!iter->name[0])
87103 return 0;
87104@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
87105 */
87106 type = iter->exported ? toupper(iter->type) :
87107 tolower(iter->type);
87108+
87109 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
87110 type, iter->name, iter->module_name);
87111 } else
87112@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
87113 struct kallsym_iter *iter;
87114 int ret;
87115
87116- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
87117+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
87118 if (!iter)
87119 return -ENOMEM;
87120 reset_iter(iter, 0);
87121diff --git a/kernel/kcmp.c b/kernel/kcmp.c
87122index e30ac0f..3528cac 100644
87123--- a/kernel/kcmp.c
87124+++ b/kernel/kcmp.c
87125@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
87126 struct task_struct *task1, *task2;
87127 int ret;
87128
87129+#ifdef CONFIG_GRKERNSEC
87130+ return -ENOSYS;
87131+#endif
87132+
87133 rcu_read_lock();
87134
87135 /*
87136diff --git a/kernel/kexec.c b/kernel/kexec.c
87137index 60bafbe..a120f4f 100644
87138--- a/kernel/kexec.c
87139+++ b/kernel/kexec.c
87140@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
87141 unsigned long flags)
87142 {
87143 struct compat_kexec_segment in;
87144- struct kexec_segment out, __user *ksegments;
87145+ struct kexec_segment out;
87146+ struct kexec_segment __user *ksegments;
87147 unsigned long i, result;
87148
87149 /* Don't allow clients that don't understand the native
87150diff --git a/kernel/kmod.c b/kernel/kmod.c
87151index 6b375af..eaff670 100644
87152--- a/kernel/kmod.c
87153+++ b/kernel/kmod.c
87154@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
87155 kfree(info->argv);
87156 }
87157
87158-static int call_modprobe(char *module_name, int wait)
87159+static int call_modprobe(char *module_name, char *module_param, int wait)
87160 {
87161 struct subprocess_info *info;
87162 static char *envp[] = {
87163@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
87164 NULL
87165 };
87166
87167- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
87168+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
87169 if (!argv)
87170 goto out;
87171
87172@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
87173 argv[1] = "-q";
87174 argv[2] = "--";
87175 argv[3] = module_name; /* check free_modprobe_argv() */
87176- argv[4] = NULL;
87177+ argv[4] = module_param;
87178+ argv[5] = NULL;
87179
87180 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87181 NULL, free_modprobe_argv, NULL);
87182@@ -129,9 +130,8 @@ out:
87183 * If module auto-loading support is disabled then this function
87184 * becomes a no-operation.
87185 */
87186-int __request_module(bool wait, const char *fmt, ...)
87187+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87188 {
87189- va_list args;
87190 char module_name[MODULE_NAME_LEN];
87191 unsigned int max_modprobes;
87192 int ret;
87193@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87194 if (!modprobe_path[0])
87195 return 0;
87196
87197- va_start(args, fmt);
87198- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87199- va_end(args);
87200+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87201 if (ret >= MODULE_NAME_LEN)
87202 return -ENAMETOOLONG;
87203
87204@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87205 if (ret)
87206 return ret;
87207
87208+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87209+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87210+ /* hack to workaround consolekit/udisks stupidity */
87211+ read_lock(&tasklist_lock);
87212+ if (!strcmp(current->comm, "mount") &&
87213+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87214+ read_unlock(&tasklist_lock);
87215+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87216+ return -EPERM;
87217+ }
87218+ read_unlock(&tasklist_lock);
87219+ }
87220+#endif
87221+
87222 /* If modprobe needs a service that is in a module, we get a recursive
87223 * loop. Limit the number of running kmod threads to max_threads/2 or
87224 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87225@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87226
87227 trace_module_request(module_name, wait, _RET_IP_);
87228
87229- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87230+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87231
87232 atomic_dec(&kmod_concurrent);
87233 return ret;
87234 }
87235+
87236+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87237+{
87238+ va_list args;
87239+ int ret;
87240+
87241+ va_start(args, fmt);
87242+ ret = ____request_module(wait, module_param, fmt, args);
87243+ va_end(args);
87244+
87245+ return ret;
87246+}
87247+
87248+int __request_module(bool wait, const char *fmt, ...)
87249+{
87250+ va_list args;
87251+ int ret;
87252+
87253+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87254+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87255+ char module_param[MODULE_NAME_LEN];
87256+
87257+ memset(module_param, 0, sizeof(module_param));
87258+
87259+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87260+
87261+ va_start(args, fmt);
87262+ ret = ____request_module(wait, module_param, fmt, args);
87263+ va_end(args);
87264+
87265+ return ret;
87266+ }
87267+#endif
87268+
87269+ va_start(args, fmt);
87270+ ret = ____request_module(wait, NULL, fmt, args);
87271+ va_end(args);
87272+
87273+ return ret;
87274+}
87275+
87276 EXPORT_SYMBOL(__request_module);
87277 #endif /* CONFIG_MODULES */
87278
87279@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87280 */
87281 set_user_nice(current, 0);
87282
87283+#ifdef CONFIG_GRKERNSEC
87284+ /* this is race-free as far as userland is concerned as we copied
87285+ out the path to be used prior to this point and are now operating
87286+ on that copy
87287+ */
87288+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87289+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87290+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87291+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87292+ retval = -EPERM;
87293+ goto fail;
87294+ }
87295+#endif
87296+
87297 retval = -ENOMEM;
87298 new = prepare_kernel_cred(current);
87299 if (!new)
87300@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87301 commit_creds(new);
87302
87303 retval = do_execve(getname_kernel(sub_info->path),
87304- (const char __user *const __user *)sub_info->argv,
87305- (const char __user *const __user *)sub_info->envp);
87306+ (const char __user *const __force_user *)sub_info->argv,
87307+ (const char __user *const __force_user *)sub_info->envp);
87308 if (!retval)
87309 return 0;
87310
87311@@ -260,6 +327,10 @@ static int call_helper(void *data)
87312
87313 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87314 {
87315+#ifdef CONFIG_GRKERNSEC
87316+ kfree(info->path);
87317+ info->path = info->origpath;
87318+#endif
87319 if (info->cleanup)
87320 (*info->cleanup)(info);
87321 kfree(info);
87322@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87323 *
87324 * Thus the __user pointer cast is valid here.
87325 */
87326- sys_wait4(pid, (int __user *)&ret, 0, NULL);
87327+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87328
87329 /*
87330 * If ret is 0, either ____call_usermodehelper failed and the
87331@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87332 goto out;
87333
87334 INIT_WORK(&sub_info->work, __call_usermodehelper);
87335+#ifdef CONFIG_GRKERNSEC
87336+ sub_info->origpath = path;
87337+ sub_info->path = kstrdup(path, gfp_mask);
87338+#else
87339 sub_info->path = path;
87340+#endif
87341 sub_info->argv = argv;
87342 sub_info->envp = envp;
87343
87344@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87345 static int proc_cap_handler(struct ctl_table *table, int write,
87346 void __user *buffer, size_t *lenp, loff_t *ppos)
87347 {
87348- struct ctl_table t;
87349+ ctl_table_no_const t;
87350 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87351 kernel_cap_t new_cap;
87352 int err, i;
87353diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87354index ceeadfc..11c18b6 100644
87355--- a/kernel/kprobes.c
87356+++ b/kernel/kprobes.c
87357@@ -31,6 +31,9 @@
87358 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87359 * <prasanna@in.ibm.com> added function-return probes.
87360 */
87361+#ifdef CONFIG_GRKERNSEC_HIDESYM
87362+#define __INCLUDED_BY_HIDESYM 1
87363+#endif
87364 #include <linux/kprobes.h>
87365 #include <linux/hash.h>
87366 #include <linux/init.h>
87367@@ -135,12 +138,12 @@ enum kprobe_slot_state {
87368
87369 static void *alloc_insn_page(void)
87370 {
87371- return module_alloc(PAGE_SIZE);
87372+ return module_alloc_exec(PAGE_SIZE);
87373 }
87374
87375 static void free_insn_page(void *page)
87376 {
87377- module_free(NULL, page);
87378+ module_free_exec(NULL, page);
87379 }
87380
87381 struct kprobe_insn_cache kprobe_insn_slots = {
87382@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87383 kprobe_type = "k";
87384
87385 if (sym)
87386- seq_printf(pi, "%p %s %s+0x%x %s ",
87387+ seq_printf(pi, "%pK %s %s+0x%x %s ",
87388 p->addr, kprobe_type, sym, offset,
87389 (modname ? modname : " "));
87390 else
87391- seq_printf(pi, "%p %s %p ",
87392+ seq_printf(pi, "%pK %s %pK ",
87393 p->addr, kprobe_type, p->addr);
87394
87395 if (!pp)
87396diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87397index d945a94..0b7f45f 100644
87398--- a/kernel/ksysfs.c
87399+++ b/kernel/ksysfs.c
87400@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87401 {
87402 if (count+1 > UEVENT_HELPER_PATH_LEN)
87403 return -ENOENT;
87404+ if (!capable(CAP_SYS_ADMIN))
87405+ return -EPERM;
87406 memcpy(uevent_helper, buf, count);
87407 uevent_helper[count] = '\0';
87408 if (count && uevent_helper[count-1] == '\n')
87409@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87410 return count;
87411 }
87412
87413-static struct bin_attribute notes_attr = {
87414+static bin_attribute_no_const notes_attr __read_only = {
87415 .attr = {
87416 .name = "notes",
87417 .mode = S_IRUGO,
87418diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87419index eb8a547..321d8e1 100644
87420--- a/kernel/locking/lockdep.c
87421+++ b/kernel/locking/lockdep.c
87422@@ -597,6 +597,10 @@ static int static_obj(void *obj)
87423 end = (unsigned long) &_end,
87424 addr = (unsigned long) obj;
87425
87426+#ifdef CONFIG_PAX_KERNEXEC
87427+ start = ktla_ktva(start);
87428+#endif
87429+
87430 /*
87431 * static variable?
87432 */
87433@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87434 if (!static_obj(lock->key)) {
87435 debug_locks_off();
87436 printk("INFO: trying to register non-static key.\n");
87437+ printk("lock:%pS key:%pS.\n", lock, lock->key);
87438 printk("the code is fine but needs lockdep annotation.\n");
87439 printk("turning off the locking correctness validator.\n");
87440 dump_stack();
87441@@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87442 if (!class)
87443 return 0;
87444 }
87445- atomic_inc((atomic_t *)&class->ops);
87446+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87447 if (very_verbose(class)) {
87448 printk("\nacquire class [%p] %s", class->key, class->name);
87449 if (class->name_version > 1)
87450diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87451index ef43ac4..2720dfa 100644
87452--- a/kernel/locking/lockdep_proc.c
87453+++ b/kernel/locking/lockdep_proc.c
87454@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87455 return 0;
87456 }
87457
87458- seq_printf(m, "%p", class->key);
87459+ seq_printf(m, "%pK", class->key);
87460 #ifdef CONFIG_DEBUG_LOCKDEP
87461 seq_printf(m, " OPS:%8ld", class->ops);
87462 #endif
87463@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87464
87465 list_for_each_entry(entry, &class->locks_after, entry) {
87466 if (entry->distance == 1) {
87467- seq_printf(m, " -> [%p] ", entry->class->key);
87468+ seq_printf(m, " -> [%pK] ", entry->class->key);
87469 print_name(m, entry->class);
87470 seq_puts(m, "\n");
87471 }
87472@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87473 if (!class->key)
87474 continue;
87475
87476- seq_printf(m, "[%p] ", class->key);
87477+ seq_printf(m, "[%pK] ", class->key);
87478 print_name(m, class);
87479 seq_puts(m, "\n");
87480 }
87481@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87482 if (!i)
87483 seq_line(m, '-', 40-namelen, namelen);
87484
87485- snprintf(ip, sizeof(ip), "[<%p>]",
87486+ snprintf(ip, sizeof(ip), "[<%pK>]",
87487 (void *)class->contention_point[i]);
87488 seq_printf(m, "%40s %14lu %29s %pS\n",
87489 name, stats->contention_point[i],
87490@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87491 if (!i)
87492 seq_line(m, '-', 40-namelen, namelen);
87493
87494- snprintf(ip, sizeof(ip), "[<%p>]",
87495+ snprintf(ip, sizeof(ip), "[<%pK>]",
87496 (void *)class->contending_point[i]);
87497 seq_printf(m, "%40s %14lu %29s %pS\n",
87498 name, stats->contending_point[i],
87499diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87500index faf6f5b..dc9070a 100644
87501--- a/kernel/locking/mutex-debug.c
87502+++ b/kernel/locking/mutex-debug.c
87503@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87504 }
87505
87506 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87507- struct thread_info *ti)
87508+ struct task_struct *task)
87509 {
87510 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87511
87512 /* Mark the current thread as blocked on the lock: */
87513- ti->task->blocked_on = waiter;
87514+ task->blocked_on = waiter;
87515 }
87516
87517 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87518- struct thread_info *ti)
87519+ struct task_struct *task)
87520 {
87521 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87522- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87523- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87524- ti->task->blocked_on = NULL;
87525+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
87526+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87527+ task->blocked_on = NULL;
87528
87529 list_del_init(&waiter->list);
87530 waiter->task = NULL;
87531diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87532index 0799fd3..d06ae3b 100644
87533--- a/kernel/locking/mutex-debug.h
87534+++ b/kernel/locking/mutex-debug.h
87535@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87536 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87537 extern void debug_mutex_add_waiter(struct mutex *lock,
87538 struct mutex_waiter *waiter,
87539- struct thread_info *ti);
87540+ struct task_struct *task);
87541 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87542- struct thread_info *ti);
87543+ struct task_struct *task);
87544 extern void debug_mutex_unlock(struct mutex *lock);
87545 extern void debug_mutex_init(struct mutex *lock, const char *name,
87546 struct lock_class_key *key);
87547diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87548index 4dd6e4c..df52693 100644
87549--- a/kernel/locking/mutex.c
87550+++ b/kernel/locking/mutex.c
87551@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
87552 node->locked = 1;
87553 return;
87554 }
87555- ACCESS_ONCE(prev->next) = node;
87556+ ACCESS_ONCE_RW(prev->next) = node;
87557 smp_wmb();
87558 /* Wait until the lock holder passes the lock down */
87559 while (!ACCESS_ONCE(node->locked))
87560@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
87561 while (!(next = ACCESS_ONCE(node->next)))
87562 arch_mutex_cpu_relax();
87563 }
87564- ACCESS_ONCE(next->locked) = 1;
87565+ ACCESS_ONCE_RW(next->locked) = 1;
87566 smp_wmb();
87567 }
87568
87569@@ -520,7 +520,7 @@ slowpath:
87570 goto skip_wait;
87571
87572 debug_mutex_lock_common(lock, &waiter);
87573- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87574+ debug_mutex_add_waiter(lock, &waiter, task);
87575
87576 /* add waiting tasks to the end of the waitqueue (FIFO): */
87577 list_add_tail(&waiter.list, &lock->wait_list);
87578@@ -564,7 +564,7 @@ slowpath:
87579 schedule_preempt_disabled();
87580 spin_lock_mutex(&lock->wait_lock, flags);
87581 }
87582- mutex_remove_waiter(lock, &waiter, current_thread_info());
87583+ mutex_remove_waiter(lock, &waiter, task);
87584 /* set it to 0 if there are no waiters left: */
87585 if (likely(list_empty(&lock->wait_list)))
87586 atomic_set(&lock->count, 0);
87587@@ -601,7 +601,7 @@ skip_wait:
87588 return 0;
87589
87590 err:
87591- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87592+ mutex_remove_waiter(lock, &waiter, task);
87593 spin_unlock_mutex(&lock->wait_lock, flags);
87594 debug_mutex_free_waiter(&waiter);
87595 mutex_release(&lock->dep_map, 1, ip);
87596diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87597index 1d96dd0..994ff19 100644
87598--- a/kernel/locking/rtmutex-tester.c
87599+++ b/kernel/locking/rtmutex-tester.c
87600@@ -22,7 +22,7 @@
87601 #define MAX_RT_TEST_MUTEXES 8
87602
87603 static spinlock_t rttest_lock;
87604-static atomic_t rttest_event;
87605+static atomic_unchecked_t rttest_event;
87606
87607 struct test_thread_data {
87608 int opcode;
87609@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87610
87611 case RTTEST_LOCKCONT:
87612 td->mutexes[td->opdata] = 1;
87613- td->event = atomic_add_return(1, &rttest_event);
87614+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87615 return 0;
87616
87617 case RTTEST_RESET:
87618@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87619 return 0;
87620
87621 case RTTEST_RESETEVENT:
87622- atomic_set(&rttest_event, 0);
87623+ atomic_set_unchecked(&rttest_event, 0);
87624 return 0;
87625
87626 default:
87627@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87628 return ret;
87629
87630 td->mutexes[id] = 1;
87631- td->event = atomic_add_return(1, &rttest_event);
87632+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87633 rt_mutex_lock(&mutexes[id]);
87634- td->event = atomic_add_return(1, &rttest_event);
87635+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87636 td->mutexes[id] = 4;
87637 return 0;
87638
87639@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87640 return ret;
87641
87642 td->mutexes[id] = 1;
87643- td->event = atomic_add_return(1, &rttest_event);
87644+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87645 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87646- td->event = atomic_add_return(1, &rttest_event);
87647+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87648 td->mutexes[id] = ret ? 0 : 4;
87649 return ret ? -EINTR : 0;
87650
87651@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87652 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87653 return ret;
87654
87655- td->event = atomic_add_return(1, &rttest_event);
87656+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87657 rt_mutex_unlock(&mutexes[id]);
87658- td->event = atomic_add_return(1, &rttest_event);
87659+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87660 td->mutexes[id] = 0;
87661 return 0;
87662
87663@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87664 break;
87665
87666 td->mutexes[dat] = 2;
87667- td->event = atomic_add_return(1, &rttest_event);
87668+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87669 break;
87670
87671 default:
87672@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87673 return;
87674
87675 td->mutexes[dat] = 3;
87676- td->event = atomic_add_return(1, &rttest_event);
87677+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87678 break;
87679
87680 case RTTEST_LOCKNOWAIT:
87681@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87682 return;
87683
87684 td->mutexes[dat] = 1;
87685- td->event = atomic_add_return(1, &rttest_event);
87686+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87687 return;
87688
87689 default:
87690diff --git a/kernel/module.c b/kernel/module.c
87691index d24fcf2..2af3fd9 100644
87692--- a/kernel/module.c
87693+++ b/kernel/module.c
87694@@ -61,6 +61,7 @@
87695 #include <linux/pfn.h>
87696 #include <linux/bsearch.h>
87697 #include <linux/fips.h>
87698+#include <linux/grsecurity.h>
87699 #include <uapi/linux/module.h>
87700 #include "module-internal.h"
87701
87702@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87703
87704 /* Bounds of module allocation, for speeding __module_address.
87705 * Protected by module_mutex. */
87706-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87707+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87708+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87709
87710 int register_module_notifier(struct notifier_block * nb)
87711 {
87712@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87713 return true;
87714
87715 list_for_each_entry_rcu(mod, &modules, list) {
87716- struct symsearch arr[] = {
87717+ struct symsearch modarr[] = {
87718 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87719 NOT_GPL_ONLY, false },
87720 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87721@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87722 if (mod->state == MODULE_STATE_UNFORMED)
87723 continue;
87724
87725- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87726+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87727 return true;
87728 }
87729 return false;
87730@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87731 if (!pcpusec->sh_size)
87732 return 0;
87733
87734- if (align > PAGE_SIZE) {
87735+ if (align-1 >= PAGE_SIZE) {
87736 pr_warn("%s: per-cpu alignment %li > %li\n",
87737 mod->name, align, PAGE_SIZE);
87738 align = PAGE_SIZE;
87739@@ -1062,7 +1064,7 @@ struct module_attribute module_uevent =
87740 static ssize_t show_coresize(struct module_attribute *mattr,
87741 struct module_kobject *mk, char *buffer)
87742 {
87743- return sprintf(buffer, "%u\n", mk->mod->core_size);
87744+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87745 }
87746
87747 static struct module_attribute modinfo_coresize =
87748@@ -1071,7 +1073,7 @@ static struct module_attribute modinfo_coresize =
87749 static ssize_t show_initsize(struct module_attribute *mattr,
87750 struct module_kobject *mk, char *buffer)
87751 {
87752- return sprintf(buffer, "%u\n", mk->mod->init_size);
87753+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87754 }
87755
87756 static struct module_attribute modinfo_initsize =
87757@@ -1163,12 +1165,29 @@ static int check_version(Elf_Shdr *sechdrs,
87758 goto bad_version;
87759 }
87760
87761+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87762+ /*
87763+ * avoid potentially printing jibberish on attempted load
87764+ * of a module randomized with a different seed
87765+ */
87766+ pr_warn("no symbol version for %s\n", symname);
87767+#else
87768 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87769+#endif
87770 return 0;
87771
87772 bad_version:
87773+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87774+ /*
87775+ * avoid potentially printing jibberish on attempted load
87776+ * of a module randomized with a different seed
87777+ */
87778+ printk("attempted module disagrees about version of symbol %s\n",
87779+ symname);
87780+#else
87781 printk("%s: disagrees about version of symbol %s\n",
87782 mod->name, symname);
87783+#endif
87784 return 0;
87785 }
87786
87787@@ -1284,7 +1303,7 @@ resolve_symbol_wait(struct module *mod,
87788 */
87789 #ifdef CONFIG_SYSFS
87790
87791-#ifdef CONFIG_KALLSYMS
87792+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87793 static inline bool sect_empty(const Elf_Shdr *sect)
87794 {
87795 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87796@@ -1424,7 +1443,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87797 {
87798 unsigned int notes, loaded, i;
87799 struct module_notes_attrs *notes_attrs;
87800- struct bin_attribute *nattr;
87801+ bin_attribute_no_const *nattr;
87802
87803 /* failed to create section attributes, so can't create notes */
87804 if (!mod->sect_attrs)
87805@@ -1536,7 +1555,7 @@ static void del_usage_links(struct module *mod)
87806 static int module_add_modinfo_attrs(struct module *mod)
87807 {
87808 struct module_attribute *attr;
87809- struct module_attribute *temp_attr;
87810+ module_attribute_no_const *temp_attr;
87811 int error = 0;
87812 int i;
87813
87814@@ -1757,21 +1776,21 @@ static void set_section_ro_nx(void *base,
87815
87816 static void unset_module_core_ro_nx(struct module *mod)
87817 {
87818- set_page_attributes(mod->module_core + mod->core_text_size,
87819- mod->module_core + mod->core_size,
87820+ set_page_attributes(mod->module_core_rw,
87821+ mod->module_core_rw + mod->core_size_rw,
87822 set_memory_x);
87823- set_page_attributes(mod->module_core,
87824- mod->module_core + mod->core_ro_size,
87825+ set_page_attributes(mod->module_core_rx,
87826+ mod->module_core_rx + mod->core_size_rx,
87827 set_memory_rw);
87828 }
87829
87830 static void unset_module_init_ro_nx(struct module *mod)
87831 {
87832- set_page_attributes(mod->module_init + mod->init_text_size,
87833- mod->module_init + mod->init_size,
87834+ set_page_attributes(mod->module_init_rw,
87835+ mod->module_init_rw + mod->init_size_rw,
87836 set_memory_x);
87837- set_page_attributes(mod->module_init,
87838- mod->module_init + mod->init_ro_size,
87839+ set_page_attributes(mod->module_init_rx,
87840+ mod->module_init_rx + mod->init_size_rx,
87841 set_memory_rw);
87842 }
87843
87844@@ -1784,14 +1803,14 @@ void set_all_modules_text_rw(void)
87845 list_for_each_entry_rcu(mod, &modules, list) {
87846 if (mod->state == MODULE_STATE_UNFORMED)
87847 continue;
87848- if ((mod->module_core) && (mod->core_text_size)) {
87849- set_page_attributes(mod->module_core,
87850- mod->module_core + mod->core_text_size,
87851+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87852+ set_page_attributes(mod->module_core_rx,
87853+ mod->module_core_rx + mod->core_size_rx,
87854 set_memory_rw);
87855 }
87856- if ((mod->module_init) && (mod->init_text_size)) {
87857- set_page_attributes(mod->module_init,
87858- mod->module_init + mod->init_text_size,
87859+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87860+ set_page_attributes(mod->module_init_rx,
87861+ mod->module_init_rx + mod->init_size_rx,
87862 set_memory_rw);
87863 }
87864 }
87865@@ -1807,14 +1826,14 @@ void set_all_modules_text_ro(void)
87866 list_for_each_entry_rcu(mod, &modules, list) {
87867 if (mod->state == MODULE_STATE_UNFORMED)
87868 continue;
87869- if ((mod->module_core) && (mod->core_text_size)) {
87870- set_page_attributes(mod->module_core,
87871- mod->module_core + mod->core_text_size,
87872+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87873+ set_page_attributes(mod->module_core_rx,
87874+ mod->module_core_rx + mod->core_size_rx,
87875 set_memory_ro);
87876 }
87877- if ((mod->module_init) && (mod->init_text_size)) {
87878- set_page_attributes(mod->module_init,
87879- mod->module_init + mod->init_text_size,
87880+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87881+ set_page_attributes(mod->module_init_rx,
87882+ mod->module_init_rx + mod->init_size_rx,
87883 set_memory_ro);
87884 }
87885 }
87886@@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
87887
87888 /* This may be NULL, but that's OK */
87889 unset_module_init_ro_nx(mod);
87890- module_free(mod, mod->module_init);
87891+ module_free(mod, mod->module_init_rw);
87892+ module_free_exec(mod, mod->module_init_rx);
87893 kfree(mod->args);
87894 percpu_modfree(mod);
87895
87896 /* Free lock-classes: */
87897- lockdep_free_key_range(mod->module_core, mod->core_size);
87898+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87899+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87900
87901 /* Finally, free the core (containing the module structure) */
87902 unset_module_core_ro_nx(mod);
87903- module_free(mod, mod->module_core);
87904+ module_free_exec(mod, mod->module_core_rx);
87905+ module_free(mod, mod->module_core_rw);
87906
87907 #ifdef CONFIG_MPU
87908 update_protections(current->mm);
87909@@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87910 int ret = 0;
87911 const struct kernel_symbol *ksym;
87912
87913+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87914+ int is_fs_load = 0;
87915+ int register_filesystem_found = 0;
87916+ char *p;
87917+
87918+ p = strstr(mod->args, "grsec_modharden_fs");
87919+ if (p) {
87920+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87921+ /* copy \0 as well */
87922+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87923+ is_fs_load = 1;
87924+ }
87925+#endif
87926+
87927 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87928 const char *name = info->strtab + sym[i].st_name;
87929
87930+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87931+ /* it's a real shame this will never get ripped and copied
87932+ upstream! ;(
87933+ */
87934+ if (is_fs_load && !strcmp(name, "register_filesystem"))
87935+ register_filesystem_found = 1;
87936+#endif
87937+
87938 switch (sym[i].st_shndx) {
87939 case SHN_COMMON:
87940 /* We compiled with -fno-common. These are not
87941@@ -1966,7 +2010,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87942 ksym = resolve_symbol_wait(mod, info, name);
87943 /* Ok if resolved. */
87944 if (ksym && !IS_ERR(ksym)) {
87945+ pax_open_kernel();
87946 sym[i].st_value = ksym->value;
87947+ pax_close_kernel();
87948 break;
87949 }
87950
87951@@ -1985,11 +2031,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87952 secbase = (unsigned long)mod_percpu(mod);
87953 else
87954 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87955+ pax_open_kernel();
87956 sym[i].st_value += secbase;
87957+ pax_close_kernel();
87958 break;
87959 }
87960 }
87961
87962+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87963+ if (is_fs_load && !register_filesystem_found) {
87964+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87965+ ret = -EPERM;
87966+ }
87967+#endif
87968+
87969 return ret;
87970 }
87971
87972@@ -2073,22 +2128,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87973 || s->sh_entsize != ~0UL
87974 || strstarts(sname, ".init"))
87975 continue;
87976- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87977+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87978+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87979+ else
87980+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87981 pr_debug("\t%s\n", sname);
87982 }
87983- switch (m) {
87984- case 0: /* executable */
87985- mod->core_size = debug_align(mod->core_size);
87986- mod->core_text_size = mod->core_size;
87987- break;
87988- case 1: /* RO: text and ro-data */
87989- mod->core_size = debug_align(mod->core_size);
87990- mod->core_ro_size = mod->core_size;
87991- break;
87992- case 3: /* whole core */
87993- mod->core_size = debug_align(mod->core_size);
87994- break;
87995- }
87996 }
87997
87998 pr_debug("Init section allocation order:\n");
87999@@ -2102,23 +2147,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
88000 || s->sh_entsize != ~0UL
88001 || !strstarts(sname, ".init"))
88002 continue;
88003- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
88004- | INIT_OFFSET_MASK);
88005+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88006+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
88007+ else
88008+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
88009+ s->sh_entsize |= INIT_OFFSET_MASK;
88010 pr_debug("\t%s\n", sname);
88011 }
88012- switch (m) {
88013- case 0: /* executable */
88014- mod->init_size = debug_align(mod->init_size);
88015- mod->init_text_size = mod->init_size;
88016- break;
88017- case 1: /* RO: text and ro-data */
88018- mod->init_size = debug_align(mod->init_size);
88019- mod->init_ro_size = mod->init_size;
88020- break;
88021- case 3: /* whole init */
88022- mod->init_size = debug_align(mod->init_size);
88023- break;
88024- }
88025 }
88026 }
88027
88028@@ -2291,7 +2326,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88029
88030 /* Put symbol section at end of init part of module. */
88031 symsect->sh_flags |= SHF_ALLOC;
88032- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
88033+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
88034 info->index.sym) | INIT_OFFSET_MASK;
88035 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
88036
88037@@ -2308,13 +2343,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88038 }
88039
88040 /* Append room for core symbols at end of core part. */
88041- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
88042- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
88043- mod->core_size += strtab_size;
88044+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
88045+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
88046+ mod->core_size_rx += strtab_size;
88047
88048 /* Put string table section at end of init part of module. */
88049 strsect->sh_flags |= SHF_ALLOC;
88050- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
88051+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
88052 info->index.str) | INIT_OFFSET_MASK;
88053 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
88054 }
88055@@ -2332,12 +2367,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88056 /* Make sure we get permanent strtab: don't use info->strtab. */
88057 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
88058
88059+ pax_open_kernel();
88060+
88061 /* Set types up while we still have access to sections. */
88062 for (i = 0; i < mod->num_symtab; i++)
88063 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
88064
88065- mod->core_symtab = dst = mod->module_core + info->symoffs;
88066- mod->core_strtab = s = mod->module_core + info->stroffs;
88067+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
88068+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
88069 src = mod->symtab;
88070 for (ndst = i = 0; i < mod->num_symtab; i++) {
88071 if (i == 0 ||
88072@@ -2349,6 +2386,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88073 }
88074 }
88075 mod->core_num_syms = ndst;
88076+
88077+ pax_close_kernel();
88078 }
88079 #else
88080 static inline void layout_symtab(struct module *mod, struct load_info *info)
88081@@ -2382,17 +2421,33 @@ void * __weak module_alloc(unsigned long size)
88082 return vmalloc_exec(size);
88083 }
88084
88085-static void *module_alloc_update_bounds(unsigned long size)
88086+static void *module_alloc_update_bounds_rw(unsigned long size)
88087 {
88088 void *ret = module_alloc(size);
88089
88090 if (ret) {
88091 mutex_lock(&module_mutex);
88092 /* Update module bounds. */
88093- if ((unsigned long)ret < module_addr_min)
88094- module_addr_min = (unsigned long)ret;
88095- if ((unsigned long)ret + size > module_addr_max)
88096- module_addr_max = (unsigned long)ret + size;
88097+ if ((unsigned long)ret < module_addr_min_rw)
88098+ module_addr_min_rw = (unsigned long)ret;
88099+ if ((unsigned long)ret + size > module_addr_max_rw)
88100+ module_addr_max_rw = (unsigned long)ret + size;
88101+ mutex_unlock(&module_mutex);
88102+ }
88103+ return ret;
88104+}
88105+
88106+static void *module_alloc_update_bounds_rx(unsigned long size)
88107+{
88108+ void *ret = module_alloc_exec(size);
88109+
88110+ if (ret) {
88111+ mutex_lock(&module_mutex);
88112+ /* Update module bounds. */
88113+ if ((unsigned long)ret < module_addr_min_rx)
88114+ module_addr_min_rx = (unsigned long)ret;
88115+ if ((unsigned long)ret + size > module_addr_max_rx)
88116+ module_addr_max_rx = (unsigned long)ret + size;
88117 mutex_unlock(&module_mutex);
88118 }
88119 return ret;
88120@@ -2649,7 +2704,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88121 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
88122
88123 if (info->index.sym == 0) {
88124+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88125+ /*
88126+ * avoid potentially printing jibberish on attempted load
88127+ * of a module randomized with a different seed
88128+ */
88129+ pr_warn("module has no symbols (stripped?)\n");
88130+#else
88131 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
88132+#endif
88133 return ERR_PTR(-ENOEXEC);
88134 }
88135
88136@@ -2665,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88137 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88138 {
88139 const char *modmagic = get_modinfo(info, "vermagic");
88140+ const char *license = get_modinfo(info, "license");
88141 int err;
88142
88143+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
88144+ if (!license || !license_is_gpl_compatible(license))
88145+ return -ENOEXEC;
88146+#endif
88147+
88148 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
88149 modmagic = NULL;
88150
88151@@ -2691,7 +2760,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88152 }
88153
88154 /* Set up license info based on the info section */
88155- set_license(mod, get_modinfo(info, "license"));
88156+ set_license(mod, license);
88157
88158 return 0;
88159 }
88160@@ -2785,7 +2854,7 @@ static int move_module(struct module *mod, struct load_info *info)
88161 void *ptr;
88162
88163 /* Do the allocs. */
88164- ptr = module_alloc_update_bounds(mod->core_size);
88165+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
88166 /*
88167 * The pointer to this block is stored in the module structure
88168 * which is inside the block. Just mark it as not being a
88169@@ -2795,11 +2864,11 @@ static int move_module(struct module *mod, struct load_info *info)
88170 if (!ptr)
88171 return -ENOMEM;
88172
88173- memset(ptr, 0, mod->core_size);
88174- mod->module_core = ptr;
88175+ memset(ptr, 0, mod->core_size_rw);
88176+ mod->module_core_rw = ptr;
88177
88178- if (mod->init_size) {
88179- ptr = module_alloc_update_bounds(mod->init_size);
88180+ if (mod->init_size_rw) {
88181+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88182 /*
88183 * The pointer to this block is stored in the module structure
88184 * which is inside the block. This block doesn't need to be
88185@@ -2808,13 +2877,45 @@ static int move_module(struct module *mod, struct load_info *info)
88186 */
88187 kmemleak_ignore(ptr);
88188 if (!ptr) {
88189- module_free(mod, mod->module_core);
88190+ module_free(mod, mod->module_core_rw);
88191 return -ENOMEM;
88192 }
88193- memset(ptr, 0, mod->init_size);
88194- mod->module_init = ptr;
88195+ memset(ptr, 0, mod->init_size_rw);
88196+ mod->module_init_rw = ptr;
88197 } else
88198- mod->module_init = NULL;
88199+ mod->module_init_rw = NULL;
88200+
88201+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88202+ kmemleak_not_leak(ptr);
88203+ if (!ptr) {
88204+ if (mod->module_init_rw)
88205+ module_free(mod, mod->module_init_rw);
88206+ module_free(mod, mod->module_core_rw);
88207+ return -ENOMEM;
88208+ }
88209+
88210+ pax_open_kernel();
88211+ memset(ptr, 0, mod->core_size_rx);
88212+ pax_close_kernel();
88213+ mod->module_core_rx = ptr;
88214+
88215+ if (mod->init_size_rx) {
88216+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88217+ kmemleak_ignore(ptr);
88218+ if (!ptr && mod->init_size_rx) {
88219+ module_free_exec(mod, mod->module_core_rx);
88220+ if (mod->module_init_rw)
88221+ module_free(mod, mod->module_init_rw);
88222+ module_free(mod, mod->module_core_rw);
88223+ return -ENOMEM;
88224+ }
88225+
88226+ pax_open_kernel();
88227+ memset(ptr, 0, mod->init_size_rx);
88228+ pax_close_kernel();
88229+ mod->module_init_rx = ptr;
88230+ } else
88231+ mod->module_init_rx = NULL;
88232
88233 /* Transfer each section which specifies SHF_ALLOC */
88234 pr_debug("final section addresses:\n");
88235@@ -2825,16 +2926,45 @@ static int move_module(struct module *mod, struct load_info *info)
88236 if (!(shdr->sh_flags & SHF_ALLOC))
88237 continue;
88238
88239- if (shdr->sh_entsize & INIT_OFFSET_MASK)
88240- dest = mod->module_init
88241- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88242- else
88243- dest = mod->module_core + shdr->sh_entsize;
88244+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88245+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88246+ dest = mod->module_init_rw
88247+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88248+ else
88249+ dest = mod->module_init_rx
88250+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88251+ } else {
88252+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88253+ dest = mod->module_core_rw + shdr->sh_entsize;
88254+ else
88255+ dest = mod->module_core_rx + shdr->sh_entsize;
88256+ }
88257+
88258+ if (shdr->sh_type != SHT_NOBITS) {
88259+
88260+#ifdef CONFIG_PAX_KERNEXEC
88261+#ifdef CONFIG_X86_64
88262+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88263+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88264+#endif
88265+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88266+ pax_open_kernel();
88267+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88268+ pax_close_kernel();
88269+ } else
88270+#endif
88271
88272- if (shdr->sh_type != SHT_NOBITS)
88273 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88274+ }
88275 /* Update sh_addr to point to copy in image. */
88276- shdr->sh_addr = (unsigned long)dest;
88277+
88278+#ifdef CONFIG_PAX_KERNEXEC
88279+ if (shdr->sh_flags & SHF_EXECINSTR)
88280+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
88281+ else
88282+#endif
88283+
88284+ shdr->sh_addr = (unsigned long)dest;
88285 pr_debug("\t0x%lx %s\n",
88286 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88287 }
88288@@ -2891,12 +3021,12 @@ static void flush_module_icache(const struct module *mod)
88289 * Do it before processing of module parameters, so the module
88290 * can provide parameter accessor functions of its own.
88291 */
88292- if (mod->module_init)
88293- flush_icache_range((unsigned long)mod->module_init,
88294- (unsigned long)mod->module_init
88295- + mod->init_size);
88296- flush_icache_range((unsigned long)mod->module_core,
88297- (unsigned long)mod->module_core + mod->core_size);
88298+ if (mod->module_init_rx)
88299+ flush_icache_range((unsigned long)mod->module_init_rx,
88300+ (unsigned long)mod->module_init_rx
88301+ + mod->init_size_rx);
88302+ flush_icache_range((unsigned long)mod->module_core_rx,
88303+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
88304
88305 set_fs(old_fs);
88306 }
88307@@ -2953,8 +3083,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88308 static void module_deallocate(struct module *mod, struct load_info *info)
88309 {
88310 percpu_modfree(mod);
88311- module_free(mod, mod->module_init);
88312- module_free(mod, mod->module_core);
88313+ module_free_exec(mod, mod->module_init_rx);
88314+ module_free_exec(mod, mod->module_core_rx);
88315+ module_free(mod, mod->module_init_rw);
88316+ module_free(mod, mod->module_core_rw);
88317 }
88318
88319 int __weak module_finalize(const Elf_Ehdr *hdr,
88320@@ -2967,7 +3099,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88321 static int post_relocation(struct module *mod, const struct load_info *info)
88322 {
88323 /* Sort exception table now relocations are done. */
88324+ pax_open_kernel();
88325 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88326+ pax_close_kernel();
88327
88328 /* Copy relocated percpu area over. */
88329 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88330@@ -3021,16 +3155,16 @@ static int do_init_module(struct module *mod)
88331 MODULE_STATE_COMING, mod);
88332
88333 /* Set RO and NX regions for core */
88334- set_section_ro_nx(mod->module_core,
88335- mod->core_text_size,
88336- mod->core_ro_size,
88337- mod->core_size);
88338+ set_section_ro_nx(mod->module_core_rx,
88339+ mod->core_size_rx,
88340+ mod->core_size_rx,
88341+ mod->core_size_rx);
88342
88343 /* Set RO and NX regions for init */
88344- set_section_ro_nx(mod->module_init,
88345- mod->init_text_size,
88346- mod->init_ro_size,
88347- mod->init_size);
88348+ set_section_ro_nx(mod->module_init_rx,
88349+ mod->init_size_rx,
88350+ mod->init_size_rx,
88351+ mod->init_size_rx);
88352
88353 do_mod_ctors(mod);
88354 /* Start the module */
88355@@ -3091,11 +3225,12 @@ static int do_init_module(struct module *mod)
88356 mod->strtab = mod->core_strtab;
88357 #endif
88358 unset_module_init_ro_nx(mod);
88359- module_free(mod, mod->module_init);
88360- mod->module_init = NULL;
88361- mod->init_size = 0;
88362- mod->init_ro_size = 0;
88363- mod->init_text_size = 0;
88364+ module_free(mod, mod->module_init_rw);
88365+ module_free_exec(mod, mod->module_init_rx);
88366+ mod->module_init_rw = NULL;
88367+ mod->module_init_rx = NULL;
88368+ mod->init_size_rw = 0;
88369+ mod->init_size_rx = 0;
88370 mutex_unlock(&module_mutex);
88371 wake_up_all(&module_wq);
88372
88373@@ -3238,9 +3373,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88374 if (err)
88375 goto free_unload;
88376
88377+ /* Now copy in args */
88378+ mod->args = strndup_user(uargs, ~0UL >> 1);
88379+ if (IS_ERR(mod->args)) {
88380+ err = PTR_ERR(mod->args);
88381+ goto free_unload;
88382+ }
88383+
88384 /* Set up MODINFO_ATTR fields */
88385 setup_modinfo(mod, info);
88386
88387+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88388+ {
88389+ char *p, *p2;
88390+
88391+ if (strstr(mod->args, "grsec_modharden_netdev")) {
88392+ 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);
88393+ err = -EPERM;
88394+ goto free_modinfo;
88395+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88396+ p += sizeof("grsec_modharden_normal") - 1;
88397+ p2 = strstr(p, "_");
88398+ if (p2) {
88399+ *p2 = '\0';
88400+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88401+ *p2 = '_';
88402+ }
88403+ err = -EPERM;
88404+ goto free_modinfo;
88405+ }
88406+ }
88407+#endif
88408+
88409 /* Fix up syms, so that st_value is a pointer to location. */
88410 err = simplify_symbols(mod, info);
88411 if (err < 0)
88412@@ -3256,13 +3420,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88413
88414 flush_module_icache(mod);
88415
88416- /* Now copy in args */
88417- mod->args = strndup_user(uargs, ~0UL >> 1);
88418- if (IS_ERR(mod->args)) {
88419- err = PTR_ERR(mod->args);
88420- goto free_arch_cleanup;
88421- }
88422-
88423 dynamic_debug_setup(info->debug, info->num_debug);
88424
88425 /* Finally it's fully formed, ready to start executing. */
88426@@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88427 ddebug_cleanup:
88428 dynamic_debug_remove(info->debug);
88429 synchronize_sched();
88430- kfree(mod->args);
88431- free_arch_cleanup:
88432 module_arch_cleanup(mod);
88433 free_modinfo:
88434 free_modinfo(mod);
88435+ kfree(mod->args);
88436 free_unload:
88437 module_unload_free(mod);
88438 unlink_mod:
88439@@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
88440 unsigned long nextval;
88441
88442 /* At worse, next value is at end of module */
88443- if (within_module_init(addr, mod))
88444- nextval = (unsigned long)mod->module_init+mod->init_text_size;
88445+ if (within_module_init_rx(addr, mod))
88446+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88447+ else if (within_module_init_rw(addr, mod))
88448+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88449+ else if (within_module_core_rx(addr, mod))
88450+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88451+ else if (within_module_core_rw(addr, mod))
88452+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88453 else
88454- nextval = (unsigned long)mod->module_core+mod->core_text_size;
88455+ return NULL;
88456
88457 /* Scan for closest preceding symbol, and next symbol. (ELF
88458 starts real symbols at 1). */
88459@@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
88460 return 0;
88461
88462 seq_printf(m, "%s %u",
88463- mod->name, mod->init_size + mod->core_size);
88464+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88465 print_unload_info(m, mod);
88466
88467 /* Informative for users. */
88468@@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
88469 mod->state == MODULE_STATE_COMING ? "Loading":
88470 "Live");
88471 /* Used by oprofile and other similar tools. */
88472- seq_printf(m, " 0x%pK", mod->module_core);
88473+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88474
88475 /* Taints info */
88476 if (mod->taints)
88477@@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
88478
88479 static int __init proc_modules_init(void)
88480 {
88481+#ifndef CONFIG_GRKERNSEC_HIDESYM
88482+#ifdef CONFIG_GRKERNSEC_PROC_USER
88483+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88484+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88485+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88486+#else
88487 proc_create("modules", 0, NULL, &proc_modules_operations);
88488+#endif
88489+#else
88490+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88491+#endif
88492 return 0;
88493 }
88494 module_init(proc_modules_init);
88495@@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
88496 {
88497 struct module *mod;
88498
88499- if (addr < module_addr_min || addr > module_addr_max)
88500+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88501+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
88502 return NULL;
88503
88504 list_for_each_entry_rcu(mod, &modules, list) {
88505 if (mod->state == MODULE_STATE_UNFORMED)
88506 continue;
88507- if (within_module_core(addr, mod)
88508- || within_module_init(addr, mod))
88509+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
88510 return mod;
88511 }
88512 return NULL;
88513@@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
88514 */
88515 struct module *__module_text_address(unsigned long addr)
88516 {
88517- struct module *mod = __module_address(addr);
88518+ struct module *mod;
88519+
88520+#ifdef CONFIG_X86_32
88521+ addr = ktla_ktva(addr);
88522+#endif
88523+
88524+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88525+ return NULL;
88526+
88527+ mod = __module_address(addr);
88528+
88529 if (mod) {
88530 /* Make sure it's within the text section. */
88531- if (!within(addr, mod->module_init, mod->init_text_size)
88532- && !within(addr, mod->module_core, mod->core_text_size))
88533+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88534 mod = NULL;
88535 }
88536 return mod;
88537diff --git a/kernel/notifier.c b/kernel/notifier.c
88538index 2d5cc4c..d9ea600 100644
88539--- a/kernel/notifier.c
88540+++ b/kernel/notifier.c
88541@@ -5,6 +5,7 @@
88542 #include <linux/rcupdate.h>
88543 #include <linux/vmalloc.h>
88544 #include <linux/reboot.h>
88545+#include <linux/mm.h>
88546
88547 /*
88548 * Notifier list for kernel code which wants to be called
88549@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88550 while ((*nl) != NULL) {
88551 if (n->priority > (*nl)->priority)
88552 break;
88553- nl = &((*nl)->next);
88554+ nl = (struct notifier_block **)&((*nl)->next);
88555 }
88556- n->next = *nl;
88557+ pax_open_kernel();
88558+ *(const void **)&n->next = *nl;
88559 rcu_assign_pointer(*nl, n);
88560+ pax_close_kernel();
88561 return 0;
88562 }
88563
88564@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88565 return 0;
88566 if (n->priority > (*nl)->priority)
88567 break;
88568- nl = &((*nl)->next);
88569+ nl = (struct notifier_block **)&((*nl)->next);
88570 }
88571- n->next = *nl;
88572+ pax_open_kernel();
88573+ *(const void **)&n->next = *nl;
88574 rcu_assign_pointer(*nl, n);
88575+ pax_close_kernel();
88576 return 0;
88577 }
88578
88579@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88580 {
88581 while ((*nl) != NULL) {
88582 if ((*nl) == n) {
88583+ pax_open_kernel();
88584 rcu_assign_pointer(*nl, n->next);
88585+ pax_close_kernel();
88586 return 0;
88587 }
88588- nl = &((*nl)->next);
88589+ nl = (struct notifier_block **)&((*nl)->next);
88590 }
88591 return -ENOENT;
88592 }
88593diff --git a/kernel/padata.c b/kernel/padata.c
88594index 161402f..598814c 100644
88595--- a/kernel/padata.c
88596+++ b/kernel/padata.c
88597@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88598 * seq_nr mod. number of cpus in use.
88599 */
88600
88601- seq_nr = atomic_inc_return(&pd->seq_nr);
88602+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88603 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88604
88605 return padata_index_to_cpu(pd, cpu_index);
88606@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88607 padata_init_pqueues(pd);
88608 padata_init_squeues(pd);
88609 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88610- atomic_set(&pd->seq_nr, -1);
88611+ atomic_set_unchecked(&pd->seq_nr, -1);
88612 atomic_set(&pd->reorder_objects, 0);
88613 atomic_set(&pd->refcnt, 0);
88614 pd->pinst = pinst;
88615diff --git a/kernel/panic.c b/kernel/panic.c
88616index 6d63003..486a109 100644
88617--- a/kernel/panic.c
88618+++ b/kernel/panic.c
88619@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88620 /*
88621 * Stop ourself in panic -- architecture code may override this
88622 */
88623-void __weak panic_smp_self_stop(void)
88624+void __weak __noreturn panic_smp_self_stop(void)
88625 {
88626 while (1)
88627 cpu_relax();
88628@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88629 disable_trace_on_warning();
88630
88631 pr_warn("------------[ cut here ]------------\n");
88632- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88633+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88634 raw_smp_processor_id(), current->pid, file, line, caller);
88635
88636 if (args)
88637@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88638 */
88639 void __stack_chk_fail(void)
88640 {
88641- panic("stack-protector: Kernel stack is corrupted in: %p\n",
88642+ dump_stack();
88643+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88644 __builtin_return_address(0));
88645 }
88646 EXPORT_SYMBOL(__stack_chk_fail);
88647diff --git a/kernel/pid.c b/kernel/pid.c
88648index 9b9a266..c20ef80 100644
88649--- a/kernel/pid.c
88650+++ b/kernel/pid.c
88651@@ -33,6 +33,7 @@
88652 #include <linux/rculist.h>
88653 #include <linux/bootmem.h>
88654 #include <linux/hash.h>
88655+#include <linux/security.h>
88656 #include <linux/pid_namespace.h>
88657 #include <linux/init_task.h>
88658 #include <linux/syscalls.h>
88659@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88660
88661 int pid_max = PID_MAX_DEFAULT;
88662
88663-#define RESERVED_PIDS 300
88664+#define RESERVED_PIDS 500
88665
88666 int pid_max_min = RESERVED_PIDS + 1;
88667 int pid_max_max = PID_MAX_LIMIT;
88668@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88669 */
88670 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88671 {
88672+ struct task_struct *task;
88673+
88674 rcu_lockdep_assert(rcu_read_lock_held(),
88675 "find_task_by_pid_ns() needs rcu_read_lock()"
88676 " protection");
88677- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88678+
88679+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88680+
88681+ if (gr_pid_is_chrooted(task))
88682+ return NULL;
88683+
88684+ return task;
88685 }
88686
88687 struct task_struct *find_task_by_vpid(pid_t vnr)
88688@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88689 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88690 }
88691
88692+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88693+{
88694+ rcu_lockdep_assert(rcu_read_lock_held(),
88695+ "find_task_by_pid_ns() needs rcu_read_lock()"
88696+ " protection");
88697+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88698+}
88699+
88700 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88701 {
88702 struct pid *pid;
88703diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88704index db95d8e..a0ca23f 100644
88705--- a/kernel/pid_namespace.c
88706+++ b/kernel/pid_namespace.c
88707@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88708 void __user *buffer, size_t *lenp, loff_t *ppos)
88709 {
88710 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88711- struct ctl_table tmp = *table;
88712+ ctl_table_no_const tmp = *table;
88713
88714 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88715 return -EPERM;
88716diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88717index 3b89464..5e38379 100644
88718--- a/kernel/posix-cpu-timers.c
88719+++ b/kernel/posix-cpu-timers.c
88720@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88721
88722 static __init int init_posix_cpu_timers(void)
88723 {
88724- struct k_clock process = {
88725+ static struct k_clock process = {
88726 .clock_getres = process_cpu_clock_getres,
88727 .clock_get = process_cpu_clock_get,
88728 .timer_create = process_cpu_timer_create,
88729 .nsleep = process_cpu_nsleep,
88730 .nsleep_restart = process_cpu_nsleep_restart,
88731 };
88732- struct k_clock thread = {
88733+ static struct k_clock thread = {
88734 .clock_getres = thread_cpu_clock_getres,
88735 .clock_get = thread_cpu_clock_get,
88736 .timer_create = thread_cpu_timer_create,
88737diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88738index 424c2d4..679242f 100644
88739--- a/kernel/posix-timers.c
88740+++ b/kernel/posix-timers.c
88741@@ -43,6 +43,7 @@
88742 #include <linux/hash.h>
88743 #include <linux/posix-clock.h>
88744 #include <linux/posix-timers.h>
88745+#include <linux/grsecurity.h>
88746 #include <linux/syscalls.h>
88747 #include <linux/wait.h>
88748 #include <linux/workqueue.h>
88749@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88750 * which we beg off on and pass to do_sys_settimeofday().
88751 */
88752
88753-static struct k_clock posix_clocks[MAX_CLOCKS];
88754+static struct k_clock *posix_clocks[MAX_CLOCKS];
88755
88756 /*
88757 * These ones are defined below.
88758@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88759 */
88760 static __init int init_posix_timers(void)
88761 {
88762- struct k_clock clock_realtime = {
88763+ static struct k_clock clock_realtime = {
88764 .clock_getres = hrtimer_get_res,
88765 .clock_get = posix_clock_realtime_get,
88766 .clock_set = posix_clock_realtime_set,
88767@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88768 .timer_get = common_timer_get,
88769 .timer_del = common_timer_del,
88770 };
88771- struct k_clock clock_monotonic = {
88772+ static struct k_clock clock_monotonic = {
88773 .clock_getres = hrtimer_get_res,
88774 .clock_get = posix_ktime_get_ts,
88775 .nsleep = common_nsleep,
88776@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88777 .timer_get = common_timer_get,
88778 .timer_del = common_timer_del,
88779 };
88780- struct k_clock clock_monotonic_raw = {
88781+ static struct k_clock clock_monotonic_raw = {
88782 .clock_getres = hrtimer_get_res,
88783 .clock_get = posix_get_monotonic_raw,
88784 };
88785- struct k_clock clock_realtime_coarse = {
88786+ static struct k_clock clock_realtime_coarse = {
88787 .clock_getres = posix_get_coarse_res,
88788 .clock_get = posix_get_realtime_coarse,
88789 };
88790- struct k_clock clock_monotonic_coarse = {
88791+ static struct k_clock clock_monotonic_coarse = {
88792 .clock_getres = posix_get_coarse_res,
88793 .clock_get = posix_get_monotonic_coarse,
88794 };
88795- struct k_clock clock_tai = {
88796+ static struct k_clock clock_tai = {
88797 .clock_getres = hrtimer_get_res,
88798 .clock_get = posix_get_tai,
88799 .nsleep = common_nsleep,
88800@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88801 .timer_get = common_timer_get,
88802 .timer_del = common_timer_del,
88803 };
88804- struct k_clock clock_boottime = {
88805+ static struct k_clock clock_boottime = {
88806 .clock_getres = hrtimer_get_res,
88807 .clock_get = posix_get_boottime,
88808 .nsleep = common_nsleep,
88809@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88810 return;
88811 }
88812
88813- posix_clocks[clock_id] = *new_clock;
88814+ posix_clocks[clock_id] = new_clock;
88815 }
88816 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88817
88818@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88819 return (id & CLOCKFD_MASK) == CLOCKFD ?
88820 &clock_posix_dynamic : &clock_posix_cpu;
88821
88822- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88823+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88824 return NULL;
88825- return &posix_clocks[id];
88826+ return posix_clocks[id];
88827 }
88828
88829 static int common_timer_create(struct k_itimer *new_timer)
88830@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88831 struct k_clock *kc = clockid_to_kclock(which_clock);
88832 struct k_itimer *new_timer;
88833 int error, new_timer_id;
88834- sigevent_t event;
88835+ sigevent_t event = { };
88836 int it_id_set = IT_ID_NOT_SET;
88837
88838 if (!kc)
88839@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88840 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88841 return -EFAULT;
88842
88843+ /* only the CLOCK_REALTIME clock can be set, all other clocks
88844+ have their clock_set fptr set to a nosettime dummy function
88845+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88846+ call common_clock_set, which calls do_sys_settimeofday, which
88847+ we hook
88848+ */
88849+
88850 return kc->clock_set(which_clock, &new_tp);
88851 }
88852
88853diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88854index 2fac9cc..56fef29 100644
88855--- a/kernel/power/Kconfig
88856+++ b/kernel/power/Kconfig
88857@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88858 config HIBERNATION
88859 bool "Hibernation (aka 'suspend to disk')"
88860 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88861+ depends on !GRKERNSEC_KMEM
88862+ depends on !PAX_MEMORY_SANITIZE
88863 select HIBERNATE_CALLBACKS
88864 select LZO_COMPRESS
88865 select LZO_DECOMPRESS
88866diff --git a/kernel/power/process.c b/kernel/power/process.c
88867index 06ec886..9dba35e 100644
88868--- a/kernel/power/process.c
88869+++ b/kernel/power/process.c
88870@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88871 unsigned int elapsed_msecs;
88872 bool wakeup = false;
88873 int sleep_usecs = USEC_PER_MSEC;
88874+ bool timedout = false;
88875
88876 do_gettimeofday(&start);
88877
88878@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88879
88880 while (true) {
88881 todo = 0;
88882+ if (time_after(jiffies, end_time))
88883+ timedout = true;
88884 read_lock(&tasklist_lock);
88885 do_each_thread(g, p) {
88886 if (p == current || !freeze_task(p))
88887 continue;
88888
88889- if (!freezer_should_skip(p))
88890+ if (!freezer_should_skip(p)) {
88891 todo++;
88892+ if (timedout) {
88893+ printk(KERN_ERR "Task refusing to freeze:\n");
88894+ sched_show_task(p);
88895+ }
88896+ }
88897 } while_each_thread(g, p);
88898 read_unlock(&tasklist_lock);
88899
88900@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88901 todo += wq_busy;
88902 }
88903
88904- if (!todo || time_after(jiffies, end_time))
88905+ if (!todo || timedout)
88906 break;
88907
88908 if (pm_wakeup_pending()) {
88909diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88910index 4dae9cb..039ffbb 100644
88911--- a/kernel/printk/printk.c
88912+++ b/kernel/printk/printk.c
88913@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88914 if (from_file && type != SYSLOG_ACTION_OPEN)
88915 return 0;
88916
88917+#ifdef CONFIG_GRKERNSEC_DMESG
88918+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88919+ return -EPERM;
88920+#endif
88921+
88922 if (syslog_action_restricted(type)) {
88923 if (capable(CAP_SYSLOG))
88924 return 0;
88925diff --git a/kernel/profile.c b/kernel/profile.c
88926index ebdd9c1..612ee05 100644
88927--- a/kernel/profile.c
88928+++ b/kernel/profile.c
88929@@ -37,7 +37,7 @@ struct profile_hit {
88930 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88931 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88932
88933-static atomic_t *prof_buffer;
88934+static atomic_unchecked_t *prof_buffer;
88935 static unsigned long prof_len, prof_shift;
88936
88937 int prof_on __read_mostly;
88938@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88939 hits[i].pc = 0;
88940 continue;
88941 }
88942- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88943+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88944 hits[i].hits = hits[i].pc = 0;
88945 }
88946 }
88947@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88948 * Add the current hit(s) and flush the write-queue out
88949 * to the global buffer:
88950 */
88951- atomic_add(nr_hits, &prof_buffer[pc]);
88952+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88953 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88954- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88955+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88956 hits[i].pc = hits[i].hits = 0;
88957 }
88958 out:
88959@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88960 {
88961 unsigned long pc;
88962 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88963- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88964+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88965 }
88966 #endif /* !CONFIG_SMP */
88967
88968@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88969 return -EFAULT;
88970 buf++; p++; count--; read++;
88971 }
88972- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88973+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88974 if (copy_to_user(buf, (void *)pnt, count))
88975 return -EFAULT;
88976 read += count;
88977@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88978 }
88979 #endif
88980 profile_discard_flip_buffers();
88981- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88982+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88983 return count;
88984 }
88985
88986diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88987index 1f4bcb3..99cf7ab 100644
88988--- a/kernel/ptrace.c
88989+++ b/kernel/ptrace.c
88990@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88991 if (seize)
88992 flags |= PT_SEIZED;
88993 rcu_read_lock();
88994- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88995+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88996 flags |= PT_PTRACE_CAP;
88997 rcu_read_unlock();
88998 task->ptrace = flags;
88999@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
89000 break;
89001 return -EIO;
89002 }
89003- if (copy_to_user(dst, buf, retval))
89004+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
89005 return -EFAULT;
89006 copied += retval;
89007 src += retval;
89008@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
89009 bool seized = child->ptrace & PT_SEIZED;
89010 int ret = -EIO;
89011 siginfo_t siginfo, *si;
89012- void __user *datavp = (void __user *) data;
89013+ void __user *datavp = (__force void __user *) data;
89014 unsigned long __user *datalp = datavp;
89015 unsigned long flags;
89016
89017@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
89018 goto out;
89019 }
89020
89021+ if (gr_handle_ptrace(child, request)) {
89022+ ret = -EPERM;
89023+ goto out_put_task_struct;
89024+ }
89025+
89026 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89027 ret = ptrace_attach(child, request, addr, data);
89028 /*
89029 * Some architectures need to do book-keeping after
89030 * a ptrace attach.
89031 */
89032- if (!ret)
89033+ if (!ret) {
89034 arch_ptrace_attach(child);
89035+ gr_audit_ptrace(child);
89036+ }
89037 goto out_put_task_struct;
89038 }
89039
89040@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
89041 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
89042 if (copied != sizeof(tmp))
89043 return -EIO;
89044- return put_user(tmp, (unsigned long __user *)data);
89045+ return put_user(tmp, (__force unsigned long __user *)data);
89046 }
89047
89048 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
89049@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
89050 }
89051
89052 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
89053- compat_long_t addr, compat_long_t data)
89054+ compat_ulong_t addr, compat_ulong_t data)
89055 {
89056 struct task_struct *child;
89057 long ret;
89058@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
89059 goto out;
89060 }
89061
89062+ if (gr_handle_ptrace(child, request)) {
89063+ ret = -EPERM;
89064+ goto out_put_task_struct;
89065+ }
89066+
89067 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89068 ret = ptrace_attach(child, request, addr, data);
89069 /*
89070 * Some architectures need to do book-keeping after
89071 * a ptrace attach.
89072 */
89073- if (!ret)
89074+ if (!ret) {
89075 arch_ptrace_attach(child);
89076+ gr_audit_ptrace(child);
89077+ }
89078 goto out_put_task_struct;
89079 }
89080
89081diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
89082index 3318d82..1a5b2d1 100644
89083--- a/kernel/rcu/srcu.c
89084+++ b/kernel/rcu/srcu.c
89085@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
89086
89087 idx = ACCESS_ONCE(sp->completed) & 0x1;
89088 preempt_disable();
89089- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89090+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89091 smp_mb(); /* B */ /* Avoid leaking the critical section. */
89092- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89093+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89094 preempt_enable();
89095 return idx;
89096 }
89097diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
89098index 1254f31..16258dc 100644
89099--- a/kernel/rcu/tiny.c
89100+++ b/kernel/rcu/tiny.c
89101@@ -46,7 +46,7 @@
89102 /* Forward declarations for tiny_plugin.h. */
89103 struct rcu_ctrlblk;
89104 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
89105-static void rcu_process_callbacks(struct softirq_action *unused);
89106+static void rcu_process_callbacks(void);
89107 static void __call_rcu(struct rcu_head *head,
89108 void (*func)(struct rcu_head *rcu),
89109 struct rcu_ctrlblk *rcp);
89110@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89111 false));
89112 }
89113
89114-static void rcu_process_callbacks(struct softirq_action *unused)
89115+static __latent_entropy void rcu_process_callbacks(void)
89116 {
89117 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89118 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89119diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
89120index 732f8ae..42c1919 100644
89121--- a/kernel/rcu/torture.c
89122+++ b/kernel/rcu/torture.c
89123@@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
89124 { 0 };
89125 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
89126 { 0 };
89127-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89128-static atomic_t n_rcu_torture_alloc;
89129-static atomic_t n_rcu_torture_alloc_fail;
89130-static atomic_t n_rcu_torture_free;
89131-static atomic_t n_rcu_torture_mberror;
89132-static atomic_t n_rcu_torture_error;
89133+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89134+static atomic_unchecked_t n_rcu_torture_alloc;
89135+static atomic_unchecked_t n_rcu_torture_alloc_fail;
89136+static atomic_unchecked_t n_rcu_torture_free;
89137+static atomic_unchecked_t n_rcu_torture_mberror;
89138+static atomic_unchecked_t n_rcu_torture_error;
89139 static long n_rcu_torture_barrier_error;
89140 static long n_rcu_torture_boost_ktrerror;
89141 static long n_rcu_torture_boost_rterror;
89142@@ -297,11 +297,11 @@ rcu_torture_alloc(void)
89143
89144 spin_lock_bh(&rcu_torture_lock);
89145 if (list_empty(&rcu_torture_freelist)) {
89146- atomic_inc(&n_rcu_torture_alloc_fail);
89147+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
89148 spin_unlock_bh(&rcu_torture_lock);
89149 return NULL;
89150 }
89151- atomic_inc(&n_rcu_torture_alloc);
89152+ atomic_inc_unchecked(&n_rcu_torture_alloc);
89153 p = rcu_torture_freelist.next;
89154 list_del_init(p);
89155 spin_unlock_bh(&rcu_torture_lock);
89156@@ -314,7 +314,7 @@ rcu_torture_alloc(void)
89157 static void
89158 rcu_torture_free(struct rcu_torture *p)
89159 {
89160- atomic_inc(&n_rcu_torture_free);
89161+ atomic_inc_unchecked(&n_rcu_torture_free);
89162 spin_lock_bh(&rcu_torture_lock);
89163 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
89164 spin_unlock_bh(&rcu_torture_lock);
89165@@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
89166 i = rp->rtort_pipe_count;
89167 if (i > RCU_TORTURE_PIPE_LEN)
89168 i = RCU_TORTURE_PIPE_LEN;
89169- atomic_inc(&rcu_torture_wcount[i]);
89170+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89171 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
89172 rp->rtort_mbtest = 0;
89173 rcu_torture_free(rp);
89174@@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
89175 i = old_rp->rtort_pipe_count;
89176 if (i > RCU_TORTURE_PIPE_LEN)
89177 i = RCU_TORTURE_PIPE_LEN;
89178- atomic_inc(&rcu_torture_wcount[i]);
89179+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89180 old_rp->rtort_pipe_count++;
89181 if (gp_normal == gp_exp)
89182 exp = !!(rcu_random(&rand) & 0x80);
89183@@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
89184 i = rp->rtort_pipe_count;
89185 if (i > RCU_TORTURE_PIPE_LEN)
89186 i = RCU_TORTURE_PIPE_LEN;
89187- atomic_inc(&rcu_torture_wcount[i]);
89188+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89189 if (++rp->rtort_pipe_count >=
89190 RCU_TORTURE_PIPE_LEN) {
89191 rp->rtort_mbtest = 0;
89192@@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
89193 return;
89194 }
89195 if (p->rtort_mbtest == 0)
89196- atomic_inc(&n_rcu_torture_mberror);
89197+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89198 spin_lock(&rand_lock);
89199 cur_ops->read_delay(&rand);
89200 n_rcu_torture_timers++;
89201@@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
89202 continue;
89203 }
89204 if (p->rtort_mbtest == 0)
89205- atomic_inc(&n_rcu_torture_mberror);
89206+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89207 cur_ops->read_delay(&rand);
89208 preempt_disable();
89209 pipe_count = p->rtort_pipe_count;
89210@@ -1068,15 +1068,15 @@ rcu_torture_printk(char *page)
89211 }
89212 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89213 page += sprintf(page,
89214- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89215+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89216 rcu_torture_current,
89217 rcu_torture_current_version,
89218 list_empty(&rcu_torture_freelist),
89219- atomic_read(&n_rcu_torture_alloc),
89220- atomic_read(&n_rcu_torture_alloc_fail),
89221- atomic_read(&n_rcu_torture_free));
89222+ atomic_read_unchecked(&n_rcu_torture_alloc),
89223+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89224+ atomic_read_unchecked(&n_rcu_torture_free));
89225 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89226- atomic_read(&n_rcu_torture_mberror),
89227+ atomic_read_unchecked(&n_rcu_torture_mberror),
89228 n_rcu_torture_boost_ktrerror,
89229 n_rcu_torture_boost_rterror);
89230 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89231@@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
89232 n_barrier_attempts,
89233 n_rcu_torture_barrier_error);
89234 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89235- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89236+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89237 n_rcu_torture_barrier_error != 0 ||
89238 n_rcu_torture_boost_ktrerror != 0 ||
89239 n_rcu_torture_boost_rterror != 0 ||
89240 n_rcu_torture_boost_failure != 0 ||
89241 i > 1) {
89242 page += sprintf(page, "!!! ");
89243- atomic_inc(&n_rcu_torture_error);
89244+ atomic_inc_unchecked(&n_rcu_torture_error);
89245 WARN_ON_ONCE(1);
89246 }
89247 page += sprintf(page, "Reader Pipe: ");
89248@@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
89249 page += sprintf(page, "Free-Block Circulation: ");
89250 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89251 page += sprintf(page, " %d",
89252- atomic_read(&rcu_torture_wcount[i]));
89253+ atomic_read_unchecked(&rcu_torture_wcount[i]));
89254 }
89255 page += sprintf(page, "\n");
89256 if (cur_ops->stats)
89257@@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
89258
89259 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89260
89261- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89262+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89263 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89264 else if (n_online_successes != n_online_attempts ||
89265 n_offline_successes != n_offline_attempts)
89266@@ -1961,18 +1961,18 @@ rcu_torture_init(void)
89267
89268 rcu_torture_current = NULL;
89269 rcu_torture_current_version = 0;
89270- atomic_set(&n_rcu_torture_alloc, 0);
89271- atomic_set(&n_rcu_torture_alloc_fail, 0);
89272- atomic_set(&n_rcu_torture_free, 0);
89273- atomic_set(&n_rcu_torture_mberror, 0);
89274- atomic_set(&n_rcu_torture_error, 0);
89275+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89276+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89277+ atomic_set_unchecked(&n_rcu_torture_free, 0);
89278+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89279+ atomic_set_unchecked(&n_rcu_torture_error, 0);
89280 n_rcu_torture_barrier_error = 0;
89281 n_rcu_torture_boost_ktrerror = 0;
89282 n_rcu_torture_boost_rterror = 0;
89283 n_rcu_torture_boost_failure = 0;
89284 n_rcu_torture_boosts = 0;
89285 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89286- atomic_set(&rcu_torture_wcount[i], 0);
89287+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89288 for_each_possible_cpu(cpu) {
89289 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89290 per_cpu(rcu_torture_count, cpu)[i] = 0;
89291diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89292index b3d116c..ebf6598 100644
89293--- a/kernel/rcu/tree.c
89294+++ b/kernel/rcu/tree.c
89295@@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89296 rcu_prepare_for_idle(smp_processor_id());
89297 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89298 smp_mb__before_atomic_inc(); /* See above. */
89299- atomic_inc(&rdtp->dynticks);
89300+ atomic_inc_unchecked(&rdtp->dynticks);
89301 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89302- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89303+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89304
89305 /*
89306 * It is illegal to enter an extended quiescent state while
89307@@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89308 int user)
89309 {
89310 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89311- atomic_inc(&rdtp->dynticks);
89312+ atomic_inc_unchecked(&rdtp->dynticks);
89313 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89314 smp_mb__after_atomic_inc(); /* See above. */
89315- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89316+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89317 rcu_cleanup_after_idle(smp_processor_id());
89318 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89319 if (!user && !is_idle_task(current)) {
89320@@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
89321 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89322
89323 if (rdtp->dynticks_nmi_nesting == 0 &&
89324- (atomic_read(&rdtp->dynticks) & 0x1))
89325+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89326 return;
89327 rdtp->dynticks_nmi_nesting++;
89328 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89329- atomic_inc(&rdtp->dynticks);
89330+ atomic_inc_unchecked(&rdtp->dynticks);
89331 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89332 smp_mb__after_atomic_inc(); /* See above. */
89333- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89334+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89335 }
89336
89337 /**
89338@@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
89339 return;
89340 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89341 smp_mb__before_atomic_inc(); /* See above. */
89342- atomic_inc(&rdtp->dynticks);
89343+ atomic_inc_unchecked(&rdtp->dynticks);
89344 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89345- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89346+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89347 }
89348
89349 /**
89350@@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
89351 */
89352 bool notrace __rcu_is_watching(void)
89353 {
89354- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89355+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89356 }
89357
89358 /**
89359@@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89360 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89361 bool *isidle, unsigned long *maxj)
89362 {
89363- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89364+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89365 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89366 return (rdp->dynticks_snap & 0x1) == 0;
89367 }
89368@@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89369 unsigned int curr;
89370 unsigned int snap;
89371
89372- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89373+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89374 snap = (unsigned int)rdp->dynticks_snap;
89375
89376 /*
89377@@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89378 rdp = this_cpu_ptr(rsp->rda);
89379 rcu_preempt_check_blocked_tasks(rnp);
89380 rnp->qsmask = rnp->qsmaskinit;
89381- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89382+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89383 WARN_ON_ONCE(rnp->completed != rsp->completed);
89384- ACCESS_ONCE(rnp->completed) = rsp->completed;
89385+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89386 if (rnp == rdp->mynode)
89387 __note_gp_changes(rsp, rnp, rdp);
89388 rcu_preempt_boost_start_gp(rnp);
89389@@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89390 rcu_for_each_node_breadth_first(rsp, rnp) {
89391 raw_spin_lock_irq(&rnp->lock);
89392 smp_mb__after_unlock_lock();
89393- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89394+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89395 rdp = this_cpu_ptr(rsp->rda);
89396 if (rnp == rdp->mynode)
89397 __note_gp_changes(rsp, rnp, rdp);
89398@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89399 rsp->qlen += rdp->qlen;
89400 rdp->n_cbs_orphaned += rdp->qlen;
89401 rdp->qlen_lazy = 0;
89402- ACCESS_ONCE(rdp->qlen) = 0;
89403+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89404 }
89405
89406 /*
89407@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89408 }
89409 smp_mb(); /* List handling before counting for rcu_barrier(). */
89410 rdp->qlen_lazy -= count_lazy;
89411- ACCESS_ONCE(rdp->qlen) -= count;
89412+ ACCESS_ONCE_RW(rdp->qlen) -= count;
89413 rdp->n_cbs_invoked += count;
89414
89415 /* Reinstate batch limit if we have worked down the excess. */
89416@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89417 /*
89418 * Do RCU core processing for the current CPU.
89419 */
89420-static void rcu_process_callbacks(struct softirq_action *unused)
89421+static void rcu_process_callbacks(void)
89422 {
89423 struct rcu_state *rsp;
89424
89425@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89426 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89427 if (debug_rcu_head_queue(head)) {
89428 /* Probable double call_rcu(), so leak the callback. */
89429- ACCESS_ONCE(head->func) = rcu_leak_callback;
89430+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89431 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89432 return;
89433 }
89434@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89435 local_irq_restore(flags);
89436 return;
89437 }
89438- ACCESS_ONCE(rdp->qlen)++;
89439+ ACCESS_ONCE_RW(rdp->qlen)++;
89440 if (lazy)
89441 rdp->qlen_lazy++;
89442 else
89443@@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
89444 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89445 * course be required on a 64-bit system.
89446 */
89447- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89448+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89449 (ulong)atomic_long_read(&rsp->expedited_done) +
89450 ULONG_MAX / 8)) {
89451 synchronize_sched();
89452- atomic_long_inc(&rsp->expedited_wrap);
89453+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
89454 return;
89455 }
89456
89457@@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
89458 * Take a ticket. Note that atomic_inc_return() implies a
89459 * full memory barrier.
89460 */
89461- snap = atomic_long_inc_return(&rsp->expedited_start);
89462+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89463 firstsnap = snap;
89464 get_online_cpus();
89465 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89466@@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
89467 synchronize_sched_expedited_cpu_stop,
89468 NULL) == -EAGAIN) {
89469 put_online_cpus();
89470- atomic_long_inc(&rsp->expedited_tryfail);
89471+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89472
89473 /* Check to see if someone else did our work for us. */
89474 s = atomic_long_read(&rsp->expedited_done);
89475 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89476 /* ensure test happens before caller kfree */
89477 smp_mb__before_atomic_inc(); /* ^^^ */
89478- atomic_long_inc(&rsp->expedited_workdone1);
89479+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89480 return;
89481 }
89482
89483@@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
89484 udelay(trycount * num_online_cpus());
89485 } else {
89486 wait_rcu_gp(call_rcu_sched);
89487- atomic_long_inc(&rsp->expedited_normal);
89488+ atomic_long_inc_unchecked(&rsp->expedited_normal);
89489 return;
89490 }
89491
89492@@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
89493 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89494 /* ensure test happens before caller kfree */
89495 smp_mb__before_atomic_inc(); /* ^^^ */
89496- atomic_long_inc(&rsp->expedited_workdone2);
89497+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89498 return;
89499 }
89500
89501@@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
89502 * period works for us.
89503 */
89504 get_online_cpus();
89505- snap = atomic_long_read(&rsp->expedited_start);
89506+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
89507 smp_mb(); /* ensure read is before try_stop_cpus(). */
89508 }
89509- atomic_long_inc(&rsp->expedited_stoppedcpus);
89510+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89511
89512 /*
89513 * Everyone up to our most recent fetch is covered by our grace
89514@@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
89515 * than we did already did their update.
89516 */
89517 do {
89518- atomic_long_inc(&rsp->expedited_done_tries);
89519+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89520 s = atomic_long_read(&rsp->expedited_done);
89521 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89522 /* ensure test happens before caller kfree */
89523 smp_mb__before_atomic_inc(); /* ^^^ */
89524- atomic_long_inc(&rsp->expedited_done_lost);
89525+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89526 break;
89527 }
89528 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89529- atomic_long_inc(&rsp->expedited_done_exit);
89530+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89531
89532 put_online_cpus();
89533 }
89534@@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89535 * ACCESS_ONCE() to prevent the compiler from speculating
89536 * the increment to precede the early-exit check.
89537 */
89538- ACCESS_ONCE(rsp->n_barrier_done)++;
89539+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89540 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89541 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89542 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89543@@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89544
89545 /* Increment ->n_barrier_done to prevent duplicate work. */
89546 smp_mb(); /* Keep increment after above mechanism. */
89547- ACCESS_ONCE(rsp->n_barrier_done)++;
89548+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89549 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89550 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89551 smp_mb(); /* Keep increment before caller's subsequent code. */
89552@@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89553 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89554 init_callback_list(rdp);
89555 rdp->qlen_lazy = 0;
89556- ACCESS_ONCE(rdp->qlen) = 0;
89557+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89558 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89559 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89560- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89561+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89562 rdp->cpu = cpu;
89563 rdp->rsp = rsp;
89564 rcu_boot_init_nocb_percpu_data(rdp);
89565@@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89566 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89567 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89568 rcu_sysidle_init_percpu_data(rdp->dynticks);
89569- atomic_set(&rdp->dynticks->dynticks,
89570- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89571+ atomic_set_unchecked(&rdp->dynticks->dynticks,
89572+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89573 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89574
89575 /* Add CPU to rcu_node bitmasks. */
89576diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89577index 8c19873..bf83c57 100644
89578--- a/kernel/rcu/tree.h
89579+++ b/kernel/rcu/tree.h
89580@@ -87,11 +87,11 @@ struct rcu_dynticks {
89581 long long dynticks_nesting; /* Track irq/process nesting level. */
89582 /* Process level is worth LLONG_MAX/2. */
89583 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89584- atomic_t dynticks; /* Even value for idle, else odd. */
89585+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89586 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89587 long long dynticks_idle_nesting;
89588 /* irq/process nesting level from idle. */
89589- atomic_t dynticks_idle; /* Even value for idle, else odd. */
89590+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89591 /* "Idle" excludes userspace execution. */
89592 unsigned long dynticks_idle_jiffies;
89593 /* End of last non-NMI non-idle period. */
89594@@ -431,17 +431,17 @@ struct rcu_state {
89595 /* _rcu_barrier(). */
89596 /* End of fields guarded by barrier_mutex. */
89597
89598- atomic_long_t expedited_start; /* Starting ticket. */
89599- atomic_long_t expedited_done; /* Done ticket. */
89600- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89601- atomic_long_t expedited_tryfail; /* # acquisition failures. */
89602- atomic_long_t expedited_workdone1; /* # done by others #1. */
89603- atomic_long_t expedited_workdone2; /* # done by others #2. */
89604- atomic_long_t expedited_normal; /* # fallbacks to normal. */
89605- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89606- atomic_long_t expedited_done_tries; /* # tries to update _done. */
89607- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89608- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89609+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89610+ atomic_long_t expedited_done; /* Done ticket. */
89611+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89612+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89613+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89614+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89615+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89616+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89617+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89618+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89619+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89620
89621 unsigned long jiffies_force_qs; /* Time at which to invoke */
89622 /* force_quiescent_state(). */
89623diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89624index 6e2ef4b..c15df94 100644
89625--- a/kernel/rcu/tree_plugin.h
89626+++ b/kernel/rcu/tree_plugin.h
89627@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89628 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89629 {
89630 return !rcu_preempted_readers_exp(rnp) &&
89631- ACCESS_ONCE(rnp->expmask) == 0;
89632+ ACCESS_ONCE_RW(rnp->expmask) == 0;
89633 }
89634
89635 /*
89636@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89637
89638 /* Clean up and exit. */
89639 smp_mb(); /* ensure expedited GP seen before counter increment. */
89640- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89641+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89642 unlock_mb_ret:
89643 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89644 mb_ret:
89645@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89646 free_cpumask_var(cm);
89647 }
89648
89649-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89650+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89651 .store = &rcu_cpu_kthread_task,
89652 .thread_should_run = rcu_cpu_kthread_should_run,
89653 .thread_fn = rcu_cpu_kthread,
89654@@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89655 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89656 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89657 cpu, ticks_value, ticks_title,
89658- atomic_read(&rdtp->dynticks) & 0xfff,
89659+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89660 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89661 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89662 fast_no_hz);
89663@@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89664
89665 /* Enqueue the callback on the nocb list and update counts. */
89666 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89667- ACCESS_ONCE(*old_rhpp) = rhp;
89668+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
89669 atomic_long_add(rhcount, &rdp->nocb_q_count);
89670 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89671
89672@@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
89673 * Extract queued callbacks, update counts, and wait
89674 * for a grace period to elapse.
89675 */
89676- ACCESS_ONCE(rdp->nocb_head) = NULL;
89677+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89678 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89679 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89680 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89681- ACCESS_ONCE(rdp->nocb_p_count) += c;
89682- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89683+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89684+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89685 rcu_nocb_wait_gp(rdp);
89686
89687 /* Each pass through the following loop invokes a callback. */
89688@@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
89689 list = next;
89690 }
89691 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89692- ACCESS_ONCE(rdp->nocb_p_count) -= c;
89693- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89694+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89695+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89696 rdp->n_nocbs_invoked += c;
89697 }
89698 return 0;
89699@@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89700 {
89701 if (!rcu_nocb_need_deferred_wakeup(rdp))
89702 return;
89703- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89704+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89705 wake_up(&rdp->nocb_wq);
89706 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89707 }
89708@@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89709 t = kthread_run(rcu_nocb_kthread, rdp,
89710 "rcuo%c/%d", rsp->abbr, cpu);
89711 BUG_ON(IS_ERR(t));
89712- ACCESS_ONCE(rdp->nocb_kthread) = t;
89713+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89714 }
89715 }
89716
89717@@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89718
89719 /* Record start of fully idle period. */
89720 j = jiffies;
89721- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89722+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89723 smp_mb__before_atomic_inc();
89724- atomic_inc(&rdtp->dynticks_idle);
89725+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89726 smp_mb__after_atomic_inc();
89727- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89728+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89729 }
89730
89731 /*
89732@@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89733
89734 /* Record end of idle period. */
89735 smp_mb__before_atomic_inc();
89736- atomic_inc(&rdtp->dynticks_idle);
89737+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89738 smp_mb__after_atomic_inc();
89739- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89740+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89741
89742 /*
89743 * If we are the timekeeping CPU, we are permitted to be non-idle
89744@@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89745 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89746
89747 /* Pick up current idle and NMI-nesting counter and check. */
89748- cur = atomic_read(&rdtp->dynticks_idle);
89749+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89750 if (cur & 0x1) {
89751 *isidle = false; /* We are not idle! */
89752 return;
89753@@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
89754 case RCU_SYSIDLE_NOT:
89755
89756 /* First time all are idle, so note a short idle period. */
89757- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89758+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89759 break;
89760
89761 case RCU_SYSIDLE_SHORT:
89762@@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
89763 static void rcu_sysidle_cancel(void)
89764 {
89765 smp_mb();
89766- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89767+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89768 }
89769
89770 /*
89771@@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89772 smp_mb(); /* grace period precedes setting inuse. */
89773
89774 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89775- ACCESS_ONCE(rshp->inuse) = 0;
89776+ ACCESS_ONCE_RW(rshp->inuse) = 0;
89777 }
89778
89779 /*
89780diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89781index 4def475..8ffddde 100644
89782--- a/kernel/rcu/tree_trace.c
89783+++ b/kernel/rcu/tree_trace.c
89784@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89785 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89786 rdp->passed_quiesce, rdp->qs_pending);
89787 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89788- atomic_read(&rdp->dynticks->dynticks),
89789+ atomic_read_unchecked(&rdp->dynticks->dynticks),
89790 rdp->dynticks->dynticks_nesting,
89791 rdp->dynticks->dynticks_nmi_nesting,
89792 rdp->dynticks_fqs);
89793@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89794 struct rcu_state *rsp = (struct rcu_state *)m->private;
89795
89796 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",
89797- atomic_long_read(&rsp->expedited_start),
89798+ atomic_long_read_unchecked(&rsp->expedited_start),
89799 atomic_long_read(&rsp->expedited_done),
89800- atomic_long_read(&rsp->expedited_wrap),
89801- atomic_long_read(&rsp->expedited_tryfail),
89802- atomic_long_read(&rsp->expedited_workdone1),
89803- atomic_long_read(&rsp->expedited_workdone2),
89804- atomic_long_read(&rsp->expedited_normal),
89805- atomic_long_read(&rsp->expedited_stoppedcpus),
89806- atomic_long_read(&rsp->expedited_done_tries),
89807- atomic_long_read(&rsp->expedited_done_lost),
89808- atomic_long_read(&rsp->expedited_done_exit));
89809+ atomic_long_read_unchecked(&rsp->expedited_wrap),
89810+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
89811+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
89812+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
89813+ atomic_long_read_unchecked(&rsp->expedited_normal),
89814+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89815+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
89816+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
89817+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
89818 return 0;
89819 }
89820
89821diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89822index c54609f..2e8829c 100644
89823--- a/kernel/rcu/update.c
89824+++ b/kernel/rcu/update.c
89825@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
89826 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89827 */
89828 if (till_stall_check < 3) {
89829- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89830+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89831 till_stall_check = 3;
89832 } else if (till_stall_check > 300) {
89833- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89834+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89835 till_stall_check = 300;
89836 }
89837 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89838diff --git a/kernel/resource.c b/kernel/resource.c
89839index 3f285dc..5755f62 100644
89840--- a/kernel/resource.c
89841+++ b/kernel/resource.c
89842@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89843
89844 static int __init ioresources_init(void)
89845 {
89846+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89847+#ifdef CONFIG_GRKERNSEC_PROC_USER
89848+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89849+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89850+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89851+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89852+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89853+#endif
89854+#else
89855 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89856 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89857+#endif
89858 return 0;
89859 }
89860 __initcall(ioresources_init);
89861diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89862index 4a07353..66b5291 100644
89863--- a/kernel/sched/auto_group.c
89864+++ b/kernel/sched/auto_group.c
89865@@ -11,7 +11,7 @@
89866
89867 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89868 static struct autogroup autogroup_default;
89869-static atomic_t autogroup_seq_nr;
89870+static atomic_unchecked_t autogroup_seq_nr;
89871
89872 void __init autogroup_init(struct task_struct *init_task)
89873 {
89874@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89875
89876 kref_init(&ag->kref);
89877 init_rwsem(&ag->lock);
89878- ag->id = atomic_inc_return(&autogroup_seq_nr);
89879+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89880 ag->tg = tg;
89881 #ifdef CONFIG_RT_GROUP_SCHED
89882 /*
89883diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89884index a63f4dc..349bbb0 100644
89885--- a/kernel/sched/completion.c
89886+++ b/kernel/sched/completion.c
89887@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89888 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89889 * or number of jiffies left till timeout) if completed.
89890 */
89891-long __sched
89892+long __sched __intentional_overflow(-1)
89893 wait_for_completion_interruptible_timeout(struct completion *x,
89894 unsigned long timeout)
89895 {
89896@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89897 *
89898 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89899 */
89900-int __sched wait_for_completion_killable(struct completion *x)
89901+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89902 {
89903 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89904 if (t == -ERESTARTSYS)
89905@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89906 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89907 * or number of jiffies left till timeout) if completed.
89908 */
89909-long __sched
89910+long __sched __intentional_overflow(-1)
89911 wait_for_completion_killable_timeout(struct completion *x,
89912 unsigned long timeout)
89913 {
89914diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89915index f5c6635..7133356 100644
89916--- a/kernel/sched/core.c
89917+++ b/kernel/sched/core.c
89918@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89919 int sysctl_numa_balancing(struct ctl_table *table, int write,
89920 void __user *buffer, size_t *lenp, loff_t *ppos)
89921 {
89922- struct ctl_table t;
89923+ ctl_table_no_const t;
89924 int err;
89925 int state = numabalancing_enabled;
89926
89927@@ -2251,8 +2251,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
89928 next->active_mm = oldmm;
89929 atomic_inc(&oldmm->mm_count);
89930 enter_lazy_tlb(oldmm, next);
89931- } else
89932+ } else {
89933 switch_mm(oldmm, mm, next);
89934+ populate_stack();
89935+ }
89936
89937 if (!prev->mm) {
89938 prev->active_mm = NULL;
89939@@ -3049,6 +3051,8 @@ int can_nice(const struct task_struct *p, const int nice)
89940 /* convert nice value [19,-20] to rlimit style value [1,40] */
89941 int nice_rlim = 20 - nice;
89942
89943+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89944+
89945 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89946 capable(CAP_SYS_NICE));
89947 }
89948@@ -3082,7 +3086,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89949 if (nice > 19)
89950 nice = 19;
89951
89952- if (increment < 0 && !can_nice(current, nice))
89953+ if (increment < 0 && (!can_nice(current, nice) ||
89954+ gr_handle_chroot_nice()))
89955 return -EPERM;
89956
89957 retval = security_task_setnice(current, nice);
89958@@ -3332,6 +3337,7 @@ recheck:
89959 if (policy != p->policy && !rlim_rtprio)
89960 return -EPERM;
89961
89962+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89963 /* can't increase priority */
89964 if (attr->sched_priority > p->rt_priority &&
89965 attr->sched_priority > rlim_rtprio)
89966@@ -4702,8 +4708,10 @@ void idle_task_exit(void)
89967
89968 BUG_ON(cpu_online(smp_processor_id()));
89969
89970- if (mm != &init_mm)
89971+ if (mm != &init_mm) {
89972 switch_mm(mm, &init_mm, current);
89973+ populate_stack();
89974+ }
89975 mmdrop(mm);
89976 }
89977
89978@@ -4781,7 +4789,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89979
89980 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89981
89982-static struct ctl_table sd_ctl_dir[] = {
89983+static ctl_table_no_const sd_ctl_dir[] __read_only = {
89984 {
89985 .procname = "sched_domain",
89986 .mode = 0555,
89987@@ -4798,17 +4806,17 @@ static struct ctl_table sd_ctl_root[] = {
89988 {}
89989 };
89990
89991-static struct ctl_table *sd_alloc_ctl_entry(int n)
89992+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89993 {
89994- struct ctl_table *entry =
89995+ ctl_table_no_const *entry =
89996 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89997
89998 return entry;
89999 }
90000
90001-static void sd_free_ctl_entry(struct ctl_table **tablep)
90002+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
90003 {
90004- struct ctl_table *entry;
90005+ ctl_table_no_const *entry;
90006
90007 /*
90008 * In the intermediate directories, both the child directory and
90009@@ -4816,22 +4824,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
90010 * will always be set. In the lowest directory the names are
90011 * static strings and all have proc handlers.
90012 */
90013- for (entry = *tablep; entry->mode; entry++) {
90014- if (entry->child)
90015- sd_free_ctl_entry(&entry->child);
90016+ for (entry = tablep; entry->mode; entry++) {
90017+ if (entry->child) {
90018+ sd_free_ctl_entry(entry->child);
90019+ pax_open_kernel();
90020+ entry->child = NULL;
90021+ pax_close_kernel();
90022+ }
90023 if (entry->proc_handler == NULL)
90024 kfree(entry->procname);
90025 }
90026
90027- kfree(*tablep);
90028- *tablep = NULL;
90029+ kfree(tablep);
90030 }
90031
90032 static int min_load_idx = 0;
90033 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
90034
90035 static void
90036-set_table_entry(struct ctl_table *entry,
90037+set_table_entry(ctl_table_no_const *entry,
90038 const char *procname, void *data, int maxlen,
90039 umode_t mode, proc_handler *proc_handler,
90040 bool load_idx)
90041@@ -4851,7 +4862,7 @@ set_table_entry(struct ctl_table *entry,
90042 static struct ctl_table *
90043 sd_alloc_ctl_domain_table(struct sched_domain *sd)
90044 {
90045- struct ctl_table *table = sd_alloc_ctl_entry(13);
90046+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
90047
90048 if (table == NULL)
90049 return NULL;
90050@@ -4886,9 +4897,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
90051 return table;
90052 }
90053
90054-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
90055+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
90056 {
90057- struct ctl_table *entry, *table;
90058+ ctl_table_no_const *entry, *table;
90059 struct sched_domain *sd;
90060 int domain_num = 0, i;
90061 char buf[32];
90062@@ -4915,11 +4926,13 @@ static struct ctl_table_header *sd_sysctl_header;
90063 static void register_sched_domain_sysctl(void)
90064 {
90065 int i, cpu_num = num_possible_cpus();
90066- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
90067+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
90068 char buf[32];
90069
90070 WARN_ON(sd_ctl_dir[0].child);
90071+ pax_open_kernel();
90072 sd_ctl_dir[0].child = entry;
90073+ pax_close_kernel();
90074
90075 if (entry == NULL)
90076 return;
90077@@ -4942,8 +4955,12 @@ static void unregister_sched_domain_sysctl(void)
90078 if (sd_sysctl_header)
90079 unregister_sysctl_table(sd_sysctl_header);
90080 sd_sysctl_header = NULL;
90081- if (sd_ctl_dir[0].child)
90082- sd_free_ctl_entry(&sd_ctl_dir[0].child);
90083+ if (sd_ctl_dir[0].child) {
90084+ sd_free_ctl_entry(sd_ctl_dir[0].child);
90085+ pax_open_kernel();
90086+ sd_ctl_dir[0].child = NULL;
90087+ pax_close_kernel();
90088+ }
90089 }
90090 #else
90091 static void register_sched_domain_sysctl(void)
90092diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
90093index 9b4c4f3..665489b 100644
90094--- a/kernel/sched/fair.c
90095+++ b/kernel/sched/fair.c
90096@@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
90097
90098 static void reset_ptenuma_scan(struct task_struct *p)
90099 {
90100- ACCESS_ONCE(p->mm->numa_scan_seq)++;
90101+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
90102 p->mm->numa_scan_offset = 0;
90103 }
90104
90105@@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
90106 * run_rebalance_domains is triggered when needed from the scheduler tick.
90107 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
90108 */
90109-static void run_rebalance_domains(struct softirq_action *h)
90110+static __latent_entropy void run_rebalance_domains(void)
90111 {
90112 struct rq *this_rq = this_rq();
90113 enum cpu_idle_type idle = this_rq->idle_balance ?
90114diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
90115index f964add..dcd823d 100644
90116--- a/kernel/sched/sched.h
90117+++ b/kernel/sched/sched.h
90118@@ -1157,7 +1157,7 @@ struct sched_class {
90119 #ifdef CONFIG_FAIR_GROUP_SCHED
90120 void (*task_move_group) (struct task_struct *p, int on_rq);
90121 #endif
90122-};
90123+} __do_const;
90124
90125 #define sched_class_highest (&stop_sched_class)
90126 #define for_each_class(class) \
90127diff --git a/kernel/signal.c b/kernel/signal.c
90128index 52f881d..1e9f941 100644
90129--- a/kernel/signal.c
90130+++ b/kernel/signal.c
90131@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
90132
90133 int print_fatal_signals __read_mostly;
90134
90135-static void __user *sig_handler(struct task_struct *t, int sig)
90136+static __sighandler_t sig_handler(struct task_struct *t, int sig)
90137 {
90138 return t->sighand->action[sig - 1].sa.sa_handler;
90139 }
90140
90141-static int sig_handler_ignored(void __user *handler, int sig)
90142+static int sig_handler_ignored(__sighandler_t handler, int sig)
90143 {
90144 /* Is it explicitly or implicitly ignored? */
90145 return handler == SIG_IGN ||
90146@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
90147
90148 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
90149 {
90150- void __user *handler;
90151+ __sighandler_t handler;
90152
90153 handler = sig_handler(t, sig);
90154
90155@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
90156 atomic_inc(&user->sigpending);
90157 rcu_read_unlock();
90158
90159+ if (!override_rlimit)
90160+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
90161+
90162 if (override_rlimit ||
90163 atomic_read(&user->sigpending) <=
90164 task_rlimit(t, RLIMIT_SIGPENDING)) {
90165@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
90166
90167 int unhandled_signal(struct task_struct *tsk, int sig)
90168 {
90169- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
90170+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
90171 if (is_global_init(tsk))
90172 return 1;
90173 if (handler != SIG_IGN && handler != SIG_DFL)
90174@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
90175 }
90176 }
90177
90178+ /* allow glibc communication via tgkill to other threads in our
90179+ thread group */
90180+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90181+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90182+ && gr_handle_signal(t, sig))
90183+ return -EPERM;
90184+
90185 return security_task_kill(t, info, sig, 0);
90186 }
90187
90188@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90189 return send_signal(sig, info, p, 1);
90190 }
90191
90192-static int
90193+int
90194 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90195 {
90196 return send_signal(sig, info, t, 0);
90197@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90198 unsigned long int flags;
90199 int ret, blocked, ignored;
90200 struct k_sigaction *action;
90201+ int is_unhandled = 0;
90202
90203 spin_lock_irqsave(&t->sighand->siglock, flags);
90204 action = &t->sighand->action[sig-1];
90205@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90206 }
90207 if (action->sa.sa_handler == SIG_DFL)
90208 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90209+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90210+ is_unhandled = 1;
90211 ret = specific_send_sig_info(sig, info, t);
90212 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90213
90214+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
90215+ normal operation */
90216+ if (is_unhandled) {
90217+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90218+ gr_handle_crash(t, sig);
90219+ }
90220+
90221 return ret;
90222 }
90223
90224@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90225 ret = check_kill_permission(sig, info, p);
90226 rcu_read_unlock();
90227
90228- if (!ret && sig)
90229+ if (!ret && sig) {
90230 ret = do_send_sig_info(sig, info, p, true);
90231+ if (!ret)
90232+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90233+ }
90234
90235 return ret;
90236 }
90237@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90238 int error = -ESRCH;
90239
90240 rcu_read_lock();
90241- p = find_task_by_vpid(pid);
90242+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90243+ /* allow glibc communication via tgkill to other threads in our
90244+ thread group */
90245+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90246+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
90247+ p = find_task_by_vpid_unrestricted(pid);
90248+ else
90249+#endif
90250+ p = find_task_by_vpid(pid);
90251 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90252 error = check_kill_permission(sig, info, p);
90253 /*
90254@@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90255 }
90256 seg = get_fs();
90257 set_fs(KERNEL_DS);
90258- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90259- (stack_t __force __user *) &uoss,
90260+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90261+ (stack_t __force_user *) &uoss,
90262 compat_user_stack_pointer());
90263 set_fs(seg);
90264 if (ret >= 0 && uoss_ptr) {
90265diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90266index eb89e18..a4e6792 100644
90267--- a/kernel/smpboot.c
90268+++ b/kernel/smpboot.c
90269@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90270 }
90271 smpboot_unpark_thread(plug_thread, cpu);
90272 }
90273- list_add(&plug_thread->list, &hotplug_threads);
90274+ pax_list_add(&plug_thread->list, &hotplug_threads);
90275 out:
90276 mutex_unlock(&smpboot_threads_lock);
90277 return ret;
90278@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90279 {
90280 get_online_cpus();
90281 mutex_lock(&smpboot_threads_lock);
90282- list_del(&plug_thread->list);
90283+ pax_list_del(&plug_thread->list);
90284 smpboot_destroy_threads(plug_thread);
90285 mutex_unlock(&smpboot_threads_lock);
90286 put_online_cpus();
90287diff --git a/kernel/softirq.c b/kernel/softirq.c
90288index 490fcbb..1e502c6 100644
90289--- a/kernel/softirq.c
90290+++ b/kernel/softirq.c
90291@@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90292 EXPORT_SYMBOL(irq_stat);
90293 #endif
90294
90295-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90296+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90297
90298 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90299
90300@@ -267,7 +267,7 @@ restart:
90301 kstat_incr_softirqs_this_cpu(vec_nr);
90302
90303 trace_softirq_entry(vec_nr);
90304- h->action(h);
90305+ h->action();
90306 trace_softirq_exit(vec_nr);
90307 if (unlikely(prev_count != preempt_count())) {
90308 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90309@@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90310 or_softirq_pending(1UL << nr);
90311 }
90312
90313-void open_softirq(int nr, void (*action)(struct softirq_action *))
90314+void __init open_softirq(int nr, void (*action)(void))
90315 {
90316 softirq_vec[nr].action = action;
90317 }
90318@@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90319 }
90320 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90321
90322-static void tasklet_action(struct softirq_action *a)
90323+static void tasklet_action(void)
90324 {
90325 struct tasklet_struct *list;
90326
90327@@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
90328 }
90329 }
90330
90331-static void tasklet_hi_action(struct softirq_action *a)
90332+static __latent_entropy void tasklet_hi_action(void)
90333 {
90334 struct tasklet_struct *list;
90335
90336@@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
90337 .notifier_call = cpu_callback
90338 };
90339
90340-static struct smp_hotplug_thread softirq_threads = {
90341+static struct smp_hotplug_thread softirq_threads __read_only = {
90342 .store = &ksoftirqd,
90343 .thread_should_run = ksoftirqd_should_run,
90344 .thread_fn = run_ksoftirqd,
90345diff --git a/kernel/sys.c b/kernel/sys.c
90346index c0a58be..784c618 100644
90347--- a/kernel/sys.c
90348+++ b/kernel/sys.c
90349@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90350 error = -EACCES;
90351 goto out;
90352 }
90353+
90354+ if (gr_handle_chroot_setpriority(p, niceval)) {
90355+ error = -EACCES;
90356+ goto out;
90357+ }
90358+
90359 no_nice = security_task_setnice(p, niceval);
90360 if (no_nice) {
90361 error = no_nice;
90362@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90363 goto error;
90364 }
90365
90366+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90367+ goto error;
90368+
90369 if (rgid != (gid_t) -1 ||
90370 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90371 new->sgid = new->egid;
90372@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90373 old = current_cred();
90374
90375 retval = -EPERM;
90376+
90377+ if (gr_check_group_change(kgid, kgid, kgid))
90378+ goto error;
90379+
90380 if (ns_capable(old->user_ns, CAP_SETGID))
90381 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90382 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90383@@ -403,7 +416,7 @@ error:
90384 /*
90385 * change the user struct in a credentials set to match the new UID
90386 */
90387-static int set_user(struct cred *new)
90388+int set_user(struct cred *new)
90389 {
90390 struct user_struct *new_user;
90391
90392@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90393 goto error;
90394 }
90395
90396+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90397+ goto error;
90398+
90399 if (!uid_eq(new->uid, old->uid)) {
90400 retval = set_user(new);
90401 if (retval < 0)
90402@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90403 old = current_cred();
90404
90405 retval = -EPERM;
90406+
90407+ if (gr_check_crash_uid(kuid))
90408+ goto error;
90409+ if (gr_check_user_change(kuid, kuid, kuid))
90410+ goto error;
90411+
90412 if (ns_capable(old->user_ns, CAP_SETUID)) {
90413 new->suid = new->uid = kuid;
90414 if (!uid_eq(kuid, old->uid)) {
90415@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90416 goto error;
90417 }
90418
90419+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
90420+ goto error;
90421+
90422 if (ruid != (uid_t) -1) {
90423 new->uid = kruid;
90424 if (!uid_eq(kruid, old->uid)) {
90425@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90426 goto error;
90427 }
90428
90429+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
90430+ goto error;
90431+
90432 if (rgid != (gid_t) -1)
90433 new->gid = krgid;
90434 if (egid != (gid_t) -1)
90435@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90436 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90437 ns_capable(old->user_ns, CAP_SETUID)) {
90438 if (!uid_eq(kuid, old->fsuid)) {
90439+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90440+ goto error;
90441+
90442 new->fsuid = kuid;
90443 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90444 goto change_okay;
90445 }
90446 }
90447
90448+error:
90449 abort_creds(new);
90450 return old_fsuid;
90451
90452@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90453 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90454 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90455 ns_capable(old->user_ns, CAP_SETGID)) {
90456+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90457+ goto error;
90458+
90459 if (!gid_eq(kgid, old->fsgid)) {
90460 new->fsgid = kgid;
90461 goto change_okay;
90462 }
90463 }
90464
90465+error:
90466 abort_creds(new);
90467 return old_fsgid;
90468
90469@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90470 return -EFAULT;
90471
90472 down_read(&uts_sem);
90473- error = __copy_to_user(&name->sysname, &utsname()->sysname,
90474+ error = __copy_to_user(name->sysname, &utsname()->sysname,
90475 __OLD_UTS_LEN);
90476 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90477- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90478+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
90479 __OLD_UTS_LEN);
90480 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90481- error |= __copy_to_user(&name->release, &utsname()->release,
90482+ error |= __copy_to_user(name->release, &utsname()->release,
90483 __OLD_UTS_LEN);
90484 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90485- error |= __copy_to_user(&name->version, &utsname()->version,
90486+ error |= __copy_to_user(name->version, &utsname()->version,
90487 __OLD_UTS_LEN);
90488 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90489- error |= __copy_to_user(&name->machine, &utsname()->machine,
90490+ error |= __copy_to_user(name->machine, &utsname()->machine,
90491 __OLD_UTS_LEN);
90492 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90493 up_read(&uts_sem);
90494@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90495 */
90496 new_rlim->rlim_cur = 1;
90497 }
90498+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90499+ is changed to a lower value. Since tasks can be created by the same
90500+ user in between this limit change and an execve by this task, force
90501+ a recheck only for this task by setting PF_NPROC_EXCEEDED
90502+ */
90503+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90504+ tsk->flags |= PF_NPROC_EXCEEDED;
90505 }
90506 if (!retval) {
90507 if (old_rlim)
90508diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90509index aae21e8..58d8c9a 100644
90510--- a/kernel/sysctl.c
90511+++ b/kernel/sysctl.c
90512@@ -94,7 +94,6 @@
90513
90514
90515 #if defined(CONFIG_SYSCTL)
90516-
90517 /* External variables not in a header file. */
90518 extern int max_threads;
90519 extern int suid_dumpable;
90520@@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
90521
90522 /* Constants used for minimum and maximum */
90523 #ifdef CONFIG_LOCKUP_DETECTOR
90524-static int sixty = 60;
90525+static int sixty __read_only = 60;
90526 #endif
90527
90528-static int __maybe_unused neg_one = -1;
90529-
90530-static int zero;
90531-static int __maybe_unused one = 1;
90532-static int __maybe_unused two = 2;
90533-static int __maybe_unused three = 3;
90534-static unsigned long one_ul = 1;
90535-static int one_hundred = 100;
90536+static int __maybe_unused neg_one __read_only = -1;
90537+static int zero __read_only = 0;
90538+static int __maybe_unused one __read_only = 1;
90539+static int __maybe_unused two __read_only = 2;
90540+static int __maybe_unused three __read_only = 3;
90541+static unsigned long one_ul __read_only = 1;
90542+static int one_hundred __read_only = 100;
90543 #ifdef CONFIG_PRINTK
90544-static int ten_thousand = 10000;
90545+static int ten_thousand __read_only = 10000;
90546 #endif
90547
90548 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90549@@ -182,10 +180,8 @@ static int proc_taint(struct ctl_table *table, int write,
90550 void __user *buffer, size_t *lenp, loff_t *ppos);
90551 #endif
90552
90553-#ifdef CONFIG_PRINTK
90554 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90555 void __user *buffer, size_t *lenp, loff_t *ppos);
90556-#endif
90557
90558 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90559 void __user *buffer, size_t *lenp, loff_t *ppos);
90560@@ -216,6 +212,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90561
90562 #endif
90563
90564+extern struct ctl_table grsecurity_table[];
90565+
90566 static struct ctl_table kern_table[];
90567 static struct ctl_table vm_table[];
90568 static struct ctl_table fs_table[];
90569@@ -230,6 +228,20 @@ extern struct ctl_table epoll_table[];
90570 int sysctl_legacy_va_layout;
90571 #endif
90572
90573+#ifdef CONFIG_PAX_SOFTMODE
90574+static ctl_table pax_table[] = {
90575+ {
90576+ .procname = "softmode",
90577+ .data = &pax_softmode,
90578+ .maxlen = sizeof(unsigned int),
90579+ .mode = 0600,
90580+ .proc_handler = &proc_dointvec,
90581+ },
90582+
90583+ { }
90584+};
90585+#endif
90586+
90587 /* The default sysctl tables: */
90588
90589 static struct ctl_table sysctl_base_table[] = {
90590@@ -278,6 +290,22 @@ static int max_extfrag_threshold = 1000;
90591 #endif
90592
90593 static struct ctl_table kern_table[] = {
90594+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90595+ {
90596+ .procname = "grsecurity",
90597+ .mode = 0500,
90598+ .child = grsecurity_table,
90599+ },
90600+#endif
90601+
90602+#ifdef CONFIG_PAX_SOFTMODE
90603+ {
90604+ .procname = "pax",
90605+ .mode = 0500,
90606+ .child = pax_table,
90607+ },
90608+#endif
90609+
90610 {
90611 .procname = "sched_child_runs_first",
90612 .data = &sysctl_sched_child_runs_first,
90613@@ -640,7 +668,7 @@ static struct ctl_table kern_table[] = {
90614 .data = &modprobe_path,
90615 .maxlen = KMOD_PATH_LEN,
90616 .mode = 0644,
90617- .proc_handler = proc_dostring,
90618+ .proc_handler = proc_dostring_modpriv,
90619 },
90620 {
90621 .procname = "modules_disabled",
90622@@ -807,16 +835,20 @@ static struct ctl_table kern_table[] = {
90623 .extra1 = &zero,
90624 .extra2 = &one,
90625 },
90626+#endif
90627 {
90628 .procname = "kptr_restrict",
90629 .data = &kptr_restrict,
90630 .maxlen = sizeof(int),
90631 .mode = 0644,
90632 .proc_handler = proc_dointvec_minmax_sysadmin,
90633+#ifdef CONFIG_GRKERNSEC_HIDESYM
90634+ .extra1 = &two,
90635+#else
90636 .extra1 = &zero,
90637+#endif
90638 .extra2 = &two,
90639 },
90640-#endif
90641 {
90642 .procname = "ngroups_max",
90643 .data = &ngroups_max,
90644@@ -1061,10 +1093,17 @@ static struct ctl_table kern_table[] = {
90645 */
90646 {
90647 .procname = "perf_event_paranoid",
90648- .data = &sysctl_perf_event_paranoid,
90649- .maxlen = sizeof(sysctl_perf_event_paranoid),
90650+ .data = &sysctl_perf_event_legitimately_concerned,
90651+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90652 .mode = 0644,
90653- .proc_handler = proc_dointvec,
90654+ /* go ahead, be a hero */
90655+ .proc_handler = proc_dointvec_minmax_sysadmin,
90656+ .extra1 = &neg_one,
90657+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90658+ .extra2 = &three,
90659+#else
90660+ .extra2 = &two,
90661+#endif
90662 },
90663 {
90664 .procname = "perf_event_mlock_kb",
90665@@ -1335,6 +1374,13 @@ static struct ctl_table vm_table[] = {
90666 .proc_handler = proc_dointvec_minmax,
90667 .extra1 = &zero,
90668 },
90669+ {
90670+ .procname = "heap_stack_gap",
90671+ .data = &sysctl_heap_stack_gap,
90672+ .maxlen = sizeof(sysctl_heap_stack_gap),
90673+ .mode = 0644,
90674+ .proc_handler = proc_doulongvec_minmax,
90675+ },
90676 #else
90677 {
90678 .procname = "nr_trim_pages",
90679@@ -1799,6 +1845,16 @@ int proc_dostring(struct ctl_table *table, int write,
90680 buffer, lenp, ppos);
90681 }
90682
90683+int proc_dostring_modpriv(struct ctl_table *table, int write,
90684+ void __user *buffer, size_t *lenp, loff_t *ppos)
90685+{
90686+ if (write && !capable(CAP_SYS_MODULE))
90687+ return -EPERM;
90688+
90689+ return _proc_do_string(table->data, table->maxlen, write,
90690+ buffer, lenp, ppos);
90691+}
90692+
90693 static size_t proc_skip_spaces(char **buf)
90694 {
90695 size_t ret;
90696@@ -1904,6 +1960,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90697 len = strlen(tmp);
90698 if (len > *size)
90699 len = *size;
90700+ if (len > sizeof(tmp))
90701+ len = sizeof(tmp);
90702 if (copy_to_user(*buf, tmp, len))
90703 return -EFAULT;
90704 *size -= len;
90705@@ -2068,7 +2126,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90706 static int proc_taint(struct ctl_table *table, int write,
90707 void __user *buffer, size_t *lenp, loff_t *ppos)
90708 {
90709- struct ctl_table t;
90710+ ctl_table_no_const t;
90711 unsigned long tmptaint = get_taint();
90712 int err;
90713
90714@@ -2096,7 +2154,6 @@ static int proc_taint(struct ctl_table *table, int write,
90715 return err;
90716 }
90717
90718-#ifdef CONFIG_PRINTK
90719 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90720 void __user *buffer, size_t *lenp, loff_t *ppos)
90721 {
90722@@ -2105,7 +2162,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90723
90724 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90725 }
90726-#endif
90727
90728 struct do_proc_dointvec_minmax_conv_param {
90729 int *min;
90730@@ -2652,6 +2708,12 @@ int proc_dostring(struct ctl_table *table, int write,
90731 return -ENOSYS;
90732 }
90733
90734+int proc_dostring_modpriv(struct ctl_table *table, int write,
90735+ void __user *buffer, size_t *lenp, loff_t *ppos)
90736+{
90737+ return -ENOSYS;
90738+}
90739+
90740 int proc_dointvec(struct ctl_table *table, int write,
90741 void __user *buffer, size_t *lenp, loff_t *ppos)
90742 {
90743@@ -2708,5 +2770,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90744 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90745 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90746 EXPORT_SYMBOL(proc_dostring);
90747+EXPORT_SYMBOL(proc_dostring_modpriv);
90748 EXPORT_SYMBOL(proc_doulongvec_minmax);
90749 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90750diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90751index 13d2f7c..c93d0b0 100644
90752--- a/kernel/taskstats.c
90753+++ b/kernel/taskstats.c
90754@@ -28,9 +28,12 @@
90755 #include <linux/fs.h>
90756 #include <linux/file.h>
90757 #include <linux/pid_namespace.h>
90758+#include <linux/grsecurity.h>
90759 #include <net/genetlink.h>
90760 #include <linux/atomic.h>
90761
90762+extern int gr_is_taskstats_denied(int pid);
90763+
90764 /*
90765 * Maximum length of a cpumask that can be specified in
90766 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90767@@ -576,6 +579,9 @@ err:
90768
90769 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90770 {
90771+ if (gr_is_taskstats_denied(current->pid))
90772+ return -EACCES;
90773+
90774 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90775 return cmd_attr_register_cpumask(info);
90776 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90777diff --git a/kernel/time.c b/kernel/time.c
90778index 7c7964c..2a0d412 100644
90779--- a/kernel/time.c
90780+++ b/kernel/time.c
90781@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90782 return error;
90783
90784 if (tz) {
90785+ /* we log in do_settimeofday called below, so don't log twice
90786+ */
90787+ if (!tv)
90788+ gr_log_timechange();
90789+
90790 sys_tz = *tz;
90791 update_vsyscall_tz();
90792 if (firsttime) {
90793diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90794index 88c9c65..7497ebc 100644
90795--- a/kernel/time/alarmtimer.c
90796+++ b/kernel/time/alarmtimer.c
90797@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90798 struct platform_device *pdev;
90799 int error = 0;
90800 int i;
90801- struct k_clock alarm_clock = {
90802+ static struct k_clock alarm_clock = {
90803 .clock_getres = alarm_clock_getres,
90804 .clock_get = alarm_clock_get,
90805 .timer_create = alarm_timer_create,
90806diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90807index 5b40279..81e58db 100644
90808--- a/kernel/time/timekeeping.c
90809+++ b/kernel/time/timekeeping.c
90810@@ -15,6 +15,7 @@
90811 #include <linux/init.h>
90812 #include <linux/mm.h>
90813 #include <linux/sched.h>
90814+#include <linux/grsecurity.h>
90815 #include <linux/syscore_ops.h>
90816 #include <linux/clocksource.h>
90817 #include <linux/jiffies.h>
90818@@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
90819 if (!timespec_valid_strict(tv))
90820 return -EINVAL;
90821
90822+ gr_log_timechange();
90823+
90824 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90825 write_seqcount_begin(&timekeeper_seq);
90826
90827diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90828index 61ed862..3b52c65 100644
90829--- a/kernel/time/timer_list.c
90830+++ b/kernel/time/timer_list.c
90831@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90832
90833 static void print_name_offset(struct seq_file *m, void *sym)
90834 {
90835+#ifdef CONFIG_GRKERNSEC_HIDESYM
90836+ SEQ_printf(m, "<%p>", NULL);
90837+#else
90838 char symname[KSYM_NAME_LEN];
90839
90840 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90841 SEQ_printf(m, "<%pK>", sym);
90842 else
90843 SEQ_printf(m, "%s", symname);
90844+#endif
90845 }
90846
90847 static void
90848@@ -119,7 +123,11 @@ next_one:
90849 static void
90850 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90851 {
90852+#ifdef CONFIG_GRKERNSEC_HIDESYM
90853+ SEQ_printf(m, " .base: %p\n", NULL);
90854+#else
90855 SEQ_printf(m, " .base: %pK\n", base);
90856+#endif
90857 SEQ_printf(m, " .index: %d\n",
90858 base->index);
90859 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90860@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90861 {
90862 struct proc_dir_entry *pe;
90863
90864+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90865+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90866+#else
90867 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90868+#endif
90869 if (!pe)
90870 return -ENOMEM;
90871 return 0;
90872diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90873index 1fb08f2..ca4bb1e 100644
90874--- a/kernel/time/timer_stats.c
90875+++ b/kernel/time/timer_stats.c
90876@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90877 static unsigned long nr_entries;
90878 static struct entry entries[MAX_ENTRIES];
90879
90880-static atomic_t overflow_count;
90881+static atomic_unchecked_t overflow_count;
90882
90883 /*
90884 * The entries are in a hash-table, for fast lookup:
90885@@ -140,7 +140,7 @@ static void reset_entries(void)
90886 nr_entries = 0;
90887 memset(entries, 0, sizeof(entries));
90888 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90889- atomic_set(&overflow_count, 0);
90890+ atomic_set_unchecked(&overflow_count, 0);
90891 }
90892
90893 static struct entry *alloc_entry(void)
90894@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90895 if (likely(entry))
90896 entry->count++;
90897 else
90898- atomic_inc(&overflow_count);
90899+ atomic_inc_unchecked(&overflow_count);
90900
90901 out_unlock:
90902 raw_spin_unlock_irqrestore(lock, flags);
90903@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90904
90905 static void print_name_offset(struct seq_file *m, unsigned long addr)
90906 {
90907+#ifdef CONFIG_GRKERNSEC_HIDESYM
90908+ seq_printf(m, "<%p>", NULL);
90909+#else
90910 char symname[KSYM_NAME_LEN];
90911
90912 if (lookup_symbol_name(addr, symname) < 0)
90913- seq_printf(m, "<%p>", (void *)addr);
90914+ seq_printf(m, "<%pK>", (void *)addr);
90915 else
90916 seq_printf(m, "%s", symname);
90917+#endif
90918 }
90919
90920 static int tstats_show(struct seq_file *m, void *v)
90921@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90922
90923 seq_puts(m, "Timer Stats Version: v0.3\n");
90924 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90925- if (atomic_read(&overflow_count))
90926- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90927+ if (atomic_read_unchecked(&overflow_count))
90928+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90929 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90930
90931 for (i = 0; i < nr_entries; i++) {
90932@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90933 {
90934 struct proc_dir_entry *pe;
90935
90936+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90937+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90938+#else
90939 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90940+#endif
90941 if (!pe)
90942 return -ENOMEM;
90943 return 0;
90944diff --git a/kernel/timer.c b/kernel/timer.c
90945index accfd24..e00f0c0 100644
90946--- a/kernel/timer.c
90947+++ b/kernel/timer.c
90948@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
90949 /*
90950 * This function runs timers and the timer-tq in bottom half context.
90951 */
90952-static void run_timer_softirq(struct softirq_action *h)
90953+static __latent_entropy void run_timer_softirq(void)
90954 {
90955 struct tvec_base *base = __this_cpu_read(tvec_bases);
90956
90957@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
90958 *
90959 * In all cases the return value is guaranteed to be non-negative.
90960 */
90961-signed long __sched schedule_timeout(signed long timeout)
90962+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90963 {
90964 struct timer_list timer;
90965 unsigned long expire;
90966diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90967index b418cb0..f879a3d 100644
90968--- a/kernel/trace/blktrace.c
90969+++ b/kernel/trace/blktrace.c
90970@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90971 struct blk_trace *bt = filp->private_data;
90972 char buf[16];
90973
90974- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90975+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90976
90977 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90978 }
90979@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90980 return 1;
90981
90982 bt = buf->chan->private_data;
90983- atomic_inc(&bt->dropped);
90984+ atomic_inc_unchecked(&bt->dropped);
90985 return 0;
90986 }
90987
90988@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90989
90990 bt->dir = dir;
90991 bt->dev = dev;
90992- atomic_set(&bt->dropped, 0);
90993+ atomic_set_unchecked(&bt->dropped, 0);
90994 INIT_LIST_HEAD(&bt->running_list);
90995
90996 ret = -EIO;
90997diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90998index cd7f76d..553c805 100644
90999--- a/kernel/trace/ftrace.c
91000+++ b/kernel/trace/ftrace.c
91001@@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
91002 if (unlikely(ftrace_disabled))
91003 return 0;
91004
91005+ ret = ftrace_arch_code_modify_prepare();
91006+ FTRACE_WARN_ON(ret);
91007+ if (ret)
91008+ return 0;
91009+
91010 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
91011+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
91012 if (ret) {
91013 ftrace_bug(ret, ip);
91014- return 0;
91015 }
91016- return 1;
91017+ return ret ? 0 : 1;
91018 }
91019
91020 /*
91021@@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
91022 if (!count)
91023 return 0;
91024
91025+ pax_open_kernel();
91026 sort(start, count, sizeof(*start),
91027 ftrace_cmp_ips, ftrace_swap_ips);
91028+ pax_close_kernel();
91029
91030 start_pg = ftrace_allocate_pages(count);
91031 if (!start_pg)
91032@@ -4909,8 +4916,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
91033 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
91034
91035 static int ftrace_graph_active;
91036-static struct notifier_block ftrace_suspend_notifier;
91037-
91038 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
91039 {
91040 return 0;
91041@@ -5086,6 +5091,10 @@ static void update_function_graph_func(void)
91042 ftrace_graph_entry = ftrace_graph_entry_test;
91043 }
91044
91045+static struct notifier_block ftrace_suspend_notifier = {
91046+ .notifier_call = ftrace_suspend_notifier_call
91047+};
91048+
91049 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91050 trace_func_graph_ent_t entryfunc)
91051 {
91052@@ -5099,7 +5108,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91053 goto out;
91054 }
91055
91056- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
91057 register_pm_notifier(&ftrace_suspend_notifier);
91058
91059 ftrace_graph_active++;
91060diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
91061index fc4da2d..f3e800b 100644
91062--- a/kernel/trace/ring_buffer.c
91063+++ b/kernel/trace/ring_buffer.c
91064@@ -352,9 +352,9 @@ struct buffer_data_page {
91065 */
91066 struct buffer_page {
91067 struct list_head list; /* list of buffer pages */
91068- local_t write; /* index for next write */
91069+ local_unchecked_t write; /* index for next write */
91070 unsigned read; /* index for next read */
91071- local_t entries; /* entries on this page */
91072+ local_unchecked_t entries; /* entries on this page */
91073 unsigned long real_end; /* real end of data */
91074 struct buffer_data_page *page; /* Actual data page */
91075 };
91076@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
91077 unsigned long last_overrun;
91078 local_t entries_bytes;
91079 local_t entries;
91080- local_t overrun;
91081- local_t commit_overrun;
91082+ local_unchecked_t overrun;
91083+ local_unchecked_t commit_overrun;
91084 local_t dropped_events;
91085 local_t committing;
91086 local_t commits;
91087@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91088 *
91089 * We add a counter to the write field to denote this.
91090 */
91091- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
91092- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
91093+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
91094+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
91095
91096 /*
91097 * Just make sure we have seen our old_write and synchronize
91098@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91099 * cmpxchg to only update if an interrupt did not already
91100 * do it for us. If the cmpxchg fails, we don't care.
91101 */
91102- (void)local_cmpxchg(&next_page->write, old_write, val);
91103- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
91104+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
91105+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
91106
91107 /*
91108 * No need to worry about races with clearing out the commit.
91109@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
91110
91111 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
91112 {
91113- return local_read(&bpage->entries) & RB_WRITE_MASK;
91114+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
91115 }
91116
91117 static inline unsigned long rb_page_write(struct buffer_page *bpage)
91118 {
91119- return local_read(&bpage->write) & RB_WRITE_MASK;
91120+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
91121 }
91122
91123 static int
91124@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
91125 * bytes consumed in ring buffer from here.
91126 * Increment overrun to account for the lost events.
91127 */
91128- local_add(page_entries, &cpu_buffer->overrun);
91129+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
91130 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91131 }
91132
91133@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
91134 * it is our responsibility to update
91135 * the counters.
91136 */
91137- local_add(entries, &cpu_buffer->overrun);
91138+ local_add_unchecked(entries, &cpu_buffer->overrun);
91139 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91140
91141 /*
91142@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91143 if (tail == BUF_PAGE_SIZE)
91144 tail_page->real_end = 0;
91145
91146- local_sub(length, &tail_page->write);
91147+ local_sub_unchecked(length, &tail_page->write);
91148 return;
91149 }
91150
91151@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91152 rb_event_set_padding(event);
91153
91154 /* Set the write back to the previous setting */
91155- local_sub(length, &tail_page->write);
91156+ local_sub_unchecked(length, &tail_page->write);
91157 return;
91158 }
91159
91160@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91161
91162 /* Set write to end of buffer */
91163 length = (tail + length) - BUF_PAGE_SIZE;
91164- local_sub(length, &tail_page->write);
91165+ local_sub_unchecked(length, &tail_page->write);
91166 }
91167
91168 /*
91169@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91170 * about it.
91171 */
91172 if (unlikely(next_page == commit_page)) {
91173- local_inc(&cpu_buffer->commit_overrun);
91174+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91175 goto out_reset;
91176 }
91177
91178@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91179 cpu_buffer->tail_page) &&
91180 (cpu_buffer->commit_page ==
91181 cpu_buffer->reader_page))) {
91182- local_inc(&cpu_buffer->commit_overrun);
91183+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91184 goto out_reset;
91185 }
91186 }
91187@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91188 length += RB_LEN_TIME_EXTEND;
91189
91190 tail_page = cpu_buffer->tail_page;
91191- write = local_add_return(length, &tail_page->write);
91192+ write = local_add_return_unchecked(length, &tail_page->write);
91193
91194 /* set write to only the index of the write */
91195 write &= RB_WRITE_MASK;
91196@@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91197 kmemcheck_annotate_bitfield(event, bitfield);
91198 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91199
91200- local_inc(&tail_page->entries);
91201+ local_inc_unchecked(&tail_page->entries);
91202
91203 /*
91204 * If this is the first commit on the page, then update
91205@@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91206
91207 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91208 unsigned long write_mask =
91209- local_read(&bpage->write) & ~RB_WRITE_MASK;
91210+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91211 unsigned long event_length = rb_event_length(event);
91212 /*
91213 * This is on the tail page. It is possible that
91214@@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91215 */
91216 old_index += write_mask;
91217 new_index += write_mask;
91218- index = local_cmpxchg(&bpage->write, old_index, new_index);
91219+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91220 if (index == old_index) {
91221 /* update counters */
91222 local_sub(event_length, &cpu_buffer->entries_bytes);
91223@@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91224
91225 /* Do the likely case first */
91226 if (likely(bpage->page == (void *)addr)) {
91227- local_dec(&bpage->entries);
91228+ local_dec_unchecked(&bpage->entries);
91229 return;
91230 }
91231
91232@@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91233 start = bpage;
91234 do {
91235 if (bpage->page == (void *)addr) {
91236- local_dec(&bpage->entries);
91237+ local_dec_unchecked(&bpage->entries);
91238 return;
91239 }
91240 rb_inc_page(cpu_buffer, &bpage);
91241@@ -3146,7 +3146,7 @@ static inline unsigned long
91242 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91243 {
91244 return local_read(&cpu_buffer->entries) -
91245- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91246+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91247 }
91248
91249 /**
91250@@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91251 return 0;
91252
91253 cpu_buffer = buffer->buffers[cpu];
91254- ret = local_read(&cpu_buffer->overrun);
91255+ ret = local_read_unchecked(&cpu_buffer->overrun);
91256
91257 return ret;
91258 }
91259@@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91260 return 0;
91261
91262 cpu_buffer = buffer->buffers[cpu];
91263- ret = local_read(&cpu_buffer->commit_overrun);
91264+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91265
91266 return ret;
91267 }
91268@@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91269 /* if you care about this being correct, lock the buffer */
91270 for_each_buffer_cpu(buffer, cpu) {
91271 cpu_buffer = buffer->buffers[cpu];
91272- overruns += local_read(&cpu_buffer->overrun);
91273+ overruns += local_read_unchecked(&cpu_buffer->overrun);
91274 }
91275
91276 return overruns;
91277@@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91278 /*
91279 * Reset the reader page to size zero.
91280 */
91281- local_set(&cpu_buffer->reader_page->write, 0);
91282- local_set(&cpu_buffer->reader_page->entries, 0);
91283+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91284+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91285 local_set(&cpu_buffer->reader_page->page->commit, 0);
91286 cpu_buffer->reader_page->real_end = 0;
91287
91288@@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91289 * want to compare with the last_overrun.
91290 */
91291 smp_mb();
91292- overwrite = local_read(&(cpu_buffer->overrun));
91293+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91294
91295 /*
91296 * Here's the tricky part.
91297@@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91298
91299 cpu_buffer->head_page
91300 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91301- local_set(&cpu_buffer->head_page->write, 0);
91302- local_set(&cpu_buffer->head_page->entries, 0);
91303+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
91304+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91305 local_set(&cpu_buffer->head_page->page->commit, 0);
91306
91307 cpu_buffer->head_page->read = 0;
91308@@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91309
91310 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91311 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91312- local_set(&cpu_buffer->reader_page->write, 0);
91313- local_set(&cpu_buffer->reader_page->entries, 0);
91314+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91315+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91316 local_set(&cpu_buffer->reader_page->page->commit, 0);
91317 cpu_buffer->reader_page->read = 0;
91318
91319 local_set(&cpu_buffer->entries_bytes, 0);
91320- local_set(&cpu_buffer->overrun, 0);
91321- local_set(&cpu_buffer->commit_overrun, 0);
91322+ local_set_unchecked(&cpu_buffer->overrun, 0);
91323+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91324 local_set(&cpu_buffer->dropped_events, 0);
91325 local_set(&cpu_buffer->entries, 0);
91326 local_set(&cpu_buffer->committing, 0);
91327@@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91328 rb_init_page(bpage);
91329 bpage = reader->page;
91330 reader->page = *data_page;
91331- local_set(&reader->write, 0);
91332- local_set(&reader->entries, 0);
91333+ local_set_unchecked(&reader->write, 0);
91334+ local_set_unchecked(&reader->entries, 0);
91335 reader->read = 0;
91336 *data_page = bpage;
91337
91338diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91339index 24c1f23..781fd73f 100644
91340--- a/kernel/trace/trace.c
91341+++ b/kernel/trace/trace.c
91342@@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91343 return 0;
91344 }
91345
91346-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91347+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91348 {
91349 /* do nothing if flag is already set */
91350 if (!!(trace_flags & mask) == !!enabled)
91351diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91352index 02b592f..f971546 100644
91353--- a/kernel/trace/trace.h
91354+++ b/kernel/trace/trace.h
91355@@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
91356 void trace_printk_init_buffers(void);
91357 void trace_printk_start_comm(void);
91358 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91359-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91360+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91361
91362 /*
91363 * Normal trace_printk() and friends allocates special buffers
91364diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91365index 26dc348..8708ca7 100644
91366--- a/kernel/trace/trace_clock.c
91367+++ b/kernel/trace/trace_clock.c
91368@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
91369 return now;
91370 }
91371
91372-static atomic64_t trace_counter;
91373+static atomic64_unchecked_t trace_counter;
91374
91375 /*
91376 * trace_clock_counter(): simply an atomic counter.
91377@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
91378 */
91379 u64 notrace trace_clock_counter(void)
91380 {
91381- return atomic64_add_return(1, &trace_counter);
91382+ return atomic64_inc_return_unchecked(&trace_counter);
91383 }
91384diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91385index 7b16d40..1b2875d 100644
91386--- a/kernel/trace/trace_events.c
91387+++ b/kernel/trace/trace_events.c
91388@@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91389 return 0;
91390 }
91391
91392-struct ftrace_module_file_ops;
91393 static void __add_event_to_tracers(struct ftrace_event_call *call);
91394
91395 /* Add an additional event_call dynamically */
91396diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91397index 0abd9b8..6a663a2 100644
91398--- a/kernel/trace/trace_mmiotrace.c
91399+++ b/kernel/trace/trace_mmiotrace.c
91400@@ -24,7 +24,7 @@ struct header_iter {
91401 static struct trace_array *mmio_trace_array;
91402 static bool overrun_detected;
91403 static unsigned long prev_overruns;
91404-static atomic_t dropped_count;
91405+static atomic_unchecked_t dropped_count;
91406
91407 static void mmio_reset_data(struct trace_array *tr)
91408 {
91409@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91410
91411 static unsigned long count_overruns(struct trace_iterator *iter)
91412 {
91413- unsigned long cnt = atomic_xchg(&dropped_count, 0);
91414+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91415 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91416
91417 if (over > prev_overruns)
91418@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91419 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91420 sizeof(*entry), 0, pc);
91421 if (!event) {
91422- atomic_inc(&dropped_count);
91423+ atomic_inc_unchecked(&dropped_count);
91424 return;
91425 }
91426 entry = ring_buffer_event_data(event);
91427@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91428 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91429 sizeof(*entry), 0, pc);
91430 if (!event) {
91431- atomic_inc(&dropped_count);
91432+ atomic_inc_unchecked(&dropped_count);
91433 return;
91434 }
91435 entry = ring_buffer_event_data(event);
91436diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91437index ed32284..884d6c3 100644
91438--- a/kernel/trace/trace_output.c
91439+++ b/kernel/trace/trace_output.c
91440@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91441
91442 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91443 if (!IS_ERR(p)) {
91444- p = mangle_path(s->buffer + s->len, p, "\n");
91445+ p = mangle_path(s->buffer + s->len, p, "\n\\");
91446 if (p) {
91447 s->len = p - s->buffer;
91448 return 1;
91449@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
91450 goto out;
91451 }
91452
91453+ pax_open_kernel();
91454 if (event->funcs->trace == NULL)
91455- event->funcs->trace = trace_nop_print;
91456+ *(void **)&event->funcs->trace = trace_nop_print;
91457 if (event->funcs->raw == NULL)
91458- event->funcs->raw = trace_nop_print;
91459+ *(void **)&event->funcs->raw = trace_nop_print;
91460 if (event->funcs->hex == NULL)
91461- event->funcs->hex = trace_nop_print;
91462+ *(void **)&event->funcs->hex = trace_nop_print;
91463 if (event->funcs->binary == NULL)
91464- event->funcs->binary = trace_nop_print;
91465+ *(void **)&event->funcs->binary = trace_nop_print;
91466+ pax_close_kernel();
91467
91468 key = event->type & (EVENT_HASHSIZE - 1);
91469
91470diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91471index e6be585..d73ae5e 100644
91472--- a/kernel/trace/trace_stack.c
91473+++ b/kernel/trace/trace_stack.c
91474@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91475 return;
91476
91477 /* we do not handle interrupt stacks yet */
91478- if (!object_is_on_stack(stack))
91479+ if (!object_starts_on_stack(stack))
91480 return;
91481
91482 local_irq_save(flags);
91483diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91484index 80a57af..7f5a7ff 100644
91485--- a/kernel/user_namespace.c
91486+++ b/kernel/user_namespace.c
91487@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91488 !kgid_has_mapping(parent_ns, group))
91489 return -EPERM;
91490
91491+#ifdef CONFIG_GRKERNSEC
91492+ /*
91493+ * This doesn't really inspire confidence:
91494+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91495+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91496+ * Increases kernel attack surface in areas developers
91497+ * previously cared little about ("low importance due
91498+ * to requiring "root" capability")
91499+ * To be removed when this code receives *proper* review
91500+ */
91501+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91502+ !capable(CAP_SETGID))
91503+ return -EPERM;
91504+#endif
91505+
91506 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91507 if (!ns)
91508 return -ENOMEM;
91509@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91510 if (atomic_read(&current->mm->mm_users) > 1)
91511 return -EINVAL;
91512
91513- if (current->fs->users != 1)
91514+ if (atomic_read(&current->fs->users) != 1)
91515 return -EINVAL;
91516
91517 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91518diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91519index 4f69f9a..7c6f8f8 100644
91520--- a/kernel/utsname_sysctl.c
91521+++ b/kernel/utsname_sysctl.c
91522@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91523 static int proc_do_uts_string(ctl_table *table, int write,
91524 void __user *buffer, size_t *lenp, loff_t *ppos)
91525 {
91526- struct ctl_table uts_table;
91527+ ctl_table_no_const uts_table;
91528 int r;
91529 memcpy(&uts_table, table, sizeof(uts_table));
91530 uts_table.data = get_uts(table, write);
91531diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91532index 4431610..4265616 100644
91533--- a/kernel/watchdog.c
91534+++ b/kernel/watchdog.c
91535@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91536 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91537 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91538
91539-static struct smp_hotplug_thread watchdog_threads = {
91540+static struct smp_hotplug_thread watchdog_threads __read_only = {
91541 .store = &softlockup_watchdog,
91542 .thread_should_run = watchdog_should_run,
91543 .thread_fn = watchdog,
91544diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91545index 193e977..26dd63f 100644
91546--- a/kernel/workqueue.c
91547+++ b/kernel/workqueue.c
91548@@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
91549 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91550 worker_flags |= WORKER_REBOUND;
91551 worker_flags &= ~WORKER_UNBOUND;
91552- ACCESS_ONCE(worker->flags) = worker_flags;
91553+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
91554 }
91555
91556 spin_unlock_irq(&pool->lock);
91557diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91558index a48abea..e108def 100644
91559--- a/lib/Kconfig.debug
91560+++ b/lib/Kconfig.debug
91561@@ -854,7 +854,7 @@ config DEBUG_MUTEXES
91562
91563 config DEBUG_WW_MUTEX_SLOWPATH
91564 bool "Wait/wound mutex debugging: Slowpath testing"
91565- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91566+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91567 select DEBUG_LOCK_ALLOC
91568 select DEBUG_SPINLOCK
91569 select DEBUG_MUTEXES
91570@@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91571
91572 config DEBUG_LOCK_ALLOC
91573 bool "Lock debugging: detect incorrect freeing of live locks"
91574- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91575+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91576 select DEBUG_SPINLOCK
91577 select DEBUG_MUTEXES
91578 select LOCKDEP
91579@@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
91580
91581 config PROVE_LOCKING
91582 bool "Lock debugging: prove locking correctness"
91583- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91584+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91585 select LOCKDEP
91586 select DEBUG_SPINLOCK
91587 select DEBUG_MUTEXES
91588@@ -932,7 +932,7 @@ config LOCKDEP
91589
91590 config LOCK_STAT
91591 bool "Lock usage statistics"
91592- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91593+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91594 select LOCKDEP
91595 select DEBUG_SPINLOCK
91596 select DEBUG_MUTEXES
91597@@ -1394,6 +1394,7 @@ config LATENCYTOP
91598 depends on DEBUG_KERNEL
91599 depends on STACKTRACE_SUPPORT
91600 depends on PROC_FS
91601+ depends on !GRKERNSEC_HIDESYM
91602 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91603 select KALLSYMS
91604 select KALLSYMS_ALL
91605@@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91606 config DEBUG_STRICT_USER_COPY_CHECKS
91607 bool "Strict user copy size checks"
91608 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91609- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91610+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91611 help
91612 Enabling this option turns a certain set of sanity checks for user
91613 copy operations into compile time failures.
91614@@ -1529,7 +1530,7 @@ endmenu # runtime tests
91615
91616 config PROVIDE_OHCI1394_DMA_INIT
91617 bool "Remote debugging over FireWire early on boot"
91618- depends on PCI && X86
91619+ depends on PCI && X86 && !GRKERNSEC
91620 help
91621 If you want to debug problems which hang or crash the kernel early
91622 on boot and the crashing machine has a FireWire port, you can use
91623diff --git a/lib/Makefile b/lib/Makefile
91624index 48140e3..de854e5 100644
91625--- a/lib/Makefile
91626+++ b/lib/Makefile
91627@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91628 obj-$(CONFIG_BTREE) += btree.o
91629 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91630 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91631-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91632+obj-y += list_debug.o
91633 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91634
91635 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91636diff --git a/lib/average.c b/lib/average.c
91637index 114d1be..ab0350c 100644
91638--- a/lib/average.c
91639+++ b/lib/average.c
91640@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91641 {
91642 unsigned long internal = ACCESS_ONCE(avg->internal);
91643
91644- ACCESS_ONCE(avg->internal) = internal ?
91645+ ACCESS_ONCE_RW(avg->internal) = internal ?
91646 (((internal << avg->weight) - internal) +
91647 (val << avg->factor)) >> avg->weight :
91648 (val << avg->factor);
91649diff --git a/lib/bitmap.c b/lib/bitmap.c
91650index 06f7e4f..f3cf2b0 100644
91651--- a/lib/bitmap.c
91652+++ b/lib/bitmap.c
91653@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91654 {
91655 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91656 u32 chunk;
91657- const char __user __force *ubuf = (const char __user __force *)buf;
91658+ const char __user *ubuf = (const char __force_user *)buf;
91659
91660 bitmap_zero(maskp, nmaskbits);
91661
91662@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91663 {
91664 if (!access_ok(VERIFY_READ, ubuf, ulen))
91665 return -EFAULT;
91666- return __bitmap_parse((const char __force *)ubuf,
91667+ return __bitmap_parse((const char __force_kernel *)ubuf,
91668 ulen, 1, maskp, nmaskbits);
91669
91670 }
91671@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91672 {
91673 unsigned a, b;
91674 int c, old_c, totaldigits;
91675- const char __user __force *ubuf = (const char __user __force *)buf;
91676+ const char __user *ubuf = (const char __force_user *)buf;
91677 int exp_digit, in_range;
91678
91679 totaldigits = c = 0;
91680@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91681 {
91682 if (!access_ok(VERIFY_READ, ubuf, ulen))
91683 return -EFAULT;
91684- return __bitmap_parselist((const char __force *)ubuf,
91685+ return __bitmap_parselist((const char __force_kernel *)ubuf,
91686 ulen, 1, maskp, nmaskbits);
91687 }
91688 EXPORT_SYMBOL(bitmap_parselist_user);
91689diff --git a/lib/bug.c b/lib/bug.c
91690index 1686034..a9c00c8 100644
91691--- a/lib/bug.c
91692+++ b/lib/bug.c
91693@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91694 return BUG_TRAP_TYPE_NONE;
91695
91696 bug = find_bug(bugaddr);
91697+ if (!bug)
91698+ return BUG_TRAP_TYPE_NONE;
91699
91700 file = NULL;
91701 line = 0;
91702diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91703index e0731c3..ad66444 100644
91704--- a/lib/debugobjects.c
91705+++ b/lib/debugobjects.c
91706@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91707 if (limit > 4)
91708 return;
91709
91710- is_on_stack = object_is_on_stack(addr);
91711+ is_on_stack = object_starts_on_stack(addr);
91712 if (is_on_stack == onstack)
91713 return;
91714
91715diff --git a/lib/devres.c b/lib/devres.c
91716index 8235331..5881053 100644
91717--- a/lib/devres.c
91718+++ b/lib/devres.c
91719@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
91720 void devm_iounmap(struct device *dev, void __iomem *addr)
91721 {
91722 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
91723- (void *)addr));
91724+ (void __force *)addr));
91725 iounmap(addr);
91726 }
91727 EXPORT_SYMBOL(devm_iounmap);
91728@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
91729 {
91730 ioport_unmap(addr);
91731 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
91732- devm_ioport_map_match, (void *)addr));
91733+ devm_ioport_map_match, (void __force *)addr));
91734 }
91735 EXPORT_SYMBOL(devm_ioport_unmap);
91736 #endif /* CONFIG_HAS_IOPORT */
91737diff --git a/lib/div64.c b/lib/div64.c
91738index 4382ad7..08aa558 100644
91739--- a/lib/div64.c
91740+++ b/lib/div64.c
91741@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91742 EXPORT_SYMBOL(__div64_32);
91743
91744 #ifndef div_s64_rem
91745-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91746+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91747 {
91748 u64 quotient;
91749
91750@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91751 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91752 */
91753 #ifndef div64_u64
91754-u64 div64_u64(u64 dividend, u64 divisor)
91755+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91756 {
91757 u32 high = divisor >> 32;
91758 u64 quot;
91759diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91760index 98f2d7e..899da5c 100644
91761--- a/lib/dma-debug.c
91762+++ b/lib/dma-debug.c
91763@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91764
91765 void dma_debug_add_bus(struct bus_type *bus)
91766 {
91767- struct notifier_block *nb;
91768+ notifier_block_no_const *nb;
91769
91770 if (global_disable)
91771 return;
91772@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91773
91774 static void check_for_stack(struct device *dev, void *addr)
91775 {
91776- if (object_is_on_stack(addr))
91777+ if (object_starts_on_stack(addr))
91778 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91779 "stack [addr=%p]\n", addr);
91780 }
91781diff --git a/lib/hash.c b/lib/hash.c
91782index fea973f..386626f 100644
91783--- a/lib/hash.c
91784+++ b/lib/hash.c
91785@@ -14,7 +14,7 @@
91786 #include <linux/hash.h>
91787 #include <linux/cache.h>
91788
91789-static struct fast_hash_ops arch_hash_ops __read_mostly = {
91790+static struct fast_hash_ops arch_hash_ops __read_only = {
91791 .hash = jhash,
91792 .hash2 = jhash2,
91793 };
91794diff --git a/lib/inflate.c b/lib/inflate.c
91795index 013a761..c28f3fc 100644
91796--- a/lib/inflate.c
91797+++ b/lib/inflate.c
91798@@ -269,7 +269,7 @@ static void free(void *where)
91799 malloc_ptr = free_mem_ptr;
91800 }
91801 #else
91802-#define malloc(a) kmalloc(a, GFP_KERNEL)
91803+#define malloc(a) kmalloc((a), GFP_KERNEL)
91804 #define free(a) kfree(a)
91805 #endif
91806
91807diff --git a/lib/ioremap.c b/lib/ioremap.c
91808index 0c9216c..863bd89 100644
91809--- a/lib/ioremap.c
91810+++ b/lib/ioremap.c
91811@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91812 unsigned long next;
91813
91814 phys_addr -= addr;
91815- pmd = pmd_alloc(&init_mm, pud, addr);
91816+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91817 if (!pmd)
91818 return -ENOMEM;
91819 do {
91820@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91821 unsigned long next;
91822
91823 phys_addr -= addr;
91824- pud = pud_alloc(&init_mm, pgd, addr);
91825+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91826 if (!pud)
91827 return -ENOMEM;
91828 do {
91829diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91830index bd2bea9..6b3c95e 100644
91831--- a/lib/is_single_threaded.c
91832+++ b/lib/is_single_threaded.c
91833@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91834 struct task_struct *p, *t;
91835 bool ret;
91836
91837+ if (!mm)
91838+ return true;
91839+
91840 if (atomic_read(&task->signal->live) != 1)
91841 return false;
91842
91843diff --git a/lib/kobject.c b/lib/kobject.c
91844index cb14aea..8c53cdb 100644
91845--- a/lib/kobject.c
91846+++ b/lib/kobject.c
91847@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91848
91849
91850 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91851-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91852+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91853
91854-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91855+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91856 {
91857 enum kobj_ns_type type = ops->type;
91858 int error;
91859diff --git a/lib/list_debug.c b/lib/list_debug.c
91860index c24c2f7..f0296f4 100644
91861--- a/lib/list_debug.c
91862+++ b/lib/list_debug.c
91863@@ -11,7 +11,9 @@
91864 #include <linux/bug.h>
91865 #include <linux/kernel.h>
91866 #include <linux/rculist.h>
91867+#include <linux/mm.h>
91868
91869+#ifdef CONFIG_DEBUG_LIST
91870 /*
91871 * Insert a new entry between two known consecutive entries.
91872 *
91873@@ -19,21 +21,40 @@
91874 * the prev/next entries already!
91875 */
91876
91877+static bool __list_add_debug(struct list_head *new,
91878+ struct list_head *prev,
91879+ struct list_head *next)
91880+{
91881+ if (unlikely(next->prev != prev)) {
91882+ printk(KERN_ERR "list_add corruption. next->prev should be "
91883+ "prev (%p), but was %p. (next=%p).\n",
91884+ prev, next->prev, next);
91885+ BUG();
91886+ return false;
91887+ }
91888+ if (unlikely(prev->next != next)) {
91889+ printk(KERN_ERR "list_add corruption. prev->next should be "
91890+ "next (%p), but was %p. (prev=%p).\n",
91891+ next, prev->next, prev);
91892+ BUG();
91893+ return false;
91894+ }
91895+ if (unlikely(new == prev || new == next)) {
91896+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91897+ new, prev, next);
91898+ BUG();
91899+ return false;
91900+ }
91901+ return true;
91902+}
91903+
91904 void __list_add(struct list_head *new,
91905- struct list_head *prev,
91906- struct list_head *next)
91907+ struct list_head *prev,
91908+ struct list_head *next)
91909 {
91910- WARN(next->prev != prev,
91911- "list_add corruption. next->prev should be "
91912- "prev (%p), but was %p. (next=%p).\n",
91913- prev, next->prev, next);
91914- WARN(prev->next != next,
91915- "list_add corruption. prev->next should be "
91916- "next (%p), but was %p. (prev=%p).\n",
91917- next, prev->next, prev);
91918- WARN(new == prev || new == next,
91919- "list_add double add: new=%p, prev=%p, next=%p.\n",
91920- new, prev, next);
91921+ if (!__list_add_debug(new, prev, next))
91922+ return;
91923+
91924 next->prev = new;
91925 new->next = next;
91926 new->prev = prev;
91927@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91928 }
91929 EXPORT_SYMBOL(__list_add);
91930
91931-void __list_del_entry(struct list_head *entry)
91932+static bool __list_del_entry_debug(struct list_head *entry)
91933 {
91934 struct list_head *prev, *next;
91935
91936 prev = entry->prev;
91937 next = entry->next;
91938
91939- if (WARN(next == LIST_POISON1,
91940- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91941- entry, LIST_POISON1) ||
91942- WARN(prev == LIST_POISON2,
91943- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91944- entry, LIST_POISON2) ||
91945- WARN(prev->next != entry,
91946- "list_del corruption. prev->next should be %p, "
91947- "but was %p\n", entry, prev->next) ||
91948- WARN(next->prev != entry,
91949- "list_del corruption. next->prev should be %p, "
91950- "but was %p\n", entry, next->prev))
91951+ if (unlikely(next == LIST_POISON1)) {
91952+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91953+ entry, LIST_POISON1);
91954+ BUG();
91955+ return false;
91956+ }
91957+ if (unlikely(prev == LIST_POISON2)) {
91958+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91959+ entry, LIST_POISON2);
91960+ BUG();
91961+ return false;
91962+ }
91963+ if (unlikely(entry->prev->next != entry)) {
91964+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91965+ "but was %p\n", entry, prev->next);
91966+ BUG();
91967+ return false;
91968+ }
91969+ if (unlikely(entry->next->prev != entry)) {
91970+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91971+ "but was %p\n", entry, next->prev);
91972+ BUG();
91973+ return false;
91974+ }
91975+ return true;
91976+}
91977+
91978+void __list_del_entry(struct list_head *entry)
91979+{
91980+ if (!__list_del_entry_debug(entry))
91981 return;
91982
91983- __list_del(prev, next);
91984+ __list_del(entry->prev, entry->next);
91985 }
91986 EXPORT_SYMBOL(__list_del_entry);
91987
91988@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91989 void __list_add_rcu(struct list_head *new,
91990 struct list_head *prev, struct list_head *next)
91991 {
91992- WARN(next->prev != prev,
91993- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91994- prev, next->prev, next);
91995- WARN(prev->next != next,
91996- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91997- next, prev->next, prev);
91998+ if (!__list_add_debug(new, prev, next))
91999+ return;
92000+
92001 new->next = next;
92002 new->prev = prev;
92003 rcu_assign_pointer(list_next_rcu(prev), new);
92004 next->prev = new;
92005 }
92006 EXPORT_SYMBOL(__list_add_rcu);
92007+#endif
92008+
92009+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
92010+{
92011+#ifdef CONFIG_DEBUG_LIST
92012+ if (!__list_add_debug(new, prev, next))
92013+ return;
92014+#endif
92015+
92016+ pax_open_kernel();
92017+ next->prev = new;
92018+ new->next = next;
92019+ new->prev = prev;
92020+ prev->next = new;
92021+ pax_close_kernel();
92022+}
92023+EXPORT_SYMBOL(__pax_list_add);
92024+
92025+void pax_list_del(struct list_head *entry)
92026+{
92027+#ifdef CONFIG_DEBUG_LIST
92028+ if (!__list_del_entry_debug(entry))
92029+ return;
92030+#endif
92031+
92032+ pax_open_kernel();
92033+ __list_del(entry->prev, entry->next);
92034+ entry->next = LIST_POISON1;
92035+ entry->prev = LIST_POISON2;
92036+ pax_close_kernel();
92037+}
92038+EXPORT_SYMBOL(pax_list_del);
92039+
92040+void pax_list_del_init(struct list_head *entry)
92041+{
92042+ pax_open_kernel();
92043+ __list_del(entry->prev, entry->next);
92044+ INIT_LIST_HEAD(entry);
92045+ pax_close_kernel();
92046+}
92047+EXPORT_SYMBOL(pax_list_del_init);
92048+
92049+void __pax_list_add_rcu(struct list_head *new,
92050+ struct list_head *prev, struct list_head *next)
92051+{
92052+#ifdef CONFIG_DEBUG_LIST
92053+ if (!__list_add_debug(new, prev, next))
92054+ return;
92055+#endif
92056+
92057+ pax_open_kernel();
92058+ new->next = next;
92059+ new->prev = prev;
92060+ rcu_assign_pointer(list_next_rcu(prev), new);
92061+ next->prev = new;
92062+ pax_close_kernel();
92063+}
92064+EXPORT_SYMBOL(__pax_list_add_rcu);
92065+
92066+void pax_list_del_rcu(struct list_head *entry)
92067+{
92068+#ifdef CONFIG_DEBUG_LIST
92069+ if (!__list_del_entry_debug(entry))
92070+ return;
92071+#endif
92072+
92073+ pax_open_kernel();
92074+ __list_del(entry->prev, entry->next);
92075+ entry->next = LIST_POISON1;
92076+ entry->prev = LIST_POISON2;
92077+ pax_close_kernel();
92078+}
92079+EXPORT_SYMBOL(pax_list_del_rcu);
92080diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
92081index 963b703..438bc51 100644
92082--- a/lib/percpu-refcount.c
92083+++ b/lib/percpu-refcount.c
92084@@ -29,7 +29,7 @@
92085 * can't hit 0 before we've added up all the percpu refs.
92086 */
92087
92088-#define PCPU_COUNT_BIAS (1U << 31)
92089+#define PCPU_COUNT_BIAS (1U << 30)
92090
92091 /**
92092 * percpu_ref_init - initialize a percpu refcount
92093diff --git a/lib/radix-tree.c b/lib/radix-tree.c
92094index bd4a8df..9e4804f 100644
92095--- a/lib/radix-tree.c
92096+++ b/lib/radix-tree.c
92097@@ -93,7 +93,7 @@ struct radix_tree_preload {
92098 int nr;
92099 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
92100 };
92101-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
92102+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
92103
92104 static inline void *ptr_to_indirect(void *ptr)
92105 {
92106diff --git a/lib/random32.c b/lib/random32.c
92107index 6148967..009bfe8 100644
92108--- a/lib/random32.c
92109+++ b/lib/random32.c
92110@@ -44,7 +44,7 @@
92111 static void __init prandom_state_selftest(void);
92112 #endif
92113
92114-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
92115+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
92116
92117 /**
92118 * prandom_u32_state - seeded pseudo-random number generator.
92119diff --git a/lib/rbtree.c b/lib/rbtree.c
92120index 65f4eff..2cfa167 100644
92121--- a/lib/rbtree.c
92122+++ b/lib/rbtree.c
92123@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
92124 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
92125
92126 static const struct rb_augment_callbacks dummy_callbacks = {
92127- dummy_propagate, dummy_copy, dummy_rotate
92128+ .propagate = dummy_propagate,
92129+ .copy = dummy_copy,
92130+ .rotate = dummy_rotate
92131 };
92132
92133 void rb_insert_color(struct rb_node *node, struct rb_root *root)
92134diff --git a/lib/show_mem.c b/lib/show_mem.c
92135index 0922579..9d7adb9 100644
92136--- a/lib/show_mem.c
92137+++ b/lib/show_mem.c
92138@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
92139 quicklist_total_size());
92140 #endif
92141 #ifdef CONFIG_MEMORY_FAILURE
92142- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
92143+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
92144 #endif
92145 }
92146diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
92147index bb2b201..46abaf9 100644
92148--- a/lib/strncpy_from_user.c
92149+++ b/lib/strncpy_from_user.c
92150@@ -21,7 +21,7 @@
92151 */
92152 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
92153 {
92154- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92155+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92156 long res = 0;
92157
92158 /*
92159diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
92160index a28df52..3d55877 100644
92161--- a/lib/strnlen_user.c
92162+++ b/lib/strnlen_user.c
92163@@ -26,7 +26,7 @@
92164 */
92165 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92166 {
92167- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92168+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92169 long align, res = 0;
92170 unsigned long c;
92171
92172diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92173index b604b83..c0547f6 100644
92174--- a/lib/swiotlb.c
92175+++ b/lib/swiotlb.c
92176@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92177
92178 void
92179 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92180- dma_addr_t dev_addr)
92181+ dma_addr_t dev_addr, struct dma_attrs *attrs)
92182 {
92183 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92184
92185diff --git a/lib/usercopy.c b/lib/usercopy.c
92186index 4f5b1dd..7cab418 100644
92187--- a/lib/usercopy.c
92188+++ b/lib/usercopy.c
92189@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92190 WARN(1, "Buffer overflow detected!\n");
92191 }
92192 EXPORT_SYMBOL(copy_from_user_overflow);
92193+
92194+void copy_to_user_overflow(void)
92195+{
92196+ WARN(1, "Buffer overflow detected!\n");
92197+}
92198+EXPORT_SYMBOL(copy_to_user_overflow);
92199diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92200index 185b6d3..823c48c 100644
92201--- a/lib/vsprintf.c
92202+++ b/lib/vsprintf.c
92203@@ -16,6 +16,9 @@
92204 * - scnprintf and vscnprintf
92205 */
92206
92207+#ifdef CONFIG_GRKERNSEC_HIDESYM
92208+#define __INCLUDED_BY_HIDESYM 1
92209+#endif
92210 #include <stdarg.h>
92211 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92212 #include <linux/types.h>
92213@@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
92214 return number(buf, end, num, spec);
92215 }
92216
92217+#ifdef CONFIG_GRKERNSEC_HIDESYM
92218+int kptr_restrict __read_mostly = 2;
92219+#else
92220 int kptr_restrict __read_mostly;
92221+#endif
92222
92223 /*
92224 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92225@@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
92226 * - 'f' For simple symbolic function names without offset
92227 * - 'S' For symbolic direct pointers with offset
92228 * - 's' For symbolic direct pointers without offset
92229+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92230 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92231 * - 'B' For backtraced symbolic direct pointers with offset
92232 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92233@@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92234
92235 if (!ptr && *fmt != 'K') {
92236 /*
92237- * Print (null) with the same width as a pointer so it makes
92238+ * Print (nil) with the same width as a pointer so it makes
92239 * tabular output look nice.
92240 */
92241 if (spec.field_width == -1)
92242 spec.field_width = default_width;
92243- return string(buf, end, "(null)", spec);
92244+ return string(buf, end, "(nil)", spec);
92245 }
92246
92247 switch (*fmt) {
92248@@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92249 /* Fallthrough */
92250 case 'S':
92251 case 's':
92252+#ifdef CONFIG_GRKERNSEC_HIDESYM
92253+ break;
92254+#else
92255+ return symbol_string(buf, end, ptr, spec, fmt);
92256+#endif
92257+ case 'A':
92258 case 'B':
92259 return symbol_string(buf, end, ptr, spec, fmt);
92260 case 'R':
92261@@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92262 va_end(va);
92263 return buf;
92264 }
92265+ case 'P':
92266+ break;
92267 case 'K':
92268 /*
92269 * %pK cannot be used in IRQ context because its test
92270@@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92271 ((const struct file *)ptr)->f_path.dentry,
92272 spec, fmt);
92273 }
92274+
92275+#ifdef CONFIG_GRKERNSEC_HIDESYM
92276+ /* 'P' = approved pointers to copy to userland,
92277+ as in the /proc/kallsyms case, as we make it display nothing
92278+ for non-root users, and the real contents for root users
92279+ Also ignore 'K' pointers, since we force their NULLing for non-root users
92280+ above
92281+ */
92282+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92283+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92284+ dump_stack();
92285+ ptr = NULL;
92286+ }
92287+#endif
92288+
92289 spec.flags |= SMALL;
92290 if (spec.field_width == -1) {
92291 spec.field_width = default_width;
92292@@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92293 typeof(type) value; \
92294 if (sizeof(type) == 8) { \
92295 args = PTR_ALIGN(args, sizeof(u32)); \
92296- *(u32 *)&value = *(u32 *)args; \
92297- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92298+ *(u32 *)&value = *(const u32 *)args; \
92299+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92300 } else { \
92301 args = PTR_ALIGN(args, sizeof(type)); \
92302- value = *(typeof(type) *)args; \
92303+ value = *(const typeof(type) *)args; \
92304 } \
92305 args += sizeof(type); \
92306 value; \
92307@@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92308 case FORMAT_TYPE_STR: {
92309 const char *str_arg = args;
92310 args += strlen(str_arg) + 1;
92311- str = string(str, end, (char *)str_arg, spec);
92312+ str = string(str, end, str_arg, spec);
92313 break;
92314 }
92315
92316diff --git a/localversion-grsec b/localversion-grsec
92317new file mode 100644
92318index 0000000..7cd6065
92319--- /dev/null
92320+++ b/localversion-grsec
92321@@ -0,0 +1 @@
92322+-grsec
92323diff --git a/mm/Kconfig b/mm/Kconfig
92324index 2888024..c15a810 100644
92325--- a/mm/Kconfig
92326+++ b/mm/Kconfig
92327@@ -326,10 +326,11 @@ config KSM
92328 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92329
92330 config DEFAULT_MMAP_MIN_ADDR
92331- int "Low address space to protect from user allocation"
92332+ int "Low address space to protect from user allocation"
92333 depends on MMU
92334- default 4096
92335- help
92336+ default 32768 if ALPHA || ARM || PARISC || SPARC32
92337+ default 65536
92338+ help
92339 This is the portion of low virtual memory which should be protected
92340 from userspace allocation. Keeping a user from writing to low pages
92341 can help reduce the impact of kernel NULL pointer bugs.
92342@@ -360,7 +361,7 @@ config MEMORY_FAILURE
92343
92344 config HWPOISON_INJECT
92345 tristate "HWPoison pages injector"
92346- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92347+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92348 select PROC_PAGE_MONITOR
92349
92350 config NOMMU_INITIAL_TRIM_EXCESS
92351diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92352index 09d9591..165bb75 100644
92353--- a/mm/backing-dev.c
92354+++ b/mm/backing-dev.c
92355@@ -12,7 +12,7 @@
92356 #include <linux/device.h>
92357 #include <trace/events/writeback.h>
92358
92359-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92360+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92361
92362 struct backing_dev_info default_backing_dev_info = {
92363 .name = "default",
92364@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92365 return err;
92366
92367 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92368- atomic_long_inc_return(&bdi_seq));
92369+ atomic_long_inc_return_unchecked(&bdi_seq));
92370 if (err) {
92371 bdi_destroy(bdi);
92372 return err;
92373diff --git a/mm/filemap.c b/mm/filemap.c
92374index 7a13f6a..e31738b 100644
92375--- a/mm/filemap.c
92376+++ b/mm/filemap.c
92377@@ -192,9 +192,11 @@ static int filemap_check_errors(struct address_space *mapping)
92378 {
92379 int ret = 0;
92380 /* Check for outstanding write errors */
92381- if (test_and_clear_bit(AS_ENOSPC, &mapping->flags))
92382+ if (test_bit(AS_ENOSPC, &mapping->flags) &&
92383+ test_and_clear_bit(AS_ENOSPC, &mapping->flags))
92384 ret = -ENOSPC;
92385- if (test_and_clear_bit(AS_EIO, &mapping->flags))
92386+ if (test_bit(AS_EIO, &mapping->flags) &&
92387+ test_and_clear_bit(AS_EIO, &mapping->flags))
92388 ret = -EIO;
92389 return ret;
92390 }
92391@@ -1766,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92392 struct address_space *mapping = file->f_mapping;
92393
92394 if (!mapping->a_ops->readpage)
92395- return -ENOEXEC;
92396+ return -ENODEV;
92397 file_accessed(file);
92398 vma->vm_ops = &generic_file_vm_ops;
92399 return 0;
92400@@ -1948,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92401
92402 while (bytes) {
92403 char __user *buf = iov->iov_base + base;
92404- int copy = min(bytes, iov->iov_len - base);
92405+ size_t copy = min(bytes, iov->iov_len - base);
92406
92407 base = 0;
92408 left = __copy_from_user_inatomic(vaddr, buf, copy);
92409@@ -1977,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92410 BUG_ON(!in_atomic());
92411 kaddr = kmap_atomic(page);
92412 if (likely(i->nr_segs == 1)) {
92413- int left;
92414+ size_t left;
92415 char __user *buf = i->iov->iov_base + i->iov_offset;
92416 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92417 copied = bytes - left;
92418@@ -2005,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92419
92420 kaddr = kmap(page);
92421 if (likely(i->nr_segs == 1)) {
92422- int left;
92423+ size_t left;
92424 char __user *buf = i->iov->iov_base + i->iov_offset;
92425 left = __copy_from_user(kaddr + offset, buf, bytes);
92426 copied = bytes - left;
92427@@ -2035,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92428 * zero-length segments (without overruning the iovec).
92429 */
92430 while (bytes || unlikely(i->count && !iov->iov_len)) {
92431- int copy;
92432+ size_t copy;
92433
92434 copy = min(bytes, iov->iov_len - base);
92435 BUG_ON(!i->count || i->count < copy);
92436@@ -2106,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92437 *pos = i_size_read(inode);
92438
92439 if (limit != RLIM_INFINITY) {
92440+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92441 if (*pos >= limit) {
92442 send_sig(SIGXFSZ, current, 0);
92443 return -EFBIG;
92444diff --git a/mm/fremap.c b/mm/fremap.c
92445index 34feba6..315fe78 100644
92446--- a/mm/fremap.c
92447+++ b/mm/fremap.c
92448@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92449 retry:
92450 vma = find_vma(mm, start);
92451
92452+#ifdef CONFIG_PAX_SEGMEXEC
92453+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92454+ goto out;
92455+#endif
92456+
92457 /*
92458 * Make sure the vma is shared, that it supports prefaulting,
92459 * and that the remapped range is valid and fully within
92460diff --git a/mm/highmem.c b/mm/highmem.c
92461index b32b70c..e512eb0 100644
92462--- a/mm/highmem.c
92463+++ b/mm/highmem.c
92464@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92465 * So no dangers, even with speculative execution.
92466 */
92467 page = pte_page(pkmap_page_table[i]);
92468+ pax_open_kernel();
92469 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92470-
92471+ pax_close_kernel();
92472 set_page_address(page, NULL);
92473 need_flush = 1;
92474 }
92475@@ -198,9 +199,11 @@ start:
92476 }
92477 }
92478 vaddr = PKMAP_ADDR(last_pkmap_nr);
92479+
92480+ pax_open_kernel();
92481 set_pte_at(&init_mm, vaddr,
92482 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92483-
92484+ pax_close_kernel();
92485 pkmap_count[last_pkmap_nr] = 1;
92486 set_page_address(page, (void *)vaddr);
92487
92488diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92489index 2de3c84..4ecaf1b 100644
92490--- a/mm/hugetlb.c
92491+++ b/mm/hugetlb.c
92492@@ -2069,15 +2069,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92493 struct hstate *h = &default_hstate;
92494 unsigned long tmp;
92495 int ret;
92496+ ctl_table_no_const hugetlb_table;
92497
92498 tmp = h->max_huge_pages;
92499
92500 if (write && h->order >= MAX_ORDER)
92501 return -EINVAL;
92502
92503- table->data = &tmp;
92504- table->maxlen = sizeof(unsigned long);
92505- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92506+ hugetlb_table = *table;
92507+ hugetlb_table.data = &tmp;
92508+ hugetlb_table.maxlen = sizeof(unsigned long);
92509+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92510 if (ret)
92511 goto out;
92512
92513@@ -2122,15 +2124,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92514 struct hstate *h = &default_hstate;
92515 unsigned long tmp;
92516 int ret;
92517+ ctl_table_no_const hugetlb_table;
92518
92519 tmp = h->nr_overcommit_huge_pages;
92520
92521 if (write && h->order >= MAX_ORDER)
92522 return -EINVAL;
92523
92524- table->data = &tmp;
92525- table->maxlen = sizeof(unsigned long);
92526- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92527+ hugetlb_table = *table;
92528+ hugetlb_table.data = &tmp;
92529+ hugetlb_table.maxlen = sizeof(unsigned long);
92530+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92531 if (ret)
92532 goto out;
92533
92534@@ -2599,6 +2603,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92535 return 1;
92536 }
92537
92538+#ifdef CONFIG_PAX_SEGMEXEC
92539+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92540+{
92541+ struct mm_struct *mm = vma->vm_mm;
92542+ struct vm_area_struct *vma_m;
92543+ unsigned long address_m;
92544+ pte_t *ptep_m;
92545+
92546+ vma_m = pax_find_mirror_vma(vma);
92547+ if (!vma_m)
92548+ return;
92549+
92550+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92551+ address_m = address + SEGMEXEC_TASK_SIZE;
92552+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92553+ get_page(page_m);
92554+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
92555+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92556+}
92557+#endif
92558+
92559 /*
92560 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92561 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92562@@ -2715,6 +2740,11 @@ retry_avoidcopy:
92563 make_huge_pte(vma, new_page, 1));
92564 page_remove_rmap(old_page);
92565 hugepage_add_new_anon_rmap(new_page, vma, address);
92566+
92567+#ifdef CONFIG_PAX_SEGMEXEC
92568+ pax_mirror_huge_pte(vma, address, new_page);
92569+#endif
92570+
92571 /* Make the old page be freed below */
92572 new_page = old_page;
92573 }
92574@@ -2879,6 +2909,10 @@ retry:
92575 && (vma->vm_flags & VM_SHARED)));
92576 set_huge_pte_at(mm, address, ptep, new_pte);
92577
92578+#ifdef CONFIG_PAX_SEGMEXEC
92579+ pax_mirror_huge_pte(vma, address, page);
92580+#endif
92581+
92582 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92583 /* Optimization, do the COW without a second fault */
92584 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92585@@ -2909,6 +2943,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92586 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
92587 struct hstate *h = hstate_vma(vma);
92588
92589+#ifdef CONFIG_PAX_SEGMEXEC
92590+ struct vm_area_struct *vma_m;
92591+#endif
92592+
92593 address &= huge_page_mask(h);
92594
92595 ptep = huge_pte_offset(mm, address);
92596@@ -2922,6 +2960,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92597 VM_FAULT_SET_HINDEX(hstate_index(h));
92598 }
92599
92600+#ifdef CONFIG_PAX_SEGMEXEC
92601+ vma_m = pax_find_mirror_vma(vma);
92602+ if (vma_m) {
92603+ unsigned long address_m;
92604+
92605+ if (vma->vm_start > vma_m->vm_start) {
92606+ address_m = address;
92607+ address -= SEGMEXEC_TASK_SIZE;
92608+ vma = vma_m;
92609+ h = hstate_vma(vma);
92610+ } else
92611+ address_m = address + SEGMEXEC_TASK_SIZE;
92612+
92613+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92614+ return VM_FAULT_OOM;
92615+ address_m &= HPAGE_MASK;
92616+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92617+ }
92618+#endif
92619+
92620 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92621 if (!ptep)
92622 return VM_FAULT_OOM;
92623diff --git a/mm/internal.h b/mm/internal.h
92624index 3e91000..4741a60 100644
92625--- a/mm/internal.h
92626+++ b/mm/internal.h
92627@@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92628 * in mm/page_alloc.c
92629 */
92630 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92631+extern void free_compound_page(struct page *page);
92632 extern void prep_compound_page(struct page *page, unsigned long order);
92633 #ifdef CONFIG_MEMORY_FAILURE
92634 extern bool is_free_buddy_page(struct page *page);
92635@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
92636
92637 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92638 unsigned long, unsigned long,
92639- unsigned long, unsigned long);
92640+ unsigned long, unsigned long) __intentional_overflow(-1);
92641
92642 extern void set_pageblock_order(void);
92643 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92644diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92645index 31f01c5..7015178 100644
92646--- a/mm/kmemleak.c
92647+++ b/mm/kmemleak.c
92648@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
92649
92650 for (i = 0; i < object->trace_len; i++) {
92651 void *ptr = (void *)object->trace[i];
92652- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92653+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92654 }
92655 }
92656
92657@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
92658 return -ENOMEM;
92659 }
92660
92661- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92662+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92663 &kmemleak_fops);
92664 if (!dentry)
92665 pr_warning("Failed to create the debugfs kmemleak file\n");
92666diff --git a/mm/maccess.c b/mm/maccess.c
92667index d53adf9..03a24bf 100644
92668--- a/mm/maccess.c
92669+++ b/mm/maccess.c
92670@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92671 set_fs(KERNEL_DS);
92672 pagefault_disable();
92673 ret = __copy_from_user_inatomic(dst,
92674- (__force const void __user *)src, size);
92675+ (const void __force_user *)src, size);
92676 pagefault_enable();
92677 set_fs(old_fs);
92678
92679@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92680
92681 set_fs(KERNEL_DS);
92682 pagefault_disable();
92683- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92684+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92685 pagefault_enable();
92686 set_fs(old_fs);
92687
92688diff --git a/mm/madvise.c b/mm/madvise.c
92689index 539eeb9..e24a987 100644
92690--- a/mm/madvise.c
92691+++ b/mm/madvise.c
92692@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92693 pgoff_t pgoff;
92694 unsigned long new_flags = vma->vm_flags;
92695
92696+#ifdef CONFIG_PAX_SEGMEXEC
92697+ struct vm_area_struct *vma_m;
92698+#endif
92699+
92700 switch (behavior) {
92701 case MADV_NORMAL:
92702 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92703@@ -126,6 +130,13 @@ success:
92704 /*
92705 * vm_flags is protected by the mmap_sem held in write mode.
92706 */
92707+
92708+#ifdef CONFIG_PAX_SEGMEXEC
92709+ vma_m = pax_find_mirror_vma(vma);
92710+ if (vma_m)
92711+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92712+#endif
92713+
92714 vma->vm_flags = new_flags;
92715
92716 out:
92717@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92718 struct vm_area_struct **prev,
92719 unsigned long start, unsigned long end)
92720 {
92721+
92722+#ifdef CONFIG_PAX_SEGMEXEC
92723+ struct vm_area_struct *vma_m;
92724+#endif
92725+
92726 *prev = vma;
92727 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92728 return -EINVAL;
92729@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92730 zap_page_range(vma, start, end - start, &details);
92731 } else
92732 zap_page_range(vma, start, end - start, NULL);
92733+
92734+#ifdef CONFIG_PAX_SEGMEXEC
92735+ vma_m = pax_find_mirror_vma(vma);
92736+ if (vma_m) {
92737+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92738+ struct zap_details details = {
92739+ .nonlinear_vma = vma_m,
92740+ .last_index = ULONG_MAX,
92741+ };
92742+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92743+ } else
92744+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92745+ }
92746+#endif
92747+
92748 return 0;
92749 }
92750
92751@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92752 if (end < start)
92753 return error;
92754
92755+#ifdef CONFIG_PAX_SEGMEXEC
92756+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92757+ if (end > SEGMEXEC_TASK_SIZE)
92758+ return error;
92759+ } else
92760+#endif
92761+
92762+ if (end > TASK_SIZE)
92763+ return error;
92764+
92765 error = 0;
92766 if (end == start)
92767 return error;
92768diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92769index 90002ea..db1452d 100644
92770--- a/mm/memory-failure.c
92771+++ b/mm/memory-failure.c
92772@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92773
92774 int sysctl_memory_failure_recovery __read_mostly = 1;
92775
92776-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92777+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92778
92779 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92780
92781@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92782 pfn, t->comm, t->pid);
92783 si.si_signo = SIGBUS;
92784 si.si_errno = 0;
92785- si.si_addr = (void *)addr;
92786+ si.si_addr = (void __user *)addr;
92787 #ifdef __ARCH_SI_TRAPNO
92788 si.si_trapno = trapno;
92789 #endif
92790@@ -762,7 +762,7 @@ static struct page_state {
92791 unsigned long res;
92792 char *msg;
92793 int (*action)(struct page *p, unsigned long pfn);
92794-} error_states[] = {
92795+} __do_const error_states[] = {
92796 { reserved, reserved, "reserved kernel", me_kernel },
92797 /*
92798 * free pages are specially detected outside this table:
92799@@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92800 nr_pages = 1 << compound_order(hpage);
92801 else /* normal page or thp */
92802 nr_pages = 1;
92803- atomic_long_add(nr_pages, &num_poisoned_pages);
92804+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92805
92806 /*
92807 * We need/can do nothing about count=0 pages.
92808@@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92809 if (!PageHWPoison(hpage)
92810 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
92811 || (p != hpage && TestSetPageHWPoison(hpage))) {
92812- atomic_long_sub(nr_pages, &num_poisoned_pages);
92813+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92814 return 0;
92815 }
92816 set_page_hwpoison_huge_page(hpage);
92817@@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92818 }
92819 if (hwpoison_filter(p)) {
92820 if (TestClearPageHWPoison(p))
92821- atomic_long_sub(nr_pages, &num_poisoned_pages);
92822+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92823 unlock_page(hpage);
92824 put_page(hpage);
92825 return 0;
92826@@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
92827 return 0;
92828 }
92829 if (TestClearPageHWPoison(p))
92830- atomic_long_dec(&num_poisoned_pages);
92831+ atomic_long_dec_unchecked(&num_poisoned_pages);
92832 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92833 return 0;
92834 }
92835@@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
92836 */
92837 if (TestClearPageHWPoison(page)) {
92838 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92839- atomic_long_sub(nr_pages, &num_poisoned_pages);
92840+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92841 freeit = 1;
92842 if (PageHuge(page))
92843 clear_page_hwpoison_huge_page(page);
92844@@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92845 if (PageHuge(page)) {
92846 set_page_hwpoison_huge_page(hpage);
92847 dequeue_hwpoisoned_huge_page(hpage);
92848- atomic_long_add(1 << compound_order(hpage),
92849+ atomic_long_add_unchecked(1 << compound_order(hpage),
92850 &num_poisoned_pages);
92851 } else {
92852 SetPageHWPoison(page);
92853- atomic_long_inc(&num_poisoned_pages);
92854+ atomic_long_inc_unchecked(&num_poisoned_pages);
92855 }
92856 }
92857 return ret;
92858@@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
92859 put_page(page);
92860 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92861 SetPageHWPoison(page);
92862- atomic_long_inc(&num_poisoned_pages);
92863+ atomic_long_inc_unchecked(&num_poisoned_pages);
92864 return 0;
92865 }
92866
92867@@ -1616,7 +1616,7 @@ static int __soft_offline_page(struct page *page, int flags)
92868 if (!is_free_buddy_page(page))
92869 pr_info("soft offline: %#lx: page leaked\n",
92870 pfn);
92871- atomic_long_inc(&num_poisoned_pages);
92872+ atomic_long_inc_unchecked(&num_poisoned_pages);
92873 }
92874 } else {
92875 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92876@@ -1690,11 +1690,11 @@ int soft_offline_page(struct page *page, int flags)
92877 if (PageHuge(page)) {
92878 set_page_hwpoison_huge_page(hpage);
92879 dequeue_hwpoisoned_huge_page(hpage);
92880- atomic_long_add(1 << compound_order(hpage),
92881+ atomic_long_add_unchecked(1 << compound_order(hpage),
92882 &num_poisoned_pages);
92883 } else {
92884 SetPageHWPoison(page);
92885- atomic_long_inc(&num_poisoned_pages);
92886+ atomic_long_inc_unchecked(&num_poisoned_pages);
92887 }
92888 }
92889 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92890diff --git a/mm/memory.c b/mm/memory.c
92891index 22dfa61..90d7ec5 100644
92892--- a/mm/memory.c
92893+++ b/mm/memory.c
92894@@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92895 free_pte_range(tlb, pmd, addr);
92896 } while (pmd++, addr = next, addr != end);
92897
92898+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92899 start &= PUD_MASK;
92900 if (start < floor)
92901 return;
92902@@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92903 pmd = pmd_offset(pud, start);
92904 pud_clear(pud);
92905 pmd_free_tlb(tlb, pmd, start);
92906+#endif
92907+
92908 }
92909
92910 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92911@@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92912 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92913 } while (pud++, addr = next, addr != end);
92914
92915+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92916 start &= PGDIR_MASK;
92917 if (start < floor)
92918 return;
92919@@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92920 pud = pud_offset(pgd, start);
92921 pgd_clear(pgd);
92922 pud_free_tlb(tlb, pud, start);
92923+#endif
92924+
92925 }
92926
92927 /*
92928@@ -1636,12 +1642,6 @@ no_page_table:
92929 return page;
92930 }
92931
92932-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92933-{
92934- return stack_guard_page_start(vma, addr) ||
92935- stack_guard_page_end(vma, addr+PAGE_SIZE);
92936-}
92937-
92938 /**
92939 * __get_user_pages() - pin user pages in memory
92940 * @tsk: task_struct of target task
92941@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92942
92943 i = 0;
92944
92945- do {
92946+ while (nr_pages) {
92947 struct vm_area_struct *vma;
92948
92949- vma = find_extend_vma(mm, start);
92950+ vma = find_vma(mm, start);
92951 if (!vma && in_gate_area(mm, start)) {
92952 unsigned long pg = start & PAGE_MASK;
92953 pgd_t *pgd;
92954@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92955 goto next_page;
92956 }
92957
92958- if (!vma ||
92959+ if (!vma || start < vma->vm_start ||
92960 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
92961 !(vm_flags & vma->vm_flags))
92962 return i ? : -EFAULT;
92963@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92964 int ret;
92965 unsigned int fault_flags = 0;
92966
92967- /* For mlock, just skip the stack guard page. */
92968- if (foll_flags & FOLL_MLOCK) {
92969- if (stack_guard_page(vma, start))
92970- goto next_page;
92971- }
92972 if (foll_flags & FOLL_WRITE)
92973 fault_flags |= FAULT_FLAG_WRITE;
92974 if (nonblocking)
92975@@ -1893,7 +1888,7 @@ next_page:
92976 start += page_increm * PAGE_SIZE;
92977 nr_pages -= page_increm;
92978 } while (nr_pages && start < vma->vm_end);
92979- } while (nr_pages);
92980+ }
92981 return i;
92982 }
92983 EXPORT_SYMBOL(__get_user_pages);
92984@@ -1929,12 +1924,17 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
92985 unsigned long address, unsigned int fault_flags)
92986 {
92987 struct vm_area_struct *vma;
92988+ vm_flags_t vm_flags;
92989 int ret;
92990
92991 vma = find_extend_vma(mm, address);
92992 if (!vma || address < vma->vm_start)
92993 return -EFAULT;
92994
92995+ vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
92996+ if (!(vm_flags & vma->vm_flags))
92997+ return -EFAULT;
92998+
92999 ret = handle_mm_fault(mm, vma, address, fault_flags);
93000 if (ret & VM_FAULT_ERROR) {
93001 if (ret & VM_FAULT_OOM)
93002@@ -2100,6 +2100,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
93003 page_add_file_rmap(page);
93004 set_pte_at(mm, addr, pte, mk_pte(page, prot));
93005
93006+#ifdef CONFIG_PAX_SEGMEXEC
93007+ pax_mirror_file_pte(vma, addr, page, ptl);
93008+#endif
93009+
93010 retval = 0;
93011 pte_unmap_unlock(pte, ptl);
93012 return retval;
93013@@ -2144,9 +2148,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
93014 if (!page_count(page))
93015 return -EINVAL;
93016 if (!(vma->vm_flags & VM_MIXEDMAP)) {
93017+
93018+#ifdef CONFIG_PAX_SEGMEXEC
93019+ struct vm_area_struct *vma_m;
93020+#endif
93021+
93022 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
93023 BUG_ON(vma->vm_flags & VM_PFNMAP);
93024 vma->vm_flags |= VM_MIXEDMAP;
93025+
93026+#ifdef CONFIG_PAX_SEGMEXEC
93027+ vma_m = pax_find_mirror_vma(vma);
93028+ if (vma_m)
93029+ vma_m->vm_flags |= VM_MIXEDMAP;
93030+#endif
93031+
93032 }
93033 return insert_page(vma, addr, page, vma->vm_page_prot);
93034 }
93035@@ -2229,6 +2245,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
93036 unsigned long pfn)
93037 {
93038 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
93039+ BUG_ON(vma->vm_mirror);
93040
93041 if (addr < vma->vm_start || addr >= vma->vm_end)
93042 return -EFAULT;
93043@@ -2476,7 +2493,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
93044
93045 BUG_ON(pud_huge(*pud));
93046
93047- pmd = pmd_alloc(mm, pud, addr);
93048+ pmd = (mm == &init_mm) ?
93049+ pmd_alloc_kernel(mm, pud, addr) :
93050+ pmd_alloc(mm, pud, addr);
93051 if (!pmd)
93052 return -ENOMEM;
93053 do {
93054@@ -2496,7 +2515,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
93055 unsigned long next;
93056 int err;
93057
93058- pud = pud_alloc(mm, pgd, addr);
93059+ pud = (mm == &init_mm) ?
93060+ pud_alloc_kernel(mm, pgd, addr) :
93061+ pud_alloc(mm, pgd, addr);
93062 if (!pud)
93063 return -ENOMEM;
93064 do {
93065@@ -2586,6 +2607,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
93066 copy_user_highpage(dst, src, va, vma);
93067 }
93068
93069+#ifdef CONFIG_PAX_SEGMEXEC
93070+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
93071+{
93072+ struct mm_struct *mm = vma->vm_mm;
93073+ spinlock_t *ptl;
93074+ pte_t *pte, entry;
93075+
93076+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93077+ entry = *pte;
93078+ if (!pte_present(entry)) {
93079+ if (!pte_none(entry)) {
93080+ BUG_ON(pte_file(entry));
93081+ free_swap_and_cache(pte_to_swp_entry(entry));
93082+ pte_clear_not_present_full(mm, address, pte, 0);
93083+ }
93084+ } else {
93085+ struct page *page;
93086+
93087+ flush_cache_page(vma, address, pte_pfn(entry));
93088+ entry = ptep_clear_flush(vma, address, pte);
93089+ BUG_ON(pte_dirty(entry));
93090+ page = vm_normal_page(vma, address, entry);
93091+ if (page) {
93092+ update_hiwater_rss(mm);
93093+ if (PageAnon(page))
93094+ dec_mm_counter_fast(mm, MM_ANONPAGES);
93095+ else
93096+ dec_mm_counter_fast(mm, MM_FILEPAGES);
93097+ page_remove_rmap(page);
93098+ page_cache_release(page);
93099+ }
93100+ }
93101+ pte_unmap_unlock(pte, ptl);
93102+}
93103+
93104+/* PaX: if vma is mirrored, synchronize the mirror's PTE
93105+ *
93106+ * the ptl of the lower mapped page is held on entry and is not released on exit
93107+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
93108+ */
93109+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93110+{
93111+ struct mm_struct *mm = vma->vm_mm;
93112+ unsigned long address_m;
93113+ spinlock_t *ptl_m;
93114+ struct vm_area_struct *vma_m;
93115+ pmd_t *pmd_m;
93116+ pte_t *pte_m, entry_m;
93117+
93118+ BUG_ON(!page_m || !PageAnon(page_m));
93119+
93120+ vma_m = pax_find_mirror_vma(vma);
93121+ if (!vma_m)
93122+ return;
93123+
93124+ BUG_ON(!PageLocked(page_m));
93125+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93126+ address_m = address + SEGMEXEC_TASK_SIZE;
93127+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93128+ pte_m = pte_offset_map(pmd_m, address_m);
93129+ ptl_m = pte_lockptr(mm, pmd_m);
93130+ if (ptl != ptl_m) {
93131+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93132+ if (!pte_none(*pte_m))
93133+ goto out;
93134+ }
93135+
93136+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93137+ page_cache_get(page_m);
93138+ page_add_anon_rmap(page_m, vma_m, address_m);
93139+ inc_mm_counter_fast(mm, MM_ANONPAGES);
93140+ set_pte_at(mm, address_m, pte_m, entry_m);
93141+ update_mmu_cache(vma_m, address_m, pte_m);
93142+out:
93143+ if (ptl != ptl_m)
93144+ spin_unlock(ptl_m);
93145+ pte_unmap(pte_m);
93146+ unlock_page(page_m);
93147+}
93148+
93149+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93150+{
93151+ struct mm_struct *mm = vma->vm_mm;
93152+ unsigned long address_m;
93153+ spinlock_t *ptl_m;
93154+ struct vm_area_struct *vma_m;
93155+ pmd_t *pmd_m;
93156+ pte_t *pte_m, entry_m;
93157+
93158+ BUG_ON(!page_m || PageAnon(page_m));
93159+
93160+ vma_m = pax_find_mirror_vma(vma);
93161+ if (!vma_m)
93162+ return;
93163+
93164+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93165+ address_m = address + SEGMEXEC_TASK_SIZE;
93166+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93167+ pte_m = pte_offset_map(pmd_m, address_m);
93168+ ptl_m = pte_lockptr(mm, pmd_m);
93169+ if (ptl != ptl_m) {
93170+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93171+ if (!pte_none(*pte_m))
93172+ goto out;
93173+ }
93174+
93175+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93176+ page_cache_get(page_m);
93177+ page_add_file_rmap(page_m);
93178+ inc_mm_counter_fast(mm, MM_FILEPAGES);
93179+ set_pte_at(mm, address_m, pte_m, entry_m);
93180+ update_mmu_cache(vma_m, address_m, pte_m);
93181+out:
93182+ if (ptl != ptl_m)
93183+ spin_unlock(ptl_m);
93184+ pte_unmap(pte_m);
93185+}
93186+
93187+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93188+{
93189+ struct mm_struct *mm = vma->vm_mm;
93190+ unsigned long address_m;
93191+ spinlock_t *ptl_m;
93192+ struct vm_area_struct *vma_m;
93193+ pmd_t *pmd_m;
93194+ pte_t *pte_m, entry_m;
93195+
93196+ vma_m = pax_find_mirror_vma(vma);
93197+ if (!vma_m)
93198+ return;
93199+
93200+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93201+ address_m = address + SEGMEXEC_TASK_SIZE;
93202+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93203+ pte_m = pte_offset_map(pmd_m, address_m);
93204+ ptl_m = pte_lockptr(mm, pmd_m);
93205+ if (ptl != ptl_m) {
93206+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93207+ if (!pte_none(*pte_m))
93208+ goto out;
93209+ }
93210+
93211+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93212+ set_pte_at(mm, address_m, pte_m, entry_m);
93213+out:
93214+ if (ptl != ptl_m)
93215+ spin_unlock(ptl_m);
93216+ pte_unmap(pte_m);
93217+}
93218+
93219+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93220+{
93221+ struct page *page_m;
93222+ pte_t entry;
93223+
93224+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93225+ goto out;
93226+
93227+ entry = *pte;
93228+ page_m = vm_normal_page(vma, address, entry);
93229+ if (!page_m)
93230+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93231+ else if (PageAnon(page_m)) {
93232+ if (pax_find_mirror_vma(vma)) {
93233+ pte_unmap_unlock(pte, ptl);
93234+ lock_page(page_m);
93235+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93236+ if (pte_same(entry, *pte))
93237+ pax_mirror_anon_pte(vma, address, page_m, ptl);
93238+ else
93239+ unlock_page(page_m);
93240+ }
93241+ } else
93242+ pax_mirror_file_pte(vma, address, page_m, ptl);
93243+
93244+out:
93245+ pte_unmap_unlock(pte, ptl);
93246+}
93247+#endif
93248+
93249 /*
93250 * This routine handles present pages, when users try to write
93251 * to a shared page. It is done by copying the page to a new address
93252@@ -2810,6 +3011,12 @@ gotten:
93253 */
93254 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93255 if (likely(pte_same(*page_table, orig_pte))) {
93256+
93257+#ifdef CONFIG_PAX_SEGMEXEC
93258+ if (pax_find_mirror_vma(vma))
93259+ BUG_ON(!trylock_page(new_page));
93260+#endif
93261+
93262 if (old_page) {
93263 if (!PageAnon(old_page)) {
93264 dec_mm_counter_fast(mm, MM_FILEPAGES);
93265@@ -2861,6 +3068,10 @@ gotten:
93266 page_remove_rmap(old_page);
93267 }
93268
93269+#ifdef CONFIG_PAX_SEGMEXEC
93270+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93271+#endif
93272+
93273 /* Free the old page.. */
93274 new_page = old_page;
93275 ret |= VM_FAULT_WRITE;
93276@@ -3138,6 +3349,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93277 swap_free(entry);
93278 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93279 try_to_free_swap(page);
93280+
93281+#ifdef CONFIG_PAX_SEGMEXEC
93282+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93283+#endif
93284+
93285 unlock_page(page);
93286 if (page != swapcache) {
93287 /*
93288@@ -3161,6 +3377,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93289
93290 /* No need to invalidate - it was non-present before */
93291 update_mmu_cache(vma, address, page_table);
93292+
93293+#ifdef CONFIG_PAX_SEGMEXEC
93294+ pax_mirror_anon_pte(vma, address, page, ptl);
93295+#endif
93296+
93297 unlock:
93298 pte_unmap_unlock(page_table, ptl);
93299 out:
93300@@ -3180,40 +3401,6 @@ out_release:
93301 }
93302
93303 /*
93304- * This is like a special single-page "expand_{down|up}wards()",
93305- * except we must first make sure that 'address{-|+}PAGE_SIZE'
93306- * doesn't hit another vma.
93307- */
93308-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93309-{
93310- address &= PAGE_MASK;
93311- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93312- struct vm_area_struct *prev = vma->vm_prev;
93313-
93314- /*
93315- * Is there a mapping abutting this one below?
93316- *
93317- * That's only ok if it's the same stack mapping
93318- * that has gotten split..
93319- */
93320- if (prev && prev->vm_end == address)
93321- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93322-
93323- expand_downwards(vma, address - PAGE_SIZE);
93324- }
93325- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93326- struct vm_area_struct *next = vma->vm_next;
93327-
93328- /* As VM_GROWSDOWN but s/below/above/ */
93329- if (next && next->vm_start == address + PAGE_SIZE)
93330- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93331-
93332- expand_upwards(vma, address + PAGE_SIZE);
93333- }
93334- return 0;
93335-}
93336-
93337-/*
93338 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93339 * but allow concurrent faults), and pte mapped but not yet locked.
93340 * We return with mmap_sem still held, but pte unmapped and unlocked.
93341@@ -3222,27 +3409,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93342 unsigned long address, pte_t *page_table, pmd_t *pmd,
93343 unsigned int flags)
93344 {
93345- struct page *page;
93346+ struct page *page = NULL;
93347 spinlock_t *ptl;
93348 pte_t entry;
93349
93350- pte_unmap(page_table);
93351-
93352- /* Check if we need to add a guard page to the stack */
93353- if (check_stack_guard_page(vma, address) < 0)
93354- return VM_FAULT_SIGBUS;
93355-
93356- /* Use the zero-page for reads */
93357 if (!(flags & FAULT_FLAG_WRITE)) {
93358 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93359 vma->vm_page_prot));
93360- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93361+ ptl = pte_lockptr(mm, pmd);
93362+ spin_lock(ptl);
93363 if (!pte_none(*page_table))
93364 goto unlock;
93365 goto setpte;
93366 }
93367
93368 /* Allocate our own private page. */
93369+ pte_unmap(page_table);
93370+
93371 if (unlikely(anon_vma_prepare(vma)))
93372 goto oom;
93373 page = alloc_zeroed_user_highpage_movable(vma, address);
93374@@ -3266,6 +3449,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93375 if (!pte_none(*page_table))
93376 goto release;
93377
93378+#ifdef CONFIG_PAX_SEGMEXEC
93379+ if (pax_find_mirror_vma(vma))
93380+ BUG_ON(!trylock_page(page));
93381+#endif
93382+
93383 inc_mm_counter_fast(mm, MM_ANONPAGES);
93384 page_add_new_anon_rmap(page, vma, address);
93385 setpte:
93386@@ -3273,6 +3461,12 @@ setpte:
93387
93388 /* No need to invalidate - it was non-present before */
93389 update_mmu_cache(vma, address, page_table);
93390+
93391+#ifdef CONFIG_PAX_SEGMEXEC
93392+ if (page)
93393+ pax_mirror_anon_pte(vma, address, page, ptl);
93394+#endif
93395+
93396 unlock:
93397 pte_unmap_unlock(page_table, ptl);
93398 return 0;
93399@@ -3417,6 +3611,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93400 */
93401 /* Only go through if we didn't race with anybody else... */
93402 if (likely(pte_same(*page_table, orig_pte))) {
93403+
93404+#ifdef CONFIG_PAX_SEGMEXEC
93405+ if (anon && pax_find_mirror_vma(vma))
93406+ BUG_ON(!trylock_page(page));
93407+#endif
93408+
93409 flush_icache_page(vma, page);
93410 entry = mk_pte(page, vma->vm_page_prot);
93411 if (flags & FAULT_FLAG_WRITE)
93412@@ -3438,6 +3638,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93413
93414 /* no need to invalidate: a not-present page won't be cached */
93415 update_mmu_cache(vma, address, page_table);
93416+
93417+#ifdef CONFIG_PAX_SEGMEXEC
93418+ if (anon)
93419+ pax_mirror_anon_pte(vma, address, page, ptl);
93420+ else
93421+ pax_mirror_file_pte(vma, address, page, ptl);
93422+#endif
93423+
93424 } else {
93425 if (cow_page)
93426 mem_cgroup_uncharge_page(cow_page);
93427@@ -3685,6 +3893,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93428 if (flags & FAULT_FLAG_WRITE)
93429 flush_tlb_fix_spurious_fault(vma, address);
93430 }
93431+
93432+#ifdef CONFIG_PAX_SEGMEXEC
93433+ pax_mirror_pte(vma, address, pte, pmd, ptl);
93434+ return 0;
93435+#endif
93436+
93437 unlock:
93438 pte_unmap_unlock(pte, ptl);
93439 return 0;
93440@@ -3701,9 +3915,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93441 pmd_t *pmd;
93442 pte_t *pte;
93443
93444+#ifdef CONFIG_PAX_SEGMEXEC
93445+ struct vm_area_struct *vma_m;
93446+#endif
93447+
93448 if (unlikely(is_vm_hugetlb_page(vma)))
93449 return hugetlb_fault(mm, vma, address, flags);
93450
93451+#ifdef CONFIG_PAX_SEGMEXEC
93452+ vma_m = pax_find_mirror_vma(vma);
93453+ if (vma_m) {
93454+ unsigned long address_m;
93455+ pgd_t *pgd_m;
93456+ pud_t *pud_m;
93457+ pmd_t *pmd_m;
93458+
93459+ if (vma->vm_start > vma_m->vm_start) {
93460+ address_m = address;
93461+ address -= SEGMEXEC_TASK_SIZE;
93462+ vma = vma_m;
93463+ } else
93464+ address_m = address + SEGMEXEC_TASK_SIZE;
93465+
93466+ pgd_m = pgd_offset(mm, address_m);
93467+ pud_m = pud_alloc(mm, pgd_m, address_m);
93468+ if (!pud_m)
93469+ return VM_FAULT_OOM;
93470+ pmd_m = pmd_alloc(mm, pud_m, address_m);
93471+ if (!pmd_m)
93472+ return VM_FAULT_OOM;
93473+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93474+ return VM_FAULT_OOM;
93475+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93476+ }
93477+#endif
93478+
93479 pgd = pgd_offset(mm, address);
93480 pud = pud_alloc(mm, pgd, address);
93481 if (!pud)
93482@@ -3834,6 +4080,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93483 spin_unlock(&mm->page_table_lock);
93484 return 0;
93485 }
93486+
93487+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93488+{
93489+ pud_t *new = pud_alloc_one(mm, address);
93490+ if (!new)
93491+ return -ENOMEM;
93492+
93493+ smp_wmb(); /* See comment in __pte_alloc */
93494+
93495+ spin_lock(&mm->page_table_lock);
93496+ if (pgd_present(*pgd)) /* Another has populated it */
93497+ pud_free(mm, new);
93498+ else
93499+ pgd_populate_kernel(mm, pgd, new);
93500+ spin_unlock(&mm->page_table_lock);
93501+ return 0;
93502+}
93503 #endif /* __PAGETABLE_PUD_FOLDED */
93504
93505 #ifndef __PAGETABLE_PMD_FOLDED
93506@@ -3864,6 +4127,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93507 spin_unlock(&mm->page_table_lock);
93508 return 0;
93509 }
93510+
93511+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93512+{
93513+ pmd_t *new = pmd_alloc_one(mm, address);
93514+ if (!new)
93515+ return -ENOMEM;
93516+
93517+ smp_wmb(); /* See comment in __pte_alloc */
93518+
93519+ spin_lock(&mm->page_table_lock);
93520+#ifndef __ARCH_HAS_4LEVEL_HACK
93521+ if (pud_present(*pud)) /* Another has populated it */
93522+ pmd_free(mm, new);
93523+ else
93524+ pud_populate_kernel(mm, pud, new);
93525+#else
93526+ if (pgd_present(*pud)) /* Another has populated it */
93527+ pmd_free(mm, new);
93528+ else
93529+ pgd_populate_kernel(mm, pud, new);
93530+#endif /* __ARCH_HAS_4LEVEL_HACK */
93531+ spin_unlock(&mm->page_table_lock);
93532+ return 0;
93533+}
93534 #endif /* __PAGETABLE_PMD_FOLDED */
93535
93536 #if !defined(__HAVE_ARCH_GATE_AREA)
93537@@ -3877,7 +4164,7 @@ static int __init gate_vma_init(void)
93538 gate_vma.vm_start = FIXADDR_USER_START;
93539 gate_vma.vm_end = FIXADDR_USER_END;
93540 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93541- gate_vma.vm_page_prot = __P101;
93542+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93543
93544 return 0;
93545 }
93546@@ -4011,8 +4298,8 @@ out:
93547 return ret;
93548 }
93549
93550-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93551- void *buf, int len, int write)
93552+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93553+ void *buf, size_t len, int write)
93554 {
93555 resource_size_t phys_addr;
93556 unsigned long prot = 0;
93557@@ -4038,8 +4325,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93558 * Access another process' address space as given in mm. If non-NULL, use the
93559 * given task for page fault accounting.
93560 */
93561-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93562- unsigned long addr, void *buf, int len, int write)
93563+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93564+ unsigned long addr, void *buf, size_t len, int write)
93565 {
93566 struct vm_area_struct *vma;
93567 void *old_buf = buf;
93568@@ -4047,7 +4334,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93569 down_read(&mm->mmap_sem);
93570 /* ignore errors, just check how much was successfully transferred */
93571 while (len) {
93572- int bytes, ret, offset;
93573+ ssize_t bytes, ret, offset;
93574 void *maddr;
93575 struct page *page = NULL;
93576
93577@@ -4106,8 +4393,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93578 *
93579 * The caller must hold a reference on @mm.
93580 */
93581-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93582- void *buf, int len, int write)
93583+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93584+ void *buf, size_t len, int write)
93585 {
93586 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93587 }
93588@@ -4117,11 +4404,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93589 * Source/target buffer must be kernel space,
93590 * Do not walk the page table directly, use get_user_pages
93591 */
93592-int access_process_vm(struct task_struct *tsk, unsigned long addr,
93593- void *buf, int len, int write)
93594+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93595+ void *buf, size_t len, int write)
93596 {
93597 struct mm_struct *mm;
93598- int ret;
93599+ ssize_t ret;
93600
93601 mm = get_task_mm(tsk);
93602 if (!mm)
93603diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93604index ae3c8f3..fa4ee8e 100644
93605--- a/mm/mempolicy.c
93606+++ b/mm/mempolicy.c
93607@@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93608 unsigned long vmstart;
93609 unsigned long vmend;
93610
93611+#ifdef CONFIG_PAX_SEGMEXEC
93612+ struct vm_area_struct *vma_m;
93613+#endif
93614+
93615 vma = find_vma(mm, start);
93616 if (!vma || vma->vm_start > start)
93617 return -EFAULT;
93618@@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93619 err = vma_replace_policy(vma, new_pol);
93620 if (err)
93621 goto out;
93622+
93623+#ifdef CONFIG_PAX_SEGMEXEC
93624+ vma_m = pax_find_mirror_vma(vma);
93625+ if (vma_m) {
93626+ err = vma_replace_policy(vma_m, new_pol);
93627+ if (err)
93628+ goto out;
93629+ }
93630+#endif
93631+
93632 }
93633
93634 out:
93635@@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93636
93637 if (end < start)
93638 return -EINVAL;
93639+
93640+#ifdef CONFIG_PAX_SEGMEXEC
93641+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93642+ if (end > SEGMEXEC_TASK_SIZE)
93643+ return -EINVAL;
93644+ } else
93645+#endif
93646+
93647+ if (end > TASK_SIZE)
93648+ return -EINVAL;
93649+
93650 if (end == start)
93651 return 0;
93652
93653@@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93654 */
93655 tcred = __task_cred(task);
93656 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93657- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93658- !capable(CAP_SYS_NICE)) {
93659+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93660 rcu_read_unlock();
93661 err = -EPERM;
93662 goto out_put;
93663@@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93664 goto out;
93665 }
93666
93667+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93668+ if (mm != current->mm &&
93669+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93670+ mmput(mm);
93671+ err = -EPERM;
93672+ goto out;
93673+ }
93674+#endif
93675+
93676 err = do_migrate_pages(mm, old, new,
93677 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93678
93679diff --git a/mm/migrate.c b/mm/migrate.c
93680index bed4880..a493f67 100644
93681--- a/mm/migrate.c
93682+++ b/mm/migrate.c
93683@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93684 */
93685 tcred = __task_cred(task);
93686 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93687- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93688- !capable(CAP_SYS_NICE)) {
93689+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93690 rcu_read_unlock();
93691 err = -EPERM;
93692 goto out;
93693diff --git a/mm/mlock.c b/mm/mlock.c
93694index b1eb536..091d154 100644
93695--- a/mm/mlock.c
93696+++ b/mm/mlock.c
93697@@ -14,6 +14,7 @@
93698 #include <linux/pagevec.h>
93699 #include <linux/mempolicy.h>
93700 #include <linux/syscalls.h>
93701+#include <linux/security.h>
93702 #include <linux/sched.h>
93703 #include <linux/export.h>
93704 #include <linux/rmap.h>
93705@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93706 {
93707 unsigned long nstart, end, tmp;
93708 struct vm_area_struct * vma, * prev;
93709- int error;
93710+ int error = 0;
93711
93712 VM_BUG_ON(start & ~PAGE_MASK);
93713 VM_BUG_ON(len != PAGE_ALIGN(len));
93714@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93715 return -EINVAL;
93716 if (end == start)
93717 return 0;
93718+ if (end > TASK_SIZE)
93719+ return -EINVAL;
93720+
93721 vma = find_vma(current->mm, start);
93722 if (!vma || vma->vm_start > start)
93723 return -ENOMEM;
93724@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93725 for (nstart = start ; ; ) {
93726 vm_flags_t newflags;
93727
93728+#ifdef CONFIG_PAX_SEGMEXEC
93729+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93730+ break;
93731+#endif
93732+
93733 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93734
93735 newflags = vma->vm_flags & ~VM_LOCKED;
93736@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93737 locked += current->mm->locked_vm;
93738
93739 /* check against resource limits */
93740+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93741 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93742 error = do_mlock(start, len, 1);
93743
93744@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93745 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93746 vm_flags_t newflags;
93747
93748+#ifdef CONFIG_PAX_SEGMEXEC
93749+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93750+ break;
93751+#endif
93752+
93753 newflags = vma->vm_flags & ~VM_LOCKED;
93754 if (flags & MCL_CURRENT)
93755 newflags |= VM_LOCKED;
93756@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93757 lock_limit >>= PAGE_SHIFT;
93758
93759 ret = -ENOMEM;
93760+
93761+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93762+
93763 down_write(&current->mm->mmap_sem);
93764-
93765 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93766 capable(CAP_IPC_LOCK))
93767 ret = do_mlockall(flags);
93768diff --git a/mm/mmap.c b/mm/mmap.c
93769index 20ff0c3..a9eda98 100644
93770--- a/mm/mmap.c
93771+++ b/mm/mmap.c
93772@@ -36,6 +36,7 @@
93773 #include <linux/sched/sysctl.h>
93774 #include <linux/notifier.h>
93775 #include <linux/memory.h>
93776+#include <linux/random.h>
93777
93778 #include <asm/uaccess.h>
93779 #include <asm/cacheflush.h>
93780@@ -52,6 +53,16 @@
93781 #define arch_rebalance_pgtables(addr, len) (addr)
93782 #endif
93783
93784+static inline void verify_mm_writelocked(struct mm_struct *mm)
93785+{
93786+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93787+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93788+ up_read(&mm->mmap_sem);
93789+ BUG();
93790+ }
93791+#endif
93792+}
93793+
93794 static void unmap_region(struct mm_struct *mm,
93795 struct vm_area_struct *vma, struct vm_area_struct *prev,
93796 unsigned long start, unsigned long end);
93797@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
93798 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93799 *
93800 */
93801-pgprot_t protection_map[16] = {
93802+pgprot_t protection_map[16] __read_only = {
93803 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93804 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93805 };
93806
93807-pgprot_t vm_get_page_prot(unsigned long vm_flags)
93808+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93809 {
93810- return __pgprot(pgprot_val(protection_map[vm_flags &
93811+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93812 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93813 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93814+
93815+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93816+ if (!(__supported_pte_mask & _PAGE_NX) &&
93817+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93818+ (vm_flags & (VM_READ | VM_WRITE)))
93819+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93820+#endif
93821+
93822+ return prot;
93823 }
93824 EXPORT_SYMBOL(vm_get_page_prot);
93825
93826@@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93827 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93828 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93829 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93830+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93831 /*
93832 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93833 * other variables. It can be updated by several CPUs frequently.
93834@@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93835 struct vm_area_struct *next = vma->vm_next;
93836
93837 might_sleep();
93838+ BUG_ON(vma->vm_mirror);
93839 if (vma->vm_ops && vma->vm_ops->close)
93840 vma->vm_ops->close(vma);
93841 if (vma->vm_file)
93842@@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93843 * not page aligned -Ram Gupta
93844 */
93845 rlim = rlimit(RLIMIT_DATA);
93846+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93847 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93848 (mm->end_data - mm->start_data) > rlim)
93849 goto out;
93850@@ -940,6 +963,12 @@ static int
93851 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93852 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93853 {
93854+
93855+#ifdef CONFIG_PAX_SEGMEXEC
93856+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93857+ return 0;
93858+#endif
93859+
93860 if (is_mergeable_vma(vma, file, vm_flags) &&
93861 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93862 if (vma->vm_pgoff == vm_pgoff)
93863@@ -959,6 +988,12 @@ static int
93864 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93865 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93866 {
93867+
93868+#ifdef CONFIG_PAX_SEGMEXEC
93869+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93870+ return 0;
93871+#endif
93872+
93873 if (is_mergeable_vma(vma, file, vm_flags) &&
93874 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93875 pgoff_t vm_pglen;
93876@@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93877 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93878 struct vm_area_struct *prev, unsigned long addr,
93879 unsigned long end, unsigned long vm_flags,
93880- struct anon_vma *anon_vma, struct file *file,
93881+ struct anon_vma *anon_vma, struct file *file,
93882 pgoff_t pgoff, struct mempolicy *policy)
93883 {
93884 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93885 struct vm_area_struct *area, *next;
93886 int err;
93887
93888+#ifdef CONFIG_PAX_SEGMEXEC
93889+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93890+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93891+
93892+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93893+#endif
93894+
93895 /*
93896 * We later require that vma->vm_flags == vm_flags,
93897 * so this tests vma->vm_flags & VM_SPECIAL, too.
93898@@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93899 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93900 next = next->vm_next;
93901
93902+#ifdef CONFIG_PAX_SEGMEXEC
93903+ if (prev)
93904+ prev_m = pax_find_mirror_vma(prev);
93905+ if (area)
93906+ area_m = pax_find_mirror_vma(area);
93907+ if (next)
93908+ next_m = pax_find_mirror_vma(next);
93909+#endif
93910+
93911 /*
93912 * Can it merge with the predecessor?
93913 */
93914@@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93915 /* cases 1, 6 */
93916 err = vma_adjust(prev, prev->vm_start,
93917 next->vm_end, prev->vm_pgoff, NULL);
93918- } else /* cases 2, 5, 7 */
93919+
93920+#ifdef CONFIG_PAX_SEGMEXEC
93921+ if (!err && prev_m)
93922+ err = vma_adjust(prev_m, prev_m->vm_start,
93923+ next_m->vm_end, prev_m->vm_pgoff, NULL);
93924+#endif
93925+
93926+ } else { /* cases 2, 5, 7 */
93927 err = vma_adjust(prev, prev->vm_start,
93928 end, prev->vm_pgoff, NULL);
93929+
93930+#ifdef CONFIG_PAX_SEGMEXEC
93931+ if (!err && prev_m)
93932+ err = vma_adjust(prev_m, prev_m->vm_start,
93933+ end_m, prev_m->vm_pgoff, NULL);
93934+#endif
93935+
93936+ }
93937 if (err)
93938 return NULL;
93939 khugepaged_enter_vma_merge(prev);
93940@@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93941 mpol_equal(policy, vma_policy(next)) &&
93942 can_vma_merge_before(next, vm_flags,
93943 anon_vma, file, pgoff+pglen)) {
93944- if (prev && addr < prev->vm_end) /* case 4 */
93945+ if (prev && addr < prev->vm_end) { /* case 4 */
93946 err = vma_adjust(prev, prev->vm_start,
93947 addr, prev->vm_pgoff, NULL);
93948- else /* cases 3, 8 */
93949+
93950+#ifdef CONFIG_PAX_SEGMEXEC
93951+ if (!err && prev_m)
93952+ err = vma_adjust(prev_m, prev_m->vm_start,
93953+ addr_m, prev_m->vm_pgoff, NULL);
93954+#endif
93955+
93956+ } else { /* cases 3, 8 */
93957 err = vma_adjust(area, addr, next->vm_end,
93958 next->vm_pgoff - pglen, NULL);
93959+
93960+#ifdef CONFIG_PAX_SEGMEXEC
93961+ if (!err && area_m)
93962+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
93963+ next_m->vm_pgoff - pglen, NULL);
93964+#endif
93965+
93966+ }
93967 if (err)
93968 return NULL;
93969 khugepaged_enter_vma_merge(area);
93970@@ -1172,8 +1253,10 @@ none:
93971 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93972 struct file *file, long pages)
93973 {
93974- const unsigned long stack_flags
93975- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93976+
93977+#ifdef CONFIG_PAX_RANDMMAP
93978+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93979+#endif
93980
93981 mm->total_vm += pages;
93982
93983@@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93984 mm->shared_vm += pages;
93985 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93986 mm->exec_vm += pages;
93987- } else if (flags & stack_flags)
93988+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93989 mm->stack_vm += pages;
93990 }
93991 #endif /* CONFIG_PROC_FS */
93992@@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93993 locked += mm->locked_vm;
93994 lock_limit = rlimit(RLIMIT_MEMLOCK);
93995 lock_limit >>= PAGE_SHIFT;
93996+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93997 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93998 return -EAGAIN;
93999 }
94000@@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94001 * (the exception is when the underlying filesystem is noexec
94002 * mounted, in which case we dont add PROT_EXEC.)
94003 */
94004- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94005+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94006 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
94007 prot |= PROT_EXEC;
94008
94009@@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94010 /* Obtain the address to map to. we verify (or select) it and ensure
94011 * that it represents a valid section of the address space.
94012 */
94013- addr = get_unmapped_area(file, addr, len, pgoff, flags);
94014+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
94015 if (addr & ~PAGE_MASK)
94016 return addr;
94017
94018@@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94019 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
94020 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
94021
94022+#ifdef CONFIG_PAX_MPROTECT
94023+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94024+
94025+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
94026+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
94027+ mm->binfmt->handle_mmap)
94028+ mm->binfmt->handle_mmap(file);
94029+#endif
94030+
94031+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94032+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
94033+ gr_log_rwxmmap(file);
94034+
94035+#ifdef CONFIG_PAX_EMUPLT
94036+ vm_flags &= ~VM_EXEC;
94037+#else
94038+ return -EPERM;
94039+#endif
94040+
94041+ }
94042+
94043+ if (!(vm_flags & VM_EXEC))
94044+ vm_flags &= ~VM_MAYEXEC;
94045+#else
94046+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94047+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94048+#endif
94049+ else
94050+ vm_flags &= ~VM_MAYWRITE;
94051+ }
94052+#endif
94053+
94054+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94055+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
94056+ vm_flags &= ~VM_PAGEEXEC;
94057+#endif
94058+
94059 if (flags & MAP_LOCKED)
94060 if (!can_do_mlock())
94061 return -EPERM;
94062@@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94063 vm_flags |= VM_NORESERVE;
94064 }
94065
94066+ if (!gr_acl_handle_mmap(file, prot))
94067+ return -EACCES;
94068+
94069 addr = mmap_region(file, addr, len, vm_flags, pgoff);
94070 if (!IS_ERR_VALUE(addr) &&
94071 ((vm_flags & VM_LOCKED) ||
94072@@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
94073 vm_flags_t vm_flags = vma->vm_flags;
94074
94075 /* If it was private or non-writable, the write bit is already clear */
94076- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
94077+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
94078 return 0;
94079
94080 /* The backer wishes to know when pages are first written to? */
94081@@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94082 struct rb_node **rb_link, *rb_parent;
94083 unsigned long charged = 0;
94084
94085+#ifdef CONFIG_PAX_SEGMEXEC
94086+ struct vm_area_struct *vma_m = NULL;
94087+#endif
94088+
94089+ /*
94090+ * mm->mmap_sem is required to protect against another thread
94091+ * changing the mappings in case we sleep.
94092+ */
94093+ verify_mm_writelocked(mm);
94094+
94095 /* Check against address space limit. */
94096+
94097+#ifdef CONFIG_PAX_RANDMMAP
94098+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94099+#endif
94100+
94101 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
94102 unsigned long nr_pages;
94103
94104@@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94105
94106 /* Clear old maps */
94107 error = -ENOMEM;
94108-munmap_back:
94109 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94110 if (do_munmap(mm, addr, len))
94111 return -ENOMEM;
94112- goto munmap_back;
94113+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94114 }
94115
94116 /*
94117@@ -1554,6 +1692,16 @@ munmap_back:
94118 goto unacct_error;
94119 }
94120
94121+#ifdef CONFIG_PAX_SEGMEXEC
94122+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
94123+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94124+ if (!vma_m) {
94125+ error = -ENOMEM;
94126+ goto free_vma;
94127+ }
94128+ }
94129+#endif
94130+
94131 vma->vm_mm = mm;
94132 vma->vm_start = addr;
94133 vma->vm_end = addr + len;
94134@@ -1573,6 +1721,13 @@ munmap_back:
94135 if (error)
94136 goto unmap_and_free_vma;
94137
94138+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94139+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
94140+ vma->vm_flags |= VM_PAGEEXEC;
94141+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94142+ }
94143+#endif
94144+
94145 /* Can addr have changed??
94146 *
94147 * Answer: Yes, several device drivers can do it in their
94148@@ -1606,6 +1761,12 @@ munmap_back:
94149 }
94150
94151 vma_link(mm, vma, prev, rb_link, rb_parent);
94152+
94153+#ifdef CONFIG_PAX_SEGMEXEC
94154+ if (vma_m)
94155+ BUG_ON(pax_mirror_vma(vma_m, vma));
94156+#endif
94157+
94158 /* Once vma denies write, undo our temporary denial count */
94159 if (vm_flags & VM_DENYWRITE)
94160 allow_write_access(file);
94161@@ -1614,6 +1775,7 @@ out:
94162 perf_event_mmap(vma);
94163
94164 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
94165+ track_exec_limit(mm, addr, addr + len, vm_flags);
94166 if (vm_flags & VM_LOCKED) {
94167 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94168 vma == get_gate_vma(current->mm)))
94169@@ -1646,6 +1808,12 @@ unmap_and_free_vma:
94170 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94171 charged = 0;
94172 free_vma:
94173+
94174+#ifdef CONFIG_PAX_SEGMEXEC
94175+ if (vma_m)
94176+ kmem_cache_free(vm_area_cachep, vma_m);
94177+#endif
94178+
94179 kmem_cache_free(vm_area_cachep, vma);
94180 unacct_error:
94181 if (charged)
94182@@ -1653,7 +1821,63 @@ unacct_error:
94183 return error;
94184 }
94185
94186-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94187+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94188+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94189+{
94190+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94191+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94192+
94193+ return 0;
94194+}
94195+#endif
94196+
94197+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94198+{
94199+ if (!vma) {
94200+#ifdef CONFIG_STACK_GROWSUP
94201+ if (addr > sysctl_heap_stack_gap)
94202+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94203+ else
94204+ vma = find_vma(current->mm, 0);
94205+ if (vma && (vma->vm_flags & VM_GROWSUP))
94206+ return false;
94207+#endif
94208+ return true;
94209+ }
94210+
94211+ if (addr + len > vma->vm_start)
94212+ return false;
94213+
94214+ if (vma->vm_flags & VM_GROWSDOWN)
94215+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94216+#ifdef CONFIG_STACK_GROWSUP
94217+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94218+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94219+#endif
94220+ else if (offset)
94221+ return offset <= vma->vm_start - addr - len;
94222+
94223+ return true;
94224+}
94225+
94226+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94227+{
94228+ if (vma->vm_start < len)
94229+ return -ENOMEM;
94230+
94231+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
94232+ if (offset <= vma->vm_start - len)
94233+ return vma->vm_start - len - offset;
94234+ else
94235+ return -ENOMEM;
94236+ }
94237+
94238+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
94239+ return vma->vm_start - len - sysctl_heap_stack_gap;
94240+ return -ENOMEM;
94241+}
94242+
94243+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94244 {
94245 /*
94246 * We implement the search by looking for an rbtree node that
94247@@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94248 }
94249 }
94250
94251- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94252+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94253 check_current:
94254 /* Check if current node has a suitable gap */
94255 if (gap_start > high_limit)
94256 return -ENOMEM;
94257+
94258+ if (gap_end - gap_start > info->threadstack_offset)
94259+ gap_start += info->threadstack_offset;
94260+ else
94261+ gap_start = gap_end;
94262+
94263+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94264+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94265+ gap_start += sysctl_heap_stack_gap;
94266+ else
94267+ gap_start = gap_end;
94268+ }
94269+ if (vma->vm_flags & VM_GROWSDOWN) {
94270+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94271+ gap_end -= sysctl_heap_stack_gap;
94272+ else
94273+ gap_end = gap_start;
94274+ }
94275 if (gap_end >= low_limit && gap_end - gap_start >= length)
94276 goto found;
94277
94278@@ -1755,7 +1997,7 @@ found:
94279 return gap_start;
94280 }
94281
94282-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94283+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94284 {
94285 struct mm_struct *mm = current->mm;
94286 struct vm_area_struct *vma;
94287@@ -1809,6 +2051,24 @@ check_current:
94288 gap_end = vma->vm_start;
94289 if (gap_end < low_limit)
94290 return -ENOMEM;
94291+
94292+ if (gap_end - gap_start > info->threadstack_offset)
94293+ gap_end -= info->threadstack_offset;
94294+ else
94295+ gap_end = gap_start;
94296+
94297+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94298+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94299+ gap_start += sysctl_heap_stack_gap;
94300+ else
94301+ gap_start = gap_end;
94302+ }
94303+ if (vma->vm_flags & VM_GROWSDOWN) {
94304+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94305+ gap_end -= sysctl_heap_stack_gap;
94306+ else
94307+ gap_end = gap_start;
94308+ }
94309 if (gap_start <= high_limit && gap_end - gap_start >= length)
94310 goto found;
94311
94312@@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94313 struct mm_struct *mm = current->mm;
94314 struct vm_area_struct *vma;
94315 struct vm_unmapped_area_info info;
94316+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94317
94318 if (len > TASK_SIZE - mmap_min_addr)
94319 return -ENOMEM;
94320@@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94321 if (flags & MAP_FIXED)
94322 return addr;
94323
94324+#ifdef CONFIG_PAX_RANDMMAP
94325+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94326+#endif
94327+
94328 if (addr) {
94329 addr = PAGE_ALIGN(addr);
94330 vma = find_vma(mm, addr);
94331 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94332- (!vma || addr + len <= vma->vm_start))
94333+ check_heap_stack_gap(vma, addr, len, offset))
94334 return addr;
94335 }
94336
94337@@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94338 info.low_limit = mm->mmap_base;
94339 info.high_limit = TASK_SIZE;
94340 info.align_mask = 0;
94341+ info.threadstack_offset = offset;
94342 return vm_unmapped_area(&info);
94343 }
94344 #endif
94345@@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94346 struct mm_struct *mm = current->mm;
94347 unsigned long addr = addr0;
94348 struct vm_unmapped_area_info info;
94349+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94350
94351 /* requested length too big for entire address space */
94352 if (len > TASK_SIZE - mmap_min_addr)
94353@@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94354 if (flags & MAP_FIXED)
94355 return addr;
94356
94357+#ifdef CONFIG_PAX_RANDMMAP
94358+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94359+#endif
94360+
94361 /* requesting a specific address */
94362 if (addr) {
94363 addr = PAGE_ALIGN(addr);
94364 vma = find_vma(mm, addr);
94365 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94366- (!vma || addr + len <= vma->vm_start))
94367+ check_heap_stack_gap(vma, addr, len, offset))
94368 return addr;
94369 }
94370
94371@@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94372 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94373 info.high_limit = mm->mmap_base;
94374 info.align_mask = 0;
94375+ info.threadstack_offset = offset;
94376 addr = vm_unmapped_area(&info);
94377
94378 /*
94379@@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94380 VM_BUG_ON(addr != -ENOMEM);
94381 info.flags = 0;
94382 info.low_limit = TASK_UNMAPPED_BASE;
94383+
94384+#ifdef CONFIG_PAX_RANDMMAP
94385+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94386+ info.low_limit += mm->delta_mmap;
94387+#endif
94388+
94389 info.high_limit = TASK_SIZE;
94390 addr = vm_unmapped_area(&info);
94391 }
94392@@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94393 return vma;
94394 }
94395
94396+#ifdef CONFIG_PAX_SEGMEXEC
94397+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94398+{
94399+ struct vm_area_struct *vma_m;
94400+
94401+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94402+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94403+ BUG_ON(vma->vm_mirror);
94404+ return NULL;
94405+ }
94406+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94407+ vma_m = vma->vm_mirror;
94408+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94409+ BUG_ON(vma->vm_file != vma_m->vm_file);
94410+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94411+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94412+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94413+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94414+ return vma_m;
94415+}
94416+#endif
94417+
94418 /*
94419 * Verify that the stack growth is acceptable and
94420 * update accounting. This is shared with both the
94421@@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94422 return -ENOMEM;
94423
94424 /* Stack limit test */
94425+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
94426 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94427 return -ENOMEM;
94428
94429@@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94430 locked = mm->locked_vm + grow;
94431 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94432 limit >>= PAGE_SHIFT;
94433+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94434 if (locked > limit && !capable(CAP_IPC_LOCK))
94435 return -ENOMEM;
94436 }
94437@@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94438 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94439 * vma is the last one with address > vma->vm_end. Have to extend vma.
94440 */
94441+#ifndef CONFIG_IA64
94442+static
94443+#endif
94444 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94445 {
94446 int error;
94447+ bool locknext;
94448
94449 if (!(vma->vm_flags & VM_GROWSUP))
94450 return -EFAULT;
94451
94452+ /* Also guard against wrapping around to address 0. */
94453+ if (address < PAGE_ALIGN(address+1))
94454+ address = PAGE_ALIGN(address+1);
94455+ else
94456+ return -ENOMEM;
94457+
94458 /*
94459 * We must make sure the anon_vma is allocated
94460 * so that the anon_vma locking is not a noop.
94461 */
94462 if (unlikely(anon_vma_prepare(vma)))
94463 return -ENOMEM;
94464+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94465+ if (locknext && anon_vma_prepare(vma->vm_next))
94466+ return -ENOMEM;
94467 vma_lock_anon_vma(vma);
94468+ if (locknext)
94469+ vma_lock_anon_vma(vma->vm_next);
94470
94471 /*
94472 * vma->vm_start/vm_end cannot change under us because the caller
94473 * is required to hold the mmap_sem in read mode. We need the
94474- * anon_vma lock to serialize against concurrent expand_stacks.
94475- * Also guard against wrapping around to address 0.
94476+ * anon_vma locks to serialize against concurrent expand_stacks
94477+ * and expand_upwards.
94478 */
94479- if (address < PAGE_ALIGN(address+4))
94480- address = PAGE_ALIGN(address+4);
94481- else {
94482- vma_unlock_anon_vma(vma);
94483- return -ENOMEM;
94484- }
94485 error = 0;
94486
94487 /* Somebody else might have raced and expanded it already */
94488- if (address > vma->vm_end) {
94489+ 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)
94490+ error = -ENOMEM;
94491+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94492 unsigned long size, grow;
94493
94494 size = address - vma->vm_start;
94495@@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94496 }
94497 }
94498 }
94499+ if (locknext)
94500+ vma_unlock_anon_vma(vma->vm_next);
94501 vma_unlock_anon_vma(vma);
94502 khugepaged_enter_vma_merge(vma);
94503 validate_mm(vma->vm_mm);
94504@@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
94505 unsigned long address)
94506 {
94507 int error;
94508+ bool lockprev = false;
94509+ struct vm_area_struct *prev;
94510
94511 /*
94512 * We must make sure the anon_vma is allocated
94513@@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
94514 if (error)
94515 return error;
94516
94517+ prev = vma->vm_prev;
94518+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94519+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94520+#endif
94521+ if (lockprev && anon_vma_prepare(prev))
94522+ return -ENOMEM;
94523+ if (lockprev)
94524+ vma_lock_anon_vma(prev);
94525+
94526 vma_lock_anon_vma(vma);
94527
94528 /*
94529@@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
94530 */
94531
94532 /* Somebody else might have raced and expanded it already */
94533- if (address < vma->vm_start) {
94534+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94535+ error = -ENOMEM;
94536+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94537 unsigned long size, grow;
94538
94539+#ifdef CONFIG_PAX_SEGMEXEC
94540+ struct vm_area_struct *vma_m;
94541+
94542+ vma_m = pax_find_mirror_vma(vma);
94543+#endif
94544+
94545 size = vma->vm_end - address;
94546 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94547
94548@@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
94549 vma->vm_pgoff -= grow;
94550 anon_vma_interval_tree_post_update_vma(vma);
94551 vma_gap_update(vma);
94552+
94553+#ifdef CONFIG_PAX_SEGMEXEC
94554+ if (vma_m) {
94555+ anon_vma_interval_tree_pre_update_vma(vma_m);
94556+ vma_m->vm_start -= grow << PAGE_SHIFT;
94557+ vma_m->vm_pgoff -= grow;
94558+ anon_vma_interval_tree_post_update_vma(vma_m);
94559+ vma_gap_update(vma_m);
94560+ }
94561+#endif
94562+
94563 spin_unlock(&vma->vm_mm->page_table_lock);
94564
94565+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94566 perf_event_mmap(vma);
94567 }
94568 }
94569 }
94570 vma_unlock_anon_vma(vma);
94571+ if (lockprev)
94572+ vma_unlock_anon_vma(prev);
94573 khugepaged_enter_vma_merge(vma);
94574 validate_mm(vma->vm_mm);
94575 return error;
94576@@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94577 do {
94578 long nrpages = vma_pages(vma);
94579
94580+#ifdef CONFIG_PAX_SEGMEXEC
94581+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94582+ vma = remove_vma(vma);
94583+ continue;
94584+ }
94585+#endif
94586+
94587 if (vma->vm_flags & VM_ACCOUNT)
94588 nr_accounted += nrpages;
94589 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94590@@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94591 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94592 vma->vm_prev = NULL;
94593 do {
94594+
94595+#ifdef CONFIG_PAX_SEGMEXEC
94596+ if (vma->vm_mirror) {
94597+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94598+ vma->vm_mirror->vm_mirror = NULL;
94599+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
94600+ vma->vm_mirror = NULL;
94601+ }
94602+#endif
94603+
94604 vma_rb_erase(vma, &mm->mm_rb);
94605 mm->map_count--;
94606 tail_vma = vma;
94607@@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94608 struct vm_area_struct *new;
94609 int err = -ENOMEM;
94610
94611+#ifdef CONFIG_PAX_SEGMEXEC
94612+ struct vm_area_struct *vma_m, *new_m = NULL;
94613+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94614+#endif
94615+
94616 if (is_vm_hugetlb_page(vma) && (addr &
94617 ~(huge_page_mask(hstate_vma(vma)))))
94618 return -EINVAL;
94619
94620+#ifdef CONFIG_PAX_SEGMEXEC
94621+ vma_m = pax_find_mirror_vma(vma);
94622+#endif
94623+
94624 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94625 if (!new)
94626 goto out_err;
94627
94628+#ifdef CONFIG_PAX_SEGMEXEC
94629+ if (vma_m) {
94630+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94631+ if (!new_m) {
94632+ kmem_cache_free(vm_area_cachep, new);
94633+ goto out_err;
94634+ }
94635+ }
94636+#endif
94637+
94638 /* most fields are the same, copy all, and then fixup */
94639 *new = *vma;
94640
94641@@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94642 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94643 }
94644
94645+#ifdef CONFIG_PAX_SEGMEXEC
94646+ if (vma_m) {
94647+ *new_m = *vma_m;
94648+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
94649+ new_m->vm_mirror = new;
94650+ new->vm_mirror = new_m;
94651+
94652+ if (new_below)
94653+ new_m->vm_end = addr_m;
94654+ else {
94655+ new_m->vm_start = addr_m;
94656+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94657+ }
94658+ }
94659+#endif
94660+
94661 err = vma_dup_policy(vma, new);
94662 if (err)
94663 goto out_free_vma;
94664@@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94665 else
94666 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94667
94668+#ifdef CONFIG_PAX_SEGMEXEC
94669+ if (!err && vma_m) {
94670+ struct mempolicy *pol = vma_policy(new);
94671+
94672+ if (anon_vma_clone(new_m, vma_m))
94673+ goto out_free_mpol;
94674+
94675+ mpol_get(pol);
94676+ set_vma_policy(new_m, pol);
94677+
94678+ if (new_m->vm_file)
94679+ get_file(new_m->vm_file);
94680+
94681+ if (new_m->vm_ops && new_m->vm_ops->open)
94682+ new_m->vm_ops->open(new_m);
94683+
94684+ if (new_below)
94685+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94686+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94687+ else
94688+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94689+
94690+ if (err) {
94691+ if (new_m->vm_ops && new_m->vm_ops->close)
94692+ new_m->vm_ops->close(new_m);
94693+ if (new_m->vm_file)
94694+ fput(new_m->vm_file);
94695+ mpol_put(pol);
94696+ }
94697+ }
94698+#endif
94699+
94700 /* Success. */
94701 if (!err)
94702 return 0;
94703@@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94704 new->vm_ops->close(new);
94705 if (new->vm_file)
94706 fput(new->vm_file);
94707- unlink_anon_vmas(new);
94708 out_free_mpol:
94709 mpol_put(vma_policy(new));
94710 out_free_vma:
94711+
94712+#ifdef CONFIG_PAX_SEGMEXEC
94713+ if (new_m) {
94714+ unlink_anon_vmas(new_m);
94715+ kmem_cache_free(vm_area_cachep, new_m);
94716+ }
94717+#endif
94718+
94719+ unlink_anon_vmas(new);
94720 kmem_cache_free(vm_area_cachep, new);
94721 out_err:
94722 return err;
94723@@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94724 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94725 unsigned long addr, int new_below)
94726 {
94727+
94728+#ifdef CONFIG_PAX_SEGMEXEC
94729+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94730+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94731+ if (mm->map_count >= sysctl_max_map_count-1)
94732+ return -ENOMEM;
94733+ } else
94734+#endif
94735+
94736 if (mm->map_count >= sysctl_max_map_count)
94737 return -ENOMEM;
94738
94739@@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94740 * work. This now handles partial unmappings.
94741 * Jeremy Fitzhardinge <jeremy@goop.org>
94742 */
94743+#ifdef CONFIG_PAX_SEGMEXEC
94744 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94745 {
94746+ int ret = __do_munmap(mm, start, len);
94747+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94748+ return ret;
94749+
94750+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94751+}
94752+
94753+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94754+#else
94755+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94756+#endif
94757+{
94758 unsigned long end;
94759 struct vm_area_struct *vma, *prev, *last;
94760
94761+ /*
94762+ * mm->mmap_sem is required to protect against another thread
94763+ * changing the mappings in case we sleep.
94764+ */
94765+ verify_mm_writelocked(mm);
94766+
94767 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94768 return -EINVAL;
94769
94770@@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94771 /* Fix up all other VM information */
94772 remove_vma_list(mm, vma);
94773
94774+ track_exec_limit(mm, start, end, 0UL);
94775+
94776 return 0;
94777 }
94778
94779@@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
94780 int ret;
94781 struct mm_struct *mm = current->mm;
94782
94783+
94784+#ifdef CONFIG_PAX_SEGMEXEC
94785+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94786+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94787+ return -EINVAL;
94788+#endif
94789+
94790 down_write(&mm->mmap_sem);
94791 ret = do_munmap(mm, start, len);
94792 up_write(&mm->mmap_sem);
94793@@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94794 return vm_munmap(addr, len);
94795 }
94796
94797-static inline void verify_mm_writelocked(struct mm_struct *mm)
94798-{
94799-#ifdef CONFIG_DEBUG_VM
94800- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94801- WARN_ON(1);
94802- up_read(&mm->mmap_sem);
94803- }
94804-#endif
94805-}
94806-
94807 /*
94808 * this is really a simplified "do_mmap". it only handles
94809 * anonymous maps. eventually we may be able to do some
94810@@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94811 struct rb_node ** rb_link, * rb_parent;
94812 pgoff_t pgoff = addr >> PAGE_SHIFT;
94813 int error;
94814+ unsigned long charged;
94815
94816 len = PAGE_ALIGN(len);
94817 if (!len)
94818@@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94819
94820 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94821
94822+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94823+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94824+ flags &= ~VM_EXEC;
94825+
94826+#ifdef CONFIG_PAX_MPROTECT
94827+ if (mm->pax_flags & MF_PAX_MPROTECT)
94828+ flags &= ~VM_MAYEXEC;
94829+#endif
94830+
94831+ }
94832+#endif
94833+
94834 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94835 if (error & ~PAGE_MASK)
94836 return error;
94837
94838+ charged = len >> PAGE_SHIFT;
94839+
94840 error = mlock_future_check(mm, mm->def_flags, len);
94841 if (error)
94842 return error;
94843@@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94844 /*
94845 * Clear old maps. this also does some error checking for us
94846 */
94847- munmap_back:
94848 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94849 if (do_munmap(mm, addr, len))
94850 return -ENOMEM;
94851- goto munmap_back;
94852+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94853 }
94854
94855 /* Check against address space limits *after* clearing old maps... */
94856- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94857+ if (!may_expand_vm(mm, charged))
94858 return -ENOMEM;
94859
94860 if (mm->map_count > sysctl_max_map_count)
94861 return -ENOMEM;
94862
94863- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94864+ if (security_vm_enough_memory_mm(mm, charged))
94865 return -ENOMEM;
94866
94867 /* Can we just expand an old private anonymous mapping? */
94868@@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94869 */
94870 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94871 if (!vma) {
94872- vm_unacct_memory(len >> PAGE_SHIFT);
94873+ vm_unacct_memory(charged);
94874 return -ENOMEM;
94875 }
94876
94877@@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94878 vma_link(mm, vma, prev, rb_link, rb_parent);
94879 out:
94880 perf_event_mmap(vma);
94881- mm->total_vm += len >> PAGE_SHIFT;
94882+ mm->total_vm += charged;
94883 if (flags & VM_LOCKED)
94884- mm->locked_vm += (len >> PAGE_SHIFT);
94885+ mm->locked_vm += charged;
94886 vma->vm_flags |= VM_SOFTDIRTY;
94887+ track_exec_limit(mm, addr, addr + len, flags);
94888 return addr;
94889 }
94890
94891@@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
94892 while (vma) {
94893 if (vma->vm_flags & VM_ACCOUNT)
94894 nr_accounted += vma_pages(vma);
94895+ vma->vm_mirror = NULL;
94896 vma = remove_vma(vma);
94897 }
94898 vm_unacct_memory(nr_accounted);
94899@@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94900 struct vm_area_struct *prev;
94901 struct rb_node **rb_link, *rb_parent;
94902
94903+#ifdef CONFIG_PAX_SEGMEXEC
94904+ struct vm_area_struct *vma_m = NULL;
94905+#endif
94906+
94907+ if (security_mmap_addr(vma->vm_start))
94908+ return -EPERM;
94909+
94910 /*
94911 * The vm_pgoff of a purely anonymous vma should be irrelevant
94912 * until its first write fault, when page's anon_vma and index
94913@@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94914 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94915 return -ENOMEM;
94916
94917+#ifdef CONFIG_PAX_SEGMEXEC
94918+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94919+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94920+ if (!vma_m)
94921+ return -ENOMEM;
94922+ }
94923+#endif
94924+
94925 vma_link(mm, vma, prev, rb_link, rb_parent);
94926+
94927+#ifdef CONFIG_PAX_SEGMEXEC
94928+ if (vma_m)
94929+ BUG_ON(pax_mirror_vma(vma_m, vma));
94930+#endif
94931+
94932 return 0;
94933 }
94934
94935@@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94936 struct rb_node **rb_link, *rb_parent;
94937 bool faulted_in_anon_vma = true;
94938
94939+ BUG_ON(vma->vm_mirror);
94940+
94941 /*
94942 * If anonymous vma has not yet been faulted, update new pgoff
94943 * to match new location, to increase its chance of merging.
94944@@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94945 return NULL;
94946 }
94947
94948+#ifdef CONFIG_PAX_SEGMEXEC
94949+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94950+{
94951+ struct vm_area_struct *prev_m;
94952+ struct rb_node **rb_link_m, *rb_parent_m;
94953+ struct mempolicy *pol_m;
94954+
94955+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94956+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94957+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94958+ *vma_m = *vma;
94959+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94960+ if (anon_vma_clone(vma_m, vma))
94961+ return -ENOMEM;
94962+ pol_m = vma_policy(vma_m);
94963+ mpol_get(pol_m);
94964+ set_vma_policy(vma_m, pol_m);
94965+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94966+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94967+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94968+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94969+ if (vma_m->vm_file)
94970+ get_file(vma_m->vm_file);
94971+ if (vma_m->vm_ops && vma_m->vm_ops->open)
94972+ vma_m->vm_ops->open(vma_m);
94973+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94974+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94975+ vma_m->vm_mirror = vma;
94976+ vma->vm_mirror = vma_m;
94977+ return 0;
94978+}
94979+#endif
94980+
94981 /*
94982 * Return true if the calling process may expand its vm space by the passed
94983 * number of pages
94984@@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94985
94986 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94987
94988+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94989 if (cur + npages > lim)
94990 return 0;
94991 return 1;
94992@@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
94993 vma->vm_start = addr;
94994 vma->vm_end = addr + len;
94995
94996+#ifdef CONFIG_PAX_MPROTECT
94997+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94998+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94999+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
95000+ return -EPERM;
95001+ if (!(vm_flags & VM_EXEC))
95002+ vm_flags &= ~VM_MAYEXEC;
95003+#else
95004+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
95005+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
95006+#endif
95007+ else
95008+ vm_flags &= ~VM_MAYWRITE;
95009+ }
95010+#endif
95011+
95012 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
95013 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
95014
95015diff --git a/mm/mprotect.c b/mm/mprotect.c
95016index 769a67a..414d24f 100644
95017--- a/mm/mprotect.c
95018+++ b/mm/mprotect.c
95019@@ -24,10 +24,18 @@
95020 #include <linux/migrate.h>
95021 #include <linux/perf_event.h>
95022 #include <linux/ksm.h>
95023+#include <linux/sched/sysctl.h>
95024+
95025+#ifdef CONFIG_PAX_MPROTECT
95026+#include <linux/elf.h>
95027+#include <linux/binfmts.h>
95028+#endif
95029+
95030 #include <asm/uaccess.h>
95031 #include <asm/pgtable.h>
95032 #include <asm/cacheflush.h>
95033 #include <asm/tlbflush.h>
95034+#include <asm/mmu_context.h>
95035
95036 #ifndef pgprot_modify
95037 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
95038@@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
95039 return pages;
95040 }
95041
95042+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95043+/* called while holding the mmap semaphor for writing except stack expansion */
95044+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
95045+{
95046+ unsigned long oldlimit, newlimit = 0UL;
95047+
95048+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
95049+ return;
95050+
95051+ spin_lock(&mm->page_table_lock);
95052+ oldlimit = mm->context.user_cs_limit;
95053+ if ((prot & VM_EXEC) && oldlimit < end)
95054+ /* USER_CS limit moved up */
95055+ newlimit = end;
95056+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
95057+ /* USER_CS limit moved down */
95058+ newlimit = start;
95059+
95060+ if (newlimit) {
95061+ mm->context.user_cs_limit = newlimit;
95062+
95063+#ifdef CONFIG_SMP
95064+ wmb();
95065+ cpus_clear(mm->context.cpu_user_cs_mask);
95066+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
95067+#endif
95068+
95069+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
95070+ }
95071+ spin_unlock(&mm->page_table_lock);
95072+ if (newlimit == end) {
95073+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
95074+
95075+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
95076+ if (is_vm_hugetlb_page(vma))
95077+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
95078+ else
95079+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
95080+ }
95081+}
95082+#endif
95083+
95084 int
95085 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95086 unsigned long start, unsigned long end, unsigned long newflags)
95087@@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95088 int error;
95089 int dirty_accountable = 0;
95090
95091+#ifdef CONFIG_PAX_SEGMEXEC
95092+ struct vm_area_struct *vma_m = NULL;
95093+ unsigned long start_m, end_m;
95094+
95095+ start_m = start + SEGMEXEC_TASK_SIZE;
95096+ end_m = end + SEGMEXEC_TASK_SIZE;
95097+#endif
95098+
95099 if (newflags == oldflags) {
95100 *pprev = vma;
95101 return 0;
95102 }
95103
95104+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
95105+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
95106+
95107+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
95108+ return -ENOMEM;
95109+
95110+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
95111+ return -ENOMEM;
95112+ }
95113+
95114 /*
95115 * If we make a private mapping writable we increase our commit;
95116 * but (without finer accounting) cannot reduce our commit if we
95117@@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95118 }
95119 }
95120
95121+#ifdef CONFIG_PAX_SEGMEXEC
95122+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
95123+ if (start != vma->vm_start) {
95124+ error = split_vma(mm, vma, start, 1);
95125+ if (error)
95126+ goto fail;
95127+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
95128+ *pprev = (*pprev)->vm_next;
95129+ }
95130+
95131+ if (end != vma->vm_end) {
95132+ error = split_vma(mm, vma, end, 0);
95133+ if (error)
95134+ goto fail;
95135+ }
95136+
95137+ if (pax_find_mirror_vma(vma)) {
95138+ error = __do_munmap(mm, start_m, end_m - start_m);
95139+ if (error)
95140+ goto fail;
95141+ } else {
95142+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95143+ if (!vma_m) {
95144+ error = -ENOMEM;
95145+ goto fail;
95146+ }
95147+ vma->vm_flags = newflags;
95148+ error = pax_mirror_vma(vma_m, vma);
95149+ if (error) {
95150+ vma->vm_flags = oldflags;
95151+ goto fail;
95152+ }
95153+ }
95154+ }
95155+#endif
95156+
95157 /*
95158 * First try to merge with previous and/or next vma.
95159 */
95160@@ -277,9 +381,21 @@ success:
95161 * vm_flags and vm_page_prot are protected by the mmap_sem
95162 * held in write mode.
95163 */
95164+
95165+#ifdef CONFIG_PAX_SEGMEXEC
95166+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
95167+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95168+#endif
95169+
95170 vma->vm_flags = newflags;
95171+
95172+#ifdef CONFIG_PAX_MPROTECT
95173+ if (mm->binfmt && mm->binfmt->handle_mprotect)
95174+ mm->binfmt->handle_mprotect(vma, newflags);
95175+#endif
95176+
95177 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95178- vm_get_page_prot(newflags));
95179+ vm_get_page_prot(vma->vm_flags));
95180
95181 if (vma_wants_writenotify(vma)) {
95182 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95183@@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95184 end = start + len;
95185 if (end <= start)
95186 return -ENOMEM;
95187+
95188+#ifdef CONFIG_PAX_SEGMEXEC
95189+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95190+ if (end > SEGMEXEC_TASK_SIZE)
95191+ return -EINVAL;
95192+ } else
95193+#endif
95194+
95195+ if (end > TASK_SIZE)
95196+ return -EINVAL;
95197+
95198 if (!arch_validate_prot(prot))
95199 return -EINVAL;
95200
95201@@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95202 /*
95203 * Does the application expect PROT_READ to imply PROT_EXEC:
95204 */
95205- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95206+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95207 prot |= PROT_EXEC;
95208
95209 vm_flags = calc_vm_prot_bits(prot);
95210@@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95211 if (start > vma->vm_start)
95212 prev = vma;
95213
95214+#ifdef CONFIG_PAX_MPROTECT
95215+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95216+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
95217+#endif
95218+
95219 for (nstart = start ; ; ) {
95220 unsigned long newflags;
95221
95222@@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95223
95224 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95225 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95226+ if (prot & (PROT_WRITE | PROT_EXEC))
95227+ gr_log_rwxmprotect(vma);
95228+
95229+ error = -EACCES;
95230+ goto out;
95231+ }
95232+
95233+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95234 error = -EACCES;
95235 goto out;
95236 }
95237@@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95238 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95239 if (error)
95240 goto out;
95241+
95242+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
95243+
95244 nstart = tmp;
95245
95246 if (nstart < prev->vm_end)
95247diff --git a/mm/mremap.c b/mm/mremap.c
95248index 0843feb..c3cde48 100644
95249--- a/mm/mremap.c
95250+++ b/mm/mremap.c
95251@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95252 continue;
95253 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95254 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95255+
95256+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95257+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95258+ pte = pte_exprotect(pte);
95259+#endif
95260+
95261 pte = move_soft_dirty_pte(pte);
95262 set_pte_at(mm, new_addr, new_pte, pte);
95263 }
95264@@ -194,10 +200,17 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
95265 break;
95266 if (pmd_trans_huge(*old_pmd)) {
95267 int err = 0;
95268- if (extent == HPAGE_PMD_SIZE)
95269+ if (extent == HPAGE_PMD_SIZE) {
95270+ VM_BUG_ON(vma->vm_file || !vma->anon_vma);
95271+ /* See comment in move_ptes() */
95272+ if (need_rmap_locks)
95273+ anon_vma_lock_write(vma->anon_vma);
95274 err = move_huge_pmd(vma, new_vma, old_addr,
95275 new_addr, old_end,
95276 old_pmd, new_pmd);
95277+ if (need_rmap_locks)
95278+ anon_vma_unlock_write(vma->anon_vma);
95279+ }
95280 if (err > 0) {
95281 need_flush = true;
95282 continue;
95283@@ -337,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95284 if (is_vm_hugetlb_page(vma))
95285 goto Einval;
95286
95287+#ifdef CONFIG_PAX_SEGMEXEC
95288+ if (pax_find_mirror_vma(vma))
95289+ goto Einval;
95290+#endif
95291+
95292 /* We can't remap across vm area boundaries */
95293 if (old_len > vma->vm_end - addr)
95294 goto Efault;
95295@@ -392,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95296 unsigned long ret = -EINVAL;
95297 unsigned long charged = 0;
95298 unsigned long map_flags;
95299+ unsigned long pax_task_size = TASK_SIZE;
95300
95301 if (new_addr & ~PAGE_MASK)
95302 goto out;
95303
95304- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95305+#ifdef CONFIG_PAX_SEGMEXEC
95306+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95307+ pax_task_size = SEGMEXEC_TASK_SIZE;
95308+#endif
95309+
95310+ pax_task_size -= PAGE_SIZE;
95311+
95312+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95313 goto out;
95314
95315 /* Check if the location we're moving into overlaps the
95316 * old location at all, and fail if it does.
95317 */
95318- if ((new_addr <= addr) && (new_addr+new_len) > addr)
95319- goto out;
95320-
95321- if ((addr <= new_addr) && (addr+old_len) > new_addr)
95322+ if (addr + old_len > new_addr && new_addr + new_len > addr)
95323 goto out;
95324
95325 ret = do_munmap(mm, new_addr, new_len);
95326@@ -474,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95327 unsigned long ret = -EINVAL;
95328 unsigned long charged = 0;
95329 bool locked = false;
95330+ unsigned long pax_task_size = TASK_SIZE;
95331
95332 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95333 return ret;
95334@@ -495,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95335 if (!new_len)
95336 return ret;
95337
95338+#ifdef CONFIG_PAX_SEGMEXEC
95339+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95340+ pax_task_size = SEGMEXEC_TASK_SIZE;
95341+#endif
95342+
95343+ pax_task_size -= PAGE_SIZE;
95344+
95345+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95346+ old_len > pax_task_size || addr > pax_task_size-old_len)
95347+ return ret;
95348+
95349 down_write(&current->mm->mmap_sem);
95350
95351 if (flags & MREMAP_FIXED) {
95352@@ -545,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95353 new_addr = addr;
95354 }
95355 ret = addr;
95356+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95357 goto out;
95358 }
95359 }
95360@@ -568,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95361 goto out;
95362 }
95363
95364+ map_flags = vma->vm_flags;
95365 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95366+ if (!(ret & ~PAGE_MASK)) {
95367+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95368+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95369+ }
95370 }
95371 out:
95372 if (ret & ~PAGE_MASK)
95373diff --git a/mm/nommu.c b/mm/nommu.c
95374index 8740213..f87e25b 100644
95375--- a/mm/nommu.c
95376+++ b/mm/nommu.c
95377@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95378 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95379 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95380 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95381-int heap_stack_gap = 0;
95382
95383 atomic_long_t mmap_pages_allocated;
95384
95385@@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95386 EXPORT_SYMBOL(find_vma);
95387
95388 /*
95389- * find a VMA
95390- * - we don't extend stack VMAs under NOMMU conditions
95391- */
95392-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95393-{
95394- return find_vma(mm, addr);
95395-}
95396-
95397-/*
95398 * expand a stack to a given address
95399 * - not supported under NOMMU conditions
95400 */
95401@@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95402
95403 /* most fields are the same, copy all, and then fixup */
95404 *new = *vma;
95405+ INIT_LIST_HEAD(&new->anon_vma_chain);
95406 *region = *vma->vm_region;
95407 new->vm_region = region;
95408
95409@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95410 }
95411 EXPORT_SYMBOL(generic_file_remap_pages);
95412
95413-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95414- unsigned long addr, void *buf, int len, int write)
95415+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95416+ unsigned long addr, void *buf, size_t len, int write)
95417 {
95418 struct vm_area_struct *vma;
95419
95420@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95421 *
95422 * The caller must hold a reference on @mm.
95423 */
95424-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95425- void *buf, int len, int write)
95426+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95427+ void *buf, size_t len, int write)
95428 {
95429 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95430 }
95431@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95432 * Access another process' address space.
95433 * - source/target buffer must be kernel space
95434 */
95435-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95436+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95437 {
95438 struct mm_struct *mm;
95439
95440diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95441index 7106cb1..0805f48 100644
95442--- a/mm/page-writeback.c
95443+++ b/mm/page-writeback.c
95444@@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
95445 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95446 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95447 */
95448-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95449+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95450 unsigned long thresh,
95451 unsigned long bg_thresh,
95452 unsigned long dirty,
95453diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95454index 7387a67..67105e4 100644
95455--- a/mm/page_alloc.c
95456+++ b/mm/page_alloc.c
95457@@ -61,6 +61,7 @@
95458 #include <linux/page-debug-flags.h>
95459 #include <linux/hugetlb.h>
95460 #include <linux/sched/rt.h>
95461+#include <linux/random.h>
95462
95463 #include <asm/sections.h>
95464 #include <asm/tlbflush.h>
95465@@ -354,7 +355,7 @@ out:
95466 * This usage means that zero-order pages may not be compound.
95467 */
95468
95469-static void free_compound_page(struct page *page)
95470+void free_compound_page(struct page *page)
95471 {
95472 __free_pages_ok(page, compound_order(page));
95473 }
95474@@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95475 int i;
95476 int bad = 0;
95477
95478+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95479+ unsigned long index = 1UL << order;
95480+#endif
95481+
95482 trace_mm_page_free(page, order);
95483 kmemcheck_free_shadow(page, order);
95484
95485@@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95486 debug_check_no_obj_freed(page_address(page),
95487 PAGE_SIZE << order);
95488 }
95489+
95490+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95491+ for (; index; --index)
95492+ sanitize_highpage(page + index - 1);
95493+#endif
95494+
95495 arch_free_page(page, order);
95496 kernel_map_pages(page, 1 << order, 0);
95497
95498@@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95499 local_irq_restore(flags);
95500 }
95501
95502+#ifdef CONFIG_PAX_LATENT_ENTROPY
95503+bool __meminitdata extra_latent_entropy;
95504+
95505+static int __init setup_pax_extra_latent_entropy(char *str)
95506+{
95507+ extra_latent_entropy = true;
95508+ return 0;
95509+}
95510+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95511+
95512+volatile u64 latent_entropy __latent_entropy;
95513+EXPORT_SYMBOL(latent_entropy);
95514+#endif
95515+
95516 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95517 {
95518 unsigned int nr_pages = 1 << order;
95519@@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95520 __ClearPageReserved(p);
95521 set_page_count(p, 0);
95522
95523+#ifdef CONFIG_PAX_LATENT_ENTROPY
95524+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95525+ u64 hash = 0;
95526+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95527+ const u64 *data = lowmem_page_address(page);
95528+
95529+ for (index = 0; index < end; index++)
95530+ hash ^= hash + data[index];
95531+ latent_entropy ^= hash;
95532+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95533+ }
95534+#endif
95535+
95536 page_zone(page)->managed_pages += nr_pages;
95537 set_page_refcounted(page);
95538 __free_pages(page, order);
95539@@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95540 arch_alloc_page(page, order);
95541 kernel_map_pages(page, 1 << order, 1);
95542
95543+#ifndef CONFIG_PAX_MEMORY_SANITIZE
95544 if (gfp_flags & __GFP_ZERO)
95545 prep_zero_page(page, order, gfp_flags);
95546+#endif
95547
95548 if (order && (gfp_flags & __GFP_COMP))
95549 prep_compound_page(page, order);
95550@@ -2401,7 +2441,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95551 continue;
95552 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95553 high_wmark_pages(zone) - low_wmark_pages(zone) -
95554- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95555+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95556 }
95557 }
95558
95559@@ -6565,4 +6605,4 @@ void dump_page(struct page *page, char *reason)
95560 {
95561 dump_page_badflags(page, reason, 0);
95562 }
95563-EXPORT_SYMBOL_GPL(dump_page);
95564+EXPORT_SYMBOL(dump_page);
95565diff --git a/mm/page_io.c b/mm/page_io.c
95566index 7c59ef6..1358905 100644
95567--- a/mm/page_io.c
95568+++ b/mm/page_io.c
95569@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95570 struct file *swap_file = sis->swap_file;
95571 struct address_space *mapping = swap_file->f_mapping;
95572 struct iovec iov = {
95573- .iov_base = kmap(page),
95574+ .iov_base = (void __force_user *)kmap(page),
95575 .iov_len = PAGE_SIZE,
95576 };
95577
95578diff --git a/mm/percpu.c b/mm/percpu.c
95579index 036cfe0..980d0fa 100644
95580--- a/mm/percpu.c
95581+++ b/mm/percpu.c
95582@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95583 static unsigned int pcpu_high_unit_cpu __read_mostly;
95584
95585 /* the address of the first chunk which starts with the kernel static area */
95586-void *pcpu_base_addr __read_mostly;
95587+void *pcpu_base_addr __read_only;
95588 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95589
95590 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95591diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95592index fd26d04..0cea1b0 100644
95593--- a/mm/process_vm_access.c
95594+++ b/mm/process_vm_access.c
95595@@ -13,6 +13,7 @@
95596 #include <linux/uio.h>
95597 #include <linux/sched.h>
95598 #include <linux/highmem.h>
95599+#include <linux/security.h>
95600 #include <linux/ptrace.h>
95601 #include <linux/slab.h>
95602 #include <linux/syscalls.h>
95603@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95604 size_t iov_l_curr_offset = 0;
95605 ssize_t iov_len;
95606
95607+ return -ENOSYS; // PaX: until properly audited
95608+
95609 /*
95610 * Work out how many pages of struct pages we're going to need
95611 * when eventually calling get_user_pages
95612 */
95613 for (i = 0; i < riovcnt; i++) {
95614 iov_len = rvec[i].iov_len;
95615- if (iov_len > 0) {
95616- nr_pages_iov = ((unsigned long)rvec[i].iov_base
95617- + iov_len)
95618- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95619- / PAGE_SIZE + 1;
95620- nr_pages = max(nr_pages, nr_pages_iov);
95621- }
95622+ if (iov_len <= 0)
95623+ continue;
95624+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95625+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95626+ nr_pages = max(nr_pages, nr_pages_iov);
95627 }
95628
95629 if (nr_pages == 0)
95630@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95631 goto free_proc_pages;
95632 }
95633
95634+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95635+ rc = -EPERM;
95636+ goto put_task_struct;
95637+ }
95638+
95639 mm = mm_access(task, PTRACE_MODE_ATTACH);
95640 if (!mm || IS_ERR(mm)) {
95641 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95642diff --git a/mm/rmap.c b/mm/rmap.c
95643index d3cbac5..0788da4 100644
95644--- a/mm/rmap.c
95645+++ b/mm/rmap.c
95646@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95647 struct anon_vma *anon_vma = vma->anon_vma;
95648 struct anon_vma_chain *avc;
95649
95650+#ifdef CONFIG_PAX_SEGMEXEC
95651+ struct anon_vma_chain *avc_m = NULL;
95652+#endif
95653+
95654 might_sleep();
95655 if (unlikely(!anon_vma)) {
95656 struct mm_struct *mm = vma->vm_mm;
95657@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95658 if (!avc)
95659 goto out_enomem;
95660
95661+#ifdef CONFIG_PAX_SEGMEXEC
95662+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95663+ if (!avc_m)
95664+ goto out_enomem_free_avc;
95665+#endif
95666+
95667 anon_vma = find_mergeable_anon_vma(vma);
95668 allocated = NULL;
95669 if (!anon_vma) {
95670@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95671 /* page_table_lock to protect against threads */
95672 spin_lock(&mm->page_table_lock);
95673 if (likely(!vma->anon_vma)) {
95674+
95675+#ifdef CONFIG_PAX_SEGMEXEC
95676+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95677+
95678+ if (vma_m) {
95679+ BUG_ON(vma_m->anon_vma);
95680+ vma_m->anon_vma = anon_vma;
95681+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
95682+ avc_m = NULL;
95683+ }
95684+#endif
95685+
95686 vma->anon_vma = anon_vma;
95687 anon_vma_chain_link(vma, avc, anon_vma);
95688 allocated = NULL;
95689@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95690
95691 if (unlikely(allocated))
95692 put_anon_vma(allocated);
95693+
95694+#ifdef CONFIG_PAX_SEGMEXEC
95695+ if (unlikely(avc_m))
95696+ anon_vma_chain_free(avc_m);
95697+#endif
95698+
95699 if (unlikely(avc))
95700 anon_vma_chain_free(avc);
95701 }
95702 return 0;
95703
95704 out_enomem_free_avc:
95705+
95706+#ifdef CONFIG_PAX_SEGMEXEC
95707+ if (avc_m)
95708+ anon_vma_chain_free(avc_m);
95709+#endif
95710+
95711 anon_vma_chain_free(avc);
95712 out_enomem:
95713 return -ENOMEM;
95714@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95715 * Attach the anon_vmas from src to dst.
95716 * Returns 0 on success, -ENOMEM on failure.
95717 */
95718-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95719+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95720 {
95721 struct anon_vma_chain *avc, *pavc;
95722 struct anon_vma *root = NULL;
95723@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95724 * the corresponding VMA in the parent process is attached to.
95725 * Returns 0 on success, non-zero on failure.
95726 */
95727-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95728+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95729 {
95730 struct anon_vma_chain *avc;
95731 struct anon_vma *anon_vma;
95732@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
95733 void __init anon_vma_init(void)
95734 {
95735 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95736- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95737- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95738+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95739+ anon_vma_ctor);
95740+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95741+ SLAB_PANIC|SLAB_NO_SANITIZE);
95742 }
95743
95744 /*
95745diff --git a/mm/shmem.c b/mm/shmem.c
95746index 1f18c9d..3e03d33 100644
95747--- a/mm/shmem.c
95748+++ b/mm/shmem.c
95749@@ -33,7 +33,7 @@
95750 #include <linux/swap.h>
95751 #include <linux/aio.h>
95752
95753-static struct vfsmount *shm_mnt;
95754+struct vfsmount *shm_mnt;
95755
95756 #ifdef CONFIG_SHMEM
95757 /*
95758@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
95759 #define BOGO_DIRENT_SIZE 20
95760
95761 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95762-#define SHORT_SYMLINK_LEN 128
95763+#define SHORT_SYMLINK_LEN 64
95764
95765 /*
95766 * shmem_fallocate and shmem_writepage communicate via inode->i_private
95767@@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95768 static int shmem_xattr_validate(const char *name)
95769 {
95770 struct { const char *prefix; size_t len; } arr[] = {
95771+
95772+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95773+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95774+#endif
95775+
95776 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95777 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95778 };
95779@@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95780 if (err)
95781 return err;
95782
95783+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95784+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95785+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95786+ return -EOPNOTSUPP;
95787+ if (size > 8)
95788+ return -EINVAL;
95789+ }
95790+#endif
95791+
95792 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95793 }
95794
95795@@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95796 int err = -ENOMEM;
95797
95798 /* Round up to L1_CACHE_BYTES to resist false sharing */
95799- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95800- L1_CACHE_BYTES), GFP_KERNEL);
95801+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95802 if (!sbinfo)
95803 return -ENOMEM;
95804
95805diff --git a/mm/slab.c b/mm/slab.c
95806index b264214..83872cd 100644
95807--- a/mm/slab.c
95808+++ b/mm/slab.c
95809@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95810 if ((x)->max_freeable < i) \
95811 (x)->max_freeable = i; \
95812 } while (0)
95813-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95814-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95815-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95816-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95817+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95818+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95819+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95820+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95821+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95822+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95823 #else
95824 #define STATS_INC_ACTIVE(x) do { } while (0)
95825 #define STATS_DEC_ACTIVE(x) do { } while (0)
95826@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95827 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95828 #define STATS_INC_FREEHIT(x) do { } while (0)
95829 #define STATS_INC_FREEMISS(x) do { } while (0)
95830+#define STATS_INC_SANITIZED(x) do { } while (0)
95831+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95832 #endif
95833
95834 #if DEBUG
95835@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95836 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95837 */
95838 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95839- const struct page *page, void *obj)
95840+ const struct page *page, const void *obj)
95841 {
95842 u32 offset = (obj - page->s_mem);
95843 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95844@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
95845 */
95846
95847 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95848- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95849+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95850
95851 if (INDEX_AC != INDEX_NODE)
95852 kmalloc_caches[INDEX_NODE] =
95853 create_kmalloc_cache("kmalloc-node",
95854- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95855+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95856
95857 slab_early_init = 0;
95858
95859@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95860 struct array_cache *ac = cpu_cache_get(cachep);
95861
95862 check_irq_off();
95863+
95864+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95865+ if (pax_sanitize_slab) {
95866+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95867+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95868+
95869+ if (cachep->ctor)
95870+ cachep->ctor(objp);
95871+
95872+ STATS_INC_SANITIZED(cachep);
95873+ } else
95874+ STATS_INC_NOT_SANITIZED(cachep);
95875+ }
95876+#endif
95877+
95878 kmemleak_free_recursive(objp, cachep->flags);
95879 objp = cache_free_debugcheck(cachep, objp, caller);
95880
95881@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
95882
95883 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95884 return;
95885+ VM_BUG_ON(!virt_addr_valid(objp));
95886 local_irq_save(flags);
95887 kfree_debugcheck(objp);
95888 c = virt_to_cache(objp);
95889@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95890 }
95891 /* cpu stats */
95892 {
95893- unsigned long allochit = atomic_read(&cachep->allochit);
95894- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95895- unsigned long freehit = atomic_read(&cachep->freehit);
95896- unsigned long freemiss = atomic_read(&cachep->freemiss);
95897+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95898+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95899+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95900+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95901
95902 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95903 allochit, allocmiss, freehit, freemiss);
95904 }
95905+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95906+ {
95907+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95908+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95909+
95910+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95911+ }
95912+#endif
95913 #endif
95914 }
95915
95916@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
95917 static int __init slab_proc_init(void)
95918 {
95919 #ifdef CONFIG_DEBUG_SLAB_LEAK
95920- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
95921+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
95922 #endif
95923 return 0;
95924 }
95925 module_init(slab_proc_init);
95926 #endif
95927
95928+bool is_usercopy_object(const void *ptr)
95929+{
95930+ struct page *page;
95931+ struct kmem_cache *cachep;
95932+
95933+ if (ZERO_OR_NULL_PTR(ptr))
95934+ return false;
95935+
95936+ if (!slab_is_available())
95937+ return false;
95938+
95939+ if (!virt_addr_valid(ptr))
95940+ return false;
95941+
95942+ page = virt_to_head_page(ptr);
95943+
95944+ if (!PageSlab(page))
95945+ return false;
95946+
95947+ cachep = page->slab_cache;
95948+ return cachep->flags & SLAB_USERCOPY;
95949+}
95950+
95951+#ifdef CONFIG_PAX_USERCOPY
95952+const char *check_heap_object(const void *ptr, unsigned long n)
95953+{
95954+ struct page *page;
95955+ struct kmem_cache *cachep;
95956+ unsigned int objnr;
95957+ unsigned long offset;
95958+
95959+ if (ZERO_OR_NULL_PTR(ptr))
95960+ return "<null>";
95961+
95962+ if (!virt_addr_valid(ptr))
95963+ return NULL;
95964+
95965+ page = virt_to_head_page(ptr);
95966+
95967+ if (!PageSlab(page))
95968+ return NULL;
95969+
95970+ cachep = page->slab_cache;
95971+ if (!(cachep->flags & SLAB_USERCOPY))
95972+ return cachep->name;
95973+
95974+ objnr = obj_to_index(cachep, page, ptr);
95975+ BUG_ON(objnr >= cachep->num);
95976+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95977+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95978+ return NULL;
95979+
95980+ return cachep->name;
95981+}
95982+#endif
95983+
95984 /**
95985 * ksize - get the actual amount of memory allocated for a given object
95986 * @objp: Pointer to the object
95987diff --git a/mm/slab.h b/mm/slab.h
95988index 8184a7c..ab27737 100644
95989--- a/mm/slab.h
95990+++ b/mm/slab.h
95991@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95992 /* The slab cache that manages slab cache information */
95993 extern struct kmem_cache *kmem_cache;
95994
95995+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95996+#ifdef CONFIG_X86_64
95997+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95998+#else
95999+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
96000+#endif
96001+extern bool pax_sanitize_slab;
96002+#endif
96003+
96004 unsigned long calculate_alignment(unsigned long flags,
96005 unsigned long align, unsigned long size);
96006
96007@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96008
96009 /* Legal flag mask for kmem_cache_create(), for various configurations */
96010 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
96011- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
96012+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
96013+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
96014
96015 #if defined(CONFIG_DEBUG_SLAB)
96016 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
96017@@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
96018 return s;
96019
96020 page = virt_to_head_page(x);
96021+
96022+ BUG_ON(!PageSlab(page));
96023+
96024 cachep = page->slab_cache;
96025 if (slab_equal_or_root(cachep, s))
96026 return cachep;
96027diff --git a/mm/slab_common.c b/mm/slab_common.c
96028index 1ec3c61..2067c11 100644
96029--- a/mm/slab_common.c
96030+++ b/mm/slab_common.c
96031@@ -23,11 +23,22 @@
96032
96033 #include "slab.h"
96034
96035-enum slab_state slab_state;
96036+enum slab_state slab_state __read_only;
96037 LIST_HEAD(slab_caches);
96038 DEFINE_MUTEX(slab_mutex);
96039 struct kmem_cache *kmem_cache;
96040
96041+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96042+bool pax_sanitize_slab __read_only = true;
96043+static int __init pax_sanitize_slab_setup(char *str)
96044+{
96045+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
96046+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
96047+ return 1;
96048+}
96049+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
96050+#endif
96051+
96052 #ifdef CONFIG_DEBUG_VM
96053 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
96054 size_t size)
96055@@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
96056 if (err)
96057 goto out_free_cache;
96058
96059- s->refcount = 1;
96060+ atomic_set(&s->refcount, 1);
96061 list_add(&s->list, &slab_caches);
96062 memcg_register_cache(s);
96063
96064@@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96065
96066 get_online_cpus();
96067 mutex_lock(&slab_mutex);
96068- s->refcount--;
96069- if (!s->refcount) {
96070+ if (atomic_dec_and_test(&s->refcount)) {
96071 list_del(&s->list);
96072
96073 if (!__kmem_cache_shutdown(s)) {
96074@@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
96075 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
96076 name, size, err);
96077
96078- s->refcount = -1; /* Exempt from merging for now */
96079+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
96080 }
96081
96082 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96083@@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96084
96085 create_boot_cache(s, name, size, flags);
96086 list_add(&s->list, &slab_caches);
96087- s->refcount = 1;
96088+ atomic_set(&s->refcount, 1);
96089 return s;
96090 }
96091
96092@@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
96093 EXPORT_SYMBOL(kmalloc_dma_caches);
96094 #endif
96095
96096+#ifdef CONFIG_PAX_USERCOPY_SLABS
96097+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
96098+EXPORT_SYMBOL(kmalloc_usercopy_caches);
96099+#endif
96100+
96101 /*
96102 * Conversion table for small slabs sizes / 8 to the index in the
96103 * kmalloc array. This is necessary for slabs < 192 since we have non power
96104@@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
96105 return kmalloc_dma_caches[index];
96106
96107 #endif
96108+
96109+#ifdef CONFIG_PAX_USERCOPY_SLABS
96110+ if (unlikely((flags & GFP_USERCOPY)))
96111+ return kmalloc_usercopy_caches[index];
96112+
96113+#endif
96114+
96115 return kmalloc_caches[index];
96116 }
96117
96118@@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
96119 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
96120 if (!kmalloc_caches[i]) {
96121 kmalloc_caches[i] = create_kmalloc_cache(NULL,
96122- 1 << i, flags);
96123+ 1 << i, SLAB_USERCOPY | flags);
96124 }
96125
96126 /*
96127@@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
96128 * earlier power of two caches
96129 */
96130 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
96131- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
96132+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
96133
96134 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
96135- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
96136+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
96137 }
96138
96139 /* Kmalloc array is now usable */
96140@@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
96141 }
96142 }
96143 #endif
96144+
96145+#ifdef CONFIG_PAX_USERCOPY_SLABS
96146+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96147+ struct kmem_cache *s = kmalloc_caches[i];
96148+
96149+ if (s) {
96150+ int size = kmalloc_size(i);
96151+ char *n = kasprintf(GFP_NOWAIT,
96152+ "usercopy-kmalloc-%d", size);
96153+
96154+ BUG_ON(!n);
96155+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96156+ size, SLAB_USERCOPY | flags);
96157+ }
96158+ }
96159+#endif
96160+
96161 }
96162 #endif /* !CONFIG_SLOB */
96163
96164@@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
96165 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96166 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96167 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96168+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96169+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
96170+#endif
96171 #endif
96172 seq_putc(m, '\n');
96173 }
96174diff --git a/mm/slob.c b/mm/slob.c
96175index 4bf8809..98a6914 100644
96176--- a/mm/slob.c
96177+++ b/mm/slob.c
96178@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96179 /*
96180 * Return the size of a slob block.
96181 */
96182-static slobidx_t slob_units(slob_t *s)
96183+static slobidx_t slob_units(const slob_t *s)
96184 {
96185 if (s->units > 0)
96186 return s->units;
96187@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96188 /*
96189 * Return the next free slob block pointer after this one.
96190 */
96191-static slob_t *slob_next(slob_t *s)
96192+static slob_t *slob_next(const slob_t *s)
96193 {
96194 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96195 slobidx_t next;
96196@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96197 /*
96198 * Returns true if s is the last free block in its page.
96199 */
96200-static int slob_last(slob_t *s)
96201+static int slob_last(const slob_t *s)
96202 {
96203 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96204 }
96205
96206-static void *slob_new_pages(gfp_t gfp, int order, int node)
96207+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96208 {
96209- void *page;
96210+ struct page *page;
96211
96212 #ifdef CONFIG_NUMA
96213 if (node != NUMA_NO_NODE)
96214@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96215 if (!page)
96216 return NULL;
96217
96218- return page_address(page);
96219+ __SetPageSlab(page);
96220+ return page;
96221 }
96222
96223-static void slob_free_pages(void *b, int order)
96224+static void slob_free_pages(struct page *sp, int order)
96225 {
96226 if (current->reclaim_state)
96227 current->reclaim_state->reclaimed_slab += 1 << order;
96228- free_pages((unsigned long)b, order);
96229+ __ClearPageSlab(sp);
96230+ page_mapcount_reset(sp);
96231+ sp->private = 0;
96232+ __free_pages(sp, order);
96233 }
96234
96235 /*
96236@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96237
96238 /* Not enough space: must allocate a new page */
96239 if (!b) {
96240- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96241- if (!b)
96242+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96243+ if (!sp)
96244 return NULL;
96245- sp = virt_to_page(b);
96246- __SetPageSlab(sp);
96247+ b = page_address(sp);
96248
96249 spin_lock_irqsave(&slob_lock, flags);
96250 sp->units = SLOB_UNITS(PAGE_SIZE);
96251 sp->freelist = b;
96252+ sp->private = 0;
96253 INIT_LIST_HEAD(&sp->list);
96254 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96255 set_slob_page_free(sp, slob_list);
96256@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96257 if (slob_page_free(sp))
96258 clear_slob_page_free(sp);
96259 spin_unlock_irqrestore(&slob_lock, flags);
96260- __ClearPageSlab(sp);
96261- page_mapcount_reset(sp);
96262- slob_free_pages(b, 0);
96263+ slob_free_pages(sp, 0);
96264 return;
96265 }
96266
96267+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96268+ if (pax_sanitize_slab)
96269+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96270+#endif
96271+
96272 if (!slob_page_free(sp)) {
96273 /* This slob page is about to become partially free. Easy! */
96274 sp->units = units;
96275@@ -424,11 +431,10 @@ out:
96276 */
96277
96278 static __always_inline void *
96279-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96280+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96281 {
96282- unsigned int *m;
96283- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96284- void *ret;
96285+ slob_t *m;
96286+ void *ret = NULL;
96287
96288 gfp &= gfp_allowed_mask;
96289
96290@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96291
96292 if (!m)
96293 return NULL;
96294- *m = size;
96295+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96296+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96297+ m[0].units = size;
96298+ m[1].units = align;
96299 ret = (void *)m + align;
96300
96301 trace_kmalloc_node(caller, ret,
96302 size, size + align, gfp, node);
96303 } else {
96304 unsigned int order = get_order(size);
96305+ struct page *page;
96306
96307 if (likely(order))
96308 gfp |= __GFP_COMP;
96309- ret = slob_new_pages(gfp, order, node);
96310+ page = slob_new_pages(gfp, order, node);
96311+ if (page) {
96312+ ret = page_address(page);
96313+ page->private = size;
96314+ }
96315
96316 trace_kmalloc_node(caller, ret,
96317 size, PAGE_SIZE << order, gfp, node);
96318 }
96319
96320- kmemleak_alloc(ret, size, 1, gfp);
96321+ return ret;
96322+}
96323+
96324+static __always_inline void *
96325+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96326+{
96327+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96328+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96329+
96330+ if (!ZERO_OR_NULL_PTR(ret))
96331+ kmemleak_alloc(ret, size, 1, gfp);
96332 return ret;
96333 }
96334
96335@@ -493,34 +517,112 @@ void kfree(const void *block)
96336 return;
96337 kmemleak_free(block);
96338
96339+ VM_BUG_ON(!virt_addr_valid(block));
96340 sp = virt_to_page(block);
96341- if (PageSlab(sp)) {
96342+ VM_BUG_ON(!PageSlab(sp));
96343+ if (!sp->private) {
96344 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96345- unsigned int *m = (unsigned int *)(block - align);
96346- slob_free(m, *m + align);
96347- } else
96348+ slob_t *m = (slob_t *)(block - align);
96349+ slob_free(m, m[0].units + align);
96350+ } else {
96351+ __ClearPageSlab(sp);
96352+ page_mapcount_reset(sp);
96353+ sp->private = 0;
96354 __free_pages(sp, compound_order(sp));
96355+ }
96356 }
96357 EXPORT_SYMBOL(kfree);
96358
96359+bool is_usercopy_object(const void *ptr)
96360+{
96361+ if (!slab_is_available())
96362+ return false;
96363+
96364+ // PAX: TODO
96365+
96366+ return false;
96367+}
96368+
96369+#ifdef CONFIG_PAX_USERCOPY
96370+const char *check_heap_object(const void *ptr, unsigned long n)
96371+{
96372+ struct page *page;
96373+ const slob_t *free;
96374+ const void *base;
96375+ unsigned long flags;
96376+
96377+ if (ZERO_OR_NULL_PTR(ptr))
96378+ return "<null>";
96379+
96380+ if (!virt_addr_valid(ptr))
96381+ return NULL;
96382+
96383+ page = virt_to_head_page(ptr);
96384+ if (!PageSlab(page))
96385+ return NULL;
96386+
96387+ if (page->private) {
96388+ base = page;
96389+ if (base <= ptr && n <= page->private - (ptr - base))
96390+ return NULL;
96391+ return "<slob>";
96392+ }
96393+
96394+ /* some tricky double walking to find the chunk */
96395+ spin_lock_irqsave(&slob_lock, flags);
96396+ base = (void *)((unsigned long)ptr & PAGE_MASK);
96397+ free = page->freelist;
96398+
96399+ while (!slob_last(free) && (void *)free <= ptr) {
96400+ base = free + slob_units(free);
96401+ free = slob_next(free);
96402+ }
96403+
96404+ while (base < (void *)free) {
96405+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96406+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
96407+ int offset;
96408+
96409+ if (ptr < base + align)
96410+ break;
96411+
96412+ offset = ptr - base - align;
96413+ if (offset >= m) {
96414+ base += size;
96415+ continue;
96416+ }
96417+
96418+ if (n > m - offset)
96419+ break;
96420+
96421+ spin_unlock_irqrestore(&slob_lock, flags);
96422+ return NULL;
96423+ }
96424+
96425+ spin_unlock_irqrestore(&slob_lock, flags);
96426+ return "<slob>";
96427+}
96428+#endif
96429+
96430 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96431 size_t ksize(const void *block)
96432 {
96433 struct page *sp;
96434 int align;
96435- unsigned int *m;
96436+ slob_t *m;
96437
96438 BUG_ON(!block);
96439 if (unlikely(block == ZERO_SIZE_PTR))
96440 return 0;
96441
96442 sp = virt_to_page(block);
96443- if (unlikely(!PageSlab(sp)))
96444- return PAGE_SIZE << compound_order(sp);
96445+ VM_BUG_ON(!PageSlab(sp));
96446+ if (sp->private)
96447+ return sp->private;
96448
96449 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96450- m = (unsigned int *)(block - align);
96451- return SLOB_UNITS(*m) * SLOB_UNIT;
96452+ m = (slob_t *)(block - align);
96453+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96454 }
96455 EXPORT_SYMBOL(ksize);
96456
96457@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96458
96459 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96460 {
96461- void *b;
96462+ void *b = NULL;
96463
96464 flags &= gfp_allowed_mask;
96465
96466 lockdep_trace_alloc(flags);
96467
96468+#ifdef CONFIG_PAX_USERCOPY_SLABS
96469+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96470+#else
96471 if (c->size < PAGE_SIZE) {
96472 b = slob_alloc(c->size, flags, c->align, node);
96473 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96474 SLOB_UNITS(c->size) * SLOB_UNIT,
96475 flags, node);
96476 } else {
96477- b = slob_new_pages(flags, get_order(c->size), node);
96478+ struct page *sp;
96479+
96480+ sp = slob_new_pages(flags, get_order(c->size), node);
96481+ if (sp) {
96482+ b = page_address(sp);
96483+ sp->private = c->size;
96484+ }
96485 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96486 PAGE_SIZE << get_order(c->size),
96487 flags, node);
96488 }
96489+#endif
96490
96491 if (b && c->ctor)
96492 c->ctor(b);
96493@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96494
96495 static void __kmem_cache_free(void *b, int size)
96496 {
96497- if (size < PAGE_SIZE)
96498+ struct page *sp;
96499+
96500+ sp = virt_to_page(b);
96501+ BUG_ON(!PageSlab(sp));
96502+ if (!sp->private)
96503 slob_free(b, size);
96504 else
96505- slob_free_pages(b, get_order(size));
96506+ slob_free_pages(sp, get_order(size));
96507 }
96508
96509 static void kmem_rcu_free(struct rcu_head *head)
96510@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96511
96512 void kmem_cache_free(struct kmem_cache *c, void *b)
96513 {
96514+ int size = c->size;
96515+
96516+#ifdef CONFIG_PAX_USERCOPY_SLABS
96517+ if (size + c->align < PAGE_SIZE) {
96518+ size += c->align;
96519+ b -= c->align;
96520+ }
96521+#endif
96522+
96523 kmemleak_free_recursive(b, c->flags);
96524 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96525 struct slob_rcu *slob_rcu;
96526- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96527- slob_rcu->size = c->size;
96528+ slob_rcu = b + (size - sizeof(struct slob_rcu));
96529+ slob_rcu->size = size;
96530 call_rcu(&slob_rcu->head, kmem_rcu_free);
96531 } else {
96532- __kmem_cache_free(b, c->size);
96533+ __kmem_cache_free(b, size);
96534 }
96535
96536+#ifdef CONFIG_PAX_USERCOPY_SLABS
96537+ trace_kfree(_RET_IP_, b);
96538+#else
96539 trace_kmem_cache_free(_RET_IP_, b);
96540+#endif
96541+
96542 }
96543 EXPORT_SYMBOL(kmem_cache_free);
96544
96545diff --git a/mm/slub.c b/mm/slub.c
96546index 25f14ad..c904f6f 100644
96547--- a/mm/slub.c
96548+++ b/mm/slub.c
96549@@ -207,7 +207,7 @@ struct track {
96550
96551 enum track_item { TRACK_ALLOC, TRACK_FREE };
96552
96553-#ifdef CONFIG_SYSFS
96554+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96555 static int sysfs_slab_add(struct kmem_cache *);
96556 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96557 static void sysfs_slab_remove(struct kmem_cache *);
96558@@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
96559 if (!t->addr)
96560 return;
96561
96562- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96563+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96564 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96565 #ifdef CONFIG_STACKTRACE
96566 {
96567@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96568
96569 slab_free_hook(s, x);
96570
96571+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96572+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96573+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96574+ if (s->ctor)
96575+ s->ctor(x);
96576+ }
96577+#endif
96578+
96579 redo:
96580 /*
96581 * Determine the currently cpus per cpu slab.
96582@@ -2733,7 +2741,7 @@ static int slub_min_objects;
96583 * Merge control. If this is set then no merging of slab caches will occur.
96584 * (Could be removed. This was introduced to pacify the merge skeptics.)
96585 */
96586-static int slub_nomerge;
96587+static int slub_nomerge = 1;
96588
96589 /*
96590 * Calculate the order of allocation given an slab object size.
96591@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96592 s->inuse = size;
96593
96594 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96595+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96596+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96597+#endif
96598 s->ctor)) {
96599 /*
96600 * Relocate free pointer after the object if it is not
96601@@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96602 EXPORT_SYMBOL(__kmalloc_node);
96603 #endif
96604
96605+bool is_usercopy_object(const void *ptr)
96606+{
96607+ struct page *page;
96608+ struct kmem_cache *s;
96609+
96610+ if (ZERO_OR_NULL_PTR(ptr))
96611+ return false;
96612+
96613+ if (!slab_is_available())
96614+ return false;
96615+
96616+ if (!virt_addr_valid(ptr))
96617+ return false;
96618+
96619+ page = virt_to_head_page(ptr);
96620+
96621+ if (!PageSlab(page))
96622+ return false;
96623+
96624+ s = page->slab_cache;
96625+ return s->flags & SLAB_USERCOPY;
96626+}
96627+
96628+#ifdef CONFIG_PAX_USERCOPY
96629+const char *check_heap_object(const void *ptr, unsigned long n)
96630+{
96631+ struct page *page;
96632+ struct kmem_cache *s;
96633+ unsigned long offset;
96634+
96635+ if (ZERO_OR_NULL_PTR(ptr))
96636+ return "<null>";
96637+
96638+ if (!virt_addr_valid(ptr))
96639+ return NULL;
96640+
96641+ page = virt_to_head_page(ptr);
96642+
96643+ if (!PageSlab(page))
96644+ return NULL;
96645+
96646+ s = page->slab_cache;
96647+ if (!(s->flags & SLAB_USERCOPY))
96648+ return s->name;
96649+
96650+ offset = (ptr - page_address(page)) % s->size;
96651+ if (offset <= s->object_size && n <= s->object_size - offset)
96652+ return NULL;
96653+
96654+ return s->name;
96655+}
96656+#endif
96657+
96658 size_t ksize(const void *object)
96659 {
96660 struct page *page;
96661@@ -3387,6 +3451,7 @@ void kfree(const void *x)
96662 if (unlikely(ZERO_OR_NULL_PTR(x)))
96663 return;
96664
96665+ VM_BUG_ON(!virt_addr_valid(x));
96666 page = virt_to_head_page(x);
96667 if (unlikely(!PageSlab(page))) {
96668 BUG_ON(!PageCompound(page));
96669@@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96670 /*
96671 * We may have set a slab to be unmergeable during bootstrap.
96672 */
96673- if (s->refcount < 0)
96674+ if (atomic_read(&s->refcount) < 0)
96675 return 1;
96676
96677 return 0;
96678@@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96679
96680 s = find_mergeable(memcg, size, align, flags, name, ctor);
96681 if (s) {
96682- s->refcount++;
96683+ atomic_inc(&s->refcount);
96684 /*
96685 * Adjust the object sizes so that we clear
96686 * the complete object on kzalloc.
96687@@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96688 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
96689
96690 if (sysfs_slab_alias(s, name)) {
96691- s->refcount--;
96692+ atomic_dec(&s->refcount);
96693 s = NULL;
96694 }
96695 }
96696@@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96697 }
96698 #endif
96699
96700-#ifdef CONFIG_SYSFS
96701+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96702 static int count_inuse(struct page *page)
96703 {
96704 return page->inuse;
96705@@ -4163,7 +4228,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
96706 len += sprintf(buf + len, "%7ld ", l->count);
96707
96708 if (l->addr)
96709+#ifdef CONFIG_GRKERNSEC_HIDESYM
96710+ len += sprintf(buf + len, "%pS", NULL);
96711+#else
96712 len += sprintf(buf + len, "%pS", (void *)l->addr);
96713+#endif
96714 else
96715 len += sprintf(buf + len, "<not-available>");
96716
96717@@ -4268,12 +4337,12 @@ static void resiliency_test(void)
96718 validate_slab_cache(kmalloc_caches[9]);
96719 }
96720 #else
96721-#ifdef CONFIG_SYSFS
96722+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96723 static void resiliency_test(void) {};
96724 #endif
96725 #endif
96726
96727-#ifdef CONFIG_SYSFS
96728+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96729 enum slab_stat_type {
96730 SL_ALL, /* All slabs */
96731 SL_PARTIAL, /* Only partially allocated slabs */
96732@@ -4513,13 +4582,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
96733 {
96734 if (!s->ctor)
96735 return 0;
96736+#ifdef CONFIG_GRKERNSEC_HIDESYM
96737+ return sprintf(buf, "%pS\n", NULL);
96738+#else
96739 return sprintf(buf, "%pS\n", s->ctor);
96740+#endif
96741 }
96742 SLAB_ATTR_RO(ctor);
96743
96744 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96745 {
96746- return sprintf(buf, "%d\n", s->refcount - 1);
96747+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96748 }
96749 SLAB_ATTR_RO(aliases);
96750
96751@@ -4607,6 +4680,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96752 SLAB_ATTR_RO(cache_dma);
96753 #endif
96754
96755+#ifdef CONFIG_PAX_USERCOPY_SLABS
96756+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96757+{
96758+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96759+}
96760+SLAB_ATTR_RO(usercopy);
96761+#endif
96762+
96763 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96764 {
96765 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96766@@ -4941,6 +5022,9 @@ static struct attribute *slab_attrs[] = {
96767 #ifdef CONFIG_ZONE_DMA
96768 &cache_dma_attr.attr,
96769 #endif
96770+#ifdef CONFIG_PAX_USERCOPY_SLABS
96771+ &usercopy_attr.attr,
96772+#endif
96773 #ifdef CONFIG_NUMA
96774 &remote_node_defrag_ratio_attr.attr,
96775 #endif
96776@@ -5173,6 +5257,7 @@ static char *create_unique_id(struct kmem_cache *s)
96777 return name;
96778 }
96779
96780+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96781 static int sysfs_slab_add(struct kmem_cache *s)
96782 {
96783 int err;
96784@@ -5230,6 +5315,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
96785 kobject_del(&s->kobj);
96786 kobject_put(&s->kobj);
96787 }
96788+#endif
96789
96790 /*
96791 * Need to buffer aliases during bootup until sysfs becomes
96792@@ -5243,6 +5329,7 @@ struct saved_alias {
96793
96794 static struct saved_alias *alias_list;
96795
96796+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96797 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96798 {
96799 struct saved_alias *al;
96800@@ -5265,6 +5352,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96801 alias_list = al;
96802 return 0;
96803 }
96804+#endif
96805
96806 static int __init slab_sysfs_init(void)
96807 {
96808diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96809index 4cba9c2..b4f9fcc 100644
96810--- a/mm/sparse-vmemmap.c
96811+++ b/mm/sparse-vmemmap.c
96812@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96813 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96814 if (!p)
96815 return NULL;
96816- pud_populate(&init_mm, pud, p);
96817+ pud_populate_kernel(&init_mm, pud, p);
96818 }
96819 return pud;
96820 }
96821@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96822 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96823 if (!p)
96824 return NULL;
96825- pgd_populate(&init_mm, pgd, p);
96826+ pgd_populate_kernel(&init_mm, pgd, p);
96827 }
96828 return pgd;
96829 }
96830diff --git a/mm/sparse.c b/mm/sparse.c
96831index 63c3ea5..95c0858 100644
96832--- a/mm/sparse.c
96833+++ b/mm/sparse.c
96834@@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96835
96836 for (i = 0; i < PAGES_PER_SECTION; i++) {
96837 if (PageHWPoison(&memmap[i])) {
96838- atomic_long_sub(1, &num_poisoned_pages);
96839+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
96840 ClearPageHWPoison(&memmap[i]);
96841 }
96842 }
96843diff --git a/mm/swap.c b/mm/swap.c
96844index 0092097..33361ff 100644
96845--- a/mm/swap.c
96846+++ b/mm/swap.c
96847@@ -31,6 +31,7 @@
96848 #include <linux/memcontrol.h>
96849 #include <linux/gfp.h>
96850 #include <linux/uio.h>
96851+#include <linux/hugetlb.h>
96852
96853 #include "internal.h"
96854
96855@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96856
96857 __page_cache_release(page);
96858 dtor = get_compound_page_dtor(page);
96859+ if (!PageHuge(page))
96860+ BUG_ON(dtor != free_compound_page);
96861 (*dtor)(page);
96862 }
96863
96864diff --git a/mm/swapfile.c b/mm/swapfile.c
96865index 4a7f7e6..22cddf5 100644
96866--- a/mm/swapfile.c
96867+++ b/mm/swapfile.c
96868@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96869
96870 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96871 /* Activity counter to indicate that a swapon or swapoff has occurred */
96872-static atomic_t proc_poll_event = ATOMIC_INIT(0);
96873+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96874
96875 static inline unsigned char swap_count(unsigned char ent)
96876 {
96877@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96878 spin_unlock(&swap_lock);
96879
96880 err = 0;
96881- atomic_inc(&proc_poll_event);
96882+ atomic_inc_unchecked(&proc_poll_event);
96883 wake_up_interruptible(&proc_poll_wait);
96884
96885 out_dput:
96886@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96887
96888 poll_wait(file, &proc_poll_wait, wait);
96889
96890- if (seq->poll_event != atomic_read(&proc_poll_event)) {
96891- seq->poll_event = atomic_read(&proc_poll_event);
96892+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96893+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96894 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96895 }
96896
96897@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96898 return ret;
96899
96900 seq = file->private_data;
96901- seq->poll_event = atomic_read(&proc_poll_event);
96902+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96903 return 0;
96904 }
96905
96906@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96907 (frontswap_map) ? "FS" : "");
96908
96909 mutex_unlock(&swapon_mutex);
96910- atomic_inc(&proc_poll_event);
96911+ atomic_inc_unchecked(&proc_poll_event);
96912 wake_up_interruptible(&proc_poll_wait);
96913
96914 if (S_ISREG(inode->i_mode))
96915diff --git a/mm/util.c b/mm/util.c
96916index a24aa22..a0d41ae 100644
96917--- a/mm/util.c
96918+++ b/mm/util.c
96919@@ -297,6 +297,12 @@ done:
96920 void arch_pick_mmap_layout(struct mm_struct *mm)
96921 {
96922 mm->mmap_base = TASK_UNMAPPED_BASE;
96923+
96924+#ifdef CONFIG_PAX_RANDMMAP
96925+ if (mm->pax_flags & MF_PAX_RANDMMAP)
96926+ mm->mmap_base += mm->delta_mmap;
96927+#endif
96928+
96929 mm->get_unmapped_area = arch_get_unmapped_area;
96930 }
96931 #endif
96932diff --git a/mm/vmalloc.c b/mm/vmalloc.c
96933index 0fdf968..2183ba3 100644
96934--- a/mm/vmalloc.c
96935+++ b/mm/vmalloc.c
96936@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96937
96938 pte = pte_offset_kernel(pmd, addr);
96939 do {
96940- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96941- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96942+
96943+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96944+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
96945+ BUG_ON(!pte_exec(*pte));
96946+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
96947+ continue;
96948+ }
96949+#endif
96950+
96951+ {
96952+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96953+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96954+ }
96955 } while (pte++, addr += PAGE_SIZE, addr != end);
96956 }
96957
96958@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
96959 pte = pte_alloc_kernel(pmd, addr);
96960 if (!pte)
96961 return -ENOMEM;
96962+
96963+ pax_open_kernel();
96964 do {
96965 struct page *page = pages[*nr];
96966
96967- if (WARN_ON(!pte_none(*pte)))
96968+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96969+ if (pgprot_val(prot) & _PAGE_NX)
96970+#endif
96971+
96972+ if (!pte_none(*pte)) {
96973+ pax_close_kernel();
96974+ WARN_ON(1);
96975 return -EBUSY;
96976- if (WARN_ON(!page))
96977+ }
96978+ if (!page) {
96979+ pax_close_kernel();
96980+ WARN_ON(1);
96981 return -ENOMEM;
96982+ }
96983 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
96984 (*nr)++;
96985 } while (pte++, addr += PAGE_SIZE, addr != end);
96986+ pax_close_kernel();
96987 return 0;
96988 }
96989
96990@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
96991 pmd_t *pmd;
96992 unsigned long next;
96993
96994- pmd = pmd_alloc(&init_mm, pud, addr);
96995+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96996 if (!pmd)
96997 return -ENOMEM;
96998 do {
96999@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
97000 pud_t *pud;
97001 unsigned long next;
97002
97003- pud = pud_alloc(&init_mm, pgd, addr);
97004+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
97005 if (!pud)
97006 return -ENOMEM;
97007 do {
97008@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
97009 if (addr >= MODULES_VADDR && addr < MODULES_END)
97010 return 1;
97011 #endif
97012+
97013+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97014+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
97015+ return 1;
97016+#endif
97017+
97018 return is_vmalloc_addr(x);
97019 }
97020
97021@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
97022
97023 if (!pgd_none(*pgd)) {
97024 pud_t *pud = pud_offset(pgd, addr);
97025+#ifdef CONFIG_X86
97026+ if (!pud_large(*pud))
97027+#endif
97028 if (!pud_none(*pud)) {
97029 pmd_t *pmd = pmd_offset(pud, addr);
97030+#ifdef CONFIG_X86
97031+ if (!pmd_large(*pmd))
97032+#endif
97033 if (!pmd_none(*pmd)) {
97034 pte_t *ptep, pte;
97035
97036@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
97037 struct vm_struct *area;
97038
97039 BUG_ON(in_interrupt());
97040+
97041+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97042+ if (flags & VM_KERNEXEC) {
97043+ if (start != VMALLOC_START || end != VMALLOC_END)
97044+ return NULL;
97045+ start = (unsigned long)MODULES_EXEC_VADDR;
97046+ end = (unsigned long)MODULES_EXEC_END;
97047+ }
97048+#endif
97049+
97050 if (flags & VM_IOREMAP)
97051 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
97052
97053@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
97054 if (count > totalram_pages)
97055 return NULL;
97056
97057+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97058+ if (!(pgprot_val(prot) & _PAGE_NX))
97059+ flags |= VM_KERNEXEC;
97060+#endif
97061+
97062 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
97063 __builtin_return_address(0));
97064 if (!area)
97065@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
97066 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
97067 goto fail;
97068
97069+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97070+ if (!(pgprot_val(prot) & _PAGE_NX))
97071+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
97072+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
97073+ else
97074+#endif
97075+
97076 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
97077 start, end, node, gfp_mask, caller);
97078 if (!area)
97079@@ -1701,6 +1759,12 @@ static inline void *__vmalloc_node_flags(unsigned long size,
97080 node, __builtin_return_address(0));
97081 }
97082
97083+void *vmalloc_stack(int node)
97084+{
97085+ return __vmalloc_node(THREAD_SIZE, THREAD_SIZE, THREADINFO_GFP, PAGE_KERNEL,
97086+ node, __builtin_return_address(0));
97087+}
97088+
97089 /**
97090 * vmalloc - allocate virtually contiguous memory
97091 * @size: allocation size
97092@@ -1810,10 +1874,9 @@ EXPORT_SYMBOL(vzalloc_node);
97093 * For tight control over page level allocator and protection flags
97094 * use __vmalloc() instead.
97095 */
97096-
97097 void *vmalloc_exec(unsigned long size)
97098 {
97099- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
97100+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
97101 NUMA_NO_NODE, __builtin_return_address(0));
97102 }
97103
97104@@ -2120,6 +2183,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
97105 {
97106 struct vm_struct *area;
97107
97108+ BUG_ON(vma->vm_mirror);
97109+
97110 size = PAGE_ALIGN(size);
97111
97112 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
97113@@ -2602,7 +2667,11 @@ static int s_show(struct seq_file *m, void *p)
97114 v->addr, v->addr + v->size, v->size);
97115
97116 if (v->caller)
97117+#ifdef CONFIG_GRKERNSEC_HIDESYM
97118+ seq_printf(m, " %pK", v->caller);
97119+#else
97120 seq_printf(m, " %pS", v->caller);
97121+#endif
97122
97123 if (v->nr_pages)
97124 seq_printf(m, " pages=%d", v->nr_pages);
97125diff --git a/mm/vmstat.c b/mm/vmstat.c
97126index def5dd2..4ce55cec 100644
97127--- a/mm/vmstat.c
97128+++ b/mm/vmstat.c
97129@@ -20,6 +20,7 @@
97130 #include <linux/writeback.h>
97131 #include <linux/compaction.h>
97132 #include <linux/mm_inline.h>
97133+#include <linux/grsecurity.h>
97134
97135 #include "internal.h"
97136
97137@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
97138 *
97139 * vm_stat contains the global counters
97140 */
97141-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97142+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97143 EXPORT_SYMBOL(vm_stat);
97144
97145 #ifdef CONFIG_SMP
97146@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
97147
97148 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97149 if (diff[i])
97150- atomic_long_add(diff[i], &vm_stat[i]);
97151+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
97152 }
97153
97154 /*
97155@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
97156 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97157 if (v) {
97158
97159- atomic_long_add(v, &zone->vm_stat[i]);
97160+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97161 global_diff[i] += v;
97162 #ifdef CONFIG_NUMA
97163 /* 3 seconds idle till flush */
97164@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97165
97166 v = p->vm_stat_diff[i];
97167 p->vm_stat_diff[i] = 0;
97168- atomic_long_add(v, &zone->vm_stat[i]);
97169+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97170 global_diff[i] += v;
97171 }
97172 }
97173@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97174 if (pset->vm_stat_diff[i]) {
97175 int v = pset->vm_stat_diff[i];
97176 pset->vm_stat_diff[i] = 0;
97177- atomic_long_add(v, &zone->vm_stat[i]);
97178- atomic_long_add(v, &vm_stat[i]);
97179+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97180+ atomic_long_add_unchecked(v, &vm_stat[i]);
97181 }
97182 }
97183 #endif
97184@@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97185 stat_items_size += sizeof(struct vm_event_state);
97186 #endif
97187
97188- v = kmalloc(stat_items_size, GFP_KERNEL);
97189+ v = kzalloc(stat_items_size, GFP_KERNEL);
97190 m->private = v;
97191 if (!v)
97192 return ERR_PTR(-ENOMEM);
97193+
97194+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97195+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97196+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97197+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97198+ && !in_group_p(grsec_proc_gid)
97199+#endif
97200+ )
97201+ return (unsigned long *)m->private + *pos;
97202+#endif
97203+#endif
97204+
97205 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97206 v[i] = global_page_state(i);
97207 v += NR_VM_ZONE_STAT_ITEMS;
97208@@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
97209 put_online_cpus();
97210 #endif
97211 #ifdef CONFIG_PROC_FS
97212- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97213- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97214- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97215- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97216+ {
97217+ mode_t gr_mode = S_IRUGO;
97218+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97219+ gr_mode = S_IRUSR;
97220+#endif
97221+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97222+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97223+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97224+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97225+ }
97226 #endif
97227 return 0;
97228 }
97229diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97230index 175273f..1c63e05 100644
97231--- a/net/8021q/vlan.c
97232+++ b/net/8021q/vlan.c
97233@@ -474,7 +474,7 @@ out:
97234 return NOTIFY_DONE;
97235 }
97236
97237-static struct notifier_block vlan_notifier_block __read_mostly = {
97238+static struct notifier_block vlan_notifier_block = {
97239 .notifier_call = vlan_device_event,
97240 };
97241
97242@@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97243 err = -EPERM;
97244 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97245 break;
97246- if ((args.u.name_type >= 0) &&
97247- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97248+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97249 struct vlan_net *vn;
97250
97251 vn = net_generic(net, vlan_net_id);
97252diff --git a/net/9p/client.c b/net/9p/client.c
97253index 9186550..e604a2f 100644
97254--- a/net/9p/client.c
97255+++ b/net/9p/client.c
97256@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97257 len - inline_len);
97258 } else {
97259 err = copy_from_user(ename + inline_len,
97260- uidata, len - inline_len);
97261+ (char __force_user *)uidata, len - inline_len);
97262 if (err) {
97263 err = -EFAULT;
97264 goto out_err;
97265@@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97266 kernel_buf = 1;
97267 indata = data;
97268 } else
97269- indata = (__force char *)udata;
97270+ indata = (__force_kernel char *)udata;
97271 /*
97272 * response header len is 11
97273 * PDU Header(7) + IO Size (4)
97274@@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97275 kernel_buf = 1;
97276 odata = data;
97277 } else
97278- odata = (char *)udata;
97279+ odata = (char __force_kernel *)udata;
97280 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97281 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97282 fid->fid, offset, rsize);
97283diff --git a/net/9p/mod.c b/net/9p/mod.c
97284index 6ab36ae..6f1841b 100644
97285--- a/net/9p/mod.c
97286+++ b/net/9p/mod.c
97287@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97288 void v9fs_register_trans(struct p9_trans_module *m)
97289 {
97290 spin_lock(&v9fs_trans_lock);
97291- list_add_tail(&m->list, &v9fs_trans_list);
97292+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97293 spin_unlock(&v9fs_trans_lock);
97294 }
97295 EXPORT_SYMBOL(v9fs_register_trans);
97296@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97297 void v9fs_unregister_trans(struct p9_trans_module *m)
97298 {
97299 spin_lock(&v9fs_trans_lock);
97300- list_del_init(&m->list);
97301+ pax_list_del_init((struct list_head *)&m->list);
97302 spin_unlock(&v9fs_trans_lock);
97303 }
97304 EXPORT_SYMBOL(v9fs_unregister_trans);
97305diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97306index b7bd7f2..2498bf7 100644
97307--- a/net/9p/trans_fd.c
97308+++ b/net/9p/trans_fd.c
97309@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97310 oldfs = get_fs();
97311 set_fs(get_ds());
97312 /* The cast to a user pointer is valid due to the set_fs() */
97313- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97314+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97315 set_fs(oldfs);
97316
97317 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97318diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97319index af46bc4..f9adfcd 100644
97320--- a/net/appletalk/atalk_proc.c
97321+++ b/net/appletalk/atalk_proc.c
97322@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97323 struct proc_dir_entry *p;
97324 int rc = -ENOMEM;
97325
97326- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97327+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97328 if (!atalk_proc_dir)
97329 goto out;
97330
97331diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97332index 876fbe8..8bbea9f 100644
97333--- a/net/atm/atm_misc.c
97334+++ b/net/atm/atm_misc.c
97335@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97336 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97337 return 1;
97338 atm_return(vcc, truesize);
97339- atomic_inc(&vcc->stats->rx_drop);
97340+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97341 return 0;
97342 }
97343 EXPORT_SYMBOL(atm_charge);
97344@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97345 }
97346 }
97347 atm_return(vcc, guess);
97348- atomic_inc(&vcc->stats->rx_drop);
97349+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97350 return NULL;
97351 }
97352 EXPORT_SYMBOL(atm_alloc_charge);
97353@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97354
97355 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97356 {
97357-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97358+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97359 __SONET_ITEMS
97360 #undef __HANDLE_ITEM
97361 }
97362@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97363
97364 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97365 {
97366-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97367+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97368 __SONET_ITEMS
97369 #undef __HANDLE_ITEM
97370 }
97371diff --git a/net/atm/lec.c b/net/atm/lec.c
97372index 5a2f602..9396143 100644
97373--- a/net/atm/lec.c
97374+++ b/net/atm/lec.c
97375@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97376 }
97377
97378 static struct lane2_ops lane2_ops = {
97379- lane2_resolve, /* resolve, spec 3.1.3 */
97380- lane2_associate_req, /* associate_req, spec 3.1.4 */
97381- NULL /* associate indicator, spec 3.1.5 */
97382+ .resolve = lane2_resolve,
97383+ .associate_req = lane2_associate_req,
97384+ .associate_indicator = NULL
97385 };
97386
97387 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97388diff --git a/net/atm/lec.h b/net/atm/lec.h
97389index 4149db1..f2ab682 100644
97390--- a/net/atm/lec.h
97391+++ b/net/atm/lec.h
97392@@ -48,7 +48,7 @@ struct lane2_ops {
97393 const u8 *tlvs, u32 sizeoftlvs);
97394 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97395 const u8 *tlvs, u32 sizeoftlvs);
97396-};
97397+} __no_const;
97398
97399 /*
97400 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97401diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97402index d1b2d9a..d549f7f 100644
97403--- a/net/atm/mpoa_caches.c
97404+++ b/net/atm/mpoa_caches.c
97405@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97406
97407
97408 static struct in_cache_ops ingress_ops = {
97409- in_cache_add_entry, /* add_entry */
97410- in_cache_get, /* get */
97411- in_cache_get_with_mask, /* get_with_mask */
97412- in_cache_get_by_vcc, /* get_by_vcc */
97413- in_cache_put, /* put */
97414- in_cache_remove_entry, /* remove_entry */
97415- cache_hit, /* cache_hit */
97416- clear_count_and_expired, /* clear_count */
97417- check_resolving_entries, /* check_resolving */
97418- refresh_entries, /* refresh */
97419- in_destroy_cache /* destroy_cache */
97420+ .add_entry = in_cache_add_entry,
97421+ .get = in_cache_get,
97422+ .get_with_mask = in_cache_get_with_mask,
97423+ .get_by_vcc = in_cache_get_by_vcc,
97424+ .put = in_cache_put,
97425+ .remove_entry = in_cache_remove_entry,
97426+ .cache_hit = cache_hit,
97427+ .clear_count = clear_count_and_expired,
97428+ .check_resolving = check_resolving_entries,
97429+ .refresh = refresh_entries,
97430+ .destroy_cache = in_destroy_cache
97431 };
97432
97433 static struct eg_cache_ops egress_ops = {
97434- eg_cache_add_entry, /* add_entry */
97435- eg_cache_get_by_cache_id, /* get_by_cache_id */
97436- eg_cache_get_by_tag, /* get_by_tag */
97437- eg_cache_get_by_vcc, /* get_by_vcc */
97438- eg_cache_get_by_src_ip, /* get_by_src_ip */
97439- eg_cache_put, /* put */
97440- eg_cache_remove_entry, /* remove_entry */
97441- update_eg_cache_entry, /* update */
97442- clear_expired, /* clear_expired */
97443- eg_destroy_cache /* destroy_cache */
97444+ .add_entry = eg_cache_add_entry,
97445+ .get_by_cache_id = eg_cache_get_by_cache_id,
97446+ .get_by_tag = eg_cache_get_by_tag,
97447+ .get_by_vcc = eg_cache_get_by_vcc,
97448+ .get_by_src_ip = eg_cache_get_by_src_ip,
97449+ .put = eg_cache_put,
97450+ .remove_entry = eg_cache_remove_entry,
97451+ .update = update_eg_cache_entry,
97452+ .clear_expired = clear_expired,
97453+ .destroy_cache = eg_destroy_cache
97454 };
97455
97456
97457diff --git a/net/atm/proc.c b/net/atm/proc.c
97458index bbb6461..cf04016 100644
97459--- a/net/atm/proc.c
97460+++ b/net/atm/proc.c
97461@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97462 const struct k_atm_aal_stats *stats)
97463 {
97464 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97465- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97466- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97467- atomic_read(&stats->rx_drop));
97468+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97469+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97470+ atomic_read_unchecked(&stats->rx_drop));
97471 }
97472
97473 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97474diff --git a/net/atm/resources.c b/net/atm/resources.c
97475index 0447d5d..3cf4728 100644
97476--- a/net/atm/resources.c
97477+++ b/net/atm/resources.c
97478@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97479 static void copy_aal_stats(struct k_atm_aal_stats *from,
97480 struct atm_aal_stats *to)
97481 {
97482-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97483+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97484 __AAL_STAT_ITEMS
97485 #undef __HANDLE_ITEM
97486 }
97487@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97488 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97489 struct atm_aal_stats *to)
97490 {
97491-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97492+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97493 __AAL_STAT_ITEMS
97494 #undef __HANDLE_ITEM
97495 }
97496diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97497index 919a5ce..cc6b444 100644
97498--- a/net/ax25/sysctl_net_ax25.c
97499+++ b/net/ax25/sysctl_net_ax25.c
97500@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97501 {
97502 char path[sizeof("net/ax25/") + IFNAMSIZ];
97503 int k;
97504- struct ctl_table *table;
97505+ ctl_table_no_const *table;
97506
97507 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97508 if (!table)
97509diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97510index 8323bce..a03130d 100644
97511--- a/net/batman-adv/bat_iv_ogm.c
97512+++ b/net/batman-adv/bat_iv_ogm.c
97513@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97514
97515 /* randomize initial seqno to avoid collision */
97516 get_random_bytes(&random_seqno, sizeof(random_seqno));
97517- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97518+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97519
97520 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97521 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97522@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97523 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97524
97525 /* change sequence number to network order */
97526- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97527+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97528 batadv_ogm_packet->seqno = htonl(seqno);
97529- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97530+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97531
97532 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97533
97534@@ -1594,7 +1594,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97535 return;
97536
97537 /* could be changed by schedule_own_packet() */
97538- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97539+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97540
97541 if (ogm_packet->flags & BATADV_DIRECTLINK)
97542 has_directlink_flag = true;
97543diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97544index 88df9b1..69cf7c0 100644
97545--- a/net/batman-adv/fragmentation.c
97546+++ b/net/batman-adv/fragmentation.c
97547@@ -445,7 +445,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97548 frag_header.packet_type = BATADV_UNICAST_FRAG;
97549 frag_header.version = BATADV_COMPAT_VERSION;
97550 frag_header.ttl = BATADV_TTL;
97551- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97552+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97553 frag_header.reserved = 0;
97554 frag_header.no = 0;
97555 frag_header.total_size = htons(skb->len);
97556diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97557index f82c267..0e56d32 100644
97558--- a/net/batman-adv/soft-interface.c
97559+++ b/net/batman-adv/soft-interface.c
97560@@ -283,7 +283,7 @@ send:
97561 primary_if->net_dev->dev_addr, ETH_ALEN);
97562
97563 /* set broadcast sequence number */
97564- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97565+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97566 bcast_packet->seqno = htonl(seqno);
97567
97568 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97569@@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97570 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97571
97572 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97573- atomic_set(&bat_priv->bcast_seqno, 1);
97574+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97575 atomic_set(&bat_priv->tt.vn, 0);
97576 atomic_set(&bat_priv->tt.local_changes, 0);
97577 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97578@@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97579
97580 /* randomize initial seqno to avoid collision */
97581 get_random_bytes(&random_seqno, sizeof(random_seqno));
97582- atomic_set(&bat_priv->frag_seqno, random_seqno);
97583+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97584
97585 bat_priv->primary_if = NULL;
97586 bat_priv->num_ifaces = 0;
97587diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97588index 78370ab..1cb3614 100644
97589--- a/net/batman-adv/types.h
97590+++ b/net/batman-adv/types.h
97591@@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
97592 struct batadv_hard_iface_bat_iv {
97593 unsigned char *ogm_buff;
97594 int ogm_buff_len;
97595- atomic_t ogm_seqno;
97596+ atomic_unchecked_t ogm_seqno;
97597 };
97598
97599 /**
97600@@ -714,7 +714,7 @@ struct batadv_priv {
97601 atomic_t bonding;
97602 atomic_t fragmentation;
97603 atomic_t packet_size_max;
97604- atomic_t frag_seqno;
97605+ atomic_unchecked_t frag_seqno;
97606 #ifdef CONFIG_BATMAN_ADV_BLA
97607 atomic_t bridge_loop_avoidance;
97608 #endif
97609@@ -730,7 +730,7 @@ struct batadv_priv {
97610 #endif
97611 uint32_t isolation_mark;
97612 uint32_t isolation_mark_mask;
97613- atomic_t bcast_seqno;
97614+ atomic_unchecked_t bcast_seqno;
97615 atomic_t bcast_queue_left;
97616 atomic_t batman_queue_left;
97617 char num_ifaces;
97618diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97619index 7552f9e..074ce29 100644
97620--- a/net/bluetooth/hci_sock.c
97621+++ b/net/bluetooth/hci_sock.c
97622@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97623 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97624 }
97625
97626- len = min_t(unsigned int, len, sizeof(uf));
97627+ len = min((size_t)len, sizeof(uf));
97628 if (copy_from_user(&uf, optval, len)) {
97629 err = -EFAULT;
97630 break;
97631diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97632index b0ad2c7..96f6a5e 100644
97633--- a/net/bluetooth/l2cap_core.c
97634+++ b/net/bluetooth/l2cap_core.c
97635@@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
97636 break;
97637
97638 case L2CAP_CONF_RFC:
97639- if (olen == sizeof(rfc))
97640- memcpy(&rfc, (void *)val, olen);
97641+ if (olen != sizeof(rfc))
97642+ break;
97643+
97644+ memcpy(&rfc, (void *)val, olen);
97645
97646 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
97647 rfc.mode != chan->mode)
97648diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
97649index d58f76b..b69600a 100644
97650--- a/net/bluetooth/l2cap_sock.c
97651+++ b/net/bluetooth/l2cap_sock.c
97652@@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97653 struct sock *sk = sock->sk;
97654 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
97655 struct l2cap_options opts;
97656- int len, err = 0;
97657+ int err = 0;
97658+ size_t len = optlen;
97659 u32 opt;
97660
97661 BT_DBG("sk %p", sk);
97662@@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97663 opts.max_tx = chan->max_tx;
97664 opts.txwin_size = chan->tx_win;
97665
97666- len = min_t(unsigned int, sizeof(opts), optlen);
97667+ len = min(sizeof(opts), len);
97668 if (copy_from_user((char *) &opts, optval, len)) {
97669 err = -EFAULT;
97670 break;
97671@@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97672 struct bt_security sec;
97673 struct bt_power pwr;
97674 struct l2cap_conn *conn;
97675- int len, err = 0;
97676+ int err = 0;
97677+ size_t len = optlen;
97678 u32 opt;
97679
97680 BT_DBG("sk %p", sk);
97681@@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97682
97683 sec.level = BT_SECURITY_LOW;
97684
97685- len = min_t(unsigned int, sizeof(sec), optlen);
97686+ len = min(sizeof(sec), len);
97687 if (copy_from_user((char *) &sec, optval, len)) {
97688 err = -EFAULT;
97689 break;
97690@@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97691
97692 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
97693
97694- len = min_t(unsigned int, sizeof(pwr), optlen);
97695+ len = min(sizeof(pwr), len);
97696 if (copy_from_user((char *) &pwr, optval, len)) {
97697 err = -EFAULT;
97698 break;
97699diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97700index 3c2d3e4..884855a 100644
97701--- a/net/bluetooth/rfcomm/sock.c
97702+++ b/net/bluetooth/rfcomm/sock.c
97703@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97704 struct sock *sk = sock->sk;
97705 struct bt_security sec;
97706 int err = 0;
97707- size_t len;
97708+ size_t len = optlen;
97709 u32 opt;
97710
97711 BT_DBG("sk %p", sk);
97712@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97713
97714 sec.level = BT_SECURITY_LOW;
97715
97716- len = min_t(unsigned int, sizeof(sec), optlen);
97717+ len = min(sizeof(sec), len);
97718 if (copy_from_user((char *) &sec, optval, len)) {
97719 err = -EFAULT;
97720 break;
97721diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97722index f9c0980a..fcbbfeb 100644
97723--- a/net/bluetooth/rfcomm/tty.c
97724+++ b/net/bluetooth/rfcomm/tty.c
97725@@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97726 BT_DBG("tty %p id %d", tty, tty->index);
97727
97728 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97729- dev->channel, dev->port.count);
97730+ dev->channel, atomic_read(&dev->port.count));
97731
97732 err = tty_port_open(&dev->port, tty, filp);
97733 if (err)
97734@@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97735 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97736
97737 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97738- dev->port.count);
97739+ atomic_read(&dev->port.count));
97740
97741 tty_port_close(&dev->port, tty, filp);
97742 }
97743diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97744index 0e474b1..fb7109c 100644
97745--- a/net/bridge/netfilter/ebtables.c
97746+++ b/net/bridge/netfilter/ebtables.c
97747@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97748 tmp.valid_hooks = t->table->valid_hooks;
97749 }
97750 mutex_unlock(&ebt_mutex);
97751- if (copy_to_user(user, &tmp, *len) != 0) {
97752+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97753 BUGPRINT("c2u Didn't work\n");
97754 ret = -EFAULT;
97755 break;
97756@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97757 goto out;
97758 tmp.valid_hooks = t->valid_hooks;
97759
97760- if (copy_to_user(user, &tmp, *len) != 0) {
97761+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97762 ret = -EFAULT;
97763 break;
97764 }
97765@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97766 tmp.entries_size = t->table->entries_size;
97767 tmp.valid_hooks = t->table->valid_hooks;
97768
97769- if (copy_to_user(user, &tmp, *len) != 0) {
97770+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97771 ret = -EFAULT;
97772 break;
97773 }
97774diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97775index 0f45522..dab651f 100644
97776--- a/net/caif/cfctrl.c
97777+++ b/net/caif/cfctrl.c
97778@@ -10,6 +10,7 @@
97779 #include <linux/spinlock.h>
97780 #include <linux/slab.h>
97781 #include <linux/pkt_sched.h>
97782+#include <linux/sched.h>
97783 #include <net/caif/caif_layer.h>
97784 #include <net/caif/cfpkt.h>
97785 #include <net/caif/cfctrl.h>
97786@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97787 memset(&dev_info, 0, sizeof(dev_info));
97788 dev_info.id = 0xff;
97789 cfsrvl_init(&this->serv, 0, &dev_info, false);
97790- atomic_set(&this->req_seq_no, 1);
97791- atomic_set(&this->rsp_seq_no, 1);
97792+ atomic_set_unchecked(&this->req_seq_no, 1);
97793+ atomic_set_unchecked(&this->rsp_seq_no, 1);
97794 this->serv.layer.receive = cfctrl_recv;
97795 sprintf(this->serv.layer.name, "ctrl");
97796 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97797@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97798 struct cfctrl_request_info *req)
97799 {
97800 spin_lock_bh(&ctrl->info_list_lock);
97801- atomic_inc(&ctrl->req_seq_no);
97802- req->sequence_no = atomic_read(&ctrl->req_seq_no);
97803+ atomic_inc_unchecked(&ctrl->req_seq_no);
97804+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97805 list_add_tail(&req->list, &ctrl->list);
97806 spin_unlock_bh(&ctrl->info_list_lock);
97807 }
97808@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97809 if (p != first)
97810 pr_warn("Requests are not received in order\n");
97811
97812- atomic_set(&ctrl->rsp_seq_no,
97813+ atomic_set_unchecked(&ctrl->rsp_seq_no,
97814 p->sequence_no);
97815 list_del(&p->list);
97816 goto out;
97817diff --git a/net/can/af_can.c b/net/can/af_can.c
97818index a27f8aa..67174a3 100644
97819--- a/net/can/af_can.c
97820+++ b/net/can/af_can.c
97821@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97822 };
97823
97824 /* notifier block for netdevice event */
97825-static struct notifier_block can_netdev_notifier __read_mostly = {
97826+static struct notifier_block can_netdev_notifier = {
97827 .notifier_call = can_notifier,
97828 };
97829
97830diff --git a/net/can/bcm.c b/net/can/bcm.c
97831index dcb75c0..24b1b43 100644
97832--- a/net/can/bcm.c
97833+++ b/net/can/bcm.c
97834@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
97835 }
97836
97837 /* create /proc/net/can-bcm directory */
97838- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
97839+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
97840 return 0;
97841 }
97842
97843diff --git a/net/can/gw.c b/net/can/gw.c
97844index ac31891..4799c17 100644
97845--- a/net/can/gw.c
97846+++ b/net/can/gw.c
97847@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
97848 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
97849
97850 static HLIST_HEAD(cgw_list);
97851-static struct notifier_block notifier;
97852
97853 static struct kmem_cache *cgw_cache __read_mostly;
97854
97855@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
97856 return err;
97857 }
97858
97859+static struct notifier_block notifier = {
97860+ .notifier_call = cgw_notifier
97861+};
97862+
97863 static __init int cgw_module_init(void)
97864 {
97865 /* sanitize given module parameter */
97866@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
97867 return -ENOMEM;
97868
97869 /* set notifier */
97870- notifier.notifier_call = cgw_notifier;
97871 register_netdevice_notifier(&notifier);
97872
97873 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
97874diff --git a/net/can/proc.c b/net/can/proc.c
97875index b543470..d2ddae2 100644
97876--- a/net/can/proc.c
97877+++ b/net/can/proc.c
97878@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
97879 void can_init_proc(void)
97880 {
97881 /* create /proc/net/can directory */
97882- can_dir = proc_mkdir("can", init_net.proc_net);
97883+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
97884
97885 if (!can_dir) {
97886 printk(KERN_INFO "can: failed to create /proc/net/can . "
97887diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
97888index 30efc5c..cfa1bbc 100644
97889--- a/net/ceph/messenger.c
97890+++ b/net/ceph/messenger.c
97891@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
97892 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
97893
97894 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
97895-static atomic_t addr_str_seq = ATOMIC_INIT(0);
97896+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
97897
97898 static struct page *zero_page; /* used in certain error cases */
97899
97900@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
97901 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
97902 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
97903
97904- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97905+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97906 s = addr_str[i];
97907
97908 switch (ss->ss_family) {
97909diff --git a/net/compat.c b/net/compat.c
97910index f50161f..94fa415 100644
97911--- a/net/compat.c
97912+++ b/net/compat.c
97913@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
97914 return -EFAULT;
97915 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
97916 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
97917- kmsg->msg_name = compat_ptr(tmp1);
97918- kmsg->msg_iov = compat_ptr(tmp2);
97919- kmsg->msg_control = compat_ptr(tmp3);
97920+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
97921+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
97922+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
97923 return 0;
97924 }
97925
97926@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97927
97928 if (kern_msg->msg_namelen) {
97929 if (mode == VERIFY_READ) {
97930- int err = move_addr_to_kernel(kern_msg->msg_name,
97931+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
97932 kern_msg->msg_namelen,
97933 kern_address);
97934 if (err < 0)
97935@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97936 kern_msg->msg_name = NULL;
97937
97938 tot_len = iov_from_user_compat_to_kern(kern_iov,
97939- (struct compat_iovec __user *)kern_msg->msg_iov,
97940+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
97941 kern_msg->msg_iovlen);
97942 if (tot_len >= 0)
97943 kern_msg->msg_iov = kern_iov;
97944@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97945
97946 #define CMSG_COMPAT_FIRSTHDR(msg) \
97947 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
97948- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
97949+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
97950 (struct compat_cmsghdr __user *)NULL)
97951
97952 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
97953 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
97954 (ucmlen) <= (unsigned long) \
97955 ((mhdr)->msg_controllen - \
97956- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
97957+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
97958
97959 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
97960 struct compat_cmsghdr __user *cmsg, int cmsg_len)
97961 {
97962 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
97963- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
97964+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
97965 msg->msg_controllen)
97966 return NULL;
97967 return (struct compat_cmsghdr __user *)ptr;
97968@@ -222,7 +222,7 @@ Efault:
97969
97970 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
97971 {
97972- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97973+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97974 struct compat_cmsghdr cmhdr;
97975 struct compat_timeval ctv;
97976 struct compat_timespec cts[3];
97977@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
97978
97979 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
97980 {
97981- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97982+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97983 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
97984 int fdnum = scm->fp->count;
97985 struct file **fp = scm->fp->fp;
97986@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
97987 return -EFAULT;
97988 old_fs = get_fs();
97989 set_fs(KERNEL_DS);
97990- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
97991+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
97992 set_fs(old_fs);
97993
97994 return err;
97995@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
97996 len = sizeof(ktime);
97997 old_fs = get_fs();
97998 set_fs(KERNEL_DS);
97999- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
98000+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
98001 set_fs(old_fs);
98002
98003 if (!err) {
98004@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98005 case MCAST_JOIN_GROUP:
98006 case MCAST_LEAVE_GROUP:
98007 {
98008- struct compat_group_req __user *gr32 = (void *)optval;
98009+ struct compat_group_req __user *gr32 = (void __user *)optval;
98010 struct group_req __user *kgr =
98011 compat_alloc_user_space(sizeof(struct group_req));
98012 u32 interface;
98013@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98014 case MCAST_BLOCK_SOURCE:
98015 case MCAST_UNBLOCK_SOURCE:
98016 {
98017- struct compat_group_source_req __user *gsr32 = (void *)optval;
98018+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
98019 struct group_source_req __user *kgsr = compat_alloc_user_space(
98020 sizeof(struct group_source_req));
98021 u32 interface;
98022@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98023 }
98024 case MCAST_MSFILTER:
98025 {
98026- struct compat_group_filter __user *gf32 = (void *)optval;
98027+ struct compat_group_filter __user *gf32 = (void __user *)optval;
98028 struct group_filter __user *kgf;
98029 u32 interface, fmode, numsrc;
98030
98031@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
98032 char __user *optval, int __user *optlen,
98033 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
98034 {
98035- struct compat_group_filter __user *gf32 = (void *)optval;
98036+ struct compat_group_filter __user *gf32 = (void __user *)optval;
98037 struct group_filter __user *kgf;
98038 int __user *koptlen;
98039 u32 interface, fmode, numsrc;
98040@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
98041
98042 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
98043 return -EINVAL;
98044- if (copy_from_user(a, args, nas[call]))
98045+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
98046 return -EFAULT;
98047 a0 = a[0];
98048 a1 = a[1];
98049diff --git a/net/core/datagram.c b/net/core/datagram.c
98050index a16ed7b..eb44d17 100644
98051--- a/net/core/datagram.c
98052+++ b/net/core/datagram.c
98053@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
98054 }
98055
98056 kfree_skb(skb);
98057- atomic_inc(&sk->sk_drops);
98058+ atomic_inc_unchecked(&sk->sk_drops);
98059 sk_mem_reclaim_partial(sk);
98060
98061 return err;
98062diff --git a/net/core/dev.c b/net/core/dev.c
98063index 45fa2f1..f3e28ec 100644
98064--- a/net/core/dev.c
98065+++ b/net/core/dev.c
98066@@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
98067 {
98068 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
98069 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
98070- atomic_long_inc(&dev->rx_dropped);
98071+ atomic_long_inc_unchecked(&dev->rx_dropped);
98072 kfree_skb(skb);
98073 return NET_RX_DROP;
98074 }
98075 }
98076
98077 if (unlikely(!is_skb_forwardable(dev, skb))) {
98078- atomic_long_inc(&dev->rx_dropped);
98079+ atomic_long_inc_unchecked(&dev->rx_dropped);
98080 kfree_skb(skb);
98081 return NET_RX_DROP;
98082 }
98083@@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
98084
98085 struct dev_gso_cb {
98086 void (*destructor)(struct sk_buff *skb);
98087-};
98088+} __no_const;
98089
98090 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
98091
98092@@ -3227,7 +3227,7 @@ enqueue:
98093
98094 local_irq_restore(flags);
98095
98096- atomic_long_inc(&skb->dev->rx_dropped);
98097+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98098 kfree_skb(skb);
98099 return NET_RX_DROP;
98100 }
98101@@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
98102 }
98103 EXPORT_SYMBOL(netif_rx_ni);
98104
98105-static void net_tx_action(struct softirq_action *h)
98106+static __latent_entropy void net_tx_action(void)
98107 {
98108 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98109
98110@@ -3645,7 +3645,7 @@ ncls:
98111 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
98112 } else {
98113 drop:
98114- atomic_long_inc(&skb->dev->rx_dropped);
98115+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98116 kfree_skb(skb);
98117 /* Jamal, now you will not able to escape explaining
98118 * me how you were going to use this. :-)
98119@@ -4331,7 +4331,7 @@ void netif_napi_del(struct napi_struct *napi)
98120 }
98121 EXPORT_SYMBOL(netif_napi_del);
98122
98123-static void net_rx_action(struct softirq_action *h)
98124+static __latent_entropy void net_rx_action(void)
98125 {
98126 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98127 unsigned long time_limit = jiffies + 2;
98128@@ -6250,7 +6250,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
98129 } else {
98130 netdev_stats_to_stats64(storage, &dev->stats);
98131 }
98132- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
98133+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
98134 return storage;
98135 }
98136 EXPORT_SYMBOL(dev_get_stats);
98137diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
98138index cf999e0..c59a975 100644
98139--- a/net/core/dev_ioctl.c
98140+++ b/net/core/dev_ioctl.c
98141@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
98142 if (no_module && capable(CAP_NET_ADMIN))
98143 no_module = request_module("netdev-%s", name);
98144 if (no_module && capable(CAP_SYS_MODULE)) {
98145+#ifdef CONFIG_GRKERNSEC_MODHARDEN
98146+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
98147+#else
98148 if (!request_module("%s", name))
98149 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
98150 name);
98151+#endif
98152 }
98153 }
98154 EXPORT_SYMBOL(dev_load);
98155diff --git a/net/core/filter.c b/net/core/filter.c
98156index ad30d62..21c0743 100644
98157--- a/net/core/filter.c
98158+++ b/net/core/filter.c
98159@@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
98160 void *ptr;
98161 u32 A = 0; /* Accumulator */
98162 u32 X = 0; /* Index Register */
98163- u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
98164+ u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
98165 u32 tmp;
98166 int k;
98167
98168@@ -292,10 +292,10 @@ load_b:
98169 X = K;
98170 continue;
98171 case BPF_S_LD_MEM:
98172- A = mem[K];
98173+ A = mem[K&15];
98174 continue;
98175 case BPF_S_LDX_MEM:
98176- X = mem[K];
98177+ X = mem[K&15];
98178 continue;
98179 case BPF_S_MISC_TAX:
98180 X = A;
98181@@ -308,10 +308,10 @@ load_b:
98182 case BPF_S_RET_A:
98183 return A;
98184 case BPF_S_ST:
98185- mem[K] = A;
98186+ mem[K&15] = A;
98187 continue;
98188 case BPF_S_STX:
98189- mem[K] = X;
98190+ mem[K&15] = X;
98191 continue;
98192 case BPF_S_ANC_PROTOCOL:
98193 A = ntohs(skb->protocol);
98194@@ -355,6 +355,10 @@ load_b:
98195
98196 if (skb_is_nonlinear(skb))
98197 return 0;
98198+
98199+ if (skb->len < sizeof(struct nlattr))
98200+ return 0;
98201+
98202 if (A > skb->len - sizeof(struct nlattr))
98203 return 0;
98204
98205@@ -371,11 +375,15 @@ load_b:
98206
98207 if (skb_is_nonlinear(skb))
98208 return 0;
98209+
98210+ if (skb->len < sizeof(struct nlattr))
98211+ return 0;
98212+
98213 if (A > skb->len - sizeof(struct nlattr))
98214 return 0;
98215
98216 nla = (struct nlattr *)&skb->data[A];
98217- if (nla->nla_len > A - skb->len)
98218+ if (nla->nla_len > skb->len - A)
98219 return 0;
98220
98221 nla = nla_find_nested(nla, X);
98222@@ -391,9 +399,10 @@ load_b:
98223 continue;
98224 #endif
98225 default:
98226- WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
98227+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98228 fentry->code, fentry->jt,
98229 fentry->jf, fentry->k);
98230+ BUG();
98231 return 0;
98232 }
98233 }
98234@@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98235 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98236 int pc, ret = 0;
98237
98238- BUILD_BUG_ON(BPF_MEMWORDS > 16);
98239+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
98240 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98241 if (!masks)
98242 return -ENOMEM;
98243@@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98244 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
98245 if (!fp)
98246 return -ENOMEM;
98247- memcpy(fp->insns, fprog->filter, fsize);
98248+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98249
98250 atomic_set(&fp->refcnt, 1);
98251 fp->len = fprog->len;
98252diff --git a/net/core/flow.c b/net/core/flow.c
98253index dfa602c..3103d88 100644
98254--- a/net/core/flow.c
98255+++ b/net/core/flow.c
98256@@ -61,7 +61,7 @@ struct flow_cache {
98257 struct timer_list rnd_timer;
98258 };
98259
98260-atomic_t flow_cache_genid = ATOMIC_INIT(0);
98261+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
98262 EXPORT_SYMBOL(flow_cache_genid);
98263 static struct flow_cache flow_cache_global;
98264 static struct kmem_cache *flow_cachep __read_mostly;
98265@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98266
98267 static int flow_entry_valid(struct flow_cache_entry *fle)
98268 {
98269- if (atomic_read(&flow_cache_genid) != fle->genid)
98270+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
98271 return 0;
98272 if (fle->object && !fle->object->ops->check(fle->object))
98273 return 0;
98274@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98275 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98276 fcp->hash_count++;
98277 }
98278- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
98279+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
98280 flo = fle->object;
98281 if (!flo)
98282 goto ret_object;
98283@@ -279,7 +279,7 @@ nocache:
98284 }
98285 flo = resolver(net, key, family, dir, flo, ctx);
98286 if (fle) {
98287- fle->genid = atomic_read(&flow_cache_genid);
98288+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
98289 if (!IS_ERR(flo))
98290 fle->object = flo;
98291 else
98292diff --git a/net/core/iovec.c b/net/core/iovec.c
98293index b618694..192bbba 100644
98294--- a/net/core/iovec.c
98295+++ b/net/core/iovec.c
98296@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98297 if (m->msg_namelen) {
98298 if (mode == VERIFY_READ) {
98299 void __user *namep;
98300- namep = (void __user __force *) m->msg_name;
98301+ namep = (void __force_user *) m->msg_name;
98302 err = move_addr_to_kernel(namep, m->msg_namelen,
98303 address);
98304 if (err < 0)
98305@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98306 }
98307
98308 size = m->msg_iovlen * sizeof(struct iovec);
98309- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98310+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98311 return -EFAULT;
98312
98313 m->msg_iov = iov;
98314diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98315index e161290..8149aea 100644
98316--- a/net/core/neighbour.c
98317+++ b/net/core/neighbour.c
98318@@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98319 void __user *buffer, size_t *lenp, loff_t *ppos)
98320 {
98321 int size, ret;
98322- struct ctl_table tmp = *ctl;
98323+ ctl_table_no_const tmp = *ctl;
98324
98325 tmp.extra1 = &zero;
98326 tmp.extra2 = &unres_qlen_max;
98327@@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98328 void __user *buffer,
98329 size_t *lenp, loff_t *ppos)
98330 {
98331- struct ctl_table tmp = *ctl;
98332+ ctl_table_no_const tmp = *ctl;
98333 int ret;
98334
98335 tmp.extra1 = &zero;
98336@@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98337 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98338 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98339 } else {
98340+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98341 dev_name_source = "default";
98342- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98343- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98344- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98345- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98346+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98347+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98348+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98349+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98350 }
98351
98352 if (handler) {
98353diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98354index 2bf8329..2eb1423 100644
98355--- a/net/core/net-procfs.c
98356+++ b/net/core/net-procfs.c
98357@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98358 struct rtnl_link_stats64 temp;
98359 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98360
98361- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98362+ if (gr_proc_is_restricted())
98363+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98364+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98365+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98366+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98367+ else
98368+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98369 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98370 dev->name, stats->rx_bytes, stats->rx_packets,
98371 stats->rx_errors,
98372@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98373 return 0;
98374 }
98375
98376-static const struct seq_operations dev_seq_ops = {
98377+const struct seq_operations dev_seq_ops = {
98378 .start = dev_seq_start,
98379 .next = dev_seq_next,
98380 .stop = dev_seq_stop,
98381@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98382
98383 static int softnet_seq_open(struct inode *inode, struct file *file)
98384 {
98385- return seq_open(file, &softnet_seq_ops);
98386+ return seq_open_restrict(file, &softnet_seq_ops);
98387 }
98388
98389 static const struct file_operations softnet_seq_fops = {
98390@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98391 else
98392 seq_printf(seq, "%04x", ntohs(pt->type));
98393
98394+#ifdef CONFIG_GRKERNSEC_HIDESYM
98395+ seq_printf(seq, " %-8s %pf\n",
98396+ pt->dev ? pt->dev->name : "", NULL);
98397+#else
98398 seq_printf(seq, " %-8s %pf\n",
98399 pt->dev ? pt->dev->name : "", pt->func);
98400+#endif
98401 }
98402
98403 return 0;
98404diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98405index 81d3a9a..a0bd7a8 100644
98406--- a/net/core/net_namespace.c
98407+++ b/net/core/net_namespace.c
98408@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98409 int error;
98410 LIST_HEAD(net_exit_list);
98411
98412- list_add_tail(&ops->list, list);
98413+ pax_list_add_tail((struct list_head *)&ops->list, list);
98414 if (ops->init || (ops->id && ops->size)) {
98415 for_each_net(net) {
98416 error = ops_init(ops, net);
98417@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98418
98419 out_undo:
98420 /* If I have an error cleanup all namespaces I initialized */
98421- list_del(&ops->list);
98422+ pax_list_del((struct list_head *)&ops->list);
98423 ops_exit_list(ops, &net_exit_list);
98424 ops_free_list(ops, &net_exit_list);
98425 return error;
98426@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98427 struct net *net;
98428 LIST_HEAD(net_exit_list);
98429
98430- list_del(&ops->list);
98431+ pax_list_del((struct list_head *)&ops->list);
98432 for_each_net(net)
98433 list_add_tail(&net->exit_list, &net_exit_list);
98434 ops_exit_list(ops, &net_exit_list);
98435@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98436 mutex_lock(&net_mutex);
98437 error = register_pernet_operations(&pernet_list, ops);
98438 if (!error && (first_device == &pernet_list))
98439- first_device = &ops->list;
98440+ first_device = (struct list_head *)&ops->list;
98441 mutex_unlock(&net_mutex);
98442 return error;
98443 }
98444diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98445index df9e6b1..6e68e4e 100644
98446--- a/net/core/netpoll.c
98447+++ b/net/core/netpoll.c
98448@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98449 struct udphdr *udph;
98450 struct iphdr *iph;
98451 struct ethhdr *eth;
98452- static atomic_t ip_ident;
98453+ static atomic_unchecked_t ip_ident;
98454 struct ipv6hdr *ip6h;
98455
98456 udp_len = len + sizeof(*udph);
98457@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98458 put_unaligned(0x45, (unsigned char *)iph);
98459 iph->tos = 0;
98460 put_unaligned(htons(ip_len), &(iph->tot_len));
98461- iph->id = htons(atomic_inc_return(&ip_ident));
98462+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98463 iph->frag_off = 0;
98464 iph->ttl = 64;
98465 iph->protocol = IPPROTO_UDP;
98466diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98467index fdac61c..e5e5b46 100644
98468--- a/net/core/pktgen.c
98469+++ b/net/core/pktgen.c
98470@@ -3719,7 +3719,7 @@ static int __net_init pg_net_init(struct net *net)
98471 pn->net = net;
98472 INIT_LIST_HEAD(&pn->pktgen_threads);
98473 pn->pktgen_exiting = false;
98474- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98475+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98476 if (!pn->proc_dir) {
98477 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98478 return -ENODEV;
98479diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98480index 120eecc..cd1ec44 100644
98481--- a/net/core/rtnetlink.c
98482+++ b/net/core/rtnetlink.c
98483@@ -58,7 +58,7 @@ struct rtnl_link {
98484 rtnl_doit_func doit;
98485 rtnl_dumpit_func dumpit;
98486 rtnl_calcit_func calcit;
98487-};
98488+} __no_const;
98489
98490 static DEFINE_MUTEX(rtnl_mutex);
98491
98492@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98493 if (rtnl_link_ops_get(ops->kind))
98494 return -EEXIST;
98495
98496- if (!ops->dellink)
98497- ops->dellink = unregister_netdevice_queue;
98498+ if (!ops->dellink) {
98499+ pax_open_kernel();
98500+ *(void **)&ops->dellink = unregister_netdevice_queue;
98501+ pax_close_kernel();
98502+ }
98503
98504- list_add_tail(&ops->list, &link_ops);
98505+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98506 return 0;
98507 }
98508 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98509@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98510 for_each_net(net) {
98511 __rtnl_kill_links(net, ops);
98512 }
98513- list_del(&ops->list);
98514+ pax_list_del((struct list_head *)&ops->list);
98515 }
98516 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98517
98518diff --git a/net/core/scm.c b/net/core/scm.c
98519index b442e7e..6f5b5a2 100644
98520--- a/net/core/scm.c
98521+++ b/net/core/scm.c
98522@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98523 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98524 {
98525 struct cmsghdr __user *cm
98526- = (__force struct cmsghdr __user *)msg->msg_control;
98527+ = (struct cmsghdr __force_user *)msg->msg_control;
98528 struct cmsghdr cmhdr;
98529 int cmlen = CMSG_LEN(len);
98530 int err;
98531@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98532 err = -EFAULT;
98533 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98534 goto out;
98535- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98536+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98537 goto out;
98538 cmlen = CMSG_SPACE(len);
98539 if (msg->msg_controllen < cmlen)
98540@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98541 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98542 {
98543 struct cmsghdr __user *cm
98544- = (__force struct cmsghdr __user*)msg->msg_control;
98545+ = (struct cmsghdr __force_user *)msg->msg_control;
98546
98547 int fdmax = 0;
98548 int fdnum = scm->fp->count;
98549@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98550 if (fdnum < fdmax)
98551 fdmax = fdnum;
98552
98553- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98554+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98555 i++, cmfptr++)
98556 {
98557 struct socket *sock;
98558diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98559index 90b96a1..cd18f16d 100644
98560--- a/net/core/skbuff.c
98561+++ b/net/core/skbuff.c
98562@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98563 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98564 int len, __wsum csum)
98565 {
98566- const struct skb_checksum_ops ops = {
98567+ static const struct skb_checksum_ops ops = {
98568 .update = csum_partial_ext,
98569 .combine = csum_block_add_ext,
98570 };
98571@@ -3220,13 +3220,15 @@ void __init skb_init(void)
98572 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98573 sizeof(struct sk_buff),
98574 0,
98575- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98576+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98577+ SLAB_NO_SANITIZE,
98578 NULL);
98579 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98580 (2*sizeof(struct sk_buff)) +
98581 sizeof(atomic_t),
98582 0,
98583- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98584+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98585+ SLAB_NO_SANITIZE,
98586 NULL);
98587 }
98588
98589diff --git a/net/core/sock.c b/net/core/sock.c
98590index c0fc6bd..51d8326 100644
98591--- a/net/core/sock.c
98592+++ b/net/core/sock.c
98593@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98594 struct sk_buff_head *list = &sk->sk_receive_queue;
98595
98596 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98597- atomic_inc(&sk->sk_drops);
98598+ atomic_inc_unchecked(&sk->sk_drops);
98599 trace_sock_rcvqueue_full(sk, skb);
98600 return -ENOMEM;
98601 }
98602@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98603 return err;
98604
98605 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98606- atomic_inc(&sk->sk_drops);
98607+ atomic_inc_unchecked(&sk->sk_drops);
98608 return -ENOBUFS;
98609 }
98610
98611@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98612 skb_dst_force(skb);
98613
98614 spin_lock_irqsave(&list->lock, flags);
98615- skb->dropcount = atomic_read(&sk->sk_drops);
98616+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98617 __skb_queue_tail(list, skb);
98618 spin_unlock_irqrestore(&list->lock, flags);
98619
98620@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98621 skb->dev = NULL;
98622
98623 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98624- atomic_inc(&sk->sk_drops);
98625+ atomic_inc_unchecked(&sk->sk_drops);
98626 goto discard_and_relse;
98627 }
98628 if (nested)
98629@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98630 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98631 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98632 bh_unlock_sock(sk);
98633- atomic_inc(&sk->sk_drops);
98634+ atomic_inc_unchecked(&sk->sk_drops);
98635 goto discard_and_relse;
98636 }
98637
98638@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98639 struct timeval tm;
98640 } v;
98641
98642- int lv = sizeof(int);
98643- int len;
98644+ unsigned int lv = sizeof(int);
98645+ unsigned int len;
98646
98647 if (get_user(len, optlen))
98648 return -EFAULT;
98649- if (len < 0)
98650+ if (len > INT_MAX)
98651 return -EINVAL;
98652
98653 memset(&v, 0, sizeof(v));
98654@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98655
98656 case SO_PEERNAME:
98657 {
98658- char address[128];
98659+ char address[_K_SS_MAXSIZE];
98660
98661 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98662 return -ENOTCONN;
98663- if (lv < len)
98664+ if (lv < len || sizeof address < len)
98665 return -EINVAL;
98666 if (copy_to_user(optval, address, len))
98667 return -EFAULT;
98668@@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98669
98670 if (len > lv)
98671 len = lv;
98672- if (copy_to_user(optval, &v, len))
98673+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
98674 return -EFAULT;
98675 lenout:
98676 if (put_user(len, optlen))
98677@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
98678 */
98679 smp_wmb();
98680 atomic_set(&sk->sk_refcnt, 1);
98681- atomic_set(&sk->sk_drops, 0);
98682+ atomic_set_unchecked(&sk->sk_drops, 0);
98683 }
98684 EXPORT_SYMBOL(sock_init_data);
98685
98686@@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
98687 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98688 int level, int type)
98689 {
98690+ struct sock_extended_err ee;
98691 struct sock_exterr_skb *serr;
98692 struct sk_buff *skb, *skb2;
98693 int copied, err;
98694@@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98695 sock_recv_timestamp(msg, sk, skb);
98696
98697 serr = SKB_EXT_ERR(skb);
98698- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98699+ ee = serr->ee;
98700+ put_cmsg(msg, level, type, sizeof ee, &ee);
98701
98702 msg->msg_flags |= MSG_ERRQUEUE;
98703 err = copied;
98704diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98705index a0e9cf6..ef7f9ed 100644
98706--- a/net/core/sock_diag.c
98707+++ b/net/core/sock_diag.c
98708@@ -9,26 +9,33 @@
98709 #include <linux/inet_diag.h>
98710 #include <linux/sock_diag.h>
98711
98712-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98713+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98714 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98715 static DEFINE_MUTEX(sock_diag_table_mutex);
98716
98717 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98718 {
98719+#ifndef CONFIG_GRKERNSEC_HIDESYM
98720 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98721 cookie[1] != INET_DIAG_NOCOOKIE) &&
98722 ((u32)(unsigned long)sk != cookie[0] ||
98723 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98724 return -ESTALE;
98725 else
98726+#endif
98727 return 0;
98728 }
98729 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98730
98731 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98732 {
98733+#ifdef CONFIG_GRKERNSEC_HIDESYM
98734+ cookie[0] = 0;
98735+ cookie[1] = 0;
98736+#else
98737 cookie[0] = (u32)(unsigned long)sk;
98738 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98739+#endif
98740 }
98741 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98742
98743@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98744 mutex_lock(&sock_diag_table_mutex);
98745 if (sock_diag_handlers[hndl->family])
98746 err = -EBUSY;
98747- else
98748+ else {
98749+ pax_open_kernel();
98750 sock_diag_handlers[hndl->family] = hndl;
98751+ pax_close_kernel();
98752+ }
98753 mutex_unlock(&sock_diag_table_mutex);
98754
98755 return err;
98756@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98757
98758 mutex_lock(&sock_diag_table_mutex);
98759 BUG_ON(sock_diag_handlers[family] != hnld);
98760+ pax_open_kernel();
98761 sock_diag_handlers[family] = NULL;
98762+ pax_close_kernel();
98763 mutex_unlock(&sock_diag_table_mutex);
98764 }
98765 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98766diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98767index cf9cd13..8b56af3 100644
98768--- a/net/core/sysctl_net_core.c
98769+++ b/net/core/sysctl_net_core.c
98770@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98771 {
98772 unsigned int orig_size, size;
98773 int ret, i;
98774- struct ctl_table tmp = {
98775+ ctl_table_no_const tmp = {
98776 .data = &size,
98777 .maxlen = sizeof(size),
98778 .mode = table->mode
98779@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98780 void __user *buffer, size_t *lenp, loff_t *ppos)
98781 {
98782 char id[IFNAMSIZ];
98783- struct ctl_table tbl = {
98784+ ctl_table_no_const tbl = {
98785 .data = id,
98786 .maxlen = IFNAMSIZ,
98787 };
98788@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98789
98790 static __net_init int sysctl_core_net_init(struct net *net)
98791 {
98792- struct ctl_table *tbl;
98793+ ctl_table_no_const *tbl = NULL;
98794
98795 net->core.sysctl_somaxconn = SOMAXCONN;
98796
98797- tbl = netns_core_table;
98798 if (!net_eq(net, &init_net)) {
98799- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98800+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98801 if (tbl == NULL)
98802 goto err_dup;
98803
98804@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98805 if (net->user_ns != &init_user_ns) {
98806 tbl[0].procname = NULL;
98807 }
98808- }
98809-
98810- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98811+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98812+ } else
98813+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98814 if (net->core.sysctl_hdr == NULL)
98815 goto err_reg;
98816
98817 return 0;
98818
98819 err_reg:
98820- if (tbl != netns_core_table)
98821- kfree(tbl);
98822+ kfree(tbl);
98823 err_dup:
98824 return -ENOMEM;
98825 }
98826@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98827 kfree(tbl);
98828 }
98829
98830-static __net_initdata struct pernet_operations sysctl_core_ops = {
98831+static __net_initconst struct pernet_operations sysctl_core_ops = {
98832 .init = sysctl_core_net_init,
98833 .exit = sysctl_core_net_exit,
98834 };
98835diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98836index 4c04848..f575934 100644
98837--- a/net/decnet/af_decnet.c
98838+++ b/net/decnet/af_decnet.c
98839@@ -465,6 +465,7 @@ static struct proto dn_proto = {
98840 .sysctl_rmem = sysctl_decnet_rmem,
98841 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98842 .obj_size = sizeof(struct dn_sock),
98843+ .slab_flags = SLAB_USERCOPY,
98844 };
98845
98846 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98847diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98848index a603823..a36ee0b 100644
98849--- a/net/decnet/dn_dev.c
98850+++ b/net/decnet/dn_dev.c
98851@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
98852 .extra1 = &min_t3,
98853 .extra2 = &max_t3
98854 },
98855- {0}
98856+ { }
98857 },
98858 };
98859
98860diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
98861index 5325b54..a0d4d69 100644
98862--- a/net/decnet/sysctl_net_decnet.c
98863+++ b/net/decnet/sysctl_net_decnet.c
98864@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
98865
98866 if (len > *lenp) len = *lenp;
98867
98868- if (copy_to_user(buffer, addr, len))
98869+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
98870 return -EFAULT;
98871
98872 *lenp = len;
98873@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
98874
98875 if (len > *lenp) len = *lenp;
98876
98877- if (copy_to_user(buffer, devname, len))
98878+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
98879 return -EFAULT;
98880
98881 *lenp = len;
98882diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
98883index 1846c1f..96d4a9f 100644
98884--- a/net/ieee802154/dgram.c
98885+++ b/net/ieee802154/dgram.c
98886@@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
98887 if (saddr) {
98888 saddr->family = AF_IEEE802154;
98889 saddr->addr = mac_cb(skb)->sa;
98890+ }
98891+ if (addr_len)
98892 *addr_len = sizeof(*saddr);
98893- }
98894
98895 if (flags & MSG_TRUNC)
98896 copied = skb->len;
98897diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
98898index 19ab78a..bf575c9 100644
98899--- a/net/ipv4/af_inet.c
98900+++ b/net/ipv4/af_inet.c
98901@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
98902
98903 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
98904
98905- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
98906- if (!sysctl_local_reserved_ports)
98907- goto out;
98908-
98909 rc = proto_register(&tcp_prot, 1);
98910 if (rc)
98911- goto out_free_reserved_ports;
98912+ goto out;
98913
98914 rc = proto_register(&udp_prot, 1);
98915 if (rc)
98916@@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
98917 proto_unregister(&udp_prot);
98918 out_unregister_tcp_proto:
98919 proto_unregister(&tcp_prot);
98920-out_free_reserved_ports:
98921- kfree(sysctl_local_reserved_ports);
98922 goto out;
98923 }
98924
98925diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
98926index bdbf68b..deb4759 100644
98927--- a/net/ipv4/devinet.c
98928+++ b/net/ipv4/devinet.c
98929@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
98930 idx = 0;
98931 head = &net->dev_index_head[h];
98932 rcu_read_lock();
98933- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98934+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98935 net->dev_base_seq;
98936 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98937 if (idx < s_idx)
98938@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
98939 idx = 0;
98940 head = &net->dev_index_head[h];
98941 rcu_read_lock();
98942- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98943+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98944 net->dev_base_seq;
98945 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98946 if (idx < s_idx)
98947@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
98948 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
98949 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
98950
98951-static struct devinet_sysctl_table {
98952+static const struct devinet_sysctl_table {
98953 struct ctl_table_header *sysctl_header;
98954 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
98955 } devinet_sysctl = {
98956@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
98957 int err;
98958 struct ipv4_devconf *all, *dflt;
98959 #ifdef CONFIG_SYSCTL
98960- struct ctl_table *tbl = ctl_forward_entry;
98961+ ctl_table_no_const *tbl = NULL;
98962 struct ctl_table_header *forw_hdr;
98963 #endif
98964
98965@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
98966 goto err_alloc_dflt;
98967
98968 #ifdef CONFIG_SYSCTL
98969- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
98970+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
98971 if (tbl == NULL)
98972 goto err_alloc_ctl;
98973
98974@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
98975 goto err_reg_dflt;
98976
98977 err = -ENOMEM;
98978- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98979+ if (!net_eq(net, &init_net))
98980+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98981+ else
98982+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
98983 if (forw_hdr == NULL)
98984 goto err_reg_ctl;
98985 net->ipv4.forw_hdr = forw_hdr;
98986@@ -2272,8 +2275,7 @@ err_reg_ctl:
98987 err_reg_dflt:
98988 __devinet_sysctl_unregister(all);
98989 err_reg_all:
98990- if (tbl != ctl_forward_entry)
98991- kfree(tbl);
98992+ kfree(tbl);
98993 err_alloc_ctl:
98994 #endif
98995 if (dflt != &ipv4_devconf_dflt)
98996diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
98997index c7539e2..b455e51 100644
98998--- a/net/ipv4/fib_frontend.c
98999+++ b/net/ipv4/fib_frontend.c
99000@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
99001 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99002 fib_sync_up(dev);
99003 #endif
99004- atomic_inc(&net->ipv4.dev_addr_genid);
99005+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99006 rt_cache_flush(dev_net(dev));
99007 break;
99008 case NETDEV_DOWN:
99009 fib_del_ifaddr(ifa, NULL);
99010- atomic_inc(&net->ipv4.dev_addr_genid);
99011+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99012 if (ifa->ifa_dev->ifa_list == NULL) {
99013 /* Last address was deleted from this interface.
99014 * Disable IP.
99015@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
99016 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99017 fib_sync_up(dev);
99018 #endif
99019- atomic_inc(&net->ipv4.dev_addr_genid);
99020+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99021 rt_cache_flush(net);
99022 break;
99023 case NETDEV_DOWN:
99024diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
99025index b53f0bf..3585b33 100644
99026--- a/net/ipv4/fib_semantics.c
99027+++ b/net/ipv4/fib_semantics.c
99028@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
99029 nh->nh_saddr = inet_select_addr(nh->nh_dev,
99030 nh->nh_gw,
99031 nh->nh_parent->fib_scope);
99032- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
99033+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
99034
99035 return nh->nh_saddr;
99036 }
99037diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
99038index 0d1e2cb..4501a2c 100644
99039--- a/net/ipv4/inet_connection_sock.c
99040+++ b/net/ipv4/inet_connection_sock.c
99041@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
99042 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
99043 #endif
99044
99045-unsigned long *sysctl_local_reserved_ports;
99046+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
99047 EXPORT_SYMBOL(sysctl_local_reserved_ports);
99048
99049 void inet_get_local_port_range(struct net *net, int *low, int *high)
99050diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
99051index 8b9cf27..0d8d592 100644
99052--- a/net/ipv4/inet_hashtables.c
99053+++ b/net/ipv4/inet_hashtables.c
99054@@ -18,6 +18,7 @@
99055 #include <linux/sched.h>
99056 #include <linux/slab.h>
99057 #include <linux/wait.h>
99058+#include <linux/security.h>
99059
99060 #include <net/inet_connection_sock.h>
99061 #include <net/inet_hashtables.h>
99062@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
99063 return inet_ehashfn(net, laddr, lport, faddr, fport);
99064 }
99065
99066+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
99067+
99068 /*
99069 * Allocate and initialize a new local port bind bucket.
99070 * The bindhash mutex for snum's hash chain must be held here.
99071@@ -554,6 +557,8 @@ ok:
99072 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
99073 spin_unlock(&head->lock);
99074
99075+ gr_update_task_in_ip_table(current, inet_sk(sk));
99076+
99077 if (tw) {
99078 inet_twsk_deschedule(tw, death_row);
99079 while (twrefcnt) {
99080diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
99081index 48f4244..f56d83a 100644
99082--- a/net/ipv4/inetpeer.c
99083+++ b/net/ipv4/inetpeer.c
99084@@ -496,8 +496,8 @@ relookup:
99085 if (p) {
99086 p->daddr = *daddr;
99087 atomic_set(&p->refcnt, 1);
99088- atomic_set(&p->rid, 0);
99089- atomic_set(&p->ip_id_count,
99090+ atomic_set_unchecked(&p->rid, 0);
99091+ atomic_set_unchecked(&p->ip_id_count,
99092 (daddr->family == AF_INET) ?
99093 secure_ip_id(daddr->addr.a4) :
99094 secure_ipv6_id(daddr->addr.a6));
99095diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
99096index c10a3ce..dd71f84 100644
99097--- a/net/ipv4/ip_fragment.c
99098+++ b/net/ipv4/ip_fragment.c
99099@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
99100 return 0;
99101
99102 start = qp->rid;
99103- end = atomic_inc_return(&peer->rid);
99104+ end = atomic_inc_return_unchecked(&peer->rid);
99105 qp->rid = end;
99106
99107 rc = qp->q.fragments && (end - start) > max;
99108@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
99109
99110 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99111 {
99112- struct ctl_table *table;
99113+ ctl_table_no_const *table = NULL;
99114 struct ctl_table_header *hdr;
99115
99116- table = ip4_frags_ns_ctl_table;
99117 if (!net_eq(net, &init_net)) {
99118- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99119+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99120 if (table == NULL)
99121 goto err_alloc;
99122
99123@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99124 /* Don't export sysctls to unprivileged users */
99125 if (net->user_ns != &init_user_ns)
99126 table[0].procname = NULL;
99127- }
99128+ hdr = register_net_sysctl(net, "net/ipv4", table);
99129+ } else
99130+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
99131
99132- hdr = register_net_sysctl(net, "net/ipv4", table);
99133 if (hdr == NULL)
99134 goto err_reg;
99135
99136@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99137 return 0;
99138
99139 err_reg:
99140- if (!net_eq(net, &init_net))
99141- kfree(table);
99142+ kfree(table);
99143 err_alloc:
99144 return -ENOMEM;
99145 }
99146diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
99147index ec4f762..4ce3645 100644
99148--- a/net/ipv4/ip_gre.c
99149+++ b/net/ipv4/ip_gre.c
99150@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
99151 module_param(log_ecn_error, bool, 0644);
99152 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99153
99154-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
99155+static struct rtnl_link_ops ipgre_link_ops;
99156 static int ipgre_tunnel_init(struct net_device *dev);
99157
99158 static int ipgre_net_id __read_mostly;
99159@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99160 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99161 };
99162
99163-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99164+static struct rtnl_link_ops ipgre_link_ops = {
99165 .kind = "gre",
99166 .maxtype = IFLA_GRE_MAX,
99167 .policy = ipgre_policy,
99168@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99169 .fill_info = ipgre_fill_info,
99170 };
99171
99172-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99173+static struct rtnl_link_ops ipgre_tap_ops = {
99174 .kind = "gretap",
99175 .maxtype = IFLA_GRE_MAX,
99176 .policy = ipgre_policy,
99177diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99178index 580dd96..9fcef7e 100644
99179--- a/net/ipv4/ip_sockglue.c
99180+++ b/net/ipv4/ip_sockglue.c
99181@@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99182 len = min_t(unsigned int, len, opt->optlen);
99183 if (put_user(len, optlen))
99184 return -EFAULT;
99185- if (copy_to_user(optval, opt->__data, len))
99186+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99187+ copy_to_user(optval, opt->__data, len))
99188 return -EFAULT;
99189 return 0;
99190 }
99191@@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99192 if (sk->sk_type != SOCK_STREAM)
99193 return -ENOPROTOOPT;
99194
99195- msg.msg_control = optval;
99196+ msg.msg_control = (void __force_kernel *)optval;
99197 msg.msg_controllen = len;
99198 msg.msg_flags = flags;
99199
99200diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99201index 48eafae..defff53 100644
99202--- a/net/ipv4/ip_vti.c
99203+++ b/net/ipv4/ip_vti.c
99204@@ -44,7 +44,7 @@
99205 #include <net/net_namespace.h>
99206 #include <net/netns/generic.h>
99207
99208-static struct rtnl_link_ops vti_link_ops __read_mostly;
99209+static struct rtnl_link_ops vti_link_ops;
99210
99211 static int vti_net_id __read_mostly;
99212 static int vti_tunnel_init(struct net_device *dev);
99213@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99214 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99215 };
99216
99217-static struct rtnl_link_ops vti_link_ops __read_mostly = {
99218+static struct rtnl_link_ops vti_link_ops = {
99219 .kind = "vti",
99220 .maxtype = IFLA_VTI_MAX,
99221 .policy = vti_policy,
99222diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99223index b3e86ea..18ce98c 100644
99224--- a/net/ipv4/ipconfig.c
99225+++ b/net/ipv4/ipconfig.c
99226@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99227
99228 mm_segment_t oldfs = get_fs();
99229 set_fs(get_ds());
99230- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99231+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99232 set_fs(oldfs);
99233 return res;
99234 }
99235@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99236
99237 mm_segment_t oldfs = get_fs();
99238 set_fs(get_ds());
99239- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99240+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99241 set_fs(oldfs);
99242 return res;
99243 }
99244@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99245
99246 mm_segment_t oldfs = get_fs();
99247 set_fs(get_ds());
99248- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99249+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99250 set_fs(oldfs);
99251 return res;
99252 }
99253diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99254index 812b183..56cbe9c 100644
99255--- a/net/ipv4/ipip.c
99256+++ b/net/ipv4/ipip.c
99257@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99258 static int ipip_net_id __read_mostly;
99259
99260 static int ipip_tunnel_init(struct net_device *dev);
99261-static struct rtnl_link_ops ipip_link_ops __read_mostly;
99262+static struct rtnl_link_ops ipip_link_ops;
99263
99264 static int ipip_err(struct sk_buff *skb, u32 info)
99265 {
99266@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99267 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99268 };
99269
99270-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99271+static struct rtnl_link_ops ipip_link_ops = {
99272 .kind = "ipip",
99273 .maxtype = IFLA_IPTUN_MAX,
99274 .policy = ipip_policy,
99275diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99276index 59da7cd..e318de1 100644
99277--- a/net/ipv4/netfilter/arp_tables.c
99278+++ b/net/ipv4/netfilter/arp_tables.c
99279@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99280 #endif
99281
99282 static int get_info(struct net *net, void __user *user,
99283- const int *len, int compat)
99284+ int len, int compat)
99285 {
99286 char name[XT_TABLE_MAXNAMELEN];
99287 struct xt_table *t;
99288 int ret;
99289
99290- if (*len != sizeof(struct arpt_getinfo)) {
99291- duprintf("length %u != %Zu\n", *len,
99292+ if (len != sizeof(struct arpt_getinfo)) {
99293+ duprintf("length %u != %Zu\n", len,
99294 sizeof(struct arpt_getinfo));
99295 return -EINVAL;
99296 }
99297@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99298 info.size = private->size;
99299 strcpy(info.name, name);
99300
99301- if (copy_to_user(user, &info, *len) != 0)
99302+ if (copy_to_user(user, &info, len) != 0)
99303 ret = -EFAULT;
99304 else
99305 ret = 0;
99306@@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99307
99308 switch (cmd) {
99309 case ARPT_SO_GET_INFO:
99310- ret = get_info(sock_net(sk), user, len, 1);
99311+ ret = get_info(sock_net(sk), user, *len, 1);
99312 break;
99313 case ARPT_SO_GET_ENTRIES:
99314 ret = compat_get_entries(sock_net(sk), user, len);
99315@@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99316
99317 switch (cmd) {
99318 case ARPT_SO_GET_INFO:
99319- ret = get_info(sock_net(sk), user, len, 0);
99320+ ret = get_info(sock_net(sk), user, *len, 0);
99321 break;
99322
99323 case ARPT_SO_GET_ENTRIES:
99324diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99325index 718dfbd..cef4152 100644
99326--- a/net/ipv4/netfilter/ip_tables.c
99327+++ b/net/ipv4/netfilter/ip_tables.c
99328@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99329 #endif
99330
99331 static int get_info(struct net *net, void __user *user,
99332- const int *len, int compat)
99333+ int len, int compat)
99334 {
99335 char name[XT_TABLE_MAXNAMELEN];
99336 struct xt_table *t;
99337 int ret;
99338
99339- if (*len != sizeof(struct ipt_getinfo)) {
99340- duprintf("length %u != %zu\n", *len,
99341+ if (len != sizeof(struct ipt_getinfo)) {
99342+ duprintf("length %u != %zu\n", len,
99343 sizeof(struct ipt_getinfo));
99344 return -EINVAL;
99345 }
99346@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99347 info.size = private->size;
99348 strcpy(info.name, name);
99349
99350- if (copy_to_user(user, &info, *len) != 0)
99351+ if (copy_to_user(user, &info, len) != 0)
99352 ret = -EFAULT;
99353 else
99354 ret = 0;
99355@@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99356
99357 switch (cmd) {
99358 case IPT_SO_GET_INFO:
99359- ret = get_info(sock_net(sk), user, len, 1);
99360+ ret = get_info(sock_net(sk), user, *len, 1);
99361 break;
99362 case IPT_SO_GET_ENTRIES:
99363 ret = compat_get_entries(sock_net(sk), user, len);
99364@@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99365
99366 switch (cmd) {
99367 case IPT_SO_GET_INFO:
99368- ret = get_info(sock_net(sk), user, len, 0);
99369+ ret = get_info(sock_net(sk), user, *len, 0);
99370 break;
99371
99372 case IPT_SO_GET_ENTRIES:
99373diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99374index 2510c02..cfb34fa 100644
99375--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99376+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99377@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99378 spin_lock_init(&cn->lock);
99379
99380 #ifdef CONFIG_PROC_FS
99381- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99382+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99383 if (!cn->procdir) {
99384 pr_err("Unable to proc dir entry\n");
99385 return -ENOMEM;
99386diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99387index 2d11c09..3f153f8 100644
99388--- a/net/ipv4/ping.c
99389+++ b/net/ipv4/ping.c
99390@@ -59,7 +59,7 @@ struct ping_table {
99391 };
99392
99393 static struct ping_table ping_table;
99394-struct pingv6_ops pingv6_ops;
99395+struct pingv6_ops *pingv6_ops;
99396 EXPORT_SYMBOL_GPL(pingv6_ops);
99397
99398 static u16 ping_port_rover;
99399@@ -255,23 +255,28 @@ int ping_init_sock(struct sock *sk)
99400 struct group_info *group_info = get_current_groups();
99401 int i, j, count = group_info->ngroups;
99402 kgid_t low, high;
99403+ int ret = 0;
99404
99405 inet_get_ping_group_range_net(net, &low, &high);
99406 if (gid_lte(low, group) && gid_lte(group, high))
99407- return 0;
99408+ goto out_release_group;
99409
99410 for (i = 0; i < group_info->nblocks; i++) {
99411 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
99412 for (j = 0; j < cp_count; j++) {
99413 kgid_t gid = group_info->blocks[i][j];
99414 if (gid_lte(low, gid) && gid_lte(gid, high))
99415- return 0;
99416+ goto out_release_group;
99417 }
99418
99419 count -= cp_count;
99420 }
99421
99422- return -EACCES;
99423+ ret = -EACCES;
99424+
99425+out_release_group:
99426+ put_group_info(group_info);
99427+ return ret;
99428 }
99429 EXPORT_SYMBOL_GPL(ping_init_sock);
99430
99431@@ -341,7 +346,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99432 return -ENODEV;
99433 }
99434 }
99435- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99436+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99437 scoped);
99438 rcu_read_unlock();
99439
99440@@ -549,7 +554,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99441 }
99442 #if IS_ENABLED(CONFIG_IPV6)
99443 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99444- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99445+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99446 #endif
99447 }
99448
99449@@ -567,7 +572,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99450 info, (u8 *)icmph);
99451 #if IS_ENABLED(CONFIG_IPV6)
99452 } else if (family == AF_INET6) {
99453- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99454+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99455 info, (u8 *)icmph);
99456 #endif
99457 }
99458@@ -837,6 +842,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99459 {
99460 struct inet_sock *isk = inet_sk(sk);
99461 int family = sk->sk_family;
99462+ struct sockaddr_in *sin;
99463+ struct sockaddr_in6 *sin6;
99464 struct sk_buff *skb;
99465 int copied, err;
99466
99467@@ -846,12 +853,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99468 if (flags & MSG_OOB)
99469 goto out;
99470
99471+ if (addr_len) {
99472+ if (family == AF_INET)
99473+ *addr_len = sizeof(*sin);
99474+ else if (family == AF_INET6 && addr_len)
99475+ *addr_len = sizeof(*sin6);
99476+ }
99477+
99478 if (flags & MSG_ERRQUEUE) {
99479 if (family == AF_INET) {
99480 return ip_recv_error(sk, msg, len, addr_len);
99481 #if IS_ENABLED(CONFIG_IPV6)
99482 } else if (family == AF_INET6) {
99483- return pingv6_ops.ipv6_recv_error(sk, msg, len,
99484+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
99485 addr_len);
99486 #endif
99487 }
99488@@ -883,7 +897,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99489 sin->sin_port = 0 /* skb->h.uh->source */;
99490 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99491 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99492- *addr_len = sizeof(*sin);
99493 }
99494
99495 if (isk->cmsg_flags)
99496@@ -905,14 +918,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99497 sin6->sin6_scope_id =
99498 ipv6_iface_scope_id(&sin6->sin6_addr,
99499 IP6CB(skb)->iif);
99500- *addr_len = sizeof(*sin6);
99501 }
99502
99503 if (inet6_sk(sk)->rxopt.all)
99504- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99505+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99506 if (skb->protocol == htons(ETH_P_IPV6) &&
99507 inet6_sk(sk)->rxopt.all)
99508- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99509+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99510 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99511 ip_cmsg_recv(msg, skb);
99512 #endif
99513@@ -1104,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99514 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99515 0, sock_i_ino(sp),
99516 atomic_read(&sp->sk_refcnt), sp,
99517- atomic_read(&sp->sk_drops));
99518+ atomic_read_unchecked(&sp->sk_drops));
99519 }
99520
99521 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99522diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99523index c04518f..824ebe5 100644
99524--- a/net/ipv4/raw.c
99525+++ b/net/ipv4/raw.c
99526@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99527 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99528 {
99529 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99530- atomic_inc(&sk->sk_drops);
99531+ atomic_inc_unchecked(&sk->sk_drops);
99532 kfree_skb(skb);
99533 return NET_RX_DROP;
99534 }
99535@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99536 if (flags & MSG_OOB)
99537 goto out;
99538
99539+ if (addr_len)
99540+ *addr_len = sizeof(*sin);
99541+
99542 if (flags & MSG_ERRQUEUE) {
99543 err = ip_recv_error(sk, msg, len, addr_len);
99544 goto out;
99545@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99546 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99547 sin->sin_port = 0;
99548 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99549- *addr_len = sizeof(*sin);
99550 }
99551 if (inet->cmsg_flags)
99552 ip_cmsg_recv(msg, skb);
99553@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99554
99555 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99556 {
99557+ struct icmp_filter filter;
99558+
99559 if (optlen > sizeof(struct icmp_filter))
99560 optlen = sizeof(struct icmp_filter);
99561- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99562+ if (copy_from_user(&filter, optval, optlen))
99563 return -EFAULT;
99564+ raw_sk(sk)->filter = filter;
99565 return 0;
99566 }
99567
99568 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99569 {
99570 int len, ret = -EFAULT;
99571+ struct icmp_filter filter;
99572
99573 if (get_user(len, optlen))
99574 goto out;
99575@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99576 if (len > sizeof(struct icmp_filter))
99577 len = sizeof(struct icmp_filter);
99578 ret = -EFAULT;
99579- if (put_user(len, optlen) ||
99580- copy_to_user(optval, &raw_sk(sk)->filter, len))
99581+ filter = raw_sk(sk)->filter;
99582+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99583 goto out;
99584 ret = 0;
99585 out: return ret;
99586@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99587 0, 0L, 0,
99588 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99589 0, sock_i_ino(sp),
99590- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99591+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99592 }
99593
99594 static int raw_seq_show(struct seq_file *seq, void *v)
99595diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99596index 4c011ec..8fae66b 100644
99597--- a/net/ipv4/route.c
99598+++ b/net/ipv4/route.c
99599@@ -233,7 +233,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99600
99601 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99602 {
99603- return seq_open(file, &rt_cache_seq_ops);
99604+ return seq_open_restrict(file, &rt_cache_seq_ops);
99605 }
99606
99607 static const struct file_operations rt_cache_seq_fops = {
99608@@ -324,7 +324,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99609
99610 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99611 {
99612- return seq_open(file, &rt_cpu_seq_ops);
99613+ return seq_open_restrict(file, &rt_cpu_seq_ops);
99614 }
99615
99616 static const struct file_operations rt_cpu_seq_fops = {
99617@@ -362,7 +362,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99618
99619 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99620 {
99621- return single_open(file, rt_acct_proc_show, NULL);
99622+ return single_open_restrict(file, rt_acct_proc_show, NULL);
99623 }
99624
99625 static const struct file_operations rt_acct_proc_fops = {
99626@@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99627 .maxlen = sizeof(int),
99628 .mode = 0200,
99629 .proc_handler = ipv4_sysctl_rtcache_flush,
99630+ .extra1 = &init_net,
99631 },
99632 { },
99633 };
99634
99635 static __net_init int sysctl_route_net_init(struct net *net)
99636 {
99637- struct ctl_table *tbl;
99638+ ctl_table_no_const *tbl = NULL;
99639
99640- tbl = ipv4_route_flush_table;
99641 if (!net_eq(net, &init_net)) {
99642- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99643+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99644 if (tbl == NULL)
99645 goto err_dup;
99646
99647 /* Don't export sysctls to unprivileged users */
99648 if (net->user_ns != &init_user_ns)
99649 tbl[0].procname = NULL;
99650- }
99651- tbl[0].extra1 = net;
99652+ tbl[0].extra1 = net;
99653+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99654+ } else
99655+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99656
99657- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99658 if (net->ipv4.route_hdr == NULL)
99659 goto err_reg;
99660 return 0;
99661
99662 err_reg:
99663- if (tbl != ipv4_route_flush_table)
99664- kfree(tbl);
99665+ kfree(tbl);
99666 err_dup:
99667 return -ENOMEM;
99668 }
99669@@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
99670
99671 static __net_init int rt_genid_init(struct net *net)
99672 {
99673- atomic_set(&net->ipv4.rt_genid, 0);
99674- atomic_set(&net->fnhe_genid, 0);
99675+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
99676+ atomic_set_unchecked(&net->fnhe_genid, 0);
99677 get_random_bytes(&net->ipv4.dev_addr_genid,
99678 sizeof(net->ipv4.dev_addr_genid));
99679 return 0;
99680diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
99681index 44eba05..b36864b 100644
99682--- a/net/ipv4/sysctl_net_ipv4.c
99683+++ b/net/ipv4/sysctl_net_ipv4.c
99684@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
99685 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
99686 int ret;
99687 int range[2];
99688- struct ctl_table tmp = {
99689+ ctl_table_no_const tmp = {
99690 .data = &range,
99691 .maxlen = sizeof(range),
99692 .mode = table->mode,
99693@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
99694 int ret;
99695 gid_t urange[2];
99696 kgid_t low, high;
99697- struct ctl_table tmp = {
99698+ ctl_table_no_const tmp = {
99699 .data = &urange,
99700 .maxlen = sizeof(urange),
99701 .mode = table->mode,
99702@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99703 void __user *buffer, size_t *lenp, loff_t *ppos)
99704 {
99705 char val[TCP_CA_NAME_MAX];
99706- struct ctl_table tbl = {
99707+ ctl_table_no_const tbl = {
99708 .data = val,
99709 .maxlen = TCP_CA_NAME_MAX,
99710 };
99711@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99712 void __user *buffer, size_t *lenp,
99713 loff_t *ppos)
99714 {
99715- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99716+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99717 int ret;
99718
99719 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99720@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99721 void __user *buffer, size_t *lenp,
99722 loff_t *ppos)
99723 {
99724- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99725+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99726 int ret;
99727
99728 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99729@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99730 void __user *buffer, size_t *lenp,
99731 loff_t *ppos)
99732 {
99733- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99734+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99735 struct tcp_fastopen_context *ctxt;
99736 int ret;
99737 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99738@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99739 },
99740 {
99741 .procname = "ip_local_reserved_ports",
99742- .data = NULL, /* initialized in sysctl_ipv4_init */
99743+ .data = sysctl_local_reserved_ports,
99744 .maxlen = 65536,
99745 .mode = 0644,
99746 .proc_handler = proc_do_large_bitmap,
99747@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99748
99749 static __net_init int ipv4_sysctl_init_net(struct net *net)
99750 {
99751- struct ctl_table *table;
99752+ ctl_table_no_const *table = NULL;
99753
99754- table = ipv4_net_table;
99755 if (!net_eq(net, &init_net)) {
99756 int i;
99757
99758- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99759+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99760 if (table == NULL)
99761 goto err_alloc;
99762
99763@@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99764 net->ipv4.sysctl_local_ports.range[0] = 32768;
99765 net->ipv4.sysctl_local_ports.range[1] = 61000;
99766
99767- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99768+ if (!net_eq(net, &init_net))
99769+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99770+ else
99771+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99772 if (net->ipv4.ipv4_hdr == NULL)
99773 goto err_reg;
99774
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 }
99784@@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
99785 static __init int sysctl_ipv4_init(void)
99786 {
99787 struct ctl_table_header *hdr;
99788- struct ctl_table *i;
99789-
99790- for (i = ipv4_table; i->procname; i++) {
99791- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
99792- i->data = sysctl_local_reserved_ports;
99793- break;
99794- }
99795- }
99796- if (!i->procname)
99797- return -EINVAL;
99798
99799 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
99800 if (hdr == NULL)
99801diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
99802index eeaac39..dc29942 100644
99803--- a/net/ipv4/tcp_input.c
99804+++ b/net/ipv4/tcp_input.c
99805@@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99806 * without any lock. We want to make sure compiler wont store
99807 * intermediate values in this location.
99808 */
99809- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99810+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99811 sk->sk_max_pacing_rate);
99812 }
99813
99814@@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99815 * simplifies code)
99816 */
99817 static void
99818-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99819+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99820 struct sk_buff *head, struct sk_buff *tail,
99821 u32 start, u32 end)
99822 {
99823@@ -5562,6 +5562,7 @@ discard:
99824 tcp_paws_reject(&tp->rx_opt, 0))
99825 goto discard_and_undo;
99826
99827+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99828 if (th->syn) {
99829 /* We see SYN without ACK. It is attempt of
99830 * simultaneous connect with crossed SYNs.
99831@@ -5612,6 +5613,7 @@ discard:
99832 goto discard;
99833 #endif
99834 }
99835+#endif
99836 /* "fifth, if neither of the SYN or RST bits is set then
99837 * drop the segment and return."
99838 */
99839@@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99840 goto discard;
99841
99842 if (th->syn) {
99843- if (th->fin)
99844+ if (th->fin || th->urg || th->psh)
99845 goto discard;
99846 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99847 return 1;
99848diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99849index 1e4eac7..a66fa4a 100644
99850--- a/net/ipv4/tcp_ipv4.c
99851+++ b/net/ipv4/tcp_ipv4.c
99852@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99853 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99854
99855
99856+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99857+extern int grsec_enable_blackhole;
99858+#endif
99859+
99860 #ifdef CONFIG_TCP_MD5SIG
99861 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99862 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99863@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99864 return 0;
99865
99866 reset:
99867+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99868+ if (!grsec_enable_blackhole)
99869+#endif
99870 tcp_v4_send_reset(rsk, skb);
99871 discard:
99872 kfree_skb(skb);
99873@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99874 TCP_SKB_CB(skb)->sacked = 0;
99875
99876 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99877- if (!sk)
99878+ if (!sk) {
99879+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99880+ ret = 1;
99881+#endif
99882 goto no_tcp_socket;
99883-
99884+ }
99885 process:
99886- if (sk->sk_state == TCP_TIME_WAIT)
99887+ if (sk->sk_state == TCP_TIME_WAIT) {
99888+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99889+ ret = 2;
99890+#endif
99891 goto do_time_wait;
99892+ }
99893
99894 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
99895 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99896@@ -2033,6 +2047,10 @@ csum_error:
99897 bad_packet:
99898 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99899 } else {
99900+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99901+ if (!grsec_enable_blackhole || (ret == 1 &&
99902+ (skb->dev->flags & IFF_LOOPBACK)))
99903+#endif
99904 tcp_v4_send_reset(NULL, skb);
99905 }
99906
99907diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
99908index 7a436c5..1b05c59 100644
99909--- a/net/ipv4/tcp_minisocks.c
99910+++ b/net/ipv4/tcp_minisocks.c
99911@@ -27,6 +27,10 @@
99912 #include <net/inet_common.h>
99913 #include <net/xfrm.h>
99914
99915+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99916+extern int grsec_enable_blackhole;
99917+#endif
99918+
99919 int sysctl_tcp_syncookies __read_mostly = 1;
99920 EXPORT_SYMBOL(sysctl_tcp_syncookies);
99921
99922@@ -709,7 +713,10 @@ embryonic_reset:
99923 * avoid becoming vulnerable to outside attack aiming at
99924 * resetting legit local connections.
99925 */
99926- req->rsk_ops->send_reset(sk, skb);
99927+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99928+ if (!grsec_enable_blackhole)
99929+#endif
99930+ req->rsk_ops->send_reset(sk, skb);
99931 } else if (fastopen) { /* received a valid RST pkt */
99932 reqsk_fastopen_remove(sk, req, true);
99933 tcp_reset(sk);
99934diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
99935index 1f2d376..01d18c4 100644
99936--- a/net/ipv4/tcp_probe.c
99937+++ b/net/ipv4/tcp_probe.c
99938@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
99939 if (cnt + width >= len)
99940 break;
99941
99942- if (copy_to_user(buf + cnt, tbuf, width))
99943+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
99944 return -EFAULT;
99945 cnt += width;
99946 }
99947diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
99948index 64f0354..a81b39d 100644
99949--- a/net/ipv4/tcp_timer.c
99950+++ b/net/ipv4/tcp_timer.c
99951@@ -22,6 +22,10 @@
99952 #include <linux/gfp.h>
99953 #include <net/tcp.h>
99954
99955+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99956+extern int grsec_lastack_retries;
99957+#endif
99958+
99959 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
99960 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
99961 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
99962@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
99963 }
99964 }
99965
99966+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99967+ if ((sk->sk_state == TCP_LAST_ACK) &&
99968+ (grsec_lastack_retries > 0) &&
99969+ (grsec_lastack_retries < retry_until))
99970+ retry_until = grsec_lastack_retries;
99971+#endif
99972+
99973 if (retransmits_timed_out(sk, retry_until,
99974 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
99975 /* Has it gone just too far? */
99976diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
99977index 77bd16f..5f7174a 100644
99978--- a/net/ipv4/udp.c
99979+++ b/net/ipv4/udp.c
99980@@ -87,6 +87,7 @@
99981 #include <linux/types.h>
99982 #include <linux/fcntl.h>
99983 #include <linux/module.h>
99984+#include <linux/security.h>
99985 #include <linux/socket.h>
99986 #include <linux/sockios.h>
99987 #include <linux/igmp.h>
99988@@ -113,6 +114,10 @@
99989 #include <net/busy_poll.h>
99990 #include "udp_impl.h"
99991
99992+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99993+extern int grsec_enable_blackhole;
99994+#endif
99995+
99996 struct udp_table udp_table __read_mostly;
99997 EXPORT_SYMBOL(udp_table);
99998
99999@@ -615,6 +620,9 @@ found:
100000 return s;
100001 }
100002
100003+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
100004+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
100005+
100006 /*
100007 * This routine is called by the ICMP module when it gets some
100008 * sort of error condition. If err < 0 then the socket should
100009@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100010 dport = usin->sin_port;
100011 if (dport == 0)
100012 return -EINVAL;
100013+
100014+ err = gr_search_udp_sendmsg(sk, usin);
100015+ if (err)
100016+ return err;
100017 } else {
100018 if (sk->sk_state != TCP_ESTABLISHED)
100019 return -EDESTADDRREQ;
100020+
100021+ err = gr_search_udp_sendmsg(sk, NULL);
100022+ if (err)
100023+ return err;
100024+
100025 daddr = inet->inet_daddr;
100026 dport = inet->inet_dport;
100027 /* Open fast path for connected socket.
100028@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
100029 IS_UDPLITE(sk));
100030 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100031 IS_UDPLITE(sk));
100032- atomic_inc(&sk->sk_drops);
100033+ atomic_inc_unchecked(&sk->sk_drops);
100034 __skb_unlink(skb, rcvq);
100035 __skb_queue_tail(&list_kill, skb);
100036 }
100037@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100038 int is_udplite = IS_UDPLITE(sk);
100039 bool slow;
100040
100041+ /*
100042+ * Check any passed addresses
100043+ */
100044+ if (addr_len)
100045+ *addr_len = sizeof(*sin);
100046+
100047 if (flags & MSG_ERRQUEUE)
100048 return ip_recv_error(sk, msg, len, addr_len);
100049
100050@@ -1243,6 +1266,10 @@ try_again:
100051 if (!skb)
100052 goto out;
100053
100054+ err = gr_search_udp_recvmsg(sk, skb);
100055+ if (err)
100056+ goto out_free;
100057+
100058 ulen = skb->len - sizeof(struct udphdr);
100059 copied = len;
100060 if (copied > ulen)
100061@@ -1276,7 +1303,7 @@ try_again:
100062 if (unlikely(err)) {
100063 trace_kfree_skb(skb, udp_recvmsg);
100064 if (!peeked) {
100065- atomic_inc(&sk->sk_drops);
100066+ atomic_inc_unchecked(&sk->sk_drops);
100067 UDP_INC_STATS_USER(sock_net(sk),
100068 UDP_MIB_INERRORS, is_udplite);
100069 }
100070@@ -1295,7 +1322,6 @@ try_again:
100071 sin->sin_port = udp_hdr(skb)->source;
100072 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100073 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100074- *addr_len = sizeof(*sin);
100075 }
100076 if (inet->cmsg_flags)
100077 ip_cmsg_recv(msg, skb);
100078@@ -1566,7 +1592,7 @@ csum_error:
100079 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100080 drop:
100081 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100082- atomic_inc(&sk->sk_drops);
100083+ atomic_inc_unchecked(&sk->sk_drops);
100084 kfree_skb(skb);
100085 return -1;
100086 }
100087@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100088 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100089
100090 if (!skb1) {
100091- atomic_inc(&sk->sk_drops);
100092+ atomic_inc_unchecked(&sk->sk_drops);
100093 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100094 IS_UDPLITE(sk));
100095 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100096@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100097 goto csum_error;
100098
100099 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100100+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100101+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100102+#endif
100103 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
100104
100105 /*
100106@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
100107 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100108 0, sock_i_ino(sp),
100109 atomic_read(&sp->sk_refcnt), sp,
100110- atomic_read(&sp->sk_drops));
100111+ atomic_read_unchecked(&sp->sk_drops));
100112 }
100113
100114 int udp4_seq_show(struct seq_file *seq, void *v)
100115diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
100116index e1a6393..f634ce5 100644
100117--- a/net/ipv4/xfrm4_policy.c
100118+++ b/net/ipv4/xfrm4_policy.c
100119@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
100120 fl4->flowi4_tos = iph->tos;
100121 }
100122
100123-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
100124+static int xfrm4_garbage_collect(struct dst_ops *ops)
100125 {
100126 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
100127
100128- xfrm4_policy_afinfo.garbage_collect(net);
100129+ xfrm_garbage_collect_deferred(net);
100130 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
100131 }
100132
100133@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
100134
100135 static int __net_init xfrm4_net_init(struct net *net)
100136 {
100137- struct ctl_table *table;
100138+ ctl_table_no_const *table = NULL;
100139 struct ctl_table_header *hdr;
100140
100141- table = xfrm4_policy_table;
100142 if (!net_eq(net, &init_net)) {
100143- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100144+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100145 if (!table)
100146 goto err_alloc;
100147
100148 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
100149- }
100150-
100151- hdr = register_net_sysctl(net, "net/ipv4", table);
100152+ hdr = register_net_sysctl(net, "net/ipv4", table);
100153+ } else
100154+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
100155 if (!hdr)
100156 goto err_reg;
100157
100158@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100159 return 0;
100160
100161 err_reg:
100162- if (!net_eq(net, &init_net))
100163- kfree(table);
100164+ kfree(table);
100165 err_alloc:
100166 return -ENOMEM;
100167 }
100168diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100169index 6c7fa08..285086c 100644
100170--- a/net/ipv6/addrconf.c
100171+++ b/net/ipv6/addrconf.c
100172@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100173 idx = 0;
100174 head = &net->dev_index_head[h];
100175 rcu_read_lock();
100176- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100177+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100178 net->dev_base_seq;
100179 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100180 if (idx < s_idx)
100181@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100182 p.iph.ihl = 5;
100183 p.iph.protocol = IPPROTO_IPV6;
100184 p.iph.ttl = 64;
100185- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100186+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100187
100188 if (ops->ndo_do_ioctl) {
100189 mm_segment_t oldfs = get_fs();
100190@@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100191 s_ip_idx = ip_idx = cb->args[2];
100192
100193 rcu_read_lock();
100194- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100195+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100196 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100197 idx = 0;
100198 head = &net->dev_index_head[h];
100199@@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100200 dst_free(&ifp->rt->dst);
100201 break;
100202 }
100203- atomic_inc(&net->ipv6.dev_addr_genid);
100204+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100205 rt_genid_bump_ipv6(net);
100206 }
100207
100208@@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100209 int *valp = ctl->data;
100210 int val = *valp;
100211 loff_t pos = *ppos;
100212- struct ctl_table lctl;
100213+ ctl_table_no_const lctl;
100214 int ret;
100215
100216 /*
100217@@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100218 int *valp = ctl->data;
100219 int val = *valp;
100220 loff_t pos = *ppos;
100221- struct ctl_table lctl;
100222+ ctl_table_no_const lctl;
100223 int ret;
100224
100225 /*
100226diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100227index d935889..2f64330 100644
100228--- a/net/ipv6/af_inet6.c
100229+++ b/net/ipv6/af_inet6.c
100230@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100231 net->ipv6.sysctl.bindv6only = 0;
100232 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100233 net->ipv6.sysctl.flowlabel_consistency = 1;
100234- atomic_set(&net->ipv6.rt_genid, 0);
100235+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100236
100237 err = ipv6_init_mibs(net);
100238 if (err)
100239diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100240index c3bf2d2..1f00573 100644
100241--- a/net/ipv6/datagram.c
100242+++ b/net/ipv6/datagram.c
100243@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100244 0,
100245 sock_i_ino(sp),
100246 atomic_read(&sp->sk_refcnt), sp,
100247- atomic_read(&sp->sk_drops));
100248+ atomic_read_unchecked(&sp->sk_drops));
100249 }
100250diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100251index 7b32652..0bc348b 100644
100252--- a/net/ipv6/icmp.c
100253+++ b/net/ipv6/icmp.c
100254@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100255
100256 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100257 {
100258- struct ctl_table *table;
100259+ ctl_table_no_const *table;
100260
100261 table = kmemdup(ipv6_icmp_table_template,
100262 sizeof(ipv6_icmp_table_template),
100263diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100264index f3ffb43..1172ba7 100644
100265--- a/net/ipv6/ip6_gre.c
100266+++ b/net/ipv6/ip6_gre.c
100267@@ -71,7 +71,7 @@ struct ip6gre_net {
100268 struct net_device *fb_tunnel_dev;
100269 };
100270
100271-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100272+static struct rtnl_link_ops ip6gre_link_ops;
100273 static int ip6gre_tunnel_init(struct net_device *dev);
100274 static void ip6gre_tunnel_setup(struct net_device *dev);
100275 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100276@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100277 }
100278
100279
100280-static struct inet6_protocol ip6gre_protocol __read_mostly = {
100281+static struct inet6_protocol ip6gre_protocol = {
100282 .handler = ip6gre_rcv,
100283 .err_handler = ip6gre_err,
100284 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100285@@ -1634,7 +1634,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100286 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100287 };
100288
100289-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100290+static struct rtnl_link_ops ip6gre_link_ops = {
100291 .kind = "ip6gre",
100292 .maxtype = IFLA_GRE_MAX,
100293 .policy = ip6gre_policy,
100294@@ -1647,7 +1647,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100295 .fill_info = ip6gre_fill_info,
100296 };
100297
100298-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100299+static struct rtnl_link_ops ip6gre_tap_ops = {
100300 .kind = "ip6gretap",
100301 .maxtype = IFLA_GRE_MAX,
100302 .policy = ip6gre_policy,
100303diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100304index 5db8d31..4a72c26 100644
100305--- a/net/ipv6/ip6_tunnel.c
100306+++ b/net/ipv6/ip6_tunnel.c
100307@@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100308
100309 static int ip6_tnl_dev_init(struct net_device *dev);
100310 static void ip6_tnl_dev_setup(struct net_device *dev);
100311-static struct rtnl_link_ops ip6_link_ops __read_mostly;
100312+static struct rtnl_link_ops ip6_link_ops;
100313
100314 static int ip6_tnl_net_id __read_mostly;
100315 struct ip6_tnl_net {
100316@@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100317 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100318 };
100319
100320-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100321+static struct rtnl_link_ops ip6_link_ops = {
100322 .kind = "ip6tnl",
100323 .maxtype = IFLA_IPTUN_MAX,
100324 .policy = ip6_tnl_policy,
100325diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100326index 2d19272..3a46322 100644
100327--- a/net/ipv6/ip6_vti.c
100328+++ b/net/ipv6/ip6_vti.c
100329@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100330
100331 static int vti6_dev_init(struct net_device *dev);
100332 static void vti6_dev_setup(struct net_device *dev);
100333-static struct rtnl_link_ops vti6_link_ops __read_mostly;
100334+static struct rtnl_link_ops vti6_link_ops;
100335
100336 static int vti6_net_id __read_mostly;
100337 struct vti6_net {
100338@@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100339 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100340 };
100341
100342-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100343+static struct rtnl_link_ops vti6_link_ops = {
100344 .kind = "vti6",
100345 .maxtype = IFLA_VTI_MAX,
100346 .policy = vti6_policy,
100347diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100348index 0a00f44..bec42b2 100644
100349--- a/net/ipv6/ipv6_sockglue.c
100350+++ b/net/ipv6/ipv6_sockglue.c
100351@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100352 if (sk->sk_type != SOCK_STREAM)
100353 return -ENOPROTOOPT;
100354
100355- msg.msg_control = optval;
100356+ msg.msg_control = (void __force_kernel *)optval;
100357 msg.msg_controllen = len;
100358 msg.msg_flags = flags;
100359
100360diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100361index 710238f..0fd1816 100644
100362--- a/net/ipv6/netfilter/ip6_tables.c
100363+++ b/net/ipv6/netfilter/ip6_tables.c
100364@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100365 #endif
100366
100367 static int get_info(struct net *net, void __user *user,
100368- const int *len, int compat)
100369+ int len, int compat)
100370 {
100371 char name[XT_TABLE_MAXNAMELEN];
100372 struct xt_table *t;
100373 int ret;
100374
100375- if (*len != sizeof(struct ip6t_getinfo)) {
100376- duprintf("length %u != %zu\n", *len,
100377+ if (len != sizeof(struct ip6t_getinfo)) {
100378+ duprintf("length %u != %zu\n", len,
100379 sizeof(struct ip6t_getinfo));
100380 return -EINVAL;
100381 }
100382@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100383 info.size = private->size;
100384 strcpy(info.name, name);
100385
100386- if (copy_to_user(user, &info, *len) != 0)
100387+ if (copy_to_user(user, &info, len) != 0)
100388 ret = -EFAULT;
100389 else
100390 ret = 0;
100391@@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100392
100393 switch (cmd) {
100394 case IP6T_SO_GET_INFO:
100395- ret = get_info(sock_net(sk), user, len, 1);
100396+ ret = get_info(sock_net(sk), user, *len, 1);
100397 break;
100398 case IP6T_SO_GET_ENTRIES:
100399 ret = compat_get_entries(sock_net(sk), user, len);
100400@@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100401
100402 switch (cmd) {
100403 case IP6T_SO_GET_INFO:
100404- ret = get_info(sock_net(sk), user, len, 0);
100405+ ret = get_info(sock_net(sk), user, *len, 0);
100406 break;
100407
100408 case IP6T_SO_GET_ENTRIES:
100409diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100410index 767ab8d..c5ec70a 100644
100411--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100412+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100413@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100414
100415 static int nf_ct_frag6_sysctl_register(struct net *net)
100416 {
100417- struct ctl_table *table;
100418+ ctl_table_no_const *table = NULL;
100419 struct ctl_table_header *hdr;
100420
100421- table = nf_ct_frag6_sysctl_table;
100422 if (!net_eq(net, &init_net)) {
100423- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100424+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100425 GFP_KERNEL);
100426 if (table == NULL)
100427 goto err_alloc;
100428@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100429 table[0].data = &net->nf_frag.frags.timeout;
100430 table[1].data = &net->nf_frag.frags.low_thresh;
100431 table[2].data = &net->nf_frag.frags.high_thresh;
100432- }
100433-
100434- hdr = register_net_sysctl(net, "net/netfilter", table);
100435+ hdr = register_net_sysctl(net, "net/netfilter", table);
100436+ } else
100437+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100438 if (hdr == NULL)
100439 goto err_reg;
100440
100441@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100442 return 0;
100443
100444 err_reg:
100445- if (!net_eq(net, &init_net))
100446- kfree(table);
100447+ kfree(table);
100448 err_alloc:
100449 return -ENOMEM;
100450 }
100451diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100452index 827f795..7e28e82 100644
100453--- a/net/ipv6/output_core.c
100454+++ b/net/ipv6/output_core.c
100455@@ -9,8 +9,8 @@
100456
100457 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100458 {
100459- static atomic_t ipv6_fragmentation_id;
100460- int old, new;
100461+ static atomic_unchecked_t ipv6_fragmentation_id;
100462+ int id;
100463
100464 #if IS_ENABLED(CONFIG_IPV6)
100465 if (rt && !(rt->dst.flags & DST_NOPEER)) {
100466@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100467 }
100468 }
100469 #endif
100470- do {
100471- old = atomic_read(&ipv6_fragmentation_id);
100472- new = old + 1;
100473- if (!new)
100474- new = 1;
100475- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
100476- fhdr->identification = htonl(new);
100477+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100478+ if (!id)
100479+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100480+ fhdr->identification = htonl(id);
100481 }
100482 EXPORT_SYMBOL(ipv6_select_ident);
100483
100484diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100485index bda7429..469b26b 100644
100486--- a/net/ipv6/ping.c
100487+++ b/net/ipv6/ping.c
100488@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100489 };
100490 #endif
100491
100492+static struct pingv6_ops real_pingv6_ops = {
100493+ .ipv6_recv_error = ipv6_recv_error,
100494+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100495+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100496+ .icmpv6_err_convert = icmpv6_err_convert,
100497+ .ipv6_icmp_error = ipv6_icmp_error,
100498+ .ipv6_chk_addr = ipv6_chk_addr,
100499+};
100500+
100501+static struct pingv6_ops dummy_pingv6_ops = {
100502+ .ipv6_recv_error = dummy_ipv6_recv_error,
100503+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100504+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100505+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
100506+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
100507+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
100508+};
100509+
100510 int __init pingv6_init(void)
100511 {
100512 #ifdef CONFIG_PROC_FS
100513@@ -253,13 +271,7 @@ int __init pingv6_init(void)
100514 if (ret)
100515 return ret;
100516 #endif
100517- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100518- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100519- pingv6_ops.ip6_datagram_recv_specific_ctl =
100520- ip6_datagram_recv_specific_ctl;
100521- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100522- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100523- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100524+ pingv6_ops = &real_pingv6_ops;
100525 return inet6_register_protosw(&pingv6_protosw);
100526 }
100527
100528@@ -268,14 +280,9 @@ int __init pingv6_init(void)
100529 */
100530 void pingv6_exit(void)
100531 {
100532- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100533- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100534- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100535- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100536- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100537- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100538 #ifdef CONFIG_PROC_FS
100539 unregister_pernet_subsys(&ping_v6_net_ops);
100540 #endif
100541+ pingv6_ops = &dummy_pingv6_ops;
100542 inet6_unregister_protosw(&pingv6_protosw);
100543 }
100544diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100545index 091d066..139d410 100644
100546--- a/net/ipv6/proc.c
100547+++ b/net/ipv6/proc.c
100548@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100549 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100550 goto proc_snmp6_fail;
100551
100552- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100553+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100554 if (!net->mib.proc_net_devsnmp6)
100555 goto proc_dev_snmp6_fail;
100556 return 0;
100557diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100558index 1f29996..46fe0c7 100644
100559--- a/net/ipv6/raw.c
100560+++ b/net/ipv6/raw.c
100561@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100562 {
100563 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100564 skb_checksum_complete(skb)) {
100565- atomic_inc(&sk->sk_drops);
100566+ atomic_inc_unchecked(&sk->sk_drops);
100567 kfree_skb(skb);
100568 return NET_RX_DROP;
100569 }
100570@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100571 struct raw6_sock *rp = raw6_sk(sk);
100572
100573 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100574- atomic_inc(&sk->sk_drops);
100575+ atomic_inc_unchecked(&sk->sk_drops);
100576 kfree_skb(skb);
100577 return NET_RX_DROP;
100578 }
100579@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100580
100581 if (inet->hdrincl) {
100582 if (skb_checksum_complete(skb)) {
100583- atomic_inc(&sk->sk_drops);
100584+ atomic_inc_unchecked(&sk->sk_drops);
100585 kfree_skb(skb);
100586 return NET_RX_DROP;
100587 }
100588@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100589 if (flags & MSG_OOB)
100590 return -EOPNOTSUPP;
100591
100592+ if (addr_len)
100593+ *addr_len=sizeof(*sin6);
100594+
100595 if (flags & MSG_ERRQUEUE)
100596 return ipv6_recv_error(sk, msg, len, addr_len);
100597
100598@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100599 sin6->sin6_flowinfo = 0;
100600 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100601 IP6CB(skb)->iif);
100602- *addr_len = sizeof(*sin6);
100603 }
100604
100605 sock_recv_ts_and_drops(msg, sk, skb);
100606@@ -610,7 +612,7 @@ out:
100607 return err;
100608 }
100609
100610-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100611+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100612 struct flowi6 *fl6, struct dst_entry **dstp,
100613 unsigned int flags)
100614 {
100615@@ -922,12 +924,15 @@ do_confirm:
100616 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100617 char __user *optval, int optlen)
100618 {
100619+ struct icmp6_filter filter;
100620+
100621 switch (optname) {
100622 case ICMPV6_FILTER:
100623 if (optlen > sizeof(struct icmp6_filter))
100624 optlen = sizeof(struct icmp6_filter);
100625- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100626+ if (copy_from_user(&filter, optval, optlen))
100627 return -EFAULT;
100628+ raw6_sk(sk)->filter = filter;
100629 return 0;
100630 default:
100631 return -ENOPROTOOPT;
100632@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100633 char __user *optval, int __user *optlen)
100634 {
100635 int len;
100636+ struct icmp6_filter filter;
100637
100638 switch (optname) {
100639 case ICMPV6_FILTER:
100640@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100641 len = sizeof(struct icmp6_filter);
100642 if (put_user(len, optlen))
100643 return -EFAULT;
100644- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100645+ filter = raw6_sk(sk)->filter;
100646+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
100647 return -EFAULT;
100648 return 0;
100649 default:
100650diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100651index cc85a9b..526a133 100644
100652--- a/net/ipv6/reassembly.c
100653+++ b/net/ipv6/reassembly.c
100654@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100655
100656 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100657 {
100658- struct ctl_table *table;
100659+ ctl_table_no_const *table = NULL;
100660 struct ctl_table_header *hdr;
100661
100662- table = ip6_frags_ns_ctl_table;
100663 if (!net_eq(net, &init_net)) {
100664- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100665+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100666 if (table == NULL)
100667 goto err_alloc;
100668
100669@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100670 /* Don't export sysctls to unprivileged users */
100671 if (net->user_ns != &init_user_ns)
100672 table[0].procname = NULL;
100673- }
100674+ hdr = register_net_sysctl(net, "net/ipv6", table);
100675+ } else
100676+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
100677
100678- hdr = register_net_sysctl(net, "net/ipv6", table);
100679 if (hdr == NULL)
100680 goto err_reg;
100681
100682@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100683 return 0;
100684
100685 err_reg:
100686- if (!net_eq(net, &init_net))
100687- kfree(table);
100688+ kfree(table);
100689 err_alloc:
100690 return -ENOMEM;
100691 }
100692diff --git a/net/ipv6/route.c b/net/ipv6/route.c
100693index fba54a4..73e374e 100644
100694--- a/net/ipv6/route.c
100695+++ b/net/ipv6/route.c
100696@@ -2972,7 +2972,7 @@ struct ctl_table ipv6_route_table_template[] = {
100697
100698 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100699 {
100700- struct ctl_table *table;
100701+ ctl_table_no_const *table;
100702
100703 table = kmemdup(ipv6_route_table_template,
100704 sizeof(ipv6_route_table_template),
100705diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100706index b4d74c8..b4f3fbe 100644
100707--- a/net/ipv6/sit.c
100708+++ b/net/ipv6/sit.c
100709@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100710 static void ipip6_dev_free(struct net_device *dev);
100711 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100712 __be32 *v4dst);
100713-static struct rtnl_link_ops sit_link_ops __read_mostly;
100714+static struct rtnl_link_ops sit_link_ops;
100715
100716 static int sit_net_id __read_mostly;
100717 struct sit_net {
100718@@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100719 unregister_netdevice_queue(dev, head);
100720 }
100721
100722-static struct rtnl_link_ops sit_link_ops __read_mostly = {
100723+static struct rtnl_link_ops sit_link_ops = {
100724 .kind = "sit",
100725 .maxtype = IFLA_IPTUN_MAX,
100726 .policy = ipip6_policy,
100727diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100728index 7f405a1..eabef92 100644
100729--- a/net/ipv6/sysctl_net_ipv6.c
100730+++ b/net/ipv6/sysctl_net_ipv6.c
100731@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100732
100733 static int __net_init ipv6_sysctl_net_init(struct net *net)
100734 {
100735- struct ctl_table *ipv6_table;
100736+ ctl_table_no_const *ipv6_table;
100737 struct ctl_table *ipv6_route_table;
100738 struct ctl_table *ipv6_icmp_table;
100739 int err;
100740diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100741index 889079b..a04512c 100644
100742--- a/net/ipv6/tcp_ipv6.c
100743+++ b/net/ipv6/tcp_ipv6.c
100744@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100745 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100746 }
100747
100748+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100749+extern int grsec_enable_blackhole;
100750+#endif
100751+
100752 static void tcp_v6_hash(struct sock *sk)
100753 {
100754 if (sk->sk_state != TCP_CLOSE) {
100755@@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100756 return 0;
100757
100758 reset:
100759+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100760+ if (!grsec_enable_blackhole)
100761+#endif
100762 tcp_v6_send_reset(sk, skb);
100763 discard:
100764 if (opt_skb)
100765@@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100766 TCP_SKB_CB(skb)->sacked = 0;
100767
100768 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100769- if (!sk)
100770+ if (!sk) {
100771+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100772+ ret = 1;
100773+#endif
100774 goto no_tcp_socket;
100775+ }
100776
100777 process:
100778- if (sk->sk_state == TCP_TIME_WAIT)
100779+ if (sk->sk_state == TCP_TIME_WAIT) {
100780+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100781+ ret = 2;
100782+#endif
100783 goto do_time_wait;
100784+ }
100785
100786 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
100787 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100788@@ -1553,6 +1568,10 @@ csum_error:
100789 bad_packet:
100790 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100791 } else {
100792+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100793+ if (!grsec_enable_blackhole || (ret == 1 &&
100794+ (skb->dev->flags & IFF_LOOPBACK)))
100795+#endif
100796 tcp_v6_send_reset(NULL, skb);
100797 }
100798
100799diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
100800index 1e586d9..384a9c9 100644
100801--- a/net/ipv6/udp.c
100802+++ b/net/ipv6/udp.c
100803@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
100804 udp_ipv6_hash_secret + net_hash_mix(net));
100805 }
100806
100807+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100808+extern int grsec_enable_blackhole;
100809+#endif
100810+
100811 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100812 {
100813 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100814@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100815 int is_udp4;
100816 bool slow;
100817
100818+ if (addr_len)
100819+ *addr_len = sizeof(struct sockaddr_in6);
100820+
100821 if (flags & MSG_ERRQUEUE)
100822 return ipv6_recv_error(sk, msg, len, addr_len);
100823
100824@@ -435,7 +442,7 @@ try_again:
100825 if (unlikely(err)) {
100826 trace_kfree_skb(skb, udpv6_recvmsg);
100827 if (!peeked) {
100828- atomic_inc(&sk->sk_drops);
100829+ atomic_inc_unchecked(&sk->sk_drops);
100830 if (is_udp4)
100831 UDP_INC_STATS_USER(sock_net(sk),
100832 UDP_MIB_INERRORS,
100833@@ -475,7 +482,7 @@ try_again:
100834 ipv6_iface_scope_id(&sin6->sin6_addr,
100835 IP6CB(skb)->iif);
100836 }
100837- *addr_len = sizeof(*sin6);
100838+
100839 }
100840
100841 if (np->rxopt.all)
100842@@ -690,7 +697,7 @@ csum_error:
100843 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100844 drop:
100845 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100846- atomic_inc(&sk->sk_drops);
100847+ atomic_inc_unchecked(&sk->sk_drops);
100848 kfree_skb(skb);
100849 return -1;
100850 }
100851@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100852 if (likely(skb1 == NULL))
100853 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100854 if (!skb1) {
100855- atomic_inc(&sk->sk_drops);
100856+ atomic_inc_unchecked(&sk->sk_drops);
100857 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100858 IS_UDPLITE(sk));
100859 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100860@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100861 goto csum_error;
100862
100863 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100864+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100865+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100866+#endif
100867 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100868
100869 kfree_skb(skb);
100870diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100871index 5f8e128..865d38e 100644
100872--- a/net/ipv6/xfrm6_policy.c
100873+++ b/net/ipv6/xfrm6_policy.c
100874@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100875 }
100876 }
100877
100878-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100879+static int xfrm6_garbage_collect(struct dst_ops *ops)
100880 {
100881 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100882
100883- xfrm6_policy_afinfo.garbage_collect(net);
100884+ xfrm_garbage_collect_deferred(net);
100885 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
100886 }
100887
100888@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
100889
100890 static int __net_init xfrm6_net_init(struct net *net)
100891 {
100892- struct ctl_table *table;
100893+ ctl_table_no_const *table = NULL;
100894 struct ctl_table_header *hdr;
100895
100896- table = xfrm6_policy_table;
100897 if (!net_eq(net, &init_net)) {
100898- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100899+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100900 if (!table)
100901 goto err_alloc;
100902
100903 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
100904- }
100905+ hdr = register_net_sysctl(net, "net/ipv6", table);
100906+ } else
100907+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
100908
100909- hdr = register_net_sysctl(net, "net/ipv6", table);
100910 if (!hdr)
100911 goto err_reg;
100912
100913@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
100914 return 0;
100915
100916 err_reg:
100917- if (!net_eq(net, &init_net))
100918- kfree(table);
100919+ kfree(table);
100920 err_alloc:
100921 return -ENOMEM;
100922 }
100923diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
100924index e15c16a..7cf07aa 100644
100925--- a/net/ipx/ipx_proc.c
100926+++ b/net/ipx/ipx_proc.c
100927@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
100928 struct proc_dir_entry *p;
100929 int rc = -ENOMEM;
100930
100931- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
100932+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
100933
100934 if (!ipx_proc_dir)
100935 goto out;
100936diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
100937index 2ba8b97..6d33010 100644
100938--- a/net/irda/ircomm/ircomm_tty.c
100939+++ b/net/irda/ircomm/ircomm_tty.c
100940@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100941 add_wait_queue(&port->open_wait, &wait);
100942
100943 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
100944- __FILE__, __LINE__, tty->driver->name, port->count);
100945+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100946
100947 spin_lock_irqsave(&port->lock, flags);
100948 if (!tty_hung_up_p(filp))
100949- port->count--;
100950+ atomic_dec(&port->count);
100951 port->blocked_open++;
100952 spin_unlock_irqrestore(&port->lock, flags);
100953
100954@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100955 }
100956
100957 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
100958- __FILE__, __LINE__, tty->driver->name, port->count);
100959+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100960
100961 schedule();
100962 }
100963@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100964
100965 spin_lock_irqsave(&port->lock, flags);
100966 if (!tty_hung_up_p(filp))
100967- port->count++;
100968+ atomic_inc(&port->count);
100969 port->blocked_open--;
100970 spin_unlock_irqrestore(&port->lock, flags);
100971
100972 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
100973- __FILE__, __LINE__, tty->driver->name, port->count);
100974+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100975
100976 if (!retval)
100977 port->flags |= ASYNC_NORMAL_ACTIVE;
100978@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
100979
100980 /* ++ is not atomic, so this should be protected - Jean II */
100981 spin_lock_irqsave(&self->port.lock, flags);
100982- self->port.count++;
100983+ atomic_inc(&self->port.count);
100984 spin_unlock_irqrestore(&self->port.lock, flags);
100985 tty_port_tty_set(&self->port, tty);
100986
100987 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
100988- self->line, self->port.count);
100989+ self->line, atomic_read(&self->port.count));
100990
100991 /* Not really used by us, but lets do it anyway */
100992 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
100993@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
100994 tty_kref_put(port->tty);
100995 }
100996 port->tty = NULL;
100997- port->count = 0;
100998+ atomic_set(&port->count, 0);
100999 spin_unlock_irqrestore(&port->lock, flags);
101000
101001 wake_up_interruptible(&port->open_wait);
101002@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
101003 seq_putc(m, '\n');
101004
101005 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
101006- seq_printf(m, "Open count: %d\n", self->port.count);
101007+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
101008 seq_printf(m, "Max data size: %d\n", self->max_data_size);
101009 seq_printf(m, "Max header size: %d\n", self->max_header_size);
101010
101011diff --git a/net/irda/irproc.c b/net/irda/irproc.c
101012index b9ac598..f88cc56 100644
101013--- a/net/irda/irproc.c
101014+++ b/net/irda/irproc.c
101015@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
101016 {
101017 int i;
101018
101019- proc_irda = proc_mkdir("irda", init_net.proc_net);
101020+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
101021 if (proc_irda == NULL)
101022 return;
101023
101024diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
101025index c4b7218..3e83259 100644
101026--- a/net/iucv/af_iucv.c
101027+++ b/net/iucv/af_iucv.c
101028@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
101029
101030 write_lock_bh(&iucv_sk_list.lock);
101031
101032- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
101033+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101034 while (__iucv_get_sock_by_name(name)) {
101035 sprintf(name, "%08x",
101036- atomic_inc_return(&iucv_sk_list.autobind_name));
101037+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101038 }
101039
101040 write_unlock_bh(&iucv_sk_list.lock);
101041diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
101042index cd5b8ec..f205e6b 100644
101043--- a/net/iucv/iucv.c
101044+++ b/net/iucv/iucv.c
101045@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
101046 return NOTIFY_OK;
101047 }
101048
101049-static struct notifier_block __refdata iucv_cpu_notifier = {
101050+static struct notifier_block iucv_cpu_notifier = {
101051 .notifier_call = iucv_cpu_notify,
101052 };
101053
101054diff --git a/net/key/af_key.c b/net/key/af_key.c
101055index 7932697..a13d158 100644
101056--- a/net/key/af_key.c
101057+++ b/net/key/af_key.c
101058@@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
101059 static u32 get_acqseq(void)
101060 {
101061 u32 res;
101062- static atomic_t acqseq;
101063+ static atomic_unchecked_t acqseq;
101064
101065 do {
101066- res = atomic_inc_return(&acqseq);
101067+ res = atomic_inc_return_unchecked(&acqseq);
101068 } while (!res);
101069 return res;
101070 }
101071diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
101072index 0b44d85..1a7f88b 100644
101073--- a/net/l2tp/l2tp_ip.c
101074+++ b/net/l2tp/l2tp_ip.c
101075@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101076 if (flags & MSG_OOB)
101077 goto out;
101078
101079+ if (addr_len)
101080+ *addr_len = sizeof(*sin);
101081+
101082 skb = skb_recv_datagram(sk, flags, noblock, &err);
101083 if (!skb)
101084 goto out;
101085@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101086 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
101087 sin->sin_port = 0;
101088 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
101089- *addr_len = sizeof(*sin);
101090 }
101091 if (inet->cmsg_flags)
101092 ip_cmsg_recv(msg, skb);
101093diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
101094index 1a3c7e0..80f8b0c 100644
101095--- a/net/llc/llc_proc.c
101096+++ b/net/llc/llc_proc.c
101097@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
101098 int rc = -ENOMEM;
101099 struct proc_dir_entry *p;
101100
101101- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
101102+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
101103 if (!llc_proc_dir)
101104 goto out;
101105
101106diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
101107index 453e974..b3a43a5 100644
101108--- a/net/mac80211/cfg.c
101109+++ b/net/mac80211/cfg.c
101110@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
101111 ret = ieee80211_vif_use_channel(sdata, chandef,
101112 IEEE80211_CHANCTX_EXCLUSIVE);
101113 }
101114- } else if (local->open_count == local->monitors) {
101115+ } else if (local_read(&local->open_count) == local->monitors) {
101116 local->_oper_chandef = *chandef;
101117 ieee80211_hw_config(local, 0);
101118 }
101119@@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
101120 else
101121 local->probe_req_reg--;
101122
101123- if (!local->open_count)
101124+ if (!local_read(&local->open_count))
101125 break;
101126
101127 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
101128@@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
101129 if (chanctx_conf) {
101130 *chandef = chanctx_conf->def;
101131 ret = 0;
101132- } else if (local->open_count > 0 &&
101133- local->open_count == local->monitors &&
101134+ } else if (local_read(&local->open_count) > 0 &&
101135+ local_read(&local->open_count) == local->monitors &&
101136 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
101137 if (local->use_chanctx)
101138 *chandef = local->monitor_chandef;
101139diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
101140index 6bd4984..d8805c5 100644
101141--- a/net/mac80211/ieee80211_i.h
101142+++ b/net/mac80211/ieee80211_i.h
101143@@ -28,6 +28,7 @@
101144 #include <net/ieee80211_radiotap.h>
101145 #include <net/cfg80211.h>
101146 #include <net/mac80211.h>
101147+#include <asm/local.h>
101148 #include "key.h"
101149 #include "sta_info.h"
101150 #include "debug.h"
101151@@ -994,7 +995,7 @@ struct ieee80211_local {
101152 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
101153 spinlock_t queue_stop_reason_lock;
101154
101155- int open_count;
101156+ local_t open_count;
101157 int monitors, cooked_mntrs;
101158 /* number of interfaces with corresponding FIF_ flags */
101159 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101160diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101161index ce1c443..6cd39e1 100644
101162--- a/net/mac80211/iface.c
101163+++ b/net/mac80211/iface.c
101164@@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101165 break;
101166 }
101167
101168- if (local->open_count == 0) {
101169+ if (local_read(&local->open_count) == 0) {
101170 res = drv_start(local);
101171 if (res)
101172 goto err_del_bss;
101173@@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101174 res = drv_add_interface(local, sdata);
101175 if (res)
101176 goto err_stop;
101177- } else if (local->monitors == 0 && local->open_count == 0) {
101178+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101179 res = ieee80211_add_virtual_monitor(local);
101180 if (res)
101181 goto err_stop;
101182@@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101183 atomic_inc(&local->iff_promiscs);
101184
101185 if (coming_up)
101186- local->open_count++;
101187+ local_inc(&local->open_count);
101188
101189 if (hw_reconf_flags)
101190 ieee80211_hw_config(local, hw_reconf_flags);
101191@@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101192 err_del_interface:
101193 drv_remove_interface(local, sdata);
101194 err_stop:
101195- if (!local->open_count)
101196+ if (!local_read(&local->open_count))
101197 drv_stop(local);
101198 err_del_bss:
101199 sdata->bss = NULL;
101200@@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101201 }
101202
101203 if (going_down)
101204- local->open_count--;
101205+ local_dec(&local->open_count);
101206
101207 switch (sdata->vif.type) {
101208 case NL80211_IFTYPE_AP_VLAN:
101209@@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101210 }
101211 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101212
101213- if (local->open_count == 0)
101214+ if (local_read(&local->open_count) == 0)
101215 ieee80211_clear_tx_pending(local);
101216
101217 /*
101218@@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101219
101220 ieee80211_recalc_ps(local, -1);
101221
101222- if (local->open_count == 0) {
101223+ if (local_read(&local->open_count) == 0) {
101224 ieee80211_stop_device(local);
101225
101226 /* no reconfiguring after stop! */
101227@@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101228 ieee80211_configure_filter(local);
101229 ieee80211_hw_config(local, hw_reconf_flags);
101230
101231- if (local->monitors == local->open_count)
101232+ if (local->monitors == local_read(&local->open_count))
101233 ieee80211_add_virtual_monitor(local);
101234 }
101235
101236diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101237index c7a7a86..a74f57b 100644
101238--- a/net/mac80211/main.c
101239+++ b/net/mac80211/main.c
101240@@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101241 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101242 IEEE80211_CONF_CHANGE_POWER);
101243
101244- if (changed && local->open_count) {
101245+ if (changed && local_read(&local->open_count)) {
101246 ret = drv_config(local, changed);
101247 /*
101248 * Goal:
101249diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101250index d478b88..8c8d157 100644
101251--- a/net/mac80211/pm.c
101252+++ b/net/mac80211/pm.c
101253@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101254 struct ieee80211_sub_if_data *sdata;
101255 struct sta_info *sta;
101256
101257- if (!local->open_count)
101258+ if (!local_read(&local->open_count))
101259 goto suspend;
101260
101261 ieee80211_scan_cancel(local);
101262@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101263 cancel_work_sync(&local->dynamic_ps_enable_work);
101264 del_timer_sync(&local->dynamic_ps_timer);
101265
101266- local->wowlan = wowlan && local->open_count;
101267+ local->wowlan = wowlan && local_read(&local->open_count);
101268 if (local->wowlan) {
101269 int err = drv_suspend(local, wowlan);
101270 if (err < 0) {
101271@@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101272 WARN_ON(!list_empty(&local->chanctx_list));
101273
101274 /* stop hardware - this must stop RX */
101275- if (local->open_count)
101276+ if (local_read(&local->open_count))
101277 ieee80211_stop_device(local);
101278
101279 suspend:
101280diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101281index 22b223f..ab70070 100644
101282--- a/net/mac80211/rate.c
101283+++ b/net/mac80211/rate.c
101284@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101285
101286 ASSERT_RTNL();
101287
101288- if (local->open_count)
101289+ if (local_read(&local->open_count))
101290 return -EBUSY;
101291
101292 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101293diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101294index 6ff1346..936ca9a 100644
101295--- a/net/mac80211/rc80211_pid_debugfs.c
101296+++ b/net/mac80211/rc80211_pid_debugfs.c
101297@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101298
101299 spin_unlock_irqrestore(&events->lock, status);
101300
101301- if (copy_to_user(buf, pb, p))
101302+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101303 return -EFAULT;
101304
101305 return p;
101306diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101307index b8700d4..89086d5 100644
101308--- a/net/mac80211/util.c
101309+++ b/net/mac80211/util.c
101310@@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101311 }
101312 #endif
101313 /* everything else happens only if HW was up & running */
101314- if (!local->open_count)
101315+ if (!local_read(&local->open_count))
101316 goto wake_up;
101317
101318 /*
101319@@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101320 local->in_reconfig = false;
101321 barrier();
101322
101323- if (local->monitors == local->open_count && local->monitors > 0)
101324+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101325 ieee80211_add_virtual_monitor(local);
101326
101327 /*
101328diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101329index e9410d1..77b6378 100644
101330--- a/net/netfilter/Kconfig
101331+++ b/net/netfilter/Kconfig
101332@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101333
101334 To compile it as a module, choose M here. If unsure, say N.
101335
101336+config NETFILTER_XT_MATCH_GRADM
101337+ tristate '"gradm" match support'
101338+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101339+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101340+ ---help---
101341+ The gradm match allows to match on grsecurity RBAC being enabled.
101342+ It is useful when iptables rules are applied early on bootup to
101343+ prevent connections to the machine (except from a trusted host)
101344+ while the RBAC system is disabled.
101345+
101346 config NETFILTER_XT_MATCH_HASHLIMIT
101347 tristate '"hashlimit" match support'
101348 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101349diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101350index bffdad7..f9317d1 100644
101351--- a/net/netfilter/Makefile
101352+++ b/net/netfilter/Makefile
101353@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101354 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101355 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101356 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101357+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101358 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101359 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101360 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101361diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101362index de770ec..3fc49d2 100644
101363--- a/net/netfilter/ipset/ip_set_core.c
101364+++ b/net/netfilter/ipset/ip_set_core.c
101365@@ -1922,7 +1922,7 @@ done:
101366 return ret;
101367 }
101368
101369-static struct nf_sockopt_ops so_set __read_mostly = {
101370+static struct nf_sockopt_ops so_set = {
101371 .pf = PF_INET,
101372 .get_optmin = SO_IP_SET,
101373 .get_optmax = SO_IP_SET + 1,
101374diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101375index a8eb0a8..86f2de4 100644
101376--- a/net/netfilter/ipvs/ip_vs_conn.c
101377+++ b/net/netfilter/ipvs/ip_vs_conn.c
101378@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101379 /* Increase the refcnt counter of the dest */
101380 ip_vs_dest_hold(dest);
101381
101382- conn_flags = atomic_read(&dest->conn_flags);
101383+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
101384 if (cp->protocol != IPPROTO_UDP)
101385 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101386 flags = cp->flags;
101387@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101388
101389 cp->control = NULL;
101390 atomic_set(&cp->n_control, 0);
101391- atomic_set(&cp->in_pkts, 0);
101392+ atomic_set_unchecked(&cp->in_pkts, 0);
101393
101394 cp->packet_xmit = NULL;
101395 cp->app = NULL;
101396@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101397
101398 /* Don't drop the entry if its number of incoming packets is not
101399 located in [0, 8] */
101400- i = atomic_read(&cp->in_pkts);
101401+ i = atomic_read_unchecked(&cp->in_pkts);
101402 if (i > 8 || i < 0) return 0;
101403
101404 if (!todrop_rate[i]) return 0;
101405diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101406index 4f26ee4..6a9d7c3 100644
101407--- a/net/netfilter/ipvs/ip_vs_core.c
101408+++ b/net/netfilter/ipvs/ip_vs_core.c
101409@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101410 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101411 /* do not touch skb anymore */
101412
101413- atomic_inc(&cp->in_pkts);
101414+ atomic_inc_unchecked(&cp->in_pkts);
101415 ip_vs_conn_put(cp);
101416 return ret;
101417 }
101418@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101419 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101420 pkts = sysctl_sync_threshold(ipvs);
101421 else
101422- pkts = atomic_add_return(1, &cp->in_pkts);
101423+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101424
101425 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101426 ip_vs_sync_conn(net, cp, pkts);
101427diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101428index 35be035..50f8834 100644
101429--- a/net/netfilter/ipvs/ip_vs_ctl.c
101430+++ b/net/netfilter/ipvs/ip_vs_ctl.c
101431@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101432 */
101433 ip_vs_rs_hash(ipvs, dest);
101434 }
101435- atomic_set(&dest->conn_flags, conn_flags);
101436+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
101437
101438 /* bind the service */
101439 old_svc = rcu_dereference_protected(dest->svc, 1);
101440@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101441 * align with netns init in ip_vs_control_net_init()
101442 */
101443
101444-static struct ctl_table vs_vars[] = {
101445+static ctl_table_no_const vs_vars[] __read_only = {
101446 {
101447 .procname = "amemthresh",
101448 .maxlen = sizeof(int),
101449@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101450 " %-7s %-6d %-10d %-10d\n",
101451 &dest->addr.in6,
101452 ntohs(dest->port),
101453- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101454+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101455 atomic_read(&dest->weight),
101456 atomic_read(&dest->activeconns),
101457 atomic_read(&dest->inactconns));
101458@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101459 "%-7s %-6d %-10d %-10d\n",
101460 ntohl(dest->addr.ip),
101461 ntohs(dest->port),
101462- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101463+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101464 atomic_read(&dest->weight),
101465 atomic_read(&dest->activeconns),
101466 atomic_read(&dest->inactconns));
101467@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101468
101469 entry.addr = dest->addr.ip;
101470 entry.port = dest->port;
101471- entry.conn_flags = atomic_read(&dest->conn_flags);
101472+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101473 entry.weight = atomic_read(&dest->weight);
101474 entry.u_threshold = dest->u_threshold;
101475 entry.l_threshold = dest->l_threshold;
101476@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101477 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101478 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101479 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101480- (atomic_read(&dest->conn_flags) &
101481+ (atomic_read_unchecked(&dest->conn_flags) &
101482 IP_VS_CONN_F_FWD_MASK)) ||
101483 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101484 atomic_read(&dest->weight)) ||
101485@@ -3580,7 +3580,7 @@ out:
101486 }
101487
101488
101489-static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
101490+static const struct genl_ops ip_vs_genl_ops[] = {
101491 {
101492 .cmd = IPVS_CMD_NEW_SERVICE,
101493 .flags = GENL_ADMIN_PERM,
101494@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101495 {
101496 int idx;
101497 struct netns_ipvs *ipvs = net_ipvs(net);
101498- struct ctl_table *tbl;
101499+ ctl_table_no_const *tbl;
101500
101501 atomic_set(&ipvs->dropentry, 0);
101502 spin_lock_init(&ipvs->dropentry_lock);
101503diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101504index ca056a3..9cf01ef 100644
101505--- a/net/netfilter/ipvs/ip_vs_lblc.c
101506+++ b/net/netfilter/ipvs/ip_vs_lblc.c
101507@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101508 * IPVS LBLC sysctl table
101509 */
101510 #ifdef CONFIG_SYSCTL
101511-static struct ctl_table vs_vars_table[] = {
101512+static ctl_table_no_const vs_vars_table[] __read_only = {
101513 {
101514 .procname = "lblc_expiration",
101515 .data = NULL,
101516diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101517index 3f21a2f..a112e85 100644
101518--- a/net/netfilter/ipvs/ip_vs_lblcr.c
101519+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101520@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101521 * IPVS LBLCR sysctl table
101522 */
101523
101524-static struct ctl_table vs_vars_table[] = {
101525+static ctl_table_no_const vs_vars_table[] __read_only = {
101526 {
101527 .procname = "lblcr_expiration",
101528 .data = NULL,
101529diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101530index db80126..ef7110e 100644
101531--- a/net/netfilter/ipvs/ip_vs_sync.c
101532+++ b/net/netfilter/ipvs/ip_vs_sync.c
101533@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101534 cp = cp->control;
101535 if (cp) {
101536 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101537- pkts = atomic_add_return(1, &cp->in_pkts);
101538+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101539 else
101540 pkts = sysctl_sync_threshold(ipvs);
101541 ip_vs_sync_conn(net, cp->control, pkts);
101542@@ -771,7 +771,7 @@ control:
101543 if (!cp)
101544 return;
101545 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101546- pkts = atomic_add_return(1, &cp->in_pkts);
101547+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101548 else
101549 pkts = sysctl_sync_threshold(ipvs);
101550 goto sloop;
101551@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101552
101553 if (opt)
101554 memcpy(&cp->in_seq, opt, sizeof(*opt));
101555- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101556+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101557 cp->state = state;
101558 cp->old_state = cp->state;
101559 /*
101560diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101561index c47444e..b0961c6 100644
101562--- a/net/netfilter/ipvs/ip_vs_xmit.c
101563+++ b/net/netfilter/ipvs/ip_vs_xmit.c
101564@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
101565 else
101566 rc = NF_ACCEPT;
101567 /* do not touch skb anymore */
101568- atomic_inc(&cp->in_pkts);
101569+ atomic_inc_unchecked(&cp->in_pkts);
101570 goto out;
101571 }
101572
101573@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
101574 else
101575 rc = NF_ACCEPT;
101576 /* do not touch skb anymore */
101577- atomic_inc(&cp->in_pkts);
101578+ atomic_inc_unchecked(&cp->in_pkts);
101579 goto out;
101580 }
101581
101582diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
101583index a4b5e2a..13b1de3 100644
101584--- a/net/netfilter/nf_conntrack_acct.c
101585+++ b/net/netfilter/nf_conntrack_acct.c
101586@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101587 #ifdef CONFIG_SYSCTL
101588 static int nf_conntrack_acct_init_sysctl(struct net *net)
101589 {
101590- struct ctl_table *table;
101591+ ctl_table_no_const *table;
101592
101593 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
101594 GFP_KERNEL);
101595diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
101596index 356bef5..99932cb 100644
101597--- a/net/netfilter/nf_conntrack_core.c
101598+++ b/net/netfilter/nf_conntrack_core.c
101599@@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
101600 #define DYING_NULLS_VAL ((1<<30)+1)
101601 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
101602
101603+#ifdef CONFIG_GRKERNSEC_HIDESYM
101604+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
101605+#endif
101606+
101607 int nf_conntrack_init_net(struct net *net)
101608 {
101609 int ret;
101610@@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
101611 goto err_stat;
101612 }
101613
101614+#ifdef CONFIG_GRKERNSEC_HIDESYM
101615+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
101616+#else
101617 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
101618+#endif
101619 if (!net->ct.slabname) {
101620 ret = -ENOMEM;
101621 goto err_slabname;
101622diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
101623index 1df1761..ce8b88a 100644
101624--- a/net/netfilter/nf_conntrack_ecache.c
101625+++ b/net/netfilter/nf_conntrack_ecache.c
101626@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
101627 #ifdef CONFIG_SYSCTL
101628 static int nf_conntrack_event_init_sysctl(struct net *net)
101629 {
101630- struct ctl_table *table;
101631+ ctl_table_no_const *table;
101632
101633 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
101634 GFP_KERNEL);
101635diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
101636index 974a2a4..52cc6ff 100644
101637--- a/net/netfilter/nf_conntrack_helper.c
101638+++ b/net/netfilter/nf_conntrack_helper.c
101639@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
101640
101641 static int nf_conntrack_helper_init_sysctl(struct net *net)
101642 {
101643- struct ctl_table *table;
101644+ ctl_table_no_const *table;
101645
101646 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
101647 GFP_KERNEL);
101648diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
101649index b65d586..beec902 100644
101650--- a/net/netfilter/nf_conntrack_proto.c
101651+++ b/net/netfilter/nf_conntrack_proto.c
101652@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
101653
101654 static void
101655 nf_ct_unregister_sysctl(struct ctl_table_header **header,
101656- struct ctl_table **table,
101657+ ctl_table_no_const **table,
101658 unsigned int users)
101659 {
101660 if (users > 0)
101661diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
101662index f641751..d3c5b51 100644
101663--- a/net/netfilter/nf_conntrack_standalone.c
101664+++ b/net/netfilter/nf_conntrack_standalone.c
101665@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
101666
101667 static int nf_conntrack_standalone_init_sysctl(struct net *net)
101668 {
101669- struct ctl_table *table;
101670+ ctl_table_no_const *table;
101671
101672 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
101673 GFP_KERNEL);
101674diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
101675index 7a394df..bd91a8a 100644
101676--- a/net/netfilter/nf_conntrack_timestamp.c
101677+++ b/net/netfilter/nf_conntrack_timestamp.c
101678@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
101679 #ifdef CONFIG_SYSCTL
101680 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
101681 {
101682- struct ctl_table *table;
101683+ ctl_table_no_const *table;
101684
101685 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
101686 GFP_KERNEL);
101687diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
101688index 85296d4..8becdec 100644
101689--- a/net/netfilter/nf_log.c
101690+++ b/net/netfilter/nf_log.c
101691@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
101692
101693 #ifdef CONFIG_SYSCTL
101694 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
101695-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
101696+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
101697
101698 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101699 void __user *buffer, size_t *lenp, loff_t *ppos)
101700@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101701 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101702 mutex_unlock(&nf_log_mutex);
101703 } else {
101704+ ctl_table_no_const nf_log_table = *table;
101705+
101706 mutex_lock(&nf_log_mutex);
101707 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
101708 lockdep_is_held(&nf_log_mutex));
101709 if (!logger)
101710- table->data = "NONE";
101711+ nf_log_table.data = "NONE";
101712 else
101713- table->data = logger->name;
101714- r = proc_dostring(table, write, buffer, lenp, ppos);
101715+ nf_log_table.data = logger->name;
101716+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
101717 mutex_unlock(&nf_log_mutex);
101718 }
101719
101720diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
101721index f042ae5..30ea486 100644
101722--- a/net/netfilter/nf_sockopt.c
101723+++ b/net/netfilter/nf_sockopt.c
101724@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
101725 }
101726 }
101727
101728- list_add(&reg->list, &nf_sockopts);
101729+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
101730 out:
101731 mutex_unlock(&nf_sockopt_mutex);
101732 return ret;
101733@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
101734 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
101735 {
101736 mutex_lock(&nf_sockopt_mutex);
101737- list_del(&reg->list);
101738+ pax_list_del((struct list_head *)&reg->list);
101739 mutex_unlock(&nf_sockopt_mutex);
101740 }
101741 EXPORT_SYMBOL(nf_unregister_sockopt);
101742diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
101743index adce01e..8d52d50 100644
101744--- a/net/netfilter/nf_tables_api.c
101745+++ b/net/netfilter/nf_tables_api.c
101746@@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
101747 #ifdef CONFIG_MODULES
101748 if (autoload) {
101749 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
101750- request_module("nft-chain-%u-%*.s", afi->family,
101751- nla_len(nla)-1, (const char *)nla_data(nla));
101752+ request_module("nft-chain-%u-%.*s", afi->family,
101753+ nla_len(nla), (const char *)nla_data(nla));
101754 nfnl_lock(NFNL_SUBSYS_NFTABLES);
101755 type = __nf_tables_chain_type_lookup(afi->family, nla);
101756 if (type != NULL)
101757@@ -1934,7 +1934,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
101758
101759 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
101760 [NFTA_SET_TABLE] = { .type = NLA_STRING },
101761- [NFTA_SET_NAME] = { .type = NLA_STRING },
101762+ [NFTA_SET_NAME] = { .type = NLA_STRING,
101763+ .len = IFNAMSIZ - 1 },
101764 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
101765 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
101766 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
101767diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
101768index a155d19..726b0f2 100644
101769--- a/net/netfilter/nfnetlink_log.c
101770+++ b/net/netfilter/nfnetlink_log.c
101771@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
101772 struct nfnl_log_net {
101773 spinlock_t instances_lock;
101774 struct hlist_head instance_table[INSTANCE_BUCKETS];
101775- atomic_t global_seq;
101776+ atomic_unchecked_t global_seq;
101777 };
101778
101779 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
101780@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
101781 /* global sequence number */
101782 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
101783 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
101784- htonl(atomic_inc_return(&log->global_seq))))
101785+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
101786 goto nla_put_failure;
101787
101788 if (data_len) {
101789diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
101790index 82cb823..5685dd5 100644
101791--- a/net/netfilter/nft_compat.c
101792+++ b/net/netfilter/nft_compat.c
101793@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
101794 /* We want to reuse existing compat_to_user */
101795 old_fs = get_fs();
101796 set_fs(KERNEL_DS);
101797- t->compat_to_user(out, in);
101798+ t->compat_to_user((void __force_user *)out, in);
101799 set_fs(old_fs);
101800 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
101801 kfree(out);
101802@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
101803 /* We want to reuse existing compat_to_user */
101804 old_fs = get_fs();
101805 set_fs(KERNEL_DS);
101806- m->compat_to_user(out, in);
101807+ m->compat_to_user((void __force_user *)out, in);
101808 set_fs(old_fs);
101809 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101810 kfree(out);
101811diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101812new file mode 100644
101813index 0000000..c566332
101814--- /dev/null
101815+++ b/net/netfilter/xt_gradm.c
101816@@ -0,0 +1,51 @@
101817+/*
101818+ * gradm match for netfilter
101819