]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.14.8-201406191347.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.14.8-201406191347.patch
CommitLineData
f9d9c54f
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 ef1d59b..7030652 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@@ -1111,7 +1188,7 @@ distclean: mrproper
461 @find $(srctree) $(RCS_FIND_IGNORE) \
462 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
463 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
464- -o -name '.*.rej' \
465+ -o -name '.*.rej' -o -name '*.so' \
466 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
467 -type f -print | xargs rm -f
468
469@@ -1273,6 +1350,8 @@ PHONY += $(module-dirs) modules
470 $(module-dirs): crmodverdir $(objtree)/Module.symvers
471 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
472
473+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
474+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
475 modules: $(module-dirs)
476 @$(kecho) ' Building modules, stage 2.';
477 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
478@@ -1412,17 +1491,21 @@ else
479 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
480 endif
481
482-%.s: %.c prepare scripts FORCE
483+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
484+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
485+%.s: %.c gcc-plugins prepare scripts FORCE
486 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
487 %.i: %.c prepare scripts FORCE
488 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
489-%.o: %.c prepare scripts FORCE
490+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
491+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
492+%.o: %.c gcc-plugins prepare scripts FORCE
493 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
494 %.lst: %.c prepare scripts FORCE
495 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
496-%.s: %.S prepare scripts FORCE
497+%.s: %.S gcc-plugins prepare scripts FORCE
498 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
499-%.o: %.S prepare scripts FORCE
500+%.o: %.S gcc-plugins prepare scripts FORCE
501 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
502 %.symtypes: %.c prepare scripts FORCE
503 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
504@@ -1432,11 +1515,15 @@ endif
505 $(cmd_crmodverdir)
506 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
507 $(build)=$(build-dir)
508-%/: prepare scripts FORCE
509+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
510+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
511+%/: gcc-plugins prepare scripts FORCE
512 $(cmd_crmodverdir)
513 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
514 $(build)=$(build-dir)
515-%.ko: prepare scripts FORCE
516+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
517+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
518+%.ko: gcc-plugins prepare scripts FORCE
519 $(cmd_crmodverdir)
520 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
521 $(build)=$(build-dir) $(@:.ko=.o)
522diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
523index 78b03ef..da28a51 100644
524--- a/arch/alpha/include/asm/atomic.h
525+++ b/arch/alpha/include/asm/atomic.h
526@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
527 #define atomic_dec(v) atomic_sub(1,(v))
528 #define atomic64_dec(v) atomic64_sub(1,(v))
529
530+#define atomic64_read_unchecked(v) atomic64_read(v)
531+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
532+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
533+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
534+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
535+#define atomic64_inc_unchecked(v) atomic64_inc(v)
536+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
537+#define atomic64_dec_unchecked(v) atomic64_dec(v)
538+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
539+
540 #define smp_mb__before_atomic_dec() smp_mb()
541 #define smp_mb__after_atomic_dec() smp_mb()
542 #define smp_mb__before_atomic_inc() smp_mb()
543diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
544index ad368a9..fbe0f25 100644
545--- a/arch/alpha/include/asm/cache.h
546+++ b/arch/alpha/include/asm/cache.h
547@@ -4,19 +4,19 @@
548 #ifndef __ARCH_ALPHA_CACHE_H
549 #define __ARCH_ALPHA_CACHE_H
550
551+#include <linux/const.h>
552
553 /* Bytes per L1 (data) cache line. */
554 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
555-# define L1_CACHE_BYTES 64
556 # define L1_CACHE_SHIFT 6
557 #else
558 /* Both EV4 and EV5 are write-through, read-allocate,
559 direct-mapped, physical.
560 */
561-# define L1_CACHE_BYTES 32
562 # define L1_CACHE_SHIFT 5
563 #endif
564
565+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
566 #define SMP_CACHE_BYTES L1_CACHE_BYTES
567
568 #endif
569diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
570index 968d999..d36b2df 100644
571--- a/arch/alpha/include/asm/elf.h
572+++ b/arch/alpha/include/asm/elf.h
573@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
574
575 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
576
577+#ifdef CONFIG_PAX_ASLR
578+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
579+
580+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
581+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
582+#endif
583+
584 /* $0 is set by ld.so to a pointer to a function which might be
585 registered using atexit. This provides a mean for the dynamic
586 linker to call DT_FINI functions for shared libraries that have
587diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
588index aab14a0..b4fa3e7 100644
589--- a/arch/alpha/include/asm/pgalloc.h
590+++ b/arch/alpha/include/asm/pgalloc.h
591@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
592 pgd_set(pgd, pmd);
593 }
594
595+static inline void
596+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
597+{
598+ pgd_populate(mm, pgd, pmd);
599+}
600+
601 extern pgd_t *pgd_alloc(struct mm_struct *mm);
602
603 static inline void
604diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
605index d8f9b7e..f6222fa 100644
606--- a/arch/alpha/include/asm/pgtable.h
607+++ b/arch/alpha/include/asm/pgtable.h
608@@ -102,6 +102,17 @@ struct vm_area_struct;
609 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
610 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
611 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
612+
613+#ifdef CONFIG_PAX_PAGEEXEC
614+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
615+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
616+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
617+#else
618+# define PAGE_SHARED_NOEXEC PAGE_SHARED
619+# define PAGE_COPY_NOEXEC PAGE_COPY
620+# define PAGE_READONLY_NOEXEC PAGE_READONLY
621+#endif
622+
623 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
624
625 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
626diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
627index 2fd00b7..cfd5069 100644
628--- a/arch/alpha/kernel/module.c
629+++ b/arch/alpha/kernel/module.c
630@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
631
632 /* The small sections were sorted to the end of the segment.
633 The following should definitely cover them. */
634- gp = (u64)me->module_core + me->core_size - 0x8000;
635+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
636 got = sechdrs[me->arch.gotsecindex].sh_addr;
637
638 for (i = 0; i < n; i++) {
639diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
640index 1402fcc..0b1abd2 100644
641--- a/arch/alpha/kernel/osf_sys.c
642+++ b/arch/alpha/kernel/osf_sys.c
643@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
644 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
645
646 static unsigned long
647-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
648- unsigned long limit)
649+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
650+ unsigned long limit, unsigned long flags)
651 {
652 struct vm_unmapped_area_info info;
653+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
654
655 info.flags = 0;
656 info.length = len;
657@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
658 info.high_limit = limit;
659 info.align_mask = 0;
660 info.align_offset = 0;
661+ info.threadstack_offset = offset;
662 return vm_unmapped_area(&info);
663 }
664
665@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
666 merely specific addresses, but regions of memory -- perhaps
667 this feature should be incorporated into all ports? */
668
669+#ifdef CONFIG_PAX_RANDMMAP
670+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
671+#endif
672+
673 if (addr) {
674- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
675+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
676 if (addr != (unsigned long) -ENOMEM)
677 return addr;
678 }
679
680 /* Next, try allocating at TASK_UNMAPPED_BASE. */
681- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
682- len, limit);
683+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
684+
685 if (addr != (unsigned long) -ENOMEM)
686 return addr;
687
688 /* Finally, try allocating in low memory. */
689- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
690+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
691
692 return addr;
693 }
694diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
695index 98838a0..b304fb4 100644
696--- a/arch/alpha/mm/fault.c
697+++ b/arch/alpha/mm/fault.c
698@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
699 __reload_thread(pcb);
700 }
701
702+#ifdef CONFIG_PAX_PAGEEXEC
703+/*
704+ * PaX: decide what to do with offenders (regs->pc = fault address)
705+ *
706+ * returns 1 when task should be killed
707+ * 2 when patched PLT trampoline was detected
708+ * 3 when unpatched PLT trampoline was detected
709+ */
710+static int pax_handle_fetch_fault(struct pt_regs *regs)
711+{
712+
713+#ifdef CONFIG_PAX_EMUPLT
714+ int err;
715+
716+ do { /* PaX: patched PLT emulation #1 */
717+ unsigned int ldah, ldq, jmp;
718+
719+ err = get_user(ldah, (unsigned int *)regs->pc);
720+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
721+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
722+
723+ if (err)
724+ break;
725+
726+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
727+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
728+ jmp == 0x6BFB0000U)
729+ {
730+ unsigned long r27, addr;
731+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
732+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
733+
734+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
735+ err = get_user(r27, (unsigned long *)addr);
736+ if (err)
737+ break;
738+
739+ regs->r27 = r27;
740+ regs->pc = r27;
741+ return 2;
742+ }
743+ } while (0);
744+
745+ do { /* PaX: patched PLT emulation #2 */
746+ unsigned int ldah, lda, br;
747+
748+ err = get_user(ldah, (unsigned int *)regs->pc);
749+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
750+ err |= get_user(br, (unsigned int *)(regs->pc+8));
751+
752+ if (err)
753+ break;
754+
755+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
756+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
757+ (br & 0xFFE00000U) == 0xC3E00000U)
758+ {
759+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
760+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
761+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
762+
763+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
764+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
765+ return 2;
766+ }
767+ } while (0);
768+
769+ do { /* PaX: unpatched PLT emulation */
770+ unsigned int br;
771+
772+ err = get_user(br, (unsigned int *)regs->pc);
773+
774+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
775+ unsigned int br2, ldq, nop, jmp;
776+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
777+
778+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
779+ err = get_user(br2, (unsigned int *)addr);
780+ err |= get_user(ldq, (unsigned int *)(addr+4));
781+ err |= get_user(nop, (unsigned int *)(addr+8));
782+ err |= get_user(jmp, (unsigned int *)(addr+12));
783+ err |= get_user(resolver, (unsigned long *)(addr+16));
784+
785+ if (err)
786+ break;
787+
788+ if (br2 == 0xC3600000U &&
789+ ldq == 0xA77B000CU &&
790+ nop == 0x47FF041FU &&
791+ jmp == 0x6B7B0000U)
792+ {
793+ regs->r28 = regs->pc+4;
794+ regs->r27 = addr+16;
795+ regs->pc = resolver;
796+ return 3;
797+ }
798+ }
799+ } while (0);
800+#endif
801+
802+ return 1;
803+}
804+
805+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
806+{
807+ unsigned long i;
808+
809+ printk(KERN_ERR "PAX: bytes at PC: ");
810+ for (i = 0; i < 5; i++) {
811+ unsigned int c;
812+ if (get_user(c, (unsigned int *)pc+i))
813+ printk(KERN_CONT "???????? ");
814+ else
815+ printk(KERN_CONT "%08x ", c);
816+ }
817+ printk("\n");
818+}
819+#endif
820
821 /*
822 * This routine handles page faults. It determines the address,
823@@ -133,8 +251,29 @@ retry:
824 good_area:
825 si_code = SEGV_ACCERR;
826 if (cause < 0) {
827- if (!(vma->vm_flags & VM_EXEC))
828+ if (!(vma->vm_flags & VM_EXEC)) {
829+
830+#ifdef CONFIG_PAX_PAGEEXEC
831+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
832+ goto bad_area;
833+
834+ up_read(&mm->mmap_sem);
835+ switch (pax_handle_fetch_fault(regs)) {
836+
837+#ifdef CONFIG_PAX_EMUPLT
838+ case 2:
839+ case 3:
840+ return;
841+#endif
842+
843+ }
844+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
845+ do_group_exit(SIGKILL);
846+#else
847 goto bad_area;
848+#endif
849+
850+ }
851 } else if (!cause) {
852 /* Allow reads even for write-only mappings */
853 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
854diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
855index 44298ad..29a20c0 100644
856--- a/arch/arm/Kconfig
857+++ b/arch/arm/Kconfig
858@@ -1862,7 +1862,7 @@ config ALIGNMENT_TRAP
859
860 config UACCESS_WITH_MEMCPY
861 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
862- depends on MMU
863+ depends on MMU && !PAX_MEMORY_UDEREF
864 default y if CPU_FEROCEON
865 help
866 Implement faster copy_to_user and clear_user methods for CPU
867@@ -2125,6 +2125,7 @@ config XIP_PHYS_ADDR
868 config KEXEC
869 bool "Kexec system call (EXPERIMENTAL)"
870 depends on (!SMP || PM_SLEEP_SMP)
871+ depends on !GRKERNSEC_KMEM
872 help
873 kexec is a system call that implements the ability to shutdown your
874 current kernel, and to start another kernel. It is like a reboot
875diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
876index 62d2cb5..09d45e3 100644
877--- a/arch/arm/include/asm/atomic.h
878+++ b/arch/arm/include/asm/atomic.h
879@@ -18,17 +18,35 @@
880 #include <asm/barrier.h>
881 #include <asm/cmpxchg.h>
882
883+#ifdef CONFIG_GENERIC_ATOMIC64
884+#include <asm-generic/atomic64.h>
885+#endif
886+
887 #define ATOMIC_INIT(i) { (i) }
888
889 #ifdef __KERNEL__
890
891+#define _ASM_EXTABLE(from, to) \
892+" .pushsection __ex_table,\"a\"\n"\
893+" .align 3\n" \
894+" .long " #from ", " #to"\n" \
895+" .popsection"
896+
897 /*
898 * On ARM, ordinary assignment (str instruction) doesn't clear the local
899 * strex/ldrex monitor on some implementations. The reason we can use it for
900 * atomic_set() is the clrex or dummy strex done on every exception return.
901 */
902 #define atomic_read(v) (*(volatile int *)&(v)->counter)
903+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
904+{
905+ return v->counter;
906+}
907 #define atomic_set(v,i) (((v)->counter) = (i))
908+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
909+{
910+ v->counter = i;
911+}
912
913 #if __LINUX_ARM_ARCH__ >= 6
914
915@@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
916
917 prefetchw(&v->counter);
918 __asm__ __volatile__("@ atomic_add\n"
919+"1: ldrex %1, [%3]\n"
920+" adds %0, %1, %4\n"
921+
922+#ifdef CONFIG_PAX_REFCOUNT
923+" bvc 3f\n"
924+"2: bkpt 0xf103\n"
925+"3:\n"
926+#endif
927+
928+" strex %1, %0, [%3]\n"
929+" teq %1, #0\n"
930+" bne 1b"
931+
932+#ifdef CONFIG_PAX_REFCOUNT
933+"\n4:\n"
934+ _ASM_EXTABLE(2b, 4b)
935+#endif
936+
937+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
938+ : "r" (&v->counter), "Ir" (i)
939+ : "cc");
940+}
941+
942+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
943+{
944+ unsigned long tmp;
945+ int result;
946+
947+ prefetchw(&v->counter);
948+ __asm__ __volatile__("@ atomic_add_unchecked\n"
949 "1: ldrex %0, [%3]\n"
950 " add %0, %0, %4\n"
951 " strex %1, %0, [%3]\n"
952@@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
953 smp_mb();
954
955 __asm__ __volatile__("@ atomic_add_return\n"
956+"1: ldrex %1, [%3]\n"
957+" adds %0, %1, %4\n"
958+
959+#ifdef CONFIG_PAX_REFCOUNT
960+" bvc 3f\n"
961+" mov %0, %1\n"
962+"2: bkpt 0xf103\n"
963+"3:\n"
964+#endif
965+
966+" strex %1, %0, [%3]\n"
967+" teq %1, #0\n"
968+" bne 1b"
969+
970+#ifdef CONFIG_PAX_REFCOUNT
971+"\n4:\n"
972+ _ASM_EXTABLE(2b, 4b)
973+#endif
974+
975+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
976+ : "r" (&v->counter), "Ir" (i)
977+ : "cc");
978+
979+ smp_mb();
980+
981+ return result;
982+}
983+
984+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
985+{
986+ unsigned long tmp;
987+ int result;
988+
989+ smp_mb();
990+
991+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
992 "1: ldrex %0, [%3]\n"
993 " add %0, %0, %4\n"
994 " strex %1, %0, [%3]\n"
995@@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
996
997 prefetchw(&v->counter);
998 __asm__ __volatile__("@ atomic_sub\n"
999+"1: ldrex %1, [%3]\n"
1000+" subs %0, %1, %4\n"
1001+
1002+#ifdef CONFIG_PAX_REFCOUNT
1003+" bvc 3f\n"
1004+"2: bkpt 0xf103\n"
1005+"3:\n"
1006+#endif
1007+
1008+" strex %1, %0, [%3]\n"
1009+" teq %1, #0\n"
1010+" bne 1b"
1011+
1012+#ifdef CONFIG_PAX_REFCOUNT
1013+"\n4:\n"
1014+ _ASM_EXTABLE(2b, 4b)
1015+#endif
1016+
1017+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1018+ : "r" (&v->counter), "Ir" (i)
1019+ : "cc");
1020+}
1021+
1022+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1023+{
1024+ unsigned long tmp;
1025+ int result;
1026+
1027+ prefetchw(&v->counter);
1028+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1029 "1: ldrex %0, [%3]\n"
1030 " sub %0, %0, %4\n"
1031 " strex %1, %0, [%3]\n"
1032@@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1033 smp_mb();
1034
1035 __asm__ __volatile__("@ atomic_sub_return\n"
1036-"1: ldrex %0, [%3]\n"
1037-" sub %0, %0, %4\n"
1038+"1: ldrex %1, [%3]\n"
1039+" subs %0, %1, %4\n"
1040+
1041+#ifdef CONFIG_PAX_REFCOUNT
1042+" bvc 3f\n"
1043+" mov %0, %1\n"
1044+"2: bkpt 0xf103\n"
1045+"3:\n"
1046+#endif
1047+
1048 " strex %1, %0, [%3]\n"
1049 " teq %1, #0\n"
1050 " bne 1b"
1051+
1052+#ifdef CONFIG_PAX_REFCOUNT
1053+"\n4:\n"
1054+ _ASM_EXTABLE(2b, 4b)
1055+#endif
1056+
1057 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1058 : "r" (&v->counter), "Ir" (i)
1059 : "cc");
1060@@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1061 return oldval;
1062 }
1063
1064+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1065+{
1066+ unsigned long oldval, res;
1067+
1068+ smp_mb();
1069+
1070+ do {
1071+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1072+ "ldrex %1, [%3]\n"
1073+ "mov %0, #0\n"
1074+ "teq %1, %4\n"
1075+ "strexeq %0, %5, [%3]\n"
1076+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1077+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1078+ : "cc");
1079+ } while (res);
1080+
1081+ smp_mb();
1082+
1083+ return oldval;
1084+}
1085+
1086 #else /* ARM_ARCH_6 */
1087
1088 #ifdef CONFIG_SMP
1089@@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1090
1091 return val;
1092 }
1093+
1094+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1095+{
1096+ return atomic_add_return(i, v);
1097+}
1098+
1099 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1100+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1101+{
1102+ (void) atomic_add_return(i, v);
1103+}
1104
1105 static inline int atomic_sub_return(int i, atomic_t *v)
1106 {
1107@@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1108 return val;
1109 }
1110 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1111+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1112+{
1113+ (void) atomic_sub_return(i, v);
1114+}
1115
1116 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1117 {
1118@@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1119 return ret;
1120 }
1121
1122+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1123+{
1124+ return atomic_cmpxchg(v, old, new);
1125+}
1126+
1127 #endif /* __LINUX_ARM_ARCH__ */
1128
1129 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1130+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1131+{
1132+ return xchg(&v->counter, new);
1133+}
1134
1135 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1136 {
1137@@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1138 }
1139
1140 #define atomic_inc(v) atomic_add(1, v)
1141+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1142+{
1143+ atomic_add_unchecked(1, v);
1144+}
1145 #define atomic_dec(v) atomic_sub(1, v)
1146+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1147+{
1148+ atomic_sub_unchecked(1, v);
1149+}
1150
1151 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1152+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1153+{
1154+ return atomic_add_return_unchecked(1, v) == 0;
1155+}
1156 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1157 #define atomic_inc_return(v) (atomic_add_return(1, v))
1158+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1159+{
1160+ return atomic_add_return_unchecked(1, v);
1161+}
1162 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1163 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1164
1165@@ -221,6 +410,14 @@ typedef struct {
1166 long long counter;
1167 } atomic64_t;
1168
1169+#ifdef CONFIG_PAX_REFCOUNT
1170+typedef struct {
1171+ long long counter;
1172+} atomic64_unchecked_t;
1173+#else
1174+typedef atomic64_t atomic64_unchecked_t;
1175+#endif
1176+
1177 #define ATOMIC64_INIT(i) { (i) }
1178
1179 #ifdef CONFIG_ARM_LPAE
1180@@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1181 return result;
1182 }
1183
1184+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1185+{
1186+ long long result;
1187+
1188+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1189+" ldrd %0, %H0, [%1]"
1190+ : "=&r" (result)
1191+ : "r" (&v->counter), "Qo" (v->counter)
1192+ );
1193+
1194+ return result;
1195+}
1196+
1197 static inline void atomic64_set(atomic64_t *v, long long i)
1198 {
1199 __asm__ __volatile__("@ atomic64_set\n"
1200@@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1201 : "r" (&v->counter), "r" (i)
1202 );
1203 }
1204+
1205+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1206+{
1207+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1208+" strd %2, %H2, [%1]"
1209+ : "=Qo" (v->counter)
1210+ : "r" (&v->counter), "r" (i)
1211+ );
1212+}
1213 #else
1214 static inline long long atomic64_read(const atomic64_t *v)
1215 {
1216@@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1217 return result;
1218 }
1219
1220+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1221+{
1222+ long long result;
1223+
1224+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1225+" ldrexd %0, %H0, [%1]"
1226+ : "=&r" (result)
1227+ : "r" (&v->counter), "Qo" (v->counter)
1228+ );
1229+
1230+ return result;
1231+}
1232+
1233 static inline void atomic64_set(atomic64_t *v, long long i)
1234 {
1235 long long tmp;
1236@@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1237 : "r" (&v->counter), "r" (i)
1238 : "cc");
1239 }
1240+
1241+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1242+{
1243+ long long tmp;
1244+
1245+ prefetchw(&v->counter);
1246+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1247+"1: ldrexd %0, %H0, [%2]\n"
1248+" strexd %0, %3, %H3, [%2]\n"
1249+" teq %0, #0\n"
1250+" bne 1b"
1251+ : "=&r" (tmp), "=Qo" (v->counter)
1252+ : "r" (&v->counter), "r" (i)
1253+ : "cc");
1254+}
1255 #endif
1256
1257 static inline void atomic64_add(long long i, atomic64_t *v)
1258@@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1259 __asm__ __volatile__("@ atomic64_add\n"
1260 "1: ldrexd %0, %H0, [%3]\n"
1261 " adds %Q0, %Q0, %Q4\n"
1262+" adcs %R0, %R0, %R4\n"
1263+
1264+#ifdef CONFIG_PAX_REFCOUNT
1265+" bvc 3f\n"
1266+"2: bkpt 0xf103\n"
1267+"3:\n"
1268+#endif
1269+
1270+" strexd %1, %0, %H0, [%3]\n"
1271+" teq %1, #0\n"
1272+" bne 1b"
1273+
1274+#ifdef CONFIG_PAX_REFCOUNT
1275+"\n4:\n"
1276+ _ASM_EXTABLE(2b, 4b)
1277+#endif
1278+
1279+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1280+ : "r" (&v->counter), "r" (i)
1281+ : "cc");
1282+}
1283+
1284+static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1285+{
1286+ long long result;
1287+ unsigned long tmp;
1288+
1289+ prefetchw(&v->counter);
1290+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1291+"1: ldrexd %0, %H0, [%3]\n"
1292+" adds %Q0, %Q0, %Q4\n"
1293 " adc %R0, %R0, %R4\n"
1294 " strexd %1, %0, %H0, [%3]\n"
1295 " teq %1, #0\n"
1296@@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1297 __asm__ __volatile__("@ atomic64_add_return\n"
1298 "1: ldrexd %0, %H0, [%3]\n"
1299 " adds %Q0, %Q0, %Q4\n"
1300+" adcs %R0, %R0, %R4\n"
1301+
1302+#ifdef CONFIG_PAX_REFCOUNT
1303+" bvc 3f\n"
1304+" mov %0, %1\n"
1305+" mov %H0, %H1\n"
1306+"2: bkpt 0xf103\n"
1307+"3:\n"
1308+#endif
1309+
1310+" strexd %1, %0, %H0, [%3]\n"
1311+" teq %1, #0\n"
1312+" bne 1b"
1313+
1314+#ifdef CONFIG_PAX_REFCOUNT
1315+"\n4:\n"
1316+ _ASM_EXTABLE(2b, 4b)
1317+#endif
1318+
1319+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1320+ : "r" (&v->counter), "r" (i)
1321+ : "cc");
1322+
1323+ smp_mb();
1324+
1325+ return result;
1326+}
1327+
1328+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1329+{
1330+ long long result;
1331+ unsigned long tmp;
1332+
1333+ smp_mb();
1334+
1335+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1336+"1: ldrexd %0, %H0, [%3]\n"
1337+" adds %Q0, %Q0, %Q4\n"
1338 " adc %R0, %R0, %R4\n"
1339 " strexd %1, %0, %H0, [%3]\n"
1340 " teq %1, #0\n"
1341@@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1342 __asm__ __volatile__("@ atomic64_sub\n"
1343 "1: ldrexd %0, %H0, [%3]\n"
1344 " subs %Q0, %Q0, %Q4\n"
1345+" sbcs %R0, %R0, %R4\n"
1346+
1347+#ifdef CONFIG_PAX_REFCOUNT
1348+" bvc 3f\n"
1349+"2: bkpt 0xf103\n"
1350+"3:\n"
1351+#endif
1352+
1353+" strexd %1, %0, %H0, [%3]\n"
1354+" teq %1, #0\n"
1355+" bne 1b"
1356+
1357+#ifdef CONFIG_PAX_REFCOUNT
1358+"\n4:\n"
1359+ _ASM_EXTABLE(2b, 4b)
1360+#endif
1361+
1362+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1363+ : "r" (&v->counter), "r" (i)
1364+ : "cc");
1365+}
1366+
1367+static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1368+{
1369+ long long result;
1370+ unsigned long tmp;
1371+
1372+ prefetchw(&v->counter);
1373+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1374+"1: ldrexd %0, %H0, [%3]\n"
1375+" subs %Q0, %Q0, %Q4\n"
1376 " sbc %R0, %R0, %R4\n"
1377 " strexd %1, %0, %H0, [%3]\n"
1378 " teq %1, #0\n"
1379@@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1380 __asm__ __volatile__("@ atomic64_sub_return\n"
1381 "1: ldrexd %0, %H0, [%3]\n"
1382 " subs %Q0, %Q0, %Q4\n"
1383-" sbc %R0, %R0, %R4\n"
1384+" sbcs %R0, %R0, %R4\n"
1385+
1386+#ifdef CONFIG_PAX_REFCOUNT
1387+" bvc 3f\n"
1388+" mov %0, %1\n"
1389+" mov %H0, %H1\n"
1390+"2: bkpt 0xf103\n"
1391+"3:\n"
1392+#endif
1393+
1394 " strexd %1, %0, %H0, [%3]\n"
1395 " teq %1, #0\n"
1396 " bne 1b"
1397+
1398+#ifdef CONFIG_PAX_REFCOUNT
1399+"\n4:\n"
1400+ _ASM_EXTABLE(2b, 4b)
1401+#endif
1402+
1403 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1404 : "r" (&v->counter), "r" (i)
1405 : "cc");
1406
1407- smp_mb();
1408-
1409 return result;
1410 }
1411
1412@@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1413 return oldval;
1414 }
1415
1416+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1417+ long long new)
1418+{
1419+ long long oldval;
1420+ unsigned long res;
1421+
1422+ smp_mb();
1423+
1424+ do {
1425+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1426+ "ldrexd %1, %H1, [%3]\n"
1427+ "mov %0, #0\n"
1428+ "teq %1, %4\n"
1429+ "teqeq %H1, %H4\n"
1430+ "strexdeq %0, %5, %H5, [%3]"
1431+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1432+ : "r" (&ptr->counter), "r" (old), "r" (new)
1433+ : "cc");
1434+ } while (res);
1435+
1436+ smp_mb();
1437+
1438+ return oldval;
1439+}
1440+
1441 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 {
1443 long long result;
1444@@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1445 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1446 {
1447 long long result;
1448- unsigned long tmp;
1449+ u64 tmp;
1450
1451 smp_mb();
1452
1453 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1454-"1: ldrexd %0, %H0, [%3]\n"
1455-" subs %Q0, %Q0, #1\n"
1456-" sbc %R0, %R0, #0\n"
1457+"1: ldrexd %1, %H1, [%3]\n"
1458+" subs %Q0, %Q1, #1\n"
1459+" sbcs %R0, %R1, #0\n"
1460+
1461+#ifdef CONFIG_PAX_REFCOUNT
1462+" bvc 3f\n"
1463+" mov %Q0, %Q1\n"
1464+" mov %R0, %R1\n"
1465+"2: bkpt 0xf103\n"
1466+"3:\n"
1467+#endif
1468+
1469 " teq %R0, #0\n"
1470-" bmi 2f\n"
1471+" bmi 4f\n"
1472 " strexd %1, %0, %H0, [%3]\n"
1473 " teq %1, #0\n"
1474 " bne 1b\n"
1475-"2:"
1476+"4:\n"
1477+
1478+#ifdef CONFIG_PAX_REFCOUNT
1479+ _ASM_EXTABLE(2b, 4b)
1480+#endif
1481+
1482 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1483 : "r" (&v->counter)
1484 : "cc");
1485@@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1486 " teq %0, %5\n"
1487 " teqeq %H0, %H5\n"
1488 " moveq %1, #0\n"
1489-" beq 2f\n"
1490+" beq 4f\n"
1491 " adds %Q0, %Q0, %Q6\n"
1492-" adc %R0, %R0, %R6\n"
1493+" adcs %R0, %R0, %R6\n"
1494+
1495+#ifdef CONFIG_PAX_REFCOUNT
1496+" bvc 3f\n"
1497+"2: bkpt 0xf103\n"
1498+"3:\n"
1499+#endif
1500+
1501 " strexd %2, %0, %H0, [%4]\n"
1502 " teq %2, #0\n"
1503 " bne 1b\n"
1504-"2:"
1505+"4:\n"
1506+
1507+#ifdef CONFIG_PAX_REFCOUNT
1508+ _ASM_EXTABLE(2b, 4b)
1509+#endif
1510+
1511 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1512 : "r" (&v->counter), "r" (u), "r" (a)
1513 : "cc");
1514@@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1515
1516 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1517 #define atomic64_inc(v) atomic64_add(1LL, (v))
1518+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1519 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1520+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1521 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1522 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1523 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1524+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1525 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1526 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1527 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1528diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1529index 2f59f74..1594659 100644
1530--- a/arch/arm/include/asm/barrier.h
1531+++ b/arch/arm/include/asm/barrier.h
1532@@ -63,7 +63,7 @@
1533 do { \
1534 compiletime_assert_atomic_type(*p); \
1535 smp_mb(); \
1536- ACCESS_ONCE(*p) = (v); \
1537+ ACCESS_ONCE_RW(*p) = (v); \
1538 } while (0)
1539
1540 #define smp_load_acquire(p) \
1541diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1542index 75fe66b..ba3dee4 100644
1543--- a/arch/arm/include/asm/cache.h
1544+++ b/arch/arm/include/asm/cache.h
1545@@ -4,8 +4,10 @@
1546 #ifndef __ASMARM_CACHE_H
1547 #define __ASMARM_CACHE_H
1548
1549+#include <linux/const.h>
1550+
1551 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1552-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1553+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1554
1555 /*
1556 * Memory returned by kmalloc() may be used for DMA, so we must make
1557@@ -24,5 +26,6 @@
1558 #endif
1559
1560 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1561+#define __read_only __attribute__ ((__section__(".data..read_only")))
1562
1563 #endif
1564diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1565index 8b8b616..d973d24 100644
1566--- a/arch/arm/include/asm/cacheflush.h
1567+++ b/arch/arm/include/asm/cacheflush.h
1568@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1569 void (*dma_unmap_area)(const void *, size_t, int);
1570
1571 void (*dma_flush_range)(const void *, const void *);
1572-};
1573+} __no_const;
1574
1575 /*
1576 * Select the calling method
1577diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1578index 5233151..87a71fa 100644
1579--- a/arch/arm/include/asm/checksum.h
1580+++ b/arch/arm/include/asm/checksum.h
1581@@ -37,7 +37,19 @@ __wsum
1582 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1583
1584 __wsum
1585-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1586+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1587+
1588+static inline __wsum
1589+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1590+{
1591+ __wsum ret;
1592+ pax_open_userland();
1593+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1594+ pax_close_userland();
1595+ return ret;
1596+}
1597+
1598+
1599
1600 /*
1601 * Fold a partial checksum without adding pseudo headers
1602diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1603index df2fbba..63fe3e1 100644
1604--- a/arch/arm/include/asm/cmpxchg.h
1605+++ b/arch/arm/include/asm/cmpxchg.h
1606@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1607
1608 #define xchg(ptr,x) \
1609 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1610+#define xchg_unchecked(ptr,x) \
1611+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1612
1613 #include <asm-generic/cmpxchg-local.h>
1614
1615diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1616index 6ddbe44..b5e38b1 100644
1617--- a/arch/arm/include/asm/domain.h
1618+++ b/arch/arm/include/asm/domain.h
1619@@ -48,18 +48,37 @@
1620 * Domain types
1621 */
1622 #define DOMAIN_NOACCESS 0
1623-#define DOMAIN_CLIENT 1
1624 #ifdef CONFIG_CPU_USE_DOMAINS
1625+#define DOMAIN_USERCLIENT 1
1626+#define DOMAIN_KERNELCLIENT 1
1627 #define DOMAIN_MANAGER 3
1628+#define DOMAIN_VECTORS DOMAIN_USER
1629 #else
1630+
1631+#ifdef CONFIG_PAX_KERNEXEC
1632 #define DOMAIN_MANAGER 1
1633+#define DOMAIN_KERNEXEC 3
1634+#else
1635+#define DOMAIN_MANAGER 1
1636+#endif
1637+
1638+#ifdef CONFIG_PAX_MEMORY_UDEREF
1639+#define DOMAIN_USERCLIENT 0
1640+#define DOMAIN_UDEREF 1
1641+#define DOMAIN_VECTORS DOMAIN_KERNEL
1642+#else
1643+#define DOMAIN_USERCLIENT 1
1644+#define DOMAIN_VECTORS DOMAIN_USER
1645+#endif
1646+#define DOMAIN_KERNELCLIENT 1
1647+
1648 #endif
1649
1650 #define domain_val(dom,type) ((type) << (2*(dom)))
1651
1652 #ifndef __ASSEMBLY__
1653
1654-#ifdef CONFIG_CPU_USE_DOMAINS
1655+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1656 static inline void set_domain(unsigned val)
1657 {
1658 asm volatile(
1659@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1660 isb();
1661 }
1662
1663-#define modify_domain(dom,type) \
1664- do { \
1665- struct thread_info *thread = current_thread_info(); \
1666- unsigned int domain = thread->cpu_domain; \
1667- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1668- thread->cpu_domain = domain | domain_val(dom, type); \
1669- set_domain(thread->cpu_domain); \
1670- } while (0)
1671-
1672+extern void modify_domain(unsigned int dom, unsigned int type);
1673 #else
1674 static inline void set_domain(unsigned val) { }
1675 static inline void modify_domain(unsigned dom, unsigned type) { }
1676diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1677index f4b46d3..abc9b2b 100644
1678--- a/arch/arm/include/asm/elf.h
1679+++ b/arch/arm/include/asm/elf.h
1680@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1681 the loader. We need to make sure that it is out of the way of the program
1682 that it will "exec", and that there is sufficient room for the brk. */
1683
1684-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1685+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1686+
1687+#ifdef CONFIG_PAX_ASLR
1688+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1689+
1690+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1691+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1692+#endif
1693
1694 /* When the program starts, a1 contains a pointer to a function to be
1695 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1696@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1697 extern void elf_set_personality(const struct elf32_hdr *);
1698 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1699
1700-struct mm_struct;
1701-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1702-#define arch_randomize_brk arch_randomize_brk
1703-
1704 #ifdef CONFIG_MMU
1705 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1706 struct linux_binprm;
1707diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1708index de53547..52b9a28 100644
1709--- a/arch/arm/include/asm/fncpy.h
1710+++ b/arch/arm/include/asm/fncpy.h
1711@@ -81,7 +81,9 @@
1712 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1713 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1714 \
1715+ pax_open_kernel(); \
1716 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1717+ pax_close_kernel(); \
1718 flush_icache_range((unsigned long)(dest_buf), \
1719 (unsigned long)(dest_buf) + (size)); \
1720 \
1721diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1722index 2aff798..099eb15 100644
1723--- a/arch/arm/include/asm/futex.h
1724+++ b/arch/arm/include/asm/futex.h
1725@@ -45,6 +45,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1726 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1727 return -EFAULT;
1728
1729+ pax_open_userland();
1730+
1731 smp_mb();
1732 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1733 "1: ldrex %1, [%4]\n"
1734@@ -60,6 +62,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1735 : "cc", "memory");
1736 smp_mb();
1737
1738+ pax_close_userland();
1739+
1740 *uval = val;
1741 return ret;
1742 }
1743@@ -90,6 +94,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1744 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1745 return -EFAULT;
1746
1747+ pax_open_userland();
1748+
1749 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1750 "1: " TUSER(ldr) " %1, [%4]\n"
1751 " teq %1, %2\n"
1752@@ -100,6 +106,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1753 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1754 : "cc", "memory");
1755
1756+ pax_close_userland();
1757+
1758 *uval = val;
1759 return ret;
1760 }
1761@@ -122,6 +130,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1762 return -EFAULT;
1763
1764 pagefault_disable(); /* implies preempt_disable() */
1765+ pax_open_userland();
1766
1767 switch (op) {
1768 case FUTEX_OP_SET:
1769@@ -143,6 +152,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1770 ret = -ENOSYS;
1771 }
1772
1773+ pax_close_userland();
1774 pagefault_enable(); /* subsumes preempt_enable() */
1775
1776 if (!ret) {
1777diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1778index 83eb2f7..ed77159 100644
1779--- a/arch/arm/include/asm/kmap_types.h
1780+++ b/arch/arm/include/asm/kmap_types.h
1781@@ -4,6 +4,6 @@
1782 /*
1783 * This is the "bare minimum". AIO seems to require this.
1784 */
1785-#define KM_TYPE_NR 16
1786+#define KM_TYPE_NR 17
1787
1788 #endif
1789diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1790index 9e614a1..3302cca 100644
1791--- a/arch/arm/include/asm/mach/dma.h
1792+++ b/arch/arm/include/asm/mach/dma.h
1793@@ -22,7 +22,7 @@ struct dma_ops {
1794 int (*residue)(unsigned int, dma_t *); /* optional */
1795 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1796 const char *type;
1797-};
1798+} __do_const;
1799
1800 struct dma_struct {
1801 void *addr; /* single DMA address */
1802diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1803index f98c7f3..e5c626d 100644
1804--- a/arch/arm/include/asm/mach/map.h
1805+++ b/arch/arm/include/asm/mach/map.h
1806@@ -23,17 +23,19 @@ struct map_desc {
1807
1808 /* types 0-3 are defined in asm/io.h */
1809 enum {
1810- MT_UNCACHED = 4,
1811- MT_CACHECLEAN,
1812- MT_MINICLEAN,
1813+ MT_UNCACHED_RW = 4,
1814+ MT_CACHECLEAN_RO,
1815+ MT_MINICLEAN_RO,
1816 MT_LOW_VECTORS,
1817 MT_HIGH_VECTORS,
1818- MT_MEMORY_RWX,
1819+ __MT_MEMORY_RWX,
1820 MT_MEMORY_RW,
1821- MT_ROM,
1822- MT_MEMORY_RWX_NONCACHED,
1823+ MT_MEMORY_RX,
1824+ MT_ROM_RX,
1825+ MT_MEMORY_RW_NONCACHED,
1826+ MT_MEMORY_RX_NONCACHED,
1827 MT_MEMORY_RW_DTCM,
1828- MT_MEMORY_RWX_ITCM,
1829+ MT_MEMORY_RX_ITCM,
1830 MT_MEMORY_RW_SO,
1831 MT_MEMORY_DMA_READY,
1832 };
1833diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1834index f94784f..9a09a4a 100644
1835--- a/arch/arm/include/asm/outercache.h
1836+++ b/arch/arm/include/asm/outercache.h
1837@@ -35,7 +35,7 @@ struct outer_cache_fns {
1838 #endif
1839 void (*set_debug)(unsigned long);
1840 void (*resume)(void);
1841-};
1842+} __no_const;
1843
1844 extern struct outer_cache_fns outer_cache;
1845
1846diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1847index 4355f0e..cd9168e 100644
1848--- a/arch/arm/include/asm/page.h
1849+++ b/arch/arm/include/asm/page.h
1850@@ -23,6 +23,7 @@
1851
1852 #else
1853
1854+#include <linux/compiler.h>
1855 #include <asm/glue.h>
1856
1857 /*
1858@@ -114,7 +115,7 @@ struct cpu_user_fns {
1859 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1860 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1861 unsigned long vaddr, struct vm_area_struct *vma);
1862-};
1863+} __no_const;
1864
1865 #ifdef MULTI_USER
1866 extern struct cpu_user_fns cpu_user;
1867diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1868index 78a7793..e3dc06c 100644
1869--- a/arch/arm/include/asm/pgalloc.h
1870+++ b/arch/arm/include/asm/pgalloc.h
1871@@ -17,6 +17,7 @@
1872 #include <asm/processor.h>
1873 #include <asm/cacheflush.h>
1874 #include <asm/tlbflush.h>
1875+#include <asm/system_info.h>
1876
1877 #define check_pgt_cache() do { } while (0)
1878
1879@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1880 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1881 }
1882
1883+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1884+{
1885+ pud_populate(mm, pud, pmd);
1886+}
1887+
1888 #else /* !CONFIG_ARM_LPAE */
1889
1890 /*
1891@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1892 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1893 #define pmd_free(mm, pmd) do { } while (0)
1894 #define pud_populate(mm,pmd,pte) BUG()
1895+#define pud_populate_kernel(mm,pmd,pte) BUG()
1896
1897 #endif /* CONFIG_ARM_LPAE */
1898
1899@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1900 __free_page(pte);
1901 }
1902
1903+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1904+{
1905+#ifdef CONFIG_ARM_LPAE
1906+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1907+#else
1908+ if (addr & SECTION_SIZE)
1909+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1910+ else
1911+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1912+#endif
1913+ flush_pmd_entry(pmdp);
1914+}
1915+
1916 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1917 pmdval_t prot)
1918 {
1919@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1920 static inline void
1921 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1922 {
1923- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1924+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1925 }
1926 #define pmd_pgtable(pmd) pmd_page(pmd)
1927
1928diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1929index 5cfba15..f415e1a 100644
1930--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1931+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1932@@ -20,12 +20,15 @@
1933 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1934 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1935 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1936+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1937 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1938 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1939 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1940+
1941 /*
1942 * - section
1943 */
1944+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1945 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1946 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1947 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1948@@ -37,6 +40,7 @@
1949 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1950 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1951 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1952+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1953
1954 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1955 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1956@@ -66,6 +70,7 @@
1957 * - extended small page/tiny page
1958 */
1959 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1960+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1961 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1962 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1963 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1964diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1965index 219ac88..73ec32a 100644
1966--- a/arch/arm/include/asm/pgtable-2level.h
1967+++ b/arch/arm/include/asm/pgtable-2level.h
1968@@ -126,6 +126,9 @@
1969 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1970 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1971
1972+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1973+#define L_PTE_PXN (_AT(pteval_t, 0))
1974+
1975 /*
1976 * These are the memory types, defined to be compatible with
1977 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1978diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1979index 626989f..9d67a33 100644
1980--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1981+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1982@@ -75,6 +75,7 @@
1983 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1984 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1985 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1986+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1987 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1988
1989 /*
1990diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1991index 85c60ad..b0bbd7e 100644
1992--- a/arch/arm/include/asm/pgtable-3level.h
1993+++ b/arch/arm/include/asm/pgtable-3level.h
1994@@ -82,6 +82,7 @@
1995 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1996 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1997 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1998+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1999 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2000 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2001 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2002@@ -95,6 +96,7 @@
2003 /*
2004 * To be used in assembly code with the upper page attributes.
2005 */
2006+#define L_PTE_PXN_HIGH (1 << (53 - 32))
2007 #define L_PTE_XN_HIGH (1 << (54 - 32))
2008 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2009
2010diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2011index 7d59b52..27a12f8 100644
2012--- a/arch/arm/include/asm/pgtable.h
2013+++ b/arch/arm/include/asm/pgtable.h
2014@@ -33,6 +33,9 @@
2015 #include <asm/pgtable-2level.h>
2016 #endif
2017
2018+#define ktla_ktva(addr) (addr)
2019+#define ktva_ktla(addr) (addr)
2020+
2021 /*
2022 * Just any arbitrary offset to the start of the vmalloc VM area: the
2023 * current 8MB value just means that there will be a 8MB "hole" after the
2024@@ -48,6 +51,9 @@
2025 #define LIBRARY_TEXT_START 0x0c000000
2026
2027 #ifndef __ASSEMBLY__
2028+extern pteval_t __supported_pte_mask;
2029+extern pmdval_t __supported_pmd_mask;
2030+
2031 extern void __pte_error(const char *file, int line, pte_t);
2032 extern void __pmd_error(const char *file, int line, pmd_t);
2033 extern void __pgd_error(const char *file, int line, pgd_t);
2034@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2035 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2036 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2037
2038+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2039+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2040+
2041+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2042+#include <asm/domain.h>
2043+#include <linux/thread_info.h>
2044+#include <linux/preempt.h>
2045+
2046+static inline int test_domain(int domain, int domaintype)
2047+{
2048+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2049+}
2050+#endif
2051+
2052+#ifdef CONFIG_PAX_KERNEXEC
2053+static inline unsigned long pax_open_kernel(void) {
2054+#ifdef CONFIG_ARM_LPAE
2055+ /* TODO */
2056+#else
2057+ preempt_disable();
2058+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2059+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2060+#endif
2061+ return 0;
2062+}
2063+
2064+static inline unsigned long pax_close_kernel(void) {
2065+#ifdef CONFIG_ARM_LPAE
2066+ /* TODO */
2067+#else
2068+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2069+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2070+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2071+ preempt_enable_no_resched();
2072+#endif
2073+ return 0;
2074+}
2075+#else
2076+static inline unsigned long pax_open_kernel(void) { return 0; }
2077+static inline unsigned long pax_close_kernel(void) { return 0; }
2078+#endif
2079+
2080 /*
2081 * This is the lowest virtual address we can permit any user space
2082 * mapping to be mapped at. This is particularly important for
2083@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2084 /*
2085 * The pgprot_* and protection_map entries will be fixed up in runtime
2086 * to include the cachable and bufferable bits based on memory policy,
2087- * as well as any architecture dependent bits like global/ASID and SMP
2088- * shared mapping bits.
2089+ * as well as any architecture dependent bits like global/ASID, PXN,
2090+ * and SMP shared mapping bits.
2091 */
2092 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2093
2094@@ -262,7 +310,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2095 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2096 {
2097 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2098- L_PTE_NONE | L_PTE_VALID;
2099+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2100 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2101 return pte;
2102 }
2103diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2104index c4ae171..ea0c0c2 100644
2105--- a/arch/arm/include/asm/psci.h
2106+++ b/arch/arm/include/asm/psci.h
2107@@ -29,7 +29,7 @@ struct psci_operations {
2108 int (*cpu_off)(struct psci_power_state state);
2109 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2110 int (*migrate)(unsigned long cpuid);
2111-};
2112+} __no_const;
2113
2114 extern struct psci_operations psci_ops;
2115 extern struct smp_operations psci_smp_ops;
2116diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2117index 22a3b9b..7f214ee 100644
2118--- a/arch/arm/include/asm/smp.h
2119+++ b/arch/arm/include/asm/smp.h
2120@@ -112,7 +112,7 @@ struct smp_operations {
2121 int (*cpu_disable)(unsigned int cpu);
2122 #endif
2123 #endif
2124-};
2125+} __no_const;
2126
2127 /*
2128 * set platform specific SMP operations
2129diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2130index 71a06b2..8bb9ae1 100644
2131--- a/arch/arm/include/asm/thread_info.h
2132+++ b/arch/arm/include/asm/thread_info.h
2133@@ -88,9 +88,9 @@ struct thread_info {
2134 .flags = 0, \
2135 .preempt_count = INIT_PREEMPT_COUNT, \
2136 .addr_limit = KERNEL_DS, \
2137- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2138- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2139- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2140+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2141+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2142+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2143 .restart_block = { \
2144 .fn = do_no_restart_syscall, \
2145 }, \
2146@@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2147 #define TIF_SYSCALL_AUDIT 9
2148 #define TIF_SYSCALL_TRACEPOINT 10
2149 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2150-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2151+/* within 8 bits of TIF_SYSCALL_TRACE
2152+ * to meet flexible second operand requirements
2153+ */
2154+#define TIF_GRSEC_SETXID 12
2155+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2156 #define TIF_USING_IWMMXT 17
2157 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2158 #define TIF_RESTORE_SIGMASK 20
2159@@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2160 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2161 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2162 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2163+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2164
2165 /* Checks for any syscall work in entry-common.S */
2166 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2167- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2168+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2169
2170 /*
2171 * Change these and you break ASM code in entry-common.S
2172diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2173index 7f3f3cc..bdf0665 100644
2174--- a/arch/arm/include/asm/uaccess.h
2175+++ b/arch/arm/include/asm/uaccess.h
2176@@ -18,6 +18,7 @@
2177 #include <asm/domain.h>
2178 #include <asm/unified.h>
2179 #include <asm/compiler.h>
2180+#include <asm/pgtable.h>
2181
2182 #if __LINUX_ARM_ARCH__ < 6
2183 #include <asm-generic/uaccess-unaligned.h>
2184@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2185 static inline void set_fs(mm_segment_t fs)
2186 {
2187 current_thread_info()->addr_limit = fs;
2188- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2189+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2190 }
2191
2192 #define segment_eq(a,b) ((a) == (b))
2193
2194+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2195+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2196+
2197+static inline void pax_open_userland(void)
2198+{
2199+
2200+#ifdef CONFIG_PAX_MEMORY_UDEREF
2201+ if (segment_eq(get_fs(), USER_DS)) {
2202+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2203+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2204+ }
2205+#endif
2206+
2207+}
2208+
2209+static inline void pax_close_userland(void)
2210+{
2211+
2212+#ifdef CONFIG_PAX_MEMORY_UDEREF
2213+ if (segment_eq(get_fs(), USER_DS)) {
2214+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2215+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2216+ }
2217+#endif
2218+
2219+}
2220+
2221 #define __addr_ok(addr) ({ \
2222 unsigned long flag; \
2223 __asm__("cmp %2, %0; movlo %0, #0" \
2224@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2225
2226 #define get_user(x,p) \
2227 ({ \
2228+ int __e; \
2229 might_fault(); \
2230- __get_user_check(x,p); \
2231+ pax_open_userland(); \
2232+ __e = __get_user_check(x,p); \
2233+ pax_close_userland(); \
2234+ __e; \
2235 })
2236
2237 extern int __put_user_1(void *, unsigned int);
2238@@ -196,8 +228,12 @@ extern int __put_user_8(void *, unsigned long long);
2239
2240 #define put_user(x,p) \
2241 ({ \
2242+ int __e; \
2243 might_fault(); \
2244- __put_user_check(x,p); \
2245+ pax_open_userland(); \
2246+ __e = __put_user_check(x,p); \
2247+ pax_close_userland(); \
2248+ __e; \
2249 })
2250
2251 #else /* CONFIG_MMU */
2252@@ -221,6 +257,7 @@ static inline void set_fs(mm_segment_t fs)
2253
2254 #endif /* CONFIG_MMU */
2255
2256+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2257 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2258
2259 #define user_addr_max() \
2260@@ -238,13 +275,17 @@ static inline void set_fs(mm_segment_t fs)
2261 #define __get_user(x,ptr) \
2262 ({ \
2263 long __gu_err = 0; \
2264+ pax_open_userland(); \
2265 __get_user_err((x),(ptr),__gu_err); \
2266+ pax_close_userland(); \
2267 __gu_err; \
2268 })
2269
2270 #define __get_user_error(x,ptr,err) \
2271 ({ \
2272+ pax_open_userland(); \
2273 __get_user_err((x),(ptr),err); \
2274+ pax_close_userland(); \
2275 (void) 0; \
2276 })
2277
2278@@ -320,13 +361,17 @@ do { \
2279 #define __put_user(x,ptr) \
2280 ({ \
2281 long __pu_err = 0; \
2282+ pax_open_userland(); \
2283 __put_user_err((x),(ptr),__pu_err); \
2284+ pax_close_userland(); \
2285 __pu_err; \
2286 })
2287
2288 #define __put_user_error(x,ptr,err) \
2289 ({ \
2290+ pax_open_userland(); \
2291 __put_user_err((x),(ptr),err); \
2292+ pax_close_userland(); \
2293 (void) 0; \
2294 })
2295
2296@@ -426,11 +471,44 @@ do { \
2297
2298
2299 #ifdef CONFIG_MMU
2300-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2301-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2302+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2303+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2304+
2305+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2306+{
2307+ unsigned long ret;
2308+
2309+ check_object_size(to, n, false);
2310+ pax_open_userland();
2311+ ret = ___copy_from_user(to, from, n);
2312+ pax_close_userland();
2313+ return ret;
2314+}
2315+
2316+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2317+{
2318+ unsigned long ret;
2319+
2320+ check_object_size(from, n, true);
2321+ pax_open_userland();
2322+ ret = ___copy_to_user(to, from, n);
2323+ pax_close_userland();
2324+ return ret;
2325+}
2326+
2327 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2328-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2329+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2330 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2331+
2332+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2333+{
2334+ unsigned long ret;
2335+ pax_open_userland();
2336+ ret = ___clear_user(addr, n);
2337+ pax_close_userland();
2338+ return ret;
2339+}
2340+
2341 #else
2342 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2343 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2344@@ -439,6 +517,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2345
2346 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2347 {
2348+ if ((long)n < 0)
2349+ return n;
2350+
2351 if (access_ok(VERIFY_READ, from, n))
2352 n = __copy_from_user(to, from, n);
2353 else /* security hole - plug it */
2354@@ -448,6 +529,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2355
2356 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2357 {
2358+ if ((long)n < 0)
2359+ return n;
2360+
2361 if (access_ok(VERIFY_WRITE, to, n))
2362 n = __copy_to_user(to, from, n);
2363 return n;
2364diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2365index 5af0ed1..cea83883 100644
2366--- a/arch/arm/include/uapi/asm/ptrace.h
2367+++ b/arch/arm/include/uapi/asm/ptrace.h
2368@@ -92,7 +92,7 @@
2369 * ARMv7 groups of PSR bits
2370 */
2371 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2372-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2373+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2374 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2375 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2376
2377diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2378index 85e664b..419a1cd 100644
2379--- a/arch/arm/kernel/armksyms.c
2380+++ b/arch/arm/kernel/armksyms.c
2381@@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2382
2383 /* networking */
2384 EXPORT_SYMBOL(csum_partial);
2385-EXPORT_SYMBOL(csum_partial_copy_from_user);
2386+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2387 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2388 EXPORT_SYMBOL(__csum_ipv6_magic);
2389
2390@@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2391 #ifdef CONFIG_MMU
2392 EXPORT_SYMBOL(copy_page);
2393
2394-EXPORT_SYMBOL(__copy_from_user);
2395-EXPORT_SYMBOL(__copy_to_user);
2396-EXPORT_SYMBOL(__clear_user);
2397+EXPORT_SYMBOL(___copy_from_user);
2398+EXPORT_SYMBOL(___copy_to_user);
2399+EXPORT_SYMBOL(___clear_user);
2400
2401 EXPORT_SYMBOL(__get_user_1);
2402 EXPORT_SYMBOL(__get_user_2);
2403diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2404index 1879e8d..b2207fc 100644
2405--- a/arch/arm/kernel/entry-armv.S
2406+++ b/arch/arm/kernel/entry-armv.S
2407@@ -47,6 +47,87 @@
2408 9997:
2409 .endm
2410
2411+ .macro pax_enter_kernel
2412+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2413+ @ make aligned space for saved DACR
2414+ sub sp, sp, #8
2415+ @ save regs
2416+ stmdb sp!, {r1, r2}
2417+ @ read DACR from cpu_domain into r1
2418+ mov r2, sp
2419+ @ assume 8K pages, since we have to split the immediate in two
2420+ bic r2, r2, #(0x1fc0)
2421+ bic r2, r2, #(0x3f)
2422+ ldr r1, [r2, #TI_CPU_DOMAIN]
2423+ @ store old DACR on stack
2424+ str r1, [sp, #8]
2425+#ifdef CONFIG_PAX_KERNEXEC
2426+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2427+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2428+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2429+#endif
2430+#ifdef CONFIG_PAX_MEMORY_UDEREF
2431+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2432+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2433+#endif
2434+ @ write r1 to current_thread_info()->cpu_domain
2435+ str r1, [r2, #TI_CPU_DOMAIN]
2436+ @ write r1 to DACR
2437+ mcr p15, 0, r1, c3, c0, 0
2438+ @ instruction sync
2439+ instr_sync
2440+ @ restore regs
2441+ ldmia sp!, {r1, r2}
2442+#endif
2443+ .endm
2444+
2445+ .macro pax_open_userland
2446+#ifdef CONFIG_PAX_MEMORY_UDEREF
2447+ @ save regs
2448+ stmdb sp!, {r0, r1}
2449+ @ read DACR from cpu_domain into r1
2450+ mov r0, sp
2451+ @ assume 8K pages, since we have to split the immediate in two
2452+ bic r0, r0, #(0x1fc0)
2453+ bic r0, r0, #(0x3f)
2454+ ldr r1, [r0, #TI_CPU_DOMAIN]
2455+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2456+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2457+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2458+ @ write r1 to current_thread_info()->cpu_domain
2459+ str r1, [r0, #TI_CPU_DOMAIN]
2460+ @ write r1 to DACR
2461+ mcr p15, 0, r1, c3, c0, 0
2462+ @ instruction sync
2463+ instr_sync
2464+ @ restore regs
2465+ ldmia sp!, {r0, r1}
2466+#endif
2467+ .endm
2468+
2469+ .macro pax_close_userland
2470+#ifdef CONFIG_PAX_MEMORY_UDEREF
2471+ @ save regs
2472+ stmdb sp!, {r0, r1}
2473+ @ read DACR from cpu_domain into r1
2474+ mov r0, sp
2475+ @ assume 8K pages, since we have to split the immediate in two
2476+ bic r0, r0, #(0x1fc0)
2477+ bic r0, r0, #(0x3f)
2478+ ldr r1, [r0, #TI_CPU_DOMAIN]
2479+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2480+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2481+ @ write r1 to current_thread_info()->cpu_domain
2482+ str r1, [r0, #TI_CPU_DOMAIN]
2483+ @ write r1 to DACR
2484+ mcr p15, 0, r1, c3, c0, 0
2485+ @ instruction sync
2486+ instr_sync
2487+ @ restore regs
2488+ ldmia sp!, {r0, r1}
2489+#endif
2490+ .endm
2491+
2492 .macro pabt_helper
2493 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2494 #ifdef MULTI_PABORT
2495@@ -89,11 +170,15 @@
2496 * Invalid mode handlers
2497 */
2498 .macro inv_entry, reason
2499+
2500+ pax_enter_kernel
2501+
2502 sub sp, sp, #S_FRAME_SIZE
2503 ARM( stmib sp, {r1 - lr} )
2504 THUMB( stmia sp, {r0 - r12} )
2505 THUMB( str sp, [sp, #S_SP] )
2506 THUMB( str lr, [sp, #S_LR] )
2507+
2508 mov r1, #\reason
2509 .endm
2510
2511@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2512 .macro svc_entry, stack_hole=0
2513 UNWIND(.fnstart )
2514 UNWIND(.save {r0 - pc} )
2515+
2516+ pax_enter_kernel
2517+
2518 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2519+
2520 #ifdef CONFIG_THUMB2_KERNEL
2521 SPFIX( str r0, [sp] ) @ temporarily saved
2522 SPFIX( mov r0, sp )
2523@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2524 ldmia r0, {r3 - r5}
2525 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2526 mov r6, #-1 @ "" "" "" ""
2527+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2528+ @ offset sp by 8 as done in pax_enter_kernel
2529+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2530+#else
2531 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2532+#endif
2533 SPFIX( addeq r2, r2, #4 )
2534 str r3, [sp, #-4]! @ save the "real" r0 copied
2535 @ from the exception stack
2536@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2537 .macro usr_entry
2538 UNWIND(.fnstart )
2539 UNWIND(.cantunwind ) @ don't unwind the user space
2540+
2541+ pax_enter_kernel_user
2542+
2543 sub sp, sp, #S_FRAME_SIZE
2544 ARM( stmib sp, {r1 - r12} )
2545 THUMB( stmia sp, {r0 - r12} )
2546@@ -416,7 +513,9 @@ __und_usr:
2547 tst r3, #PSR_T_BIT @ Thumb mode?
2548 bne __und_usr_thumb
2549 sub r4, r2, #4 @ ARM instr at LR - 4
2550+ pax_open_userland
2551 1: ldrt r0, [r4]
2552+ pax_close_userland
2553 ARM_BE8(rev r0, r0) @ little endian instruction
2554
2555 @ r0 = 32-bit ARM instruction which caused the exception
2556@@ -450,11 +549,15 @@ __und_usr_thumb:
2557 */
2558 .arch armv6t2
2559 #endif
2560+ pax_open_userland
2561 2: ldrht r5, [r4]
2562+ pax_close_userland
2563 ARM_BE8(rev16 r5, r5) @ little endian instruction
2564 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2565 blo __und_usr_fault_16 @ 16bit undefined instruction
2566+ pax_open_userland
2567 3: ldrht r0, [r2]
2568+ pax_close_userland
2569 ARM_BE8(rev16 r0, r0) @ little endian instruction
2570 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2571 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2572@@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2573 */
2574 .pushsection .fixup, "ax"
2575 .align 2
2576-4: mov pc, r9
2577+4: pax_close_userland
2578+ mov pc, r9
2579 .popsection
2580 .pushsection __ex_table,"a"
2581 .long 1b, 4b
2582@@ -694,7 +798,7 @@ ENTRY(__switch_to)
2583 THUMB( str lr, [ip], #4 )
2584 ldr r4, [r2, #TI_TP_VALUE]
2585 ldr r5, [r2, #TI_TP_VALUE + 4]
2586-#ifdef CONFIG_CPU_USE_DOMAINS
2587+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2588 ldr r6, [r2, #TI_CPU_DOMAIN]
2589 #endif
2590 switch_tls r1, r4, r5, r3, r7
2591@@ -703,7 +807,7 @@ ENTRY(__switch_to)
2592 ldr r8, =__stack_chk_guard
2593 ldr r7, [r7, #TSK_STACK_CANARY]
2594 #endif
2595-#ifdef CONFIG_CPU_USE_DOMAINS
2596+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2597 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2598 #endif
2599 mov r5, r0
2600diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2601index a2dcafd..1048b5a 100644
2602--- a/arch/arm/kernel/entry-common.S
2603+++ b/arch/arm/kernel/entry-common.S
2604@@ -10,18 +10,46 @@
2605
2606 #include <asm/unistd.h>
2607 #include <asm/ftrace.h>
2608+#include <asm/domain.h>
2609 #include <asm/unwind.h>
2610
2611+#include "entry-header.S"
2612+
2613 #ifdef CONFIG_NEED_RET_TO_USER
2614 #include <mach/entry-macro.S>
2615 #else
2616 .macro arch_ret_to_user, tmp1, tmp2
2617+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2618+ @ save regs
2619+ stmdb sp!, {r1, r2}
2620+ @ read DACR from cpu_domain into r1
2621+ mov r2, sp
2622+ @ assume 8K pages, since we have to split the immediate in two
2623+ bic r2, r2, #(0x1fc0)
2624+ bic r2, r2, #(0x3f)
2625+ ldr r1, [r2, #TI_CPU_DOMAIN]
2626+#ifdef CONFIG_PAX_KERNEXEC
2627+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2628+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2629+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2630+#endif
2631+#ifdef CONFIG_PAX_MEMORY_UDEREF
2632+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2633+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2634+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2635+#endif
2636+ @ write r1 to current_thread_info()->cpu_domain
2637+ str r1, [r2, #TI_CPU_DOMAIN]
2638+ @ write r1 to DACR
2639+ mcr p15, 0, r1, c3, c0, 0
2640+ @ instruction sync
2641+ instr_sync
2642+ @ restore regs
2643+ ldmia sp!, {r1, r2}
2644+#endif
2645 .endm
2646 #endif
2647
2648-#include "entry-header.S"
2649-
2650-
2651 .align 5
2652 /*
2653 * This is the fast syscall return path. We do as little as
2654@@ -411,6 +439,12 @@ ENTRY(vector_swi)
2655 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2656 #endif
2657
2658+ /*
2659+ * do this here to avoid a performance hit of wrapping the code above
2660+ * that directly dereferences userland to parse the SWI instruction
2661+ */
2662+ pax_enter_kernel_user
2663+
2664 adr tbl, sys_call_table @ load syscall table pointer
2665
2666 #if defined(CONFIG_OABI_COMPAT)
2667diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2668index 88c6bab..652981b 100644
2669--- a/arch/arm/kernel/entry-header.S
2670+++ b/arch/arm/kernel/entry-header.S
2671@@ -188,6 +188,60 @@
2672 msr cpsr_c, \rtemp @ switch back to the SVC mode
2673 .endm
2674
2675+ .macro pax_enter_kernel_user
2676+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2677+ @ save regs
2678+ stmdb sp!, {r0, r1}
2679+ @ read DACR from cpu_domain into r1
2680+ mov r0, sp
2681+ @ assume 8K pages, since we have to split the immediate in two
2682+ bic r0, r0, #(0x1fc0)
2683+ bic r0, r0, #(0x3f)
2684+ ldr r1, [r0, #TI_CPU_DOMAIN]
2685+#ifdef CONFIG_PAX_MEMORY_UDEREF
2686+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2687+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2688+#endif
2689+#ifdef CONFIG_PAX_KERNEXEC
2690+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2691+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2692+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2693+#endif
2694+ @ write r1 to current_thread_info()->cpu_domain
2695+ str r1, [r0, #TI_CPU_DOMAIN]
2696+ @ write r1 to DACR
2697+ mcr p15, 0, r1, c3, c0, 0
2698+ @ instruction sync
2699+ instr_sync
2700+ @ restore regs
2701+ ldmia sp!, {r0, r1}
2702+#endif
2703+ .endm
2704+
2705+ .macro pax_exit_kernel
2706+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2707+ @ save regs
2708+ stmdb sp!, {r0, r1}
2709+ @ read old DACR from stack into r1
2710+ ldr r1, [sp, #(8 + S_SP)]
2711+ sub r1, r1, #8
2712+ ldr r1, [r1]
2713+
2714+ @ write r1 to current_thread_info()->cpu_domain
2715+ mov r0, sp
2716+ @ assume 8K pages, since we have to split the immediate in two
2717+ bic r0, r0, #(0x1fc0)
2718+ bic r0, r0, #(0x3f)
2719+ str r1, [r0, #TI_CPU_DOMAIN]
2720+ @ write r1 to DACR
2721+ mcr p15, 0, r1, c3, c0, 0
2722+ @ instruction sync
2723+ instr_sync
2724+ @ restore regs
2725+ ldmia sp!, {r0, r1}
2726+#endif
2727+ .endm
2728+
2729 #ifndef CONFIG_THUMB2_KERNEL
2730 .macro svc_exit, rpsr, irq = 0
2731 .if \irq != 0
2732@@ -207,6 +261,9 @@
2733 blne trace_hardirqs_off
2734 #endif
2735 .endif
2736+
2737+ pax_exit_kernel
2738+
2739 msr spsr_cxsf, \rpsr
2740 #if defined(CONFIG_CPU_V6)
2741 ldr r0, [sp]
2742@@ -270,6 +327,9 @@
2743 blne trace_hardirqs_off
2744 #endif
2745 .endif
2746+
2747+ pax_exit_kernel
2748+
2749 ldr lr, [sp, #S_SP] @ top of the stack
2750 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2751 clrex @ clear the exclusive monitor
2752diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2753index 918875d..cd5fa27 100644
2754--- a/arch/arm/kernel/fiq.c
2755+++ b/arch/arm/kernel/fiq.c
2756@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2757 void *base = vectors_page;
2758 unsigned offset = FIQ_OFFSET;
2759
2760+ pax_open_kernel();
2761 memcpy(base + offset, start, length);
2762+ pax_close_kernel();
2763+
2764 if (!cache_is_vipt_nonaliasing())
2765 flush_icache_range((unsigned long)base + offset, offset +
2766 length);
2767diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2768index f5f381d..a6f36a1 100644
2769--- a/arch/arm/kernel/head.S
2770+++ b/arch/arm/kernel/head.S
2771@@ -437,7 +437,7 @@ __enable_mmu:
2772 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2773 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2774 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2775- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2776+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2777 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2778 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2779 #endif
2780diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2781index 45e4781..8eac93d 100644
2782--- a/arch/arm/kernel/module.c
2783+++ b/arch/arm/kernel/module.c
2784@@ -38,12 +38,39 @@
2785 #endif
2786
2787 #ifdef CONFIG_MMU
2788-void *module_alloc(unsigned long size)
2789+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2790 {
2791+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2792+ return NULL;
2793 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2794- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2795+ GFP_KERNEL, prot, NUMA_NO_NODE,
2796 __builtin_return_address(0));
2797 }
2798+
2799+void *module_alloc(unsigned long size)
2800+{
2801+
2802+#ifdef CONFIG_PAX_KERNEXEC
2803+ return __module_alloc(size, PAGE_KERNEL);
2804+#else
2805+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2806+#endif
2807+
2808+}
2809+
2810+#ifdef CONFIG_PAX_KERNEXEC
2811+void module_free_exec(struct module *mod, void *module_region)
2812+{
2813+ module_free(mod, module_region);
2814+}
2815+EXPORT_SYMBOL(module_free_exec);
2816+
2817+void *module_alloc_exec(unsigned long size)
2818+{
2819+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2820+}
2821+EXPORT_SYMBOL(module_alloc_exec);
2822+#endif
2823 #endif
2824
2825 int
2826diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2827index 07314af..c46655c 100644
2828--- a/arch/arm/kernel/patch.c
2829+++ b/arch/arm/kernel/patch.c
2830@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2831 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2832 int size;
2833
2834+ pax_open_kernel();
2835 if (thumb2 && __opcode_is_thumb16(insn)) {
2836 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2837 size = sizeof(u16);
2838@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2839 *(u32 *)addr = insn;
2840 size = sizeof(u32);
2841 }
2842+ pax_close_kernel();
2843
2844 flush_icache_range((uintptr_t)(addr),
2845 (uintptr_t)(addr) + size);
2846diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2847index 92f7b15..7048500 100644
2848--- a/arch/arm/kernel/process.c
2849+++ b/arch/arm/kernel/process.c
2850@@ -217,6 +217,7 @@ void machine_power_off(void)
2851
2852 if (pm_power_off)
2853 pm_power_off();
2854+ BUG();
2855 }
2856
2857 /*
2858@@ -230,7 +231,7 @@ void machine_power_off(void)
2859 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2860 * to use. Implementing such co-ordination would be essentially impossible.
2861 */
2862-void machine_restart(char *cmd)
2863+__noreturn void machine_restart(char *cmd)
2864 {
2865 local_irq_disable();
2866 smp_send_stop();
2867@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2868
2869 show_regs_print_info(KERN_DEFAULT);
2870
2871- print_symbol("PC is at %s\n", instruction_pointer(regs));
2872- print_symbol("LR is at %s\n", regs->ARM_lr);
2873+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2874+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2875 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2876 "sp : %08lx ip : %08lx fp : %08lx\n",
2877 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2878@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2879 return 0;
2880 }
2881
2882-unsigned long arch_randomize_brk(struct mm_struct *mm)
2883-{
2884- unsigned long range_end = mm->brk + 0x02000000;
2885- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2886-}
2887-
2888 #ifdef CONFIG_MMU
2889 #ifdef CONFIG_KUSER_HELPERS
2890 /*
2891@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2892
2893 static int __init gate_vma_init(void)
2894 {
2895- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2896+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2897 return 0;
2898 }
2899 arch_initcall(gate_vma_init);
2900@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2901
2902 const char *arch_vma_name(struct vm_area_struct *vma)
2903 {
2904- return is_gate_vma(vma) ? "[vectors]" :
2905- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2906- "[sigpage]" : NULL;
2907+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2908 }
2909
2910-static struct page *signal_page;
2911-extern struct page *get_signal_page(void);
2912-
2913 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2914 {
2915 struct mm_struct *mm = current->mm;
2916- unsigned long addr;
2917- int ret;
2918-
2919- if (!signal_page)
2920- signal_page = get_signal_page();
2921- if (!signal_page)
2922- return -ENOMEM;
2923
2924 down_write(&mm->mmap_sem);
2925- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2926- if (IS_ERR_VALUE(addr)) {
2927- ret = addr;
2928- goto up_fail;
2929- }
2930-
2931- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2932- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2933- &signal_page);
2934-
2935- if (ret == 0)
2936- mm->context.sigpage = addr;
2937-
2938- up_fail:
2939+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2940 up_write(&mm->mmap_sem);
2941- return ret;
2942+ return 0;
2943 }
2944 #endif
2945diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2946index 4693188..4596c5e 100644
2947--- a/arch/arm/kernel/psci.c
2948+++ b/arch/arm/kernel/psci.c
2949@@ -24,7 +24,7 @@
2950 #include <asm/opcodes-virt.h>
2951 #include <asm/psci.h>
2952
2953-struct psci_operations psci_ops;
2954+struct psci_operations psci_ops __read_only;
2955
2956 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2957
2958diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2959index 0dd3b79..e018f64 100644
2960--- a/arch/arm/kernel/ptrace.c
2961+++ b/arch/arm/kernel/ptrace.c
2962@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2963 return current_thread_info()->syscall;
2964 }
2965
2966+#ifdef CONFIG_GRKERNSEC_SETXID
2967+extern void gr_delayed_cred_worker(void);
2968+#endif
2969+
2970 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2971 {
2972 current_thread_info()->syscall = scno;
2973
2974+#ifdef CONFIG_GRKERNSEC_SETXID
2975+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2976+ gr_delayed_cred_worker();
2977+#endif
2978+
2979 /* Do the secure computing check first; failures should be fast. */
2980 if (secure_computing(scno) == -1)
2981 return -1;
2982diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2983index 1e8b030..37c3022 100644
2984--- a/arch/arm/kernel/setup.c
2985+++ b/arch/arm/kernel/setup.c
2986@@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2987 unsigned int elf_hwcap __read_mostly;
2988 EXPORT_SYMBOL(elf_hwcap);
2989
2990+pteval_t __supported_pte_mask __read_only;
2991+pmdval_t __supported_pmd_mask __read_only;
2992
2993 #ifdef MULTI_CPU
2994-struct processor processor __read_mostly;
2995+struct processor processor __read_only;
2996 #endif
2997 #ifdef MULTI_TLB
2998-struct cpu_tlb_fns cpu_tlb __read_mostly;
2999+struct cpu_tlb_fns cpu_tlb __read_only;
3000 #endif
3001 #ifdef MULTI_USER
3002-struct cpu_user_fns cpu_user __read_mostly;
3003+struct cpu_user_fns cpu_user __read_only;
3004 #endif
3005 #ifdef MULTI_CACHE
3006-struct cpu_cache_fns cpu_cache __read_mostly;
3007+struct cpu_cache_fns cpu_cache __read_only;
3008 #endif
3009 #ifdef CONFIG_OUTER_CACHE
3010-struct outer_cache_fns outer_cache __read_mostly;
3011+struct outer_cache_fns outer_cache __read_only;
3012 EXPORT_SYMBOL(outer_cache);
3013 #endif
3014
3015@@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3016 asm("mrc p15, 0, %0, c0, c1, 4"
3017 : "=r" (mmfr0));
3018 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3019- (mmfr0 & 0x000000f0) >= 0x00000030)
3020+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3021 cpu_arch = CPU_ARCH_ARMv7;
3022- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3023+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3024+ __supported_pte_mask |= L_PTE_PXN;
3025+ __supported_pmd_mask |= PMD_PXNTABLE;
3026+ }
3027+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3028 (mmfr0 & 0x000000f0) == 0x00000020)
3029 cpu_arch = CPU_ARCH_ARMv6;
3030 else
3031diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3032index 04d6388..5115238 100644
3033--- a/arch/arm/kernel/signal.c
3034+++ b/arch/arm/kernel/signal.c
3035@@ -23,8 +23,6 @@
3036
3037 extern const unsigned long sigreturn_codes[7];
3038
3039-static unsigned long signal_return_offset;
3040-
3041 #ifdef CONFIG_CRUNCH
3042 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3043 {
3044@@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3045 * except when the MPU has protected the vectors
3046 * page from PL0
3047 */
3048- retcode = mm->context.sigpage + signal_return_offset +
3049- (idx << 2) + thumb;
3050+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3051 } else
3052 #endif
3053 {
3054@@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3055 } while (thread_flags & _TIF_WORK_MASK);
3056 return 0;
3057 }
3058-
3059-struct page *get_signal_page(void)
3060-{
3061- unsigned long ptr;
3062- unsigned offset;
3063- struct page *page;
3064- void *addr;
3065-
3066- page = alloc_pages(GFP_KERNEL, 0);
3067-
3068- if (!page)
3069- return NULL;
3070-
3071- addr = page_address(page);
3072-
3073- /* Give the signal return code some randomness */
3074- offset = 0x200 + (get_random_int() & 0x7fc);
3075- signal_return_offset = offset;
3076-
3077- /*
3078- * Copy signal return handlers into the vector page, and
3079- * set sigreturn to be a pointer to these.
3080- */
3081- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3082-
3083- ptr = (unsigned long)addr + offset;
3084- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3085-
3086- return page;
3087-}
3088diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3089index b7b4c86..47c4f77 100644
3090--- a/arch/arm/kernel/smp.c
3091+++ b/arch/arm/kernel/smp.c
3092@@ -73,7 +73,7 @@ enum ipi_msg_type {
3093
3094 static DECLARE_COMPLETION(cpu_running);
3095
3096-static struct smp_operations smp_ops;
3097+static struct smp_operations smp_ops __read_only;
3098
3099 void __init smp_set_ops(struct smp_operations *ops)
3100 {
3101diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3102index 7a3be1d..b00c7de 100644
3103--- a/arch/arm/kernel/tcm.c
3104+++ b/arch/arm/kernel/tcm.c
3105@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3106 .virtual = ITCM_OFFSET,
3107 .pfn = __phys_to_pfn(ITCM_OFFSET),
3108 .length = 0,
3109- .type = MT_MEMORY_RWX_ITCM,
3110+ .type = MT_MEMORY_RX_ITCM,
3111 }
3112 };
3113
3114@@ -267,7 +267,9 @@ no_dtcm:
3115 start = &__sitcm_text;
3116 end = &__eitcm_text;
3117 ram = &__itcm_start;
3118+ pax_open_kernel();
3119 memcpy(start, ram, itcm_code_sz);
3120+ pax_close_kernel();
3121 pr_debug("CPU ITCM: copied code from %p - %p\n",
3122 start, end);
3123 itcm_present = true;
3124diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3125index 172ee18..ce4ec3d 100644
3126--- a/arch/arm/kernel/traps.c
3127+++ b/arch/arm/kernel/traps.c
3128@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3129 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3130 {
3131 #ifdef CONFIG_KALLSYMS
3132- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3133+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3134 #else
3135 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3136 #endif
3137@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3138 static int die_owner = -1;
3139 static unsigned int die_nest_count;
3140
3141+extern void gr_handle_kernel_exploit(void);
3142+
3143 static unsigned long oops_begin(void)
3144 {
3145 int cpu;
3146@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3147 panic("Fatal exception in interrupt");
3148 if (panic_on_oops)
3149 panic("Fatal exception");
3150+
3151+ gr_handle_kernel_exploit();
3152+
3153 if (signr)
3154 do_exit(signr);
3155 }
3156@@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3157 * The user helper at 0xffff0fe0 must be used instead.
3158 * (see entry-armv.S for details)
3159 */
3160+ pax_open_kernel();
3161 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3162+ pax_close_kernel();
3163 }
3164 return 0;
3165
3166@@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3167 kuser_init(vectors_base);
3168
3169 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3170- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3171+
3172+#ifndef CONFIG_PAX_MEMORY_UDEREF
3173+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3174+#endif
3175+
3176 #else /* ifndef CONFIG_CPU_V7M */
3177 /*
3178 * on V7-M there is no need to copy the vector table to a dedicated
3179diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3180index 7bcee5c..e2f3249 100644
3181--- a/arch/arm/kernel/vmlinux.lds.S
3182+++ b/arch/arm/kernel/vmlinux.lds.S
3183@@ -8,7 +8,11 @@
3184 #include <asm/thread_info.h>
3185 #include <asm/memory.h>
3186 #include <asm/page.h>
3187-
3188+
3189+#ifdef CONFIG_PAX_KERNEXEC
3190+#include <asm/pgtable.h>
3191+#endif
3192+
3193 #define PROC_INFO \
3194 . = ALIGN(4); \
3195 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3196@@ -34,7 +38,7 @@
3197 #endif
3198
3199 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3200- defined(CONFIG_GENERIC_BUG)
3201+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3202 #define ARM_EXIT_KEEP(x) x
3203 #define ARM_EXIT_DISCARD(x)
3204 #else
3205@@ -90,6 +94,11 @@ SECTIONS
3206 _text = .;
3207 HEAD_TEXT
3208 }
3209+
3210+#ifdef CONFIG_PAX_KERNEXEC
3211+ . = ALIGN(1<<SECTION_SHIFT);
3212+#endif
3213+
3214 .text : { /* Real text segment */
3215 _stext = .; /* Text and read-only data */
3216 __exception_text_start = .;
3217@@ -112,6 +121,8 @@ SECTIONS
3218 ARM_CPU_KEEP(PROC_INFO)
3219 }
3220
3221+ _etext = .; /* End of text section */
3222+
3223 RO_DATA(PAGE_SIZE)
3224
3225 . = ALIGN(4);
3226@@ -142,7 +153,9 @@ SECTIONS
3227
3228 NOTES
3229
3230- _etext = .; /* End of text and rodata section */
3231+#ifdef CONFIG_PAX_KERNEXEC
3232+ . = ALIGN(1<<SECTION_SHIFT);
3233+#endif
3234
3235 #ifndef CONFIG_XIP_KERNEL
3236 . = ALIGN(PAGE_SIZE);
3237@@ -220,6 +233,11 @@ SECTIONS
3238 . = PAGE_OFFSET + TEXT_OFFSET;
3239 #else
3240 __init_end = .;
3241+
3242+#ifdef CONFIG_PAX_KERNEXEC
3243+ . = ALIGN(1<<SECTION_SHIFT);
3244+#endif
3245+
3246 . = ALIGN(THREAD_SIZE);
3247 __data_loc = .;
3248 #endif
3249diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3250index bd18bb8..87ede26 100644
3251--- a/arch/arm/kvm/arm.c
3252+++ b/arch/arm/kvm/arm.c
3253@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3254 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3255
3256 /* The VMID used in the VTTBR */
3257-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3258+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3259 static u8 kvm_next_vmid;
3260 static DEFINE_SPINLOCK(kvm_vmid_lock);
3261
3262@@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3263 */
3264 static bool need_new_vmid_gen(struct kvm *kvm)
3265 {
3266- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3267+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3268 }
3269
3270 /**
3271@@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3272
3273 /* First user of a new VMID generation? */
3274 if (unlikely(kvm_next_vmid == 0)) {
3275- atomic64_inc(&kvm_vmid_gen);
3276+ atomic64_inc_unchecked(&kvm_vmid_gen);
3277 kvm_next_vmid = 1;
3278
3279 /*
3280@@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3281 kvm_call_hyp(__kvm_flush_vm_context);
3282 }
3283
3284- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3285+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3286 kvm->arch.vmid = kvm_next_vmid;
3287 kvm_next_vmid++;
3288
3289diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3290index 14a0d98..7771a7d 100644
3291--- a/arch/arm/lib/clear_user.S
3292+++ b/arch/arm/lib/clear_user.S
3293@@ -12,14 +12,14 @@
3294
3295 .text
3296
3297-/* Prototype: int __clear_user(void *addr, size_t sz)
3298+/* Prototype: int ___clear_user(void *addr, size_t sz)
3299 * Purpose : clear some user memory
3300 * Params : addr - user memory address to clear
3301 * : sz - number of bytes to clear
3302 * Returns : number of bytes NOT cleared
3303 */
3304 ENTRY(__clear_user_std)
3305-WEAK(__clear_user)
3306+WEAK(___clear_user)
3307 stmfd sp!, {r1, lr}
3308 mov r2, #0
3309 cmp r1, #4
3310@@ -44,7 +44,7 @@ WEAK(__clear_user)
3311 USER( strnebt r2, [r0])
3312 mov r0, #0
3313 ldmfd sp!, {r1, pc}
3314-ENDPROC(__clear_user)
3315+ENDPROC(___clear_user)
3316 ENDPROC(__clear_user_std)
3317
3318 .pushsection .fixup,"ax"
3319diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3320index 66a477a..bee61d3 100644
3321--- a/arch/arm/lib/copy_from_user.S
3322+++ b/arch/arm/lib/copy_from_user.S
3323@@ -16,7 +16,7 @@
3324 /*
3325 * Prototype:
3326 *
3327- * size_t __copy_from_user(void *to, const void *from, size_t n)
3328+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3329 *
3330 * Purpose:
3331 *
3332@@ -84,11 +84,11 @@
3333
3334 .text
3335
3336-ENTRY(__copy_from_user)
3337+ENTRY(___copy_from_user)
3338
3339 #include "copy_template.S"
3340
3341-ENDPROC(__copy_from_user)
3342+ENDPROC(___copy_from_user)
3343
3344 .pushsection .fixup,"ax"
3345 .align 0
3346diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3347index 6ee2f67..d1cce76 100644
3348--- a/arch/arm/lib/copy_page.S
3349+++ b/arch/arm/lib/copy_page.S
3350@@ -10,6 +10,7 @@
3351 * ASM optimised string functions
3352 */
3353 #include <linux/linkage.h>
3354+#include <linux/const.h>
3355 #include <asm/assembler.h>
3356 #include <asm/asm-offsets.h>
3357 #include <asm/cache.h>
3358diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3359index d066df6..df28194 100644
3360--- a/arch/arm/lib/copy_to_user.S
3361+++ b/arch/arm/lib/copy_to_user.S
3362@@ -16,7 +16,7 @@
3363 /*
3364 * Prototype:
3365 *
3366- * size_t __copy_to_user(void *to, const void *from, size_t n)
3367+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3368 *
3369 * Purpose:
3370 *
3371@@ -88,11 +88,11 @@
3372 .text
3373
3374 ENTRY(__copy_to_user_std)
3375-WEAK(__copy_to_user)
3376+WEAK(___copy_to_user)
3377
3378 #include "copy_template.S"
3379
3380-ENDPROC(__copy_to_user)
3381+ENDPROC(___copy_to_user)
3382 ENDPROC(__copy_to_user_std)
3383
3384 .pushsection .fixup,"ax"
3385diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3386index 7d08b43..f7ca7ea 100644
3387--- a/arch/arm/lib/csumpartialcopyuser.S
3388+++ b/arch/arm/lib/csumpartialcopyuser.S
3389@@ -57,8 +57,8 @@
3390 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3391 */
3392
3393-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3394-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3395+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3396+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3397
3398 #include "csumpartialcopygeneric.S"
3399
3400diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3401index 5306de3..aed6d03 100644
3402--- a/arch/arm/lib/delay.c
3403+++ b/arch/arm/lib/delay.c
3404@@ -28,7 +28,7 @@
3405 /*
3406 * Default to the loop-based delay implementation.
3407 */
3408-struct arm_delay_ops arm_delay_ops = {
3409+struct arm_delay_ops arm_delay_ops __read_only = {
3410 .delay = __loop_delay,
3411 .const_udelay = __loop_const_udelay,
3412 .udelay = __loop_udelay,
3413diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3414index 3e58d71..029817c 100644
3415--- a/arch/arm/lib/uaccess_with_memcpy.c
3416+++ b/arch/arm/lib/uaccess_with_memcpy.c
3417@@ -136,7 +136,7 @@ out:
3418 }
3419
3420 unsigned long
3421-__copy_to_user(void __user *to, const void *from, unsigned long n)
3422+___copy_to_user(void __user *to, const void *from, unsigned long n)
3423 {
3424 /*
3425 * This test is stubbed out of the main function above to keep
3426@@ -190,7 +190,7 @@ out:
3427 return n;
3428 }
3429
3430-unsigned long __clear_user(void __user *addr, unsigned long n)
3431+unsigned long ___clear_user(void __user *addr, unsigned long n)
3432 {
3433 /* See rational for this in __copy_to_user() above. */
3434 if (n < 64)
3435diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3436index f7ca97b..3d7e719 100644
3437--- a/arch/arm/mach-at91/setup.c
3438+++ b/arch/arm/mach-at91/setup.c
3439@@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3440
3441 desc->pfn = __phys_to_pfn(base);
3442 desc->length = length;
3443- desc->type = MT_MEMORY_RWX_NONCACHED;
3444+ desc->type = MT_MEMORY_RW_NONCACHED;
3445
3446 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3447 base, length, desc->virtual);
3448diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3449index f3407a5..bd4256f 100644
3450--- a/arch/arm/mach-kirkwood/common.c
3451+++ b/arch/arm/mach-kirkwood/common.c
3452@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3453 clk_gate_ops.disable(hw);
3454 }
3455
3456-static struct clk_ops clk_gate_fn_ops;
3457+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3458+{
3459+ return clk_gate_ops.is_enabled(hw);
3460+}
3461+
3462+static struct clk_ops clk_gate_fn_ops = {
3463+ .enable = clk_gate_fn_enable,
3464+ .disable = clk_gate_fn_disable,
3465+ .is_enabled = clk_gate_fn_is_enabled,
3466+};
3467
3468 static struct clk __init *clk_register_gate_fn(struct device *dev,
3469 const char *name,
3470@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3471 gate_fn->fn_en = fn_en;
3472 gate_fn->fn_dis = fn_dis;
3473
3474- /* ops is the gate ops, but with our enable/disable functions */
3475- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3476- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3477- clk_gate_fn_ops = clk_gate_ops;
3478- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3479- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3480- }
3481-
3482 clk = clk_register(dev, &gate_fn->gate.hw);
3483
3484 if (IS_ERR(clk))
3485diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3486index aead77a..a2253fa 100644
3487--- a/arch/arm/mach-omap2/board-n8x0.c
3488+++ b/arch/arm/mach-omap2/board-n8x0.c
3489@@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3490 }
3491 #endif
3492
3493-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3494+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3495 .late_init = n8x0_menelaus_late_init,
3496 };
3497
3498diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3499index ab43755..ccfa231 100644
3500--- a/arch/arm/mach-omap2/gpmc.c
3501+++ b/arch/arm/mach-omap2/gpmc.c
3502@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3503 };
3504
3505 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3506-static struct irq_chip gpmc_irq_chip;
3507 static int gpmc_irq_start;
3508
3509 static struct resource gpmc_mem_root;
3510@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3511
3512 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3513
3514+static struct irq_chip gpmc_irq_chip = {
3515+ .name = "gpmc",
3516+ .irq_startup = gpmc_irq_noop_ret,
3517+ .irq_enable = gpmc_irq_enable,
3518+ .irq_disable = gpmc_irq_disable,
3519+ .irq_shutdown = gpmc_irq_noop,
3520+ .irq_ack = gpmc_irq_noop,
3521+ .irq_mask = gpmc_irq_noop,
3522+ .irq_unmask = gpmc_irq_noop,
3523+
3524+};
3525+
3526 static int gpmc_setup_irq(void)
3527 {
3528 int i;
3529@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3530 return gpmc_irq_start;
3531 }
3532
3533- gpmc_irq_chip.name = "gpmc";
3534- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3535- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3536- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3537- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3538- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3539- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3540- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3541-
3542 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3543 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3544
3545diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3546index 667915d..2ee1219 100644
3547--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3548+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3549@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3550 int (*finish_suspend)(unsigned long cpu_state);
3551 void (*resume)(void);
3552 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3553-};
3554+} __no_const;
3555
3556 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3557 static struct powerdomain *mpuss_pd;
3558@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3559 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3560 {}
3561
3562-struct cpu_pm_ops omap_pm_ops = {
3563+static struct cpu_pm_ops omap_pm_ops __read_only = {
3564 .finish_suspend = default_finish_suspend,
3565 .resume = dummy_cpu_resume,
3566 .scu_prepare = dummy_scu_prepare,
3567diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3568index 3664562..72f85c6 100644
3569--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3570+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3571@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3572 return NOTIFY_OK;
3573 }
3574
3575-static struct notifier_block __refdata irq_hotplug_notifier = {
3576+static struct notifier_block irq_hotplug_notifier = {
3577 .notifier_call = irq_cpu_hotplug_notify,
3578 };
3579
3580diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3581index 01ef59d..32ae28a8 100644
3582--- a/arch/arm/mach-omap2/omap_device.c
3583+++ b/arch/arm/mach-omap2/omap_device.c
3584@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3585 struct platform_device __init *omap_device_build(const char *pdev_name,
3586 int pdev_id,
3587 struct omap_hwmod *oh,
3588- void *pdata, int pdata_len)
3589+ const void *pdata, int pdata_len)
3590 {
3591 struct omap_hwmod *ohs[] = { oh };
3592
3593@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3594 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3595 int pdev_id,
3596 struct omap_hwmod **ohs,
3597- int oh_cnt, void *pdata,
3598+ int oh_cnt, const void *pdata,
3599 int pdata_len)
3600 {
3601 int ret = -ENOMEM;
3602diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3603index 78c02b3..c94109a 100644
3604--- a/arch/arm/mach-omap2/omap_device.h
3605+++ b/arch/arm/mach-omap2/omap_device.h
3606@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3607 /* Core code interface */
3608
3609 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3610- struct omap_hwmod *oh, void *pdata,
3611+ struct omap_hwmod *oh, const void *pdata,
3612 int pdata_len);
3613
3614 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3615 struct omap_hwmod **oh, int oh_cnt,
3616- void *pdata, int pdata_len);
3617+ const void *pdata, int pdata_len);
3618
3619 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3620 struct omap_hwmod **ohs, int oh_cnt);
3621diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3622index 66c60fe..c78950d 100644
3623--- a/arch/arm/mach-omap2/omap_hwmod.c
3624+++ b/arch/arm/mach-omap2/omap_hwmod.c
3625@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3626 int (*init_clkdm)(struct omap_hwmod *oh);
3627 void (*update_context_lost)(struct omap_hwmod *oh);
3628 int (*get_context_lost)(struct omap_hwmod *oh);
3629-};
3630+} __no_const;
3631
3632 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3633-static struct omap_hwmod_soc_ops soc_ops;
3634+static struct omap_hwmod_soc_ops soc_ops __read_only;
3635
3636 /* omap_hwmod_list contains all registered struct omap_hwmods */
3637 static LIST_HEAD(omap_hwmod_list);
3638diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3639index 95fee54..cfa9cf1 100644
3640--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3641+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3642@@ -10,6 +10,7 @@
3643
3644 #include <linux/kernel.h>
3645 #include <linux/init.h>
3646+#include <asm/pgtable.h>
3647
3648 #include "powerdomain.h"
3649
3650@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3651
3652 void __init am43xx_powerdomains_init(void)
3653 {
3654- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3655+ pax_open_kernel();
3656+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3657+ pax_close_kernel();
3658 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3659 pwrdm_register_pwrdms(powerdomains_am43xx);
3660 pwrdm_complete_init();
3661diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3662index d15c7bb..b2d1f0c 100644
3663--- a/arch/arm/mach-omap2/wd_timer.c
3664+++ b/arch/arm/mach-omap2/wd_timer.c
3665@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3666 struct omap_hwmod *oh;
3667 char *oh_name = "wd_timer2";
3668 char *dev_name = "omap_wdt";
3669- struct omap_wd_timer_platform_data pdata;
3670+ static struct omap_wd_timer_platform_data pdata = {
3671+ .read_reset_sources = prm_read_reset_sources
3672+ };
3673
3674 if (!cpu_class_is_omap2() || of_have_populated_dt())
3675 return 0;
3676@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3677 return -EINVAL;
3678 }
3679
3680- pdata.read_reset_sources = prm_read_reset_sources;
3681-
3682 pdev = omap_device_build(dev_name, id, oh, &pdata,
3683 sizeof(struct omap_wd_timer_platform_data));
3684 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3685diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3686index b82dcae..44ee5b6 100644
3687--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3688+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3689@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3690 bool entered_lp2 = false;
3691
3692 if (tegra_pending_sgi())
3693- ACCESS_ONCE(abort_flag) = true;
3694+ ACCESS_ONCE_RW(abort_flag) = true;
3695
3696 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3697
3698diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3699index 2dea8b5..6499da2 100644
3700--- a/arch/arm/mach-ux500/setup.h
3701+++ b/arch/arm/mach-ux500/setup.h
3702@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3703 .type = MT_DEVICE, \
3704 }
3705
3706-#define __MEM_DEV_DESC(x, sz) { \
3707- .virtual = IO_ADDRESS(x), \
3708- .pfn = __phys_to_pfn(x), \
3709- .length = sz, \
3710- .type = MT_MEMORY_RWX, \
3711-}
3712-
3713 extern struct smp_operations ux500_smp_ops;
3714 extern void ux500_cpu_die(unsigned int cpu);
3715
3716diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3717index ca8ecde..58ba893 100644
3718--- a/arch/arm/mm/Kconfig
3719+++ b/arch/arm/mm/Kconfig
3720@@ -446,6 +446,7 @@ config CPU_32v5
3721
3722 config CPU_32v6
3723 bool
3724+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3725 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3726
3727 config CPU_32v6K
3728@@ -600,6 +601,7 @@ config CPU_CP15_MPU
3729
3730 config CPU_USE_DOMAINS
3731 bool
3732+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3733 help
3734 This option enables or disables the use of domain switching
3735 via the set_fs() function.
3736@@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3737 config KUSER_HELPERS
3738 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3739 default y
3740+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3741 help
3742 Warning: disabling this option may break user programs.
3743
3744@@ -811,7 +814,7 @@ config KUSER_HELPERS
3745 See Documentation/arm/kernel_user_helpers.txt for details.
3746
3747 However, the fixed address nature of these helpers can be used
3748- by ROP (return orientated programming) authors when creating
3749+ by ROP (Return Oriented Programming) authors when creating
3750 exploits.
3751
3752 If all of the binaries and libraries which run on your platform
3753diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3754index 9240364..a2b8cf3 100644
3755--- a/arch/arm/mm/alignment.c
3756+++ b/arch/arm/mm/alignment.c
3757@@ -212,10 +212,12 @@ union offset_union {
3758 #define __get16_unaligned_check(ins,val,addr) \
3759 do { \
3760 unsigned int err = 0, v, a = addr; \
3761+ pax_open_userland(); \
3762 __get8_unaligned_check(ins,v,a,err); \
3763 val = v << ((BE) ? 8 : 0); \
3764 __get8_unaligned_check(ins,v,a,err); \
3765 val |= v << ((BE) ? 0 : 8); \
3766+ pax_close_userland(); \
3767 if (err) \
3768 goto fault; \
3769 } while (0)
3770@@ -229,6 +231,7 @@ union offset_union {
3771 #define __get32_unaligned_check(ins,val,addr) \
3772 do { \
3773 unsigned int err = 0, v, a = addr; \
3774+ pax_open_userland(); \
3775 __get8_unaligned_check(ins,v,a,err); \
3776 val = v << ((BE) ? 24 : 0); \
3777 __get8_unaligned_check(ins,v,a,err); \
3778@@ -237,6 +240,7 @@ union offset_union {
3779 val |= v << ((BE) ? 8 : 16); \
3780 __get8_unaligned_check(ins,v,a,err); \
3781 val |= v << ((BE) ? 0 : 24); \
3782+ pax_close_userland(); \
3783 if (err) \
3784 goto fault; \
3785 } while (0)
3786@@ -250,6 +254,7 @@ union offset_union {
3787 #define __put16_unaligned_check(ins,val,addr) \
3788 do { \
3789 unsigned int err = 0, v = val, a = addr; \
3790+ pax_open_userland(); \
3791 __asm__( FIRST_BYTE_16 \
3792 ARM( "1: "ins" %1, [%2], #1\n" ) \
3793 THUMB( "1: "ins" %1, [%2]\n" ) \
3794@@ -269,6 +274,7 @@ union offset_union {
3795 " .popsection\n" \
3796 : "=r" (err), "=&r" (v), "=&r" (a) \
3797 : "0" (err), "1" (v), "2" (a)); \
3798+ pax_close_userland(); \
3799 if (err) \
3800 goto fault; \
3801 } while (0)
3802@@ -282,6 +288,7 @@ union offset_union {
3803 #define __put32_unaligned_check(ins,val,addr) \
3804 do { \
3805 unsigned int err = 0, v = val, a = addr; \
3806+ pax_open_userland(); \
3807 __asm__( FIRST_BYTE_32 \
3808 ARM( "1: "ins" %1, [%2], #1\n" ) \
3809 THUMB( "1: "ins" %1, [%2]\n" ) \
3810@@ -311,6 +318,7 @@ union offset_union {
3811 " .popsection\n" \
3812 : "=r" (err), "=&r" (v), "=&r" (a) \
3813 : "0" (err), "1" (v), "2" (a)); \
3814+ pax_close_userland(); \
3815 if (err) \
3816 goto fault; \
3817 } while (0)
3818diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3819index 7abde2c..9df495f 100644
3820--- a/arch/arm/mm/cache-l2x0.c
3821+++ b/arch/arm/mm/cache-l2x0.c
3822@@ -46,7 +46,7 @@ struct l2x0_of_data {
3823 void (*setup)(const struct device_node *, u32 *, u32 *);
3824 void (*save)(void);
3825 struct outer_cache_fns outer_cache;
3826-};
3827+} __do_const;
3828
3829 static bool of_init = false;
3830
3831diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3832index 6eb97b3..ac509f6 100644
3833--- a/arch/arm/mm/context.c
3834+++ b/arch/arm/mm/context.c
3835@@ -43,7 +43,7 @@
3836 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3837
3838 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3839-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3840+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3841 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3842
3843 static DEFINE_PER_CPU(atomic64_t, active_asids);
3844@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3845 {
3846 static u32 cur_idx = 1;
3847 u64 asid = atomic64_read(&mm->context.id);
3848- u64 generation = atomic64_read(&asid_generation);
3849+ u64 generation = atomic64_read_unchecked(&asid_generation);
3850
3851 if (asid != 0 && is_reserved_asid(asid)) {
3852 /*
3853@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3854 */
3855 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3856 if (asid == NUM_USER_ASIDS) {
3857- generation = atomic64_add_return(ASID_FIRST_VERSION,
3858+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3859 &asid_generation);
3860 flush_context(cpu);
3861 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3862@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3863 cpu_set_reserved_ttbr0();
3864
3865 asid = atomic64_read(&mm->context.id);
3866- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3867+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3868 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3869 goto switch_mm_fastpath;
3870
3871 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3872 /* Check that our ASID belongs to the current generation. */
3873 asid = atomic64_read(&mm->context.id);
3874- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3875+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3876 asid = new_context(mm, cpu);
3877 atomic64_set(&mm->context.id, asid);
3878 }
3879diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3880index eb8830a..5360ce7 100644
3881--- a/arch/arm/mm/fault.c
3882+++ b/arch/arm/mm/fault.c
3883@@ -25,6 +25,7 @@
3884 #include <asm/system_misc.h>
3885 #include <asm/system_info.h>
3886 #include <asm/tlbflush.h>
3887+#include <asm/sections.h>
3888
3889 #include "fault.h"
3890
3891@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3892 if (fixup_exception(regs))
3893 return;
3894
3895+#ifdef CONFIG_PAX_MEMORY_UDEREF
3896+ if (addr < TASK_SIZE) {
3897+ if (current->signal->curr_ip)
3898+ 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),
3899+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3900+ else
3901+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3902+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3903+ }
3904+#endif
3905+
3906+#ifdef CONFIG_PAX_KERNEXEC
3907+ if ((fsr & FSR_WRITE) &&
3908+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3909+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3910+ {
3911+ if (current->signal->curr_ip)
3912+ 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),
3913+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3914+ else
3915+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3916+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3917+ }
3918+#endif
3919+
3920 /*
3921 * No handler, we'll have to terminate things with extreme prejudice.
3922 */
3923@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3924 }
3925 #endif
3926
3927+#ifdef CONFIG_PAX_PAGEEXEC
3928+ if (fsr & FSR_LNX_PF) {
3929+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3930+ do_group_exit(SIGKILL);
3931+ }
3932+#endif
3933+
3934 tsk->thread.address = addr;
3935 tsk->thread.error_code = fsr;
3936 tsk->thread.trap_no = 14;
3937@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3938 }
3939 #endif /* CONFIG_MMU */
3940
3941+#ifdef CONFIG_PAX_PAGEEXEC
3942+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3943+{
3944+ long i;
3945+
3946+ printk(KERN_ERR "PAX: bytes at PC: ");
3947+ for (i = 0; i < 20; i++) {
3948+ unsigned char c;
3949+ if (get_user(c, (__force unsigned char __user *)pc+i))
3950+ printk(KERN_CONT "?? ");
3951+ else
3952+ printk(KERN_CONT "%02x ", c);
3953+ }
3954+ printk("\n");
3955+
3956+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3957+ for (i = -1; i < 20; i++) {
3958+ unsigned long c;
3959+ if (get_user(c, (__force unsigned long __user *)sp+i))
3960+ printk(KERN_CONT "???????? ");
3961+ else
3962+ printk(KERN_CONT "%08lx ", c);
3963+ }
3964+ printk("\n");
3965+}
3966+#endif
3967+
3968 /*
3969 * First Level Translation Fault Handler
3970 *
3971@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3972 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3973 struct siginfo info;
3974
3975+#ifdef CONFIG_PAX_MEMORY_UDEREF
3976+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3977+ if (current->signal->curr_ip)
3978+ 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),
3979+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3980+ else
3981+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3982+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3983+ goto die;
3984+ }
3985+#endif
3986+
3987 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3988 return;
3989
3990+die:
3991 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3992 inf->name, fsr, addr);
3993
3994@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3995 ifsr_info[nr].name = name;
3996 }
3997
3998+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3999+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4000+
4001 asmlinkage void __exception
4002 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4003 {
4004 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4005 struct siginfo info;
4006+ unsigned long pc = instruction_pointer(regs);
4007+
4008+ if (user_mode(regs)) {
4009+ unsigned long sigpage = current->mm->context.sigpage;
4010+
4011+ if (sigpage <= pc && pc < sigpage + 7*4) {
4012+ if (pc < sigpage + 3*4)
4013+ sys_sigreturn(regs);
4014+ else
4015+ sys_rt_sigreturn(regs);
4016+ return;
4017+ }
4018+ if (pc == 0xffff0f60UL) {
4019+ /*
4020+ * PaX: __kuser_cmpxchg64 emulation
4021+ */
4022+ // TODO
4023+ //regs->ARM_pc = regs->ARM_lr;
4024+ //return;
4025+ }
4026+ if (pc == 0xffff0fa0UL) {
4027+ /*
4028+ * PaX: __kuser_memory_barrier emulation
4029+ */
4030+ // dmb(); implied by the exception
4031+ regs->ARM_pc = regs->ARM_lr;
4032+ return;
4033+ }
4034+ if (pc == 0xffff0fc0UL) {
4035+ /*
4036+ * PaX: __kuser_cmpxchg emulation
4037+ */
4038+ // TODO
4039+ //long new;
4040+ //int op;
4041+
4042+ //op = FUTEX_OP_SET << 28;
4043+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4044+ //regs->ARM_r0 = old != new;
4045+ //regs->ARM_pc = regs->ARM_lr;
4046+ //return;
4047+ }
4048+ if (pc == 0xffff0fe0UL) {
4049+ /*
4050+ * PaX: __kuser_get_tls emulation
4051+ */
4052+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4053+ regs->ARM_pc = regs->ARM_lr;
4054+ return;
4055+ }
4056+ }
4057+
4058+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4059+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4060+ if (current->signal->curr_ip)
4061+ 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),
4062+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4063+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4064+ else
4065+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4066+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4067+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4068+ goto die;
4069+ }
4070+#endif
4071+
4072+#ifdef CONFIG_PAX_REFCOUNT
4073+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4074+ unsigned int bkpt;
4075+
4076+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4077+ current->thread.error_code = ifsr;
4078+ current->thread.trap_no = 0;
4079+ pax_report_refcount_overflow(regs);
4080+ fixup_exception(regs);
4081+ return;
4082+ }
4083+ }
4084+#endif
4085
4086 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4087 return;
4088
4089+die:
4090 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4091 inf->name, ifsr, addr);
4092
4093diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4094index cf08bdf..772656c 100644
4095--- a/arch/arm/mm/fault.h
4096+++ b/arch/arm/mm/fault.h
4097@@ -3,6 +3,7 @@
4098
4099 /*
4100 * Fault status register encodings. We steal bit 31 for our own purposes.
4101+ * Set when the FSR value is from an instruction fault.
4102 */
4103 #define FSR_LNX_PF (1 << 31)
4104 #define FSR_WRITE (1 << 11)
4105@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4106 }
4107 #endif
4108
4109+/* valid for LPAE and !LPAE */
4110+static inline int is_xn_fault(unsigned int fsr)
4111+{
4112+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4113+}
4114+
4115+static inline int is_domain_fault(unsigned int fsr)
4116+{
4117+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4118+}
4119+
4120 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4121 unsigned long search_exception_table(unsigned long addr);
4122
4123diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4124index 804d615..fcec50a 100644
4125--- a/arch/arm/mm/init.c
4126+++ b/arch/arm/mm/init.c
4127@@ -30,6 +30,8 @@
4128 #include <asm/setup.h>
4129 #include <asm/tlb.h>
4130 #include <asm/fixmap.h>
4131+#include <asm/system_info.h>
4132+#include <asm/cp15.h>
4133
4134 #include <asm/mach/arch.h>
4135 #include <asm/mach/map.h>
4136@@ -625,7 +627,46 @@ void free_initmem(void)
4137 {
4138 #ifdef CONFIG_HAVE_TCM
4139 extern char __tcm_start, __tcm_end;
4140+#endif
4141
4142+#ifdef CONFIG_PAX_KERNEXEC
4143+ unsigned long addr;
4144+ pgd_t *pgd;
4145+ pud_t *pud;
4146+ pmd_t *pmd;
4147+ int cpu_arch = cpu_architecture();
4148+ unsigned int cr = get_cr();
4149+
4150+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4151+ /* make pages tables, etc before .text NX */
4152+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4153+ pgd = pgd_offset_k(addr);
4154+ pud = pud_offset(pgd, addr);
4155+ pmd = pmd_offset(pud, addr);
4156+ __section_update(pmd, addr, PMD_SECT_XN);
4157+ }
4158+ /* make init NX */
4159+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4160+ pgd = pgd_offset_k(addr);
4161+ pud = pud_offset(pgd, addr);
4162+ pmd = pmd_offset(pud, addr);
4163+ __section_update(pmd, addr, PMD_SECT_XN);
4164+ }
4165+ /* make kernel code/rodata RX */
4166+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4167+ pgd = pgd_offset_k(addr);
4168+ pud = pud_offset(pgd, addr);
4169+ pmd = pmd_offset(pud, addr);
4170+#ifdef CONFIG_ARM_LPAE
4171+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4172+#else
4173+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4174+#endif
4175+ }
4176+ }
4177+#endif
4178+
4179+#ifdef CONFIG_HAVE_TCM
4180 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4181 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4182 #endif
4183diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4184index f9c32ba..8540068 100644
4185--- a/arch/arm/mm/ioremap.c
4186+++ b/arch/arm/mm/ioremap.c
4187@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4188 unsigned int mtype;
4189
4190 if (cached)
4191- mtype = MT_MEMORY_RWX;
4192+ mtype = MT_MEMORY_RX;
4193 else
4194- mtype = MT_MEMORY_RWX_NONCACHED;
4195+ mtype = MT_MEMORY_RX_NONCACHED;
4196
4197 return __arm_ioremap_caller(phys_addr, size, mtype,
4198 __builtin_return_address(0));
4199diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4200index 5e85ed3..b10a7ed 100644
4201--- a/arch/arm/mm/mmap.c
4202+++ b/arch/arm/mm/mmap.c
4203@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4204 struct vm_area_struct *vma;
4205 int do_align = 0;
4206 int aliasing = cache_is_vipt_aliasing();
4207+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4208 struct vm_unmapped_area_info info;
4209
4210 /*
4211@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4212 if (len > TASK_SIZE)
4213 return -ENOMEM;
4214
4215+#ifdef CONFIG_PAX_RANDMMAP
4216+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4217+#endif
4218+
4219 if (addr) {
4220 if (do_align)
4221 addr = COLOUR_ALIGN(addr, pgoff);
4222@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4223 addr = PAGE_ALIGN(addr);
4224
4225 vma = find_vma(mm, addr);
4226- if (TASK_SIZE - len >= addr &&
4227- (!vma || addr + len <= vma->vm_start))
4228+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4229 return addr;
4230 }
4231
4232@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4233 info.high_limit = TASK_SIZE;
4234 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4235 info.align_offset = pgoff << PAGE_SHIFT;
4236+ info.threadstack_offset = offset;
4237 return vm_unmapped_area(&info);
4238 }
4239
4240@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4241 unsigned long addr = addr0;
4242 int do_align = 0;
4243 int aliasing = cache_is_vipt_aliasing();
4244+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4245 struct vm_unmapped_area_info info;
4246
4247 /*
4248@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4249 return addr;
4250 }
4251
4252+#ifdef CONFIG_PAX_RANDMMAP
4253+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4254+#endif
4255+
4256 /* requesting a specific address */
4257 if (addr) {
4258 if (do_align)
4259@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4260 else
4261 addr = PAGE_ALIGN(addr);
4262 vma = find_vma(mm, addr);
4263- if (TASK_SIZE - len >= addr &&
4264- (!vma || addr + len <= vma->vm_start))
4265+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4266 return addr;
4267 }
4268
4269@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4270 info.high_limit = mm->mmap_base;
4271 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4272 info.align_offset = pgoff << PAGE_SHIFT;
4273+ info.threadstack_offset = offset;
4274 addr = vm_unmapped_area(&info);
4275
4276 /*
4277@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4278 {
4279 unsigned long random_factor = 0UL;
4280
4281+#ifdef CONFIG_PAX_RANDMMAP
4282+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4283+#endif
4284+
4285 /* 8 bits of randomness in 20 address space bits */
4286 if ((current->flags & PF_RANDOMIZE) &&
4287 !(current->personality & ADDR_NO_RANDOMIZE))
4288@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4289
4290 if (mmap_is_legacy()) {
4291 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4292+
4293+#ifdef CONFIG_PAX_RANDMMAP
4294+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4295+ mm->mmap_base += mm->delta_mmap;
4296+#endif
4297+
4298 mm->get_unmapped_area = arch_get_unmapped_area;
4299 } else {
4300 mm->mmap_base = mmap_base(random_factor);
4301+
4302+#ifdef CONFIG_PAX_RANDMMAP
4303+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4304+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4305+#endif
4306+
4307 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4308 }
4309 }
4310diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4311index b68c6b2..f66c492 100644
4312--- a/arch/arm/mm/mmu.c
4313+++ b/arch/arm/mm/mmu.c
4314@@ -39,6 +39,22 @@
4315 #include "mm.h"
4316 #include "tcm.h"
4317
4318+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4319+void modify_domain(unsigned int dom, unsigned int type)
4320+{
4321+ struct thread_info *thread = current_thread_info();
4322+ unsigned int domain = thread->cpu_domain;
4323+ /*
4324+ * DOMAIN_MANAGER might be defined to some other value,
4325+ * use the arch-defined constant
4326+ */
4327+ domain &= ~domain_val(dom, 3);
4328+ thread->cpu_domain = domain | domain_val(dom, type);
4329+ set_domain(thread->cpu_domain);
4330+}
4331+EXPORT_SYMBOL(modify_domain);
4332+#endif
4333+
4334 /*
4335 * empty_zero_page is a special page that is used for
4336 * zero-initialized data and COW.
4337@@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4338 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4339 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4340
4341-static struct mem_type mem_types[] = {
4342+#ifdef CONFIG_PAX_KERNEXEC
4343+#define L_PTE_KERNEXEC L_PTE_RDONLY
4344+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4345+#else
4346+#define L_PTE_KERNEXEC L_PTE_DIRTY
4347+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4348+#endif
4349+
4350+static struct mem_type mem_types[] __read_only = {
4351 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4352 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4353 L_PTE_SHARED,
4354@@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4355 .prot_sect = PROT_SECT_DEVICE,
4356 .domain = DOMAIN_IO,
4357 },
4358- [MT_UNCACHED] = {
4359+ [MT_UNCACHED_RW] = {
4360 .prot_pte = PROT_PTE_DEVICE,
4361 .prot_l1 = PMD_TYPE_TABLE,
4362 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4363 .domain = DOMAIN_IO,
4364 },
4365- [MT_CACHECLEAN] = {
4366- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4367+ [MT_CACHECLEAN_RO] = {
4368+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4369 .domain = DOMAIN_KERNEL,
4370 },
4371 #ifndef CONFIG_ARM_LPAE
4372- [MT_MINICLEAN] = {
4373- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4374+ [MT_MINICLEAN_RO] = {
4375+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4376 .domain = DOMAIN_KERNEL,
4377 },
4378 #endif
4379@@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4380 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4381 L_PTE_RDONLY,
4382 .prot_l1 = PMD_TYPE_TABLE,
4383- .domain = DOMAIN_USER,
4384+ .domain = DOMAIN_VECTORS,
4385 },
4386 [MT_HIGH_VECTORS] = {
4387 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4388 L_PTE_USER | L_PTE_RDONLY,
4389 .prot_l1 = PMD_TYPE_TABLE,
4390- .domain = DOMAIN_USER,
4391+ .domain = DOMAIN_VECTORS,
4392 },
4393- [MT_MEMORY_RWX] = {
4394+ [__MT_MEMORY_RWX] = {
4395 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4396 .prot_l1 = PMD_TYPE_TABLE,
4397 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4398@@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4399 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4400 .domain = DOMAIN_KERNEL,
4401 },
4402- [MT_ROM] = {
4403- .prot_sect = PMD_TYPE_SECT,
4404+ [MT_MEMORY_RX] = {
4405+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4406+ .prot_l1 = PMD_TYPE_TABLE,
4407+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4408+ .domain = DOMAIN_KERNEL,
4409+ },
4410+ [MT_ROM_RX] = {
4411+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4412 .domain = DOMAIN_KERNEL,
4413 },
4414- [MT_MEMORY_RWX_NONCACHED] = {
4415+ [MT_MEMORY_RW_NONCACHED] = {
4416 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4417 L_PTE_MT_BUFFERABLE,
4418 .prot_l1 = PMD_TYPE_TABLE,
4419 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4420 .domain = DOMAIN_KERNEL,
4421 },
4422+ [MT_MEMORY_RX_NONCACHED] = {
4423+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4424+ L_PTE_MT_BUFFERABLE,
4425+ .prot_l1 = PMD_TYPE_TABLE,
4426+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4427+ .domain = DOMAIN_KERNEL,
4428+ },
4429 [MT_MEMORY_RW_DTCM] = {
4430 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4431 L_PTE_XN,
4432@@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4433 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4434 .domain = DOMAIN_KERNEL,
4435 },
4436- [MT_MEMORY_RWX_ITCM] = {
4437- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4438+ [MT_MEMORY_RX_ITCM] = {
4439+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4440 .prot_l1 = PMD_TYPE_TABLE,
4441+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4442 .domain = DOMAIN_KERNEL,
4443 },
4444 [MT_MEMORY_RW_SO] = {
4445@@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4446 * Mark cache clean areas and XIP ROM read only
4447 * from SVC mode and no access from userspace.
4448 */
4449- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4450- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4451- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4452+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4453+#ifdef CONFIG_PAX_KERNEXEC
4454+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4455+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4456+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4457+#endif
4458+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4459+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4460 #endif
4461
4462 if (is_smp()) {
4463@@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4464 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4465 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4466 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4467- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4468- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4469+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4470+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4471 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4472 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4473+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4474+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4475 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4476- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4477- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4478+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4479+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4480+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4481+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4482 }
4483 }
4484
4485@@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4486 if (cpu_arch >= CPU_ARCH_ARMv6) {
4487 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4488 /* Non-cacheable Normal is XCB = 001 */
4489- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4490+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4491+ PMD_SECT_BUFFERED;
4492+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4493 PMD_SECT_BUFFERED;
4494 } else {
4495 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4496- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4497+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4498+ PMD_SECT_TEX(1);
4499+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4500 PMD_SECT_TEX(1);
4501 }
4502 } else {
4503- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4504+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4505+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4506 }
4507
4508 #ifdef CONFIG_ARM_LPAE
4509@@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4510 vecs_pgprot |= PTE_EXT_AF;
4511 #endif
4512
4513+ user_pgprot |= __supported_pte_mask;
4514+
4515 for (i = 0; i < 16; i++) {
4516 pteval_t v = pgprot_val(protection_map[i]);
4517 protection_map[i] = __pgprot(v | user_pgprot);
4518@@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4519
4520 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4521 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4522- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4523- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4524+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4525+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4526 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4527 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4528+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4529+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4530 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4531- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4532- mem_types[MT_ROM].prot_sect |= cp->pmd;
4533+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4534+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4535+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4536
4537 switch (cp->pmd) {
4538 case PMD_SECT_WT:
4539- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4540+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4541 break;
4542 case PMD_SECT_WB:
4543 case PMD_SECT_WBWA:
4544- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4545+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4546 break;
4547 }
4548 pr_info("Memory policy: %sData cache %s\n",
4549@@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4550 return;
4551 }
4552
4553- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4554+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4555 md->virtual >= PAGE_OFFSET &&
4556 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4557 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4558@@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4559 * called function. This means you can't use any function or debugging
4560 * method which may touch any device, otherwise the kernel _will_ crash.
4561 */
4562+
4563+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4564+
4565 static void __init devicemaps_init(const struct machine_desc *mdesc)
4566 {
4567 struct map_desc map;
4568 unsigned long addr;
4569- void *vectors;
4570
4571- /*
4572- * Allocate the vector page early.
4573- */
4574- vectors = early_alloc(PAGE_SIZE * 2);
4575-
4576- early_trap_init(vectors);
4577+ early_trap_init(&vectors);
4578
4579 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4580 pmd_clear(pmd_off_k(addr));
4581@@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4582 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4583 map.virtual = MODULES_VADDR;
4584 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4585- map.type = MT_ROM;
4586+ map.type = MT_ROM_RX;
4587 create_mapping(&map);
4588 #endif
4589
4590@@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4591 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4592 map.virtual = FLUSH_BASE;
4593 map.length = SZ_1M;
4594- map.type = MT_CACHECLEAN;
4595+ map.type = MT_CACHECLEAN_RO;
4596 create_mapping(&map);
4597 #endif
4598 #ifdef FLUSH_BASE_MINICACHE
4599 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4600 map.virtual = FLUSH_BASE_MINICACHE;
4601 map.length = SZ_1M;
4602- map.type = MT_MINICLEAN;
4603+ map.type = MT_MINICLEAN_RO;
4604 create_mapping(&map);
4605 #endif
4606
4607@@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4608 * location (0xffff0000). If we aren't using high-vectors, also
4609 * create a mapping at the low-vectors virtual address.
4610 */
4611- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4612+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4613 map.virtual = 0xffff0000;
4614 map.length = PAGE_SIZE;
4615 #ifdef CONFIG_KUSER_HELPERS
4616@@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4617 static void __init map_lowmem(void)
4618 {
4619 struct memblock_region *reg;
4620+#ifndef CONFIG_PAX_KERNEXEC
4621 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4622 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4623+#endif
4624
4625 /* Map all the lowmem memory banks. */
4626 for_each_memblock(memory, reg) {
4627@@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4628 if (start >= end)
4629 break;
4630
4631+#ifdef CONFIG_PAX_KERNEXEC
4632+ map.pfn = __phys_to_pfn(start);
4633+ map.virtual = __phys_to_virt(start);
4634+ map.length = end - start;
4635+
4636+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4637+ struct map_desc kernel;
4638+ struct map_desc initmap;
4639+
4640+ /* when freeing initmem we will make this RW */
4641+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4642+ initmap.virtual = (unsigned long)__init_begin;
4643+ initmap.length = _sdata - __init_begin;
4644+ initmap.type = __MT_MEMORY_RWX;
4645+ create_mapping(&initmap);
4646+
4647+ /* when freeing initmem we will make this RX */
4648+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4649+ kernel.virtual = (unsigned long)_stext;
4650+ kernel.length = __init_begin - _stext;
4651+ kernel.type = __MT_MEMORY_RWX;
4652+ create_mapping(&kernel);
4653+
4654+ if (map.virtual < (unsigned long)_stext) {
4655+ map.length = (unsigned long)_stext - map.virtual;
4656+ map.type = __MT_MEMORY_RWX;
4657+ create_mapping(&map);
4658+ }
4659+
4660+ map.pfn = __phys_to_pfn(__pa(_sdata));
4661+ map.virtual = (unsigned long)_sdata;
4662+ map.length = end - __pa(_sdata);
4663+ }
4664+
4665+ map.type = MT_MEMORY_RW;
4666+ create_mapping(&map);
4667+#else
4668 if (end < kernel_x_start || start >= kernel_x_end) {
4669 map.pfn = __phys_to_pfn(start);
4670 map.virtual = __phys_to_virt(start);
4671 map.length = end - start;
4672- map.type = MT_MEMORY_RWX;
4673+ map.type = __MT_MEMORY_RWX;
4674
4675 create_mapping(&map);
4676 } else {
4677@@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4678 map.pfn = __phys_to_pfn(kernel_x_start);
4679 map.virtual = __phys_to_virt(kernel_x_start);
4680 map.length = kernel_x_end - kernel_x_start;
4681- map.type = MT_MEMORY_RWX;
4682+ map.type = __MT_MEMORY_RWX;
4683
4684 create_mapping(&map);
4685
4686@@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4687 create_mapping(&map);
4688 }
4689 }
4690+#endif
4691 }
4692 }
4693
4694diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4695index 5b217f4..c23f40e 100644
4696--- a/arch/arm/plat-iop/setup.c
4697+++ b/arch/arm/plat-iop/setup.c
4698@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4699 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4700 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4701 .length = IOP3XX_PERIPHERAL_SIZE,
4702- .type = MT_UNCACHED,
4703+ .type = MT_UNCACHED_RW,
4704 },
4705 };
4706
4707diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4708index a5bc92d..0bb4730 100644
4709--- a/arch/arm/plat-omap/sram.c
4710+++ b/arch/arm/plat-omap/sram.c
4711@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4712 * Looks like we need to preserve some bootloader code at the
4713 * beginning of SRAM for jumping to flash for reboot to work...
4714 */
4715+ pax_open_kernel();
4716 memset_io(omap_sram_base + omap_sram_skip, 0,
4717 omap_sram_size - omap_sram_skip);
4718+ pax_close_kernel();
4719 }
4720diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4721index ce6d763..cfea917 100644
4722--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4723+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4724@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4725 int (*started)(unsigned ch);
4726 int (*flush)(unsigned ch);
4727 int (*stop)(unsigned ch);
4728-};
4729+} __no_const;
4730
4731 extern void *samsung_dmadev_get_ops(void);
4732 extern void *s3c_dma_get_ops(void);
4733diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4734index 409ca37..10c87ad 100644
4735--- a/arch/arm64/include/asm/barrier.h
4736+++ b/arch/arm64/include/asm/barrier.h
4737@@ -40,7 +40,7 @@
4738 do { \
4739 compiletime_assert_atomic_type(*p); \
4740 smp_mb(); \
4741- ACCESS_ONCE(*p) = (v); \
4742+ ACCESS_ONCE_RW(*p) = (v); \
4743 } while (0)
4744
4745 #define smp_load_acquire(p) \
4746diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4747index 6c0f684..5faea9d 100644
4748--- a/arch/arm64/include/asm/uaccess.h
4749+++ b/arch/arm64/include/asm/uaccess.h
4750@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4751 flag; \
4752 })
4753
4754+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4755 #define access_ok(type, addr, size) __range_ok(addr, size)
4756 #define user_addr_max get_fs
4757
4758diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4759index c3a58a1..78fbf54 100644
4760--- a/arch/avr32/include/asm/cache.h
4761+++ b/arch/avr32/include/asm/cache.h
4762@@ -1,8 +1,10 @@
4763 #ifndef __ASM_AVR32_CACHE_H
4764 #define __ASM_AVR32_CACHE_H
4765
4766+#include <linux/const.h>
4767+
4768 #define L1_CACHE_SHIFT 5
4769-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4770+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4771
4772 /*
4773 * Memory returned by kmalloc() may be used for DMA, so we must make
4774diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4775index d232888..87c8df1 100644
4776--- a/arch/avr32/include/asm/elf.h
4777+++ b/arch/avr32/include/asm/elf.h
4778@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4779 the loader. We need to make sure that it is out of the way of the program
4780 that it will "exec", and that there is sufficient room for the brk. */
4781
4782-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4783+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4784
4785+#ifdef CONFIG_PAX_ASLR
4786+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4787+
4788+#define PAX_DELTA_MMAP_LEN 15
4789+#define PAX_DELTA_STACK_LEN 15
4790+#endif
4791
4792 /* This yields a mask that user programs can use to figure out what
4793 instruction set this CPU supports. This could be done in user space,
4794diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4795index 479330b..53717a8 100644
4796--- a/arch/avr32/include/asm/kmap_types.h
4797+++ b/arch/avr32/include/asm/kmap_types.h
4798@@ -2,9 +2,9 @@
4799 #define __ASM_AVR32_KMAP_TYPES_H
4800
4801 #ifdef CONFIG_DEBUG_HIGHMEM
4802-# define KM_TYPE_NR 29
4803+# define KM_TYPE_NR 30
4804 #else
4805-# define KM_TYPE_NR 14
4806+# define KM_TYPE_NR 15
4807 #endif
4808
4809 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4810diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4811index 0eca933..eb78c7b 100644
4812--- a/arch/avr32/mm/fault.c
4813+++ b/arch/avr32/mm/fault.c
4814@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4815
4816 int exception_trace = 1;
4817
4818+#ifdef CONFIG_PAX_PAGEEXEC
4819+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4820+{
4821+ unsigned long i;
4822+
4823+ printk(KERN_ERR "PAX: bytes at PC: ");
4824+ for (i = 0; i < 20; i++) {
4825+ unsigned char c;
4826+ if (get_user(c, (unsigned char *)pc+i))
4827+ printk(KERN_CONT "???????? ");
4828+ else
4829+ printk(KERN_CONT "%02x ", c);
4830+ }
4831+ printk("\n");
4832+}
4833+#endif
4834+
4835 /*
4836 * This routine handles page faults. It determines the address and the
4837 * problem, and then passes it off to one of the appropriate routines.
4838@@ -176,6 +193,16 @@ bad_area:
4839 up_read(&mm->mmap_sem);
4840
4841 if (user_mode(regs)) {
4842+
4843+#ifdef CONFIG_PAX_PAGEEXEC
4844+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4845+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4846+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4847+ do_group_exit(SIGKILL);
4848+ }
4849+ }
4850+#endif
4851+
4852 if (exception_trace && printk_ratelimit())
4853 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4854 "sp %08lx ecr %lu\n",
4855diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4856index 568885a..f8008df 100644
4857--- a/arch/blackfin/include/asm/cache.h
4858+++ b/arch/blackfin/include/asm/cache.h
4859@@ -7,6 +7,7 @@
4860 #ifndef __ARCH_BLACKFIN_CACHE_H
4861 #define __ARCH_BLACKFIN_CACHE_H
4862
4863+#include <linux/const.h>
4864 #include <linux/linkage.h> /* for asmlinkage */
4865
4866 /*
4867@@ -14,7 +15,7 @@
4868 * Blackfin loads 32 bytes for cache
4869 */
4870 #define L1_CACHE_SHIFT 5
4871-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4872+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4873 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4874
4875 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4876diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4877index aea2718..3639a60 100644
4878--- a/arch/cris/include/arch-v10/arch/cache.h
4879+++ b/arch/cris/include/arch-v10/arch/cache.h
4880@@ -1,8 +1,9 @@
4881 #ifndef _ASM_ARCH_CACHE_H
4882 #define _ASM_ARCH_CACHE_H
4883
4884+#include <linux/const.h>
4885 /* Etrax 100LX have 32-byte cache-lines. */
4886-#define L1_CACHE_BYTES 32
4887 #define L1_CACHE_SHIFT 5
4888+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4889
4890 #endif /* _ASM_ARCH_CACHE_H */
4891diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4892index 7caf25d..ee65ac5 100644
4893--- a/arch/cris/include/arch-v32/arch/cache.h
4894+++ b/arch/cris/include/arch-v32/arch/cache.h
4895@@ -1,11 +1,12 @@
4896 #ifndef _ASM_CRIS_ARCH_CACHE_H
4897 #define _ASM_CRIS_ARCH_CACHE_H
4898
4899+#include <linux/const.h>
4900 #include <arch/hwregs/dma.h>
4901
4902 /* A cache-line is 32 bytes. */
4903-#define L1_CACHE_BYTES 32
4904 #define L1_CACHE_SHIFT 5
4905+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4906
4907 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4908
4909diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4910index b86329d..6709906 100644
4911--- a/arch/frv/include/asm/atomic.h
4912+++ b/arch/frv/include/asm/atomic.h
4913@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4914 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4915 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4916
4917+#define atomic64_read_unchecked(v) atomic64_read(v)
4918+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4919+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4920+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4921+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4922+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4923+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4924+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4925+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4926+
4927 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4928 {
4929 int c, old;
4930diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4931index 2797163..c2a401d 100644
4932--- a/arch/frv/include/asm/cache.h
4933+++ b/arch/frv/include/asm/cache.h
4934@@ -12,10 +12,11 @@
4935 #ifndef __ASM_CACHE_H
4936 #define __ASM_CACHE_H
4937
4938+#include <linux/const.h>
4939
4940 /* bytes per L1 cache line */
4941 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4942-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4943+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4944
4945 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4946 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4947diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4948index 43901f2..0d8b865 100644
4949--- a/arch/frv/include/asm/kmap_types.h
4950+++ b/arch/frv/include/asm/kmap_types.h
4951@@ -2,6 +2,6 @@
4952 #ifndef _ASM_KMAP_TYPES_H
4953 #define _ASM_KMAP_TYPES_H
4954
4955-#define KM_TYPE_NR 17
4956+#define KM_TYPE_NR 18
4957
4958 #endif
4959diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4960index 836f147..4cf23f5 100644
4961--- a/arch/frv/mm/elf-fdpic.c
4962+++ b/arch/frv/mm/elf-fdpic.c
4963@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4964 {
4965 struct vm_area_struct *vma;
4966 struct vm_unmapped_area_info info;
4967+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4968
4969 if (len > TASK_SIZE)
4970 return -ENOMEM;
4971@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4972 if (addr) {
4973 addr = PAGE_ALIGN(addr);
4974 vma = find_vma(current->mm, addr);
4975- if (TASK_SIZE - len >= addr &&
4976- (!vma || addr + len <= vma->vm_start))
4977+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4978 goto success;
4979 }
4980
4981@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4982 info.high_limit = (current->mm->start_stack - 0x00200000);
4983 info.align_mask = 0;
4984 info.align_offset = 0;
4985+ info.threadstack_offset = offset;
4986 addr = vm_unmapped_area(&info);
4987 if (!(addr & ~PAGE_MASK))
4988 goto success;
4989diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4990index f4ca594..adc72fd6 100644
4991--- a/arch/hexagon/include/asm/cache.h
4992+++ b/arch/hexagon/include/asm/cache.h
4993@@ -21,9 +21,11 @@
4994 #ifndef __ASM_CACHE_H
4995 #define __ASM_CACHE_H
4996
4997+#include <linux/const.h>
4998+
4999 /* Bytes per L1 cache line */
5000-#define L1_CACHE_SHIFT (5)
5001-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5002+#define L1_CACHE_SHIFT 5
5003+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5004
5005 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5006 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5007diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5008index 0c8e553..112d734 100644
5009--- a/arch/ia64/Kconfig
5010+++ b/arch/ia64/Kconfig
5011@@ -544,6 +544,7 @@ source "drivers/sn/Kconfig"
5012 config KEXEC
5013 bool "kexec system call"
5014 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5015+ depends on !GRKERNSEC_KMEM
5016 help
5017 kexec is a system call that implements the ability to shutdown your
5018 current kernel, and to start another kernel. It is like a reboot
5019diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5020index 6e6fe18..a6ae668 100644
5021--- a/arch/ia64/include/asm/atomic.h
5022+++ b/arch/ia64/include/asm/atomic.h
5023@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5024 #define atomic64_inc(v) atomic64_add(1, (v))
5025 #define atomic64_dec(v) atomic64_sub(1, (v))
5026
5027+#define atomic64_read_unchecked(v) atomic64_read(v)
5028+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5029+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5030+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5031+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5032+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5033+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5034+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5035+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5036+
5037 /* Atomic operations are already serializing */
5038 #define smp_mb__before_atomic_dec() barrier()
5039 #define smp_mb__after_atomic_dec() barrier()
5040diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5041index d0a69aa..142f878 100644
5042--- a/arch/ia64/include/asm/barrier.h
5043+++ b/arch/ia64/include/asm/barrier.h
5044@@ -64,7 +64,7 @@
5045 do { \
5046 compiletime_assert_atomic_type(*p); \
5047 barrier(); \
5048- ACCESS_ONCE(*p) = (v); \
5049+ ACCESS_ONCE_RW(*p) = (v); \
5050 } while (0)
5051
5052 #define smp_load_acquire(p) \
5053diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5054index 988254a..e1ee885 100644
5055--- a/arch/ia64/include/asm/cache.h
5056+++ b/arch/ia64/include/asm/cache.h
5057@@ -1,6 +1,7 @@
5058 #ifndef _ASM_IA64_CACHE_H
5059 #define _ASM_IA64_CACHE_H
5060
5061+#include <linux/const.h>
5062
5063 /*
5064 * Copyright (C) 1998-2000 Hewlett-Packard Co
5065@@ -9,7 +10,7 @@
5066
5067 /* Bytes per L1 (data) cache line. */
5068 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5069-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5070+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5071
5072 #ifdef CONFIG_SMP
5073 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5074diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5075index 5a83c5c..4d7f553 100644
5076--- a/arch/ia64/include/asm/elf.h
5077+++ b/arch/ia64/include/asm/elf.h
5078@@ -42,6 +42,13 @@
5079 */
5080 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5081
5082+#ifdef CONFIG_PAX_ASLR
5083+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5084+
5085+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5086+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5087+#endif
5088+
5089 #define PT_IA_64_UNWIND 0x70000001
5090
5091 /* IA-64 relocations: */
5092diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5093index 5767cdf..7462574 100644
5094--- a/arch/ia64/include/asm/pgalloc.h
5095+++ b/arch/ia64/include/asm/pgalloc.h
5096@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5097 pgd_val(*pgd_entry) = __pa(pud);
5098 }
5099
5100+static inline void
5101+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5102+{
5103+ pgd_populate(mm, pgd_entry, pud);
5104+}
5105+
5106 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5107 {
5108 return quicklist_alloc(0, GFP_KERNEL, NULL);
5109@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5110 pud_val(*pud_entry) = __pa(pmd);
5111 }
5112
5113+static inline void
5114+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5115+{
5116+ pud_populate(mm, pud_entry, pmd);
5117+}
5118+
5119 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5120 {
5121 return quicklist_alloc(0, GFP_KERNEL, NULL);
5122diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5123index 7935115..c0eca6a 100644
5124--- a/arch/ia64/include/asm/pgtable.h
5125+++ b/arch/ia64/include/asm/pgtable.h
5126@@ -12,7 +12,7 @@
5127 * David Mosberger-Tang <davidm@hpl.hp.com>
5128 */
5129
5130-
5131+#include <linux/const.h>
5132 #include <asm/mman.h>
5133 #include <asm/page.h>
5134 #include <asm/processor.h>
5135@@ -142,6 +142,17 @@
5136 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5137 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5138 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5139+
5140+#ifdef CONFIG_PAX_PAGEEXEC
5141+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5142+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5143+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5144+#else
5145+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5146+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5147+# define PAGE_COPY_NOEXEC PAGE_COPY
5148+#endif
5149+
5150 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5151 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5152 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5153diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5154index 45698cd..e8e2dbc 100644
5155--- a/arch/ia64/include/asm/spinlock.h
5156+++ b/arch/ia64/include/asm/spinlock.h
5157@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5158 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5159
5160 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5161- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5162+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5163 }
5164
5165 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5166diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5167index 449c8c0..3d4b1e9 100644
5168--- a/arch/ia64/include/asm/uaccess.h
5169+++ b/arch/ia64/include/asm/uaccess.h
5170@@ -70,6 +70,7 @@
5171 && ((segment).seg == KERNEL_DS.seg \
5172 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5173 })
5174+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5175 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5176
5177 /*
5178@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5179 static inline unsigned long
5180 __copy_to_user (void __user *to, const void *from, unsigned long count)
5181 {
5182+ if (count > INT_MAX)
5183+ return count;
5184+
5185+ if (!__builtin_constant_p(count))
5186+ check_object_size(from, count, true);
5187+
5188 return __copy_user(to, (__force void __user *) from, count);
5189 }
5190
5191 static inline unsigned long
5192 __copy_from_user (void *to, const void __user *from, unsigned long count)
5193 {
5194+ if (count > INT_MAX)
5195+ return count;
5196+
5197+ if (!__builtin_constant_p(count))
5198+ check_object_size(to, count, false);
5199+
5200 return __copy_user((__force void __user *) to, from, count);
5201 }
5202
5203@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5204 ({ \
5205 void __user *__cu_to = (to); \
5206 const void *__cu_from = (from); \
5207- long __cu_len = (n); \
5208+ unsigned long __cu_len = (n); \
5209 \
5210- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5211+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5212+ if (!__builtin_constant_p(n)) \
5213+ check_object_size(__cu_from, __cu_len, true); \
5214 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5215+ } \
5216 __cu_len; \
5217 })
5218
5219@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5220 ({ \
5221 void *__cu_to = (to); \
5222 const void __user *__cu_from = (from); \
5223- long __cu_len = (n); \
5224+ unsigned long __cu_len = (n); \
5225 \
5226 __chk_user_ptr(__cu_from); \
5227- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5228+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5229+ if (!__builtin_constant_p(n)) \
5230+ check_object_size(__cu_to, __cu_len, false); \
5231 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5232+ } \
5233 __cu_len; \
5234 })
5235
5236diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5237index 24603be..948052d 100644
5238--- a/arch/ia64/kernel/module.c
5239+++ b/arch/ia64/kernel/module.c
5240@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5241 void
5242 module_free (struct module *mod, void *module_region)
5243 {
5244- if (mod && mod->arch.init_unw_table &&
5245- module_region == mod->module_init) {
5246+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5247 unw_remove_unwind_table(mod->arch.init_unw_table);
5248 mod->arch.init_unw_table = NULL;
5249 }
5250@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5251 }
5252
5253 static inline int
5254+in_init_rx (const struct module *mod, uint64_t addr)
5255+{
5256+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5257+}
5258+
5259+static inline int
5260+in_init_rw (const struct module *mod, uint64_t addr)
5261+{
5262+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5263+}
5264+
5265+static inline int
5266 in_init (const struct module *mod, uint64_t addr)
5267 {
5268- return addr - (uint64_t) mod->module_init < mod->init_size;
5269+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5270+}
5271+
5272+static inline int
5273+in_core_rx (const struct module *mod, uint64_t addr)
5274+{
5275+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5276+}
5277+
5278+static inline int
5279+in_core_rw (const struct module *mod, uint64_t addr)
5280+{
5281+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5282 }
5283
5284 static inline int
5285 in_core (const struct module *mod, uint64_t addr)
5286 {
5287- return addr - (uint64_t) mod->module_core < mod->core_size;
5288+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5289 }
5290
5291 static inline int
5292@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5293 break;
5294
5295 case RV_BDREL:
5296- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5297+ if (in_init_rx(mod, val))
5298+ val -= (uint64_t) mod->module_init_rx;
5299+ else if (in_init_rw(mod, val))
5300+ val -= (uint64_t) mod->module_init_rw;
5301+ else if (in_core_rx(mod, val))
5302+ val -= (uint64_t) mod->module_core_rx;
5303+ else if (in_core_rw(mod, val))
5304+ val -= (uint64_t) mod->module_core_rw;
5305 break;
5306
5307 case RV_LTV:
5308@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5309 * addresses have been selected...
5310 */
5311 uint64_t gp;
5312- if (mod->core_size > MAX_LTOFF)
5313+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5314 /*
5315 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5316 * at the end of the module.
5317 */
5318- gp = mod->core_size - MAX_LTOFF / 2;
5319+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5320 else
5321- gp = mod->core_size / 2;
5322- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5323+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5324+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5325 mod->arch.gp = gp;
5326 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5327 }
5328diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5329index ab33328..f39506c 100644
5330--- a/arch/ia64/kernel/palinfo.c
5331+++ b/arch/ia64/kernel/palinfo.c
5332@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5333 return NOTIFY_OK;
5334 }
5335
5336-static struct notifier_block __refdata palinfo_cpu_notifier =
5337+static struct notifier_block palinfo_cpu_notifier =
5338 {
5339 .notifier_call = palinfo_cpu_callback,
5340 .priority = 0,
5341diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5342index 41e33f8..65180b2a 100644
5343--- a/arch/ia64/kernel/sys_ia64.c
5344+++ b/arch/ia64/kernel/sys_ia64.c
5345@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5346 unsigned long align_mask = 0;
5347 struct mm_struct *mm = current->mm;
5348 struct vm_unmapped_area_info info;
5349+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5350
5351 if (len > RGN_MAP_LIMIT)
5352 return -ENOMEM;
5353@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5354 if (REGION_NUMBER(addr) == RGN_HPAGE)
5355 addr = 0;
5356 #endif
5357+
5358+#ifdef CONFIG_PAX_RANDMMAP
5359+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5360+ addr = mm->free_area_cache;
5361+ else
5362+#endif
5363+
5364 if (!addr)
5365 addr = TASK_UNMAPPED_BASE;
5366
5367@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5368 info.high_limit = TASK_SIZE;
5369 info.align_mask = align_mask;
5370 info.align_offset = 0;
5371+ info.threadstack_offset = offset;
5372 return vm_unmapped_area(&info);
5373 }
5374
5375diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5376index 84f8a52..7c76178 100644
5377--- a/arch/ia64/kernel/vmlinux.lds.S
5378+++ b/arch/ia64/kernel/vmlinux.lds.S
5379@@ -192,7 +192,7 @@ SECTIONS {
5380 /* Per-cpu data: */
5381 . = ALIGN(PERCPU_PAGE_SIZE);
5382 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5383- __phys_per_cpu_start = __per_cpu_load;
5384+ __phys_per_cpu_start = per_cpu_load;
5385 /*
5386 * ensure percpu data fits
5387 * into percpu page size
5388diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5389index 7225dad..2a7c8256 100644
5390--- a/arch/ia64/mm/fault.c
5391+++ b/arch/ia64/mm/fault.c
5392@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5393 return pte_present(pte);
5394 }
5395
5396+#ifdef CONFIG_PAX_PAGEEXEC
5397+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5398+{
5399+ unsigned long i;
5400+
5401+ printk(KERN_ERR "PAX: bytes at PC: ");
5402+ for (i = 0; i < 8; i++) {
5403+ unsigned int c;
5404+ if (get_user(c, (unsigned int *)pc+i))
5405+ printk(KERN_CONT "???????? ");
5406+ else
5407+ printk(KERN_CONT "%08x ", c);
5408+ }
5409+ printk("\n");
5410+}
5411+#endif
5412+
5413 # define VM_READ_BIT 0
5414 # define VM_WRITE_BIT 1
5415 # define VM_EXEC_BIT 2
5416@@ -151,8 +168,21 @@ retry:
5417 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5418 goto bad_area;
5419
5420- if ((vma->vm_flags & mask) != mask)
5421+ if ((vma->vm_flags & mask) != mask) {
5422+
5423+#ifdef CONFIG_PAX_PAGEEXEC
5424+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5425+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5426+ goto bad_area;
5427+
5428+ up_read(&mm->mmap_sem);
5429+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5430+ do_group_exit(SIGKILL);
5431+ }
5432+#endif
5433+
5434 goto bad_area;
5435+ }
5436
5437 /*
5438 * If for any reason at all we couldn't handle the fault, make
5439diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5440index 68232db..6ca80af 100644
5441--- a/arch/ia64/mm/hugetlbpage.c
5442+++ b/arch/ia64/mm/hugetlbpage.c
5443@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5444 unsigned long pgoff, unsigned long flags)
5445 {
5446 struct vm_unmapped_area_info info;
5447+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5448
5449 if (len > RGN_MAP_LIMIT)
5450 return -ENOMEM;
5451@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5452 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5453 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5454 info.align_offset = 0;
5455+ info.threadstack_offset = offset;
5456 return vm_unmapped_area(&info);
5457 }
5458
5459diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5460index 25c3502..560dae7 100644
5461--- a/arch/ia64/mm/init.c
5462+++ b/arch/ia64/mm/init.c
5463@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5464 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5465 vma->vm_end = vma->vm_start + PAGE_SIZE;
5466 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5467+
5468+#ifdef CONFIG_PAX_PAGEEXEC
5469+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5470+ vma->vm_flags &= ~VM_EXEC;
5471+
5472+#ifdef CONFIG_PAX_MPROTECT
5473+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5474+ vma->vm_flags &= ~VM_MAYEXEC;
5475+#endif
5476+
5477+ }
5478+#endif
5479+
5480 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5481 down_write(&current->mm->mmap_sem);
5482 if (insert_vm_struct(current->mm, vma)) {
5483diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5484index 40b3ee9..8c2c112 100644
5485--- a/arch/m32r/include/asm/cache.h
5486+++ b/arch/m32r/include/asm/cache.h
5487@@ -1,8 +1,10 @@
5488 #ifndef _ASM_M32R_CACHE_H
5489 #define _ASM_M32R_CACHE_H
5490
5491+#include <linux/const.h>
5492+
5493 /* L1 cache line size */
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 #endif /* _ASM_M32R_CACHE_H */
5499diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5500index 82abd15..d95ae5d 100644
5501--- a/arch/m32r/lib/usercopy.c
5502+++ b/arch/m32r/lib/usercopy.c
5503@@ -14,6 +14,9 @@
5504 unsigned long
5505 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5506 {
5507+ if ((long)n < 0)
5508+ return n;
5509+
5510 prefetch(from);
5511 if (access_ok(VERIFY_WRITE, to, n))
5512 __copy_user(to,from,n);
5513@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5514 unsigned long
5515 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5516 {
5517+ if ((long)n < 0)
5518+ return n;
5519+
5520 prefetchw(to);
5521 if (access_ok(VERIFY_READ, from, n))
5522 __copy_user_zeroing(to,from,n);
5523diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5524index 0395c51..5f26031 100644
5525--- a/arch/m68k/include/asm/cache.h
5526+++ b/arch/m68k/include/asm/cache.h
5527@@ -4,9 +4,11 @@
5528 #ifndef __ARCH_M68K_CACHE_H
5529 #define __ARCH_M68K_CACHE_H
5530
5531+#include <linux/const.h>
5532+
5533 /* bytes per L1 cache line */
5534 #define L1_CACHE_SHIFT 4
5535-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5536+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5537
5538 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5539
5540diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5541index 2d6f0de..de5f5ac 100644
5542--- a/arch/metag/include/asm/barrier.h
5543+++ b/arch/metag/include/asm/barrier.h
5544@@ -89,7 +89,7 @@ static inline void fence(void)
5545 do { \
5546 compiletime_assert_atomic_type(*p); \
5547 smp_mb(); \
5548- ACCESS_ONCE(*p) = (v); \
5549+ ACCESS_ONCE_RW(*p) = (v); \
5550 } while (0)
5551
5552 #define smp_load_acquire(p) \
5553diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5554index 0424315..defcca9 100644
5555--- a/arch/metag/mm/hugetlbpage.c
5556+++ b/arch/metag/mm/hugetlbpage.c
5557@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5558 info.high_limit = TASK_SIZE;
5559 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5560 info.align_offset = 0;
5561+ info.threadstack_offset = 0;
5562 return vm_unmapped_area(&info);
5563 }
5564
5565diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5566index 4efe96a..60e8699 100644
5567--- a/arch/microblaze/include/asm/cache.h
5568+++ b/arch/microblaze/include/asm/cache.h
5569@@ -13,11 +13,12 @@
5570 #ifndef _ASM_MICROBLAZE_CACHE_H
5571 #define _ASM_MICROBLAZE_CACHE_H
5572
5573+#include <linux/const.h>
5574 #include <asm/registers.h>
5575
5576 #define L1_CACHE_SHIFT 5
5577 /* word-granular cache in microblaze */
5578-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5579+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5580
5581 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5582
5583diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5584index 95fa1f1..56a6fa2 100644
5585--- a/arch/mips/Kconfig
5586+++ b/arch/mips/Kconfig
5587@@ -2298,6 +2298,7 @@ source "kernel/Kconfig.preempt"
5588
5589 config KEXEC
5590 bool "Kexec system call"
5591+ depends on !GRKERNSEC_KMEM
5592 help
5593 kexec is a system call that implements the ability to shutdown your
5594 current kernel, and to start another kernel. It is like a reboot
5595diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5596index 02f2444..506969c 100644
5597--- a/arch/mips/cavium-octeon/dma-octeon.c
5598+++ b/arch/mips/cavium-octeon/dma-octeon.c
5599@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5600 if (dma_release_from_coherent(dev, order, vaddr))
5601 return;
5602
5603- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5604+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5605 }
5606
5607 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5608diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5609index 7eed2f2..c4e385d 100644
5610--- a/arch/mips/include/asm/atomic.h
5611+++ b/arch/mips/include/asm/atomic.h
5612@@ -21,15 +21,39 @@
5613 #include <asm/cmpxchg.h>
5614 #include <asm/war.h>
5615
5616+#ifdef CONFIG_GENERIC_ATOMIC64
5617+#include <asm-generic/atomic64.h>
5618+#endif
5619+
5620 #define ATOMIC_INIT(i) { (i) }
5621
5622+#ifdef CONFIG_64BIT
5623+#define _ASM_EXTABLE(from, to) \
5624+" .section __ex_table,\"a\"\n" \
5625+" .dword " #from ", " #to"\n" \
5626+" .previous\n"
5627+#else
5628+#define _ASM_EXTABLE(from, to) \
5629+" .section __ex_table,\"a\"\n" \
5630+" .word " #from ", " #to"\n" \
5631+" .previous\n"
5632+#endif
5633+
5634 /*
5635 * atomic_read - read atomic variable
5636 * @v: pointer of type atomic_t
5637 *
5638 * Atomically reads the value of @v.
5639 */
5640-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5641+static inline int atomic_read(const atomic_t *v)
5642+{
5643+ return (*(volatile const int *) &v->counter);
5644+}
5645+
5646+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5647+{
5648+ return (*(volatile const int *) &v->counter);
5649+}
5650
5651 /*
5652 * atomic_set - set atomic variable
5653@@ -38,7 +62,15 @@
5654 *
5655 * Atomically sets the value of @v to @i.
5656 */
5657-#define atomic_set(v, i) ((v)->counter = (i))
5658+static inline void atomic_set(atomic_t *v, int i)
5659+{
5660+ v->counter = i;
5661+}
5662+
5663+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5664+{
5665+ v->counter = i;
5666+}
5667
5668 /*
5669 * atomic_add - add integer to atomic variable
5670@@ -47,7 +79,67 @@
5671 *
5672 * Atomically adds @i to @v.
5673 */
5674-static __inline__ void atomic_add(int i, atomic_t * v)
5675+static __inline__ void atomic_add(int i, atomic_t *v)
5676+{
5677+ int temp;
5678+
5679+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5680+ __asm__ __volatile__(
5681+ " .set mips3 \n"
5682+ "1: ll %0, %1 # atomic_add \n"
5683+#ifdef CONFIG_PAX_REFCOUNT
5684+ /* Exception on overflow. */
5685+ "2: add %0, %2 \n"
5686+#else
5687+ " addu %0, %2 \n"
5688+#endif
5689+ " sc %0, %1 \n"
5690+ " beqzl %0, 1b \n"
5691+#ifdef CONFIG_PAX_REFCOUNT
5692+ "3: \n"
5693+ _ASM_EXTABLE(2b, 3b)
5694+#endif
5695+ " .set mips0 \n"
5696+ : "=&r" (temp), "+m" (v->counter)
5697+ : "Ir" (i));
5698+ } else if (kernel_uses_llsc) {
5699+ __asm__ __volatile__(
5700+ " .set mips3 \n"
5701+ "1: ll %0, %1 # atomic_add \n"
5702+#ifdef CONFIG_PAX_REFCOUNT
5703+ /* Exception on overflow. */
5704+ "2: add %0, %2 \n"
5705+#else
5706+ " addu %0, %2 \n"
5707+#endif
5708+ " sc %0, %1 \n"
5709+ " beqz %0, 1b \n"
5710+#ifdef CONFIG_PAX_REFCOUNT
5711+ "3: \n"
5712+ _ASM_EXTABLE(2b, 3b)
5713+#endif
5714+ " .set mips0 \n"
5715+ : "=&r" (temp), "+m" (v->counter)
5716+ : "Ir" (i));
5717+ } else {
5718+ unsigned long flags;
5719+
5720+ raw_local_irq_save(flags);
5721+ __asm__ __volatile__(
5722+#ifdef CONFIG_PAX_REFCOUNT
5723+ /* Exception on overflow. */
5724+ "1: add %0, %1 \n"
5725+ "2: \n"
5726+ _ASM_EXTABLE(1b, 2b)
5727+#else
5728+ " addu %0, %1 \n"
5729+#endif
5730+ : "+r" (v->counter) : "Ir" (i));
5731+ raw_local_irq_restore(flags);
5732+ }
5733+}
5734+
5735+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5736 {
5737 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5738 int temp;
5739@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5740 *
5741 * Atomically subtracts @i from @v.
5742 */
5743-static __inline__ void atomic_sub(int i, atomic_t * v)
5744+static __inline__ void atomic_sub(int i, atomic_t *v)
5745+{
5746+ int temp;
5747+
5748+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5749+ __asm__ __volatile__(
5750+ " .set mips3 \n"
5751+ "1: ll %0, %1 # atomic64_sub \n"
5752+#ifdef CONFIG_PAX_REFCOUNT
5753+ /* Exception on overflow. */
5754+ "2: sub %0, %2 \n"
5755+#else
5756+ " subu %0, %2 \n"
5757+#endif
5758+ " sc %0, %1 \n"
5759+ " beqzl %0, 1b \n"
5760+#ifdef CONFIG_PAX_REFCOUNT
5761+ "3: \n"
5762+ _ASM_EXTABLE(2b, 3b)
5763+#endif
5764+ " .set mips0 \n"
5765+ : "=&r" (temp), "+m" (v->counter)
5766+ : "Ir" (i));
5767+ } else if (kernel_uses_llsc) {
5768+ __asm__ __volatile__(
5769+ " .set mips3 \n"
5770+ "1: ll %0, %1 # atomic64_sub \n"
5771+#ifdef CONFIG_PAX_REFCOUNT
5772+ /* Exception on overflow. */
5773+ "2: sub %0, %2 \n"
5774+#else
5775+ " subu %0, %2 \n"
5776+#endif
5777+ " sc %0, %1 \n"
5778+ " beqz %0, 1b \n"
5779+#ifdef CONFIG_PAX_REFCOUNT
5780+ "3: \n"
5781+ _ASM_EXTABLE(2b, 3b)
5782+#endif
5783+ " .set mips0 \n"
5784+ : "=&r" (temp), "+m" (v->counter)
5785+ : "Ir" (i));
5786+ } else {
5787+ unsigned long flags;
5788+
5789+ raw_local_irq_save(flags);
5790+ __asm__ __volatile__(
5791+#ifdef CONFIG_PAX_REFCOUNT
5792+ /* Exception on overflow. */
5793+ "1: sub %0, %1 \n"
5794+ "2: \n"
5795+ _ASM_EXTABLE(1b, 2b)
5796+#else
5797+ " subu %0, %1 \n"
5798+#endif
5799+ : "+r" (v->counter) : "Ir" (i));
5800+ raw_local_irq_restore(flags);
5801+ }
5802+}
5803+
5804+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5805 {
5806 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5807 int temp;
5808@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5809 /*
5810 * Same as above, but return the result value
5811 */
5812-static __inline__ int atomic_add_return(int i, atomic_t * v)
5813+static __inline__ int atomic_add_return(int i, atomic_t *v)
5814+{
5815+ int result;
5816+ int temp;
5817+
5818+ smp_mb__before_llsc();
5819+
5820+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5821+ __asm__ __volatile__(
5822+ " .set mips3 \n"
5823+ "1: ll %1, %2 # atomic_add_return \n"
5824+#ifdef CONFIG_PAX_REFCOUNT
5825+ "2: add %0, %1, %3 \n"
5826+#else
5827+ " addu %0, %1, %3 \n"
5828+#endif
5829+ " sc %0, %2 \n"
5830+ " beqzl %0, 1b \n"
5831+#ifdef CONFIG_PAX_REFCOUNT
5832+ " b 4f \n"
5833+ " .set noreorder \n"
5834+ "3: b 5f \n"
5835+ " move %0, %1 \n"
5836+ " .set reorder \n"
5837+ _ASM_EXTABLE(2b, 3b)
5838+#endif
5839+ "4: addu %0, %1, %3 \n"
5840+#ifdef CONFIG_PAX_REFCOUNT
5841+ "5: \n"
5842+#endif
5843+ " .set mips0 \n"
5844+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5845+ : "Ir" (i));
5846+ } else if (kernel_uses_llsc) {
5847+ __asm__ __volatile__(
5848+ " .set mips3 \n"
5849+ "1: ll %1, %2 # atomic_add_return \n"
5850+#ifdef CONFIG_PAX_REFCOUNT
5851+ "2: add %0, %1, %3 \n"
5852+#else
5853+ " addu %0, %1, %3 \n"
5854+#endif
5855+ " sc %0, %2 \n"
5856+ " bnez %0, 4f \n"
5857+ " b 1b \n"
5858+#ifdef CONFIG_PAX_REFCOUNT
5859+ " .set noreorder \n"
5860+ "3: b 5f \n"
5861+ " move %0, %1 \n"
5862+ " .set reorder \n"
5863+ _ASM_EXTABLE(2b, 3b)
5864+#endif
5865+ "4: addu %0, %1, %3 \n"
5866+#ifdef CONFIG_PAX_REFCOUNT
5867+ "5: \n"
5868+#endif
5869+ " .set mips0 \n"
5870+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5871+ : "Ir" (i));
5872+ } else {
5873+ unsigned long flags;
5874+
5875+ raw_local_irq_save(flags);
5876+ __asm__ __volatile__(
5877+ " lw %0, %1 \n"
5878+#ifdef CONFIG_PAX_REFCOUNT
5879+ /* Exception on overflow. */
5880+ "1: add %0, %2 \n"
5881+#else
5882+ " addu %0, %2 \n"
5883+#endif
5884+ " sw %0, %1 \n"
5885+#ifdef CONFIG_PAX_REFCOUNT
5886+ /* Note: Dest reg is not modified on overflow */
5887+ "2: \n"
5888+ _ASM_EXTABLE(1b, 2b)
5889+#endif
5890+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5891+ raw_local_irq_restore(flags);
5892+ }
5893+
5894+ smp_llsc_mb();
5895+
5896+ return result;
5897+}
5898+
5899+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5900 {
5901 int result;
5902
5903@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5904 return result;
5905 }
5906
5907-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5908+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5909+{
5910+ int result;
5911+ int temp;
5912+
5913+ smp_mb__before_llsc();
5914+
5915+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5916+ __asm__ __volatile__(
5917+ " .set mips3 \n"
5918+ "1: ll %1, %2 # atomic_sub_return \n"
5919+#ifdef CONFIG_PAX_REFCOUNT
5920+ "2: sub %0, %1, %3 \n"
5921+#else
5922+ " subu %0, %1, %3 \n"
5923+#endif
5924+ " sc %0, %2 \n"
5925+ " beqzl %0, 1b \n"
5926+#ifdef CONFIG_PAX_REFCOUNT
5927+ " b 4f \n"
5928+ " .set noreorder \n"
5929+ "3: b 5f \n"
5930+ " move %0, %1 \n"
5931+ " .set reorder \n"
5932+ _ASM_EXTABLE(2b, 3b)
5933+#endif
5934+ "4: subu %0, %1, %3 \n"
5935+#ifdef CONFIG_PAX_REFCOUNT
5936+ "5: \n"
5937+#endif
5938+ " .set mips0 \n"
5939+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5940+ : "Ir" (i), "m" (v->counter)
5941+ : "memory");
5942+ } else if (kernel_uses_llsc) {
5943+ __asm__ __volatile__(
5944+ " .set mips3 \n"
5945+ "1: ll %1, %2 # atomic_sub_return \n"
5946+#ifdef CONFIG_PAX_REFCOUNT
5947+ "2: sub %0, %1, %3 \n"
5948+#else
5949+ " subu %0, %1, %3 \n"
5950+#endif
5951+ " sc %0, %2 \n"
5952+ " bnez %0, 4f \n"
5953+ " b 1b \n"
5954+#ifdef CONFIG_PAX_REFCOUNT
5955+ " .set noreorder \n"
5956+ "3: b 5f \n"
5957+ " move %0, %1 \n"
5958+ " .set reorder \n"
5959+ _ASM_EXTABLE(2b, 3b)
5960+#endif
5961+ "4: subu %0, %1, %3 \n"
5962+#ifdef CONFIG_PAX_REFCOUNT
5963+ "5: \n"
5964+#endif
5965+ " .set mips0 \n"
5966+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5967+ : "Ir" (i));
5968+ } else {
5969+ unsigned long flags;
5970+
5971+ raw_local_irq_save(flags);
5972+ __asm__ __volatile__(
5973+ " lw %0, %1 \n"
5974+#ifdef CONFIG_PAX_REFCOUNT
5975+ /* Exception on overflow. */
5976+ "1: sub %0, %2 \n"
5977+#else
5978+ " subu %0, %2 \n"
5979+#endif
5980+ " sw %0, %1 \n"
5981+#ifdef CONFIG_PAX_REFCOUNT
5982+ /* Note: Dest reg is not modified on overflow */
5983+ "2: \n"
5984+ _ASM_EXTABLE(1b, 2b)
5985+#endif
5986+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5987+ raw_local_irq_restore(flags);
5988+ }
5989+
5990+ smp_llsc_mb();
5991+
5992+ return result;
5993+}
5994+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5995 {
5996 int result;
5997
5998@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5999 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6000 * The function returns the old value of @v minus @i.
6001 */
6002-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6003+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6004 {
6005 int result;
6006
6007@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6008 return result;
6009 }
6010
6011-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6012-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6013+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6014+{
6015+ return cmpxchg(&v->counter, old, new);
6016+}
6017+
6018+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6019+ int new)
6020+{
6021+ return cmpxchg(&(v->counter), old, new);
6022+}
6023+
6024+static inline int atomic_xchg(atomic_t *v, int new)
6025+{
6026+ return xchg(&v->counter, new);
6027+}
6028+
6029+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6030+{
6031+ return xchg(&(v->counter), new);
6032+}
6033
6034 /**
6035 * __atomic_add_unless - add unless the number is a given value
6036@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6037
6038 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6039 #define atomic_inc_return(v) atomic_add_return(1, (v))
6040+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6041+{
6042+ return atomic_add_return_unchecked(1, v);
6043+}
6044
6045 /*
6046 * atomic_sub_and_test - subtract value from variable and test result
6047@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6048 * other cases.
6049 */
6050 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6051+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6052+{
6053+ return atomic_add_return_unchecked(1, v) == 0;
6054+}
6055
6056 /*
6057 * atomic_dec_and_test - decrement by 1 and test
6058@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6059 * Atomically increments @v by 1.
6060 */
6061 #define atomic_inc(v) atomic_add(1, (v))
6062+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6063+{
6064+ atomic_add_unchecked(1, v);
6065+}
6066
6067 /*
6068 * atomic_dec - decrement and test
6069@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6070 * Atomically decrements @v by 1.
6071 */
6072 #define atomic_dec(v) atomic_sub(1, (v))
6073+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6074+{
6075+ atomic_sub_unchecked(1, v);
6076+}
6077
6078 /*
6079 * atomic_add_negative - add and test if negative
6080@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6081 * @v: pointer of type atomic64_t
6082 *
6083 */
6084-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6085+static inline long atomic64_read(const atomic64_t *v)
6086+{
6087+ return (*(volatile const long *) &v->counter);
6088+}
6089+
6090+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6091+{
6092+ return (*(volatile const long *) &v->counter);
6093+}
6094
6095 /*
6096 * atomic64_set - set atomic variable
6097 * @v: pointer of type atomic64_t
6098 * @i: required value
6099 */
6100-#define atomic64_set(v, i) ((v)->counter = (i))
6101+static inline void atomic64_set(atomic64_t *v, long i)
6102+{
6103+ v->counter = i;
6104+}
6105+
6106+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6107+{
6108+ v->counter = i;
6109+}
6110
6111 /*
6112 * atomic64_add - add integer to atomic variable
6113@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6114 *
6115 * Atomically adds @i to @v.
6116 */
6117-static __inline__ void atomic64_add(long i, atomic64_t * v)
6118+static __inline__ void atomic64_add(long i, atomic64_t *v)
6119+{
6120+ long temp;
6121+
6122+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6123+ __asm__ __volatile__(
6124+ " .set mips3 \n"
6125+ "1: lld %0, %1 # atomic64_add \n"
6126+#ifdef CONFIG_PAX_REFCOUNT
6127+ /* Exception on overflow. */
6128+ "2: dadd %0, %2 \n"
6129+#else
6130+ " daddu %0, %2 \n"
6131+#endif
6132+ " scd %0, %1 \n"
6133+ " beqzl %0, 1b \n"
6134+#ifdef CONFIG_PAX_REFCOUNT
6135+ "3: \n"
6136+ _ASM_EXTABLE(2b, 3b)
6137+#endif
6138+ " .set mips0 \n"
6139+ : "=&r" (temp), "+m" (v->counter)
6140+ : "Ir" (i));
6141+ } else if (kernel_uses_llsc) {
6142+ __asm__ __volatile__(
6143+ " .set mips3 \n"
6144+ "1: lld %0, %1 # atomic64_add \n"
6145+#ifdef CONFIG_PAX_REFCOUNT
6146+ /* Exception on overflow. */
6147+ "2: dadd %0, %2 \n"
6148+#else
6149+ " daddu %0, %2 \n"
6150+#endif
6151+ " scd %0, %1 \n"
6152+ " beqz %0, 1b \n"
6153+#ifdef CONFIG_PAX_REFCOUNT
6154+ "3: \n"
6155+ _ASM_EXTABLE(2b, 3b)
6156+#endif
6157+ " .set mips0 \n"
6158+ : "=&r" (temp), "+m" (v->counter)
6159+ : "Ir" (i));
6160+ } else {
6161+ unsigned long flags;
6162+
6163+ raw_local_irq_save(flags);
6164+ __asm__ __volatile__(
6165+#ifdef CONFIG_PAX_REFCOUNT
6166+ /* Exception on overflow. */
6167+ "1: dadd %0, %1 \n"
6168+ "2: \n"
6169+ _ASM_EXTABLE(1b, 2b)
6170+#else
6171+ " daddu %0, %1 \n"
6172+#endif
6173+ : "+r" (v->counter) : "Ir" (i));
6174+ raw_local_irq_restore(flags);
6175+ }
6176+}
6177+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6178 {
6179 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6180 long temp;
6181@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6182 *
6183 * Atomically subtracts @i from @v.
6184 */
6185-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6186+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6187+{
6188+ long temp;
6189+
6190+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6191+ __asm__ __volatile__(
6192+ " .set mips3 \n"
6193+ "1: lld %0, %1 # atomic64_sub \n"
6194+#ifdef CONFIG_PAX_REFCOUNT
6195+ /* Exception on overflow. */
6196+ "2: dsub %0, %2 \n"
6197+#else
6198+ " dsubu %0, %2 \n"
6199+#endif
6200+ " scd %0, %1 \n"
6201+ " beqzl %0, 1b \n"
6202+#ifdef CONFIG_PAX_REFCOUNT
6203+ "3: \n"
6204+ _ASM_EXTABLE(2b, 3b)
6205+#endif
6206+ " .set mips0 \n"
6207+ : "=&r" (temp), "+m" (v->counter)
6208+ : "Ir" (i));
6209+ } else if (kernel_uses_llsc) {
6210+ __asm__ __volatile__(
6211+ " .set mips3 \n"
6212+ "1: lld %0, %1 # atomic64_sub \n"
6213+#ifdef CONFIG_PAX_REFCOUNT
6214+ /* Exception on overflow. */
6215+ "2: dsub %0, %2 \n"
6216+#else
6217+ " dsubu %0, %2 \n"
6218+#endif
6219+ " scd %0, %1 \n"
6220+ " beqz %0, 1b \n"
6221+#ifdef CONFIG_PAX_REFCOUNT
6222+ "3: \n"
6223+ _ASM_EXTABLE(2b, 3b)
6224+#endif
6225+ " .set mips0 \n"
6226+ : "=&r" (temp), "+m" (v->counter)
6227+ : "Ir" (i));
6228+ } else {
6229+ unsigned long flags;
6230+
6231+ raw_local_irq_save(flags);
6232+ __asm__ __volatile__(
6233+#ifdef CONFIG_PAX_REFCOUNT
6234+ /* Exception on overflow. */
6235+ "1: dsub %0, %1 \n"
6236+ "2: \n"
6237+ _ASM_EXTABLE(1b, 2b)
6238+#else
6239+ " dsubu %0, %1 \n"
6240+#endif
6241+ : "+r" (v->counter) : "Ir" (i));
6242+ raw_local_irq_restore(flags);
6243+ }
6244+}
6245+
6246+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6247 {
6248 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6249 long temp;
6250@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6251 /*
6252 * Same as above, but return the result value
6253 */
6254-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6255+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6256+{
6257+ long result;
6258+ long temp;
6259+
6260+ smp_mb__before_llsc();
6261+
6262+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6263+ __asm__ __volatile__(
6264+ " .set mips3 \n"
6265+ "1: lld %1, %2 # atomic64_add_return \n"
6266+#ifdef CONFIG_PAX_REFCOUNT
6267+ "2: dadd %0, %1, %3 \n"
6268+#else
6269+ " daddu %0, %1, %3 \n"
6270+#endif
6271+ " scd %0, %2 \n"
6272+ " beqzl %0, 1b \n"
6273+#ifdef CONFIG_PAX_REFCOUNT
6274+ " b 4f \n"
6275+ " .set noreorder \n"
6276+ "3: b 5f \n"
6277+ " move %0, %1 \n"
6278+ " .set reorder \n"
6279+ _ASM_EXTABLE(2b, 3b)
6280+#endif
6281+ "4: daddu %0, %1, %3 \n"
6282+#ifdef CONFIG_PAX_REFCOUNT
6283+ "5: \n"
6284+#endif
6285+ " .set mips0 \n"
6286+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6287+ : "Ir" (i));
6288+ } else if (kernel_uses_llsc) {
6289+ __asm__ __volatile__(
6290+ " .set mips3 \n"
6291+ "1: lld %1, %2 # atomic64_add_return \n"
6292+#ifdef CONFIG_PAX_REFCOUNT
6293+ "2: dadd %0, %1, %3 \n"
6294+#else
6295+ " daddu %0, %1, %3 \n"
6296+#endif
6297+ " scd %0, %2 \n"
6298+ " bnez %0, 4f \n"
6299+ " b 1b \n"
6300+#ifdef CONFIG_PAX_REFCOUNT
6301+ " .set noreorder \n"
6302+ "3: b 5f \n"
6303+ " move %0, %1 \n"
6304+ " .set reorder \n"
6305+ _ASM_EXTABLE(2b, 3b)
6306+#endif
6307+ "4: daddu %0, %1, %3 \n"
6308+#ifdef CONFIG_PAX_REFCOUNT
6309+ "5: \n"
6310+#endif
6311+ " .set mips0 \n"
6312+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6313+ : "Ir" (i), "m" (v->counter)
6314+ : "memory");
6315+ } else {
6316+ unsigned long flags;
6317+
6318+ raw_local_irq_save(flags);
6319+ __asm__ __volatile__(
6320+ " ld %0, %1 \n"
6321+#ifdef CONFIG_PAX_REFCOUNT
6322+ /* Exception on overflow. */
6323+ "1: dadd %0, %2 \n"
6324+#else
6325+ " daddu %0, %2 \n"
6326+#endif
6327+ " sd %0, %1 \n"
6328+#ifdef CONFIG_PAX_REFCOUNT
6329+ /* Note: Dest reg is not modified on overflow */
6330+ "2: \n"
6331+ _ASM_EXTABLE(1b, 2b)
6332+#endif
6333+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6334+ raw_local_irq_restore(flags);
6335+ }
6336+
6337+ smp_llsc_mb();
6338+
6339+ return result;
6340+}
6341+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6342 {
6343 long result;
6344
6345@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6346 return result;
6347 }
6348
6349-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6350+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6351+{
6352+ long result;
6353+ long temp;
6354+
6355+ smp_mb__before_llsc();
6356+
6357+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6358+ long temp;
6359+
6360+ __asm__ __volatile__(
6361+ " .set mips3 \n"
6362+ "1: lld %1, %2 # atomic64_sub_return \n"
6363+#ifdef CONFIG_PAX_REFCOUNT
6364+ "2: dsub %0, %1, %3 \n"
6365+#else
6366+ " dsubu %0, %1, %3 \n"
6367+#endif
6368+ " scd %0, %2 \n"
6369+ " beqzl %0, 1b \n"
6370+#ifdef CONFIG_PAX_REFCOUNT
6371+ " b 4f \n"
6372+ " .set noreorder \n"
6373+ "3: b 5f \n"
6374+ " move %0, %1 \n"
6375+ " .set reorder \n"
6376+ _ASM_EXTABLE(2b, 3b)
6377+#endif
6378+ "4: dsubu %0, %1, %3 \n"
6379+#ifdef CONFIG_PAX_REFCOUNT
6380+ "5: \n"
6381+#endif
6382+ " .set mips0 \n"
6383+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6384+ : "Ir" (i), "m" (v->counter)
6385+ : "memory");
6386+ } else if (kernel_uses_llsc) {
6387+ __asm__ __volatile__(
6388+ " .set mips3 \n"
6389+ "1: lld %1, %2 # atomic64_sub_return \n"
6390+#ifdef CONFIG_PAX_REFCOUNT
6391+ "2: dsub %0, %1, %3 \n"
6392+#else
6393+ " dsubu %0, %1, %3 \n"
6394+#endif
6395+ " scd %0, %2 \n"
6396+ " bnez %0, 4f \n"
6397+ " b 1b \n"
6398+#ifdef CONFIG_PAX_REFCOUNT
6399+ " .set noreorder \n"
6400+ "3: b 5f \n"
6401+ " move %0, %1 \n"
6402+ " .set reorder \n"
6403+ _ASM_EXTABLE(2b, 3b)
6404+#endif
6405+ "4: dsubu %0, %1, %3 \n"
6406+#ifdef CONFIG_PAX_REFCOUNT
6407+ "5: \n"
6408+#endif
6409+ " .set mips0 \n"
6410+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6411+ : "Ir" (i), "m" (v->counter)
6412+ : "memory");
6413+ } else {
6414+ unsigned long flags;
6415+
6416+ raw_local_irq_save(flags);
6417+ __asm__ __volatile__(
6418+ " ld %0, %1 \n"
6419+#ifdef CONFIG_PAX_REFCOUNT
6420+ /* Exception on overflow. */
6421+ "1: dsub %0, %2 \n"
6422+#else
6423+ " dsubu %0, %2 \n"
6424+#endif
6425+ " sd %0, %1 \n"
6426+#ifdef CONFIG_PAX_REFCOUNT
6427+ /* Note: Dest reg is not modified on overflow */
6428+ "2: \n"
6429+ _ASM_EXTABLE(1b, 2b)
6430+#endif
6431+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6432+ raw_local_irq_restore(flags);
6433+ }
6434+
6435+ smp_llsc_mb();
6436+
6437+ return result;
6438+}
6439+
6440+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6441 {
6442 long result;
6443
6444@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6445 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6446 * The function returns the old value of @v minus @i.
6447 */
6448-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6449+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6450 {
6451 long result;
6452
6453@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6454 return result;
6455 }
6456
6457-#define atomic64_cmpxchg(v, o, n) \
6458- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6459-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6460+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6461+{
6462+ return cmpxchg(&v->counter, old, new);
6463+}
6464+
6465+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6466+ long new)
6467+{
6468+ return cmpxchg(&(v->counter), old, new);
6469+}
6470+
6471+static inline long atomic64_xchg(atomic64_t *v, long new)
6472+{
6473+ return xchg(&v->counter, new);
6474+}
6475+
6476+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6477+{
6478+ return xchg(&(v->counter), new);
6479+}
6480
6481 /**
6482 * atomic64_add_unless - add unless the number is a given value
6483@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6484
6485 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6486 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6487+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6488
6489 /*
6490 * atomic64_sub_and_test - subtract value from variable and test result
6491@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6492 * other cases.
6493 */
6494 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6495+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6496
6497 /*
6498 * atomic64_dec_and_test - decrement by 1 and test
6499@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6500 * Atomically increments @v by 1.
6501 */
6502 #define atomic64_inc(v) atomic64_add(1, (v))
6503+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6504
6505 /*
6506 * atomic64_dec - decrement and test
6507@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6508 * Atomically decrements @v by 1.
6509 */
6510 #define atomic64_dec(v) atomic64_sub(1, (v))
6511+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6512
6513 /*
6514 * atomic64_add_negative - add and test if negative
6515diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6516index e1aa4e4..670b68b 100644
6517--- a/arch/mips/include/asm/barrier.h
6518+++ b/arch/mips/include/asm/barrier.h
6519@@ -184,7 +184,7 @@
6520 do { \
6521 compiletime_assert_atomic_type(*p); \
6522 smp_mb(); \
6523- ACCESS_ONCE(*p) = (v); \
6524+ ACCESS_ONCE_RW(*p) = (v); \
6525 } while (0)
6526
6527 #define smp_load_acquire(p) \
6528diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6529index b4db69f..8f3b093 100644
6530--- a/arch/mips/include/asm/cache.h
6531+++ b/arch/mips/include/asm/cache.h
6532@@ -9,10 +9,11 @@
6533 #ifndef _ASM_CACHE_H
6534 #define _ASM_CACHE_H
6535
6536+#include <linux/const.h>
6537 #include <kmalloc.h>
6538
6539 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6540-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6541+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6542
6543 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6544 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6545diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6546index d414405..6bb4ba2 100644
6547--- a/arch/mips/include/asm/elf.h
6548+++ b/arch/mips/include/asm/elf.h
6549@@ -398,13 +398,16 @@ extern const char *__elf_platform;
6550 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6551 #endif
6552
6553+#ifdef CONFIG_PAX_ASLR
6554+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6555+
6556+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6557+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6558+#endif
6559+
6560 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6561 struct linux_binprm;
6562 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6563 int uses_interp);
6564
6565-struct mm_struct;
6566-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6567-#define arch_randomize_brk arch_randomize_brk
6568-
6569 #endif /* _ASM_ELF_H */
6570diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6571index c1f6afa..38cc6e9 100644
6572--- a/arch/mips/include/asm/exec.h
6573+++ b/arch/mips/include/asm/exec.h
6574@@ -12,6 +12,6 @@
6575 #ifndef _ASM_EXEC_H
6576 #define _ASM_EXEC_H
6577
6578-extern unsigned long arch_align_stack(unsigned long sp);
6579+#define arch_align_stack(x) ((x) & ~0xfUL)
6580
6581 #endif /* _ASM_EXEC_H */
6582diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6583index 9e8ef59..1139d6b 100644
6584--- a/arch/mips/include/asm/hw_irq.h
6585+++ b/arch/mips/include/asm/hw_irq.h
6586@@ -10,7 +10,7 @@
6587
6588 #include <linux/atomic.h>
6589
6590-extern atomic_t irq_err_count;
6591+extern atomic_unchecked_t irq_err_count;
6592
6593 /*
6594 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6595diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6596index d44622c..64990d2 100644
6597--- a/arch/mips/include/asm/local.h
6598+++ b/arch/mips/include/asm/local.h
6599@@ -12,15 +12,25 @@ typedef struct
6600 atomic_long_t a;
6601 } local_t;
6602
6603+typedef struct {
6604+ atomic_long_unchecked_t a;
6605+} local_unchecked_t;
6606+
6607 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6608
6609 #define local_read(l) atomic_long_read(&(l)->a)
6610+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6611 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6612+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6613
6614 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6615+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6616 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6617+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6618 #define local_inc(l) atomic_long_inc(&(l)->a)
6619+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6620 #define local_dec(l) atomic_long_dec(&(l)->a)
6621+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6622
6623 /*
6624 * Same as above, but return the result value
6625@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6626 return result;
6627 }
6628
6629+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6630+{
6631+ unsigned long result;
6632+
6633+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6634+ unsigned long temp;
6635+
6636+ __asm__ __volatile__(
6637+ " .set mips3 \n"
6638+ "1:" __LL "%1, %2 # local_add_return \n"
6639+ " addu %0, %1, %3 \n"
6640+ __SC "%0, %2 \n"
6641+ " beqzl %0, 1b \n"
6642+ " addu %0, %1, %3 \n"
6643+ " .set mips0 \n"
6644+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6645+ : "Ir" (i), "m" (l->a.counter)
6646+ : "memory");
6647+ } else if (kernel_uses_llsc) {
6648+ unsigned long temp;
6649+
6650+ __asm__ __volatile__(
6651+ " .set mips3 \n"
6652+ "1:" __LL "%1, %2 # local_add_return \n"
6653+ " addu %0, %1, %3 \n"
6654+ __SC "%0, %2 \n"
6655+ " beqz %0, 1b \n"
6656+ " addu %0, %1, %3 \n"
6657+ " .set mips0 \n"
6658+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6659+ : "Ir" (i), "m" (l->a.counter)
6660+ : "memory");
6661+ } else {
6662+ unsigned long flags;
6663+
6664+ local_irq_save(flags);
6665+ result = l->a.counter;
6666+ result += i;
6667+ l->a.counter = result;
6668+ local_irq_restore(flags);
6669+ }
6670+
6671+ return result;
6672+}
6673+
6674 static __inline__ long local_sub_return(long i, local_t * l)
6675 {
6676 unsigned long result;
6677@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6678
6679 #define local_cmpxchg(l, o, n) \
6680 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6681+#define local_cmpxchg_unchecked(l, o, n) \
6682+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6683 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6684
6685 /**
6686diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6687index 5e08bcc..cfedefc 100644
6688--- a/arch/mips/include/asm/page.h
6689+++ b/arch/mips/include/asm/page.h
6690@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6691 #ifdef CONFIG_CPU_MIPS32
6692 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6693 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6694- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6695+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6696 #else
6697 typedef struct { unsigned long long pte; } pte_t;
6698 #define pte_val(x) ((x).pte)
6699diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6700index b336037..5b874cc 100644
6701--- a/arch/mips/include/asm/pgalloc.h
6702+++ b/arch/mips/include/asm/pgalloc.h
6703@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6704 {
6705 set_pud(pud, __pud((unsigned long)pmd));
6706 }
6707+
6708+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6709+{
6710+ pud_populate(mm, pud, pmd);
6711+}
6712 #endif
6713
6714 /*
6715diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6716index 008324d..f67c239 100644
6717--- a/arch/mips/include/asm/pgtable.h
6718+++ b/arch/mips/include/asm/pgtable.h
6719@@ -20,6 +20,9 @@
6720 #include <asm/io.h>
6721 #include <asm/pgtable-bits.h>
6722
6723+#define ktla_ktva(addr) (addr)
6724+#define ktva_ktla(addr) (addr)
6725+
6726 struct mm_struct;
6727 struct vm_area_struct;
6728
6729diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6730index 25da651..ae2a259 100644
6731--- a/arch/mips/include/asm/smtc_proc.h
6732+++ b/arch/mips/include/asm/smtc_proc.h
6733@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6734
6735 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6736
6737-extern atomic_t smtc_fpu_recoveries;
6738+extern atomic_unchecked_t smtc_fpu_recoveries;
6739
6740 #endif /* __ASM_SMTC_PROC_H */
6741diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6742index e80ae50..4404147 100644
6743--- a/arch/mips/include/asm/thread_info.h
6744+++ b/arch/mips/include/asm/thread_info.h
6745@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6746 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6747 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6748 #define TIF_32BIT_FPREGS 27 /* 32-bit floating point registers */
6749+/* li takes a 32bit immediate */
6750+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6751 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6752
6753 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6754@@ -134,14 +136,15 @@ static inline struct thread_info *current_thread_info(void)
6755 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6756 #define _TIF_32BIT_FPREGS (1<<TIF_32BIT_FPREGS)
6757 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6758+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6759
6760 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6761 _TIF_SYSCALL_AUDIT | \
6762- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6763+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
6764
6765 /* work to do in syscall_trace_leave() */
6766 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6767- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6768+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6769
6770 /* work to do on interrupt/exception return */
6771 #define _TIF_WORK_MASK \
6772@@ -149,7 +152,7 @@ static inline struct thread_info *current_thread_info(void)
6773 /* work to do on any return to u-space */
6774 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6775 _TIF_WORK_SYSCALL_EXIT | \
6776- _TIF_SYSCALL_TRACEPOINT)
6777+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6778
6779 /*
6780 * We stash processor id into a COP0 register to retrieve it fast
6781diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6782index f3fa375..3af6637 100644
6783--- a/arch/mips/include/asm/uaccess.h
6784+++ b/arch/mips/include/asm/uaccess.h
6785@@ -128,6 +128,7 @@ extern u64 __ua_limit;
6786 __ok == 0; \
6787 })
6788
6789+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6790 #define access_ok(type, addr, size) \
6791 likely(__access_ok((addr), (size), __access_mask))
6792
6793diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6794index 1188e00..41cf144 100644
6795--- a/arch/mips/kernel/binfmt_elfn32.c
6796+++ b/arch/mips/kernel/binfmt_elfn32.c
6797@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6798 #undef ELF_ET_DYN_BASE
6799 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6800
6801+#ifdef CONFIG_PAX_ASLR
6802+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6803+
6804+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6805+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6806+#endif
6807+
6808 #include <asm/processor.h>
6809 #include <linux/module.h>
6810 #include <linux/elfcore.h>
6811diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6812index 7faf5f2..f3d3cf4 100644
6813--- a/arch/mips/kernel/binfmt_elfo32.c
6814+++ b/arch/mips/kernel/binfmt_elfo32.c
6815@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6816 #undef ELF_ET_DYN_BASE
6817 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6818
6819+#ifdef CONFIG_PAX_ASLR
6820+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6821+
6822+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6823+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6824+#endif
6825+
6826 #include <asm/processor.h>
6827
6828 /*
6829diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6830index 2b91fe8..fe4f6b4 100644
6831--- a/arch/mips/kernel/i8259.c
6832+++ b/arch/mips/kernel/i8259.c
6833@@ -205,7 +205,7 @@ spurious_8259A_irq:
6834 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6835 spurious_irq_mask |= irqmask;
6836 }
6837- atomic_inc(&irq_err_count);
6838+ atomic_inc_unchecked(&irq_err_count);
6839 /*
6840 * Theoretically we do not have to handle this IRQ,
6841 * but in Linux this does not cause problems and is
6842diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6843index 44a1f79..2bd6aa3 100644
6844--- a/arch/mips/kernel/irq-gt641xx.c
6845+++ b/arch/mips/kernel/irq-gt641xx.c
6846@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6847 }
6848 }
6849
6850- atomic_inc(&irq_err_count);
6851+ atomic_inc_unchecked(&irq_err_count);
6852 }
6853
6854 void __init gt641xx_irq_init(void)
6855diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6856index d1fea7a..2e591b0 100644
6857--- a/arch/mips/kernel/irq.c
6858+++ b/arch/mips/kernel/irq.c
6859@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6860 printk("unexpected IRQ # %d\n", irq);
6861 }
6862
6863-atomic_t irq_err_count;
6864+atomic_unchecked_t irq_err_count;
6865
6866 int arch_show_interrupts(struct seq_file *p, int prec)
6867 {
6868- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6869+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6870 return 0;
6871 }
6872
6873 asmlinkage void spurious_interrupt(void)
6874 {
6875- atomic_inc(&irq_err_count);
6876+ atomic_inc_unchecked(&irq_err_count);
6877 }
6878
6879 void __init init_IRQ(void)
6880@@ -110,7 +110,10 @@ void __init init_IRQ(void)
6881 #endif
6882 }
6883
6884+
6885 #ifdef DEBUG_STACKOVERFLOW
6886+extern void gr_handle_kernel_exploit(void);
6887+
6888 static inline void check_stack_overflow(void)
6889 {
6890 unsigned long sp;
6891@@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6892 printk("do_IRQ: stack overflow: %ld\n",
6893 sp - sizeof(struct thread_info));
6894 dump_stack();
6895+ gr_handle_kernel_exploit();
6896 }
6897 }
6898 #else
6899diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6900index 6ae540e..b7396dc 100644
6901--- a/arch/mips/kernel/process.c
6902+++ b/arch/mips/kernel/process.c
6903@@ -562,15 +562,3 @@ unsigned long get_wchan(struct task_struct *task)
6904 out:
6905 return pc;
6906 }
6907-
6908-/*
6909- * Don't forget that the stack pointer must be aligned on a 8 bytes
6910- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6911- */
6912-unsigned long arch_align_stack(unsigned long sp)
6913-{
6914- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6915- sp -= get_random_int() & ~PAGE_MASK;
6916-
6917- return sp & ALMASK;
6918-}
6919diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6920index 7da9b76..21578be 100644
6921--- a/arch/mips/kernel/ptrace.c
6922+++ b/arch/mips/kernel/ptrace.c
6923@@ -658,6 +658,10 @@ long arch_ptrace(struct task_struct *child, long request,
6924 return ret;
6925 }
6926
6927+#ifdef CONFIG_GRKERNSEC_SETXID
6928+extern void gr_delayed_cred_worker(void);
6929+#endif
6930+
6931 /*
6932 * Notification of system call entry/exit
6933 * - triggered by current->work.syscall_trace
6934@@ -674,6 +678,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6935 tracehook_report_syscall_entry(regs))
6936 ret = -1;
6937
6938+#ifdef CONFIG_GRKERNSEC_SETXID
6939+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6940+ gr_delayed_cred_worker();
6941+#endif
6942+
6943 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6944 trace_sys_enter(regs, regs->regs[2]);
6945
6946diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6947index 07fc524..b9d7f28 100644
6948--- a/arch/mips/kernel/reset.c
6949+++ b/arch/mips/kernel/reset.c
6950@@ -13,6 +13,7 @@
6951 #include <linux/reboot.h>
6952
6953 #include <asm/reboot.h>
6954+#include <asm/bug.h>
6955
6956 /*
6957 * Urgs ... Too many MIPS machines to handle this in a generic way.
6958@@ -29,16 +30,19 @@ void machine_restart(char *command)
6959 {
6960 if (_machine_restart)
6961 _machine_restart(command);
6962+ BUG();
6963 }
6964
6965 void machine_halt(void)
6966 {
6967 if (_machine_halt)
6968 _machine_halt();
6969+ BUG();
6970 }
6971
6972 void machine_power_off(void)
6973 {
6974 if (pm_power_off)
6975 pm_power_off();
6976+ BUG();
6977 }
6978diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6979index c10aa84..9ec2e60 100644
6980--- a/arch/mips/kernel/smtc-proc.c
6981+++ b/arch/mips/kernel/smtc-proc.c
6982@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6983
6984 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6985
6986-atomic_t smtc_fpu_recoveries;
6987+atomic_unchecked_t smtc_fpu_recoveries;
6988
6989 static int smtc_proc_show(struct seq_file *m, void *v)
6990 {
6991@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6992 for(i = 0; i < NR_CPUS; i++)
6993 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6994 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6995- atomic_read(&smtc_fpu_recoveries));
6996+ atomic_read_unchecked(&smtc_fpu_recoveries));
6997 return 0;
6998 }
6999
7000@@ -73,7 +73,7 @@ void init_smtc_stats(void)
7001 smtc_cpu_stats[i].selfipis = 0;
7002 }
7003
7004- atomic_set(&smtc_fpu_recoveries, 0);
7005+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
7006
7007 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
7008 }
7009diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
7010index dfc1b91..11a2c07 100644
7011--- a/arch/mips/kernel/smtc.c
7012+++ b/arch/mips/kernel/smtc.c
7013@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
7014 }
7015 smtc_ipi_qdump();
7016 printk("%d Recoveries of \"stolen\" FPU\n",
7017- atomic_read(&smtc_fpu_recoveries));
7018+ atomic_read_unchecked(&smtc_fpu_recoveries));
7019 }
7020
7021
7022diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7023index c24ad5f..9983ab2 100644
7024--- a/arch/mips/kernel/sync-r4k.c
7025+++ b/arch/mips/kernel/sync-r4k.c
7026@@ -20,8 +20,8 @@
7027 #include <asm/mipsregs.h>
7028
7029 static atomic_t count_start_flag = ATOMIC_INIT(0);
7030-static atomic_t count_count_start = ATOMIC_INIT(0);
7031-static atomic_t count_count_stop = ATOMIC_INIT(0);
7032+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7033+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7034 static atomic_t count_reference = ATOMIC_INIT(0);
7035
7036 #define COUNTON 100
7037@@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
7038
7039 for (i = 0; i < NR_LOOPS; i++) {
7040 /* slaves loop on '!= 2' */
7041- while (atomic_read(&count_count_start) != 1)
7042+ while (atomic_read_unchecked(&count_count_start) != 1)
7043 mb();
7044- atomic_set(&count_count_stop, 0);
7045+ atomic_set_unchecked(&count_count_stop, 0);
7046 smp_wmb();
7047
7048 /* this lets the slaves write their count register */
7049- atomic_inc(&count_count_start);
7050+ atomic_inc_unchecked(&count_count_start);
7051
7052 /*
7053 * Everyone initialises count in the last loop:
7054@@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
7055 /*
7056 * Wait for all slaves to leave the synchronization point:
7057 */
7058- while (atomic_read(&count_count_stop) != 1)
7059+ while (atomic_read_unchecked(&count_count_stop) != 1)
7060 mb();
7061- atomic_set(&count_count_start, 0);
7062+ atomic_set_unchecked(&count_count_start, 0);
7063 smp_wmb();
7064- atomic_inc(&count_count_stop);
7065+ atomic_inc_unchecked(&count_count_stop);
7066 }
7067 /* Arrange for an interrupt in a short while */
7068 write_c0_compare(read_c0_count() + COUNTON);
7069@@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7070 initcount = atomic_read(&count_reference);
7071
7072 for (i = 0; i < NR_LOOPS; i++) {
7073- atomic_inc(&count_count_start);
7074- while (atomic_read(&count_count_start) != 2)
7075+ atomic_inc_unchecked(&count_count_start);
7076+ while (atomic_read_unchecked(&count_count_start) != 2)
7077 mb();
7078
7079 /*
7080@@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7081 if (i == NR_LOOPS-1)
7082 write_c0_count(initcount);
7083
7084- atomic_inc(&count_count_stop);
7085- while (atomic_read(&count_count_stop) != 2)
7086+ atomic_inc_unchecked(&count_count_stop);
7087+ while (atomic_read_unchecked(&count_count_stop) != 2)
7088 mb();
7089 }
7090 /* Arrange for an interrupt in a short while */
7091diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7092index 81e6ae0..6ab6e79 100644
7093--- a/arch/mips/kernel/traps.c
7094+++ b/arch/mips/kernel/traps.c
7095@@ -691,7 +691,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7096 siginfo_t info;
7097
7098 prev_state = exception_enter();
7099- die_if_kernel("Integer overflow", regs);
7100+ if (unlikely(!user_mode(regs))) {
7101+
7102+#ifdef CONFIG_PAX_REFCOUNT
7103+ if (fixup_exception(regs)) {
7104+ pax_report_refcount_overflow(regs);
7105+ exception_exit(prev_state);
7106+ return;
7107+ }
7108+#endif
7109+
7110+ die("Integer overflow", regs);
7111+ }
7112
7113 info.si_code = FPE_INTOVF;
7114 info.si_signo = SIGFPE;
7115diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7116index becc42b..9e43d4b 100644
7117--- a/arch/mips/mm/fault.c
7118+++ b/arch/mips/mm/fault.c
7119@@ -28,6 +28,23 @@
7120 #include <asm/highmem.h> /* For VMALLOC_END */
7121 #include <linux/kdebug.h>
7122
7123+#ifdef CONFIG_PAX_PAGEEXEC
7124+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7125+{
7126+ unsigned long i;
7127+
7128+ printk(KERN_ERR "PAX: bytes at PC: ");
7129+ for (i = 0; i < 5; i++) {
7130+ unsigned int c;
7131+ if (get_user(c, (unsigned int *)pc+i))
7132+ printk(KERN_CONT "???????? ");
7133+ else
7134+ printk(KERN_CONT "%08x ", c);
7135+ }
7136+ printk("\n");
7137+}
7138+#endif
7139+
7140 /*
7141 * This routine handles page faults. It determines the address,
7142 * and the problem, and then passes it off to one of the appropriate
7143@@ -199,6 +216,14 @@ bad_area:
7144 bad_area_nosemaphore:
7145 /* User mode accesses just cause a SIGSEGV */
7146 if (user_mode(regs)) {
7147+
7148+#ifdef CONFIG_PAX_PAGEEXEC
7149+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7150+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7151+ do_group_exit(SIGKILL);
7152+ }
7153+#endif
7154+
7155 tsk->thread.cp0_badvaddr = address;
7156 tsk->thread.error_code = write;
7157 #if 0
7158diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7159index f1baadd..5472dca 100644
7160--- a/arch/mips/mm/mmap.c
7161+++ b/arch/mips/mm/mmap.c
7162@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7163 struct vm_area_struct *vma;
7164 unsigned long addr = addr0;
7165 int do_color_align;
7166+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7167 struct vm_unmapped_area_info info;
7168
7169 if (unlikely(len > TASK_SIZE))
7170@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7171 do_color_align = 1;
7172
7173 /* requesting a specific address */
7174+
7175+#ifdef CONFIG_PAX_RANDMMAP
7176+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7177+#endif
7178+
7179 if (addr) {
7180 if (do_color_align)
7181 addr = COLOUR_ALIGN(addr, pgoff);
7182@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7183 addr = PAGE_ALIGN(addr);
7184
7185 vma = find_vma(mm, addr);
7186- if (TASK_SIZE - len >= addr &&
7187- (!vma || addr + len <= vma->vm_start))
7188+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7189 return addr;
7190 }
7191
7192 info.length = len;
7193 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7194 info.align_offset = pgoff << PAGE_SHIFT;
7195+ info.threadstack_offset = offset;
7196
7197 if (dir == DOWN) {
7198 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7199@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7200 {
7201 unsigned long random_factor = 0UL;
7202
7203+#ifdef CONFIG_PAX_RANDMMAP
7204+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7205+#endif
7206+
7207 if (current->flags & PF_RANDOMIZE) {
7208 random_factor = get_random_int();
7209 random_factor = random_factor << PAGE_SHIFT;
7210@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7211
7212 if (mmap_is_legacy()) {
7213 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7214+
7215+#ifdef CONFIG_PAX_RANDMMAP
7216+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7217+ mm->mmap_base += mm->delta_mmap;
7218+#endif
7219+
7220 mm->get_unmapped_area = arch_get_unmapped_area;
7221 } else {
7222 mm->mmap_base = mmap_base(random_factor);
7223+
7224+#ifdef CONFIG_PAX_RANDMMAP
7225+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7226+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7227+#endif
7228+
7229 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7230 }
7231 }
7232
7233-static inline unsigned long brk_rnd(void)
7234-{
7235- unsigned long rnd = get_random_int();
7236-
7237- rnd = rnd << PAGE_SHIFT;
7238- /* 8MB for 32bit, 256MB for 64bit */
7239- if (TASK_IS_32BIT_ADDR)
7240- rnd = rnd & 0x7ffffful;
7241- else
7242- rnd = rnd & 0xffffffful;
7243-
7244- return rnd;
7245-}
7246-
7247-unsigned long arch_randomize_brk(struct mm_struct *mm)
7248-{
7249- unsigned long base = mm->brk;
7250- unsigned long ret;
7251-
7252- ret = PAGE_ALIGN(base + brk_rnd());
7253-
7254- if (ret < mm->brk)
7255- return mm->brk;
7256-
7257- return ret;
7258-}
7259-
7260 int __virt_addr_valid(const volatile void *kaddr)
7261 {
7262 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7263diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7264index 59cccd9..f39ac2f 100644
7265--- a/arch/mips/pci/pci-octeon.c
7266+++ b/arch/mips/pci/pci-octeon.c
7267@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7268
7269
7270 static struct pci_ops octeon_pci_ops = {
7271- octeon_read_config,
7272- octeon_write_config,
7273+ .read = octeon_read_config,
7274+ .write = octeon_write_config,
7275 };
7276
7277 static struct resource octeon_pci_mem_resource = {
7278diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7279index 5e36c33..eb4a17b 100644
7280--- a/arch/mips/pci/pcie-octeon.c
7281+++ b/arch/mips/pci/pcie-octeon.c
7282@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7283 }
7284
7285 static struct pci_ops octeon_pcie0_ops = {
7286- octeon_pcie0_read_config,
7287- octeon_pcie0_write_config,
7288+ .read = octeon_pcie0_read_config,
7289+ .write = octeon_pcie0_write_config,
7290 };
7291
7292 static struct resource octeon_pcie0_mem_resource = {
7293@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7294 };
7295
7296 static struct pci_ops octeon_pcie1_ops = {
7297- octeon_pcie1_read_config,
7298- octeon_pcie1_write_config,
7299+ .read = octeon_pcie1_read_config,
7300+ .write = octeon_pcie1_write_config,
7301 };
7302
7303 static struct resource octeon_pcie1_mem_resource = {
7304@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7305 };
7306
7307 static struct pci_ops octeon_dummy_ops = {
7308- octeon_dummy_read_config,
7309- octeon_dummy_write_config,
7310+ .read = octeon_dummy_read_config,
7311+ .write = octeon_dummy_write_config,
7312 };
7313
7314 static struct resource octeon_dummy_mem_resource = {
7315diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7316index a2358b4..7cead4f 100644
7317--- a/arch/mips/sgi-ip27/ip27-nmi.c
7318+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7319@@ -187,9 +187,9 @@ void
7320 cont_nmi_dump(void)
7321 {
7322 #ifndef REAL_NMI_SIGNAL
7323- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7324+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7325
7326- atomic_inc(&nmied_cpus);
7327+ atomic_inc_unchecked(&nmied_cpus);
7328 #endif
7329 /*
7330 * Only allow 1 cpu to proceed
7331@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7332 udelay(10000);
7333 }
7334 #else
7335- while (atomic_read(&nmied_cpus) != num_online_cpus());
7336+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7337 #endif
7338
7339 /*
7340diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7341index a046b30..6799527 100644
7342--- a/arch/mips/sni/rm200.c
7343+++ b/arch/mips/sni/rm200.c
7344@@ -270,7 +270,7 @@ spurious_8259A_irq:
7345 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7346 spurious_irq_mask |= irqmask;
7347 }
7348- atomic_inc(&irq_err_count);
7349+ atomic_inc_unchecked(&irq_err_count);
7350 /*
7351 * Theoretically we do not have to handle this IRQ,
7352 * but in Linux this does not cause problems and is
7353diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7354index 41e873b..34d33a7 100644
7355--- a/arch/mips/vr41xx/common/icu.c
7356+++ b/arch/mips/vr41xx/common/icu.c
7357@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7358
7359 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7360
7361- atomic_inc(&irq_err_count);
7362+ atomic_inc_unchecked(&irq_err_count);
7363
7364 return -1;
7365 }
7366diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7367index ae0e4ee..e8f0692 100644
7368--- a/arch/mips/vr41xx/common/irq.c
7369+++ b/arch/mips/vr41xx/common/irq.c
7370@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7371 irq_cascade_t *cascade;
7372
7373 if (irq >= NR_IRQS) {
7374- atomic_inc(&irq_err_count);
7375+ atomic_inc_unchecked(&irq_err_count);
7376 return;
7377 }
7378
7379@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7380 ret = cascade->get_irq(irq);
7381 irq = ret;
7382 if (ret < 0)
7383- atomic_inc(&irq_err_count);
7384+ atomic_inc_unchecked(&irq_err_count);
7385 else
7386 irq_dispatch(irq);
7387 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7388diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7389index 967d144..db12197 100644
7390--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7391+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7392@@ -11,12 +11,14 @@
7393 #ifndef _ASM_PROC_CACHE_H
7394 #define _ASM_PROC_CACHE_H
7395
7396+#include <linux/const.h>
7397+
7398 /* L1 cache */
7399
7400 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7401 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7402-#define L1_CACHE_BYTES 16 /* bytes per entry */
7403 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7404+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7405 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7406
7407 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7408diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7409index bcb5df2..84fabd2 100644
7410--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7411+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7412@@ -16,13 +16,15 @@
7413 #ifndef _ASM_PROC_CACHE_H
7414 #define _ASM_PROC_CACHE_H
7415
7416+#include <linux/const.h>
7417+
7418 /*
7419 * L1 cache
7420 */
7421 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7422 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7423-#define L1_CACHE_BYTES 32 /* bytes per entry */
7424 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7425+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7426 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7427
7428 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7429diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7430index 4ce7a01..449202a 100644
7431--- a/arch/openrisc/include/asm/cache.h
7432+++ b/arch/openrisc/include/asm/cache.h
7433@@ -19,11 +19,13 @@
7434 #ifndef __ASM_OPENRISC_CACHE_H
7435 #define __ASM_OPENRISC_CACHE_H
7436
7437+#include <linux/const.h>
7438+
7439 /* FIXME: How can we replace these with values from the CPU...
7440 * they shouldn't be hard-coded!
7441 */
7442
7443-#define L1_CACHE_BYTES 16
7444 #define L1_CACHE_SHIFT 4
7445+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7446
7447 #endif /* __ASM_OPENRISC_CACHE_H */
7448diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7449index 472886c..00e7df9 100644
7450--- a/arch/parisc/include/asm/atomic.h
7451+++ b/arch/parisc/include/asm/atomic.h
7452@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7453 return dec;
7454 }
7455
7456+#define atomic64_read_unchecked(v) atomic64_read(v)
7457+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7458+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7459+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7460+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7461+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7462+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7463+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7464+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7465+
7466 #endif /* !CONFIG_64BIT */
7467
7468
7469diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7470index 47f11c7..3420df2 100644
7471--- a/arch/parisc/include/asm/cache.h
7472+++ b/arch/parisc/include/asm/cache.h
7473@@ -5,6 +5,7 @@
7474 #ifndef __ARCH_PARISC_CACHE_H
7475 #define __ARCH_PARISC_CACHE_H
7476
7477+#include <linux/const.h>
7478
7479 /*
7480 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7481@@ -15,13 +16,13 @@
7482 * just ruin performance.
7483 */
7484 #ifdef CONFIG_PA20
7485-#define L1_CACHE_BYTES 64
7486 #define L1_CACHE_SHIFT 6
7487 #else
7488-#define L1_CACHE_BYTES 32
7489 #define L1_CACHE_SHIFT 5
7490 #endif
7491
7492+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7493+
7494 #ifndef __ASSEMBLY__
7495
7496 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7497diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7498index 3391d06..c23a2cc 100644
7499--- a/arch/parisc/include/asm/elf.h
7500+++ b/arch/parisc/include/asm/elf.h
7501@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7502
7503 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7504
7505+#ifdef CONFIG_PAX_ASLR
7506+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7507+
7508+#define PAX_DELTA_MMAP_LEN 16
7509+#define PAX_DELTA_STACK_LEN 16
7510+#endif
7511+
7512 /* This yields a mask that user programs can use to figure out what
7513 instruction set this CPU supports. This could be done in user space,
7514 but it's not easy, and we've already done it here. */
7515diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7516index f213f5b..0af3e8e 100644
7517--- a/arch/parisc/include/asm/pgalloc.h
7518+++ b/arch/parisc/include/asm/pgalloc.h
7519@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7520 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7521 }
7522
7523+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7524+{
7525+ pgd_populate(mm, pgd, pmd);
7526+}
7527+
7528 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7529 {
7530 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7531@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7532 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7533 #define pmd_free(mm, x) do { } while (0)
7534 #define pgd_populate(mm, pmd, pte) BUG()
7535+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7536
7537 #endif
7538
7539diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7540index 22b89d1..ce34230 100644
7541--- a/arch/parisc/include/asm/pgtable.h
7542+++ b/arch/parisc/include/asm/pgtable.h
7543@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7544 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7545 #define PAGE_COPY PAGE_EXECREAD
7546 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7547+
7548+#ifdef CONFIG_PAX_PAGEEXEC
7549+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7550+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7551+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7552+#else
7553+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7554+# define PAGE_COPY_NOEXEC PAGE_COPY
7555+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7556+#endif
7557+
7558 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7559 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7560 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7561diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7562index 4006964..fcb3cc2 100644
7563--- a/arch/parisc/include/asm/uaccess.h
7564+++ b/arch/parisc/include/asm/uaccess.h
7565@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7566 const void __user *from,
7567 unsigned long n)
7568 {
7569- int sz = __compiletime_object_size(to);
7570+ size_t sz = __compiletime_object_size(to);
7571 int ret = -EFAULT;
7572
7573- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7574+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7575 ret = __copy_from_user(to, from, n);
7576 else
7577 copy_from_user_overflow();
7578diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7579index 50dfafc..b9fc230 100644
7580--- a/arch/parisc/kernel/module.c
7581+++ b/arch/parisc/kernel/module.c
7582@@ -98,16 +98,38 @@
7583
7584 /* three functions to determine where in the module core
7585 * or init pieces the location is */
7586+static inline int in_init_rx(struct module *me, void *loc)
7587+{
7588+ return (loc >= me->module_init_rx &&
7589+ loc < (me->module_init_rx + me->init_size_rx));
7590+}
7591+
7592+static inline int in_init_rw(struct module *me, void *loc)
7593+{
7594+ return (loc >= me->module_init_rw &&
7595+ loc < (me->module_init_rw + me->init_size_rw));
7596+}
7597+
7598 static inline int in_init(struct module *me, void *loc)
7599 {
7600- return (loc >= me->module_init &&
7601- loc <= (me->module_init + me->init_size));
7602+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7603+}
7604+
7605+static inline int in_core_rx(struct module *me, void *loc)
7606+{
7607+ return (loc >= me->module_core_rx &&
7608+ loc < (me->module_core_rx + me->core_size_rx));
7609+}
7610+
7611+static inline int in_core_rw(struct module *me, void *loc)
7612+{
7613+ return (loc >= me->module_core_rw &&
7614+ loc < (me->module_core_rw + me->core_size_rw));
7615 }
7616
7617 static inline int in_core(struct module *me, void *loc)
7618 {
7619- return (loc >= me->module_core &&
7620- loc <= (me->module_core + me->core_size));
7621+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7622 }
7623
7624 static inline int in_local(struct module *me, void *loc)
7625@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7626 }
7627
7628 /* align things a bit */
7629- me->core_size = ALIGN(me->core_size, 16);
7630- me->arch.got_offset = me->core_size;
7631- me->core_size += gots * sizeof(struct got_entry);
7632+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7633+ me->arch.got_offset = me->core_size_rw;
7634+ me->core_size_rw += gots * sizeof(struct got_entry);
7635
7636- me->core_size = ALIGN(me->core_size, 16);
7637- me->arch.fdesc_offset = me->core_size;
7638- me->core_size += fdescs * sizeof(Elf_Fdesc);
7639+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7640+ me->arch.fdesc_offset = me->core_size_rw;
7641+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7642
7643 me->arch.got_max = gots;
7644 me->arch.fdesc_max = fdescs;
7645@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7646
7647 BUG_ON(value == 0);
7648
7649- got = me->module_core + me->arch.got_offset;
7650+ got = me->module_core_rw + me->arch.got_offset;
7651 for (i = 0; got[i].addr; i++)
7652 if (got[i].addr == value)
7653 goto out;
7654@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7655 #ifdef CONFIG_64BIT
7656 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7657 {
7658- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7659+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7660
7661 if (!value) {
7662 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7663@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7664
7665 /* Create new one */
7666 fdesc->addr = value;
7667- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7668+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7669 return (Elf_Addr)fdesc;
7670 }
7671 #endif /* CONFIG_64BIT */
7672@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7673
7674 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7675 end = table + sechdrs[me->arch.unwind_section].sh_size;
7676- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7677+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7678
7679 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7680 me->arch.unwind_section, table, end, gp);
7681diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7682index 31ffa9b..588a798 100644
7683--- a/arch/parisc/kernel/sys_parisc.c
7684+++ b/arch/parisc/kernel/sys_parisc.c
7685@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7686 unsigned long task_size = TASK_SIZE;
7687 int do_color_align, last_mmap;
7688 struct vm_unmapped_area_info info;
7689+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7690
7691 if (len > task_size)
7692 return -ENOMEM;
7693@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7694 goto found_addr;
7695 }
7696
7697+#ifdef CONFIG_PAX_RANDMMAP
7698+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7699+#endif
7700+
7701 if (addr) {
7702 if (do_color_align && last_mmap)
7703 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7704@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7705 info.high_limit = mmap_upper_limit();
7706 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7707 info.align_offset = shared_align_offset(last_mmap, pgoff);
7708+ info.threadstack_offset = offset;
7709 addr = vm_unmapped_area(&info);
7710
7711 found_addr:
7712@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7713 unsigned long addr = addr0;
7714 int do_color_align, last_mmap;
7715 struct vm_unmapped_area_info info;
7716+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7717
7718 #ifdef CONFIG_64BIT
7719 /* This should only ever run for 32-bit processes. */
7720@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7721 }
7722
7723 /* requesting a specific address */
7724+#ifdef CONFIG_PAX_RANDMMAP
7725+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7726+#endif
7727+
7728 if (addr) {
7729 if (do_color_align && last_mmap)
7730 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7731@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7732 info.high_limit = mm->mmap_base;
7733 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7734 info.align_offset = shared_align_offset(last_mmap, pgoff);
7735+ info.threadstack_offset = offset;
7736 addr = vm_unmapped_area(&info);
7737 if (!(addr & ~PAGE_MASK))
7738 goto found_addr;
7739@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7740 mm->mmap_legacy_base = mmap_legacy_base();
7741 mm->mmap_base = mmap_upper_limit();
7742
7743+#ifdef CONFIG_PAX_RANDMMAP
7744+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7745+ mm->mmap_legacy_base += mm->delta_mmap;
7746+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7747+ }
7748+#endif
7749+
7750 if (mmap_is_legacy()) {
7751 mm->mmap_base = mm->mmap_legacy_base;
7752 mm->get_unmapped_area = arch_get_unmapped_area;
7753diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7754index 47ee620..1107387 100644
7755--- a/arch/parisc/kernel/traps.c
7756+++ b/arch/parisc/kernel/traps.c
7757@@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7758
7759 down_read(&current->mm->mmap_sem);
7760 vma = find_vma(current->mm,regs->iaoq[0]);
7761- if (vma && (regs->iaoq[0] >= vma->vm_start)
7762- && (vma->vm_flags & VM_EXEC)) {
7763-
7764+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7765 fault_address = regs->iaoq[0];
7766 fault_space = regs->iasq[0];
7767
7768diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7769index d72197f..c017c84 100644
7770--- a/arch/parisc/mm/fault.c
7771+++ b/arch/parisc/mm/fault.c
7772@@ -15,6 +15,7 @@
7773 #include <linux/sched.h>
7774 #include <linux/interrupt.h>
7775 #include <linux/module.h>
7776+#include <linux/unistd.h>
7777
7778 #include <asm/uaccess.h>
7779 #include <asm/traps.h>
7780@@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7781 static unsigned long
7782 parisc_acctyp(unsigned long code, unsigned int inst)
7783 {
7784- if (code == 6 || code == 16)
7785+ if (code == 6 || code == 7 || code == 16)
7786 return VM_EXEC;
7787
7788 switch (inst & 0xf0000000) {
7789@@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7790 }
7791 #endif
7792
7793+#ifdef CONFIG_PAX_PAGEEXEC
7794+/*
7795+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7796+ *
7797+ * returns 1 when task should be killed
7798+ * 2 when rt_sigreturn trampoline was detected
7799+ * 3 when unpatched PLT trampoline was detected
7800+ */
7801+static int pax_handle_fetch_fault(struct pt_regs *regs)
7802+{
7803+
7804+#ifdef CONFIG_PAX_EMUPLT
7805+ int err;
7806+
7807+ do { /* PaX: unpatched PLT emulation */
7808+ unsigned int bl, depwi;
7809+
7810+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7811+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7812+
7813+ if (err)
7814+ break;
7815+
7816+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7817+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7818+
7819+ err = get_user(ldw, (unsigned int *)addr);
7820+ err |= get_user(bv, (unsigned int *)(addr+4));
7821+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7822+
7823+ if (err)
7824+ break;
7825+
7826+ if (ldw == 0x0E801096U &&
7827+ bv == 0xEAC0C000U &&
7828+ ldw2 == 0x0E881095U)
7829+ {
7830+ unsigned int resolver, map;
7831+
7832+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7833+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7834+ if (err)
7835+ break;
7836+
7837+ regs->gr[20] = instruction_pointer(regs)+8;
7838+ regs->gr[21] = map;
7839+ regs->gr[22] = resolver;
7840+ regs->iaoq[0] = resolver | 3UL;
7841+ regs->iaoq[1] = regs->iaoq[0] + 4;
7842+ return 3;
7843+ }
7844+ }
7845+ } while (0);
7846+#endif
7847+
7848+#ifdef CONFIG_PAX_EMUTRAMP
7849+
7850+#ifndef CONFIG_PAX_EMUSIGRT
7851+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7852+ return 1;
7853+#endif
7854+
7855+ do { /* PaX: rt_sigreturn emulation */
7856+ unsigned int ldi1, ldi2, bel, nop;
7857+
7858+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7859+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7860+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7861+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7862+
7863+ if (err)
7864+ break;
7865+
7866+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7867+ ldi2 == 0x3414015AU &&
7868+ bel == 0xE4008200U &&
7869+ nop == 0x08000240U)
7870+ {
7871+ regs->gr[25] = (ldi1 & 2) >> 1;
7872+ regs->gr[20] = __NR_rt_sigreturn;
7873+ regs->gr[31] = regs->iaoq[1] + 16;
7874+ regs->sr[0] = regs->iasq[1];
7875+ regs->iaoq[0] = 0x100UL;
7876+ regs->iaoq[1] = regs->iaoq[0] + 4;
7877+ regs->iasq[0] = regs->sr[2];
7878+ regs->iasq[1] = regs->sr[2];
7879+ return 2;
7880+ }
7881+ } while (0);
7882+#endif
7883+
7884+ return 1;
7885+}
7886+
7887+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7888+{
7889+ unsigned long i;
7890+
7891+ printk(KERN_ERR "PAX: bytes at PC: ");
7892+ for (i = 0; i < 5; i++) {
7893+ unsigned int c;
7894+ if (get_user(c, (unsigned int *)pc+i))
7895+ printk(KERN_CONT "???????? ");
7896+ else
7897+ printk(KERN_CONT "%08x ", c);
7898+ }
7899+ printk("\n");
7900+}
7901+#endif
7902+
7903 int fixup_exception(struct pt_regs *regs)
7904 {
7905 const struct exception_table_entry *fix;
7906@@ -234,8 +345,33 @@ retry:
7907
7908 good_area:
7909
7910- if ((vma->vm_flags & acc_type) != acc_type)
7911+ if ((vma->vm_flags & acc_type) != acc_type) {
7912+
7913+#ifdef CONFIG_PAX_PAGEEXEC
7914+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7915+ (address & ~3UL) == instruction_pointer(regs))
7916+ {
7917+ up_read(&mm->mmap_sem);
7918+ switch (pax_handle_fetch_fault(regs)) {
7919+
7920+#ifdef CONFIG_PAX_EMUPLT
7921+ case 3:
7922+ return;
7923+#endif
7924+
7925+#ifdef CONFIG_PAX_EMUTRAMP
7926+ case 2:
7927+ return;
7928+#endif
7929+
7930+ }
7931+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7932+ do_group_exit(SIGKILL);
7933+ }
7934+#endif
7935+
7936 goto bad_area;
7937+ }
7938
7939 /*
7940 * If for any reason at all we couldn't handle the fault, make
7941diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7942index 957bf34..3430cc8 100644
7943--- a/arch/powerpc/Kconfig
7944+++ b/arch/powerpc/Kconfig
7945@@ -393,6 +393,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7946 config KEXEC
7947 bool "kexec system call"
7948 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7949+ depends on !GRKERNSEC_KMEM
7950 help
7951 kexec is a system call that implements the ability to shutdown your
7952 current kernel, and to start another kernel. It is like a reboot
7953diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7954index e3b1d41..8e81edf 100644
7955--- a/arch/powerpc/include/asm/atomic.h
7956+++ b/arch/powerpc/include/asm/atomic.h
7957@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7958 return t1;
7959 }
7960
7961+#define atomic64_read_unchecked(v) atomic64_read(v)
7962+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7963+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7964+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7965+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7966+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7967+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7968+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7969+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7970+
7971 #endif /* __powerpc64__ */
7972
7973 #endif /* __KERNEL__ */
7974diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
7975index f89da80..7f5b05a 100644
7976--- a/arch/powerpc/include/asm/barrier.h
7977+++ b/arch/powerpc/include/asm/barrier.h
7978@@ -73,7 +73,7 @@
7979 do { \
7980 compiletime_assert_atomic_type(*p); \
7981 __lwsync(); \
7982- ACCESS_ONCE(*p) = (v); \
7983+ ACCESS_ONCE_RW(*p) = (v); \
7984 } while (0)
7985
7986 #define smp_load_acquire(p) \
7987diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7988index ed0afc1..0332825 100644
7989--- a/arch/powerpc/include/asm/cache.h
7990+++ b/arch/powerpc/include/asm/cache.h
7991@@ -3,6 +3,7 @@
7992
7993 #ifdef __KERNEL__
7994
7995+#include <linux/const.h>
7996
7997 /* bytes per L1 cache line */
7998 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7999@@ -22,7 +23,7 @@
8000 #define L1_CACHE_SHIFT 7
8001 #endif
8002
8003-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8004+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8005
8006 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8007
8008diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8009index 935b5e7..7001d2d 100644
8010--- a/arch/powerpc/include/asm/elf.h
8011+++ b/arch/powerpc/include/asm/elf.h
8012@@ -28,8 +28,19 @@
8013 the loader. We need to make sure that it is out of the way of the program
8014 that it will "exec", and that there is sufficient room for the brk. */
8015
8016-extern unsigned long randomize_et_dyn(unsigned long base);
8017-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8018+#define ELF_ET_DYN_BASE (0x20000000)
8019+
8020+#ifdef CONFIG_PAX_ASLR
8021+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8022+
8023+#ifdef __powerpc64__
8024+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8025+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8026+#else
8027+#define PAX_DELTA_MMAP_LEN 15
8028+#define PAX_DELTA_STACK_LEN 15
8029+#endif
8030+#endif
8031
8032 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8033
8034@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8035 (0x7ff >> (PAGE_SHIFT - 12)) : \
8036 (0x3ffff >> (PAGE_SHIFT - 12)))
8037
8038-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8039-#define arch_randomize_brk arch_randomize_brk
8040-
8041-
8042 #ifdef CONFIG_SPU_BASE
8043 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8044 #define NT_SPU 1
8045diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8046index 8196e9c..d83a9f3 100644
8047--- a/arch/powerpc/include/asm/exec.h
8048+++ b/arch/powerpc/include/asm/exec.h
8049@@ -4,6 +4,6 @@
8050 #ifndef _ASM_POWERPC_EXEC_H
8051 #define _ASM_POWERPC_EXEC_H
8052
8053-extern unsigned long arch_align_stack(unsigned long sp);
8054+#define arch_align_stack(x) ((x) & ~0xfUL)
8055
8056 #endif /* _ASM_POWERPC_EXEC_H */
8057diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8058index 5acabbd..7ea14fa 100644
8059--- a/arch/powerpc/include/asm/kmap_types.h
8060+++ b/arch/powerpc/include/asm/kmap_types.h
8061@@ -10,7 +10,7 @@
8062 * 2 of the License, or (at your option) any later version.
8063 */
8064
8065-#define KM_TYPE_NR 16
8066+#define KM_TYPE_NR 17
8067
8068 #endif /* __KERNEL__ */
8069 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8070diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8071index b8da913..60b608a 100644
8072--- a/arch/powerpc/include/asm/local.h
8073+++ b/arch/powerpc/include/asm/local.h
8074@@ -9,15 +9,26 @@ typedef struct
8075 atomic_long_t a;
8076 } local_t;
8077
8078+typedef struct
8079+{
8080+ atomic_long_unchecked_t a;
8081+} local_unchecked_t;
8082+
8083 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8084
8085 #define local_read(l) atomic_long_read(&(l)->a)
8086+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8087 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8088+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8089
8090 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8091+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8092 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8093+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8094 #define local_inc(l) atomic_long_inc(&(l)->a)
8095+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8096 #define local_dec(l) atomic_long_dec(&(l)->a)
8097+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8098
8099 static __inline__ long local_add_return(long a, local_t *l)
8100 {
8101@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8102
8103 return t;
8104 }
8105+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8106
8107 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8108
8109@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8110
8111 return t;
8112 }
8113+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8114
8115 static __inline__ long local_inc_return(local_t *l)
8116 {
8117@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8118
8119 #define local_cmpxchg(l, o, n) \
8120 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8121+#define local_cmpxchg_unchecked(l, o, n) \
8122+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8123 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8124
8125 /**
8126diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8127index 8565c25..2865190 100644
8128--- a/arch/powerpc/include/asm/mman.h
8129+++ b/arch/powerpc/include/asm/mman.h
8130@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8131 }
8132 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8133
8134-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8135+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8136 {
8137 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8138 }
8139diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8140index 32e4e21..62afb12 100644
8141--- a/arch/powerpc/include/asm/page.h
8142+++ b/arch/powerpc/include/asm/page.h
8143@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8144 * and needs to be executable. This means the whole heap ends
8145 * up being executable.
8146 */
8147-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8148- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8149+#define VM_DATA_DEFAULT_FLAGS32 \
8150+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8151+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8152
8153 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8154 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8155@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8156 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8157 #endif
8158
8159+#define ktla_ktva(addr) (addr)
8160+#define ktva_ktla(addr) (addr)
8161+
8162 #ifndef CONFIG_PPC_BOOK3S_64
8163 /*
8164 * Use the top bit of the higher-level page table entries to indicate whether
8165diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8166index 88693ce..ac6f9ab 100644
8167--- a/arch/powerpc/include/asm/page_64.h
8168+++ b/arch/powerpc/include/asm/page_64.h
8169@@ -153,15 +153,18 @@ do { \
8170 * stack by default, so in the absence of a PT_GNU_STACK program header
8171 * we turn execute permission off.
8172 */
8173-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8174- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8175+#define VM_STACK_DEFAULT_FLAGS32 \
8176+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8177+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8178
8179 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8180 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8181
8182+#ifndef CONFIG_PAX_PAGEEXEC
8183 #define VM_STACK_DEFAULT_FLAGS \
8184 (is_32bit_task() ? \
8185 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8186+#endif
8187
8188 #include <asm-generic/getorder.h>
8189
8190diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8191index 4b0be20..c15a27d 100644
8192--- a/arch/powerpc/include/asm/pgalloc-64.h
8193+++ b/arch/powerpc/include/asm/pgalloc-64.h
8194@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8195 #ifndef CONFIG_PPC_64K_PAGES
8196
8197 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8198+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8199
8200 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8201 {
8202@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8203 pud_set(pud, (unsigned long)pmd);
8204 }
8205
8206+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8207+{
8208+ pud_populate(mm, pud, pmd);
8209+}
8210+
8211 #define pmd_populate(mm, pmd, pte_page) \
8212 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8213 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8214@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8215 #endif
8216
8217 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8218+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8219
8220 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8221 pte_t *pte)
8222diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8223index 3ebb188..e17dddf 100644
8224--- a/arch/powerpc/include/asm/pgtable.h
8225+++ b/arch/powerpc/include/asm/pgtable.h
8226@@ -2,6 +2,7 @@
8227 #define _ASM_POWERPC_PGTABLE_H
8228 #ifdef __KERNEL__
8229
8230+#include <linux/const.h>
8231 #ifndef __ASSEMBLY__
8232 #include <linux/mmdebug.h>
8233 #include <asm/processor.h> /* For TASK_SIZE */
8234diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8235index 4aad413..85d86bf 100644
8236--- a/arch/powerpc/include/asm/pte-hash32.h
8237+++ b/arch/powerpc/include/asm/pte-hash32.h
8238@@ -21,6 +21,7 @@
8239 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8240 #define _PAGE_USER 0x004 /* usermode access allowed */
8241 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8242+#define _PAGE_EXEC _PAGE_GUARDED
8243 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8244 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8245 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8246diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8247index ce17815..c5574cc 100644
8248--- a/arch/powerpc/include/asm/reg.h
8249+++ b/arch/powerpc/include/asm/reg.h
8250@@ -249,6 +249,7 @@
8251 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8252 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8253 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8254+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8255 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8256 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8257 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8258diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8259index 084e080..9415a3d 100644
8260--- a/arch/powerpc/include/asm/smp.h
8261+++ b/arch/powerpc/include/asm/smp.h
8262@@ -51,7 +51,7 @@ struct smp_ops_t {
8263 int (*cpu_disable)(void);
8264 void (*cpu_die)(unsigned int nr);
8265 int (*cpu_bootable)(unsigned int nr);
8266-};
8267+} __no_const;
8268
8269 extern void smp_send_debugger_break(void);
8270 extern void start_secondary_resume(void);
8271diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8272index b034ecd..af7e31f 100644
8273--- a/arch/powerpc/include/asm/thread_info.h
8274+++ b/arch/powerpc/include/asm/thread_info.h
8275@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8276 #if defined(CONFIG_PPC64)
8277 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8278 #endif
8279+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8280+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8281
8282 /* as above, but as bit values */
8283 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8284@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8285 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8286 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8287 #define _TIF_NOHZ (1<<TIF_NOHZ)
8288+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8289 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8290 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8291- _TIF_NOHZ)
8292+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8293
8294 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8295 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8296diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8297index 9485b43..3bd3c16 100644
8298--- a/arch/powerpc/include/asm/uaccess.h
8299+++ b/arch/powerpc/include/asm/uaccess.h
8300@@ -58,6 +58,7 @@
8301
8302 #endif
8303
8304+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8305 #define access_ok(type, addr, size) \
8306 (__chk_user_ptr(addr), \
8307 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8308@@ -318,52 +319,6 @@ do { \
8309 extern unsigned long __copy_tofrom_user(void __user *to,
8310 const void __user *from, unsigned long size);
8311
8312-#ifndef __powerpc64__
8313-
8314-static inline unsigned long copy_from_user(void *to,
8315- const void __user *from, unsigned long n)
8316-{
8317- unsigned long over;
8318-
8319- if (access_ok(VERIFY_READ, from, n))
8320- return __copy_tofrom_user((__force void __user *)to, from, n);
8321- if ((unsigned long)from < TASK_SIZE) {
8322- over = (unsigned long)from + n - TASK_SIZE;
8323- return __copy_tofrom_user((__force void __user *)to, from,
8324- n - over) + over;
8325- }
8326- return n;
8327-}
8328-
8329-static inline unsigned long copy_to_user(void __user *to,
8330- const void *from, unsigned long n)
8331-{
8332- unsigned long over;
8333-
8334- if (access_ok(VERIFY_WRITE, to, n))
8335- return __copy_tofrom_user(to, (__force void __user *)from, n);
8336- if ((unsigned long)to < TASK_SIZE) {
8337- over = (unsigned long)to + n - TASK_SIZE;
8338- return __copy_tofrom_user(to, (__force void __user *)from,
8339- n - over) + over;
8340- }
8341- return n;
8342-}
8343-
8344-#else /* __powerpc64__ */
8345-
8346-#define __copy_in_user(to, from, size) \
8347- __copy_tofrom_user((to), (from), (size))
8348-
8349-extern unsigned long copy_from_user(void *to, const void __user *from,
8350- unsigned long n);
8351-extern unsigned long copy_to_user(void __user *to, const void *from,
8352- unsigned long n);
8353-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8354- unsigned long n);
8355-
8356-#endif /* __powerpc64__ */
8357-
8358 static inline unsigned long __copy_from_user_inatomic(void *to,
8359 const void __user *from, unsigned long n)
8360 {
8361@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8362 if (ret == 0)
8363 return 0;
8364 }
8365+
8366+ if (!__builtin_constant_p(n))
8367+ check_object_size(to, n, false);
8368+
8369 return __copy_tofrom_user((__force void __user *)to, from, n);
8370 }
8371
8372@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8373 if (ret == 0)
8374 return 0;
8375 }
8376+
8377+ if (!__builtin_constant_p(n))
8378+ check_object_size(from, n, true);
8379+
8380 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8381 }
8382
8383@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8384 return __copy_to_user_inatomic(to, from, size);
8385 }
8386
8387+#ifndef __powerpc64__
8388+
8389+static inline unsigned long __must_check copy_from_user(void *to,
8390+ const void __user *from, unsigned long n)
8391+{
8392+ unsigned long over;
8393+
8394+ if ((long)n < 0)
8395+ return n;
8396+
8397+ if (access_ok(VERIFY_READ, from, n)) {
8398+ if (!__builtin_constant_p(n))
8399+ check_object_size(to, n, false);
8400+ return __copy_tofrom_user((__force void __user *)to, from, n);
8401+ }
8402+ if ((unsigned long)from < TASK_SIZE) {
8403+ over = (unsigned long)from + n - TASK_SIZE;
8404+ if (!__builtin_constant_p(n - over))
8405+ check_object_size(to, n - over, false);
8406+ return __copy_tofrom_user((__force void __user *)to, from,
8407+ n - over) + over;
8408+ }
8409+ return n;
8410+}
8411+
8412+static inline unsigned long __must_check copy_to_user(void __user *to,
8413+ const void *from, unsigned long n)
8414+{
8415+ unsigned long over;
8416+
8417+ if ((long)n < 0)
8418+ return n;
8419+
8420+ if (access_ok(VERIFY_WRITE, to, n)) {
8421+ if (!__builtin_constant_p(n))
8422+ check_object_size(from, n, true);
8423+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8424+ }
8425+ if ((unsigned long)to < TASK_SIZE) {
8426+ over = (unsigned long)to + n - TASK_SIZE;
8427+ if (!__builtin_constant_p(n))
8428+ check_object_size(from, n - over, true);
8429+ return __copy_tofrom_user(to, (__force void __user *)from,
8430+ n - over) + over;
8431+ }
8432+ return n;
8433+}
8434+
8435+#else /* __powerpc64__ */
8436+
8437+#define __copy_in_user(to, from, size) \
8438+ __copy_tofrom_user((to), (from), (size))
8439+
8440+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8441+{
8442+ if ((long)n < 0 || n > INT_MAX)
8443+ return n;
8444+
8445+ if (!__builtin_constant_p(n))
8446+ check_object_size(to, n, false);
8447+
8448+ if (likely(access_ok(VERIFY_READ, from, n)))
8449+ n = __copy_from_user(to, from, n);
8450+ else
8451+ memset(to, 0, n);
8452+ return n;
8453+}
8454+
8455+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8456+{
8457+ if ((long)n < 0 || n > INT_MAX)
8458+ return n;
8459+
8460+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8461+ if (!__builtin_constant_p(n))
8462+ check_object_size(from, n, true);
8463+ n = __copy_to_user(to, from, n);
8464+ }
8465+ return n;
8466+}
8467+
8468+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8469+ unsigned long n);
8470+
8471+#endif /* __powerpc64__ */
8472+
8473 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8474
8475 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8476diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8477index fcc9a89..07be2bb 100644
8478--- a/arch/powerpc/kernel/Makefile
8479+++ b/arch/powerpc/kernel/Makefile
8480@@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8481 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8482 endif
8483
8484+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8485+
8486 obj-y := cputable.o ptrace.o syscalls.o \
8487 irq.o align.o signal_32.o pmc.o vdso.o \
8488 process.o systbl.o idle.o \
8489diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8490index 063b65d..7a26e9d 100644
8491--- a/arch/powerpc/kernel/exceptions-64e.S
8492+++ b/arch/powerpc/kernel/exceptions-64e.S
8493@@ -771,6 +771,7 @@ storage_fault_common:
8494 std r14,_DAR(r1)
8495 std r15,_DSISR(r1)
8496 addi r3,r1,STACK_FRAME_OVERHEAD
8497+ bl .save_nvgprs
8498 mr r4,r14
8499 mr r5,r15
8500 ld r14,PACA_EXGEN+EX_R14(r13)
8501@@ -779,8 +780,7 @@ storage_fault_common:
8502 cmpdi r3,0
8503 bne- 1f
8504 b .ret_from_except_lite
8505-1: bl .save_nvgprs
8506- mr r5,r3
8507+1: mr r5,r3
8508 addi r3,r1,STACK_FRAME_OVERHEAD
8509 ld r4,_DAR(r1)
8510 bl .bad_page_fault
8511diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8512index 38d5073..f00af8d 100644
8513--- a/arch/powerpc/kernel/exceptions-64s.S
8514+++ b/arch/powerpc/kernel/exceptions-64s.S
8515@@ -1584,10 +1584,10 @@ handle_page_fault:
8516 11: ld r4,_DAR(r1)
8517 ld r5,_DSISR(r1)
8518 addi r3,r1,STACK_FRAME_OVERHEAD
8519+ bl .save_nvgprs
8520 bl .do_page_fault
8521 cmpdi r3,0
8522 beq+ 12f
8523- bl .save_nvgprs
8524 mr r5,r3
8525 addi r3,r1,STACK_FRAME_OVERHEAD
8526 lwz r4,_DAR(r1)
8527diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8528index 1d0848b..d74685f 100644
8529--- a/arch/powerpc/kernel/irq.c
8530+++ b/arch/powerpc/kernel/irq.c
8531@@ -447,6 +447,8 @@ void migrate_irqs(void)
8532 }
8533 #endif
8534
8535+extern void gr_handle_kernel_exploit(void);
8536+
8537 static inline void check_stack_overflow(void)
8538 {
8539 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8540@@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8541 printk("do_IRQ: stack overflow: %ld\n",
8542 sp - sizeof(struct thread_info));
8543 dump_stack();
8544+ gr_handle_kernel_exploit();
8545 }
8546 #endif
8547 }
8548diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8549index 6cff040..74ac5d1 100644
8550--- a/arch/powerpc/kernel/module_32.c
8551+++ b/arch/powerpc/kernel/module_32.c
8552@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8553 me->arch.core_plt_section = i;
8554 }
8555 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8556- printk("Module doesn't contain .plt or .init.plt sections.\n");
8557+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8558 return -ENOEXEC;
8559 }
8560
8561@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8562
8563 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8564 /* Init, or core PLT? */
8565- if (location >= mod->module_core
8566- && location < mod->module_core + mod->core_size)
8567+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8568+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8569 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8570- else
8571+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8572+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8573 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8574+ else {
8575+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8576+ return ~0UL;
8577+ }
8578
8579 /* Find this entry, or if that fails, the next avail. entry */
8580 while (entry->jump[0]) {
8581@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8582 }
8583 #ifdef CONFIG_DYNAMIC_FTRACE
8584 module->arch.tramp =
8585- do_plt_call(module->module_core,
8586+ do_plt_call(module->module_core_rx,
8587 (unsigned long)ftrace_caller,
8588 sechdrs, module);
8589 #endif
8590diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8591index 31d0215..206af70 100644
8592--- a/arch/powerpc/kernel/process.c
8593+++ b/arch/powerpc/kernel/process.c
8594@@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
8595 * Lookup NIP late so we have the best change of getting the
8596 * above info out without failing
8597 */
8598- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8599- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8600+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8601+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8602 #endif
8603 show_stack(current, (unsigned long *) regs->gpr[1]);
8604 if (!user_mode(regs))
8605@@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8606 newsp = stack[0];
8607 ip = stack[STACK_FRAME_LR_SAVE];
8608 if (!firstframe || ip != lr) {
8609- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8610+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8611 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8612 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8613- printk(" (%pS)",
8614+ printk(" (%pA)",
8615 (void *)current->ret_stack[curr_frame].ret);
8616 curr_frame--;
8617 }
8618@@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8619 struct pt_regs *regs = (struct pt_regs *)
8620 (sp + STACK_FRAME_OVERHEAD);
8621 lr = regs->link;
8622- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8623+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8624 regs->trap, (void *)regs->nip, (void *)lr);
8625 firstframe = 1;
8626 }
8627@@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
8628 mtspr(SPRN_CTRLT, ctrl);
8629 }
8630 #endif /* CONFIG_PPC64 */
8631-
8632-unsigned long arch_align_stack(unsigned long sp)
8633-{
8634- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8635- sp -= get_random_int() & ~PAGE_MASK;
8636- return sp & ~0xf;
8637-}
8638-
8639-static inline unsigned long brk_rnd(void)
8640-{
8641- unsigned long rnd = 0;
8642-
8643- /* 8MB for 32bit, 1GB for 64bit */
8644- if (is_32bit_task())
8645- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8646- else
8647- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8648-
8649- return rnd << PAGE_SHIFT;
8650-}
8651-
8652-unsigned long arch_randomize_brk(struct mm_struct *mm)
8653-{
8654- unsigned long base = mm->brk;
8655- unsigned long ret;
8656-
8657-#ifdef CONFIG_PPC_STD_MMU_64
8658- /*
8659- * If we are using 1TB segments and we are allowed to randomise
8660- * the heap, we can put it above 1TB so it is backed by a 1TB
8661- * segment. Otherwise the heap will be in the bottom 1TB
8662- * which always uses 256MB segments and this may result in a
8663- * performance penalty.
8664- */
8665- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8666- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8667-#endif
8668-
8669- ret = PAGE_ALIGN(base + brk_rnd());
8670-
8671- if (ret < mm->brk)
8672- return mm->brk;
8673-
8674- return ret;
8675-}
8676-
8677-unsigned long randomize_et_dyn(unsigned long base)
8678-{
8679- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8680-
8681- if (ret < base)
8682- return base;
8683-
8684- return ret;
8685-}
8686diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8687index 2e3d2bf..35df241 100644
8688--- a/arch/powerpc/kernel/ptrace.c
8689+++ b/arch/powerpc/kernel/ptrace.c
8690@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8691 return ret;
8692 }
8693
8694+#ifdef CONFIG_GRKERNSEC_SETXID
8695+extern void gr_delayed_cred_worker(void);
8696+#endif
8697+
8698 /*
8699 * We must return the syscall number to actually look up in the table.
8700 * This can be -1L to skip running any syscall at all.
8701@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8702
8703 secure_computing_strict(regs->gpr[0]);
8704
8705+#ifdef CONFIG_GRKERNSEC_SETXID
8706+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8707+ gr_delayed_cred_worker();
8708+#endif
8709+
8710 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8711 tracehook_report_syscall_entry(regs))
8712 /*
8713@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8714 {
8715 int step;
8716
8717+#ifdef CONFIG_GRKERNSEC_SETXID
8718+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8719+ gr_delayed_cred_worker();
8720+#endif
8721+
8722 audit_syscall_exit(regs);
8723
8724 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8725diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8726index 4e47db6..6dcc96e 100644
8727--- a/arch/powerpc/kernel/signal_32.c
8728+++ b/arch/powerpc/kernel/signal_32.c
8729@@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8730 /* Save user registers on the stack */
8731 frame = &rt_sf->uc.uc_mcontext;
8732 addr = frame;
8733- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8734+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8735 sigret = 0;
8736 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8737 } else {
8738diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8739index d501dc4..e5a0de0 100644
8740--- a/arch/powerpc/kernel/signal_64.c
8741+++ b/arch/powerpc/kernel/signal_64.c
8742@@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8743 current->thread.fp_state.fpscr = 0;
8744
8745 /* Set up to return from userspace. */
8746- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8747+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8748 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8749 } else {
8750 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8751diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8752index 33cd7a0..d615344 100644
8753--- a/arch/powerpc/kernel/traps.c
8754+++ b/arch/powerpc/kernel/traps.c
8755@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8756 return flags;
8757 }
8758
8759+extern void gr_handle_kernel_exploit(void);
8760+
8761 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8762 int signr)
8763 {
8764@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8765 panic("Fatal exception in interrupt");
8766 if (panic_on_oops)
8767 panic("Fatal exception");
8768+
8769+ gr_handle_kernel_exploit();
8770+
8771 do_exit(signr);
8772 }
8773
8774diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8775index 094e45c..d82b848 100644
8776--- a/arch/powerpc/kernel/vdso.c
8777+++ b/arch/powerpc/kernel/vdso.c
8778@@ -35,6 +35,7 @@
8779 #include <asm/vdso.h>
8780 #include <asm/vdso_datapage.h>
8781 #include <asm/setup.h>
8782+#include <asm/mman.h>
8783
8784 #undef DEBUG
8785
8786@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8787 vdso_base = VDSO32_MBASE;
8788 #endif
8789
8790- current->mm->context.vdso_base = 0;
8791+ current->mm->context.vdso_base = ~0UL;
8792
8793 /* vDSO has a problem and was disabled, just don't "enable" it for the
8794 * process
8795@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8796 vdso_base = get_unmapped_area(NULL, vdso_base,
8797 (vdso_pages << PAGE_SHIFT) +
8798 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8799- 0, 0);
8800+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8801 if (IS_ERR_VALUE(vdso_base)) {
8802 rc = vdso_base;
8803 goto fail_mmapsem;
8804diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8805index 3cf541a..ab2d825 100644
8806--- a/arch/powerpc/kvm/powerpc.c
8807+++ b/arch/powerpc/kvm/powerpc.c
8808@@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8809 }
8810 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8811
8812-int kvm_arch_init(void *opaque)
8813+int kvm_arch_init(const void *opaque)
8814 {
8815 return 0;
8816 }
8817diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8818index 5eea6f3..5d10396 100644
8819--- a/arch/powerpc/lib/usercopy_64.c
8820+++ b/arch/powerpc/lib/usercopy_64.c
8821@@ -9,22 +9,6 @@
8822 #include <linux/module.h>
8823 #include <asm/uaccess.h>
8824
8825-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8826-{
8827- if (likely(access_ok(VERIFY_READ, from, n)))
8828- n = __copy_from_user(to, from, n);
8829- else
8830- memset(to, 0, n);
8831- return n;
8832-}
8833-
8834-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8835-{
8836- if (likely(access_ok(VERIFY_WRITE, to, n)))
8837- n = __copy_to_user(to, from, n);
8838- return n;
8839-}
8840-
8841 unsigned long copy_in_user(void __user *to, const void __user *from,
8842 unsigned long n)
8843 {
8844@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8845 return n;
8846 }
8847
8848-EXPORT_SYMBOL(copy_from_user);
8849-EXPORT_SYMBOL(copy_to_user);
8850 EXPORT_SYMBOL(copy_in_user);
8851
8852diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8853index 51ab9e7..7d3c78b 100644
8854--- a/arch/powerpc/mm/fault.c
8855+++ b/arch/powerpc/mm/fault.c
8856@@ -33,6 +33,10 @@
8857 #include <linux/magic.h>
8858 #include <linux/ratelimit.h>
8859 #include <linux/context_tracking.h>
8860+#include <linux/slab.h>
8861+#include <linux/pagemap.h>
8862+#include <linux/compiler.h>
8863+#include <linux/unistd.h>
8864
8865 #include <asm/firmware.h>
8866 #include <asm/page.h>
8867@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8868 }
8869 #endif
8870
8871+#ifdef CONFIG_PAX_PAGEEXEC
8872+/*
8873+ * PaX: decide what to do with offenders (regs->nip = fault address)
8874+ *
8875+ * returns 1 when task should be killed
8876+ */
8877+static int pax_handle_fetch_fault(struct pt_regs *regs)
8878+{
8879+ return 1;
8880+}
8881+
8882+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8883+{
8884+ unsigned long i;
8885+
8886+ printk(KERN_ERR "PAX: bytes at PC: ");
8887+ for (i = 0; i < 5; i++) {
8888+ unsigned int c;
8889+ if (get_user(c, (unsigned int __user *)pc+i))
8890+ printk(KERN_CONT "???????? ");
8891+ else
8892+ printk(KERN_CONT "%08x ", c);
8893+ }
8894+ printk("\n");
8895+}
8896+#endif
8897+
8898 /*
8899 * Check whether the instruction at regs->nip is a store using
8900 * an update addressing form which will update r1.
8901@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8902 * indicate errors in DSISR but can validly be set in SRR1.
8903 */
8904 if (trap == 0x400)
8905- error_code &= 0x48200000;
8906+ error_code &= 0x58200000;
8907 else
8908 is_write = error_code & DSISR_ISSTORE;
8909 #else
8910@@ -378,7 +409,7 @@ good_area:
8911 * "undefined". Of those that can be set, this is the only
8912 * one which seems bad.
8913 */
8914- if (error_code & 0x10000000)
8915+ if (error_code & DSISR_GUARDED)
8916 /* Guarded storage error. */
8917 goto bad_area;
8918 #endif /* CONFIG_8xx */
8919@@ -393,7 +424,7 @@ good_area:
8920 * processors use the same I/D cache coherency mechanism
8921 * as embedded.
8922 */
8923- if (error_code & DSISR_PROTFAULT)
8924+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8925 goto bad_area;
8926 #endif /* CONFIG_PPC_STD_MMU */
8927
8928@@ -483,6 +514,23 @@ bad_area:
8929 bad_area_nosemaphore:
8930 /* User mode accesses cause a SIGSEGV */
8931 if (user_mode(regs)) {
8932+
8933+#ifdef CONFIG_PAX_PAGEEXEC
8934+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8935+#ifdef CONFIG_PPC_STD_MMU
8936+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8937+#else
8938+ if (is_exec && regs->nip == address) {
8939+#endif
8940+ switch (pax_handle_fetch_fault(regs)) {
8941+ }
8942+
8943+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8944+ do_group_exit(SIGKILL);
8945+ }
8946+ }
8947+#endif
8948+
8949 _exception(SIGSEGV, regs, code, address);
8950 goto bail;
8951 }
8952diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8953index cb8bdbe..cde4bc7 100644
8954--- a/arch/powerpc/mm/mmap.c
8955+++ b/arch/powerpc/mm/mmap.c
8956@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8957 return sysctl_legacy_va_layout;
8958 }
8959
8960-static unsigned long mmap_rnd(void)
8961+static unsigned long mmap_rnd(struct mm_struct *mm)
8962 {
8963 unsigned long rnd = 0;
8964
8965+#ifdef CONFIG_PAX_RANDMMAP
8966+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8967+#endif
8968+
8969 if (current->flags & PF_RANDOMIZE) {
8970 /* 8MB for 32bit, 1GB for 64bit */
8971 if (is_32bit_task())
8972@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8973 return rnd << PAGE_SHIFT;
8974 }
8975
8976-static inline unsigned long mmap_base(void)
8977+static inline unsigned long mmap_base(struct mm_struct *mm)
8978 {
8979 unsigned long gap = rlimit(RLIMIT_STACK);
8980
8981@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8982 else if (gap > MAX_GAP)
8983 gap = MAX_GAP;
8984
8985- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8986+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8987 }
8988
8989 /*
8990@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8991 */
8992 if (mmap_is_legacy()) {
8993 mm->mmap_base = TASK_UNMAPPED_BASE;
8994+
8995+#ifdef CONFIG_PAX_RANDMMAP
8996+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8997+ mm->mmap_base += mm->delta_mmap;
8998+#endif
8999+
9000 mm->get_unmapped_area = arch_get_unmapped_area;
9001 } else {
9002- mm->mmap_base = mmap_base();
9003+ mm->mmap_base = mmap_base(mm);
9004+
9005+#ifdef CONFIG_PAX_RANDMMAP
9006+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9007+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9008+#endif
9009+
9010 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9011 }
9012 }
9013diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9014index b0c75cc..ef7fb93 100644
9015--- a/arch/powerpc/mm/slice.c
9016+++ b/arch/powerpc/mm/slice.c
9017@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9018 if ((mm->task_size - len) < addr)
9019 return 0;
9020 vma = find_vma(mm, addr);
9021- return (!vma || (addr + len) <= vma->vm_start);
9022+ return check_heap_stack_gap(vma, addr, len, 0);
9023 }
9024
9025 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9026@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9027 info.align_offset = 0;
9028
9029 addr = TASK_UNMAPPED_BASE;
9030+
9031+#ifdef CONFIG_PAX_RANDMMAP
9032+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9033+ addr += mm->delta_mmap;
9034+#endif
9035+
9036 while (addr < TASK_SIZE) {
9037 info.low_limit = addr;
9038 if (!slice_scan_available(addr, available, 1, &addr))
9039@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9040 if (fixed && addr > (mm->task_size - len))
9041 return -ENOMEM;
9042
9043+#ifdef CONFIG_PAX_RANDMMAP
9044+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9045+ addr = 0;
9046+#endif
9047+
9048 /* If hint, make sure it matches our alignment restrictions */
9049 if (!fixed && addr) {
9050 addr = _ALIGN_UP(addr, 1ul << pshift);
9051diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9052index 4278acf..67fd0e6 100644
9053--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9054+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9055@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9056 }
9057
9058 static struct pci_ops scc_pciex_pci_ops = {
9059- scc_pciex_read_config,
9060- scc_pciex_write_config,
9061+ .read = scc_pciex_read_config,
9062+ .write = scc_pciex_write_config,
9063 };
9064
9065 static void pciex_clear_intr_all(unsigned int __iomem *base)
9066diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9067index 9098692..3d54cd1 100644
9068--- a/arch/powerpc/platforms/cell/spufs/file.c
9069+++ b/arch/powerpc/platforms/cell/spufs/file.c
9070@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9071 return VM_FAULT_NOPAGE;
9072 }
9073
9074-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9075+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9076 unsigned long address,
9077- void *buf, int len, int write)
9078+ void *buf, size_t len, int write)
9079 {
9080 struct spu_context *ctx = vma->vm_file->private_data;
9081 unsigned long offset = address - vma->vm_start;
9082diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9083index 1d47061..0714963 100644
9084--- a/arch/s390/include/asm/atomic.h
9085+++ b/arch/s390/include/asm/atomic.h
9086@@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9087 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9088 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9089
9090+#define atomic64_read_unchecked(v) atomic64_read(v)
9091+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9092+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9093+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9094+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9095+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9096+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9097+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9098+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9099+
9100 #define smp_mb__before_atomic_dec() smp_mb()
9101 #define smp_mb__after_atomic_dec() smp_mb()
9102 #define smp_mb__before_atomic_inc() smp_mb()
9103diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9104index 578680f..0eb3b11 100644
9105--- a/arch/s390/include/asm/barrier.h
9106+++ b/arch/s390/include/asm/barrier.h
9107@@ -36,7 +36,7 @@
9108 do { \
9109 compiletime_assert_atomic_type(*p); \
9110 barrier(); \
9111- ACCESS_ONCE(*p) = (v); \
9112+ ACCESS_ONCE_RW(*p) = (v); \
9113 } while (0)
9114
9115 #define smp_load_acquire(p) \
9116diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9117index 4d7ccac..d03d0ad 100644
9118--- a/arch/s390/include/asm/cache.h
9119+++ b/arch/s390/include/asm/cache.h
9120@@ -9,8 +9,10 @@
9121 #ifndef __ARCH_S390_CACHE_H
9122 #define __ARCH_S390_CACHE_H
9123
9124-#define L1_CACHE_BYTES 256
9125+#include <linux/const.h>
9126+
9127 #define L1_CACHE_SHIFT 8
9128+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9129 #define NET_SKB_PAD 32
9130
9131 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9132diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9133index 78f4f87..598ce39 100644
9134--- a/arch/s390/include/asm/elf.h
9135+++ b/arch/s390/include/asm/elf.h
9136@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9137 the loader. We need to make sure that it is out of the way of the program
9138 that it will "exec", and that there is sufficient room for the brk. */
9139
9140-extern unsigned long randomize_et_dyn(unsigned long base);
9141-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9142+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9143+
9144+#ifdef CONFIG_PAX_ASLR
9145+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9146+
9147+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9148+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9149+#endif
9150
9151 /* This yields a mask that user programs can use to figure out what
9152 instruction set this CPU supports. */
9153@@ -222,9 +228,6 @@ struct linux_binprm;
9154 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9155 int arch_setup_additional_pages(struct linux_binprm *, int);
9156
9157-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9158-#define arch_randomize_brk arch_randomize_brk
9159-
9160 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9161
9162 #endif
9163diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9164index c4a93d6..4d2a9b4 100644
9165--- a/arch/s390/include/asm/exec.h
9166+++ b/arch/s390/include/asm/exec.h
9167@@ -7,6 +7,6 @@
9168 #ifndef __ASM_EXEC_H
9169 #define __ASM_EXEC_H
9170
9171-extern unsigned long arch_align_stack(unsigned long sp);
9172+#define arch_align_stack(x) ((x) & ~0xfUL)
9173
9174 #endif /* __ASM_EXEC_H */
9175diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9176index 79330af..254cf37 100644
9177--- a/arch/s390/include/asm/uaccess.h
9178+++ b/arch/s390/include/asm/uaccess.h
9179@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9180 __range_ok((unsigned long)(addr), (size)); \
9181 })
9182
9183+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9184 #define access_ok(type, addr, size) __access_ok(addr, size)
9185
9186 /*
9187@@ -245,6 +246,10 @@ static inline unsigned long __must_check
9188 copy_to_user(void __user *to, const void *from, unsigned long n)
9189 {
9190 might_fault();
9191+
9192+ if ((long)n < 0)
9193+ return n;
9194+
9195 return __copy_to_user(to, from, n);
9196 }
9197
9198@@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9199 static inline unsigned long __must_check
9200 __copy_from_user(void *to, const void __user *from, unsigned long n)
9201 {
9202+ if ((long)n < 0)
9203+ return n;
9204+
9205 return uaccess.copy_from_user(n, from, to);
9206 }
9207
9208@@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9209 static inline unsigned long __must_check
9210 copy_from_user(void *to, const void __user *from, unsigned long n)
9211 {
9212- unsigned int sz = __compiletime_object_size(to);
9213+ size_t sz = __compiletime_object_size(to);
9214
9215 might_fault();
9216- if (unlikely(sz != -1 && sz < n)) {
9217+
9218+ if ((long)n < 0)
9219+ return n;
9220+
9221+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9222 copy_from_user_overflow();
9223 return n;
9224 }
9225diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9226index b89b591..fd9609d 100644
9227--- a/arch/s390/kernel/module.c
9228+++ b/arch/s390/kernel/module.c
9229@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9230
9231 /* Increase core size by size of got & plt and set start
9232 offsets for got and plt. */
9233- me->core_size = ALIGN(me->core_size, 4);
9234- me->arch.got_offset = me->core_size;
9235- me->core_size += me->arch.got_size;
9236- me->arch.plt_offset = me->core_size;
9237- me->core_size += me->arch.plt_size;
9238+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9239+ me->arch.got_offset = me->core_size_rw;
9240+ me->core_size_rw += me->arch.got_size;
9241+ me->arch.plt_offset = me->core_size_rx;
9242+ me->core_size_rx += me->arch.plt_size;
9243 return 0;
9244 }
9245
9246@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9247 if (info->got_initialized == 0) {
9248 Elf_Addr *gotent;
9249
9250- gotent = me->module_core + me->arch.got_offset +
9251+ gotent = me->module_core_rw + me->arch.got_offset +
9252 info->got_offset;
9253 *gotent = val;
9254 info->got_initialized = 1;
9255@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9256 rc = apply_rela_bits(loc, val, 0, 64, 0);
9257 else if (r_type == R_390_GOTENT ||
9258 r_type == R_390_GOTPLTENT) {
9259- val += (Elf_Addr) me->module_core - loc;
9260+ val += (Elf_Addr) me->module_core_rw - loc;
9261 rc = apply_rela_bits(loc, val, 1, 32, 1);
9262 }
9263 break;
9264@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9265 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9266 if (info->plt_initialized == 0) {
9267 unsigned int *ip;
9268- ip = me->module_core + me->arch.plt_offset +
9269+ ip = me->module_core_rx + me->arch.plt_offset +
9270 info->plt_offset;
9271 #ifndef CONFIG_64BIT
9272 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9273@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9274 val - loc + 0xffffUL < 0x1ffffeUL) ||
9275 (r_type == R_390_PLT32DBL &&
9276 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9277- val = (Elf_Addr) me->module_core +
9278+ val = (Elf_Addr) me->module_core_rx +
9279 me->arch.plt_offset +
9280 info->plt_offset;
9281 val += rela->r_addend - loc;
9282@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9283 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9284 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9285 val = val + rela->r_addend -
9286- ((Elf_Addr) me->module_core + me->arch.got_offset);
9287+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9288 if (r_type == R_390_GOTOFF16)
9289 rc = apply_rela_bits(loc, val, 0, 16, 0);
9290 else if (r_type == R_390_GOTOFF32)
9291@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9292 break;
9293 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9294 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9295- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9296+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9297 rela->r_addend - loc;
9298 if (r_type == R_390_GOTPC)
9299 rc = apply_rela_bits(loc, val, 1, 32, 0);
9300diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9301index dd14532..1dfc145 100644
9302--- a/arch/s390/kernel/process.c
9303+++ b/arch/s390/kernel/process.c
9304@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9305 }
9306 return 0;
9307 }
9308-
9309-unsigned long arch_align_stack(unsigned long sp)
9310-{
9311- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9312- sp -= get_random_int() & ~PAGE_MASK;
9313- return sp & ~0xf;
9314-}
9315-
9316-static inline unsigned long brk_rnd(void)
9317-{
9318- /* 8MB for 32bit, 1GB for 64bit */
9319- if (is_32bit_task())
9320- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9321- else
9322- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9323-}
9324-
9325-unsigned long arch_randomize_brk(struct mm_struct *mm)
9326-{
9327- unsigned long ret;
9328-
9329- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9330- return (ret > mm->brk) ? ret : mm->brk;
9331-}
9332-
9333-unsigned long randomize_et_dyn(unsigned long base)
9334-{
9335- unsigned long ret;
9336-
9337- if (!(current->flags & PF_RANDOMIZE))
9338- return base;
9339- ret = PAGE_ALIGN(base + brk_rnd());
9340- return (ret > base) ? ret : base;
9341-}
9342diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9343index 9b436c2..54fbf0a 100644
9344--- a/arch/s390/mm/mmap.c
9345+++ b/arch/s390/mm/mmap.c
9346@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9347 */
9348 if (mmap_is_legacy()) {
9349 mm->mmap_base = mmap_base_legacy();
9350+
9351+#ifdef CONFIG_PAX_RANDMMAP
9352+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9353+ mm->mmap_base += mm->delta_mmap;
9354+#endif
9355+
9356 mm->get_unmapped_area = arch_get_unmapped_area;
9357 } else {
9358 mm->mmap_base = mmap_base();
9359+
9360+#ifdef CONFIG_PAX_RANDMMAP
9361+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9362+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9363+#endif
9364+
9365 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9366 }
9367 }
9368@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9369 */
9370 if (mmap_is_legacy()) {
9371 mm->mmap_base = mmap_base_legacy();
9372+
9373+#ifdef CONFIG_PAX_RANDMMAP
9374+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9375+ mm->mmap_base += mm->delta_mmap;
9376+#endif
9377+
9378 mm->get_unmapped_area = s390_get_unmapped_area;
9379 } else {
9380 mm->mmap_base = mmap_base();
9381+
9382+#ifdef CONFIG_PAX_RANDMMAP
9383+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9384+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9385+#endif
9386+
9387 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9388 }
9389 }
9390diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9391index ae3d59f..f65f075 100644
9392--- a/arch/score/include/asm/cache.h
9393+++ b/arch/score/include/asm/cache.h
9394@@ -1,7 +1,9 @@
9395 #ifndef _ASM_SCORE_CACHE_H
9396 #define _ASM_SCORE_CACHE_H
9397
9398+#include <linux/const.h>
9399+
9400 #define L1_CACHE_SHIFT 4
9401-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9402+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9403
9404 #endif /* _ASM_SCORE_CACHE_H */
9405diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9406index f9f3cd5..58ff438 100644
9407--- a/arch/score/include/asm/exec.h
9408+++ b/arch/score/include/asm/exec.h
9409@@ -1,6 +1,6 @@
9410 #ifndef _ASM_SCORE_EXEC_H
9411 #define _ASM_SCORE_EXEC_H
9412
9413-extern unsigned long arch_align_stack(unsigned long sp);
9414+#define arch_align_stack(x) (x)
9415
9416 #endif /* _ASM_SCORE_EXEC_H */
9417diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9418index a1519ad3..e8ac1ff 100644
9419--- a/arch/score/kernel/process.c
9420+++ b/arch/score/kernel/process.c
9421@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9422
9423 return task_pt_regs(task)->cp0_epc;
9424 }
9425-
9426-unsigned long arch_align_stack(unsigned long sp)
9427-{
9428- return sp;
9429-}
9430diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9431index ef9e555..331bd29 100644
9432--- a/arch/sh/include/asm/cache.h
9433+++ b/arch/sh/include/asm/cache.h
9434@@ -9,10 +9,11 @@
9435 #define __ASM_SH_CACHE_H
9436 #ifdef __KERNEL__
9437
9438+#include <linux/const.h>
9439 #include <linux/init.h>
9440 #include <cpu/cache.h>
9441
9442-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9443+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9444
9445 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9446
9447diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9448index 6777177..cb5e44f 100644
9449--- a/arch/sh/mm/mmap.c
9450+++ b/arch/sh/mm/mmap.c
9451@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9452 struct mm_struct *mm = current->mm;
9453 struct vm_area_struct *vma;
9454 int do_colour_align;
9455+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9456 struct vm_unmapped_area_info info;
9457
9458 if (flags & MAP_FIXED) {
9459@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9460 if (filp || (flags & MAP_SHARED))
9461 do_colour_align = 1;
9462
9463+#ifdef CONFIG_PAX_RANDMMAP
9464+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9465+#endif
9466+
9467 if (addr) {
9468 if (do_colour_align)
9469 addr = COLOUR_ALIGN(addr, pgoff);
9470@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9471 addr = PAGE_ALIGN(addr);
9472
9473 vma = find_vma(mm, addr);
9474- if (TASK_SIZE - len >= addr &&
9475- (!vma || addr + len <= vma->vm_start))
9476+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9477 return addr;
9478 }
9479
9480 info.flags = 0;
9481 info.length = len;
9482- info.low_limit = TASK_UNMAPPED_BASE;
9483+ info.low_limit = mm->mmap_base;
9484 info.high_limit = TASK_SIZE;
9485 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9486 info.align_offset = pgoff << PAGE_SHIFT;
9487@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9488 struct mm_struct *mm = current->mm;
9489 unsigned long addr = addr0;
9490 int do_colour_align;
9491+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9492 struct vm_unmapped_area_info info;
9493
9494 if (flags & MAP_FIXED) {
9495@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9496 if (filp || (flags & MAP_SHARED))
9497 do_colour_align = 1;
9498
9499+#ifdef CONFIG_PAX_RANDMMAP
9500+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9501+#endif
9502+
9503 /* requesting a specific address */
9504 if (addr) {
9505 if (do_colour_align)
9506@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9507 addr = PAGE_ALIGN(addr);
9508
9509 vma = find_vma(mm, addr);
9510- if (TASK_SIZE - len >= addr &&
9511- (!vma || addr + len <= vma->vm_start))
9512+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9513 return addr;
9514 }
9515
9516@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9517 VM_BUG_ON(addr != -ENOMEM);
9518 info.flags = 0;
9519 info.low_limit = TASK_UNMAPPED_BASE;
9520+
9521+#ifdef CONFIG_PAX_RANDMMAP
9522+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9523+ info.low_limit += mm->delta_mmap;
9524+#endif
9525+
9526 info.high_limit = TASK_SIZE;
9527 addr = vm_unmapped_area(&info);
9528 }
9529diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9530index be56a24..443328f 100644
9531--- a/arch/sparc/include/asm/atomic_64.h
9532+++ b/arch/sparc/include/asm/atomic_64.h
9533@@ -14,18 +14,40 @@
9534 #define ATOMIC64_INIT(i) { (i) }
9535
9536 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9537+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9538+{
9539+ return v->counter;
9540+}
9541 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9542+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9543+{
9544+ return v->counter;
9545+}
9546
9547 #define atomic_set(v, i) (((v)->counter) = i)
9548+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9549+{
9550+ v->counter = i;
9551+}
9552 #define atomic64_set(v, i) (((v)->counter) = i)
9553+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9554+{
9555+ v->counter = i;
9556+}
9557
9558 extern void atomic_add(int, atomic_t *);
9559+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9560 extern void atomic64_add(long, atomic64_t *);
9561+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9562 extern void atomic_sub(int, atomic_t *);
9563+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9564 extern void atomic64_sub(long, atomic64_t *);
9565+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9566
9567 extern int atomic_add_ret(int, atomic_t *);
9568+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9569 extern long atomic64_add_ret(long, atomic64_t *);
9570+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9571 extern int atomic_sub_ret(int, atomic_t *);
9572 extern long atomic64_sub_ret(long, atomic64_t *);
9573
9574@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9575 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9576
9577 #define atomic_inc_return(v) atomic_add_ret(1, v)
9578+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9579+{
9580+ return atomic_add_ret_unchecked(1, v);
9581+}
9582 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9583+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9584+{
9585+ return atomic64_add_ret_unchecked(1, v);
9586+}
9587
9588 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9589 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9590
9591 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9592+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9593+{
9594+ return atomic_add_ret_unchecked(i, v);
9595+}
9596 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9597+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9598+{
9599+ return atomic64_add_ret_unchecked(i, v);
9600+}
9601
9602 /*
9603 * atomic_inc_and_test - increment and test
9604@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9605 * other cases.
9606 */
9607 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9608+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9609+{
9610+ return atomic_inc_return_unchecked(v) == 0;
9611+}
9612 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9613
9614 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9615@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9616 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9617
9618 #define atomic_inc(v) atomic_add(1, v)
9619+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9620+{
9621+ atomic_add_unchecked(1, v);
9622+}
9623 #define atomic64_inc(v) atomic64_add(1, v)
9624+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9625+{
9626+ atomic64_add_unchecked(1, v);
9627+}
9628
9629 #define atomic_dec(v) atomic_sub(1, v)
9630+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9631+{
9632+ atomic_sub_unchecked(1, v);
9633+}
9634 #define atomic64_dec(v) atomic64_sub(1, v)
9635+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9636+{
9637+ atomic64_sub_unchecked(1, v);
9638+}
9639
9640 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9641 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9642
9643 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9644+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9645+{
9646+ return cmpxchg(&v->counter, old, new);
9647+}
9648 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9649+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9650+{
9651+ return xchg(&v->counter, new);
9652+}
9653
9654 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9655 {
9656- int c, old;
9657+ int c, old, new;
9658 c = atomic_read(v);
9659 for (;;) {
9660- if (unlikely(c == (u)))
9661+ if (unlikely(c == u))
9662 break;
9663- old = atomic_cmpxchg((v), c, c + (a));
9664+
9665+ asm volatile("addcc %2, %0, %0\n"
9666+
9667+#ifdef CONFIG_PAX_REFCOUNT
9668+ "tvs %%icc, 6\n"
9669+#endif
9670+
9671+ : "=r" (new)
9672+ : "0" (c), "ir" (a)
9673+ : "cc");
9674+
9675+ old = atomic_cmpxchg(v, c, new);
9676 if (likely(old == c))
9677 break;
9678 c = old;
9679@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9680 #define atomic64_cmpxchg(v, o, n) \
9681 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9682 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9683+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9684+{
9685+ return xchg(&v->counter, new);
9686+}
9687
9688 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9689 {
9690- long c, old;
9691+ long c, old, new;
9692 c = atomic64_read(v);
9693 for (;;) {
9694- if (unlikely(c == (u)))
9695+ if (unlikely(c == u))
9696 break;
9697- old = atomic64_cmpxchg((v), c, c + (a));
9698+
9699+ asm volatile("addcc %2, %0, %0\n"
9700+
9701+#ifdef CONFIG_PAX_REFCOUNT
9702+ "tvs %%xcc, 6\n"
9703+#endif
9704+
9705+ : "=r" (new)
9706+ : "0" (c), "ir" (a)
9707+ : "cc");
9708+
9709+ old = atomic64_cmpxchg(v, c, new);
9710 if (likely(old == c))
9711 break;
9712 c = old;
9713 }
9714- return c != (u);
9715+ return c != u;
9716 }
9717
9718 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9719diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
9720index b5aad96..99d7465 100644
9721--- a/arch/sparc/include/asm/barrier_64.h
9722+++ b/arch/sparc/include/asm/barrier_64.h
9723@@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
9724 do { \
9725 compiletime_assert_atomic_type(*p); \
9726 barrier(); \
9727- ACCESS_ONCE(*p) = (v); \
9728+ ACCESS_ONCE_RW(*p) = (v); \
9729 } while (0)
9730
9731 #define smp_load_acquire(p) \
9732diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9733index 5bb6991..5c2132e 100644
9734--- a/arch/sparc/include/asm/cache.h
9735+++ b/arch/sparc/include/asm/cache.h
9736@@ -7,10 +7,12 @@
9737 #ifndef _SPARC_CACHE_H
9738 #define _SPARC_CACHE_H
9739
9740+#include <linux/const.h>
9741+
9742 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9743
9744 #define L1_CACHE_SHIFT 5
9745-#define L1_CACHE_BYTES 32
9746+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9747
9748 #ifdef CONFIG_SPARC32
9749 #define SMP_CACHE_BYTES_SHIFT 5
9750diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9751index a24e41f..47677ff 100644
9752--- a/arch/sparc/include/asm/elf_32.h
9753+++ b/arch/sparc/include/asm/elf_32.h
9754@@ -114,6 +114,13 @@ typedef struct {
9755
9756 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9757
9758+#ifdef CONFIG_PAX_ASLR
9759+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9760+
9761+#define PAX_DELTA_MMAP_LEN 16
9762+#define PAX_DELTA_STACK_LEN 16
9763+#endif
9764+
9765 /* This yields a mask that user programs can use to figure out what
9766 instruction set this cpu supports. This can NOT be done in userspace
9767 on Sparc. */
9768diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9769index 370ca1e..d4f4a98 100644
9770--- a/arch/sparc/include/asm/elf_64.h
9771+++ b/arch/sparc/include/asm/elf_64.h
9772@@ -189,6 +189,13 @@ typedef struct {
9773 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9774 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9775
9776+#ifdef CONFIG_PAX_ASLR
9777+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9778+
9779+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9780+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9781+#endif
9782+
9783 extern unsigned long sparc64_elf_hwcap;
9784 #define ELF_HWCAP sparc64_elf_hwcap
9785
9786diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9787index 9b1c36d..209298b 100644
9788--- a/arch/sparc/include/asm/pgalloc_32.h
9789+++ b/arch/sparc/include/asm/pgalloc_32.h
9790@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9791 }
9792
9793 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9794+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9795
9796 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9797 unsigned long address)
9798diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9799index bcfe063..b333142 100644
9800--- a/arch/sparc/include/asm/pgalloc_64.h
9801+++ b/arch/sparc/include/asm/pgalloc_64.h
9802@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9803 }
9804
9805 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9806+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9807
9808 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9809 {
9810diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9811index 59ba6f6..4518128 100644
9812--- a/arch/sparc/include/asm/pgtable.h
9813+++ b/arch/sparc/include/asm/pgtable.h
9814@@ -5,4 +5,8 @@
9815 #else
9816 #include <asm/pgtable_32.h>
9817 #endif
9818+
9819+#define ktla_ktva(addr) (addr)
9820+#define ktva_ktla(addr) (addr)
9821+
9822 #endif
9823diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9824index 502f632..da1917f 100644
9825--- a/arch/sparc/include/asm/pgtable_32.h
9826+++ b/arch/sparc/include/asm/pgtable_32.h
9827@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9828 #define PAGE_SHARED SRMMU_PAGE_SHARED
9829 #define PAGE_COPY SRMMU_PAGE_COPY
9830 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9831+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9832+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9833+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9834 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9835
9836 /* Top-level page directory - dummy used by init-mm.
9837@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9838
9839 /* xwr */
9840 #define __P000 PAGE_NONE
9841-#define __P001 PAGE_READONLY
9842-#define __P010 PAGE_COPY
9843-#define __P011 PAGE_COPY
9844+#define __P001 PAGE_READONLY_NOEXEC
9845+#define __P010 PAGE_COPY_NOEXEC
9846+#define __P011 PAGE_COPY_NOEXEC
9847 #define __P100 PAGE_READONLY
9848 #define __P101 PAGE_READONLY
9849 #define __P110 PAGE_COPY
9850 #define __P111 PAGE_COPY
9851
9852 #define __S000 PAGE_NONE
9853-#define __S001 PAGE_READONLY
9854-#define __S010 PAGE_SHARED
9855-#define __S011 PAGE_SHARED
9856+#define __S001 PAGE_READONLY_NOEXEC
9857+#define __S010 PAGE_SHARED_NOEXEC
9858+#define __S011 PAGE_SHARED_NOEXEC
9859 #define __S100 PAGE_READONLY
9860 #define __S101 PAGE_READONLY
9861 #define __S110 PAGE_SHARED
9862diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
9863index 0f9e945..a949e55 100644
9864--- a/arch/sparc/include/asm/pgtable_64.h
9865+++ b/arch/sparc/include/asm/pgtable_64.h
9866@@ -71,6 +71,23 @@
9867
9868 #include <linux/sched.h>
9869
9870+extern unsigned long sparc64_valid_addr_bitmap[];
9871+
9872+/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
9873+static inline bool __kern_addr_valid(unsigned long paddr)
9874+{
9875+ if ((paddr >> MAX_PHYS_ADDRESS_BITS) != 0UL)
9876+ return false;
9877+ return test_bit(paddr >> ILOG2_4MB, sparc64_valid_addr_bitmap);
9878+}
9879+
9880+static inline bool kern_addr_valid(unsigned long addr)
9881+{
9882+ unsigned long paddr = __pa(addr);
9883+
9884+ return __kern_addr_valid(paddr);
9885+}
9886+
9887 /* Entries per page directory level. */
9888 #define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
9889 #define PTRS_PER_PMD (1UL << PMD_BITS)
9890@@ -79,9 +96,12 @@
9891 /* Kernel has a separate 44bit address space. */
9892 #define FIRST_USER_ADDRESS 0
9893
9894-#define pte_ERROR(e) __builtin_trap()
9895-#define pmd_ERROR(e) __builtin_trap()
9896-#define pgd_ERROR(e) __builtin_trap()
9897+#define pmd_ERROR(e) \
9898+ pr_err("%s:%d: bad pmd %p(%016lx) seen at (%pS)\n", \
9899+ __FILE__, __LINE__, &(e), pmd_val(e), __builtin_return_address(0))
9900+#define pgd_ERROR(e) \
9901+ pr_err("%s:%d: bad pgd %p(%016lx) seen at (%pS)\n", \
9902+ __FILE__, __LINE__, &(e), pgd_val(e), __builtin_return_address(0))
9903
9904 #endif /* !(__ASSEMBLY__) */
9905
9906@@ -633,7 +653,7 @@ static inline unsigned long pmd_large(pmd_t pmd)
9907 {
9908 pte_t pte = __pte(pmd_val(pmd));
9909
9910- return (pte_val(pte) & _PAGE_PMD_HUGE) && pte_present(pte);
9911+ return pte_val(pte) & _PAGE_PMD_HUGE;
9912 }
9913
9914 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
9915@@ -719,20 +739,6 @@ static inline pmd_t pmd_mkwrite(pmd_t pmd)
9916 return __pmd(pte_val(pte));
9917 }
9918
9919-static inline pmd_t pmd_mknotpresent(pmd_t pmd)
9920-{
9921- unsigned long mask;
9922-
9923- if (tlb_type == hypervisor)
9924- mask = _PAGE_PRESENT_4V;
9925- else
9926- mask = _PAGE_PRESENT_4U;
9927-
9928- pmd_val(pmd) &= ~mask;
9929-
9930- return pmd;
9931-}
9932-
9933 static inline pmd_t pmd_mksplitting(pmd_t pmd)
9934 {
9935 pte_t pte = __pte(pmd_val(pmd));
9936@@ -757,6 +763,20 @@ static inline int pmd_present(pmd_t pmd)
9937
9938 #define pmd_none(pmd) (!pmd_val(pmd))
9939
9940+/* pmd_bad() is only called on non-trans-huge PMDs. Our encoding is
9941+ * very simple, it's just the physical address. PTE tables are of
9942+ * size PAGE_SIZE so make sure the sub-PAGE_SIZE bits are clear and
9943+ * the top bits outside of the range of any physical address size we
9944+ * support are clear as well. We also validate the physical itself.
9945+ */
9946+#define pmd_bad(pmd) ((pmd_val(pmd) & ~PAGE_MASK) || \
9947+ !__kern_addr_valid(pmd_val(pmd)))
9948+
9949+#define pud_none(pud) (!pud_val(pud))
9950+
9951+#define pud_bad(pud) ((pud_val(pud) & ~PAGE_MASK) || \
9952+ !__kern_addr_valid(pud_val(pud)))
9953+
9954 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
9955 extern void set_pmd_at(struct mm_struct *mm, unsigned long addr,
9956 pmd_t *pmdp, pmd_t pmd);
9957@@ -790,10 +810,7 @@ static inline unsigned long __pmd_page(pmd_t pmd)
9958 #define pud_page_vaddr(pud) \
9959 ((unsigned long) __va(pud_val(pud)))
9960 #define pud_page(pud) virt_to_page((void *)pud_page_vaddr(pud))
9961-#define pmd_bad(pmd) (0)
9962 #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0UL)
9963-#define pud_none(pud) (!pud_val(pud))
9964-#define pud_bad(pud) (0)
9965 #define pud_present(pud) (pud_val(pud) != 0U)
9966 #define pud_clear(pudp) (pud_val(*(pudp)) = 0UL)
9967
9968@@ -893,6 +910,10 @@ extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);
9969 extern void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,
9970 pmd_t *pmd);
9971
9972+#define __HAVE_ARCH_PMDP_INVALIDATE
9973+extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
9974+ pmd_t *pmdp);
9975+
9976 #define __HAVE_ARCH_PGTABLE_DEPOSIT
9977 extern void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
9978 pgtable_t pgtable);
9979@@ -919,18 +940,6 @@ extern unsigned long pte_file(pte_t);
9980 extern pte_t pgoff_to_pte(unsigned long);
9981 #define PTE_FILE_MAX_BITS (64UL - PAGE_SHIFT - 1UL)
9982
9983-extern unsigned long sparc64_valid_addr_bitmap[];
9984-
9985-/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
9986-static inline bool kern_addr_valid(unsigned long addr)
9987-{
9988- unsigned long paddr = __pa(addr);
9989-
9990- if ((paddr >> 41UL) != 0UL)
9991- return false;
9992- return test_bit(paddr >> 22, sparc64_valid_addr_bitmap);
9993-}
9994-
9995 extern int page_in_phys_avail(unsigned long paddr);
9996
9997 /*
9998diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9999index 79da178..c2eede8 100644
10000--- a/arch/sparc/include/asm/pgtsrmmu.h
10001+++ b/arch/sparc/include/asm/pgtsrmmu.h
10002@@ -115,6 +115,11 @@
10003 SRMMU_EXEC | SRMMU_REF)
10004 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10005 SRMMU_EXEC | SRMMU_REF)
10006+
10007+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10008+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10009+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10010+
10011 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10012 SRMMU_DIRTY | SRMMU_REF)
10013
10014diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10015index 9689176..63c18ea 100644
10016--- a/arch/sparc/include/asm/spinlock_64.h
10017+++ b/arch/sparc/include/asm/spinlock_64.h
10018@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10019
10020 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10021
10022-static void inline arch_read_lock(arch_rwlock_t *lock)
10023+static inline void arch_read_lock(arch_rwlock_t *lock)
10024 {
10025 unsigned long tmp1, tmp2;
10026
10027 __asm__ __volatile__ (
10028 "1: ldsw [%2], %0\n"
10029 " brlz,pn %0, 2f\n"
10030-"4: add %0, 1, %1\n"
10031+"4: addcc %0, 1, %1\n"
10032+
10033+#ifdef CONFIG_PAX_REFCOUNT
10034+" tvs %%icc, 6\n"
10035+#endif
10036+
10037 " cas [%2], %0, %1\n"
10038 " cmp %0, %1\n"
10039 " bne,pn %%icc, 1b\n"
10040@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10041 " .previous"
10042 : "=&r" (tmp1), "=&r" (tmp2)
10043 : "r" (lock)
10044- : "memory");
10045+ : "memory", "cc");
10046 }
10047
10048-static int inline arch_read_trylock(arch_rwlock_t *lock)
10049+static inline int arch_read_trylock(arch_rwlock_t *lock)
10050 {
10051 int tmp1, tmp2;
10052
10053@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10054 "1: ldsw [%2], %0\n"
10055 " brlz,a,pn %0, 2f\n"
10056 " mov 0, %0\n"
10057-" add %0, 1, %1\n"
10058+" addcc %0, 1, %1\n"
10059+
10060+#ifdef CONFIG_PAX_REFCOUNT
10061+" tvs %%icc, 6\n"
10062+#endif
10063+
10064 " cas [%2], %0, %1\n"
10065 " cmp %0, %1\n"
10066 " bne,pn %%icc, 1b\n"
10067@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10068 return tmp1;
10069 }
10070
10071-static void inline arch_read_unlock(arch_rwlock_t *lock)
10072+static inline void arch_read_unlock(arch_rwlock_t *lock)
10073 {
10074 unsigned long tmp1, tmp2;
10075
10076 __asm__ __volatile__(
10077 "1: lduw [%2], %0\n"
10078-" sub %0, 1, %1\n"
10079+" subcc %0, 1, %1\n"
10080+
10081+#ifdef CONFIG_PAX_REFCOUNT
10082+" tvs %%icc, 6\n"
10083+#endif
10084+
10085 " cas [%2], %0, %1\n"
10086 " cmp %0, %1\n"
10087 " bne,pn %%xcc, 1b\n"
10088@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10089 : "memory");
10090 }
10091
10092-static void inline arch_write_lock(arch_rwlock_t *lock)
10093+static inline void arch_write_lock(arch_rwlock_t *lock)
10094 {
10095 unsigned long mask, tmp1, tmp2;
10096
10097@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10098 : "memory");
10099 }
10100
10101-static void inline arch_write_unlock(arch_rwlock_t *lock)
10102+static inline void arch_write_unlock(arch_rwlock_t *lock)
10103 {
10104 __asm__ __volatile__(
10105 " stw %%g0, [%0]"
10106@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10107 : "memory");
10108 }
10109
10110-static int inline arch_write_trylock(arch_rwlock_t *lock)
10111+static inline int arch_write_trylock(arch_rwlock_t *lock)
10112 {
10113 unsigned long mask, tmp1, tmp2, result;
10114
10115diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10116index 96efa7a..16858bf 100644
10117--- a/arch/sparc/include/asm/thread_info_32.h
10118+++ b/arch/sparc/include/asm/thread_info_32.h
10119@@ -49,6 +49,8 @@ struct thread_info {
10120 unsigned long w_saved;
10121
10122 struct restart_block restart_block;
10123+
10124+ unsigned long lowest_stack;
10125 };
10126
10127 /*
10128diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10129index a5f01ac..703b554 100644
10130--- a/arch/sparc/include/asm/thread_info_64.h
10131+++ b/arch/sparc/include/asm/thread_info_64.h
10132@@ -63,6 +63,8 @@ struct thread_info {
10133 struct pt_regs *kern_una_regs;
10134 unsigned int kern_una_insn;
10135
10136+ unsigned long lowest_stack;
10137+
10138 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10139 };
10140
10141@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10142 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10143 /* flag bit 4 is available */
10144 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10145-/* flag bit 6 is available */
10146+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10147 #define TIF_32BIT 7 /* 32-bit binary */
10148 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10149 #define TIF_SECCOMP 9 /* secure computing */
10150 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10151 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10152+
10153 /* NOTE: Thread flags >= 12 should be ones we have no interest
10154 * in using in assembly, else we can't use the mask as
10155 * an immediate value in instructions such as andcc.
10156@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10157 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10158 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10159 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10160+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10161
10162 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10163 _TIF_DO_NOTIFY_RESUME_MASK | \
10164 _TIF_NEED_RESCHED)
10165 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10166
10167+#define _TIF_WORK_SYSCALL \
10168+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10169+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10170+
10171+
10172 /*
10173 * Thread-synchronous status.
10174 *
10175diff --git a/arch/sparc/include/asm/tsb.h b/arch/sparc/include/asm/tsb.h
10176index 2230f80..90916f9 100644
10177--- a/arch/sparc/include/asm/tsb.h
10178+++ b/arch/sparc/include/asm/tsb.h
10179@@ -171,7 +171,8 @@ extern struct tsb_phys_patch_entry __tsb_phys_patch, __tsb_phys_patch_end;
10180 andcc REG1, REG2, %g0; \
10181 be,pt %xcc, 700f; \
10182 sethi %hi(4 * 1024 * 1024), REG2; \
10183- andn REG1, REG2, REG1; \
10184+ brgez,pn REG1, FAIL_LABEL; \
10185+ andn REG1, REG2, REG1; \
10186 and VADDR, REG2, REG2; \
10187 brlz,pt REG1, PTE_LABEL; \
10188 or REG1, REG2, REG1; \
10189diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10190index 0167d26..767bb0c 100644
10191--- a/arch/sparc/include/asm/uaccess.h
10192+++ b/arch/sparc/include/asm/uaccess.h
10193@@ -1,5 +1,6 @@
10194 #ifndef ___ASM_SPARC_UACCESS_H
10195 #define ___ASM_SPARC_UACCESS_H
10196+
10197 #if defined(__sparc__) && defined(__arch64__)
10198 #include <asm/uaccess_64.h>
10199 #else
10200diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10201index 53a28dd..50c38c3 100644
10202--- a/arch/sparc/include/asm/uaccess_32.h
10203+++ b/arch/sparc/include/asm/uaccess_32.h
10204@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
10205
10206 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10207 {
10208- if (n && __access_ok((unsigned long) to, n))
10209+ if ((long)n < 0)
10210+ return n;
10211+
10212+ if (n && __access_ok((unsigned long) to, n)) {
10213+ if (!__builtin_constant_p(n))
10214+ check_object_size(from, n, true);
10215 return __copy_user(to, (__force void __user *) from, n);
10216- else
10217+ } else
10218 return n;
10219 }
10220
10221 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10222 {
10223+ if ((long)n < 0)
10224+ return n;
10225+
10226+ if (!__builtin_constant_p(n))
10227+ check_object_size(from, n, true);
10228+
10229 return __copy_user(to, (__force void __user *) from, n);
10230 }
10231
10232 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10233 {
10234- if (n && __access_ok((unsigned long) from, n))
10235+ if ((long)n < 0)
10236+ return n;
10237+
10238+ if (n && __access_ok((unsigned long) from, n)) {
10239+ if (!__builtin_constant_p(n))
10240+ check_object_size(to, n, false);
10241 return __copy_user((__force void __user *) to, from, n);
10242- else
10243+ } else
10244 return n;
10245 }
10246
10247 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10248 {
10249+ if ((long)n < 0)
10250+ return n;
10251+
10252 return __copy_user((__force void __user *) to, from, n);
10253 }
10254
10255diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10256index ad7e178..c9e7423 100644
10257--- a/arch/sparc/include/asm/uaccess_64.h
10258+++ b/arch/sparc/include/asm/uaccess_64.h
10259@@ -10,6 +10,7 @@
10260 #include <linux/compiler.h>
10261 #include <linux/string.h>
10262 #include <linux/thread_info.h>
10263+#include <linux/kernel.h>
10264 #include <asm/asi.h>
10265 #include <asm/spitfire.h>
10266 #include <asm-generic/uaccess-unaligned.h>
10267@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10268 static inline unsigned long __must_check
10269 copy_from_user(void *to, const void __user *from, unsigned long size)
10270 {
10271- unsigned long ret = ___copy_from_user(to, from, size);
10272+ unsigned long ret;
10273
10274+ if ((long)size < 0 || size > INT_MAX)
10275+ return size;
10276+
10277+ if (!__builtin_constant_p(size))
10278+ check_object_size(to, size, false);
10279+
10280+ ret = ___copy_from_user(to, from, size);
10281 if (unlikely(ret))
10282 ret = copy_from_user_fixup(to, from, size);
10283
10284@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10285 static inline unsigned long __must_check
10286 copy_to_user(void __user *to, const void *from, unsigned long size)
10287 {
10288- unsigned long ret = ___copy_to_user(to, from, size);
10289+ unsigned long ret;
10290
10291+ if ((long)size < 0 || size > INT_MAX)
10292+ return size;
10293+
10294+ if (!__builtin_constant_p(size))
10295+ check_object_size(from, size, true);
10296+
10297+ ret = ___copy_to_user(to, from, size);
10298 if (unlikely(ret))
10299 ret = copy_to_user_fixup(to, from, size);
10300 return ret;
10301diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10302index d15cc17..d0ae796 100644
10303--- a/arch/sparc/kernel/Makefile
10304+++ b/arch/sparc/kernel/Makefile
10305@@ -4,7 +4,7 @@
10306 #
10307
10308 asflags-y := -ansi
10309-ccflags-y := -Werror
10310+#ccflags-y := -Werror
10311
10312 extra-y := head_$(BITS).o
10313
10314diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10315index 510baec..9ff2607 100644
10316--- a/arch/sparc/kernel/process_32.c
10317+++ b/arch/sparc/kernel/process_32.c
10318@@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10319
10320 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10321 r->psr, r->pc, r->npc, r->y, print_tainted());
10322- printk("PC: <%pS>\n", (void *) r->pc);
10323+ printk("PC: <%pA>\n", (void *) r->pc);
10324 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10325 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10326 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10327 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10328 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10329 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10330- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10331+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10332
10333 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10334 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10335@@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10336 rw = (struct reg_window32 *) fp;
10337 pc = rw->ins[7];
10338 printk("[%08lx : ", pc);
10339- printk("%pS ] ", (void *) pc);
10340+ printk("%pA ] ", (void *) pc);
10341 fp = rw->ins[6];
10342 } while (++count < 16);
10343 printk("\n");
10344diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10345index d7b4967..2edf827 100644
10346--- a/arch/sparc/kernel/process_64.c
10347+++ b/arch/sparc/kernel/process_64.c
10348@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10349 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10350 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10351 if (regs->tstate & TSTATE_PRIV)
10352- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10353+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10354 }
10355
10356 void show_regs(struct pt_regs *regs)
10357@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10358
10359 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10360 regs->tpc, regs->tnpc, regs->y, print_tainted());
10361- printk("TPC: <%pS>\n", (void *) regs->tpc);
10362+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10363 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10364 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10365 regs->u_regs[3]);
10366@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10367 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10368 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10369 regs->u_regs[15]);
10370- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10371+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10372 show_regwindow(regs);
10373 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10374 }
10375@@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10376 ((tp && tp->task) ? tp->task->pid : -1));
10377
10378 if (gp->tstate & TSTATE_PRIV) {
10379- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10380+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10381 (void *) gp->tpc,
10382 (void *) gp->o7,
10383 (void *) gp->i7,
10384diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10385index 79cc0d1..ec62734 100644
10386--- a/arch/sparc/kernel/prom_common.c
10387+++ b/arch/sparc/kernel/prom_common.c
10388@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10389
10390 unsigned int prom_early_allocated __initdata;
10391
10392-static struct of_pdt_ops prom_sparc_ops __initdata = {
10393+static struct of_pdt_ops prom_sparc_ops __initconst = {
10394 .nextprop = prom_common_nextprop,
10395 .getproplen = prom_getproplen,
10396 .getproperty = prom_getproperty,
10397diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10398index c13c9f2..d572c34 100644
10399--- a/arch/sparc/kernel/ptrace_64.c
10400+++ b/arch/sparc/kernel/ptrace_64.c
10401@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10402 return ret;
10403 }
10404
10405+#ifdef CONFIG_GRKERNSEC_SETXID
10406+extern void gr_delayed_cred_worker(void);
10407+#endif
10408+
10409 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10410 {
10411 int ret = 0;
10412@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10413 if (test_thread_flag(TIF_NOHZ))
10414 user_exit();
10415
10416+#ifdef CONFIG_GRKERNSEC_SETXID
10417+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10418+ gr_delayed_cred_worker();
10419+#endif
10420+
10421 if (test_thread_flag(TIF_SYSCALL_TRACE))
10422 ret = tracehook_report_syscall_entry(regs);
10423
10424@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10425 if (test_thread_flag(TIF_NOHZ))
10426 user_exit();
10427
10428+#ifdef CONFIG_GRKERNSEC_SETXID
10429+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10430+ gr_delayed_cred_worker();
10431+#endif
10432+
10433 audit_syscall_exit(regs);
10434
10435 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10436diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10437index b085311..6f885f7 100644
10438--- a/arch/sparc/kernel/smp_64.c
10439+++ b/arch/sparc/kernel/smp_64.c
10440@@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10441 extern unsigned long xcall_flush_dcache_page_spitfire;
10442
10443 #ifdef CONFIG_DEBUG_DCFLUSH
10444-extern atomic_t dcpage_flushes;
10445-extern atomic_t dcpage_flushes_xcall;
10446+extern atomic_unchecked_t dcpage_flushes;
10447+extern atomic_unchecked_t dcpage_flushes_xcall;
10448 #endif
10449
10450 static inline void __local_flush_dcache_page(struct page *page)
10451@@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10452 return;
10453
10454 #ifdef CONFIG_DEBUG_DCFLUSH
10455- atomic_inc(&dcpage_flushes);
10456+ atomic_inc_unchecked(&dcpage_flushes);
10457 #endif
10458
10459 this_cpu = get_cpu();
10460@@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10461 xcall_deliver(data0, __pa(pg_addr),
10462 (u64) pg_addr, cpumask_of(cpu));
10463 #ifdef CONFIG_DEBUG_DCFLUSH
10464- atomic_inc(&dcpage_flushes_xcall);
10465+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10466 #endif
10467 }
10468 }
10469@@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10470 preempt_disable();
10471
10472 #ifdef CONFIG_DEBUG_DCFLUSH
10473- atomic_inc(&dcpage_flushes);
10474+ atomic_inc_unchecked(&dcpage_flushes);
10475 #endif
10476 data0 = 0;
10477 pg_addr = page_address(page);
10478@@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10479 xcall_deliver(data0, __pa(pg_addr),
10480 (u64) pg_addr, cpu_online_mask);
10481 #ifdef CONFIG_DEBUG_DCFLUSH
10482- atomic_inc(&dcpage_flushes_xcall);
10483+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10484 #endif
10485 }
10486 __local_flush_dcache_page(page);
10487diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10488index 3a8d184..49498a8 100644
10489--- a/arch/sparc/kernel/sys_sparc_32.c
10490+++ b/arch/sparc/kernel/sys_sparc_32.c
10491@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10492 if (len > TASK_SIZE - PAGE_SIZE)
10493 return -ENOMEM;
10494 if (!addr)
10495- addr = TASK_UNMAPPED_BASE;
10496+ addr = current->mm->mmap_base;
10497
10498 info.flags = 0;
10499 info.length = len;
10500diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10501index beb0b5a..5a153f7 100644
10502--- a/arch/sparc/kernel/sys_sparc_64.c
10503+++ b/arch/sparc/kernel/sys_sparc_64.c
10504@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10505 struct vm_area_struct * vma;
10506 unsigned long task_size = TASK_SIZE;
10507 int do_color_align;
10508+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10509 struct vm_unmapped_area_info info;
10510
10511 if (flags & MAP_FIXED) {
10512 /* We do not accept a shared mapping if it would violate
10513 * cache aliasing constraints.
10514 */
10515- if ((flags & MAP_SHARED) &&
10516+ if ((filp || (flags & MAP_SHARED)) &&
10517 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10518 return -EINVAL;
10519 return addr;
10520@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10521 if (filp || (flags & MAP_SHARED))
10522 do_color_align = 1;
10523
10524+#ifdef CONFIG_PAX_RANDMMAP
10525+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10526+#endif
10527+
10528 if (addr) {
10529 if (do_color_align)
10530 addr = COLOR_ALIGN(addr, pgoff);
10531@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10532 addr = PAGE_ALIGN(addr);
10533
10534 vma = find_vma(mm, addr);
10535- if (task_size - len >= addr &&
10536- (!vma || addr + len <= vma->vm_start))
10537+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10538 return addr;
10539 }
10540
10541 info.flags = 0;
10542 info.length = len;
10543- info.low_limit = TASK_UNMAPPED_BASE;
10544+ info.low_limit = mm->mmap_base;
10545 info.high_limit = min(task_size, VA_EXCLUDE_START);
10546 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10547 info.align_offset = pgoff << PAGE_SHIFT;
10548+ info.threadstack_offset = offset;
10549 addr = vm_unmapped_area(&info);
10550
10551 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10552 VM_BUG_ON(addr != -ENOMEM);
10553 info.low_limit = VA_EXCLUDE_END;
10554+
10555+#ifdef CONFIG_PAX_RANDMMAP
10556+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10557+ info.low_limit += mm->delta_mmap;
10558+#endif
10559+
10560 info.high_limit = task_size;
10561 addr = vm_unmapped_area(&info);
10562 }
10563@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10564 unsigned long task_size = STACK_TOP32;
10565 unsigned long addr = addr0;
10566 int do_color_align;
10567+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10568 struct vm_unmapped_area_info info;
10569
10570 /* This should only ever run for 32-bit processes. */
10571@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10572 /* We do not accept a shared mapping if it would violate
10573 * cache aliasing constraints.
10574 */
10575- if ((flags & MAP_SHARED) &&
10576+ if ((filp || (flags & MAP_SHARED)) &&
10577 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10578 return -EINVAL;
10579 return addr;
10580@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10581 if (filp || (flags & MAP_SHARED))
10582 do_color_align = 1;
10583
10584+#ifdef CONFIG_PAX_RANDMMAP
10585+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10586+#endif
10587+
10588 /* requesting a specific address */
10589 if (addr) {
10590 if (do_color_align)
10591@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10592 addr = PAGE_ALIGN(addr);
10593
10594 vma = find_vma(mm, addr);
10595- if (task_size - len >= addr &&
10596- (!vma || addr + len <= vma->vm_start))
10597+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10598 return addr;
10599 }
10600
10601@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10602 info.high_limit = mm->mmap_base;
10603 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10604 info.align_offset = pgoff << PAGE_SHIFT;
10605+ info.threadstack_offset = offset;
10606 addr = vm_unmapped_area(&info);
10607
10608 /*
10609@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10610 VM_BUG_ON(addr != -ENOMEM);
10611 info.flags = 0;
10612 info.low_limit = TASK_UNMAPPED_BASE;
10613+
10614+#ifdef CONFIG_PAX_RANDMMAP
10615+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10616+ info.low_limit += mm->delta_mmap;
10617+#endif
10618+
10619 info.high_limit = STACK_TOP32;
10620 addr = vm_unmapped_area(&info);
10621 }
10622@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10623 EXPORT_SYMBOL(get_fb_unmapped_area);
10624
10625 /* Essentially the same as PowerPC. */
10626-static unsigned long mmap_rnd(void)
10627+static unsigned long mmap_rnd(struct mm_struct *mm)
10628 {
10629 unsigned long rnd = 0UL;
10630
10631+#ifdef CONFIG_PAX_RANDMMAP
10632+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10633+#endif
10634+
10635 if (current->flags & PF_RANDOMIZE) {
10636 unsigned long val = get_random_int();
10637 if (test_thread_flag(TIF_32BIT))
10638@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10639
10640 void arch_pick_mmap_layout(struct mm_struct *mm)
10641 {
10642- unsigned long random_factor = mmap_rnd();
10643+ unsigned long random_factor = mmap_rnd(mm);
10644 unsigned long gap;
10645
10646 /*
10647@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10648 gap == RLIM_INFINITY ||
10649 sysctl_legacy_va_layout) {
10650 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10651+
10652+#ifdef CONFIG_PAX_RANDMMAP
10653+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10654+ mm->mmap_base += mm->delta_mmap;
10655+#endif
10656+
10657 mm->get_unmapped_area = arch_get_unmapped_area;
10658 } else {
10659 /* We know it's 32-bit */
10660@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10661 gap = (task_size / 6 * 5);
10662
10663 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10664+
10665+#ifdef CONFIG_PAX_RANDMMAP
10666+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10667+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10668+#endif
10669+
10670 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10671 }
10672 }
10673diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10674index 33a17e7..d87fb1f 100644
10675--- a/arch/sparc/kernel/syscalls.S
10676+++ b/arch/sparc/kernel/syscalls.S
10677@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10678 #endif
10679 .align 32
10680 1: ldx [%g6 + TI_FLAGS], %l5
10681- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10682+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10683 be,pt %icc, rtrap
10684 nop
10685 call syscall_trace_leave
10686@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10687
10688 srl %i3, 0, %o3 ! IEU0
10689 srl %i2, 0, %o2 ! IEU0 Group
10690- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10691+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10692 bne,pn %icc, linux_syscall_trace32 ! CTI
10693 mov %i0, %l5 ! IEU1
10694 5: call %l7 ! CTI Group brk forced
10695@@ -208,7 +208,7 @@ linux_sparc_syscall:
10696
10697 mov %i3, %o3 ! IEU1
10698 mov %i4, %o4 ! IEU0 Group
10699- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10700+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10701 bne,pn %icc, linux_syscall_trace ! CTI Group
10702 mov %i0, %l5 ! IEU0
10703 2: call %l7 ! CTI Group brk forced
10704@@ -223,7 +223,7 @@ ret_sys_call:
10705
10706 cmp %o0, -ERESTART_RESTARTBLOCK
10707 bgeu,pn %xcc, 1f
10708- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10709+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10710 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10711
10712 2:
10713diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10714index 6629829..036032d 100644
10715--- a/arch/sparc/kernel/traps_32.c
10716+++ b/arch/sparc/kernel/traps_32.c
10717@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10718 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10719 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10720
10721+extern void gr_handle_kernel_exploit(void);
10722+
10723 void die_if_kernel(char *str, struct pt_regs *regs)
10724 {
10725 static int die_counter;
10726@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10727 count++ < 30 &&
10728 (((unsigned long) rw) >= PAGE_OFFSET) &&
10729 !(((unsigned long) rw) & 0x7)) {
10730- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10731+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10732 (void *) rw->ins[7]);
10733 rw = (struct reg_window32 *)rw->ins[6];
10734 }
10735 }
10736 printk("Instruction DUMP:");
10737 instruction_dump ((unsigned long *) regs->pc);
10738- if(regs->psr & PSR_PS)
10739+ if(regs->psr & PSR_PS) {
10740+ gr_handle_kernel_exploit();
10741 do_exit(SIGKILL);
10742+ }
10743 do_exit(SIGSEGV);
10744 }
10745
10746diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10747index 4ced92f..965eeed 100644
10748--- a/arch/sparc/kernel/traps_64.c
10749+++ b/arch/sparc/kernel/traps_64.c
10750@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10751 i + 1,
10752 p->trapstack[i].tstate, p->trapstack[i].tpc,
10753 p->trapstack[i].tnpc, p->trapstack[i].tt);
10754- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10755+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10756 }
10757 }
10758
10759@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10760
10761 lvl -= 0x100;
10762 if (regs->tstate & TSTATE_PRIV) {
10763+
10764+#ifdef CONFIG_PAX_REFCOUNT
10765+ if (lvl == 6)
10766+ pax_report_refcount_overflow(regs);
10767+#endif
10768+
10769 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10770 die_if_kernel(buffer, regs);
10771 }
10772@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10773 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10774 {
10775 char buffer[32];
10776-
10777+
10778 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10779 0, lvl, SIGTRAP) == NOTIFY_STOP)
10780 return;
10781
10782+#ifdef CONFIG_PAX_REFCOUNT
10783+ if (lvl == 6)
10784+ pax_report_refcount_overflow(regs);
10785+#endif
10786+
10787 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10788
10789 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10790@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10791 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10792 printk("%s" "ERROR(%d): ",
10793 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10794- printk("TPC<%pS>\n", (void *) regs->tpc);
10795+ printk("TPC<%pA>\n", (void *) regs->tpc);
10796 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10797 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10798 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10799@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10800 smp_processor_id(),
10801 (type & 0x1) ? 'I' : 'D',
10802 regs->tpc);
10803- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10804+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10805 panic("Irrecoverable Cheetah+ parity error.");
10806 }
10807
10808@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10809 smp_processor_id(),
10810 (type & 0x1) ? 'I' : 'D',
10811 regs->tpc);
10812- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10813+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10814 }
10815
10816 struct sun4v_error_entry {
10817@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10818 /*0x38*/u64 reserved_5;
10819 };
10820
10821-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10822-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10823+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10824+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10825
10826 static const char *sun4v_err_type_to_str(u8 type)
10827 {
10828@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10829 }
10830
10831 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10832- int cpu, const char *pfx, atomic_t *ocnt)
10833+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10834 {
10835 u64 *raw_ptr = (u64 *) ent;
10836 u32 attrs;
10837@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10838
10839 show_regs(regs);
10840
10841- if ((cnt = atomic_read(ocnt)) != 0) {
10842- atomic_set(ocnt, 0);
10843+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10844+ atomic_set_unchecked(ocnt, 0);
10845 wmb();
10846 printk("%s: Queue overflowed %d times.\n",
10847 pfx, cnt);
10848@@ -2046,7 +2057,7 @@ out:
10849 */
10850 void sun4v_resum_overflow(struct pt_regs *regs)
10851 {
10852- atomic_inc(&sun4v_resum_oflow_cnt);
10853+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10854 }
10855
10856 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10857@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10858 /* XXX Actually even this can make not that much sense. Perhaps
10859 * XXX we should just pull the plug and panic directly from here?
10860 */
10861- atomic_inc(&sun4v_nonresum_oflow_cnt);
10862+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10863 }
10864
10865 unsigned long sun4v_err_itlb_vaddr;
10866@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10867
10868 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10869 regs->tpc, tl);
10870- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10871+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10872 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10873- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10874+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10875 (void *) regs->u_regs[UREG_I7]);
10876 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10877 "pte[%lx] error[%lx]\n",
10878@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10879
10880 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10881 regs->tpc, tl);
10882- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10883+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10884 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10885- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10886+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10887 (void *) regs->u_regs[UREG_I7]);
10888 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10889 "pte[%lx] error[%lx]\n",
10890@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10891 fp = (unsigned long)sf->fp + STACK_BIAS;
10892 }
10893
10894- printk(" [%016lx] %pS\n", pc, (void *) pc);
10895+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10896 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10897 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10898 int index = tsk->curr_ret_stack;
10899 if (tsk->ret_stack && index >= graph) {
10900 pc = tsk->ret_stack[index - graph].ret;
10901- printk(" [%016lx] %pS\n", pc, (void *) pc);
10902+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10903 graph++;
10904 }
10905 }
10906@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10907 return (struct reg_window *) (fp + STACK_BIAS);
10908 }
10909
10910+extern void gr_handle_kernel_exploit(void);
10911+
10912 void die_if_kernel(char *str, struct pt_regs *regs)
10913 {
10914 static int die_counter;
10915@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10916 while (rw &&
10917 count++ < 30 &&
10918 kstack_valid(tp, (unsigned long) rw)) {
10919- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10920+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10921 (void *) rw->ins[7]);
10922
10923 rw = kernel_stack_up(rw);
10924@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10925 }
10926 user_instruction_dump ((unsigned int __user *) regs->tpc);
10927 }
10928- if (regs->tstate & TSTATE_PRIV)
10929+ if (regs->tstate & TSTATE_PRIV) {
10930+ gr_handle_kernel_exploit();
10931 do_exit(SIGKILL);
10932+ }
10933 do_exit(SIGSEGV);
10934 }
10935 EXPORT_SYMBOL(die_if_kernel);
10936diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10937index 3c1a7cb..9046547 100644
10938--- a/arch/sparc/kernel/unaligned_64.c
10939+++ b/arch/sparc/kernel/unaligned_64.c
10940@@ -166,17 +166,23 @@ static unsigned long *fetch_reg_addr(unsigned int reg, struct pt_regs *regs)
10941 unsigned long compute_effective_address(struct pt_regs *regs,
10942 unsigned int insn, unsigned int rd)
10943 {
10944+ int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
10945 unsigned int rs1 = (insn >> 14) & 0x1f;
10946 unsigned int rs2 = insn & 0x1f;
10947- int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
10948+ unsigned long addr;
10949
10950 if (insn & 0x2000) {
10951 maybe_flush_windows(rs1, 0, rd, from_kernel);
10952- return (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
10953+ addr = (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
10954 } else {
10955 maybe_flush_windows(rs1, rs2, rd, from_kernel);
10956- return (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
10957+ addr = (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
10958 }
10959+
10960+ if (!from_kernel && test_thread_flag(TIF_32BIT))
10961+ addr &= 0xffffffff;
10962+
10963+ return addr;
10964 }
10965
10966 /* This is just to make gcc think die_if_kernel does return... */
10967@@ -289,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
10968 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10969
10970 if (__ratelimit(&ratelimit)) {
10971- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10972+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10973 regs->tpc, (void *) regs->tpc);
10974 }
10975 }
10976diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10977index dbe119b..089c7c1 100644
10978--- a/arch/sparc/lib/Makefile
10979+++ b/arch/sparc/lib/Makefile
10980@@ -2,7 +2,7 @@
10981 #
10982
10983 asflags-y := -ansi -DST_DIV0=0x02
10984-ccflags-y := -Werror
10985+#ccflags-y := -Werror
10986
10987 lib-$(CONFIG_SPARC32) += ashrdi3.o
10988 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10989diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10990index 85c233d..68500e0 100644
10991--- a/arch/sparc/lib/atomic_64.S
10992+++ b/arch/sparc/lib/atomic_64.S
10993@@ -17,7 +17,12 @@
10994 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10995 BACKOFF_SETUP(%o2)
10996 1: lduw [%o1], %g1
10997- add %g1, %o0, %g7
10998+ addcc %g1, %o0, %g7
10999+
11000+#ifdef CONFIG_PAX_REFCOUNT
11001+ tvs %icc, 6
11002+#endif
11003+
11004 cas [%o1], %g1, %g7
11005 cmp %g1, %g7
11006 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11007@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11008 2: BACKOFF_SPIN(%o2, %o3, 1b)
11009 ENDPROC(atomic_add)
11010
11011+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11012+ BACKOFF_SETUP(%o2)
11013+1: lduw [%o1], %g1
11014+ add %g1, %o0, %g7
11015+ cas [%o1], %g1, %g7
11016+ cmp %g1, %g7
11017+ bne,pn %icc, 2f
11018+ nop
11019+ retl
11020+ nop
11021+2: BACKOFF_SPIN(%o2, %o3, 1b)
11022+ENDPROC(atomic_add_unchecked)
11023+
11024 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11025 BACKOFF_SETUP(%o2)
11026 1: lduw [%o1], %g1
11027- sub %g1, %o0, %g7
11028+ subcc %g1, %o0, %g7
11029+
11030+#ifdef CONFIG_PAX_REFCOUNT
11031+ tvs %icc, 6
11032+#endif
11033+
11034 cas [%o1], %g1, %g7
11035 cmp %g1, %g7
11036 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11037@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11038 2: BACKOFF_SPIN(%o2, %o3, 1b)
11039 ENDPROC(atomic_sub)
11040
11041+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11042+ BACKOFF_SETUP(%o2)
11043+1: lduw [%o1], %g1
11044+ sub %g1, %o0, %g7
11045+ cas [%o1], %g1, %g7
11046+ cmp %g1, %g7
11047+ bne,pn %icc, 2f
11048+ nop
11049+ retl
11050+ nop
11051+2: BACKOFF_SPIN(%o2, %o3, 1b)
11052+ENDPROC(atomic_sub_unchecked)
11053+
11054 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11055 BACKOFF_SETUP(%o2)
11056 1: lduw [%o1], %g1
11057- add %g1, %o0, %g7
11058+ addcc %g1, %o0, %g7
11059+
11060+#ifdef CONFIG_PAX_REFCOUNT
11061+ tvs %icc, 6
11062+#endif
11063+
11064 cas [%o1], %g1, %g7
11065 cmp %g1, %g7
11066 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11067@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11068 2: BACKOFF_SPIN(%o2, %o3, 1b)
11069 ENDPROC(atomic_add_ret)
11070
11071+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11072+ BACKOFF_SETUP(%o2)
11073+1: lduw [%o1], %g1
11074+ addcc %g1, %o0, %g7
11075+ cas [%o1], %g1, %g7
11076+ cmp %g1, %g7
11077+ bne,pn %icc, 2f
11078+ add %g7, %o0, %g7
11079+ sra %g7, 0, %o0
11080+ retl
11081+ nop
11082+2: BACKOFF_SPIN(%o2, %o3, 1b)
11083+ENDPROC(atomic_add_ret_unchecked)
11084+
11085 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11086 BACKOFF_SETUP(%o2)
11087 1: lduw [%o1], %g1
11088- sub %g1, %o0, %g7
11089+ subcc %g1, %o0, %g7
11090+
11091+#ifdef CONFIG_PAX_REFCOUNT
11092+ tvs %icc, 6
11093+#endif
11094+
11095 cas [%o1], %g1, %g7
11096 cmp %g1, %g7
11097 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11098@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11099 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11100 BACKOFF_SETUP(%o2)
11101 1: ldx [%o1], %g1
11102- add %g1, %o0, %g7
11103+ addcc %g1, %o0, %g7
11104+
11105+#ifdef CONFIG_PAX_REFCOUNT
11106+ tvs %xcc, 6
11107+#endif
11108+
11109 casx [%o1], %g1, %g7
11110 cmp %g1, %g7
11111 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11112@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11113 2: BACKOFF_SPIN(%o2, %o3, 1b)
11114 ENDPROC(atomic64_add)
11115
11116+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11117+ BACKOFF_SETUP(%o2)
11118+1: ldx [%o1], %g1
11119+ addcc %g1, %o0, %g7
11120+ casx [%o1], %g1, %g7
11121+ cmp %g1, %g7
11122+ bne,pn %xcc, 2f
11123+ nop
11124+ retl
11125+ nop
11126+2: BACKOFF_SPIN(%o2, %o3, 1b)
11127+ENDPROC(atomic64_add_unchecked)
11128+
11129 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11130 BACKOFF_SETUP(%o2)
11131 1: ldx [%o1], %g1
11132- sub %g1, %o0, %g7
11133+ subcc %g1, %o0, %g7
11134+
11135+#ifdef CONFIG_PAX_REFCOUNT
11136+ tvs %xcc, 6
11137+#endif
11138+
11139 casx [%o1], %g1, %g7
11140 cmp %g1, %g7
11141 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11142@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11143 2: BACKOFF_SPIN(%o2, %o3, 1b)
11144 ENDPROC(atomic64_sub)
11145
11146+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11147+ BACKOFF_SETUP(%o2)
11148+1: ldx [%o1], %g1
11149+ subcc %g1, %o0, %g7
11150+ casx [%o1], %g1, %g7
11151+ cmp %g1, %g7
11152+ bne,pn %xcc, 2f
11153+ nop
11154+ retl
11155+ nop
11156+2: BACKOFF_SPIN(%o2, %o3, 1b)
11157+ENDPROC(atomic64_sub_unchecked)
11158+
11159 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11160 BACKOFF_SETUP(%o2)
11161 1: ldx [%o1], %g1
11162- add %g1, %o0, %g7
11163+ addcc %g1, %o0, %g7
11164+
11165+#ifdef CONFIG_PAX_REFCOUNT
11166+ tvs %xcc, 6
11167+#endif
11168+
11169 casx [%o1], %g1, %g7
11170 cmp %g1, %g7
11171 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11172@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11173 2: BACKOFF_SPIN(%o2, %o3, 1b)
11174 ENDPROC(atomic64_add_ret)
11175
11176+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11177+ BACKOFF_SETUP(%o2)
11178+1: ldx [%o1], %g1
11179+ addcc %g1, %o0, %g7
11180+ casx [%o1], %g1, %g7
11181+ cmp %g1, %g7
11182+ bne,pn %xcc, 2f
11183+ add %g7, %o0, %g7
11184+ mov %g7, %o0
11185+ retl
11186+ nop
11187+2: BACKOFF_SPIN(%o2, %o3, 1b)
11188+ENDPROC(atomic64_add_ret_unchecked)
11189+
11190 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11191 BACKOFF_SETUP(%o2)
11192 1: ldx [%o1], %g1
11193- sub %g1, %o0, %g7
11194+ subcc %g1, %o0, %g7
11195+
11196+#ifdef CONFIG_PAX_REFCOUNT
11197+ tvs %xcc, 6
11198+#endif
11199+
11200 casx [%o1], %g1, %g7
11201 cmp %g1, %g7
11202 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11203diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11204index 323335b..ed85ea2 100644
11205--- a/arch/sparc/lib/ksyms.c
11206+++ b/arch/sparc/lib/ksyms.c
11207@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11208
11209 /* Atomic counter implementation. */
11210 EXPORT_SYMBOL(atomic_add);
11211+EXPORT_SYMBOL(atomic_add_unchecked);
11212 EXPORT_SYMBOL(atomic_add_ret);
11213+EXPORT_SYMBOL(atomic_add_ret_unchecked);
11214 EXPORT_SYMBOL(atomic_sub);
11215+EXPORT_SYMBOL(atomic_sub_unchecked);
11216 EXPORT_SYMBOL(atomic_sub_ret);
11217 EXPORT_SYMBOL(atomic64_add);
11218+EXPORT_SYMBOL(atomic64_add_unchecked);
11219 EXPORT_SYMBOL(atomic64_add_ret);
11220+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11221 EXPORT_SYMBOL(atomic64_sub);
11222+EXPORT_SYMBOL(atomic64_sub_unchecked);
11223 EXPORT_SYMBOL(atomic64_sub_ret);
11224 EXPORT_SYMBOL(atomic64_dec_if_positive);
11225
11226diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11227index 30c3ecc..736f015 100644
11228--- a/arch/sparc/mm/Makefile
11229+++ b/arch/sparc/mm/Makefile
11230@@ -2,7 +2,7 @@
11231 #
11232
11233 asflags-y := -ansi
11234-ccflags-y := -Werror
11235+#ccflags-y := -Werror
11236
11237 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11238 obj-y += fault_$(BITS).o
11239diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11240index 59dbd46..1dd7f5e 100644
11241--- a/arch/sparc/mm/fault_32.c
11242+++ b/arch/sparc/mm/fault_32.c
11243@@ -21,6 +21,9 @@
11244 #include <linux/perf_event.h>
11245 #include <linux/interrupt.h>
11246 #include <linux/kdebug.h>
11247+#include <linux/slab.h>
11248+#include <linux/pagemap.h>
11249+#include <linux/compiler.h>
11250
11251 #include <asm/page.h>
11252 #include <asm/pgtable.h>
11253@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11254 return safe_compute_effective_address(regs, insn);
11255 }
11256
11257+#ifdef CONFIG_PAX_PAGEEXEC
11258+#ifdef CONFIG_PAX_DLRESOLVE
11259+static void pax_emuplt_close(struct vm_area_struct *vma)
11260+{
11261+ vma->vm_mm->call_dl_resolve = 0UL;
11262+}
11263+
11264+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11265+{
11266+ unsigned int *kaddr;
11267+
11268+ vmf->page = alloc_page(GFP_HIGHUSER);
11269+ if (!vmf->page)
11270+ return VM_FAULT_OOM;
11271+
11272+ kaddr = kmap(vmf->page);
11273+ memset(kaddr, 0, PAGE_SIZE);
11274+ kaddr[0] = 0x9DE3BFA8U; /* save */
11275+ flush_dcache_page(vmf->page);
11276+ kunmap(vmf->page);
11277+ return VM_FAULT_MAJOR;
11278+}
11279+
11280+static const struct vm_operations_struct pax_vm_ops = {
11281+ .close = pax_emuplt_close,
11282+ .fault = pax_emuplt_fault
11283+};
11284+
11285+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11286+{
11287+ int ret;
11288+
11289+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11290+ vma->vm_mm = current->mm;
11291+ vma->vm_start = addr;
11292+ vma->vm_end = addr + PAGE_SIZE;
11293+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11294+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11295+ vma->vm_ops = &pax_vm_ops;
11296+
11297+ ret = insert_vm_struct(current->mm, vma);
11298+ if (ret)
11299+ return ret;
11300+
11301+ ++current->mm->total_vm;
11302+ return 0;
11303+}
11304+#endif
11305+
11306+/*
11307+ * PaX: decide what to do with offenders (regs->pc = fault address)
11308+ *
11309+ * returns 1 when task should be killed
11310+ * 2 when patched PLT trampoline was detected
11311+ * 3 when unpatched PLT trampoline was detected
11312+ */
11313+static int pax_handle_fetch_fault(struct pt_regs *regs)
11314+{
11315+
11316+#ifdef CONFIG_PAX_EMUPLT
11317+ int err;
11318+
11319+ do { /* PaX: patched PLT emulation #1 */
11320+ unsigned int sethi1, sethi2, jmpl;
11321+
11322+ err = get_user(sethi1, (unsigned int *)regs->pc);
11323+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11324+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11325+
11326+ if (err)
11327+ break;
11328+
11329+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11330+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11331+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11332+ {
11333+ unsigned int addr;
11334+
11335+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11336+ addr = regs->u_regs[UREG_G1];
11337+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11338+ regs->pc = addr;
11339+ regs->npc = addr+4;
11340+ return 2;
11341+ }
11342+ } while (0);
11343+
11344+ do { /* PaX: patched PLT emulation #2 */
11345+ unsigned int ba;
11346+
11347+ err = get_user(ba, (unsigned int *)regs->pc);
11348+
11349+ if (err)
11350+ break;
11351+
11352+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11353+ unsigned int addr;
11354+
11355+ if ((ba & 0xFFC00000U) == 0x30800000U)
11356+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11357+ else
11358+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11359+ regs->pc = addr;
11360+ regs->npc = addr+4;
11361+ return 2;
11362+ }
11363+ } while (0);
11364+
11365+ do { /* PaX: patched PLT emulation #3 */
11366+ unsigned int sethi, bajmpl, nop;
11367+
11368+ err = get_user(sethi, (unsigned int *)regs->pc);
11369+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11370+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11371+
11372+ if (err)
11373+ break;
11374+
11375+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11376+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11377+ nop == 0x01000000U)
11378+ {
11379+ unsigned int addr;
11380+
11381+ addr = (sethi & 0x003FFFFFU) << 10;
11382+ regs->u_regs[UREG_G1] = addr;
11383+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11384+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11385+ else
11386+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11387+ regs->pc = addr;
11388+ regs->npc = addr+4;
11389+ return 2;
11390+ }
11391+ } while (0);
11392+
11393+ do { /* PaX: unpatched PLT emulation step 1 */
11394+ unsigned int sethi, ba, nop;
11395+
11396+ err = get_user(sethi, (unsigned int *)regs->pc);
11397+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11398+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11399+
11400+ if (err)
11401+ break;
11402+
11403+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11404+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11405+ nop == 0x01000000U)
11406+ {
11407+ unsigned int addr, save, call;
11408+
11409+ if ((ba & 0xFFC00000U) == 0x30800000U)
11410+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11411+ else
11412+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11413+
11414+ err = get_user(save, (unsigned int *)addr);
11415+ err |= get_user(call, (unsigned int *)(addr+4));
11416+ err |= get_user(nop, (unsigned int *)(addr+8));
11417+ if (err)
11418+ break;
11419+
11420+#ifdef CONFIG_PAX_DLRESOLVE
11421+ if (save == 0x9DE3BFA8U &&
11422+ (call & 0xC0000000U) == 0x40000000U &&
11423+ nop == 0x01000000U)
11424+ {
11425+ struct vm_area_struct *vma;
11426+ unsigned long call_dl_resolve;
11427+
11428+ down_read(&current->mm->mmap_sem);
11429+ call_dl_resolve = current->mm->call_dl_resolve;
11430+ up_read(&current->mm->mmap_sem);
11431+ if (likely(call_dl_resolve))
11432+ goto emulate;
11433+
11434+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11435+
11436+ down_write(&current->mm->mmap_sem);
11437+ if (current->mm->call_dl_resolve) {
11438+ call_dl_resolve = current->mm->call_dl_resolve;
11439+ up_write(&current->mm->mmap_sem);
11440+ if (vma)
11441+ kmem_cache_free(vm_area_cachep, vma);
11442+ goto emulate;
11443+ }
11444+
11445+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11446+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11447+ up_write(&current->mm->mmap_sem);
11448+ if (vma)
11449+ kmem_cache_free(vm_area_cachep, vma);
11450+ return 1;
11451+ }
11452+
11453+ if (pax_insert_vma(vma, call_dl_resolve)) {
11454+ up_write(&current->mm->mmap_sem);
11455+ kmem_cache_free(vm_area_cachep, vma);
11456+ return 1;
11457+ }
11458+
11459+ current->mm->call_dl_resolve = call_dl_resolve;
11460+ up_write(&current->mm->mmap_sem);
11461+
11462+emulate:
11463+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11464+ regs->pc = call_dl_resolve;
11465+ regs->npc = addr+4;
11466+ return 3;
11467+ }
11468+#endif
11469+
11470+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11471+ if ((save & 0xFFC00000U) == 0x05000000U &&
11472+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11473+ nop == 0x01000000U)
11474+ {
11475+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11476+ regs->u_regs[UREG_G2] = addr + 4;
11477+ addr = (save & 0x003FFFFFU) << 10;
11478+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11479+ regs->pc = addr;
11480+ regs->npc = addr+4;
11481+ return 3;
11482+ }
11483+ }
11484+ } while (0);
11485+
11486+ do { /* PaX: unpatched PLT emulation step 2 */
11487+ unsigned int save, call, nop;
11488+
11489+ err = get_user(save, (unsigned int *)(regs->pc-4));
11490+ err |= get_user(call, (unsigned int *)regs->pc);
11491+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11492+ if (err)
11493+ break;
11494+
11495+ if (save == 0x9DE3BFA8U &&
11496+ (call & 0xC0000000U) == 0x40000000U &&
11497+ nop == 0x01000000U)
11498+ {
11499+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11500+
11501+ regs->u_regs[UREG_RETPC] = regs->pc;
11502+ regs->pc = dl_resolve;
11503+ regs->npc = dl_resolve+4;
11504+ return 3;
11505+ }
11506+ } while (0);
11507+#endif
11508+
11509+ return 1;
11510+}
11511+
11512+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11513+{
11514+ unsigned long i;
11515+
11516+ printk(KERN_ERR "PAX: bytes at PC: ");
11517+ for (i = 0; i < 8; i++) {
11518+ unsigned int c;
11519+ if (get_user(c, (unsigned int *)pc+i))
11520+ printk(KERN_CONT "???????? ");
11521+ else
11522+ printk(KERN_CONT "%08x ", c);
11523+ }
11524+ printk("\n");
11525+}
11526+#endif
11527+
11528 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11529 int text_fault)
11530 {
11531@@ -229,6 +503,24 @@ good_area:
11532 if (!(vma->vm_flags & VM_WRITE))
11533 goto bad_area;
11534 } else {
11535+
11536+#ifdef CONFIG_PAX_PAGEEXEC
11537+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11538+ up_read(&mm->mmap_sem);
11539+ switch (pax_handle_fetch_fault(regs)) {
11540+
11541+#ifdef CONFIG_PAX_EMUPLT
11542+ case 2:
11543+ case 3:
11544+ return;
11545+#endif
11546+
11547+ }
11548+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11549+ do_group_exit(SIGKILL);
11550+ }
11551+#endif
11552+
11553 /* Allow reads even for write-only mappings */
11554 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11555 goto bad_area;
11556diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11557index 69bb818..3542236 100644
11558--- a/arch/sparc/mm/fault_64.c
11559+++ b/arch/sparc/mm/fault_64.c
11560@@ -22,6 +22,9 @@
11561 #include <linux/kdebug.h>
11562 #include <linux/percpu.h>
11563 #include <linux/context_tracking.h>
11564+#include <linux/slab.h>
11565+#include <linux/pagemap.h>
11566+#include <linux/compiler.h>
11567
11568 #include <asm/page.h>
11569 #include <asm/pgtable.h>
11570@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11571 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11572 regs->tpc);
11573 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11574- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11575+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11576 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11577 dump_stack();
11578 unhandled_fault(regs->tpc, current, regs);
11579@@ -96,38 +99,51 @@ static unsigned int get_user_insn(unsigned long tpc)
11580 pte_t *ptep, pte;
11581 unsigned long pa;
11582 u32 insn = 0;
11583- unsigned long pstate;
11584
11585- if (pgd_none(*pgdp))
11586- goto outret;
11587+ if (pgd_none(*pgdp) || unlikely(pgd_bad(*pgdp)))
11588+ goto out;
11589 pudp = pud_offset(pgdp, tpc);
11590- if (pud_none(*pudp))
11591- goto outret;
11592- pmdp = pmd_offset(pudp, tpc);
11593- if (pmd_none(*pmdp))
11594- goto outret;
11595+ if (pud_none(*pudp) || unlikely(pud_bad(*pudp)))
11596+ goto out;
11597
11598 /* This disables preemption for us as well. */
11599- __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
11600- __asm__ __volatile__("wrpr %0, %1, %%pstate"
11601- : : "r" (pstate), "i" (PSTATE_IE));
11602- ptep = pte_offset_map(pmdp, tpc);
11603- pte = *ptep;
11604- if (!pte_present(pte))
11605- goto out;
11606+ local_irq_disable();
11607
11608- pa = (pte_pfn(pte) << PAGE_SHIFT);
11609- pa += (tpc & ~PAGE_MASK);
11610+ pmdp = pmd_offset(pudp, tpc);
11611+ if (pmd_none(*pmdp) || unlikely(pmd_bad(*pmdp)))
11612+ goto out_irq_enable;
11613
11614- /* Use phys bypass so we don't pollute dtlb/dcache. */
11615- __asm__ __volatile__("lduwa [%1] %2, %0"
11616- : "=r" (insn)
11617- : "r" (pa), "i" (ASI_PHYS_USE_EC));
11618+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
11619+ if (pmd_trans_huge(*pmdp)) {
11620+ if (pmd_trans_splitting(*pmdp))
11621+ goto out_irq_enable;
11622
11623+ pa = pmd_pfn(*pmdp) << PAGE_SHIFT;
11624+ pa += tpc & ~HPAGE_MASK;
11625+
11626+ /* Use phys bypass so we don't pollute dtlb/dcache. */
11627+ __asm__ __volatile__("lduwa [%1] %2, %0"
11628+ : "=r" (insn)
11629+ : "r" (pa), "i" (ASI_PHYS_USE_EC));
11630+ } else
11631+#endif
11632+ {
11633+ ptep = pte_offset_map(pmdp, tpc);
11634+ pte = *ptep;
11635+ if (pte_present(pte)) {
11636+ pa = (pte_pfn(pte) << PAGE_SHIFT);
11637+ pa += (tpc & ~PAGE_MASK);
11638+
11639+ /* Use phys bypass so we don't pollute dtlb/dcache. */
11640+ __asm__ __volatile__("lduwa [%1] %2, %0"
11641+ : "=r" (insn)
11642+ : "r" (pa), "i" (ASI_PHYS_USE_EC));
11643+ }
11644+ pte_unmap(ptep);
11645+ }
11646+out_irq_enable:
11647+ local_irq_enable();
11648 out:
11649- pte_unmap(ptep);
11650- __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
11651-outret:
11652 return insn;
11653 }
11654
11655@@ -153,7 +169,8 @@ show_signal_msg(struct pt_regs *regs, int sig, int code,
11656 }
11657
11658 static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11659- unsigned int insn, int fault_code)
11660+ unsigned long fault_addr, unsigned int insn,
11661+ int fault_code)
11662 {
11663 unsigned long addr;
11664 siginfo_t info;
11665@@ -161,10 +178,18 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11666 info.si_code = code;
11667 info.si_signo = sig;
11668 info.si_errno = 0;
11669- if (fault_code & FAULT_CODE_ITLB)
11670+ if (fault_code & FAULT_CODE_ITLB) {
11671 addr = regs->tpc;
11672- else
11673- addr = compute_effective_address(regs, insn, 0);
11674+ } else {
11675+ /* If we were able to probe the faulting instruction, use it
11676+ * to compute a precise fault address. Otherwise use the fault
11677+ * time provided address which may only have page granularity.
11678+ */
11679+ if (insn)
11680+ addr = compute_effective_address(regs, insn, 0);
11681+ else
11682+ addr = fault_addr;
11683+ }
11684 info.si_addr = (void __user *) addr;
11685 info.si_trapno = 0;
11686
11687@@ -239,7 +264,7 @@ static void __kprobes do_kernel_fault(struct pt_regs *regs, int si_code,
11688 /* The si_code was set to make clear whether
11689 * this was a SEGV_MAPERR or SEGV_ACCERR fault.
11690 */
11691- do_fault_siginfo(si_code, SIGSEGV, regs, insn, fault_code);
11692+ do_fault_siginfo(si_code, SIGSEGV, regs, address, insn, fault_code);
11693 return;
11694 }
11695
11696@@ -271,6 +296,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11697 show_regs(regs);
11698 }
11699
11700+#ifdef CONFIG_PAX_PAGEEXEC
11701+#ifdef CONFIG_PAX_DLRESOLVE
11702+static void pax_emuplt_close(struct vm_area_struct *vma)
11703+{
11704+ vma->vm_mm->call_dl_resolve = 0UL;
11705+}
11706+
11707+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11708+{
11709+ unsigned int *kaddr;
11710+
11711+ vmf->page = alloc_page(GFP_HIGHUSER);
11712+ if (!vmf->page)
11713+ return VM_FAULT_OOM;
11714+
11715+ kaddr = kmap(vmf->page);
11716+ memset(kaddr, 0, PAGE_SIZE);
11717+ kaddr[0] = 0x9DE3BFA8U; /* save */
11718+ flush_dcache_page(vmf->page);
11719+ kunmap(vmf->page);
11720+ return VM_FAULT_MAJOR;
11721+}
11722+
11723+static const struct vm_operations_struct pax_vm_ops = {
11724+ .close = pax_emuplt_close,
11725+ .fault = pax_emuplt_fault
11726+};
11727+
11728+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11729+{
11730+ int ret;
11731+
11732+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11733+ vma->vm_mm = current->mm;
11734+ vma->vm_start = addr;
11735+ vma->vm_end = addr + PAGE_SIZE;
11736+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11737+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11738+ vma->vm_ops = &pax_vm_ops;
11739+
11740+ ret = insert_vm_struct(current->mm, vma);
11741+ if (ret)
11742+ return ret;
11743+
11744+ ++current->mm->total_vm;
11745+ return 0;
11746+}
11747+#endif
11748+
11749+/*
11750+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11751+ *
11752+ * returns 1 when task should be killed
11753+ * 2 when patched PLT trampoline was detected
11754+ * 3 when unpatched PLT trampoline was detected
11755+ */
11756+static int pax_handle_fetch_fault(struct pt_regs *regs)
11757+{
11758+
11759+#ifdef CONFIG_PAX_EMUPLT
11760+ int err;
11761+
11762+ do { /* PaX: patched PLT emulation #1 */
11763+ unsigned int sethi1, sethi2, jmpl;
11764+
11765+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11766+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11767+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11768+
11769+ if (err)
11770+ break;
11771+
11772+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11773+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11774+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11775+ {
11776+ unsigned long addr;
11777+
11778+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11779+ addr = regs->u_regs[UREG_G1];
11780+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11781+
11782+ if (test_thread_flag(TIF_32BIT))
11783+ addr &= 0xFFFFFFFFUL;
11784+
11785+ regs->tpc = addr;
11786+ regs->tnpc = addr+4;
11787+ return 2;
11788+ }
11789+ } while (0);
11790+
11791+ do { /* PaX: patched PLT emulation #2 */
11792+ unsigned int ba;
11793+
11794+ err = get_user(ba, (unsigned int *)regs->tpc);
11795+
11796+ if (err)
11797+ break;
11798+
11799+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11800+ unsigned long addr;
11801+
11802+ if ((ba & 0xFFC00000U) == 0x30800000U)
11803+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11804+ else
11805+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11806+
11807+ if (test_thread_flag(TIF_32BIT))
11808+ addr &= 0xFFFFFFFFUL;
11809+
11810+ regs->tpc = addr;
11811+ regs->tnpc = addr+4;
11812+ return 2;
11813+ }
11814+ } while (0);
11815+
11816+ do { /* PaX: patched PLT emulation #3 */
11817+ unsigned int sethi, bajmpl, nop;
11818+
11819+ err = get_user(sethi, (unsigned int *)regs->tpc);
11820+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11821+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11822+
11823+ if (err)
11824+ break;
11825+
11826+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11827+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11828+ nop == 0x01000000U)
11829+ {
11830+ unsigned long addr;
11831+
11832+ addr = (sethi & 0x003FFFFFU) << 10;
11833+ regs->u_regs[UREG_G1] = addr;
11834+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11835+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11836+ else
11837+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11838+
11839+ if (test_thread_flag(TIF_32BIT))
11840+ addr &= 0xFFFFFFFFUL;
11841+
11842+ regs->tpc = addr;
11843+ regs->tnpc = addr+4;
11844+ return 2;
11845+ }
11846+ } while (0);
11847+
11848+ do { /* PaX: patched PLT emulation #4 */
11849+ unsigned int sethi, mov1, call, mov2;
11850+
11851+ err = get_user(sethi, (unsigned int *)regs->tpc);
11852+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11853+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11854+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11855+
11856+ if (err)
11857+ break;
11858+
11859+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11860+ mov1 == 0x8210000FU &&
11861+ (call & 0xC0000000U) == 0x40000000U &&
11862+ mov2 == 0x9E100001U)
11863+ {
11864+ unsigned long addr;
11865+
11866+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11867+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11868+
11869+ if (test_thread_flag(TIF_32BIT))
11870+ addr &= 0xFFFFFFFFUL;
11871+
11872+ regs->tpc = addr;
11873+ regs->tnpc = addr+4;
11874+ return 2;
11875+ }
11876+ } while (0);
11877+
11878+ do { /* PaX: patched PLT emulation #5 */
11879+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11880+
11881+ err = get_user(sethi, (unsigned int *)regs->tpc);
11882+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11883+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11884+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11885+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11886+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11887+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11888+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11889+
11890+ if (err)
11891+ break;
11892+
11893+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11894+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11895+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11896+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11897+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11898+ sllx == 0x83287020U &&
11899+ jmpl == 0x81C04005U &&
11900+ nop == 0x01000000U)
11901+ {
11902+ unsigned long addr;
11903+
11904+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11905+ regs->u_regs[UREG_G1] <<= 32;
11906+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11907+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11908+ regs->tpc = addr;
11909+ regs->tnpc = addr+4;
11910+ return 2;
11911+ }
11912+ } while (0);
11913+
11914+ do { /* PaX: patched PLT emulation #6 */
11915+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11916+
11917+ err = get_user(sethi, (unsigned int *)regs->tpc);
11918+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11919+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11920+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11921+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11922+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11923+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11924+
11925+ if (err)
11926+ break;
11927+
11928+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11929+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11930+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11931+ sllx == 0x83287020U &&
11932+ (or & 0xFFFFE000U) == 0x8A116000U &&
11933+ jmpl == 0x81C04005U &&
11934+ nop == 0x01000000U)
11935+ {
11936+ unsigned long addr;
11937+
11938+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11939+ regs->u_regs[UREG_G1] <<= 32;
11940+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11941+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11942+ regs->tpc = addr;
11943+ regs->tnpc = addr+4;
11944+ return 2;
11945+ }
11946+ } while (0);
11947+
11948+ do { /* PaX: unpatched PLT emulation step 1 */
11949+ unsigned int sethi, ba, nop;
11950+
11951+ err = get_user(sethi, (unsigned int *)regs->tpc);
11952+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11953+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11954+
11955+ if (err)
11956+ break;
11957+
11958+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11959+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11960+ nop == 0x01000000U)
11961+ {
11962+ unsigned long addr;
11963+ unsigned int save, call;
11964+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11965+
11966+ if ((ba & 0xFFC00000U) == 0x30800000U)
11967+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11968+ else
11969+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11970+
11971+ if (test_thread_flag(TIF_32BIT))
11972+ addr &= 0xFFFFFFFFUL;
11973+
11974+ err = get_user(save, (unsigned int *)addr);
11975+ err |= get_user(call, (unsigned int *)(addr+4));
11976+ err |= get_user(nop, (unsigned int *)(addr+8));
11977+ if (err)
11978+ break;
11979+
11980+#ifdef CONFIG_PAX_DLRESOLVE
11981+ if (save == 0x9DE3BFA8U &&
11982+ (call & 0xC0000000U) == 0x40000000U &&
11983+ nop == 0x01000000U)
11984+ {
11985+ struct vm_area_struct *vma;
11986+ unsigned long call_dl_resolve;
11987+
11988+ down_read(&current->mm->mmap_sem);
11989+ call_dl_resolve = current->mm->call_dl_resolve;
11990+ up_read(&current->mm->mmap_sem);
11991+ if (likely(call_dl_resolve))
11992+ goto emulate;
11993+
11994+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11995+
11996+ down_write(&current->mm->mmap_sem);
11997+ if (current->mm->call_dl_resolve) {
11998+ call_dl_resolve = current->mm->call_dl_resolve;
11999+ up_write(&current->mm->mmap_sem);
12000+ if (vma)
12001+ kmem_cache_free(vm_area_cachep, vma);
12002+ goto emulate;
12003+ }
12004+
12005+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12006+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12007+ up_write(&current->mm->mmap_sem);
12008+ if (vma)
12009+ kmem_cache_free(vm_area_cachep, vma);
12010+ return 1;
12011+ }
12012+
12013+ if (pax_insert_vma(vma, call_dl_resolve)) {
12014+ up_write(&current->mm->mmap_sem);
12015+ kmem_cache_free(vm_area_cachep, vma);
12016+ return 1;
12017+ }
12018+
12019+ current->mm->call_dl_resolve = call_dl_resolve;
12020+ up_write(&current->mm->mmap_sem);
12021+
12022+emulate:
12023+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12024+ regs->tpc = call_dl_resolve;
12025+ regs->tnpc = addr+4;
12026+ return 3;
12027+ }
12028+#endif
12029+
12030+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12031+ if ((save & 0xFFC00000U) == 0x05000000U &&
12032+ (call & 0xFFFFE000U) == 0x85C0A000U &&
12033+ nop == 0x01000000U)
12034+ {
12035+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12036+ regs->u_regs[UREG_G2] = addr + 4;
12037+ addr = (save & 0x003FFFFFU) << 10;
12038+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12039+
12040+ if (test_thread_flag(TIF_32BIT))
12041+ addr &= 0xFFFFFFFFUL;
12042+
12043+ regs->tpc = addr;
12044+ regs->tnpc = addr+4;
12045+ return 3;
12046+ }
12047+
12048+ /* PaX: 64-bit PLT stub */
12049+ err = get_user(sethi1, (unsigned int *)addr);
12050+ err |= get_user(sethi2, (unsigned int *)(addr+4));
12051+ err |= get_user(or1, (unsigned int *)(addr+8));
12052+ err |= get_user(or2, (unsigned int *)(addr+12));
12053+ err |= get_user(sllx, (unsigned int *)(addr+16));
12054+ err |= get_user(add, (unsigned int *)(addr+20));
12055+ err |= get_user(jmpl, (unsigned int *)(addr+24));
12056+ err |= get_user(nop, (unsigned int *)(addr+28));
12057+ if (err)
12058+ break;
12059+
12060+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12061+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12062+ (or1 & 0xFFFFE000U) == 0x88112000U &&
12063+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
12064+ sllx == 0x89293020U &&
12065+ add == 0x8A010005U &&
12066+ jmpl == 0x89C14000U &&
12067+ nop == 0x01000000U)
12068+ {
12069+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12070+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12071+ regs->u_regs[UREG_G4] <<= 32;
12072+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12073+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12074+ regs->u_regs[UREG_G4] = addr + 24;
12075+ addr = regs->u_regs[UREG_G5];
12076+ regs->tpc = addr;
12077+ regs->tnpc = addr+4;
12078+ return 3;
12079+ }
12080+ }
12081+ } while (0);
12082+
12083+#ifdef CONFIG_PAX_DLRESOLVE
12084+ do { /* PaX: unpatched PLT emulation step 2 */
12085+ unsigned int save, call, nop;
12086+
12087+ err = get_user(save, (unsigned int *)(regs->tpc-4));
12088+ err |= get_user(call, (unsigned int *)regs->tpc);
12089+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12090+ if (err)
12091+ break;
12092+
12093+ if (save == 0x9DE3BFA8U &&
12094+ (call & 0xC0000000U) == 0x40000000U &&
12095+ nop == 0x01000000U)
12096+ {
12097+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12098+
12099+ if (test_thread_flag(TIF_32BIT))
12100+ dl_resolve &= 0xFFFFFFFFUL;
12101+
12102+ regs->u_regs[UREG_RETPC] = regs->tpc;
12103+ regs->tpc = dl_resolve;
12104+ regs->tnpc = dl_resolve+4;
12105+ return 3;
12106+ }
12107+ } while (0);
12108+#endif
12109+
12110+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12111+ unsigned int sethi, ba, nop;
12112+
12113+ err = get_user(sethi, (unsigned int *)regs->tpc);
12114+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12115+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12116+
12117+ if (err)
12118+ break;
12119+
12120+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12121+ (ba & 0xFFF00000U) == 0x30600000U &&
12122+ nop == 0x01000000U)
12123+ {
12124+ unsigned long addr;
12125+
12126+ addr = (sethi & 0x003FFFFFU) << 10;
12127+ regs->u_regs[UREG_G1] = addr;
12128+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12129+
12130+ if (test_thread_flag(TIF_32BIT))
12131+ addr &= 0xFFFFFFFFUL;
12132+
12133+ regs->tpc = addr;
12134+ regs->tnpc = addr+4;
12135+ return 2;
12136+ }
12137+ } while (0);
12138+
12139+#endif
12140+
12141+ return 1;
12142+}
12143+
12144+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12145+{
12146+ unsigned long i;
12147+
12148+ printk(KERN_ERR "PAX: bytes at PC: ");
12149+ for (i = 0; i < 8; i++) {
12150+ unsigned int c;
12151+ if (get_user(c, (unsigned int *)pc+i))
12152+ printk(KERN_CONT "???????? ");
12153+ else
12154+ printk(KERN_CONT "%08x ", c);
12155+ }
12156+ printk("\n");
12157+}
12158+#endif
12159+
12160 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12161 {
12162 enum ctx_state prev_state = exception_enter();
12163@@ -344,6 +829,29 @@ retry:
12164 if (!vma)
12165 goto bad_area;
12166
12167+#ifdef CONFIG_PAX_PAGEEXEC
12168+ /* PaX: detect ITLB misses on non-exec pages */
12169+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12170+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12171+ {
12172+ if (address != regs->tpc)
12173+ goto good_area;
12174+
12175+ up_read(&mm->mmap_sem);
12176+ switch (pax_handle_fetch_fault(regs)) {
12177+
12178+#ifdef CONFIG_PAX_EMUPLT
12179+ case 2:
12180+ case 3:
12181+ return;
12182+#endif
12183+
12184+ }
12185+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12186+ do_group_exit(SIGKILL);
12187+ }
12188+#endif
12189+
12190 /* Pure DTLB misses do not tell us whether the fault causing
12191 * load/store/atomic was a write or not, it only says that there
12192 * was no match. So in such a case we (carefully) read the
12193@@ -525,7 +1033,7 @@ do_sigbus:
12194 * Send a sigbus, regardless of whether we were in kernel
12195 * or user mode.
12196 */
12197- do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, insn, fault_code);
12198+ do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, address, insn, fault_code);
12199
12200 /* Kernel mode? Handle exceptions or die */
12201 if (regs->tstate & TSTATE_PRIV)
12202diff --git a/arch/sparc/mm/gup.c b/arch/sparc/mm/gup.c
12203index c4d3da6..1aed043 100644
12204--- a/arch/sparc/mm/gup.c
12205+++ b/arch/sparc/mm/gup.c
12206@@ -73,7 +73,7 @@ static int gup_huge_pmd(pmd_t *pmdp, pmd_t pmd, unsigned long addr,
12207 struct page *head, *page, *tail;
12208 int refs;
12209
12210- if (!pmd_large(pmd))
12211+ if (!(pmd_val(pmd) & _PAGE_VALID))
12212 return 0;
12213
12214 if (write && !pmd_write(pmd))
12215diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12216index 9bd9ce8..dc84852 100644
12217--- a/arch/sparc/mm/hugetlbpage.c
12218+++ b/arch/sparc/mm/hugetlbpage.c
12219@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12220 unsigned long addr,
12221 unsigned long len,
12222 unsigned long pgoff,
12223- unsigned long flags)
12224+ unsigned long flags,
12225+ unsigned long offset)
12226 {
12227+ struct mm_struct *mm = current->mm;
12228 unsigned long task_size = TASK_SIZE;
12229 struct vm_unmapped_area_info info;
12230
12231@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12232
12233 info.flags = 0;
12234 info.length = len;
12235- info.low_limit = TASK_UNMAPPED_BASE;
12236+ info.low_limit = mm->mmap_base;
12237 info.high_limit = min(task_size, VA_EXCLUDE_START);
12238 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12239 info.align_offset = 0;
12240+ info.threadstack_offset = offset;
12241 addr = vm_unmapped_area(&info);
12242
12243 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12244 VM_BUG_ON(addr != -ENOMEM);
12245 info.low_limit = VA_EXCLUDE_END;
12246+
12247+#ifdef CONFIG_PAX_RANDMMAP
12248+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12249+ info.low_limit += mm->delta_mmap;
12250+#endif
12251+
12252 info.high_limit = task_size;
12253 addr = vm_unmapped_area(&info);
12254 }
12255@@ -55,7 +64,8 @@ static unsigned long
12256 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12257 const unsigned long len,
12258 const unsigned long pgoff,
12259- const unsigned long flags)
12260+ const unsigned long flags,
12261+ const unsigned long offset)
12262 {
12263 struct mm_struct *mm = current->mm;
12264 unsigned long addr = addr0;
12265@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12266 info.high_limit = mm->mmap_base;
12267 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12268 info.align_offset = 0;
12269+ info.threadstack_offset = offset;
12270 addr = vm_unmapped_area(&info);
12271
12272 /*
12273@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12274 VM_BUG_ON(addr != -ENOMEM);
12275 info.flags = 0;
12276 info.low_limit = TASK_UNMAPPED_BASE;
12277+
12278+#ifdef CONFIG_PAX_RANDMMAP
12279+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12280+ info.low_limit += mm->delta_mmap;
12281+#endif
12282+
12283 info.high_limit = STACK_TOP32;
12284 addr = vm_unmapped_area(&info);
12285 }
12286@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12287 struct mm_struct *mm = current->mm;
12288 struct vm_area_struct *vma;
12289 unsigned long task_size = TASK_SIZE;
12290+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12291
12292 if (test_thread_flag(TIF_32BIT))
12293 task_size = STACK_TOP32;
12294@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12295 return addr;
12296 }
12297
12298+#ifdef CONFIG_PAX_RANDMMAP
12299+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12300+#endif
12301+
12302 if (addr) {
12303 addr = ALIGN(addr, HPAGE_SIZE);
12304 vma = find_vma(mm, addr);
12305- if (task_size - len >= addr &&
12306- (!vma || addr + len <= vma->vm_start))
12307+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12308 return addr;
12309 }
12310 if (mm->get_unmapped_area == arch_get_unmapped_area)
12311 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12312- pgoff, flags);
12313+ pgoff, flags, offset);
12314 else
12315 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12316- pgoff, flags);
12317+ pgoff, flags, offset);
12318 }
12319
12320 pte_t *huge_pte_alloc(struct mm_struct *mm,
12321diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12322index eafbc65..5a8070d 100644
12323--- a/arch/sparc/mm/init_64.c
12324+++ b/arch/sparc/mm/init_64.c
12325@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12326 int num_kernel_image_mappings;
12327
12328 #ifdef CONFIG_DEBUG_DCFLUSH
12329-atomic_t dcpage_flushes = ATOMIC_INIT(0);
12330+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12331 #ifdef CONFIG_SMP
12332-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12333+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12334 #endif
12335 #endif
12336
12337@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
12338 {
12339 BUG_ON(tlb_type == hypervisor);
12340 #ifdef CONFIG_DEBUG_DCFLUSH
12341- atomic_inc(&dcpage_flushes);
12342+ atomic_inc_unchecked(&dcpage_flushes);
12343 #endif
12344
12345 #ifdef DCACHE_ALIASING_POSSIBLE
12346@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
12347
12348 #ifdef CONFIG_DEBUG_DCFLUSH
12349 seq_printf(m, "DCPageFlushes\t: %d\n",
12350- atomic_read(&dcpage_flushes));
12351+ atomic_read_unchecked(&dcpage_flushes));
12352 #ifdef CONFIG_SMP
12353 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12354- atomic_read(&dcpage_flushes_xcall));
12355+ atomic_read_unchecked(&dcpage_flushes_xcall));
12356 #endif /* CONFIG_SMP */
12357 #endif /* CONFIG_DEBUG_DCFLUSH */
12358 }
12359diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c
12360index b12cb5e..b89aba2 100644
12361--- a/arch/sparc/mm/tlb.c
12362+++ b/arch/sparc/mm/tlb.c
12363@@ -134,7 +134,7 @@ no_cache_flush:
12364
12365 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
12366 static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
12367- pmd_t pmd, bool exec)
12368+ pmd_t pmd)
12369 {
12370 unsigned long end;
12371 pte_t *pte;
12372@@ -142,8 +142,11 @@ static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
12373 pte = pte_offset_map(&pmd, vaddr);
12374 end = vaddr + HPAGE_SIZE;
12375 while (vaddr < end) {
12376- if (pte_val(*pte) & _PAGE_VALID)
12377+ if (pte_val(*pte) & _PAGE_VALID) {
12378+ bool exec = pte_exec(*pte);
12379+
12380 tlb_batch_add_one(mm, vaddr, exec);
12381+ }
12382 pte++;
12383 vaddr += PAGE_SIZE;
12384 }
12385@@ -177,19 +180,30 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,
12386 }
12387
12388 if (!pmd_none(orig)) {
12389- pte_t orig_pte = __pte(pmd_val(orig));
12390- bool exec = pte_exec(orig_pte);
12391-
12392 addr &= HPAGE_MASK;
12393 if (pmd_trans_huge(orig)) {
12394+ pte_t orig_pte = __pte(pmd_val(orig));
12395+ bool exec = pte_exec(orig_pte);
12396+
12397 tlb_batch_add_one(mm, addr, exec);
12398 tlb_batch_add_one(mm, addr + REAL_HPAGE_SIZE, exec);
12399 } else {
12400- tlb_batch_pmd_scan(mm, addr, orig, exec);
12401+ tlb_batch_pmd_scan(mm, addr, orig);
12402 }
12403 }
12404 }
12405
12406+void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
12407+ pmd_t *pmdp)
12408+{
12409+ pmd_t entry = *pmdp;
12410+
12411+ pmd_val(entry) &= ~_PAGE_VALID;
12412+
12413+ set_pmd_at(vma->vm_mm, address, pmdp, entry);
12414+ flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
12415+}
12416+
12417 void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
12418 pgtable_t pgtable)
12419 {
12420diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12421index b3692ce..e4517c9 100644
12422--- a/arch/tile/Kconfig
12423+++ b/arch/tile/Kconfig
12424@@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
12425
12426 config KEXEC
12427 bool "kexec system call"
12428+ depends on !GRKERNSEC_KMEM
12429 ---help---
12430 kexec is a system call that implements the ability to shutdown your
12431 current kernel, and to start another kernel. It is like a reboot
12432diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12433index ad220ee..2f537b3 100644
12434--- a/arch/tile/include/asm/atomic_64.h
12435+++ b/arch/tile/include/asm/atomic_64.h
12436@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12437
12438 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12439
12440+#define atomic64_read_unchecked(v) atomic64_read(v)
12441+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12442+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12443+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12444+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12445+#define atomic64_inc_unchecked(v) atomic64_inc(v)
12446+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12447+#define atomic64_dec_unchecked(v) atomic64_dec(v)
12448+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12449+
12450 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
12451 #define smp_mb__before_atomic_dec() smp_mb()
12452 #define smp_mb__after_atomic_dec() smp_mb()
12453diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12454index 6160761..00cac88 100644
12455--- a/arch/tile/include/asm/cache.h
12456+++ b/arch/tile/include/asm/cache.h
12457@@ -15,11 +15,12 @@
12458 #ifndef _ASM_TILE_CACHE_H
12459 #define _ASM_TILE_CACHE_H
12460
12461+#include <linux/const.h>
12462 #include <arch/chip.h>
12463
12464 /* bytes per L1 data cache line */
12465 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12466-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12467+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12468
12469 /* bytes per L2 cache line */
12470 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12471diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12472index b6cde32..c0cb736 100644
12473--- a/arch/tile/include/asm/uaccess.h
12474+++ b/arch/tile/include/asm/uaccess.h
12475@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12476 const void __user *from,
12477 unsigned long n)
12478 {
12479- int sz = __compiletime_object_size(to);
12480+ size_t sz = __compiletime_object_size(to);
12481
12482- if (likely(sz == -1 || sz >= n))
12483+ if (likely(sz == (size_t)-1 || sz >= n))
12484 n = _copy_from_user(to, from, n);
12485 else
12486 copy_from_user_overflow();
12487diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12488index 0cb3bba..7338b2d 100644
12489--- a/arch/tile/mm/hugetlbpage.c
12490+++ b/arch/tile/mm/hugetlbpage.c
12491@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12492 info.high_limit = TASK_SIZE;
12493 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12494 info.align_offset = 0;
12495+ info.threadstack_offset = 0;
12496 return vm_unmapped_area(&info);
12497 }
12498
12499@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12500 info.high_limit = current->mm->mmap_base;
12501 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12502 info.align_offset = 0;
12503+ info.threadstack_offset = 0;
12504 addr = vm_unmapped_area(&info);
12505
12506 /*
12507diff --git a/arch/um/Makefile b/arch/um/Makefile
12508index 36e658a..71a5c5a 100644
12509--- a/arch/um/Makefile
12510+++ b/arch/um/Makefile
12511@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12512 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12513 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12514
12515+ifdef CONSTIFY_PLUGIN
12516+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12517+endif
12518+
12519 #This will adjust *FLAGS accordingly to the platform.
12520 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12521
12522diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12523index 19e1bdd..3665b77 100644
12524--- a/arch/um/include/asm/cache.h
12525+++ b/arch/um/include/asm/cache.h
12526@@ -1,6 +1,7 @@
12527 #ifndef __UM_CACHE_H
12528 #define __UM_CACHE_H
12529
12530+#include <linux/const.h>
12531
12532 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12533 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12534@@ -12,6 +13,6 @@
12535 # define L1_CACHE_SHIFT 5
12536 #endif
12537
12538-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12539+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12540
12541 #endif
12542diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12543index 2e0a6b1..a64d0f5 100644
12544--- a/arch/um/include/asm/kmap_types.h
12545+++ b/arch/um/include/asm/kmap_types.h
12546@@ -8,6 +8,6 @@
12547
12548 /* No more #include "asm/arch/kmap_types.h" ! */
12549
12550-#define KM_TYPE_NR 14
12551+#define KM_TYPE_NR 15
12552
12553 #endif
12554diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12555index 5ff53d9..5850cdf 100644
12556--- a/arch/um/include/asm/page.h
12557+++ b/arch/um/include/asm/page.h
12558@@ -14,6 +14,9 @@
12559 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12560 #define PAGE_MASK (~(PAGE_SIZE-1))
12561
12562+#define ktla_ktva(addr) (addr)
12563+#define ktva_ktla(addr) (addr)
12564+
12565 #ifndef __ASSEMBLY__
12566
12567 struct page;
12568diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12569index 0032f92..cd151e0 100644
12570--- a/arch/um/include/asm/pgtable-3level.h
12571+++ b/arch/um/include/asm/pgtable-3level.h
12572@@ -58,6 +58,7 @@
12573 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12574 #define pud_populate(mm, pud, pmd) \
12575 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12576+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12577
12578 #ifdef CONFIG_64BIT
12579 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12580diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12581index eecc414..48adb87 100644
12582--- a/arch/um/kernel/process.c
12583+++ b/arch/um/kernel/process.c
12584@@ -356,22 +356,6 @@ int singlestepping(void * t)
12585 return 2;
12586 }
12587
12588-/*
12589- * Only x86 and x86_64 have an arch_align_stack().
12590- * All other arches have "#define arch_align_stack(x) (x)"
12591- * in their asm/system.h
12592- * As this is included in UML from asm-um/system-generic.h,
12593- * we can use it to behave as the subarch does.
12594- */
12595-#ifndef arch_align_stack
12596-unsigned long arch_align_stack(unsigned long sp)
12597-{
12598- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12599- sp -= get_random_int() % 8192;
12600- return sp & ~0xf;
12601-}
12602-#endif
12603-
12604 unsigned long get_wchan(struct task_struct *p)
12605 {
12606 unsigned long stack_page, sp, ip;
12607diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12608index ad8f795..2c7eec6 100644
12609--- a/arch/unicore32/include/asm/cache.h
12610+++ b/arch/unicore32/include/asm/cache.h
12611@@ -12,8 +12,10 @@
12612 #ifndef __UNICORE_CACHE_H__
12613 #define __UNICORE_CACHE_H__
12614
12615-#define L1_CACHE_SHIFT (5)
12616-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12617+#include <linux/const.h>
12618+
12619+#define L1_CACHE_SHIFT 5
12620+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12621
12622 /*
12623 * Memory returned by kmalloc() may be used for DMA, so we must make
12624diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12625index 0af5250..59f9597 100644
12626--- a/arch/x86/Kconfig
12627+++ b/arch/x86/Kconfig
12628@@ -126,7 +126,7 @@ config X86
12629 select RTC_LIB
12630 select HAVE_DEBUG_STACKOVERFLOW
12631 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12632- select HAVE_CC_STACKPROTECTOR
12633+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12634
12635 config INSTRUCTION_DECODER
12636 def_bool y
12637@@ -251,7 +251,7 @@ config X86_HT
12638
12639 config X86_32_LAZY_GS
12640 def_bool y
12641- depends on X86_32 && !CC_STACKPROTECTOR
12642+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12643
12644 config ARCH_HWEIGHT_CFLAGS
12645 string
12646@@ -589,6 +589,7 @@ config SCHED_OMIT_FRAME_POINTER
12647
12648 menuconfig HYPERVISOR_GUEST
12649 bool "Linux guest support"
12650+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12651 ---help---
12652 Say Y here to enable options for running Linux under various hyper-
12653 visors. This option enables basic hypervisor detection and platform
12654@@ -1111,7 +1112,7 @@ choice
12655
12656 config NOHIGHMEM
12657 bool "off"
12658- depends on !X86_NUMAQ
12659+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12660 ---help---
12661 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12662 However, the address space of 32-bit x86 processors is only 4
12663@@ -1148,7 +1149,7 @@ config NOHIGHMEM
12664
12665 config HIGHMEM4G
12666 bool "4GB"
12667- depends on !X86_NUMAQ
12668+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12669 ---help---
12670 Select this if you have a 32-bit processor and between 1 and 4
12671 gigabytes of physical RAM.
12672@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
12673 hex
12674 default 0xB0000000 if VMSPLIT_3G_OPT
12675 default 0x80000000 if VMSPLIT_2G
12676- default 0x78000000 if VMSPLIT_2G_OPT
12677+ default 0x70000000 if VMSPLIT_2G_OPT
12678 default 0x40000000 if VMSPLIT_1G
12679 default 0xC0000000
12680 depends on X86_32
12681@@ -1605,6 +1606,7 @@ source kernel/Kconfig.hz
12682
12683 config KEXEC
12684 bool "kexec system call"
12685+ depends on !GRKERNSEC_KMEM
12686 ---help---
12687 kexec is a system call that implements the ability to shutdown your
12688 current kernel, and to start another kernel. It is like a reboot
12689@@ -1756,7 +1758,9 @@ config X86_NEED_RELOCS
12690
12691 config PHYSICAL_ALIGN
12692 hex "Alignment value to which kernel should be aligned"
12693- default "0x200000"
12694+ default "0x1000000"
12695+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12696+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12697 range 0x2000 0x1000000 if X86_32
12698 range 0x200000 0x1000000 if X86_64
12699 ---help---
12700@@ -1836,9 +1840,10 @@ config DEBUG_HOTPLUG_CPU0
12701 If unsure, say N.
12702
12703 config COMPAT_VDSO
12704- def_bool y
12705+ def_bool n
12706 prompt "Compat VDSO support"
12707 depends on X86_32 || IA32_EMULATION
12708+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12709 ---help---
12710 Map the 32-bit VDSO to the predictable old-style address too.
12711
12712diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12713index f3aaf23..a1d3c49 100644
12714--- a/arch/x86/Kconfig.cpu
12715+++ b/arch/x86/Kconfig.cpu
12716@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12717
12718 config X86_F00F_BUG
12719 def_bool y
12720- depends on M586MMX || M586TSC || M586 || M486
12721+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12722
12723 config X86_INVD_BUG
12724 def_bool y
12725@@ -327,7 +327,7 @@ config X86_INVD_BUG
12726
12727 config X86_ALIGNMENT_16
12728 def_bool y
12729- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12730+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12731
12732 config X86_INTEL_USERCOPY
12733 def_bool y
12734@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12735 # generates cmov.
12736 config X86_CMOV
12737 def_bool y
12738- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12739+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12740
12741 config X86_MINIMUM_CPU_FAMILY
12742 int
12743diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12744index 321a52c..3d51a5e 100644
12745--- a/arch/x86/Kconfig.debug
12746+++ b/arch/x86/Kconfig.debug
12747@@ -84,7 +84,7 @@ config X86_PTDUMP
12748 config DEBUG_RODATA
12749 bool "Write protect kernel read-only data structures"
12750 default y
12751- depends on DEBUG_KERNEL
12752+ depends on DEBUG_KERNEL && BROKEN
12753 ---help---
12754 Mark the kernel read-only data as write-protected in the pagetables,
12755 in order to catch accidental (and incorrect) writes to such const
12756@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12757
12758 config DEBUG_SET_MODULE_RONX
12759 bool "Set loadable kernel module data as NX and text as RO"
12760- depends on MODULES
12761+ depends on MODULES && BROKEN
12762 ---help---
12763 This option helps catch unintended modifications to loadable
12764 kernel module's text and read-only data. It also prevents execution
12765diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12766index 0dd99ea..4a63d82 100644
12767--- a/arch/x86/Makefile
12768+++ b/arch/x86/Makefile
12769@@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12770 # CPU-specific tuning. Anything which can be shared with UML should go here.
12771 include $(srctree)/arch/x86/Makefile_32.cpu
12772 KBUILD_CFLAGS += $(cflags-y)
12773-
12774- # temporary until string.h is fixed
12775- KBUILD_CFLAGS += -ffreestanding
12776 else
12777 BITS := 64
12778 UTS_MACHINE := x86_64
12779@@ -112,6 +109,9 @@ else
12780 KBUILD_CFLAGS += -maccumulate-outgoing-args
12781 endif
12782
12783+# temporary until string.h is fixed
12784+KBUILD_CFLAGS += -ffreestanding
12785+
12786 # Make sure compiler does not have buggy stack-protector support.
12787 ifdef CONFIG_CC_STACKPROTECTOR
12788 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12789@@ -269,3 +269,12 @@ define archhelp
12790 echo ' FDINITRD=file initrd for the booted kernel'
12791 echo ' kvmconfig - Enable additional options for guest kernel support'
12792 endef
12793+
12794+define OLD_LD
12795+
12796+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12797+*** Please upgrade your binutils to 2.18 or newer
12798+endef
12799+
12800+archprepare:
12801+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12802diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12803index 878df7e..a803913 100644
12804--- a/arch/x86/boot/Makefile
12805+++ b/arch/x86/boot/Makefile
12806@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12807 # ---------------------------------------------------------------------------
12808
12809 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12810+ifdef CONSTIFY_PLUGIN
12811+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12812+endif
12813 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12814 GCOV_PROFILE := n
12815
12816diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12817index 878e4b9..20537ab 100644
12818--- a/arch/x86/boot/bitops.h
12819+++ b/arch/x86/boot/bitops.h
12820@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12821 u8 v;
12822 const u32 *p = (const u32 *)addr;
12823
12824- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12825+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12826 return v;
12827 }
12828
12829@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12830
12831 static inline void set_bit(int nr, void *addr)
12832 {
12833- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12834+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12835 }
12836
12837 #endif /* BOOT_BITOPS_H */
12838diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12839index 50f8c5e..4f84fff 100644
12840--- a/arch/x86/boot/boot.h
12841+++ b/arch/x86/boot/boot.h
12842@@ -84,7 +84,7 @@ static inline void io_delay(void)
12843 static inline u16 ds(void)
12844 {
12845 u16 seg;
12846- asm("movw %%ds,%0" : "=rm" (seg));
12847+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12848 return seg;
12849 }
12850
12851@@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12852 static inline int memcmp(const void *s1, const void *s2, size_t len)
12853 {
12854 u8 diff;
12855- asm("repe; cmpsb; setnz %0"
12856+ asm volatile("repe; cmpsb; setnz %0"
12857 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12858 return diff;
12859 }
12860diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12861index 0fcd913..3bb5c42 100644
12862--- a/arch/x86/boot/compressed/Makefile
12863+++ b/arch/x86/boot/compressed/Makefile
12864@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12865 KBUILD_CFLAGS += -mno-mmx -mno-sse
12866 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12867 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12868+ifdef CONSTIFY_PLUGIN
12869+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12870+endif
12871
12872 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12873 GCOV_PROFILE := n
12874diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12875index a53440e..c3dbf1e 100644
12876--- a/arch/x86/boot/compressed/efi_stub_32.S
12877+++ b/arch/x86/boot/compressed/efi_stub_32.S
12878@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12879 * parameter 2, ..., param n. To make things easy, we save the return
12880 * address of efi_call_phys in a global variable.
12881 */
12882- popl %ecx
12883- movl %ecx, saved_return_addr(%edx)
12884- /* get the function pointer into ECX*/
12885- popl %ecx
12886- movl %ecx, efi_rt_function_ptr(%edx)
12887+ popl saved_return_addr(%edx)
12888+ popl efi_rt_function_ptr(%edx)
12889
12890 /*
12891 * 3. Call the physical function.
12892 */
12893- call *%ecx
12894+ call *efi_rt_function_ptr(%edx)
12895
12896 /*
12897 * 4. Balance the stack. And because EAX contain the return value,
12898@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12899 1: popl %edx
12900 subl $1b, %edx
12901
12902- movl efi_rt_function_ptr(%edx), %ecx
12903- pushl %ecx
12904+ pushl efi_rt_function_ptr(%edx)
12905
12906 /*
12907 * 10. Push the saved return address onto the stack and return.
12908 */
12909- movl saved_return_addr(%edx), %ecx
12910- pushl %ecx
12911- ret
12912+ jmpl *saved_return_addr(%edx)
12913 ENDPROC(efi_call_phys)
12914 .previous
12915
12916diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12917index f45ab7a..ebc015f 100644
12918--- a/arch/x86/boot/compressed/head_32.S
12919+++ b/arch/x86/boot/compressed/head_32.S
12920@@ -119,10 +119,10 @@ preferred_addr:
12921 addl %eax, %ebx
12922 notl %eax
12923 andl %eax, %ebx
12924- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12925+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12926 jge 1f
12927 #endif
12928- movl $LOAD_PHYSICAL_ADDR, %ebx
12929+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12930 1:
12931
12932 /* Target address to relocate to for decompression */
12933diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12934index b10fa66..5ee0472 100644
12935--- a/arch/x86/boot/compressed/head_64.S
12936+++ b/arch/x86/boot/compressed/head_64.S
12937@@ -94,10 +94,10 @@ ENTRY(startup_32)
12938 addl %eax, %ebx
12939 notl %eax
12940 andl %eax, %ebx
12941- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12942+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12943 jge 1f
12944 #endif
12945- movl $LOAD_PHYSICAL_ADDR, %ebx
12946+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12947 1:
12948
12949 /* Target address to relocate to for decompression */
12950@@ -268,10 +268,10 @@ preferred_addr:
12951 addq %rax, %rbp
12952 notq %rax
12953 andq %rax, %rbp
12954- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12955+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12956 jge 1f
12957 #endif
12958- movq $LOAD_PHYSICAL_ADDR, %rbp
12959+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12960 1:
12961
12962 /* Target address to relocate to for decompression */
12963@@ -363,8 +363,8 @@ gdt:
12964 .long gdt
12965 .word 0
12966 .quad 0x0000000000000000 /* NULL descriptor */
12967- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12968- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12969+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12970+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12971 .quad 0x0080890000000000 /* TS descriptor */
12972 .quad 0x0000000000000000 /* TS continued */
12973 gdt_end:
12974diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12975index 196eaf3..c96716d 100644
12976--- a/arch/x86/boot/compressed/misc.c
12977+++ b/arch/x86/boot/compressed/misc.c
12978@@ -218,7 +218,7 @@ void __putstr(const char *s)
12979
12980 void *memset(void *s, int c, size_t n)
12981 {
12982- int i;
12983+ size_t i;
12984 char *ss = s;
12985
12986 for (i = 0; i < n; i++)
12987@@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12988 * Calculate the delta between where vmlinux was linked to load
12989 * and where it was actually loaded.
12990 */
12991- delta = min_addr - LOAD_PHYSICAL_ADDR;
12992+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12993 if (!delta) {
12994 debug_putstr("No relocation needed... ");
12995 return;
12996@@ -347,7 +347,7 @@ static void parse_elf(void *output)
12997 Elf32_Ehdr ehdr;
12998 Elf32_Phdr *phdrs, *phdr;
12999 #endif
13000- void *dest;
13001+ void *dest, *prev;
13002 int i;
13003
13004 memcpy(&ehdr, output, sizeof(ehdr));
13005@@ -374,13 +374,16 @@ static void parse_elf(void *output)
13006 case PT_LOAD:
13007 #ifdef CONFIG_RELOCATABLE
13008 dest = output;
13009- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
13010+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
13011 #else
13012 dest = (void *)(phdr->p_paddr);
13013 #endif
13014 memcpy(dest,
13015 output + phdr->p_offset,
13016 phdr->p_filesz);
13017+ if (i)
13018+ memset(prev, 0xff, dest - prev);
13019+ prev = dest + phdr->p_filesz;
13020 break;
13021 default: /* Ignore other PT_* */ break;
13022 }
13023@@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
13024 error("Destination address too large");
13025 #endif
13026 #ifndef CONFIG_RELOCATABLE
13027- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
13028+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
13029 error("Wrong destination address");
13030 #endif
13031
13032diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
13033index 100a9a1..bb3bdb0 100644
13034--- a/arch/x86/boot/cpucheck.c
13035+++ b/arch/x86/boot/cpucheck.c
13036@@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13037 u32 ecx = MSR_K7_HWCR;
13038 u32 eax, edx;
13039
13040- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13041+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13042 eax &= ~(1 << 15);
13043- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13044+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13045
13046 get_cpuflags(); /* Make sure it really did something */
13047 err = check_cpuflags();
13048@@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13049 u32 ecx = MSR_VIA_FCR;
13050 u32 eax, edx;
13051
13052- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13053+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13054 eax |= (1<<1)|(1<<7);
13055- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13056+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13057
13058 set_bit(X86_FEATURE_CX8, cpu.flags);
13059 err = check_cpuflags();
13060@@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13061 u32 eax, edx;
13062 u32 level = 1;
13063
13064- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13065- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13066- asm("cpuid"
13067+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13068+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13069+ asm volatile("cpuid"
13070 : "+a" (level), "=d" (cpu.flags[0])
13071 : : "ecx", "ebx");
13072- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13073+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13074
13075 err = check_cpuflags();
13076 }
13077diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13078index ec3b8ba..6a0db1f 100644
13079--- a/arch/x86/boot/header.S
13080+++ b/arch/x86/boot/header.S
13081@@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13082 # single linked list of
13083 # struct setup_data
13084
13085-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13086+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13087
13088 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13089+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13090+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13091+#else
13092 #define VO_INIT_SIZE (VO__end - VO__text)
13093+#endif
13094 #if ZO_INIT_SIZE > VO_INIT_SIZE
13095 #define INIT_SIZE ZO_INIT_SIZE
13096 #else
13097diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13098index db75d07..8e6d0af 100644
13099--- a/arch/x86/boot/memory.c
13100+++ b/arch/x86/boot/memory.c
13101@@ -19,7 +19,7 @@
13102
13103 static int detect_memory_e820(void)
13104 {
13105- int count = 0;
13106+ unsigned int count = 0;
13107 struct biosregs ireg, oreg;
13108 struct e820entry *desc = boot_params.e820_map;
13109 static struct e820entry buf; /* static so it is zeroed */
13110diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13111index 11e8c6e..fdbb1ed 100644
13112--- a/arch/x86/boot/video-vesa.c
13113+++ b/arch/x86/boot/video-vesa.c
13114@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
13115
13116 boot_params.screen_info.vesapm_seg = oreg.es;
13117 boot_params.screen_info.vesapm_off = oreg.di;
13118+ boot_params.screen_info.vesapm_size = oreg.cx;
13119 }
13120
13121 /*
13122diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13123index 43eda28..5ab5fdb 100644
13124--- a/arch/x86/boot/video.c
13125+++ b/arch/x86/boot/video.c
13126@@ -96,7 +96,7 @@ static void store_mode_params(void)
13127 static unsigned int get_entry(void)
13128 {
13129 char entry_buf[4];
13130- int i, len = 0;
13131+ unsigned int i, len = 0;
13132 int key;
13133 unsigned int v;
13134
13135diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13136index 9105655..41779c1 100644
13137--- a/arch/x86/crypto/aes-x86_64-asm_64.S
13138+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13139@@ -8,6 +8,8 @@
13140 * including this sentence is retained in full.
13141 */
13142
13143+#include <asm/alternative-asm.h>
13144+
13145 .extern crypto_ft_tab
13146 .extern crypto_it_tab
13147 .extern crypto_fl_tab
13148@@ -70,6 +72,8 @@
13149 je B192; \
13150 leaq 32(r9),r9;
13151
13152+#define ret pax_force_retaddr; ret
13153+
13154 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13155 movq r1,r2; \
13156 movq r3,r4; \
13157diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13158index 477e9d7..c92c7d8 100644
13159--- a/arch/x86/crypto/aesni-intel_asm.S
13160+++ b/arch/x86/crypto/aesni-intel_asm.S
13161@@ -31,6 +31,7 @@
13162
13163 #include <linux/linkage.h>
13164 #include <asm/inst.h>
13165+#include <asm/alternative-asm.h>
13166
13167 #ifdef __x86_64__
13168 .data
13169@@ -205,7 +206,7 @@ enc: .octa 0x2
13170 * num_initial_blocks = b mod 4
13171 * encrypt the initial num_initial_blocks blocks and apply ghash on
13172 * the ciphertext
13173-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13174+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13175 * are clobbered
13176 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13177 */
13178@@ -214,8 +215,8 @@ enc: .octa 0x2
13179 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13180 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13181 mov arg7, %r10 # %r10 = AAD
13182- mov arg8, %r12 # %r12 = aadLen
13183- mov %r12, %r11
13184+ mov arg8, %r15 # %r15 = aadLen
13185+ mov %r15, %r11
13186 pxor %xmm\i, %xmm\i
13187 _get_AAD_loop\num_initial_blocks\operation:
13188 movd (%r10), \TMP1
13189@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13190 psrldq $4, %xmm\i
13191 pxor \TMP1, %xmm\i
13192 add $4, %r10
13193- sub $4, %r12
13194+ sub $4, %r15
13195 jne _get_AAD_loop\num_initial_blocks\operation
13196 cmp $16, %r11
13197 je _get_AAD_loop2_done\num_initial_blocks\operation
13198- mov $16, %r12
13199+ mov $16, %r15
13200 _get_AAD_loop2\num_initial_blocks\operation:
13201 psrldq $4, %xmm\i
13202- sub $4, %r12
13203- cmp %r11, %r12
13204+ sub $4, %r15
13205+ cmp %r11, %r15
13206 jne _get_AAD_loop2\num_initial_blocks\operation
13207 _get_AAD_loop2_done\num_initial_blocks\operation:
13208 movdqa SHUF_MASK(%rip), %xmm14
13209@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13210 * num_initial_blocks = b mod 4
13211 * encrypt the initial num_initial_blocks blocks and apply ghash on
13212 * the ciphertext
13213-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13214+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13215 * are clobbered
13216 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13217 */
13218@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13219 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13220 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13221 mov arg7, %r10 # %r10 = AAD
13222- mov arg8, %r12 # %r12 = aadLen
13223- mov %r12, %r11
13224+ mov arg8, %r15 # %r15 = aadLen
13225+ mov %r15, %r11
13226 pxor %xmm\i, %xmm\i
13227 _get_AAD_loop\num_initial_blocks\operation:
13228 movd (%r10), \TMP1
13229@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13230 psrldq $4, %xmm\i
13231 pxor \TMP1, %xmm\i
13232 add $4, %r10
13233- sub $4, %r12
13234+ sub $4, %r15
13235 jne _get_AAD_loop\num_initial_blocks\operation
13236 cmp $16, %r11
13237 je _get_AAD_loop2_done\num_initial_blocks\operation
13238- mov $16, %r12
13239+ mov $16, %r15
13240 _get_AAD_loop2\num_initial_blocks\operation:
13241 psrldq $4, %xmm\i
13242- sub $4, %r12
13243- cmp %r11, %r12
13244+ sub $4, %r15
13245+ cmp %r11, %r15
13246 jne _get_AAD_loop2\num_initial_blocks\operation
13247 _get_AAD_loop2_done\num_initial_blocks\operation:
13248 movdqa SHUF_MASK(%rip), %xmm14
13249@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13250 *
13251 *****************************************************************************/
13252 ENTRY(aesni_gcm_dec)
13253- push %r12
13254+ push %r15
13255 push %r13
13256 push %r14
13257 mov %rsp, %r14
13258@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13259 */
13260 sub $VARIABLE_OFFSET, %rsp
13261 and $~63, %rsp # align rsp to 64 bytes
13262- mov %arg6, %r12
13263- movdqu (%r12), %xmm13 # %xmm13 = HashKey
13264+ mov %arg6, %r15
13265+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
13266 movdqa SHUF_MASK(%rip), %xmm2
13267 PSHUFB_XMM %xmm2, %xmm13
13268
13269@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13270 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13271 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13272 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13273- mov %r13, %r12
13274- and $(3<<4), %r12
13275+ mov %r13, %r15
13276+ and $(3<<4), %r15
13277 jz _initial_num_blocks_is_0_decrypt
13278- cmp $(2<<4), %r12
13279+ cmp $(2<<4), %r15
13280 jb _initial_num_blocks_is_1_decrypt
13281 je _initial_num_blocks_is_2_decrypt
13282 _initial_num_blocks_is_3_decrypt:
13283@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13284 sub $16, %r11
13285 add %r13, %r11
13286 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13287- lea SHIFT_MASK+16(%rip), %r12
13288- sub %r13, %r12
13289+ lea SHIFT_MASK+16(%rip), %r15
13290+ sub %r13, %r15
13291 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13292 # (%r13 is the number of bytes in plaintext mod 16)
13293- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13294+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13295 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13296
13297 movdqa %xmm1, %xmm2
13298 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13299- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13300+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13301 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13302 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13303 pand %xmm1, %xmm2
13304@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13305 sub $1, %r13
13306 jne _less_than_8_bytes_left_decrypt
13307 _multiple_of_16_bytes_decrypt:
13308- mov arg8, %r12 # %r13 = aadLen (number of bytes)
13309- shl $3, %r12 # convert into number of bits
13310- movd %r12d, %xmm15 # len(A) in %xmm15
13311+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
13312+ shl $3, %r15 # convert into number of bits
13313+ movd %r15d, %xmm15 # len(A) in %xmm15
13314 shl $3, %arg4 # len(C) in bits (*128)
13315 MOVQ_R64_XMM %arg4, %xmm1
13316 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13317@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13318 mov %r14, %rsp
13319 pop %r14
13320 pop %r13
13321- pop %r12
13322+ pop %r15
13323+ pax_force_retaddr
13324 ret
13325 ENDPROC(aesni_gcm_dec)
13326
13327@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13328 * poly = x^128 + x^127 + x^126 + x^121 + 1
13329 ***************************************************************************/
13330 ENTRY(aesni_gcm_enc)
13331- push %r12
13332+ push %r15
13333 push %r13
13334 push %r14
13335 mov %rsp, %r14
13336@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13337 #
13338 sub $VARIABLE_OFFSET, %rsp
13339 and $~63, %rsp
13340- mov %arg6, %r12
13341- movdqu (%r12), %xmm13
13342+ mov %arg6, %r15
13343+ movdqu (%r15), %xmm13
13344 movdqa SHUF_MASK(%rip), %xmm2
13345 PSHUFB_XMM %xmm2, %xmm13
13346
13347@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13348 movdqa %xmm13, HashKey(%rsp)
13349 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13350 and $-16, %r13
13351- mov %r13, %r12
13352+ mov %r13, %r15
13353
13354 # Encrypt first few blocks
13355
13356- and $(3<<4), %r12
13357+ and $(3<<4), %r15
13358 jz _initial_num_blocks_is_0_encrypt
13359- cmp $(2<<4), %r12
13360+ cmp $(2<<4), %r15
13361 jb _initial_num_blocks_is_1_encrypt
13362 je _initial_num_blocks_is_2_encrypt
13363 _initial_num_blocks_is_3_encrypt:
13364@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13365 sub $16, %r11
13366 add %r13, %r11
13367 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13368- lea SHIFT_MASK+16(%rip), %r12
13369- sub %r13, %r12
13370+ lea SHIFT_MASK+16(%rip), %r15
13371+ sub %r13, %r15
13372 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13373 # (%r13 is the number of bytes in plaintext mod 16)
13374- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13375+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13376 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13377 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13378- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13379+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13380 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13381 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13382 movdqa SHUF_MASK(%rip), %xmm10
13383@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13384 sub $1, %r13
13385 jne _less_than_8_bytes_left_encrypt
13386 _multiple_of_16_bytes_encrypt:
13387- mov arg8, %r12 # %r12 = addLen (number of bytes)
13388- shl $3, %r12
13389- movd %r12d, %xmm15 # len(A) in %xmm15
13390+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13391+ shl $3, %r15
13392+ movd %r15d, %xmm15 # len(A) in %xmm15
13393 shl $3, %arg4 # len(C) in bits (*128)
13394 MOVQ_R64_XMM %arg4, %xmm1
13395 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13396@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13397 mov %r14, %rsp
13398 pop %r14
13399 pop %r13
13400- pop %r12
13401+ pop %r15
13402+ pax_force_retaddr
13403 ret
13404 ENDPROC(aesni_gcm_enc)
13405
13406@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13407 pxor %xmm1, %xmm0
13408 movaps %xmm0, (TKEYP)
13409 add $0x10, TKEYP
13410+ pax_force_retaddr
13411 ret
13412 ENDPROC(_key_expansion_128)
13413 ENDPROC(_key_expansion_256a)
13414@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13415 shufps $0b01001110, %xmm2, %xmm1
13416 movaps %xmm1, 0x10(TKEYP)
13417 add $0x20, TKEYP
13418+ pax_force_retaddr
13419 ret
13420 ENDPROC(_key_expansion_192a)
13421
13422@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13423
13424 movaps %xmm0, (TKEYP)
13425 add $0x10, TKEYP
13426+ pax_force_retaddr
13427 ret
13428 ENDPROC(_key_expansion_192b)
13429
13430@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13431 pxor %xmm1, %xmm2
13432 movaps %xmm2, (TKEYP)
13433 add $0x10, TKEYP
13434+ pax_force_retaddr
13435 ret
13436 ENDPROC(_key_expansion_256b)
13437
13438@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13439 #ifndef __x86_64__
13440 popl KEYP
13441 #endif
13442+ pax_force_retaddr
13443 ret
13444 ENDPROC(aesni_set_key)
13445
13446@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13447 popl KLEN
13448 popl KEYP
13449 #endif
13450+ pax_force_retaddr
13451 ret
13452 ENDPROC(aesni_enc)
13453
13454@@ -1974,6 +1983,7 @@ _aesni_enc1:
13455 AESENC KEY STATE
13456 movaps 0x70(TKEYP), KEY
13457 AESENCLAST KEY STATE
13458+ pax_force_retaddr
13459 ret
13460 ENDPROC(_aesni_enc1)
13461
13462@@ -2083,6 +2093,7 @@ _aesni_enc4:
13463 AESENCLAST KEY STATE2
13464 AESENCLAST KEY STATE3
13465 AESENCLAST KEY STATE4
13466+ pax_force_retaddr
13467 ret
13468 ENDPROC(_aesni_enc4)
13469
13470@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13471 popl KLEN
13472 popl KEYP
13473 #endif
13474+ pax_force_retaddr
13475 ret
13476 ENDPROC(aesni_dec)
13477
13478@@ -2164,6 +2176,7 @@ _aesni_dec1:
13479 AESDEC KEY STATE
13480 movaps 0x70(TKEYP), KEY
13481 AESDECLAST KEY STATE
13482+ pax_force_retaddr
13483 ret
13484 ENDPROC(_aesni_dec1)
13485
13486@@ -2273,6 +2286,7 @@ _aesni_dec4:
13487 AESDECLAST KEY STATE2
13488 AESDECLAST KEY STATE3
13489 AESDECLAST KEY STATE4
13490+ pax_force_retaddr
13491 ret
13492 ENDPROC(_aesni_dec4)
13493
13494@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13495 popl KEYP
13496 popl LEN
13497 #endif
13498+ pax_force_retaddr
13499 ret
13500 ENDPROC(aesni_ecb_enc)
13501
13502@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13503 popl KEYP
13504 popl LEN
13505 #endif
13506+ pax_force_retaddr
13507 ret
13508 ENDPROC(aesni_ecb_dec)
13509
13510@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13511 popl LEN
13512 popl IVP
13513 #endif
13514+ pax_force_retaddr
13515 ret
13516 ENDPROC(aesni_cbc_enc)
13517
13518@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13519 popl LEN
13520 popl IVP
13521 #endif
13522+ pax_force_retaddr
13523 ret
13524 ENDPROC(aesni_cbc_dec)
13525
13526@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13527 mov $1, TCTR_LOW
13528 MOVQ_R64_XMM TCTR_LOW INC
13529 MOVQ_R64_XMM CTR TCTR_LOW
13530+ pax_force_retaddr
13531 ret
13532 ENDPROC(_aesni_inc_init)
13533
13534@@ -2579,6 +2598,7 @@ _aesni_inc:
13535 .Linc_low:
13536 movaps CTR, IV
13537 PSHUFB_XMM BSWAP_MASK IV
13538+ pax_force_retaddr
13539 ret
13540 ENDPROC(_aesni_inc)
13541
13542@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13543 .Lctr_enc_ret:
13544 movups IV, (IVP)
13545 .Lctr_enc_just_ret:
13546+ pax_force_retaddr
13547 ret
13548 ENDPROC(aesni_ctr_enc)
13549
13550@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13551 pxor INC, STATE4
13552 movdqu STATE4, 0x70(OUTP)
13553
13554+ pax_force_retaddr
13555 ret
13556 ENDPROC(aesni_xts_crypt8)
13557
13558diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13559index 246c670..466e2d6 100644
13560--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13561+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13562@@ -21,6 +21,7 @@
13563 */
13564
13565 #include <linux/linkage.h>
13566+#include <asm/alternative-asm.h>
13567
13568 .file "blowfish-x86_64-asm.S"
13569 .text
13570@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13571 jnz .L__enc_xor;
13572
13573 write_block();
13574+ pax_force_retaddr
13575 ret;
13576 .L__enc_xor:
13577 xor_block();
13578+ pax_force_retaddr
13579 ret;
13580 ENDPROC(__blowfish_enc_blk)
13581
13582@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13583
13584 movq %r11, %rbp;
13585
13586+ pax_force_retaddr
13587 ret;
13588 ENDPROC(blowfish_dec_blk)
13589
13590@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13591
13592 popq %rbx;
13593 popq %rbp;
13594+ pax_force_retaddr
13595 ret;
13596
13597 .L__enc_xor4:
13598@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13599
13600 popq %rbx;
13601 popq %rbp;
13602+ pax_force_retaddr
13603 ret;
13604 ENDPROC(__blowfish_enc_blk_4way)
13605
13606@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13607 popq %rbx;
13608 popq %rbp;
13609
13610+ pax_force_retaddr
13611 ret;
13612 ENDPROC(blowfish_dec_blk_4way)
13613diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13614index ce71f92..1dce7ec 100644
13615--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13616+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13617@@ -16,6 +16,7 @@
13618 */
13619
13620 #include <linux/linkage.h>
13621+#include <asm/alternative-asm.h>
13622
13623 #define CAMELLIA_TABLE_BYTE_LEN 272
13624
13625@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13626 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13627 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13628 %rcx, (%r9));
13629+ pax_force_retaddr
13630 ret;
13631 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13632
13633@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13634 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13635 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13636 %rax, (%r9));
13637+ pax_force_retaddr
13638 ret;
13639 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13640
13641@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13642 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13643 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13644
13645+ pax_force_retaddr
13646 ret;
13647
13648 .align 8
13649@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13650 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13651 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13652
13653+ pax_force_retaddr
13654 ret;
13655
13656 .align 8
13657@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13658 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13659 %xmm8, %rsi);
13660
13661+ pax_force_retaddr
13662 ret;
13663 ENDPROC(camellia_ecb_enc_16way)
13664
13665@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13666 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13667 %xmm8, %rsi);
13668
13669+ pax_force_retaddr
13670 ret;
13671 ENDPROC(camellia_ecb_dec_16way)
13672
13673@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13674 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13675 %xmm8, %rsi);
13676
13677+ pax_force_retaddr
13678 ret;
13679 ENDPROC(camellia_cbc_dec_16way)
13680
13681@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13682 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13683 %xmm8, %rsi);
13684
13685+ pax_force_retaddr
13686 ret;
13687 ENDPROC(camellia_ctr_16way)
13688
13689@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13690 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13691 %xmm8, %rsi);
13692
13693+ pax_force_retaddr
13694 ret;
13695 ENDPROC(camellia_xts_crypt_16way)
13696
13697diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13698index 0e0b886..5a3123c 100644
13699--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13700+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13701@@ -11,6 +11,7 @@
13702 */
13703
13704 #include <linux/linkage.h>
13705+#include <asm/alternative-asm.h>
13706
13707 #define CAMELLIA_TABLE_BYTE_LEN 272
13708
13709@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13710 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13711 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13712 %rcx, (%r9));
13713+ pax_force_retaddr
13714 ret;
13715 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13716
13717@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13718 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13719 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13720 %rax, (%r9));
13721+ pax_force_retaddr
13722 ret;
13723 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13724
13725@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13726 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13727 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13728
13729+ pax_force_retaddr
13730 ret;
13731
13732 .align 8
13733@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13734 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13735 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13736
13737+ pax_force_retaddr
13738 ret;
13739
13740 .align 8
13741@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13742
13743 vzeroupper;
13744
13745+ pax_force_retaddr
13746 ret;
13747 ENDPROC(camellia_ecb_enc_32way)
13748
13749@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13750
13751 vzeroupper;
13752
13753+ pax_force_retaddr
13754 ret;
13755 ENDPROC(camellia_ecb_dec_32way)
13756
13757@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13758
13759 vzeroupper;
13760
13761+ pax_force_retaddr
13762 ret;
13763 ENDPROC(camellia_cbc_dec_32way)
13764
13765@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13766
13767 vzeroupper;
13768
13769+ pax_force_retaddr
13770 ret;
13771 ENDPROC(camellia_ctr_32way)
13772
13773@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13774
13775 vzeroupper;
13776
13777+ pax_force_retaddr
13778 ret;
13779 ENDPROC(camellia_xts_crypt_32way)
13780
13781diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13782index 310319c..db3d7b5 100644
13783--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13784+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13785@@ -21,6 +21,7 @@
13786 */
13787
13788 #include <linux/linkage.h>
13789+#include <asm/alternative-asm.h>
13790
13791 .file "camellia-x86_64-asm_64.S"
13792 .text
13793@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13794 enc_outunpack(mov, RT1);
13795
13796 movq RRBP, %rbp;
13797+ pax_force_retaddr
13798 ret;
13799
13800 .L__enc_xor:
13801 enc_outunpack(xor, RT1);
13802
13803 movq RRBP, %rbp;
13804+ pax_force_retaddr
13805 ret;
13806 ENDPROC(__camellia_enc_blk)
13807
13808@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13809 dec_outunpack();
13810
13811 movq RRBP, %rbp;
13812+ pax_force_retaddr
13813 ret;
13814 ENDPROC(camellia_dec_blk)
13815
13816@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13817
13818 movq RRBP, %rbp;
13819 popq %rbx;
13820+ pax_force_retaddr
13821 ret;
13822
13823 .L__enc2_xor:
13824@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13825
13826 movq RRBP, %rbp;
13827 popq %rbx;
13828+ pax_force_retaddr
13829 ret;
13830 ENDPROC(__camellia_enc_blk_2way)
13831
13832@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13833
13834 movq RRBP, %rbp;
13835 movq RXOR, %rbx;
13836+ pax_force_retaddr
13837 ret;
13838 ENDPROC(camellia_dec_blk_2way)
13839diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13840index c35fd5d..2d8c7db 100644
13841--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13842+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13843@@ -24,6 +24,7 @@
13844 */
13845
13846 #include <linux/linkage.h>
13847+#include <asm/alternative-asm.h>
13848
13849 .file "cast5-avx-x86_64-asm_64.S"
13850
13851@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13852 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13853 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13854
13855+ pax_force_retaddr
13856 ret;
13857 ENDPROC(__cast5_enc_blk16)
13858
13859@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13860 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13861 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13862
13863+ pax_force_retaddr
13864 ret;
13865
13866 .L__skip_dec:
13867@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13868 vmovdqu RR4, (6*4*4)(%r11);
13869 vmovdqu RL4, (7*4*4)(%r11);
13870
13871+ pax_force_retaddr
13872 ret;
13873 ENDPROC(cast5_ecb_enc_16way)
13874
13875@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13876 vmovdqu RR4, (6*4*4)(%r11);
13877 vmovdqu RL4, (7*4*4)(%r11);
13878
13879+ pax_force_retaddr
13880 ret;
13881 ENDPROC(cast5_ecb_dec_16way)
13882
13883@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13884 * %rdx: src
13885 */
13886
13887- pushq %r12;
13888+ pushq %r14;
13889
13890 movq %rsi, %r11;
13891- movq %rdx, %r12;
13892+ movq %rdx, %r14;
13893
13894 vmovdqu (0*16)(%rdx), RL1;
13895 vmovdqu (1*16)(%rdx), RR1;
13896@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13897 call __cast5_dec_blk16;
13898
13899 /* xor with src */
13900- vmovq (%r12), RX;
13901+ vmovq (%r14), RX;
13902 vpshufd $0x4f, RX, RX;
13903 vpxor RX, RR1, RR1;
13904- vpxor 0*16+8(%r12), RL1, RL1;
13905- vpxor 1*16+8(%r12), RR2, RR2;
13906- vpxor 2*16+8(%r12), RL2, RL2;
13907- vpxor 3*16+8(%r12), RR3, RR3;
13908- vpxor 4*16+8(%r12), RL3, RL3;
13909- vpxor 5*16+8(%r12), RR4, RR4;
13910- vpxor 6*16+8(%r12), RL4, RL4;
13911+ vpxor 0*16+8(%r14), RL1, RL1;
13912+ vpxor 1*16+8(%r14), RR2, RR2;
13913+ vpxor 2*16+8(%r14), RL2, RL2;
13914+ vpxor 3*16+8(%r14), RR3, RR3;
13915+ vpxor 4*16+8(%r14), RL3, RL3;
13916+ vpxor 5*16+8(%r14), RR4, RR4;
13917+ vpxor 6*16+8(%r14), RL4, RL4;
13918
13919 vmovdqu RR1, (0*16)(%r11);
13920 vmovdqu RL1, (1*16)(%r11);
13921@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13922 vmovdqu RR4, (6*16)(%r11);
13923 vmovdqu RL4, (7*16)(%r11);
13924
13925- popq %r12;
13926+ popq %r14;
13927
13928+ pax_force_retaddr
13929 ret;
13930 ENDPROC(cast5_cbc_dec_16way)
13931
13932@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13933 * %rcx: iv (big endian, 64bit)
13934 */
13935
13936- pushq %r12;
13937+ pushq %r14;
13938
13939 movq %rsi, %r11;
13940- movq %rdx, %r12;
13941+ movq %rdx, %r14;
13942
13943 vpcmpeqd RTMP, RTMP, RTMP;
13944 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13945@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13946 call __cast5_enc_blk16;
13947
13948 /* dst = src ^ iv */
13949- vpxor (0*16)(%r12), RR1, RR1;
13950- vpxor (1*16)(%r12), RL1, RL1;
13951- vpxor (2*16)(%r12), RR2, RR2;
13952- vpxor (3*16)(%r12), RL2, RL2;
13953- vpxor (4*16)(%r12), RR3, RR3;
13954- vpxor (5*16)(%r12), RL3, RL3;
13955- vpxor (6*16)(%r12), RR4, RR4;
13956- vpxor (7*16)(%r12), RL4, RL4;
13957+ vpxor (0*16)(%r14), RR1, RR1;
13958+ vpxor (1*16)(%r14), RL1, RL1;
13959+ vpxor (2*16)(%r14), RR2, RR2;
13960+ vpxor (3*16)(%r14), RL2, RL2;
13961+ vpxor (4*16)(%r14), RR3, RR3;
13962+ vpxor (5*16)(%r14), RL3, RL3;
13963+ vpxor (6*16)(%r14), RR4, RR4;
13964+ vpxor (7*16)(%r14), RL4, RL4;
13965 vmovdqu RR1, (0*16)(%r11);
13966 vmovdqu RL1, (1*16)(%r11);
13967 vmovdqu RR2, (2*16)(%r11);
13968@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13969 vmovdqu RR4, (6*16)(%r11);
13970 vmovdqu RL4, (7*16)(%r11);
13971
13972- popq %r12;
13973+ popq %r14;
13974
13975+ pax_force_retaddr
13976 ret;
13977 ENDPROC(cast5_ctr_16way)
13978diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13979index e3531f8..e123f35 100644
13980--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13981+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13982@@ -24,6 +24,7 @@
13983 */
13984
13985 #include <linux/linkage.h>
13986+#include <asm/alternative-asm.h>
13987 #include "glue_helper-asm-avx.S"
13988
13989 .file "cast6-avx-x86_64-asm_64.S"
13990@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13991 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13992 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13993
13994+ pax_force_retaddr
13995 ret;
13996 ENDPROC(__cast6_enc_blk8)
13997
13998@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13999 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14000 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14001
14002+ pax_force_retaddr
14003 ret;
14004 ENDPROC(__cast6_dec_blk8)
14005
14006@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
14007
14008 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14009
14010+ pax_force_retaddr
14011 ret;
14012 ENDPROC(cast6_ecb_enc_8way)
14013
14014@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
14015
14016 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14017
14018+ pax_force_retaddr
14019 ret;
14020 ENDPROC(cast6_ecb_dec_8way)
14021
14022@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
14023 * %rdx: src
14024 */
14025
14026- pushq %r12;
14027+ pushq %r14;
14028
14029 movq %rsi, %r11;
14030- movq %rdx, %r12;
14031+ movq %rdx, %r14;
14032
14033 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14034
14035 call __cast6_dec_blk8;
14036
14037- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14038+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14039
14040- popq %r12;
14041+ popq %r14;
14042
14043+ pax_force_retaddr
14044 ret;
14045 ENDPROC(cast6_cbc_dec_8way)
14046
14047@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
14048 * %rcx: iv (little endian, 128bit)
14049 */
14050
14051- pushq %r12;
14052+ pushq %r14;
14053
14054 movq %rsi, %r11;
14055- movq %rdx, %r12;
14056+ movq %rdx, %r14;
14057
14058 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14059 RD2, RX, RKR, RKM);
14060
14061 call __cast6_enc_blk8;
14062
14063- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14064+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14065
14066- popq %r12;
14067+ popq %r14;
14068
14069+ pax_force_retaddr
14070 ret;
14071 ENDPROC(cast6_ctr_8way)
14072
14073@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14074 /* dst <= regs xor IVs(in dst) */
14075 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14076
14077+ pax_force_retaddr
14078 ret;
14079 ENDPROC(cast6_xts_enc_8way)
14080
14081@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14082 /* dst <= regs xor IVs(in dst) */
14083 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14084
14085+ pax_force_retaddr
14086 ret;
14087 ENDPROC(cast6_xts_dec_8way)
14088diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14089index dbc4339..de6e120 100644
14090--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14091+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14092@@ -45,6 +45,7 @@
14093
14094 #include <asm/inst.h>
14095 #include <linux/linkage.h>
14096+#include <asm/alternative-asm.h>
14097
14098 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14099
14100@@ -312,6 +313,7 @@ do_return:
14101 popq %rsi
14102 popq %rdi
14103 popq %rbx
14104+ pax_force_retaddr
14105 ret
14106
14107 ################################################################
14108diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14109index 185fad4..ff4cd36 100644
14110--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14111+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14112@@ -18,6 +18,7 @@
14113
14114 #include <linux/linkage.h>
14115 #include <asm/inst.h>
14116+#include <asm/alternative-asm.h>
14117
14118 .data
14119
14120@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14121 psrlq $1, T2
14122 pxor T2, T1
14123 pxor T1, DATA
14124+ pax_force_retaddr
14125 ret
14126 ENDPROC(__clmul_gf128mul_ble)
14127
14128@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14129 call __clmul_gf128mul_ble
14130 PSHUFB_XMM BSWAP DATA
14131 movups DATA, (%rdi)
14132+ pax_force_retaddr
14133 ret
14134 ENDPROC(clmul_ghash_mul)
14135
14136@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14137 PSHUFB_XMM BSWAP DATA
14138 movups DATA, (%rdi)
14139 .Lupdate_just_ret:
14140+ pax_force_retaddr
14141 ret
14142 ENDPROC(clmul_ghash_update)
14143diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14144index 9279e0b..c4b3d2c 100644
14145--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14146+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14147@@ -1,4 +1,5 @@
14148 #include <linux/linkage.h>
14149+#include <asm/alternative-asm.h>
14150
14151 # enter salsa20_encrypt_bytes
14152 ENTRY(salsa20_encrypt_bytes)
14153@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14154 add %r11,%rsp
14155 mov %rdi,%rax
14156 mov %rsi,%rdx
14157+ pax_force_retaddr
14158 ret
14159 # bytesatleast65:
14160 ._bytesatleast65:
14161@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14162 add %r11,%rsp
14163 mov %rdi,%rax
14164 mov %rsi,%rdx
14165+ pax_force_retaddr
14166 ret
14167 ENDPROC(salsa20_keysetup)
14168
14169@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14170 add %r11,%rsp
14171 mov %rdi,%rax
14172 mov %rsi,%rdx
14173+ pax_force_retaddr
14174 ret
14175 ENDPROC(salsa20_ivsetup)
14176diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14177index 2f202f4..d9164d6 100644
14178--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14179+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14180@@ -24,6 +24,7 @@
14181 */
14182
14183 #include <linux/linkage.h>
14184+#include <asm/alternative-asm.h>
14185 #include "glue_helper-asm-avx.S"
14186
14187 .file "serpent-avx-x86_64-asm_64.S"
14188@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14189 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14190 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14191
14192+ pax_force_retaddr
14193 ret;
14194 ENDPROC(__serpent_enc_blk8_avx)
14195
14196@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14197 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14198 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14199
14200+ pax_force_retaddr
14201 ret;
14202 ENDPROC(__serpent_dec_blk8_avx)
14203
14204@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14205
14206 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14207
14208+ pax_force_retaddr
14209 ret;
14210 ENDPROC(serpent_ecb_enc_8way_avx)
14211
14212@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14213
14214 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14215
14216+ pax_force_retaddr
14217 ret;
14218 ENDPROC(serpent_ecb_dec_8way_avx)
14219
14220@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14221
14222 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14223
14224+ pax_force_retaddr
14225 ret;
14226 ENDPROC(serpent_cbc_dec_8way_avx)
14227
14228@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14229
14230 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14231
14232+ pax_force_retaddr
14233 ret;
14234 ENDPROC(serpent_ctr_8way_avx)
14235
14236@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14237 /* dst <= regs xor IVs(in dst) */
14238 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14239
14240+ pax_force_retaddr
14241 ret;
14242 ENDPROC(serpent_xts_enc_8way_avx)
14243
14244@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14245 /* dst <= regs xor IVs(in dst) */
14246 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14247
14248+ pax_force_retaddr
14249 ret;
14250 ENDPROC(serpent_xts_dec_8way_avx)
14251diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14252index b222085..abd483c 100644
14253--- a/arch/x86/crypto/serpent-avx2-asm_64.S
14254+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14255@@ -15,6 +15,7 @@
14256 */
14257
14258 #include <linux/linkage.h>
14259+#include <asm/alternative-asm.h>
14260 #include "glue_helper-asm-avx2.S"
14261
14262 .file "serpent-avx2-asm_64.S"
14263@@ -610,6 +611,7 @@ __serpent_enc_blk16:
14264 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14265 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14266
14267+ pax_force_retaddr
14268 ret;
14269 ENDPROC(__serpent_enc_blk16)
14270
14271@@ -664,6 +666,7 @@ __serpent_dec_blk16:
14272 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14273 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14274
14275+ pax_force_retaddr
14276 ret;
14277 ENDPROC(__serpent_dec_blk16)
14278
14279@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14280
14281 vzeroupper;
14282
14283+ pax_force_retaddr
14284 ret;
14285 ENDPROC(serpent_ecb_enc_16way)
14286
14287@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14288
14289 vzeroupper;
14290
14291+ pax_force_retaddr
14292 ret;
14293 ENDPROC(serpent_ecb_dec_16way)
14294
14295@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14296
14297 vzeroupper;
14298
14299+ pax_force_retaddr
14300 ret;
14301 ENDPROC(serpent_cbc_dec_16way)
14302
14303@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14304
14305 vzeroupper;
14306
14307+ pax_force_retaddr
14308 ret;
14309 ENDPROC(serpent_ctr_16way)
14310
14311@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14312
14313 vzeroupper;
14314
14315+ pax_force_retaddr
14316 ret;
14317 ENDPROC(serpent_xts_enc_16way)
14318
14319@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14320
14321 vzeroupper;
14322
14323+ pax_force_retaddr
14324 ret;
14325 ENDPROC(serpent_xts_dec_16way)
14326diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14327index acc066c..1559cc4 100644
14328--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14329+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14330@@ -25,6 +25,7 @@
14331 */
14332
14333 #include <linux/linkage.h>
14334+#include <asm/alternative-asm.h>
14335
14336 .file "serpent-sse2-x86_64-asm_64.S"
14337 .text
14338@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14339 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14340 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14341
14342+ pax_force_retaddr
14343 ret;
14344
14345 .L__enc_xor8:
14346 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14347 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14348
14349+ pax_force_retaddr
14350 ret;
14351 ENDPROC(__serpent_enc_blk_8way)
14352
14353@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14354 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14355 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14356
14357+ pax_force_retaddr
14358 ret;
14359 ENDPROC(serpent_dec_blk_8way)
14360diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14361index a410950..9dfe7ad 100644
14362--- a/arch/x86/crypto/sha1_ssse3_asm.S
14363+++ b/arch/x86/crypto/sha1_ssse3_asm.S
14364@@ -29,6 +29,7 @@
14365 */
14366
14367 #include <linux/linkage.h>
14368+#include <asm/alternative-asm.h>
14369
14370 #define CTX %rdi // arg1
14371 #define BUF %rsi // arg2
14372@@ -75,9 +76,9 @@
14373
14374 push %rbx
14375 push %rbp
14376- push %r12
14377+ push %r14
14378
14379- mov %rsp, %r12
14380+ mov %rsp, %r14
14381 sub $64, %rsp # allocate workspace
14382 and $~15, %rsp # align stack
14383
14384@@ -99,11 +100,12 @@
14385 xor %rax, %rax
14386 rep stosq
14387
14388- mov %r12, %rsp # deallocate workspace
14389+ mov %r14, %rsp # deallocate workspace
14390
14391- pop %r12
14392+ pop %r14
14393 pop %rbp
14394 pop %rbx
14395+ pax_force_retaddr
14396 ret
14397
14398 ENDPROC(\name)
14399diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14400index 642f156..51a513c 100644
14401--- a/arch/x86/crypto/sha256-avx-asm.S
14402+++ b/arch/x86/crypto/sha256-avx-asm.S
14403@@ -49,6 +49,7 @@
14404
14405 #ifdef CONFIG_AS_AVX
14406 #include <linux/linkage.h>
14407+#include <asm/alternative-asm.h>
14408
14409 ## assume buffers not aligned
14410 #define VMOVDQ vmovdqu
14411@@ -460,6 +461,7 @@ done_hash:
14412 popq %r13
14413 popq %rbp
14414 popq %rbx
14415+ pax_force_retaddr
14416 ret
14417 ENDPROC(sha256_transform_avx)
14418
14419diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14420index 9e86944..3795e6a 100644
14421--- a/arch/x86/crypto/sha256-avx2-asm.S
14422+++ b/arch/x86/crypto/sha256-avx2-asm.S
14423@@ -50,6 +50,7 @@
14424
14425 #ifdef CONFIG_AS_AVX2
14426 #include <linux/linkage.h>
14427+#include <asm/alternative-asm.h>
14428
14429 ## assume buffers not aligned
14430 #define VMOVDQ vmovdqu
14431@@ -720,6 +721,7 @@ done_hash:
14432 popq %r12
14433 popq %rbp
14434 popq %rbx
14435+ pax_force_retaddr
14436 ret
14437 ENDPROC(sha256_transform_rorx)
14438
14439diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14440index f833b74..8c62a9e 100644
14441--- a/arch/x86/crypto/sha256-ssse3-asm.S
14442+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14443@@ -47,6 +47,7 @@
14444 ########################################################################
14445
14446 #include <linux/linkage.h>
14447+#include <asm/alternative-asm.h>
14448
14449 ## assume buffers not aligned
14450 #define MOVDQ movdqu
14451@@ -471,6 +472,7 @@ done_hash:
14452 popq %rbp
14453 popq %rbx
14454
14455+ pax_force_retaddr
14456 ret
14457 ENDPROC(sha256_transform_ssse3)
14458
14459diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14460index 974dde9..a823ff9 100644
14461--- a/arch/x86/crypto/sha512-avx-asm.S
14462+++ b/arch/x86/crypto/sha512-avx-asm.S
14463@@ -49,6 +49,7 @@
14464
14465 #ifdef CONFIG_AS_AVX
14466 #include <linux/linkage.h>
14467+#include <asm/alternative-asm.h>
14468
14469 .text
14470
14471@@ -364,6 +365,7 @@ updateblock:
14472 mov frame_RSPSAVE(%rsp), %rsp
14473
14474 nowork:
14475+ pax_force_retaddr
14476 ret
14477 ENDPROC(sha512_transform_avx)
14478
14479diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14480index 568b961..ed20c37 100644
14481--- a/arch/x86/crypto/sha512-avx2-asm.S
14482+++ b/arch/x86/crypto/sha512-avx2-asm.S
14483@@ -51,6 +51,7 @@
14484
14485 #ifdef CONFIG_AS_AVX2
14486 #include <linux/linkage.h>
14487+#include <asm/alternative-asm.h>
14488
14489 .text
14490
14491@@ -678,6 +679,7 @@ done_hash:
14492
14493 # Restore Stack Pointer
14494 mov frame_RSPSAVE(%rsp), %rsp
14495+ pax_force_retaddr
14496 ret
14497 ENDPROC(sha512_transform_rorx)
14498
14499diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14500index fb56855..6edd768 100644
14501--- a/arch/x86/crypto/sha512-ssse3-asm.S
14502+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14503@@ -48,6 +48,7 @@
14504 ########################################################################
14505
14506 #include <linux/linkage.h>
14507+#include <asm/alternative-asm.h>
14508
14509 .text
14510
14511@@ -363,6 +364,7 @@ updateblock:
14512 mov frame_RSPSAVE(%rsp), %rsp
14513
14514 nowork:
14515+ pax_force_retaddr
14516 ret
14517 ENDPROC(sha512_transform_ssse3)
14518
14519diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14520index 0505813..b067311 100644
14521--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14522+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14523@@ -24,6 +24,7 @@
14524 */
14525
14526 #include <linux/linkage.h>
14527+#include <asm/alternative-asm.h>
14528 #include "glue_helper-asm-avx.S"
14529
14530 .file "twofish-avx-x86_64-asm_64.S"
14531@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14532 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14533 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14534
14535+ pax_force_retaddr
14536 ret;
14537 ENDPROC(__twofish_enc_blk8)
14538
14539@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14540 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14541 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14542
14543+ pax_force_retaddr
14544 ret;
14545 ENDPROC(__twofish_dec_blk8)
14546
14547@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14548
14549 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14550
14551+ pax_force_retaddr
14552 ret;
14553 ENDPROC(twofish_ecb_enc_8way)
14554
14555@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14556
14557 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14558
14559+ pax_force_retaddr
14560 ret;
14561 ENDPROC(twofish_ecb_dec_8way)
14562
14563@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14564 * %rdx: src
14565 */
14566
14567- pushq %r12;
14568+ pushq %r14;
14569
14570 movq %rsi, %r11;
14571- movq %rdx, %r12;
14572+ movq %rdx, %r14;
14573
14574 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14575
14576 call __twofish_dec_blk8;
14577
14578- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14579+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14580
14581- popq %r12;
14582+ popq %r14;
14583
14584+ pax_force_retaddr
14585 ret;
14586 ENDPROC(twofish_cbc_dec_8way)
14587
14588@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14589 * %rcx: iv (little endian, 128bit)
14590 */
14591
14592- pushq %r12;
14593+ pushq %r14;
14594
14595 movq %rsi, %r11;
14596- movq %rdx, %r12;
14597+ movq %rdx, %r14;
14598
14599 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14600 RD2, RX0, RX1, RY0);
14601
14602 call __twofish_enc_blk8;
14603
14604- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14605+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14606
14607- popq %r12;
14608+ popq %r14;
14609
14610+ pax_force_retaddr
14611 ret;
14612 ENDPROC(twofish_ctr_8way)
14613
14614@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14615 /* dst <= regs xor IVs(in dst) */
14616 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14617
14618+ pax_force_retaddr
14619 ret;
14620 ENDPROC(twofish_xts_enc_8way)
14621
14622@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14623 /* dst <= regs xor IVs(in dst) */
14624 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14625
14626+ pax_force_retaddr
14627 ret;
14628 ENDPROC(twofish_xts_dec_8way)
14629diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14630index 1c3b7ce..02f578d 100644
14631--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14632+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14633@@ -21,6 +21,7 @@
14634 */
14635
14636 #include <linux/linkage.h>
14637+#include <asm/alternative-asm.h>
14638
14639 .file "twofish-x86_64-asm-3way.S"
14640 .text
14641@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14642 popq %r13;
14643 popq %r14;
14644 popq %r15;
14645+ pax_force_retaddr
14646 ret;
14647
14648 .L__enc_xor3:
14649@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14650 popq %r13;
14651 popq %r14;
14652 popq %r15;
14653+ pax_force_retaddr
14654 ret;
14655 ENDPROC(__twofish_enc_blk_3way)
14656
14657@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14658 popq %r13;
14659 popq %r14;
14660 popq %r15;
14661+ pax_force_retaddr
14662 ret;
14663 ENDPROC(twofish_dec_blk_3way)
14664diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14665index a039d21..524b8b2 100644
14666--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14667+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14668@@ -22,6 +22,7 @@
14669
14670 #include <linux/linkage.h>
14671 #include <asm/asm-offsets.h>
14672+#include <asm/alternative-asm.h>
14673
14674 #define a_offset 0
14675 #define b_offset 4
14676@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14677
14678 popq R1
14679 movq $1,%rax
14680+ pax_force_retaddr
14681 ret
14682 ENDPROC(twofish_enc_blk)
14683
14684@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14685
14686 popq R1
14687 movq $1,%rax
14688+ pax_force_retaddr
14689 ret
14690 ENDPROC(twofish_dec_blk)
14691diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14692index d21ff89..6da8e6e 100644
14693--- a/arch/x86/ia32/ia32_aout.c
14694+++ b/arch/x86/ia32/ia32_aout.c
14695@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14696 unsigned long dump_start, dump_size;
14697 struct user32 dump;
14698
14699+ memset(&dump, 0, sizeof(dump));
14700+
14701 fs = get_fs();
14702 set_fs(KERNEL_DS);
14703 has_dumped = 1;
14704diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14705index 2206757..85cbcfa 100644
14706--- a/arch/x86/ia32/ia32_signal.c
14707+++ b/arch/x86/ia32/ia32_signal.c
14708@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14709 if (__get_user(set.sig[0], &frame->sc.oldmask)
14710 || (_COMPAT_NSIG_WORDS > 1
14711 && __copy_from_user((((char *) &set.sig) + 4),
14712- &frame->extramask,
14713+ frame->extramask,
14714 sizeof(frame->extramask))))
14715 goto badframe;
14716
14717@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14718 sp -= frame_size;
14719 /* Align the stack pointer according to the i386 ABI,
14720 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14721- sp = ((sp + 4) & -16ul) - 4;
14722+ sp = ((sp - 12) & -16ul) - 4;
14723 return (void __user *) sp;
14724 }
14725
14726@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14727 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14728 sigreturn);
14729 else
14730- restorer = &frame->retcode;
14731+ restorer = frame->retcode;
14732 }
14733
14734 put_user_try {
14735@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14736 * These are actually not used anymore, but left because some
14737 * gdb versions depend on them as a marker.
14738 */
14739- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14740+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14741 } put_user_catch(err);
14742
14743 if (err)
14744@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14745 0xb8,
14746 __NR_ia32_rt_sigreturn,
14747 0x80cd,
14748- 0,
14749+ 0
14750 };
14751
14752 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14753@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14754
14755 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14756 restorer = ksig->ka.sa.sa_restorer;
14757+ else if (current->mm->context.vdso)
14758+ /* Return stub is in 32bit vsyscall page */
14759+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14760 else
14761- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14762- rt_sigreturn);
14763+ restorer = frame->retcode;
14764 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14765
14766 /*
14767 * Not actually used anymore, but left because some gdb
14768 * versions need it.
14769 */
14770- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14771+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14772 } put_user_catch(err);
14773
14774 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14775diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14776index 4299eb0..c0687a7 100644
14777--- a/arch/x86/ia32/ia32entry.S
14778+++ b/arch/x86/ia32/ia32entry.S
14779@@ -15,8 +15,10 @@
14780 #include <asm/irqflags.h>
14781 #include <asm/asm.h>
14782 #include <asm/smap.h>
14783+#include <asm/pgtable.h>
14784 #include <linux/linkage.h>
14785 #include <linux/err.h>
14786+#include <asm/alternative-asm.h>
14787
14788 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14789 #include <linux/elf-em.h>
14790@@ -62,12 +64,12 @@
14791 */
14792 .macro LOAD_ARGS32 offset, _r9=0
14793 .if \_r9
14794- movl \offset+16(%rsp),%r9d
14795+ movl \offset+R9(%rsp),%r9d
14796 .endif
14797- movl \offset+40(%rsp),%ecx
14798- movl \offset+48(%rsp),%edx
14799- movl \offset+56(%rsp),%esi
14800- movl \offset+64(%rsp),%edi
14801+ movl \offset+RCX(%rsp),%ecx
14802+ movl \offset+RDX(%rsp),%edx
14803+ movl \offset+RSI(%rsp),%esi
14804+ movl \offset+RDI(%rsp),%edi
14805 movl %eax,%eax /* zero extension */
14806 .endm
14807
14808@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14809 ENDPROC(native_irq_enable_sysexit)
14810 #endif
14811
14812+ .macro pax_enter_kernel_user
14813+ pax_set_fptr_mask
14814+#ifdef CONFIG_PAX_MEMORY_UDEREF
14815+ call pax_enter_kernel_user
14816+#endif
14817+ .endm
14818+
14819+ .macro pax_exit_kernel_user
14820+#ifdef CONFIG_PAX_MEMORY_UDEREF
14821+ call pax_exit_kernel_user
14822+#endif
14823+#ifdef CONFIG_PAX_RANDKSTACK
14824+ pushq %rax
14825+ pushq %r11
14826+ call pax_randomize_kstack
14827+ popq %r11
14828+ popq %rax
14829+#endif
14830+ .endm
14831+
14832+ .macro pax_erase_kstack
14833+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14834+ call pax_erase_kstack
14835+#endif
14836+ .endm
14837+
14838 /*
14839 * 32bit SYSENTER instruction entry.
14840 *
14841@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14842 CFI_REGISTER rsp,rbp
14843 SWAPGS_UNSAFE_STACK
14844 movq PER_CPU_VAR(kernel_stack), %rsp
14845- addq $(KERNEL_STACK_OFFSET),%rsp
14846- /*
14847- * No need to follow this irqs on/off section: the syscall
14848- * disabled irqs, here we enable it straight after entry:
14849- */
14850- ENABLE_INTERRUPTS(CLBR_NONE)
14851 movl %ebp,%ebp /* zero extension */
14852 pushq_cfi $__USER32_DS
14853 /*CFI_REL_OFFSET ss,0*/
14854@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14855 CFI_REL_OFFSET rsp,0
14856 pushfq_cfi
14857 /*CFI_REL_OFFSET rflags,0*/
14858- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14859- CFI_REGISTER rip,r10
14860+ orl $X86_EFLAGS_IF,(%rsp)
14861+ GET_THREAD_INFO(%r11)
14862+ movl TI_sysenter_return(%r11), %r11d
14863+ CFI_REGISTER rip,r11
14864 pushq_cfi $__USER32_CS
14865 /*CFI_REL_OFFSET cs,0*/
14866 movl %eax, %eax
14867- pushq_cfi %r10
14868+ pushq_cfi %r11
14869 CFI_REL_OFFSET rip,0
14870 pushq_cfi %rax
14871 cld
14872 SAVE_ARGS 0,1,0
14873+ pax_enter_kernel_user
14874+
14875+#ifdef CONFIG_PAX_RANDKSTACK
14876+ pax_erase_kstack
14877+#endif
14878+
14879+ /*
14880+ * No need to follow this irqs on/off section: the syscall
14881+ * disabled irqs, here we enable it straight after entry:
14882+ */
14883+ ENABLE_INTERRUPTS(CLBR_NONE)
14884 /* no need to do an access_ok check here because rbp has been
14885 32bit zero extended */
14886+
14887+#ifdef CONFIG_PAX_MEMORY_UDEREF
14888+ addq pax_user_shadow_base,%rbp
14889+ ASM_PAX_OPEN_USERLAND
14890+#endif
14891+
14892 ASM_STAC
14893 1: movl (%rbp),%ebp
14894 _ASM_EXTABLE(1b,ia32_badarg)
14895 ASM_CLAC
14896- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14897- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14898+
14899+#ifdef CONFIG_PAX_MEMORY_UDEREF
14900+ ASM_PAX_CLOSE_USERLAND
14901+#endif
14902+
14903+ GET_THREAD_INFO(%r11)
14904+ orl $TS_COMPAT,TI_status(%r11)
14905+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14906 CFI_REMEMBER_STATE
14907 jnz sysenter_tracesys
14908 cmpq $(IA32_NR_syscalls-1),%rax
14909@@ -162,15 +209,18 @@ sysenter_do_call:
14910 sysenter_dispatch:
14911 call *ia32_sys_call_table(,%rax,8)
14912 movq %rax,RAX-ARGOFFSET(%rsp)
14913+ GET_THREAD_INFO(%r11)
14914 DISABLE_INTERRUPTS(CLBR_NONE)
14915 TRACE_IRQS_OFF
14916- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14917+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14918 jnz sysexit_audit
14919 sysexit_from_sys_call:
14920- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14921+ pax_exit_kernel_user
14922+ pax_erase_kstack
14923+ andl $~TS_COMPAT,TI_status(%r11)
14924 /* clear IF, that popfq doesn't enable interrupts early */
14925- andl $~0x200,EFLAGS-R11(%rsp)
14926- movl RIP-R11(%rsp),%edx /* User %eip */
14927+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14928+ movl RIP(%rsp),%edx /* User %eip */
14929 CFI_REGISTER rip,rdx
14930 RESTORE_ARGS 0,24,0,0,0,0
14931 xorq %r8,%r8
14932@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14933 movl %eax,%esi /* 2nd arg: syscall number */
14934 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14935 call __audit_syscall_entry
14936+
14937+ pax_erase_kstack
14938+
14939 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14940 cmpq $(IA32_NR_syscalls-1),%rax
14941 ja ia32_badsys
14942@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14943 .endm
14944
14945 .macro auditsys_exit exit
14946- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14947+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14948 jnz ia32_ret_from_sys_call
14949 TRACE_IRQS_ON
14950 ENABLE_INTERRUPTS(CLBR_NONE)
14951@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14952 1: setbe %al /* 1 if error, 0 if not */
14953 movzbl %al,%edi /* zero-extend that into %edi */
14954 call __audit_syscall_exit
14955+ GET_THREAD_INFO(%r11)
14956 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14957 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14958 DISABLE_INTERRUPTS(CLBR_NONE)
14959 TRACE_IRQS_OFF
14960- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14961+ testl %edi,TI_flags(%r11)
14962 jz \exit
14963 CLEAR_RREGS -ARGOFFSET
14964 jmp int_with_check
14965@@ -237,7 +291,7 @@ sysexit_audit:
14966
14967 sysenter_tracesys:
14968 #ifdef CONFIG_AUDITSYSCALL
14969- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14970+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14971 jz sysenter_auditsys
14972 #endif
14973 SAVE_REST
14974@@ -249,6 +303,9 @@ sysenter_tracesys:
14975 RESTORE_REST
14976 cmpq $(IA32_NR_syscalls-1),%rax
14977 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14978+
14979+ pax_erase_kstack
14980+
14981 jmp sysenter_do_call
14982 CFI_ENDPROC
14983 ENDPROC(ia32_sysenter_target)
14984@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14985 ENTRY(ia32_cstar_target)
14986 CFI_STARTPROC32 simple
14987 CFI_SIGNAL_FRAME
14988- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14989+ CFI_DEF_CFA rsp,0
14990 CFI_REGISTER rip,rcx
14991 /*CFI_REGISTER rflags,r11*/
14992 SWAPGS_UNSAFE_STACK
14993 movl %esp,%r8d
14994 CFI_REGISTER rsp,r8
14995 movq PER_CPU_VAR(kernel_stack),%rsp
14996+ SAVE_ARGS 8*6,0,0
14997+ pax_enter_kernel_user
14998+
14999+#ifdef CONFIG_PAX_RANDKSTACK
15000+ pax_erase_kstack
15001+#endif
15002+
15003 /*
15004 * No need to follow this irqs on/off section: the syscall
15005 * disabled irqs and here we enable it straight after entry:
15006 */
15007 ENABLE_INTERRUPTS(CLBR_NONE)
15008- SAVE_ARGS 8,0,0
15009 movl %eax,%eax /* zero extension */
15010 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15011 movq %rcx,RIP-ARGOFFSET(%rsp)
15012@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
15013 /* no need to do an access_ok check here because r8 has been
15014 32bit zero extended */
15015 /* hardware stack frame is complete now */
15016+
15017+#ifdef CONFIG_PAX_MEMORY_UDEREF
15018+ ASM_PAX_OPEN_USERLAND
15019+ movq pax_user_shadow_base,%r8
15020+ addq RSP-ARGOFFSET(%rsp),%r8
15021+#endif
15022+
15023 ASM_STAC
15024 1: movl (%r8),%r9d
15025 _ASM_EXTABLE(1b,ia32_badarg)
15026 ASM_CLAC
15027- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15028- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15029+
15030+#ifdef CONFIG_PAX_MEMORY_UDEREF
15031+ ASM_PAX_CLOSE_USERLAND
15032+#endif
15033+
15034+ GET_THREAD_INFO(%r11)
15035+ orl $TS_COMPAT,TI_status(%r11)
15036+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15037 CFI_REMEMBER_STATE
15038 jnz cstar_tracesys
15039 cmpq $IA32_NR_syscalls-1,%rax
15040@@ -319,13 +395,16 @@ cstar_do_call:
15041 cstar_dispatch:
15042 call *ia32_sys_call_table(,%rax,8)
15043 movq %rax,RAX-ARGOFFSET(%rsp)
15044+ GET_THREAD_INFO(%r11)
15045 DISABLE_INTERRUPTS(CLBR_NONE)
15046 TRACE_IRQS_OFF
15047- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15048+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15049 jnz sysretl_audit
15050 sysretl_from_sys_call:
15051- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15052- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15053+ pax_exit_kernel_user
15054+ pax_erase_kstack
15055+ andl $~TS_COMPAT,TI_status(%r11)
15056+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15057 movl RIP-ARGOFFSET(%rsp),%ecx
15058 CFI_REGISTER rip,rcx
15059 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15060@@ -352,7 +431,7 @@ sysretl_audit:
15061
15062 cstar_tracesys:
15063 #ifdef CONFIG_AUDITSYSCALL
15064- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15065+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15066 jz cstar_auditsys
15067 #endif
15068 xchgl %r9d,%ebp
15069@@ -366,11 +445,19 @@ cstar_tracesys:
15070 xchgl %ebp,%r9d
15071 cmpq $(IA32_NR_syscalls-1),%rax
15072 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15073+
15074+ pax_erase_kstack
15075+
15076 jmp cstar_do_call
15077 END(ia32_cstar_target)
15078
15079 ia32_badarg:
15080 ASM_CLAC
15081+
15082+#ifdef CONFIG_PAX_MEMORY_UDEREF
15083+ ASM_PAX_CLOSE_USERLAND
15084+#endif
15085+
15086 movq $-EFAULT,%rax
15087 jmp ia32_sysret
15088 CFI_ENDPROC
15089@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
15090 CFI_REL_OFFSET rip,RIP-RIP
15091 PARAVIRT_ADJUST_EXCEPTION_FRAME
15092 SWAPGS
15093- /*
15094- * No need to follow this irqs on/off section: the syscall
15095- * disabled irqs and here we enable it straight after entry:
15096- */
15097- ENABLE_INTERRUPTS(CLBR_NONE)
15098 movl %eax,%eax
15099 pushq_cfi %rax
15100 cld
15101 /* note the registers are not zero extended to the sf.
15102 this could be a problem. */
15103 SAVE_ARGS 0,1,0
15104- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15105- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15106+ pax_enter_kernel_user
15107+
15108+#ifdef CONFIG_PAX_RANDKSTACK
15109+ pax_erase_kstack
15110+#endif
15111+
15112+ /*
15113+ * No need to follow this irqs on/off section: the syscall
15114+ * disabled irqs and here we enable it straight after entry:
15115+ */
15116+ ENABLE_INTERRUPTS(CLBR_NONE)
15117+ GET_THREAD_INFO(%r11)
15118+ orl $TS_COMPAT,TI_status(%r11)
15119+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15120 jnz ia32_tracesys
15121 cmpq $(IA32_NR_syscalls-1),%rax
15122 ja ia32_badsys
15123@@ -442,6 +536,9 @@ ia32_tracesys:
15124 RESTORE_REST
15125 cmpq $(IA32_NR_syscalls-1),%rax
15126 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15127+
15128+ pax_erase_kstack
15129+
15130 jmp ia32_do_call
15131 END(ia32_syscall)
15132
15133diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15134index 8e0ceec..af13504 100644
15135--- a/arch/x86/ia32/sys_ia32.c
15136+++ b/arch/x86/ia32/sys_ia32.c
15137@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15138 */
15139 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15140 {
15141- typeof(ubuf->st_uid) uid = 0;
15142- typeof(ubuf->st_gid) gid = 0;
15143+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
15144+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
15145 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15146 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15147 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15148diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15149index 372231c..51b537d 100644
15150--- a/arch/x86/include/asm/alternative-asm.h
15151+++ b/arch/x86/include/asm/alternative-asm.h
15152@@ -18,6 +18,45 @@
15153 .endm
15154 #endif
15155
15156+#ifdef KERNEXEC_PLUGIN
15157+ .macro pax_force_retaddr_bts rip=0
15158+ btsq $63,\rip(%rsp)
15159+ .endm
15160+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15161+ .macro pax_force_retaddr rip=0, reload=0
15162+ btsq $63,\rip(%rsp)
15163+ .endm
15164+ .macro pax_force_fptr ptr
15165+ btsq $63,\ptr
15166+ .endm
15167+ .macro pax_set_fptr_mask
15168+ .endm
15169+#endif
15170+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15171+ .macro pax_force_retaddr rip=0, reload=0
15172+ .if \reload
15173+ pax_set_fptr_mask
15174+ .endif
15175+ orq %r12,\rip(%rsp)
15176+ .endm
15177+ .macro pax_force_fptr ptr
15178+ orq %r12,\ptr
15179+ .endm
15180+ .macro pax_set_fptr_mask
15181+ movabs $0x8000000000000000,%r12
15182+ .endm
15183+#endif
15184+#else
15185+ .macro pax_force_retaddr rip=0, reload=0
15186+ .endm
15187+ .macro pax_force_fptr ptr
15188+ .endm
15189+ .macro pax_force_retaddr_bts rip=0
15190+ .endm
15191+ .macro pax_set_fptr_mask
15192+ .endm
15193+#endif
15194+
15195 .macro altinstruction_entry orig alt feature orig_len alt_len
15196 .long \orig - .
15197 .long \alt - .
15198diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15199index 0a3f9c9..c9d081d 100644
15200--- a/arch/x86/include/asm/alternative.h
15201+++ b/arch/x86/include/asm/alternative.h
15202@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15203 ".pushsection .discard,\"aw\",@progbits\n" \
15204 DISCARD_ENTRY(1) \
15205 ".popsection\n" \
15206- ".pushsection .altinstr_replacement, \"ax\"\n" \
15207+ ".pushsection .altinstr_replacement, \"a\"\n" \
15208 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15209 ".popsection"
15210
15211@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15212 DISCARD_ENTRY(1) \
15213 DISCARD_ENTRY(2) \
15214 ".popsection\n" \
15215- ".pushsection .altinstr_replacement, \"ax\"\n" \
15216+ ".pushsection .altinstr_replacement, \"a\"\n" \
15217 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15218 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15219 ".popsection"
15220diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15221index 1d2091a..f5074c1 100644
15222--- a/arch/x86/include/asm/apic.h
15223+++ b/arch/x86/include/asm/apic.h
15224@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15225
15226 #ifdef CONFIG_X86_LOCAL_APIC
15227
15228-extern unsigned int apic_verbosity;
15229+extern int apic_verbosity;
15230 extern int local_apic_timer_c2_ok;
15231
15232 extern int disable_apic;
15233diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15234index 20370c6..a2eb9b0 100644
15235--- a/arch/x86/include/asm/apm.h
15236+++ b/arch/x86/include/asm/apm.h
15237@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15238 __asm__ __volatile__(APM_DO_ZERO_SEGS
15239 "pushl %%edi\n\t"
15240 "pushl %%ebp\n\t"
15241- "lcall *%%cs:apm_bios_entry\n\t"
15242+ "lcall *%%ss:apm_bios_entry\n\t"
15243 "setc %%al\n\t"
15244 "popl %%ebp\n\t"
15245 "popl %%edi\n\t"
15246@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15247 __asm__ __volatile__(APM_DO_ZERO_SEGS
15248 "pushl %%edi\n\t"
15249 "pushl %%ebp\n\t"
15250- "lcall *%%cs:apm_bios_entry\n\t"
15251+ "lcall *%%ss:apm_bios_entry\n\t"
15252 "setc %%bl\n\t"
15253 "popl %%ebp\n\t"
15254 "popl %%edi\n\t"
15255diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15256index b17f4f4..9620151 100644
15257--- a/arch/x86/include/asm/atomic.h
15258+++ b/arch/x86/include/asm/atomic.h
15259@@ -23,7 +23,18 @@
15260 */
15261 static inline int atomic_read(const atomic_t *v)
15262 {
15263- return (*(volatile int *)&(v)->counter);
15264+ return (*(volatile const int *)&(v)->counter);
15265+}
15266+
15267+/**
15268+ * atomic_read_unchecked - read atomic variable
15269+ * @v: pointer of type atomic_unchecked_t
15270+ *
15271+ * Atomically reads the value of @v.
15272+ */
15273+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15274+{
15275+ return (*(volatile const int *)&(v)->counter);
15276 }
15277
15278 /**
15279@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
15280 }
15281
15282 /**
15283+ * atomic_set_unchecked - set atomic variable
15284+ * @v: pointer of type atomic_unchecked_t
15285+ * @i: required value
15286+ *
15287+ * Atomically sets the value of @v to @i.
15288+ */
15289+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15290+{
15291+ v->counter = i;
15292+}
15293+
15294+/**
15295 * atomic_add - add integer to atomic variable
15296 * @i: integer value to add
15297 * @v: pointer of type atomic_t
15298@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
15299 */
15300 static inline void atomic_add(int i, atomic_t *v)
15301 {
15302- asm volatile(LOCK_PREFIX "addl %1,%0"
15303+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15304+
15305+#ifdef CONFIG_PAX_REFCOUNT
15306+ "jno 0f\n"
15307+ LOCK_PREFIX "subl %1,%0\n"
15308+ "int $4\n0:\n"
15309+ _ASM_EXTABLE(0b, 0b)
15310+#endif
15311+
15312+ : "+m" (v->counter)
15313+ : "ir" (i));
15314+}
15315+
15316+/**
15317+ * atomic_add_unchecked - add integer to atomic variable
15318+ * @i: integer value to add
15319+ * @v: pointer of type atomic_unchecked_t
15320+ *
15321+ * Atomically adds @i to @v.
15322+ */
15323+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15324+{
15325+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15326 : "+m" (v->counter)
15327 : "ir" (i));
15328 }
15329@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
15330 */
15331 static inline void atomic_sub(int i, atomic_t *v)
15332 {
15333- asm volatile(LOCK_PREFIX "subl %1,%0"
15334+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15335+
15336+#ifdef CONFIG_PAX_REFCOUNT
15337+ "jno 0f\n"
15338+ LOCK_PREFIX "addl %1,%0\n"
15339+ "int $4\n0:\n"
15340+ _ASM_EXTABLE(0b, 0b)
15341+#endif
15342+
15343+ : "+m" (v->counter)
15344+ : "ir" (i));
15345+}
15346+
15347+/**
15348+ * atomic_sub_unchecked - subtract integer from atomic variable
15349+ * @i: integer value to subtract
15350+ * @v: pointer of type atomic_unchecked_t
15351+ *
15352+ * Atomically subtracts @i from @v.
15353+ */
15354+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15355+{
15356+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15357 : "+m" (v->counter)
15358 : "ir" (i));
15359 }
15360@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15361 */
15362 static inline int atomic_sub_and_test(int i, atomic_t *v)
15363 {
15364- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15365+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15366 }
15367
15368 /**
15369@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15370 */
15371 static inline void atomic_inc(atomic_t *v)
15372 {
15373- asm volatile(LOCK_PREFIX "incl %0"
15374+ asm volatile(LOCK_PREFIX "incl %0\n"
15375+
15376+#ifdef CONFIG_PAX_REFCOUNT
15377+ "jno 0f\n"
15378+ LOCK_PREFIX "decl %0\n"
15379+ "int $4\n0:\n"
15380+ _ASM_EXTABLE(0b, 0b)
15381+#endif
15382+
15383+ : "+m" (v->counter));
15384+}
15385+
15386+/**
15387+ * atomic_inc_unchecked - increment atomic variable
15388+ * @v: pointer of type atomic_unchecked_t
15389+ *
15390+ * Atomically increments @v by 1.
15391+ */
15392+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15393+{
15394+ asm volatile(LOCK_PREFIX "incl %0\n"
15395 : "+m" (v->counter));
15396 }
15397
15398@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15399 */
15400 static inline void atomic_dec(atomic_t *v)
15401 {
15402- asm volatile(LOCK_PREFIX "decl %0"
15403+ asm volatile(LOCK_PREFIX "decl %0\n"
15404+
15405+#ifdef CONFIG_PAX_REFCOUNT
15406+ "jno 0f\n"
15407+ LOCK_PREFIX "incl %0\n"
15408+ "int $4\n0:\n"
15409+ _ASM_EXTABLE(0b, 0b)
15410+#endif
15411+
15412+ : "+m" (v->counter));
15413+}
15414+
15415+/**
15416+ * atomic_dec_unchecked - decrement atomic variable
15417+ * @v: pointer of type atomic_unchecked_t
15418+ *
15419+ * Atomically decrements @v by 1.
15420+ */
15421+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15422+{
15423+ asm volatile(LOCK_PREFIX "decl %0\n"
15424 : "+m" (v->counter));
15425 }
15426
15427@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15428 */
15429 static inline int atomic_dec_and_test(atomic_t *v)
15430 {
15431- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15432+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15433 }
15434
15435 /**
15436@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15437 */
15438 static inline int atomic_inc_and_test(atomic_t *v)
15439 {
15440- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15441+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15442+}
15443+
15444+/**
15445+ * atomic_inc_and_test_unchecked - increment and test
15446+ * @v: pointer of type atomic_unchecked_t
15447+ *
15448+ * Atomically increments @v by 1
15449+ * and returns true if the result is zero, or false for all
15450+ * other cases.
15451+ */
15452+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15453+{
15454+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15455 }
15456
15457 /**
15458@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15459 */
15460 static inline int atomic_add_negative(int i, atomic_t *v)
15461 {
15462- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15463+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15464 }
15465
15466 /**
15467@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15468 */
15469 static inline int atomic_add_return(int i, atomic_t *v)
15470 {
15471+ return i + xadd_check_overflow(&v->counter, i);
15472+}
15473+
15474+/**
15475+ * atomic_add_return_unchecked - add integer and return
15476+ * @i: integer value to add
15477+ * @v: pointer of type atomic_unchecked_t
15478+ *
15479+ * Atomically adds @i to @v and returns @i + @v
15480+ */
15481+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15482+{
15483 return i + xadd(&v->counter, i);
15484 }
15485
15486@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15487 }
15488
15489 #define atomic_inc_return(v) (atomic_add_return(1, v))
15490+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15491+{
15492+ return atomic_add_return_unchecked(1, v);
15493+}
15494 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15495
15496-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15497+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15498+{
15499+ return cmpxchg(&v->counter, old, new);
15500+}
15501+
15502+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15503 {
15504 return cmpxchg(&v->counter, old, new);
15505 }
15506@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15507 return xchg(&v->counter, new);
15508 }
15509
15510+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15511+{
15512+ return xchg(&v->counter, new);
15513+}
15514+
15515 /**
15516 * __atomic_add_unless - add unless the number is already a given value
15517 * @v: pointer of type atomic_t
15518@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15519 * Atomically adds @a to @v, so long as @v was not already @u.
15520 * Returns the old value of @v.
15521 */
15522-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15523+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15524 {
15525- int c, old;
15526+ int c, old, new;
15527 c = atomic_read(v);
15528 for (;;) {
15529- if (unlikely(c == (u)))
15530+ if (unlikely(c == u))
15531 break;
15532- old = atomic_cmpxchg((v), c, c + (a));
15533+
15534+ asm volatile("addl %2,%0\n"
15535+
15536+#ifdef CONFIG_PAX_REFCOUNT
15537+ "jno 0f\n"
15538+ "subl %2,%0\n"
15539+ "int $4\n0:\n"
15540+ _ASM_EXTABLE(0b, 0b)
15541+#endif
15542+
15543+ : "=r" (new)
15544+ : "0" (c), "ir" (a));
15545+
15546+ old = atomic_cmpxchg(v, c, new);
15547 if (likely(old == c))
15548 break;
15549 c = old;
15550@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15551 }
15552
15553 /**
15554+ * atomic_inc_not_zero_hint - increment if not null
15555+ * @v: pointer of type atomic_t
15556+ * @hint: probable value of the atomic before the increment
15557+ *
15558+ * This version of atomic_inc_not_zero() gives a hint of probable
15559+ * value of the atomic. This helps processor to not read the memory
15560+ * before doing the atomic read/modify/write cycle, lowering
15561+ * number of bus transactions on some arches.
15562+ *
15563+ * Returns: 0 if increment was not done, 1 otherwise.
15564+ */
15565+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15566+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15567+{
15568+ int val, c = hint, new;
15569+
15570+ /* sanity test, should be removed by compiler if hint is a constant */
15571+ if (!hint)
15572+ return __atomic_add_unless(v, 1, 0);
15573+
15574+ do {
15575+ asm volatile("incl %0\n"
15576+
15577+#ifdef CONFIG_PAX_REFCOUNT
15578+ "jno 0f\n"
15579+ "decl %0\n"
15580+ "int $4\n0:\n"
15581+ _ASM_EXTABLE(0b, 0b)
15582+#endif
15583+
15584+ : "=r" (new)
15585+ : "0" (c));
15586+
15587+ val = atomic_cmpxchg(v, c, new);
15588+ if (val == c)
15589+ return 1;
15590+ c = val;
15591+ } while (c);
15592+
15593+ return 0;
15594+}
15595+
15596+/**
15597 * atomic_inc_short - increment of a short integer
15598 * @v: pointer to type int
15599 *
15600@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15601 #endif
15602
15603 /* These are x86-specific, used by some header files */
15604-#define atomic_clear_mask(mask, addr) \
15605- asm volatile(LOCK_PREFIX "andl %0,%1" \
15606- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15607+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15608+{
15609+ asm volatile(LOCK_PREFIX "andl %1,%0"
15610+ : "+m" (v->counter)
15611+ : "r" (~(mask))
15612+ : "memory");
15613+}
15614
15615-#define atomic_set_mask(mask, addr) \
15616- asm volatile(LOCK_PREFIX "orl %0,%1" \
15617- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15618- : "memory")
15619+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15620+{
15621+ asm volatile(LOCK_PREFIX "andl %1,%0"
15622+ : "+m" (v->counter)
15623+ : "r" (~(mask))
15624+ : "memory");
15625+}
15626+
15627+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15628+{
15629+ asm volatile(LOCK_PREFIX "orl %1,%0"
15630+ : "+m" (v->counter)
15631+ : "r" (mask)
15632+ : "memory");
15633+}
15634+
15635+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15636+{
15637+ asm volatile(LOCK_PREFIX "orl %1,%0"
15638+ : "+m" (v->counter)
15639+ : "r" (mask)
15640+ : "memory");
15641+}
15642
15643 /* Atomic operations are already serializing on x86 */
15644 #define smp_mb__before_atomic_dec() barrier()
15645diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15646index b154de7..bf18a5a 100644
15647--- a/arch/x86/include/asm/atomic64_32.h
15648+++ b/arch/x86/include/asm/atomic64_32.h
15649@@ -12,6 +12,14 @@ typedef struct {
15650 u64 __aligned(8) counter;
15651 } atomic64_t;
15652
15653+#ifdef CONFIG_PAX_REFCOUNT
15654+typedef struct {
15655+ u64 __aligned(8) counter;
15656+} atomic64_unchecked_t;
15657+#else
15658+typedef atomic64_t atomic64_unchecked_t;
15659+#endif
15660+
15661 #define ATOMIC64_INIT(val) { (val) }
15662
15663 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15664@@ -37,21 +45,31 @@ typedef struct {
15665 ATOMIC64_DECL_ONE(sym##_386)
15666
15667 ATOMIC64_DECL_ONE(add_386);
15668+ATOMIC64_DECL_ONE(add_unchecked_386);
15669 ATOMIC64_DECL_ONE(sub_386);
15670+ATOMIC64_DECL_ONE(sub_unchecked_386);
15671 ATOMIC64_DECL_ONE(inc_386);
15672+ATOMIC64_DECL_ONE(inc_unchecked_386);
15673 ATOMIC64_DECL_ONE(dec_386);
15674+ATOMIC64_DECL_ONE(dec_unchecked_386);
15675 #endif
15676
15677 #define alternative_atomic64(f, out, in...) \
15678 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15679
15680 ATOMIC64_DECL(read);
15681+ATOMIC64_DECL(read_unchecked);
15682 ATOMIC64_DECL(set);
15683+ATOMIC64_DECL(set_unchecked);
15684 ATOMIC64_DECL(xchg);
15685 ATOMIC64_DECL(add_return);
15686+ATOMIC64_DECL(add_return_unchecked);
15687 ATOMIC64_DECL(sub_return);
15688+ATOMIC64_DECL(sub_return_unchecked);
15689 ATOMIC64_DECL(inc_return);
15690+ATOMIC64_DECL(inc_return_unchecked);
15691 ATOMIC64_DECL(dec_return);
15692+ATOMIC64_DECL(dec_return_unchecked);
15693 ATOMIC64_DECL(dec_if_positive);
15694 ATOMIC64_DECL(inc_not_zero);
15695 ATOMIC64_DECL(add_unless);
15696@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15697 }
15698
15699 /**
15700+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15701+ * @p: pointer to type atomic64_unchecked_t
15702+ * @o: expected value
15703+ * @n: new value
15704+ *
15705+ * Atomically sets @v to @n if it was equal to @o and returns
15706+ * the old value.
15707+ */
15708+
15709+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15710+{
15711+ return cmpxchg64(&v->counter, o, n);
15712+}
15713+
15714+/**
15715 * atomic64_xchg - xchg atomic64 variable
15716 * @v: pointer to type atomic64_t
15717 * @n: value to assign
15718@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15719 }
15720
15721 /**
15722+ * atomic64_set_unchecked - set atomic64 variable
15723+ * @v: pointer to type atomic64_unchecked_t
15724+ * @n: value to assign
15725+ *
15726+ * Atomically sets the value of @v to @n.
15727+ */
15728+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15729+{
15730+ unsigned high = (unsigned)(i >> 32);
15731+ unsigned low = (unsigned)i;
15732+ alternative_atomic64(set, /* no output */,
15733+ "S" (v), "b" (low), "c" (high)
15734+ : "eax", "edx", "memory");
15735+}
15736+
15737+/**
15738 * atomic64_read - read atomic64 variable
15739 * @v: pointer to type atomic64_t
15740 *
15741@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15742 }
15743
15744 /**
15745+ * atomic64_read_unchecked - read atomic64 variable
15746+ * @v: pointer to type atomic64_unchecked_t
15747+ *
15748+ * Atomically reads the value of @v and returns it.
15749+ */
15750+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15751+{
15752+ long long r;
15753+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15754+ return r;
15755+ }
15756+
15757+/**
15758 * atomic64_add_return - add and return
15759 * @i: integer value to add
15760 * @v: pointer to type atomic64_t
15761@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15762 return i;
15763 }
15764
15765+/**
15766+ * atomic64_add_return_unchecked - add and return
15767+ * @i: integer value to add
15768+ * @v: pointer to type atomic64_unchecked_t
15769+ *
15770+ * Atomically adds @i to @v and returns @i + *@v
15771+ */
15772+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15773+{
15774+ alternative_atomic64(add_return_unchecked,
15775+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15776+ ASM_NO_INPUT_CLOBBER("memory"));
15777+ return i;
15778+}
15779+
15780 /*
15781 * Other variants with different arithmetic operators:
15782 */
15783@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15784 return a;
15785 }
15786
15787+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15788+{
15789+ long long a;
15790+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15791+ "S" (v) : "memory", "ecx");
15792+ return a;
15793+}
15794+
15795 static inline long long atomic64_dec_return(atomic64_t *v)
15796 {
15797 long long a;
15798@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15799 }
15800
15801 /**
15802+ * atomic64_add_unchecked - add integer to atomic64 variable
15803+ * @i: integer value to add
15804+ * @v: pointer to type atomic64_unchecked_t
15805+ *
15806+ * Atomically adds @i to @v.
15807+ */
15808+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15809+{
15810+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15811+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15812+ ASM_NO_INPUT_CLOBBER("memory"));
15813+ return i;
15814+}
15815+
15816+/**
15817 * atomic64_sub - subtract the atomic64 variable
15818 * @i: integer value to subtract
15819 * @v: pointer to type atomic64_t
15820diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15821index 46e9052..ae45136 100644
15822--- a/arch/x86/include/asm/atomic64_64.h
15823+++ b/arch/x86/include/asm/atomic64_64.h
15824@@ -18,7 +18,19 @@
15825 */
15826 static inline long atomic64_read(const atomic64_t *v)
15827 {
15828- return (*(volatile long *)&(v)->counter);
15829+ return (*(volatile const long *)&(v)->counter);
15830+}
15831+
15832+/**
15833+ * atomic64_read_unchecked - read atomic64 variable
15834+ * @v: pointer of type atomic64_unchecked_t
15835+ *
15836+ * Atomically reads the value of @v.
15837+ * Doesn't imply a read memory barrier.
15838+ */
15839+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15840+{
15841+ return (*(volatile const long *)&(v)->counter);
15842 }
15843
15844 /**
15845@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15846 }
15847
15848 /**
15849+ * atomic64_set_unchecked - set atomic64 variable
15850+ * @v: pointer to type atomic64_unchecked_t
15851+ * @i: required value
15852+ *
15853+ * Atomically sets the value of @v to @i.
15854+ */
15855+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15856+{
15857+ v->counter = i;
15858+}
15859+
15860+/**
15861 * atomic64_add - add integer to atomic64 variable
15862 * @i: integer value to add
15863 * @v: pointer to type atomic64_t
15864@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15865 */
15866 static inline void atomic64_add(long i, atomic64_t *v)
15867 {
15868+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15869+
15870+#ifdef CONFIG_PAX_REFCOUNT
15871+ "jno 0f\n"
15872+ LOCK_PREFIX "subq %1,%0\n"
15873+ "int $4\n0:\n"
15874+ _ASM_EXTABLE(0b, 0b)
15875+#endif
15876+
15877+ : "=m" (v->counter)
15878+ : "er" (i), "m" (v->counter));
15879+}
15880+
15881+/**
15882+ * atomic64_add_unchecked - add integer to atomic64 variable
15883+ * @i: integer value to add
15884+ * @v: pointer to type atomic64_unchecked_t
15885+ *
15886+ * Atomically adds @i to @v.
15887+ */
15888+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15889+{
15890 asm volatile(LOCK_PREFIX "addq %1,%0"
15891 : "=m" (v->counter)
15892 : "er" (i), "m" (v->counter));
15893@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15894 */
15895 static inline void atomic64_sub(long i, atomic64_t *v)
15896 {
15897- asm volatile(LOCK_PREFIX "subq %1,%0"
15898+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15899+
15900+#ifdef CONFIG_PAX_REFCOUNT
15901+ "jno 0f\n"
15902+ LOCK_PREFIX "addq %1,%0\n"
15903+ "int $4\n0:\n"
15904+ _ASM_EXTABLE(0b, 0b)
15905+#endif
15906+
15907+ : "=m" (v->counter)
15908+ : "er" (i), "m" (v->counter));
15909+}
15910+
15911+/**
15912+ * atomic64_sub_unchecked - subtract the atomic64 variable
15913+ * @i: integer value to subtract
15914+ * @v: pointer to type atomic64_unchecked_t
15915+ *
15916+ * Atomically subtracts @i from @v.
15917+ */
15918+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15919+{
15920+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15921 : "=m" (v->counter)
15922 : "er" (i), "m" (v->counter));
15923 }
15924@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15925 */
15926 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15927 {
15928- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15929+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15930 }
15931
15932 /**
15933@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15934 */
15935 static inline void atomic64_inc(atomic64_t *v)
15936 {
15937+ asm volatile(LOCK_PREFIX "incq %0\n"
15938+
15939+#ifdef CONFIG_PAX_REFCOUNT
15940+ "jno 0f\n"
15941+ LOCK_PREFIX "decq %0\n"
15942+ "int $4\n0:\n"
15943+ _ASM_EXTABLE(0b, 0b)
15944+#endif
15945+
15946+ : "=m" (v->counter)
15947+ : "m" (v->counter));
15948+}
15949+
15950+/**
15951+ * atomic64_inc_unchecked - increment atomic64 variable
15952+ * @v: pointer to type atomic64_unchecked_t
15953+ *
15954+ * Atomically increments @v by 1.
15955+ */
15956+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15957+{
15958 asm volatile(LOCK_PREFIX "incq %0"
15959 : "=m" (v->counter)
15960 : "m" (v->counter));
15961@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15962 */
15963 static inline void atomic64_dec(atomic64_t *v)
15964 {
15965- asm volatile(LOCK_PREFIX "decq %0"
15966+ asm volatile(LOCK_PREFIX "decq %0\n"
15967+
15968+#ifdef CONFIG_PAX_REFCOUNT
15969+ "jno 0f\n"
15970+ LOCK_PREFIX "incq %0\n"
15971+ "int $4\n0:\n"
15972+ _ASM_EXTABLE(0b, 0b)
15973+#endif
15974+
15975+ : "=m" (v->counter)
15976+ : "m" (v->counter));
15977+}
15978+
15979+/**
15980+ * atomic64_dec_unchecked - decrement atomic64 variable
15981+ * @v: pointer to type atomic64_t
15982+ *
15983+ * Atomically decrements @v by 1.
15984+ */
15985+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15986+{
15987+ asm volatile(LOCK_PREFIX "decq %0\n"
15988 : "=m" (v->counter)
15989 : "m" (v->counter));
15990 }
15991@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15992 */
15993 static inline int atomic64_dec_and_test(atomic64_t *v)
15994 {
15995- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15996+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15997 }
15998
15999 /**
16000@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
16001 */
16002 static inline int atomic64_inc_and_test(atomic64_t *v)
16003 {
16004- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
16005+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
16006 }
16007
16008 /**
16009@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
16010 */
16011 static inline int atomic64_add_negative(long i, atomic64_t *v)
16012 {
16013- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
16014+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
16015 }
16016
16017 /**
16018@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
16019 */
16020 static inline long atomic64_add_return(long i, atomic64_t *v)
16021 {
16022+ return i + xadd_check_overflow(&v->counter, i);
16023+}
16024+
16025+/**
16026+ * atomic64_add_return_unchecked - add and return
16027+ * @i: integer value to add
16028+ * @v: pointer to type atomic64_unchecked_t
16029+ *
16030+ * Atomically adds @i to @v and returns @i + @v
16031+ */
16032+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
16033+{
16034 return i + xadd(&v->counter, i);
16035 }
16036
16037@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
16038 }
16039
16040 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
16041+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16042+{
16043+ return atomic64_add_return_unchecked(1, v);
16044+}
16045 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16046
16047 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16048@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16049 return cmpxchg(&v->counter, old, new);
16050 }
16051
16052+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16053+{
16054+ return cmpxchg(&v->counter, old, new);
16055+}
16056+
16057 static inline long atomic64_xchg(atomic64_t *v, long new)
16058 {
16059 return xchg(&v->counter, new);
16060@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16061 */
16062 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16063 {
16064- long c, old;
16065+ long c, old, new;
16066 c = atomic64_read(v);
16067 for (;;) {
16068- if (unlikely(c == (u)))
16069+ if (unlikely(c == u))
16070 break;
16071- old = atomic64_cmpxchg((v), c, c + (a));
16072+
16073+ asm volatile("add %2,%0\n"
16074+
16075+#ifdef CONFIG_PAX_REFCOUNT
16076+ "jno 0f\n"
16077+ "sub %2,%0\n"
16078+ "int $4\n0:\n"
16079+ _ASM_EXTABLE(0b, 0b)
16080+#endif
16081+
16082+ : "=r" (new)
16083+ : "0" (c), "ir" (a));
16084+
16085+ old = atomic64_cmpxchg(v, c, new);
16086 if (likely(old == c))
16087 break;
16088 c = old;
16089 }
16090- return c != (u);
16091+ return c != u;
16092 }
16093
16094 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16095diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16096index 69bbb48..32517fe 100644
16097--- a/arch/x86/include/asm/barrier.h
16098+++ b/arch/x86/include/asm/barrier.h
16099@@ -107,7 +107,7 @@
16100 do { \
16101 compiletime_assert_atomic_type(*p); \
16102 smp_mb(); \
16103- ACCESS_ONCE(*p) = (v); \
16104+ ACCESS_ONCE_RW(*p) = (v); \
16105 } while (0)
16106
16107 #define smp_load_acquire(p) \
16108@@ -124,7 +124,7 @@ do { \
16109 do { \
16110 compiletime_assert_atomic_type(*p); \
16111 barrier(); \
16112- ACCESS_ONCE(*p) = (v); \
16113+ ACCESS_ONCE_RW(*p) = (v); \
16114 } while (0)
16115
16116 #define smp_load_acquire(p) \
16117diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16118index 9fc1af7..fc71228 100644
16119--- a/arch/x86/include/asm/bitops.h
16120+++ b/arch/x86/include/asm/bitops.h
16121@@ -49,7 +49,7 @@
16122 * a mask operation on a byte.
16123 */
16124 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16125-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16126+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16127 #define CONST_MASK(nr) (1 << ((nr) & 7))
16128
16129 /**
16130@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16131 */
16132 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16133 {
16134- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16135+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16136 }
16137
16138 /**
16139@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16140 */
16141 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16142 {
16143- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16144+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16145 }
16146
16147 /**
16148@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16149 */
16150 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16151 {
16152- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16153+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16154 }
16155
16156 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16157@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16158 *
16159 * Undefined if no bit exists, so code should check against 0 first.
16160 */
16161-static inline unsigned long __ffs(unsigned long word)
16162+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16163 {
16164 asm("rep; bsf %1,%0"
16165 : "=r" (word)
16166@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
16167 *
16168 * Undefined if no zero exists, so code should check against ~0UL first.
16169 */
16170-static inline unsigned long ffz(unsigned long word)
16171+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16172 {
16173 asm("rep; bsf %1,%0"
16174 : "=r" (word)
16175@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
16176 *
16177 * Undefined if no set bit exists, so code should check against 0 first.
16178 */
16179-static inline unsigned long __fls(unsigned long word)
16180+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16181 {
16182 asm("bsr %1,%0"
16183 : "=r" (word)
16184@@ -436,7 +436,7 @@ static inline int ffs(int x)
16185 * set bit if value is nonzero. The last (most significant) bit is
16186 * at position 32.
16187 */
16188-static inline int fls(int x)
16189+static inline int __intentional_overflow(-1) fls(int x)
16190 {
16191 int r;
16192
16193@@ -478,7 +478,7 @@ static inline int fls(int x)
16194 * at position 64.
16195 */
16196 #ifdef CONFIG_X86_64
16197-static __always_inline int fls64(__u64 x)
16198+static __always_inline long fls64(__u64 x)
16199 {
16200 int bitpos = -1;
16201 /*
16202diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16203index 4fa687a..60f2d39 100644
16204--- a/arch/x86/include/asm/boot.h
16205+++ b/arch/x86/include/asm/boot.h
16206@@ -6,10 +6,15 @@
16207 #include <uapi/asm/boot.h>
16208
16209 /* Physical address where kernel should be loaded. */
16210-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16211+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16212 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16213 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16214
16215+#ifndef __ASSEMBLY__
16216+extern unsigned char __LOAD_PHYSICAL_ADDR[];
16217+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16218+#endif
16219+
16220 /* Minimum kernel alignment, as a power of two */
16221 #ifdef CONFIG_X86_64
16222 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16223diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16224index 48f99f1..d78ebf9 100644
16225--- a/arch/x86/include/asm/cache.h
16226+++ b/arch/x86/include/asm/cache.h
16227@@ -5,12 +5,13 @@
16228
16229 /* L1 cache line size */
16230 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16231-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16232+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16233
16234 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16235+#define __read_only __attribute__((__section__(".data..read_only")))
16236
16237 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16238-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16239+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16240
16241 #ifdef CONFIG_X86_VSMP
16242 #ifdef CONFIG_SMP
16243diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16244index 9863ee3..4a1f8e1 100644
16245--- a/arch/x86/include/asm/cacheflush.h
16246+++ b/arch/x86/include/asm/cacheflush.h
16247@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16248 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16249
16250 if (pg_flags == _PGMT_DEFAULT)
16251- return -1;
16252+ return ~0UL;
16253 else if (pg_flags == _PGMT_WC)
16254 return _PAGE_CACHE_WC;
16255 else if (pg_flags == _PGMT_UC_MINUS)
16256diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16257index cb4c73b..c473c29 100644
16258--- a/arch/x86/include/asm/calling.h
16259+++ b/arch/x86/include/asm/calling.h
16260@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16261 #define RSP 152
16262 #define SS 160
16263
16264-#define ARGOFFSET R11
16265-#define SWFRAME ORIG_RAX
16266+#define ARGOFFSET R15
16267
16268 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16269- subq $9*8+\addskip, %rsp
16270- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16271- movq_cfi rdi, 8*8
16272- movq_cfi rsi, 7*8
16273- movq_cfi rdx, 6*8
16274+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16275+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16276+ movq_cfi rdi, RDI
16277+ movq_cfi rsi, RSI
16278+ movq_cfi rdx, RDX
16279
16280 .if \save_rcx
16281- movq_cfi rcx, 5*8
16282+ movq_cfi rcx, RCX
16283 .endif
16284
16285- movq_cfi rax, 4*8
16286+ movq_cfi rax, RAX
16287
16288 .if \save_r891011
16289- movq_cfi r8, 3*8
16290- movq_cfi r9, 2*8
16291- movq_cfi r10, 1*8
16292- movq_cfi r11, 0*8
16293+ movq_cfi r8, R8
16294+ movq_cfi r9, R9
16295+ movq_cfi r10, R10
16296+ movq_cfi r11, R11
16297 .endif
16298
16299+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16300+ movq_cfi r12, R12
16301+#endif
16302+
16303 .endm
16304
16305-#define ARG_SKIP (9*8)
16306+#define ARG_SKIP ORIG_RAX
16307
16308 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16309 rstor_r8910=1, rstor_rdx=1
16310+
16311+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16312+ movq_cfi_restore R12, r12
16313+#endif
16314+
16315 .if \rstor_r11
16316- movq_cfi_restore 0*8, r11
16317+ movq_cfi_restore R11, r11
16318 .endif
16319
16320 .if \rstor_r8910
16321- movq_cfi_restore 1*8, r10
16322- movq_cfi_restore 2*8, r9
16323- movq_cfi_restore 3*8, r8
16324+ movq_cfi_restore R10, r10
16325+ movq_cfi_restore R9, r9
16326+ movq_cfi_restore R8, r8
16327 .endif
16328
16329 .if \rstor_rax
16330- movq_cfi_restore 4*8, rax
16331+ movq_cfi_restore RAX, rax
16332 .endif
16333
16334 .if \rstor_rcx
16335- movq_cfi_restore 5*8, rcx
16336+ movq_cfi_restore RCX, rcx
16337 .endif
16338
16339 .if \rstor_rdx
16340- movq_cfi_restore 6*8, rdx
16341+ movq_cfi_restore RDX, rdx
16342 .endif
16343
16344- movq_cfi_restore 7*8, rsi
16345- movq_cfi_restore 8*8, rdi
16346+ movq_cfi_restore RSI, rsi
16347+ movq_cfi_restore RDI, rdi
16348
16349- .if ARG_SKIP+\addskip > 0
16350- addq $ARG_SKIP+\addskip, %rsp
16351- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16352+ .if ORIG_RAX+\addskip > 0
16353+ addq $ORIG_RAX+\addskip, %rsp
16354+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16355 .endif
16356 .endm
16357
16358- .macro LOAD_ARGS offset, skiprax=0
16359- movq \offset(%rsp), %r11
16360- movq \offset+8(%rsp), %r10
16361- movq \offset+16(%rsp), %r9
16362- movq \offset+24(%rsp), %r8
16363- movq \offset+40(%rsp), %rcx
16364- movq \offset+48(%rsp), %rdx
16365- movq \offset+56(%rsp), %rsi
16366- movq \offset+64(%rsp), %rdi
16367+ .macro LOAD_ARGS skiprax=0
16368+ movq R11(%rsp), %r11
16369+ movq R10(%rsp), %r10
16370+ movq R9(%rsp), %r9
16371+ movq R8(%rsp), %r8
16372+ movq RCX(%rsp), %rcx
16373+ movq RDX(%rsp), %rdx
16374+ movq RSI(%rsp), %rsi
16375+ movq RDI(%rsp), %rdi
16376 .if \skiprax
16377 .else
16378- movq \offset+72(%rsp), %rax
16379+ movq RAX(%rsp), %rax
16380 .endif
16381 .endm
16382
16383-#define REST_SKIP (6*8)
16384-
16385 .macro SAVE_REST
16386- subq $REST_SKIP, %rsp
16387- CFI_ADJUST_CFA_OFFSET REST_SKIP
16388- movq_cfi rbx, 5*8
16389- movq_cfi rbp, 4*8
16390- movq_cfi r12, 3*8
16391- movq_cfi r13, 2*8
16392- movq_cfi r14, 1*8
16393- movq_cfi r15, 0*8
16394+ movq_cfi rbx, RBX
16395+ movq_cfi rbp, RBP
16396+
16397+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16398+ movq_cfi r12, R12
16399+#endif
16400+
16401+ movq_cfi r13, R13
16402+ movq_cfi r14, R14
16403+ movq_cfi r15, R15
16404 .endm
16405
16406 .macro RESTORE_REST
16407- movq_cfi_restore 0*8, r15
16408- movq_cfi_restore 1*8, r14
16409- movq_cfi_restore 2*8, r13
16410- movq_cfi_restore 3*8, r12
16411- movq_cfi_restore 4*8, rbp
16412- movq_cfi_restore 5*8, rbx
16413- addq $REST_SKIP, %rsp
16414- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16415+ movq_cfi_restore R15, r15
16416+ movq_cfi_restore R14, r14
16417+ movq_cfi_restore R13, r13
16418+
16419+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16420+ movq_cfi_restore R12, r12
16421+#endif
16422+
16423+ movq_cfi_restore RBP, rbp
16424+ movq_cfi_restore RBX, rbx
16425 .endm
16426
16427 .macro SAVE_ALL
16428diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16429index f50de69..2b0a458 100644
16430--- a/arch/x86/include/asm/checksum_32.h
16431+++ b/arch/x86/include/asm/checksum_32.h
16432@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16433 int len, __wsum sum,
16434 int *src_err_ptr, int *dst_err_ptr);
16435
16436+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16437+ int len, __wsum sum,
16438+ int *src_err_ptr, int *dst_err_ptr);
16439+
16440+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16441+ int len, __wsum sum,
16442+ int *src_err_ptr, int *dst_err_ptr);
16443+
16444 /*
16445 * Note: when you get a NULL pointer exception here this means someone
16446 * passed in an incorrect kernel address to one of these functions.
16447@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16448
16449 might_sleep();
16450 stac();
16451- ret = csum_partial_copy_generic((__force void *)src, dst,
16452+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16453 len, sum, err_ptr, NULL);
16454 clac();
16455
16456@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16457 might_sleep();
16458 if (access_ok(VERIFY_WRITE, dst, len)) {
16459 stac();
16460- ret = csum_partial_copy_generic(src, (__force void *)dst,
16461+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16462 len, sum, NULL, err_ptr);
16463 clac();
16464 return ret;
16465diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16466index d47786a..2d8883e 100644
16467--- a/arch/x86/include/asm/cmpxchg.h
16468+++ b/arch/x86/include/asm/cmpxchg.h
16469@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16470 __compiletime_error("Bad argument size for cmpxchg");
16471 extern void __xadd_wrong_size(void)
16472 __compiletime_error("Bad argument size for xadd");
16473+extern void __xadd_check_overflow_wrong_size(void)
16474+ __compiletime_error("Bad argument size for xadd_check_overflow");
16475 extern void __add_wrong_size(void)
16476 __compiletime_error("Bad argument size for add");
16477+extern void __add_check_overflow_wrong_size(void)
16478+ __compiletime_error("Bad argument size for add_check_overflow");
16479
16480 /*
16481 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16482@@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16483 __ret; \
16484 })
16485
16486+#ifdef CONFIG_PAX_REFCOUNT
16487+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16488+ ({ \
16489+ __typeof__ (*(ptr)) __ret = (arg); \
16490+ switch (sizeof(*(ptr))) { \
16491+ case __X86_CASE_L: \
16492+ asm volatile (lock #op "l %0, %1\n" \
16493+ "jno 0f\n" \
16494+ "mov %0,%1\n" \
16495+ "int $4\n0:\n" \
16496+ _ASM_EXTABLE(0b, 0b) \
16497+ : "+r" (__ret), "+m" (*(ptr)) \
16498+ : : "memory", "cc"); \
16499+ break; \
16500+ case __X86_CASE_Q: \
16501+ asm volatile (lock #op "q %q0, %1\n" \
16502+ "jno 0f\n" \
16503+ "mov %0,%1\n" \
16504+ "int $4\n0:\n" \
16505+ _ASM_EXTABLE(0b, 0b) \
16506+ : "+r" (__ret), "+m" (*(ptr)) \
16507+ : : "memory", "cc"); \
16508+ break; \
16509+ default: \
16510+ __ ## op ## _check_overflow_wrong_size(); \
16511+ } \
16512+ __ret; \
16513+ })
16514+#else
16515+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16516+#endif
16517+
16518 /*
16519 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16520 * Since this is generally used to protect other memory information, we
16521@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16522 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16523 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16524
16525+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16526+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16527+
16528 #define __add(ptr, inc, lock) \
16529 ({ \
16530 __typeof__ (*(ptr)) __ret = (inc); \
16531diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16532index 59c6c40..5e0b22c 100644
16533--- a/arch/x86/include/asm/compat.h
16534+++ b/arch/x86/include/asm/compat.h
16535@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16536 typedef u32 compat_uint_t;
16537 typedef u32 compat_ulong_t;
16538 typedef u64 __attribute__((aligned(4))) compat_u64;
16539-typedef u32 compat_uptr_t;
16540+typedef u32 __user compat_uptr_t;
16541
16542 struct compat_timespec {
16543 compat_time_t tv_sec;
16544diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16545index 5f12968..a383517 100644
16546--- a/arch/x86/include/asm/cpufeature.h
16547+++ b/arch/x86/include/asm/cpufeature.h
16548@@ -203,7 +203,7 @@
16549 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16550 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16551 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16552-
16553+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16554
16555 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16556 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16557@@ -211,7 +211,7 @@
16558 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16559 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16560 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16561-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16562+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16563 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16564 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16565 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16566@@ -358,6 +358,7 @@ extern const char * const x86_power_flags[32];
16567 #undef cpu_has_centaur_mcr
16568 #define cpu_has_centaur_mcr 0
16569
16570+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16571 #endif /* CONFIG_X86_64 */
16572
16573 #if __GNUC__ >= 4
16574@@ -410,7 +411,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16575
16576 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16577 t_warn:
16578- warn_pre_alternatives();
16579+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16580+ warn_pre_alternatives();
16581 return false;
16582 #endif
16583
16584@@ -430,7 +432,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16585 ".section .discard,\"aw\",@progbits\n"
16586 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16587 ".previous\n"
16588- ".section .altinstr_replacement,\"ax\"\n"
16589+ ".section .altinstr_replacement,\"a\"\n"
16590 "3: movb $1,%0\n"
16591 "4:\n"
16592 ".previous\n"
16593@@ -467,7 +469,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16594 " .byte 2b - 1b\n" /* src len */
16595 " .byte 4f - 3f\n" /* repl len */
16596 ".previous\n"
16597- ".section .altinstr_replacement,\"ax\"\n"
16598+ ".section .altinstr_replacement,\"a\"\n"
16599 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16600 "4:\n"
16601 ".previous\n"
16602@@ -500,7 +502,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16603 ".section .discard,\"aw\",@progbits\n"
16604 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16605 ".previous\n"
16606- ".section .altinstr_replacement,\"ax\"\n"
16607+ ".section .altinstr_replacement,\"a\"\n"
16608 "3: movb $0,%0\n"
16609 "4:\n"
16610 ".previous\n"
16611@@ -514,7 +516,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16612 ".section .discard,\"aw\",@progbits\n"
16613 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16614 ".previous\n"
16615- ".section .altinstr_replacement,\"ax\"\n"
16616+ ".section .altinstr_replacement,\"a\"\n"
16617 "5: movb $1,%0\n"
16618 "6:\n"
16619 ".previous\n"
16620diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16621index 50d033a..37deb26 100644
16622--- a/arch/x86/include/asm/desc.h
16623+++ b/arch/x86/include/asm/desc.h
16624@@ -4,6 +4,7 @@
16625 #include <asm/desc_defs.h>
16626 #include <asm/ldt.h>
16627 #include <asm/mmu.h>
16628+#include <asm/pgtable.h>
16629
16630 #include <linux/smp.h>
16631 #include <linux/percpu.h>
16632@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16633
16634 desc->type = (info->read_exec_only ^ 1) << 1;
16635 desc->type |= info->contents << 2;
16636+ desc->type |= info->seg_not_present ^ 1;
16637
16638 desc->s = 1;
16639 desc->dpl = 0x3;
16640@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16641 }
16642
16643 extern struct desc_ptr idt_descr;
16644-extern gate_desc idt_table[];
16645-extern struct desc_ptr debug_idt_descr;
16646-extern gate_desc debug_idt_table[];
16647-
16648-struct gdt_page {
16649- struct desc_struct gdt[GDT_ENTRIES];
16650-} __attribute__((aligned(PAGE_SIZE)));
16651-
16652-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16653+extern gate_desc idt_table[IDT_ENTRIES];
16654+extern const struct desc_ptr debug_idt_descr;
16655+extern gate_desc debug_idt_table[IDT_ENTRIES];
16656
16657+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16658 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16659 {
16660- return per_cpu(gdt_page, cpu).gdt;
16661+ return cpu_gdt_table[cpu];
16662 }
16663
16664 #ifdef CONFIG_X86_64
16665@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16666 unsigned long base, unsigned dpl, unsigned flags,
16667 unsigned short seg)
16668 {
16669- gate->a = (seg << 16) | (base & 0xffff);
16670- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16671+ gate->gate.offset_low = base;
16672+ gate->gate.seg = seg;
16673+ gate->gate.reserved = 0;
16674+ gate->gate.type = type;
16675+ gate->gate.s = 0;
16676+ gate->gate.dpl = dpl;
16677+ gate->gate.p = 1;
16678+ gate->gate.offset_high = base >> 16;
16679 }
16680
16681 #endif
16682@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16683
16684 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16685 {
16686+ pax_open_kernel();
16687 memcpy(&idt[entry], gate, sizeof(*gate));
16688+ pax_close_kernel();
16689 }
16690
16691 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16692 {
16693+ pax_open_kernel();
16694 memcpy(&ldt[entry], desc, 8);
16695+ pax_close_kernel();
16696 }
16697
16698 static inline void
16699@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16700 default: size = sizeof(*gdt); break;
16701 }
16702
16703+ pax_open_kernel();
16704 memcpy(&gdt[entry], desc, size);
16705+ pax_close_kernel();
16706 }
16707
16708 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16709@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16710
16711 static inline void native_load_tr_desc(void)
16712 {
16713+ pax_open_kernel();
16714 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16715+ pax_close_kernel();
16716 }
16717
16718 static inline void native_load_gdt(const struct desc_ptr *dtr)
16719@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16720 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16721 unsigned int i;
16722
16723+ pax_open_kernel();
16724 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16725 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16726+ pax_close_kernel();
16727 }
16728
16729 #define _LDT_empty(info) \
16730@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16731 preempt_enable();
16732 }
16733
16734-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16735+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16736 {
16737 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16738 }
16739@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16740 }
16741
16742 #ifdef CONFIG_X86_64
16743-static inline void set_nmi_gate(int gate, void *addr)
16744+static inline void set_nmi_gate(int gate, const void *addr)
16745 {
16746 gate_desc s;
16747
16748@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16749 #endif
16750
16751 #ifdef CONFIG_TRACING
16752-extern struct desc_ptr trace_idt_descr;
16753-extern gate_desc trace_idt_table[];
16754+extern const struct desc_ptr trace_idt_descr;
16755+extern gate_desc trace_idt_table[IDT_ENTRIES];
16756 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16757 {
16758 write_idt_entry(trace_idt_table, entry, gate);
16759 }
16760
16761-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16762+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16763 unsigned dpl, unsigned ist, unsigned seg)
16764 {
16765 gate_desc s;
16766@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16767 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16768 #endif
16769
16770-static inline void _set_gate(int gate, unsigned type, void *addr,
16771+static inline void _set_gate(int gate, unsigned type, const void *addr,
16772 unsigned dpl, unsigned ist, unsigned seg)
16773 {
16774 gate_desc s;
16775@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16776 #define set_intr_gate(n, addr) \
16777 do { \
16778 BUG_ON((unsigned)n > 0xFF); \
16779- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16780+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16781 __KERNEL_CS); \
16782- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16783+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16784 0, 0, __KERNEL_CS); \
16785 } while (0)
16786
16787@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16788 /*
16789 * This routine sets up an interrupt gate at directory privilege level 3.
16790 */
16791-static inline void set_system_intr_gate(unsigned int n, void *addr)
16792+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16793 {
16794 BUG_ON((unsigned)n > 0xFF);
16795 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16796 }
16797
16798-static inline void set_system_trap_gate(unsigned int n, void *addr)
16799+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16800 {
16801 BUG_ON((unsigned)n > 0xFF);
16802 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16803 }
16804
16805-static inline void set_trap_gate(unsigned int n, void *addr)
16806+static inline void set_trap_gate(unsigned int n, const void *addr)
16807 {
16808 BUG_ON((unsigned)n > 0xFF);
16809 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16810@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16811 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16812 {
16813 BUG_ON((unsigned)n > 0xFF);
16814- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16815+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16816 }
16817
16818-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16819+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16820 {
16821 BUG_ON((unsigned)n > 0xFF);
16822 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16823 }
16824
16825-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16826+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16827 {
16828 BUG_ON((unsigned)n > 0xFF);
16829 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16830@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16831 else
16832 load_idt((const struct desc_ptr *)&idt_descr);
16833 }
16834+
16835+#ifdef CONFIG_X86_32
16836+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16837+{
16838+ struct desc_struct d;
16839+
16840+ if (likely(limit))
16841+ limit = (limit - 1UL) >> PAGE_SHIFT;
16842+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16843+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16844+}
16845+#endif
16846+
16847 #endif /* _ASM_X86_DESC_H */
16848diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16849index 278441f..b95a174 100644
16850--- a/arch/x86/include/asm/desc_defs.h
16851+++ b/arch/x86/include/asm/desc_defs.h
16852@@ -31,6 +31,12 @@ struct desc_struct {
16853 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16854 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16855 };
16856+ struct {
16857+ u16 offset_low;
16858+ u16 seg;
16859+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16860+ unsigned offset_high: 16;
16861+ } gate;
16862 };
16863 } __attribute__((packed));
16864
16865diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16866index ced283a..ffe04cc 100644
16867--- a/arch/x86/include/asm/div64.h
16868+++ b/arch/x86/include/asm/div64.h
16869@@ -39,7 +39,7 @@
16870 __mod; \
16871 })
16872
16873-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16874+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16875 {
16876 union {
16877 u64 v64;
16878diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16879index 9c999c1..3860cb8 100644
16880--- a/arch/x86/include/asm/elf.h
16881+++ b/arch/x86/include/asm/elf.h
16882@@ -243,7 +243,25 @@ extern int force_personality32;
16883 the loader. We need to make sure that it is out of the way of the program
16884 that it will "exec", and that there is sufficient room for the brk. */
16885
16886+#ifdef CONFIG_PAX_SEGMEXEC
16887+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16888+#else
16889 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16890+#endif
16891+
16892+#ifdef CONFIG_PAX_ASLR
16893+#ifdef CONFIG_X86_32
16894+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16895+
16896+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16897+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16898+#else
16899+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16900+
16901+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16902+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16903+#endif
16904+#endif
16905
16906 /* This yields a mask that user programs can use to figure out what
16907 instruction set this CPU supports. This could be done in user space,
16908@@ -296,16 +314,12 @@ do { \
16909
16910 #define ARCH_DLINFO \
16911 do { \
16912- if (vdso_enabled) \
16913- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16914- (unsigned long)current->mm->context.vdso); \
16915+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16916 } while (0)
16917
16918 #define ARCH_DLINFO_X32 \
16919 do { \
16920- if (vdso_enabled) \
16921- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16922- (unsigned long)current->mm->context.vdso); \
16923+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16924 } while (0)
16925
16926 #define AT_SYSINFO 32
16927@@ -320,7 +334,7 @@ else \
16928
16929 #endif /* !CONFIG_X86_32 */
16930
16931-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16932+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16933
16934 #define VDSO_ENTRY \
16935 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16936@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16937 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16938 #define compat_arch_setup_additional_pages syscall32_setup_pages
16939
16940-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16941-#define arch_randomize_brk arch_randomize_brk
16942-
16943 /*
16944 * True on X86_32 or when emulating IA32 on X86_64
16945 */
16946diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16947index 77a99ac..39ff7f5 100644
16948--- a/arch/x86/include/asm/emergency-restart.h
16949+++ b/arch/x86/include/asm/emergency-restart.h
16950@@ -1,6 +1,6 @@
16951 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16952 #define _ASM_X86_EMERGENCY_RESTART_H
16953
16954-extern void machine_emergency_restart(void);
16955+extern void machine_emergency_restart(void) __noreturn;
16956
16957 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16958diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16959index d3d7469..677ef72 100644
16960--- a/arch/x86/include/asm/floppy.h
16961+++ b/arch/x86/include/asm/floppy.h
16962@@ -229,18 +229,18 @@ static struct fd_routine_l {
16963 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16964 } fd_routine[] = {
16965 {
16966- request_dma,
16967- free_dma,
16968- get_dma_residue,
16969- dma_mem_alloc,
16970- hard_dma_setup
16971+ ._request_dma = request_dma,
16972+ ._free_dma = free_dma,
16973+ ._get_dma_residue = get_dma_residue,
16974+ ._dma_mem_alloc = dma_mem_alloc,
16975+ ._dma_setup = hard_dma_setup
16976 },
16977 {
16978- vdma_request_dma,
16979- vdma_nop,
16980- vdma_get_dma_residue,
16981- vdma_mem_alloc,
16982- vdma_dma_setup
16983+ ._request_dma = vdma_request_dma,
16984+ ._free_dma = vdma_nop,
16985+ ._get_dma_residue = vdma_get_dma_residue,
16986+ ._dma_mem_alloc = vdma_mem_alloc,
16987+ ._dma_setup = vdma_dma_setup
16988 }
16989 };
16990
16991diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16992index cea1c76..6c0d79b 100644
16993--- a/arch/x86/include/asm/fpu-internal.h
16994+++ b/arch/x86/include/asm/fpu-internal.h
16995@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16996 #define user_insn(insn, output, input...) \
16997 ({ \
16998 int err; \
16999+ pax_open_userland(); \
17000 asm volatile(ASM_STAC "\n" \
17001- "1:" #insn "\n\t" \
17002+ "1:" \
17003+ __copyuser_seg \
17004+ #insn "\n\t" \
17005 "2: " ASM_CLAC "\n" \
17006 ".section .fixup,\"ax\"\n" \
17007 "3: movl $-1,%[err]\n" \
17008@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17009 _ASM_EXTABLE(1b, 3b) \
17010 : [err] "=r" (err), output \
17011 : "0"(0), input); \
17012+ pax_close_userland(); \
17013 err; \
17014 })
17015
17016@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
17017 "fnclex\n\t"
17018 "emms\n\t"
17019 "fildl %P[addr]" /* set F?P to defined value */
17020- : : [addr] "m" (tsk->thread.fpu.has_fpu));
17021+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
17022 }
17023
17024 return fpu_restore_checking(&tsk->thread.fpu);
17025diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17026index b4c1f54..e290c08 100644
17027--- a/arch/x86/include/asm/futex.h
17028+++ b/arch/x86/include/asm/futex.h
17029@@ -12,6 +12,7 @@
17030 #include <asm/smap.h>
17031
17032 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17033+ typecheck(u32 __user *, uaddr); \
17034 asm volatile("\t" ASM_STAC "\n" \
17035 "1:\t" insn "\n" \
17036 "2:\t" ASM_CLAC "\n" \
17037@@ -20,15 +21,16 @@
17038 "\tjmp\t2b\n" \
17039 "\t.previous\n" \
17040 _ASM_EXTABLE(1b, 3b) \
17041- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17042+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17043 : "i" (-EFAULT), "0" (oparg), "1" (0))
17044
17045 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17046+ typecheck(u32 __user *, uaddr); \
17047 asm volatile("\t" ASM_STAC "\n" \
17048 "1:\tmovl %2, %0\n" \
17049 "\tmovl\t%0, %3\n" \
17050 "\t" insn "\n" \
17051- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17052+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17053 "\tjnz\t1b\n" \
17054 "3:\t" ASM_CLAC "\n" \
17055 "\t.section .fixup,\"ax\"\n" \
17056@@ -38,7 +40,7 @@
17057 _ASM_EXTABLE(1b, 4b) \
17058 _ASM_EXTABLE(2b, 4b) \
17059 : "=&a" (oldval), "=&r" (ret), \
17060- "+m" (*uaddr), "=&r" (tem) \
17061+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17062 : "r" (oparg), "i" (-EFAULT), "1" (0))
17063
17064 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17065@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17066
17067 pagefault_disable();
17068
17069+ pax_open_userland();
17070 switch (op) {
17071 case FUTEX_OP_SET:
17072- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17073+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17074 break;
17075 case FUTEX_OP_ADD:
17076- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17077+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17078 uaddr, oparg);
17079 break;
17080 case FUTEX_OP_OR:
17081@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17082 default:
17083 ret = -ENOSYS;
17084 }
17085+ pax_close_userland();
17086
17087 pagefault_enable();
17088
17089diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17090index 67d69b8..50e4b77 100644
17091--- a/arch/x86/include/asm/hw_irq.h
17092+++ b/arch/x86/include/asm/hw_irq.h
17093@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
17094 extern void enable_IO_APIC(void);
17095
17096 /* Statistics */
17097-extern atomic_t irq_err_count;
17098-extern atomic_t irq_mis_count;
17099+extern atomic_unchecked_t irq_err_count;
17100+extern atomic_unchecked_t irq_mis_count;
17101
17102 /* EISA */
17103 extern void eisa_set_level_irq(unsigned int irq);
17104diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17105index a203659..9889f1c 100644
17106--- a/arch/x86/include/asm/i8259.h
17107+++ b/arch/x86/include/asm/i8259.h
17108@@ -62,7 +62,7 @@ struct legacy_pic {
17109 void (*init)(int auto_eoi);
17110 int (*irq_pending)(unsigned int irq);
17111 void (*make_irq)(unsigned int irq);
17112-};
17113+} __do_const;
17114
17115 extern struct legacy_pic *legacy_pic;
17116 extern struct legacy_pic null_legacy_pic;
17117diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17118index 91d9c69..dfae7d0 100644
17119--- a/arch/x86/include/asm/io.h
17120+++ b/arch/x86/include/asm/io.h
17121@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17122 "m" (*(volatile type __force *)addr) barrier); }
17123
17124 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17125-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17126-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17127+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17128+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17129
17130 build_mmio_read(__readb, "b", unsigned char, "=q", )
17131-build_mmio_read(__readw, "w", unsigned short, "=r", )
17132-build_mmio_read(__readl, "l", unsigned int, "=r", )
17133+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17134+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17135
17136 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17137 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17138@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17139 return ioremap_nocache(offset, size);
17140 }
17141
17142-extern void iounmap(volatile void __iomem *addr);
17143+extern void iounmap(const volatile void __iomem *addr);
17144
17145 extern void set_iounmap_nonlazy(void);
17146
17147@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
17148
17149 #include <linux/vmalloc.h>
17150
17151+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17152+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17153+{
17154+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17155+}
17156+
17157+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17158+{
17159+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17160+}
17161+
17162 /*
17163 * Convert a virtual cached pointer to an uncached pointer
17164 */
17165diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17166index bba3cf8..06bc8da 100644
17167--- a/arch/x86/include/asm/irqflags.h
17168+++ b/arch/x86/include/asm/irqflags.h
17169@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17170 sti; \
17171 sysexit
17172
17173+#define GET_CR0_INTO_RDI mov %cr0, %rdi
17174+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17175+#define GET_CR3_INTO_RDI mov %cr3, %rdi
17176+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17177+
17178 #else
17179 #define INTERRUPT_RETURN iret
17180 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17181diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17182index 9454c16..e4100e3 100644
17183--- a/arch/x86/include/asm/kprobes.h
17184+++ b/arch/x86/include/asm/kprobes.h
17185@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17186 #define RELATIVEJUMP_SIZE 5
17187 #define RELATIVECALL_OPCODE 0xe8
17188 #define RELATIVE_ADDR_SIZE 4
17189-#define MAX_STACK_SIZE 64
17190-#define MIN_STACK_SIZE(ADDR) \
17191- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17192- THREAD_SIZE - (unsigned long)(ADDR))) \
17193- ? (MAX_STACK_SIZE) \
17194- : (((unsigned long)current_thread_info()) + \
17195- THREAD_SIZE - (unsigned long)(ADDR)))
17196+#define MAX_STACK_SIZE 64UL
17197+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17198
17199 #define flush_insn_slot(p) do { } while (0)
17200
17201diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17202index 4ad6560..75c7bdd 100644
17203--- a/arch/x86/include/asm/local.h
17204+++ b/arch/x86/include/asm/local.h
17205@@ -10,33 +10,97 @@ typedef struct {
17206 atomic_long_t a;
17207 } local_t;
17208
17209+typedef struct {
17210+ atomic_long_unchecked_t a;
17211+} local_unchecked_t;
17212+
17213 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17214
17215 #define local_read(l) atomic_long_read(&(l)->a)
17216+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17217 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17218+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17219
17220 static inline void local_inc(local_t *l)
17221 {
17222- asm volatile(_ASM_INC "%0"
17223+ asm volatile(_ASM_INC "%0\n"
17224+
17225+#ifdef CONFIG_PAX_REFCOUNT
17226+ "jno 0f\n"
17227+ _ASM_DEC "%0\n"
17228+ "int $4\n0:\n"
17229+ _ASM_EXTABLE(0b, 0b)
17230+#endif
17231+
17232+ : "+m" (l->a.counter));
17233+}
17234+
17235+static inline void local_inc_unchecked(local_unchecked_t *l)
17236+{
17237+ asm volatile(_ASM_INC "%0\n"
17238 : "+m" (l->a.counter));
17239 }
17240
17241 static inline void local_dec(local_t *l)
17242 {
17243- asm volatile(_ASM_DEC "%0"
17244+ asm volatile(_ASM_DEC "%0\n"
17245+
17246+#ifdef CONFIG_PAX_REFCOUNT
17247+ "jno 0f\n"
17248+ _ASM_INC "%0\n"
17249+ "int $4\n0:\n"
17250+ _ASM_EXTABLE(0b, 0b)
17251+#endif
17252+
17253+ : "+m" (l->a.counter));
17254+}
17255+
17256+static inline void local_dec_unchecked(local_unchecked_t *l)
17257+{
17258+ asm volatile(_ASM_DEC "%0\n"
17259 : "+m" (l->a.counter));
17260 }
17261
17262 static inline void local_add(long i, local_t *l)
17263 {
17264- asm volatile(_ASM_ADD "%1,%0"
17265+ asm volatile(_ASM_ADD "%1,%0\n"
17266+
17267+#ifdef CONFIG_PAX_REFCOUNT
17268+ "jno 0f\n"
17269+ _ASM_SUB "%1,%0\n"
17270+ "int $4\n0:\n"
17271+ _ASM_EXTABLE(0b, 0b)
17272+#endif
17273+
17274+ : "+m" (l->a.counter)
17275+ : "ir" (i));
17276+}
17277+
17278+static inline void local_add_unchecked(long i, local_unchecked_t *l)
17279+{
17280+ asm volatile(_ASM_ADD "%1,%0\n"
17281 : "+m" (l->a.counter)
17282 : "ir" (i));
17283 }
17284
17285 static inline void local_sub(long i, local_t *l)
17286 {
17287- asm volatile(_ASM_SUB "%1,%0"
17288+ asm volatile(_ASM_SUB "%1,%0\n"
17289+
17290+#ifdef CONFIG_PAX_REFCOUNT
17291+ "jno 0f\n"
17292+ _ASM_ADD "%1,%0\n"
17293+ "int $4\n0:\n"
17294+ _ASM_EXTABLE(0b, 0b)
17295+#endif
17296+
17297+ : "+m" (l->a.counter)
17298+ : "ir" (i));
17299+}
17300+
17301+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17302+{
17303+ asm volatile(_ASM_SUB "%1,%0\n"
17304 : "+m" (l->a.counter)
17305 : "ir" (i));
17306 }
17307@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17308 */
17309 static inline int local_sub_and_test(long i, local_t *l)
17310 {
17311- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17312+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17313 }
17314
17315 /**
17316@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17317 */
17318 static inline int local_dec_and_test(local_t *l)
17319 {
17320- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17321+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17322 }
17323
17324 /**
17325@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17326 */
17327 static inline int local_inc_and_test(local_t *l)
17328 {
17329- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17330+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17331 }
17332
17333 /**
17334@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17335 */
17336 static inline int local_add_negative(long i, local_t *l)
17337 {
17338- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17339+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17340 }
17341
17342 /**
17343@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17344 static inline long local_add_return(long i, local_t *l)
17345 {
17346 long __i = i;
17347+ asm volatile(_ASM_XADD "%0, %1\n"
17348+
17349+#ifdef CONFIG_PAX_REFCOUNT
17350+ "jno 0f\n"
17351+ _ASM_MOV "%0,%1\n"
17352+ "int $4\n0:\n"
17353+ _ASM_EXTABLE(0b, 0b)
17354+#endif
17355+
17356+ : "+r" (i), "+m" (l->a.counter)
17357+ : : "memory");
17358+ return i + __i;
17359+}
17360+
17361+/**
17362+ * local_add_return_unchecked - add and return
17363+ * @i: integer value to add
17364+ * @l: pointer to type local_unchecked_t
17365+ *
17366+ * Atomically adds @i to @l and returns @i + @l
17367+ */
17368+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17369+{
17370+ long __i = i;
17371 asm volatile(_ASM_XADD "%0, %1;"
17372 : "+r" (i), "+m" (l->a.counter)
17373 : : "memory");
17374@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17375
17376 #define local_cmpxchg(l, o, n) \
17377 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17378+#define local_cmpxchg_unchecked(l, o, n) \
17379+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17380 /* Always has a lock prefix */
17381 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17382
17383diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17384new file mode 100644
17385index 0000000..2bfd3ba
17386--- /dev/null
17387+++ b/arch/x86/include/asm/mman.h
17388@@ -0,0 +1,15 @@
17389+#ifndef _X86_MMAN_H
17390+#define _X86_MMAN_H
17391+
17392+#include <uapi/asm/mman.h>
17393+
17394+#ifdef __KERNEL__
17395+#ifndef __ASSEMBLY__
17396+#ifdef CONFIG_X86_32
17397+#define arch_mmap_check i386_mmap_check
17398+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17399+#endif
17400+#endif
17401+#endif
17402+
17403+#endif /* X86_MMAN_H */
17404diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17405index 5f55e69..e20bfb1 100644
17406--- a/arch/x86/include/asm/mmu.h
17407+++ b/arch/x86/include/asm/mmu.h
17408@@ -9,7 +9,7 @@
17409 * we put the segment information here.
17410 */
17411 typedef struct {
17412- void *ldt;
17413+ struct desc_struct *ldt;
17414 int size;
17415
17416 #ifdef CONFIG_X86_64
17417@@ -18,7 +18,19 @@ typedef struct {
17418 #endif
17419
17420 struct mutex lock;
17421- void *vdso;
17422+ unsigned long vdso;
17423+
17424+#ifdef CONFIG_X86_32
17425+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17426+ unsigned long user_cs_base;
17427+ unsigned long user_cs_limit;
17428+
17429+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17430+ cpumask_t cpu_user_cs_mask;
17431+#endif
17432+
17433+#endif
17434+#endif
17435 } mm_context_t;
17436
17437 #ifdef CONFIG_SMP
17438diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17439index be12c53..4d24039 100644
17440--- a/arch/x86/include/asm/mmu_context.h
17441+++ b/arch/x86/include/asm/mmu_context.h
17442@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17443
17444 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17445 {
17446+
17447+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17448+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17449+ unsigned int i;
17450+ pgd_t *pgd;
17451+
17452+ pax_open_kernel();
17453+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17454+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17455+ set_pgd_batched(pgd+i, native_make_pgd(0));
17456+ pax_close_kernel();
17457+ }
17458+#endif
17459+
17460 #ifdef CONFIG_SMP
17461 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17462 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17463@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17464 struct task_struct *tsk)
17465 {
17466 unsigned cpu = smp_processor_id();
17467+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17468+ int tlbstate = TLBSTATE_OK;
17469+#endif
17470
17471 if (likely(prev != next)) {
17472 #ifdef CONFIG_SMP
17473+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17474+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17475+#endif
17476 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17477 this_cpu_write(cpu_tlbstate.active_mm, next);
17478 #endif
17479 cpumask_set_cpu(cpu, mm_cpumask(next));
17480
17481 /* Re-load page tables */
17482+#ifdef CONFIG_PAX_PER_CPU_PGD
17483+ pax_open_kernel();
17484+
17485+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17486+ if (static_cpu_has(X86_FEATURE_PCID))
17487+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17488+ else
17489+#endif
17490+
17491+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17492+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17493+ pax_close_kernel();
17494+ 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));
17495+
17496+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17497+ if (static_cpu_has(X86_FEATURE_PCID)) {
17498+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17499+ u64 descriptor[2];
17500+ descriptor[0] = PCID_USER;
17501+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17502+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17503+ descriptor[0] = PCID_KERNEL;
17504+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17505+ }
17506+ } else {
17507+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17508+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17509+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17510+ else
17511+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17512+ }
17513+ } else
17514+#endif
17515+
17516+ load_cr3(get_cpu_pgd(cpu, kernel));
17517+#else
17518 load_cr3(next->pgd);
17519+#endif
17520
17521 /* Stop flush ipis for the previous mm */
17522 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17523@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17524 /* Load the LDT, if the LDT is different: */
17525 if (unlikely(prev->context.ldt != next->context.ldt))
17526 load_LDT_nolock(&next->context);
17527+
17528+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17529+ if (!(__supported_pte_mask & _PAGE_NX)) {
17530+ smp_mb__before_clear_bit();
17531+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17532+ smp_mb__after_clear_bit();
17533+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17534+ }
17535+#endif
17536+
17537+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17538+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17539+ prev->context.user_cs_limit != next->context.user_cs_limit))
17540+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17541+#ifdef CONFIG_SMP
17542+ else if (unlikely(tlbstate != TLBSTATE_OK))
17543+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17544+#endif
17545+#endif
17546+
17547 }
17548+ else {
17549+
17550+#ifdef CONFIG_PAX_PER_CPU_PGD
17551+ pax_open_kernel();
17552+
17553+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17554+ if (static_cpu_has(X86_FEATURE_PCID))
17555+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17556+ else
17557+#endif
17558+
17559+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17560+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17561+ pax_close_kernel();
17562+ 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));
17563+
17564+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17565+ if (static_cpu_has(X86_FEATURE_PCID)) {
17566+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17567+ u64 descriptor[2];
17568+ descriptor[0] = PCID_USER;
17569+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17570+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17571+ descriptor[0] = PCID_KERNEL;
17572+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17573+ }
17574+ } else {
17575+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17576+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17577+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17578+ else
17579+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17580+ }
17581+ } else
17582+#endif
17583+
17584+ load_cr3(get_cpu_pgd(cpu, kernel));
17585+#endif
17586+
17587 #ifdef CONFIG_SMP
17588- else {
17589 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17590 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17591
17592@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17593 * tlb flush IPI delivery. We must reload CR3
17594 * to make sure to use no freed page tables.
17595 */
17596+
17597+#ifndef CONFIG_PAX_PER_CPU_PGD
17598 load_cr3(next->pgd);
17599+#endif
17600+
17601 load_LDT_nolock(&next->context);
17602+
17603+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17604+ if (!(__supported_pte_mask & _PAGE_NX))
17605+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17606+#endif
17607+
17608+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17609+#ifdef CONFIG_PAX_PAGEEXEC
17610+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17611+#endif
17612+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17613+#endif
17614+
17615 }
17616+#endif
17617 }
17618-#endif
17619 }
17620
17621 #define activate_mm(prev, next) \
17622diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17623index e3b7819..b257c64 100644
17624--- a/arch/x86/include/asm/module.h
17625+++ b/arch/x86/include/asm/module.h
17626@@ -5,6 +5,7 @@
17627
17628 #ifdef CONFIG_X86_64
17629 /* X86_64 does not define MODULE_PROC_FAMILY */
17630+#define MODULE_PROC_FAMILY ""
17631 #elif defined CONFIG_M486
17632 #define MODULE_PROC_FAMILY "486 "
17633 #elif defined CONFIG_M586
17634@@ -57,8 +58,20 @@
17635 #error unknown processor family
17636 #endif
17637
17638-#ifdef CONFIG_X86_32
17639-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17640+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17641+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17642+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17643+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17644+#else
17645+#define MODULE_PAX_KERNEXEC ""
17646 #endif
17647
17648+#ifdef CONFIG_PAX_MEMORY_UDEREF
17649+#define MODULE_PAX_UDEREF "UDEREF "
17650+#else
17651+#define MODULE_PAX_UDEREF ""
17652+#endif
17653+
17654+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17655+
17656 #endif /* _ASM_X86_MODULE_H */
17657diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17658index 86f9301..b365cda 100644
17659--- a/arch/x86/include/asm/nmi.h
17660+++ b/arch/x86/include/asm/nmi.h
17661@@ -40,11 +40,11 @@ struct nmiaction {
17662 nmi_handler_t handler;
17663 unsigned long flags;
17664 const char *name;
17665-};
17666+} __do_const;
17667
17668 #define register_nmi_handler(t, fn, fg, n, init...) \
17669 ({ \
17670- static struct nmiaction init fn##_na = { \
17671+ static const struct nmiaction init fn##_na = { \
17672 .handler = (fn), \
17673 .name = (n), \
17674 .flags = (fg), \
17675@@ -52,7 +52,7 @@ struct nmiaction {
17676 __register_nmi_handler((t), &fn##_na); \
17677 })
17678
17679-int __register_nmi_handler(unsigned int, struct nmiaction *);
17680+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17681
17682 void unregister_nmi_handler(unsigned int, const char *);
17683
17684diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17685index 775873d..de5f0304 100644
17686--- a/arch/x86/include/asm/page.h
17687+++ b/arch/x86/include/asm/page.h
17688@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17689 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17690
17691 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17692+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17693
17694 #define __boot_va(x) __va(x)
17695 #define __boot_pa(x) __pa(x)
17696diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17697index 0f1ddee..e2fc3d1 100644
17698--- a/arch/x86/include/asm/page_64.h
17699+++ b/arch/x86/include/asm/page_64.h
17700@@ -7,9 +7,9 @@
17701
17702 /* duplicated to the one in bootmem.h */
17703 extern unsigned long max_pfn;
17704-extern unsigned long phys_base;
17705+extern const unsigned long phys_base;
17706
17707-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17708+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17709 {
17710 unsigned long y = x - __START_KERNEL_map;
17711
17712diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
17713index 8de6d9c..6782051 100644
17714--- a/arch/x86/include/asm/page_64_types.h
17715+++ b/arch/x86/include/asm/page_64_types.h
17716@@ -1,7 +1,7 @@
17717 #ifndef _ASM_X86_PAGE_64_DEFS_H
17718 #define _ASM_X86_PAGE_64_DEFS_H
17719
17720-#define THREAD_SIZE_ORDER 1
17721+#define THREAD_SIZE_ORDER 2
17722 #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
17723 #define CURRENT_MASK (~(THREAD_SIZE - 1))
17724
17725diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17726index cd6e1610..70f4418 100644
17727--- a/arch/x86/include/asm/paravirt.h
17728+++ b/arch/x86/include/asm/paravirt.h
17729@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17730 return (pmd_t) { ret };
17731 }
17732
17733-static inline pmdval_t pmd_val(pmd_t pmd)
17734+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17735 {
17736 pmdval_t ret;
17737
17738@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17739 val);
17740 }
17741
17742+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17743+{
17744+ pgdval_t val = native_pgd_val(pgd);
17745+
17746+ if (sizeof(pgdval_t) > sizeof(long))
17747+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17748+ val, (u64)val >> 32);
17749+ else
17750+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17751+ val);
17752+}
17753+
17754 static inline void pgd_clear(pgd_t *pgdp)
17755 {
17756 set_pgd(pgdp, __pgd(0));
17757@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17758 pv_mmu_ops.set_fixmap(idx, phys, flags);
17759 }
17760
17761+#ifdef CONFIG_PAX_KERNEXEC
17762+static inline unsigned long pax_open_kernel(void)
17763+{
17764+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17765+}
17766+
17767+static inline unsigned long pax_close_kernel(void)
17768+{
17769+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17770+}
17771+#else
17772+static inline unsigned long pax_open_kernel(void) { return 0; }
17773+static inline unsigned long pax_close_kernel(void) { return 0; }
17774+#endif
17775+
17776 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17777
17778 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17779@@ -906,7 +933,7 @@ extern void default_banner(void);
17780
17781 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17782 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17783-#define PARA_INDIRECT(addr) *%cs:addr
17784+#define PARA_INDIRECT(addr) *%ss:addr
17785 #endif
17786
17787 #define INTERRUPT_RETURN \
17788@@ -981,6 +1008,21 @@ extern void default_banner(void);
17789 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17790 CLBR_NONE, \
17791 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17792+
17793+#define GET_CR0_INTO_RDI \
17794+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17795+ mov %rax,%rdi
17796+
17797+#define SET_RDI_INTO_CR0 \
17798+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17799+
17800+#define GET_CR3_INTO_RDI \
17801+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17802+ mov %rax,%rdi
17803+
17804+#define SET_RDI_INTO_CR3 \
17805+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17806+
17807 #endif /* CONFIG_X86_32 */
17808
17809 #endif /* __ASSEMBLY__ */
17810diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17811index 7549b8b..f0edfda 100644
17812--- a/arch/x86/include/asm/paravirt_types.h
17813+++ b/arch/x86/include/asm/paravirt_types.h
17814@@ -84,7 +84,7 @@ struct pv_init_ops {
17815 */
17816 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17817 unsigned long addr, unsigned len);
17818-};
17819+} __no_const __no_randomize_layout;
17820
17821
17822 struct pv_lazy_ops {
17823@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17824 void (*enter)(void);
17825 void (*leave)(void);
17826 void (*flush)(void);
17827-};
17828+} __no_randomize_layout;
17829
17830 struct pv_time_ops {
17831 unsigned long long (*sched_clock)(void);
17832 unsigned long long (*steal_clock)(int cpu);
17833 unsigned long (*get_tsc_khz)(void);
17834-};
17835+} __no_const __no_randomize_layout;
17836
17837 struct pv_cpu_ops {
17838 /* hooks for various privileged instructions */
17839@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17840
17841 void (*start_context_switch)(struct task_struct *prev);
17842 void (*end_context_switch)(struct task_struct *next);
17843-};
17844+} __no_const __no_randomize_layout;
17845
17846 struct pv_irq_ops {
17847 /*
17848@@ -215,7 +215,7 @@ struct pv_irq_ops {
17849 #ifdef CONFIG_X86_64
17850 void (*adjust_exception_frame)(void);
17851 #endif
17852-};
17853+} __no_randomize_layout;
17854
17855 struct pv_apic_ops {
17856 #ifdef CONFIG_X86_LOCAL_APIC
17857@@ -223,7 +223,7 @@ struct pv_apic_ops {
17858 unsigned long start_eip,
17859 unsigned long start_esp);
17860 #endif
17861-};
17862+} __no_const __no_randomize_layout;
17863
17864 struct pv_mmu_ops {
17865 unsigned long (*read_cr2)(void);
17866@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17867 struct paravirt_callee_save make_pud;
17868
17869 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17870+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17871 #endif /* PAGETABLE_LEVELS == 4 */
17872 #endif /* PAGETABLE_LEVELS >= 3 */
17873
17874@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17875 an mfn. We can tell which is which from the index. */
17876 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17877 phys_addr_t phys, pgprot_t flags);
17878-};
17879+
17880+#ifdef CONFIG_PAX_KERNEXEC
17881+ unsigned long (*pax_open_kernel)(void);
17882+ unsigned long (*pax_close_kernel)(void);
17883+#endif
17884+
17885+} __no_randomize_layout;
17886
17887 struct arch_spinlock;
17888 #ifdef CONFIG_SMP
17889@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17890 struct pv_lock_ops {
17891 struct paravirt_callee_save lock_spinning;
17892 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17893-};
17894+} __no_randomize_layout;
17895
17896 /* This contains all the paravirt structures: we get a convenient
17897 * number for each function using the offset which we use to indicate
17898- * what to patch. */
17899+ * what to patch.
17900+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17901+ */
17902+
17903 struct paravirt_patch_template {
17904 struct pv_init_ops pv_init_ops;
17905 struct pv_time_ops pv_time_ops;
17906@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17907 struct pv_apic_ops pv_apic_ops;
17908 struct pv_mmu_ops pv_mmu_ops;
17909 struct pv_lock_ops pv_lock_ops;
17910-};
17911+} __no_randomize_layout;
17912
17913 extern struct pv_info pv_info;
17914 extern struct pv_init_ops pv_init_ops;
17915diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17916index c4412e9..90e88c5 100644
17917--- a/arch/x86/include/asm/pgalloc.h
17918+++ b/arch/x86/include/asm/pgalloc.h
17919@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17920 pmd_t *pmd, pte_t *pte)
17921 {
17922 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17923+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17924+}
17925+
17926+static inline void pmd_populate_user(struct mm_struct *mm,
17927+ pmd_t *pmd, pte_t *pte)
17928+{
17929+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17930 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17931 }
17932
17933@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17934
17935 #ifdef CONFIG_X86_PAE
17936 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17937+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17938+{
17939+ pud_populate(mm, pudp, pmd);
17940+}
17941 #else /* !CONFIG_X86_PAE */
17942 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17943 {
17944 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17945 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17946 }
17947+
17948+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17949+{
17950+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17951+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17952+}
17953 #endif /* CONFIG_X86_PAE */
17954
17955 #if PAGETABLE_LEVELS > 3
17956@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17957 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17958 }
17959
17960+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17961+{
17962+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17963+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17964+}
17965+
17966 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17967 {
17968 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17969diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17970index 0d193e2..bf59aeb 100644
17971--- a/arch/x86/include/asm/pgtable-2level.h
17972+++ b/arch/x86/include/asm/pgtable-2level.h
17973@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17974
17975 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17976 {
17977+ pax_open_kernel();
17978 *pmdp = pmd;
17979+ pax_close_kernel();
17980 }
17981
17982 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17983diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17984index 81bb91b..9392125 100644
17985--- a/arch/x86/include/asm/pgtable-3level.h
17986+++ b/arch/x86/include/asm/pgtable-3level.h
17987@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17988
17989 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17990 {
17991+ pax_open_kernel();
17992 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17993+ pax_close_kernel();
17994 }
17995
17996 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17997 {
17998+ pax_open_kernel();
17999 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18000+ pax_close_kernel();
18001 }
18002
18003 /*
18004diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18005index bbc8b12..f228861 100644
18006--- a/arch/x86/include/asm/pgtable.h
18007+++ b/arch/x86/include/asm/pgtable.h
18008@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18009
18010 #ifndef __PAGETABLE_PUD_FOLDED
18011 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18012+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18013 #define pgd_clear(pgd) native_pgd_clear(pgd)
18014 #endif
18015
18016@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18017
18018 #define arch_end_context_switch(prev) do {} while(0)
18019
18020+#define pax_open_kernel() native_pax_open_kernel()
18021+#define pax_close_kernel() native_pax_close_kernel()
18022 #endif /* CONFIG_PARAVIRT */
18023
18024+#define __HAVE_ARCH_PAX_OPEN_KERNEL
18025+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18026+
18027+#ifdef CONFIG_PAX_KERNEXEC
18028+static inline unsigned long native_pax_open_kernel(void)
18029+{
18030+ unsigned long cr0;
18031+
18032+ preempt_disable();
18033+ barrier();
18034+ cr0 = read_cr0() ^ X86_CR0_WP;
18035+ BUG_ON(cr0 & X86_CR0_WP);
18036+ write_cr0(cr0);
18037+ return cr0 ^ X86_CR0_WP;
18038+}
18039+
18040+static inline unsigned long native_pax_close_kernel(void)
18041+{
18042+ unsigned long cr0;
18043+
18044+ cr0 = read_cr0() ^ X86_CR0_WP;
18045+ BUG_ON(!(cr0 & X86_CR0_WP));
18046+ write_cr0(cr0);
18047+ barrier();
18048+ preempt_enable_no_resched();
18049+ return cr0 ^ X86_CR0_WP;
18050+}
18051+#else
18052+static inline unsigned long native_pax_open_kernel(void) { return 0; }
18053+static inline unsigned long native_pax_close_kernel(void) { return 0; }
18054+#endif
18055+
18056 /*
18057 * The following only work if pte_present() is true.
18058 * Undefined behaviour if not..
18059 */
18060+static inline int pte_user(pte_t pte)
18061+{
18062+ return pte_val(pte) & _PAGE_USER;
18063+}
18064+
18065 static inline int pte_dirty(pte_t pte)
18066 {
18067 return pte_flags(pte) & _PAGE_DIRTY;
18068@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18069 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18070 }
18071
18072+static inline unsigned long pgd_pfn(pgd_t pgd)
18073+{
18074+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18075+}
18076+
18077 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18078
18079 static inline int pmd_large(pmd_t pte)
18080@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18081 return pte_clear_flags(pte, _PAGE_RW);
18082 }
18083
18084+static inline pte_t pte_mkread(pte_t pte)
18085+{
18086+ return __pte(pte_val(pte) | _PAGE_USER);
18087+}
18088+
18089 static inline pte_t pte_mkexec(pte_t pte)
18090 {
18091- return pte_clear_flags(pte, _PAGE_NX);
18092+#ifdef CONFIG_X86_PAE
18093+ if (__supported_pte_mask & _PAGE_NX)
18094+ return pte_clear_flags(pte, _PAGE_NX);
18095+ else
18096+#endif
18097+ return pte_set_flags(pte, _PAGE_USER);
18098+}
18099+
18100+static inline pte_t pte_exprotect(pte_t pte)
18101+{
18102+#ifdef CONFIG_X86_PAE
18103+ if (__supported_pte_mask & _PAGE_NX)
18104+ return pte_set_flags(pte, _PAGE_NX);
18105+ else
18106+#endif
18107+ return pte_clear_flags(pte, _PAGE_USER);
18108 }
18109
18110 static inline pte_t pte_mkdirty(pte_t pte)
18111@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18112 #endif
18113
18114 #ifndef __ASSEMBLY__
18115+
18116+#ifdef CONFIG_PAX_PER_CPU_PGD
18117+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18118+enum cpu_pgd_type {kernel = 0, user = 1};
18119+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18120+{
18121+ return cpu_pgd[cpu][type];
18122+}
18123+#endif
18124+
18125 #include <linux/mm_types.h>
18126 #include <linux/mmdebug.h>
18127 #include <linux/log2.h>
18128@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18129 * Currently stuck as a macro due to indirect forward reference to
18130 * linux/mmzone.h's __section_mem_map_addr() definition:
18131 */
18132-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18133+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18134
18135 /* Find an entry in the second-level page table.. */
18136 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18137@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18138 * Currently stuck as a macro due to indirect forward reference to
18139 * linux/mmzone.h's __section_mem_map_addr() definition:
18140 */
18141-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18142+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18143
18144 /* to find an entry in a page-table-directory. */
18145 static inline unsigned long pud_index(unsigned long address)
18146@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18147
18148 static inline int pgd_bad(pgd_t pgd)
18149 {
18150- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18151+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18152 }
18153
18154 static inline int pgd_none(pgd_t pgd)
18155@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
18156 * pgd_offset() returns a (pgd_t *)
18157 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18158 */
18159-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18160+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18161+
18162+#ifdef CONFIG_PAX_PER_CPU_PGD
18163+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18164+#endif
18165+
18166 /*
18167 * a shortcut which implies the use of the kernel's pgd, instead
18168 * of a process's
18169@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
18170 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18171 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18172
18173+#ifdef CONFIG_X86_32
18174+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18175+#else
18176+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18177+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18178+
18179+#ifdef CONFIG_PAX_MEMORY_UDEREF
18180+#ifdef __ASSEMBLY__
18181+#define pax_user_shadow_base pax_user_shadow_base(%rip)
18182+#else
18183+extern unsigned long pax_user_shadow_base;
18184+extern pgdval_t clone_pgd_mask;
18185+#endif
18186+#endif
18187+
18188+#endif
18189+
18190 #ifndef __ASSEMBLY__
18191
18192 extern int direct_gbpages;
18193@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18194 * dst and src can be on the same page, but the range must not overlap,
18195 * and must not cross a page boundary.
18196 */
18197-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18198+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18199 {
18200- memcpy(dst, src, count * sizeof(pgd_t));
18201+ pax_open_kernel();
18202+ while (count--)
18203+ *dst++ = *src++;
18204+ pax_close_kernel();
18205 }
18206
18207+#ifdef CONFIG_PAX_PER_CPU_PGD
18208+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18209+#endif
18210+
18211+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18212+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18213+#else
18214+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18215+#endif
18216+
18217 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18218 static inline int page_level_shift(enum pg_level level)
18219 {
18220diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18221index 9ee3221..b979c6b 100644
18222--- a/arch/x86/include/asm/pgtable_32.h
18223+++ b/arch/x86/include/asm/pgtable_32.h
18224@@ -25,9 +25,6 @@
18225 struct mm_struct;
18226 struct vm_area_struct;
18227
18228-extern pgd_t swapper_pg_dir[1024];
18229-extern pgd_t initial_page_table[1024];
18230-
18231 static inline void pgtable_cache_init(void) { }
18232 static inline void check_pgt_cache(void) { }
18233 void paging_init(void);
18234@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18235 # include <asm/pgtable-2level.h>
18236 #endif
18237
18238+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18239+extern pgd_t initial_page_table[PTRS_PER_PGD];
18240+#ifdef CONFIG_X86_PAE
18241+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18242+#endif
18243+
18244 #if defined(CONFIG_HIGHPTE)
18245 #define pte_offset_map(dir, address) \
18246 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18247@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18248 /* Clear a kernel PTE and flush it from the TLB */
18249 #define kpte_clear_flush(ptep, vaddr) \
18250 do { \
18251+ pax_open_kernel(); \
18252 pte_clear(&init_mm, (vaddr), (ptep)); \
18253+ pax_close_kernel(); \
18254 __flush_tlb_one((vaddr)); \
18255 } while (0)
18256
18257 #endif /* !__ASSEMBLY__ */
18258
18259+#define HAVE_ARCH_UNMAPPED_AREA
18260+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18261+
18262 /*
18263 * kern_addr_valid() is (1) for FLATMEM and (0) for
18264 * SPARSEMEM and DISCONTIGMEM
18265diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18266index ed5903b..c7fe163 100644
18267--- a/arch/x86/include/asm/pgtable_32_types.h
18268+++ b/arch/x86/include/asm/pgtable_32_types.h
18269@@ -8,7 +8,7 @@
18270 */
18271 #ifdef CONFIG_X86_PAE
18272 # include <asm/pgtable-3level_types.h>
18273-# define PMD_SIZE (1UL << PMD_SHIFT)
18274+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18275 # define PMD_MASK (~(PMD_SIZE - 1))
18276 #else
18277 # include <asm/pgtable-2level_types.h>
18278@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18279 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18280 #endif
18281
18282+#ifdef CONFIG_PAX_KERNEXEC
18283+#ifndef __ASSEMBLY__
18284+extern unsigned char MODULES_EXEC_VADDR[];
18285+extern unsigned char MODULES_EXEC_END[];
18286+#endif
18287+#include <asm/boot.h>
18288+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18289+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18290+#else
18291+#define ktla_ktva(addr) (addr)
18292+#define ktva_ktla(addr) (addr)
18293+#endif
18294+
18295 #define MODULES_VADDR VMALLOC_START
18296 #define MODULES_END VMALLOC_END
18297 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18298diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18299index e22c1db..23a625a 100644
18300--- a/arch/x86/include/asm/pgtable_64.h
18301+++ b/arch/x86/include/asm/pgtable_64.h
18302@@ -16,10 +16,14 @@
18303
18304 extern pud_t level3_kernel_pgt[512];
18305 extern pud_t level3_ident_pgt[512];
18306+extern pud_t level3_vmalloc_start_pgt[512];
18307+extern pud_t level3_vmalloc_end_pgt[512];
18308+extern pud_t level3_vmemmap_pgt[512];
18309+extern pud_t level2_vmemmap_pgt[512];
18310 extern pmd_t level2_kernel_pgt[512];
18311 extern pmd_t level2_fixmap_pgt[512];
18312-extern pmd_t level2_ident_pgt[512];
18313-extern pgd_t init_level4_pgt[];
18314+extern pmd_t level2_ident_pgt[512*2];
18315+extern pgd_t init_level4_pgt[512];
18316
18317 #define swapper_pg_dir init_level4_pgt
18318
18319@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18320
18321 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18322 {
18323+ pax_open_kernel();
18324 *pmdp = pmd;
18325+ pax_close_kernel();
18326 }
18327
18328 static inline void native_pmd_clear(pmd_t *pmd)
18329@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18330
18331 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18332 {
18333+ pax_open_kernel();
18334 *pudp = pud;
18335+ pax_close_kernel();
18336 }
18337
18338 static inline void native_pud_clear(pud_t *pud)
18339@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18340
18341 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18342 {
18343+ pax_open_kernel();
18344+ *pgdp = pgd;
18345+ pax_close_kernel();
18346+}
18347+
18348+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18349+{
18350 *pgdp = pgd;
18351 }
18352
18353diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18354index c883bf7..19970b3 100644
18355--- a/arch/x86/include/asm/pgtable_64_types.h
18356+++ b/arch/x86/include/asm/pgtable_64_types.h
18357@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
18358 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18359 #define MODULES_END _AC(0xffffffffff000000, UL)
18360 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18361+#define MODULES_EXEC_VADDR MODULES_VADDR
18362+#define MODULES_EXEC_END MODULES_END
18363+
18364+#define ktla_ktva(addr) (addr)
18365+#define ktva_ktla(addr) (addr)
18366
18367 #define EARLY_DYNAMIC_PAGE_TABLES 64
18368
18369diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18370index 94e40f1..ebd03e4 100644
18371--- a/arch/x86/include/asm/pgtable_types.h
18372+++ b/arch/x86/include/asm/pgtable_types.h
18373@@ -16,13 +16,12 @@
18374 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18375 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18376 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18377-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18378+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18379 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18380 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18381 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18382-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18383-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18384-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18385+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18386+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18387 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18388
18389 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18390@@ -40,7 +39,6 @@
18391 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18392 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18393 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18394-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18395 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18396 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18397 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18398@@ -87,8 +85,10 @@
18399
18400 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18401 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18402-#else
18403+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18404 #define _PAGE_NX (_AT(pteval_t, 0))
18405+#else
18406+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18407 #endif
18408
18409 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18410@@ -147,6 +147,9 @@
18411 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18412 _PAGE_ACCESSED)
18413
18414+#define PAGE_READONLY_NOEXEC PAGE_READONLY
18415+#define PAGE_SHARED_NOEXEC PAGE_SHARED
18416+
18417 #define __PAGE_KERNEL_EXEC \
18418 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18419 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18420@@ -157,7 +160,7 @@
18421 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18422 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18423 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18424-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18425+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18426 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18427 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18428 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18429@@ -219,8 +222,8 @@
18430 * bits are combined, this will alow user to access the high address mapped
18431 * VDSO in the presence of CONFIG_COMPAT_VDSO
18432 */
18433-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18434-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
18435+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18436+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18437 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18438 #endif
18439
18440@@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18441 {
18442 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18443 }
18444+#endif
18445
18446+#if PAGETABLE_LEVELS == 3
18447+#include <asm-generic/pgtable-nopud.h>
18448+#endif
18449+
18450+#if PAGETABLE_LEVELS == 2
18451+#include <asm-generic/pgtable-nopmd.h>
18452+#endif
18453+
18454+#ifndef __ASSEMBLY__
18455 #if PAGETABLE_LEVELS > 3
18456 typedef struct { pudval_t pud; } pud_t;
18457
18458@@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18459 return pud.pud;
18460 }
18461 #else
18462-#include <asm-generic/pgtable-nopud.h>
18463-
18464 static inline pudval_t native_pud_val(pud_t pud)
18465 {
18466 return native_pgd_val(pud.pgd);
18467@@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18468 return pmd.pmd;
18469 }
18470 #else
18471-#include <asm-generic/pgtable-nopmd.h>
18472-
18473 static inline pmdval_t native_pmd_val(pmd_t pmd)
18474 {
18475 return native_pgd_val(pmd.pud.pgd);
18476@@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
18477
18478 extern pteval_t __supported_pte_mask;
18479 extern void set_nx(void);
18480-extern int nx_enabled;
18481
18482 #define pgprot_writecombine pgprot_writecombine
18483 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18484diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18485index b39e194..9d44fd1 100644
18486--- a/arch/x86/include/asm/preempt.h
18487+++ b/arch/x86/include/asm/preempt.h
18488@@ -99,7 +99,7 @@ static __always_inline void __preempt_count_sub(int val)
18489 */
18490 static __always_inline bool __preempt_count_dec_and_test(void)
18491 {
18492- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18493+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18494 }
18495
18496 /*
18497diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18498index fdedd38..95c02c2 100644
18499--- a/arch/x86/include/asm/processor.h
18500+++ b/arch/x86/include/asm/processor.h
18501@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18502 /* Index into per_cpu list: */
18503 u16 cpu_index;
18504 u32 microcode;
18505-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18506+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18507
18508 #define X86_VENDOR_INTEL 0
18509 #define X86_VENDOR_CYRIX 1
18510@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18511 : "memory");
18512 }
18513
18514+/* invpcid (%rdx),%rax */
18515+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18516+
18517+#define INVPCID_SINGLE_ADDRESS 0UL
18518+#define INVPCID_SINGLE_CONTEXT 1UL
18519+#define INVPCID_ALL_GLOBAL 2UL
18520+#define INVPCID_ALL_MONGLOBAL 3UL
18521+
18522+#define PCID_KERNEL 0UL
18523+#define PCID_USER 1UL
18524+#define PCID_NOFLUSH (1UL << 63)
18525+
18526 static inline void load_cr3(pgd_t *pgdir)
18527 {
18528- write_cr3(__pa(pgdir));
18529+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18530 }
18531
18532 #ifdef CONFIG_X86_32
18533@@ -283,7 +295,7 @@ struct tss_struct {
18534
18535 } ____cacheline_aligned;
18536
18537-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18538+extern struct tss_struct init_tss[NR_CPUS];
18539
18540 /*
18541 * Save the original ist values for checking stack pointers during debugging
18542@@ -470,6 +482,7 @@ struct thread_struct {
18543 unsigned short ds;
18544 unsigned short fsindex;
18545 unsigned short gsindex;
18546+ unsigned short ss;
18547 #endif
18548 #ifdef CONFIG_X86_32
18549 unsigned long ip;
18550@@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
18551 extern unsigned long mmu_cr4_features;
18552 extern u32 *trampoline_cr4_features;
18553
18554-static inline void set_in_cr4(unsigned long mask)
18555-{
18556- unsigned long cr4;
18557-
18558- mmu_cr4_features |= mask;
18559- if (trampoline_cr4_features)
18560- *trampoline_cr4_features = mmu_cr4_features;
18561- cr4 = read_cr4();
18562- cr4 |= mask;
18563- write_cr4(cr4);
18564-}
18565-
18566-static inline void clear_in_cr4(unsigned long mask)
18567-{
18568- unsigned long cr4;
18569-
18570- mmu_cr4_features &= ~mask;
18571- if (trampoline_cr4_features)
18572- *trampoline_cr4_features = mmu_cr4_features;
18573- cr4 = read_cr4();
18574- cr4 &= ~mask;
18575- write_cr4(cr4);
18576-}
18577+extern void set_in_cr4(unsigned long mask);
18578+extern void clear_in_cr4(unsigned long mask);
18579
18580 typedef struct {
18581 unsigned long seg;
18582@@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
18583 */
18584 #define TASK_SIZE PAGE_OFFSET
18585 #define TASK_SIZE_MAX TASK_SIZE
18586+
18587+#ifdef CONFIG_PAX_SEGMEXEC
18588+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18589+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18590+#else
18591 #define STACK_TOP TASK_SIZE
18592-#define STACK_TOP_MAX STACK_TOP
18593+#endif
18594+
18595+#define STACK_TOP_MAX TASK_SIZE
18596
18597 #define INIT_THREAD { \
18598- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18599+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18600 .vm86_info = NULL, \
18601 .sysenter_cs = __KERNEL_CS, \
18602 .io_bitmap_ptr = NULL, \
18603@@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
18604 */
18605 #define INIT_TSS { \
18606 .x86_tss = { \
18607- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18608+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18609 .ss0 = __KERNEL_DS, \
18610 .ss1 = __KERNEL_CS, \
18611 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18612@@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
18613 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18614
18615 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18616-#define KSTK_TOP(info) \
18617-({ \
18618- unsigned long *__ptr = (unsigned long *)(info); \
18619- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18620-})
18621+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18622
18623 /*
18624 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18625@@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18626 #define task_pt_regs(task) \
18627 ({ \
18628 struct pt_regs *__regs__; \
18629- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18630+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18631 __regs__ - 1; \
18632 })
18633
18634@@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18635 /*
18636 * User space process size. 47bits minus one guard page.
18637 */
18638-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18639+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18640
18641 /* This decides where the kernel will search for a free chunk of vm
18642 * space during mmap's.
18643 */
18644 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18645- 0xc0000000 : 0xFFFFe000)
18646+ 0xc0000000 : 0xFFFFf000)
18647
18648 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18649 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18650@@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18651 #define STACK_TOP_MAX TASK_SIZE_MAX
18652
18653 #define INIT_THREAD { \
18654- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18655+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18656 }
18657
18658 #define INIT_TSS { \
18659- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18660+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18661 }
18662
18663 /*
18664@@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18665 */
18666 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18667
18668+#ifdef CONFIG_PAX_SEGMEXEC
18669+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18670+#endif
18671+
18672 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18673
18674 /* Get/set a process' ability to use the timestamp counter instruction */
18675@@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18676 return 0;
18677 }
18678
18679-extern unsigned long arch_align_stack(unsigned long sp);
18680+#define arch_align_stack(x) ((x) & ~0xfUL)
18681 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18682
18683 void default_idle(void);
18684@@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
18685 #define xen_set_default_idle 0
18686 #endif
18687
18688-void stop_this_cpu(void *dummy);
18689+void stop_this_cpu(void *dummy) __noreturn;
18690 void df_debug(struct pt_regs *regs, long error_code);
18691 #endif /* _ASM_X86_PROCESSOR_H */
18692diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18693index 14fd6fd..6740420 100644
18694--- a/arch/x86/include/asm/ptrace.h
18695+++ b/arch/x86/include/asm/ptrace.h
18696@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18697 }
18698
18699 /*
18700- * user_mode_vm(regs) determines whether a register set came from user mode.
18701+ * user_mode(regs) determines whether a register set came from user mode.
18702 * This is true if V8086 mode was enabled OR if the register set was from
18703 * protected mode with RPL-3 CS value. This tricky test checks that with
18704 * one comparison. Many places in the kernel can bypass this full check
18705- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18706+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18707+ * be used.
18708 */
18709-static inline int user_mode(struct pt_regs *regs)
18710+static inline int user_mode_novm(struct pt_regs *regs)
18711 {
18712 #ifdef CONFIG_X86_32
18713 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18714 #else
18715- return !!(regs->cs & 3);
18716+ return !!(regs->cs & SEGMENT_RPL_MASK);
18717 #endif
18718 }
18719
18720-static inline int user_mode_vm(struct pt_regs *regs)
18721+static inline int user_mode(struct pt_regs *regs)
18722 {
18723 #ifdef CONFIG_X86_32
18724 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18725 USER_RPL;
18726 #else
18727- return user_mode(regs);
18728+ return user_mode_novm(regs);
18729 #endif
18730 }
18731
18732@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18733 #ifdef CONFIG_X86_64
18734 static inline bool user_64bit_mode(struct pt_regs *regs)
18735 {
18736+ unsigned long cs = regs->cs & 0xffff;
18737 #ifndef CONFIG_PARAVIRT
18738 /*
18739 * On non-paravirt systems, this is the only long mode CPL 3
18740 * selector. We do not allow long mode selectors in the LDT.
18741 */
18742- return regs->cs == __USER_CS;
18743+ return cs == __USER_CS;
18744 #else
18745 /* Headers are too twisted for this to go in paravirt.h. */
18746- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18747+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18748 #endif
18749 }
18750
18751@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18752 * Traps from the kernel do not save sp and ss.
18753 * Use the helper function to retrieve sp.
18754 */
18755- if (offset == offsetof(struct pt_regs, sp) &&
18756- regs->cs == __KERNEL_CS)
18757- return kernel_stack_pointer(regs);
18758+ if (offset == offsetof(struct pt_regs, sp)) {
18759+ unsigned long cs = regs->cs & 0xffff;
18760+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18761+ return kernel_stack_pointer(regs);
18762+ }
18763 #endif
18764 return *(unsigned long *)((unsigned long)regs + offset);
18765 }
18766diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18767index 9c6b890..5305f53 100644
18768--- a/arch/x86/include/asm/realmode.h
18769+++ b/arch/x86/include/asm/realmode.h
18770@@ -22,16 +22,14 @@ struct real_mode_header {
18771 #endif
18772 /* APM/BIOS reboot */
18773 u32 machine_real_restart_asm;
18774-#ifdef CONFIG_X86_64
18775 u32 machine_real_restart_seg;
18776-#endif
18777 };
18778
18779 /* This must match data at trampoline_32/64.S */
18780 struct trampoline_header {
18781 #ifdef CONFIG_X86_32
18782 u32 start;
18783- u16 gdt_pad;
18784+ u16 boot_cs;
18785 u16 gdt_limit;
18786 u32 gdt_base;
18787 #else
18788diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18789index a82c4f1..ac45053 100644
18790--- a/arch/x86/include/asm/reboot.h
18791+++ b/arch/x86/include/asm/reboot.h
18792@@ -6,13 +6,13 @@
18793 struct pt_regs;
18794
18795 struct machine_ops {
18796- void (*restart)(char *cmd);
18797- void (*halt)(void);
18798- void (*power_off)(void);
18799+ void (* __noreturn restart)(char *cmd);
18800+ void (* __noreturn halt)(void);
18801+ void (* __noreturn power_off)(void);
18802 void (*shutdown)(void);
18803 void (*crash_shutdown)(struct pt_regs *);
18804- void (*emergency_restart)(void);
18805-};
18806+ void (* __noreturn emergency_restart)(void);
18807+} __no_const;
18808
18809 extern struct machine_ops machine_ops;
18810
18811diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18812index 8f7866a..e442f20 100644
18813--- a/arch/x86/include/asm/rmwcc.h
18814+++ b/arch/x86/include/asm/rmwcc.h
18815@@ -3,7 +3,34 @@
18816
18817 #ifdef CC_HAVE_ASM_GOTO
18818
18819-#define __GEN_RMWcc(fullop, var, cc, ...) \
18820+#ifdef CONFIG_PAX_REFCOUNT
18821+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18822+do { \
18823+ asm_volatile_goto (fullop \
18824+ ";jno 0f\n" \
18825+ fullantiop \
18826+ ";int $4\n0:\n" \
18827+ _ASM_EXTABLE(0b, 0b) \
18828+ ";j" cc " %l[cc_label]" \
18829+ : : "m" (var), ## __VA_ARGS__ \
18830+ : "memory" : cc_label); \
18831+ return 0; \
18832+cc_label: \
18833+ return 1; \
18834+} while (0)
18835+#else
18836+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18837+do { \
18838+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18839+ : : "m" (var), ## __VA_ARGS__ \
18840+ : "memory" : cc_label); \
18841+ return 0; \
18842+cc_label: \
18843+ return 1; \
18844+} while (0)
18845+#endif
18846+
18847+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18848 do { \
18849 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18850 : : "m" (var), ## __VA_ARGS__ \
18851@@ -13,15 +40,46 @@ cc_label: \
18852 return 1; \
18853 } while (0)
18854
18855-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18856- __GEN_RMWcc(op " " arg0, var, cc)
18857+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18858+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18859
18860-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18861- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18862+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18863+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18864+
18865+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18866+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18867+
18868+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18869+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18870
18871 #else /* !CC_HAVE_ASM_GOTO */
18872
18873-#define __GEN_RMWcc(fullop, var, cc, ...) \
18874+#ifdef CONFIG_PAX_REFCOUNT
18875+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18876+do { \
18877+ char c; \
18878+ asm volatile (fullop \
18879+ ";jno 0f\n" \
18880+ fullantiop \
18881+ ";int $4\n0:\n" \
18882+ _ASM_EXTABLE(0b, 0b) \
18883+ "; set" cc " %1" \
18884+ : "+m" (var), "=qm" (c) \
18885+ : __VA_ARGS__ : "memory"); \
18886+ return c != 0; \
18887+} while (0)
18888+#else
18889+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18890+do { \
18891+ char c; \
18892+ asm volatile (fullop "; set" cc " %1" \
18893+ : "+m" (var), "=qm" (c) \
18894+ : __VA_ARGS__ : "memory"); \
18895+ return c != 0; \
18896+} while (0)
18897+#endif
18898+
18899+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18900 do { \
18901 char c; \
18902 asm volatile (fullop "; set" cc " %1" \
18903@@ -30,11 +88,17 @@ do { \
18904 return c != 0; \
18905 } while (0)
18906
18907-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18908- __GEN_RMWcc(op " " arg0, var, cc)
18909+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18910+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18911+
18912+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18913+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18914+
18915+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18916+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18917
18918-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18919- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18920+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18921+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18922
18923 #endif /* CC_HAVE_ASM_GOTO */
18924
18925diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18926index cad82c9..2e5c5c1 100644
18927--- a/arch/x86/include/asm/rwsem.h
18928+++ b/arch/x86/include/asm/rwsem.h
18929@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18930 {
18931 asm volatile("# beginning down_read\n\t"
18932 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18933+
18934+#ifdef CONFIG_PAX_REFCOUNT
18935+ "jno 0f\n"
18936+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18937+ "int $4\n0:\n"
18938+ _ASM_EXTABLE(0b, 0b)
18939+#endif
18940+
18941 /* adds 0x00000001 */
18942 " jns 1f\n"
18943 " call call_rwsem_down_read_failed\n"
18944@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18945 "1:\n\t"
18946 " mov %1,%2\n\t"
18947 " add %3,%2\n\t"
18948+
18949+#ifdef CONFIG_PAX_REFCOUNT
18950+ "jno 0f\n"
18951+ "sub %3,%2\n"
18952+ "int $4\n0:\n"
18953+ _ASM_EXTABLE(0b, 0b)
18954+#endif
18955+
18956 " jle 2f\n\t"
18957 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18958 " jnz 1b\n\t"
18959@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18960 long tmp;
18961 asm volatile("# beginning down_write\n\t"
18962 LOCK_PREFIX " xadd %1,(%2)\n\t"
18963+
18964+#ifdef CONFIG_PAX_REFCOUNT
18965+ "jno 0f\n"
18966+ "mov %1,(%2)\n"
18967+ "int $4\n0:\n"
18968+ _ASM_EXTABLE(0b, 0b)
18969+#endif
18970+
18971 /* adds 0xffff0001, returns the old value */
18972 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18973 /* was the active mask 0 before? */
18974@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18975 long tmp;
18976 asm volatile("# beginning __up_read\n\t"
18977 LOCK_PREFIX " xadd %1,(%2)\n\t"
18978+
18979+#ifdef CONFIG_PAX_REFCOUNT
18980+ "jno 0f\n"
18981+ "mov %1,(%2)\n"
18982+ "int $4\n0:\n"
18983+ _ASM_EXTABLE(0b, 0b)
18984+#endif
18985+
18986 /* subtracts 1, returns the old value */
18987 " jns 1f\n\t"
18988 " call call_rwsem_wake\n" /* expects old value in %edx */
18989@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18990 long tmp;
18991 asm volatile("# beginning __up_write\n\t"
18992 LOCK_PREFIX " xadd %1,(%2)\n\t"
18993+
18994+#ifdef CONFIG_PAX_REFCOUNT
18995+ "jno 0f\n"
18996+ "mov %1,(%2)\n"
18997+ "int $4\n0:\n"
18998+ _ASM_EXTABLE(0b, 0b)
18999+#endif
19000+
19001 /* subtracts 0xffff0001, returns the old value */
19002 " jns 1f\n\t"
19003 " call call_rwsem_wake\n" /* expects old value in %edx */
19004@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19005 {
19006 asm volatile("# beginning __downgrade_write\n\t"
19007 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19008+
19009+#ifdef CONFIG_PAX_REFCOUNT
19010+ "jno 0f\n"
19011+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19012+ "int $4\n0:\n"
19013+ _ASM_EXTABLE(0b, 0b)
19014+#endif
19015+
19016 /*
19017 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19018 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19019@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19020 */
19021 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19022 {
19023- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19024+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19025+
19026+#ifdef CONFIG_PAX_REFCOUNT
19027+ "jno 0f\n"
19028+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
19029+ "int $4\n0:\n"
19030+ _ASM_EXTABLE(0b, 0b)
19031+#endif
19032+
19033 : "+m" (sem->count)
19034 : "er" (delta));
19035 }
19036@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19037 */
19038 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19039 {
19040- return delta + xadd(&sem->count, delta);
19041+ return delta + xadd_check_overflow(&sem->count, delta);
19042 }
19043
19044 #endif /* __KERNEL__ */
19045diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19046index 6f1c3a8..7744f19 100644
19047--- a/arch/x86/include/asm/segment.h
19048+++ b/arch/x86/include/asm/segment.h
19049@@ -64,10 +64,15 @@
19050 * 26 - ESPFIX small SS
19051 * 27 - per-cpu [ offset to per-cpu data area ]
19052 * 28 - stack_canary-20 [ for stack protector ]
19053- * 29 - unused
19054- * 30 - unused
19055+ * 29 - PCI BIOS CS
19056+ * 30 - PCI BIOS DS
19057 * 31 - TSS for double fault handler
19058 */
19059+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19060+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19061+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19062+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19063+
19064 #define GDT_ENTRY_TLS_MIN 6
19065 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19066
19067@@ -79,6 +84,8 @@
19068
19069 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19070
19071+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19072+
19073 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19074
19075 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19076@@ -104,6 +111,12 @@
19077 #define __KERNEL_STACK_CANARY 0
19078 #endif
19079
19080+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19081+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19082+
19083+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19084+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19085+
19086 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19087
19088 /*
19089@@ -141,7 +154,7 @@
19090 */
19091
19092 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19093-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19094+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19095
19096
19097 #else
19098@@ -165,6 +178,8 @@
19099 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19100 #define __USER32_DS __USER_DS
19101
19102+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19103+
19104 #define GDT_ENTRY_TSS 8 /* needs two entries */
19105 #define GDT_ENTRY_LDT 10 /* needs two entries */
19106 #define GDT_ENTRY_TLS_MIN 12
19107@@ -173,6 +188,8 @@
19108 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19109 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19110
19111+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19112+
19113 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19114 #define FS_TLS 0
19115 #define GS_TLS 1
19116@@ -180,12 +197,14 @@
19117 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19118 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19119
19120-#define GDT_ENTRIES 16
19121+#define GDT_ENTRIES 17
19122
19123 #endif
19124
19125 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19126+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19127 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19128+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19129 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19130 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19131 #ifndef CONFIG_PARAVIRT
19132@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19133 {
19134 unsigned long __limit;
19135 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19136- return __limit + 1;
19137+ return __limit;
19138 }
19139
19140 #endif /* !__ASSEMBLY__ */
19141diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19142index 8d3120f..352b440 100644
19143--- a/arch/x86/include/asm/smap.h
19144+++ b/arch/x86/include/asm/smap.h
19145@@ -25,11 +25,40 @@
19146
19147 #include <asm/alternative-asm.h>
19148
19149+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19150+#define ASM_PAX_OPEN_USERLAND \
19151+ 661: jmp 663f; \
19152+ .pushsection .altinstr_replacement, "a" ; \
19153+ 662: pushq %rax; nop; \
19154+ .popsection ; \
19155+ .pushsection .altinstructions, "a" ; \
19156+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19157+ .popsection ; \
19158+ call __pax_open_userland; \
19159+ popq %rax; \
19160+ 663:
19161+
19162+#define ASM_PAX_CLOSE_USERLAND \
19163+ 661: jmp 663f; \
19164+ .pushsection .altinstr_replacement, "a" ; \
19165+ 662: pushq %rax; nop; \
19166+ .popsection; \
19167+ .pushsection .altinstructions, "a" ; \
19168+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19169+ .popsection; \
19170+ call __pax_close_userland; \
19171+ popq %rax; \
19172+ 663:
19173+#else
19174+#define ASM_PAX_OPEN_USERLAND
19175+#define ASM_PAX_CLOSE_USERLAND
19176+#endif
19177+
19178 #ifdef CONFIG_X86_SMAP
19179
19180 #define ASM_CLAC \
19181 661: ASM_NOP3 ; \
19182- .pushsection .altinstr_replacement, "ax" ; \
19183+ .pushsection .altinstr_replacement, "a" ; \
19184 662: __ASM_CLAC ; \
19185 .popsection ; \
19186 .pushsection .altinstructions, "a" ; \
19187@@ -38,7 +67,7 @@
19188
19189 #define ASM_STAC \
19190 661: ASM_NOP3 ; \
19191- .pushsection .altinstr_replacement, "ax" ; \
19192+ .pushsection .altinstr_replacement, "a" ; \
19193 662: __ASM_STAC ; \
19194 .popsection ; \
19195 .pushsection .altinstructions, "a" ; \
19196@@ -56,6 +85,37 @@
19197
19198 #include <asm/alternative.h>
19199
19200+#define __HAVE_ARCH_PAX_OPEN_USERLAND
19201+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19202+
19203+extern void __pax_open_userland(void);
19204+static __always_inline unsigned long pax_open_userland(void)
19205+{
19206+
19207+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19208+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19209+ :
19210+ : [open] "i" (__pax_open_userland)
19211+ : "memory", "rax");
19212+#endif
19213+
19214+ return 0;
19215+}
19216+
19217+extern void __pax_close_userland(void);
19218+static __always_inline unsigned long pax_close_userland(void)
19219+{
19220+
19221+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19222+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19223+ :
19224+ : [close] "i" (__pax_close_userland)
19225+ : "memory", "rax");
19226+#endif
19227+
19228+ return 0;
19229+}
19230+
19231 #ifdef CONFIG_X86_SMAP
19232
19233 static __always_inline void clac(void)
19234diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19235index 8cd27e0..7f05ec8 100644
19236--- a/arch/x86/include/asm/smp.h
19237+++ b/arch/x86/include/asm/smp.h
19238@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19239 /* cpus sharing the last level cache: */
19240 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19241 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19242-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19243+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19244
19245 static inline struct cpumask *cpu_sibling_mask(int cpu)
19246 {
19247@@ -78,7 +78,7 @@ struct smp_ops {
19248
19249 void (*send_call_func_ipi)(const struct cpumask *mask);
19250 void (*send_call_func_single_ipi)(int cpu);
19251-};
19252+} __no_const;
19253
19254 /* Globals due to paravirt */
19255 extern void set_cpu_sibling_map(int cpu);
19256@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19257 extern int safe_smp_processor_id(void);
19258
19259 #elif defined(CONFIG_X86_64_SMP)
19260-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19261-
19262-#define stack_smp_processor_id() \
19263-({ \
19264- struct thread_info *ti; \
19265- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19266- ti->cpu; \
19267-})
19268+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19269+#define stack_smp_processor_id() raw_smp_processor_id()
19270 #define safe_smp_processor_id() smp_processor_id()
19271
19272 #endif
19273diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19274index 0f62f54..cb5d0dd 100644
19275--- a/arch/x86/include/asm/spinlock.h
19276+++ b/arch/x86/include/asm/spinlock.h
19277@@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19278 static inline void arch_read_lock(arch_rwlock_t *rw)
19279 {
19280 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19281+
19282+#ifdef CONFIG_PAX_REFCOUNT
19283+ "jno 0f\n"
19284+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19285+ "int $4\n0:\n"
19286+ _ASM_EXTABLE(0b, 0b)
19287+#endif
19288+
19289 "jns 1f\n"
19290 "call __read_lock_failed\n\t"
19291 "1:\n"
19292@@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19293 static inline void arch_write_lock(arch_rwlock_t *rw)
19294 {
19295 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19296+
19297+#ifdef CONFIG_PAX_REFCOUNT
19298+ "jno 0f\n"
19299+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19300+ "int $4\n0:\n"
19301+ _ASM_EXTABLE(0b, 0b)
19302+#endif
19303+
19304 "jz 1f\n"
19305 "call __write_lock_failed\n\t"
19306 "1:\n"
19307@@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19308
19309 static inline void arch_read_unlock(arch_rwlock_t *rw)
19310 {
19311- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19312+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19313+
19314+#ifdef CONFIG_PAX_REFCOUNT
19315+ "jno 0f\n"
19316+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19317+ "int $4\n0:\n"
19318+ _ASM_EXTABLE(0b, 0b)
19319+#endif
19320+
19321 :"+m" (rw->lock) : : "memory");
19322 }
19323
19324 static inline void arch_write_unlock(arch_rwlock_t *rw)
19325 {
19326- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19327+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19328+
19329+#ifdef CONFIG_PAX_REFCOUNT
19330+ "jno 0f\n"
19331+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19332+ "int $4\n0:\n"
19333+ _ASM_EXTABLE(0b, 0b)
19334+#endif
19335+
19336 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19337 }
19338
19339diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19340index 6a99859..03cb807 100644
19341--- a/arch/x86/include/asm/stackprotector.h
19342+++ b/arch/x86/include/asm/stackprotector.h
19343@@ -47,7 +47,7 @@
19344 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19345 */
19346 #define GDT_STACK_CANARY_INIT \
19347- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19348+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19349
19350 /*
19351 * Initialize the stackprotector canary value.
19352@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19353
19354 static inline void load_stack_canary_segment(void)
19355 {
19356-#ifdef CONFIG_X86_32
19357+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19358 asm volatile ("mov %0, %%gs" : : "r" (0));
19359 #endif
19360 }
19361diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19362index 70bbe39..4ae2bd4 100644
19363--- a/arch/x86/include/asm/stacktrace.h
19364+++ b/arch/x86/include/asm/stacktrace.h
19365@@ -11,28 +11,20 @@
19366
19367 extern int kstack_depth_to_print;
19368
19369-struct thread_info;
19370+struct task_struct;
19371 struct stacktrace_ops;
19372
19373-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19374- unsigned long *stack,
19375- unsigned long bp,
19376- const struct stacktrace_ops *ops,
19377- void *data,
19378- unsigned long *end,
19379- int *graph);
19380+typedef unsigned long walk_stack_t(struct task_struct *task,
19381+ void *stack_start,
19382+ unsigned long *stack,
19383+ unsigned long bp,
19384+ const struct stacktrace_ops *ops,
19385+ void *data,
19386+ unsigned long *end,
19387+ int *graph);
19388
19389-extern unsigned long
19390-print_context_stack(struct thread_info *tinfo,
19391- unsigned long *stack, unsigned long bp,
19392- const struct stacktrace_ops *ops, void *data,
19393- unsigned long *end, int *graph);
19394-
19395-extern unsigned long
19396-print_context_stack_bp(struct thread_info *tinfo,
19397- unsigned long *stack, unsigned long bp,
19398- const struct stacktrace_ops *ops, void *data,
19399- unsigned long *end, int *graph);
19400+extern walk_stack_t print_context_stack;
19401+extern walk_stack_t print_context_stack_bp;
19402
19403 /* Generic stack tracer with callbacks */
19404
19405@@ -40,7 +32,7 @@ struct stacktrace_ops {
19406 void (*address)(void *data, unsigned long address, int reliable);
19407 /* On negative return stop dumping */
19408 int (*stack)(void *data, char *name);
19409- walk_stack_t walk_stack;
19410+ walk_stack_t *walk_stack;
19411 };
19412
19413 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19414diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19415index d7f3b3b..3cc39f1 100644
19416--- a/arch/x86/include/asm/switch_to.h
19417+++ b/arch/x86/include/asm/switch_to.h
19418@@ -108,7 +108,7 @@ do { \
19419 "call __switch_to\n\t" \
19420 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19421 __switch_canary \
19422- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19423+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19424 "movq %%rax,%%rdi\n\t" \
19425 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19426 "jnz ret_from_fork\n\t" \
19427@@ -119,7 +119,7 @@ do { \
19428 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19429 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19430 [_tif_fork] "i" (_TIF_FORK), \
19431- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19432+ [thread_info] "m" (current_tinfo), \
19433 [current_task] "m" (current_task) \
19434 __switch_canary_iparam \
19435 : "memory", "cc" __EXTRA_CLOBBER)
19436diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19437index e1940c0..ac50dd8 100644
19438--- a/arch/x86/include/asm/thread_info.h
19439+++ b/arch/x86/include/asm/thread_info.h
19440@@ -10,6 +10,7 @@
19441 #include <linux/compiler.h>
19442 #include <asm/page.h>
19443 #include <asm/types.h>
19444+#include <asm/percpu.h>
19445
19446 /*
19447 * low level task data that entry.S needs immediate access to
19448@@ -23,7 +24,6 @@ struct exec_domain;
19449 #include <linux/atomic.h>
19450
19451 struct thread_info {
19452- struct task_struct *task; /* main task structure */
19453 struct exec_domain *exec_domain; /* execution domain */
19454 __u32 flags; /* low level flags */
19455 __u32 status; /* thread synchronous flags */
19456@@ -32,19 +32,13 @@ struct thread_info {
19457 mm_segment_t addr_limit;
19458 struct restart_block restart_block;
19459 void __user *sysenter_return;
19460-#ifdef CONFIG_X86_32
19461- unsigned long previous_esp; /* ESP of the previous stack in
19462- case of nested (IRQ) stacks
19463- */
19464- __u8 supervisor_stack[0];
19465-#endif
19466+ unsigned long lowest_stack;
19467 unsigned int sig_on_uaccess_error:1;
19468 unsigned int uaccess_err:1; /* uaccess failed */
19469 };
19470
19471-#define INIT_THREAD_INFO(tsk) \
19472+#define INIT_THREAD_INFO \
19473 { \
19474- .task = &tsk, \
19475 .exec_domain = &default_exec_domain, \
19476 .flags = 0, \
19477 .cpu = 0, \
19478@@ -55,7 +49,7 @@ struct thread_info {
19479 }, \
19480 }
19481
19482-#define init_thread_info (init_thread_union.thread_info)
19483+#define init_thread_info (init_thread_union.stack)
19484 #define init_stack (init_thread_union.stack)
19485
19486 #else /* !__ASSEMBLY__ */
19487@@ -95,6 +89,7 @@ struct thread_info {
19488 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19489 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19490 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19491+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19492
19493 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19494 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19495@@ -118,17 +113,18 @@ struct thread_info {
19496 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19497 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19498 #define _TIF_X32 (1 << TIF_X32)
19499+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19500
19501 /* work to do in syscall_trace_enter() */
19502 #define _TIF_WORK_SYSCALL_ENTRY \
19503 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19504 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19505- _TIF_NOHZ)
19506+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19507
19508 /* work to do in syscall_trace_leave() */
19509 #define _TIF_WORK_SYSCALL_EXIT \
19510 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19511- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19512+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19513
19514 /* work to do on interrupt/exception return */
19515 #define _TIF_WORK_MASK \
19516@@ -139,7 +135,7 @@ struct thread_info {
19517 /* work to do on any return to user space */
19518 #define _TIF_ALLWORK_MASK \
19519 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19520- _TIF_NOHZ)
19521+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19522
19523 /* Only used for 64 bit */
19524 #define _TIF_DO_NOTIFY_MASK \
19525@@ -153,6 +149,23 @@ struct thread_info {
19526 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19527 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19528
19529+#ifdef __ASSEMBLY__
19530+/* how to get the thread information struct from ASM */
19531+#define GET_THREAD_INFO(reg) \
19532+ mov PER_CPU_VAR(current_tinfo), reg
19533+
19534+/* use this one if reg already contains %esp */
19535+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19536+#else
19537+/* how to get the thread information struct from C */
19538+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19539+
19540+static __always_inline struct thread_info *current_thread_info(void)
19541+{
19542+ return this_cpu_read_stable(current_tinfo);
19543+}
19544+#endif
19545+
19546 #ifdef CONFIG_X86_32
19547
19548 #define STACK_WARN (THREAD_SIZE/8)
19549@@ -169,31 +182,10 @@ struct thread_info {
19550 sp; \
19551 })
19552
19553-/* how to get the thread information struct from C */
19554-static inline struct thread_info *current_thread_info(void)
19555-{
19556- return (struct thread_info *)
19557- (current_stack_pointer & ~(THREAD_SIZE - 1));
19558-}
19559-
19560-#else /* !__ASSEMBLY__ */
19561-
19562-/* how to get the thread information struct from ASM */
19563-#define GET_THREAD_INFO(reg) \
19564- movl $-THREAD_SIZE, reg; \
19565- andl %esp, reg
19566-
19567-/* use this one if reg already contains %esp */
19568-#define GET_THREAD_INFO_WITH_ESP(reg) \
19569- andl $-THREAD_SIZE, reg
19570-
19571 #endif
19572
19573 #else /* X86_32 */
19574
19575-#include <asm/percpu.h>
19576-#define KERNEL_STACK_OFFSET (5*8)
19577-
19578 /*
19579 * macros/functions for gaining access to the thread information structure
19580 * preempt_count needs to be 1 initially, until the scheduler is functional.
19581@@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
19582 #ifndef __ASSEMBLY__
19583 DECLARE_PER_CPU(unsigned long, kernel_stack);
19584
19585-static inline struct thread_info *current_thread_info(void)
19586-{
19587- struct thread_info *ti;
19588- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19589- KERNEL_STACK_OFFSET - THREAD_SIZE);
19590- return ti;
19591-}
19592-
19593-#else /* !__ASSEMBLY__ */
19594-
19595-/* how to get the thread information struct from ASM */
19596-#define GET_THREAD_INFO(reg) \
19597- movq PER_CPU_VAR(kernel_stack),reg ; \
19598- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19599-
19600-/*
19601- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19602- * a certain register (to be used in assembler memory operands).
19603- */
19604-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19605-
19606+/* how to get the current stack pointer from C */
19607+register unsigned long current_stack_pointer asm("rsp") __used;
19608 #endif
19609
19610 #endif /* !X86_32 */
19611@@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
19612 extern void arch_task_cache_init(void);
19613 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19614 extern void arch_release_task_struct(struct task_struct *tsk);
19615+
19616+#define __HAVE_THREAD_FUNCTIONS
19617+#define task_thread_info(task) (&(task)->tinfo)
19618+#define task_stack_page(task) ((task)->stack)
19619+#define setup_thread_stack(p, org) do {} while (0)
19620+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19621+
19622 #endif
19623 #endif /* _ASM_X86_THREAD_INFO_H */
19624diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19625index 04905bf..49203ca 100644
19626--- a/arch/x86/include/asm/tlbflush.h
19627+++ b/arch/x86/include/asm/tlbflush.h
19628@@ -17,18 +17,44 @@
19629
19630 static inline void __native_flush_tlb(void)
19631 {
19632+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19633+ u64 descriptor[2];
19634+
19635+ descriptor[0] = PCID_KERNEL;
19636+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19637+ return;
19638+ }
19639+
19640+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19641+ if (static_cpu_has(X86_FEATURE_PCID)) {
19642+ unsigned int cpu = raw_get_cpu();
19643+
19644+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19645+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19646+ raw_put_cpu_no_resched();
19647+ return;
19648+ }
19649+#endif
19650+
19651 native_write_cr3(native_read_cr3());
19652 }
19653
19654 static inline void __native_flush_tlb_global_irq_disabled(void)
19655 {
19656- unsigned long cr4;
19657+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19658+ u64 descriptor[2];
19659
19660- cr4 = native_read_cr4();
19661- /* clear PGE */
19662- native_write_cr4(cr4 & ~X86_CR4_PGE);
19663- /* write old PGE again and flush TLBs */
19664- native_write_cr4(cr4);
19665+ descriptor[0] = PCID_KERNEL;
19666+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19667+ } else {
19668+ unsigned long cr4;
19669+
19670+ cr4 = native_read_cr4();
19671+ /* clear PGE */
19672+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19673+ /* write old PGE again and flush TLBs */
19674+ native_write_cr4(cr4);
19675+ }
19676 }
19677
19678 static inline void __native_flush_tlb_global(void)
19679@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19680
19681 static inline void __native_flush_tlb_single(unsigned long addr)
19682 {
19683+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19684+ u64 descriptor[2];
19685+
19686+ descriptor[0] = PCID_KERNEL;
19687+ descriptor[1] = addr;
19688+
19689+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19690+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19691+ if (addr < TASK_SIZE_MAX)
19692+ descriptor[1] += pax_user_shadow_base;
19693+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19694+ }
19695+
19696+ descriptor[0] = PCID_USER;
19697+ descriptor[1] = addr;
19698+#endif
19699+
19700+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19701+ return;
19702+ }
19703+
19704+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19705+ if (static_cpu_has(X86_FEATURE_PCID)) {
19706+ unsigned int cpu = raw_get_cpu();
19707+
19708+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19709+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19710+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19711+ raw_put_cpu_no_resched();
19712+
19713+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19714+ addr += pax_user_shadow_base;
19715+ }
19716+#endif
19717+
19718 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19719 }
19720
19721diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19722index 0d592e0..7437fcc 100644
19723--- a/arch/x86/include/asm/uaccess.h
19724+++ b/arch/x86/include/asm/uaccess.h
19725@@ -7,6 +7,7 @@
19726 #include <linux/compiler.h>
19727 #include <linux/thread_info.h>
19728 #include <linux/string.h>
19729+#include <linux/spinlock.h>
19730 #include <asm/asm.h>
19731 #include <asm/page.h>
19732 #include <asm/smap.h>
19733@@ -29,7 +30,12 @@
19734
19735 #define get_ds() (KERNEL_DS)
19736 #define get_fs() (current_thread_info()->addr_limit)
19737+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19738+void __set_fs(mm_segment_t x);
19739+void set_fs(mm_segment_t x);
19740+#else
19741 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19742+#endif
19743
19744 #define segment_eq(a, b) ((a).seg == (b).seg)
19745
19746@@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19747 * checks that the pointer is in the user space range - after calling
19748 * this function, memory access functions may still return -EFAULT.
19749 */
19750-#define access_ok(type, addr, size) \
19751- likely(!__range_not_ok(addr, size, user_addr_max()))
19752+extern int _cond_resched(void);
19753+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19754+#define access_ok(type, addr, size) \
19755+({ \
19756+ unsigned long __size = size; \
19757+ unsigned long __addr = (unsigned long)addr; \
19758+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19759+ if (__ret_ao && __size) { \
19760+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19761+ unsigned long __end_ao = __addr + __size - 1; \
19762+ if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19763+ while (__addr_ao <= __end_ao) { \
19764+ char __c_ao; \
19765+ __addr_ao += PAGE_SIZE; \
19766+ if (__size > PAGE_SIZE) \
19767+ _cond_resched(); \
19768+ if (__get_user(__c_ao, (char __user *)__addr)) \
19769+ break; \
19770+ if (type != VERIFY_WRITE) { \
19771+ __addr = __addr_ao; \
19772+ continue; \
19773+ } \
19774+ if (__put_user(__c_ao, (char __user *)__addr)) \
19775+ break; \
19776+ __addr = __addr_ao; \
19777+ } \
19778+ } \
19779+ } \
19780+ __ret_ao; \
19781+})
19782
19783 /*
19784 * The exception table consists of pairs of addresses relative to the
19785@@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19786 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19787 __chk_user_ptr(ptr); \
19788 might_fault(); \
19789+ pax_open_userland(); \
19790 asm volatile("call __get_user_%P3" \
19791 : "=a" (__ret_gu), "=r" (__val_gu) \
19792 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19793 (x) = (__typeof__(*(ptr))) __val_gu; \
19794+ pax_close_userland(); \
19795 __ret_gu; \
19796 })
19797
19798@@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19799 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19800 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19801
19802-
19803+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19804+#define __copyuser_seg "gs;"
19805+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19806+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19807+#else
19808+#define __copyuser_seg
19809+#define __COPYUSER_SET_ES
19810+#define __COPYUSER_RESTORE_ES
19811+#endif
19812
19813 #ifdef CONFIG_X86_32
19814 #define __put_user_asm_u64(x, addr, err, errret) \
19815 asm volatile(ASM_STAC "\n" \
19816- "1: movl %%eax,0(%2)\n" \
19817- "2: movl %%edx,4(%2)\n" \
19818+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19819+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19820 "3: " ASM_CLAC "\n" \
19821 ".section .fixup,\"ax\"\n" \
19822 "4: movl %3,%0\n" \
19823@@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19824
19825 #define __put_user_asm_ex_u64(x, addr) \
19826 asm volatile(ASM_STAC "\n" \
19827- "1: movl %%eax,0(%1)\n" \
19828- "2: movl %%edx,4(%1)\n" \
19829+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19830+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19831 "3: " ASM_CLAC "\n" \
19832 _ASM_EXTABLE_EX(1b, 2b) \
19833 _ASM_EXTABLE_EX(2b, 3b) \
19834@@ -257,7 +301,8 @@ extern void __put_user_8(void);
19835 __typeof__(*(ptr)) __pu_val; \
19836 __chk_user_ptr(ptr); \
19837 might_fault(); \
19838- __pu_val = x; \
19839+ __pu_val = (x); \
19840+ pax_open_userland(); \
19841 switch (sizeof(*(ptr))) { \
19842 case 1: \
19843 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19844@@ -275,6 +320,7 @@ extern void __put_user_8(void);
19845 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19846 break; \
19847 } \
19848+ pax_close_userland(); \
19849 __ret_pu; \
19850 })
19851
19852@@ -355,8 +401,10 @@ do { \
19853 } while (0)
19854
19855 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19856+do { \
19857+ pax_open_userland(); \
19858 asm volatile(ASM_STAC "\n" \
19859- "1: mov"itype" %2,%"rtype"1\n" \
19860+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19861 "2: " ASM_CLAC "\n" \
19862 ".section .fixup,\"ax\"\n" \
19863 "3: mov %3,%0\n" \
19864@@ -364,8 +412,10 @@ do { \
19865 " jmp 2b\n" \
19866 ".previous\n" \
19867 _ASM_EXTABLE(1b, 3b) \
19868- : "=r" (err), ltype(x) \
19869- : "m" (__m(addr)), "i" (errret), "0" (err))
19870+ : "=r" (err), ltype (x) \
19871+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19872+ pax_close_userland(); \
19873+} while (0)
19874
19875 #define __get_user_size_ex(x, ptr, size) \
19876 do { \
19877@@ -389,7 +439,7 @@ do { \
19878 } while (0)
19879
19880 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19881- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19882+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19883 "2:\n" \
19884 _ASM_EXTABLE_EX(1b, 2b) \
19885 : ltype(x) : "m" (__m(addr)))
19886@@ -406,13 +456,24 @@ do { \
19887 int __gu_err; \
19888 unsigned long __gu_val; \
19889 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19890- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19891+ (x) = (__typeof__(*(ptr)))__gu_val; \
19892 __gu_err; \
19893 })
19894
19895 /* FIXME: this hack is definitely wrong -AK */
19896 struct __large_struct { unsigned long buf[100]; };
19897-#define __m(x) (*(struct __large_struct __user *)(x))
19898+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19899+#define ____m(x) \
19900+({ \
19901+ unsigned long ____x = (unsigned long)(x); \
19902+ if (____x < pax_user_shadow_base) \
19903+ ____x += pax_user_shadow_base; \
19904+ (typeof(x))____x; \
19905+})
19906+#else
19907+#define ____m(x) (x)
19908+#endif
19909+#define __m(x) (*(struct __large_struct __user *)____m(x))
19910
19911 /*
19912 * Tell gcc we read from memory instead of writing: this is because
19913@@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19914 * aliasing issues.
19915 */
19916 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19917+do { \
19918+ pax_open_userland(); \
19919 asm volatile(ASM_STAC "\n" \
19920- "1: mov"itype" %"rtype"1,%2\n" \
19921+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19922 "2: " ASM_CLAC "\n" \
19923 ".section .fixup,\"ax\"\n" \
19924 "3: mov %3,%0\n" \
19925@@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19926 ".previous\n" \
19927 _ASM_EXTABLE(1b, 3b) \
19928 : "=r"(err) \
19929- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19930+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19931+ pax_close_userland(); \
19932+} while (0)
19933
19934 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19935- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19936+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19937 "2:\n" \
19938 _ASM_EXTABLE_EX(1b, 2b) \
19939 : : ltype(x), "m" (__m(addr)))
19940@@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19941 */
19942 #define uaccess_try do { \
19943 current_thread_info()->uaccess_err = 0; \
19944+ pax_open_userland(); \
19945 stac(); \
19946 barrier();
19947
19948 #define uaccess_catch(err) \
19949 clac(); \
19950+ pax_close_userland(); \
19951 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19952 } while (0)
19953
19954@@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19955 * On error, the variable @x is set to zero.
19956 */
19957
19958+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19959+#define __get_user(x, ptr) get_user((x), (ptr))
19960+#else
19961 #define __get_user(x, ptr) \
19962 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19963+#endif
19964
19965 /**
19966 * __put_user: - Write a simple value into user space, with less checking.
19967@@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19968 * Returns zero on success, or -EFAULT on error.
19969 */
19970
19971+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19972+#define __put_user(x, ptr) put_user((x), (ptr))
19973+#else
19974 #define __put_user(x, ptr) \
19975 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19976+#endif
19977
19978 #define __get_user_unaligned __get_user
19979 #define __put_user_unaligned __put_user
19980@@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19981 #define get_user_ex(x, ptr) do { \
19982 unsigned long __gue_val; \
19983 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19984- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19985+ (x) = (__typeof__(*(ptr)))__gue_val; \
19986 } while (0)
19987
19988 #define put_user_try uaccess_try
19989@@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19990 __typeof__(ptr) __uval = (uval); \
19991 __typeof__(*(ptr)) __old = (old); \
19992 __typeof__(*(ptr)) __new = (new); \
19993+ pax_open_userland(); \
19994 switch (size) { \
19995 case 1: \
19996 { \
19997 asm volatile("\t" ASM_STAC "\n" \
19998- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19999+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
20000 "2:\t" ASM_CLAC "\n" \
20001 "\t.section .fixup, \"ax\"\n" \
20002 "3:\tmov %3, %0\n" \
20003 "\tjmp 2b\n" \
20004 "\t.previous\n" \
20005 _ASM_EXTABLE(1b, 3b) \
20006- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20007+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20008 : "i" (-EFAULT), "q" (__new), "1" (__old) \
20009 : "memory" \
20010 ); \
20011@@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
20012 case 2: \
20013 { \
20014 asm volatile("\t" ASM_STAC "\n" \
20015- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
20016+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
20017 "2:\t" ASM_CLAC "\n" \
20018 "\t.section .fixup, \"ax\"\n" \
20019 "3:\tmov %3, %0\n" \
20020 "\tjmp 2b\n" \
20021 "\t.previous\n" \
20022 _ASM_EXTABLE(1b, 3b) \
20023- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20024+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20025 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20026 : "memory" \
20027 ); \
20028@@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
20029 case 4: \
20030 { \
20031 asm volatile("\t" ASM_STAC "\n" \
20032- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
20033+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
20034 "2:\t" ASM_CLAC "\n" \
20035 "\t.section .fixup, \"ax\"\n" \
20036 "3:\tmov %3, %0\n" \
20037 "\tjmp 2b\n" \
20038 "\t.previous\n" \
20039 _ASM_EXTABLE(1b, 3b) \
20040- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20041+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20042 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20043 : "memory" \
20044 ); \
20045@@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
20046 __cmpxchg_wrong_size(); \
20047 \
20048 asm volatile("\t" ASM_STAC "\n" \
20049- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
20050+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
20051 "2:\t" ASM_CLAC "\n" \
20052 "\t.section .fixup, \"ax\"\n" \
20053 "3:\tmov %3, %0\n" \
20054 "\tjmp 2b\n" \
20055 "\t.previous\n" \
20056 _ASM_EXTABLE(1b, 3b) \
20057- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20058+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20059 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20060 : "memory" \
20061 ); \
20062@@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
20063 default: \
20064 __cmpxchg_wrong_size(); \
20065 } \
20066+ pax_close_userland(); \
20067 *__uval = __old; \
20068 __ret; \
20069 })
20070@@ -636,17 +713,6 @@ extern struct movsl_mask {
20071
20072 #define ARCH_HAS_NOCACHE_UACCESS 1
20073
20074-#ifdef CONFIG_X86_32
20075-# include <asm/uaccess_32.h>
20076-#else
20077-# include <asm/uaccess_64.h>
20078-#endif
20079-
20080-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
20081- unsigned n);
20082-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20083- unsigned n);
20084-
20085 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
20086 # define copy_user_diag __compiletime_error
20087 #else
20088@@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20089 extern void copy_user_diag("copy_from_user() buffer size is too small")
20090 copy_from_user_overflow(void);
20091 extern void copy_user_diag("copy_to_user() buffer size is too small")
20092-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20093+copy_to_user_overflow(void);
20094
20095 #undef copy_user_diag
20096
20097@@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
20098
20099 extern void
20100 __compiletime_warning("copy_to_user() buffer size is not provably correct")
20101-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20102+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
20103 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
20104
20105 #else
20106@@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
20107
20108 #endif
20109
20110+#ifdef CONFIG_X86_32
20111+# include <asm/uaccess_32.h>
20112+#else
20113+# include <asm/uaccess_64.h>
20114+#endif
20115+
20116 static inline unsigned long __must_check
20117 copy_from_user(void *to, const void __user *from, unsigned long n)
20118 {
20119- int sz = __compiletime_object_size(to);
20120+ size_t sz = __compiletime_object_size(to);
20121
20122 might_fault();
20123
20124@@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20125 * case, and do only runtime checking for non-constant sizes.
20126 */
20127
20128- if (likely(sz < 0 || sz >= n))
20129- n = _copy_from_user(to, from, n);
20130- else if(__builtin_constant_p(n))
20131- copy_from_user_overflow();
20132- else
20133- __copy_from_user_overflow(sz, n);
20134+ if (likely(sz != (size_t)-1 && sz < n)) {
20135+ if(__builtin_constant_p(n))
20136+ copy_from_user_overflow();
20137+ else
20138+ __copy_from_user_overflow(sz, n);
20139+ } if (access_ok(VERIFY_READ, from, n))
20140+ n = __copy_from_user(to, from, n);
20141+ else if ((long)n > 0)
20142+ memset(to, 0, n);
20143
20144 return n;
20145 }
20146@@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20147 static inline unsigned long __must_check
20148 copy_to_user(void __user *to, const void *from, unsigned long n)
20149 {
20150- int sz = __compiletime_object_size(from);
20151+ size_t sz = __compiletime_object_size(from);
20152
20153 might_fault();
20154
20155 /* See the comment in copy_from_user() above. */
20156- if (likely(sz < 0 || sz >= n))
20157- n = _copy_to_user(to, from, n);
20158- else if(__builtin_constant_p(n))
20159- copy_to_user_overflow();
20160- else
20161- __copy_to_user_overflow(sz, n);
20162+ if (likely(sz != (size_t)-1 && sz < n)) {
20163+ if(__builtin_constant_p(n))
20164+ copy_to_user_overflow();
20165+ else
20166+ __copy_to_user_overflow(sz, n);
20167+ } else if (access_ok(VERIFY_WRITE, to, n))
20168+ n = __copy_to_user(to, from, n);
20169
20170 return n;
20171 }
20172diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20173index 3c03a5d..1071638 100644
20174--- a/arch/x86/include/asm/uaccess_32.h
20175+++ b/arch/x86/include/asm/uaccess_32.h
20176@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20177 static __always_inline unsigned long __must_check
20178 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20179 {
20180+ if ((long)n < 0)
20181+ return n;
20182+
20183+ check_object_size(from, n, true);
20184+
20185 if (__builtin_constant_p(n)) {
20186 unsigned long ret;
20187
20188@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20189 __copy_to_user(void __user *to, const void *from, unsigned long n)
20190 {
20191 might_fault();
20192+
20193 return __copy_to_user_inatomic(to, from, n);
20194 }
20195
20196 static __always_inline unsigned long
20197 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20198 {
20199+ if ((long)n < 0)
20200+ return n;
20201+
20202 /* Avoid zeroing the tail if the copy fails..
20203 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20204 * but as the zeroing behaviour is only significant when n is not
20205@@ -137,6 +146,12 @@ static __always_inline unsigned long
20206 __copy_from_user(void *to, const void __user *from, unsigned long n)
20207 {
20208 might_fault();
20209+
20210+ if ((long)n < 0)
20211+ return n;
20212+
20213+ check_object_size(to, n, false);
20214+
20215 if (__builtin_constant_p(n)) {
20216 unsigned long ret;
20217
20218@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20219 const void __user *from, unsigned long n)
20220 {
20221 might_fault();
20222+
20223+ if ((long)n < 0)
20224+ return n;
20225+
20226 if (__builtin_constant_p(n)) {
20227 unsigned long ret;
20228
20229@@ -181,7 +200,10 @@ static __always_inline unsigned long
20230 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20231 unsigned long n)
20232 {
20233- return __copy_from_user_ll_nocache_nozero(to, from, n);
20234+ if ((long)n < 0)
20235+ return n;
20236+
20237+ return __copy_from_user_ll_nocache_nozero(to, from, n);
20238 }
20239
20240 #endif /* _ASM_X86_UACCESS_32_H */
20241diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20242index 12a26b9..206c200 100644
20243--- a/arch/x86/include/asm/uaccess_64.h
20244+++ b/arch/x86/include/asm/uaccess_64.h
20245@@ -10,6 +10,9 @@
20246 #include <asm/alternative.h>
20247 #include <asm/cpufeature.h>
20248 #include <asm/page.h>
20249+#include <asm/pgtable.h>
20250+
20251+#define set_fs(x) (current_thread_info()->addr_limit = (x))
20252
20253 /*
20254 * Copy To/From Userspace
20255@@ -17,14 +20,14 @@
20256
20257 /* Handles exceptions in both to and from, but doesn't do access_ok */
20258 __must_check unsigned long
20259-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20260+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20261 __must_check unsigned long
20262-copy_user_generic_string(void *to, const void *from, unsigned len);
20263+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20264 __must_check unsigned long
20265-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20266+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20267
20268 static __always_inline __must_check unsigned long
20269-copy_user_generic(void *to, const void *from, unsigned len)
20270+copy_user_generic(void *to, const void *from, unsigned long len)
20271 {
20272 unsigned ret;
20273
20274@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20275 }
20276
20277 __must_check unsigned long
20278-copy_in_user(void __user *to, const void __user *from, unsigned len);
20279+copy_in_user(void __user *to, const void __user *from, unsigned long len);
20280
20281 static __always_inline __must_check
20282-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20283+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20284 {
20285- int ret = 0;
20286+ size_t sz = __compiletime_object_size(dst);
20287+ unsigned ret = 0;
20288+
20289+ if (size > INT_MAX)
20290+ return size;
20291+
20292+ check_object_size(dst, size, false);
20293+
20294+#ifdef CONFIG_PAX_MEMORY_UDEREF
20295+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20296+ return size;
20297+#endif
20298+
20299+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20300+ if(__builtin_constant_p(size))
20301+ copy_from_user_overflow();
20302+ else
20303+ __copy_from_user_overflow(sz, size);
20304+ return size;
20305+ }
20306
20307 if (!__builtin_constant_p(size))
20308- return copy_user_generic(dst, (__force void *)src, size);
20309+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20310 switch (size) {
20311- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20312+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20313 ret, "b", "b", "=q", 1);
20314 return ret;
20315- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20316+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20317 ret, "w", "w", "=r", 2);
20318 return ret;
20319- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20320+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20321 ret, "l", "k", "=r", 4);
20322 return ret;
20323- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20324+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20325 ret, "q", "", "=r", 8);
20326 return ret;
20327 case 10:
20328- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20329+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20330 ret, "q", "", "=r", 10);
20331 if (unlikely(ret))
20332 return ret;
20333 __get_user_asm(*(u16 *)(8 + (char *)dst),
20334- (u16 __user *)(8 + (char __user *)src),
20335+ (const u16 __user *)(8 + (const char __user *)src),
20336 ret, "w", "w", "=r", 2);
20337 return ret;
20338 case 16:
20339- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20340+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20341 ret, "q", "", "=r", 16);
20342 if (unlikely(ret))
20343 return ret;
20344 __get_user_asm(*(u64 *)(8 + (char *)dst),
20345- (u64 __user *)(8 + (char __user *)src),
20346+ (const u64 __user *)(8 + (const char __user *)src),
20347 ret, "q", "", "=r", 8);
20348 return ret;
20349 default:
20350- return copy_user_generic(dst, (__force void *)src, size);
20351+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20352 }
20353 }
20354
20355 static __always_inline __must_check
20356-int __copy_from_user(void *dst, const void __user *src, unsigned size)
20357+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20358 {
20359 might_fault();
20360 return __copy_from_user_nocheck(dst, src, size);
20361 }
20362
20363 static __always_inline __must_check
20364-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20365+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20366 {
20367- int ret = 0;
20368+ size_t sz = __compiletime_object_size(src);
20369+ unsigned ret = 0;
20370+
20371+ if (size > INT_MAX)
20372+ return size;
20373+
20374+ check_object_size(src, size, true);
20375+
20376+#ifdef CONFIG_PAX_MEMORY_UDEREF
20377+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20378+ return size;
20379+#endif
20380+
20381+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20382+ if(__builtin_constant_p(size))
20383+ copy_to_user_overflow();
20384+ else
20385+ __copy_to_user_overflow(sz, size);
20386+ return size;
20387+ }
20388
20389 if (!__builtin_constant_p(size))
20390- return copy_user_generic((__force void *)dst, src, size);
20391+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20392 switch (size) {
20393- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20394+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20395 ret, "b", "b", "iq", 1);
20396 return ret;
20397- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20398+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20399 ret, "w", "w", "ir", 2);
20400 return ret;
20401- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20402+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20403 ret, "l", "k", "ir", 4);
20404 return ret;
20405- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20406+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20407 ret, "q", "", "er", 8);
20408 return ret;
20409 case 10:
20410- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20411+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20412 ret, "q", "", "er", 10);
20413 if (unlikely(ret))
20414 return ret;
20415 asm("":::"memory");
20416- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20417+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20418 ret, "w", "w", "ir", 2);
20419 return ret;
20420 case 16:
20421- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20422+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20423 ret, "q", "", "er", 16);
20424 if (unlikely(ret))
20425 return ret;
20426 asm("":::"memory");
20427- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20428+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20429 ret, "q", "", "er", 8);
20430 return ret;
20431 default:
20432- return copy_user_generic((__force void *)dst, src, size);
20433+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20434 }
20435 }
20436
20437 static __always_inline __must_check
20438-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20439+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20440 {
20441 might_fault();
20442 return __copy_to_user_nocheck(dst, src, size);
20443 }
20444
20445 static __always_inline __must_check
20446-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20447+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20448 {
20449- int ret = 0;
20450+ unsigned ret = 0;
20451
20452 might_fault();
20453+
20454+ if (size > INT_MAX)
20455+ return size;
20456+
20457+#ifdef CONFIG_PAX_MEMORY_UDEREF
20458+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20459+ return size;
20460+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20461+ return size;
20462+#endif
20463+
20464 if (!__builtin_constant_p(size))
20465- return copy_user_generic((__force void *)dst,
20466- (__force void *)src, size);
20467+ return copy_user_generic((__force_kernel void *)____m(dst),
20468+ (__force_kernel const void *)____m(src), size);
20469 switch (size) {
20470 case 1: {
20471 u8 tmp;
20472- __get_user_asm(tmp, (u8 __user *)src,
20473+ __get_user_asm(tmp, (const u8 __user *)src,
20474 ret, "b", "b", "=q", 1);
20475 if (likely(!ret))
20476 __put_user_asm(tmp, (u8 __user *)dst,
20477@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20478 }
20479 case 2: {
20480 u16 tmp;
20481- __get_user_asm(tmp, (u16 __user *)src,
20482+ __get_user_asm(tmp, (const u16 __user *)src,
20483 ret, "w", "w", "=r", 2);
20484 if (likely(!ret))
20485 __put_user_asm(tmp, (u16 __user *)dst,
20486@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20487
20488 case 4: {
20489 u32 tmp;
20490- __get_user_asm(tmp, (u32 __user *)src,
20491+ __get_user_asm(tmp, (const u32 __user *)src,
20492 ret, "l", "k", "=r", 4);
20493 if (likely(!ret))
20494 __put_user_asm(tmp, (u32 __user *)dst,
20495@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20496 }
20497 case 8: {
20498 u64 tmp;
20499- __get_user_asm(tmp, (u64 __user *)src,
20500+ __get_user_asm(tmp, (const u64 __user *)src,
20501 ret, "q", "", "=r", 8);
20502 if (likely(!ret))
20503 __put_user_asm(tmp, (u64 __user *)dst,
20504@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20505 return ret;
20506 }
20507 default:
20508- return copy_user_generic((__force void *)dst,
20509- (__force void *)src, size);
20510+ return copy_user_generic((__force_kernel void *)____m(dst),
20511+ (__force_kernel const void *)____m(src), size);
20512 }
20513 }
20514
20515-static __must_check __always_inline int
20516-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20517+static __must_check __always_inline unsigned long
20518+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20519 {
20520 return __copy_from_user_nocheck(dst, src, size);
20521 }
20522
20523-static __must_check __always_inline int
20524-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20525+static __must_check __always_inline unsigned long
20526+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20527 {
20528 return __copy_to_user_nocheck(dst, src, size);
20529 }
20530
20531-extern long __copy_user_nocache(void *dst, const void __user *src,
20532- unsigned size, int zerorest);
20533+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20534+ unsigned long size, int zerorest);
20535
20536-static inline int
20537-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20538+static inline unsigned long
20539+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20540 {
20541 might_fault();
20542+
20543+ if (size > INT_MAX)
20544+ return size;
20545+
20546+#ifdef CONFIG_PAX_MEMORY_UDEREF
20547+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20548+ return size;
20549+#endif
20550+
20551 return __copy_user_nocache(dst, src, size, 1);
20552 }
20553
20554-static inline int
20555+static inline unsigned long
20556 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20557- unsigned size)
20558+ unsigned long size)
20559 {
20560+ if (size > INT_MAX)
20561+ return size;
20562+
20563+#ifdef CONFIG_PAX_MEMORY_UDEREF
20564+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20565+ return size;
20566+#endif
20567+
20568 return __copy_user_nocache(dst, src, size, 0);
20569 }
20570
20571 unsigned long
20572-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20573+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20574
20575 #endif /* _ASM_X86_UACCESS_64_H */
20576diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20577index 5b238981..77fdd78 100644
20578--- a/arch/x86/include/asm/word-at-a-time.h
20579+++ b/arch/x86/include/asm/word-at-a-time.h
20580@@ -11,7 +11,7 @@
20581 * and shift, for example.
20582 */
20583 struct word_at_a_time {
20584- const unsigned long one_bits, high_bits;
20585+ unsigned long one_bits, high_bits;
20586 };
20587
20588 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20589diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20590index e45e4da..44e8572 100644
20591--- a/arch/x86/include/asm/x86_init.h
20592+++ b/arch/x86/include/asm/x86_init.h
20593@@ -129,7 +129,7 @@ struct x86_init_ops {
20594 struct x86_init_timers timers;
20595 struct x86_init_iommu iommu;
20596 struct x86_init_pci pci;
20597-};
20598+} __no_const;
20599
20600 /**
20601 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20602@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20603 void (*setup_percpu_clockev)(void);
20604 void (*early_percpu_clock_init)(void);
20605 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20606-};
20607+} __no_const;
20608
20609 struct timespec;
20610
20611@@ -168,7 +168,7 @@ struct x86_platform_ops {
20612 void (*save_sched_clock_state)(void);
20613 void (*restore_sched_clock_state)(void);
20614 void (*apic_post_init)(void);
20615-};
20616+} __no_const;
20617
20618 struct pci_dev;
20619 struct msi_msg;
20620@@ -185,7 +185,7 @@ struct x86_msi_ops {
20621 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20622 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20623 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20624-};
20625+} __no_const;
20626
20627 struct IO_APIC_route_entry;
20628 struct io_apic_irq_attr;
20629@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20630 unsigned int destination, int vector,
20631 struct io_apic_irq_attr *attr);
20632 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20633-};
20634+} __no_const;
20635
20636 extern struct x86_init_ops x86_init;
20637 extern struct x86_cpuinit_ops x86_cpuinit;
20638diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20639index 3e276eb..2eb3c30 100644
20640--- a/arch/x86/include/asm/xen/page.h
20641+++ b/arch/x86/include/asm/xen/page.h
20642@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20643 extern struct page *m2p_find_override(unsigned long mfn);
20644 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20645
20646-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20647+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20648 {
20649 unsigned long mfn;
20650
20651diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20652index 6c1d741..39e6ecf 100644
20653--- a/arch/x86/include/asm/xsave.h
20654+++ b/arch/x86/include/asm/xsave.h
20655@@ -80,8 +80,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20656 if (unlikely(err))
20657 return -EFAULT;
20658
20659+ pax_open_userland();
20660 __asm__ __volatile__(ASM_STAC "\n"
20661- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20662+ "1:"
20663+ __copyuser_seg
20664+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20665 "2: " ASM_CLAC "\n"
20666 ".section .fixup,\"ax\"\n"
20667 "3: movl $-1,%[err]\n"
20668@@ -91,18 +94,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20669 : [err] "=r" (err)
20670 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20671 : "memory");
20672+ pax_close_userland();
20673 return err;
20674 }
20675
20676 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20677 {
20678 int err;
20679- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20680+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20681 u32 lmask = mask;
20682 u32 hmask = mask >> 32;
20683
20684+ pax_open_userland();
20685 __asm__ __volatile__(ASM_STAC "\n"
20686- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20687+ "1:"
20688+ __copyuser_seg
20689+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20690 "2: " ASM_CLAC "\n"
20691 ".section .fixup,\"ax\"\n"
20692 "3: movl $-1,%[err]\n"
20693@@ -112,6 +119,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20694 : [err] "=r" (err)
20695 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20696 : "memory"); /* memory required? */
20697+ pax_close_userland();
20698 return err;
20699 }
20700
20701diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20702index bbae024..e1528f9 100644
20703--- a/arch/x86/include/uapi/asm/e820.h
20704+++ b/arch/x86/include/uapi/asm/e820.h
20705@@ -63,7 +63,7 @@ struct e820map {
20706 #define ISA_START_ADDRESS 0xa0000
20707 #define ISA_END_ADDRESS 0x100000
20708
20709-#define BIOS_BEGIN 0x000a0000
20710+#define BIOS_BEGIN 0x000c0000
20711 #define BIOS_END 0x00100000
20712
20713 #define BIOS_ROM_BASE 0xffe00000
20714diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20715index 7b0a55a..ad115bf 100644
20716--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20717+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20718@@ -49,7 +49,6 @@
20719 #define EFLAGS 144
20720 #define RSP 152
20721 #define SS 160
20722-#define ARGOFFSET R11
20723 #endif /* __ASSEMBLY__ */
20724
20725 /* top of stack page */
20726diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20727index cb648c8..91cb07e 100644
20728--- a/arch/x86/kernel/Makefile
20729+++ b/arch/x86/kernel/Makefile
20730@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20731 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20732 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20733 obj-y += probe_roms.o
20734-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20735+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20736 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20737 obj-y += syscall_$(BITS).o
20738 obj-$(CONFIG_X86_64) += vsyscall_64.o
20739diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20740index 1dac942..19c8b0c 100644
20741--- a/arch/x86/kernel/acpi/boot.c
20742+++ b/arch/x86/kernel/acpi/boot.c
20743@@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20744 * If your system is blacklisted here, but you find that acpi=force
20745 * works for you, please contact linux-acpi@vger.kernel.org
20746 */
20747-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20748+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20749 /*
20750 * Boxes that need ACPI disabled
20751 */
20752@@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20753 };
20754
20755 /* second table for DMI checks that should run after early-quirks */
20756-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20757+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20758 /*
20759 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20760 * which includes some code which overrides all temperature
20761diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20762index 3a2ae4c..9db31d6 100644
20763--- a/arch/x86/kernel/acpi/sleep.c
20764+++ b/arch/x86/kernel/acpi/sleep.c
20765@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20766 #else /* CONFIG_64BIT */
20767 #ifdef CONFIG_SMP
20768 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20769+
20770+ pax_open_kernel();
20771 early_gdt_descr.address =
20772 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20773+ pax_close_kernel();
20774+
20775 initial_gs = per_cpu_offset(smp_processor_id());
20776 #endif
20777 initial_code = (unsigned long)wakeup_long64;
20778diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20779index 665c6b7..eae4d56 100644
20780--- a/arch/x86/kernel/acpi/wakeup_32.S
20781+++ b/arch/x86/kernel/acpi/wakeup_32.S
20782@@ -29,13 +29,11 @@ wakeup_pmode_return:
20783 # and restore the stack ... but you need gdt for this to work
20784 movl saved_context_esp, %esp
20785
20786- movl %cs:saved_magic, %eax
20787- cmpl $0x12345678, %eax
20788+ cmpl $0x12345678, saved_magic
20789 jne bogus_magic
20790
20791 # jump to place where we left off
20792- movl saved_eip, %eax
20793- jmp *%eax
20794+ jmp *(saved_eip)
20795
20796 bogus_magic:
20797 jmp bogus_magic
20798diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20799index df94598..f3b29bf 100644
20800--- a/arch/x86/kernel/alternative.c
20801+++ b/arch/x86/kernel/alternative.c
20802@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20803 */
20804 for (a = start; a < end; a++) {
20805 instr = (u8 *)&a->instr_offset + a->instr_offset;
20806+
20807+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20808+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20809+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20810+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20811+#endif
20812+
20813 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20814 BUG_ON(a->replacementlen > a->instrlen);
20815 BUG_ON(a->instrlen > sizeof(insnbuf));
20816@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20817 for (poff = start; poff < end; poff++) {
20818 u8 *ptr = (u8 *)poff + *poff;
20819
20820+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20821+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20822+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20823+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20824+#endif
20825+
20826 if (!*poff || ptr < text || ptr >= text_end)
20827 continue;
20828 /* turn DS segment override prefix into lock prefix */
20829- if (*ptr == 0x3e)
20830+ if (*ktla_ktva(ptr) == 0x3e)
20831 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20832 }
20833 mutex_unlock(&text_mutex);
20834@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20835 for (poff = start; poff < end; poff++) {
20836 u8 *ptr = (u8 *)poff + *poff;
20837
20838+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20839+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20840+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20841+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20842+#endif
20843+
20844 if (!*poff || ptr < text || ptr >= text_end)
20845 continue;
20846 /* turn lock prefix into DS segment override prefix */
20847- if (*ptr == 0xf0)
20848+ if (*ktla_ktva(ptr) == 0xf0)
20849 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20850 }
20851 mutex_unlock(&text_mutex);
20852@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20853
20854 BUG_ON(p->len > MAX_PATCH_LEN);
20855 /* prep the buffer with the original instructions */
20856- memcpy(insnbuf, p->instr, p->len);
20857+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20858 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20859 (unsigned long)p->instr, p->len);
20860
20861@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20862 if (!uniproc_patched || num_possible_cpus() == 1)
20863 free_init_pages("SMP alternatives",
20864 (unsigned long)__smp_locks,
20865- (unsigned long)__smp_locks_end);
20866+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20867 #endif
20868
20869 apply_paravirt(__parainstructions, __parainstructions_end);
20870@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20871 * instructions. And on the local CPU you need to be protected again NMI or MCE
20872 * handlers seeing an inconsistent instruction while you patch.
20873 */
20874-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20875+void *__kprobes text_poke_early(void *addr, const void *opcode,
20876 size_t len)
20877 {
20878 unsigned long flags;
20879 local_irq_save(flags);
20880- memcpy(addr, opcode, len);
20881+
20882+ pax_open_kernel();
20883+ memcpy(ktla_ktva(addr), opcode, len);
20884 sync_core();
20885+ pax_close_kernel();
20886+
20887 local_irq_restore(flags);
20888 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20889 that causes hangs on some VIA CPUs. */
20890@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20891 */
20892 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20893 {
20894- unsigned long flags;
20895- char *vaddr;
20896+ unsigned char *vaddr = ktla_ktva(addr);
20897 struct page *pages[2];
20898- int i;
20899+ size_t i;
20900
20901 if (!core_kernel_text((unsigned long)addr)) {
20902- pages[0] = vmalloc_to_page(addr);
20903- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20904+ pages[0] = vmalloc_to_page(vaddr);
20905+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20906 } else {
20907- pages[0] = virt_to_page(addr);
20908+ pages[0] = virt_to_page(vaddr);
20909 WARN_ON(!PageReserved(pages[0]));
20910- pages[1] = virt_to_page(addr + PAGE_SIZE);
20911+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20912 }
20913 BUG_ON(!pages[0]);
20914- local_irq_save(flags);
20915- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20916- if (pages[1])
20917- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20918- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20919- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20920- clear_fixmap(FIX_TEXT_POKE0);
20921- if (pages[1])
20922- clear_fixmap(FIX_TEXT_POKE1);
20923- local_flush_tlb();
20924- sync_core();
20925- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20926- that causes hangs on some VIA CPUs. */
20927+ text_poke_early(addr, opcode, len);
20928 for (i = 0; i < len; i++)
20929- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20930- local_irq_restore(flags);
20931+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20932 return addr;
20933 }
20934
20935@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20936 if (likely(!bp_patching_in_progress))
20937 return 0;
20938
20939- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20940+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20941 return 0;
20942
20943 /* set up the specified breakpoint handler */
20944@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20945 */
20946 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20947 {
20948- unsigned char int3 = 0xcc;
20949+ const unsigned char int3 = 0xcc;
20950
20951 bp_int3_handler = handler;
20952 bp_int3_addr = (u8 *)addr + sizeof(int3);
20953diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20954index 7f26c9a..694544e 100644
20955--- a/arch/x86/kernel/apic/apic.c
20956+++ b/arch/x86/kernel/apic/apic.c
20957@@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
20958 /*
20959 * Debug level, exported for io_apic.c
20960 */
20961-unsigned int apic_verbosity;
20962+int apic_verbosity;
20963
20964 int pic_mode;
20965
20966@@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20967 apic_write(APIC_ESR, 0);
20968 v = apic_read(APIC_ESR);
20969 ack_APIC_irq();
20970- atomic_inc(&irq_err_count);
20971+ atomic_inc_unchecked(&irq_err_count);
20972
20973 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20974 smp_processor_id(), v);
20975diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20976index 2c621a6..fa2b1ae 100644
20977--- a/arch/x86/kernel/apic/apic_flat_64.c
20978+++ b/arch/x86/kernel/apic/apic_flat_64.c
20979@@ -154,7 +154,7 @@ static int flat_probe(void)
20980 return 1;
20981 }
20982
20983-static struct apic apic_flat = {
20984+static struct apic apic_flat __read_only = {
20985 .name = "flat",
20986 .probe = flat_probe,
20987 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20988@@ -268,7 +268,7 @@ static int physflat_probe(void)
20989 return 0;
20990 }
20991
20992-static struct apic apic_physflat = {
20993+static struct apic apic_physflat __read_only = {
20994
20995 .name = "physical flat",
20996 .probe = physflat_probe,
20997diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20998index 191ce75..2db6d63 100644
20999--- a/arch/x86/kernel/apic/apic_noop.c
21000+++ b/arch/x86/kernel/apic/apic_noop.c
21001@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
21002 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
21003 }
21004
21005-struct apic apic_noop = {
21006+struct apic apic_noop __read_only = {
21007 .name = "noop",
21008 .probe = noop_probe,
21009 .acpi_madt_oem_check = NULL,
21010diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
21011index d50e364..543bee3 100644
21012--- a/arch/x86/kernel/apic/bigsmp_32.c
21013+++ b/arch/x86/kernel/apic/bigsmp_32.c
21014@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
21015 return dmi_bigsmp;
21016 }
21017
21018-static struct apic apic_bigsmp = {
21019+static struct apic apic_bigsmp __read_only = {
21020
21021 .name = "bigsmp",
21022 .probe = probe_bigsmp,
21023diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
21024index c552247..587a316 100644
21025--- a/arch/x86/kernel/apic/es7000_32.c
21026+++ b/arch/x86/kernel/apic/es7000_32.c
21027@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
21028 return ret && es7000_apic_is_cluster();
21029 }
21030
21031-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
21032-static struct apic __refdata apic_es7000_cluster = {
21033+static struct apic apic_es7000_cluster __read_only = {
21034
21035 .name = "es7000",
21036 .probe = probe_es7000,
21037@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
21038 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
21039 };
21040
21041-static struct apic __refdata apic_es7000 = {
21042+static struct apic apic_es7000 __read_only = {
21043
21044 .name = "es7000",
21045 .probe = probe_es7000,
21046diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
21047index 6ad4658..38a7b5c 100644
21048--- a/arch/x86/kernel/apic/io_apic.c
21049+++ b/arch/x86/kernel/apic/io_apic.c
21050@@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
21051 }
21052 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
21053
21054-void lock_vector_lock(void)
21055+void lock_vector_lock(void) __acquires(vector_lock)
21056 {
21057 /* Used to the online set of cpus does not change
21058 * during assign_irq_vector.
21059@@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
21060 raw_spin_lock(&vector_lock);
21061 }
21062
21063-void unlock_vector_lock(void)
21064+void unlock_vector_lock(void) __releases(vector_lock)
21065 {
21066 raw_spin_unlock(&vector_lock);
21067 }
21068@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
21069 ack_APIC_irq();
21070 }
21071
21072-atomic_t irq_mis_count;
21073+atomic_unchecked_t irq_mis_count;
21074
21075 #ifdef CONFIG_GENERIC_PENDING_IRQ
21076 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
21077@@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
21078 * at the cpu.
21079 */
21080 if (!(v & (1 << (i & 0x1f)))) {
21081- atomic_inc(&irq_mis_count);
21082+ atomic_inc_unchecked(&irq_mis_count);
21083
21084 eoi_ioapic_irq(irq, cfg);
21085 }
21086diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
21087index 1e42e8f..daacf44 100644
21088--- a/arch/x86/kernel/apic/numaq_32.c
21089+++ b/arch/x86/kernel/apic/numaq_32.c
21090@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
21091 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
21092 }
21093
21094-/* Use __refdata to keep false positive warning calm. */
21095-static struct apic __refdata apic_numaq = {
21096+static struct apic apic_numaq __read_only = {
21097
21098 .name = "NUMAQ",
21099 .probe = probe_numaq,
21100diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
21101index eb35ef9..f184a21 100644
21102--- a/arch/x86/kernel/apic/probe_32.c
21103+++ b/arch/x86/kernel/apic/probe_32.c
21104@@ -72,7 +72,7 @@ static int probe_default(void)
21105 return 1;
21106 }
21107
21108-static struct apic apic_default = {
21109+static struct apic apic_default __read_only = {
21110
21111 .name = "default",
21112 .probe = probe_default,
21113diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
21114index 00146f9..5e299b8 100644
21115--- a/arch/x86/kernel/apic/summit_32.c
21116+++ b/arch/x86/kernel/apic/summit_32.c
21117@@ -485,7 +485,7 @@ void setup_summit(void)
21118 }
21119 #endif
21120
21121-static struct apic apic_summit = {
21122+static struct apic apic_summit __read_only = {
21123
21124 .name = "summit",
21125 .probe = probe_summit,
21126diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21127index cac85ee..01fa741 100644
21128--- a/arch/x86/kernel/apic/x2apic_cluster.c
21129+++ b/arch/x86/kernel/apic/x2apic_cluster.c
21130@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21131 return notifier_from_errno(err);
21132 }
21133
21134-static struct notifier_block __refdata x2apic_cpu_notifier = {
21135+static struct notifier_block x2apic_cpu_notifier = {
21136 .notifier_call = update_clusterinfo,
21137 };
21138
21139@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21140 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21141 }
21142
21143-static struct apic apic_x2apic_cluster = {
21144+static struct apic apic_x2apic_cluster __read_only = {
21145
21146 .name = "cluster x2apic",
21147 .probe = x2apic_cluster_probe,
21148diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21149index de231e3..1d1b2ee 100644
21150--- a/arch/x86/kernel/apic/x2apic_phys.c
21151+++ b/arch/x86/kernel/apic/x2apic_phys.c
21152@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21153 return apic == &apic_x2apic_phys;
21154 }
21155
21156-static struct apic apic_x2apic_phys = {
21157+static struct apic apic_x2apic_phys __read_only = {
21158
21159 .name = "physical x2apic",
21160 .probe = x2apic_phys_probe,
21161diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21162index d263b13..963258b 100644
21163--- a/arch/x86/kernel/apic/x2apic_uv_x.c
21164+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21165@@ -350,7 +350,7 @@ static int uv_probe(void)
21166 return apic == &apic_x2apic_uv_x;
21167 }
21168
21169-static struct apic __refdata apic_x2apic_uv_x = {
21170+static struct apic apic_x2apic_uv_x __read_only = {
21171
21172 .name = "UV large system",
21173 .probe = uv_probe,
21174diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21175index 3ab0343..814c4787 100644
21176--- a/arch/x86/kernel/apm_32.c
21177+++ b/arch/x86/kernel/apm_32.c
21178@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21179 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21180 * even though they are called in protected mode.
21181 */
21182-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21183+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21184 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21185
21186 static const char driver_version[] = "1.16ac"; /* no spaces */
21187@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21188 BUG_ON(cpu != 0);
21189 gdt = get_cpu_gdt_table(cpu);
21190 save_desc_40 = gdt[0x40 / 8];
21191+
21192+ pax_open_kernel();
21193 gdt[0x40 / 8] = bad_bios_desc;
21194+ pax_close_kernel();
21195
21196 apm_irq_save(flags);
21197 APM_DO_SAVE_SEGS;
21198@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21199 &call->esi);
21200 APM_DO_RESTORE_SEGS;
21201 apm_irq_restore(flags);
21202+
21203+ pax_open_kernel();
21204 gdt[0x40 / 8] = save_desc_40;
21205+ pax_close_kernel();
21206+
21207 put_cpu();
21208
21209 return call->eax & 0xff;
21210@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21211 BUG_ON(cpu != 0);
21212 gdt = get_cpu_gdt_table(cpu);
21213 save_desc_40 = gdt[0x40 / 8];
21214+
21215+ pax_open_kernel();
21216 gdt[0x40 / 8] = bad_bios_desc;
21217+ pax_close_kernel();
21218
21219 apm_irq_save(flags);
21220 APM_DO_SAVE_SEGS;
21221@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21222 &call->eax);
21223 APM_DO_RESTORE_SEGS;
21224 apm_irq_restore(flags);
21225+
21226+ pax_open_kernel();
21227 gdt[0x40 / 8] = save_desc_40;
21228+ pax_close_kernel();
21229+
21230 put_cpu();
21231 return error;
21232 }
21233@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
21234 * code to that CPU.
21235 */
21236 gdt = get_cpu_gdt_table(0);
21237+
21238+ pax_open_kernel();
21239 set_desc_base(&gdt[APM_CS >> 3],
21240 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21241 set_desc_base(&gdt[APM_CS_16 >> 3],
21242 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21243 set_desc_base(&gdt[APM_DS >> 3],
21244 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21245+ pax_close_kernel();
21246
21247 proc_create("apm", 0, NULL, &apm_file_ops);
21248
21249diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21250index 9f6b934..cf5ffb3 100644
21251--- a/arch/x86/kernel/asm-offsets.c
21252+++ b/arch/x86/kernel/asm-offsets.c
21253@@ -32,6 +32,8 @@ void common(void) {
21254 OFFSET(TI_flags, thread_info, flags);
21255 OFFSET(TI_status, thread_info, status);
21256 OFFSET(TI_addr_limit, thread_info, addr_limit);
21257+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21258+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21259
21260 BLANK();
21261 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21262@@ -52,8 +54,26 @@ void common(void) {
21263 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21264 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21265 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21266+
21267+#ifdef CONFIG_PAX_KERNEXEC
21268+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21269 #endif
21270
21271+#ifdef CONFIG_PAX_MEMORY_UDEREF
21272+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21273+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21274+#ifdef CONFIG_X86_64
21275+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21276+#endif
21277+#endif
21278+
21279+#endif
21280+
21281+ BLANK();
21282+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21283+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21284+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21285+
21286 #ifdef CONFIG_XEN
21287 BLANK();
21288 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21289diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21290index e7c798b..2b2019b 100644
21291--- a/arch/x86/kernel/asm-offsets_64.c
21292+++ b/arch/x86/kernel/asm-offsets_64.c
21293@@ -77,6 +77,7 @@ int main(void)
21294 BLANK();
21295 #undef ENTRY
21296
21297+ DEFINE(TSS_size, sizeof(struct tss_struct));
21298 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21299 BLANK();
21300
21301diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21302index 7fd54f0..0691410 100644
21303--- a/arch/x86/kernel/cpu/Makefile
21304+++ b/arch/x86/kernel/cpu/Makefile
21305@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21306 CFLAGS_REMOVE_perf_event.o = -pg
21307 endif
21308
21309-# Make sure load_percpu_segment has no stackprotector
21310-nostackp := $(call cc-option, -fno-stack-protector)
21311-CFLAGS_common.o := $(nostackp)
21312-
21313 obj-y := intel_cacheinfo.o scattered.o topology.o
21314 obj-y += proc.o capflags.o powerflags.o common.o
21315 obj-y += rdrand.o
21316diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21317index c67ffa6..f41fbbf 100644
21318--- a/arch/x86/kernel/cpu/amd.c
21319+++ b/arch/x86/kernel/cpu/amd.c
21320@@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21321 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21322 {
21323 /* AMD errata T13 (order #21922) */
21324- if ((c->x86 == 6)) {
21325+ if (c->x86 == 6) {
21326 /* Duron Rev A0 */
21327 if (c->x86_model == 3 && c->x86_mask == 0)
21328 size = 64;
21329diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21330index 8e28bf2..bf5c0d2 100644
21331--- a/arch/x86/kernel/cpu/common.c
21332+++ b/arch/x86/kernel/cpu/common.c
21333@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
21334
21335 static const struct cpu_dev *this_cpu = &default_cpu;
21336
21337-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21338-#ifdef CONFIG_X86_64
21339- /*
21340- * We need valid kernel segments for data and code in long mode too
21341- * IRET will check the segment types kkeil 2000/10/28
21342- * Also sysret mandates a special GDT layout
21343- *
21344- * TLS descriptors are currently at a different place compared to i386.
21345- * Hopefully nobody expects them at a fixed place (Wine?)
21346- */
21347- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21348- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21349- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21350- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21351- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21352- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21353-#else
21354- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21355- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21356- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21357- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21358- /*
21359- * Segments used for calling PnP BIOS have byte granularity.
21360- * They code segments and data segments have fixed 64k limits,
21361- * the transfer segment sizes are set at run time.
21362- */
21363- /* 32-bit code */
21364- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21365- /* 16-bit code */
21366- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21367- /* 16-bit data */
21368- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21369- /* 16-bit data */
21370- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21371- /* 16-bit data */
21372- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21373- /*
21374- * The APM segments have byte granularity and their bases
21375- * are set at run time. All have 64k limits.
21376- */
21377- /* 32-bit code */
21378- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21379- /* 16-bit code */
21380- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21381- /* data */
21382- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21383-
21384- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21385- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21386- GDT_STACK_CANARY_INIT
21387-#endif
21388-} };
21389-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21390-
21391 static int __init x86_xsave_setup(char *s)
21392 {
21393 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21394@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21395 }
21396 }
21397
21398+#ifdef CONFIG_X86_64
21399+static __init int setup_disable_pcid(char *arg)
21400+{
21401+ setup_clear_cpu_cap(X86_FEATURE_PCID);
21402+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21403+
21404+#ifdef CONFIG_PAX_MEMORY_UDEREF
21405+ if (clone_pgd_mask != ~(pgdval_t)0UL)
21406+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21407+#endif
21408+
21409+ return 1;
21410+}
21411+__setup("nopcid", setup_disable_pcid);
21412+
21413+static void setup_pcid(struct cpuinfo_x86 *c)
21414+{
21415+ if (!cpu_has(c, X86_FEATURE_PCID)) {
21416+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
21417+
21418+#ifdef CONFIG_PAX_MEMORY_UDEREF
21419+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
21420+ pax_open_kernel();
21421+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21422+ pax_close_kernel();
21423+ printk("PAX: slow and weak UDEREF enabled\n");
21424+ } else
21425+ printk("PAX: UDEREF disabled\n");
21426+#endif
21427+
21428+ return;
21429+ }
21430+
21431+ printk("PAX: PCID detected\n");
21432+ set_in_cr4(X86_CR4_PCIDE);
21433+
21434+#ifdef CONFIG_PAX_MEMORY_UDEREF
21435+ pax_open_kernel();
21436+ clone_pgd_mask = ~(pgdval_t)0UL;
21437+ pax_close_kernel();
21438+ if (pax_user_shadow_base)
21439+ printk("PAX: weak UDEREF enabled\n");
21440+ else {
21441+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21442+ printk("PAX: strong UDEREF enabled\n");
21443+ }
21444+#endif
21445+
21446+ if (cpu_has(c, X86_FEATURE_INVPCID))
21447+ printk("PAX: INVPCID detected\n");
21448+}
21449+#endif
21450+
21451 /*
21452 * Some CPU features depend on higher CPUID levels, which may not always
21453 * be available due to CPUID level capping or broken virtualization
21454@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21455 {
21456 struct desc_ptr gdt_descr;
21457
21458- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21459+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21460 gdt_descr.size = GDT_SIZE - 1;
21461 load_gdt(&gdt_descr);
21462 /* Reload the per-cpu base */
21463@@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21464 setup_smep(c);
21465 setup_smap(c);
21466
21467+#ifdef CONFIG_X86_64
21468+ setup_pcid(c);
21469+#endif
21470+
21471 /*
21472 * The vendor-specific functions might have changed features.
21473 * Now we do "generic changes."
21474@@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21475 /* Filter out anything that depends on CPUID levels we don't have */
21476 filter_cpuid_features(c, true);
21477
21478+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21479+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21480+#endif
21481+
21482 /* If the model name is still unset, do table lookup. */
21483 if (!c->x86_model_id[0]) {
21484 const char *p;
21485@@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
21486 }
21487 __setup("clearcpuid=", setup_disablecpuid);
21488
21489+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21490+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21491+
21492 #ifdef CONFIG_X86_64
21493-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21494-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21495- (unsigned long) debug_idt_table };
21496+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21497+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21498
21499 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21500 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21501@@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
21502 EXPORT_PER_CPU_SYMBOL(current_task);
21503
21504 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21505- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21506+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21507 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21508
21509 DEFINE_PER_CPU(char *, irq_stack_ptr) =
21510@@ -1245,7 +1254,7 @@ void cpu_init(void)
21511 load_ucode_ap();
21512
21513 cpu = stack_smp_processor_id();
21514- t = &per_cpu(init_tss, cpu);
21515+ t = init_tss + cpu;
21516 oist = &per_cpu(orig_ist, cpu);
21517
21518 #ifdef CONFIG_NUMA
21519@@ -1280,7 +1289,6 @@ void cpu_init(void)
21520 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21521 barrier();
21522
21523- x86_configure_nx();
21524 enable_x2apic();
21525
21526 /*
21527@@ -1332,7 +1340,7 @@ void cpu_init(void)
21528 {
21529 int cpu = smp_processor_id();
21530 struct task_struct *curr = current;
21531- struct tss_struct *t = &per_cpu(init_tss, cpu);
21532+ struct tss_struct *t = init_tss + cpu;
21533 struct thread_struct *thread = &curr->thread;
21534
21535 show_ucode_info_early();
21536diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21537index 0641113..06f5ba4 100644
21538--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21539+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21540@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21541 };
21542
21543 #ifdef CONFIG_AMD_NB
21544+static struct attribute *default_attrs_amd_nb[] = {
21545+ &type.attr,
21546+ &level.attr,
21547+ &coherency_line_size.attr,
21548+ &physical_line_partition.attr,
21549+ &ways_of_associativity.attr,
21550+ &number_of_sets.attr,
21551+ &size.attr,
21552+ &shared_cpu_map.attr,
21553+ &shared_cpu_list.attr,
21554+ NULL,
21555+ NULL,
21556+ NULL,
21557+ NULL
21558+};
21559+
21560 static struct attribute **amd_l3_attrs(void)
21561 {
21562 static struct attribute **attrs;
21563@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21564
21565 n = ARRAY_SIZE(default_attrs);
21566
21567- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21568- n += 2;
21569-
21570- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21571- n += 1;
21572-
21573- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21574- if (attrs == NULL)
21575- return attrs = default_attrs;
21576-
21577- for (n = 0; default_attrs[n]; n++)
21578- attrs[n] = default_attrs[n];
21579+ attrs = default_attrs_amd_nb;
21580
21581 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21582 attrs[n++] = &cache_disable_0.attr;
21583@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21584 .default_attrs = default_attrs,
21585 };
21586
21587+#ifdef CONFIG_AMD_NB
21588+static struct kobj_type ktype_cache_amd_nb = {
21589+ .sysfs_ops = &sysfs_ops,
21590+ .default_attrs = default_attrs_amd_nb,
21591+};
21592+#endif
21593+
21594 static struct kobj_type ktype_percpu_entry = {
21595 .sysfs_ops = &sysfs_ops,
21596 };
21597@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21598 return retval;
21599 }
21600
21601+#ifdef CONFIG_AMD_NB
21602+ amd_l3_attrs();
21603+#endif
21604+
21605 for (i = 0; i < num_cache_leaves; i++) {
21606+ struct kobj_type *ktype;
21607+
21608 this_object = INDEX_KOBJECT_PTR(cpu, i);
21609 this_object->cpu = cpu;
21610 this_object->index = i;
21611
21612 this_leaf = CPUID4_INFO_IDX(cpu, i);
21613
21614- ktype_cache.default_attrs = default_attrs;
21615+ ktype = &ktype_cache;
21616 #ifdef CONFIG_AMD_NB
21617 if (this_leaf->base.nb)
21618- ktype_cache.default_attrs = amd_l3_attrs();
21619+ ktype = &ktype_cache_amd_nb;
21620 #endif
21621 retval = kobject_init_and_add(&(this_object->kobj),
21622- &ktype_cache,
21623+ ktype,
21624 per_cpu(ici_cache_kobject, cpu),
21625 "index%1lu", i);
21626 if (unlikely(retval)) {
21627diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21628index 4d5419b..95f11bb 100644
21629--- a/arch/x86/kernel/cpu/mcheck/mce.c
21630+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21631@@ -45,6 +45,7 @@
21632 #include <asm/processor.h>
21633 #include <asm/mce.h>
21634 #include <asm/msr.h>
21635+#include <asm/local.h>
21636
21637 #include "mce-internal.h"
21638
21639@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21640 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21641 m->cs, m->ip);
21642
21643- if (m->cs == __KERNEL_CS)
21644+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21645 print_symbol("{%s}", m->ip);
21646 pr_cont("\n");
21647 }
21648@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21649
21650 #define PANIC_TIMEOUT 5 /* 5 seconds */
21651
21652-static atomic_t mce_paniced;
21653+static atomic_unchecked_t mce_paniced;
21654
21655 static int fake_panic;
21656-static atomic_t mce_fake_paniced;
21657+static atomic_unchecked_t mce_fake_paniced;
21658
21659 /* Panic in progress. Enable interrupts and wait for final IPI */
21660 static void wait_for_panic(void)
21661@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21662 /*
21663 * Make sure only one CPU runs in machine check panic
21664 */
21665- if (atomic_inc_return(&mce_paniced) > 1)
21666+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21667 wait_for_panic();
21668 barrier();
21669
21670@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21671 console_verbose();
21672 } else {
21673 /* Don't log too much for fake panic */
21674- if (atomic_inc_return(&mce_fake_paniced) > 1)
21675+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21676 return;
21677 }
21678 /* First print corrected ones that are still unlogged */
21679@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21680 if (!fake_panic) {
21681 if (panic_timeout == 0)
21682 panic_timeout = mca_cfg.panic_timeout;
21683- panic(msg);
21684+ panic("%s", msg);
21685 } else
21686 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21687 }
21688@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21689 * might have been modified by someone else.
21690 */
21691 rmb();
21692- if (atomic_read(&mce_paniced))
21693+ if (atomic_read_unchecked(&mce_paniced))
21694 wait_for_panic();
21695 if (!mca_cfg.monarch_timeout)
21696 goto out;
21697@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21698 }
21699
21700 /* Call the installed machine check handler for this CPU setup. */
21701-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21702+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21703 unexpected_machine_check;
21704
21705 /*
21706@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21707 return;
21708 }
21709
21710+ pax_open_kernel();
21711 machine_check_vector = do_machine_check;
21712+ pax_close_kernel();
21713
21714 __mcheck_cpu_init_generic();
21715 __mcheck_cpu_init_vendor(c);
21716@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21717 */
21718
21719 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21720-static int mce_chrdev_open_count; /* #times opened */
21721+static local_t mce_chrdev_open_count; /* #times opened */
21722 static int mce_chrdev_open_exclu; /* already open exclusive? */
21723
21724 static int mce_chrdev_open(struct inode *inode, struct file *file)
21725@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21726 spin_lock(&mce_chrdev_state_lock);
21727
21728 if (mce_chrdev_open_exclu ||
21729- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21730+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21731 spin_unlock(&mce_chrdev_state_lock);
21732
21733 return -EBUSY;
21734@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21735
21736 if (file->f_flags & O_EXCL)
21737 mce_chrdev_open_exclu = 1;
21738- mce_chrdev_open_count++;
21739+ local_inc(&mce_chrdev_open_count);
21740
21741 spin_unlock(&mce_chrdev_state_lock);
21742
21743@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21744 {
21745 spin_lock(&mce_chrdev_state_lock);
21746
21747- mce_chrdev_open_count--;
21748+ local_dec(&mce_chrdev_open_count);
21749 mce_chrdev_open_exclu = 0;
21750
21751 spin_unlock(&mce_chrdev_state_lock);
21752@@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
21753
21754 for (i = 0; i < mca_cfg.banks; i++) {
21755 struct mce_bank *b = &mce_banks[i];
21756- struct device_attribute *a = &b->attr;
21757+ device_attribute_no_const *a = &b->attr;
21758
21759 sysfs_attr_init(&a->attr);
21760 a->attr.name = b->attrname;
21761@@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
21762 static void mce_reset(void)
21763 {
21764 cpu_missing = 0;
21765- atomic_set(&mce_fake_paniced, 0);
21766+ atomic_set_unchecked(&mce_fake_paniced, 0);
21767 atomic_set(&mce_executing, 0);
21768 atomic_set(&mce_callin, 0);
21769 atomic_set(&global_nwo, 0);
21770diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21771index a304298..49b6d06 100644
21772--- a/arch/x86/kernel/cpu/mcheck/p5.c
21773+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21774@@ -10,6 +10,7 @@
21775 #include <asm/processor.h>
21776 #include <asm/mce.h>
21777 #include <asm/msr.h>
21778+#include <asm/pgtable.h>
21779
21780 /* By default disabled */
21781 int mce_p5_enabled __read_mostly;
21782@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21783 if (!cpu_has(c, X86_FEATURE_MCE))
21784 return;
21785
21786+ pax_open_kernel();
21787 machine_check_vector = pentium_machine_check;
21788+ pax_close_kernel();
21789 /* Make sure the vector pointer is visible before we enable MCEs: */
21790 wmb();
21791
21792diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21793index 7dc5564..1273569 100644
21794--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21795+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21796@@ -9,6 +9,7 @@
21797 #include <asm/processor.h>
21798 #include <asm/mce.h>
21799 #include <asm/msr.h>
21800+#include <asm/pgtable.h>
21801
21802 /* Machine check handler for WinChip C6: */
21803 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21804@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21805 {
21806 u32 lo, hi;
21807
21808+ pax_open_kernel();
21809 machine_check_vector = winchip_machine_check;
21810+ pax_close_kernel();
21811 /* Make sure the vector pointer is visible before we enable MCEs: */
21812 wmb();
21813
21814diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21815index 15c9876..0a43909 100644
21816--- a/arch/x86/kernel/cpu/microcode/core.c
21817+++ b/arch/x86/kernel/cpu/microcode/core.c
21818@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21819 return NOTIFY_OK;
21820 }
21821
21822-static struct notifier_block __refdata mc_cpu_notifier = {
21823+static struct notifier_block mc_cpu_notifier = {
21824 .notifier_call = mc_cpu_callback,
21825 };
21826
21827diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21828index a276fa7..e66810f 100644
21829--- a/arch/x86/kernel/cpu/microcode/intel.c
21830+++ b/arch/x86/kernel/cpu/microcode/intel.c
21831@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21832
21833 static int get_ucode_user(void *to, const void *from, size_t n)
21834 {
21835- return copy_from_user(to, from, n);
21836+ return copy_from_user(to, (const void __force_user *)from, n);
21837 }
21838
21839 static enum ucode_state
21840 request_microcode_user(int cpu, const void __user *buf, size_t size)
21841 {
21842- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21843+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21844 }
21845
21846 static void microcode_fini_cpu(int cpu)
21847diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21848index f961de9..8a9d332 100644
21849--- a/arch/x86/kernel/cpu/mtrr/main.c
21850+++ b/arch/x86/kernel/cpu/mtrr/main.c
21851@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21852 u64 size_or_mask, size_and_mask;
21853 static bool mtrr_aps_delayed_init;
21854
21855-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21856+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21857
21858 const struct mtrr_ops *mtrr_if;
21859
21860diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21861index df5e41f..816c719 100644
21862--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21863+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21864@@ -25,7 +25,7 @@ struct mtrr_ops {
21865 int (*validate_add_page)(unsigned long base, unsigned long size,
21866 unsigned int type);
21867 int (*have_wrcomb)(void);
21868-};
21869+} __do_const;
21870
21871 extern int generic_get_free_region(unsigned long base, unsigned long size,
21872 int replace_reg);
21873diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21874index 79f9f84..38ace52 100644
21875--- a/arch/x86/kernel/cpu/perf_event.c
21876+++ b/arch/x86/kernel/cpu/perf_event.c
21877@@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21878 pr_info("no hardware sampling interrupt available.\n");
21879 }
21880
21881-static struct attribute_group x86_pmu_format_group = {
21882+static attribute_group_no_const x86_pmu_format_group = {
21883 .name = "format",
21884 .attrs = NULL,
21885 };
21886@@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21887 NULL,
21888 };
21889
21890-static struct attribute_group x86_pmu_events_group = {
21891+static attribute_group_no_const x86_pmu_events_group = {
21892 .name = "events",
21893 .attrs = events_attr,
21894 };
21895@@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
21896 if (idx > GDT_ENTRIES)
21897 return 0;
21898
21899- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21900+ desc = get_cpu_gdt_table(smp_processor_id());
21901 }
21902
21903 return get_desc_base(desc + idx);
21904@@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21905 break;
21906
21907 perf_callchain_store(entry, frame.return_address);
21908- fp = frame.next_frame;
21909+ fp = (const void __force_user *)frame.next_frame;
21910 }
21911 }
21912
21913diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21914index 639d128..e92d7e5 100644
21915--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21916+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21917@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21918 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21919 {
21920 struct attribute **attrs;
21921- struct attribute_group *attr_group;
21922+ attribute_group_no_const *attr_group;
21923 int i = 0, j;
21924
21925 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21926diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21927index aa333d9..f9db700 100644
21928--- a/arch/x86/kernel/cpu/perf_event_intel.c
21929+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21930@@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
21931 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21932
21933 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21934- u64 capabilities;
21935+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21936
21937- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21938- x86_pmu.intel_cap.capabilities = capabilities;
21939+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21940+ x86_pmu.intel_cap.capabilities = capabilities;
21941 }
21942
21943 intel_ds_init();
21944diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21945index 5ad35ad..e0a3960 100644
21946--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21947+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21948@@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
21949 NULL,
21950 };
21951
21952-static struct attribute_group rapl_pmu_events_group = {
21953+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21954 .name = "events",
21955 .attrs = NULL, /* patched at runtime */
21956 };
21957diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21958index 047f540..afdeba0 100644
21959--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21960+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21961@@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21962 static int __init uncore_type_init(struct intel_uncore_type *type)
21963 {
21964 struct intel_uncore_pmu *pmus;
21965- struct attribute_group *attr_group;
21966+ attribute_group_no_const *attr_group;
21967 struct attribute **attrs;
21968 int i, j;
21969
21970diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21971index a80ab71..4089da5 100644
21972--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21973+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21974@@ -498,7 +498,7 @@ struct intel_uncore_box {
21975 struct uncore_event_desc {
21976 struct kobj_attribute attr;
21977 const char *config;
21978-};
21979+} __do_const;
21980
21981 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21982 { \
21983diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21984index 7d9481c..99c7e4b 100644
21985--- a/arch/x86/kernel/cpuid.c
21986+++ b/arch/x86/kernel/cpuid.c
21987@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21988 return notifier_from_errno(err);
21989 }
21990
21991-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21992+static struct notifier_block cpuid_class_cpu_notifier =
21993 {
21994 .notifier_call = cpuid_class_cpu_callback,
21995 };
21996diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21997index a57902e..ebaae2a 100644
21998--- a/arch/x86/kernel/crash.c
21999+++ b/arch/x86/kernel/crash.c
22000@@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
22001 {
22002 #ifdef CONFIG_X86_32
22003 struct pt_regs fixed_regs;
22004-#endif
22005
22006-#ifdef CONFIG_X86_32
22007- if (!user_mode_vm(regs)) {
22008+ if (!user_mode(regs)) {
22009 crash_fixup_ss_esp(&fixed_regs, regs);
22010 regs = &fixed_regs;
22011 }
22012diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
22013index afa64ad..dce67dd 100644
22014--- a/arch/x86/kernel/crash_dump_64.c
22015+++ b/arch/x86/kernel/crash_dump_64.c
22016@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
22017 return -ENOMEM;
22018
22019 if (userbuf) {
22020- if (copy_to_user(buf, vaddr + offset, csize)) {
22021+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
22022 iounmap(vaddr);
22023 return -EFAULT;
22024 }
22025diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
22026index f6dfd93..892ade4 100644
22027--- a/arch/x86/kernel/doublefault.c
22028+++ b/arch/x86/kernel/doublefault.c
22029@@ -12,7 +12,7 @@
22030
22031 #define DOUBLEFAULT_STACKSIZE (1024)
22032 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
22033-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
22034+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
22035
22036 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
22037
22038@@ -22,7 +22,7 @@ static void doublefault_fn(void)
22039 unsigned long gdt, tss;
22040
22041 native_store_gdt(&gdt_desc);
22042- gdt = gdt_desc.address;
22043+ gdt = (unsigned long)gdt_desc.address;
22044
22045 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
22046
22047@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
22048 /* 0x2 bit is always set */
22049 .flags = X86_EFLAGS_SF | 0x2,
22050 .sp = STACK_START,
22051- .es = __USER_DS,
22052+ .es = __KERNEL_DS,
22053 .cs = __KERNEL_CS,
22054 .ss = __KERNEL_DS,
22055- .ds = __USER_DS,
22056+ .ds = __KERNEL_DS,
22057 .fs = __KERNEL_PERCPU,
22058
22059 .__cr3 = __pa_nodebug(swapper_pg_dir),
22060diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
22061index d9c12d3..7858b62 100644
22062--- a/arch/x86/kernel/dumpstack.c
22063+++ b/arch/x86/kernel/dumpstack.c
22064@@ -2,6 +2,9 @@
22065 * Copyright (C) 1991, 1992 Linus Torvalds
22066 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
22067 */
22068+#ifdef CONFIG_GRKERNSEC_HIDESYM
22069+#define __INCLUDED_BY_HIDESYM 1
22070+#endif
22071 #include <linux/kallsyms.h>
22072 #include <linux/kprobes.h>
22073 #include <linux/uaccess.h>
22074@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
22075 static void
22076 print_ftrace_graph_addr(unsigned long addr, void *data,
22077 const struct stacktrace_ops *ops,
22078- struct thread_info *tinfo, int *graph)
22079+ struct task_struct *task, int *graph)
22080 {
22081- struct task_struct *task;
22082 unsigned long ret_addr;
22083 int index;
22084
22085 if (addr != (unsigned long)return_to_handler)
22086 return;
22087
22088- task = tinfo->task;
22089 index = task->curr_ret_stack;
22090
22091 if (!task->ret_stack || index < *graph)
22092@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22093 static inline void
22094 print_ftrace_graph_addr(unsigned long addr, void *data,
22095 const struct stacktrace_ops *ops,
22096- struct thread_info *tinfo, int *graph)
22097+ struct task_struct *task, int *graph)
22098 { }
22099 #endif
22100
22101@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22102 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
22103 */
22104
22105-static inline int valid_stack_ptr(struct thread_info *tinfo,
22106- void *p, unsigned int size, void *end)
22107+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
22108 {
22109- void *t = tinfo;
22110 if (end) {
22111 if (p < end && p >= (end-THREAD_SIZE))
22112 return 1;
22113@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
22114 }
22115
22116 unsigned long
22117-print_context_stack(struct thread_info *tinfo,
22118+print_context_stack(struct task_struct *task, void *stack_start,
22119 unsigned long *stack, unsigned long bp,
22120 const struct stacktrace_ops *ops, void *data,
22121 unsigned long *end, int *graph)
22122 {
22123 struct stack_frame *frame = (struct stack_frame *)bp;
22124
22125- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22126+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22127 unsigned long addr;
22128
22129 addr = *stack;
22130@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22131 } else {
22132 ops->address(data, addr, 0);
22133 }
22134- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22135+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22136 }
22137 stack++;
22138 }
22139@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22140 EXPORT_SYMBOL_GPL(print_context_stack);
22141
22142 unsigned long
22143-print_context_stack_bp(struct thread_info *tinfo,
22144+print_context_stack_bp(struct task_struct *task, void *stack_start,
22145 unsigned long *stack, unsigned long bp,
22146 const struct stacktrace_ops *ops, void *data,
22147 unsigned long *end, int *graph)
22148@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22149 struct stack_frame *frame = (struct stack_frame *)bp;
22150 unsigned long *ret_addr = &frame->return_address;
22151
22152- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22153+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22154 unsigned long addr = *ret_addr;
22155
22156 if (!__kernel_text_address(addr))
22157@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22158 ops->address(data, addr, 1);
22159 frame = frame->next_frame;
22160 ret_addr = &frame->return_address;
22161- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22162+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22163 }
22164
22165 return (unsigned long)frame;
22166@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22167 static void print_trace_address(void *data, unsigned long addr, int reliable)
22168 {
22169 touch_nmi_watchdog();
22170- printk(data);
22171+ printk("%s", (char *)data);
22172 printk_stack_address(addr, reliable);
22173 }
22174
22175@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
22176 }
22177 EXPORT_SYMBOL_GPL(oops_begin);
22178
22179+extern void gr_handle_kernel_exploit(void);
22180+
22181 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22182 {
22183 if (regs && kexec_should_crash(current))
22184@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22185 panic("Fatal exception in interrupt");
22186 if (panic_on_oops)
22187 panic("Fatal exception");
22188- do_exit(signr);
22189+
22190+ gr_handle_kernel_exploit();
22191+
22192+ do_group_exit(signr);
22193 }
22194
22195 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
22196@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
22197 print_modules();
22198 show_regs(regs);
22199 #ifdef CONFIG_X86_32
22200- if (user_mode_vm(regs)) {
22201+ if (user_mode(regs)) {
22202 sp = regs->sp;
22203 ss = regs->ss & 0xffff;
22204 } else {
22205@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22206 unsigned long flags = oops_begin();
22207 int sig = SIGSEGV;
22208
22209- if (!user_mode_vm(regs))
22210+ if (!user_mode(regs))
22211 report_bug(regs->ip, regs);
22212
22213 if (__die(str, regs, err))
22214diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22215index f2a1770..10fa52d 100644
22216--- a/arch/x86/kernel/dumpstack_32.c
22217+++ b/arch/x86/kernel/dumpstack_32.c
22218@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22219 bp = stack_frame(task, regs);
22220
22221 for (;;) {
22222- struct thread_info *context;
22223+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22224
22225- context = (struct thread_info *)
22226- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
22227- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
22228+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22229
22230- stack = (unsigned long *)context->previous_esp;
22231- if (!stack)
22232+ if (stack_start == task_stack_page(task))
22233 break;
22234+ stack = *(unsigned long **)stack_start;
22235 if (ops->stack(data, "IRQ") < 0)
22236 break;
22237 touch_nmi_watchdog();
22238@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
22239 int i;
22240
22241 show_regs_print_info(KERN_EMERG);
22242- __show_regs(regs, !user_mode_vm(regs));
22243+ __show_regs(regs, !user_mode(regs));
22244
22245 /*
22246 * When in-kernel, we also print out the stack and code at the
22247 * time of the fault..
22248 */
22249- if (!user_mode_vm(regs)) {
22250+ if (!user_mode(regs)) {
22251 unsigned int code_prologue = code_bytes * 43 / 64;
22252 unsigned int code_len = code_bytes;
22253 unsigned char c;
22254 u8 *ip;
22255+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22256
22257 pr_emerg("Stack:\n");
22258 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22259
22260 pr_emerg("Code:");
22261
22262- ip = (u8 *)regs->ip - code_prologue;
22263+ ip = (u8 *)regs->ip - code_prologue + cs_base;
22264 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22265 /* try starting at IP */
22266- ip = (u8 *)regs->ip;
22267+ ip = (u8 *)regs->ip + cs_base;
22268 code_len = code_len - code_prologue + 1;
22269 }
22270 for (i = 0; i < code_len; i++, ip++) {
22271@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
22272 pr_cont(" Bad EIP value.");
22273 break;
22274 }
22275- if (ip == (u8 *)regs->ip)
22276+ if (ip == (u8 *)regs->ip + cs_base)
22277 pr_cont(" <%02x>", c);
22278 else
22279 pr_cont(" %02x", c);
22280@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
22281 {
22282 unsigned short ud2;
22283
22284+ ip = ktla_ktva(ip);
22285 if (ip < PAGE_OFFSET)
22286 return 0;
22287 if (probe_kernel_address((unsigned short *)ip, ud2))
22288@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
22289
22290 return ud2 == 0x0b0f;
22291 }
22292+
22293+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22294+void pax_check_alloca(unsigned long size)
22295+{
22296+ unsigned long sp = (unsigned long)&sp, stack_left;
22297+
22298+ /* all kernel stacks are of the same size */
22299+ stack_left = sp & (THREAD_SIZE - 1);
22300+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22301+}
22302+EXPORT_SYMBOL(pax_check_alloca);
22303+#endif
22304diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22305index addb207..921706b 100644
22306--- a/arch/x86/kernel/dumpstack_64.c
22307+++ b/arch/x86/kernel/dumpstack_64.c
22308@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22309 unsigned long *irq_stack_end =
22310 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22311 unsigned used = 0;
22312- struct thread_info *tinfo;
22313 int graph = 0;
22314 unsigned long dummy;
22315+ void *stack_start;
22316
22317 if (!task)
22318 task = current;
22319@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22320 * current stack address. If the stacks consist of nested
22321 * exceptions
22322 */
22323- tinfo = task_thread_info(task);
22324 for (;;) {
22325 char *id;
22326 unsigned long *estack_end;
22327+
22328 estack_end = in_exception_stack(cpu, (unsigned long)stack,
22329 &used, &id);
22330
22331@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22332 if (ops->stack(data, id) < 0)
22333 break;
22334
22335- bp = ops->walk_stack(tinfo, stack, bp, ops,
22336+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
22337 data, estack_end, &graph);
22338 ops->stack(data, "<EOE>");
22339 /*
22340@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22341 * second-to-last pointer (index -2 to end) in the
22342 * exception stack:
22343 */
22344+ if ((u16)estack_end[-1] != __KERNEL_DS)
22345+ goto out;
22346 stack = (unsigned long *) estack_end[-2];
22347 continue;
22348 }
22349@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22350 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
22351 if (ops->stack(data, "IRQ") < 0)
22352 break;
22353- bp = ops->walk_stack(tinfo, stack, bp,
22354+ bp = ops->walk_stack(task, irq_stack, stack, bp,
22355 ops, data, irq_stack_end, &graph);
22356 /*
22357 * We link to the next stack (which would be
22358@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22359 /*
22360 * This handles the process stack:
22361 */
22362- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22363+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22364+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22365+out:
22366 put_cpu();
22367 }
22368 EXPORT_SYMBOL(dump_trace);
22369@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
22370
22371 return ud2 == 0x0b0f;
22372 }
22373+
22374+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22375+void pax_check_alloca(unsigned long size)
22376+{
22377+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22378+ unsigned cpu, used;
22379+ char *id;
22380+
22381+ /* check the process stack first */
22382+ stack_start = (unsigned long)task_stack_page(current);
22383+ stack_end = stack_start + THREAD_SIZE;
22384+ if (likely(stack_start <= sp && sp < stack_end)) {
22385+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
22386+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22387+ return;
22388+ }
22389+
22390+ cpu = get_cpu();
22391+
22392+ /* check the irq stacks */
22393+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22394+ stack_start = stack_end - IRQ_STACK_SIZE;
22395+ if (stack_start <= sp && sp < stack_end) {
22396+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22397+ put_cpu();
22398+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22399+ return;
22400+ }
22401+
22402+ /* check the exception stacks */
22403+ used = 0;
22404+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22405+ stack_start = stack_end - EXCEPTION_STKSZ;
22406+ if (stack_end && stack_start <= sp && sp < stack_end) {
22407+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22408+ put_cpu();
22409+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22410+ return;
22411+ }
22412+
22413+ put_cpu();
22414+
22415+ /* unknown stack */
22416+ BUG();
22417+}
22418+EXPORT_SYMBOL(pax_check_alloca);
22419+#endif
22420diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22421index 988c00a..4f673b6 100644
22422--- a/arch/x86/kernel/e820.c
22423+++ b/arch/x86/kernel/e820.c
22424@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22425
22426 static void early_panic(char *msg)
22427 {
22428- early_printk(msg);
22429- panic(msg);
22430+ early_printk("%s", msg);
22431+ panic("%s", msg);
22432 }
22433
22434 static int userdef __initdata;
22435diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22436index 01d1c18..8073693 100644
22437--- a/arch/x86/kernel/early_printk.c
22438+++ b/arch/x86/kernel/early_printk.c
22439@@ -7,6 +7,7 @@
22440 #include <linux/pci_regs.h>
22441 #include <linux/pci_ids.h>
22442 #include <linux/errno.h>
22443+#include <linux/sched.h>
22444 #include <asm/io.h>
22445 #include <asm/processor.h>
22446 #include <asm/fcntl.h>
22447diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22448index a2a4f46..6cab058 100644
22449--- a/arch/x86/kernel/entry_32.S
22450+++ b/arch/x86/kernel/entry_32.S
22451@@ -177,13 +177,153 @@
22452 /*CFI_REL_OFFSET gs, PT_GS*/
22453 .endm
22454 .macro SET_KERNEL_GS reg
22455+
22456+#ifdef CONFIG_CC_STACKPROTECTOR
22457 movl $(__KERNEL_STACK_CANARY), \reg
22458+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22459+ movl $(__USER_DS), \reg
22460+#else
22461+ xorl \reg, \reg
22462+#endif
22463+
22464 movl \reg, %gs
22465 .endm
22466
22467 #endif /* CONFIG_X86_32_LAZY_GS */
22468
22469-.macro SAVE_ALL
22470+.macro pax_enter_kernel
22471+#ifdef CONFIG_PAX_KERNEXEC
22472+ call pax_enter_kernel
22473+#endif
22474+.endm
22475+
22476+.macro pax_exit_kernel
22477+#ifdef CONFIG_PAX_KERNEXEC
22478+ call pax_exit_kernel
22479+#endif
22480+.endm
22481+
22482+#ifdef CONFIG_PAX_KERNEXEC
22483+ENTRY(pax_enter_kernel)
22484+#ifdef CONFIG_PARAVIRT
22485+ pushl %eax
22486+ pushl %ecx
22487+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22488+ mov %eax, %esi
22489+#else
22490+ mov %cr0, %esi
22491+#endif
22492+ bts $16, %esi
22493+ jnc 1f
22494+ mov %cs, %esi
22495+ cmp $__KERNEL_CS, %esi
22496+ jz 3f
22497+ ljmp $__KERNEL_CS, $3f
22498+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22499+2:
22500+#ifdef CONFIG_PARAVIRT
22501+ mov %esi, %eax
22502+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22503+#else
22504+ mov %esi, %cr0
22505+#endif
22506+3:
22507+#ifdef CONFIG_PARAVIRT
22508+ popl %ecx
22509+ popl %eax
22510+#endif
22511+ ret
22512+ENDPROC(pax_enter_kernel)
22513+
22514+ENTRY(pax_exit_kernel)
22515+#ifdef CONFIG_PARAVIRT
22516+ pushl %eax
22517+ pushl %ecx
22518+#endif
22519+ mov %cs, %esi
22520+ cmp $__KERNEXEC_KERNEL_CS, %esi
22521+ jnz 2f
22522+#ifdef CONFIG_PARAVIRT
22523+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22524+ mov %eax, %esi
22525+#else
22526+ mov %cr0, %esi
22527+#endif
22528+ btr $16, %esi
22529+ ljmp $__KERNEL_CS, $1f
22530+1:
22531+#ifdef CONFIG_PARAVIRT
22532+ mov %esi, %eax
22533+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22534+#else
22535+ mov %esi, %cr0
22536+#endif
22537+2:
22538+#ifdef CONFIG_PARAVIRT
22539+ popl %ecx
22540+ popl %eax
22541+#endif
22542+ ret
22543+ENDPROC(pax_exit_kernel)
22544+#endif
22545+
22546+ .macro pax_erase_kstack
22547+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22548+ call pax_erase_kstack
22549+#endif
22550+ .endm
22551+
22552+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22553+/*
22554+ * ebp: thread_info
22555+ */
22556+ENTRY(pax_erase_kstack)
22557+ pushl %edi
22558+ pushl %ecx
22559+ pushl %eax
22560+
22561+ mov TI_lowest_stack(%ebp), %edi
22562+ mov $-0xBEEF, %eax
22563+ std
22564+
22565+1: mov %edi, %ecx
22566+ and $THREAD_SIZE_asm - 1, %ecx
22567+ shr $2, %ecx
22568+ repne scasl
22569+ jecxz 2f
22570+
22571+ cmp $2*16, %ecx
22572+ jc 2f
22573+
22574+ mov $2*16, %ecx
22575+ repe scasl
22576+ jecxz 2f
22577+ jne 1b
22578+
22579+2: cld
22580+ mov %esp, %ecx
22581+ sub %edi, %ecx
22582+
22583+ cmp $THREAD_SIZE_asm, %ecx
22584+ jb 3f
22585+ ud2
22586+3:
22587+
22588+ shr $2, %ecx
22589+ rep stosl
22590+
22591+ mov TI_task_thread_sp0(%ebp), %edi
22592+ sub $128, %edi
22593+ mov %edi, TI_lowest_stack(%ebp)
22594+
22595+ popl %eax
22596+ popl %ecx
22597+ popl %edi
22598+ ret
22599+ENDPROC(pax_erase_kstack)
22600+#endif
22601+
22602+.macro __SAVE_ALL _DS
22603 cld
22604 PUSH_GS
22605 pushl_cfi %fs
22606@@ -206,7 +346,7 @@
22607 CFI_REL_OFFSET ecx, 0
22608 pushl_cfi %ebx
22609 CFI_REL_OFFSET ebx, 0
22610- movl $(__USER_DS), %edx
22611+ movl $\_DS, %edx
22612 movl %edx, %ds
22613 movl %edx, %es
22614 movl $(__KERNEL_PERCPU), %edx
22615@@ -214,6 +354,15 @@
22616 SET_KERNEL_GS %edx
22617 .endm
22618
22619+.macro SAVE_ALL
22620+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22621+ __SAVE_ALL __KERNEL_DS
22622+ pax_enter_kernel
22623+#else
22624+ __SAVE_ALL __USER_DS
22625+#endif
22626+.endm
22627+
22628 .macro RESTORE_INT_REGS
22629 popl_cfi %ebx
22630 CFI_RESTORE ebx
22631@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22632 popfl_cfi
22633 jmp syscall_exit
22634 CFI_ENDPROC
22635-END(ret_from_fork)
22636+ENDPROC(ret_from_fork)
22637
22638 ENTRY(ret_from_kernel_thread)
22639 CFI_STARTPROC
22640@@ -344,7 +493,15 @@ ret_from_intr:
22641 andl $SEGMENT_RPL_MASK, %eax
22642 #endif
22643 cmpl $USER_RPL, %eax
22644+
22645+#ifdef CONFIG_PAX_KERNEXEC
22646+ jae resume_userspace
22647+
22648+ pax_exit_kernel
22649+ jmp resume_kernel
22650+#else
22651 jb resume_kernel # not returning to v8086 or userspace
22652+#endif
22653
22654 ENTRY(resume_userspace)
22655 LOCKDEP_SYS_EXIT
22656@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22657 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22658 # int/exception return?
22659 jne work_pending
22660- jmp restore_all
22661-END(ret_from_exception)
22662+ jmp restore_all_pax
22663+ENDPROC(ret_from_exception)
22664
22665 #ifdef CONFIG_PREEMPT
22666 ENTRY(resume_kernel)
22667@@ -369,7 +526,7 @@ need_resched:
22668 jz restore_all
22669 call preempt_schedule_irq
22670 jmp need_resched
22671-END(resume_kernel)
22672+ENDPROC(resume_kernel)
22673 #endif
22674 CFI_ENDPROC
22675 /*
22676@@ -403,30 +560,45 @@ sysenter_past_esp:
22677 /*CFI_REL_OFFSET cs, 0*/
22678 /*
22679 * Push current_thread_info()->sysenter_return to the stack.
22680- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22681- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22682 */
22683- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22684+ pushl_cfi $0
22685 CFI_REL_OFFSET eip, 0
22686
22687 pushl_cfi %eax
22688 SAVE_ALL
22689+ GET_THREAD_INFO(%ebp)
22690+ movl TI_sysenter_return(%ebp),%ebp
22691+ movl %ebp,PT_EIP(%esp)
22692 ENABLE_INTERRUPTS(CLBR_NONE)
22693
22694 /*
22695 * Load the potential sixth argument from user stack.
22696 * Careful about security.
22697 */
22698+ movl PT_OLDESP(%esp),%ebp
22699+
22700+#ifdef CONFIG_PAX_MEMORY_UDEREF
22701+ mov PT_OLDSS(%esp),%ds
22702+1: movl %ds:(%ebp),%ebp
22703+ push %ss
22704+ pop %ds
22705+#else
22706 cmpl $__PAGE_OFFSET-3,%ebp
22707 jae syscall_fault
22708 ASM_STAC
22709 1: movl (%ebp),%ebp
22710 ASM_CLAC
22711+#endif
22712+
22713 movl %ebp,PT_EBP(%esp)
22714 _ASM_EXTABLE(1b,syscall_fault)
22715
22716 GET_THREAD_INFO(%ebp)
22717
22718+#ifdef CONFIG_PAX_RANDKSTACK
22719+ pax_erase_kstack
22720+#endif
22721+
22722 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22723 jnz sysenter_audit
22724 sysenter_do_call:
22725@@ -441,12 +613,24 @@ sysenter_do_call:
22726 testl $_TIF_ALLWORK_MASK, %ecx
22727 jne sysexit_audit
22728 sysenter_exit:
22729+
22730+#ifdef CONFIG_PAX_RANDKSTACK
22731+ pushl_cfi %eax
22732+ movl %esp, %eax
22733+ call pax_randomize_kstack
22734+ popl_cfi %eax
22735+#endif
22736+
22737+ pax_erase_kstack
22738+
22739 /* if something modifies registers it must also disable sysexit */
22740 movl PT_EIP(%esp), %edx
22741 movl PT_OLDESP(%esp), %ecx
22742 xorl %ebp,%ebp
22743 TRACE_IRQS_ON
22744 1: mov PT_FS(%esp), %fs
22745+2: mov PT_DS(%esp), %ds
22746+3: mov PT_ES(%esp), %es
22747 PTGS_TO_GS
22748 ENABLE_INTERRUPTS_SYSEXIT
22749
22750@@ -463,6 +647,9 @@ sysenter_audit:
22751 movl %eax,%edx /* 2nd arg: syscall number */
22752 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22753 call __audit_syscall_entry
22754+
22755+ pax_erase_kstack
22756+
22757 pushl_cfi %ebx
22758 movl PT_EAX(%esp),%eax /* reload syscall number */
22759 jmp sysenter_do_call
22760@@ -488,10 +675,16 @@ sysexit_audit:
22761
22762 CFI_ENDPROC
22763 .pushsection .fixup,"ax"
22764-2: movl $0,PT_FS(%esp)
22765+4: movl $0,PT_FS(%esp)
22766+ jmp 1b
22767+5: movl $0,PT_DS(%esp)
22768+ jmp 1b
22769+6: movl $0,PT_ES(%esp)
22770 jmp 1b
22771 .popsection
22772- _ASM_EXTABLE(1b,2b)
22773+ _ASM_EXTABLE(1b,4b)
22774+ _ASM_EXTABLE(2b,5b)
22775+ _ASM_EXTABLE(3b,6b)
22776 PTGS_TO_GS_EX
22777 ENDPROC(ia32_sysenter_target)
22778
22779@@ -506,6 +699,11 @@ ENTRY(system_call)
22780 pushl_cfi %eax # save orig_eax
22781 SAVE_ALL
22782 GET_THREAD_INFO(%ebp)
22783+
22784+#ifdef CONFIG_PAX_RANDKSTACK
22785+ pax_erase_kstack
22786+#endif
22787+
22788 # system call tracing in operation / emulation
22789 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22790 jnz syscall_trace_entry
22791@@ -524,6 +722,15 @@ syscall_exit:
22792 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22793 jne syscall_exit_work
22794
22795+restore_all_pax:
22796+
22797+#ifdef CONFIG_PAX_RANDKSTACK
22798+ movl %esp, %eax
22799+ call pax_randomize_kstack
22800+#endif
22801+
22802+ pax_erase_kstack
22803+
22804 restore_all:
22805 TRACE_IRQS_IRET
22806 restore_all_notrace:
22807@@ -580,14 +787,34 @@ ldt_ss:
22808 * compensating for the offset by changing to the ESPFIX segment with
22809 * a base address that matches for the difference.
22810 */
22811-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22812+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22813 mov %esp, %edx /* load kernel esp */
22814 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22815 mov %dx, %ax /* eax: new kernel esp */
22816 sub %eax, %edx /* offset (low word is 0) */
22817+#ifdef CONFIG_SMP
22818+ movl PER_CPU_VAR(cpu_number), %ebx
22819+ shll $PAGE_SHIFT_asm, %ebx
22820+ addl $cpu_gdt_table, %ebx
22821+#else
22822+ movl $cpu_gdt_table, %ebx
22823+#endif
22824 shr $16, %edx
22825- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22826- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22827+
22828+#ifdef CONFIG_PAX_KERNEXEC
22829+ mov %cr0, %esi
22830+ btr $16, %esi
22831+ mov %esi, %cr0
22832+#endif
22833+
22834+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22835+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22836+
22837+#ifdef CONFIG_PAX_KERNEXEC
22838+ bts $16, %esi
22839+ mov %esi, %cr0
22840+#endif
22841+
22842 pushl_cfi $__ESPFIX_SS
22843 pushl_cfi %eax /* new kernel esp */
22844 /* Disable interrupts, but do not irqtrace this section: we
22845@@ -616,20 +843,18 @@ work_resched:
22846 movl TI_flags(%ebp), %ecx
22847 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22848 # than syscall tracing?
22849- jz restore_all
22850+ jz restore_all_pax
22851 testb $_TIF_NEED_RESCHED, %cl
22852 jnz work_resched
22853
22854 work_notifysig: # deal with pending signals and
22855 # notify-resume requests
22856+ movl %esp, %eax
22857 #ifdef CONFIG_VM86
22858 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22859- movl %esp, %eax
22860 jne work_notifysig_v86 # returning to kernel-space or
22861 # vm86-space
22862 1:
22863-#else
22864- movl %esp, %eax
22865 #endif
22866 TRACE_IRQS_ON
22867 ENABLE_INTERRUPTS(CLBR_NONE)
22868@@ -650,7 +875,7 @@ work_notifysig_v86:
22869 movl %eax, %esp
22870 jmp 1b
22871 #endif
22872-END(work_pending)
22873+ENDPROC(work_pending)
22874
22875 # perform syscall exit tracing
22876 ALIGN
22877@@ -658,11 +883,14 @@ syscall_trace_entry:
22878 movl $-ENOSYS,PT_EAX(%esp)
22879 movl %esp, %eax
22880 call syscall_trace_enter
22881+
22882+ pax_erase_kstack
22883+
22884 /* What it returned is what we'll actually use. */
22885 cmpl $(NR_syscalls), %eax
22886 jnae syscall_call
22887 jmp syscall_exit
22888-END(syscall_trace_entry)
22889+ENDPROC(syscall_trace_entry)
22890
22891 # perform syscall exit tracing
22892 ALIGN
22893@@ -675,21 +903,25 @@ syscall_exit_work:
22894 movl %esp, %eax
22895 call syscall_trace_leave
22896 jmp resume_userspace
22897-END(syscall_exit_work)
22898+ENDPROC(syscall_exit_work)
22899 CFI_ENDPROC
22900
22901 RING0_INT_FRAME # can't unwind into user space anyway
22902 syscall_fault:
22903+#ifdef CONFIG_PAX_MEMORY_UDEREF
22904+ push %ss
22905+ pop %ds
22906+#endif
22907 ASM_CLAC
22908 GET_THREAD_INFO(%ebp)
22909 movl $-EFAULT,PT_EAX(%esp)
22910 jmp resume_userspace
22911-END(syscall_fault)
22912+ENDPROC(syscall_fault)
22913
22914 syscall_badsys:
22915 movl $-ENOSYS,PT_EAX(%esp)
22916 jmp resume_userspace
22917-END(syscall_badsys)
22918+ENDPROC(syscall_badsys)
22919 CFI_ENDPROC
22920 /*
22921 * End of kprobes section
22922@@ -705,8 +937,15 @@ END(syscall_badsys)
22923 * normal stack and adjusts ESP with the matching offset.
22924 */
22925 /* fixup the stack */
22926- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22927- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22928+#ifdef CONFIG_SMP
22929+ movl PER_CPU_VAR(cpu_number), %ebx
22930+ shll $PAGE_SHIFT_asm, %ebx
22931+ addl $cpu_gdt_table, %ebx
22932+#else
22933+ movl $cpu_gdt_table, %ebx
22934+#endif
22935+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22936+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22937 shl $16, %eax
22938 addl %esp, %eax /* the adjusted stack pointer */
22939 pushl_cfi $__KERNEL_DS
22940@@ -759,7 +998,7 @@ vector=vector+1
22941 .endr
22942 2: jmp common_interrupt
22943 .endr
22944-END(irq_entries_start)
22945+ENDPROC(irq_entries_start)
22946
22947 .previous
22948 END(interrupt)
22949@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22950 pushl_cfi $do_coprocessor_error
22951 jmp error_code
22952 CFI_ENDPROC
22953-END(coprocessor_error)
22954+ENDPROC(coprocessor_error)
22955
22956 ENTRY(simd_coprocessor_error)
22957 RING0_INT_FRAME
22958@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22959 .section .altinstructions,"a"
22960 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22961 .previous
22962-.section .altinstr_replacement,"ax"
22963+.section .altinstr_replacement,"a"
22964 663: pushl $do_simd_coprocessor_error
22965 664:
22966 .previous
22967@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22968 #endif
22969 jmp error_code
22970 CFI_ENDPROC
22971-END(simd_coprocessor_error)
22972+ENDPROC(simd_coprocessor_error)
22973
22974 ENTRY(device_not_available)
22975 RING0_INT_FRAME
22976@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22977 pushl_cfi $do_device_not_available
22978 jmp error_code
22979 CFI_ENDPROC
22980-END(device_not_available)
22981+ENDPROC(device_not_available)
22982
22983 #ifdef CONFIG_PARAVIRT
22984 ENTRY(native_iret)
22985 iret
22986 _ASM_EXTABLE(native_iret, iret_exc)
22987-END(native_iret)
22988+ENDPROC(native_iret)
22989
22990 ENTRY(native_irq_enable_sysexit)
22991 sti
22992 sysexit
22993-END(native_irq_enable_sysexit)
22994+ENDPROC(native_irq_enable_sysexit)
22995 #endif
22996
22997 ENTRY(overflow)
22998@@ -872,7 +1111,7 @@ ENTRY(overflow)
22999 pushl_cfi $do_overflow
23000 jmp error_code
23001 CFI_ENDPROC
23002-END(overflow)
23003+ENDPROC(overflow)
23004
23005 ENTRY(bounds)
23006 RING0_INT_FRAME
23007@@ -881,7 +1120,7 @@ ENTRY(bounds)
23008 pushl_cfi $do_bounds
23009 jmp error_code
23010 CFI_ENDPROC
23011-END(bounds)
23012+ENDPROC(bounds)
23013
23014 ENTRY(invalid_op)
23015 RING0_INT_FRAME
23016@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
23017 pushl_cfi $do_invalid_op
23018 jmp error_code
23019 CFI_ENDPROC
23020-END(invalid_op)
23021+ENDPROC(invalid_op)
23022
23023 ENTRY(coprocessor_segment_overrun)
23024 RING0_INT_FRAME
23025@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
23026 pushl_cfi $do_coprocessor_segment_overrun
23027 jmp error_code
23028 CFI_ENDPROC
23029-END(coprocessor_segment_overrun)
23030+ENDPROC(coprocessor_segment_overrun)
23031
23032 ENTRY(invalid_TSS)
23033 RING0_EC_FRAME
23034@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
23035 pushl_cfi $do_invalid_TSS
23036 jmp error_code
23037 CFI_ENDPROC
23038-END(invalid_TSS)
23039+ENDPROC(invalid_TSS)
23040
23041 ENTRY(segment_not_present)
23042 RING0_EC_FRAME
23043@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
23044 pushl_cfi $do_segment_not_present
23045 jmp error_code
23046 CFI_ENDPROC
23047-END(segment_not_present)
23048+ENDPROC(segment_not_present)
23049
23050 ENTRY(stack_segment)
23051 RING0_EC_FRAME
23052@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
23053 pushl_cfi $do_stack_segment
23054 jmp error_code
23055 CFI_ENDPROC
23056-END(stack_segment)
23057+ENDPROC(stack_segment)
23058
23059 ENTRY(alignment_check)
23060 RING0_EC_FRAME
23061@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
23062 pushl_cfi $do_alignment_check
23063 jmp error_code
23064 CFI_ENDPROC
23065-END(alignment_check)
23066+ENDPROC(alignment_check)
23067
23068 ENTRY(divide_error)
23069 RING0_INT_FRAME
23070@@ -940,7 +1179,7 @@ ENTRY(divide_error)
23071 pushl_cfi $do_divide_error
23072 jmp error_code
23073 CFI_ENDPROC
23074-END(divide_error)
23075+ENDPROC(divide_error)
23076
23077 #ifdef CONFIG_X86_MCE
23078 ENTRY(machine_check)
23079@@ -950,7 +1189,7 @@ ENTRY(machine_check)
23080 pushl_cfi machine_check_vector
23081 jmp error_code
23082 CFI_ENDPROC
23083-END(machine_check)
23084+ENDPROC(machine_check)
23085 #endif
23086
23087 ENTRY(spurious_interrupt_bug)
23088@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
23089 pushl_cfi $do_spurious_interrupt_bug
23090 jmp error_code
23091 CFI_ENDPROC
23092-END(spurious_interrupt_bug)
23093+ENDPROC(spurious_interrupt_bug)
23094 /*
23095 * End of kprobes section
23096 */
23097@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
23098
23099 ENTRY(mcount)
23100 ret
23101-END(mcount)
23102+ENDPROC(mcount)
23103
23104 ENTRY(ftrace_caller)
23105 cmpl $0, function_trace_stop
23106@@ -1103,7 +1342,7 @@ ftrace_graph_call:
23107 .globl ftrace_stub
23108 ftrace_stub:
23109 ret
23110-END(ftrace_caller)
23111+ENDPROC(ftrace_caller)
23112
23113 ENTRY(ftrace_regs_caller)
23114 pushf /* push flags before compare (in cs location) */
23115@@ -1207,7 +1446,7 @@ trace:
23116 popl %ecx
23117 popl %eax
23118 jmp ftrace_stub
23119-END(mcount)
23120+ENDPROC(mcount)
23121 #endif /* CONFIG_DYNAMIC_FTRACE */
23122 #endif /* CONFIG_FUNCTION_TRACER */
23123
23124@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
23125 popl %ecx
23126 popl %eax
23127 ret
23128-END(ftrace_graph_caller)
23129+ENDPROC(ftrace_graph_caller)
23130
23131 .globl return_to_handler
23132 return_to_handler:
23133@@ -1291,15 +1530,18 @@ error_code:
23134 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23135 REG_TO_PTGS %ecx
23136 SET_KERNEL_GS %ecx
23137- movl $(__USER_DS), %ecx
23138+ movl $(__KERNEL_DS), %ecx
23139 movl %ecx, %ds
23140 movl %ecx, %es
23141+
23142+ pax_enter_kernel
23143+
23144 TRACE_IRQS_OFF
23145 movl %esp,%eax # pt_regs pointer
23146 call *%edi
23147 jmp ret_from_exception
23148 CFI_ENDPROC
23149-END(page_fault)
23150+ENDPROC(page_fault)
23151
23152 /*
23153 * Debug traps and NMI can happen at the one SYSENTER instruction
23154@@ -1342,7 +1584,7 @@ debug_stack_correct:
23155 call do_debug
23156 jmp ret_from_exception
23157 CFI_ENDPROC
23158-END(debug)
23159+ENDPROC(debug)
23160
23161 /*
23162 * NMI is doubly nasty. It can happen _while_ we're handling
23163@@ -1380,6 +1622,9 @@ nmi_stack_correct:
23164 xorl %edx,%edx # zero error code
23165 movl %esp,%eax # pt_regs pointer
23166 call do_nmi
23167+
23168+ pax_exit_kernel
23169+
23170 jmp restore_all_notrace
23171 CFI_ENDPROC
23172
23173@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
23174 FIXUP_ESPFIX_STACK # %eax == %esp
23175 xorl %edx,%edx # zero error code
23176 call do_nmi
23177+
23178+ pax_exit_kernel
23179+
23180 RESTORE_REGS
23181 lss 12+4(%esp), %esp # back to espfix stack
23182 CFI_ADJUST_CFA_OFFSET -24
23183 jmp irq_return
23184 CFI_ENDPROC
23185-END(nmi)
23186+ENDPROC(nmi)
23187
23188 ENTRY(int3)
23189 RING0_INT_FRAME
23190@@ -1434,14 +1682,14 @@ ENTRY(int3)
23191 call do_int3
23192 jmp ret_from_exception
23193 CFI_ENDPROC
23194-END(int3)
23195+ENDPROC(int3)
23196
23197 ENTRY(general_protection)
23198 RING0_EC_FRAME
23199 pushl_cfi $do_general_protection
23200 jmp error_code
23201 CFI_ENDPROC
23202-END(general_protection)
23203+ENDPROC(general_protection)
23204
23205 #ifdef CONFIG_KVM_GUEST
23206 ENTRY(async_page_fault)
23207@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
23208 pushl_cfi $do_async_page_fault
23209 jmp error_code
23210 CFI_ENDPROC
23211-END(async_page_fault)
23212+ENDPROC(async_page_fault)
23213 #endif
23214
23215 /*
23216diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23217index 1e96c36..3ff710a 100644
23218--- a/arch/x86/kernel/entry_64.S
23219+++ b/arch/x86/kernel/entry_64.S
23220@@ -59,6 +59,8 @@
23221 #include <asm/context_tracking.h>
23222 #include <asm/smap.h>
23223 #include <linux/err.h>
23224+#include <asm/pgtable.h>
23225+#include <asm/alternative-asm.h>
23226
23227 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23228 #include <linux/elf-em.h>
23229@@ -80,8 +82,9 @@
23230 #ifdef CONFIG_DYNAMIC_FTRACE
23231
23232 ENTRY(function_hook)
23233+ pax_force_retaddr
23234 retq
23235-END(function_hook)
23236+ENDPROC(function_hook)
23237
23238 /* skip is set if stack has been adjusted */
23239 .macro ftrace_caller_setup skip=0
23240@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
23241 #endif
23242
23243 GLOBAL(ftrace_stub)
23244+ pax_force_retaddr
23245 retq
23246-END(ftrace_caller)
23247+ENDPROC(ftrace_caller)
23248
23249 ENTRY(ftrace_regs_caller)
23250 /* Save the current flags before compare (in SS location)*/
23251@@ -191,7 +195,7 @@ ftrace_restore_flags:
23252 popfq
23253 jmp ftrace_stub
23254
23255-END(ftrace_regs_caller)
23256+ENDPROC(ftrace_regs_caller)
23257
23258
23259 #else /* ! CONFIG_DYNAMIC_FTRACE */
23260@@ -212,6 +216,7 @@ ENTRY(function_hook)
23261 #endif
23262
23263 GLOBAL(ftrace_stub)
23264+ pax_force_retaddr
23265 retq
23266
23267 trace:
23268@@ -225,12 +230,13 @@ trace:
23269 #endif
23270 subq $MCOUNT_INSN_SIZE, %rdi
23271
23272+ pax_force_fptr ftrace_trace_function
23273 call *ftrace_trace_function
23274
23275 MCOUNT_RESTORE_FRAME
23276
23277 jmp ftrace_stub
23278-END(function_hook)
23279+ENDPROC(function_hook)
23280 #endif /* CONFIG_DYNAMIC_FTRACE */
23281 #endif /* CONFIG_FUNCTION_TRACER */
23282
23283@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
23284
23285 MCOUNT_RESTORE_FRAME
23286
23287+ pax_force_retaddr
23288 retq
23289-END(ftrace_graph_caller)
23290+ENDPROC(ftrace_graph_caller)
23291
23292 GLOBAL(return_to_handler)
23293 subq $24, %rsp
23294@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
23295 movq 8(%rsp), %rdx
23296 movq (%rsp), %rax
23297 addq $24, %rsp
23298+ pax_force_fptr %rdi
23299 jmp *%rdi
23300+ENDPROC(return_to_handler)
23301 #endif
23302
23303
23304@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
23305 ENDPROC(native_usergs_sysret64)
23306 #endif /* CONFIG_PARAVIRT */
23307
23308+ .macro ljmpq sel, off
23309+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23310+ .byte 0x48; ljmp *1234f(%rip)
23311+ .pushsection .rodata
23312+ .align 16
23313+ 1234: .quad \off; .word \sel
23314+ .popsection
23315+#else
23316+ pushq $\sel
23317+ pushq $\off
23318+ lretq
23319+#endif
23320+ .endm
23321+
23322+ .macro pax_enter_kernel
23323+ pax_set_fptr_mask
23324+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23325+ call pax_enter_kernel
23326+#endif
23327+ .endm
23328+
23329+ .macro pax_exit_kernel
23330+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23331+ call pax_exit_kernel
23332+#endif
23333+
23334+ .endm
23335+
23336+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23337+ENTRY(pax_enter_kernel)
23338+ pushq %rdi
23339+
23340+#ifdef CONFIG_PARAVIRT
23341+ PV_SAVE_REGS(CLBR_RDI)
23342+#endif
23343+
23344+#ifdef CONFIG_PAX_KERNEXEC
23345+ GET_CR0_INTO_RDI
23346+ bts $16,%rdi
23347+ jnc 3f
23348+ mov %cs,%edi
23349+ cmp $__KERNEL_CS,%edi
23350+ jnz 2f
23351+1:
23352+#endif
23353+
23354+#ifdef CONFIG_PAX_MEMORY_UDEREF
23355+ 661: jmp 111f
23356+ .pushsection .altinstr_replacement, "a"
23357+ 662: ASM_NOP2
23358+ .popsection
23359+ .pushsection .altinstructions, "a"
23360+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23361+ .popsection
23362+ GET_CR3_INTO_RDI
23363+ cmp $0,%dil
23364+ jnz 112f
23365+ mov $__KERNEL_DS,%edi
23366+ mov %edi,%ss
23367+ jmp 111f
23368+112: cmp $1,%dil
23369+ jz 113f
23370+ ud2
23371+113: sub $4097,%rdi
23372+ bts $63,%rdi
23373+ SET_RDI_INTO_CR3
23374+ mov $__UDEREF_KERNEL_DS,%edi
23375+ mov %edi,%ss
23376+111:
23377+#endif
23378+
23379+#ifdef CONFIG_PARAVIRT
23380+ PV_RESTORE_REGS(CLBR_RDI)
23381+#endif
23382+
23383+ popq %rdi
23384+ pax_force_retaddr
23385+ retq
23386+
23387+#ifdef CONFIG_PAX_KERNEXEC
23388+2: ljmpq __KERNEL_CS,1b
23389+3: ljmpq __KERNEXEC_KERNEL_CS,4f
23390+4: SET_RDI_INTO_CR0
23391+ jmp 1b
23392+#endif
23393+ENDPROC(pax_enter_kernel)
23394+
23395+ENTRY(pax_exit_kernel)
23396+ pushq %rdi
23397+
23398+#ifdef CONFIG_PARAVIRT
23399+ PV_SAVE_REGS(CLBR_RDI)
23400+#endif
23401+
23402+#ifdef CONFIG_PAX_KERNEXEC
23403+ mov %cs,%rdi
23404+ cmp $__KERNEXEC_KERNEL_CS,%edi
23405+ jz 2f
23406+ GET_CR0_INTO_RDI
23407+ bts $16,%rdi
23408+ jnc 4f
23409+1:
23410+#endif
23411+
23412+#ifdef CONFIG_PAX_MEMORY_UDEREF
23413+ 661: jmp 111f
23414+ .pushsection .altinstr_replacement, "a"
23415+ 662: ASM_NOP2
23416+ .popsection
23417+ .pushsection .altinstructions, "a"
23418+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23419+ .popsection
23420+ mov %ss,%edi
23421+ cmp $__UDEREF_KERNEL_DS,%edi
23422+ jnz 111f
23423+ GET_CR3_INTO_RDI
23424+ cmp $0,%dil
23425+ jz 112f
23426+ ud2
23427+112: add $4097,%rdi
23428+ bts $63,%rdi
23429+ SET_RDI_INTO_CR3
23430+ mov $__KERNEL_DS,%edi
23431+ mov %edi,%ss
23432+111:
23433+#endif
23434+
23435+#ifdef CONFIG_PARAVIRT
23436+ PV_RESTORE_REGS(CLBR_RDI);
23437+#endif
23438+
23439+ popq %rdi
23440+ pax_force_retaddr
23441+ retq
23442+
23443+#ifdef CONFIG_PAX_KERNEXEC
23444+2: GET_CR0_INTO_RDI
23445+ btr $16,%rdi
23446+ jnc 4f
23447+ ljmpq __KERNEL_CS,3f
23448+3: SET_RDI_INTO_CR0
23449+ jmp 1b
23450+4: ud2
23451+ jmp 4b
23452+#endif
23453+ENDPROC(pax_exit_kernel)
23454+#endif
23455+
23456+ .macro pax_enter_kernel_user
23457+ pax_set_fptr_mask
23458+#ifdef CONFIG_PAX_MEMORY_UDEREF
23459+ call pax_enter_kernel_user
23460+#endif
23461+ .endm
23462+
23463+ .macro pax_exit_kernel_user
23464+#ifdef CONFIG_PAX_MEMORY_UDEREF
23465+ call pax_exit_kernel_user
23466+#endif
23467+#ifdef CONFIG_PAX_RANDKSTACK
23468+ pushq %rax
23469+ pushq %r11
23470+ call pax_randomize_kstack
23471+ popq %r11
23472+ popq %rax
23473+#endif
23474+ .endm
23475+
23476+#ifdef CONFIG_PAX_MEMORY_UDEREF
23477+ENTRY(pax_enter_kernel_user)
23478+ pushq %rdi
23479+ pushq %rbx
23480+
23481+#ifdef CONFIG_PARAVIRT
23482+ PV_SAVE_REGS(CLBR_RDI)
23483+#endif
23484+
23485+ 661: jmp 111f
23486+ .pushsection .altinstr_replacement, "a"
23487+ 662: ASM_NOP2
23488+ .popsection
23489+ .pushsection .altinstructions, "a"
23490+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23491+ .popsection
23492+ GET_CR3_INTO_RDI
23493+ cmp $1,%dil
23494+ jnz 4f
23495+ sub $4097,%rdi
23496+ bts $63,%rdi
23497+ SET_RDI_INTO_CR3
23498+ jmp 3f
23499+111:
23500+
23501+ GET_CR3_INTO_RDI
23502+ mov %rdi,%rbx
23503+ add $__START_KERNEL_map,%rbx
23504+ sub phys_base(%rip),%rbx
23505+
23506+#ifdef CONFIG_PARAVIRT
23507+ cmpl $0, pv_info+PARAVIRT_enabled
23508+ jz 1f
23509+ pushq %rdi
23510+ i = 0
23511+ .rept USER_PGD_PTRS
23512+ mov i*8(%rbx),%rsi
23513+ mov $0,%sil
23514+ lea i*8(%rbx),%rdi
23515+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23516+ i = i + 1
23517+ .endr
23518+ popq %rdi
23519+ jmp 2f
23520+1:
23521+#endif
23522+
23523+ i = 0
23524+ .rept USER_PGD_PTRS
23525+ movb $0,i*8(%rbx)
23526+ i = i + 1
23527+ .endr
23528+
23529+2: SET_RDI_INTO_CR3
23530+
23531+#ifdef CONFIG_PAX_KERNEXEC
23532+ GET_CR0_INTO_RDI
23533+ bts $16,%rdi
23534+ SET_RDI_INTO_CR0
23535+#endif
23536+
23537+3:
23538+
23539+#ifdef CONFIG_PARAVIRT
23540+ PV_RESTORE_REGS(CLBR_RDI)
23541+#endif
23542+
23543+ popq %rbx
23544+ popq %rdi
23545+ pax_force_retaddr
23546+ retq
23547+4: ud2
23548+ENDPROC(pax_enter_kernel_user)
23549+
23550+ENTRY(pax_exit_kernel_user)
23551+ pushq %rdi
23552+ pushq %rbx
23553+
23554+#ifdef CONFIG_PARAVIRT
23555+ PV_SAVE_REGS(CLBR_RDI)
23556+#endif
23557+
23558+ GET_CR3_INTO_RDI
23559+ 661: jmp 1f
23560+ .pushsection .altinstr_replacement, "a"
23561+ 662: ASM_NOP2
23562+ .popsection
23563+ .pushsection .altinstructions, "a"
23564+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23565+ .popsection
23566+ cmp $0,%dil
23567+ jnz 3f
23568+ add $4097,%rdi
23569+ bts $63,%rdi
23570+ SET_RDI_INTO_CR3
23571+ jmp 2f
23572+1:
23573+
23574+ mov %rdi,%rbx
23575+
23576+#ifdef CONFIG_PAX_KERNEXEC
23577+ GET_CR0_INTO_RDI
23578+ btr $16,%rdi
23579+ jnc 3f
23580+ SET_RDI_INTO_CR0
23581+#endif
23582+
23583+ add $__START_KERNEL_map,%rbx
23584+ sub phys_base(%rip),%rbx
23585+
23586+#ifdef CONFIG_PARAVIRT
23587+ cmpl $0, pv_info+PARAVIRT_enabled
23588+ jz 1f
23589+ i = 0
23590+ .rept USER_PGD_PTRS
23591+ mov i*8(%rbx),%rsi
23592+ mov $0x67,%sil
23593+ lea i*8(%rbx),%rdi
23594+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23595+ i = i + 1
23596+ .endr
23597+ jmp 2f
23598+1:
23599+#endif
23600+
23601+ i = 0
23602+ .rept USER_PGD_PTRS
23603+ movb $0x67,i*8(%rbx)
23604+ i = i + 1
23605+ .endr
23606+2:
23607+
23608+#ifdef CONFIG_PARAVIRT
23609+ PV_RESTORE_REGS(CLBR_RDI)
23610+#endif
23611+
23612+ popq %rbx
23613+ popq %rdi
23614+ pax_force_retaddr
23615+ retq
23616+3: ud2
23617+ENDPROC(pax_exit_kernel_user)
23618+#endif
23619+
23620+ .macro pax_enter_kernel_nmi
23621+ pax_set_fptr_mask
23622+
23623+#ifdef CONFIG_PAX_KERNEXEC
23624+ GET_CR0_INTO_RDI
23625+ bts $16,%rdi
23626+ jc 110f
23627+ SET_RDI_INTO_CR0
23628+ or $2,%ebx
23629+110:
23630+#endif
23631+
23632+#ifdef CONFIG_PAX_MEMORY_UDEREF
23633+ 661: jmp 111f
23634+ .pushsection .altinstr_replacement, "a"
23635+ 662: ASM_NOP2
23636+ .popsection
23637+ .pushsection .altinstructions, "a"
23638+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23639+ .popsection
23640+ GET_CR3_INTO_RDI
23641+ cmp $0,%dil
23642+ jz 111f
23643+ sub $4097,%rdi
23644+ or $4,%ebx
23645+ bts $63,%rdi
23646+ SET_RDI_INTO_CR3
23647+ mov $__UDEREF_KERNEL_DS,%edi
23648+ mov %edi,%ss
23649+111:
23650+#endif
23651+ .endm
23652+
23653+ .macro pax_exit_kernel_nmi
23654+#ifdef CONFIG_PAX_KERNEXEC
23655+ btr $1,%ebx
23656+ jnc 110f
23657+ GET_CR0_INTO_RDI
23658+ btr $16,%rdi
23659+ SET_RDI_INTO_CR0
23660+110:
23661+#endif
23662+
23663+#ifdef CONFIG_PAX_MEMORY_UDEREF
23664+ btr $2,%ebx
23665+ jnc 111f
23666+ GET_CR3_INTO_RDI
23667+ add $4097,%rdi
23668+ bts $63,%rdi
23669+ SET_RDI_INTO_CR3
23670+ mov $__KERNEL_DS,%edi
23671+ mov %edi,%ss
23672+111:
23673+#endif
23674+ .endm
23675+
23676+ .macro pax_erase_kstack
23677+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23678+ call pax_erase_kstack
23679+#endif
23680+ .endm
23681+
23682+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23683+ENTRY(pax_erase_kstack)
23684+ pushq %rdi
23685+ pushq %rcx
23686+ pushq %rax
23687+ pushq %r11
23688+
23689+ GET_THREAD_INFO(%r11)
23690+ mov TI_lowest_stack(%r11), %rdi
23691+ mov $-0xBEEF, %rax
23692+ std
23693+
23694+1: mov %edi, %ecx
23695+ and $THREAD_SIZE_asm - 1, %ecx
23696+ shr $3, %ecx
23697+ repne scasq
23698+ jecxz 2f
23699+
23700+ cmp $2*8, %ecx
23701+ jc 2f
23702+
23703+ mov $2*8, %ecx
23704+ repe scasq
23705+ jecxz 2f
23706+ jne 1b
23707+
23708+2: cld
23709+ mov %esp, %ecx
23710+ sub %edi, %ecx
23711+
23712+ cmp $THREAD_SIZE_asm, %rcx
23713+ jb 3f
23714+ ud2
23715+3:
23716+
23717+ shr $3, %ecx
23718+ rep stosq
23719+
23720+ mov TI_task_thread_sp0(%r11), %rdi
23721+ sub $256, %rdi
23722+ mov %rdi, TI_lowest_stack(%r11)
23723+
23724+ popq %r11
23725+ popq %rax
23726+ popq %rcx
23727+ popq %rdi
23728+ pax_force_retaddr
23729+ ret
23730+ENDPROC(pax_erase_kstack)
23731+#endif
23732
23733 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23734 #ifdef CONFIG_TRACE_IRQFLAGS
23735@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23736 .endm
23737
23738 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23739- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23740+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23741 jnc 1f
23742 TRACE_IRQS_ON_DEBUG
23743 1:
23744@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23745 movq \tmp,R11+\offset(%rsp)
23746 .endm
23747
23748- .macro FAKE_STACK_FRAME child_rip
23749- /* push in order ss, rsp, eflags, cs, rip */
23750- xorl %eax, %eax
23751- pushq_cfi $__KERNEL_DS /* ss */
23752- /*CFI_REL_OFFSET ss,0*/
23753- pushq_cfi %rax /* rsp */
23754- CFI_REL_OFFSET rsp,0
23755- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23756- /*CFI_REL_OFFSET rflags,0*/
23757- pushq_cfi $__KERNEL_CS /* cs */
23758- /*CFI_REL_OFFSET cs,0*/
23759- pushq_cfi \child_rip /* rip */
23760- CFI_REL_OFFSET rip,0
23761- pushq_cfi %rax /* orig rax */
23762- .endm
23763-
23764- .macro UNFAKE_STACK_FRAME
23765- addq $8*6, %rsp
23766- CFI_ADJUST_CFA_OFFSET -(6*8)
23767- .endm
23768-
23769 /*
23770 * initial frame state for interrupts (and exceptions without error code)
23771 */
23772@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23773 /* save partial stack frame */
23774 .macro SAVE_ARGS_IRQ
23775 cld
23776- /* start from rbp in pt_regs and jump over */
23777- movq_cfi rdi, (RDI-RBP)
23778- movq_cfi rsi, (RSI-RBP)
23779- movq_cfi rdx, (RDX-RBP)
23780- movq_cfi rcx, (RCX-RBP)
23781- movq_cfi rax, (RAX-RBP)
23782- movq_cfi r8, (R8-RBP)
23783- movq_cfi r9, (R9-RBP)
23784- movq_cfi r10, (R10-RBP)
23785- movq_cfi r11, (R11-RBP)
23786+ /* start from r15 in pt_regs and jump over */
23787+ movq_cfi rdi, RDI
23788+ movq_cfi rsi, RSI
23789+ movq_cfi rdx, RDX
23790+ movq_cfi rcx, RCX
23791+ movq_cfi rax, RAX
23792+ movq_cfi r8, R8
23793+ movq_cfi r9, R9
23794+ movq_cfi r10, R10
23795+ movq_cfi r11, R11
23796+ movq_cfi r12, R12
23797
23798 /* Save rbp so that we can unwind from get_irq_regs() */
23799- movq_cfi rbp, 0
23800+ movq_cfi rbp, RBP
23801
23802 /* Save previous stack value */
23803 movq %rsp, %rsi
23804
23805- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23806- testl $3, CS-RBP(%rsi)
23807+ movq %rsp,%rdi /* arg1 for handler */
23808+ testb $3, CS(%rsi)
23809 je 1f
23810 SWAPGS
23811 /*
23812@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23813 0x06 /* DW_OP_deref */, \
23814 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23815 0x22 /* DW_OP_plus */
23816+
23817+#ifdef CONFIG_PAX_MEMORY_UDEREF
23818+ testb $3, CS(%rdi)
23819+ jnz 1f
23820+ pax_enter_kernel
23821+ jmp 2f
23822+1: pax_enter_kernel_user
23823+2:
23824+#else
23825+ pax_enter_kernel
23826+#endif
23827+
23828 /* We entered an interrupt context - irqs are off: */
23829 TRACE_IRQS_OFF
23830 .endm
23831@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23832 js 1f /* negative -> in kernel */
23833 SWAPGS
23834 xorl %ebx,%ebx
23835-1: ret
23836+1:
23837+#ifdef CONFIG_PAX_MEMORY_UDEREF
23838+ testb $3, CS+8(%rsp)
23839+ jnz 1f
23840+ pax_enter_kernel
23841+ jmp 2f
23842+1: pax_enter_kernel_user
23843+2:
23844+#else
23845+ pax_enter_kernel
23846+#endif
23847+ pax_force_retaddr
23848+ ret
23849 CFI_ENDPROC
23850-END(save_paranoid)
23851+ENDPROC(save_paranoid)
23852+
23853+ENTRY(save_paranoid_nmi)
23854+ XCPT_FRAME 1 RDI+8
23855+ cld
23856+ movq_cfi rdi, RDI+8
23857+ movq_cfi rsi, RSI+8
23858+ movq_cfi rdx, RDX+8
23859+ movq_cfi rcx, RCX+8
23860+ movq_cfi rax, RAX+8
23861+ movq_cfi r8, R8+8
23862+ movq_cfi r9, R9+8
23863+ movq_cfi r10, R10+8
23864+ movq_cfi r11, R11+8
23865+ movq_cfi rbx, RBX+8
23866+ movq_cfi rbp, RBP+8
23867+ movq_cfi r12, R12+8
23868+ movq_cfi r13, R13+8
23869+ movq_cfi r14, R14+8
23870+ movq_cfi r15, R15+8
23871+ movl $1,%ebx
23872+ movl $MSR_GS_BASE,%ecx
23873+ rdmsr
23874+ testl %edx,%edx
23875+ js 1f /* negative -> in kernel */
23876+ SWAPGS
23877+ xorl %ebx,%ebx
23878+1: pax_enter_kernel_nmi
23879+ pax_force_retaddr
23880+ ret
23881+ CFI_ENDPROC
23882+ENDPROC(save_paranoid_nmi)
23883 .popsection
23884
23885 /*
23886@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23887
23888 RESTORE_REST
23889
23890- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23891+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23892 jz 1f
23893
23894 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23895@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23896 jmp ret_from_sys_call # go to the SYSRET fastpath
23897
23898 1:
23899- subq $REST_SKIP, %rsp # leave space for volatiles
23900- CFI_ADJUST_CFA_OFFSET REST_SKIP
23901 movq %rbp, %rdi
23902 call *%rbx
23903 movl $0, RAX(%rsp)
23904 RESTORE_REST
23905 jmp int_ret_from_sys_call
23906 CFI_ENDPROC
23907-END(ret_from_fork)
23908+ENDPROC(ret_from_fork)
23909
23910 /*
23911 * System call entry. Up to 6 arguments in registers are supported.
23912@@ -593,7 +1059,7 @@ END(ret_from_fork)
23913 ENTRY(system_call)
23914 CFI_STARTPROC simple
23915 CFI_SIGNAL_FRAME
23916- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23917+ CFI_DEF_CFA rsp,0
23918 CFI_REGISTER rip,rcx
23919 /*CFI_REGISTER rflags,r11*/
23920 SWAPGS_UNSAFE_STACK
23921@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23922
23923 movq %rsp,PER_CPU_VAR(old_rsp)
23924 movq PER_CPU_VAR(kernel_stack),%rsp
23925+ SAVE_ARGS 8*6,0
23926+ pax_enter_kernel_user
23927+
23928+#ifdef CONFIG_PAX_RANDKSTACK
23929+ pax_erase_kstack
23930+#endif
23931+
23932 /*
23933 * No need to follow this irqs off/on section - it's straight
23934 * and short:
23935 */
23936 ENABLE_INTERRUPTS(CLBR_NONE)
23937- SAVE_ARGS 8,0
23938 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23939 movq %rcx,RIP-ARGOFFSET(%rsp)
23940 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23941- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23942+ GET_THREAD_INFO(%rcx)
23943+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23944 jnz tracesys
23945 system_call_fastpath:
23946 #if __SYSCALL_MASK == ~0
23947@@ -639,10 +1112,13 @@ sysret_check:
23948 LOCKDEP_SYS_EXIT
23949 DISABLE_INTERRUPTS(CLBR_NONE)
23950 TRACE_IRQS_OFF
23951- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23952+ GET_THREAD_INFO(%rcx)
23953+ movl TI_flags(%rcx),%edx
23954 andl %edi,%edx
23955 jnz sysret_careful
23956 CFI_REMEMBER_STATE
23957+ pax_exit_kernel_user
23958+ pax_erase_kstack
23959 /*
23960 * sysretq will re-enable interrupts:
23961 */
23962@@ -701,6 +1177,9 @@ auditsys:
23963 movq %rax,%rsi /* 2nd arg: syscall number */
23964 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23965 call __audit_syscall_entry
23966+
23967+ pax_erase_kstack
23968+
23969 LOAD_ARGS 0 /* reload call-clobbered registers */
23970 jmp system_call_fastpath
23971
23972@@ -722,7 +1201,7 @@ sysret_audit:
23973 /* Do syscall tracing */
23974 tracesys:
23975 #ifdef CONFIG_AUDITSYSCALL
23976- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23977+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23978 jz auditsys
23979 #endif
23980 SAVE_REST
23981@@ -730,12 +1209,15 @@ tracesys:
23982 FIXUP_TOP_OF_STACK %rdi
23983 movq %rsp,%rdi
23984 call syscall_trace_enter
23985+
23986+ pax_erase_kstack
23987+
23988 /*
23989 * Reload arg registers from stack in case ptrace changed them.
23990 * We don't reload %rax because syscall_trace_enter() returned
23991 * the value it wants us to use in the table lookup.
23992 */
23993- LOAD_ARGS ARGOFFSET, 1
23994+ LOAD_ARGS 1
23995 RESTORE_REST
23996 #if __SYSCALL_MASK == ~0
23997 cmpq $__NR_syscall_max,%rax
23998@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23999 andl %edi,%edx
24000 jnz int_careful
24001 andl $~TS_COMPAT,TI_status(%rcx)
24002- jmp retint_swapgs
24003+ pax_exit_kernel_user
24004+ pax_erase_kstack
24005+ jmp retint_swapgs_pax
24006
24007 /* Either reschedule or signal or syscall exit tracking needed. */
24008 /* First do a reschedule test. */
24009@@ -811,7 +1295,7 @@ int_restore_rest:
24010 TRACE_IRQS_OFF
24011 jmp int_with_check
24012 CFI_ENDPROC
24013-END(system_call)
24014+ENDPROC(system_call)
24015
24016 .macro FORK_LIKE func
24017 ENTRY(stub_\func)
24018@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
24019 DEFAULT_FRAME 0 8 /* offset 8: return address */
24020 call sys_\func
24021 RESTORE_TOP_OF_STACK %r11, 8
24022- ret $REST_SKIP /* pop extended registers */
24023+ pax_force_retaddr
24024+ ret
24025 CFI_ENDPROC
24026-END(stub_\func)
24027+ENDPROC(stub_\func)
24028 .endm
24029
24030 .macro FIXED_FRAME label,func
24031@@ -836,9 +1321,10 @@ ENTRY(\label)
24032 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
24033 call \func
24034 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
24035+ pax_force_retaddr
24036 ret
24037 CFI_ENDPROC
24038-END(\label)
24039+ENDPROC(\label)
24040 .endm
24041
24042 FORK_LIKE clone
24043@@ -846,19 +1332,6 @@ END(\label)
24044 FORK_LIKE vfork
24045 FIXED_FRAME stub_iopl, sys_iopl
24046
24047-ENTRY(ptregscall_common)
24048- DEFAULT_FRAME 1 8 /* offset 8: return address */
24049- RESTORE_TOP_OF_STACK %r11, 8
24050- movq_cfi_restore R15+8, r15
24051- movq_cfi_restore R14+8, r14
24052- movq_cfi_restore R13+8, r13
24053- movq_cfi_restore R12+8, r12
24054- movq_cfi_restore RBP+8, rbp
24055- movq_cfi_restore RBX+8, rbx
24056- ret $REST_SKIP /* pop extended registers */
24057- CFI_ENDPROC
24058-END(ptregscall_common)
24059-
24060 ENTRY(stub_execve)
24061 CFI_STARTPROC
24062 addq $8, %rsp
24063@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
24064 RESTORE_REST
24065 jmp int_ret_from_sys_call
24066 CFI_ENDPROC
24067-END(stub_execve)
24068+ENDPROC(stub_execve)
24069
24070 /*
24071 * sigreturn is special because it needs to restore all registers on return.
24072@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
24073 RESTORE_REST
24074 jmp int_ret_from_sys_call
24075 CFI_ENDPROC
24076-END(stub_rt_sigreturn)
24077+ENDPROC(stub_rt_sigreturn)
24078
24079 #ifdef CONFIG_X86_X32_ABI
24080 ENTRY(stub_x32_rt_sigreturn)
24081@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
24082 RESTORE_REST
24083 jmp int_ret_from_sys_call
24084 CFI_ENDPROC
24085-END(stub_x32_rt_sigreturn)
24086+ENDPROC(stub_x32_rt_sigreturn)
24087
24088 ENTRY(stub_x32_execve)
24089 CFI_STARTPROC
24090@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
24091 RESTORE_REST
24092 jmp int_ret_from_sys_call
24093 CFI_ENDPROC
24094-END(stub_x32_execve)
24095+ENDPROC(stub_x32_execve)
24096
24097 #endif
24098
24099@@ -952,7 +1425,7 @@ vector=vector+1
24100 2: jmp common_interrupt
24101 .endr
24102 CFI_ENDPROC
24103-END(irq_entries_start)
24104+ENDPROC(irq_entries_start)
24105
24106 .previous
24107 END(interrupt)
24108@@ -969,8 +1442,8 @@ END(interrupt)
24109 /* 0(%rsp): ~(interrupt number) */
24110 .macro interrupt func
24111 /* reserve pt_regs for scratch regs and rbp */
24112- subq $ORIG_RAX-RBP, %rsp
24113- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
24114+ subq $ORIG_RAX, %rsp
24115+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
24116 SAVE_ARGS_IRQ
24117 call \func
24118 .endm
24119@@ -997,14 +1470,14 @@ ret_from_intr:
24120
24121 /* Restore saved previous stack */
24122 popq %rsi
24123- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24124- leaq ARGOFFSET-RBP(%rsi), %rsp
24125+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24126+ movq %rsi, %rsp
24127 CFI_DEF_CFA_REGISTER rsp
24128- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24129+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24130
24131 exit_intr:
24132 GET_THREAD_INFO(%rcx)
24133- testl $3,CS-ARGOFFSET(%rsp)
24134+ testb $3,CS-ARGOFFSET(%rsp)
24135 je retint_kernel
24136
24137 /* Interrupt came from user space */
24138@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
24139 * The iretq could re-enable interrupts:
24140 */
24141 DISABLE_INTERRUPTS(CLBR_ANY)
24142+ pax_exit_kernel_user
24143+retint_swapgs_pax:
24144 TRACE_IRQS_IRETQ
24145 SWAPGS
24146 jmp restore_args
24147
24148 retint_restore_args: /* return to kernel space */
24149 DISABLE_INTERRUPTS(CLBR_ANY)
24150+ pax_exit_kernel
24151+ pax_force_retaddr (RIP-ARGOFFSET)
24152 /*
24153 * The iretq could re-enable interrupts:
24154 */
24155@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
24156 #endif
24157
24158 CFI_ENDPROC
24159-END(common_interrupt)
24160+ENDPROC(common_interrupt)
24161 /*
24162 * End of kprobes section
24163 */
24164@@ -1130,7 +1607,7 @@ ENTRY(\sym)
24165 interrupt \do_sym
24166 jmp ret_from_intr
24167 CFI_ENDPROC
24168-END(\sym)
24169+ENDPROC(\sym)
24170 .endm
24171
24172 #ifdef CONFIG_TRACING
24173@@ -1218,7 +1695,7 @@ ENTRY(\sym)
24174 call \do_sym
24175 jmp error_exit /* %ebx: no swapgs flag */
24176 CFI_ENDPROC
24177-END(\sym)
24178+ENDPROC(\sym)
24179 .endm
24180
24181 .macro paranoidzeroentry sym do_sym
24182@@ -1236,10 +1713,10 @@ ENTRY(\sym)
24183 call \do_sym
24184 jmp paranoid_exit /* %ebx: no swapgs flag */
24185 CFI_ENDPROC
24186-END(\sym)
24187+ENDPROC(\sym)
24188 .endm
24189
24190-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24191+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24192 .macro paranoidzeroentry_ist sym do_sym ist
24193 ENTRY(\sym)
24194 INTR_FRAME
24195@@ -1252,12 +1729,18 @@ ENTRY(\sym)
24196 TRACE_IRQS_OFF_DEBUG
24197 movq %rsp,%rdi /* pt_regs pointer */
24198 xorl %esi,%esi /* no error code */
24199+#ifdef CONFIG_SMP
24200+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24201+ lea init_tss(%r13), %r13
24202+#else
24203+ lea init_tss(%rip), %r13
24204+#endif
24205 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
24206 call \do_sym
24207 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
24208 jmp paranoid_exit /* %ebx: no swapgs flag */
24209 CFI_ENDPROC
24210-END(\sym)
24211+ENDPROC(\sym)
24212 .endm
24213
24214 .macro errorentry sym do_sym
24215@@ -1275,7 +1758,7 @@ ENTRY(\sym)
24216 call \do_sym
24217 jmp error_exit /* %ebx: no swapgs flag */
24218 CFI_ENDPROC
24219-END(\sym)
24220+ENDPROC(\sym)
24221 .endm
24222
24223 #ifdef CONFIG_TRACING
24224@@ -1306,7 +1789,7 @@ ENTRY(\sym)
24225 call \do_sym
24226 jmp paranoid_exit /* %ebx: no swapgs flag */
24227 CFI_ENDPROC
24228-END(\sym)
24229+ENDPROC(\sym)
24230 .endm
24231
24232 zeroentry divide_error do_divide_error
24233@@ -1336,9 +1819,10 @@ gs_change:
24234 2: mfence /* workaround */
24235 SWAPGS
24236 popfq_cfi
24237+ pax_force_retaddr
24238 ret
24239 CFI_ENDPROC
24240-END(native_load_gs_index)
24241+ENDPROC(native_load_gs_index)
24242
24243 _ASM_EXTABLE(gs_change,bad_gs)
24244 .section .fixup,"ax"
24245@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
24246 CFI_DEF_CFA_REGISTER rsp
24247 CFI_ADJUST_CFA_OFFSET -8
24248 decl PER_CPU_VAR(irq_count)
24249+ pax_force_retaddr
24250 ret
24251 CFI_ENDPROC
24252-END(do_softirq_own_stack)
24253+ENDPROC(do_softirq_own_stack)
24254
24255 #ifdef CONFIG_XEN
24256 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
24257@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24258 decl PER_CPU_VAR(irq_count)
24259 jmp error_exit
24260 CFI_ENDPROC
24261-END(xen_do_hypervisor_callback)
24262+ENDPROC(xen_do_hypervisor_callback)
24263
24264 /*
24265 * Hypervisor uses this for application faults while it executes.
24266@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
24267 SAVE_ALL
24268 jmp error_exit
24269 CFI_ENDPROC
24270-END(xen_failsafe_callback)
24271+ENDPROC(xen_failsafe_callback)
24272
24273 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24274 xen_hvm_callback_vector xen_evtchn_do_upcall
24275@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
24276 DEFAULT_FRAME
24277 DISABLE_INTERRUPTS(CLBR_NONE)
24278 TRACE_IRQS_OFF_DEBUG
24279- testl %ebx,%ebx /* swapgs needed? */
24280+ testl $1,%ebx /* swapgs needed? */
24281 jnz paranoid_restore
24282- testl $3,CS(%rsp)
24283+ testb $3,CS(%rsp)
24284 jnz paranoid_userspace
24285+#ifdef CONFIG_PAX_MEMORY_UDEREF
24286+ pax_exit_kernel
24287+ TRACE_IRQS_IRETQ 0
24288+ SWAPGS_UNSAFE_STACK
24289+ RESTORE_ALL 8
24290+ pax_force_retaddr_bts
24291+ jmp irq_return
24292+#endif
24293 paranoid_swapgs:
24294+#ifdef CONFIG_PAX_MEMORY_UDEREF
24295+ pax_exit_kernel_user
24296+#else
24297+ pax_exit_kernel
24298+#endif
24299 TRACE_IRQS_IRETQ 0
24300 SWAPGS_UNSAFE_STACK
24301 RESTORE_ALL 8
24302 jmp irq_return
24303 paranoid_restore:
24304+ pax_exit_kernel
24305 TRACE_IRQS_IRETQ_DEBUG 0
24306 RESTORE_ALL 8
24307+ pax_force_retaddr_bts
24308 jmp irq_return
24309 paranoid_userspace:
24310 GET_THREAD_INFO(%rcx)
24311@@ -1557,7 +2057,7 @@ paranoid_schedule:
24312 TRACE_IRQS_OFF
24313 jmp paranoid_userspace
24314 CFI_ENDPROC
24315-END(paranoid_exit)
24316+ENDPROC(paranoid_exit)
24317
24318 /*
24319 * Exception entry point. This expects an error code/orig_rax on the stack.
24320@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
24321 movq_cfi r14, R14+8
24322 movq_cfi r15, R15+8
24323 xorl %ebx,%ebx
24324- testl $3,CS+8(%rsp)
24325+ testb $3,CS+8(%rsp)
24326 je error_kernelspace
24327 error_swapgs:
24328 SWAPGS
24329 error_sti:
24330+#ifdef CONFIG_PAX_MEMORY_UDEREF
24331+ testb $3, CS+8(%rsp)
24332+ jnz 1f
24333+ pax_enter_kernel
24334+ jmp 2f
24335+1: pax_enter_kernel_user
24336+2:
24337+#else
24338+ pax_enter_kernel
24339+#endif
24340 TRACE_IRQS_OFF
24341+ pax_force_retaddr
24342 ret
24343
24344 /*
24345@@ -1616,7 +2127,7 @@ bstep_iret:
24346 movq %rcx,RIP+8(%rsp)
24347 jmp error_swapgs
24348 CFI_ENDPROC
24349-END(error_entry)
24350+ENDPROC(error_entry)
24351
24352
24353 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24354@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
24355 DISABLE_INTERRUPTS(CLBR_NONE)
24356 TRACE_IRQS_OFF
24357 GET_THREAD_INFO(%rcx)
24358- testl %eax,%eax
24359+ testl $1,%eax
24360 jne retint_kernel
24361 LOCKDEP_SYS_EXIT_IRQ
24362 movl TI_flags(%rcx),%edx
24363@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
24364 jnz retint_careful
24365 jmp retint_swapgs
24366 CFI_ENDPROC
24367-END(error_exit)
24368+ENDPROC(error_exit)
24369
24370 /*
24371 * Test if a given stack is an NMI stack or not.
24372@@ -1694,9 +2205,11 @@ ENTRY(nmi)
24373 * If %cs was not the kernel segment, then the NMI triggered in user
24374 * space, which means it is definitely not nested.
24375 */
24376+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24377+ je 1f
24378 cmpl $__KERNEL_CS, 16(%rsp)
24379 jne first_nmi
24380-
24381+1:
24382 /*
24383 * Check the special variable on the stack to see if NMIs are
24384 * executing.
24385@@ -1730,8 +2243,7 @@ nested_nmi:
24386
24387 1:
24388 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24389- leaq -1*8(%rsp), %rdx
24390- movq %rdx, %rsp
24391+ subq $8, %rsp
24392 CFI_ADJUST_CFA_OFFSET 1*8
24393 leaq -10*8(%rsp), %rdx
24394 pushq_cfi $__KERNEL_DS
24395@@ -1749,6 +2261,7 @@ nested_nmi_out:
24396 CFI_RESTORE rdx
24397
24398 /* No need to check faults here */
24399+# pax_force_retaddr_bts
24400 INTERRUPT_RETURN
24401
24402 CFI_RESTORE_STATE
24403@@ -1845,13 +2358,13 @@ end_repeat_nmi:
24404 subq $ORIG_RAX-R15, %rsp
24405 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24406 /*
24407- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24408+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24409 * as we should not be calling schedule in NMI context.
24410 * Even with normal interrupts enabled. An NMI should not be
24411 * setting NEED_RESCHED or anything that normal interrupts and
24412 * exceptions might do.
24413 */
24414- call save_paranoid
24415+ call save_paranoid_nmi
24416 DEFAULT_FRAME 0
24417
24418 /*
24419@@ -1861,9 +2374,9 @@ end_repeat_nmi:
24420 * NMI itself takes a page fault, the page fault that was preempted
24421 * will read the information from the NMI page fault and not the
24422 * origin fault. Save it off and restore it if it changes.
24423- * Use the r12 callee-saved register.
24424+ * Use the r13 callee-saved register.
24425 */
24426- movq %cr2, %r12
24427+ movq %cr2, %r13
24428
24429 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24430 movq %rsp,%rdi
24431@@ -1872,31 +2385,36 @@ end_repeat_nmi:
24432
24433 /* Did the NMI take a page fault? Restore cr2 if it did */
24434 movq %cr2, %rcx
24435- cmpq %rcx, %r12
24436+ cmpq %rcx, %r13
24437 je 1f
24438- movq %r12, %cr2
24439+ movq %r13, %cr2
24440 1:
24441
24442- testl %ebx,%ebx /* swapgs needed? */
24443+ testl $1,%ebx /* swapgs needed? */
24444 jnz nmi_restore
24445 nmi_swapgs:
24446 SWAPGS_UNSAFE_STACK
24447 nmi_restore:
24448+ pax_exit_kernel_nmi
24449 /* Pop the extra iret frame at once */
24450 RESTORE_ALL 6*8
24451+ testb $3, 8(%rsp)
24452+ jnz 1f
24453+ pax_force_retaddr_bts
24454+1:
24455
24456 /* Clear the NMI executing stack variable */
24457 movq $0, 5*8(%rsp)
24458 jmp irq_return
24459 CFI_ENDPROC
24460-END(nmi)
24461+ENDPROC(nmi)
24462
24463 ENTRY(ignore_sysret)
24464 CFI_STARTPROC
24465 mov $-ENOSYS,%eax
24466 sysret
24467 CFI_ENDPROC
24468-END(ignore_sysret)
24469+ENDPROC(ignore_sysret)
24470
24471 /*
24472 * End of kprobes section
24473diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24474index 1ffc32d..e52c745 100644
24475--- a/arch/x86/kernel/ftrace.c
24476+++ b/arch/x86/kernel/ftrace.c
24477@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24478 {
24479 unsigned char replaced[MCOUNT_INSN_SIZE];
24480
24481+ ip = ktla_ktva(ip);
24482+
24483 /*
24484 * Note: Due to modules and __init, code can
24485 * disappear and change, we need to protect against faulting
24486@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24487 unsigned char old[MCOUNT_INSN_SIZE];
24488 int ret;
24489
24490- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24491+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24492
24493 ftrace_update_func = ip;
24494 /* Make sure the breakpoints see the ftrace_update_func update */
24495@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24496 * kernel identity mapping to modify code.
24497 */
24498 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24499- ip = (unsigned long)__va(__pa_symbol(ip));
24500+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24501
24502 return probe_kernel_write((void *)ip, val, size);
24503 }
24504@@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
24505 unsigned char replaced[MCOUNT_INSN_SIZE];
24506 unsigned char brk = BREAKPOINT_INSTRUCTION;
24507
24508- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24509+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24510 return -EFAULT;
24511
24512 /* Make sure it is what we expect it to be */
24513@@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
24514 return ret;
24515
24516 fail_update:
24517- probe_kernel_write((void *)ip, &old_code[0], 1);
24518+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
24519 goto out;
24520 }
24521
24522diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24523index 85126cc..1bbce17 100644
24524--- a/arch/x86/kernel/head64.c
24525+++ b/arch/x86/kernel/head64.c
24526@@ -67,12 +67,12 @@ again:
24527 pgd = *pgd_p;
24528
24529 /*
24530- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24531- * critical -- __PAGE_OFFSET would point us back into the dynamic
24532+ * The use of __early_va rather than __va here is critical:
24533+ * __va would point us back into the dynamic
24534 * range and we might end up looping forever...
24535 */
24536 if (pgd)
24537- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24538+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24539 else {
24540 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24541 reset_early_page_tables();
24542@@ -82,13 +82,13 @@ again:
24543 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24544 for (i = 0; i < PTRS_PER_PUD; i++)
24545 pud_p[i] = 0;
24546- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24547+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24548 }
24549 pud_p += pud_index(address);
24550 pud = *pud_p;
24551
24552 if (pud)
24553- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24554+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24555 else {
24556 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24557 reset_early_page_tables();
24558@@ -98,7 +98,7 @@ again:
24559 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24560 for (i = 0; i < PTRS_PER_PMD; i++)
24561 pmd_p[i] = 0;
24562- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24563+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24564 }
24565 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24566 pmd_p[pmd_index(address)] = pmd;
24567@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24568 if (console_loglevel == 10)
24569 early_printk("Kernel alive\n");
24570
24571- clear_page(init_level4_pgt);
24572 /* set init_level4_pgt kernel high mapping*/
24573 init_level4_pgt[511] = early_level4_pgt[511];
24574
24575diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24576index f36bd42..56ee1534 100644
24577--- a/arch/x86/kernel/head_32.S
24578+++ b/arch/x86/kernel/head_32.S
24579@@ -26,6 +26,12 @@
24580 /* Physical address */
24581 #define pa(X) ((X) - __PAGE_OFFSET)
24582
24583+#ifdef CONFIG_PAX_KERNEXEC
24584+#define ta(X) (X)
24585+#else
24586+#define ta(X) ((X) - __PAGE_OFFSET)
24587+#endif
24588+
24589 /*
24590 * References to members of the new_cpu_data structure.
24591 */
24592@@ -55,11 +61,7 @@
24593 * and small than max_low_pfn, otherwise will waste some page table entries
24594 */
24595
24596-#if PTRS_PER_PMD > 1
24597-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24598-#else
24599-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24600-#endif
24601+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24602
24603 /* Number of possible pages in the lowmem region */
24604 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24605@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24606 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24607
24608 /*
24609+ * Real beginning of normal "text" segment
24610+ */
24611+ENTRY(stext)
24612+ENTRY(_stext)
24613+
24614+/*
24615 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24616 * %esi points to the real-mode code as a 32-bit pointer.
24617 * CS and DS must be 4 GB flat segments, but we don't depend on
24618@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24619 * can.
24620 */
24621 __HEAD
24622+
24623+#ifdef CONFIG_PAX_KERNEXEC
24624+ jmp startup_32
24625+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24626+.fill PAGE_SIZE-5,1,0xcc
24627+#endif
24628+
24629 ENTRY(startup_32)
24630 movl pa(stack_start),%ecx
24631
24632@@ -106,6 +121,59 @@ ENTRY(startup_32)
24633 2:
24634 leal -__PAGE_OFFSET(%ecx),%esp
24635
24636+#ifdef CONFIG_SMP
24637+ movl $pa(cpu_gdt_table),%edi
24638+ movl $__per_cpu_load,%eax
24639+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24640+ rorl $16,%eax
24641+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24642+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24643+ movl $__per_cpu_end - 1,%eax
24644+ subl $__per_cpu_start,%eax
24645+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24646+#endif
24647+
24648+#ifdef CONFIG_PAX_MEMORY_UDEREF
24649+ movl $NR_CPUS,%ecx
24650+ movl $pa(cpu_gdt_table),%edi
24651+1:
24652+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24653+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24654+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24655+ addl $PAGE_SIZE_asm,%edi
24656+ loop 1b
24657+#endif
24658+
24659+#ifdef CONFIG_PAX_KERNEXEC
24660+ movl $pa(boot_gdt),%edi
24661+ movl $__LOAD_PHYSICAL_ADDR,%eax
24662+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24663+ rorl $16,%eax
24664+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24665+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24666+ rorl $16,%eax
24667+
24668+ ljmp $(__BOOT_CS),$1f
24669+1:
24670+
24671+ movl $NR_CPUS,%ecx
24672+ movl $pa(cpu_gdt_table),%edi
24673+ addl $__PAGE_OFFSET,%eax
24674+1:
24675+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24676+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24677+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24678+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24679+ rorl $16,%eax
24680+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24681+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24682+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24683+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24684+ rorl $16,%eax
24685+ addl $PAGE_SIZE_asm,%edi
24686+ loop 1b
24687+#endif
24688+
24689 /*
24690 * Clear BSS first so that there are no surprises...
24691 */
24692@@ -201,8 +269,11 @@ ENTRY(startup_32)
24693 movl %eax, pa(max_pfn_mapped)
24694
24695 /* Do early initialization of the fixmap area */
24696- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24697- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24698+#ifdef CONFIG_COMPAT_VDSO
24699+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24700+#else
24701+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24702+#endif
24703 #else /* Not PAE */
24704
24705 page_pde_offset = (__PAGE_OFFSET >> 20);
24706@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24707 movl %eax, pa(max_pfn_mapped)
24708
24709 /* Do early initialization of the fixmap area */
24710- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24711- movl %eax,pa(initial_page_table+0xffc)
24712+#ifdef CONFIG_COMPAT_VDSO
24713+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24714+#else
24715+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24716+#endif
24717 #endif
24718
24719 #ifdef CONFIG_PARAVIRT
24720@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24721 cmpl $num_subarch_entries, %eax
24722 jae bad_subarch
24723
24724- movl pa(subarch_entries)(,%eax,4), %eax
24725- subl $__PAGE_OFFSET, %eax
24726- jmp *%eax
24727+ jmp *pa(subarch_entries)(,%eax,4)
24728
24729 bad_subarch:
24730 WEAK(lguest_entry)
24731@@ -261,10 +333,10 @@ WEAK(xen_entry)
24732 __INITDATA
24733
24734 subarch_entries:
24735- .long default_entry /* normal x86/PC */
24736- .long lguest_entry /* lguest hypervisor */
24737- .long xen_entry /* Xen hypervisor */
24738- .long default_entry /* Moorestown MID */
24739+ .long ta(default_entry) /* normal x86/PC */
24740+ .long ta(lguest_entry) /* lguest hypervisor */
24741+ .long ta(xen_entry) /* Xen hypervisor */
24742+ .long ta(default_entry) /* Moorestown MID */
24743 num_subarch_entries = (. - subarch_entries) / 4
24744 .previous
24745 #else
24746@@ -354,6 +426,7 @@ default_entry:
24747 movl pa(mmu_cr4_features),%eax
24748 movl %eax,%cr4
24749
24750+#ifdef CONFIG_X86_PAE
24751 testb $X86_CR4_PAE, %al # check if PAE is enabled
24752 jz enable_paging
24753
24754@@ -382,6 +455,9 @@ default_entry:
24755 /* Make changes effective */
24756 wrmsr
24757
24758+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24759+#endif
24760+
24761 enable_paging:
24762
24763 /*
24764@@ -449,14 +525,20 @@ is486:
24765 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24766 movl %eax,%ss # after changing gdt.
24767
24768- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24769+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24770 movl %eax,%ds
24771 movl %eax,%es
24772
24773 movl $(__KERNEL_PERCPU), %eax
24774 movl %eax,%fs # set this cpu's percpu
24775
24776+#ifdef CONFIG_CC_STACKPROTECTOR
24777 movl $(__KERNEL_STACK_CANARY),%eax
24778+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24779+ movl $(__USER_DS),%eax
24780+#else
24781+ xorl %eax,%eax
24782+#endif
24783 movl %eax,%gs
24784
24785 xorl %eax,%eax # Clear LDT
24786@@ -512,8 +594,11 @@ setup_once:
24787 * relocation. Manually set base address in stack canary
24788 * segment descriptor.
24789 */
24790- movl $gdt_page,%eax
24791+ movl $cpu_gdt_table,%eax
24792 movl $stack_canary,%ecx
24793+#ifdef CONFIG_SMP
24794+ addl $__per_cpu_load,%ecx
24795+#endif
24796 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24797 shrl $16, %ecx
24798 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24799@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24800 cmpl $2,(%esp) # X86_TRAP_NMI
24801 je is_nmi # Ignore NMI
24802
24803- cmpl $2,%ss:early_recursion_flag
24804+ cmpl $1,%ss:early_recursion_flag
24805 je hlt_loop
24806 incl %ss:early_recursion_flag
24807
24808@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24809 pushl (20+6*4)(%esp) /* trapno */
24810 pushl $fault_msg
24811 call printk
24812-#endif
24813 call dump_stack
24814+#endif
24815 hlt_loop:
24816 hlt
24817 jmp hlt_loop
24818@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24819 /* This is the default interrupt "handler" :-) */
24820 ALIGN
24821 ignore_int:
24822- cld
24823 #ifdef CONFIG_PRINTK
24824+ cmpl $2,%ss:early_recursion_flag
24825+ je hlt_loop
24826+ incl %ss:early_recursion_flag
24827+ cld
24828 pushl %eax
24829 pushl %ecx
24830 pushl %edx
24831@@ -617,9 +705,6 @@ ignore_int:
24832 movl $(__KERNEL_DS),%eax
24833 movl %eax,%ds
24834 movl %eax,%es
24835- cmpl $2,early_recursion_flag
24836- je hlt_loop
24837- incl early_recursion_flag
24838 pushl 16(%esp)
24839 pushl 24(%esp)
24840 pushl 32(%esp)
24841@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24842 /*
24843 * BSS section
24844 */
24845-__PAGE_ALIGNED_BSS
24846- .align PAGE_SIZE
24847 #ifdef CONFIG_X86_PAE
24848+.section .initial_pg_pmd,"a",@progbits
24849 initial_pg_pmd:
24850 .fill 1024*KPMDS,4,0
24851 #else
24852+.section .initial_page_table,"a",@progbits
24853 ENTRY(initial_page_table)
24854 .fill 1024,4,0
24855 #endif
24856+.section .initial_pg_fixmap,"a",@progbits
24857 initial_pg_fixmap:
24858 .fill 1024,4,0
24859+.section .empty_zero_page,"a",@progbits
24860 ENTRY(empty_zero_page)
24861 .fill 4096,1,0
24862+.section .swapper_pg_dir,"a",@progbits
24863 ENTRY(swapper_pg_dir)
24864+#ifdef CONFIG_X86_PAE
24865+ .fill 4,8,0
24866+#else
24867 .fill 1024,4,0
24868+#endif
24869
24870 /*
24871 * This starts the data section.
24872 */
24873 #ifdef CONFIG_X86_PAE
24874-__PAGE_ALIGNED_DATA
24875- /* Page-aligned for the benefit of paravirt? */
24876- .align PAGE_SIZE
24877+.section .initial_page_table,"a",@progbits
24878 ENTRY(initial_page_table)
24879 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24880 # if KPMDS == 3
24881@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24882 # error "Kernel PMDs should be 1, 2 or 3"
24883 # endif
24884 .align PAGE_SIZE /* needs to be page-sized too */
24885+
24886+#ifdef CONFIG_PAX_PER_CPU_PGD
24887+ENTRY(cpu_pgd)
24888+ .rept 2*NR_CPUS
24889+ .fill 4,8,0
24890+ .endr
24891+#endif
24892+
24893 #endif
24894
24895 .data
24896 .balign 4
24897 ENTRY(stack_start)
24898- .long init_thread_union+THREAD_SIZE
24899+ .long init_thread_union+THREAD_SIZE-8
24900
24901 __INITRODATA
24902 int_msg:
24903@@ -727,7 +825,7 @@ fault_msg:
24904 * segment size, and 32-bit linear address value:
24905 */
24906
24907- .data
24908+.section .rodata,"a",@progbits
24909 .globl boot_gdt_descr
24910 .globl idt_descr
24911
24912@@ -736,7 +834,7 @@ fault_msg:
24913 .word 0 # 32 bit align gdt_desc.address
24914 boot_gdt_descr:
24915 .word __BOOT_DS+7
24916- .long boot_gdt - __PAGE_OFFSET
24917+ .long pa(boot_gdt)
24918
24919 .word 0 # 32-bit align idt_desc.address
24920 idt_descr:
24921@@ -747,7 +845,7 @@ idt_descr:
24922 .word 0 # 32 bit align gdt_desc.address
24923 ENTRY(early_gdt_descr)
24924 .word GDT_ENTRIES*8-1
24925- .long gdt_page /* Overwritten for secondary CPUs */
24926+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24927
24928 /*
24929 * The boot_gdt must mirror the equivalent in setup.S and is
24930@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24931 .align L1_CACHE_BYTES
24932 ENTRY(boot_gdt)
24933 .fill GDT_ENTRY_BOOT_CS,8,0
24934- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24935- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24936+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24937+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24938+
24939+ .align PAGE_SIZE_asm
24940+ENTRY(cpu_gdt_table)
24941+ .rept NR_CPUS
24942+ .quad 0x0000000000000000 /* NULL descriptor */
24943+ .quad 0x0000000000000000 /* 0x0b reserved */
24944+ .quad 0x0000000000000000 /* 0x13 reserved */
24945+ .quad 0x0000000000000000 /* 0x1b reserved */
24946+
24947+#ifdef CONFIG_PAX_KERNEXEC
24948+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24949+#else
24950+ .quad 0x0000000000000000 /* 0x20 unused */
24951+#endif
24952+
24953+ .quad 0x0000000000000000 /* 0x28 unused */
24954+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24955+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24956+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24957+ .quad 0x0000000000000000 /* 0x4b reserved */
24958+ .quad 0x0000000000000000 /* 0x53 reserved */
24959+ .quad 0x0000000000000000 /* 0x5b reserved */
24960+
24961+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24962+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24963+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24964+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24965+
24966+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24967+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24968+
24969+ /*
24970+ * Segments used for calling PnP BIOS have byte granularity.
24971+ * The code segments and data segments have fixed 64k limits,
24972+ * the transfer segment sizes are set at run time.
24973+ */
24974+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24975+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24976+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24977+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24978+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24979+
24980+ /*
24981+ * The APM segments have byte granularity and their bases
24982+ * are set at run time. All have 64k limits.
24983+ */
24984+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24985+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24986+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24987+
24988+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24989+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24990+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24991+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24992+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24993+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24994+
24995+ /* Be sure this is zeroed to avoid false validations in Xen */
24996+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24997+ .endr
24998diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24999index a468c0a..c7dec74 100644
25000--- a/arch/x86/kernel/head_64.S
25001+++ b/arch/x86/kernel/head_64.S
25002@@ -20,6 +20,8 @@
25003 #include <asm/processor-flags.h>
25004 #include <asm/percpu.h>
25005 #include <asm/nops.h>
25006+#include <asm/cpufeature.h>
25007+#include <asm/alternative-asm.h>
25008
25009 #ifdef CONFIG_PARAVIRT
25010 #include <asm/asm-offsets.h>
25011@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
25012 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
25013 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
25014 L3_START_KERNEL = pud_index(__START_KERNEL_map)
25015+L4_VMALLOC_START = pgd_index(VMALLOC_START)
25016+L3_VMALLOC_START = pud_index(VMALLOC_START)
25017+L4_VMALLOC_END = pgd_index(VMALLOC_END)
25018+L3_VMALLOC_END = pud_index(VMALLOC_END)
25019+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
25020+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
25021
25022 .text
25023 __HEAD
25024@@ -89,11 +97,24 @@ startup_64:
25025 * Fixup the physical addresses in the page table
25026 */
25027 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
25028+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
25029+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
25030+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
25031+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
25032+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
25033
25034- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
25035- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
25036+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
25037+#ifndef CONFIG_XEN
25038+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
25039+#endif
25040+
25041+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
25042+
25043+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
25044+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
25045
25046 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
25047+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
25048
25049 /*
25050 * Set up the identity mapping for the switchover. These
25051@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
25052 movq $(init_level4_pgt - __START_KERNEL_map), %rax
25053 1:
25054
25055- /* Enable PAE mode and PGE */
25056- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
25057+ /* Enable PAE mode and PSE/PGE */
25058+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
25059 movq %rcx, %cr4
25060
25061 /* Setup early boot stage 4 level pagetables. */
25062@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
25063 movl $MSR_EFER, %ecx
25064 rdmsr
25065 btsl $_EFER_SCE, %eax /* Enable System Call */
25066- btl $20,%edi /* No Execute supported? */
25067+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
25068 jnc 1f
25069 btsl $_EFER_NX, %eax
25070 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
25071+#ifndef CONFIG_EFI
25072+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
25073+#endif
25074+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
25075+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
25076+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
25077+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
25078+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
25079+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
25080 1: wrmsr /* Make changes effective */
25081
25082 /* Setup cr0 */
25083@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
25084 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
25085 * address given in m16:64.
25086 */
25087+ pax_set_fptr_mask
25088 movq initial_code(%rip),%rax
25089 pushq $0 # fake return address to stop unwinder
25090 pushq $__KERNEL_CS # set correct cs
25091@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
25092 .quad INIT_PER_CPU_VAR(irq_stack_union)
25093
25094 GLOBAL(stack_start)
25095- .quad init_thread_union+THREAD_SIZE-8
25096+ .quad init_thread_union+THREAD_SIZE-16
25097 .word 0
25098 __FINITDATA
25099
25100@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
25101 call dump_stack
25102 #ifdef CONFIG_KALLSYMS
25103 leaq early_idt_ripmsg(%rip),%rdi
25104- movq 40(%rsp),%rsi # %rip again
25105+ movq 88(%rsp),%rsi # %rip again
25106 call __print_symbol
25107 #endif
25108 #endif /* EARLY_PRINTK */
25109@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
25110 early_recursion_flag:
25111 .long 0
25112
25113+ .section .rodata,"a",@progbits
25114 #ifdef CONFIG_EARLY_PRINTK
25115 early_idt_msg:
25116 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
25117@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
25118 NEXT_PAGE(early_dynamic_pgts)
25119 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25120
25121- .data
25122+ .section .rodata,"a",@progbits
25123
25124-#ifndef CONFIG_XEN
25125 NEXT_PAGE(init_level4_pgt)
25126- .fill 512,8,0
25127-#else
25128-NEXT_PAGE(init_level4_pgt)
25129- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25130 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25131 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25132+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
25133+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25134+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
25135+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25136+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25137+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25138 .org init_level4_pgt + L4_START_KERNEL*8, 0
25139 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25140 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25141
25142+#ifdef CONFIG_PAX_PER_CPU_PGD
25143+NEXT_PAGE(cpu_pgd)
25144+ .rept 2*NR_CPUS
25145+ .fill 512,8,0
25146+ .endr
25147+#endif
25148+
25149 NEXT_PAGE(level3_ident_pgt)
25150 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25151+#ifdef CONFIG_XEN
25152 .fill 511, 8, 0
25153+#else
25154+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25155+ .fill 510,8,0
25156+#endif
25157+
25158+NEXT_PAGE(level3_vmalloc_start_pgt)
25159+ .fill 512,8,0
25160+
25161+NEXT_PAGE(level3_vmalloc_end_pgt)
25162+ .fill 512,8,0
25163+
25164+NEXT_PAGE(level3_vmemmap_pgt)
25165+ .fill L3_VMEMMAP_START,8,0
25166+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25167+
25168 NEXT_PAGE(level2_ident_pgt)
25169- /* Since I easily can, map the first 1G.
25170+ /* Since I easily can, map the first 2G.
25171 * Don't set NX because code runs from these pages.
25172 */
25173- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25174-#endif
25175+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25176
25177 NEXT_PAGE(level3_kernel_pgt)
25178 .fill L3_START_KERNEL,8,0
25179@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
25180 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25181 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25182
25183+NEXT_PAGE(level2_vmemmap_pgt)
25184+ .fill 512,8,0
25185+
25186 NEXT_PAGE(level2_kernel_pgt)
25187 /*
25188 * 512 MB kernel mapping. We spend a full page on this pagetable
25189@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
25190 NEXT_PAGE(level2_fixmap_pgt)
25191 .fill 506,8,0
25192 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25193- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25194- .fill 5,8,0
25195+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25196+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25197+ .fill 4,8,0
25198
25199 NEXT_PAGE(level1_fixmap_pgt)
25200 .fill 512,8,0
25201
25202+NEXT_PAGE(level1_vsyscall_pgt)
25203+ .fill 512,8,0
25204+
25205 #undef PMDS
25206
25207- .data
25208+ .align PAGE_SIZE
25209+ENTRY(cpu_gdt_table)
25210+ .rept NR_CPUS
25211+ .quad 0x0000000000000000 /* NULL descriptor */
25212+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25213+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
25214+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
25215+ .quad 0x00cffb000000ffff /* __USER32_CS */
25216+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25217+ .quad 0x00affb000000ffff /* __USER_CS */
25218+
25219+#ifdef CONFIG_PAX_KERNEXEC
25220+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25221+#else
25222+ .quad 0x0 /* unused */
25223+#endif
25224+
25225+ .quad 0,0 /* TSS */
25226+ .quad 0,0 /* LDT */
25227+ .quad 0,0,0 /* three TLS descriptors */
25228+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
25229+ /* asm/segment.h:GDT_ENTRIES must match this */
25230+
25231+#ifdef CONFIG_PAX_MEMORY_UDEREF
25232+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25233+#else
25234+ .quad 0x0 /* unused */
25235+#endif
25236+
25237+ /* zero the remaining page */
25238+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25239+ .endr
25240+
25241 .align 16
25242 .globl early_gdt_descr
25243 early_gdt_descr:
25244 .word GDT_ENTRIES*8-1
25245 early_gdt_descr_base:
25246- .quad INIT_PER_CPU_VAR(gdt_page)
25247+ .quad cpu_gdt_table
25248
25249 ENTRY(phys_base)
25250 /* This must match the first entry in level2_kernel_pgt */
25251 .quad 0x0000000000000000
25252
25253 #include "../../x86/xen/xen-head.S"
25254-
25255- __PAGE_ALIGNED_BSS
25256+
25257+ .section .rodata,"a",@progbits
25258 NEXT_PAGE(empty_zero_page)
25259 .skip PAGE_SIZE
25260diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25261index 05fd74f..c3548b1 100644
25262--- a/arch/x86/kernel/i386_ksyms_32.c
25263+++ b/arch/x86/kernel/i386_ksyms_32.c
25264@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25265 EXPORT_SYMBOL(cmpxchg8b_emu);
25266 #endif
25267
25268+EXPORT_SYMBOL_GPL(cpu_gdt_table);
25269+
25270 /* Networking helper routines. */
25271 EXPORT_SYMBOL(csum_partial_copy_generic);
25272+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25273+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25274
25275 EXPORT_SYMBOL(__get_user_1);
25276 EXPORT_SYMBOL(__get_user_2);
25277@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25278 EXPORT_SYMBOL(___preempt_schedule_context);
25279 #endif
25280 #endif
25281+
25282+#ifdef CONFIG_PAX_KERNEXEC
25283+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25284+#endif
25285+
25286+#ifdef CONFIG_PAX_PER_CPU_PGD
25287+EXPORT_SYMBOL(cpu_pgd);
25288+#endif
25289diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25290index d5dd808..b6432cf 100644
25291--- a/arch/x86/kernel/i387.c
25292+++ b/arch/x86/kernel/i387.c
25293@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25294 static inline bool interrupted_user_mode(void)
25295 {
25296 struct pt_regs *regs = get_irq_regs();
25297- return regs && user_mode_vm(regs);
25298+ return regs && user_mode(regs);
25299 }
25300
25301 /*
25302diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25303index 2e977b5..5f2c273 100644
25304--- a/arch/x86/kernel/i8259.c
25305+++ b/arch/x86/kernel/i8259.c
25306@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25307 static void make_8259A_irq(unsigned int irq)
25308 {
25309 disable_irq_nosync(irq);
25310- io_apic_irqs &= ~(1<<irq);
25311+ io_apic_irqs &= ~(1UL<<irq);
25312 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25313 i8259A_chip.name);
25314 enable_irq(irq);
25315@@ -209,7 +209,7 @@ spurious_8259A_irq:
25316 "spurious 8259A interrupt: IRQ%d.\n", irq);
25317 spurious_irq_mask |= irqmask;
25318 }
25319- atomic_inc(&irq_err_count);
25320+ atomic_inc_unchecked(&irq_err_count);
25321 /*
25322 * Theoretically we do not have to handle this IRQ,
25323 * but in Linux this does not cause problems and is
25324@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
25325 /* (slave's support for AEOI in flat mode is to be investigated) */
25326 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25327
25328+ pax_open_kernel();
25329 if (auto_eoi)
25330 /*
25331 * In AEOI mode we just have to mask the interrupt
25332 * when acking.
25333 */
25334- i8259A_chip.irq_mask_ack = disable_8259A_irq;
25335+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25336 else
25337- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25338+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25339+ pax_close_kernel();
25340
25341 udelay(100); /* wait for 8259A to initialize */
25342
25343diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25344index a979b5b..1d6db75 100644
25345--- a/arch/x86/kernel/io_delay.c
25346+++ b/arch/x86/kernel/io_delay.c
25347@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25348 * Quirk table for systems that misbehave (lock up, etc.) if port
25349 * 0x80 is used:
25350 */
25351-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25352+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25353 {
25354 .callback = dmi_io_delay_0xed_port,
25355 .ident = "Compaq Presario V6000",
25356diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25357index 4ddaf66..49d5c18 100644
25358--- a/arch/x86/kernel/ioport.c
25359+++ b/arch/x86/kernel/ioport.c
25360@@ -6,6 +6,7 @@
25361 #include <linux/sched.h>
25362 #include <linux/kernel.h>
25363 #include <linux/capability.h>
25364+#include <linux/security.h>
25365 #include <linux/errno.h>
25366 #include <linux/types.h>
25367 #include <linux/ioport.h>
25368@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25369 return -EINVAL;
25370 if (turn_on && !capable(CAP_SYS_RAWIO))
25371 return -EPERM;
25372+#ifdef CONFIG_GRKERNSEC_IO
25373+ if (turn_on && grsec_disable_privio) {
25374+ gr_handle_ioperm();
25375+ return -ENODEV;
25376+ }
25377+#endif
25378
25379 /*
25380 * If it's the first ioperm() call in this thread's lifetime, set the
25381@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25382 * because the ->io_bitmap_max value must match the bitmap
25383 * contents:
25384 */
25385- tss = &per_cpu(init_tss, get_cpu());
25386+ tss = init_tss + get_cpu();
25387
25388 if (turn_on)
25389 bitmap_clear(t->io_bitmap_ptr, from, num);
25390@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25391 if (level > old) {
25392 if (!capable(CAP_SYS_RAWIO))
25393 return -EPERM;
25394+#ifdef CONFIG_GRKERNSEC_IO
25395+ if (grsec_disable_privio) {
25396+ gr_handle_iopl();
25397+ return -ENODEV;
25398+ }
25399+#endif
25400 }
25401 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25402 t->iopl = level << 12;
25403diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25404index d99f31d..1c0f466 100644
25405--- a/arch/x86/kernel/irq.c
25406+++ b/arch/x86/kernel/irq.c
25407@@ -21,7 +21,7 @@
25408 #define CREATE_TRACE_POINTS
25409 #include <asm/trace/irq_vectors.h>
25410
25411-atomic_t irq_err_count;
25412+atomic_unchecked_t irq_err_count;
25413
25414 /* Function pointer for generic interrupt vector handling */
25415 void (*x86_platform_ipi_callback)(void) = NULL;
25416@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25417 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
25418 seq_printf(p, " Machine check polls\n");
25419 #endif
25420- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25421+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25422 #if defined(CONFIG_X86_IO_APIC)
25423- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25424+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25425 #endif
25426 return 0;
25427 }
25428@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25429
25430 u64 arch_irq_stat(void)
25431 {
25432- u64 sum = atomic_read(&irq_err_count);
25433+ u64 sum = atomic_read_unchecked(&irq_err_count);
25434 return sum;
25435 }
25436
25437diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25438index d7fcbed..96e715a 100644
25439--- a/arch/x86/kernel/irq_32.c
25440+++ b/arch/x86/kernel/irq_32.c
25441@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25442
25443 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25444
25445+extern void gr_handle_kernel_exploit(void);
25446+
25447 int sysctl_panic_on_stackoverflow __read_mostly;
25448
25449 /* Debugging check for stack overflow: is there less than 1KB free? */
25450@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25451 __asm__ __volatile__("andl %%esp,%0" :
25452 "=r" (sp) : "0" (THREAD_SIZE - 1));
25453
25454- return sp < (sizeof(struct thread_info) + STACK_WARN);
25455+ return sp < STACK_WARN;
25456 }
25457
25458 static void print_stack_overflow(void)
25459 {
25460 printk(KERN_WARNING "low stack detected by irq handler\n");
25461 dump_stack();
25462+ gr_handle_kernel_exploit();
25463 if (sysctl_panic_on_stackoverflow)
25464 panic("low stack detected by irq handler - check messages\n");
25465 }
25466@@ -59,8 +62,8 @@ static inline void print_stack_overflow(void) { }
25467 * per-CPU IRQ handling contexts (thread information and stack)
25468 */
25469 union irq_ctx {
25470- struct thread_info tinfo;
25471- u32 stack[THREAD_SIZE/sizeof(u32)];
25472+ unsigned long previous_esp;
25473+ u32 stack[THREAD_SIZE/sizeof(u32)];
25474 } __attribute__((aligned(THREAD_SIZE)));
25475
25476 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
25477@@ -80,10 +83,9 @@ static void call_on_stack(void *func, void *stack)
25478 static inline int
25479 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25480 {
25481- union irq_ctx *curctx, *irqctx;
25482+ union irq_ctx *irqctx;
25483 u32 *isp, arg1, arg2;
25484
25485- curctx = (union irq_ctx *) current_thread_info();
25486 irqctx = __this_cpu_read(hardirq_ctx);
25487
25488 /*
25489@@ -92,13 +94,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25490 * handler) we can't do that and just have to keep using the
25491 * current stack (which is the irq stack already after all)
25492 */
25493- if (unlikely(curctx == irqctx))
25494+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
25495 return 0;
25496
25497 /* build the stack frame on the IRQ stack */
25498- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25499- irqctx->tinfo.task = curctx->tinfo.task;
25500- irqctx->tinfo.previous_esp = current_stack_pointer;
25501+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25502+ irqctx->previous_esp = current_stack_pointer;
25503+
25504+#ifdef CONFIG_PAX_MEMORY_UDEREF
25505+ __set_fs(MAKE_MM_SEG(0));
25506+#endif
25507
25508 if (unlikely(overflow))
25509 call_on_stack(print_stack_overflow, isp);
25510@@ -110,6 +115,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25511 : "0" (irq), "1" (desc), "2" (isp),
25512 "D" (desc->handle_irq)
25513 : "memory", "cc", "ecx");
25514+
25515+#ifdef CONFIG_PAX_MEMORY_UDEREF
25516+ __set_fs(current_thread_info()->addr_limit);
25517+#endif
25518+
25519 return 1;
25520 }
25521
25522@@ -118,48 +128,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25523 */
25524 void irq_ctx_init(int cpu)
25525 {
25526- union irq_ctx *irqctx;
25527-
25528 if (per_cpu(hardirq_ctx, cpu))
25529 return;
25530
25531- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25532- THREADINFO_GFP,
25533- THREAD_SIZE_ORDER));
25534- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25535- irqctx->tinfo.cpu = cpu;
25536- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25537-
25538- per_cpu(hardirq_ctx, cpu) = irqctx;
25539-
25540- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25541- THREADINFO_GFP,
25542- THREAD_SIZE_ORDER));
25543- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25544- irqctx->tinfo.cpu = cpu;
25545- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25546-
25547- per_cpu(softirq_ctx, cpu) = irqctx;
25548-
25549- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25550- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
25551+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25552+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25553 }
25554
25555 void do_softirq_own_stack(void)
25556 {
25557- struct thread_info *curctx;
25558 union irq_ctx *irqctx;
25559 u32 *isp;
25560
25561- curctx = current_thread_info();
25562 irqctx = __this_cpu_read(softirq_ctx);
25563- irqctx->tinfo.task = curctx->task;
25564- irqctx->tinfo.previous_esp = current_stack_pointer;
25565+ irqctx->previous_esp = current_stack_pointer;
25566
25567 /* build the stack frame on the softirq stack */
25568- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25569+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25570+
25571+#ifdef CONFIG_PAX_MEMORY_UDEREF
25572+ __set_fs(MAKE_MM_SEG(0));
25573+#endif
25574
25575 call_on_stack(__do_softirq, isp);
25576+
25577+#ifdef CONFIG_PAX_MEMORY_UDEREF
25578+ __set_fs(current_thread_info()->addr_limit);
25579+#endif
25580+
25581 }
25582
25583 bool handle_irq(unsigned irq, struct pt_regs *regs)
25584@@ -173,7 +169,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25585 if (unlikely(!desc))
25586 return false;
25587
25588- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25589+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25590 if (unlikely(overflow))
25591 print_stack_overflow();
25592 desc->handle_irq(irq, desc);
25593diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25594index 4d1c746..55a22d6 100644
25595--- a/arch/x86/kernel/irq_64.c
25596+++ b/arch/x86/kernel/irq_64.c
25597@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25598 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25599 EXPORT_PER_CPU_SYMBOL(irq_regs);
25600
25601+extern void gr_handle_kernel_exploit(void);
25602+
25603 int sysctl_panic_on_stackoverflow;
25604
25605 /*
25606@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25607 u64 estack_top, estack_bottom;
25608 u64 curbase = (u64)task_stack_page(current);
25609
25610- if (user_mode_vm(regs))
25611+ if (user_mode(regs))
25612 return;
25613
25614 if (regs->sp >= curbase + sizeof(struct thread_info) +
25615@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25616 irq_stack_top, irq_stack_bottom,
25617 estack_top, estack_bottom);
25618
25619+ gr_handle_kernel_exploit();
25620+
25621 if (sysctl_panic_on_stackoverflow)
25622 panic("low stack detected by irq handler - check messages\n");
25623 #endif
25624diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25625index 26d5a55..a01160a 100644
25626--- a/arch/x86/kernel/jump_label.c
25627+++ b/arch/x86/kernel/jump_label.c
25628@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25629 * Jump label is enabled for the first time.
25630 * So we expect a default_nop...
25631 */
25632- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25633+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25634 != 0))
25635 bug_at((void *)entry->code, __LINE__);
25636 } else {
25637@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25638 * ...otherwise expect an ideal_nop. Otherwise
25639 * something went horribly wrong.
25640 */
25641- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25642+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25643 != 0))
25644 bug_at((void *)entry->code, __LINE__);
25645 }
25646@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25647 * are converting the default nop to the ideal nop.
25648 */
25649 if (init) {
25650- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25651+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25652 bug_at((void *)entry->code, __LINE__);
25653 } else {
25654 code.jump = 0xe9;
25655 code.offset = entry->target -
25656 (entry->code + JUMP_LABEL_NOP_SIZE);
25657- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25658+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25659 bug_at((void *)entry->code, __LINE__);
25660 }
25661 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25662diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25663index 7ec1d5f..5a7d130 100644
25664--- a/arch/x86/kernel/kgdb.c
25665+++ b/arch/x86/kernel/kgdb.c
25666@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25667 #ifdef CONFIG_X86_32
25668 switch (regno) {
25669 case GDB_SS:
25670- if (!user_mode_vm(regs))
25671+ if (!user_mode(regs))
25672 *(unsigned long *)mem = __KERNEL_DS;
25673 break;
25674 case GDB_SP:
25675- if (!user_mode_vm(regs))
25676+ if (!user_mode(regs))
25677 *(unsigned long *)mem = kernel_stack_pointer(regs);
25678 break;
25679 case GDB_GS:
25680@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25681 bp->attr.bp_addr = breakinfo[breakno].addr;
25682 bp->attr.bp_len = breakinfo[breakno].len;
25683 bp->attr.bp_type = breakinfo[breakno].type;
25684- info->address = breakinfo[breakno].addr;
25685+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25686+ info->address = ktla_ktva(breakinfo[breakno].addr);
25687+ else
25688+ info->address = breakinfo[breakno].addr;
25689 info->len = breakinfo[breakno].len;
25690 info->type = breakinfo[breakno].type;
25691 val = arch_install_hw_breakpoint(bp);
25692@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25693 case 'k':
25694 /* clear the trace bit */
25695 linux_regs->flags &= ~X86_EFLAGS_TF;
25696- atomic_set(&kgdb_cpu_doing_single_step, -1);
25697+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25698
25699 /* set the trace bit if we're stepping */
25700 if (remcomInBuffer[0] == 's') {
25701 linux_regs->flags |= X86_EFLAGS_TF;
25702- atomic_set(&kgdb_cpu_doing_single_step,
25703+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25704 raw_smp_processor_id());
25705 }
25706
25707@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25708
25709 switch (cmd) {
25710 case DIE_DEBUG:
25711- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25712+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25713 if (user_mode(regs))
25714 return single_step_cont(regs, args);
25715 break;
25716@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25717 #endif /* CONFIG_DEBUG_RODATA */
25718
25719 bpt->type = BP_BREAKPOINT;
25720- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25721+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25722 BREAK_INSTR_SIZE);
25723 if (err)
25724 return err;
25725- err = probe_kernel_write((char *)bpt->bpt_addr,
25726+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25727 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25728 #ifdef CONFIG_DEBUG_RODATA
25729 if (!err)
25730@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25731 return -EBUSY;
25732 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25733 BREAK_INSTR_SIZE);
25734- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25735+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25736 if (err)
25737 return err;
25738 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25739@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25740 if (mutex_is_locked(&text_mutex))
25741 goto knl_write;
25742 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25743- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25744+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25745 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25746 goto knl_write;
25747 return err;
25748 knl_write:
25749 #endif /* CONFIG_DEBUG_RODATA */
25750- return probe_kernel_write((char *)bpt->bpt_addr,
25751+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25752 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25753 }
25754
25755diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25756index 79a3f96..6ba030a 100644
25757--- a/arch/x86/kernel/kprobes/core.c
25758+++ b/arch/x86/kernel/kprobes/core.c
25759@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25760 s32 raddr;
25761 } __packed *insn;
25762
25763- insn = (struct __arch_relative_insn *)from;
25764+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25765+
25766+ pax_open_kernel();
25767 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25768 insn->op = op;
25769+ pax_close_kernel();
25770 }
25771
25772 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25773@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25774 kprobe_opcode_t opcode;
25775 kprobe_opcode_t *orig_opcodes = opcodes;
25776
25777- if (search_exception_tables((unsigned long)opcodes))
25778+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25779 return 0; /* Page fault may occur on this address. */
25780
25781 retry:
25782@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25783 * for the first byte, we can recover the original instruction
25784 * from it and kp->opcode.
25785 */
25786- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25787+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25788 buf[0] = kp->opcode;
25789- return (unsigned long)buf;
25790+ return ktva_ktla((unsigned long)buf);
25791 }
25792
25793 /*
25794@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25795 /* Another subsystem puts a breakpoint, failed to recover */
25796 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25797 return 0;
25798+ pax_open_kernel();
25799 memcpy(dest, insn.kaddr, insn.length);
25800+ pax_close_kernel();
25801
25802 #ifdef CONFIG_X86_64
25803 if (insn_rip_relative(&insn)) {
25804@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25805 return 0;
25806 }
25807 disp = (u8 *) dest + insn_offset_displacement(&insn);
25808+ pax_open_kernel();
25809 *(s32 *) disp = (s32) newdisp;
25810+ pax_close_kernel();
25811 }
25812 #endif
25813 return insn.length;
25814@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25815 * nor set current_kprobe, because it doesn't use single
25816 * stepping.
25817 */
25818- regs->ip = (unsigned long)p->ainsn.insn;
25819+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25820 preempt_enable_no_resched();
25821 return;
25822 }
25823@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25824 regs->flags &= ~X86_EFLAGS_IF;
25825 /* single step inline if the instruction is an int3 */
25826 if (p->opcode == BREAKPOINT_INSTRUCTION)
25827- regs->ip = (unsigned long)p->addr;
25828+ regs->ip = ktla_ktva((unsigned long)p->addr);
25829 else
25830- regs->ip = (unsigned long)p->ainsn.insn;
25831+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25832 }
25833
25834 /*
25835@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25836 setup_singlestep(p, regs, kcb, 0);
25837 return 1;
25838 }
25839- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25840+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25841 /*
25842 * The breakpoint instruction was removed right
25843 * after we hit it. Another cpu has removed
25844@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25845 " movq %rax, 152(%rsp)\n"
25846 RESTORE_REGS_STRING
25847 " popfq\n"
25848+#ifdef KERNEXEC_PLUGIN
25849+ " btsq $63,(%rsp)\n"
25850+#endif
25851 #else
25852 " pushf\n"
25853 SAVE_REGS_STRING
25854@@ -779,7 +789,7 @@ static void __kprobes
25855 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25856 {
25857 unsigned long *tos = stack_addr(regs);
25858- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25859+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25860 unsigned long orig_ip = (unsigned long)p->addr;
25861 kprobe_opcode_t *insn = p->ainsn.insn;
25862
25863@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25864 struct die_args *args = data;
25865 int ret = NOTIFY_DONE;
25866
25867- if (args->regs && user_mode_vm(args->regs))
25868+ if (args->regs && user_mode(args->regs))
25869 return ret;
25870
25871 switch (val) {
25872diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25873index 898160b..758cde8 100644
25874--- a/arch/x86/kernel/kprobes/opt.c
25875+++ b/arch/x86/kernel/kprobes/opt.c
25876@@ -79,6 +79,7 @@ found:
25877 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25878 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25879 {
25880+ pax_open_kernel();
25881 #ifdef CONFIG_X86_64
25882 *addr++ = 0x48;
25883 *addr++ = 0xbf;
25884@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25885 *addr++ = 0xb8;
25886 #endif
25887 *(unsigned long *)addr = val;
25888+ pax_close_kernel();
25889 }
25890
25891 asm (
25892@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25893 * Verify if the address gap is in 2GB range, because this uses
25894 * a relative jump.
25895 */
25896- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25897+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25898 if (abs(rel) > 0x7fffffff)
25899 return -ERANGE;
25900
25901@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25902 op->optinsn.size = ret;
25903
25904 /* Copy arch-dep-instance from template */
25905- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25906+ pax_open_kernel();
25907+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25908+ pax_close_kernel();
25909
25910 /* Set probe information */
25911 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25912
25913 /* Set probe function call */
25914- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25915+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25916
25917 /* Set returning jmp instruction at the tail of out-of-line buffer */
25918- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25919+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25920 (u8 *)op->kp.addr + op->optinsn.size);
25921
25922 flush_icache_range((unsigned long) buf,
25923@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25924 WARN_ON(kprobe_disabled(&op->kp));
25925
25926 /* Backup instructions which will be replaced by jump address */
25927- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25928+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25929 RELATIVE_ADDR_SIZE);
25930
25931 insn_buf[0] = RELATIVEJUMP_OPCODE;
25932@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25933 /* This kprobe is really able to run optimized path. */
25934 op = container_of(p, struct optimized_kprobe, kp);
25935 /* Detour through copied instructions */
25936- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25937+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25938 if (!reenter)
25939 reset_current_kprobe();
25940 preempt_enable_no_resched();
25941diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25942index c2bedae..25e7ab6 100644
25943--- a/arch/x86/kernel/ksysfs.c
25944+++ b/arch/x86/kernel/ksysfs.c
25945@@ -184,7 +184,7 @@ out:
25946
25947 static struct kobj_attribute type_attr = __ATTR_RO(type);
25948
25949-static struct bin_attribute data_attr = {
25950+static bin_attribute_no_const data_attr __read_only = {
25951 .attr = {
25952 .name = "data",
25953 .mode = S_IRUGO,
25954diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25955index dcbbaa1..81ae763 100644
25956--- a/arch/x86/kernel/ldt.c
25957+++ b/arch/x86/kernel/ldt.c
25958@@ -68,13 +68,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25959 if (reload) {
25960 #ifdef CONFIG_SMP
25961 preempt_disable();
25962- load_LDT(pc);
25963+ load_LDT_nolock(pc);
25964 if (!cpumask_equal(mm_cpumask(current->mm),
25965 cpumask_of(smp_processor_id())))
25966 smp_call_function(flush_ldt, current->mm, 1);
25967 preempt_enable();
25968 #else
25969- load_LDT(pc);
25970+ load_LDT_nolock(pc);
25971 #endif
25972 }
25973 if (oldsize) {
25974@@ -96,7 +96,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25975 return err;
25976
25977 for (i = 0; i < old->size; i++)
25978- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25979+ write_ldt_entry(new->ldt, i, old->ldt + i);
25980 return 0;
25981 }
25982
25983@@ -117,6 +117,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25984 retval = copy_ldt(&mm->context, &old_mm->context);
25985 mutex_unlock(&old_mm->context.lock);
25986 }
25987+
25988+ if (tsk == current) {
25989+ mm->context.vdso = 0;
25990+
25991+#ifdef CONFIG_X86_32
25992+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25993+ mm->context.user_cs_base = 0UL;
25994+ mm->context.user_cs_limit = ~0UL;
25995+
25996+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25997+ cpus_clear(mm->context.cpu_user_cs_mask);
25998+#endif
25999+
26000+#endif
26001+#endif
26002+
26003+ }
26004+
26005 return retval;
26006 }
26007
26008@@ -231,6 +249,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
26009 }
26010 }
26011
26012+#ifdef CONFIG_PAX_SEGMEXEC
26013+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
26014+ error = -EINVAL;
26015+ goto out_unlock;
26016+ }
26017+#endif
26018+
26019 /*
26020 * On x86-64 we do not support 16-bit segments due to
26021 * IRET leaking the high bits of the kernel stack address.
26022diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
26023index 1667b1d..16492c5 100644
26024--- a/arch/x86/kernel/machine_kexec_32.c
26025+++ b/arch/x86/kernel/machine_kexec_32.c
26026@@ -25,7 +25,7 @@
26027 #include <asm/cacheflush.h>
26028 #include <asm/debugreg.h>
26029
26030-static void set_idt(void *newidt, __u16 limit)
26031+static void set_idt(struct desc_struct *newidt, __u16 limit)
26032 {
26033 struct desc_ptr curidt;
26034
26035@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
26036 }
26037
26038
26039-static void set_gdt(void *newgdt, __u16 limit)
26040+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
26041 {
26042 struct desc_ptr curgdt;
26043
26044@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
26045 }
26046
26047 control_page = page_address(image->control_code_page);
26048- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
26049+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
26050
26051 relocate_kernel_ptr = control_page;
26052 page_list[PA_CONTROL_PAGE] = __pa(control_page);
26053diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26054index 18be189..4a9fe40 100644
26055--- a/arch/x86/kernel/module.c
26056+++ b/arch/x86/kernel/module.c
26057@@ -43,15 +43,60 @@ do { \
26058 } while (0)
26059 #endif
26060
26061-void *module_alloc(unsigned long size)
26062+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26063 {
26064- if (PAGE_ALIGN(size) > MODULES_LEN)
26065+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26066 return NULL;
26067 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
26068- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
26069+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
26070 NUMA_NO_NODE, __builtin_return_address(0));
26071 }
26072
26073+void *module_alloc(unsigned long size)
26074+{
26075+
26076+#ifdef CONFIG_PAX_KERNEXEC
26077+ return __module_alloc(size, PAGE_KERNEL);
26078+#else
26079+ return __module_alloc(size, PAGE_KERNEL_EXEC);
26080+#endif
26081+
26082+}
26083+
26084+#ifdef CONFIG_PAX_KERNEXEC
26085+#ifdef CONFIG_X86_32
26086+void *module_alloc_exec(unsigned long size)
26087+{
26088+ struct vm_struct *area;
26089+
26090+ if (size == 0)
26091+ return NULL;
26092+
26093+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26094+ return area ? area->addr : NULL;
26095+}
26096+EXPORT_SYMBOL(module_alloc_exec);
26097+
26098+void module_free_exec(struct module *mod, void *module_region)
26099+{
26100+ vunmap(module_region);
26101+}
26102+EXPORT_SYMBOL(module_free_exec);
26103+#else
26104+void module_free_exec(struct module *mod, void *module_region)
26105+{
26106+ module_free(mod, module_region);
26107+}
26108+EXPORT_SYMBOL(module_free_exec);
26109+
26110+void *module_alloc_exec(unsigned long size)
26111+{
26112+ return __module_alloc(size, PAGE_KERNEL_RX);
26113+}
26114+EXPORT_SYMBOL(module_alloc_exec);
26115+#endif
26116+#endif
26117+
26118 #ifdef CONFIG_X86_32
26119 int apply_relocate(Elf32_Shdr *sechdrs,
26120 const char *strtab,
26121@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26122 unsigned int i;
26123 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26124 Elf32_Sym *sym;
26125- uint32_t *location;
26126+ uint32_t *plocation, location;
26127
26128 DEBUGP("Applying relocate section %u to %u\n",
26129 relsec, sechdrs[relsec].sh_info);
26130 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26131 /* This is where to make the change */
26132- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26133- + rel[i].r_offset;
26134+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26135+ location = (uint32_t)plocation;
26136+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26137+ plocation = ktla_ktva((void *)plocation);
26138 /* This is the symbol it is referring to. Note that all
26139 undefined symbols have been resolved. */
26140 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26141@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26142 switch (ELF32_R_TYPE(rel[i].r_info)) {
26143 case R_386_32:
26144 /* We add the value into the location given */
26145- *location += sym->st_value;
26146+ pax_open_kernel();
26147+ *plocation += sym->st_value;
26148+ pax_close_kernel();
26149 break;
26150 case R_386_PC32:
26151 /* Add the value, subtract its position */
26152- *location += sym->st_value - (uint32_t)location;
26153+ pax_open_kernel();
26154+ *plocation += sym->st_value - location;
26155+ pax_close_kernel();
26156 break;
26157 default:
26158 pr_err("%s: Unknown relocation: %u\n",
26159@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26160 case R_X86_64_NONE:
26161 break;
26162 case R_X86_64_64:
26163+ pax_open_kernel();
26164 *(u64 *)loc = val;
26165+ pax_close_kernel();
26166 break;
26167 case R_X86_64_32:
26168+ pax_open_kernel();
26169 *(u32 *)loc = val;
26170+ pax_close_kernel();
26171 if (val != *(u32 *)loc)
26172 goto overflow;
26173 break;
26174 case R_X86_64_32S:
26175+ pax_open_kernel();
26176 *(s32 *)loc = val;
26177+ pax_close_kernel();
26178 if ((s64)val != *(s32 *)loc)
26179 goto overflow;
26180 break;
26181 case R_X86_64_PC32:
26182 val -= (u64)loc;
26183+ pax_open_kernel();
26184 *(u32 *)loc = val;
26185+ pax_close_kernel();
26186+
26187 #if 0
26188 if ((s64)val != *(s32 *)loc)
26189 goto overflow;
26190diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26191index 05266b5..3432443 100644
26192--- a/arch/x86/kernel/msr.c
26193+++ b/arch/x86/kernel/msr.c
26194@@ -37,6 +37,7 @@
26195 #include <linux/notifier.h>
26196 #include <linux/uaccess.h>
26197 #include <linux/gfp.h>
26198+#include <linux/grsecurity.h>
26199
26200 #include <asm/processor.h>
26201 #include <asm/msr.h>
26202@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26203 int err = 0;
26204 ssize_t bytes = 0;
26205
26206+#ifdef CONFIG_GRKERNSEC_KMEM
26207+ gr_handle_msr_write();
26208+ return -EPERM;
26209+#endif
26210+
26211 if (count % 8)
26212 return -EINVAL; /* Invalid chunk size */
26213
26214@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26215 err = -EBADF;
26216 break;
26217 }
26218+#ifdef CONFIG_GRKERNSEC_KMEM
26219+ gr_handle_msr_write();
26220+ return -EPERM;
26221+#endif
26222 if (copy_from_user(&regs, uregs, sizeof regs)) {
26223 err = -EFAULT;
26224 break;
26225@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26226 return notifier_from_errno(err);
26227 }
26228
26229-static struct notifier_block __refdata msr_class_cpu_notifier = {
26230+static struct notifier_block msr_class_cpu_notifier = {
26231 .notifier_call = msr_class_cpu_callback,
26232 };
26233
26234diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26235index 6fcb49c..5b3f4ff 100644
26236--- a/arch/x86/kernel/nmi.c
26237+++ b/arch/x86/kernel/nmi.c
26238@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
26239 return handled;
26240 }
26241
26242-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26243+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26244 {
26245 struct nmi_desc *desc = nmi_to_desc(type);
26246 unsigned long flags;
26247@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26248 * event confuses some handlers (kdump uses this flag)
26249 */
26250 if (action->flags & NMI_FLAG_FIRST)
26251- list_add_rcu(&action->list, &desc->head);
26252+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26253 else
26254- list_add_tail_rcu(&action->list, &desc->head);
26255+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26256
26257 spin_unlock_irqrestore(&desc->lock, flags);
26258 return 0;
26259@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26260 if (!strcmp(n->name, name)) {
26261 WARN(in_nmi(),
26262 "Trying to free NMI (%s) from NMI context!\n", n->name);
26263- list_del_rcu(&n->list);
26264+ pax_list_del_rcu((struct list_head *)&n->list);
26265 break;
26266 }
26267 }
26268@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
26269 dotraplinkage notrace __kprobes void
26270 do_nmi(struct pt_regs *regs, long error_code)
26271 {
26272+
26273+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26274+ if (!user_mode(regs)) {
26275+ unsigned long cs = regs->cs & 0xFFFF;
26276+ unsigned long ip = ktva_ktla(regs->ip);
26277+
26278+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26279+ regs->ip = ip;
26280+ }
26281+#endif
26282+
26283 nmi_nesting_preprocess(regs);
26284
26285 nmi_enter();
26286diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26287index 6d9582e..f746287 100644
26288--- a/arch/x86/kernel/nmi_selftest.c
26289+++ b/arch/x86/kernel/nmi_selftest.c
26290@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26291 {
26292 /* trap all the unknown NMIs we may generate */
26293 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26294- __initdata);
26295+ __initconst);
26296 }
26297
26298 static void __init cleanup_nmi_testsuite(void)
26299@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26300 unsigned long timeout;
26301
26302 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26303- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26304+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26305 nmi_fail = FAILURE;
26306 return;
26307 }
26308diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26309index bbb6c73..24a58ef 100644
26310--- a/arch/x86/kernel/paravirt-spinlocks.c
26311+++ b/arch/x86/kernel/paravirt-spinlocks.c
26312@@ -8,7 +8,7 @@
26313
26314 #include <asm/paravirt.h>
26315
26316-struct pv_lock_ops pv_lock_ops = {
26317+struct pv_lock_ops pv_lock_ops __read_only = {
26318 #ifdef CONFIG_SMP
26319 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26320 .unlock_kick = paravirt_nop,
26321diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26322index 1b10af8..45bfbec 100644
26323--- a/arch/x86/kernel/paravirt.c
26324+++ b/arch/x86/kernel/paravirt.c
26325@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
26326 {
26327 return x;
26328 }
26329+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26330+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26331+#endif
26332
26333 void __init default_banner(void)
26334 {
26335@@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26336
26337 if (opfunc == NULL)
26338 /* If there's no function, patch it with a ud2a (BUG) */
26339- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26340- else if (opfunc == _paravirt_nop)
26341+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26342+ else if (opfunc == (void *)_paravirt_nop)
26343 /* If the operation is a nop, then nop the callsite */
26344 ret = paravirt_patch_nop();
26345
26346 /* identity functions just return their single argument */
26347- else if (opfunc == _paravirt_ident_32)
26348+ else if (opfunc == (void *)_paravirt_ident_32)
26349 ret = paravirt_patch_ident_32(insnbuf, len);
26350- else if (opfunc == _paravirt_ident_64)
26351+ else if (opfunc == (void *)_paravirt_ident_64)
26352 ret = paravirt_patch_ident_64(insnbuf, len);
26353+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26354+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26355+ ret = paravirt_patch_ident_64(insnbuf, len);
26356+#endif
26357
26358 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26359 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26360@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26361 if (insn_len > len || start == NULL)
26362 insn_len = len;
26363 else
26364- memcpy(insnbuf, start, insn_len);
26365+ memcpy(insnbuf, ktla_ktva(start), insn_len);
26366
26367 return insn_len;
26368 }
26369@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26370 return this_cpu_read(paravirt_lazy_mode);
26371 }
26372
26373-struct pv_info pv_info = {
26374+struct pv_info pv_info __read_only = {
26375 .name = "bare hardware",
26376 .paravirt_enabled = 0,
26377 .kernel_rpl = 0,
26378@@ -310,16 +317,16 @@ struct pv_info pv_info = {
26379 #endif
26380 };
26381
26382-struct pv_init_ops pv_init_ops = {
26383+struct pv_init_ops pv_init_ops __read_only = {
26384 .patch = native_patch,
26385 };
26386
26387-struct pv_time_ops pv_time_ops = {
26388+struct pv_time_ops pv_time_ops __read_only = {
26389 .sched_clock = native_sched_clock,
26390 .steal_clock = native_steal_clock,
26391 };
26392
26393-__visible struct pv_irq_ops pv_irq_ops = {
26394+__visible struct pv_irq_ops pv_irq_ops __read_only = {
26395 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26396 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26397 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26398@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26399 #endif
26400 };
26401
26402-__visible struct pv_cpu_ops pv_cpu_ops = {
26403+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26404 .cpuid = native_cpuid,
26405 .get_debugreg = native_get_debugreg,
26406 .set_debugreg = native_set_debugreg,
26407@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
26408 .end_context_switch = paravirt_nop,
26409 };
26410
26411-struct pv_apic_ops pv_apic_ops = {
26412+struct pv_apic_ops pv_apic_ops __read_only= {
26413 #ifdef CONFIG_X86_LOCAL_APIC
26414 .startup_ipi_hook = paravirt_nop,
26415 #endif
26416 };
26417
26418-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26419+#ifdef CONFIG_X86_32
26420+#ifdef CONFIG_X86_PAE
26421+/* 64-bit pagetable entries */
26422+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26423+#else
26424 /* 32-bit pagetable entries */
26425 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26426+#endif
26427 #else
26428 /* 64-bit pagetable entries */
26429 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26430 #endif
26431
26432-struct pv_mmu_ops pv_mmu_ops = {
26433+struct pv_mmu_ops pv_mmu_ops __read_only = {
26434
26435 .read_cr2 = native_read_cr2,
26436 .write_cr2 = native_write_cr2,
26437@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26438 .make_pud = PTE_IDENT,
26439
26440 .set_pgd = native_set_pgd,
26441+ .set_pgd_batched = native_set_pgd_batched,
26442 #endif
26443 #endif /* PAGETABLE_LEVELS >= 3 */
26444
26445@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26446 },
26447
26448 .set_fixmap = native_set_fixmap,
26449+
26450+#ifdef CONFIG_PAX_KERNEXEC
26451+ .pax_open_kernel = native_pax_open_kernel,
26452+ .pax_close_kernel = native_pax_close_kernel,
26453+#endif
26454+
26455 };
26456
26457 EXPORT_SYMBOL_GPL(pv_time_ops);
26458diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26459index 299d493..2ccb0ee 100644
26460--- a/arch/x86/kernel/pci-calgary_64.c
26461+++ b/arch/x86/kernel/pci-calgary_64.c
26462@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
26463 tce_space = be64_to_cpu(readq(target));
26464 tce_space = tce_space & TAR_SW_BITS;
26465
26466- tce_space = tce_space & (~specified_table_size);
26467+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26468 info->tce_space = (u64 *)__va(tce_space);
26469 }
26470 }
26471diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26472index 35ccf75..7a15747 100644
26473--- a/arch/x86/kernel/pci-iommu_table.c
26474+++ b/arch/x86/kernel/pci-iommu_table.c
26475@@ -2,7 +2,7 @@
26476 #include <asm/iommu_table.h>
26477 #include <linux/string.h>
26478 #include <linux/kallsyms.h>
26479-
26480+#include <linux/sched.h>
26481
26482 #define DEBUG 1
26483
26484diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26485index 6c483ba..d10ce2f 100644
26486--- a/arch/x86/kernel/pci-swiotlb.c
26487+++ b/arch/x86/kernel/pci-swiotlb.c
26488@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26489 void *vaddr, dma_addr_t dma_addr,
26490 struct dma_attrs *attrs)
26491 {
26492- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26493+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26494 }
26495
26496 static struct dma_map_ops swiotlb_dma_ops = {
26497diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26498index ca7f0d5..8996469 100644
26499--- a/arch/x86/kernel/preempt.S
26500+++ b/arch/x86/kernel/preempt.S
26501@@ -3,12 +3,14 @@
26502 #include <asm/dwarf2.h>
26503 #include <asm/asm.h>
26504 #include <asm/calling.h>
26505+#include <asm/alternative-asm.h>
26506
26507 ENTRY(___preempt_schedule)
26508 CFI_STARTPROC
26509 SAVE_ALL
26510 call preempt_schedule
26511 RESTORE_ALL
26512+ pax_force_retaddr
26513 ret
26514 CFI_ENDPROC
26515
26516@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26517 SAVE_ALL
26518 call preempt_schedule_context
26519 RESTORE_ALL
26520+ pax_force_retaddr
26521 ret
26522 CFI_ENDPROC
26523
26524diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26525index 3fb8d95..254dc51 100644
26526--- a/arch/x86/kernel/process.c
26527+++ b/arch/x86/kernel/process.c
26528@@ -36,7 +36,8 @@
26529 * section. Since TSS's are completely CPU-local, we want them
26530 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26531 */
26532-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26533+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26534+EXPORT_SYMBOL(init_tss);
26535
26536 #ifdef CONFIG_X86_64
26537 static DEFINE_PER_CPU(unsigned char, is_idle);
26538@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26539 task_xstate_cachep =
26540 kmem_cache_create("task_xstate", xstate_size,
26541 __alignof__(union thread_xstate),
26542- SLAB_PANIC | SLAB_NOTRACK, NULL);
26543+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26544 }
26545
26546 /*
26547@@ -105,7 +106,7 @@ void exit_thread(void)
26548 unsigned long *bp = t->io_bitmap_ptr;
26549
26550 if (bp) {
26551- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26552+ struct tss_struct *tss = init_tss + get_cpu();
26553
26554 t->io_bitmap_ptr = NULL;
26555 clear_thread_flag(TIF_IO_BITMAP);
26556@@ -125,6 +126,9 @@ void flush_thread(void)
26557 {
26558 struct task_struct *tsk = current;
26559
26560+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26561+ loadsegment(gs, 0);
26562+#endif
26563 flush_ptrace_hw_breakpoint(tsk);
26564 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26565 drop_init_fpu(tsk);
26566@@ -271,7 +275,7 @@ static void __exit_idle(void)
26567 void exit_idle(void)
26568 {
26569 /* idle loop has pid 0 */
26570- if (current->pid)
26571+ if (task_pid_nr(current))
26572 return;
26573 __exit_idle();
26574 }
26575@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26576 return ret;
26577 }
26578 #endif
26579-void stop_this_cpu(void *dummy)
26580+__noreturn void stop_this_cpu(void *dummy)
26581 {
26582 local_irq_disable();
26583 /*
26584@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26585 }
26586 early_param("idle", idle_setup);
26587
26588-unsigned long arch_align_stack(unsigned long sp)
26589+#ifdef CONFIG_PAX_RANDKSTACK
26590+void pax_randomize_kstack(struct pt_regs *regs)
26591 {
26592- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26593- sp -= get_random_int() % 8192;
26594- return sp & ~0xf;
26595-}
26596+ struct thread_struct *thread = &current->thread;
26597+ unsigned long time;
26598
26599-unsigned long arch_randomize_brk(struct mm_struct *mm)
26600-{
26601- unsigned long range_end = mm->brk + 0x02000000;
26602- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26603-}
26604+ if (!randomize_va_space)
26605+ return;
26606+
26607+ if (v8086_mode(regs))
26608+ return;
26609
26610+ rdtscl(time);
26611+
26612+ /* P4 seems to return a 0 LSB, ignore it */
26613+#ifdef CONFIG_MPENTIUM4
26614+ time &= 0x3EUL;
26615+ time <<= 2;
26616+#elif defined(CONFIG_X86_64)
26617+ time &= 0xFUL;
26618+ time <<= 4;
26619+#else
26620+ time &= 0x1FUL;
26621+ time <<= 3;
26622+#endif
26623+
26624+ thread->sp0 ^= time;
26625+ load_sp0(init_tss + smp_processor_id(), thread);
26626+
26627+#ifdef CONFIG_X86_64
26628+ this_cpu_write(kernel_stack, thread->sp0);
26629+#endif
26630+}
26631+#endif
26632diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26633index 0de43e9..056b840 100644
26634--- a/arch/x86/kernel/process_32.c
26635+++ b/arch/x86/kernel/process_32.c
26636@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26637 unsigned long thread_saved_pc(struct task_struct *tsk)
26638 {
26639 return ((unsigned long *)tsk->thread.sp)[3];
26640+//XXX return tsk->thread.eip;
26641 }
26642
26643 void __show_regs(struct pt_regs *regs, int all)
26644@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26645 unsigned long sp;
26646 unsigned short ss, gs;
26647
26648- if (user_mode_vm(regs)) {
26649+ if (user_mode(regs)) {
26650 sp = regs->sp;
26651 ss = regs->ss & 0xffff;
26652- gs = get_user_gs(regs);
26653 } else {
26654 sp = kernel_stack_pointer(regs);
26655 savesegment(ss, ss);
26656- savesegment(gs, gs);
26657 }
26658+ gs = get_user_gs(regs);
26659
26660 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26661 (u16)regs->cs, regs->ip, regs->flags,
26662- smp_processor_id());
26663+ raw_smp_processor_id());
26664 print_symbol("EIP is at %s\n", regs->ip);
26665
26666 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26667@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26668 int copy_thread(unsigned long clone_flags, unsigned long sp,
26669 unsigned long arg, struct task_struct *p)
26670 {
26671- struct pt_regs *childregs = task_pt_regs(p);
26672+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26673 struct task_struct *tsk;
26674 int err;
26675
26676 p->thread.sp = (unsigned long) childregs;
26677 p->thread.sp0 = (unsigned long) (childregs+1);
26678+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26679
26680 if (unlikely(p->flags & PF_KTHREAD)) {
26681 /* kernel thread */
26682 memset(childregs, 0, sizeof(struct pt_regs));
26683 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26684- task_user_gs(p) = __KERNEL_STACK_CANARY;
26685- childregs->ds = __USER_DS;
26686- childregs->es = __USER_DS;
26687+ savesegment(gs, childregs->gs);
26688+ childregs->ds = __KERNEL_DS;
26689+ childregs->es = __KERNEL_DS;
26690 childregs->fs = __KERNEL_PERCPU;
26691 childregs->bx = sp; /* function */
26692 childregs->bp = arg;
26693@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26694 struct thread_struct *prev = &prev_p->thread,
26695 *next = &next_p->thread;
26696 int cpu = smp_processor_id();
26697- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26698+ struct tss_struct *tss = init_tss + cpu;
26699 fpu_switch_t fpu;
26700
26701 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26702@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26703 */
26704 lazy_save_gs(prev->gs);
26705
26706+#ifdef CONFIG_PAX_MEMORY_UDEREF
26707+ __set_fs(task_thread_info(next_p)->addr_limit);
26708+#endif
26709+
26710 /*
26711 * Load the per-thread Thread-Local Storage descriptor.
26712 */
26713@@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26714 */
26715 arch_end_context_switch(next_p);
26716
26717+ this_cpu_write(current_task, next_p);
26718+ this_cpu_write(current_tinfo, &next_p->tinfo);
26719+
26720 /*
26721 * Restore %gs if needed (which is common)
26722 */
26723@@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26724
26725 switch_fpu_finish(next_p, fpu);
26726
26727- this_cpu_write(current_task, next_p);
26728-
26729 return prev_p;
26730 }
26731
26732@@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
26733 } while (count++ < 16);
26734 return 0;
26735 }
26736-
26737diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26738index 9c0280f..5bbb1c0 100644
26739--- a/arch/x86/kernel/process_64.c
26740+++ b/arch/x86/kernel/process_64.c
26741@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26742 struct pt_regs *childregs;
26743 struct task_struct *me = current;
26744
26745- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26746+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26747 childregs = task_pt_regs(p);
26748 p->thread.sp = (unsigned long) childregs;
26749 p->thread.usersp = me->thread.usersp;
26750+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26751 set_tsk_thread_flag(p, TIF_FORK);
26752 p->thread.fpu_counter = 0;
26753 p->thread.io_bitmap_ptr = NULL;
26754@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26755 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26756 savesegment(es, p->thread.es);
26757 savesegment(ds, p->thread.ds);
26758+ savesegment(ss, p->thread.ss);
26759+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26760 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26761
26762 if (unlikely(p->flags & PF_KTHREAD)) {
26763@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26764 struct thread_struct *prev = &prev_p->thread;
26765 struct thread_struct *next = &next_p->thread;
26766 int cpu = smp_processor_id();
26767- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26768+ struct tss_struct *tss = init_tss + cpu;
26769 unsigned fsindex, gsindex;
26770 fpu_switch_t fpu;
26771
26772@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26773 if (unlikely(next->ds | prev->ds))
26774 loadsegment(ds, next->ds);
26775
26776+ savesegment(ss, prev->ss);
26777+ if (unlikely(next->ss != prev->ss))
26778+ loadsegment(ss, next->ss);
26779
26780 /* We must save %fs and %gs before load_TLS() because
26781 * %fs and %gs may be cleared by load_TLS().
26782@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26783 prev->usersp = this_cpu_read(old_rsp);
26784 this_cpu_write(old_rsp, next->usersp);
26785 this_cpu_write(current_task, next_p);
26786+ this_cpu_write(current_tinfo, &next_p->tinfo);
26787
26788 /*
26789 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26790@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26791 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26792 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26793
26794- this_cpu_write(kernel_stack,
26795- (unsigned long)task_stack_page(next_p) +
26796- THREAD_SIZE - KERNEL_STACK_OFFSET);
26797+ this_cpu_write(kernel_stack, next->sp0);
26798
26799 /*
26800 * Now maybe reload the debug registers and handle I/O bitmaps
26801@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26802 if (!p || p == current || p->state == TASK_RUNNING)
26803 return 0;
26804 stack = (unsigned long)task_stack_page(p);
26805- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26806+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26807 return 0;
26808 fp = *(u64 *)(p->thread.sp);
26809 do {
26810- if (fp < (unsigned long)stack ||
26811- fp >= (unsigned long)stack+THREAD_SIZE)
26812+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26813 return 0;
26814 ip = *(u64 *)(fp+8);
26815 if (!in_sched_functions(ip))
26816diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26817index 7461f50..1334029 100644
26818--- a/arch/x86/kernel/ptrace.c
26819+++ b/arch/x86/kernel/ptrace.c
26820@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26821 {
26822 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26823 unsigned long sp = (unsigned long)&regs->sp;
26824- struct thread_info *tinfo;
26825
26826- if (context == (sp & ~(THREAD_SIZE - 1)))
26827+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26828 return sp;
26829
26830- tinfo = (struct thread_info *)context;
26831- if (tinfo->previous_esp)
26832- return tinfo->previous_esp;
26833+ sp = *(unsigned long *)context;
26834+ if (sp)
26835+ return sp;
26836
26837 return (unsigned long)regs;
26838 }
26839@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26840 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26841 {
26842 int i;
26843- int dr7 = 0;
26844+ unsigned long dr7 = 0;
26845 struct arch_hw_breakpoint *info;
26846
26847 for (i = 0; i < HBP_NUM; i++) {
26848@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26849 unsigned long addr, unsigned long data)
26850 {
26851 int ret;
26852- unsigned long __user *datap = (unsigned long __user *)data;
26853+ unsigned long __user *datap = (__force unsigned long __user *)data;
26854
26855 switch (request) {
26856 /* read the word at location addr in the USER area. */
26857@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26858 if ((int) addr < 0)
26859 return -EIO;
26860 ret = do_get_thread_area(child, addr,
26861- (struct user_desc __user *)data);
26862+ (__force struct user_desc __user *) data);
26863 break;
26864
26865 case PTRACE_SET_THREAD_AREA:
26866 if ((int) addr < 0)
26867 return -EIO;
26868 ret = do_set_thread_area(child, addr,
26869- (struct user_desc __user *)data, 0);
26870+ (__force struct user_desc __user *) data, 0);
26871 break;
26872 #endif
26873
26874@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26875
26876 #ifdef CONFIG_X86_64
26877
26878-static struct user_regset x86_64_regsets[] __read_mostly = {
26879+static user_regset_no_const x86_64_regsets[] __read_only = {
26880 [REGSET_GENERAL] = {
26881 .core_note_type = NT_PRSTATUS,
26882 .n = sizeof(struct user_regs_struct) / sizeof(long),
26883@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26884 #endif /* CONFIG_X86_64 */
26885
26886 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26887-static struct user_regset x86_32_regsets[] __read_mostly = {
26888+static user_regset_no_const x86_32_regsets[] __read_only = {
26889 [REGSET_GENERAL] = {
26890 .core_note_type = NT_PRSTATUS,
26891 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26892@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26893 */
26894 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26895
26896-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26897+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26898 {
26899 #ifdef CONFIG_X86_64
26900 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26901@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26902 memset(info, 0, sizeof(*info));
26903 info->si_signo = SIGTRAP;
26904 info->si_code = si_code;
26905- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26906+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26907 }
26908
26909 void user_single_step_siginfo(struct task_struct *tsk,
26910@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26911 # define IS_IA32 0
26912 #endif
26913
26914+#ifdef CONFIG_GRKERNSEC_SETXID
26915+extern void gr_delayed_cred_worker(void);
26916+#endif
26917+
26918 /*
26919 * We must return the syscall number to actually look up in the table.
26920 * This can be -1L to skip running any syscall at all.
26921@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26922
26923 user_exit();
26924
26925+#ifdef CONFIG_GRKERNSEC_SETXID
26926+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26927+ gr_delayed_cred_worker();
26928+#endif
26929+
26930 /*
26931 * If we stepped into a sysenter/syscall insn, it trapped in
26932 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26933@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26934 */
26935 user_exit();
26936
26937+#ifdef CONFIG_GRKERNSEC_SETXID
26938+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26939+ gr_delayed_cred_worker();
26940+#endif
26941+
26942 audit_syscall_exit(regs);
26943
26944 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26945diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26946index 2f355d2..e75ed0a 100644
26947--- a/arch/x86/kernel/pvclock.c
26948+++ b/arch/x86/kernel/pvclock.c
26949@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26950 reset_hung_task_detector();
26951 }
26952
26953-static atomic64_t last_value = ATOMIC64_INIT(0);
26954+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26955
26956 void pvclock_resume(void)
26957 {
26958- atomic64_set(&last_value, 0);
26959+ atomic64_set_unchecked(&last_value, 0);
26960 }
26961
26962 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26963@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26964 * updating at the same time, and one of them could be slightly behind,
26965 * making the assumption that last_value always go forward fail to hold.
26966 */
26967- last = atomic64_read(&last_value);
26968+ last = atomic64_read_unchecked(&last_value);
26969 do {
26970 if (ret < last)
26971 return last;
26972- last = atomic64_cmpxchg(&last_value, last, ret);
26973+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26974 } while (unlikely(last != ret));
26975
26976 return ret;
26977diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26978index c752cb4..866c432 100644
26979--- a/arch/x86/kernel/reboot.c
26980+++ b/arch/x86/kernel/reboot.c
26981@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26982
26983 void __noreturn machine_real_restart(unsigned int type)
26984 {
26985+
26986+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26987+ struct desc_struct *gdt;
26988+#endif
26989+
26990 local_irq_disable();
26991
26992 /*
26993@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26994
26995 /* Jump to the identity-mapped low memory code */
26996 #ifdef CONFIG_X86_32
26997- asm volatile("jmpl *%0" : :
26998+
26999+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27000+ gdt = get_cpu_gdt_table(smp_processor_id());
27001+ pax_open_kernel();
27002+#ifdef CONFIG_PAX_MEMORY_UDEREF
27003+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27004+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27005+ loadsegment(ds, __KERNEL_DS);
27006+ loadsegment(es, __KERNEL_DS);
27007+ loadsegment(ss, __KERNEL_DS);
27008+#endif
27009+#ifdef CONFIG_PAX_KERNEXEC
27010+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27011+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27012+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27013+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27014+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27015+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27016+#endif
27017+ pax_close_kernel();
27018+#endif
27019+
27020+ asm volatile("ljmpl *%0" : :
27021 "rm" (real_mode_header->machine_real_restart_asm),
27022 "a" (type));
27023 #else
27024@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27025 * try to force a triple fault and then cycle between hitting the keyboard
27026 * controller and doing that
27027 */
27028-static void native_machine_emergency_restart(void)
27029+static void __noreturn native_machine_emergency_restart(void)
27030 {
27031 int i;
27032 int attempt = 0;
27033@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
27034 #endif
27035 }
27036
27037-static void __machine_emergency_restart(int emergency)
27038+static void __noreturn __machine_emergency_restart(int emergency)
27039 {
27040 reboot_emergency = emergency;
27041 machine_ops.emergency_restart();
27042 }
27043
27044-static void native_machine_restart(char *__unused)
27045+static void __noreturn native_machine_restart(char *__unused)
27046 {
27047 pr_notice("machine restart\n");
27048
27049@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
27050 __machine_emergency_restart(0);
27051 }
27052
27053-static void native_machine_halt(void)
27054+static void __noreturn native_machine_halt(void)
27055 {
27056 /* Stop other cpus and apics */
27057 machine_shutdown();
27058@@ -618,7 +645,7 @@ static void native_machine_halt(void)
27059 stop_this_cpu(NULL);
27060 }
27061
27062-static void native_machine_power_off(void)
27063+static void __noreturn native_machine_power_off(void)
27064 {
27065 if (pm_power_off) {
27066 if (!reboot_force)
27067@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
27068 }
27069 /* A fallback in case there is no PM info available */
27070 tboot_shutdown(TB_SHUTDOWN_HALT);
27071+ unreachable();
27072 }
27073
27074-struct machine_ops machine_ops = {
27075+struct machine_ops machine_ops __read_only = {
27076 .power_off = native_machine_power_off,
27077 .shutdown = native_machine_shutdown,
27078 .emergency_restart = native_machine_emergency_restart,
27079diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27080index c8e41e9..64049ef 100644
27081--- a/arch/x86/kernel/reboot_fixups_32.c
27082+++ b/arch/x86/kernel/reboot_fixups_32.c
27083@@ -57,7 +57,7 @@ struct device_fixup {
27084 unsigned int vendor;
27085 unsigned int device;
27086 void (*reboot_fixup)(struct pci_dev *);
27087-};
27088+} __do_const;
27089
27090 /*
27091 * PCI ids solely used for fixups_table go here
27092diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27093index 3fd2c69..a444264 100644
27094--- a/arch/x86/kernel/relocate_kernel_64.S
27095+++ b/arch/x86/kernel/relocate_kernel_64.S
27096@@ -96,8 +96,7 @@ relocate_kernel:
27097
27098 /* jump to identity mapped page */
27099 addq $(identity_mapped - relocate_kernel), %r8
27100- pushq %r8
27101- ret
27102+ jmp *%r8
27103
27104 identity_mapped:
27105 /* set return address to 0 if not preserving context */
27106diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27107index ce72964..be8aea7 100644
27108--- a/arch/x86/kernel/setup.c
27109+++ b/arch/x86/kernel/setup.c
27110@@ -110,6 +110,7 @@
27111 #include <asm/mce.h>
27112 #include <asm/alternative.h>
27113 #include <asm/prom.h>
27114+#include <asm/boot.h>
27115
27116 /*
27117 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27118@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27119 #endif
27120
27121
27122-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27123-__visible unsigned long mmu_cr4_features;
27124+#ifdef CONFIG_X86_64
27125+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27126+#elif defined(CONFIG_X86_PAE)
27127+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27128 #else
27129-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27130+__visible unsigned long mmu_cr4_features __read_only;
27131 #endif
27132
27133+void set_in_cr4(unsigned long mask)
27134+{
27135+ unsigned long cr4 = read_cr4();
27136+
27137+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27138+ return;
27139+
27140+ pax_open_kernel();
27141+ mmu_cr4_features |= mask;
27142+ pax_close_kernel();
27143+
27144+ if (trampoline_cr4_features)
27145+ *trampoline_cr4_features = mmu_cr4_features;
27146+ cr4 |= mask;
27147+ write_cr4(cr4);
27148+}
27149+EXPORT_SYMBOL(set_in_cr4);
27150+
27151+void clear_in_cr4(unsigned long mask)
27152+{
27153+ unsigned long cr4 = read_cr4();
27154+
27155+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27156+ return;
27157+
27158+ pax_open_kernel();
27159+ mmu_cr4_features &= ~mask;
27160+ pax_close_kernel();
27161+
27162+ if (trampoline_cr4_features)
27163+ *trampoline_cr4_features = mmu_cr4_features;
27164+ cr4 &= ~mask;
27165+ write_cr4(cr4);
27166+}
27167+EXPORT_SYMBOL(clear_in_cr4);
27168+
27169 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27170 int bootloader_type, bootloader_version;
27171
27172@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27173 * area (640->1Mb) as ram even though it is not.
27174 * take them out.
27175 */
27176- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27177+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27178
27179 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27180 }
27181@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27182 /* called before trim_bios_range() to spare extra sanitize */
27183 static void __init e820_add_kernel_range(void)
27184 {
27185- u64 start = __pa_symbol(_text);
27186+ u64 start = __pa_symbol(ktla_ktva(_text));
27187 u64 size = __pa_symbol(_end) - start;
27188
27189 /*
27190@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27191
27192 void __init setup_arch(char **cmdline_p)
27193 {
27194+#ifdef CONFIG_X86_32
27195+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27196+#else
27197 memblock_reserve(__pa_symbol(_text),
27198 (unsigned long)__bss_stop - (unsigned long)_text);
27199+#endif
27200
27201 early_reserve_initrd();
27202
27203@@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
27204
27205 if (!boot_params.hdr.root_flags)
27206 root_mountflags &= ~MS_RDONLY;
27207- init_mm.start_code = (unsigned long) _text;
27208- init_mm.end_code = (unsigned long) _etext;
27209+ init_mm.start_code = ktla_ktva((unsigned long) _text);
27210+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
27211 init_mm.end_data = (unsigned long) _edata;
27212 init_mm.brk = _brk_end;
27213
27214- code_resource.start = __pa_symbol(_text);
27215- code_resource.end = __pa_symbol(_etext)-1;
27216- data_resource.start = __pa_symbol(_etext);
27217+ code_resource.start = __pa_symbol(ktla_ktva(_text));
27218+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27219+ data_resource.start = __pa_symbol(_sdata);
27220 data_resource.end = __pa_symbol(_edata)-1;
27221 bss_resource.start = __pa_symbol(__bss_start);
27222 bss_resource.end = __pa_symbol(__bss_stop)-1;
27223diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27224index 5cdff03..80fa283 100644
27225--- a/arch/x86/kernel/setup_percpu.c
27226+++ b/arch/x86/kernel/setup_percpu.c
27227@@ -21,19 +21,17 @@
27228 #include <asm/cpu.h>
27229 #include <asm/stackprotector.h>
27230
27231-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27232+#ifdef CONFIG_SMP
27233+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27234 EXPORT_PER_CPU_SYMBOL(cpu_number);
27235+#endif
27236
27237-#ifdef CONFIG_X86_64
27238 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27239-#else
27240-#define BOOT_PERCPU_OFFSET 0
27241-#endif
27242
27243 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27244 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27245
27246-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27247+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27248 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27249 };
27250 EXPORT_SYMBOL(__per_cpu_offset);
27251@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27252 {
27253 #ifdef CONFIG_NEED_MULTIPLE_NODES
27254 pg_data_t *last = NULL;
27255- unsigned int cpu;
27256+ int cpu;
27257
27258 for_each_possible_cpu(cpu) {
27259 int node = early_cpu_to_node(cpu);
27260@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27261 {
27262 #ifdef CONFIG_X86_32
27263 struct desc_struct gdt;
27264+ unsigned long base = per_cpu_offset(cpu);
27265
27266- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27267- 0x2 | DESCTYPE_S, 0x8);
27268- gdt.s = 1;
27269+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27270+ 0x83 | DESCTYPE_S, 0xC);
27271 write_gdt_entry(get_cpu_gdt_table(cpu),
27272 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27273 #endif
27274@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27275 /* alrighty, percpu areas up and running */
27276 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27277 for_each_possible_cpu(cpu) {
27278+#ifdef CONFIG_CC_STACKPROTECTOR
27279+#ifdef CONFIG_X86_32
27280+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
27281+#endif
27282+#endif
27283 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27284 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27285 per_cpu(cpu_number, cpu) = cpu;
27286@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27287 */
27288 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27289 #endif
27290+#ifdef CONFIG_CC_STACKPROTECTOR
27291+#ifdef CONFIG_X86_32
27292+ if (!cpu)
27293+ per_cpu(stack_canary.canary, cpu) = canary;
27294+#endif
27295+#endif
27296 /*
27297 * Up to this point, the boot CPU has been using .init.data
27298 * area. Reload any changed state for the boot CPU.
27299diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27300index 9e5de68..16c53cb 100644
27301--- a/arch/x86/kernel/signal.c
27302+++ b/arch/x86/kernel/signal.c
27303@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27304 * Align the stack pointer according to the i386 ABI,
27305 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27306 */
27307- sp = ((sp + 4) & -16ul) - 4;
27308+ sp = ((sp - 12) & -16ul) - 4;
27309 #else /* !CONFIG_X86_32 */
27310 sp = round_down(sp, 16) - 8;
27311 #endif
27312@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27313 }
27314
27315 if (current->mm->context.vdso)
27316- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
27317+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
27318 else
27319- restorer = &frame->retcode;
27320+ restorer = (void __user *)&frame->retcode;
27321 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27322 restorer = ksig->ka.sa.sa_restorer;
27323
27324@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27325 * reasons and because gdb uses it as a signature to notice
27326 * signal handler stack frames.
27327 */
27328- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27329+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27330
27331 if (err)
27332 return -EFAULT;
27333@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27334 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27335
27336 /* Set up to return from userspace. */
27337- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27338+ if (current->mm->context.vdso)
27339+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27340+ else
27341+ restorer = (void __user *)&frame->retcode;
27342 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27343 restorer = ksig->ka.sa.sa_restorer;
27344 put_user_ex(restorer, &frame->pretcode);
27345@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27346 * reasons and because gdb uses it as a signature to notice
27347 * signal handler stack frames.
27348 */
27349- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27350+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27351 } put_user_catch(err);
27352
27353 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27354@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27355 {
27356 int usig = signr_convert(ksig->sig);
27357 sigset_t *set = sigmask_to_save();
27358- compat_sigset_t *cset = (compat_sigset_t *) set;
27359+ sigset_t sigcopy;
27360+ compat_sigset_t *cset;
27361+
27362+ sigcopy = *set;
27363+
27364+ cset = (compat_sigset_t *) &sigcopy;
27365
27366 /* Set up the stack frame */
27367 if (is_ia32_frame()) {
27368@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27369 } else if (is_x32_frame()) {
27370 return x32_setup_rt_frame(ksig, cset, regs);
27371 } else {
27372- return __setup_rt_frame(ksig->sig, ksig, set, regs);
27373+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27374 }
27375 }
27376
27377diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27378index 7c3a5a6..f0a8961 100644
27379--- a/arch/x86/kernel/smp.c
27380+++ b/arch/x86/kernel/smp.c
27381@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27382
27383 __setup("nonmi_ipi", nonmi_ipi_setup);
27384
27385-struct smp_ops smp_ops = {
27386+struct smp_ops smp_ops __read_only = {
27387 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27388 .smp_prepare_cpus = native_smp_prepare_cpus,
27389 .smp_cpus_done = native_smp_cpus_done,
27390diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27391index a32da80..041a4ff 100644
27392--- a/arch/x86/kernel/smpboot.c
27393+++ b/arch/x86/kernel/smpboot.c
27394@@ -229,14 +229,17 @@ static void notrace start_secondary(void *unused)
27395
27396 enable_start_cpu0 = 0;
27397
27398-#ifdef CONFIG_X86_32
27399+ /* otherwise gcc will move up smp_processor_id before the cpu_init */
27400+ barrier();
27401+
27402 /* switch away from the initial page table */
27403+#ifdef CONFIG_PAX_PER_CPU_PGD
27404+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27405+#else
27406 load_cr3(swapper_pg_dir);
27407+#endif
27408 __flush_tlb_all();
27409-#endif
27410
27411- /* otherwise gcc will move up smp_processor_id before the cpu_init */
27412- barrier();
27413 /*
27414 * Check TSC synchronization with the BP:
27415 */
27416@@ -749,8 +752,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27417 alternatives_enable_smp();
27418
27419 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27420- (THREAD_SIZE + task_stack_page(idle))) - 1);
27421+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27422 per_cpu(current_task, cpu) = idle;
27423+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27424
27425 #ifdef CONFIG_X86_32
27426 /* Stack for startup_32 can be just as for start_secondary onwards */
27427@@ -758,11 +762,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27428 #else
27429 clear_tsk_thread_flag(idle, TIF_FORK);
27430 initial_gs = per_cpu_offset(cpu);
27431- per_cpu(kernel_stack, cpu) =
27432- (unsigned long)task_stack_page(idle) -
27433- KERNEL_STACK_OFFSET + THREAD_SIZE;
27434+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27435 #endif
27436+
27437+ pax_open_kernel();
27438 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27439+ pax_close_kernel();
27440+
27441 initial_code = (unsigned long)start_secondary;
27442 stack_start = idle->thread.sp;
27443
27444@@ -911,6 +917,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27445 /* the FPU context is blank, nobody can own it */
27446 __cpu_disable_lazy_restore(cpu);
27447
27448+#ifdef CONFIG_PAX_PER_CPU_PGD
27449+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27450+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27451+ KERNEL_PGD_PTRS);
27452+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27453+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27454+ KERNEL_PGD_PTRS);
27455+#endif
27456+
27457 err = do_boot_cpu(apicid, cpu, tidle);
27458 if (err) {
27459 pr_debug("do_boot_cpu failed %d\n", err);
27460diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27461index 9b4d51d..5d28b58 100644
27462--- a/arch/x86/kernel/step.c
27463+++ b/arch/x86/kernel/step.c
27464@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27465 struct desc_struct *desc;
27466 unsigned long base;
27467
27468- seg &= ~7UL;
27469+ seg >>= 3;
27470
27471 mutex_lock(&child->mm->context.lock);
27472- if (unlikely((seg >> 3) >= child->mm->context.size))
27473+ if (unlikely(seg >= child->mm->context.size))
27474 addr = -1L; /* bogus selector, access would fault */
27475 else {
27476 desc = child->mm->context.ldt + seg;
27477@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27478 addr += base;
27479 }
27480 mutex_unlock(&child->mm->context.lock);
27481- }
27482+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27483+ addr = ktla_ktva(addr);
27484
27485 return addr;
27486 }
27487@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27488 unsigned char opcode[15];
27489 unsigned long addr = convert_ip_to_linear(child, regs);
27490
27491+ if (addr == -EINVAL)
27492+ return 0;
27493+
27494 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27495 for (i = 0; i < copied; i++) {
27496 switch (opcode[i]) {
27497diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27498new file mode 100644
27499index 0000000..5877189
27500--- /dev/null
27501+++ b/arch/x86/kernel/sys_i386_32.c
27502@@ -0,0 +1,189 @@
27503+/*
27504+ * This file contains various random system calls that
27505+ * have a non-standard calling sequence on the Linux/i386
27506+ * platform.
27507+ */
27508+
27509+#include <linux/errno.h>
27510+#include <linux/sched.h>
27511+#include <linux/mm.h>
27512+#include <linux/fs.h>
27513+#include <linux/smp.h>
27514+#include <linux/sem.h>
27515+#include <linux/msg.h>
27516+#include <linux/shm.h>
27517+#include <linux/stat.h>
27518+#include <linux/syscalls.h>
27519+#include <linux/mman.h>
27520+#include <linux/file.h>
27521+#include <linux/utsname.h>
27522+#include <linux/ipc.h>
27523+#include <linux/elf.h>
27524+
27525+#include <linux/uaccess.h>
27526+#include <linux/unistd.h>
27527+
27528+#include <asm/syscalls.h>
27529+
27530+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27531+{
27532+ unsigned long pax_task_size = TASK_SIZE;
27533+
27534+#ifdef CONFIG_PAX_SEGMEXEC
27535+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27536+ pax_task_size = SEGMEXEC_TASK_SIZE;
27537+#endif
27538+
27539+ if (flags & MAP_FIXED)
27540+ if (len > pax_task_size || addr > pax_task_size - len)
27541+ return -EINVAL;
27542+
27543+ return 0;
27544+}
27545+
27546+/*
27547+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27548+ */
27549+static unsigned long get_align_mask(void)
27550+{
27551+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27552+ return 0;
27553+
27554+ if (!(current->flags & PF_RANDOMIZE))
27555+ return 0;
27556+
27557+ return va_align.mask;
27558+}
27559+
27560+unsigned long
27561+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27562+ unsigned long len, unsigned long pgoff, unsigned long flags)
27563+{
27564+ struct mm_struct *mm = current->mm;
27565+ struct vm_area_struct *vma;
27566+ unsigned long pax_task_size = TASK_SIZE;
27567+ struct vm_unmapped_area_info info;
27568+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27569+
27570+#ifdef CONFIG_PAX_SEGMEXEC
27571+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27572+ pax_task_size = SEGMEXEC_TASK_SIZE;
27573+#endif
27574+
27575+ pax_task_size -= PAGE_SIZE;
27576+
27577+ if (len > pax_task_size)
27578+ return -ENOMEM;
27579+
27580+ if (flags & MAP_FIXED)
27581+ return addr;
27582+
27583+#ifdef CONFIG_PAX_RANDMMAP
27584+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27585+#endif
27586+
27587+ if (addr) {
27588+ addr = PAGE_ALIGN(addr);
27589+ if (pax_task_size - len >= addr) {
27590+ vma = find_vma(mm, addr);
27591+ if (check_heap_stack_gap(vma, addr, len, offset))
27592+ return addr;
27593+ }
27594+ }
27595+
27596+ info.flags = 0;
27597+ info.length = len;
27598+ info.align_mask = filp ? get_align_mask() : 0;
27599+ info.align_offset = pgoff << PAGE_SHIFT;
27600+ info.threadstack_offset = offset;
27601+
27602+#ifdef CONFIG_PAX_PAGEEXEC
27603+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27604+ info.low_limit = 0x00110000UL;
27605+ info.high_limit = mm->start_code;
27606+
27607+#ifdef CONFIG_PAX_RANDMMAP
27608+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27609+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27610+#endif
27611+
27612+ if (info.low_limit < info.high_limit) {
27613+ addr = vm_unmapped_area(&info);
27614+ if (!IS_ERR_VALUE(addr))
27615+ return addr;
27616+ }
27617+ } else
27618+#endif
27619+
27620+ info.low_limit = mm->mmap_base;
27621+ info.high_limit = pax_task_size;
27622+
27623+ return vm_unmapped_area(&info);
27624+}
27625+
27626+unsigned long
27627+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27628+ const unsigned long len, const unsigned long pgoff,
27629+ const unsigned long flags)
27630+{
27631+ struct vm_area_struct *vma;
27632+ struct mm_struct *mm = current->mm;
27633+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27634+ struct vm_unmapped_area_info info;
27635+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27636+
27637+#ifdef CONFIG_PAX_SEGMEXEC
27638+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27639+ pax_task_size = SEGMEXEC_TASK_SIZE;
27640+#endif
27641+
27642+ pax_task_size -= PAGE_SIZE;
27643+
27644+ /* requested length too big for entire address space */
27645+ if (len > pax_task_size)
27646+ return -ENOMEM;
27647+
27648+ if (flags & MAP_FIXED)
27649+ return addr;
27650+
27651+#ifdef CONFIG_PAX_PAGEEXEC
27652+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27653+ goto bottomup;
27654+#endif
27655+
27656+#ifdef CONFIG_PAX_RANDMMAP
27657+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27658+#endif
27659+
27660+ /* requesting a specific address */
27661+ if (addr) {
27662+ addr = PAGE_ALIGN(addr);
27663+ if (pax_task_size - len >= addr) {
27664+ vma = find_vma(mm, addr);
27665+ if (check_heap_stack_gap(vma, addr, len, offset))
27666+ return addr;
27667+ }
27668+ }
27669+
27670+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27671+ info.length = len;
27672+ info.low_limit = PAGE_SIZE;
27673+ info.high_limit = mm->mmap_base;
27674+ info.align_mask = filp ? get_align_mask() : 0;
27675+ info.align_offset = pgoff << PAGE_SHIFT;
27676+ info.threadstack_offset = offset;
27677+
27678+ addr = vm_unmapped_area(&info);
27679+ if (!(addr & ~PAGE_MASK))
27680+ return addr;
27681+ VM_BUG_ON(addr != -ENOMEM);
27682+
27683+bottomup:
27684+ /*
27685+ * A failed mmap() very likely causes application failure,
27686+ * so fall back to the bottom-up function here. This scenario
27687+ * can happen with large stack limits and large mmap()
27688+ * allocations.
27689+ */
27690+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27691+}
27692diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27693index 30277e2..5664a29 100644
27694--- a/arch/x86/kernel/sys_x86_64.c
27695+++ b/arch/x86/kernel/sys_x86_64.c
27696@@ -81,8 +81,8 @@ out:
27697 return error;
27698 }
27699
27700-static void find_start_end(unsigned long flags, unsigned long *begin,
27701- unsigned long *end)
27702+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27703+ unsigned long *begin, unsigned long *end)
27704 {
27705 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27706 unsigned long new_begin;
27707@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27708 *begin = new_begin;
27709 }
27710 } else {
27711- *begin = current->mm->mmap_legacy_base;
27712+ *begin = mm->mmap_legacy_base;
27713 *end = TASK_SIZE;
27714 }
27715 }
27716@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27717 struct vm_area_struct *vma;
27718 struct vm_unmapped_area_info info;
27719 unsigned long begin, end;
27720+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27721
27722 if (flags & MAP_FIXED)
27723 return addr;
27724
27725- find_start_end(flags, &begin, &end);
27726+ find_start_end(mm, flags, &begin, &end);
27727
27728 if (len > end)
27729 return -ENOMEM;
27730
27731+#ifdef CONFIG_PAX_RANDMMAP
27732+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27733+#endif
27734+
27735 if (addr) {
27736 addr = PAGE_ALIGN(addr);
27737 vma = find_vma(mm, addr);
27738- if (end - len >= addr &&
27739- (!vma || addr + len <= vma->vm_start))
27740+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27741 return addr;
27742 }
27743
27744@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27745 info.high_limit = end;
27746 info.align_mask = filp ? get_align_mask() : 0;
27747 info.align_offset = pgoff << PAGE_SHIFT;
27748+ info.threadstack_offset = offset;
27749 return vm_unmapped_area(&info);
27750 }
27751
27752@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27753 struct mm_struct *mm = current->mm;
27754 unsigned long addr = addr0;
27755 struct vm_unmapped_area_info info;
27756+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27757
27758 /* requested length too big for entire address space */
27759 if (len > TASK_SIZE)
27760@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27761 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27762 goto bottomup;
27763
27764+#ifdef CONFIG_PAX_RANDMMAP
27765+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27766+#endif
27767+
27768 /* requesting a specific address */
27769 if (addr) {
27770 addr = PAGE_ALIGN(addr);
27771 vma = find_vma(mm, addr);
27772- if (TASK_SIZE - len >= addr &&
27773- (!vma || addr + len <= vma->vm_start))
27774+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27775 return addr;
27776 }
27777
27778@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27779 info.high_limit = mm->mmap_base;
27780 info.align_mask = filp ? get_align_mask() : 0;
27781 info.align_offset = pgoff << PAGE_SHIFT;
27782+ info.threadstack_offset = offset;
27783 addr = vm_unmapped_area(&info);
27784 if (!(addr & ~PAGE_MASK))
27785 return addr;
27786diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27787index 91a4496..bb87552 100644
27788--- a/arch/x86/kernel/tboot.c
27789+++ b/arch/x86/kernel/tboot.c
27790@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27791
27792 void tboot_shutdown(u32 shutdown_type)
27793 {
27794- void (*shutdown)(void);
27795+ void (* __noreturn shutdown)(void);
27796
27797 if (!tboot_enabled())
27798 return;
27799@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27800
27801 switch_to_tboot_pt();
27802
27803- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27804+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27805 shutdown();
27806
27807 /* should not reach here */
27808@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27809 return -ENODEV;
27810 }
27811
27812-static atomic_t ap_wfs_count;
27813+static atomic_unchecked_t ap_wfs_count;
27814
27815 static int tboot_wait_for_aps(int num_aps)
27816 {
27817@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27818 {
27819 switch (action) {
27820 case CPU_DYING:
27821- atomic_inc(&ap_wfs_count);
27822+ atomic_inc_unchecked(&ap_wfs_count);
27823 if (num_online_cpus() == 1)
27824- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27825+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27826 return NOTIFY_BAD;
27827 break;
27828 }
27829@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27830
27831 tboot_create_trampoline();
27832
27833- atomic_set(&ap_wfs_count, 0);
27834+ atomic_set_unchecked(&ap_wfs_count, 0);
27835 register_hotcpu_notifier(&tboot_cpu_notifier);
27836
27837 #ifdef CONFIG_DEBUG_FS
27838diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27839index 24d3c91..d06b473 100644
27840--- a/arch/x86/kernel/time.c
27841+++ b/arch/x86/kernel/time.c
27842@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27843 {
27844 unsigned long pc = instruction_pointer(regs);
27845
27846- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27847+ if (!user_mode(regs) && in_lock_functions(pc)) {
27848 #ifdef CONFIG_FRAME_POINTER
27849- return *(unsigned long *)(regs->bp + sizeof(long));
27850+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27851 #else
27852 unsigned long *sp =
27853 (unsigned long *)kernel_stack_pointer(regs);
27854@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27855 * or above a saved flags. Eflags has bits 22-31 zero,
27856 * kernel addresses don't.
27857 */
27858+
27859+#ifdef CONFIG_PAX_KERNEXEC
27860+ return ktla_ktva(sp[0]);
27861+#else
27862 if (sp[0] >> 22)
27863 return sp[0];
27864 if (sp[1] >> 22)
27865 return sp[1];
27866 #endif
27867+
27868+#endif
27869 }
27870 return pc;
27871 }
27872diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27873index f7fec09..9991981 100644
27874--- a/arch/x86/kernel/tls.c
27875+++ b/arch/x86/kernel/tls.c
27876@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27877 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27878 return -EINVAL;
27879
27880+#ifdef CONFIG_PAX_SEGMEXEC
27881+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27882+ return -EINVAL;
27883+#endif
27884+
27885 set_tls_desc(p, idx, &info, 1);
27886
27887 return 0;
27888@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27889
27890 if (kbuf)
27891 info = kbuf;
27892- else if (__copy_from_user(infobuf, ubuf, count))
27893+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27894 return -EFAULT;
27895 else
27896 info = infobuf;
27897diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27898index 1c113db..287b42e 100644
27899--- a/arch/x86/kernel/tracepoint.c
27900+++ b/arch/x86/kernel/tracepoint.c
27901@@ -9,11 +9,11 @@
27902 #include <linux/atomic.h>
27903
27904 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27905-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27906+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27907 (unsigned long) trace_idt_table };
27908
27909 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27910-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27911+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27912
27913 static int trace_irq_vector_refcount;
27914 static DEFINE_MUTEX(irq_vector_mutex);
27915diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27916index 57409f6..b505597 100644
27917--- a/arch/x86/kernel/traps.c
27918+++ b/arch/x86/kernel/traps.c
27919@@ -66,7 +66,7 @@
27920 #include <asm/proto.h>
27921
27922 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27923-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27924+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27925 #else
27926 #include <asm/processor-flags.h>
27927 #include <asm/setup.h>
27928@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27929 #endif
27930
27931 /* Must be page-aligned because the real IDT is used in a fixmap. */
27932-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27933+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27934
27935 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27936 EXPORT_SYMBOL_GPL(used_vectors);
27937@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27938 }
27939
27940 static int __kprobes
27941-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27942+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27943 struct pt_regs *regs, long error_code)
27944 {
27945 #ifdef CONFIG_X86_32
27946- if (regs->flags & X86_VM_MASK) {
27947+ if (v8086_mode(regs)) {
27948 /*
27949 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27950 * On nmi (interrupt 2), do_trap should not be called.
27951@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27952 return -1;
27953 }
27954 #endif
27955- if (!user_mode(regs)) {
27956+ if (!user_mode_novm(regs)) {
27957 if (!fixup_exception(regs)) {
27958 tsk->thread.error_code = error_code;
27959 tsk->thread.trap_nr = trapnr;
27960+
27961+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27962+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27963+ str = "PAX: suspicious stack segment fault";
27964+#endif
27965+
27966 die(str, regs, error_code);
27967 }
27968+
27969+#ifdef CONFIG_PAX_REFCOUNT
27970+ if (trapnr == X86_TRAP_OF)
27971+ pax_report_refcount_overflow(regs);
27972+#endif
27973+
27974 return 0;
27975 }
27976
27977@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27978 }
27979
27980 static void __kprobes
27981-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27982+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27983 long error_code, siginfo_t *info)
27984 {
27985 struct task_struct *tsk = current;
27986@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27987 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27988 printk_ratelimit()) {
27989 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27990- tsk->comm, tsk->pid, str,
27991+ tsk->comm, task_pid_nr(tsk), str,
27992 regs->ip, regs->sp, error_code);
27993 print_vma_addr(" in ", regs->ip);
27994 pr_cont("\n");
27995@@ -251,6 +263,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27996 tsk->thread.error_code = error_code;
27997 tsk->thread.trap_nr = X86_TRAP_DF;
27998
27999+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28000+ if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28001+ die("grsec: kernel stack overflow detected", regs, error_code);
28002+#endif
28003+
28004 #ifdef CONFIG_DOUBLEFAULT
28005 df_debug(regs, error_code);
28006 #endif
28007@@ -273,7 +290,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28008 conditional_sti(regs);
28009
28010 #ifdef CONFIG_X86_32
28011- if (regs->flags & X86_VM_MASK) {
28012+ if (v8086_mode(regs)) {
28013 local_irq_enable();
28014 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28015 goto exit;
28016@@ -281,18 +298,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28017 #endif
28018
28019 tsk = current;
28020- if (!user_mode(regs)) {
28021+ if (!user_mode_novm(regs)) {
28022 if (fixup_exception(regs))
28023 goto exit;
28024
28025 tsk->thread.error_code = error_code;
28026 tsk->thread.trap_nr = X86_TRAP_GP;
28027 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28028- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28029+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28030+
28031+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28032+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28033+ die("PAX: suspicious general protection fault", regs, error_code);
28034+ else
28035+#endif
28036+
28037 die("general protection fault", regs, error_code);
28038+ }
28039 goto exit;
28040 }
28041
28042+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28043+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28044+ struct mm_struct *mm = tsk->mm;
28045+ unsigned long limit;
28046+
28047+ down_write(&mm->mmap_sem);
28048+ limit = mm->context.user_cs_limit;
28049+ if (limit < TASK_SIZE) {
28050+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28051+ up_write(&mm->mmap_sem);
28052+ return;
28053+ }
28054+ up_write(&mm->mmap_sem);
28055+ }
28056+#endif
28057+
28058 tsk->thread.error_code = error_code;
28059 tsk->thread.trap_nr = X86_TRAP_GP;
28060
28061@@ -453,7 +494,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
28062 /* It's safe to allow irq's after DR6 has been saved */
28063 preempt_conditional_sti(regs);
28064
28065- if (regs->flags & X86_VM_MASK) {
28066+ if (v8086_mode(regs)) {
28067 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28068 X86_TRAP_DB);
28069 preempt_conditional_cli(regs);
28070@@ -468,7 +509,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
28071 * We already checked v86 mode above, so we can check for kernel mode
28072 * by just checking the CPL of CS.
28073 */
28074- if ((dr6 & DR_STEP) && !user_mode(regs)) {
28075+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28076 tsk->thread.debugreg6 &= ~DR_STEP;
28077 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28078 regs->flags &= ~X86_EFLAGS_TF;
28079@@ -500,7 +541,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
28080 return;
28081 conditional_sti(regs);
28082
28083- if (!user_mode_vm(regs))
28084+ if (!user_mode(regs))
28085 {
28086 if (!fixup_exception(regs)) {
28087 task->thread.error_code = error_code;
28088diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28089index cfbe99f..a6e8fa7 100644
28090--- a/arch/x86/kernel/tsc.c
28091+++ b/arch/x86/kernel/tsc.c
28092@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28093 */
28094 smp_wmb();
28095
28096- ACCESS_ONCE(c2n->head) = data;
28097+ ACCESS_ONCE_RW(c2n->head) = data;
28098 }
28099
28100 /*
28101diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28102index 2ed8459..7cf329f 100644
28103--- a/arch/x86/kernel/uprobes.c
28104+++ b/arch/x86/kernel/uprobes.c
28105@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28106 int ret = NOTIFY_DONE;
28107
28108 /* We are only interested in userspace traps */
28109- if (regs && !user_mode_vm(regs))
28110+ if (regs && !user_mode(regs))
28111 return NOTIFY_DONE;
28112
28113 switch (val) {
28114@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28115
28116 if (ncopied != rasize) {
28117 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28118- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28119+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28120
28121 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28122 }
28123diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28124index b9242ba..50c5edd 100644
28125--- a/arch/x86/kernel/verify_cpu.S
28126+++ b/arch/x86/kernel/verify_cpu.S
28127@@ -20,6 +20,7 @@
28128 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28129 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28130 * arch/x86/kernel/head_32.S: processor startup
28131+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28132 *
28133 * verify_cpu, returns the status of longmode and SSE in register %eax.
28134 * 0: Success 1: Failure
28135diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28136index e8edcf5..27f9344 100644
28137--- a/arch/x86/kernel/vm86_32.c
28138+++ b/arch/x86/kernel/vm86_32.c
28139@@ -44,6 +44,7 @@
28140 #include <linux/ptrace.h>
28141 #include <linux/audit.h>
28142 #include <linux/stddef.h>
28143+#include <linux/grsecurity.h>
28144
28145 #include <asm/uaccess.h>
28146 #include <asm/io.h>
28147@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28148 do_exit(SIGSEGV);
28149 }
28150
28151- tss = &per_cpu(init_tss, get_cpu());
28152+ tss = init_tss + get_cpu();
28153 current->thread.sp0 = current->thread.saved_sp0;
28154 current->thread.sysenter_cs = __KERNEL_CS;
28155 load_sp0(tss, &current->thread);
28156@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28157
28158 if (tsk->thread.saved_sp0)
28159 return -EPERM;
28160+
28161+#ifdef CONFIG_GRKERNSEC_VM86
28162+ if (!capable(CAP_SYS_RAWIO)) {
28163+ gr_handle_vm86();
28164+ return -EPERM;
28165+ }
28166+#endif
28167+
28168 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28169 offsetof(struct kernel_vm86_struct, vm86plus) -
28170 sizeof(info.regs));
28171@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28172 int tmp;
28173 struct vm86plus_struct __user *v86;
28174
28175+#ifdef CONFIG_GRKERNSEC_VM86
28176+ if (!capable(CAP_SYS_RAWIO)) {
28177+ gr_handle_vm86();
28178+ return -EPERM;
28179+ }
28180+#endif
28181+
28182 tsk = current;
28183 switch (cmd) {
28184 case VM86_REQUEST_IRQ:
28185@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28186 tsk->thread.saved_fs = info->regs32->fs;
28187 tsk->thread.saved_gs = get_user_gs(info->regs32);
28188
28189- tss = &per_cpu(init_tss, get_cpu());
28190+ tss = init_tss + get_cpu();
28191 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28192 if (cpu_has_sep)
28193 tsk->thread.sysenter_cs = 0;
28194@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28195 goto cannot_handle;
28196 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28197 goto cannot_handle;
28198- intr_ptr = (unsigned long __user *) (i << 2);
28199+ intr_ptr = (__force unsigned long __user *) (i << 2);
28200 if (get_user(segoffs, intr_ptr))
28201 goto cannot_handle;
28202 if ((segoffs >> 16) == BIOSSEG)
28203diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28204index da6b35a..977e9cf 100644
28205--- a/arch/x86/kernel/vmlinux.lds.S
28206+++ b/arch/x86/kernel/vmlinux.lds.S
28207@@ -26,6 +26,13 @@
28208 #include <asm/page_types.h>
28209 #include <asm/cache.h>
28210 #include <asm/boot.h>
28211+#include <asm/segment.h>
28212+
28213+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28214+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28215+#else
28216+#define __KERNEL_TEXT_OFFSET 0
28217+#endif
28218
28219 #undef i386 /* in case the preprocessor is a 32bit one */
28220
28221@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28222
28223 PHDRS {
28224 text PT_LOAD FLAGS(5); /* R_E */
28225+#ifdef CONFIG_X86_32
28226+ module PT_LOAD FLAGS(5); /* R_E */
28227+#endif
28228+#ifdef CONFIG_XEN
28229+ rodata PT_LOAD FLAGS(5); /* R_E */
28230+#else
28231+ rodata PT_LOAD FLAGS(4); /* R__ */
28232+#endif
28233 data PT_LOAD FLAGS(6); /* RW_ */
28234-#ifdef CONFIG_X86_64
28235+ init.begin PT_LOAD FLAGS(6); /* RW_ */
28236 #ifdef CONFIG_SMP
28237 percpu PT_LOAD FLAGS(6); /* RW_ */
28238 #endif
28239+ text.init PT_LOAD FLAGS(5); /* R_E */
28240+ text.exit PT_LOAD FLAGS(5); /* R_E */
28241 init PT_LOAD FLAGS(7); /* RWE */
28242-#endif
28243 note PT_NOTE FLAGS(0); /* ___ */
28244 }
28245
28246 SECTIONS
28247 {
28248 #ifdef CONFIG_X86_32
28249- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28250- phys_startup_32 = startup_32 - LOAD_OFFSET;
28251+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28252 #else
28253- . = __START_KERNEL;
28254- phys_startup_64 = startup_64 - LOAD_OFFSET;
28255+ . = __START_KERNEL;
28256 #endif
28257
28258 /* Text and read-only data */
28259- .text : AT(ADDR(.text) - LOAD_OFFSET) {
28260- _text = .;
28261+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28262 /* bootstrapping code */
28263+#ifdef CONFIG_X86_32
28264+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28265+#else
28266+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28267+#endif
28268+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28269+ _text = .;
28270 HEAD_TEXT
28271 . = ALIGN(8);
28272 _stext = .;
28273@@ -104,13 +124,47 @@ SECTIONS
28274 IRQENTRY_TEXT
28275 *(.fixup)
28276 *(.gnu.warning)
28277- /* End of text section */
28278- _etext = .;
28279 } :text = 0x9090
28280
28281- NOTES :text :note
28282+ . += __KERNEL_TEXT_OFFSET;
28283
28284- EXCEPTION_TABLE(16) :text = 0x9090
28285+#ifdef CONFIG_X86_32
28286+ . = ALIGN(PAGE_SIZE);
28287+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28288+
28289+#ifdef CONFIG_PAX_KERNEXEC
28290+ MODULES_EXEC_VADDR = .;
28291+ BYTE(0)
28292+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28293+ . = ALIGN(HPAGE_SIZE) - 1;
28294+ MODULES_EXEC_END = .;
28295+#endif
28296+
28297+ } :module
28298+#endif
28299+
28300+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28301+ /* End of text section */
28302+ BYTE(0)
28303+ _etext = . - __KERNEL_TEXT_OFFSET;
28304+ }
28305+
28306+#ifdef CONFIG_X86_32
28307+ . = ALIGN(PAGE_SIZE);
28308+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28309+ . = ALIGN(PAGE_SIZE);
28310+ *(.empty_zero_page)
28311+ *(.initial_pg_fixmap)
28312+ *(.initial_pg_pmd)
28313+ *(.initial_page_table)
28314+ *(.swapper_pg_dir)
28315+ } :rodata
28316+#endif
28317+
28318+ . = ALIGN(PAGE_SIZE);
28319+ NOTES :rodata :note
28320+
28321+ EXCEPTION_TABLE(16) :rodata
28322
28323 #if defined(CONFIG_DEBUG_RODATA)
28324 /* .text should occupy whole number of pages */
28325@@ -122,16 +176,20 @@ SECTIONS
28326
28327 /* Data */
28328 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28329+
28330+#ifdef CONFIG_PAX_KERNEXEC
28331+ . = ALIGN(HPAGE_SIZE);
28332+#else
28333+ . = ALIGN(PAGE_SIZE);
28334+#endif
28335+
28336 /* Start of data section */
28337 _sdata = .;
28338
28339 /* init_task */
28340 INIT_TASK_DATA(THREAD_SIZE)
28341
28342-#ifdef CONFIG_X86_32
28343- /* 32 bit has nosave before _edata */
28344 NOSAVE_DATA
28345-#endif
28346
28347 PAGE_ALIGNED_DATA(PAGE_SIZE)
28348
28349@@ -172,12 +230,19 @@ SECTIONS
28350 #endif /* CONFIG_X86_64 */
28351
28352 /* Init code and data - will be freed after init */
28353- . = ALIGN(PAGE_SIZE);
28354 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28355+ BYTE(0)
28356+
28357+#ifdef CONFIG_PAX_KERNEXEC
28358+ . = ALIGN(HPAGE_SIZE);
28359+#else
28360+ . = ALIGN(PAGE_SIZE);
28361+#endif
28362+
28363 __init_begin = .; /* paired with __init_end */
28364- }
28365+ } :init.begin
28366
28367-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28368+#ifdef CONFIG_SMP
28369 /*
28370 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28371 * output PHDR, so the next output section - .init.text - should
28372@@ -186,12 +251,27 @@ SECTIONS
28373 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28374 #endif
28375
28376- INIT_TEXT_SECTION(PAGE_SIZE)
28377-#ifdef CONFIG_X86_64
28378- :init
28379-#endif
28380+ . = ALIGN(PAGE_SIZE);
28381+ init_begin = .;
28382+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28383+ VMLINUX_SYMBOL(_sinittext) = .;
28384+ INIT_TEXT
28385+ VMLINUX_SYMBOL(_einittext) = .;
28386+ . = ALIGN(PAGE_SIZE);
28387+ } :text.init
28388
28389- INIT_DATA_SECTION(16)
28390+ /*
28391+ * .exit.text is discard at runtime, not link time, to deal with
28392+ * references from .altinstructions and .eh_frame
28393+ */
28394+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28395+ EXIT_TEXT
28396+ . = ALIGN(16);
28397+ } :text.exit
28398+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28399+
28400+ . = ALIGN(PAGE_SIZE);
28401+ INIT_DATA_SECTION(16) :init
28402
28403 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28404 __x86_cpu_dev_start = .;
28405@@ -262,19 +342,12 @@ SECTIONS
28406 }
28407
28408 . = ALIGN(8);
28409- /*
28410- * .exit.text is discard at runtime, not link time, to deal with
28411- * references from .altinstructions and .eh_frame
28412- */
28413- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28414- EXIT_TEXT
28415- }
28416
28417 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28418 EXIT_DATA
28419 }
28420
28421-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28422+#ifndef CONFIG_SMP
28423 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28424 #endif
28425
28426@@ -293,16 +366,10 @@ SECTIONS
28427 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28428 __smp_locks = .;
28429 *(.smp_locks)
28430- . = ALIGN(PAGE_SIZE);
28431 __smp_locks_end = .;
28432+ . = ALIGN(PAGE_SIZE);
28433 }
28434
28435-#ifdef CONFIG_X86_64
28436- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28437- NOSAVE_DATA
28438- }
28439-#endif
28440-
28441 /* BSS */
28442 . = ALIGN(PAGE_SIZE);
28443 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28444@@ -318,6 +385,7 @@ SECTIONS
28445 __brk_base = .;
28446 . += 64 * 1024; /* 64k alignment slop space */
28447 *(.brk_reservation) /* areas brk users have reserved */
28448+ . = ALIGN(HPAGE_SIZE);
28449 __brk_limit = .;
28450 }
28451
28452@@ -344,13 +412,12 @@ SECTIONS
28453 * for the boot processor.
28454 */
28455 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28456-INIT_PER_CPU(gdt_page);
28457 INIT_PER_CPU(irq_stack_union);
28458
28459 /*
28460 * Build-time check on the image size:
28461 */
28462-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28463+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28464 "kernel image bigger than KERNEL_IMAGE_SIZE");
28465
28466 #ifdef CONFIG_SMP
28467diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28468index 1f96f93..6f29be7 100644
28469--- a/arch/x86/kernel/vsyscall_64.c
28470+++ b/arch/x86/kernel/vsyscall_64.c
28471@@ -56,15 +56,13 @@
28472 DEFINE_VVAR(int, vgetcpu_mode);
28473 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
28474
28475-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28476+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28477
28478 static int __init vsyscall_setup(char *str)
28479 {
28480 if (str) {
28481 if (!strcmp("emulate", str))
28482 vsyscall_mode = EMULATE;
28483- else if (!strcmp("native", str))
28484- vsyscall_mode = NATIVE;
28485 else if (!strcmp("none", str))
28486 vsyscall_mode = NONE;
28487 else
28488@@ -101,7 +99,7 @@ void update_vsyscall(struct timekeeper *tk)
28489 vdata->monotonic_time_sec = tk->xtime_sec
28490 + tk->wall_to_monotonic.tv_sec;
28491 vdata->monotonic_time_snsec = tk->xtime_nsec
28492- + (tk->wall_to_monotonic.tv_nsec
28493+ + ((u64)tk->wall_to_monotonic.tv_nsec
28494 << tk->shift);
28495 while (vdata->monotonic_time_snsec >=
28496 (((u64)NSEC_PER_SEC) << tk->shift)) {
28497@@ -323,8 +321,7 @@ do_ret:
28498 return true;
28499
28500 sigsegv:
28501- force_sig(SIGSEGV, current);
28502- return true;
28503+ do_group_exit(SIGKILL);
28504 }
28505
28506 /*
28507@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
28508 extern char __vvar_page;
28509 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28510
28511- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28512- vsyscall_mode == NATIVE
28513- ? PAGE_KERNEL_VSYSCALL
28514- : PAGE_KERNEL_VVAR);
28515+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28516 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28517 (unsigned long)VSYSCALL_START);
28518
28519diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28520index 04068192..4d75aa6 100644
28521--- a/arch/x86/kernel/x8664_ksyms_64.c
28522+++ b/arch/x86/kernel/x8664_ksyms_64.c
28523@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28524 EXPORT_SYMBOL(copy_user_generic_unrolled);
28525 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28526 EXPORT_SYMBOL(__copy_user_nocache);
28527-EXPORT_SYMBOL(_copy_from_user);
28528-EXPORT_SYMBOL(_copy_to_user);
28529
28530 EXPORT_SYMBOL(copy_page);
28531 EXPORT_SYMBOL(clear_page);
28532@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28533 EXPORT_SYMBOL(___preempt_schedule_context);
28534 #endif
28535 #endif
28536+
28537+#ifdef CONFIG_PAX_PER_CPU_PGD
28538+EXPORT_SYMBOL(cpu_pgd);
28539+#endif
28540diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28541index e48b674..a451dd9 100644
28542--- a/arch/x86/kernel/x86_init.c
28543+++ b/arch/x86/kernel/x86_init.c
28544@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28545 static void default_nmi_init(void) { };
28546 static int default_i8042_detect(void) { return 1; };
28547
28548-struct x86_platform_ops x86_platform = {
28549+struct x86_platform_ops x86_platform __read_only = {
28550 .calibrate_tsc = native_calibrate_tsc,
28551 .get_wallclock = mach_get_cmos_time,
28552 .set_wallclock = mach_set_rtc_mmss,
28553@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28554 EXPORT_SYMBOL_GPL(x86_platform);
28555
28556 #if defined(CONFIG_PCI_MSI)
28557-struct x86_msi_ops x86_msi = {
28558+struct x86_msi_ops x86_msi __read_only = {
28559 .setup_msi_irqs = native_setup_msi_irqs,
28560 .compose_msi_msg = native_compose_msi_msg,
28561 .teardown_msi_irq = native_teardown_msi_irq,
28562@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28563 }
28564 #endif
28565
28566-struct x86_io_apic_ops x86_io_apic_ops = {
28567+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28568 .init = native_io_apic_init_mappings,
28569 .read = native_io_apic_read,
28570 .write = native_io_apic_write,
28571diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28572index a4b451c..8dfe1ad 100644
28573--- a/arch/x86/kernel/xsave.c
28574+++ b/arch/x86/kernel/xsave.c
28575@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28576
28577 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28578 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28579- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28580+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28581
28582 if (!use_xsave())
28583 return err;
28584
28585- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28586+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28587
28588 /*
28589 * Read the xstate_bv which we copied (directly from the cpu or
28590 * from the state in task struct) to the user buffers.
28591 */
28592- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28593+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28594
28595 /*
28596 * For legacy compatible, we always set FP/SSE bits in the bit
28597@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28598 */
28599 xstate_bv |= XSTATE_FPSSE;
28600
28601- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28602+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28603
28604 return err;
28605 }
28606@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28607 {
28608 int err;
28609
28610+ buf = (struct xsave_struct __user *)____m(buf);
28611 if (use_xsave())
28612 err = xsave_user(buf);
28613 else if (use_fxsr())
28614@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28615 */
28616 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28617 {
28618+ buf = (void __user *)____m(buf);
28619 if (use_xsave()) {
28620 if ((unsigned long)buf % 64 || fx_only) {
28621 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28622diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28623index c697625..a032162 100644
28624--- a/arch/x86/kvm/cpuid.c
28625+++ b/arch/x86/kvm/cpuid.c
28626@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28627 struct kvm_cpuid2 *cpuid,
28628 struct kvm_cpuid_entry2 __user *entries)
28629 {
28630- int r;
28631+ int r, i;
28632
28633 r = -E2BIG;
28634 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28635 goto out;
28636 r = -EFAULT;
28637- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28638- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28639+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28640 goto out;
28641+ for (i = 0; i < cpuid->nent; ++i) {
28642+ struct kvm_cpuid_entry2 cpuid_entry;
28643+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28644+ goto out;
28645+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28646+ }
28647 vcpu->arch.cpuid_nent = cpuid->nent;
28648 kvm_apic_set_version(vcpu);
28649 kvm_x86_ops->cpuid_update(vcpu);
28650@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28651 struct kvm_cpuid2 *cpuid,
28652 struct kvm_cpuid_entry2 __user *entries)
28653 {
28654- int r;
28655+ int r, i;
28656
28657 r = -E2BIG;
28658 if (cpuid->nent < vcpu->arch.cpuid_nent)
28659 goto out;
28660 r = -EFAULT;
28661- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28662- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28663+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28664 goto out;
28665+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28666+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28667+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28668+ goto out;
28669+ }
28670 return 0;
28671
28672 out:
28673diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28674index 9736529..ab4f54c 100644
28675--- a/arch/x86/kvm/lapic.c
28676+++ b/arch/x86/kvm/lapic.c
28677@@ -55,7 +55,7 @@
28678 #define APIC_BUS_CYCLE_NS 1
28679
28680 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28681-#define apic_debug(fmt, arg...)
28682+#define apic_debug(fmt, arg...) do {} while (0)
28683
28684 #define APIC_LVT_NUM 6
28685 /* 14 is the version for Xeon and Pentium 8.4.8*/
28686diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28687index cba218a..1cc1bed 100644
28688--- a/arch/x86/kvm/paging_tmpl.h
28689+++ b/arch/x86/kvm/paging_tmpl.h
28690@@ -331,7 +331,7 @@ retry_walk:
28691 if (unlikely(kvm_is_error_hva(host_addr)))
28692 goto error;
28693
28694- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28695+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28696 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28697 goto error;
28698 walker->ptep_user[walker->level - 1] = ptep_user;
28699diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28700index 2de1bc0..22251ee 100644
28701--- a/arch/x86/kvm/svm.c
28702+++ b/arch/x86/kvm/svm.c
28703@@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28704 int cpu = raw_smp_processor_id();
28705
28706 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28707+
28708+ pax_open_kernel();
28709 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28710+ pax_close_kernel();
28711+
28712 load_TR_desc();
28713 }
28714
28715@@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28716 #endif
28717 #endif
28718
28719+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28720+ __set_fs(current_thread_info()->addr_limit);
28721+#endif
28722+
28723 reload_tss(vcpu);
28724
28725 local_irq_disable();
28726diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28727index 3927528..fc19971 100644
28728--- a/arch/x86/kvm/vmx.c
28729+++ b/arch/x86/kvm/vmx.c
28730@@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28731 #endif
28732 }
28733
28734-static void vmcs_clear_bits(unsigned long field, u32 mask)
28735+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28736 {
28737 vmcs_writel(field, vmcs_readl(field) & ~mask);
28738 }
28739
28740-static void vmcs_set_bits(unsigned long field, u32 mask)
28741+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28742 {
28743 vmcs_writel(field, vmcs_readl(field) | mask);
28744 }
28745@@ -1585,7 +1585,11 @@ static void reload_tss(void)
28746 struct desc_struct *descs;
28747
28748 descs = (void *)gdt->address;
28749+
28750+ pax_open_kernel();
28751 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28752+ pax_close_kernel();
28753+
28754 load_TR_desc();
28755 }
28756
28757@@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28758 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28759 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28760
28761+#ifdef CONFIG_PAX_PER_CPU_PGD
28762+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28763+#endif
28764+
28765 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28766 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28767 vmx->loaded_vmcs->cpu = cpu;
28768@@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28769 * reads and returns guest's timestamp counter "register"
28770 * guest_tsc = host_tsc + tsc_offset -- 21.3
28771 */
28772-static u64 guest_read_tsc(void)
28773+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28774 {
28775 u64 host_tsc, tsc_offset;
28776
28777@@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
28778 if (!cpu_has_vmx_flexpriority())
28779 flexpriority_enabled = 0;
28780
28781- if (!cpu_has_vmx_tpr_shadow())
28782- kvm_x86_ops->update_cr8_intercept = NULL;
28783+ if (!cpu_has_vmx_tpr_shadow()) {
28784+ pax_open_kernel();
28785+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28786+ pax_close_kernel();
28787+ }
28788
28789 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28790 kvm_disable_largepages();
28791@@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
28792 if (!cpu_has_vmx_apicv())
28793 enable_apicv = 0;
28794
28795+ pax_open_kernel();
28796 if (enable_apicv)
28797- kvm_x86_ops->update_cr8_intercept = NULL;
28798+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28799 else {
28800- kvm_x86_ops->hwapic_irr_update = NULL;
28801- kvm_x86_ops->deliver_posted_interrupt = NULL;
28802- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28803+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28804+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28805+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28806 }
28807+ pax_close_kernel();
28808
28809 if (nested)
28810 nested_vmx_setup_ctls_msrs();
28811@@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28812
28813 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28814 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28815+
28816+#ifndef CONFIG_PAX_PER_CPU_PGD
28817 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28818+#endif
28819
28820 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28821 #ifdef CONFIG_X86_64
28822@@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28823 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28824 vmx->host_idt_base = dt.address;
28825
28826- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28827+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28828
28829 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28830 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28831@@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28832 "jmp 2f \n\t"
28833 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28834 "2: "
28835+
28836+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28837+ "ljmp %[cs],$3f\n\t"
28838+ "3: "
28839+#endif
28840+
28841 /* Save guest registers, load host registers, keep flags */
28842 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28843 "pop %0 \n\t"
28844@@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28845 #endif
28846 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28847 [wordsize]"i"(sizeof(ulong))
28848+
28849+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28850+ ,[cs]"i"(__KERNEL_CS)
28851+#endif
28852+
28853 : "cc", "memory"
28854 #ifdef CONFIG_X86_64
28855 , "rax", "rbx", "rdi", "rsi"
28856@@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28857 if (debugctlmsr)
28858 update_debugctlmsr(debugctlmsr);
28859
28860-#ifndef CONFIG_X86_64
28861+#ifdef CONFIG_X86_32
28862 /*
28863 * The sysexit path does not restore ds/es, so we must set them to
28864 * a reasonable value ourselves.
28865@@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28866 * may be executed in interrupt context, which saves and restore segments
28867 * around it, nullifying its effect.
28868 */
28869- loadsegment(ds, __USER_DS);
28870- loadsegment(es, __USER_DS);
28871+ loadsegment(ds, __KERNEL_DS);
28872+ loadsegment(es, __KERNEL_DS);
28873+ loadsegment(ss, __KERNEL_DS);
28874+
28875+#ifdef CONFIG_PAX_KERNEXEC
28876+ loadsegment(fs, __KERNEL_PERCPU);
28877+#endif
28878+
28879+#ifdef CONFIG_PAX_MEMORY_UDEREF
28880+ __set_fs(current_thread_info()->addr_limit);
28881+#endif
28882+
28883 #endif
28884
28885 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28886diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28887index ee0c3b5..773bb94 100644
28888--- a/arch/x86/kvm/x86.c
28889+++ b/arch/x86/kvm/x86.c
28890@@ -1776,8 +1776,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28891 {
28892 struct kvm *kvm = vcpu->kvm;
28893 int lm = is_long_mode(vcpu);
28894- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28895- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28896+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28897+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28898 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28899 : kvm->arch.xen_hvm_config.blob_size_32;
28900 u32 page_num = data & ~PAGE_MASK;
28901@@ -2688,6 +2688,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28902 if (n < msr_list.nmsrs)
28903 goto out;
28904 r = -EFAULT;
28905+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28906+ goto out;
28907 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28908 num_msrs_to_save * sizeof(u32)))
28909 goto out;
28910@@ -5502,7 +5504,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28911 };
28912 #endif
28913
28914-int kvm_arch_init(void *opaque)
28915+int kvm_arch_init(const void *opaque)
28916 {
28917 int r;
28918 struct kvm_x86_ops *ops = opaque;
28919diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28920index ad1fb5f..fe30b66 100644
28921--- a/arch/x86/lguest/boot.c
28922+++ b/arch/x86/lguest/boot.c
28923@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28924 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28925 * Launcher to reboot us.
28926 */
28927-static void lguest_restart(char *reason)
28928+static __noreturn void lguest_restart(char *reason)
28929 {
28930 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28931+ BUG();
28932 }
28933
28934 /*G:050
28935diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28936index 00933d5..3a64af9 100644
28937--- a/arch/x86/lib/atomic64_386_32.S
28938+++ b/arch/x86/lib/atomic64_386_32.S
28939@@ -48,6 +48,10 @@ BEGIN(read)
28940 movl (v), %eax
28941 movl 4(v), %edx
28942 RET_ENDP
28943+BEGIN(read_unchecked)
28944+ movl (v), %eax
28945+ movl 4(v), %edx
28946+RET_ENDP
28947 #undef v
28948
28949 #define v %esi
28950@@ -55,6 +59,10 @@ BEGIN(set)
28951 movl %ebx, (v)
28952 movl %ecx, 4(v)
28953 RET_ENDP
28954+BEGIN(set_unchecked)
28955+ movl %ebx, (v)
28956+ movl %ecx, 4(v)
28957+RET_ENDP
28958 #undef v
28959
28960 #define v %esi
28961@@ -70,6 +78,20 @@ RET_ENDP
28962 BEGIN(add)
28963 addl %eax, (v)
28964 adcl %edx, 4(v)
28965+
28966+#ifdef CONFIG_PAX_REFCOUNT
28967+ jno 0f
28968+ subl %eax, (v)
28969+ sbbl %edx, 4(v)
28970+ int $4
28971+0:
28972+ _ASM_EXTABLE(0b, 0b)
28973+#endif
28974+
28975+RET_ENDP
28976+BEGIN(add_unchecked)
28977+ addl %eax, (v)
28978+ adcl %edx, 4(v)
28979 RET_ENDP
28980 #undef v
28981
28982@@ -77,6 +99,24 @@ RET_ENDP
28983 BEGIN(add_return)
28984 addl (v), %eax
28985 adcl 4(v), %edx
28986+
28987+#ifdef CONFIG_PAX_REFCOUNT
28988+ into
28989+1234:
28990+ _ASM_EXTABLE(1234b, 2f)
28991+#endif
28992+
28993+ movl %eax, (v)
28994+ movl %edx, 4(v)
28995+
28996+#ifdef CONFIG_PAX_REFCOUNT
28997+2:
28998+#endif
28999+
29000+RET_ENDP
29001+BEGIN(add_return_unchecked)
29002+ addl (v), %eax
29003+ adcl 4(v), %edx
29004 movl %eax, (v)
29005 movl %edx, 4(v)
29006 RET_ENDP
29007@@ -86,6 +126,20 @@ RET_ENDP
29008 BEGIN(sub)
29009 subl %eax, (v)
29010 sbbl %edx, 4(v)
29011+
29012+#ifdef CONFIG_PAX_REFCOUNT
29013+ jno 0f
29014+ addl %eax, (v)
29015+ adcl %edx, 4(v)
29016+ int $4
29017+0:
29018+ _ASM_EXTABLE(0b, 0b)
29019+#endif
29020+
29021+RET_ENDP
29022+BEGIN(sub_unchecked)
29023+ subl %eax, (v)
29024+ sbbl %edx, 4(v)
29025 RET_ENDP
29026 #undef v
29027
29028@@ -96,6 +150,27 @@ BEGIN(sub_return)
29029 sbbl $0, %edx
29030 addl (v), %eax
29031 adcl 4(v), %edx
29032+
29033+#ifdef CONFIG_PAX_REFCOUNT
29034+ into
29035+1234:
29036+ _ASM_EXTABLE(1234b, 2f)
29037+#endif
29038+
29039+ movl %eax, (v)
29040+ movl %edx, 4(v)
29041+
29042+#ifdef CONFIG_PAX_REFCOUNT
29043+2:
29044+#endif
29045+
29046+RET_ENDP
29047+BEGIN(sub_return_unchecked)
29048+ negl %edx
29049+ negl %eax
29050+ sbbl $0, %edx
29051+ addl (v), %eax
29052+ adcl 4(v), %edx
29053 movl %eax, (v)
29054 movl %edx, 4(v)
29055 RET_ENDP
29056@@ -105,6 +180,20 @@ RET_ENDP
29057 BEGIN(inc)
29058 addl $1, (v)
29059 adcl $0, 4(v)
29060+
29061+#ifdef CONFIG_PAX_REFCOUNT
29062+ jno 0f
29063+ subl $1, (v)
29064+ sbbl $0, 4(v)
29065+ int $4
29066+0:
29067+ _ASM_EXTABLE(0b, 0b)
29068+#endif
29069+
29070+RET_ENDP
29071+BEGIN(inc_unchecked)
29072+ addl $1, (v)
29073+ adcl $0, 4(v)
29074 RET_ENDP
29075 #undef v
29076
29077@@ -114,6 +203,26 @@ BEGIN(inc_return)
29078 movl 4(v), %edx
29079 addl $1, %eax
29080 adcl $0, %edx
29081+
29082+#ifdef CONFIG_PAX_REFCOUNT
29083+ into
29084+1234:
29085+ _ASM_EXTABLE(1234b, 2f)
29086+#endif
29087+
29088+ movl %eax, (v)
29089+ movl %edx, 4(v)
29090+
29091+#ifdef CONFIG_PAX_REFCOUNT
29092+2:
29093+#endif
29094+
29095+RET_ENDP
29096+BEGIN(inc_return_unchecked)
29097+ movl (v), %eax
29098+ movl 4(v), %edx
29099+ addl $1, %eax
29100+ adcl $0, %edx
29101 movl %eax, (v)
29102 movl %edx, 4(v)
29103 RET_ENDP
29104@@ -123,6 +232,20 @@ RET_ENDP
29105 BEGIN(dec)
29106 subl $1, (v)
29107 sbbl $0, 4(v)
29108+
29109+#ifdef CONFIG_PAX_REFCOUNT
29110+ jno 0f
29111+ addl $1, (v)
29112+ adcl $0, 4(v)
29113+ int $4
29114+0:
29115+ _ASM_EXTABLE(0b, 0b)
29116+#endif
29117+
29118+RET_ENDP
29119+BEGIN(dec_unchecked)
29120+ subl $1, (v)
29121+ sbbl $0, 4(v)
29122 RET_ENDP
29123 #undef v
29124
29125@@ -132,6 +255,26 @@ BEGIN(dec_return)
29126 movl 4(v), %edx
29127 subl $1, %eax
29128 sbbl $0, %edx
29129+
29130+#ifdef CONFIG_PAX_REFCOUNT
29131+ into
29132+1234:
29133+ _ASM_EXTABLE(1234b, 2f)
29134+#endif
29135+
29136+ movl %eax, (v)
29137+ movl %edx, 4(v)
29138+
29139+#ifdef CONFIG_PAX_REFCOUNT
29140+2:
29141+#endif
29142+
29143+RET_ENDP
29144+BEGIN(dec_return_unchecked)
29145+ movl (v), %eax
29146+ movl 4(v), %edx
29147+ subl $1, %eax
29148+ sbbl $0, %edx
29149 movl %eax, (v)
29150 movl %edx, 4(v)
29151 RET_ENDP
29152@@ -143,6 +286,13 @@ BEGIN(add_unless)
29153 adcl %edx, %edi
29154 addl (v), %eax
29155 adcl 4(v), %edx
29156+
29157+#ifdef CONFIG_PAX_REFCOUNT
29158+ into
29159+1234:
29160+ _ASM_EXTABLE(1234b, 2f)
29161+#endif
29162+
29163 cmpl %eax, %ecx
29164 je 3f
29165 1:
29166@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29167 1:
29168 addl $1, %eax
29169 adcl $0, %edx
29170+
29171+#ifdef CONFIG_PAX_REFCOUNT
29172+ into
29173+1234:
29174+ _ASM_EXTABLE(1234b, 2f)
29175+#endif
29176+
29177 movl %eax, (v)
29178 movl %edx, 4(v)
29179 movl $1, %eax
29180@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29181 movl 4(v), %edx
29182 subl $1, %eax
29183 sbbl $0, %edx
29184+
29185+#ifdef CONFIG_PAX_REFCOUNT
29186+ into
29187+1234:
29188+ _ASM_EXTABLE(1234b, 1f)
29189+#endif
29190+
29191 js 1f
29192 movl %eax, (v)
29193 movl %edx, 4(v)
29194diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29195index f5cc9eb..51fa319 100644
29196--- a/arch/x86/lib/atomic64_cx8_32.S
29197+++ b/arch/x86/lib/atomic64_cx8_32.S
29198@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29199 CFI_STARTPROC
29200
29201 read64 %ecx
29202+ pax_force_retaddr
29203 ret
29204 CFI_ENDPROC
29205 ENDPROC(atomic64_read_cx8)
29206
29207+ENTRY(atomic64_read_unchecked_cx8)
29208+ CFI_STARTPROC
29209+
29210+ read64 %ecx
29211+ pax_force_retaddr
29212+ ret
29213+ CFI_ENDPROC
29214+ENDPROC(atomic64_read_unchecked_cx8)
29215+
29216 ENTRY(atomic64_set_cx8)
29217 CFI_STARTPROC
29218
29219@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29220 cmpxchg8b (%esi)
29221 jne 1b
29222
29223+ pax_force_retaddr
29224 ret
29225 CFI_ENDPROC
29226 ENDPROC(atomic64_set_cx8)
29227
29228+ENTRY(atomic64_set_unchecked_cx8)
29229+ CFI_STARTPROC
29230+
29231+1:
29232+/* we don't need LOCK_PREFIX since aligned 64-bit writes
29233+ * are atomic on 586 and newer */
29234+ cmpxchg8b (%esi)
29235+ jne 1b
29236+
29237+ pax_force_retaddr
29238+ ret
29239+ CFI_ENDPROC
29240+ENDPROC(atomic64_set_unchecked_cx8)
29241+
29242 ENTRY(atomic64_xchg_cx8)
29243 CFI_STARTPROC
29244
29245@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29246 cmpxchg8b (%esi)
29247 jne 1b
29248
29249+ pax_force_retaddr
29250 ret
29251 CFI_ENDPROC
29252 ENDPROC(atomic64_xchg_cx8)
29253
29254-.macro addsub_return func ins insc
29255-ENTRY(atomic64_\func\()_return_cx8)
29256+.macro addsub_return func ins insc unchecked=""
29257+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29258 CFI_STARTPROC
29259 SAVE ebp
29260 SAVE ebx
29261@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29262 movl %edx, %ecx
29263 \ins\()l %esi, %ebx
29264 \insc\()l %edi, %ecx
29265+
29266+.ifb \unchecked
29267+#ifdef CONFIG_PAX_REFCOUNT
29268+ into
29269+2:
29270+ _ASM_EXTABLE(2b, 3f)
29271+#endif
29272+.endif
29273+
29274 LOCK_PREFIX
29275 cmpxchg8b (%ebp)
29276 jne 1b
29277-
29278-10:
29279 movl %ebx, %eax
29280 movl %ecx, %edx
29281+
29282+.ifb \unchecked
29283+#ifdef CONFIG_PAX_REFCOUNT
29284+3:
29285+#endif
29286+.endif
29287+
29288 RESTORE edi
29289 RESTORE esi
29290 RESTORE ebx
29291 RESTORE ebp
29292+ pax_force_retaddr
29293 ret
29294 CFI_ENDPROC
29295-ENDPROC(atomic64_\func\()_return_cx8)
29296+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29297 .endm
29298
29299 addsub_return add add adc
29300 addsub_return sub sub sbb
29301+addsub_return add add adc _unchecked
29302+addsub_return sub sub sbb _unchecked
29303
29304-.macro incdec_return func ins insc
29305-ENTRY(atomic64_\func\()_return_cx8)
29306+.macro incdec_return func ins insc unchecked=""
29307+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29308 CFI_STARTPROC
29309 SAVE ebx
29310
29311@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29312 movl %edx, %ecx
29313 \ins\()l $1, %ebx
29314 \insc\()l $0, %ecx
29315+
29316+.ifb \unchecked
29317+#ifdef CONFIG_PAX_REFCOUNT
29318+ into
29319+2:
29320+ _ASM_EXTABLE(2b, 3f)
29321+#endif
29322+.endif
29323+
29324 LOCK_PREFIX
29325 cmpxchg8b (%esi)
29326 jne 1b
29327
29328-10:
29329 movl %ebx, %eax
29330 movl %ecx, %edx
29331+
29332+.ifb \unchecked
29333+#ifdef CONFIG_PAX_REFCOUNT
29334+3:
29335+#endif
29336+.endif
29337+
29338 RESTORE ebx
29339+ pax_force_retaddr
29340 ret
29341 CFI_ENDPROC
29342-ENDPROC(atomic64_\func\()_return_cx8)
29343+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29344 .endm
29345
29346 incdec_return inc add adc
29347 incdec_return dec sub sbb
29348+incdec_return inc add adc _unchecked
29349+incdec_return dec sub sbb _unchecked
29350
29351 ENTRY(atomic64_dec_if_positive_cx8)
29352 CFI_STARTPROC
29353@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29354 movl %edx, %ecx
29355 subl $1, %ebx
29356 sbb $0, %ecx
29357+
29358+#ifdef CONFIG_PAX_REFCOUNT
29359+ into
29360+1234:
29361+ _ASM_EXTABLE(1234b, 2f)
29362+#endif
29363+
29364 js 2f
29365 LOCK_PREFIX
29366 cmpxchg8b (%esi)
29367@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29368 movl %ebx, %eax
29369 movl %ecx, %edx
29370 RESTORE ebx
29371+ pax_force_retaddr
29372 ret
29373 CFI_ENDPROC
29374 ENDPROC(atomic64_dec_if_positive_cx8)
29375@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29376 movl %edx, %ecx
29377 addl %ebp, %ebx
29378 adcl %edi, %ecx
29379+
29380+#ifdef CONFIG_PAX_REFCOUNT
29381+ into
29382+1234:
29383+ _ASM_EXTABLE(1234b, 3f)
29384+#endif
29385+
29386 LOCK_PREFIX
29387 cmpxchg8b (%esi)
29388 jne 1b
29389@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29390 CFI_ADJUST_CFA_OFFSET -8
29391 RESTORE ebx
29392 RESTORE ebp
29393+ pax_force_retaddr
29394 ret
29395 4:
29396 cmpl %edx, 4(%esp)
29397@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29398 xorl %ecx, %ecx
29399 addl $1, %ebx
29400 adcl %edx, %ecx
29401+
29402+#ifdef CONFIG_PAX_REFCOUNT
29403+ into
29404+1234:
29405+ _ASM_EXTABLE(1234b, 3f)
29406+#endif
29407+
29408 LOCK_PREFIX
29409 cmpxchg8b (%esi)
29410 jne 1b
29411@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29412 movl $1, %eax
29413 3:
29414 RESTORE ebx
29415+ pax_force_retaddr
29416 ret
29417 CFI_ENDPROC
29418 ENDPROC(atomic64_inc_not_zero_cx8)
29419diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29420index e78b8ee..7e173a8 100644
29421--- a/arch/x86/lib/checksum_32.S
29422+++ b/arch/x86/lib/checksum_32.S
29423@@ -29,7 +29,8 @@
29424 #include <asm/dwarf2.h>
29425 #include <asm/errno.h>
29426 #include <asm/asm.h>
29427-
29428+#include <asm/segment.h>
29429+
29430 /*
29431 * computes a partial checksum, e.g. for TCP/UDP fragments
29432 */
29433@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29434
29435 #define ARGBASE 16
29436 #define FP 12
29437-
29438-ENTRY(csum_partial_copy_generic)
29439+
29440+ENTRY(csum_partial_copy_generic_to_user)
29441 CFI_STARTPROC
29442+
29443+#ifdef CONFIG_PAX_MEMORY_UDEREF
29444+ pushl_cfi %gs
29445+ popl_cfi %es
29446+ jmp csum_partial_copy_generic
29447+#endif
29448+
29449+ENTRY(csum_partial_copy_generic_from_user)
29450+
29451+#ifdef CONFIG_PAX_MEMORY_UDEREF
29452+ pushl_cfi %gs
29453+ popl_cfi %ds
29454+#endif
29455+
29456+ENTRY(csum_partial_copy_generic)
29457 subl $4,%esp
29458 CFI_ADJUST_CFA_OFFSET 4
29459 pushl_cfi %edi
29460@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29461 jmp 4f
29462 SRC(1: movw (%esi), %bx )
29463 addl $2, %esi
29464-DST( movw %bx, (%edi) )
29465+DST( movw %bx, %es:(%edi) )
29466 addl $2, %edi
29467 addw %bx, %ax
29468 adcl $0, %eax
29469@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29470 SRC(1: movl (%esi), %ebx )
29471 SRC( movl 4(%esi), %edx )
29472 adcl %ebx, %eax
29473-DST( movl %ebx, (%edi) )
29474+DST( movl %ebx, %es:(%edi) )
29475 adcl %edx, %eax
29476-DST( movl %edx, 4(%edi) )
29477+DST( movl %edx, %es:4(%edi) )
29478
29479 SRC( movl 8(%esi), %ebx )
29480 SRC( movl 12(%esi), %edx )
29481 adcl %ebx, %eax
29482-DST( movl %ebx, 8(%edi) )
29483+DST( movl %ebx, %es:8(%edi) )
29484 adcl %edx, %eax
29485-DST( movl %edx, 12(%edi) )
29486+DST( movl %edx, %es:12(%edi) )
29487
29488 SRC( movl 16(%esi), %ebx )
29489 SRC( movl 20(%esi), %edx )
29490 adcl %ebx, %eax
29491-DST( movl %ebx, 16(%edi) )
29492+DST( movl %ebx, %es:16(%edi) )
29493 adcl %edx, %eax
29494-DST( movl %edx, 20(%edi) )
29495+DST( movl %edx, %es:20(%edi) )
29496
29497 SRC( movl 24(%esi), %ebx )
29498 SRC( movl 28(%esi), %edx )
29499 adcl %ebx, %eax
29500-DST( movl %ebx, 24(%edi) )
29501+DST( movl %ebx, %es:24(%edi) )
29502 adcl %edx, %eax
29503-DST( movl %edx, 28(%edi) )
29504+DST( movl %edx, %es:28(%edi) )
29505
29506 lea 32(%esi), %esi
29507 lea 32(%edi), %edi
29508@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29509 shrl $2, %edx # This clears CF
29510 SRC(3: movl (%esi), %ebx )
29511 adcl %ebx, %eax
29512-DST( movl %ebx, (%edi) )
29513+DST( movl %ebx, %es:(%edi) )
29514 lea 4(%esi), %esi
29515 lea 4(%edi), %edi
29516 dec %edx
29517@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29518 jb 5f
29519 SRC( movw (%esi), %cx )
29520 leal 2(%esi), %esi
29521-DST( movw %cx, (%edi) )
29522+DST( movw %cx, %es:(%edi) )
29523 leal 2(%edi), %edi
29524 je 6f
29525 shll $16,%ecx
29526 SRC(5: movb (%esi), %cl )
29527-DST( movb %cl, (%edi) )
29528+DST( movb %cl, %es:(%edi) )
29529 6: addl %ecx, %eax
29530 adcl $0, %eax
29531 7:
29532@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29533
29534 6001:
29535 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29536- movl $-EFAULT, (%ebx)
29537+ movl $-EFAULT, %ss:(%ebx)
29538
29539 # zero the complete destination - computing the rest
29540 # is too much work
29541@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29542
29543 6002:
29544 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29545- movl $-EFAULT,(%ebx)
29546+ movl $-EFAULT,%ss:(%ebx)
29547 jmp 5000b
29548
29549 .previous
29550
29551+ pushl_cfi %ss
29552+ popl_cfi %ds
29553+ pushl_cfi %ss
29554+ popl_cfi %es
29555 popl_cfi %ebx
29556 CFI_RESTORE ebx
29557 popl_cfi %esi
29558@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29559 popl_cfi %ecx # equivalent to addl $4,%esp
29560 ret
29561 CFI_ENDPROC
29562-ENDPROC(csum_partial_copy_generic)
29563+ENDPROC(csum_partial_copy_generic_to_user)
29564
29565 #else
29566
29567 /* Version for PentiumII/PPro */
29568
29569 #define ROUND1(x) \
29570+ nop; nop; nop; \
29571 SRC(movl x(%esi), %ebx ) ; \
29572 addl %ebx, %eax ; \
29573- DST(movl %ebx, x(%edi) ) ;
29574+ DST(movl %ebx, %es:x(%edi)) ;
29575
29576 #define ROUND(x) \
29577+ nop; nop; nop; \
29578 SRC(movl x(%esi), %ebx ) ; \
29579 adcl %ebx, %eax ; \
29580- DST(movl %ebx, x(%edi) ) ;
29581+ DST(movl %ebx, %es:x(%edi)) ;
29582
29583 #define ARGBASE 12
29584-
29585-ENTRY(csum_partial_copy_generic)
29586+
29587+ENTRY(csum_partial_copy_generic_to_user)
29588 CFI_STARTPROC
29589+
29590+#ifdef CONFIG_PAX_MEMORY_UDEREF
29591+ pushl_cfi %gs
29592+ popl_cfi %es
29593+ jmp csum_partial_copy_generic
29594+#endif
29595+
29596+ENTRY(csum_partial_copy_generic_from_user)
29597+
29598+#ifdef CONFIG_PAX_MEMORY_UDEREF
29599+ pushl_cfi %gs
29600+ popl_cfi %ds
29601+#endif
29602+
29603+ENTRY(csum_partial_copy_generic)
29604 pushl_cfi %ebx
29605 CFI_REL_OFFSET ebx, 0
29606 pushl_cfi %edi
29607@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29608 subl %ebx, %edi
29609 lea -1(%esi),%edx
29610 andl $-32,%edx
29611- lea 3f(%ebx,%ebx), %ebx
29612+ lea 3f(%ebx,%ebx,2), %ebx
29613 testl %esi, %esi
29614 jmp *%ebx
29615 1: addl $64,%esi
29616@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29617 jb 5f
29618 SRC( movw (%esi), %dx )
29619 leal 2(%esi), %esi
29620-DST( movw %dx, (%edi) )
29621+DST( movw %dx, %es:(%edi) )
29622 leal 2(%edi), %edi
29623 je 6f
29624 shll $16,%edx
29625 5:
29626 SRC( movb (%esi), %dl )
29627-DST( movb %dl, (%edi) )
29628+DST( movb %dl, %es:(%edi) )
29629 6: addl %edx, %eax
29630 adcl $0, %eax
29631 7:
29632 .section .fixup, "ax"
29633 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29634- movl $-EFAULT, (%ebx)
29635+ movl $-EFAULT, %ss:(%ebx)
29636 # zero the complete destination (computing the rest is too much work)
29637 movl ARGBASE+8(%esp),%edi # dst
29638 movl ARGBASE+12(%esp),%ecx # len
29639@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29640 rep; stosb
29641 jmp 7b
29642 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29643- movl $-EFAULT, (%ebx)
29644+ movl $-EFAULT, %ss:(%ebx)
29645 jmp 7b
29646 .previous
29647
29648+#ifdef CONFIG_PAX_MEMORY_UDEREF
29649+ pushl_cfi %ss
29650+ popl_cfi %ds
29651+ pushl_cfi %ss
29652+ popl_cfi %es
29653+#endif
29654+
29655 popl_cfi %esi
29656 CFI_RESTORE esi
29657 popl_cfi %edi
29658@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29659 CFI_RESTORE ebx
29660 ret
29661 CFI_ENDPROC
29662-ENDPROC(csum_partial_copy_generic)
29663+ENDPROC(csum_partial_copy_generic_to_user)
29664
29665 #undef ROUND
29666 #undef ROUND1
29667diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29668index f2145cf..cea889d 100644
29669--- a/arch/x86/lib/clear_page_64.S
29670+++ b/arch/x86/lib/clear_page_64.S
29671@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29672 movl $4096/8,%ecx
29673 xorl %eax,%eax
29674 rep stosq
29675+ pax_force_retaddr
29676 ret
29677 CFI_ENDPROC
29678 ENDPROC(clear_page_c)
29679@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29680 movl $4096,%ecx
29681 xorl %eax,%eax
29682 rep stosb
29683+ pax_force_retaddr
29684 ret
29685 CFI_ENDPROC
29686 ENDPROC(clear_page_c_e)
29687@@ -43,6 +45,7 @@ ENTRY(clear_page)
29688 leaq 64(%rdi),%rdi
29689 jnz .Lloop
29690 nop
29691+ pax_force_retaddr
29692 ret
29693 CFI_ENDPROC
29694 .Lclear_page_end:
29695@@ -58,7 +61,7 @@ ENDPROC(clear_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 (clear_page_c - clear_page) - (2f - 1b) /* offset */
29703 2: .byte 0xeb /* jmp <disp8> */
29704diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29705index 1e572c5..2a162cd 100644
29706--- a/arch/x86/lib/cmpxchg16b_emu.S
29707+++ b/arch/x86/lib/cmpxchg16b_emu.S
29708@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29709
29710 popf
29711 mov $1, %al
29712+ pax_force_retaddr
29713 ret
29714
29715 not_same:
29716 popf
29717 xor %al,%al
29718+ pax_force_retaddr
29719 ret
29720
29721 CFI_ENDPROC
29722diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29723index 176cca6..e0d658e 100644
29724--- a/arch/x86/lib/copy_page_64.S
29725+++ b/arch/x86/lib/copy_page_64.S
29726@@ -9,6 +9,7 @@ copy_page_rep:
29727 CFI_STARTPROC
29728 movl $4096/8, %ecx
29729 rep movsq
29730+ pax_force_retaddr
29731 ret
29732 CFI_ENDPROC
29733 ENDPROC(copy_page_rep)
29734@@ -24,8 +25,8 @@ ENTRY(copy_page)
29735 CFI_ADJUST_CFA_OFFSET 2*8
29736 movq %rbx, (%rsp)
29737 CFI_REL_OFFSET rbx, 0
29738- movq %r12, 1*8(%rsp)
29739- CFI_REL_OFFSET r12, 1*8
29740+ movq %r13, 1*8(%rsp)
29741+ CFI_REL_OFFSET r13, 1*8
29742
29743 movl $(4096/64)-5, %ecx
29744 .p2align 4
29745@@ -38,7 +39,7 @@ ENTRY(copy_page)
29746 movq 0x8*4(%rsi), %r9
29747 movq 0x8*5(%rsi), %r10
29748 movq 0x8*6(%rsi), %r11
29749- movq 0x8*7(%rsi), %r12
29750+ movq 0x8*7(%rsi), %r13
29751
29752 prefetcht0 5*64(%rsi)
29753
29754@@ -49,7 +50,7 @@ ENTRY(copy_page)
29755 movq %r9, 0x8*4(%rdi)
29756 movq %r10, 0x8*5(%rdi)
29757 movq %r11, 0x8*6(%rdi)
29758- movq %r12, 0x8*7(%rdi)
29759+ movq %r13, 0x8*7(%rdi)
29760
29761 leaq 64 (%rsi), %rsi
29762 leaq 64 (%rdi), %rdi
29763@@ -68,7 +69,7 @@ ENTRY(copy_page)
29764 movq 0x8*4(%rsi), %r9
29765 movq 0x8*5(%rsi), %r10
29766 movq 0x8*6(%rsi), %r11
29767- movq 0x8*7(%rsi), %r12
29768+ movq 0x8*7(%rsi), %r13
29769
29770 movq %rax, 0x8*0(%rdi)
29771 movq %rbx, 0x8*1(%rdi)
29772@@ -77,7 +78,7 @@ ENTRY(copy_page)
29773 movq %r9, 0x8*4(%rdi)
29774 movq %r10, 0x8*5(%rdi)
29775 movq %r11, 0x8*6(%rdi)
29776- movq %r12, 0x8*7(%rdi)
29777+ movq %r13, 0x8*7(%rdi)
29778
29779 leaq 64(%rdi), %rdi
29780 leaq 64(%rsi), %rsi
29781@@ -85,10 +86,11 @@ ENTRY(copy_page)
29782
29783 movq (%rsp), %rbx
29784 CFI_RESTORE rbx
29785- movq 1*8(%rsp), %r12
29786- CFI_RESTORE r12
29787+ movq 1*8(%rsp), %r13
29788+ CFI_RESTORE r13
29789 addq $2*8, %rsp
29790 CFI_ADJUST_CFA_OFFSET -2*8
29791+ pax_force_retaddr
29792 ret
29793 .Lcopy_page_end:
29794 CFI_ENDPROC
29795@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29796
29797 #include <asm/cpufeature.h>
29798
29799- .section .altinstr_replacement,"ax"
29800+ .section .altinstr_replacement,"a"
29801 1: .byte 0xeb /* jmp <disp8> */
29802 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29803 2:
29804diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29805index dee945d..a84067b 100644
29806--- a/arch/x86/lib/copy_user_64.S
29807+++ b/arch/x86/lib/copy_user_64.S
29808@@ -18,31 +18,7 @@
29809 #include <asm/alternative-asm.h>
29810 #include <asm/asm.h>
29811 #include <asm/smap.h>
29812-
29813-/*
29814- * By placing feature2 after feature1 in altinstructions section, we logically
29815- * implement:
29816- * If CPU has feature2, jmp to alt2 is used
29817- * else if CPU has feature1, jmp to alt1 is used
29818- * else jmp to orig is used.
29819- */
29820- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29821-0:
29822- .byte 0xe9 /* 32bit jump */
29823- .long \orig-1f /* by default jump to orig */
29824-1:
29825- .section .altinstr_replacement,"ax"
29826-2: .byte 0xe9 /* near jump with 32bit immediate */
29827- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29828-3: .byte 0xe9 /* near jump with 32bit immediate */
29829- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29830- .previous
29831-
29832- .section .altinstructions,"a"
29833- altinstruction_entry 0b,2b,\feature1,5,5
29834- altinstruction_entry 0b,3b,\feature2,5,5
29835- .previous
29836- .endm
29837+#include <asm/pgtable.h>
29838
29839 .macro ALIGN_DESTINATION
29840 #ifdef FIX_ALIGNMENT
29841@@ -70,52 +46,6 @@
29842 #endif
29843 .endm
29844
29845-/* Standard copy_to_user with segment limit checking */
29846-ENTRY(_copy_to_user)
29847- CFI_STARTPROC
29848- GET_THREAD_INFO(%rax)
29849- movq %rdi,%rcx
29850- addq %rdx,%rcx
29851- jc bad_to_user
29852- cmpq TI_addr_limit(%rax),%rcx
29853- ja bad_to_user
29854- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29855- copy_user_generic_unrolled,copy_user_generic_string, \
29856- copy_user_enhanced_fast_string
29857- CFI_ENDPROC
29858-ENDPROC(_copy_to_user)
29859-
29860-/* Standard copy_from_user with segment limit checking */
29861-ENTRY(_copy_from_user)
29862- CFI_STARTPROC
29863- GET_THREAD_INFO(%rax)
29864- movq %rsi,%rcx
29865- addq %rdx,%rcx
29866- jc bad_from_user
29867- cmpq TI_addr_limit(%rax),%rcx
29868- ja bad_from_user
29869- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29870- copy_user_generic_unrolled,copy_user_generic_string, \
29871- copy_user_enhanced_fast_string
29872- CFI_ENDPROC
29873-ENDPROC(_copy_from_user)
29874-
29875- .section .fixup,"ax"
29876- /* must zero dest */
29877-ENTRY(bad_from_user)
29878-bad_from_user:
29879- CFI_STARTPROC
29880- movl %edx,%ecx
29881- xorl %eax,%eax
29882- rep
29883- stosb
29884-bad_to_user:
29885- movl %edx,%eax
29886- ret
29887- CFI_ENDPROC
29888-ENDPROC(bad_from_user)
29889- .previous
29890-
29891 /*
29892 * copy_user_generic_unrolled - memory copy with exception handling.
29893 * This version is for CPUs like P4 that don't have efficient micro
29894@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29895 */
29896 ENTRY(copy_user_generic_unrolled)
29897 CFI_STARTPROC
29898+ ASM_PAX_OPEN_USERLAND
29899 ASM_STAC
29900 cmpl $8,%edx
29901 jb 20f /* less then 8 bytes, go to byte copy loop */
29902@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29903 jnz 21b
29904 23: xor %eax,%eax
29905 ASM_CLAC
29906+ ASM_PAX_CLOSE_USERLAND
29907+ pax_force_retaddr
29908 ret
29909
29910 .section .fixup,"ax"
29911@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29912 */
29913 ENTRY(copy_user_generic_string)
29914 CFI_STARTPROC
29915+ ASM_PAX_OPEN_USERLAND
29916 ASM_STAC
29917 cmpl $8,%edx
29918 jb 2f /* less than 8 bytes, go to byte copy loop */
29919@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29920 movsb
29921 xorl %eax,%eax
29922 ASM_CLAC
29923+ ASM_PAX_CLOSE_USERLAND
29924+ pax_force_retaddr
29925 ret
29926
29927 .section .fixup,"ax"
29928@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29929 */
29930 ENTRY(copy_user_enhanced_fast_string)
29931 CFI_STARTPROC
29932+ ASM_PAX_OPEN_USERLAND
29933 ASM_STAC
29934 movl %edx,%ecx
29935 1: rep
29936 movsb
29937 xorl %eax,%eax
29938 ASM_CLAC
29939+ ASM_PAX_CLOSE_USERLAND
29940+ pax_force_retaddr
29941 ret
29942
29943 .section .fixup,"ax"
29944diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29945index 6a4f43c..c70fb52 100644
29946--- a/arch/x86/lib/copy_user_nocache_64.S
29947+++ b/arch/x86/lib/copy_user_nocache_64.S
29948@@ -8,6 +8,7 @@
29949
29950 #include <linux/linkage.h>
29951 #include <asm/dwarf2.h>
29952+#include <asm/alternative-asm.h>
29953
29954 #define FIX_ALIGNMENT 1
29955
29956@@ -16,6 +17,7 @@
29957 #include <asm/thread_info.h>
29958 #include <asm/asm.h>
29959 #include <asm/smap.h>
29960+#include <asm/pgtable.h>
29961
29962 .macro ALIGN_DESTINATION
29963 #ifdef FIX_ALIGNMENT
29964@@ -49,6 +51,16 @@
29965 */
29966 ENTRY(__copy_user_nocache)
29967 CFI_STARTPROC
29968+
29969+#ifdef CONFIG_PAX_MEMORY_UDEREF
29970+ mov pax_user_shadow_base,%rcx
29971+ cmp %rcx,%rsi
29972+ jae 1f
29973+ add %rcx,%rsi
29974+1:
29975+#endif
29976+
29977+ ASM_PAX_OPEN_USERLAND
29978 ASM_STAC
29979 cmpl $8,%edx
29980 jb 20f /* less then 8 bytes, go to byte copy loop */
29981@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29982 jnz 21b
29983 23: xorl %eax,%eax
29984 ASM_CLAC
29985+ ASM_PAX_CLOSE_USERLAND
29986 sfence
29987+ pax_force_retaddr
29988 ret
29989
29990 .section .fixup,"ax"
29991diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29992index 2419d5f..fe52d0e 100644
29993--- a/arch/x86/lib/csum-copy_64.S
29994+++ b/arch/x86/lib/csum-copy_64.S
29995@@ -9,6 +9,7 @@
29996 #include <asm/dwarf2.h>
29997 #include <asm/errno.h>
29998 #include <asm/asm.h>
29999+#include <asm/alternative-asm.h>
30000
30001 /*
30002 * Checksum copy with exception handling.
30003@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30004 CFI_ADJUST_CFA_OFFSET 7*8
30005 movq %rbx, 2*8(%rsp)
30006 CFI_REL_OFFSET rbx, 2*8
30007- movq %r12, 3*8(%rsp)
30008- CFI_REL_OFFSET r12, 3*8
30009+ movq %r15, 3*8(%rsp)
30010+ CFI_REL_OFFSET r15, 3*8
30011 movq %r14, 4*8(%rsp)
30012 CFI_REL_OFFSET r14, 4*8
30013 movq %r13, 5*8(%rsp)
30014@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30015 movl %edx, %ecx
30016
30017 xorl %r9d, %r9d
30018- movq %rcx, %r12
30019+ movq %rcx, %r15
30020
30021- shrq $6, %r12
30022+ shrq $6, %r15
30023 jz .Lhandle_tail /* < 64 */
30024
30025 clc
30026
30027 /* main loop. clear in 64 byte blocks */
30028 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30029- /* r11: temp3, rdx: temp4, r12 loopcnt */
30030+ /* r11: temp3, rdx: temp4, r15 loopcnt */
30031 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30032 .p2align 4
30033 .Lloop:
30034@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30035 adcq %r14, %rax
30036 adcq %r13, %rax
30037
30038- decl %r12d
30039+ decl %r15d
30040
30041 dest
30042 movq %rbx, (%rsi)
30043@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30044 .Lende:
30045 movq 2*8(%rsp), %rbx
30046 CFI_RESTORE rbx
30047- movq 3*8(%rsp), %r12
30048- CFI_RESTORE r12
30049+ movq 3*8(%rsp), %r15
30050+ CFI_RESTORE r15
30051 movq 4*8(%rsp), %r14
30052 CFI_RESTORE r14
30053 movq 5*8(%rsp), %r13
30054@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30055 CFI_RESTORE rbp
30056 addq $7*8, %rsp
30057 CFI_ADJUST_CFA_OFFSET -7*8
30058+ pax_force_retaddr
30059 ret
30060 CFI_RESTORE_STATE
30061
30062diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30063index 7609e0e..b449b98 100644
30064--- a/arch/x86/lib/csum-wrappers_64.c
30065+++ b/arch/x86/lib/csum-wrappers_64.c
30066@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30067 len -= 2;
30068 }
30069 }
30070+ pax_open_userland();
30071 stac();
30072- isum = csum_partial_copy_generic((__force const void *)src,
30073+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30074 dst, len, isum, errp, NULL);
30075 clac();
30076+ pax_close_userland();
30077 if (unlikely(*errp))
30078 goto out_err;
30079
30080@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30081 }
30082
30083 *errp = 0;
30084+ pax_open_userland();
30085 stac();
30086- ret = csum_partial_copy_generic(src, (void __force *)dst,
30087+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30088 len, isum, NULL, errp);
30089 clac();
30090+ pax_close_userland();
30091 return ret;
30092 }
30093 EXPORT_SYMBOL(csum_partial_copy_to_user);
30094diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30095index a451235..1daa956 100644
30096--- a/arch/x86/lib/getuser.S
30097+++ b/arch/x86/lib/getuser.S
30098@@ -33,17 +33,40 @@
30099 #include <asm/thread_info.h>
30100 #include <asm/asm.h>
30101 #include <asm/smap.h>
30102+#include <asm/segment.h>
30103+#include <asm/pgtable.h>
30104+#include <asm/alternative-asm.h>
30105+
30106+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30107+#define __copyuser_seg gs;
30108+#else
30109+#define __copyuser_seg
30110+#endif
30111
30112 .text
30113 ENTRY(__get_user_1)
30114 CFI_STARTPROC
30115+
30116+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30117 GET_THREAD_INFO(%_ASM_DX)
30118 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30119 jae bad_get_user
30120 ASM_STAC
30121-1: movzbl (%_ASM_AX),%edx
30122+
30123+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30124+ mov pax_user_shadow_base,%_ASM_DX
30125+ cmp %_ASM_DX,%_ASM_AX
30126+ jae 1234f
30127+ add %_ASM_DX,%_ASM_AX
30128+1234:
30129+#endif
30130+
30131+#endif
30132+
30133+1: __copyuser_seg movzbl (%_ASM_AX),%edx
30134 xor %eax,%eax
30135 ASM_CLAC
30136+ pax_force_retaddr
30137 ret
30138 CFI_ENDPROC
30139 ENDPROC(__get_user_1)
30140@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30141 ENTRY(__get_user_2)
30142 CFI_STARTPROC
30143 add $1,%_ASM_AX
30144+
30145+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30146 jc bad_get_user
30147 GET_THREAD_INFO(%_ASM_DX)
30148 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30149 jae bad_get_user
30150 ASM_STAC
30151-2: movzwl -1(%_ASM_AX),%edx
30152+
30153+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30154+ mov pax_user_shadow_base,%_ASM_DX
30155+ cmp %_ASM_DX,%_ASM_AX
30156+ jae 1234f
30157+ add %_ASM_DX,%_ASM_AX
30158+1234:
30159+#endif
30160+
30161+#endif
30162+
30163+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30164 xor %eax,%eax
30165 ASM_CLAC
30166+ pax_force_retaddr
30167 ret
30168 CFI_ENDPROC
30169 ENDPROC(__get_user_2)
30170@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30171 ENTRY(__get_user_4)
30172 CFI_STARTPROC
30173 add $3,%_ASM_AX
30174+
30175+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30176 jc bad_get_user
30177 GET_THREAD_INFO(%_ASM_DX)
30178 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30179 jae bad_get_user
30180 ASM_STAC
30181-3: movl -3(%_ASM_AX),%edx
30182+
30183+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30184+ mov pax_user_shadow_base,%_ASM_DX
30185+ cmp %_ASM_DX,%_ASM_AX
30186+ jae 1234f
30187+ add %_ASM_DX,%_ASM_AX
30188+1234:
30189+#endif
30190+
30191+#endif
30192+
30193+3: __copyuser_seg movl -3(%_ASM_AX),%edx
30194 xor %eax,%eax
30195 ASM_CLAC
30196+ pax_force_retaddr
30197 ret
30198 CFI_ENDPROC
30199 ENDPROC(__get_user_4)
30200@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30201 GET_THREAD_INFO(%_ASM_DX)
30202 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30203 jae bad_get_user
30204+
30205+#ifdef CONFIG_PAX_MEMORY_UDEREF
30206+ mov pax_user_shadow_base,%_ASM_DX
30207+ cmp %_ASM_DX,%_ASM_AX
30208+ jae 1234f
30209+ add %_ASM_DX,%_ASM_AX
30210+1234:
30211+#endif
30212+
30213 ASM_STAC
30214 4: movq -7(%_ASM_AX),%rdx
30215 xor %eax,%eax
30216 ASM_CLAC
30217+ pax_force_retaddr
30218 ret
30219 #else
30220 add $7,%_ASM_AX
30221@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30222 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30223 jae bad_get_user_8
30224 ASM_STAC
30225-4: movl -7(%_ASM_AX),%edx
30226-5: movl -3(%_ASM_AX),%ecx
30227+4: __copyuser_seg movl -7(%_ASM_AX),%edx
30228+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30229 xor %eax,%eax
30230 ASM_CLAC
30231+ pax_force_retaddr
30232 ret
30233 #endif
30234 CFI_ENDPROC
30235@@ -113,6 +175,7 @@ bad_get_user:
30236 xor %edx,%edx
30237 mov $(-EFAULT),%_ASM_AX
30238 ASM_CLAC
30239+ pax_force_retaddr
30240 ret
30241 CFI_ENDPROC
30242 END(bad_get_user)
30243@@ -124,6 +187,7 @@ bad_get_user_8:
30244 xor %ecx,%ecx
30245 mov $(-EFAULT),%_ASM_AX
30246 ASM_CLAC
30247+ pax_force_retaddr
30248 ret
30249 CFI_ENDPROC
30250 END(bad_get_user_8)
30251diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30252index 54fcffe..7be149e 100644
30253--- a/arch/x86/lib/insn.c
30254+++ b/arch/x86/lib/insn.c
30255@@ -20,8 +20,10 @@
30256
30257 #ifdef __KERNEL__
30258 #include <linux/string.h>
30259+#include <asm/pgtable_types.h>
30260 #else
30261 #include <string.h>
30262+#define ktla_ktva(addr) addr
30263 #endif
30264 #include <asm/inat.h>
30265 #include <asm/insn.h>
30266@@ -53,8 +55,8 @@
30267 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30268 {
30269 memset(insn, 0, sizeof(*insn));
30270- insn->kaddr = kaddr;
30271- insn->next_byte = kaddr;
30272+ insn->kaddr = ktla_ktva(kaddr);
30273+ insn->next_byte = ktla_ktva(kaddr);
30274 insn->x86_64 = x86_64 ? 1 : 0;
30275 insn->opnd_bytes = 4;
30276 if (x86_64)
30277diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30278index 05a95e7..326f2fa 100644
30279--- a/arch/x86/lib/iomap_copy_64.S
30280+++ b/arch/x86/lib/iomap_copy_64.S
30281@@ -17,6 +17,7 @@
30282
30283 #include <linux/linkage.h>
30284 #include <asm/dwarf2.h>
30285+#include <asm/alternative-asm.h>
30286
30287 /*
30288 * override generic version in lib/iomap_copy.c
30289@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30290 CFI_STARTPROC
30291 movl %edx,%ecx
30292 rep movsd
30293+ pax_force_retaddr
30294 ret
30295 CFI_ENDPROC
30296 ENDPROC(__iowrite32_copy)
30297diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30298index 56313a3..0db417e 100644
30299--- a/arch/x86/lib/memcpy_64.S
30300+++ b/arch/x86/lib/memcpy_64.S
30301@@ -24,7 +24,7 @@
30302 * This gets patched over the unrolled variant (below) via the
30303 * alternative instructions framework:
30304 */
30305- .section .altinstr_replacement, "ax", @progbits
30306+ .section .altinstr_replacement, "a", @progbits
30307 .Lmemcpy_c:
30308 movq %rdi, %rax
30309 movq %rdx, %rcx
30310@@ -33,6 +33,7 @@
30311 rep movsq
30312 movl %edx, %ecx
30313 rep movsb
30314+ pax_force_retaddr
30315 ret
30316 .Lmemcpy_e:
30317 .previous
30318@@ -44,11 +45,12 @@
30319 * This gets patched over the unrolled variant (below) via the
30320 * alternative instructions framework:
30321 */
30322- .section .altinstr_replacement, "ax", @progbits
30323+ .section .altinstr_replacement, "a", @progbits
30324 .Lmemcpy_c_e:
30325 movq %rdi, %rax
30326 movq %rdx, %rcx
30327 rep movsb
30328+ pax_force_retaddr
30329 ret
30330 .Lmemcpy_e_e:
30331 .previous
30332@@ -136,6 +138,7 @@ ENTRY(memcpy)
30333 movq %r9, 1*8(%rdi)
30334 movq %r10, -2*8(%rdi, %rdx)
30335 movq %r11, -1*8(%rdi, %rdx)
30336+ pax_force_retaddr
30337 retq
30338 .p2align 4
30339 .Lless_16bytes:
30340@@ -148,6 +151,7 @@ ENTRY(memcpy)
30341 movq -1*8(%rsi, %rdx), %r9
30342 movq %r8, 0*8(%rdi)
30343 movq %r9, -1*8(%rdi, %rdx)
30344+ pax_force_retaddr
30345 retq
30346 .p2align 4
30347 .Lless_8bytes:
30348@@ -161,6 +165,7 @@ ENTRY(memcpy)
30349 movl -4(%rsi, %rdx), %r8d
30350 movl %ecx, (%rdi)
30351 movl %r8d, -4(%rdi, %rdx)
30352+ pax_force_retaddr
30353 retq
30354 .p2align 4
30355 .Lless_3bytes:
30356@@ -179,6 +184,7 @@ ENTRY(memcpy)
30357 movb %cl, (%rdi)
30358
30359 .Lend:
30360+ pax_force_retaddr
30361 retq
30362 CFI_ENDPROC
30363 ENDPROC(memcpy)
30364diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30365index 65268a6..dd1de11 100644
30366--- a/arch/x86/lib/memmove_64.S
30367+++ b/arch/x86/lib/memmove_64.S
30368@@ -202,14 +202,16 @@ ENTRY(memmove)
30369 movb (%rsi), %r11b
30370 movb %r11b, (%rdi)
30371 13:
30372+ pax_force_retaddr
30373 retq
30374 CFI_ENDPROC
30375
30376- .section .altinstr_replacement,"ax"
30377+ .section .altinstr_replacement,"a"
30378 .Lmemmove_begin_forward_efs:
30379 /* Forward moving data. */
30380 movq %rdx, %rcx
30381 rep movsb
30382+ pax_force_retaddr
30383 retq
30384 .Lmemmove_end_forward_efs:
30385 .previous
30386diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30387index 2dcb380..2eb79fe 100644
30388--- a/arch/x86/lib/memset_64.S
30389+++ b/arch/x86/lib/memset_64.S
30390@@ -16,7 +16,7 @@
30391 *
30392 * rax original destination
30393 */
30394- .section .altinstr_replacement, "ax", @progbits
30395+ .section .altinstr_replacement, "a", @progbits
30396 .Lmemset_c:
30397 movq %rdi,%r9
30398 movq %rdx,%rcx
30399@@ -30,6 +30,7 @@
30400 movl %edx,%ecx
30401 rep stosb
30402 movq %r9,%rax
30403+ pax_force_retaddr
30404 ret
30405 .Lmemset_e:
30406 .previous
30407@@ -45,13 +46,14 @@
30408 *
30409 * rax original destination
30410 */
30411- .section .altinstr_replacement, "ax", @progbits
30412+ .section .altinstr_replacement, "a", @progbits
30413 .Lmemset_c_e:
30414 movq %rdi,%r9
30415 movb %sil,%al
30416 movq %rdx,%rcx
30417 rep stosb
30418 movq %r9,%rax
30419+ pax_force_retaddr
30420 ret
30421 .Lmemset_e_e:
30422 .previous
30423@@ -118,6 +120,7 @@ ENTRY(__memset)
30424
30425 .Lende:
30426 movq %r10,%rax
30427+ pax_force_retaddr
30428 ret
30429
30430 CFI_RESTORE_STATE
30431diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30432index c9f2d9b..e7fd2c0 100644
30433--- a/arch/x86/lib/mmx_32.c
30434+++ b/arch/x86/lib/mmx_32.c
30435@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30436 {
30437 void *p;
30438 int i;
30439+ unsigned long cr0;
30440
30441 if (unlikely(in_interrupt()))
30442 return __memcpy(to, from, len);
30443@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30444 kernel_fpu_begin();
30445
30446 __asm__ __volatile__ (
30447- "1: prefetch (%0)\n" /* This set is 28 bytes */
30448- " prefetch 64(%0)\n"
30449- " prefetch 128(%0)\n"
30450- " prefetch 192(%0)\n"
30451- " prefetch 256(%0)\n"
30452+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30453+ " prefetch 64(%1)\n"
30454+ " prefetch 128(%1)\n"
30455+ " prefetch 192(%1)\n"
30456+ " prefetch 256(%1)\n"
30457 "2: \n"
30458 ".section .fixup, \"ax\"\n"
30459- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30460+ "3: \n"
30461+
30462+#ifdef CONFIG_PAX_KERNEXEC
30463+ " movl %%cr0, %0\n"
30464+ " movl %0, %%eax\n"
30465+ " andl $0xFFFEFFFF, %%eax\n"
30466+ " movl %%eax, %%cr0\n"
30467+#endif
30468+
30469+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30470+
30471+#ifdef CONFIG_PAX_KERNEXEC
30472+ " movl %0, %%cr0\n"
30473+#endif
30474+
30475 " jmp 2b\n"
30476 ".previous\n"
30477 _ASM_EXTABLE(1b, 3b)
30478- : : "r" (from));
30479+ : "=&r" (cr0) : "r" (from) : "ax");
30480
30481 for ( ; i > 5; i--) {
30482 __asm__ __volatile__ (
30483- "1: prefetch 320(%0)\n"
30484- "2: movq (%0), %%mm0\n"
30485- " movq 8(%0), %%mm1\n"
30486- " movq 16(%0), %%mm2\n"
30487- " movq 24(%0), %%mm3\n"
30488- " movq %%mm0, (%1)\n"
30489- " movq %%mm1, 8(%1)\n"
30490- " movq %%mm2, 16(%1)\n"
30491- " movq %%mm3, 24(%1)\n"
30492- " movq 32(%0), %%mm0\n"
30493- " movq 40(%0), %%mm1\n"
30494- " movq 48(%0), %%mm2\n"
30495- " movq 56(%0), %%mm3\n"
30496- " movq %%mm0, 32(%1)\n"
30497- " movq %%mm1, 40(%1)\n"
30498- " movq %%mm2, 48(%1)\n"
30499- " movq %%mm3, 56(%1)\n"
30500+ "1: prefetch 320(%1)\n"
30501+ "2: movq (%1), %%mm0\n"
30502+ " movq 8(%1), %%mm1\n"
30503+ " movq 16(%1), %%mm2\n"
30504+ " movq 24(%1), %%mm3\n"
30505+ " movq %%mm0, (%2)\n"
30506+ " movq %%mm1, 8(%2)\n"
30507+ " movq %%mm2, 16(%2)\n"
30508+ " movq %%mm3, 24(%2)\n"
30509+ " movq 32(%1), %%mm0\n"
30510+ " movq 40(%1), %%mm1\n"
30511+ " movq 48(%1), %%mm2\n"
30512+ " movq 56(%1), %%mm3\n"
30513+ " movq %%mm0, 32(%2)\n"
30514+ " movq %%mm1, 40(%2)\n"
30515+ " movq %%mm2, 48(%2)\n"
30516+ " movq %%mm3, 56(%2)\n"
30517 ".section .fixup, \"ax\"\n"
30518- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30519+ "3:\n"
30520+
30521+#ifdef CONFIG_PAX_KERNEXEC
30522+ " movl %%cr0, %0\n"
30523+ " movl %0, %%eax\n"
30524+ " andl $0xFFFEFFFF, %%eax\n"
30525+ " movl %%eax, %%cr0\n"
30526+#endif
30527+
30528+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30529+
30530+#ifdef CONFIG_PAX_KERNEXEC
30531+ " movl %0, %%cr0\n"
30532+#endif
30533+
30534 " jmp 2b\n"
30535 ".previous\n"
30536 _ASM_EXTABLE(1b, 3b)
30537- : : "r" (from), "r" (to) : "memory");
30538+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30539
30540 from += 64;
30541 to += 64;
30542@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30543 static void fast_copy_page(void *to, void *from)
30544 {
30545 int i;
30546+ unsigned long cr0;
30547
30548 kernel_fpu_begin();
30549
30550@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30551 * but that is for later. -AV
30552 */
30553 __asm__ __volatile__(
30554- "1: prefetch (%0)\n"
30555- " prefetch 64(%0)\n"
30556- " prefetch 128(%0)\n"
30557- " prefetch 192(%0)\n"
30558- " prefetch 256(%0)\n"
30559+ "1: prefetch (%1)\n"
30560+ " prefetch 64(%1)\n"
30561+ " prefetch 128(%1)\n"
30562+ " prefetch 192(%1)\n"
30563+ " prefetch 256(%1)\n"
30564 "2: \n"
30565 ".section .fixup, \"ax\"\n"
30566- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30567+ "3: \n"
30568+
30569+#ifdef CONFIG_PAX_KERNEXEC
30570+ " movl %%cr0, %0\n"
30571+ " movl %0, %%eax\n"
30572+ " andl $0xFFFEFFFF, %%eax\n"
30573+ " movl %%eax, %%cr0\n"
30574+#endif
30575+
30576+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30577+
30578+#ifdef CONFIG_PAX_KERNEXEC
30579+ " movl %0, %%cr0\n"
30580+#endif
30581+
30582 " jmp 2b\n"
30583 ".previous\n"
30584- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30585+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30586
30587 for (i = 0; i < (4096-320)/64; i++) {
30588 __asm__ __volatile__ (
30589- "1: prefetch 320(%0)\n"
30590- "2: movq (%0), %%mm0\n"
30591- " movntq %%mm0, (%1)\n"
30592- " movq 8(%0), %%mm1\n"
30593- " movntq %%mm1, 8(%1)\n"
30594- " movq 16(%0), %%mm2\n"
30595- " movntq %%mm2, 16(%1)\n"
30596- " movq 24(%0), %%mm3\n"
30597- " movntq %%mm3, 24(%1)\n"
30598- " movq 32(%0), %%mm4\n"
30599- " movntq %%mm4, 32(%1)\n"
30600- " movq 40(%0), %%mm5\n"
30601- " movntq %%mm5, 40(%1)\n"
30602- " movq 48(%0), %%mm6\n"
30603- " movntq %%mm6, 48(%1)\n"
30604- " movq 56(%0), %%mm7\n"
30605- " movntq %%mm7, 56(%1)\n"
30606+ "1: prefetch 320(%1)\n"
30607+ "2: movq (%1), %%mm0\n"
30608+ " movntq %%mm0, (%2)\n"
30609+ " movq 8(%1), %%mm1\n"
30610+ " movntq %%mm1, 8(%2)\n"
30611+ " movq 16(%1), %%mm2\n"
30612+ " movntq %%mm2, 16(%2)\n"
30613+ " movq 24(%1), %%mm3\n"
30614+ " movntq %%mm3, 24(%2)\n"
30615+ " movq 32(%1), %%mm4\n"
30616+ " movntq %%mm4, 32(%2)\n"
30617+ " movq 40(%1), %%mm5\n"
30618+ " movntq %%mm5, 40(%2)\n"
30619+ " movq 48(%1), %%mm6\n"
30620+ " movntq %%mm6, 48(%2)\n"
30621+ " movq 56(%1), %%mm7\n"
30622+ " movntq %%mm7, 56(%2)\n"
30623 ".section .fixup, \"ax\"\n"
30624- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30625+ "3:\n"
30626+
30627+#ifdef CONFIG_PAX_KERNEXEC
30628+ " movl %%cr0, %0\n"
30629+ " movl %0, %%eax\n"
30630+ " andl $0xFFFEFFFF, %%eax\n"
30631+ " movl %%eax, %%cr0\n"
30632+#endif
30633+
30634+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30635+
30636+#ifdef CONFIG_PAX_KERNEXEC
30637+ " movl %0, %%cr0\n"
30638+#endif
30639+
30640 " jmp 2b\n"
30641 ".previous\n"
30642- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30643+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30644
30645 from += 64;
30646 to += 64;
30647@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30648 static void fast_copy_page(void *to, void *from)
30649 {
30650 int i;
30651+ unsigned long cr0;
30652
30653 kernel_fpu_begin();
30654
30655 __asm__ __volatile__ (
30656- "1: prefetch (%0)\n"
30657- " prefetch 64(%0)\n"
30658- " prefetch 128(%0)\n"
30659- " prefetch 192(%0)\n"
30660- " prefetch 256(%0)\n"
30661+ "1: prefetch (%1)\n"
30662+ " prefetch 64(%1)\n"
30663+ " prefetch 128(%1)\n"
30664+ " prefetch 192(%1)\n"
30665+ " prefetch 256(%1)\n"
30666 "2: \n"
30667 ".section .fixup, \"ax\"\n"
30668- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30669+ "3: \n"
30670+
30671+#ifdef CONFIG_PAX_KERNEXEC
30672+ " movl %%cr0, %0\n"
30673+ " movl %0, %%eax\n"
30674+ " andl $0xFFFEFFFF, %%eax\n"
30675+ " movl %%eax, %%cr0\n"
30676+#endif
30677+
30678+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30679+
30680+#ifdef CONFIG_PAX_KERNEXEC
30681+ " movl %0, %%cr0\n"
30682+#endif
30683+
30684 " jmp 2b\n"
30685 ".previous\n"
30686- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30687+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30688
30689 for (i = 0; i < 4096/64; i++) {
30690 __asm__ __volatile__ (
30691- "1: prefetch 320(%0)\n"
30692- "2: movq (%0), %%mm0\n"
30693- " movq 8(%0), %%mm1\n"
30694- " movq 16(%0), %%mm2\n"
30695- " movq 24(%0), %%mm3\n"
30696- " movq %%mm0, (%1)\n"
30697- " movq %%mm1, 8(%1)\n"
30698- " movq %%mm2, 16(%1)\n"
30699- " movq %%mm3, 24(%1)\n"
30700- " movq 32(%0), %%mm0\n"
30701- " movq 40(%0), %%mm1\n"
30702- " movq 48(%0), %%mm2\n"
30703- " movq 56(%0), %%mm3\n"
30704- " movq %%mm0, 32(%1)\n"
30705- " movq %%mm1, 40(%1)\n"
30706- " movq %%mm2, 48(%1)\n"
30707- " movq %%mm3, 56(%1)\n"
30708+ "1: prefetch 320(%1)\n"
30709+ "2: movq (%1), %%mm0\n"
30710+ " movq 8(%1), %%mm1\n"
30711+ " movq 16(%1), %%mm2\n"
30712+ " movq 24(%1), %%mm3\n"
30713+ " movq %%mm0, (%2)\n"
30714+ " movq %%mm1, 8(%2)\n"
30715+ " movq %%mm2, 16(%2)\n"
30716+ " movq %%mm3, 24(%2)\n"
30717+ " movq 32(%1), %%mm0\n"
30718+ " movq 40(%1), %%mm1\n"
30719+ " movq 48(%1), %%mm2\n"
30720+ " movq 56(%1), %%mm3\n"
30721+ " movq %%mm0, 32(%2)\n"
30722+ " movq %%mm1, 40(%2)\n"
30723+ " movq %%mm2, 48(%2)\n"
30724+ " movq %%mm3, 56(%2)\n"
30725 ".section .fixup, \"ax\"\n"
30726- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30727+ "3:\n"
30728+
30729+#ifdef CONFIG_PAX_KERNEXEC
30730+ " movl %%cr0, %0\n"
30731+ " movl %0, %%eax\n"
30732+ " andl $0xFFFEFFFF, %%eax\n"
30733+ " movl %%eax, %%cr0\n"
30734+#endif
30735+
30736+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30737+
30738+#ifdef CONFIG_PAX_KERNEXEC
30739+ " movl %0, %%cr0\n"
30740+#endif
30741+
30742 " jmp 2b\n"
30743 ".previous\n"
30744 _ASM_EXTABLE(1b, 3b)
30745- : : "r" (from), "r" (to) : "memory");
30746+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30747
30748 from += 64;
30749 to += 64;
30750diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30751index f6d13ee..d789440 100644
30752--- a/arch/x86/lib/msr-reg.S
30753+++ b/arch/x86/lib/msr-reg.S
30754@@ -3,6 +3,7 @@
30755 #include <asm/dwarf2.h>
30756 #include <asm/asm.h>
30757 #include <asm/msr.h>
30758+#include <asm/alternative-asm.h>
30759
30760 #ifdef CONFIG_X86_64
30761 /*
30762@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30763 movl %edi, 28(%r10)
30764 popq_cfi %rbp
30765 popq_cfi %rbx
30766+ pax_force_retaddr
30767 ret
30768 3:
30769 CFI_RESTORE_STATE
30770diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30771index fc6ba17..d4d989d 100644
30772--- a/arch/x86/lib/putuser.S
30773+++ b/arch/x86/lib/putuser.S
30774@@ -16,7 +16,9 @@
30775 #include <asm/errno.h>
30776 #include <asm/asm.h>
30777 #include <asm/smap.h>
30778-
30779+#include <asm/segment.h>
30780+#include <asm/pgtable.h>
30781+#include <asm/alternative-asm.h>
30782
30783 /*
30784 * __put_user_X
30785@@ -30,57 +32,125 @@
30786 * as they get called from within inline assembly.
30787 */
30788
30789-#define ENTER CFI_STARTPROC ; \
30790- GET_THREAD_INFO(%_ASM_BX)
30791-#define EXIT ASM_CLAC ; \
30792- ret ; \
30793+#define ENTER CFI_STARTPROC
30794+#define EXIT ASM_CLAC ; \
30795+ pax_force_retaddr ; \
30796+ ret ; \
30797 CFI_ENDPROC
30798
30799+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30800+#define _DEST %_ASM_CX,%_ASM_BX
30801+#else
30802+#define _DEST %_ASM_CX
30803+#endif
30804+
30805+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30806+#define __copyuser_seg gs;
30807+#else
30808+#define __copyuser_seg
30809+#endif
30810+
30811 .text
30812 ENTRY(__put_user_1)
30813 ENTER
30814+
30815+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30816+ GET_THREAD_INFO(%_ASM_BX)
30817 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30818 jae bad_put_user
30819 ASM_STAC
30820-1: movb %al,(%_ASM_CX)
30821+
30822+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30823+ mov pax_user_shadow_base,%_ASM_BX
30824+ cmp %_ASM_BX,%_ASM_CX
30825+ jb 1234f
30826+ xor %ebx,%ebx
30827+1234:
30828+#endif
30829+
30830+#endif
30831+
30832+1: __copyuser_seg movb %al,(_DEST)
30833 xor %eax,%eax
30834 EXIT
30835 ENDPROC(__put_user_1)
30836
30837 ENTRY(__put_user_2)
30838 ENTER
30839+
30840+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30841+ GET_THREAD_INFO(%_ASM_BX)
30842 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30843 sub $1,%_ASM_BX
30844 cmp %_ASM_BX,%_ASM_CX
30845 jae bad_put_user
30846 ASM_STAC
30847-2: movw %ax,(%_ASM_CX)
30848+
30849+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30850+ mov pax_user_shadow_base,%_ASM_BX
30851+ cmp %_ASM_BX,%_ASM_CX
30852+ jb 1234f
30853+ xor %ebx,%ebx
30854+1234:
30855+#endif
30856+
30857+#endif
30858+
30859+2: __copyuser_seg movw %ax,(_DEST)
30860 xor %eax,%eax
30861 EXIT
30862 ENDPROC(__put_user_2)
30863
30864 ENTRY(__put_user_4)
30865 ENTER
30866+
30867+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30868+ GET_THREAD_INFO(%_ASM_BX)
30869 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30870 sub $3,%_ASM_BX
30871 cmp %_ASM_BX,%_ASM_CX
30872 jae bad_put_user
30873 ASM_STAC
30874-3: movl %eax,(%_ASM_CX)
30875+
30876+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30877+ mov pax_user_shadow_base,%_ASM_BX
30878+ cmp %_ASM_BX,%_ASM_CX
30879+ jb 1234f
30880+ xor %ebx,%ebx
30881+1234:
30882+#endif
30883+
30884+#endif
30885+
30886+3: __copyuser_seg movl %eax,(_DEST)
30887 xor %eax,%eax
30888 EXIT
30889 ENDPROC(__put_user_4)
30890
30891 ENTRY(__put_user_8)
30892 ENTER
30893+
30894+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30895+ GET_THREAD_INFO(%_ASM_BX)
30896 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30897 sub $7,%_ASM_BX
30898 cmp %_ASM_BX,%_ASM_CX
30899 jae bad_put_user
30900 ASM_STAC
30901-4: mov %_ASM_AX,(%_ASM_CX)
30902+
30903+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30904+ mov pax_user_shadow_base,%_ASM_BX
30905+ cmp %_ASM_BX,%_ASM_CX
30906+ jb 1234f
30907+ xor %ebx,%ebx
30908+1234:
30909+#endif
30910+
30911+#endif
30912+
30913+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30914 #ifdef CONFIG_X86_32
30915-5: movl %edx,4(%_ASM_CX)
30916+5: __copyuser_seg movl %edx,4(_DEST)
30917 #endif
30918 xor %eax,%eax
30919 EXIT
30920diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30921index 1cad221..de671ee 100644
30922--- a/arch/x86/lib/rwlock.S
30923+++ b/arch/x86/lib/rwlock.S
30924@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30925 FRAME
30926 0: LOCK_PREFIX
30927 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30928+
30929+#ifdef CONFIG_PAX_REFCOUNT
30930+ jno 1234f
30931+ LOCK_PREFIX
30932+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30933+ int $4
30934+1234:
30935+ _ASM_EXTABLE(1234b, 1234b)
30936+#endif
30937+
30938 1: rep; nop
30939 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30940 jne 1b
30941 LOCK_PREFIX
30942 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30943+
30944+#ifdef CONFIG_PAX_REFCOUNT
30945+ jno 1234f
30946+ LOCK_PREFIX
30947+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30948+ int $4
30949+1234:
30950+ _ASM_EXTABLE(1234b, 1234b)
30951+#endif
30952+
30953 jnz 0b
30954 ENDFRAME
30955+ pax_force_retaddr
30956 ret
30957 CFI_ENDPROC
30958 END(__write_lock_failed)
30959@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30960 FRAME
30961 0: LOCK_PREFIX
30962 READ_LOCK_SIZE(inc) (%__lock_ptr)
30963+
30964+#ifdef CONFIG_PAX_REFCOUNT
30965+ jno 1234f
30966+ LOCK_PREFIX
30967+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30968+ int $4
30969+1234:
30970+ _ASM_EXTABLE(1234b, 1234b)
30971+#endif
30972+
30973 1: rep; nop
30974 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30975 js 1b
30976 LOCK_PREFIX
30977 READ_LOCK_SIZE(dec) (%__lock_ptr)
30978+
30979+#ifdef CONFIG_PAX_REFCOUNT
30980+ jno 1234f
30981+ LOCK_PREFIX
30982+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30983+ int $4
30984+1234:
30985+ _ASM_EXTABLE(1234b, 1234b)
30986+#endif
30987+
30988 js 0b
30989 ENDFRAME
30990+ pax_force_retaddr
30991 ret
30992 CFI_ENDPROC
30993 END(__read_lock_failed)
30994diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30995index 5dff5f0..cadebf4 100644
30996--- a/arch/x86/lib/rwsem.S
30997+++ b/arch/x86/lib/rwsem.S
30998@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30999 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31000 CFI_RESTORE __ASM_REG(dx)
31001 restore_common_regs
31002+ pax_force_retaddr
31003 ret
31004 CFI_ENDPROC
31005 ENDPROC(call_rwsem_down_read_failed)
31006@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31007 movq %rax,%rdi
31008 call rwsem_down_write_failed
31009 restore_common_regs
31010+ pax_force_retaddr
31011 ret
31012 CFI_ENDPROC
31013 ENDPROC(call_rwsem_down_write_failed)
31014@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31015 movq %rax,%rdi
31016 call rwsem_wake
31017 restore_common_regs
31018-1: ret
31019+1: pax_force_retaddr
31020+ ret
31021 CFI_ENDPROC
31022 ENDPROC(call_rwsem_wake)
31023
31024@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31025 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31026 CFI_RESTORE __ASM_REG(dx)
31027 restore_common_regs
31028+ pax_force_retaddr
31029 ret
31030 CFI_ENDPROC
31031 ENDPROC(call_rwsem_downgrade_wake)
31032diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31033index a63efd6..8149fbe 100644
31034--- a/arch/x86/lib/thunk_64.S
31035+++ b/arch/x86/lib/thunk_64.S
31036@@ -8,6 +8,7 @@
31037 #include <linux/linkage.h>
31038 #include <asm/dwarf2.h>
31039 #include <asm/calling.h>
31040+#include <asm/alternative-asm.h>
31041
31042 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31043 .macro THUNK name, func, put_ret_addr_in_rdi=0
31044@@ -15,11 +16,11 @@
31045 \name:
31046 CFI_STARTPROC
31047
31048- /* this one pushes 9 elems, the next one would be %rIP */
31049- SAVE_ARGS
31050+ /* this one pushes 15+1 elems, the next one would be %rIP */
31051+ SAVE_ARGS 8
31052
31053 .if \put_ret_addr_in_rdi
31054- movq_cfi_restore 9*8, rdi
31055+ movq_cfi_restore RIP, rdi
31056 .endif
31057
31058 call \func
31059@@ -38,8 +39,9 @@
31060
31061 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31062 CFI_STARTPROC
31063- SAVE_ARGS
31064+ SAVE_ARGS 8
31065 restore:
31066- RESTORE_ARGS
31067+ RESTORE_ARGS 1,8
31068+ pax_force_retaddr
31069 ret
31070 CFI_ENDPROC
31071diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31072index e2f5e21..4b22130 100644
31073--- a/arch/x86/lib/usercopy_32.c
31074+++ b/arch/x86/lib/usercopy_32.c
31075@@ -42,11 +42,13 @@ do { \
31076 int __d0; \
31077 might_fault(); \
31078 __asm__ __volatile__( \
31079+ __COPYUSER_SET_ES \
31080 ASM_STAC "\n" \
31081 "0: rep; stosl\n" \
31082 " movl %2,%0\n" \
31083 "1: rep; stosb\n" \
31084 "2: " ASM_CLAC "\n" \
31085+ __COPYUSER_RESTORE_ES \
31086 ".section .fixup,\"ax\"\n" \
31087 "3: lea 0(%2,%0,4),%0\n" \
31088 " jmp 2b\n" \
31089@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31090
31091 #ifdef CONFIG_X86_INTEL_USERCOPY
31092 static unsigned long
31093-__copy_user_intel(void __user *to, const void *from, unsigned long size)
31094+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31095 {
31096 int d0, d1;
31097 __asm__ __volatile__(
31098@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31099 " .align 2,0x90\n"
31100 "3: movl 0(%4), %%eax\n"
31101 "4: movl 4(%4), %%edx\n"
31102- "5: movl %%eax, 0(%3)\n"
31103- "6: movl %%edx, 4(%3)\n"
31104+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31105+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31106 "7: movl 8(%4), %%eax\n"
31107 "8: movl 12(%4),%%edx\n"
31108- "9: movl %%eax, 8(%3)\n"
31109- "10: movl %%edx, 12(%3)\n"
31110+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31111+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31112 "11: movl 16(%4), %%eax\n"
31113 "12: movl 20(%4), %%edx\n"
31114- "13: movl %%eax, 16(%3)\n"
31115- "14: movl %%edx, 20(%3)\n"
31116+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31117+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31118 "15: movl 24(%4), %%eax\n"
31119 "16: movl 28(%4), %%edx\n"
31120- "17: movl %%eax, 24(%3)\n"
31121- "18: movl %%edx, 28(%3)\n"
31122+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31123+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31124 "19: movl 32(%4), %%eax\n"
31125 "20: movl 36(%4), %%edx\n"
31126- "21: movl %%eax, 32(%3)\n"
31127- "22: movl %%edx, 36(%3)\n"
31128+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31129+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31130 "23: movl 40(%4), %%eax\n"
31131 "24: movl 44(%4), %%edx\n"
31132- "25: movl %%eax, 40(%3)\n"
31133- "26: movl %%edx, 44(%3)\n"
31134+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31135+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31136 "27: movl 48(%4), %%eax\n"
31137 "28: movl 52(%4), %%edx\n"
31138- "29: movl %%eax, 48(%3)\n"
31139- "30: movl %%edx, 52(%3)\n"
31140+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31141+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31142 "31: movl 56(%4), %%eax\n"
31143 "32: movl 60(%4), %%edx\n"
31144- "33: movl %%eax, 56(%3)\n"
31145- "34: movl %%edx, 60(%3)\n"
31146+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31147+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31148 " addl $-64, %0\n"
31149 " addl $64, %4\n"
31150 " addl $64, %3\n"
31151@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31152 " shrl $2, %0\n"
31153 " andl $3, %%eax\n"
31154 " cld\n"
31155+ __COPYUSER_SET_ES
31156 "99: rep; movsl\n"
31157 "36: movl %%eax, %0\n"
31158 "37: rep; movsb\n"
31159 "100:\n"
31160+ __COPYUSER_RESTORE_ES
31161+ ".section .fixup,\"ax\"\n"
31162+ "101: lea 0(%%eax,%0,4),%0\n"
31163+ " jmp 100b\n"
31164+ ".previous\n"
31165+ _ASM_EXTABLE(1b,100b)
31166+ _ASM_EXTABLE(2b,100b)
31167+ _ASM_EXTABLE(3b,100b)
31168+ _ASM_EXTABLE(4b,100b)
31169+ _ASM_EXTABLE(5b,100b)
31170+ _ASM_EXTABLE(6b,100b)
31171+ _ASM_EXTABLE(7b,100b)
31172+ _ASM_EXTABLE(8b,100b)
31173+ _ASM_EXTABLE(9b,100b)
31174+ _ASM_EXTABLE(10b,100b)
31175+ _ASM_EXTABLE(11b,100b)
31176+ _ASM_EXTABLE(12b,100b)
31177+ _ASM_EXTABLE(13b,100b)
31178+ _ASM_EXTABLE(14b,100b)
31179+ _ASM_EXTABLE(15b,100b)
31180+ _ASM_EXTABLE(16b,100b)
31181+ _ASM_EXTABLE(17b,100b)
31182+ _ASM_EXTABLE(18b,100b)
31183+ _ASM_EXTABLE(19b,100b)
31184+ _ASM_EXTABLE(20b,100b)
31185+ _ASM_EXTABLE(21b,100b)
31186+ _ASM_EXTABLE(22b,100b)
31187+ _ASM_EXTABLE(23b,100b)
31188+ _ASM_EXTABLE(24b,100b)
31189+ _ASM_EXTABLE(25b,100b)
31190+ _ASM_EXTABLE(26b,100b)
31191+ _ASM_EXTABLE(27b,100b)
31192+ _ASM_EXTABLE(28b,100b)
31193+ _ASM_EXTABLE(29b,100b)
31194+ _ASM_EXTABLE(30b,100b)
31195+ _ASM_EXTABLE(31b,100b)
31196+ _ASM_EXTABLE(32b,100b)
31197+ _ASM_EXTABLE(33b,100b)
31198+ _ASM_EXTABLE(34b,100b)
31199+ _ASM_EXTABLE(35b,100b)
31200+ _ASM_EXTABLE(36b,100b)
31201+ _ASM_EXTABLE(37b,100b)
31202+ _ASM_EXTABLE(99b,101b)
31203+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
31204+ : "1"(to), "2"(from), "0"(size)
31205+ : "eax", "edx", "memory");
31206+ return size;
31207+}
31208+
31209+static unsigned long
31210+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31211+{
31212+ int d0, d1;
31213+ __asm__ __volatile__(
31214+ " .align 2,0x90\n"
31215+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31216+ " cmpl $67, %0\n"
31217+ " jbe 3f\n"
31218+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31219+ " .align 2,0x90\n"
31220+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31221+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31222+ "5: movl %%eax, 0(%3)\n"
31223+ "6: movl %%edx, 4(%3)\n"
31224+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31225+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31226+ "9: movl %%eax, 8(%3)\n"
31227+ "10: movl %%edx, 12(%3)\n"
31228+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31229+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31230+ "13: movl %%eax, 16(%3)\n"
31231+ "14: movl %%edx, 20(%3)\n"
31232+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31233+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31234+ "17: movl %%eax, 24(%3)\n"
31235+ "18: movl %%edx, 28(%3)\n"
31236+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31237+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31238+ "21: movl %%eax, 32(%3)\n"
31239+ "22: movl %%edx, 36(%3)\n"
31240+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31241+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31242+ "25: movl %%eax, 40(%3)\n"
31243+ "26: movl %%edx, 44(%3)\n"
31244+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31245+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31246+ "29: movl %%eax, 48(%3)\n"
31247+ "30: movl %%edx, 52(%3)\n"
31248+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31249+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31250+ "33: movl %%eax, 56(%3)\n"
31251+ "34: movl %%edx, 60(%3)\n"
31252+ " addl $-64, %0\n"
31253+ " addl $64, %4\n"
31254+ " addl $64, %3\n"
31255+ " cmpl $63, %0\n"
31256+ " ja 1b\n"
31257+ "35: movl %0, %%eax\n"
31258+ " shrl $2, %0\n"
31259+ " andl $3, %%eax\n"
31260+ " cld\n"
31261+ "99: rep; "__copyuser_seg" movsl\n"
31262+ "36: movl %%eax, %0\n"
31263+ "37: rep; "__copyuser_seg" movsb\n"
31264+ "100:\n"
31265 ".section .fixup,\"ax\"\n"
31266 "101: lea 0(%%eax,%0,4),%0\n"
31267 " jmp 100b\n"
31268@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31269 int d0, d1;
31270 __asm__ __volatile__(
31271 " .align 2,0x90\n"
31272- "0: movl 32(%4), %%eax\n"
31273+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31274 " cmpl $67, %0\n"
31275 " jbe 2f\n"
31276- "1: movl 64(%4), %%eax\n"
31277+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31278 " .align 2,0x90\n"
31279- "2: movl 0(%4), %%eax\n"
31280- "21: movl 4(%4), %%edx\n"
31281+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31282+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31283 " movl %%eax, 0(%3)\n"
31284 " movl %%edx, 4(%3)\n"
31285- "3: movl 8(%4), %%eax\n"
31286- "31: movl 12(%4),%%edx\n"
31287+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31288+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31289 " movl %%eax, 8(%3)\n"
31290 " movl %%edx, 12(%3)\n"
31291- "4: movl 16(%4), %%eax\n"
31292- "41: movl 20(%4), %%edx\n"
31293+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31294+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31295 " movl %%eax, 16(%3)\n"
31296 " movl %%edx, 20(%3)\n"
31297- "10: movl 24(%4), %%eax\n"
31298- "51: movl 28(%4), %%edx\n"
31299+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31300+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31301 " movl %%eax, 24(%3)\n"
31302 " movl %%edx, 28(%3)\n"
31303- "11: movl 32(%4), %%eax\n"
31304- "61: movl 36(%4), %%edx\n"
31305+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31306+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31307 " movl %%eax, 32(%3)\n"
31308 " movl %%edx, 36(%3)\n"
31309- "12: movl 40(%4), %%eax\n"
31310- "71: movl 44(%4), %%edx\n"
31311+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31312+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31313 " movl %%eax, 40(%3)\n"
31314 " movl %%edx, 44(%3)\n"
31315- "13: movl 48(%4), %%eax\n"
31316- "81: movl 52(%4), %%edx\n"
31317+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31318+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31319 " movl %%eax, 48(%3)\n"
31320 " movl %%edx, 52(%3)\n"
31321- "14: movl 56(%4), %%eax\n"
31322- "91: movl 60(%4), %%edx\n"
31323+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31324+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31325 " movl %%eax, 56(%3)\n"
31326 " movl %%edx, 60(%3)\n"
31327 " addl $-64, %0\n"
31328@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31329 " shrl $2, %0\n"
31330 " andl $3, %%eax\n"
31331 " cld\n"
31332- "6: rep; movsl\n"
31333+ "6: rep; "__copyuser_seg" movsl\n"
31334 " movl %%eax,%0\n"
31335- "7: rep; movsb\n"
31336+ "7: rep; "__copyuser_seg" movsb\n"
31337 "8:\n"
31338 ".section .fixup,\"ax\"\n"
31339 "9: lea 0(%%eax,%0,4),%0\n"
31340@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31341
31342 __asm__ __volatile__(
31343 " .align 2,0x90\n"
31344- "0: movl 32(%4), %%eax\n"
31345+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31346 " cmpl $67, %0\n"
31347 " jbe 2f\n"
31348- "1: movl 64(%4), %%eax\n"
31349+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31350 " .align 2,0x90\n"
31351- "2: movl 0(%4), %%eax\n"
31352- "21: movl 4(%4), %%edx\n"
31353+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31354+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31355 " movnti %%eax, 0(%3)\n"
31356 " movnti %%edx, 4(%3)\n"
31357- "3: movl 8(%4), %%eax\n"
31358- "31: movl 12(%4),%%edx\n"
31359+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31360+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31361 " movnti %%eax, 8(%3)\n"
31362 " movnti %%edx, 12(%3)\n"
31363- "4: movl 16(%4), %%eax\n"
31364- "41: movl 20(%4), %%edx\n"
31365+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31366+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31367 " movnti %%eax, 16(%3)\n"
31368 " movnti %%edx, 20(%3)\n"
31369- "10: movl 24(%4), %%eax\n"
31370- "51: movl 28(%4), %%edx\n"
31371+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31372+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31373 " movnti %%eax, 24(%3)\n"
31374 " movnti %%edx, 28(%3)\n"
31375- "11: movl 32(%4), %%eax\n"
31376- "61: movl 36(%4), %%edx\n"
31377+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31378+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31379 " movnti %%eax, 32(%3)\n"
31380 " movnti %%edx, 36(%3)\n"
31381- "12: movl 40(%4), %%eax\n"
31382- "71: movl 44(%4), %%edx\n"
31383+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31384+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31385 " movnti %%eax, 40(%3)\n"
31386 " movnti %%edx, 44(%3)\n"
31387- "13: movl 48(%4), %%eax\n"
31388- "81: movl 52(%4), %%edx\n"
31389+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31390+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31391 " movnti %%eax, 48(%3)\n"
31392 " movnti %%edx, 52(%3)\n"
31393- "14: movl 56(%4), %%eax\n"
31394- "91: movl 60(%4), %%edx\n"
31395+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31396+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31397 " movnti %%eax, 56(%3)\n"
31398 " movnti %%edx, 60(%3)\n"
31399 " addl $-64, %0\n"
31400@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31401 " shrl $2, %0\n"
31402 " andl $3, %%eax\n"
31403 " cld\n"
31404- "6: rep; movsl\n"
31405+ "6: rep; "__copyuser_seg" movsl\n"
31406 " movl %%eax,%0\n"
31407- "7: rep; movsb\n"
31408+ "7: rep; "__copyuser_seg" movsb\n"
31409 "8:\n"
31410 ".section .fixup,\"ax\"\n"
31411 "9: lea 0(%%eax,%0,4),%0\n"
31412@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31413
31414 __asm__ __volatile__(
31415 " .align 2,0x90\n"
31416- "0: movl 32(%4), %%eax\n"
31417+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31418 " cmpl $67, %0\n"
31419 " jbe 2f\n"
31420- "1: movl 64(%4), %%eax\n"
31421+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31422 " .align 2,0x90\n"
31423- "2: movl 0(%4), %%eax\n"
31424- "21: movl 4(%4), %%edx\n"
31425+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31426+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31427 " movnti %%eax, 0(%3)\n"
31428 " movnti %%edx, 4(%3)\n"
31429- "3: movl 8(%4), %%eax\n"
31430- "31: movl 12(%4),%%edx\n"
31431+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31432+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31433 " movnti %%eax, 8(%3)\n"
31434 " movnti %%edx, 12(%3)\n"
31435- "4: movl 16(%4), %%eax\n"
31436- "41: movl 20(%4), %%edx\n"
31437+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31438+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31439 " movnti %%eax, 16(%3)\n"
31440 " movnti %%edx, 20(%3)\n"
31441- "10: movl 24(%4), %%eax\n"
31442- "51: movl 28(%4), %%edx\n"
31443+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31444+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31445 " movnti %%eax, 24(%3)\n"
31446 " movnti %%edx, 28(%3)\n"
31447- "11: movl 32(%4), %%eax\n"
31448- "61: movl 36(%4), %%edx\n"
31449+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31450+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31451 " movnti %%eax, 32(%3)\n"
31452 " movnti %%edx, 36(%3)\n"
31453- "12: movl 40(%4), %%eax\n"
31454- "71: movl 44(%4), %%edx\n"
31455+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31456+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31457 " movnti %%eax, 40(%3)\n"
31458 " movnti %%edx, 44(%3)\n"
31459- "13: movl 48(%4), %%eax\n"
31460- "81: movl 52(%4), %%edx\n"
31461+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31462+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31463 " movnti %%eax, 48(%3)\n"
31464 " movnti %%edx, 52(%3)\n"
31465- "14: movl 56(%4), %%eax\n"
31466- "91: movl 60(%4), %%edx\n"
31467+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31468+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31469 " movnti %%eax, 56(%3)\n"
31470 " movnti %%edx, 60(%3)\n"
31471 " addl $-64, %0\n"
31472@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31473 " shrl $2, %0\n"
31474 " andl $3, %%eax\n"
31475 " cld\n"
31476- "6: rep; movsl\n"
31477+ "6: rep; "__copyuser_seg" movsl\n"
31478 " movl %%eax,%0\n"
31479- "7: rep; movsb\n"
31480+ "7: rep; "__copyuser_seg" movsb\n"
31481 "8:\n"
31482 ".section .fixup,\"ax\"\n"
31483 "9: lea 0(%%eax,%0,4),%0\n"
31484@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31485 */
31486 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31487 unsigned long size);
31488-unsigned long __copy_user_intel(void __user *to, const void *from,
31489+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31490+ unsigned long size);
31491+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31492 unsigned long size);
31493 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31494 const void __user *from, unsigned long size);
31495 #endif /* CONFIG_X86_INTEL_USERCOPY */
31496
31497 /* Generic arbitrary sized copy. */
31498-#define __copy_user(to, from, size) \
31499+#define __copy_user(to, from, size, prefix, set, restore) \
31500 do { \
31501 int __d0, __d1, __d2; \
31502 __asm__ __volatile__( \
31503+ set \
31504 " cmp $7,%0\n" \
31505 " jbe 1f\n" \
31506 " movl %1,%0\n" \
31507 " negl %0\n" \
31508 " andl $7,%0\n" \
31509 " subl %0,%3\n" \
31510- "4: rep; movsb\n" \
31511+ "4: rep; "prefix"movsb\n" \
31512 " movl %3,%0\n" \
31513 " shrl $2,%0\n" \
31514 " andl $3,%3\n" \
31515 " .align 2,0x90\n" \
31516- "0: rep; movsl\n" \
31517+ "0: rep; "prefix"movsl\n" \
31518 " movl %3,%0\n" \
31519- "1: rep; movsb\n" \
31520+ "1: rep; "prefix"movsb\n" \
31521 "2:\n" \
31522+ restore \
31523 ".section .fixup,\"ax\"\n" \
31524 "5: addl %3,%0\n" \
31525 " jmp 2b\n" \
31526@@ -538,14 +650,14 @@ do { \
31527 " negl %0\n" \
31528 " andl $7,%0\n" \
31529 " subl %0,%3\n" \
31530- "4: rep; movsb\n" \
31531+ "4: rep; "__copyuser_seg"movsb\n" \
31532 " movl %3,%0\n" \
31533 " shrl $2,%0\n" \
31534 " andl $3,%3\n" \
31535 " .align 2,0x90\n" \
31536- "0: rep; movsl\n" \
31537+ "0: rep; "__copyuser_seg"movsl\n" \
31538 " movl %3,%0\n" \
31539- "1: rep; movsb\n" \
31540+ "1: rep; "__copyuser_seg"movsb\n" \
31541 "2:\n" \
31542 ".section .fixup,\"ax\"\n" \
31543 "5: addl %3,%0\n" \
31544@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31545 {
31546 stac();
31547 if (movsl_is_ok(to, from, n))
31548- __copy_user(to, from, n);
31549+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31550 else
31551- n = __copy_user_intel(to, from, n);
31552+ n = __generic_copy_to_user_intel(to, from, n);
31553 clac();
31554 return n;
31555 }
31556@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31557 {
31558 stac();
31559 if (movsl_is_ok(to, from, n))
31560- __copy_user(to, from, n);
31561+ __copy_user(to, from, n, __copyuser_seg, "", "");
31562 else
31563- n = __copy_user_intel((void __user *)to,
31564- (const void *)from, n);
31565+ n = __generic_copy_from_user_intel(to, from, n);
31566 clac();
31567 return n;
31568 }
31569@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31570 if (n > 64 && cpu_has_xmm2)
31571 n = __copy_user_intel_nocache(to, from, n);
31572 else
31573- __copy_user(to, from, n);
31574+ __copy_user(to, from, n, __copyuser_seg, "", "");
31575 #else
31576- __copy_user(to, from, n);
31577+ __copy_user(to, from, n, __copyuser_seg, "", "");
31578 #endif
31579 clac();
31580 return n;
31581 }
31582 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31583
31584-/**
31585- * copy_to_user: - Copy a block of data into user space.
31586- * @to: Destination address, in user space.
31587- * @from: Source address, in kernel space.
31588- * @n: Number of bytes to copy.
31589- *
31590- * Context: User context only. This function may sleep.
31591- *
31592- * Copy data from kernel space to user space.
31593- *
31594- * Returns number of bytes that could not be copied.
31595- * On success, this will be zero.
31596- */
31597-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31598+#ifdef CONFIG_PAX_MEMORY_UDEREF
31599+void __set_fs(mm_segment_t x)
31600 {
31601- if (access_ok(VERIFY_WRITE, to, n))
31602- n = __copy_to_user(to, from, n);
31603- return n;
31604+ switch (x.seg) {
31605+ case 0:
31606+ loadsegment(gs, 0);
31607+ break;
31608+ case TASK_SIZE_MAX:
31609+ loadsegment(gs, __USER_DS);
31610+ break;
31611+ case -1UL:
31612+ loadsegment(gs, __KERNEL_DS);
31613+ break;
31614+ default:
31615+ BUG();
31616+ }
31617 }
31618-EXPORT_SYMBOL(_copy_to_user);
31619+EXPORT_SYMBOL(__set_fs);
31620
31621-/**
31622- * copy_from_user: - Copy a block of data from user space.
31623- * @to: Destination address, in kernel space.
31624- * @from: Source address, in user space.
31625- * @n: Number of bytes to copy.
31626- *
31627- * Context: User context only. This function may sleep.
31628- *
31629- * Copy data from user space to kernel space.
31630- *
31631- * Returns number of bytes that could not be copied.
31632- * On success, this will be zero.
31633- *
31634- * If some data could not be copied, this function will pad the copied
31635- * data to the requested size using zero bytes.
31636- */
31637-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31638+void set_fs(mm_segment_t x)
31639 {
31640- if (access_ok(VERIFY_READ, from, n))
31641- n = __copy_from_user(to, from, n);
31642- else
31643- memset(to, 0, n);
31644- return n;
31645+ current_thread_info()->addr_limit = x;
31646+ __set_fs(x);
31647 }
31648-EXPORT_SYMBOL(_copy_from_user);
31649+EXPORT_SYMBOL(set_fs);
31650+#endif
31651diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31652index c905e89..01ab928 100644
31653--- a/arch/x86/lib/usercopy_64.c
31654+++ b/arch/x86/lib/usercopy_64.c
31655@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31656 might_fault();
31657 /* no memory constraint because it doesn't change any memory gcc knows
31658 about */
31659+ pax_open_userland();
31660 stac();
31661 asm volatile(
31662 " testq %[size8],%[size8]\n"
31663@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31664 _ASM_EXTABLE(0b,3b)
31665 _ASM_EXTABLE(1b,2b)
31666 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31667- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31668+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31669 [zero] "r" (0UL), [eight] "r" (8UL));
31670 clac();
31671+ pax_close_userland();
31672 return size;
31673 }
31674 EXPORT_SYMBOL(__clear_user);
31675@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31676 }
31677 EXPORT_SYMBOL(clear_user);
31678
31679-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31680+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31681 {
31682- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31683- return copy_user_generic((__force void *)to, (__force void *)from, len);
31684- }
31685- return len;
31686+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31687+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31688+ return len;
31689 }
31690 EXPORT_SYMBOL(copy_in_user);
31691
31692@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31693 * it is not necessary to optimize tail handling.
31694 */
31695 __visible unsigned long
31696-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31697+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31698 {
31699 char c;
31700 unsigned zero_len;
31701
31702+ clac();
31703+ pax_close_userland();
31704 for (; len; --len, to++) {
31705 if (__get_user_nocheck(c, from++, sizeof(char)))
31706 break;
31707@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31708 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31709 if (__put_user_nocheck(c, to++, sizeof(char)))
31710 break;
31711- clac();
31712 return len;
31713 }
31714diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31715index 6a19ad9..1c48f9a 100644
31716--- a/arch/x86/mm/Makefile
31717+++ b/arch/x86/mm/Makefile
31718@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31719 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31720
31721 obj-$(CONFIG_MEMTEST) += memtest.o
31722+
31723+quote:="
31724+obj-$(CONFIG_X86_64) += uderef_64.o
31725+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31726diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31727index 903ec1e..c4166b2 100644
31728--- a/arch/x86/mm/extable.c
31729+++ b/arch/x86/mm/extable.c
31730@@ -6,12 +6,24 @@
31731 static inline unsigned long
31732 ex_insn_addr(const struct exception_table_entry *x)
31733 {
31734- return (unsigned long)&x->insn + x->insn;
31735+ unsigned long reloc = 0;
31736+
31737+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31738+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31739+#endif
31740+
31741+ return (unsigned long)&x->insn + x->insn + reloc;
31742 }
31743 static inline unsigned long
31744 ex_fixup_addr(const struct exception_table_entry *x)
31745 {
31746- return (unsigned long)&x->fixup + x->fixup;
31747+ unsigned long reloc = 0;
31748+
31749+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31750+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31751+#endif
31752+
31753+ return (unsigned long)&x->fixup + x->fixup + reloc;
31754 }
31755
31756 int fixup_exception(struct pt_regs *regs)
31757@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31758 unsigned long new_ip;
31759
31760 #ifdef CONFIG_PNPBIOS
31761- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31762+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31763 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31764 extern u32 pnp_bios_is_utter_crap;
31765 pnp_bios_is_utter_crap = 1;
31766@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31767 i += 4;
31768 p->fixup -= i;
31769 i += 4;
31770+
31771+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31772+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31773+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31774+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31775+#endif
31776+
31777 }
31778 }
31779
31780diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31781index a10c8c7..35a5abb 100644
31782--- a/arch/x86/mm/fault.c
31783+++ b/arch/x86/mm/fault.c
31784@@ -14,11 +14,18 @@
31785 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31786 #include <linux/prefetch.h> /* prefetchw */
31787 #include <linux/context_tracking.h> /* exception_enter(), ... */
31788+#include <linux/unistd.h>
31789+#include <linux/compiler.h>
31790
31791 #include <asm/traps.h> /* dotraplinkage, ... */
31792 #include <asm/pgalloc.h> /* pgd_*(), ... */
31793 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31794 #include <asm/fixmap.h> /* VSYSCALL_START */
31795+#include <asm/tlbflush.h>
31796+
31797+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31798+#include <asm/stacktrace.h>
31799+#endif
31800
31801 #define CREATE_TRACE_POINTS
31802 #include <asm/trace/exceptions.h>
31803@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31804 int ret = 0;
31805
31806 /* kprobe_running() needs smp_processor_id() */
31807- if (kprobes_built_in() && !user_mode_vm(regs)) {
31808+ if (kprobes_built_in() && !user_mode(regs)) {
31809 preempt_disable();
31810 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31811 ret = 1;
31812@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31813 return !instr_lo || (instr_lo>>1) == 1;
31814 case 0x00:
31815 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31816- if (probe_kernel_address(instr, opcode))
31817+ if (user_mode(regs)) {
31818+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31819+ return 0;
31820+ } else if (probe_kernel_address(instr, opcode))
31821 return 0;
31822
31823 *prefetch = (instr_lo == 0xF) &&
31824@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31825 while (instr < max_instr) {
31826 unsigned char opcode;
31827
31828- if (probe_kernel_address(instr, opcode))
31829+ if (user_mode(regs)) {
31830+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31831+ break;
31832+ } else if (probe_kernel_address(instr, opcode))
31833 break;
31834
31835 instr++;
31836@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31837 force_sig_info(si_signo, &info, tsk);
31838 }
31839
31840+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31841+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31842+#endif
31843+
31844+#ifdef CONFIG_PAX_EMUTRAMP
31845+static int pax_handle_fetch_fault(struct pt_regs *regs);
31846+#endif
31847+
31848+#ifdef CONFIG_PAX_PAGEEXEC
31849+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31850+{
31851+ pgd_t *pgd;
31852+ pud_t *pud;
31853+ pmd_t *pmd;
31854+
31855+ pgd = pgd_offset(mm, address);
31856+ if (!pgd_present(*pgd))
31857+ return NULL;
31858+ pud = pud_offset(pgd, address);
31859+ if (!pud_present(*pud))
31860+ return NULL;
31861+ pmd = pmd_offset(pud, address);
31862+ if (!pmd_present(*pmd))
31863+ return NULL;
31864+ return pmd;
31865+}
31866+#endif
31867+
31868 DEFINE_SPINLOCK(pgd_lock);
31869 LIST_HEAD(pgd_list);
31870
31871@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31872 for (address = VMALLOC_START & PMD_MASK;
31873 address >= TASK_SIZE && address < FIXADDR_TOP;
31874 address += PMD_SIZE) {
31875+
31876+#ifdef CONFIG_PAX_PER_CPU_PGD
31877+ unsigned long cpu;
31878+#else
31879 struct page *page;
31880+#endif
31881
31882 spin_lock(&pgd_lock);
31883+
31884+#ifdef CONFIG_PAX_PER_CPU_PGD
31885+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31886+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31887+ pmd_t *ret;
31888+
31889+ ret = vmalloc_sync_one(pgd, address);
31890+ if (!ret)
31891+ break;
31892+ pgd = get_cpu_pgd(cpu, kernel);
31893+#else
31894 list_for_each_entry(page, &pgd_list, lru) {
31895+ pgd_t *pgd;
31896 spinlock_t *pgt_lock;
31897 pmd_t *ret;
31898
31899@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31900 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31901
31902 spin_lock(pgt_lock);
31903- ret = vmalloc_sync_one(page_address(page), address);
31904+ pgd = page_address(page);
31905+#endif
31906+
31907+ ret = vmalloc_sync_one(pgd, address);
31908+
31909+#ifndef CONFIG_PAX_PER_CPU_PGD
31910 spin_unlock(pgt_lock);
31911+#endif
31912
31913 if (!ret)
31914 break;
31915@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31916 * an interrupt in the middle of a task switch..
31917 */
31918 pgd_paddr = read_cr3();
31919+
31920+#ifdef CONFIG_PAX_PER_CPU_PGD
31921+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31922+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31923+#endif
31924+
31925 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31926 if (!pmd_k)
31927 return -1;
31928@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31929 * happen within a race in page table update. In the later
31930 * case just flush:
31931 */
31932- pgd = pgd_offset(current->active_mm, address);
31933+
31934 pgd_ref = pgd_offset_k(address);
31935 if (pgd_none(*pgd_ref))
31936 return -1;
31937
31938+#ifdef CONFIG_PAX_PER_CPU_PGD
31939+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31940+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31941+ if (pgd_none(*pgd)) {
31942+ set_pgd(pgd, *pgd_ref);
31943+ arch_flush_lazy_mmu_mode();
31944+ } else {
31945+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31946+ }
31947+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31948+#else
31949+ pgd = pgd_offset(current->active_mm, address);
31950+#endif
31951+
31952 if (pgd_none(*pgd)) {
31953 set_pgd(pgd, *pgd_ref);
31954 arch_flush_lazy_mmu_mode();
31955@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31956 static int is_errata100(struct pt_regs *regs, unsigned long address)
31957 {
31958 #ifdef CONFIG_X86_64
31959- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31960+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31961 return 1;
31962 #endif
31963 return 0;
31964@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31965 }
31966
31967 static const char nx_warning[] = KERN_CRIT
31968-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31969+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31970
31971 static void
31972 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31973@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31974 if (!oops_may_print())
31975 return;
31976
31977- if (error_code & PF_INSTR) {
31978+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31979 unsigned int level;
31980
31981 pte_t *pte = lookup_address(address, &level);
31982
31983 if (pte && pte_present(*pte) && !pte_exec(*pte))
31984- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31985+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31986 }
31987
31988+#ifdef CONFIG_PAX_KERNEXEC
31989+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31990+ if (current->signal->curr_ip)
31991+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31992+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31993+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31994+ else
31995+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31996+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31997+ }
31998+#endif
31999+
32000 printk(KERN_ALERT "BUG: unable to handle kernel ");
32001 if (address < PAGE_SIZE)
32002 printk(KERN_CONT "NULL pointer dereference");
32003@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32004 return;
32005 }
32006 #endif
32007+
32008+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32009+ if (pax_is_fetch_fault(regs, error_code, address)) {
32010+
32011+#ifdef CONFIG_PAX_EMUTRAMP
32012+ switch (pax_handle_fetch_fault(regs)) {
32013+ case 2:
32014+ return;
32015+ }
32016+#endif
32017+
32018+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32019+ do_group_exit(SIGKILL);
32020+ }
32021+#endif
32022+
32023 /* Kernel addresses are always protection faults: */
32024 if (address >= TASK_SIZE)
32025 error_code |= PF_PROT;
32026@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32027 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32028 printk(KERN_ERR
32029 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32030- tsk->comm, tsk->pid, address);
32031+ tsk->comm, task_pid_nr(tsk), address);
32032 code = BUS_MCEERR_AR;
32033 }
32034 #endif
32035@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32036 return 1;
32037 }
32038
32039+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32040+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32041+{
32042+ pte_t *pte;
32043+ pmd_t *pmd;
32044+ spinlock_t *ptl;
32045+ unsigned char pte_mask;
32046+
32047+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32048+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
32049+ return 0;
32050+
32051+ /* PaX: it's our fault, let's handle it if we can */
32052+
32053+ /* PaX: take a look at read faults before acquiring any locks */
32054+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32055+ /* instruction fetch attempt from a protected page in user mode */
32056+ up_read(&mm->mmap_sem);
32057+
32058+#ifdef CONFIG_PAX_EMUTRAMP
32059+ switch (pax_handle_fetch_fault(regs)) {
32060+ case 2:
32061+ return 1;
32062+ }
32063+#endif
32064+
32065+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32066+ do_group_exit(SIGKILL);
32067+ }
32068+
32069+ pmd = pax_get_pmd(mm, address);
32070+ if (unlikely(!pmd))
32071+ return 0;
32072+
32073+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32074+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32075+ pte_unmap_unlock(pte, ptl);
32076+ return 0;
32077+ }
32078+
32079+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32080+ /* write attempt to a protected page in user mode */
32081+ pte_unmap_unlock(pte, ptl);
32082+ return 0;
32083+ }
32084+
32085+#ifdef CONFIG_SMP
32086+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32087+#else
32088+ if (likely(address > get_limit(regs->cs)))
32089+#endif
32090+ {
32091+ set_pte(pte, pte_mkread(*pte));
32092+ __flush_tlb_one(address);
32093+ pte_unmap_unlock(pte, ptl);
32094+ up_read(&mm->mmap_sem);
32095+ return 1;
32096+ }
32097+
32098+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32099+
32100+ /*
32101+ * PaX: fill DTLB with user rights and retry
32102+ */
32103+ __asm__ __volatile__ (
32104+ "orb %2,(%1)\n"
32105+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32106+/*
32107+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32108+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32109+ * page fault when examined during a TLB load attempt. this is true not only
32110+ * for PTEs holding a non-present entry but also present entries that will
32111+ * raise a page fault (such as those set up by PaX, or the copy-on-write
32112+ * mechanism). in effect it means that we do *not* need to flush the TLBs
32113+ * for our target pages since their PTEs are simply not in the TLBs at all.
32114+
32115+ * the best thing in omitting it is that we gain around 15-20% speed in the
32116+ * fast path of the page fault handler and can get rid of tracing since we
32117+ * can no longer flush unintended entries.
32118+ */
32119+ "invlpg (%0)\n"
32120+#endif
32121+ __copyuser_seg"testb $0,(%0)\n"
32122+ "xorb %3,(%1)\n"
32123+ :
32124+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32125+ : "memory", "cc");
32126+ pte_unmap_unlock(pte, ptl);
32127+ up_read(&mm->mmap_sem);
32128+ return 1;
32129+}
32130+#endif
32131+
32132 /*
32133 * Handle a spurious fault caused by a stale TLB entry.
32134 *
32135@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
32136 static inline int
32137 access_error(unsigned long error_code, struct vm_area_struct *vma)
32138 {
32139+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32140+ return 1;
32141+
32142 if (error_code & PF_WRITE) {
32143 /* write, present and write, not present: */
32144 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32145@@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32146 if (error_code & PF_USER)
32147 return false;
32148
32149- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32150+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32151 return false;
32152
32153 return true;
32154@@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32155 tsk = current;
32156 mm = tsk->mm;
32157
32158+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32159+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32160+ if (!search_exception_tables(regs->ip)) {
32161+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32162+ bad_area_nosemaphore(regs, error_code, address);
32163+ return;
32164+ }
32165+ if (address < pax_user_shadow_base) {
32166+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32167+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32168+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32169+ } else
32170+ address -= pax_user_shadow_base;
32171+ }
32172+#endif
32173+
32174 /*
32175 * Detect and handle instructions that would cause a page fault for
32176 * both a tracked kernel page and a userspace page.
32177@@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32178 * User-mode registers count as a user access even for any
32179 * potential system fault or CPU buglet:
32180 */
32181- if (user_mode_vm(regs)) {
32182+ if (user_mode(regs)) {
32183 local_irq_enable();
32184 error_code |= PF_USER;
32185 flags |= FAULT_FLAG_USER;
32186@@ -1162,6 +1386,11 @@ retry:
32187 might_sleep();
32188 }
32189
32190+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32191+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32192+ return;
32193+#endif
32194+
32195 vma = find_vma(mm, address);
32196 if (unlikely(!vma)) {
32197 bad_area(regs, error_code, address);
32198@@ -1173,18 +1402,24 @@ retry:
32199 bad_area(regs, error_code, address);
32200 return;
32201 }
32202- if (error_code & PF_USER) {
32203- /*
32204- * Accessing the stack below %sp is always a bug.
32205- * The large cushion allows instructions like enter
32206- * and pusha to work. ("enter $65535, $31" pushes
32207- * 32 pointers and then decrements %sp by 65535.)
32208- */
32209- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32210- bad_area(regs, error_code, address);
32211- return;
32212- }
32213+ /*
32214+ * Accessing the stack below %sp is always a bug.
32215+ * The large cushion allows instructions like enter
32216+ * and pusha to work. ("enter $65535, $31" pushes
32217+ * 32 pointers and then decrements %sp by 65535.)
32218+ */
32219+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32220+ bad_area(regs, error_code, address);
32221+ return;
32222 }
32223+
32224+#ifdef CONFIG_PAX_SEGMEXEC
32225+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32226+ bad_area(regs, error_code, address);
32227+ return;
32228+ }
32229+#endif
32230+
32231 if (unlikely(expand_stack(vma, address))) {
32232 bad_area(regs, error_code, address);
32233 return;
32234@@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32235 exception_exit(prev_state);
32236 }
32237 #endif /* CONFIG_TRACING */
32238+
32239+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32240+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32241+{
32242+ struct mm_struct *mm = current->mm;
32243+ unsigned long ip = regs->ip;
32244+
32245+ if (v8086_mode(regs))
32246+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32247+
32248+#ifdef CONFIG_PAX_PAGEEXEC
32249+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32250+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32251+ return true;
32252+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32253+ return true;
32254+ return false;
32255+ }
32256+#endif
32257+
32258+#ifdef CONFIG_PAX_SEGMEXEC
32259+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32260+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32261+ return true;
32262+ return false;
32263+ }
32264+#endif
32265+
32266+ return false;
32267+}
32268+#endif
32269+
32270+#ifdef CONFIG_PAX_EMUTRAMP
32271+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32272+{
32273+ int err;
32274+
32275+ do { /* PaX: libffi trampoline emulation */
32276+ unsigned char mov, jmp;
32277+ unsigned int addr1, addr2;
32278+
32279+#ifdef CONFIG_X86_64
32280+ if ((regs->ip + 9) >> 32)
32281+ break;
32282+#endif
32283+
32284+ err = get_user(mov, (unsigned char __user *)regs->ip);
32285+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32286+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32287+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32288+
32289+ if (err)
32290+ break;
32291+
32292+ if (mov == 0xB8 && jmp == 0xE9) {
32293+ regs->ax = addr1;
32294+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32295+ return 2;
32296+ }
32297+ } while (0);
32298+
32299+ do { /* PaX: gcc trampoline emulation #1 */
32300+ unsigned char mov1, mov2;
32301+ unsigned short jmp;
32302+ unsigned int addr1, addr2;
32303+
32304+#ifdef CONFIG_X86_64
32305+ if ((regs->ip + 11) >> 32)
32306+ break;
32307+#endif
32308+
32309+ err = get_user(mov1, (unsigned char __user *)regs->ip);
32310+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32311+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32312+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32313+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32314+
32315+ if (err)
32316+ break;
32317+
32318+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32319+ regs->cx = addr1;
32320+ regs->ax = addr2;
32321+ regs->ip = addr2;
32322+ return 2;
32323+ }
32324+ } while (0);
32325+
32326+ do { /* PaX: gcc trampoline emulation #2 */
32327+ unsigned char mov, jmp;
32328+ unsigned int addr1, addr2;
32329+
32330+#ifdef CONFIG_X86_64
32331+ if ((regs->ip + 9) >> 32)
32332+ break;
32333+#endif
32334+
32335+ err = get_user(mov, (unsigned char __user *)regs->ip);
32336+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32337+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32338+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32339+
32340+ if (err)
32341+ break;
32342+
32343+ if (mov == 0xB9 && jmp == 0xE9) {
32344+ regs->cx = addr1;
32345+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32346+ return 2;
32347+ }
32348+ } while (0);
32349+
32350+ return 1; /* PaX in action */
32351+}
32352+
32353+#ifdef CONFIG_X86_64
32354+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32355+{
32356+ int err;
32357+
32358+ do { /* PaX: libffi trampoline emulation */
32359+ unsigned short mov1, mov2, jmp1;
32360+ unsigned char stcclc, jmp2;
32361+ unsigned long addr1, addr2;
32362+
32363+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32364+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32365+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32366+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32367+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32368+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32369+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32370+
32371+ if (err)
32372+ break;
32373+
32374+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32375+ regs->r11 = addr1;
32376+ regs->r10 = addr2;
32377+ if (stcclc == 0xF8)
32378+ regs->flags &= ~X86_EFLAGS_CF;
32379+ else
32380+ regs->flags |= X86_EFLAGS_CF;
32381+ regs->ip = addr1;
32382+ return 2;
32383+ }
32384+ } while (0);
32385+
32386+ do { /* PaX: gcc trampoline emulation #1 */
32387+ unsigned short mov1, mov2, jmp1;
32388+ unsigned char jmp2;
32389+ unsigned int addr1;
32390+ unsigned long addr2;
32391+
32392+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32393+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32394+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32395+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32396+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32397+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32398+
32399+ if (err)
32400+ break;
32401+
32402+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32403+ regs->r11 = addr1;
32404+ regs->r10 = addr2;
32405+ regs->ip = addr1;
32406+ return 2;
32407+ }
32408+ } while (0);
32409+
32410+ do { /* PaX: gcc trampoline emulation #2 */
32411+ unsigned short mov1, mov2, jmp1;
32412+ unsigned char jmp2;
32413+ unsigned long addr1, addr2;
32414+
32415+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32416+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32417+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32418+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32419+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32420+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32421+
32422+ if (err)
32423+ break;
32424+
32425+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32426+ regs->r11 = addr1;
32427+ regs->r10 = addr2;
32428+ regs->ip = addr1;
32429+ return 2;
32430+ }
32431+ } while (0);
32432+
32433+ return 1; /* PaX in action */
32434+}
32435+#endif
32436+
32437+/*
32438+ * PaX: decide what to do with offenders (regs->ip = fault address)
32439+ *
32440+ * returns 1 when task should be killed
32441+ * 2 when gcc trampoline was detected
32442+ */
32443+static int pax_handle_fetch_fault(struct pt_regs *regs)
32444+{
32445+ if (v8086_mode(regs))
32446+ return 1;
32447+
32448+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32449+ return 1;
32450+
32451+#ifdef CONFIG_X86_32
32452+ return pax_handle_fetch_fault_32(regs);
32453+#else
32454+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32455+ return pax_handle_fetch_fault_32(regs);
32456+ else
32457+ return pax_handle_fetch_fault_64(regs);
32458+#endif
32459+}
32460+#endif
32461+
32462+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32463+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32464+{
32465+ long i;
32466+
32467+ printk(KERN_ERR "PAX: bytes at PC: ");
32468+ for (i = 0; i < 20; i++) {
32469+ unsigned char c;
32470+ if (get_user(c, (unsigned char __force_user *)pc+i))
32471+ printk(KERN_CONT "?? ");
32472+ else
32473+ printk(KERN_CONT "%02x ", c);
32474+ }
32475+ printk("\n");
32476+
32477+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32478+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32479+ unsigned long c;
32480+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32481+#ifdef CONFIG_X86_32
32482+ printk(KERN_CONT "???????? ");
32483+#else
32484+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32485+ printk(KERN_CONT "???????? ???????? ");
32486+ else
32487+ printk(KERN_CONT "???????????????? ");
32488+#endif
32489+ } else {
32490+#ifdef CONFIG_X86_64
32491+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32492+ printk(KERN_CONT "%08x ", (unsigned int)c);
32493+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32494+ } else
32495+#endif
32496+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32497+ }
32498+ }
32499+ printk("\n");
32500+}
32501+#endif
32502+
32503+/**
32504+ * probe_kernel_write(): safely attempt to write to a location
32505+ * @dst: address to write to
32506+ * @src: pointer to the data that shall be written
32507+ * @size: size of the data chunk
32508+ *
32509+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32510+ * happens, handle that and return -EFAULT.
32511+ */
32512+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32513+{
32514+ long ret;
32515+ mm_segment_t old_fs = get_fs();
32516+
32517+ set_fs(KERNEL_DS);
32518+ pagefault_disable();
32519+ pax_open_kernel();
32520+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32521+ pax_close_kernel();
32522+ pagefault_enable();
32523+ set_fs(old_fs);
32524+
32525+ return ret ? -EFAULT : 0;
32526+}
32527diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32528index 207d9aef..69030980 100644
32529--- a/arch/x86/mm/gup.c
32530+++ b/arch/x86/mm/gup.c
32531@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32532 addr = start;
32533 len = (unsigned long) nr_pages << PAGE_SHIFT;
32534 end = start + len;
32535- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32536+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32537 (void __user *)start, len)))
32538 return 0;
32539
32540@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32541 goto slow_irqon;
32542 #endif
32543
32544+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32545+ (void __user *)start, len)))
32546+ return 0;
32547+
32548 /*
32549 * XXX: batch / limit 'nr', to avoid large irq off latency
32550 * needs some instrumenting to determine the common sizes used by
32551diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32552index 4500142..53a363c 100644
32553--- a/arch/x86/mm/highmem_32.c
32554+++ b/arch/x86/mm/highmem_32.c
32555@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32556 idx = type + KM_TYPE_NR*smp_processor_id();
32557 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32558 BUG_ON(!pte_none(*(kmap_pte-idx)));
32559+
32560+ pax_open_kernel();
32561 set_pte(kmap_pte-idx, mk_pte(page, prot));
32562+ pax_close_kernel();
32563+
32564 arch_flush_lazy_mmu_mode();
32565
32566 return (void *)vaddr;
32567diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32568index 8c9f647..57cb402 100644
32569--- a/arch/x86/mm/hugetlbpage.c
32570+++ b/arch/x86/mm/hugetlbpage.c
32571@@ -90,23 +90,24 @@ int pmd_huge_support(void)
32572 #ifdef CONFIG_HUGETLB_PAGE
32573 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32574 unsigned long addr, unsigned long len,
32575- unsigned long pgoff, unsigned long flags)
32576+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32577 {
32578 struct hstate *h = hstate_file(file);
32579 struct vm_unmapped_area_info info;
32580-
32581+
32582 info.flags = 0;
32583 info.length = len;
32584 info.low_limit = current->mm->mmap_legacy_base;
32585 info.high_limit = TASK_SIZE;
32586 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32587 info.align_offset = 0;
32588+ info.threadstack_offset = offset;
32589 return vm_unmapped_area(&info);
32590 }
32591
32592 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32593 unsigned long addr0, unsigned long len,
32594- unsigned long pgoff, unsigned long flags)
32595+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32596 {
32597 struct hstate *h = hstate_file(file);
32598 struct vm_unmapped_area_info info;
32599@@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32600 info.high_limit = current->mm->mmap_base;
32601 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32602 info.align_offset = 0;
32603+ info.threadstack_offset = offset;
32604 addr = vm_unmapped_area(&info);
32605
32606 /*
32607@@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32608 VM_BUG_ON(addr != -ENOMEM);
32609 info.flags = 0;
32610 info.low_limit = TASK_UNMAPPED_BASE;
32611+
32612+#ifdef CONFIG_PAX_RANDMMAP
32613+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32614+ info.low_limit += current->mm->delta_mmap;
32615+#endif
32616+
32617 info.high_limit = TASK_SIZE;
32618 addr = vm_unmapped_area(&info);
32619 }
32620@@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32621 struct hstate *h = hstate_file(file);
32622 struct mm_struct *mm = current->mm;
32623 struct vm_area_struct *vma;
32624+ unsigned long pax_task_size = TASK_SIZE;
32625+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32626
32627 if (len & ~huge_page_mask(h))
32628 return -EINVAL;
32629- if (len > TASK_SIZE)
32630+
32631+#ifdef CONFIG_PAX_SEGMEXEC
32632+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32633+ pax_task_size = SEGMEXEC_TASK_SIZE;
32634+#endif
32635+
32636+ pax_task_size -= PAGE_SIZE;
32637+
32638+ if (len > pax_task_size)
32639 return -ENOMEM;
32640
32641 if (flags & MAP_FIXED) {
32642@@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32643 return addr;
32644 }
32645
32646+#ifdef CONFIG_PAX_RANDMMAP
32647+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32648+#endif
32649+
32650 if (addr) {
32651 addr = ALIGN(addr, huge_page_size(h));
32652 vma = find_vma(mm, addr);
32653- if (TASK_SIZE - len >= addr &&
32654- (!vma || addr + len <= vma->vm_start))
32655+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32656 return addr;
32657 }
32658 if (mm->get_unmapped_area == arch_get_unmapped_area)
32659 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32660- pgoff, flags);
32661+ pgoff, flags, offset);
32662 else
32663 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32664- pgoff, flags);
32665+ pgoff, flags, offset);
32666 }
32667 #endif /* CONFIG_HUGETLB_PAGE */
32668
32669diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32670index f971306..e83e0f6 100644
32671--- a/arch/x86/mm/init.c
32672+++ b/arch/x86/mm/init.c
32673@@ -4,6 +4,7 @@
32674 #include <linux/swap.h>
32675 #include <linux/memblock.h>
32676 #include <linux/bootmem.h> /* for max_low_pfn */
32677+#include <linux/tboot.h>
32678
32679 #include <asm/cacheflush.h>
32680 #include <asm/e820.h>
32681@@ -17,6 +18,8 @@
32682 #include <asm/proto.h>
32683 #include <asm/dma.h> /* for MAX_DMA_PFN */
32684 #include <asm/microcode.h>
32685+#include <asm/desc.h>
32686+#include <asm/bios_ebda.h>
32687
32688 #include "mm_internal.h"
32689
32690@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32691 early_ioremap_page_table_range_init();
32692 #endif
32693
32694+#ifdef CONFIG_PAX_PER_CPU_PGD
32695+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32696+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32697+ KERNEL_PGD_PTRS);
32698+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32699+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32700+ KERNEL_PGD_PTRS);
32701+ load_cr3(get_cpu_pgd(0, kernel));
32702+#else
32703 load_cr3(swapper_pg_dir);
32704+#endif
32705+
32706 __flush_tlb_all();
32707
32708 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32709@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32710 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32711 * mmio resources as well as potential bios/acpi data regions.
32712 */
32713+
32714+#ifdef CONFIG_GRKERNSEC_KMEM
32715+static unsigned int ebda_start __read_only;
32716+static unsigned int ebda_end __read_only;
32717+#endif
32718+
32719 int devmem_is_allowed(unsigned long pagenr)
32720 {
32721- if (pagenr < 256)
32722+#ifdef CONFIG_GRKERNSEC_KMEM
32723+ /* allow BDA */
32724+ if (!pagenr)
32725 return 1;
32726+ /* allow EBDA */
32727+ if (pagenr >= ebda_start && pagenr < ebda_end)
32728+ return 1;
32729+ /* if tboot is in use, allow access to its hardcoded serial log range */
32730+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32731+ return 1;
32732+#else
32733+ if (!pagenr)
32734+ return 1;
32735+#ifdef CONFIG_VM86
32736+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32737+ return 1;
32738+#endif
32739+#endif
32740+
32741+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32742+ return 1;
32743+#ifdef CONFIG_GRKERNSEC_KMEM
32744+ /* throw out everything else below 1MB */
32745+ if (pagenr <= 256)
32746+ return 0;
32747+#endif
32748 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32749 return 0;
32750 if (!page_is_ram(pagenr))
32751@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32752 #endif
32753 }
32754
32755+#ifdef CONFIG_GRKERNSEC_KMEM
32756+static inline void gr_init_ebda(void)
32757+{
32758+ unsigned int ebda_addr;
32759+ unsigned int ebda_size = 0;
32760+
32761+ ebda_addr = get_bios_ebda();
32762+ if (ebda_addr) {
32763+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32764+ ebda_size <<= 10;
32765+ }
32766+ if (ebda_addr && ebda_size) {
32767+ ebda_start = ebda_addr >> PAGE_SHIFT;
32768+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32769+ } else {
32770+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32771+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32772+ }
32773+}
32774+#else
32775+static inline void gr_init_ebda(void) { }
32776+#endif
32777+
32778 void free_initmem(void)
32779 {
32780+#ifdef CONFIG_PAX_KERNEXEC
32781+#ifdef CONFIG_X86_32
32782+ /* PaX: limit KERNEL_CS to actual size */
32783+ unsigned long addr, limit;
32784+ struct desc_struct d;
32785+ int cpu;
32786+#else
32787+ pgd_t *pgd;
32788+ pud_t *pud;
32789+ pmd_t *pmd;
32790+ unsigned long addr, end;
32791+#endif
32792+#endif
32793+
32794+ gr_init_ebda();
32795+
32796+#ifdef CONFIG_PAX_KERNEXEC
32797+#ifdef CONFIG_X86_32
32798+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32799+ limit = (limit - 1UL) >> PAGE_SHIFT;
32800+
32801+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32802+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32803+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32804+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32805+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32806+ }
32807+
32808+ /* PaX: make KERNEL_CS read-only */
32809+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32810+ if (!paravirt_enabled())
32811+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32812+/*
32813+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32814+ pgd = pgd_offset_k(addr);
32815+ pud = pud_offset(pgd, addr);
32816+ pmd = pmd_offset(pud, addr);
32817+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32818+ }
32819+*/
32820+#ifdef CONFIG_X86_PAE
32821+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32822+/*
32823+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32824+ pgd = pgd_offset_k(addr);
32825+ pud = pud_offset(pgd, addr);
32826+ pmd = pmd_offset(pud, addr);
32827+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32828+ }
32829+*/
32830+#endif
32831+
32832+#ifdef CONFIG_MODULES
32833+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32834+#endif
32835+
32836+#else
32837+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32838+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32839+ pgd = pgd_offset_k(addr);
32840+ pud = pud_offset(pgd, addr);
32841+ pmd = pmd_offset(pud, addr);
32842+ if (!pmd_present(*pmd))
32843+ continue;
32844+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32845+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32846+ else
32847+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32848+ }
32849+
32850+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32851+ end = addr + KERNEL_IMAGE_SIZE;
32852+ for (; addr < end; addr += PMD_SIZE) {
32853+ pgd = pgd_offset_k(addr);
32854+ pud = pud_offset(pgd, addr);
32855+ pmd = pmd_offset(pud, addr);
32856+ if (!pmd_present(*pmd))
32857+ continue;
32858+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32859+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32860+ }
32861+#endif
32862+
32863+ flush_tlb_all();
32864+#endif
32865+
32866 free_init_pages("unused kernel",
32867 (unsigned long)(&__init_begin),
32868 (unsigned long)(&__init_end));
32869diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32870index e395048..cd38278 100644
32871--- a/arch/x86/mm/init_32.c
32872+++ b/arch/x86/mm/init_32.c
32873@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32874 bool __read_mostly __vmalloc_start_set = false;
32875
32876 /*
32877- * Creates a middle page table and puts a pointer to it in the
32878- * given global directory entry. This only returns the gd entry
32879- * in non-PAE compilation mode, since the middle layer is folded.
32880- */
32881-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32882-{
32883- pud_t *pud;
32884- pmd_t *pmd_table;
32885-
32886-#ifdef CONFIG_X86_PAE
32887- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32888- pmd_table = (pmd_t *)alloc_low_page();
32889- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32890- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32891- pud = pud_offset(pgd, 0);
32892- BUG_ON(pmd_table != pmd_offset(pud, 0));
32893-
32894- return pmd_table;
32895- }
32896-#endif
32897- pud = pud_offset(pgd, 0);
32898- pmd_table = pmd_offset(pud, 0);
32899-
32900- return pmd_table;
32901-}
32902-
32903-/*
32904 * Create a page table and place a pointer to it in a middle page
32905 * directory entry:
32906 */
32907@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32908 pte_t *page_table = (pte_t *)alloc_low_page();
32909
32910 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32911+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32912+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32913+#else
32914 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32915+#endif
32916 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32917 }
32918
32919 return pte_offset_kernel(pmd, 0);
32920 }
32921
32922+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32923+{
32924+ pud_t *pud;
32925+ pmd_t *pmd_table;
32926+
32927+ pud = pud_offset(pgd, 0);
32928+ pmd_table = pmd_offset(pud, 0);
32929+
32930+ return pmd_table;
32931+}
32932+
32933 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32934 {
32935 int pgd_idx = pgd_index(vaddr);
32936@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32937 int pgd_idx, pmd_idx;
32938 unsigned long vaddr;
32939 pgd_t *pgd;
32940+ pud_t *pud;
32941 pmd_t *pmd;
32942 pte_t *pte = NULL;
32943 unsigned long count = page_table_range_init_count(start, end);
32944@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32945 pgd = pgd_base + pgd_idx;
32946
32947 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32948- pmd = one_md_table_init(pgd);
32949- pmd = pmd + pmd_index(vaddr);
32950+ pud = pud_offset(pgd, vaddr);
32951+ pmd = pmd_offset(pud, vaddr);
32952+
32953+#ifdef CONFIG_X86_PAE
32954+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32955+#endif
32956+
32957 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32958 pmd++, pmd_idx++) {
32959 pte = page_table_kmap_check(one_page_table_init(pmd),
32960@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32961 }
32962 }
32963
32964-static inline int is_kernel_text(unsigned long addr)
32965+static inline int is_kernel_text(unsigned long start, unsigned long end)
32966 {
32967- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32968- return 1;
32969- return 0;
32970+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32971+ end <= ktla_ktva((unsigned long)_stext)) &&
32972+ (start >= ktla_ktva((unsigned long)_einittext) ||
32973+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32974+
32975+#ifdef CONFIG_ACPI_SLEEP
32976+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32977+#endif
32978+
32979+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32980+ return 0;
32981+ return 1;
32982 }
32983
32984 /*
32985@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32986 unsigned long last_map_addr = end;
32987 unsigned long start_pfn, end_pfn;
32988 pgd_t *pgd_base = swapper_pg_dir;
32989- int pgd_idx, pmd_idx, pte_ofs;
32990+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32991 unsigned long pfn;
32992 pgd_t *pgd;
32993+ pud_t *pud;
32994 pmd_t *pmd;
32995 pte_t *pte;
32996 unsigned pages_2m, pages_4k;
32997@@ -291,8 +295,13 @@ repeat:
32998 pfn = start_pfn;
32999 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33000 pgd = pgd_base + pgd_idx;
33001- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33002- pmd = one_md_table_init(pgd);
33003+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33004+ pud = pud_offset(pgd, 0);
33005+ pmd = pmd_offset(pud, 0);
33006+
33007+#ifdef CONFIG_X86_PAE
33008+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33009+#endif
33010
33011 if (pfn >= end_pfn)
33012 continue;
33013@@ -304,14 +313,13 @@ repeat:
33014 #endif
33015 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33016 pmd++, pmd_idx++) {
33017- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33018+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33019
33020 /*
33021 * Map with big pages if possible, otherwise
33022 * create normal page tables:
33023 */
33024 if (use_pse) {
33025- unsigned int addr2;
33026 pgprot_t prot = PAGE_KERNEL_LARGE;
33027 /*
33028 * first pass will use the same initial
33029@@ -322,11 +330,7 @@ repeat:
33030 _PAGE_PSE);
33031
33032 pfn &= PMD_MASK >> PAGE_SHIFT;
33033- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33034- PAGE_OFFSET + PAGE_SIZE-1;
33035-
33036- if (is_kernel_text(addr) ||
33037- is_kernel_text(addr2))
33038+ if (is_kernel_text(address, address + PMD_SIZE))
33039 prot = PAGE_KERNEL_LARGE_EXEC;
33040
33041 pages_2m++;
33042@@ -343,7 +347,7 @@ repeat:
33043 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33044 pte += pte_ofs;
33045 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33046- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33047+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33048 pgprot_t prot = PAGE_KERNEL;
33049 /*
33050 * first pass will use the same initial
33051@@ -351,7 +355,7 @@ repeat:
33052 */
33053 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33054
33055- if (is_kernel_text(addr))
33056+ if (is_kernel_text(address, address + PAGE_SIZE))
33057 prot = PAGE_KERNEL_EXEC;
33058
33059 pages_4k++;
33060@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33061
33062 pud = pud_offset(pgd, va);
33063 pmd = pmd_offset(pud, va);
33064- if (!pmd_present(*pmd))
33065+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33066 break;
33067
33068 /* should not be large page here */
33069@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33070
33071 static void __init pagetable_init(void)
33072 {
33073- pgd_t *pgd_base = swapper_pg_dir;
33074-
33075- permanent_kmaps_init(pgd_base);
33076+ permanent_kmaps_init(swapper_pg_dir);
33077 }
33078
33079-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33080+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33081 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33082
33083 /* user-defined highmem size */
33084@@ -787,10 +789,10 @@ void __init mem_init(void)
33085 ((unsigned long)&__init_end -
33086 (unsigned long)&__init_begin) >> 10,
33087
33088- (unsigned long)&_etext, (unsigned long)&_edata,
33089- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33090+ (unsigned long)&_sdata, (unsigned long)&_edata,
33091+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33092
33093- (unsigned long)&_text, (unsigned long)&_etext,
33094+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33095 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33096
33097 /*
33098@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
33099 if (!kernel_set_to_readonly)
33100 return;
33101
33102+ start = ktla_ktva(start);
33103 pr_debug("Set kernel text: %lx - %lx for read write\n",
33104 start, start+size);
33105
33106@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
33107 if (!kernel_set_to_readonly)
33108 return;
33109
33110+ start = ktla_ktva(start);
33111 pr_debug("Set kernel text: %lx - %lx for read only\n",
33112 start, start+size);
33113
33114@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
33115 unsigned long start = PFN_ALIGN(_text);
33116 unsigned long size = PFN_ALIGN(_etext) - start;
33117
33118+ start = ktla_ktva(start);
33119 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33120 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33121 size >> 10);
33122diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33123index f35c66c..84b95ef 100644
33124--- a/arch/x86/mm/init_64.c
33125+++ b/arch/x86/mm/init_64.c
33126@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33127 * around without checking the pgd every time.
33128 */
33129
33130-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
33131+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
33132 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33133
33134 int force_personality32;
33135@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33136
33137 for (address = start; address <= end; address += PGDIR_SIZE) {
33138 const pgd_t *pgd_ref = pgd_offset_k(address);
33139+
33140+#ifdef CONFIG_PAX_PER_CPU_PGD
33141+ unsigned long cpu;
33142+#else
33143 struct page *page;
33144+#endif
33145
33146 if (pgd_none(*pgd_ref))
33147 continue;
33148
33149 spin_lock(&pgd_lock);
33150+
33151+#ifdef CONFIG_PAX_PER_CPU_PGD
33152+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33153+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33154+
33155+ if (pgd_none(*pgd))
33156+ set_pgd(pgd, *pgd_ref);
33157+ else
33158+ BUG_ON(pgd_page_vaddr(*pgd)
33159+ != pgd_page_vaddr(*pgd_ref));
33160+ pgd = pgd_offset_cpu(cpu, kernel, address);
33161+#else
33162 list_for_each_entry(page, &pgd_list, lru) {
33163 pgd_t *pgd;
33164 spinlock_t *pgt_lock;
33165@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33166 /* the pgt_lock only for Xen */
33167 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33168 spin_lock(pgt_lock);
33169+#endif
33170
33171 if (pgd_none(*pgd))
33172 set_pgd(pgd, *pgd_ref);
33173@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33174 BUG_ON(pgd_page_vaddr(*pgd)
33175 != pgd_page_vaddr(*pgd_ref));
33176
33177+#ifndef CONFIG_PAX_PER_CPU_PGD
33178 spin_unlock(pgt_lock);
33179+#endif
33180+
33181 }
33182 spin_unlock(&pgd_lock);
33183 }
33184@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33185 {
33186 if (pgd_none(*pgd)) {
33187 pud_t *pud = (pud_t *)spp_getpage();
33188- pgd_populate(&init_mm, pgd, pud);
33189+ pgd_populate_kernel(&init_mm, pgd, pud);
33190 if (pud != pud_offset(pgd, 0))
33191 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33192 pud, pud_offset(pgd, 0));
33193@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33194 {
33195 if (pud_none(*pud)) {
33196 pmd_t *pmd = (pmd_t *) spp_getpage();
33197- pud_populate(&init_mm, pud, pmd);
33198+ pud_populate_kernel(&init_mm, pud, pmd);
33199 if (pmd != pmd_offset(pud, 0))
33200 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33201 pmd, pmd_offset(pud, 0));
33202@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33203 pmd = fill_pmd(pud, vaddr);
33204 pte = fill_pte(pmd, vaddr);
33205
33206+ pax_open_kernel();
33207 set_pte(pte, new_pte);
33208+ pax_close_kernel();
33209
33210 /*
33211 * It's enough to flush this one mapping.
33212@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33213 pgd = pgd_offset_k((unsigned long)__va(phys));
33214 if (pgd_none(*pgd)) {
33215 pud = (pud_t *) spp_getpage();
33216- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33217- _PAGE_USER));
33218+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33219 }
33220 pud = pud_offset(pgd, (unsigned long)__va(phys));
33221 if (pud_none(*pud)) {
33222 pmd = (pmd_t *) spp_getpage();
33223- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33224- _PAGE_USER));
33225+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33226 }
33227 pmd = pmd_offset(pud, phys);
33228 BUG_ON(!pmd_none(*pmd));
33229@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33230 prot);
33231
33232 spin_lock(&init_mm.page_table_lock);
33233- pud_populate(&init_mm, pud, pmd);
33234+ pud_populate_kernel(&init_mm, pud, pmd);
33235 spin_unlock(&init_mm.page_table_lock);
33236 }
33237 __flush_tlb_all();
33238@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33239 page_size_mask);
33240
33241 spin_lock(&init_mm.page_table_lock);
33242- pgd_populate(&init_mm, pgd, pud);
33243+ pgd_populate_kernel(&init_mm, pgd, pud);
33244 spin_unlock(&init_mm.page_table_lock);
33245 pgd_changed = true;
33246 }
33247@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
33248 static struct vm_area_struct gate_vma = {
33249 .vm_start = VSYSCALL_START,
33250 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
33251- .vm_page_prot = PAGE_READONLY_EXEC,
33252- .vm_flags = VM_READ | VM_EXEC
33253+ .vm_page_prot = PAGE_READONLY,
33254+ .vm_flags = VM_READ
33255 };
33256
33257 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33258@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
33259
33260 const char *arch_vma_name(struct vm_area_struct *vma)
33261 {
33262- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33263+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33264 return "[vdso]";
33265 if (vma == &gate_vma)
33266 return "[vsyscall]";
33267diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33268index 7b179b4..6bd17777 100644
33269--- a/arch/x86/mm/iomap_32.c
33270+++ b/arch/x86/mm/iomap_32.c
33271@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33272 type = kmap_atomic_idx_push();
33273 idx = type + KM_TYPE_NR * smp_processor_id();
33274 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33275+
33276+ pax_open_kernel();
33277 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33278+ pax_close_kernel();
33279+
33280 arch_flush_lazy_mmu_mode();
33281
33282 return (void *)vaddr;
33283diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33284index 799580c..72f9fe0 100644
33285--- a/arch/x86/mm/ioremap.c
33286+++ b/arch/x86/mm/ioremap.c
33287@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
33288 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
33289 int is_ram = page_is_ram(pfn);
33290
33291- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
33292+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
33293 return NULL;
33294 WARN_ON_ONCE(is_ram);
33295 }
33296@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
33297 *
33298 * Caller must ensure there is only one unmapping for the same pointer.
33299 */
33300-void iounmap(volatile void __iomem *addr)
33301+void iounmap(const volatile void __iomem *addr)
33302 {
33303 struct vm_struct *p, *o;
33304
33305@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33306
33307 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33308 if (page_is_ram(start >> PAGE_SHIFT))
33309+#ifdef CONFIG_HIGHMEM
33310+ if ((start >> PAGE_SHIFT) < max_low_pfn)
33311+#endif
33312 return __va(phys);
33313
33314 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33315@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33316 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33317 {
33318 if (page_is_ram(phys >> PAGE_SHIFT))
33319+#ifdef CONFIG_HIGHMEM
33320+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
33321+#endif
33322 return;
33323
33324 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33325@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
33326 early_param("early_ioremap_debug", early_ioremap_debug_setup);
33327
33328 static __initdata int after_paging_init;
33329-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33330+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33331
33332 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33333 {
33334@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33335 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
33336
33337 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33338- memset(bm_pte, 0, sizeof(bm_pte));
33339- pmd_populate_kernel(&init_mm, pmd, bm_pte);
33340+ pmd_populate_user(&init_mm, pmd, bm_pte);
33341
33342 /*
33343 * The boot-ioremap range spans multiple pmds, for which
33344diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33345index d87dd6d..bf3fa66 100644
33346--- a/arch/x86/mm/kmemcheck/kmemcheck.c
33347+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33348@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33349 * memory (e.g. tracked pages)? For now, we need this to avoid
33350 * invoking kmemcheck for PnP BIOS calls.
33351 */
33352- if (regs->flags & X86_VM_MASK)
33353+ if (v8086_mode(regs))
33354 return false;
33355- if (regs->cs != __KERNEL_CS)
33356+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33357 return false;
33358
33359 pte = kmemcheck_pte_lookup(address);
33360diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33361index 25e7e13..1964579 100644
33362--- a/arch/x86/mm/mmap.c
33363+++ b/arch/x86/mm/mmap.c
33364@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33365 * Leave an at least ~128 MB hole with possible stack randomization.
33366 */
33367 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33368-#define MAX_GAP (TASK_SIZE/6*5)
33369+#define MAX_GAP (pax_task_size/6*5)
33370
33371 static int mmap_is_legacy(void)
33372 {
33373@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33374 return rnd << PAGE_SHIFT;
33375 }
33376
33377-static unsigned long mmap_base(void)
33378+static unsigned long mmap_base(struct mm_struct *mm)
33379 {
33380 unsigned long gap = rlimit(RLIMIT_STACK);
33381+ unsigned long pax_task_size = TASK_SIZE;
33382+
33383+#ifdef CONFIG_PAX_SEGMEXEC
33384+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33385+ pax_task_size = SEGMEXEC_TASK_SIZE;
33386+#endif
33387
33388 if (gap < MIN_GAP)
33389 gap = MIN_GAP;
33390 else if (gap > MAX_GAP)
33391 gap = MAX_GAP;
33392
33393- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33394+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33395 }
33396
33397 /*
33398 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33399 * does, but not when emulating X86_32
33400 */
33401-static unsigned long mmap_legacy_base(void)
33402+static unsigned long mmap_legacy_base(struct mm_struct *mm)
33403 {
33404- if (mmap_is_ia32())
33405+ if (mmap_is_ia32()) {
33406+
33407+#ifdef CONFIG_PAX_SEGMEXEC
33408+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33409+ return SEGMEXEC_TASK_UNMAPPED_BASE;
33410+ else
33411+#endif
33412+
33413 return TASK_UNMAPPED_BASE;
33414- else
33415+ } else
33416 return TASK_UNMAPPED_BASE + mmap_rnd();
33417 }
33418
33419@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33420 */
33421 void arch_pick_mmap_layout(struct mm_struct *mm)
33422 {
33423- mm->mmap_legacy_base = mmap_legacy_base();
33424- mm->mmap_base = mmap_base();
33425+ mm->mmap_legacy_base = mmap_legacy_base(mm);
33426+ mm->mmap_base = mmap_base(mm);
33427+
33428+#ifdef CONFIG_PAX_RANDMMAP
33429+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
33430+ mm->mmap_legacy_base += mm->delta_mmap;
33431+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33432+ }
33433+#endif
33434
33435 if (mmap_is_legacy()) {
33436 mm->mmap_base = mm->mmap_legacy_base;
33437diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33438index 0057a7a..95c7edd 100644
33439--- a/arch/x86/mm/mmio-mod.c
33440+++ b/arch/x86/mm/mmio-mod.c
33441@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33442 break;
33443 default:
33444 {
33445- unsigned char *ip = (unsigned char *)instptr;
33446+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33447 my_trace->opcode = MMIO_UNKNOWN_OP;
33448 my_trace->width = 0;
33449 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33450@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33451 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33452 void __iomem *addr)
33453 {
33454- static atomic_t next_id;
33455+ static atomic_unchecked_t next_id;
33456 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33457 /* These are page-unaligned. */
33458 struct mmiotrace_map map = {
33459@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33460 .private = trace
33461 },
33462 .phys = offset,
33463- .id = atomic_inc_return(&next_id)
33464+ .id = atomic_inc_return_unchecked(&next_id)
33465 };
33466 map.map_id = trace->id;
33467
33468@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33469 ioremap_trace_core(offset, size, addr);
33470 }
33471
33472-static void iounmap_trace_core(volatile void __iomem *addr)
33473+static void iounmap_trace_core(const volatile void __iomem *addr)
33474 {
33475 struct mmiotrace_map map = {
33476 .phys = 0,
33477@@ -328,7 +328,7 @@ not_enabled:
33478 }
33479 }
33480
33481-void mmiotrace_iounmap(volatile void __iomem *addr)
33482+void mmiotrace_iounmap(const volatile void __iomem *addr)
33483 {
33484 might_sleep();
33485 if (is_enabled()) /* recheck and proper locking in *_core() */
33486diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33487index 27aa0455..0eb1406 100644
33488--- a/arch/x86/mm/numa.c
33489+++ b/arch/x86/mm/numa.c
33490@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33491 return true;
33492 }
33493
33494-static int __init numa_register_memblks(struct numa_meminfo *mi)
33495+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33496 {
33497 unsigned long uninitialized_var(pfn_align);
33498 int i, nid;
33499diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33500index 461bc82..4e091a3 100644
33501--- a/arch/x86/mm/pageattr-test.c
33502+++ b/arch/x86/mm/pageattr-test.c
33503@@ -35,7 +35,7 @@ enum {
33504
33505 static int pte_testbit(pte_t pte)
33506 {
33507- return pte_flags(pte) & _PAGE_UNUSED1;
33508+ return pte_flags(pte) & _PAGE_CPA_TEST;
33509 }
33510
33511 struct split_state {
33512diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33513index a348868..3c64310 100644
33514--- a/arch/x86/mm/pageattr.c
33515+++ b/arch/x86/mm/pageattr.c
33516@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33517 */
33518 #ifdef CONFIG_PCI_BIOS
33519 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33520- pgprot_val(forbidden) |= _PAGE_NX;
33521+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33522 #endif
33523
33524 /*
33525@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33526 * Does not cover __inittext since that is gone later on. On
33527 * 64bit we do not enforce !NX on the low mapping
33528 */
33529- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33530- pgprot_val(forbidden) |= _PAGE_NX;
33531+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33532+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33533
33534+#ifdef CONFIG_DEBUG_RODATA
33535 /*
33536 * The .rodata section needs to be read-only. Using the pfn
33537 * catches all aliases.
33538@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33539 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33540 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33541 pgprot_val(forbidden) |= _PAGE_RW;
33542+#endif
33543
33544 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33545 /*
33546@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33547 }
33548 #endif
33549
33550+#ifdef CONFIG_PAX_KERNEXEC
33551+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33552+ pgprot_val(forbidden) |= _PAGE_RW;
33553+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33554+ }
33555+#endif
33556+
33557 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33558
33559 return prot;
33560@@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33561 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33562 {
33563 /* change init_mm */
33564+ pax_open_kernel();
33565 set_pte_atomic(kpte, pte);
33566+
33567 #ifdef CONFIG_X86_32
33568 if (!SHARED_KERNEL_PMD) {
33569+
33570+#ifdef CONFIG_PAX_PER_CPU_PGD
33571+ unsigned long cpu;
33572+#else
33573 struct page *page;
33574+#endif
33575
33576+#ifdef CONFIG_PAX_PER_CPU_PGD
33577+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33578+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33579+#else
33580 list_for_each_entry(page, &pgd_list, lru) {
33581- pgd_t *pgd;
33582+ pgd_t *pgd = (pgd_t *)page_address(page);
33583+#endif
33584+
33585 pud_t *pud;
33586 pmd_t *pmd;
33587
33588- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33589+ pgd += pgd_index(address);
33590 pud = pud_offset(pgd, address);
33591 pmd = pmd_offset(pud, address);
33592 set_pte_atomic((pte_t *)pmd, pte);
33593 }
33594 }
33595 #endif
33596+ pax_close_kernel();
33597 }
33598
33599 static int
33600diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33601index 6574388..87e9bef 100644
33602--- a/arch/x86/mm/pat.c
33603+++ b/arch/x86/mm/pat.c
33604@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33605
33606 if (!entry) {
33607 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33608- current->comm, current->pid, start, end - 1);
33609+ current->comm, task_pid_nr(current), start, end - 1);
33610 return -EINVAL;
33611 }
33612
33613@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33614
33615 while (cursor < to) {
33616 if (!devmem_is_allowed(pfn)) {
33617- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33618- current->comm, from, to - 1);
33619+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33620+ current->comm, from, to - 1, cursor);
33621 return 0;
33622 }
33623 cursor += PAGE_SIZE;
33624@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33625 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33626 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33627 "for [mem %#010Lx-%#010Lx]\n",
33628- current->comm, current->pid,
33629+ current->comm, task_pid_nr(current),
33630 cattr_name(flags),
33631 base, (unsigned long long)(base + size-1));
33632 return -EINVAL;
33633@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33634 flags = lookup_memtype(paddr);
33635 if (want_flags != flags) {
33636 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33637- current->comm, current->pid,
33638+ current->comm, task_pid_nr(current),
33639 cattr_name(want_flags),
33640 (unsigned long long)paddr,
33641 (unsigned long long)(paddr + size - 1),
33642@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33643 free_memtype(paddr, paddr + size);
33644 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33645 " for [mem %#010Lx-%#010Lx], got %s\n",
33646- current->comm, current->pid,
33647+ current->comm, task_pid_nr(current),
33648 cattr_name(want_flags),
33649 (unsigned long long)paddr,
33650 (unsigned long long)(paddr + size - 1),
33651diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33652index 415f6c4..d319983 100644
33653--- a/arch/x86/mm/pat_rbtree.c
33654+++ b/arch/x86/mm/pat_rbtree.c
33655@@ -160,7 +160,7 @@ success:
33656
33657 failure:
33658 printk(KERN_INFO "%s:%d conflicting memory types "
33659- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33660+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33661 end, cattr_name(found_type), cattr_name(match->type));
33662 return -EBUSY;
33663 }
33664diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33665index 9f0614d..92ae64a 100644
33666--- a/arch/x86/mm/pf_in.c
33667+++ b/arch/x86/mm/pf_in.c
33668@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33669 int i;
33670 enum reason_type rv = OTHERS;
33671
33672- p = (unsigned char *)ins_addr;
33673+ p = (unsigned char *)ktla_ktva(ins_addr);
33674 p += skip_prefix(p, &prf);
33675 p += get_opcode(p, &opcode);
33676
33677@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33678 struct prefix_bits prf;
33679 int i;
33680
33681- p = (unsigned char *)ins_addr;
33682+ p = (unsigned char *)ktla_ktva(ins_addr);
33683 p += skip_prefix(p, &prf);
33684 p += get_opcode(p, &opcode);
33685
33686@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33687 struct prefix_bits prf;
33688 int i;
33689
33690- p = (unsigned char *)ins_addr;
33691+ p = (unsigned char *)ktla_ktva(ins_addr);
33692 p += skip_prefix(p, &prf);
33693 p += get_opcode(p, &opcode);
33694
33695@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33696 struct prefix_bits prf;
33697 int i;
33698
33699- p = (unsigned char *)ins_addr;
33700+ p = (unsigned char *)ktla_ktva(ins_addr);
33701 p += skip_prefix(p, &prf);
33702 p += get_opcode(p, &opcode);
33703 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33704@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33705 struct prefix_bits prf;
33706 int i;
33707
33708- p = (unsigned char *)ins_addr;
33709+ p = (unsigned char *)ktla_ktva(ins_addr);
33710 p += skip_prefix(p, &prf);
33711 p += get_opcode(p, &opcode);
33712 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33713diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33714index c96314a..433b127 100644
33715--- a/arch/x86/mm/pgtable.c
33716+++ b/arch/x86/mm/pgtable.c
33717@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33718 list_del(&page->lru);
33719 }
33720
33721-#define UNSHARED_PTRS_PER_PGD \
33722- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33723+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33724+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33725
33726+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33727+{
33728+ unsigned int count = USER_PGD_PTRS;
33729
33730+ if (!pax_user_shadow_base)
33731+ return;
33732+
33733+ while (count--)
33734+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33735+}
33736+#endif
33737+
33738+#ifdef CONFIG_PAX_PER_CPU_PGD
33739+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33740+{
33741+ unsigned int count = USER_PGD_PTRS;
33742+
33743+ while (count--) {
33744+ pgd_t pgd;
33745+
33746+#ifdef CONFIG_X86_64
33747+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33748+#else
33749+ pgd = *src++;
33750+#endif
33751+
33752+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33753+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33754+#endif
33755+
33756+ *dst++ = pgd;
33757+ }
33758+
33759+}
33760+#endif
33761+
33762+#ifdef CONFIG_X86_64
33763+#define pxd_t pud_t
33764+#define pyd_t pgd_t
33765+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33766+#define pgtable_pxd_page_ctor(page) true
33767+#define pgtable_pxd_page_dtor(page)
33768+#define pxd_free(mm, pud) pud_free((mm), (pud))
33769+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33770+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33771+#define PYD_SIZE PGDIR_SIZE
33772+#else
33773+#define pxd_t pmd_t
33774+#define pyd_t pud_t
33775+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33776+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33777+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33778+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33779+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33780+#define pyd_offset(mm, address) pud_offset((mm), (address))
33781+#define PYD_SIZE PUD_SIZE
33782+#endif
33783+
33784+#ifdef CONFIG_PAX_PER_CPU_PGD
33785+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33786+static inline void pgd_dtor(pgd_t *pgd) {}
33787+#else
33788 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33789 {
33790 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33791@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33792 pgd_list_del(pgd);
33793 spin_unlock(&pgd_lock);
33794 }
33795+#endif
33796
33797 /*
33798 * List of all pgd's needed for non-PAE so it can invalidate entries
33799@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33800 * -- nyc
33801 */
33802
33803-#ifdef CONFIG_X86_PAE
33804+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33805 /*
33806 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33807 * updating the top-level pagetable entries to guarantee the
33808@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33809 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33810 * and initialize the kernel pmds here.
33811 */
33812-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33813+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33814
33815 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33816 {
33817@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33818 */
33819 flush_tlb_mm(mm);
33820 }
33821+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33822+#define PREALLOCATED_PXDS USER_PGD_PTRS
33823 #else /* !CONFIG_X86_PAE */
33824
33825 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33826-#define PREALLOCATED_PMDS 0
33827+#define PREALLOCATED_PXDS 0
33828
33829 #endif /* CONFIG_X86_PAE */
33830
33831-static void free_pmds(pmd_t *pmds[])
33832+static void free_pxds(pxd_t *pxds[])
33833 {
33834 int i;
33835
33836- for(i = 0; i < PREALLOCATED_PMDS; i++)
33837- if (pmds[i]) {
33838- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33839- free_page((unsigned long)pmds[i]);
33840+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33841+ if (pxds[i]) {
33842+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33843+ free_page((unsigned long)pxds[i]);
33844 }
33845 }
33846
33847-static int preallocate_pmds(pmd_t *pmds[])
33848+static int preallocate_pxds(pxd_t *pxds[])
33849 {
33850 int i;
33851 bool failed = false;
33852
33853- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33854- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33855- if (!pmd)
33856+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33857+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33858+ if (!pxd)
33859 failed = true;
33860- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33861- free_page((unsigned long)pmd);
33862- pmd = NULL;
33863+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33864+ free_page((unsigned long)pxd);
33865+ pxd = NULL;
33866 failed = true;
33867 }
33868- pmds[i] = pmd;
33869+ pxds[i] = pxd;
33870 }
33871
33872 if (failed) {
33873- free_pmds(pmds);
33874+ free_pxds(pxds);
33875 return -ENOMEM;
33876 }
33877
33878@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33879 * preallocate which never got a corresponding vma will need to be
33880 * freed manually.
33881 */
33882-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33883+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33884 {
33885 int i;
33886
33887- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33888+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33889 pgd_t pgd = pgdp[i];
33890
33891 if (pgd_val(pgd) != 0) {
33892- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33893+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33894
33895- pgdp[i] = native_make_pgd(0);
33896+ set_pgd(pgdp + i, native_make_pgd(0));
33897
33898- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33899- pmd_free(mm, pmd);
33900+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33901+ pxd_free(mm, pxd);
33902 }
33903 }
33904 }
33905
33906-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33907+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33908 {
33909- pud_t *pud;
33910+ pyd_t *pyd;
33911 int i;
33912
33913- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33914+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33915 return;
33916
33917- pud = pud_offset(pgd, 0);
33918-
33919- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33920- pmd_t *pmd = pmds[i];
33921+#ifdef CONFIG_X86_64
33922+ pyd = pyd_offset(mm, 0L);
33923+#else
33924+ pyd = pyd_offset(pgd, 0L);
33925+#endif
33926
33927+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33928+ pxd_t *pxd = pxds[i];
33929 if (i >= KERNEL_PGD_BOUNDARY)
33930- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33931- sizeof(pmd_t) * PTRS_PER_PMD);
33932+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33933+ sizeof(pxd_t) * PTRS_PER_PMD);
33934
33935- pud_populate(mm, pud, pmd);
33936+ pyd_populate(mm, pyd, pxd);
33937 }
33938 }
33939
33940 pgd_t *pgd_alloc(struct mm_struct *mm)
33941 {
33942 pgd_t *pgd;
33943- pmd_t *pmds[PREALLOCATED_PMDS];
33944+ pxd_t *pxds[PREALLOCATED_PXDS];
33945
33946 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33947
33948@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33949
33950 mm->pgd = pgd;
33951
33952- if (preallocate_pmds(pmds) != 0)
33953+ if (preallocate_pxds(pxds) != 0)
33954 goto out_free_pgd;
33955
33956 if (paravirt_pgd_alloc(mm) != 0)
33957- goto out_free_pmds;
33958+ goto out_free_pxds;
33959
33960 /*
33961 * Make sure that pre-populating the pmds is atomic with
33962@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33963 spin_lock(&pgd_lock);
33964
33965 pgd_ctor(mm, pgd);
33966- pgd_prepopulate_pmd(mm, pgd, pmds);
33967+ pgd_prepopulate_pxd(mm, pgd, pxds);
33968
33969 spin_unlock(&pgd_lock);
33970
33971 return pgd;
33972
33973-out_free_pmds:
33974- free_pmds(pmds);
33975+out_free_pxds:
33976+ free_pxds(pxds);
33977 out_free_pgd:
33978 free_page((unsigned long)pgd);
33979 out:
33980@@ -313,7 +380,7 @@ out:
33981
33982 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33983 {
33984- pgd_mop_up_pmds(mm, pgd);
33985+ pgd_mop_up_pxds(mm, pgd);
33986 pgd_dtor(pgd);
33987 paravirt_pgd_free(mm, pgd);
33988 free_page((unsigned long)pgd);
33989diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33990index a69bcb8..19068ab 100644
33991--- a/arch/x86/mm/pgtable_32.c
33992+++ b/arch/x86/mm/pgtable_32.c
33993@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33994 return;
33995 }
33996 pte = pte_offset_kernel(pmd, vaddr);
33997+
33998+ pax_open_kernel();
33999 if (pte_val(pteval))
34000 set_pte_at(&init_mm, vaddr, pte, pteval);
34001 else
34002 pte_clear(&init_mm, vaddr, pte);
34003+ pax_close_kernel();
34004
34005 /*
34006 * It's enough to flush this one mapping.
34007diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34008index e666cbb..61788c45 100644
34009--- a/arch/x86/mm/physaddr.c
34010+++ b/arch/x86/mm/physaddr.c
34011@@ -10,7 +10,7 @@
34012 #ifdef CONFIG_X86_64
34013
34014 #ifdef CONFIG_DEBUG_VIRTUAL
34015-unsigned long __phys_addr(unsigned long x)
34016+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34017 {
34018 unsigned long y = x - __START_KERNEL_map;
34019
34020@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34021 #else
34022
34023 #ifdef CONFIG_DEBUG_VIRTUAL
34024-unsigned long __phys_addr(unsigned long x)
34025+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34026 {
34027 unsigned long phys_addr = x - PAGE_OFFSET;
34028 /* VMALLOC_* aren't constants */
34029diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34030index 90555bf..f5f1828 100644
34031--- a/arch/x86/mm/setup_nx.c
34032+++ b/arch/x86/mm/setup_nx.c
34033@@ -5,8 +5,10 @@
34034 #include <asm/pgtable.h>
34035 #include <asm/proto.h>
34036
34037+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34038 static int disable_nx;
34039
34040+#ifndef CONFIG_PAX_PAGEEXEC
34041 /*
34042 * noexec = on|off
34043 *
34044@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34045 return 0;
34046 }
34047 early_param("noexec", noexec_setup);
34048+#endif
34049+
34050+#endif
34051
34052 void x86_configure_nx(void)
34053 {
34054+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34055 if (cpu_has_nx && !disable_nx)
34056 __supported_pte_mask |= _PAGE_NX;
34057 else
34058+#endif
34059 __supported_pte_mask &= ~_PAGE_NX;
34060 }
34061
34062diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34063index dd8dda1..9e9b0f6 100644
34064--- a/arch/x86/mm/tlb.c
34065+++ b/arch/x86/mm/tlb.c
34066@@ -48,7 +48,11 @@ void leave_mm(int cpu)
34067 BUG();
34068 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34069 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34070+
34071+#ifndef CONFIG_PAX_PER_CPU_PGD
34072 load_cr3(swapper_pg_dir);
34073+#endif
34074+
34075 }
34076 }
34077 EXPORT_SYMBOL_GPL(leave_mm);
34078diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34079new file mode 100644
34080index 0000000..dace51c
34081--- /dev/null
34082+++ b/arch/x86/mm/uderef_64.c
34083@@ -0,0 +1,37 @@
34084+#include <linux/mm.h>
34085+#include <asm/pgtable.h>
34086+#include <asm/uaccess.h>
34087+
34088+#ifdef CONFIG_PAX_MEMORY_UDEREF
34089+/* PaX: due to the special call convention these functions must
34090+ * - remain leaf functions under all configurations,
34091+ * - never be called directly, only dereferenced from the wrappers.
34092+ */
34093+void __pax_open_userland(void)
34094+{
34095+ unsigned int cpu;
34096+
34097+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34098+ return;
34099+
34100+ cpu = raw_get_cpu();
34101+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34102+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34103+ raw_put_cpu_no_resched();
34104+}
34105+EXPORT_SYMBOL(__pax_open_userland);
34106+
34107+void __pax_close_userland(void)
34108+{
34109+ unsigned int cpu;
34110+
34111+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34112+ return;
34113+
34114+ cpu = raw_get_cpu();
34115+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34116+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34117+ raw_put_cpu_no_resched();
34118+}
34119+EXPORT_SYMBOL(__pax_close_userland);
34120+#endif
34121diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34122index 0149575..f746de8 100644
34123--- a/arch/x86/net/bpf_jit.S
34124+++ b/arch/x86/net/bpf_jit.S
34125@@ -9,6 +9,7 @@
34126 */
34127 #include <linux/linkage.h>
34128 #include <asm/dwarf2.h>
34129+#include <asm/alternative-asm.h>
34130
34131 /*
34132 * Calling convention :
34133@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
34134 jle bpf_slow_path_word
34135 mov (SKBDATA,%rsi),%eax
34136 bswap %eax /* ntohl() */
34137+ pax_force_retaddr
34138 ret
34139
34140 sk_load_half:
34141@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
34142 jle bpf_slow_path_half
34143 movzwl (SKBDATA,%rsi),%eax
34144 rol $8,%ax # ntohs()
34145+ pax_force_retaddr
34146 ret
34147
34148 sk_load_byte:
34149@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
34150 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34151 jle bpf_slow_path_byte
34152 movzbl (SKBDATA,%rsi),%eax
34153+ pax_force_retaddr
34154 ret
34155
34156 /**
34157@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
34158 movzbl (SKBDATA,%rsi),%ebx
34159 and $15,%bl
34160 shl $2,%bl
34161+ pax_force_retaddr
34162 ret
34163
34164 /* rsi contains offset and can be scratched */
34165@@ -109,6 +114,7 @@ bpf_slow_path_word:
34166 js bpf_error
34167 mov -12(%rbp),%eax
34168 bswap %eax
34169+ pax_force_retaddr
34170 ret
34171
34172 bpf_slow_path_half:
34173@@ -117,12 +123,14 @@ bpf_slow_path_half:
34174 mov -12(%rbp),%ax
34175 rol $8,%ax
34176 movzwl %ax,%eax
34177+ pax_force_retaddr
34178 ret
34179
34180 bpf_slow_path_byte:
34181 bpf_slow_path_common(1)
34182 js bpf_error
34183 movzbl -12(%rbp),%eax
34184+ pax_force_retaddr
34185 ret
34186
34187 bpf_slow_path_byte_msh:
34188@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
34189 and $15,%al
34190 shl $2,%al
34191 xchg %eax,%ebx
34192+ pax_force_retaddr
34193 ret
34194
34195 #define sk_negative_common(SIZE) \
34196@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
34197 sk_negative_common(4)
34198 mov (%rax), %eax
34199 bswap %eax
34200+ pax_force_retaddr
34201 ret
34202
34203 bpf_slow_path_half_neg:
34204@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
34205 mov (%rax),%ax
34206 rol $8,%ax
34207 movzwl %ax,%eax
34208+ pax_force_retaddr
34209 ret
34210
34211 bpf_slow_path_byte_neg:
34212@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
34213 .globl sk_load_byte_negative_offset
34214 sk_negative_common(1)
34215 movzbl (%rax), %eax
34216+ pax_force_retaddr
34217 ret
34218
34219 bpf_slow_path_byte_msh_neg:
34220@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
34221 and $15,%al
34222 shl $2,%al
34223 xchg %eax,%ebx
34224+ pax_force_retaddr
34225 ret
34226
34227 bpf_error:
34228@@ -197,4 +210,5 @@ bpf_error:
34229 xor %eax,%eax
34230 mov -8(%rbp),%rbx
34231 leaveq
34232+ pax_force_retaddr
34233 ret
34234diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34235index af2d431..3cf24f0b 100644
34236--- a/arch/x86/net/bpf_jit_comp.c
34237+++ b/arch/x86/net/bpf_jit_comp.c
34238@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34239 return ptr + len;
34240 }
34241
34242+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34243+#define MAX_INSTR_CODE_SIZE 96
34244+#else
34245+#define MAX_INSTR_CODE_SIZE 64
34246+#endif
34247+
34248 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
34249
34250 #define EMIT1(b1) EMIT(b1, 1)
34251 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
34252 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
34253 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
34254+
34255+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34256+/* original constant will appear in ecx */
34257+#define DILUTE_CONST_SEQUENCE(_off, _key) \
34258+do { \
34259+ /* mov ecx, randkey */ \
34260+ EMIT1(0xb9); \
34261+ EMIT(_key, 4); \
34262+ /* xor ecx, randkey ^ off */ \
34263+ EMIT2(0x81, 0xf1); \
34264+ EMIT((_key) ^ (_off), 4); \
34265+} while (0)
34266+
34267+#define EMIT1_off32(b1, _off) \
34268+do { \
34269+ switch (b1) { \
34270+ case 0x05: /* add eax, imm32 */ \
34271+ case 0x2d: /* sub eax, imm32 */ \
34272+ case 0x25: /* and eax, imm32 */ \
34273+ case 0x0d: /* or eax, imm32 */ \
34274+ case 0xb8: /* mov eax, imm32 */ \
34275+ case 0x35: /* xor eax, imm32 */ \
34276+ case 0x3d: /* cmp eax, imm32 */ \
34277+ case 0xa9: /* test eax, imm32 */ \
34278+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34279+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
34280+ break; \
34281+ case 0xbb: /* mov ebx, imm32 */ \
34282+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34283+ /* mov ebx, ecx */ \
34284+ EMIT2(0x89, 0xcb); \
34285+ break; \
34286+ case 0xbe: /* mov esi, imm32 */ \
34287+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34288+ /* mov esi, ecx */ \
34289+ EMIT2(0x89, 0xce); \
34290+ break; \
34291+ case 0xe8: /* call rel imm32, always to known funcs */ \
34292+ EMIT1(b1); \
34293+ EMIT(_off, 4); \
34294+ break; \
34295+ case 0xe9: /* jmp rel imm32 */ \
34296+ EMIT1(b1); \
34297+ EMIT(_off, 4); \
34298+ /* prevent fall-through, we're not called if off = 0 */ \
34299+ EMIT(0xcccccccc, 4); \
34300+ EMIT(0xcccccccc, 4); \
34301+ break; \
34302+ default: \
34303+ BUILD_BUG(); \
34304+ } \
34305+} while (0)
34306+
34307+#define EMIT2_off32(b1, b2, _off) \
34308+do { \
34309+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
34310+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
34311+ EMIT(randkey, 4); \
34312+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
34313+ EMIT((_off) - randkey, 4); \
34314+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
34315+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34316+ /* imul eax, ecx */ \
34317+ EMIT3(0x0f, 0xaf, 0xc1); \
34318+ } else { \
34319+ BUILD_BUG(); \
34320+ } \
34321+} while (0)
34322+#else
34323 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
34324+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
34325+#endif
34326
34327 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
34328 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
34329@@ -91,6 +168,24 @@ do { \
34330 #define X86_JBE 0x76
34331 #define X86_JA 0x77
34332
34333+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34334+#define APPEND_FLOW_VERIFY() \
34335+do { \
34336+ /* mov ecx, randkey */ \
34337+ EMIT1(0xb9); \
34338+ EMIT(randkey, 4); \
34339+ /* cmp ecx, randkey */ \
34340+ EMIT2(0x81, 0xf9); \
34341+ EMIT(randkey, 4); \
34342+ /* jz after 8 int 3s */ \
34343+ EMIT2(0x74, 0x08); \
34344+ EMIT(0xcccccccc, 4); \
34345+ EMIT(0xcccccccc, 4); \
34346+} while (0)
34347+#else
34348+#define APPEND_FLOW_VERIFY() do { } while (0)
34349+#endif
34350+
34351 #define EMIT_COND_JMP(op, offset) \
34352 do { \
34353 if (is_near(offset)) \
34354@@ -98,6 +193,7 @@ do { \
34355 else { \
34356 EMIT2(0x0f, op + 0x10); \
34357 EMIT(offset, 4); /* jxx .+off32 */ \
34358+ APPEND_FLOW_VERIFY(); \
34359 } \
34360 } while (0)
34361
34362@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
34363 return -1;
34364 }
34365
34366-struct bpf_binary_header {
34367- unsigned int pages;
34368- /* Note : for security reasons, bpf code will follow a randomly
34369- * sized amount of int3 instructions
34370- */
34371- u8 image[];
34372-};
34373-
34374-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34375+/* Note : for security reasons, bpf code will follow a randomly
34376+ * sized amount of int3 instructions
34377+ */
34378+static u8 *bpf_alloc_binary(unsigned int proglen,
34379 u8 **image_ptr)
34380 {
34381 unsigned int sz, hole;
34382- struct bpf_binary_header *header;
34383+ u8 *header;
34384
34385 /* Most of BPF filters are really small,
34386 * but if some of them fill a page, allow at least
34387 * 128 extra bytes to insert a random section of int3
34388 */
34389- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34390- header = module_alloc(sz);
34391+ sz = round_up(proglen + 128, PAGE_SIZE);
34392+ header = module_alloc_exec(sz);
34393 if (!header)
34394 return NULL;
34395
34396+ pax_open_kernel();
34397 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34398+ pax_close_kernel();
34399
34400- header->pages = sz / PAGE_SIZE;
34401- hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34402+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34403
34404 /* insert a random number of int3 instructions before BPF code */
34405- *image_ptr = &header->image[prandom_u32() % hole];
34406+ *image_ptr = &header[prandom_u32() % hole];
34407 return header;
34408 }
34409
34410 void bpf_jit_compile(struct sk_filter *fp)
34411 {
34412- u8 temp[64];
34413+ u8 temp[MAX_INSTR_CODE_SIZE];
34414 u8 *prog;
34415 unsigned int proglen, oldproglen = 0;
34416 int ilen, i;
34417 int t_offset, f_offset;
34418 u8 t_op, f_op, seen = 0, pass;
34419 u8 *image = NULL;
34420- struct bpf_binary_header *header = NULL;
34421+ u8 *header = NULL;
34422 u8 *func;
34423 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34424 unsigned int cleanup_addr; /* epilogue code offset */
34425 unsigned int *addrs;
34426 const struct sock_filter *filter = fp->insns;
34427 int flen = fp->len;
34428+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34429+ unsigned int randkey;
34430+#endif
34431
34432 if (!bpf_jit_enable)
34433 return;
34434@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34435 return;
34436
34437 /* Before first pass, make a rough estimation of addrs[]
34438- * each bpf instruction is translated to less than 64 bytes
34439+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34440 */
34441 for (proglen = 0, i = 0; i < flen; i++) {
34442- proglen += 64;
34443+ proglen += MAX_INSTR_CODE_SIZE;
34444 addrs[i] = proglen;
34445 }
34446 cleanup_addr = proglen; /* epilogue address */
34447@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34448 for (i = 0; i < flen; i++) {
34449 unsigned int K = filter[i].k;
34450
34451+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34452+ randkey = prandom_u32();
34453+#endif
34454+
34455 switch (filter[i].code) {
34456 case BPF_S_ALU_ADD_X: /* A += X; */
34457 seen |= SEEN_XREG;
34458@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34459 case BPF_S_ALU_MUL_K: /* A *= K */
34460 if (is_imm8(K))
34461 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34462- else {
34463- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34464- EMIT(K, 4);
34465- }
34466+ else
34467+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34468 break;
34469 case BPF_S_ALU_DIV_X: /* A /= X; */
34470 seen |= SEEN_XREG;
34471@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34472 break;
34473 }
34474 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34475+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34476+ DILUTE_CONST_SEQUENCE(K, randkey);
34477+#else
34478 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34479+#endif
34480 EMIT2(0xf7, 0xf1); /* div %ecx */
34481 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34482 break;
34483@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34484 if (K == 1)
34485 break;
34486 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34487+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34488+ DILUTE_CONST_SEQUENCE(K, randkey);
34489+#else
34490 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34491+#endif
34492 EMIT2(0xf7, 0xf1); /* div %ecx */
34493 break;
34494 case BPF_S_ALU_AND_X:
34495@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34496 if (is_imm8(K)) {
34497 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34498 } else {
34499- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34500- EMIT(K, 4);
34501+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34502 }
34503 } else {
34504 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34505@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34506 if (unlikely(proglen + ilen > oldproglen)) {
34507 pr_err("bpb_jit_compile fatal error\n");
34508 kfree(addrs);
34509- module_free(NULL, header);
34510+ module_free_exec(NULL, image);
34511 return;
34512 }
34513+ pax_open_kernel();
34514 memcpy(image + proglen, temp, ilen);
34515+ pax_close_kernel();
34516 }
34517 proglen += ilen;
34518 addrs[i] = proglen;
34519@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34520
34521 if (image) {
34522 bpf_flush_icache(header, image + proglen);
34523- set_memory_ro((unsigned long)header, header->pages);
34524 fp->bpf_func = (void *)image;
34525 }
34526 out:
34527@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34528 {
34529 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34530 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34531- struct bpf_binary_header *header = (void *)addr;
34532
34533- set_memory_rw(addr, header->pages);
34534- module_free(NULL, header);
34535+ set_memory_rw(addr, 1);
34536+ module_free_exec(NULL, (void *)addr);
34537 kfree(fp);
34538 }
34539
34540diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34541index 5d04be5..2beeaa2 100644
34542--- a/arch/x86/oprofile/backtrace.c
34543+++ b/arch/x86/oprofile/backtrace.c
34544@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34545 struct stack_frame_ia32 *fp;
34546 unsigned long bytes;
34547
34548- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34549+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34550 if (bytes != 0)
34551 return NULL;
34552
34553- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34554+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34555
34556 oprofile_add_trace(bufhead[0].return_address);
34557
34558@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34559 struct stack_frame bufhead[2];
34560 unsigned long bytes;
34561
34562- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34563+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34564 if (bytes != 0)
34565 return NULL;
34566
34567@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34568 {
34569 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34570
34571- if (!user_mode_vm(regs)) {
34572+ if (!user_mode(regs)) {
34573 unsigned long stack = kernel_stack_pointer(regs);
34574 if (depth)
34575 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34576diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34577index 6890d84..1dad1f1 100644
34578--- a/arch/x86/oprofile/nmi_int.c
34579+++ b/arch/x86/oprofile/nmi_int.c
34580@@ -23,6 +23,7 @@
34581 #include <asm/nmi.h>
34582 #include <asm/msr.h>
34583 #include <asm/apic.h>
34584+#include <asm/pgtable.h>
34585
34586 #include "op_counter.h"
34587 #include "op_x86_model.h"
34588@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34589 if (ret)
34590 return ret;
34591
34592- if (!model->num_virt_counters)
34593- model->num_virt_counters = model->num_counters;
34594+ if (!model->num_virt_counters) {
34595+ pax_open_kernel();
34596+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34597+ pax_close_kernel();
34598+ }
34599
34600 mux_init(ops);
34601
34602diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34603index 50d86c0..7985318 100644
34604--- a/arch/x86/oprofile/op_model_amd.c
34605+++ b/arch/x86/oprofile/op_model_amd.c
34606@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34607 num_counters = AMD64_NUM_COUNTERS;
34608 }
34609
34610- op_amd_spec.num_counters = num_counters;
34611- op_amd_spec.num_controls = num_counters;
34612- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34613+ pax_open_kernel();
34614+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34615+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34616+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34617+ pax_close_kernel();
34618
34619 return 0;
34620 }
34621diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34622index d90528e..0127e2b 100644
34623--- a/arch/x86/oprofile/op_model_ppro.c
34624+++ b/arch/x86/oprofile/op_model_ppro.c
34625@@ -19,6 +19,7 @@
34626 #include <asm/msr.h>
34627 #include <asm/apic.h>
34628 #include <asm/nmi.h>
34629+#include <asm/pgtable.h>
34630
34631 #include "op_x86_model.h"
34632 #include "op_counter.h"
34633@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34634
34635 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34636
34637- op_arch_perfmon_spec.num_counters = num_counters;
34638- op_arch_perfmon_spec.num_controls = num_counters;
34639+ pax_open_kernel();
34640+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34641+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34642+ pax_close_kernel();
34643 }
34644
34645 static int arch_perfmon_init(struct oprofile_operations *ignore)
34646diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34647index 71e8a67..6a313bb 100644
34648--- a/arch/x86/oprofile/op_x86_model.h
34649+++ b/arch/x86/oprofile/op_x86_model.h
34650@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34651 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34652 struct op_msrs const * const msrs);
34653 #endif
34654-};
34655+} __do_const;
34656
34657 struct op_counter_config;
34658
34659diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34660index 84b9d67..260e5ff 100644
34661--- a/arch/x86/pci/intel_mid_pci.c
34662+++ b/arch/x86/pci/intel_mid_pci.c
34663@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34664 pr_info("Intel MID platform detected, using MID PCI ops\n");
34665 pci_mmcfg_late_init();
34666 pcibios_enable_irq = intel_mid_pci_irq_enable;
34667- pci_root_ops = intel_mid_pci_ops;
34668+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34669 pci_soc_mode = 1;
34670 /* Continue with standard init */
34671 return 1;
34672diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34673index 372e9b8..e775a6c 100644
34674--- a/arch/x86/pci/irq.c
34675+++ b/arch/x86/pci/irq.c
34676@@ -50,7 +50,7 @@ struct irq_router {
34677 struct irq_router_handler {
34678 u16 vendor;
34679 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34680-};
34681+} __do_const;
34682
34683 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34684 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34685@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34686 return 0;
34687 }
34688
34689-static __initdata struct irq_router_handler pirq_routers[] = {
34690+static __initconst const struct irq_router_handler pirq_routers[] = {
34691 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34692 { PCI_VENDOR_ID_AL, ali_router_probe },
34693 { PCI_VENDOR_ID_ITE, ite_router_probe },
34694@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34695 static void __init pirq_find_router(struct irq_router *r)
34696 {
34697 struct irq_routing_table *rt = pirq_table;
34698- struct irq_router_handler *h;
34699+ const struct irq_router_handler *h;
34700
34701 #ifdef CONFIG_PCI_BIOS
34702 if (!rt->signature) {
34703@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34704 return 0;
34705 }
34706
34707-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34708+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34709 {
34710 .callback = fix_broken_hp_bios_irq9,
34711 .ident = "HP Pavilion N5400 Series Laptop",
34712diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34713index c77b24a..c979855 100644
34714--- a/arch/x86/pci/pcbios.c
34715+++ b/arch/x86/pci/pcbios.c
34716@@ -79,7 +79,7 @@ union bios32 {
34717 static struct {
34718 unsigned long address;
34719 unsigned short segment;
34720-} bios32_indirect = { 0, __KERNEL_CS };
34721+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34722
34723 /*
34724 * Returns the entry point for the given service, NULL on error
34725@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34726 unsigned long length; /* %ecx */
34727 unsigned long entry; /* %edx */
34728 unsigned long flags;
34729+ struct desc_struct d, *gdt;
34730
34731 local_irq_save(flags);
34732- __asm__("lcall *(%%edi); cld"
34733+
34734+ gdt = get_cpu_gdt_table(smp_processor_id());
34735+
34736+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34737+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34738+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34739+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34740+
34741+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34742 : "=a" (return_code),
34743 "=b" (address),
34744 "=c" (length),
34745 "=d" (entry)
34746 : "0" (service),
34747 "1" (0),
34748- "D" (&bios32_indirect));
34749+ "D" (&bios32_indirect),
34750+ "r"(__PCIBIOS_DS)
34751+ : "memory");
34752+
34753+ pax_open_kernel();
34754+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34755+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34756+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34757+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34758+ pax_close_kernel();
34759+
34760 local_irq_restore(flags);
34761
34762 switch (return_code) {
34763- case 0:
34764- return address + entry;
34765- case 0x80: /* Not present */
34766- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34767- return 0;
34768- default: /* Shouldn't happen */
34769- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34770- service, return_code);
34771+ case 0: {
34772+ int cpu;
34773+ unsigned char flags;
34774+
34775+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34776+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34777+ printk(KERN_WARNING "bios32_service: not valid\n");
34778 return 0;
34779+ }
34780+ address = address + PAGE_OFFSET;
34781+ length += 16UL; /* some BIOSs underreport this... */
34782+ flags = 4;
34783+ if (length >= 64*1024*1024) {
34784+ length >>= PAGE_SHIFT;
34785+ flags |= 8;
34786+ }
34787+
34788+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34789+ gdt = get_cpu_gdt_table(cpu);
34790+ pack_descriptor(&d, address, length, 0x9b, flags);
34791+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34792+ pack_descriptor(&d, address, length, 0x93, flags);
34793+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34794+ }
34795+ return entry;
34796+ }
34797+ case 0x80: /* Not present */
34798+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34799+ return 0;
34800+ default: /* Shouldn't happen */
34801+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34802+ service, return_code);
34803+ return 0;
34804 }
34805 }
34806
34807 static struct {
34808 unsigned long address;
34809 unsigned short segment;
34810-} pci_indirect = { 0, __KERNEL_CS };
34811+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34812
34813-static int pci_bios_present;
34814+static int pci_bios_present __read_only;
34815
34816 static int check_pcibios(void)
34817 {
34818@@ -131,11 +174,13 @@ static int check_pcibios(void)
34819 unsigned long flags, pcibios_entry;
34820
34821 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34822- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34823+ pci_indirect.address = pcibios_entry;
34824
34825 local_irq_save(flags);
34826- __asm__(
34827- "lcall *(%%edi); cld\n\t"
34828+ __asm__("movw %w6, %%ds\n\t"
34829+ "lcall *%%ss:(%%edi); cld\n\t"
34830+ "push %%ss\n\t"
34831+ "pop %%ds\n\t"
34832 "jc 1f\n\t"
34833 "xor %%ah, %%ah\n"
34834 "1:"
34835@@ -144,7 +189,8 @@ static int check_pcibios(void)
34836 "=b" (ebx),
34837 "=c" (ecx)
34838 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34839- "D" (&pci_indirect)
34840+ "D" (&pci_indirect),
34841+ "r" (__PCIBIOS_DS)
34842 : "memory");
34843 local_irq_restore(flags);
34844
34845@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34846
34847 switch (len) {
34848 case 1:
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@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34858 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34859 "b" (bx),
34860 "D" ((long)reg),
34861- "S" (&pci_indirect));
34862+ "S" (&pci_indirect),
34863+ "r" (__PCIBIOS_DS));
34864 /*
34865 * Zero-extend the result beyond 8 bits, do not trust the
34866 * BIOS having done it:
34867@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34868 *value &= 0xff;
34869 break;
34870 case 2:
34871- __asm__("lcall *(%%esi); cld\n\t"
34872+ __asm__("movw %w6, %%ds\n\t"
34873+ "lcall *%%ss:(%%esi); cld\n\t"
34874+ "push %%ss\n\t"
34875+ "pop %%ds\n\t"
34876 "jc 1f\n\t"
34877 "xor %%ah, %%ah\n"
34878 "1:"
34879@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34880 : "1" (PCIBIOS_READ_CONFIG_WORD),
34881 "b" (bx),
34882 "D" ((long)reg),
34883- "S" (&pci_indirect));
34884+ "S" (&pci_indirect),
34885+ "r" (__PCIBIOS_DS));
34886 /*
34887 * Zero-extend the result beyond 16 bits, do not trust the
34888 * BIOS having done it:
34889@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34890 *value &= 0xffff;
34891 break;
34892 case 4:
34893- __asm__("lcall *(%%esi); cld\n\t"
34894+ __asm__("movw %w6, %%ds\n\t"
34895+ "lcall *%%ss:(%%esi); cld\n\t"
34896+ "push %%ss\n\t"
34897+ "pop %%ds\n\t"
34898 "jc 1f\n\t"
34899 "xor %%ah, %%ah\n"
34900 "1:"
34901@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34902 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34903 "b" (bx),
34904 "D" ((long)reg),
34905- "S" (&pci_indirect));
34906+ "S" (&pci_indirect),
34907+ "r" (__PCIBIOS_DS));
34908 break;
34909 }
34910
34911@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34912
34913 switch (len) {
34914 case 1:
34915- __asm__("lcall *(%%esi); cld\n\t"
34916+ __asm__("movw %w6, %%ds\n\t"
34917+ "lcall *%%ss:(%%esi); cld\n\t"
34918+ "push %%ss\n\t"
34919+ "pop %%ds\n\t"
34920 "jc 1f\n\t"
34921 "xor %%ah, %%ah\n"
34922 "1:"
34923@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34924 "c" (value),
34925 "b" (bx),
34926 "D" ((long)reg),
34927- "S" (&pci_indirect));
34928+ "S" (&pci_indirect),
34929+ "r" (__PCIBIOS_DS));
34930 break;
34931 case 2:
34932- __asm__("lcall *(%%esi); cld\n\t"
34933+ __asm__("movw %w6, %%ds\n\t"
34934+ "lcall *%%ss:(%%esi); cld\n\t"
34935+ "push %%ss\n\t"
34936+ "pop %%ds\n\t"
34937 "jc 1f\n\t"
34938 "xor %%ah, %%ah\n"
34939 "1:"
34940@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34941 "c" (value),
34942 "b" (bx),
34943 "D" ((long)reg),
34944- "S" (&pci_indirect));
34945+ "S" (&pci_indirect),
34946+ "r" (__PCIBIOS_DS));
34947 break;
34948 case 4:
34949- __asm__("lcall *(%%esi); cld\n\t"
34950+ __asm__("movw %w6, %%ds\n\t"
34951+ "lcall *%%ss:(%%esi); cld\n\t"
34952+ "push %%ss\n\t"
34953+ "pop %%ds\n\t"
34954 "jc 1f\n\t"
34955 "xor %%ah, %%ah\n"
34956 "1:"
34957@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34958 "c" (value),
34959 "b" (bx),
34960 "D" ((long)reg),
34961- "S" (&pci_indirect));
34962+ "S" (&pci_indirect),
34963+ "r" (__PCIBIOS_DS));
34964 break;
34965 }
34966
34967@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34968
34969 DBG("PCI: Fetching IRQ routing table... ");
34970 __asm__("push %%es\n\t"
34971+ "movw %w8, %%ds\n\t"
34972 "push %%ds\n\t"
34973 "pop %%es\n\t"
34974- "lcall *(%%esi); cld\n\t"
34975+ "lcall *%%ss:(%%esi); cld\n\t"
34976 "pop %%es\n\t"
34977+ "push %%ss\n\t"
34978+ "pop %%ds\n"
34979 "jc 1f\n\t"
34980 "xor %%ah, %%ah\n"
34981 "1:"
34982@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34983 "1" (0),
34984 "D" ((long) &opt),
34985 "S" (&pci_indirect),
34986- "m" (opt)
34987+ "m" (opt),
34988+ "r" (__PCIBIOS_DS)
34989 : "memory");
34990 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34991 if (ret & 0xff00)
34992@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34993 {
34994 int ret;
34995
34996- __asm__("lcall *(%%esi); cld\n\t"
34997+ __asm__("movw %w5, %%ds\n\t"
34998+ "lcall *%%ss:(%%esi); cld\n\t"
34999+ "push %%ss\n\t"
35000+ "pop %%ds\n"
35001 "jc 1f\n\t"
35002 "xor %%ah, %%ah\n"
35003 "1:"
35004@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35005 : "0" (PCIBIOS_SET_PCI_HW_INT),
35006 "b" ((dev->bus->number << 8) | dev->devfn),
35007 "c" ((irq << 8) | (pin + 10)),
35008- "S" (&pci_indirect));
35009+ "S" (&pci_indirect),
35010+ "r" (__PCIBIOS_DS));
35011 return !(ret & 0xff00);
35012 }
35013 EXPORT_SYMBOL(pcibios_set_irq_routing);
35014diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
35015index 9ee3491..872192f 100644
35016--- a/arch/x86/platform/efi/efi_32.c
35017+++ b/arch/x86/platform/efi/efi_32.c
35018@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
35019 {
35020 struct desc_ptr gdt_descr;
35021
35022+#ifdef CONFIG_PAX_KERNEXEC
35023+ struct desc_struct d;
35024+#endif
35025+
35026 local_irq_save(efi_rt_eflags);
35027
35028 load_cr3(initial_page_table);
35029 __flush_tlb_all();
35030
35031+#ifdef CONFIG_PAX_KERNEXEC
35032+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
35033+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35034+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
35035+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35036+#endif
35037+
35038 gdt_descr.address = __pa(get_cpu_gdt_table(0));
35039 gdt_descr.size = GDT_SIZE - 1;
35040 load_gdt(&gdt_descr);
35041@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
35042 {
35043 struct desc_ptr gdt_descr;
35044
35045+#ifdef CONFIG_PAX_KERNEXEC
35046+ struct desc_struct d;
35047+
35048+ memset(&d, 0, sizeof d);
35049+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35050+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35051+#endif
35052+
35053 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
35054 gdt_descr.size = GDT_SIZE - 1;
35055 load_gdt(&gdt_descr);
35056
35057+#ifdef CONFIG_PAX_PER_CPU_PGD
35058+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35059+#else
35060 load_cr3(swapper_pg_dir);
35061+#endif
35062+
35063 __flush_tlb_all();
35064
35065 local_irq_restore(efi_rt_eflags);
35066diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
35067index 666b74a..673d88f 100644
35068--- a/arch/x86/platform/efi/efi_64.c
35069+++ b/arch/x86/platform/efi/efi_64.c
35070@@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
35071 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
35072 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
35073 }
35074+
35075+#ifdef CONFIG_PAX_PER_CPU_PGD
35076+ load_cr3(swapper_pg_dir);
35077+#endif
35078+
35079 __flush_tlb_all();
35080 }
35081
35082@@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
35083 for (pgd = 0; pgd < n_pgds; pgd++)
35084 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
35085 kfree(save_pgd);
35086+
35087+#ifdef CONFIG_PAX_PER_CPU_PGD
35088+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35089+#endif
35090+
35091 __flush_tlb_all();
35092 local_irq_restore(efi_flags);
35093 early_code_mapping_set_exec(0);
35094diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
35095index fbe66e6..eae5e38 100644
35096--- a/arch/x86/platform/efi/efi_stub_32.S
35097+++ b/arch/x86/platform/efi/efi_stub_32.S
35098@@ -6,7 +6,9 @@
35099 */
35100
35101 #include <linux/linkage.h>
35102+#include <linux/init.h>
35103 #include <asm/page_types.h>
35104+#include <asm/segment.h>
35105
35106 /*
35107 * efi_call_phys(void *, ...) is a function with variable parameters.
35108@@ -20,7 +22,7 @@
35109 * service functions will comply with gcc calling convention, too.
35110 */
35111
35112-.text
35113+__INIT
35114 ENTRY(efi_call_phys)
35115 /*
35116 * 0. The function can only be called in Linux kernel. So CS has been
35117@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
35118 * The mapping of lower virtual memory has been created in prelog and
35119 * epilog.
35120 */
35121- movl $1f, %edx
35122- subl $__PAGE_OFFSET, %edx
35123- jmp *%edx
35124+#ifdef CONFIG_PAX_KERNEXEC
35125+ movl $(__KERNEXEC_EFI_DS), %edx
35126+ mov %edx, %ds
35127+ mov %edx, %es
35128+ mov %edx, %ss
35129+ addl $2f,(1f)
35130+ ljmp *(1f)
35131+
35132+__INITDATA
35133+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
35134+.previous
35135+
35136+2:
35137+ subl $2b,(1b)
35138+#else
35139+ jmp 1f-__PAGE_OFFSET
35140 1:
35141+#endif
35142
35143 /*
35144 * 2. Now on the top of stack is the return
35145@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35146 * parameter 2, ..., param n. To make things easy, we save the return
35147 * address of efi_call_phys in a global variable.
35148 */
35149- popl %edx
35150- movl %edx, saved_return_addr
35151- /* get the function pointer into ECX*/
35152- popl %ecx
35153- movl %ecx, efi_rt_function_ptr
35154- movl $2f, %edx
35155- subl $__PAGE_OFFSET, %edx
35156- pushl %edx
35157+ popl (saved_return_addr)
35158+ popl (efi_rt_function_ptr)
35159
35160 /*
35161 * 3. Clear PG bit in %CR0.
35162@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35163 /*
35164 * 5. Call the physical function.
35165 */
35166- jmp *%ecx
35167+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
35168
35169-2:
35170 /*
35171 * 6. After EFI runtime service returns, control will return to
35172 * following instruction. We'd better readjust stack pointer first.
35173@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35174 movl %cr0, %edx
35175 orl $0x80000000, %edx
35176 movl %edx, %cr0
35177- jmp 1f
35178-1:
35179+
35180 /*
35181 * 8. Now restore the virtual mode from flat mode by
35182 * adding EIP with PAGE_OFFSET.
35183 */
35184- movl $1f, %edx
35185- jmp *%edx
35186+#ifdef CONFIG_PAX_KERNEXEC
35187+ movl $(__KERNEL_DS), %edx
35188+ mov %edx, %ds
35189+ mov %edx, %es
35190+ mov %edx, %ss
35191+ ljmp $(__KERNEL_CS),$1f
35192+#else
35193+ jmp 1f+__PAGE_OFFSET
35194+#endif
35195 1:
35196
35197 /*
35198 * 9. Balance the stack. And because EAX contain the return value,
35199 * we'd better not clobber it.
35200 */
35201- leal efi_rt_function_ptr, %edx
35202- movl (%edx), %ecx
35203- pushl %ecx
35204+ pushl (efi_rt_function_ptr)
35205
35206 /*
35207- * 10. Push the saved return address onto the stack and return.
35208+ * 10. Return to the saved return address.
35209 */
35210- leal saved_return_addr, %edx
35211- movl (%edx), %ecx
35212- pushl %ecx
35213- ret
35214+ jmpl *(saved_return_addr)
35215 ENDPROC(efi_call_phys)
35216 .previous
35217
35218-.data
35219+__INITDATA
35220 saved_return_addr:
35221 .long 0
35222 efi_rt_function_ptr:
35223diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35224index 88073b1..1cc2f53 100644
35225--- a/arch/x86/platform/efi/efi_stub_64.S
35226+++ b/arch/x86/platform/efi/efi_stub_64.S
35227@@ -7,6 +7,7 @@
35228 */
35229
35230 #include <linux/linkage.h>
35231+#include <asm/alternative-asm.h>
35232
35233 #define SAVE_XMM \
35234 mov %rsp, %rax; \
35235@@ -77,6 +78,7 @@ ENTRY(efi_call0)
35236 RESTORE_PGT
35237 addq $32, %rsp
35238 RESTORE_XMM
35239+ pax_force_retaddr 0, 1
35240 ret
35241 ENDPROC(efi_call0)
35242
35243@@ -89,6 +91,7 @@ ENTRY(efi_call1)
35244 RESTORE_PGT
35245 addq $32, %rsp
35246 RESTORE_XMM
35247+ pax_force_retaddr 0, 1
35248 ret
35249 ENDPROC(efi_call1)
35250
35251@@ -101,6 +104,7 @@ ENTRY(efi_call2)
35252 RESTORE_PGT
35253 addq $32, %rsp
35254 RESTORE_XMM
35255+ pax_force_retaddr 0, 1
35256 ret
35257 ENDPROC(efi_call2)
35258
35259@@ -114,6 +118,7 @@ ENTRY(efi_call3)
35260 RESTORE_PGT
35261 addq $32, %rsp
35262 RESTORE_XMM
35263+ pax_force_retaddr 0, 1
35264 ret
35265 ENDPROC(efi_call3)
35266
35267@@ -128,6 +133,7 @@ ENTRY(efi_call4)
35268 RESTORE_PGT
35269 addq $32, %rsp
35270 RESTORE_XMM
35271+ pax_force_retaddr 0, 1
35272 ret
35273 ENDPROC(efi_call4)
35274
35275@@ -143,6 +149,7 @@ ENTRY(efi_call5)
35276 RESTORE_PGT
35277 addq $48, %rsp
35278 RESTORE_XMM
35279+ pax_force_retaddr 0, 1
35280 ret
35281 ENDPROC(efi_call5)
35282
35283@@ -161,6 +168,7 @@ ENTRY(efi_call6)
35284 RESTORE_PGT
35285 addq $48, %rsp
35286 RESTORE_XMM
35287+ pax_force_retaddr 0, 1
35288 ret
35289 ENDPROC(efi_call6)
35290
35291diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35292index 1bbedc4..eb795b5 100644
35293--- a/arch/x86/platform/intel-mid/intel-mid.c
35294+++ b/arch/x86/platform/intel-mid/intel-mid.c
35295@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35296 {
35297 };
35298
35299-static void intel_mid_reboot(void)
35300+static void __noreturn intel_mid_reboot(void)
35301 {
35302 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35303+ BUG();
35304 }
35305
35306 static unsigned long __init intel_mid_calibrate_tsc(void)
35307diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35308index d6ee929..3637cb5 100644
35309--- a/arch/x86/platform/olpc/olpc_dt.c
35310+++ b/arch/x86/platform/olpc/olpc_dt.c
35311@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35312 return res;
35313 }
35314
35315-static struct of_pdt_ops prom_olpc_ops __initdata = {
35316+static struct of_pdt_ops prom_olpc_ops __initconst = {
35317 .nextprop = olpc_dt_nextprop,
35318 .getproplen = olpc_dt_getproplen,
35319 .getproperty = olpc_dt_getproperty,
35320diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35321index 424f4c9..f2a2988 100644
35322--- a/arch/x86/power/cpu.c
35323+++ b/arch/x86/power/cpu.c
35324@@ -137,11 +137,8 @@ static void do_fpu_end(void)
35325 static void fix_processor_context(void)
35326 {
35327 int cpu = smp_processor_id();
35328- struct tss_struct *t = &per_cpu(init_tss, cpu);
35329-#ifdef CONFIG_X86_64
35330- struct desc_struct *desc = get_cpu_gdt_table(cpu);
35331- tss_desc tss;
35332-#endif
35333+ struct tss_struct *t = init_tss + cpu;
35334+
35335 set_tss_desc(cpu, t); /*
35336 * This just modifies memory; should not be
35337 * necessary. But... This is necessary, because
35338@@ -150,10 +147,6 @@ static void fix_processor_context(void)
35339 */
35340
35341 #ifdef CONFIG_X86_64
35342- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35343- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35344- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35345-
35346 syscall_init(); /* This sets MSR_*STAR and related */
35347 #endif
35348 load_TR_desc(); /* This does ltr */
35349diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35350index bad628a..a102610 100644
35351--- a/arch/x86/realmode/init.c
35352+++ b/arch/x86/realmode/init.c
35353@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35354 __va(real_mode_header->trampoline_header);
35355
35356 #ifdef CONFIG_X86_32
35357- trampoline_header->start = __pa_symbol(startup_32_smp);
35358+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35359+
35360+#ifdef CONFIG_PAX_KERNEXEC
35361+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35362+#endif
35363+
35364+ trampoline_header->boot_cs = __BOOT_CS;
35365 trampoline_header->gdt_limit = __BOOT_DS + 7;
35366 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35367 #else
35368@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35369 *trampoline_cr4_features = read_cr4();
35370
35371 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35372- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35373+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35374 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35375 #endif
35376 }
35377diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35378index 3497f14..cc73b92 100644
35379--- a/arch/x86/realmode/rm/Makefile
35380+++ b/arch/x86/realmode/rm/Makefile
35381@@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35382
35383 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35384 -I$(srctree)/arch/x86/boot
35385+ifdef CONSTIFY_PLUGIN
35386+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35387+endif
35388 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35389 GCOV_PROFILE := n
35390diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35391index a28221d..93c40f1 100644
35392--- a/arch/x86/realmode/rm/header.S
35393+++ b/arch/x86/realmode/rm/header.S
35394@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35395 #endif
35396 /* APM/BIOS reboot */
35397 .long pa_machine_real_restart_asm
35398-#ifdef CONFIG_X86_64
35399+#ifdef CONFIG_X86_32
35400+ .long __KERNEL_CS
35401+#else
35402 .long __KERNEL32_CS
35403 #endif
35404 END(real_mode_header)
35405diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35406index 48ddd76..c26749f 100644
35407--- a/arch/x86/realmode/rm/trampoline_32.S
35408+++ b/arch/x86/realmode/rm/trampoline_32.S
35409@@ -24,6 +24,12 @@
35410 #include <asm/page_types.h>
35411 #include "realmode.h"
35412
35413+#ifdef CONFIG_PAX_KERNEXEC
35414+#define ta(X) (X)
35415+#else
35416+#define ta(X) (pa_ ## X)
35417+#endif
35418+
35419 .text
35420 .code16
35421
35422@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35423
35424 cli # We should be safe anyway
35425
35426- movl tr_start, %eax # where we need to go
35427-
35428 movl $0xA5A5A5A5, trampoline_status
35429 # write marker for master knows we're running
35430
35431@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35432 movw $1, %dx # protected mode (PE) bit
35433 lmsw %dx # into protected mode
35434
35435- ljmpl $__BOOT_CS, $pa_startup_32
35436+ ljmpl *(trampoline_header)
35437
35438 .section ".text32","ax"
35439 .code32
35440@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35441 .balign 8
35442 GLOBAL(trampoline_header)
35443 tr_start: .space 4
35444- tr_gdt_pad: .space 2
35445+ tr_boot_cs: .space 2
35446 tr_gdt: .space 6
35447 END(trampoline_header)
35448
35449diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35450index dac7b20..72dbaca 100644
35451--- a/arch/x86/realmode/rm/trampoline_64.S
35452+++ b/arch/x86/realmode/rm/trampoline_64.S
35453@@ -93,6 +93,7 @@ ENTRY(startup_32)
35454 movl %edx, %gs
35455
35456 movl pa_tr_cr4, %eax
35457+ andl $~X86_CR4_PCIDE, %eax
35458 movl %eax, %cr4 # Enable PAE mode
35459
35460 # Setup trampoline 4 level pagetables
35461@@ -106,7 +107,7 @@ ENTRY(startup_32)
35462 wrmsr
35463
35464 # Enable paging and in turn activate Long Mode
35465- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35466+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35467 movl %eax, %cr0
35468
35469 /*
35470diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35471index 9e7e147..25a4158 100644
35472--- a/arch/x86/realmode/rm/wakeup_asm.S
35473+++ b/arch/x86/realmode/rm/wakeup_asm.S
35474@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35475 lgdtl pmode_gdt
35476
35477 /* This really couldn't... */
35478- movl pmode_entry, %eax
35479 movl pmode_cr0, %ecx
35480 movl %ecx, %cr0
35481- ljmpl $__KERNEL_CS, $pa_startup_32
35482- /* -> jmp *%eax in trampoline_32.S */
35483+
35484+ ljmpl *pmode_entry
35485 #else
35486 jmp trampoline_start
35487 #endif
35488diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35489index e812034..c747134 100644
35490--- a/arch/x86/tools/Makefile
35491+++ b/arch/x86/tools/Makefile
35492@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35493
35494 $(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
35495
35496-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35497+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35498 hostprogs-y += relocs
35499 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35500 relocs: $(obj)/relocs
35501diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35502index cfbdbdb..1aa763c 100644
35503--- a/arch/x86/tools/relocs.c
35504+++ b/arch/x86/tools/relocs.c
35505@@ -1,5 +1,7 @@
35506 /* This is included from relocs_32/64.c */
35507
35508+#include "../../../include/generated/autoconf.h"
35509+
35510 #define ElfW(type) _ElfW(ELF_BITS, type)
35511 #define _ElfW(bits, type) __ElfW(bits, type)
35512 #define __ElfW(bits, type) Elf##bits##_##type
35513@@ -11,6 +13,7 @@
35514 #define Elf_Sym ElfW(Sym)
35515
35516 static Elf_Ehdr ehdr;
35517+static Elf_Phdr *phdr;
35518
35519 struct relocs {
35520 uint32_t *offset;
35521@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35522 }
35523 }
35524
35525+static void read_phdrs(FILE *fp)
35526+{
35527+ unsigned int i;
35528+
35529+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35530+ if (!phdr) {
35531+ die("Unable to allocate %d program headers\n",
35532+ ehdr.e_phnum);
35533+ }
35534+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35535+ die("Seek to %d failed: %s\n",
35536+ ehdr.e_phoff, strerror(errno));
35537+ }
35538+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35539+ die("Cannot read ELF program headers: %s\n",
35540+ strerror(errno));
35541+ }
35542+ for(i = 0; i < ehdr.e_phnum; i++) {
35543+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35544+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35545+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35546+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35547+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35548+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35549+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35550+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35551+ }
35552+
35553+}
35554+
35555 static void read_shdrs(FILE *fp)
35556 {
35557- int i;
35558+ unsigned int i;
35559 Elf_Shdr shdr;
35560
35561 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35562@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35563
35564 static void read_strtabs(FILE *fp)
35565 {
35566- int i;
35567+ unsigned int i;
35568 for (i = 0; i < ehdr.e_shnum; i++) {
35569 struct section *sec = &secs[i];
35570 if (sec->shdr.sh_type != SHT_STRTAB) {
35571@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35572
35573 static void read_symtabs(FILE *fp)
35574 {
35575- int i,j;
35576+ unsigned int i,j;
35577 for (i = 0; i < ehdr.e_shnum; i++) {
35578 struct section *sec = &secs[i];
35579 if (sec->shdr.sh_type != SHT_SYMTAB) {
35580@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35581 }
35582
35583
35584-static void read_relocs(FILE *fp)
35585+static void read_relocs(FILE *fp, int use_real_mode)
35586 {
35587- int i,j;
35588+ unsigned int i,j;
35589+ uint32_t base;
35590+
35591 for (i = 0; i < ehdr.e_shnum; i++) {
35592 struct section *sec = &secs[i];
35593 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35594@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35595 die("Cannot read symbol table: %s\n",
35596 strerror(errno));
35597 }
35598+ base = 0;
35599+
35600+#ifdef CONFIG_X86_32
35601+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35602+ if (phdr[j].p_type != PT_LOAD )
35603+ continue;
35604+ 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)
35605+ continue;
35606+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35607+ break;
35608+ }
35609+#endif
35610+
35611 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35612 Elf_Rel *rel = &sec->reltab[j];
35613- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35614+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35615 rel->r_info = elf_xword_to_cpu(rel->r_info);
35616 #if (SHT_REL_TYPE == SHT_RELA)
35617 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35618@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35619
35620 static void print_absolute_symbols(void)
35621 {
35622- int i;
35623+ unsigned int i;
35624 const char *format;
35625
35626 if (ELF_BITS == 64)
35627@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35628 for (i = 0; i < ehdr.e_shnum; i++) {
35629 struct section *sec = &secs[i];
35630 char *sym_strtab;
35631- int j;
35632+ unsigned int j;
35633
35634 if (sec->shdr.sh_type != SHT_SYMTAB) {
35635 continue;
35636@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35637
35638 static void print_absolute_relocs(void)
35639 {
35640- int i, printed = 0;
35641+ unsigned int i, printed = 0;
35642 const char *format;
35643
35644 if (ELF_BITS == 64)
35645@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35646 struct section *sec_applies, *sec_symtab;
35647 char *sym_strtab;
35648 Elf_Sym *sh_symtab;
35649- int j;
35650+ unsigned int j;
35651 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35652 continue;
35653 }
35654@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35655 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35656 Elf_Sym *sym, const char *symname))
35657 {
35658- int i;
35659+ unsigned int i;
35660 /* Walk through the relocations */
35661 for (i = 0; i < ehdr.e_shnum; i++) {
35662 char *sym_strtab;
35663 Elf_Sym *sh_symtab;
35664 struct section *sec_applies, *sec_symtab;
35665- int j;
35666+ unsigned int j;
35667 struct section *sec = &secs[i];
35668
35669 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35670@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35671 {
35672 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35673 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35674+ char *sym_strtab = sec->link->link->strtab;
35675+
35676+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35677+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35678+ return 0;
35679+
35680+#ifdef CONFIG_PAX_KERNEXEC
35681+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35682+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35683+ return 0;
35684+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35685+ return 0;
35686+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35687+ return 0;
35688+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35689+ return 0;
35690+#endif
35691
35692 switch (r_type) {
35693 case R_386_NONE:
35694@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35695
35696 static void emit_relocs(int as_text, int use_real_mode)
35697 {
35698- int i;
35699+ unsigned int i;
35700 int (*write_reloc)(uint32_t, FILE *) = write32;
35701 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35702 const char *symname);
35703@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35704 {
35705 regex_init(use_real_mode);
35706 read_ehdr(fp);
35707+ read_phdrs(fp);
35708 read_shdrs(fp);
35709 read_strtabs(fp);
35710 read_symtabs(fp);
35711- read_relocs(fp);
35712+ read_relocs(fp, use_real_mode);
35713 if (ELF_BITS == 64)
35714 percpu_init();
35715 if (show_absolute_syms) {
35716diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35717index 80ffa5b..a33bd15 100644
35718--- a/arch/x86/um/tls_32.c
35719+++ b/arch/x86/um/tls_32.c
35720@@ -260,7 +260,7 @@ out:
35721 if (unlikely(task == current &&
35722 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35723 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35724- "without flushed TLS.", current->pid);
35725+ "without flushed TLS.", task_pid_nr(current));
35726 }
35727
35728 return 0;
35729diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35730index fd14be1..e3c79c0 100644
35731--- a/arch/x86/vdso/Makefile
35732+++ b/arch/x86/vdso/Makefile
35733@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35734 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35735 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35736
35737-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35738+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35739 GCOV_PROFILE := n
35740
35741 #
35742diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35743index f1d633a..a75c5f7 100644
35744--- a/arch/x86/vdso/vdso32-setup.c
35745+++ b/arch/x86/vdso/vdso32-setup.c
35746@@ -25,6 +25,7 @@
35747 #include <asm/tlbflush.h>
35748 #include <asm/vdso.h>
35749 #include <asm/proto.h>
35750+#include <asm/mman.h>
35751
35752 enum {
35753 VDSO_DISABLED = 0,
35754@@ -227,7 +228,7 @@ static inline void map_compat_vdso(int map)
35755 void enable_sep_cpu(void)
35756 {
35757 int cpu = get_cpu();
35758- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35759+ struct tss_struct *tss = init_tss + cpu;
35760
35761 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35762 put_cpu();
35763@@ -250,7 +251,7 @@ static int __init gate_vma_init(void)
35764 gate_vma.vm_start = FIXADDR_USER_START;
35765 gate_vma.vm_end = FIXADDR_USER_END;
35766 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35767- gate_vma.vm_page_prot = __P101;
35768+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35769
35770 return 0;
35771 }
35772@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35773 if (compat)
35774 addr = VDSO_HIGH_BASE;
35775 else {
35776- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35777+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35778 if (IS_ERR_VALUE(addr)) {
35779 ret = addr;
35780 goto up_fail;
35781 }
35782 }
35783
35784- current->mm->context.vdso = (void *)addr;
35785+ current->mm->context.vdso = addr;
35786
35787 if (compat_uses_vma || !compat) {
35788 /*
35789@@ -354,11 +355,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35790 }
35791
35792 current_thread_info()->sysenter_return =
35793- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35794+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35795
35796 up_fail:
35797 if (ret)
35798- current->mm->context.vdso = NULL;
35799+ current->mm->context.vdso = 0;
35800
35801 up_write(&mm->mmap_sem);
35802
35803@@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
35804
35805 const char *arch_vma_name(struct vm_area_struct *vma)
35806 {
35807- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35808+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35809 return "[vdso]";
35810+
35811+#ifdef CONFIG_PAX_SEGMEXEC
35812+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35813+ return "[vdso]";
35814+#endif
35815+
35816 return NULL;
35817 }
35818
35819@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35820 * Check to see if the corresponding task was created in compat vdso
35821 * mode.
35822 */
35823- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35824+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35825 return &gate_vma;
35826 return NULL;
35827 }
35828diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35829index 431e875..cbb23f3 100644
35830--- a/arch/x86/vdso/vma.c
35831+++ b/arch/x86/vdso/vma.c
35832@@ -16,8 +16,6 @@
35833 #include <asm/vdso.h>
35834 #include <asm/page.h>
35835
35836-unsigned int __read_mostly vdso_enabled = 1;
35837-
35838 extern char vdso_start[], vdso_end[];
35839 extern unsigned short vdso_sync_cpuid;
35840
35841@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35842 * unaligned here as a result of stack start randomization.
35843 */
35844 addr = PAGE_ALIGN(addr);
35845- addr = align_vdso_addr(addr);
35846
35847 return addr;
35848 }
35849@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35850 unsigned size)
35851 {
35852 struct mm_struct *mm = current->mm;
35853- unsigned long addr;
35854+ unsigned long addr = 0;
35855 int ret;
35856
35857- if (!vdso_enabled)
35858- return 0;
35859-
35860 down_write(&mm->mmap_sem);
35861+
35862+#ifdef CONFIG_PAX_RANDMMAP
35863+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35864+#endif
35865+
35866 addr = vdso_addr(mm->start_stack, size);
35867+ addr = align_vdso_addr(addr);
35868 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35869 if (IS_ERR_VALUE(addr)) {
35870 ret = addr;
35871 goto up_fail;
35872 }
35873
35874- current->mm->context.vdso = (void *)addr;
35875+ mm->context.vdso = addr;
35876
35877 ret = install_special_mapping(mm, addr, size,
35878 VM_READ|VM_EXEC|
35879 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35880 pages);
35881- if (ret) {
35882- current->mm->context.vdso = NULL;
35883- goto up_fail;
35884- }
35885+ if (ret)
35886+ mm->context.vdso = 0;
35887
35888 up_fail:
35889 up_write(&mm->mmap_sem);
35890@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35891 vdsox32_size);
35892 }
35893 #endif
35894-
35895-static __init int vdso_setup(char *s)
35896-{
35897- vdso_enabled = simple_strtoul(s, NULL, 0);
35898- return 0;
35899-}
35900-__setup("vdso=", vdso_setup);
35901diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35902index 01b9026..1e476df 100644
35903--- a/arch/x86/xen/Kconfig
35904+++ b/arch/x86/xen/Kconfig
35905@@ -9,6 +9,7 @@ config XEN
35906 select XEN_HAVE_PVMMU
35907 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35908 depends on X86_TSC
35909+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35910 help
35911 This is the Linux Xen port. Enabling this will allow the
35912 kernel to boot in a paravirtualized environment under the
35913diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35914index 201d09a..e4723e5 100644
35915--- a/arch/x86/xen/enlighten.c
35916+++ b/arch/x86/xen/enlighten.c
35917@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35918
35919 struct shared_info xen_dummy_shared_info;
35920
35921-void *xen_initial_gdt;
35922-
35923 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35924 __read_mostly int xen_have_vector_callback;
35925 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35926@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35927 {
35928 unsigned long va = dtr->address;
35929 unsigned int size = dtr->size + 1;
35930- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35931- unsigned long frames[pages];
35932+ unsigned long frames[65536 / PAGE_SIZE];
35933 int f;
35934
35935 /*
35936@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35937 {
35938 unsigned long va = dtr->address;
35939 unsigned int size = dtr->size + 1;
35940- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35941- unsigned long frames[pages];
35942+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35943 int f;
35944
35945 /*
35946@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35947 * 8-byte entries, or 16 4k pages..
35948 */
35949
35950- BUG_ON(size > 65536);
35951+ BUG_ON(size > GDT_SIZE);
35952 BUG_ON(va & ~PAGE_MASK);
35953
35954 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35955@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35956 return 0;
35957 }
35958
35959-static void set_xen_basic_apic_ops(void)
35960+static void __init set_xen_basic_apic_ops(void)
35961 {
35962 apic->read = xen_apic_read;
35963 apic->write = xen_apic_write;
35964@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35965 #endif
35966 };
35967
35968-static void xen_reboot(int reason)
35969+static __noreturn void xen_reboot(int reason)
35970 {
35971 struct sched_shutdown r = { .reason = reason };
35972
35973- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35974- BUG();
35975+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35976+ BUG();
35977 }
35978
35979-static void xen_restart(char *msg)
35980+static __noreturn void xen_restart(char *msg)
35981 {
35982 xen_reboot(SHUTDOWN_reboot);
35983 }
35984
35985-static void xen_emergency_restart(void)
35986+static __noreturn void xen_emergency_restart(void)
35987 {
35988 xen_reboot(SHUTDOWN_reboot);
35989 }
35990
35991-static void xen_machine_halt(void)
35992+static __noreturn void xen_machine_halt(void)
35993 {
35994 xen_reboot(SHUTDOWN_poweroff);
35995 }
35996
35997-static void xen_machine_power_off(void)
35998+static __noreturn void xen_machine_power_off(void)
35999 {
36000 if (pm_power_off)
36001 pm_power_off();
36002@@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
36003 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
36004
36005 /* Work out if we support NX */
36006- x86_configure_nx();
36007+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
36008+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
36009+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
36010+ unsigned l, h;
36011+
36012+ __supported_pte_mask |= _PAGE_NX;
36013+ rdmsr(MSR_EFER, l, h);
36014+ l |= EFER_NX;
36015+ wrmsr(MSR_EFER, l, h);
36016+ }
36017+#endif
36018
36019 /* Get mfn list */
36020 xen_build_dynamic_phys_to_machine();
36021@@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
36022
36023 machine_ops = xen_machine_ops;
36024
36025- /*
36026- * The only reliable way to retain the initial address of the
36027- * percpu gdt_page is to remember it here, so we can go and
36028- * mark it RW later, when the initial percpu area is freed.
36029- */
36030- xen_initial_gdt = &per_cpu(gdt_page, 0);
36031-
36032 xen_smp_init();
36033
36034 #ifdef CONFIG_ACPI_NUMA
36035diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
36036index 2423ef0..4f6fb5b 100644
36037--- a/arch/x86/xen/mmu.c
36038+++ b/arch/x86/xen/mmu.c
36039@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
36040 return val;
36041 }
36042
36043-static pteval_t pte_pfn_to_mfn(pteval_t val)
36044+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
36045 {
36046 if (val & _PAGE_PRESENT) {
36047 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
36048@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36049 /* L3_k[510] -> level2_kernel_pgt
36050 * L3_i[511] -> level2_fixmap_pgt */
36051 convert_pfn_mfn(level3_kernel_pgt);
36052+ convert_pfn_mfn(level3_vmalloc_start_pgt);
36053+ convert_pfn_mfn(level3_vmalloc_end_pgt);
36054+ convert_pfn_mfn(level3_vmemmap_pgt);
36055 }
36056 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
36057 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
36058@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36059 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
36060 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
36061 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
36062+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
36063+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
36064+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
36065 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
36066 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
36067+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
36068 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
36069 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
36070
36071@@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
36072 pv_mmu_ops.set_pud = xen_set_pud;
36073 #if PAGETABLE_LEVELS == 4
36074 pv_mmu_ops.set_pgd = xen_set_pgd;
36075+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
36076 #endif
36077
36078 /* This will work as long as patching hasn't happened yet
36079@@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
36080 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
36081 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
36082 .set_pgd = xen_set_pgd_hyper,
36083+ .set_pgd_batched = xen_set_pgd_hyper,
36084
36085 .alloc_pud = xen_alloc_pmd_init,
36086 .release_pud = xen_release_pmd_init,
36087diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
36088index a18eadd..2e2f10e 100644
36089--- a/arch/x86/xen/smp.c
36090+++ b/arch/x86/xen/smp.c
36091@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
36092
36093 if (xen_pv_domain()) {
36094 if (!xen_feature(XENFEAT_writable_page_tables))
36095- /* We've switched to the "real" per-cpu gdt, so make
36096- * sure the old memory can be recycled. */
36097- make_lowmem_page_readwrite(xen_initial_gdt);
36098-
36099 #ifdef CONFIG_X86_32
36100 /*
36101 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
36102 * expects __USER_DS
36103 */
36104- loadsegment(ds, __USER_DS);
36105- loadsegment(es, __USER_DS);
36106+ loadsegment(ds, __KERNEL_DS);
36107+ loadsegment(es, __KERNEL_DS);
36108 #endif
36109
36110 xen_filter_cpu_maps();
36111@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36112 #ifdef CONFIG_X86_32
36113 /* Note: PVH is not yet supported on x86_32. */
36114 ctxt->user_regs.fs = __KERNEL_PERCPU;
36115- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
36116+ savesegment(gs, ctxt->user_regs.gs);
36117 #endif
36118 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
36119
36120@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36121 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
36122 ctxt->flags = VGCF_IN_KERNEL;
36123 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
36124- ctxt->user_regs.ds = __USER_DS;
36125- ctxt->user_regs.es = __USER_DS;
36126+ ctxt->user_regs.ds = __KERNEL_DS;
36127+ ctxt->user_regs.es = __KERNEL_DS;
36128 ctxt->user_regs.ss = __KERNEL_DS;
36129
36130 xen_copy_trap_info(ctxt->trap_ctxt);
36131@@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
36132 int rc;
36133
36134 per_cpu(current_task, cpu) = idle;
36135+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
36136 #ifdef CONFIG_X86_32
36137 irq_ctx_init(cpu);
36138 #else
36139 clear_tsk_thread_flag(idle, TIF_FORK);
36140- per_cpu(kernel_stack, cpu) =
36141- (unsigned long)task_stack_page(idle) -
36142- KERNEL_STACK_OFFSET + THREAD_SIZE;
36143+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36144 #endif
36145 xen_setup_runstate_info(cpu);
36146 xen_setup_timer(cpu);
36147@@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36148
36149 void __init xen_smp_init(void)
36150 {
36151- smp_ops = xen_smp_ops;
36152+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36153 xen_fill_possible_map();
36154 }
36155
36156diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36157index 33ca6e4..0ded929 100644
36158--- a/arch/x86/xen/xen-asm_32.S
36159+++ b/arch/x86/xen/xen-asm_32.S
36160@@ -84,14 +84,14 @@ ENTRY(xen_iret)
36161 ESP_OFFSET=4 # bytes pushed onto stack
36162
36163 /*
36164- * Store vcpu_info pointer for easy access. Do it this way to
36165- * avoid having to reload %fs
36166+ * Store vcpu_info pointer for easy access.
36167 */
36168 #ifdef CONFIG_SMP
36169- GET_THREAD_INFO(%eax)
36170- movl %ss:TI_cpu(%eax), %eax
36171- movl %ss:__per_cpu_offset(,%eax,4), %eax
36172- mov %ss:xen_vcpu(%eax), %eax
36173+ push %fs
36174+ mov $(__KERNEL_PERCPU), %eax
36175+ mov %eax, %fs
36176+ mov PER_CPU_VAR(xen_vcpu), %eax
36177+ pop %fs
36178 #else
36179 movl %ss:xen_vcpu, %eax
36180 #endif
36181diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36182index 485b695..fda3e7c 100644
36183--- a/arch/x86/xen/xen-head.S
36184+++ b/arch/x86/xen/xen-head.S
36185@@ -39,6 +39,17 @@ ENTRY(startup_xen)
36186 #ifdef CONFIG_X86_32
36187 mov %esi,xen_start_info
36188 mov $init_thread_union+THREAD_SIZE,%esp
36189+#ifdef CONFIG_SMP
36190+ movl $cpu_gdt_table,%edi
36191+ movl $__per_cpu_load,%eax
36192+ movw %ax,__KERNEL_PERCPU + 2(%edi)
36193+ rorl $16,%eax
36194+ movb %al,__KERNEL_PERCPU + 4(%edi)
36195+ movb %ah,__KERNEL_PERCPU + 7(%edi)
36196+ movl $__per_cpu_end - 1,%eax
36197+ subl $__per_cpu_start,%eax
36198+ movw %ax,__KERNEL_PERCPU + 0(%edi)
36199+#endif
36200 #else
36201 mov %rsi,xen_start_info
36202 mov $init_thread_union+THREAD_SIZE,%rsp
36203diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36204index 1cb6f4c..9981524 100644
36205--- a/arch/x86/xen/xen-ops.h
36206+++ b/arch/x86/xen/xen-ops.h
36207@@ -10,8 +10,6 @@
36208 extern const char xen_hypervisor_callback[];
36209 extern const char xen_failsafe_callback[];
36210
36211-extern void *xen_initial_gdt;
36212-
36213 struct trap_info;
36214 void xen_copy_trap_info(struct trap_info *traps);
36215
36216diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36217index 525bd3d..ef888b1 100644
36218--- a/arch/xtensa/variants/dc232b/include/variant/core.h
36219+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36220@@ -119,9 +119,9 @@
36221 ----------------------------------------------------------------------*/
36222
36223 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36224-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36225 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36226 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36227+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36228
36229 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36230 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36231diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36232index 2f33760..835e50a 100644
36233--- a/arch/xtensa/variants/fsf/include/variant/core.h
36234+++ b/arch/xtensa/variants/fsf/include/variant/core.h
36235@@ -11,6 +11,7 @@
36236 #ifndef _XTENSA_CORE_H
36237 #define _XTENSA_CORE_H
36238
36239+#include <linux/const.h>
36240
36241 /****************************************************************************
36242 Parameters Useful for Any Code, USER or PRIVILEGED
36243@@ -112,9 +113,9 @@
36244 ----------------------------------------------------------------------*/
36245
36246 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36247-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36248 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36249 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36250+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36251
36252 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36253 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36254diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36255index af00795..2bb8105 100644
36256--- a/arch/xtensa/variants/s6000/include/variant/core.h
36257+++ b/arch/xtensa/variants/s6000/include/variant/core.h
36258@@ -11,6 +11,7 @@
36259 #ifndef _XTENSA_CORE_CONFIGURATION_H
36260 #define _XTENSA_CORE_CONFIGURATION_H
36261
36262+#include <linux/const.h>
36263
36264 /****************************************************************************
36265 Parameters Useful for Any Code, USER or PRIVILEGED
36266@@ -118,9 +119,9 @@
36267 ----------------------------------------------------------------------*/
36268
36269 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36270-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36271 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36272 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36273+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36274
36275 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36276 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36277diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
36278index 4e491d9..c8e18e4 100644
36279--- a/block/blk-cgroup.c
36280+++ b/block/blk-cgroup.c
36281@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
36282 static struct cgroup_subsys_state *
36283 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36284 {
36285- static atomic64_t id_seq = ATOMIC64_INIT(0);
36286+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
36287 struct blkcg *blkcg;
36288
36289 if (!parent_css) {
36290@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36291
36292 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
36293 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
36294- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
36295+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
36296 done:
36297 spin_lock_init(&blkcg->lock);
36298 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
36299diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36300index 1855bf5..af12b06 100644
36301--- a/block/blk-iopoll.c
36302+++ b/block/blk-iopoll.c
36303@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
36304 }
36305 EXPORT_SYMBOL(blk_iopoll_complete);
36306
36307-static void blk_iopoll_softirq(struct softirq_action *h)
36308+static __latent_entropy void blk_iopoll_softirq(void)
36309 {
36310 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36311 int rearm = 0, budget = blk_iopoll_budget;
36312diff --git a/block/blk-map.c b/block/blk-map.c
36313index ae4ae10..c470b8d 100644
36314--- a/block/blk-map.c
36315+++ b/block/blk-map.c
36316@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36317 if (!len || !kbuf)
36318 return -EINVAL;
36319
36320- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36321+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36322 if (do_copy)
36323 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36324 else
36325diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36326index 57790c1..5e988dd 100644
36327--- a/block/blk-softirq.c
36328+++ b/block/blk-softirq.c
36329@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36330 * Softirq action handler - move entries to local list and loop over them
36331 * while passing them to the queue registered handler.
36332 */
36333-static void blk_done_softirq(struct softirq_action *h)
36334+static __latent_entropy void blk_done_softirq(void)
36335 {
36336 struct list_head *cpu_list, local_list;
36337
36338diff --git a/block/bsg.c b/block/bsg.c
36339index 420a5a9..23834aa 100644
36340--- a/block/bsg.c
36341+++ b/block/bsg.c
36342@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36343 struct sg_io_v4 *hdr, struct bsg_device *bd,
36344 fmode_t has_write_perm)
36345 {
36346+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36347+ unsigned char *cmdptr;
36348+
36349 if (hdr->request_len > BLK_MAX_CDB) {
36350 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36351 if (!rq->cmd)
36352 return -ENOMEM;
36353- }
36354+ cmdptr = rq->cmd;
36355+ } else
36356+ cmdptr = tmpcmd;
36357
36358- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36359+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36360 hdr->request_len))
36361 return -EFAULT;
36362
36363+ if (cmdptr != rq->cmd)
36364+ memcpy(rq->cmd, cmdptr, hdr->request_len);
36365+
36366 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36367 if (blk_verify_command(rq->cmd, has_write_perm))
36368 return -EPERM;
36369diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36370index fbd5a67..f24fd95 100644
36371--- a/block/compat_ioctl.c
36372+++ b/block/compat_ioctl.c
36373@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36374 cgc = compat_alloc_user_space(sizeof(*cgc));
36375 cgc32 = compat_ptr(arg);
36376
36377- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36378+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36379 get_user(data, &cgc32->buffer) ||
36380 put_user(compat_ptr(data), &cgc->buffer) ||
36381 copy_in_user(&cgc->buflen, &cgc32->buflen,
36382@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36383 err |= __get_user(f->spec1, &uf->spec1);
36384 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36385 err |= __get_user(name, &uf->name);
36386- f->name = compat_ptr(name);
36387+ f->name = (void __force_kernel *)compat_ptr(name);
36388 if (err) {
36389 err = -EFAULT;
36390 goto out;
36391diff --git a/block/genhd.c b/block/genhd.c
36392index 791f419..89f21c4 100644
36393--- a/block/genhd.c
36394+++ b/block/genhd.c
36395@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36396
36397 /*
36398 * Register device numbers dev..(dev+range-1)
36399- * range must be nonzero
36400+ * Noop if @range is zero.
36401 * The hash chain is sorted on range, so that subranges can override.
36402 */
36403 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36404 struct kobject *(*probe)(dev_t, int *, void *),
36405 int (*lock)(dev_t, void *), void *data)
36406 {
36407- kobj_map(bdev_map, devt, range, module, probe, lock, data);
36408+ if (range)
36409+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
36410 }
36411
36412 EXPORT_SYMBOL(blk_register_region);
36413
36414+/* undo blk_register_region(), noop if @range is zero */
36415 void blk_unregister_region(dev_t devt, unsigned long range)
36416 {
36417- kobj_unmap(bdev_map, devt, range);
36418+ if (range)
36419+ kobj_unmap(bdev_map, devt, range);
36420 }
36421
36422 EXPORT_SYMBOL(blk_unregister_region);
36423diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36424index dc51f46..d5446a8 100644
36425--- a/block/partitions/efi.c
36426+++ b/block/partitions/efi.c
36427@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36428 if (!gpt)
36429 return NULL;
36430
36431+ if (!le32_to_cpu(gpt->num_partition_entries))
36432+ return NULL;
36433+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36434+ if (!pte)
36435+ return NULL;
36436+
36437 count = le32_to_cpu(gpt->num_partition_entries) *
36438 le32_to_cpu(gpt->sizeof_partition_entry);
36439- if (!count)
36440- return NULL;
36441- pte = kmalloc(count, GFP_KERNEL);
36442- if (!pte)
36443- return NULL;
36444-
36445 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36446 (u8 *) pte, count) < count) {
36447 kfree(pte);
36448diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36449index 2648797..92ed21f 100644
36450--- a/block/scsi_ioctl.c
36451+++ b/block/scsi_ioctl.c
36452@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36453 return put_user(0, p);
36454 }
36455
36456-static int sg_get_timeout(struct request_queue *q)
36457+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36458 {
36459 return jiffies_to_clock_t(q->sg_timeout);
36460 }
36461@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36462 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36463 struct sg_io_hdr *hdr, fmode_t mode)
36464 {
36465- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36466+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36467+ unsigned char *cmdptr;
36468+
36469+ if (rq->cmd != rq->__cmd)
36470+ cmdptr = rq->cmd;
36471+ else
36472+ cmdptr = tmpcmd;
36473+
36474+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36475 return -EFAULT;
36476+
36477+ if (cmdptr != rq->cmd)
36478+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36479+
36480 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36481 return -EPERM;
36482
36483@@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36484 int err;
36485 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36486 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36487+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36488+ unsigned char *cmdptr;
36489
36490 if (!sic)
36491 return -EINVAL;
36492@@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36493 */
36494 err = -EFAULT;
36495 rq->cmd_len = cmdlen;
36496- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36497+
36498+ if (rq->cmd != rq->__cmd)
36499+ cmdptr = rq->cmd;
36500+ else
36501+ cmdptr = tmpcmd;
36502+
36503+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36504 goto error;
36505
36506+ if (rq->cmd != cmdptr)
36507+ memcpy(rq->cmd, cmdptr, cmdlen);
36508+
36509 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36510 goto error;
36511
36512diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36513index 7bdd61b..afec999 100644
36514--- a/crypto/cryptd.c
36515+++ b/crypto/cryptd.c
36516@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36517
36518 struct cryptd_blkcipher_request_ctx {
36519 crypto_completion_t complete;
36520-};
36521+} __no_const;
36522
36523 struct cryptd_hash_ctx {
36524 struct crypto_shash *child;
36525@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36526
36527 struct cryptd_aead_request_ctx {
36528 crypto_completion_t complete;
36529-};
36530+} __no_const;
36531
36532 static void cryptd_queue_worker(struct work_struct *work);
36533
36534diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36535index 309d345..1632720 100644
36536--- a/crypto/pcrypt.c
36537+++ b/crypto/pcrypt.c
36538@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36539 int ret;
36540
36541 pinst->kobj.kset = pcrypt_kset;
36542- ret = kobject_add(&pinst->kobj, NULL, name);
36543+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36544 if (!ret)
36545 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36546
36547diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36548index 15dddc1..b61cf0c 100644
36549--- a/drivers/acpi/acpica/hwxfsleep.c
36550+++ b/drivers/acpi/acpica/hwxfsleep.c
36551@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36552 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36553
36554 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36555- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36556- acpi_hw_extended_sleep},
36557- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36558- acpi_hw_extended_wake_prep},
36559- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36560+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36561+ .extended_function = acpi_hw_extended_sleep},
36562+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36563+ .extended_function = acpi_hw_extended_wake_prep},
36564+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36565+ .extended_function = acpi_hw_extended_wake}
36566 };
36567
36568 /*
36569diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36570index e5bcd91..74f050d 100644
36571--- a/drivers/acpi/apei/apei-internal.h
36572+++ b/drivers/acpi/apei/apei-internal.h
36573@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36574 struct apei_exec_ins_type {
36575 u32 flags;
36576 apei_exec_ins_func_t run;
36577-};
36578+} __do_const;
36579
36580 struct apei_exec_context {
36581 u32 ip;
36582diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36583index dab7cb7..f0d2994 100644
36584--- a/drivers/acpi/apei/ghes.c
36585+++ b/drivers/acpi/apei/ghes.c
36586@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36587 const struct acpi_hest_generic *generic,
36588 const struct acpi_generic_status *estatus)
36589 {
36590- static atomic_t seqno;
36591+ static atomic_unchecked_t seqno;
36592 unsigned int curr_seqno;
36593 char pfx_seq[64];
36594
36595@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36596 else
36597 pfx = KERN_ERR;
36598 }
36599- curr_seqno = atomic_inc_return(&seqno);
36600+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36601 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36602 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36603 pfx_seq, generic->header.source_id);
36604diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36605index a83e3c6..c3d617f 100644
36606--- a/drivers/acpi/bgrt.c
36607+++ b/drivers/acpi/bgrt.c
36608@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36609 if (!bgrt_image)
36610 return -ENODEV;
36611
36612- bin_attr_image.private = bgrt_image;
36613- bin_attr_image.size = bgrt_image_size;
36614+ pax_open_kernel();
36615+ *(void **)&bin_attr_image.private = bgrt_image;
36616+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36617+ pax_close_kernel();
36618
36619 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36620 if (!bgrt_kobj)
36621diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36622index 3d8413d..95f638c 100644
36623--- a/drivers/acpi/blacklist.c
36624+++ b/drivers/acpi/blacklist.c
36625@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36626 u32 is_critical_error;
36627 };
36628
36629-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36630+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36631
36632 /*
36633 * POLICY: If *anything* doesn't work, put it on the blacklist.
36634@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36635 return 0;
36636 }
36637
36638-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36639+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36640 {
36641 .callback = dmi_disable_osi_vista,
36642 .ident = "Fujitsu Siemens",
36643diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36644index c68e724..e863008 100644
36645--- a/drivers/acpi/custom_method.c
36646+++ b/drivers/acpi/custom_method.c
36647@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36648 struct acpi_table_header table;
36649 acpi_status status;
36650
36651+#ifdef CONFIG_GRKERNSEC_KMEM
36652+ return -EPERM;
36653+#endif
36654+
36655 if (!(*ppos)) {
36656 /* parse the table header to get the table length */
36657 if (count <= sizeof(struct acpi_table_header))
36658diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36659index 3dca36d..abaf070 100644
36660--- a/drivers/acpi/processor_idle.c
36661+++ b/drivers/acpi/processor_idle.c
36662@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36663 {
36664 int i, count = CPUIDLE_DRIVER_STATE_START;
36665 struct acpi_processor_cx *cx;
36666- struct cpuidle_state *state;
36667+ cpuidle_state_no_const *state;
36668 struct cpuidle_driver *drv = &acpi_idle_driver;
36669
36670 if (!pr->flags.power_setup_done)
36671diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36672index 91a32ce..d77fcaf 100644
36673--- a/drivers/acpi/sysfs.c
36674+++ b/drivers/acpi/sysfs.c
36675@@ -425,11 +425,11 @@ static u32 num_counters;
36676 static struct attribute **all_attrs;
36677 static u32 acpi_gpe_count;
36678
36679-static struct attribute_group interrupt_stats_attr_group = {
36680+static attribute_group_no_const interrupt_stats_attr_group = {
36681 .name = "interrupts",
36682 };
36683
36684-static struct kobj_attribute *counter_attrs;
36685+static kobj_attribute_no_const *counter_attrs;
36686
36687 static void delete_gpe_attr_array(void)
36688 {
36689diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36690index 36605ab..6ef6d4b 100644
36691--- a/drivers/ata/libahci.c
36692+++ b/drivers/ata/libahci.c
36693@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36694 }
36695 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36696
36697-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36698+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36699 struct ata_taskfile *tf, int is_cmd, u16 flags,
36700 unsigned long timeout_msec)
36701 {
36702diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36703index 62fda16..8063873 100644
36704--- a/drivers/ata/libata-core.c
36705+++ b/drivers/ata/libata-core.c
36706@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36707 static void ata_dev_xfermask(struct ata_device *dev);
36708 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36709
36710-atomic_t ata_print_id = ATOMIC_INIT(0);
36711+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36712
36713 struct ata_force_param {
36714 const char *name;
36715@@ -4858,7 +4858,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36716 struct ata_port *ap;
36717 unsigned int tag;
36718
36719- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36720+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36721 ap = qc->ap;
36722
36723 qc->flags = 0;
36724@@ -4874,7 +4874,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36725 struct ata_port *ap;
36726 struct ata_link *link;
36727
36728- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36729+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36730 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36731 ap = qc->ap;
36732 link = qc->dev->link;
36733@@ -5993,6 +5993,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36734 return;
36735
36736 spin_lock(&lock);
36737+ pax_open_kernel();
36738
36739 for (cur = ops->inherits; cur; cur = cur->inherits) {
36740 void **inherit = (void **)cur;
36741@@ -6006,8 +6007,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36742 if (IS_ERR(*pp))
36743 *pp = NULL;
36744
36745- ops->inherits = NULL;
36746+ *(struct ata_port_operations **)&ops->inherits = NULL;
36747
36748+ pax_close_kernel();
36749 spin_unlock(&lock);
36750 }
36751
36752@@ -6200,7 +6202,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36753
36754 /* give ports names and add SCSI hosts */
36755 for (i = 0; i < host->n_ports; i++) {
36756- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36757+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36758 host->ports[i]->local_port_no = i + 1;
36759 }
36760
36761diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36762index ef8567d..8bdbd03 100644
36763--- a/drivers/ata/libata-scsi.c
36764+++ b/drivers/ata/libata-scsi.c
36765@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36766
36767 if (rc)
36768 return rc;
36769- ap->print_id = atomic_inc_return(&ata_print_id);
36770+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36771 return 0;
36772 }
36773 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36774diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36775index 45b5ab3..98446b8 100644
36776--- a/drivers/ata/libata.h
36777+++ b/drivers/ata/libata.h
36778@@ -53,7 +53,7 @@ enum {
36779 ATA_DNXFER_QUIET = (1 << 31),
36780 };
36781
36782-extern atomic_t ata_print_id;
36783+extern atomic_unchecked_t ata_print_id;
36784 extern int atapi_passthru16;
36785 extern int libata_fua;
36786 extern int libata_noacpi;
36787diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36788index 73492dd..ca2bff5 100644
36789--- a/drivers/ata/pata_arasan_cf.c
36790+++ b/drivers/ata/pata_arasan_cf.c
36791@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36792 /* Handle platform specific quirks */
36793 if (quirk) {
36794 if (quirk & CF_BROKEN_PIO) {
36795- ap->ops->set_piomode = NULL;
36796+ pax_open_kernel();
36797+ *(void **)&ap->ops->set_piomode = NULL;
36798+ pax_close_kernel();
36799 ap->pio_mask = 0;
36800 }
36801 if (quirk & CF_BROKEN_MWDMA)
36802diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36803index f9b983a..887b9d8 100644
36804--- a/drivers/atm/adummy.c
36805+++ b/drivers/atm/adummy.c
36806@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36807 vcc->pop(vcc, skb);
36808 else
36809 dev_kfree_skb_any(skb);
36810- atomic_inc(&vcc->stats->tx);
36811+ atomic_inc_unchecked(&vcc->stats->tx);
36812
36813 return 0;
36814 }
36815diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36816index 62a7607..cc4be104 100644
36817--- a/drivers/atm/ambassador.c
36818+++ b/drivers/atm/ambassador.c
36819@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36820 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36821
36822 // VC layer stats
36823- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36824+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36825
36826 // free the descriptor
36827 kfree (tx_descr);
36828@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36829 dump_skb ("<<<", vc, skb);
36830
36831 // VC layer stats
36832- atomic_inc(&atm_vcc->stats->rx);
36833+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36834 __net_timestamp(skb);
36835 // end of our responsibility
36836 atm_vcc->push (atm_vcc, skb);
36837@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36838 } else {
36839 PRINTK (KERN_INFO, "dropped over-size frame");
36840 // should we count this?
36841- atomic_inc(&atm_vcc->stats->rx_drop);
36842+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36843 }
36844
36845 } else {
36846@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36847 }
36848
36849 if (check_area (skb->data, skb->len)) {
36850- atomic_inc(&atm_vcc->stats->tx_err);
36851+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36852 return -ENOMEM; // ?
36853 }
36854
36855diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36856index 0e3f8f9..765a7a5 100644
36857--- a/drivers/atm/atmtcp.c
36858+++ b/drivers/atm/atmtcp.c
36859@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36860 if (vcc->pop) vcc->pop(vcc,skb);
36861 else dev_kfree_skb(skb);
36862 if (dev_data) return 0;
36863- atomic_inc(&vcc->stats->tx_err);
36864+ atomic_inc_unchecked(&vcc->stats->tx_err);
36865 return -ENOLINK;
36866 }
36867 size = skb->len+sizeof(struct atmtcp_hdr);
36868@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36869 if (!new_skb) {
36870 if (vcc->pop) vcc->pop(vcc,skb);
36871 else dev_kfree_skb(skb);
36872- atomic_inc(&vcc->stats->tx_err);
36873+ atomic_inc_unchecked(&vcc->stats->tx_err);
36874 return -ENOBUFS;
36875 }
36876 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36877@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36878 if (vcc->pop) vcc->pop(vcc,skb);
36879 else dev_kfree_skb(skb);
36880 out_vcc->push(out_vcc,new_skb);
36881- atomic_inc(&vcc->stats->tx);
36882- atomic_inc(&out_vcc->stats->rx);
36883+ atomic_inc_unchecked(&vcc->stats->tx);
36884+ atomic_inc_unchecked(&out_vcc->stats->rx);
36885 return 0;
36886 }
36887
36888@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36889 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36890 read_unlock(&vcc_sklist_lock);
36891 if (!out_vcc) {
36892- atomic_inc(&vcc->stats->tx_err);
36893+ atomic_inc_unchecked(&vcc->stats->tx_err);
36894 goto done;
36895 }
36896 skb_pull(skb,sizeof(struct atmtcp_hdr));
36897@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36898 __net_timestamp(new_skb);
36899 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36900 out_vcc->push(out_vcc,new_skb);
36901- atomic_inc(&vcc->stats->tx);
36902- atomic_inc(&out_vcc->stats->rx);
36903+ atomic_inc_unchecked(&vcc->stats->tx);
36904+ atomic_inc_unchecked(&out_vcc->stats->rx);
36905 done:
36906 if (vcc->pop) vcc->pop(vcc,skb);
36907 else dev_kfree_skb(skb);
36908diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36909index b1955ba..b179940 100644
36910--- a/drivers/atm/eni.c
36911+++ b/drivers/atm/eni.c
36912@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36913 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36914 vcc->dev->number);
36915 length = 0;
36916- atomic_inc(&vcc->stats->rx_err);
36917+ atomic_inc_unchecked(&vcc->stats->rx_err);
36918 }
36919 else {
36920 length = ATM_CELL_SIZE-1; /* no HEC */
36921@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36922 size);
36923 }
36924 eff = length = 0;
36925- atomic_inc(&vcc->stats->rx_err);
36926+ atomic_inc_unchecked(&vcc->stats->rx_err);
36927 }
36928 else {
36929 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36930@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36931 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36932 vcc->dev->number,vcc->vci,length,size << 2,descr);
36933 length = eff = 0;
36934- atomic_inc(&vcc->stats->rx_err);
36935+ atomic_inc_unchecked(&vcc->stats->rx_err);
36936 }
36937 }
36938 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36939@@ -767,7 +767,7 @@ rx_dequeued++;
36940 vcc->push(vcc,skb);
36941 pushed++;
36942 }
36943- atomic_inc(&vcc->stats->rx);
36944+ atomic_inc_unchecked(&vcc->stats->rx);
36945 }
36946 wake_up(&eni_dev->rx_wait);
36947 }
36948@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36949 PCI_DMA_TODEVICE);
36950 if (vcc->pop) vcc->pop(vcc,skb);
36951 else dev_kfree_skb_irq(skb);
36952- atomic_inc(&vcc->stats->tx);
36953+ atomic_inc_unchecked(&vcc->stats->tx);
36954 wake_up(&eni_dev->tx_wait);
36955 dma_complete++;
36956 }
36957diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36958index b41c948..a002b17 100644
36959--- a/drivers/atm/firestream.c
36960+++ b/drivers/atm/firestream.c
36961@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36962 }
36963 }
36964
36965- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36966+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36967
36968 fs_dprintk (FS_DEBUG_TXMEM, "i");
36969 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36970@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36971 #endif
36972 skb_put (skb, qe->p1 & 0xffff);
36973 ATM_SKB(skb)->vcc = atm_vcc;
36974- atomic_inc(&atm_vcc->stats->rx);
36975+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36976 __net_timestamp(skb);
36977 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36978 atm_vcc->push (atm_vcc, skb);
36979@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36980 kfree (pe);
36981 }
36982 if (atm_vcc)
36983- atomic_inc(&atm_vcc->stats->rx_drop);
36984+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36985 break;
36986 case 0x1f: /* Reassembly abort: no buffers. */
36987 /* Silently increment error counter. */
36988 if (atm_vcc)
36989- atomic_inc(&atm_vcc->stats->rx_drop);
36990+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36991 break;
36992 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36993 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36994diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36995index 204814e..cede831 100644
36996--- a/drivers/atm/fore200e.c
36997+++ b/drivers/atm/fore200e.c
36998@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36999 #endif
37000 /* check error condition */
37001 if (*entry->status & STATUS_ERROR)
37002- atomic_inc(&vcc->stats->tx_err);
37003+ atomic_inc_unchecked(&vcc->stats->tx_err);
37004 else
37005- atomic_inc(&vcc->stats->tx);
37006+ atomic_inc_unchecked(&vcc->stats->tx);
37007 }
37008 }
37009
37010@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37011 if (skb == NULL) {
37012 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
37013
37014- atomic_inc(&vcc->stats->rx_drop);
37015+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37016 return -ENOMEM;
37017 }
37018
37019@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37020
37021 dev_kfree_skb_any(skb);
37022
37023- atomic_inc(&vcc->stats->rx_drop);
37024+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37025 return -ENOMEM;
37026 }
37027
37028 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37029
37030 vcc->push(vcc, skb);
37031- atomic_inc(&vcc->stats->rx);
37032+ atomic_inc_unchecked(&vcc->stats->rx);
37033
37034 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37035
37036@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
37037 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
37038 fore200e->atm_dev->number,
37039 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
37040- atomic_inc(&vcc->stats->rx_err);
37041+ atomic_inc_unchecked(&vcc->stats->rx_err);
37042 }
37043 }
37044
37045@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
37046 goto retry_here;
37047 }
37048
37049- atomic_inc(&vcc->stats->tx_err);
37050+ atomic_inc_unchecked(&vcc->stats->tx_err);
37051
37052 fore200e->tx_sat++;
37053 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
37054diff --git a/drivers/atm/he.c b/drivers/atm/he.c
37055index aa6be26..f70a785 100644
37056--- a/drivers/atm/he.c
37057+++ b/drivers/atm/he.c
37058@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37059
37060 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
37061 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
37062- atomic_inc(&vcc->stats->rx_drop);
37063+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37064 goto return_host_buffers;
37065 }
37066
37067@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37068 RBRQ_LEN_ERR(he_dev->rbrq_head)
37069 ? "LEN_ERR" : "",
37070 vcc->vpi, vcc->vci);
37071- atomic_inc(&vcc->stats->rx_err);
37072+ atomic_inc_unchecked(&vcc->stats->rx_err);
37073 goto return_host_buffers;
37074 }
37075
37076@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37077 vcc->push(vcc, skb);
37078 spin_lock(&he_dev->global_lock);
37079
37080- atomic_inc(&vcc->stats->rx);
37081+ atomic_inc_unchecked(&vcc->stats->rx);
37082
37083 return_host_buffers:
37084 ++pdus_assembled;
37085@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
37086 tpd->vcc->pop(tpd->vcc, tpd->skb);
37087 else
37088 dev_kfree_skb_any(tpd->skb);
37089- atomic_inc(&tpd->vcc->stats->tx_err);
37090+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
37091 }
37092 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
37093 return;
37094@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37095 vcc->pop(vcc, skb);
37096 else
37097 dev_kfree_skb_any(skb);
37098- atomic_inc(&vcc->stats->tx_err);
37099+ atomic_inc_unchecked(&vcc->stats->tx_err);
37100 return -EINVAL;
37101 }
37102
37103@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37104 vcc->pop(vcc, skb);
37105 else
37106 dev_kfree_skb_any(skb);
37107- atomic_inc(&vcc->stats->tx_err);
37108+ atomic_inc_unchecked(&vcc->stats->tx_err);
37109 return -EINVAL;
37110 }
37111 #endif
37112@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37113 vcc->pop(vcc, skb);
37114 else
37115 dev_kfree_skb_any(skb);
37116- atomic_inc(&vcc->stats->tx_err);
37117+ atomic_inc_unchecked(&vcc->stats->tx_err);
37118 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37119 return -ENOMEM;
37120 }
37121@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37122 vcc->pop(vcc, skb);
37123 else
37124 dev_kfree_skb_any(skb);
37125- atomic_inc(&vcc->stats->tx_err);
37126+ atomic_inc_unchecked(&vcc->stats->tx_err);
37127 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37128 return -ENOMEM;
37129 }
37130@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37131 __enqueue_tpd(he_dev, tpd, cid);
37132 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37133
37134- atomic_inc(&vcc->stats->tx);
37135+ atomic_inc_unchecked(&vcc->stats->tx);
37136
37137 return 0;
37138 }
37139diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
37140index 1dc0519..1aadaf7 100644
37141--- a/drivers/atm/horizon.c
37142+++ b/drivers/atm/horizon.c
37143@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
37144 {
37145 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
37146 // VC layer stats
37147- atomic_inc(&vcc->stats->rx);
37148+ atomic_inc_unchecked(&vcc->stats->rx);
37149 __net_timestamp(skb);
37150 // end of our responsibility
37151 vcc->push (vcc, skb);
37152@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
37153 dev->tx_iovec = NULL;
37154
37155 // VC layer stats
37156- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37157+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37158
37159 // free the skb
37160 hrz_kfree_skb (skb);
37161diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
37162index 1bdf104..9dc44b1 100644
37163--- a/drivers/atm/idt77252.c
37164+++ b/drivers/atm/idt77252.c
37165@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
37166 else
37167 dev_kfree_skb(skb);
37168
37169- atomic_inc(&vcc->stats->tx);
37170+ atomic_inc_unchecked(&vcc->stats->tx);
37171 }
37172
37173 atomic_dec(&scq->used);
37174@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37175 if ((sb = dev_alloc_skb(64)) == NULL) {
37176 printk("%s: Can't allocate buffers for aal0.\n",
37177 card->name);
37178- atomic_add(i, &vcc->stats->rx_drop);
37179+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37180 break;
37181 }
37182 if (!atm_charge(vcc, sb->truesize)) {
37183 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37184 card->name);
37185- atomic_add(i - 1, &vcc->stats->rx_drop);
37186+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37187 dev_kfree_skb(sb);
37188 break;
37189 }
37190@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37191 ATM_SKB(sb)->vcc = vcc;
37192 __net_timestamp(sb);
37193 vcc->push(vcc, sb);
37194- atomic_inc(&vcc->stats->rx);
37195+ atomic_inc_unchecked(&vcc->stats->rx);
37196
37197 cell += ATM_CELL_PAYLOAD;
37198 }
37199@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37200 "(CDC: %08x)\n",
37201 card->name, len, rpp->len, readl(SAR_REG_CDC));
37202 recycle_rx_pool_skb(card, rpp);
37203- atomic_inc(&vcc->stats->rx_err);
37204+ atomic_inc_unchecked(&vcc->stats->rx_err);
37205 return;
37206 }
37207 if (stat & SAR_RSQE_CRC) {
37208 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37209 recycle_rx_pool_skb(card, rpp);
37210- atomic_inc(&vcc->stats->rx_err);
37211+ atomic_inc_unchecked(&vcc->stats->rx_err);
37212 return;
37213 }
37214 if (skb_queue_len(&rpp->queue) > 1) {
37215@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37216 RXPRINTK("%s: Can't alloc RX skb.\n",
37217 card->name);
37218 recycle_rx_pool_skb(card, rpp);
37219- atomic_inc(&vcc->stats->rx_err);
37220+ atomic_inc_unchecked(&vcc->stats->rx_err);
37221 return;
37222 }
37223 if (!atm_charge(vcc, skb->truesize)) {
37224@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37225 __net_timestamp(skb);
37226
37227 vcc->push(vcc, skb);
37228- atomic_inc(&vcc->stats->rx);
37229+ atomic_inc_unchecked(&vcc->stats->rx);
37230
37231 return;
37232 }
37233@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37234 __net_timestamp(skb);
37235
37236 vcc->push(vcc, skb);
37237- atomic_inc(&vcc->stats->rx);
37238+ atomic_inc_unchecked(&vcc->stats->rx);
37239
37240 if (skb->truesize > SAR_FB_SIZE_3)
37241 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37242@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37243 if (vcc->qos.aal != ATM_AAL0) {
37244 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37245 card->name, vpi, vci);
37246- atomic_inc(&vcc->stats->rx_drop);
37247+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37248 goto drop;
37249 }
37250
37251 if ((sb = dev_alloc_skb(64)) == NULL) {
37252 printk("%s: Can't allocate buffers for AAL0.\n",
37253 card->name);
37254- atomic_inc(&vcc->stats->rx_err);
37255+ atomic_inc_unchecked(&vcc->stats->rx_err);
37256 goto drop;
37257 }
37258
37259@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37260 ATM_SKB(sb)->vcc = vcc;
37261 __net_timestamp(sb);
37262 vcc->push(vcc, sb);
37263- atomic_inc(&vcc->stats->rx);
37264+ atomic_inc_unchecked(&vcc->stats->rx);
37265
37266 drop:
37267 skb_pull(queue, 64);
37268@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37269
37270 if (vc == NULL) {
37271 printk("%s: NULL connection in send().\n", card->name);
37272- atomic_inc(&vcc->stats->tx_err);
37273+ atomic_inc_unchecked(&vcc->stats->tx_err);
37274 dev_kfree_skb(skb);
37275 return -EINVAL;
37276 }
37277 if (!test_bit(VCF_TX, &vc->flags)) {
37278 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37279- atomic_inc(&vcc->stats->tx_err);
37280+ atomic_inc_unchecked(&vcc->stats->tx_err);
37281 dev_kfree_skb(skb);
37282 return -EINVAL;
37283 }
37284@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37285 break;
37286 default:
37287 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37288- atomic_inc(&vcc->stats->tx_err);
37289+ atomic_inc_unchecked(&vcc->stats->tx_err);
37290 dev_kfree_skb(skb);
37291 return -EINVAL;
37292 }
37293
37294 if (skb_shinfo(skb)->nr_frags != 0) {
37295 printk("%s: No scatter-gather yet.\n", card->name);
37296- atomic_inc(&vcc->stats->tx_err);
37297+ atomic_inc_unchecked(&vcc->stats->tx_err);
37298 dev_kfree_skb(skb);
37299 return -EINVAL;
37300 }
37301@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37302
37303 err = queue_skb(card, vc, skb, oam);
37304 if (err) {
37305- atomic_inc(&vcc->stats->tx_err);
37306+ atomic_inc_unchecked(&vcc->stats->tx_err);
37307 dev_kfree_skb(skb);
37308 return err;
37309 }
37310@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37311 skb = dev_alloc_skb(64);
37312 if (!skb) {
37313 printk("%s: Out of memory in send_oam().\n", card->name);
37314- atomic_inc(&vcc->stats->tx_err);
37315+ atomic_inc_unchecked(&vcc->stats->tx_err);
37316 return -ENOMEM;
37317 }
37318 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37319diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37320index 4217f29..88f547a 100644
37321--- a/drivers/atm/iphase.c
37322+++ b/drivers/atm/iphase.c
37323@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37324 status = (u_short) (buf_desc_ptr->desc_mode);
37325 if (status & (RX_CER | RX_PTE | RX_OFL))
37326 {
37327- atomic_inc(&vcc->stats->rx_err);
37328+ atomic_inc_unchecked(&vcc->stats->rx_err);
37329 IF_ERR(printk("IA: bad packet, dropping it");)
37330 if (status & RX_CER) {
37331 IF_ERR(printk(" cause: packet CRC error\n");)
37332@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37333 len = dma_addr - buf_addr;
37334 if (len > iadev->rx_buf_sz) {
37335 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37336- atomic_inc(&vcc->stats->rx_err);
37337+ atomic_inc_unchecked(&vcc->stats->rx_err);
37338 goto out_free_desc;
37339 }
37340
37341@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37342 ia_vcc = INPH_IA_VCC(vcc);
37343 if (ia_vcc == NULL)
37344 {
37345- atomic_inc(&vcc->stats->rx_err);
37346+ atomic_inc_unchecked(&vcc->stats->rx_err);
37347 atm_return(vcc, skb->truesize);
37348 dev_kfree_skb_any(skb);
37349 goto INCR_DLE;
37350@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37351 if ((length > iadev->rx_buf_sz) || (length >
37352 (skb->len - sizeof(struct cpcs_trailer))))
37353 {
37354- atomic_inc(&vcc->stats->rx_err);
37355+ atomic_inc_unchecked(&vcc->stats->rx_err);
37356 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37357 length, skb->len);)
37358 atm_return(vcc, skb->truesize);
37359@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37360
37361 IF_RX(printk("rx_dle_intr: skb push");)
37362 vcc->push(vcc,skb);
37363- atomic_inc(&vcc->stats->rx);
37364+ atomic_inc_unchecked(&vcc->stats->rx);
37365 iadev->rx_pkt_cnt++;
37366 }
37367 INCR_DLE:
37368@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37369 {
37370 struct k_sonet_stats *stats;
37371 stats = &PRIV(_ia_dev[board])->sonet_stats;
37372- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37373- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37374- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37375- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37376- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37377- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37378- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37379- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37380- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37381+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37382+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37383+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37384+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37385+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37386+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37387+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37388+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37389+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37390 }
37391 ia_cmds.status = 0;
37392 break;
37393@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37394 if ((desc == 0) || (desc > iadev->num_tx_desc))
37395 {
37396 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37397- atomic_inc(&vcc->stats->tx);
37398+ atomic_inc_unchecked(&vcc->stats->tx);
37399 if (vcc->pop)
37400 vcc->pop(vcc, skb);
37401 else
37402@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37403 ATM_DESC(skb) = vcc->vci;
37404 skb_queue_tail(&iadev->tx_dma_q, skb);
37405
37406- atomic_inc(&vcc->stats->tx);
37407+ atomic_inc_unchecked(&vcc->stats->tx);
37408 iadev->tx_pkt_cnt++;
37409 /* Increment transaction counter */
37410 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37411
37412 #if 0
37413 /* add flow control logic */
37414- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37415+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37416 if (iavcc->vc_desc_cnt > 10) {
37417 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37418 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37419diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37420index fa7d701..1e404c7 100644
37421--- a/drivers/atm/lanai.c
37422+++ b/drivers/atm/lanai.c
37423@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37424 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37425 lanai_endtx(lanai, lvcc);
37426 lanai_free_skb(lvcc->tx.atmvcc, skb);
37427- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37428+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37429 }
37430
37431 /* Try to fill the buffer - don't call unless there is backlog */
37432@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37433 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37434 __net_timestamp(skb);
37435 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37436- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37437+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37438 out:
37439 lvcc->rx.buf.ptr = end;
37440 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37441@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37442 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37443 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37444 lanai->stats.service_rxnotaal5++;
37445- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37446+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37447 return 0;
37448 }
37449 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37450@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37451 int bytes;
37452 read_unlock(&vcc_sklist_lock);
37453 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37454- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37455+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37456 lvcc->stats.x.aal5.service_trash++;
37457 bytes = (SERVICE_GET_END(s) * 16) -
37458 (((unsigned long) lvcc->rx.buf.ptr) -
37459@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37460 }
37461 if (s & SERVICE_STREAM) {
37462 read_unlock(&vcc_sklist_lock);
37463- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37464+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37465 lvcc->stats.x.aal5.service_stream++;
37466 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37467 "PDU on VCI %d!\n", lanai->number, vci);
37468@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37469 return 0;
37470 }
37471 DPRINTK("got rx crc error on vci %d\n", vci);
37472- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37473+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37474 lvcc->stats.x.aal5.service_rxcrc++;
37475 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37476 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37477diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37478index 9587e95..b45c5cb 100644
37479--- a/drivers/atm/nicstar.c
37480+++ b/drivers/atm/nicstar.c
37481@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37482 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37483 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37484 card->index);
37485- atomic_inc(&vcc->stats->tx_err);
37486+ atomic_inc_unchecked(&vcc->stats->tx_err);
37487 dev_kfree_skb_any(skb);
37488 return -EINVAL;
37489 }
37490@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37491 if (!vc->tx) {
37492 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37493 card->index);
37494- atomic_inc(&vcc->stats->tx_err);
37495+ atomic_inc_unchecked(&vcc->stats->tx_err);
37496 dev_kfree_skb_any(skb);
37497 return -EINVAL;
37498 }
37499@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37500 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37501 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37502 card->index);
37503- atomic_inc(&vcc->stats->tx_err);
37504+ atomic_inc_unchecked(&vcc->stats->tx_err);
37505 dev_kfree_skb_any(skb);
37506 return -EINVAL;
37507 }
37508
37509 if (skb_shinfo(skb)->nr_frags != 0) {
37510 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37511- atomic_inc(&vcc->stats->tx_err);
37512+ atomic_inc_unchecked(&vcc->stats->tx_err);
37513 dev_kfree_skb_any(skb);
37514 return -EINVAL;
37515 }
37516@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37517 }
37518
37519 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37520- atomic_inc(&vcc->stats->tx_err);
37521+ atomic_inc_unchecked(&vcc->stats->tx_err);
37522 dev_kfree_skb_any(skb);
37523 return -EIO;
37524 }
37525- atomic_inc(&vcc->stats->tx);
37526+ atomic_inc_unchecked(&vcc->stats->tx);
37527
37528 return 0;
37529 }
37530@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37531 printk
37532 ("nicstar%d: Can't allocate buffers for aal0.\n",
37533 card->index);
37534- atomic_add(i, &vcc->stats->rx_drop);
37535+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37536 break;
37537 }
37538 if (!atm_charge(vcc, sb->truesize)) {
37539 RXPRINTK
37540 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37541 card->index);
37542- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37543+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37544 dev_kfree_skb_any(sb);
37545 break;
37546 }
37547@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37548 ATM_SKB(sb)->vcc = vcc;
37549 __net_timestamp(sb);
37550 vcc->push(vcc, sb);
37551- atomic_inc(&vcc->stats->rx);
37552+ atomic_inc_unchecked(&vcc->stats->rx);
37553 cell += ATM_CELL_PAYLOAD;
37554 }
37555
37556@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37557 if (iovb == NULL) {
37558 printk("nicstar%d: Out of iovec buffers.\n",
37559 card->index);
37560- atomic_inc(&vcc->stats->rx_drop);
37561+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37562 recycle_rx_buf(card, skb);
37563 return;
37564 }
37565@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37566 small or large buffer itself. */
37567 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37568 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37569- atomic_inc(&vcc->stats->rx_err);
37570+ atomic_inc_unchecked(&vcc->stats->rx_err);
37571 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37572 NS_MAX_IOVECS);
37573 NS_PRV_IOVCNT(iovb) = 0;
37574@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37575 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37576 card->index);
37577 which_list(card, skb);
37578- atomic_inc(&vcc->stats->rx_err);
37579+ atomic_inc_unchecked(&vcc->stats->rx_err);
37580 recycle_rx_buf(card, skb);
37581 vc->rx_iov = NULL;
37582 recycle_iov_buf(card, iovb);
37583@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37584 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37585 card->index);
37586 which_list(card, skb);
37587- atomic_inc(&vcc->stats->rx_err);
37588+ atomic_inc_unchecked(&vcc->stats->rx_err);
37589 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37590 NS_PRV_IOVCNT(iovb));
37591 vc->rx_iov = NULL;
37592@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37593 printk(" - PDU size mismatch.\n");
37594 else
37595 printk(".\n");
37596- atomic_inc(&vcc->stats->rx_err);
37597+ atomic_inc_unchecked(&vcc->stats->rx_err);
37598 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37599 NS_PRV_IOVCNT(iovb));
37600 vc->rx_iov = NULL;
37601@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37602 /* skb points to a small buffer */
37603 if (!atm_charge(vcc, skb->truesize)) {
37604 push_rxbufs(card, skb);
37605- atomic_inc(&vcc->stats->rx_drop);
37606+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37607 } else {
37608 skb_put(skb, len);
37609 dequeue_sm_buf(card, skb);
37610@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37611 ATM_SKB(skb)->vcc = vcc;
37612 __net_timestamp(skb);
37613 vcc->push(vcc, skb);
37614- atomic_inc(&vcc->stats->rx);
37615+ atomic_inc_unchecked(&vcc->stats->rx);
37616 }
37617 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37618 struct sk_buff *sb;
37619@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37620 if (len <= NS_SMBUFSIZE) {
37621 if (!atm_charge(vcc, sb->truesize)) {
37622 push_rxbufs(card, sb);
37623- atomic_inc(&vcc->stats->rx_drop);
37624+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37625 } else {
37626 skb_put(sb, len);
37627 dequeue_sm_buf(card, sb);
37628@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37629 ATM_SKB(sb)->vcc = vcc;
37630 __net_timestamp(sb);
37631 vcc->push(vcc, sb);
37632- atomic_inc(&vcc->stats->rx);
37633+ atomic_inc_unchecked(&vcc->stats->rx);
37634 }
37635
37636 push_rxbufs(card, skb);
37637@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37638
37639 if (!atm_charge(vcc, skb->truesize)) {
37640 push_rxbufs(card, skb);
37641- atomic_inc(&vcc->stats->rx_drop);
37642+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37643 } else {
37644 dequeue_lg_buf(card, skb);
37645 #ifdef NS_USE_DESTRUCTORS
37646@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37647 ATM_SKB(skb)->vcc = vcc;
37648 __net_timestamp(skb);
37649 vcc->push(vcc, skb);
37650- atomic_inc(&vcc->stats->rx);
37651+ atomic_inc_unchecked(&vcc->stats->rx);
37652 }
37653
37654 push_rxbufs(card, sb);
37655@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37656 printk
37657 ("nicstar%d: Out of huge buffers.\n",
37658 card->index);
37659- atomic_inc(&vcc->stats->rx_drop);
37660+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37661 recycle_iovec_rx_bufs(card,
37662 (struct iovec *)
37663 iovb->data,
37664@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37665 card->hbpool.count++;
37666 } else
37667 dev_kfree_skb_any(hb);
37668- atomic_inc(&vcc->stats->rx_drop);
37669+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37670 } else {
37671 /* Copy the small buffer to the huge buffer */
37672 sb = (struct sk_buff *)iov->iov_base;
37673@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37674 #endif /* NS_USE_DESTRUCTORS */
37675 __net_timestamp(hb);
37676 vcc->push(vcc, hb);
37677- atomic_inc(&vcc->stats->rx);
37678+ atomic_inc_unchecked(&vcc->stats->rx);
37679 }
37680 }
37681
37682diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37683index e3fb496..d9646bf 100644
37684--- a/drivers/atm/solos-pci.c
37685+++ b/drivers/atm/solos-pci.c
37686@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37687 }
37688 atm_charge(vcc, skb->truesize);
37689 vcc->push(vcc, skb);
37690- atomic_inc(&vcc->stats->rx);
37691+ atomic_inc_unchecked(&vcc->stats->rx);
37692 break;
37693
37694 case PKT_STATUS:
37695@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37696 vcc = SKB_CB(oldskb)->vcc;
37697
37698 if (vcc) {
37699- atomic_inc(&vcc->stats->tx);
37700+ atomic_inc_unchecked(&vcc->stats->tx);
37701 solos_pop(vcc, oldskb);
37702 } else {
37703 dev_kfree_skb_irq(oldskb);
37704diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37705index 0215934..ce9f5b1 100644
37706--- a/drivers/atm/suni.c
37707+++ b/drivers/atm/suni.c
37708@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37709
37710
37711 #define ADD_LIMITED(s,v) \
37712- atomic_add((v),&stats->s); \
37713- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37714+ atomic_add_unchecked((v),&stats->s); \
37715+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37716
37717
37718 static void suni_hz(unsigned long from_timer)
37719diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37720index 5120a96..e2572bd 100644
37721--- a/drivers/atm/uPD98402.c
37722+++ b/drivers/atm/uPD98402.c
37723@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37724 struct sonet_stats tmp;
37725 int error = 0;
37726
37727- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37728+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37729 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37730 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37731 if (zero && !error) {
37732@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37733
37734
37735 #define ADD_LIMITED(s,v) \
37736- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37737- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37738- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37739+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37740+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37741+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37742
37743
37744 static void stat_event(struct atm_dev *dev)
37745@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37746 if (reason & uPD98402_INT_PFM) stat_event(dev);
37747 if (reason & uPD98402_INT_PCO) {
37748 (void) GET(PCOCR); /* clear interrupt cause */
37749- atomic_add(GET(HECCT),
37750+ atomic_add_unchecked(GET(HECCT),
37751 &PRIV(dev)->sonet_stats.uncorr_hcs);
37752 }
37753 if ((reason & uPD98402_INT_RFO) &&
37754@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37755 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37756 uPD98402_INT_LOS),PIMR); /* enable them */
37757 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37758- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37759- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37760- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37761+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37762+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37763+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37764 return 0;
37765 }
37766
37767diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37768index 969c3c2..9b72956 100644
37769--- a/drivers/atm/zatm.c
37770+++ b/drivers/atm/zatm.c
37771@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37772 }
37773 if (!size) {
37774 dev_kfree_skb_irq(skb);
37775- if (vcc) atomic_inc(&vcc->stats->rx_err);
37776+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37777 continue;
37778 }
37779 if (!atm_charge(vcc,skb->truesize)) {
37780@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37781 skb->len = size;
37782 ATM_SKB(skb)->vcc = vcc;
37783 vcc->push(vcc,skb);
37784- atomic_inc(&vcc->stats->rx);
37785+ atomic_inc_unchecked(&vcc->stats->rx);
37786 }
37787 zout(pos & 0xffff,MTA(mbx));
37788 #if 0 /* probably a stupid idea */
37789@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37790 skb_queue_head(&zatm_vcc->backlog,skb);
37791 break;
37792 }
37793- atomic_inc(&vcc->stats->tx);
37794+ atomic_inc_unchecked(&vcc->stats->tx);
37795 wake_up(&zatm_vcc->tx_wait);
37796 }
37797
37798diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37799index 59dc808..f10c74e 100644
37800--- a/drivers/base/bus.c
37801+++ b/drivers/base/bus.c
37802@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37803 return -EINVAL;
37804
37805 mutex_lock(&subsys->p->mutex);
37806- list_add_tail(&sif->node, &subsys->p->interfaces);
37807+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37808 if (sif->add_dev) {
37809 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37810 while ((dev = subsys_dev_iter_next(&iter)))
37811@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37812 subsys = sif->subsys;
37813
37814 mutex_lock(&subsys->p->mutex);
37815- list_del_init(&sif->node);
37816+ pax_list_del_init((struct list_head *)&sif->node);
37817 if (sif->remove_dev) {
37818 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37819 while ((dev = subsys_dev_iter_next(&iter)))
37820diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37821index 25798db..15f130e 100644
37822--- a/drivers/base/devtmpfs.c
37823+++ b/drivers/base/devtmpfs.c
37824@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37825 if (!thread)
37826 return 0;
37827
37828- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37829+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37830 if (err)
37831 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37832 else
37833@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37834 *err = sys_unshare(CLONE_NEWNS);
37835 if (*err)
37836 goto out;
37837- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37838+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37839 if (*err)
37840 goto out;
37841- sys_chdir("/.."); /* will traverse into overmounted root */
37842- sys_chroot(".");
37843+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37844+ sys_chroot((char __force_user *)".");
37845 complete(&setup_done);
37846 while (1) {
37847 spin_lock(&req_lock);
37848diff --git a/drivers/base/node.c b/drivers/base/node.c
37849index bc9f43b..29703b8 100644
37850--- a/drivers/base/node.c
37851+++ b/drivers/base/node.c
37852@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37853 struct node_attr {
37854 struct device_attribute attr;
37855 enum node_states state;
37856-};
37857+} __do_const;
37858
37859 static ssize_t show_node_state(struct device *dev,
37860 struct device_attribute *attr, char *buf)
37861diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37862index bfb8955..4ebff34 100644
37863--- a/drivers/base/power/domain.c
37864+++ b/drivers/base/power/domain.c
37865@@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37866
37867 if (dev->power.subsys_data->domain_data) {
37868 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37869- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37870+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37871 if (clear_td)
37872- gpd_data->td = (struct gpd_timing_data){ 0 };
37873+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37874
37875 if (--gpd_data->refcount == 0) {
37876 dev->power.subsys_data->domain_data = NULL;
37877@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37878 {
37879 struct cpuidle_driver *cpuidle_drv;
37880 struct gpd_cpu_data *cpu_data;
37881- struct cpuidle_state *idle_state;
37882+ cpuidle_state_no_const *idle_state;
37883 int ret = 0;
37884
37885 if (IS_ERR_OR_NULL(genpd) || state < 0)
37886@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37887 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37888 {
37889 struct gpd_cpu_data *cpu_data;
37890- struct cpuidle_state *idle_state;
37891+ cpuidle_state_no_const *idle_state;
37892 int ret = 0;
37893
37894 if (IS_ERR_OR_NULL(genpd))
37895diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37896index 03e089a..0e9560c 100644
37897--- a/drivers/base/power/sysfs.c
37898+++ b/drivers/base/power/sysfs.c
37899@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37900 return -EIO;
37901 }
37902 }
37903- return sprintf(buf, p);
37904+ return sprintf(buf, "%s", p);
37905 }
37906
37907 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37908diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37909index 2d56f41..8830f19 100644
37910--- a/drivers/base/power/wakeup.c
37911+++ b/drivers/base/power/wakeup.c
37912@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37913 * They need to be modified together atomically, so it's better to use one
37914 * atomic variable to hold them both.
37915 */
37916-static atomic_t combined_event_count = ATOMIC_INIT(0);
37917+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37918
37919 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37920 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37921
37922 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37923 {
37924- unsigned int comb = atomic_read(&combined_event_count);
37925+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37926
37927 *cnt = (comb >> IN_PROGRESS_BITS);
37928 *inpr = comb & MAX_IN_PROGRESS;
37929@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37930 ws->start_prevent_time = ws->last_time;
37931
37932 /* Increment the counter of events in progress. */
37933- cec = atomic_inc_return(&combined_event_count);
37934+ cec = atomic_inc_return_unchecked(&combined_event_count);
37935
37936 trace_wakeup_source_activate(ws->name, cec);
37937 }
37938@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37939 * Increment the counter of registered wakeup events and decrement the
37940 * couter of wakeup events in progress simultaneously.
37941 */
37942- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37943+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37944 trace_wakeup_source_deactivate(ws->name, cec);
37945
37946 split_counters(&cnt, &inpr);
37947diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37948index e8d11b6..7b1b36f 100644
37949--- a/drivers/base/syscore.c
37950+++ b/drivers/base/syscore.c
37951@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37952 void register_syscore_ops(struct syscore_ops *ops)
37953 {
37954 mutex_lock(&syscore_ops_lock);
37955- list_add_tail(&ops->node, &syscore_ops_list);
37956+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37957 mutex_unlock(&syscore_ops_lock);
37958 }
37959 EXPORT_SYMBOL_GPL(register_syscore_ops);
37960@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37961 void unregister_syscore_ops(struct syscore_ops *ops)
37962 {
37963 mutex_lock(&syscore_ops_lock);
37964- list_del(&ops->node);
37965+ pax_list_del((struct list_head *)&ops->node);
37966 mutex_unlock(&syscore_ops_lock);
37967 }
37968 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37969diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37970index 036e8ab..6221dec 100644
37971--- a/drivers/block/cciss.c
37972+++ b/drivers/block/cciss.c
37973@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37974 while (!list_empty(&h->reqQ)) {
37975 c = list_entry(h->reqQ.next, CommandList_struct, list);
37976 /* can't do anything if fifo is full */
37977- if ((h->access.fifo_full(h))) {
37978+ if ((h->access->fifo_full(h))) {
37979 dev_warn(&h->pdev->dev, "fifo full\n");
37980 break;
37981 }
37982@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37983 h->Qdepth--;
37984
37985 /* Tell the controller execute command */
37986- h->access.submit_command(h, c);
37987+ h->access->submit_command(h, c);
37988
37989 /* Put job onto the completed Q */
37990 addQ(&h->cmpQ, c);
37991@@ -3447,17 +3447,17 @@ startio:
37992
37993 static inline unsigned long get_next_completion(ctlr_info_t *h)
37994 {
37995- return h->access.command_completed(h);
37996+ return h->access->command_completed(h);
37997 }
37998
37999 static inline int interrupt_pending(ctlr_info_t *h)
38000 {
38001- return h->access.intr_pending(h);
38002+ return h->access->intr_pending(h);
38003 }
38004
38005 static inline long interrupt_not_for_us(ctlr_info_t *h)
38006 {
38007- return ((h->access.intr_pending(h) == 0) ||
38008+ return ((h->access->intr_pending(h) == 0) ||
38009 (h->interrupts_enabled == 0));
38010 }
38011
38012@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
38013 u32 a;
38014
38015 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38016- return h->access.command_completed(h);
38017+ return h->access->command_completed(h);
38018
38019 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
38020 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
38021@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
38022 trans_support & CFGTBL_Trans_use_short_tags);
38023
38024 /* Change the access methods to the performant access methods */
38025- h->access = SA5_performant_access;
38026+ h->access = &SA5_performant_access;
38027 h->transMethod = CFGTBL_Trans_Performant;
38028
38029 return;
38030@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
38031 if (prod_index < 0)
38032 return -ENODEV;
38033 h->product_name = products[prod_index].product_name;
38034- h->access = *(products[prod_index].access);
38035+ h->access = products[prod_index].access;
38036
38037 if (cciss_board_disabled(h)) {
38038 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
38039@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
38040 }
38041
38042 /* make sure the board interrupts are off */
38043- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38044+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38045 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
38046 if (rc)
38047 goto clean2;
38048@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
38049 * fake ones to scoop up any residual completions.
38050 */
38051 spin_lock_irqsave(&h->lock, flags);
38052- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38053+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38054 spin_unlock_irqrestore(&h->lock, flags);
38055 free_irq(h->intr[h->intr_mode], h);
38056 rc = cciss_request_irq(h, cciss_msix_discard_completions,
38057@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
38058 dev_info(&h->pdev->dev, "Board READY.\n");
38059 dev_info(&h->pdev->dev,
38060 "Waiting for stale completions to drain.\n");
38061- h->access.set_intr_mask(h, CCISS_INTR_ON);
38062+ h->access->set_intr_mask(h, CCISS_INTR_ON);
38063 msleep(10000);
38064- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38065+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38066
38067 rc = controller_reset_failed(h->cfgtable);
38068 if (rc)
38069@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
38070 cciss_scsi_setup(h);
38071
38072 /* Turn the interrupts on so we can service requests */
38073- h->access.set_intr_mask(h, CCISS_INTR_ON);
38074+ h->access->set_intr_mask(h, CCISS_INTR_ON);
38075
38076 /* Get the firmware version */
38077 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
38078@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
38079 kfree(flush_buf);
38080 if (return_code != IO_OK)
38081 dev_warn(&h->pdev->dev, "Error flushing cache\n");
38082- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38083+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38084 free_irq(h->intr[h->intr_mode], h);
38085 }
38086
38087diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
38088index 7fda30e..2f27946 100644
38089--- a/drivers/block/cciss.h
38090+++ b/drivers/block/cciss.h
38091@@ -101,7 +101,7 @@ struct ctlr_info
38092 /* information about each logical volume */
38093 drive_info_struct *drv[CISS_MAX_LUN];
38094
38095- struct access_method access;
38096+ struct access_method *access;
38097
38098 /* queue and queue Info */
38099 struct list_head reqQ;
38100@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
38101 }
38102
38103 static struct access_method SA5_access = {
38104- SA5_submit_command,
38105- SA5_intr_mask,
38106- SA5_fifo_full,
38107- SA5_intr_pending,
38108- SA5_completed,
38109+ .submit_command = SA5_submit_command,
38110+ .set_intr_mask = SA5_intr_mask,
38111+ .fifo_full = SA5_fifo_full,
38112+ .intr_pending = SA5_intr_pending,
38113+ .command_completed = SA5_completed,
38114 };
38115
38116 static struct access_method SA5B_access = {
38117- SA5_submit_command,
38118- SA5B_intr_mask,
38119- SA5_fifo_full,
38120- SA5B_intr_pending,
38121- SA5_completed,
38122+ .submit_command = SA5_submit_command,
38123+ .set_intr_mask = SA5B_intr_mask,
38124+ .fifo_full = SA5_fifo_full,
38125+ .intr_pending = SA5B_intr_pending,
38126+ .command_completed = SA5_completed,
38127 };
38128
38129 static struct access_method SA5_performant_access = {
38130- SA5_submit_command,
38131- SA5_performant_intr_mask,
38132- SA5_fifo_full,
38133- SA5_performant_intr_pending,
38134- SA5_performant_completed,
38135+ .submit_command = SA5_submit_command,
38136+ .set_intr_mask = SA5_performant_intr_mask,
38137+ .fifo_full = SA5_fifo_full,
38138+ .intr_pending = SA5_performant_intr_pending,
38139+ .command_completed = SA5_performant_completed,
38140 };
38141
38142 struct board_type {
38143diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
38144index 2b94403..fd6ad1f 100644
38145--- a/drivers/block/cpqarray.c
38146+++ b/drivers/block/cpqarray.c
38147@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38148 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
38149 goto Enomem4;
38150 }
38151- hba[i]->access.set_intr_mask(hba[i], 0);
38152+ hba[i]->access->set_intr_mask(hba[i], 0);
38153 if (request_irq(hba[i]->intr, do_ida_intr,
38154 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
38155 {
38156@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38157 add_timer(&hba[i]->timer);
38158
38159 /* Enable IRQ now that spinlock and rate limit timer are set up */
38160- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38161+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38162
38163 for(j=0; j<NWD; j++) {
38164 struct gendisk *disk = ida_gendisk[i][j];
38165@@ -694,7 +694,7 @@ DBGINFO(
38166 for(i=0; i<NR_PRODUCTS; i++) {
38167 if (board_id == products[i].board_id) {
38168 c->product_name = products[i].product_name;
38169- c->access = *(products[i].access);
38170+ c->access = products[i].access;
38171 break;
38172 }
38173 }
38174@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
38175 hba[ctlr]->intr = intr;
38176 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
38177 hba[ctlr]->product_name = products[j].product_name;
38178- hba[ctlr]->access = *(products[j].access);
38179+ hba[ctlr]->access = products[j].access;
38180 hba[ctlr]->ctlr = ctlr;
38181 hba[ctlr]->board_id = board_id;
38182 hba[ctlr]->pci_dev = NULL; /* not PCI */
38183@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
38184
38185 while((c = h->reqQ) != NULL) {
38186 /* Can't do anything if we're busy */
38187- if (h->access.fifo_full(h) == 0)
38188+ if (h->access->fifo_full(h) == 0)
38189 return;
38190
38191 /* Get the first entry from the request Q */
38192@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38193 h->Qdepth--;
38194
38195 /* Tell the controller to do our bidding */
38196- h->access.submit_command(h, c);
38197+ h->access->submit_command(h, c);
38198
38199 /* Get onto the completion Q */
38200 addQ(&h->cmpQ, c);
38201@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38202 unsigned long flags;
38203 __u32 a,a1;
38204
38205- istat = h->access.intr_pending(h);
38206+ istat = h->access->intr_pending(h);
38207 /* Is this interrupt for us? */
38208 if (istat == 0)
38209 return IRQ_NONE;
38210@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38211 */
38212 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38213 if (istat & FIFO_NOT_EMPTY) {
38214- while((a = h->access.command_completed(h))) {
38215+ while((a = h->access->command_completed(h))) {
38216 a1 = a; a &= ~3;
38217 if ((c = h->cmpQ) == NULL)
38218 {
38219@@ -1448,11 +1448,11 @@ static int sendcmd(
38220 /*
38221 * Disable interrupt
38222 */
38223- info_p->access.set_intr_mask(info_p, 0);
38224+ info_p->access->set_intr_mask(info_p, 0);
38225 /* Make sure there is room in the command FIFO */
38226 /* Actually it should be completely empty at this time. */
38227 for (i = 200000; i > 0; i--) {
38228- temp = info_p->access.fifo_full(info_p);
38229+ temp = info_p->access->fifo_full(info_p);
38230 if (temp != 0) {
38231 break;
38232 }
38233@@ -1465,7 +1465,7 @@ DBG(
38234 /*
38235 * Send the cmd
38236 */
38237- info_p->access.submit_command(info_p, c);
38238+ info_p->access->submit_command(info_p, c);
38239 complete = pollcomplete(ctlr);
38240
38241 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38242@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38243 * we check the new geometry. Then turn interrupts back on when
38244 * we're done.
38245 */
38246- host->access.set_intr_mask(host, 0);
38247+ host->access->set_intr_mask(host, 0);
38248 getgeometry(ctlr);
38249- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38250+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38251
38252 for(i=0; i<NWD; i++) {
38253 struct gendisk *disk = ida_gendisk[ctlr][i];
38254@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38255 /* Wait (up to 2 seconds) for a command to complete */
38256
38257 for (i = 200000; i > 0; i--) {
38258- done = hba[ctlr]->access.command_completed(hba[ctlr]);
38259+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
38260 if (done == 0) {
38261 udelay(10); /* a short fixed delay */
38262 } else
38263diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38264index be73e9d..7fbf140 100644
38265--- a/drivers/block/cpqarray.h
38266+++ b/drivers/block/cpqarray.h
38267@@ -99,7 +99,7 @@ struct ctlr_info {
38268 drv_info_t drv[NWD];
38269 struct proc_dir_entry *proc;
38270
38271- struct access_method access;
38272+ struct access_method *access;
38273
38274 cmdlist_t *reqQ;
38275 cmdlist_t *cmpQ;
38276diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38277index 0e06f0c..c47b81d 100644
38278--- a/drivers/block/drbd/drbd_int.h
38279+++ b/drivers/block/drbd/drbd_int.h
38280@@ -582,7 +582,7 @@ struct drbd_epoch {
38281 struct drbd_tconn *tconn;
38282 struct list_head list;
38283 unsigned int barrier_nr;
38284- atomic_t epoch_size; /* increased on every request added. */
38285+ atomic_unchecked_t epoch_size; /* increased on every request added. */
38286 atomic_t active; /* increased on every req. added, and dec on every finished. */
38287 unsigned long flags;
38288 };
38289@@ -1022,7 +1022,7 @@ struct drbd_conf {
38290 unsigned int al_tr_number;
38291 int al_tr_cycle;
38292 wait_queue_head_t seq_wait;
38293- atomic_t packet_seq;
38294+ atomic_unchecked_t packet_seq;
38295 unsigned int peer_seq;
38296 spinlock_t peer_seq_lock;
38297 unsigned int minor;
38298@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38299 char __user *uoptval;
38300 int err;
38301
38302- uoptval = (char __user __force *)optval;
38303+ uoptval = (char __force_user *)optval;
38304
38305 set_fs(KERNEL_DS);
38306 if (level == SOL_SOCKET)
38307diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
38308index 89c497c..9c736ae 100644
38309--- a/drivers/block/drbd/drbd_interval.c
38310+++ b/drivers/block/drbd/drbd_interval.c
38311@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
38312 }
38313
38314 static const struct rb_augment_callbacks augment_callbacks = {
38315- augment_propagate,
38316- augment_copy,
38317- augment_rotate,
38318+ .propagate = augment_propagate,
38319+ .copy = augment_copy,
38320+ .rotate = augment_rotate,
38321 };
38322
38323 /**
38324diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38325index 929468e..7d934eb 100644
38326--- a/drivers/block/drbd/drbd_main.c
38327+++ b/drivers/block/drbd/drbd_main.c
38328@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
38329 p->sector = sector;
38330 p->block_id = block_id;
38331 p->blksize = blksize;
38332- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
38333+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
38334 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
38335 }
38336
38337@@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
38338 return -EIO;
38339 p->sector = cpu_to_be64(req->i.sector);
38340 p->block_id = (unsigned long)req;
38341- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
38342+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
38343 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
38344 if (mdev->state.conn >= C_SYNC_SOURCE &&
38345 mdev->state.conn <= C_PAUSED_SYNC_T)
38346@@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
38347 {
38348 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
38349
38350- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
38351- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
38352+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
38353+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
38354 kfree(tconn->current_epoch);
38355
38356 idr_destroy(&tconn->volumes);
38357diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38358index c706d50..5e1b472 100644
38359--- a/drivers/block/drbd/drbd_nl.c
38360+++ b/drivers/block/drbd/drbd_nl.c
38361@@ -3440,7 +3440,7 @@ out:
38362
38363 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
38364 {
38365- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38366+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38367 struct sk_buff *msg;
38368 struct drbd_genlmsghdr *d_out;
38369 unsigned seq;
38370@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
38371 return;
38372 }
38373
38374- seq = atomic_inc_return(&drbd_genl_seq);
38375+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38376 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38377 if (!msg)
38378 goto failed;
38379diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38380index d073305..4998fea 100644
38381--- a/drivers/block/drbd/drbd_receiver.c
38382+++ b/drivers/block/drbd/drbd_receiver.c
38383@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
38384 {
38385 int err;
38386
38387- atomic_set(&mdev->packet_seq, 0);
38388+ atomic_set_unchecked(&mdev->packet_seq, 0);
38389 mdev->peer_seq = 0;
38390
38391 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
38392@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
38393 do {
38394 next_epoch = NULL;
38395
38396- epoch_size = atomic_read(&epoch->epoch_size);
38397+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38398
38399 switch (ev & ~EV_CLEANUP) {
38400 case EV_PUT:
38401@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
38402 rv = FE_DESTROYED;
38403 } else {
38404 epoch->flags = 0;
38405- atomic_set(&epoch->epoch_size, 0);
38406+ atomic_set_unchecked(&epoch->epoch_size, 0);
38407 /* atomic_set(&epoch->active, 0); is already zero */
38408 if (rv == FE_STILL_LIVE)
38409 rv = FE_RECYCLED;
38410@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
38411 conn_wait_active_ee_empty(tconn);
38412 drbd_flush(tconn);
38413
38414- if (atomic_read(&tconn->current_epoch->epoch_size)) {
38415+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
38416 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38417 if (epoch)
38418 break;
38419@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
38420 }
38421
38422 epoch->flags = 0;
38423- atomic_set(&epoch->epoch_size, 0);
38424+ atomic_set_unchecked(&epoch->epoch_size, 0);
38425 atomic_set(&epoch->active, 0);
38426
38427 spin_lock(&tconn->epoch_lock);
38428- if (atomic_read(&tconn->current_epoch->epoch_size)) {
38429+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
38430 list_add(&epoch->list, &tconn->current_epoch->list);
38431 tconn->current_epoch = epoch;
38432 tconn->epochs++;
38433@@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
38434
38435 err = wait_for_and_update_peer_seq(mdev, peer_seq);
38436 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
38437- atomic_inc(&tconn->current_epoch->epoch_size);
38438+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
38439 err2 = drbd_drain_block(mdev, pi->size);
38440 if (!err)
38441 err = err2;
38442@@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
38443
38444 spin_lock(&tconn->epoch_lock);
38445 peer_req->epoch = tconn->current_epoch;
38446- atomic_inc(&peer_req->epoch->epoch_size);
38447+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38448 atomic_inc(&peer_req->epoch->active);
38449 spin_unlock(&tconn->epoch_lock);
38450
38451@@ -4345,7 +4345,7 @@ struct data_cmd {
38452 int expect_payload;
38453 size_t pkt_size;
38454 int (*fn)(struct drbd_tconn *, struct packet_info *);
38455-};
38456+} __do_const;
38457
38458 static struct data_cmd drbd_cmd_handler[] = {
38459 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38460@@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
38461 if (!list_empty(&tconn->current_epoch->list))
38462 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
38463 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38464- atomic_set(&tconn->current_epoch->epoch_size, 0);
38465+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
38466 tconn->send.seen_any_write_yet = false;
38467
38468 conn_info(tconn, "Connection closed\n");
38469@@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
38470 struct asender_cmd {
38471 size_t pkt_size;
38472 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
38473-};
38474+} __do_const;
38475
38476 static struct asender_cmd asender_tbl[] = {
38477 [P_PING] = { 0, got_Ping },
38478diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38479index 66e8c3b..9b68dd9 100644
38480--- a/drivers/block/loop.c
38481+++ b/drivers/block/loop.c
38482@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38483
38484 file_start_write(file);
38485 set_fs(get_ds());
38486- bw = file->f_op->write(file, buf, len, &pos);
38487+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38488 set_fs(old_fs);
38489 file_end_write(file);
38490 if (likely(bw == len))
38491diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38492index 091b9ea..f5428f8 100644
38493--- a/drivers/block/null_blk.c
38494+++ b/drivers/block/null_blk.c
38495@@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38496 return 0;
38497 }
38498
38499-static struct blk_mq_ops null_mq_ops = {
38500- .queue_rq = null_queue_rq,
38501- .map_queue = blk_mq_map_queue,
38502+static struct blk_mq_ops null_mq_single_ops = {
38503+ .queue_rq = null_queue_rq,
38504+ .map_queue = blk_mq_map_queue,
38505 .init_hctx = null_init_hctx,
38506 .complete = null_softirq_done_fn,
38507+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
38508+ .free_hctx = blk_mq_free_single_hw_queue,
38509+};
38510+
38511+static struct blk_mq_ops null_mq_per_node_ops = {
38512+ .queue_rq = null_queue_rq,
38513+ .map_queue = blk_mq_map_queue,
38514+ .init_hctx = null_init_hctx,
38515+ .alloc_hctx = null_alloc_hctx,
38516+ .free_hctx = null_free_hctx,
38517 };
38518
38519 static struct blk_mq_reg null_mq_reg = {
38520- .ops = &null_mq_ops,
38521+ .ops = &null_mq_single_ops,
38522 .queue_depth = 64,
38523 .cmd_size = sizeof(struct nullb_cmd),
38524 .flags = BLK_MQ_F_SHOULD_MERGE,
38525@@ -521,13 +531,8 @@ static int null_add_dev(void)
38526 null_mq_reg.queue_depth = hw_queue_depth;
38527 null_mq_reg.nr_hw_queues = submit_queues;
38528
38529- if (use_per_node_hctx) {
38530- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38531- null_mq_reg.ops->free_hctx = null_free_hctx;
38532- } else {
38533- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38534- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38535- }
38536+ if (use_per_node_hctx)
38537+ null_mq_reg.ops = &null_mq_per_node_ops;
38538
38539 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38540 } else if (queue_mode == NULL_Q_BIO) {
38541diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38542index a2af73d..c0b8f61 100644
38543--- a/drivers/block/pktcdvd.c
38544+++ b/drivers/block/pktcdvd.c
38545@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38546
38547 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38548 {
38549- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38550+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38551 }
38552
38553 /*
38554@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38555 return -EROFS;
38556 }
38557 pd->settings.fp = ti.fp;
38558- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38559+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38560
38561 if (ti.nwa_v) {
38562 pd->nwa = be32_to_cpu(ti.next_writable);
38563diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38564index e5565fb..71be10b4 100644
38565--- a/drivers/block/smart1,2.h
38566+++ b/drivers/block/smart1,2.h
38567@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38568 }
38569
38570 static struct access_method smart4_access = {
38571- smart4_submit_command,
38572- smart4_intr_mask,
38573- smart4_fifo_full,
38574- smart4_intr_pending,
38575- smart4_completed,
38576+ .submit_command = smart4_submit_command,
38577+ .set_intr_mask = smart4_intr_mask,
38578+ .fifo_full = smart4_fifo_full,
38579+ .intr_pending = smart4_intr_pending,
38580+ .command_completed = smart4_completed,
38581 };
38582
38583 /*
38584@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38585 }
38586
38587 static struct access_method smart2_access = {
38588- smart2_submit_command,
38589- smart2_intr_mask,
38590- smart2_fifo_full,
38591- smart2_intr_pending,
38592- smart2_completed,
38593+ .submit_command = smart2_submit_command,
38594+ .set_intr_mask = smart2_intr_mask,
38595+ .fifo_full = smart2_fifo_full,
38596+ .intr_pending = smart2_intr_pending,
38597+ .command_completed = smart2_completed,
38598 };
38599
38600 /*
38601@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38602 }
38603
38604 static struct access_method smart2e_access = {
38605- smart2e_submit_command,
38606- smart2e_intr_mask,
38607- smart2e_fifo_full,
38608- smart2e_intr_pending,
38609- smart2e_completed,
38610+ .submit_command = smart2e_submit_command,
38611+ .set_intr_mask = smart2e_intr_mask,
38612+ .fifo_full = smart2e_fifo_full,
38613+ .intr_pending = smart2e_intr_pending,
38614+ .command_completed = smart2e_completed,
38615 };
38616
38617 /*
38618@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38619 }
38620
38621 static struct access_method smart1_access = {
38622- smart1_submit_command,
38623- smart1_intr_mask,
38624- smart1_fifo_full,
38625- smart1_intr_pending,
38626- smart1_completed,
38627+ .submit_command = smart1_submit_command,
38628+ .set_intr_mask = smart1_intr_mask,
38629+ .fifo_full = smart1_fifo_full,
38630+ .intr_pending = smart1_intr_pending,
38631+ .command_completed = smart1_completed,
38632 };
38633diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38634index f038dba..bb74c08 100644
38635--- a/drivers/bluetooth/btwilink.c
38636+++ b/drivers/bluetooth/btwilink.c
38637@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38638
38639 static int bt_ti_probe(struct platform_device *pdev)
38640 {
38641- static struct ti_st *hst;
38642+ struct ti_st *hst;
38643 struct hci_dev *hdev;
38644 int err;
38645
38646diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38647index 8a3aff7..d7538c2 100644
38648--- a/drivers/cdrom/cdrom.c
38649+++ b/drivers/cdrom/cdrom.c
38650@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38651 ENSURE(reset, CDC_RESET);
38652 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38653 cdi->mc_flags = 0;
38654- cdo->n_minors = 0;
38655 cdi->options = CDO_USE_FFLAGS;
38656
38657 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38658@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38659 else
38660 cdi->cdda_method = CDDA_OLD;
38661
38662- if (!cdo->generic_packet)
38663- cdo->generic_packet = cdrom_dummy_generic_packet;
38664+ if (!cdo->generic_packet) {
38665+ pax_open_kernel();
38666+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38667+ pax_close_kernel();
38668+ }
38669
38670 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38671 mutex_lock(&cdrom_mutex);
38672@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38673 if (cdi->exit)
38674 cdi->exit(cdi);
38675
38676- cdi->ops->n_minors--;
38677 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38678 }
38679
38680@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38681 */
38682 nr = nframes;
38683 do {
38684- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38685+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38686 if (cgc.buffer)
38687 break;
38688
38689@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38690 struct cdrom_device_info *cdi;
38691 int ret;
38692
38693- ret = scnprintf(info + *pos, max_size - *pos, header);
38694+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38695 if (!ret)
38696 return 1;
38697
38698diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38699index 51e75ad..39c4c76 100644
38700--- a/drivers/cdrom/gdrom.c
38701+++ b/drivers/cdrom/gdrom.c
38702@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38703 .audio_ioctl = gdrom_audio_ioctl,
38704 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38705 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38706- .n_minors = 1,
38707 };
38708
38709 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38710diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38711index 1386749..5430258 100644
38712--- a/drivers/char/Kconfig
38713+++ b/drivers/char/Kconfig
38714@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38715
38716 config DEVKMEM
38717 bool "/dev/kmem virtual device support"
38718- default y
38719+ default n
38720+ depends on !GRKERNSEC_KMEM
38721 help
38722 Say Y here if you want to support the /dev/kmem device. The
38723 /dev/kmem device is rarely used, but can be used for certain
38724@@ -577,6 +578,7 @@ config DEVPORT
38725 bool
38726 depends on !M68K
38727 depends on ISA || PCI
38728+ depends on !GRKERNSEC_KMEM
38729 default y
38730
38731 source "drivers/s390/char/Kconfig"
38732diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38733index a48e05b..6bac831 100644
38734--- a/drivers/char/agp/compat_ioctl.c
38735+++ b/drivers/char/agp/compat_ioctl.c
38736@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38737 return -ENOMEM;
38738 }
38739
38740- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38741+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38742 sizeof(*usegment) * ureserve.seg_count)) {
38743 kfree(usegment);
38744 kfree(ksegment);
38745diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38746index 1b19239..963967b 100644
38747--- a/drivers/char/agp/frontend.c
38748+++ b/drivers/char/agp/frontend.c
38749@@ -731,6 +731,7 @@ static int agpioc_info_wrap(struct agp_file_private *priv, void __user *arg)
38750
38751 agp_copy_info(agp_bridge, &kerninfo);
38752
38753+ memset(&userinfo, 0, sizeof(userinfo));
38754 userinfo.version.major = kerninfo.version.major;
38755 userinfo.version.minor = kerninfo.version.minor;
38756 userinfo.bridge_id = kerninfo.device->vendor |
38757@@ -819,7 +820,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38758 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38759 return -EFAULT;
38760
38761- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38762+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38763 return -EFAULT;
38764
38765 client = agp_find_client_by_pid(reserve.pid);
38766@@ -849,7 +850,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38767 if (segment == NULL)
38768 return -ENOMEM;
38769
38770- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38771+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38772 sizeof(struct agp_segment) * reserve.seg_count)) {
38773 kfree(segment);
38774 return -EFAULT;
38775diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38776index 4f94375..413694e 100644
38777--- a/drivers/char/genrtc.c
38778+++ b/drivers/char/genrtc.c
38779@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38780 switch (cmd) {
38781
38782 case RTC_PLL_GET:
38783+ memset(&pll, 0, sizeof(pll));
38784 if (get_rtc_pll(&pll))
38785 return -EINVAL;
38786 else
38787diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38788index d5d4cd8..22d561d 100644
38789--- a/drivers/char/hpet.c
38790+++ b/drivers/char/hpet.c
38791@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38792 }
38793
38794 static int
38795-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38796+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38797 struct hpet_info *info)
38798 {
38799 struct hpet_timer __iomem *timer;
38800diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38801index 86fe45c..c0ea948 100644
38802--- a/drivers/char/hw_random/intel-rng.c
38803+++ b/drivers/char/hw_random/intel-rng.c
38804@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38805
38806 if (no_fwh_detect)
38807 return -ENODEV;
38808- printk(warning);
38809+ printk("%s", warning);
38810 return -EBUSY;
38811 }
38812
38813diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38814index ec4e10f..f2a763b 100644
38815--- a/drivers/char/ipmi/ipmi_msghandler.c
38816+++ b/drivers/char/ipmi/ipmi_msghandler.c
38817@@ -420,7 +420,7 @@ struct ipmi_smi {
38818 struct proc_dir_entry *proc_dir;
38819 char proc_dir_name[10];
38820
38821- atomic_t stats[IPMI_NUM_STATS];
38822+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38823
38824 /*
38825 * run_to_completion duplicate of smb_info, smi_info
38826@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38827
38828
38829 #define ipmi_inc_stat(intf, stat) \
38830- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38831+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38832 #define ipmi_get_stat(intf, stat) \
38833- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38834+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38835
38836 static int is_lan_addr(struct ipmi_addr *addr)
38837 {
38838@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38839 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38840 init_waitqueue_head(&intf->waitq);
38841 for (i = 0; i < IPMI_NUM_STATS; i++)
38842- atomic_set(&intf->stats[i], 0);
38843+ atomic_set_unchecked(&intf->stats[i], 0);
38844
38845 intf->proc_dir = NULL;
38846
38847diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38848index 8b4fa2c..5f81848 100644
38849--- a/drivers/char/ipmi/ipmi_si_intf.c
38850+++ b/drivers/char/ipmi/ipmi_si_intf.c
38851@@ -283,7 +283,7 @@ struct smi_info {
38852 unsigned char slave_addr;
38853
38854 /* Counters and things for the proc filesystem. */
38855- atomic_t stats[SI_NUM_STATS];
38856+ atomic_unchecked_t stats[SI_NUM_STATS];
38857
38858 struct task_struct *thread;
38859
38860@@ -292,9 +292,9 @@ struct smi_info {
38861 };
38862
38863 #define smi_inc_stat(smi, stat) \
38864- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38865+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38866 #define smi_get_stat(smi, stat) \
38867- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38868+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38869
38870 #define SI_MAX_PARMS 4
38871
38872@@ -3349,7 +3349,7 @@ static int try_smi_init(struct smi_info *new_smi)
38873 atomic_set(&new_smi->req_events, 0);
38874 new_smi->run_to_completion = 0;
38875 for (i = 0; i < SI_NUM_STATS; i++)
38876- atomic_set(&new_smi->stats[i], 0);
38877+ atomic_set_unchecked(&new_smi->stats[i], 0);
38878
38879 new_smi->interrupt_disabled = 1;
38880 atomic_set(&new_smi->stop_operation, 0);
38881diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38882index 92c5937..1be4e4d 100644
38883--- a/drivers/char/mem.c
38884+++ b/drivers/char/mem.c
38885@@ -18,6 +18,7 @@
38886 #include <linux/raw.h>
38887 #include <linux/tty.h>
38888 #include <linux/capability.h>
38889+#include <linux/security.h>
38890 #include <linux/ptrace.h>
38891 #include <linux/device.h>
38892 #include <linux/highmem.h>
38893@@ -36,6 +37,10 @@
38894
38895 #define DEVPORT_MINOR 4
38896
38897+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38898+extern const struct file_operations grsec_fops;
38899+#endif
38900+
38901 static inline unsigned long size_inside_page(unsigned long start,
38902 unsigned long size)
38903 {
38904@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38905
38906 while (cursor < to) {
38907 if (!devmem_is_allowed(pfn)) {
38908+#ifdef CONFIG_GRKERNSEC_KMEM
38909+ gr_handle_mem_readwrite(from, to);
38910+#else
38911 printk(KERN_INFO
38912 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38913 current->comm, from, to);
38914+#endif
38915 return 0;
38916 }
38917 cursor += PAGE_SIZE;
38918@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38919 }
38920 return 1;
38921 }
38922+#elif defined(CONFIG_GRKERNSEC_KMEM)
38923+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38924+{
38925+ return 0;
38926+}
38927 #else
38928 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38929 {
38930@@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38931
38932 while (count > 0) {
38933 unsigned long remaining;
38934+ char *temp;
38935
38936 sz = size_inside_page(p, count);
38937
38938@@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38939 if (!ptr)
38940 return -EFAULT;
38941
38942- remaining = copy_to_user(buf, ptr, sz);
38943+#ifdef CONFIG_PAX_USERCOPY
38944+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38945+ if (!temp) {
38946+ unxlate_dev_mem_ptr(p, ptr);
38947+ return -ENOMEM;
38948+ }
38949+ memcpy(temp, ptr, sz);
38950+#else
38951+ temp = ptr;
38952+#endif
38953+
38954+ remaining = copy_to_user(buf, temp, sz);
38955+
38956+#ifdef CONFIG_PAX_USERCOPY
38957+ kfree(temp);
38958+#endif
38959+
38960 unxlate_dev_mem_ptr(p, ptr);
38961 if (remaining)
38962 return -EFAULT;
38963@@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38964 size_t count, loff_t *ppos)
38965 {
38966 unsigned long p = *ppos;
38967- ssize_t low_count, read, sz;
38968+ ssize_t low_count, read, sz, err = 0;
38969 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38970- int err = 0;
38971
38972 read = 0;
38973 if (p < (unsigned long) high_memory) {
38974@@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38975 }
38976 #endif
38977 while (low_count > 0) {
38978+ char *temp;
38979+
38980 sz = size_inside_page(p, low_count);
38981
38982 /*
38983@@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38984 */
38985 kbuf = xlate_dev_kmem_ptr((char *)p);
38986
38987- if (copy_to_user(buf, kbuf, sz))
38988+#ifdef CONFIG_PAX_USERCOPY
38989+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38990+ if (!temp)
38991+ return -ENOMEM;
38992+ memcpy(temp, kbuf, sz);
38993+#else
38994+ temp = kbuf;
38995+#endif
38996+
38997+ err = copy_to_user(buf, temp, sz);
38998+
38999+#ifdef CONFIG_PAX_USERCOPY
39000+ kfree(temp);
39001+#endif
39002+
39003+ if (err)
39004 return -EFAULT;
39005 buf += sz;
39006 p += sz;
39007@@ -821,6 +868,9 @@ static const struct memdev {
39008 #ifdef CONFIG_PRINTK
39009 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
39010 #endif
39011+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39012+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
39013+#endif
39014 };
39015
39016 static int memory_open(struct inode *inode, struct file *filp)
39017@@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
39018 continue;
39019
39020 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
39021- NULL, devlist[minor].name);
39022+ NULL, "%s", devlist[minor].name);
39023 }
39024
39025 return tty_init();
39026diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
39027index 9df78e2..01ba9ae 100644
39028--- a/drivers/char/nvram.c
39029+++ b/drivers/char/nvram.c
39030@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
39031
39032 spin_unlock_irq(&rtc_lock);
39033
39034- if (copy_to_user(buf, contents, tmp - contents))
39035+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
39036 return -EFAULT;
39037
39038 *ppos = i;
39039diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
39040index 8320abd..ec48108 100644
39041--- a/drivers/char/pcmcia/synclink_cs.c
39042+++ b/drivers/char/pcmcia/synclink_cs.c
39043@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
39044
39045 if (debug_level >= DEBUG_LEVEL_INFO)
39046 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
39047- __FILE__, __LINE__, info->device_name, port->count);
39048+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
39049
39050- WARN_ON(!port->count);
39051+ WARN_ON(!atomic_read(&port->count));
39052
39053 if (tty_port_close_start(port, tty, filp) == 0)
39054 goto cleanup;
39055@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
39056 cleanup:
39057 if (debug_level >= DEBUG_LEVEL_INFO)
39058 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
39059- tty->driver->name, port->count);
39060+ tty->driver->name, atomic_read(&port->count));
39061 }
39062
39063 /* Wait until the transmitter is empty.
39064@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
39065
39066 if (debug_level >= DEBUG_LEVEL_INFO)
39067 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
39068- __FILE__, __LINE__, tty->driver->name, port->count);
39069+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
39070
39071 /* If port is closing, signal caller to try again */
39072 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
39073@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
39074 goto cleanup;
39075 }
39076 spin_lock(&port->lock);
39077- port->count++;
39078+ atomic_inc(&port->count);
39079 spin_unlock(&port->lock);
39080 spin_unlock_irqrestore(&info->netlock, flags);
39081
39082- if (port->count == 1) {
39083+ if (atomic_read(&port->count) == 1) {
39084 /* 1st open on this device, init hardware */
39085 retval = startup(info, tty);
39086 if (retval < 0)
39087@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39088 unsigned short new_crctype;
39089
39090 /* return error if TTY interface open */
39091- if (info->port.count)
39092+ if (atomic_read(&info->port.count))
39093 return -EBUSY;
39094
39095 switch (encoding)
39096@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
39097
39098 /* arbitrate between network and tty opens */
39099 spin_lock_irqsave(&info->netlock, flags);
39100- if (info->port.count != 0 || info->netcount != 0) {
39101+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39102 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39103 spin_unlock_irqrestore(&info->netlock, flags);
39104 return -EBUSY;
39105@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39106 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
39107
39108 /* return error if TTY interface open */
39109- if (info->port.count)
39110+ if (atomic_read(&info->port.count))
39111 return -EBUSY;
39112
39113 if (cmd != SIOCWANDEV)
39114diff --git a/drivers/char/random.c b/drivers/char/random.c
39115index 429b75b..a7f4145 100644
39116--- a/drivers/char/random.c
39117+++ b/drivers/char/random.c
39118@@ -270,10 +270,17 @@
39119 /*
39120 * Configuration information
39121 */
39122+#ifdef CONFIG_GRKERNSEC_RANDNET
39123+#define INPUT_POOL_SHIFT 14
39124+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
39125+#define OUTPUT_POOL_SHIFT 12
39126+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
39127+#else
39128 #define INPUT_POOL_SHIFT 12
39129 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
39130 #define OUTPUT_POOL_SHIFT 10
39131 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
39132+#endif
39133 #define SEC_XFER_SIZE 512
39134 #define EXTRACT_SIZE 10
39135
39136@@ -284,9 +291,6 @@
39137 /*
39138 * To allow fractional bits to be tracked, the entropy_count field is
39139 * denominated in units of 1/8th bits.
39140- *
39141- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
39142- * credit_entropy_bits() needs to be 64 bits wide.
39143 */
39144 #define ENTROPY_SHIFT 3
39145 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
39146@@ -361,12 +365,19 @@ static struct poolinfo {
39147 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
39148 int tap1, tap2, tap3, tap4, tap5;
39149 } poolinfo_table[] = {
39150+#ifdef CONFIG_GRKERNSEC_RANDNET
39151+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
39152+ { S(512), 411, 308, 208, 104, 1 },
39153+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
39154+ { S(128), 104, 76, 51, 25, 1 },
39155+#else
39156 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
39157 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
39158 { S(128), 104, 76, 51, 25, 1 },
39159 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
39160 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
39161 { S(32), 26, 19, 14, 7, 1 },
39162+#endif
39163 #if 0
39164 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
39165 { S(2048), 1638, 1231, 819, 411, 1 },
39166@@ -433,9 +444,9 @@ struct entropy_store {
39167 };
39168
39169 static void push_to_pool(struct work_struct *work);
39170-static __u32 input_pool_data[INPUT_POOL_WORDS];
39171-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39172-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39173+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39174+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39175+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39176
39177 static struct entropy_store input_pool = {
39178 .poolinfo = &poolinfo_table[0],
39179@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
39180 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
39181 }
39182
39183- ACCESS_ONCE(r->input_rotate) = input_rotate;
39184- ACCESS_ONCE(r->add_ptr) = i;
39185+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
39186+ ACCESS_ONCE_RW(r->add_ptr) = i;
39187 smp_wmb();
39188
39189 if (out)
39190@@ -632,7 +643,7 @@ retry:
39191 /* The +2 corresponds to the /4 in the denominator */
39192
39193 do {
39194- unsigned int anfrac = min(pnfrac, pool_size/2);
39195+ u64 anfrac = min(pnfrac, pool_size/2);
39196 unsigned int add =
39197 ((pool_size - entropy_count)*anfrac*3) >> s;
39198
39199@@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39200
39201 extract_buf(r, tmp);
39202 i = min_t(int, nbytes, EXTRACT_SIZE);
39203- if (copy_to_user(buf, tmp, i)) {
39204+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39205 ret = -EFAULT;
39206 break;
39207 }
39208@@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
39209 #include <linux/sysctl.h>
39210
39211 static int min_read_thresh = 8, min_write_thresh;
39212-static int max_read_thresh = INPUT_POOL_WORDS * 32;
39213+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
39214 static int max_write_thresh = INPUT_POOL_WORDS * 32;
39215 static char sysctl_bootid[16];
39216
39217@@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
39218 static int proc_do_uuid(struct ctl_table *table, int write,
39219 void __user *buffer, size_t *lenp, loff_t *ppos)
39220 {
39221- struct ctl_table fake_table;
39222+ ctl_table_no_const fake_table;
39223 unsigned char buf[64], tmp_uuid[16], *uuid;
39224
39225 uuid = table->data;
39226@@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39227 static int proc_do_entropy(ctl_table *table, int write,
39228 void __user *buffer, size_t *lenp, loff_t *ppos)
39229 {
39230- ctl_table fake_table;
39231+ ctl_table_no_const fake_table;
39232 int entropy_count;
39233
39234 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39235diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39236index 7cc1fe22..b602d6b 100644
39237--- a/drivers/char/sonypi.c
39238+++ b/drivers/char/sonypi.c
39239@@ -54,6 +54,7 @@
39240
39241 #include <asm/uaccess.h>
39242 #include <asm/io.h>
39243+#include <asm/local.h>
39244
39245 #include <linux/sonypi.h>
39246
39247@@ -490,7 +491,7 @@ static struct sonypi_device {
39248 spinlock_t fifo_lock;
39249 wait_queue_head_t fifo_proc_list;
39250 struct fasync_struct *fifo_async;
39251- int open_count;
39252+ local_t open_count;
39253 int model;
39254 struct input_dev *input_jog_dev;
39255 struct input_dev *input_key_dev;
39256@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39257 static int sonypi_misc_release(struct inode *inode, struct file *file)
39258 {
39259 mutex_lock(&sonypi_device.lock);
39260- sonypi_device.open_count--;
39261+ local_dec(&sonypi_device.open_count);
39262 mutex_unlock(&sonypi_device.lock);
39263 return 0;
39264 }
39265@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39266 {
39267 mutex_lock(&sonypi_device.lock);
39268 /* Flush input queue on first open */
39269- if (!sonypi_device.open_count)
39270+ if (!local_read(&sonypi_device.open_count))
39271 kfifo_reset(&sonypi_device.fifo);
39272- sonypi_device.open_count++;
39273+ local_inc(&sonypi_device.open_count);
39274 mutex_unlock(&sonypi_device.lock);
39275
39276 return 0;
39277diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39278index b9a57fa..5bb9e38 100644
39279--- a/drivers/char/tpm/tpm_acpi.c
39280+++ b/drivers/char/tpm/tpm_acpi.c
39281@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39282 virt = acpi_os_map_memory(start, len);
39283 if (!virt) {
39284 kfree(log->bios_event_log);
39285+ log->bios_event_log = NULL;
39286 printk("%s: ERROR - Unable to map memory\n", __func__);
39287 return -EIO;
39288 }
39289
39290- memcpy_fromio(log->bios_event_log, virt, len);
39291+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39292
39293 acpi_os_unmap_memory(virt, len);
39294 return 0;
39295diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39296index 59f7cb2..bac8b6d 100644
39297--- a/drivers/char/tpm/tpm_eventlog.c
39298+++ b/drivers/char/tpm/tpm_eventlog.c
39299@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39300 event = addr;
39301
39302 if ((event->event_type == 0 && event->event_size == 0) ||
39303- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39304+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39305 return NULL;
39306
39307 return addr;
39308@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39309 return NULL;
39310
39311 if ((event->event_type == 0 && event->event_size == 0) ||
39312- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39313+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39314 return NULL;
39315
39316 (*pos)++;
39317@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39318 int i;
39319
39320 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39321- seq_putc(m, data[i]);
39322+ if (!seq_putc(m, data[i]))
39323+ return -EFAULT;
39324
39325 return 0;
39326 }
39327diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39328index 6928d09..ff6abe8 100644
39329--- a/drivers/char/virtio_console.c
39330+++ b/drivers/char/virtio_console.c
39331@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39332 if (to_user) {
39333 ssize_t ret;
39334
39335- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39336+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39337 if (ret)
39338 return -EFAULT;
39339 } else {
39340@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39341 if (!port_has_data(port) && !port->host_connected)
39342 return 0;
39343
39344- return fill_readbuf(port, ubuf, count, true);
39345+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39346 }
39347
39348 static int wait_port_writable(struct port *port, bool nonblock)
39349diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39350index 57a078e..c17cde8 100644
39351--- a/drivers/clk/clk-composite.c
39352+++ b/drivers/clk/clk-composite.c
39353@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39354 struct clk *clk;
39355 struct clk_init_data init;
39356 struct clk_composite *composite;
39357- struct clk_ops *clk_composite_ops;
39358+ clk_ops_no_const *clk_composite_ops;
39359
39360 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39361 if (!composite) {
39362diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
39363index 5983a26..65d5f46 100644
39364--- a/drivers/clk/socfpga/clk.c
39365+++ b/drivers/clk/socfpga/clk.c
39366@@ -22,6 +22,7 @@
39367 #include <linux/clk-provider.h>
39368 #include <linux/io.h>
39369 #include <linux/of.h>
39370+#include <asm/pgtable.h>
39371
39372 /* Clock Manager offsets */
39373 #define CLKMGR_CTRL 0x0
39374@@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
39375 streq(clk_name, "periph_pll") ||
39376 streq(clk_name, "sdram_pll")) {
39377 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39378- clk_pll_ops.enable = clk_gate_ops.enable;
39379- clk_pll_ops.disable = clk_gate_ops.disable;
39380+ pax_open_kernel();
39381+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39382+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39383+ pax_close_kernel();
39384 }
39385
39386 clk = clk_register(NULL, &socfpga_clk->hw.hw);
39387@@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
39388 return parent_rate / div;
39389 }
39390
39391-static struct clk_ops gateclk_ops = {
39392+static clk_ops_no_const gateclk_ops __read_only = {
39393 .recalc_rate = socfpga_clk_recalc_rate,
39394 .get_parent = socfpga_clk_get_parent,
39395 .set_parent = socfpga_clk_set_parent,
39396diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39397index 18448a7..d5fad43 100644
39398--- a/drivers/cpufreq/acpi-cpufreq.c
39399+++ b/drivers/cpufreq/acpi-cpufreq.c
39400@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39401 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39402 per_cpu(acfreq_data, cpu) = data;
39403
39404- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39405- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39406+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39407+ pax_open_kernel();
39408+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39409+ pax_close_kernel();
39410+ }
39411
39412 result = acpi_processor_register_performance(data->acpi_data, cpu);
39413 if (result)
39414@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39415 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39416 break;
39417 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39418- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39419+ pax_open_kernel();
39420+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39421+ pax_close_kernel();
39422 break;
39423 default:
39424 break;
39425@@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
39426 if (!msrs)
39427 return;
39428
39429- acpi_cpufreq_driver.boost_supported = true;
39430- acpi_cpufreq_driver.boost_enabled = boost_state(0);
39431+ pax_open_kernel();
39432+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39433+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39434+ pax_close_kernel();
39435 get_online_cpus();
39436
39437 /* Force all MSRs to the same value */
39438diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39439index 199b52b..e3503bb 100644
39440--- a/drivers/cpufreq/cpufreq.c
39441+++ b/drivers/cpufreq/cpufreq.c
39442@@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39443 #endif
39444
39445 mutex_lock(&cpufreq_governor_mutex);
39446- list_del(&governor->governor_list);
39447+ pax_list_del(&governor->governor_list);
39448 mutex_unlock(&cpufreq_governor_mutex);
39449 return;
39450 }
39451@@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39452 return NOTIFY_OK;
39453 }
39454
39455-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39456+static struct notifier_block cpufreq_cpu_notifier = {
39457 .notifier_call = cpufreq_cpu_callback,
39458 };
39459
39460@@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
39461 return 0;
39462
39463 write_lock_irqsave(&cpufreq_driver_lock, flags);
39464- cpufreq_driver->boost_enabled = state;
39465+ pax_open_kernel();
39466+ *(bool *)&cpufreq_driver->boost_enabled = state;
39467+ pax_close_kernel();
39468 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39469
39470 ret = cpufreq_driver->set_boost(state);
39471 if (ret) {
39472 write_lock_irqsave(&cpufreq_driver_lock, flags);
39473- cpufreq_driver->boost_enabled = !state;
39474+ pax_open_kernel();
39475+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39476+ pax_close_kernel();
39477 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39478
39479 pr_err("%s: Cannot %s BOOST\n", __func__,
39480@@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39481
39482 pr_debug("trying to register driver %s\n", driver_data->name);
39483
39484- if (driver_data->setpolicy)
39485- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39486+ if (driver_data->setpolicy) {
39487+ pax_open_kernel();
39488+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39489+ pax_close_kernel();
39490+ }
39491
39492 write_lock_irqsave(&cpufreq_driver_lock, flags);
39493 if (cpufreq_driver) {
39494@@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39495 * Check if driver provides function to enable boost -
39496 * if not, use cpufreq_boost_set_sw as default
39497 */
39498- if (!cpufreq_driver->set_boost)
39499- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39500+ if (!cpufreq_driver->set_boost) {
39501+ pax_open_kernel();
39502+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39503+ pax_close_kernel();
39504+ }
39505
39506 ret = cpufreq_sysfs_create_file(&boost.attr);
39507 if (ret) {
39508diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39509index e1c6433..31203ae 100644
39510--- a/drivers/cpufreq/cpufreq_governor.c
39511+++ b/drivers/cpufreq/cpufreq_governor.c
39512@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39513 struct dbs_data *dbs_data;
39514 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39515 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39516- struct od_ops *od_ops = NULL;
39517+ const struct od_ops *od_ops = NULL;
39518 struct od_dbs_tuners *od_tuners = NULL;
39519 struct cs_dbs_tuners *cs_tuners = NULL;
39520 struct cpu_dbs_common_info *cpu_cdbs;
39521@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39522
39523 if ((cdata->governor == GOV_CONSERVATIVE) &&
39524 (!policy->governor->initialized)) {
39525- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39526+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39527
39528 cpufreq_register_notifier(cs_ops->notifier_block,
39529 CPUFREQ_TRANSITION_NOTIFIER);
39530@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39531
39532 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39533 (policy->governor->initialized == 1)) {
39534- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39535+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39536
39537 cpufreq_unregister_notifier(cs_ops->notifier_block,
39538 CPUFREQ_TRANSITION_NOTIFIER);
39539diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39540index bfb9ae1..e1d3a7e 100644
39541--- a/drivers/cpufreq/cpufreq_governor.h
39542+++ b/drivers/cpufreq/cpufreq_governor.h
39543@@ -205,7 +205,7 @@ struct common_dbs_data {
39544 void (*exit)(struct dbs_data *dbs_data);
39545
39546 /* Governor specific ops, see below */
39547- void *gov_ops;
39548+ const void *gov_ops;
39549 };
39550
39551 /* Governor Per policy data */
39552@@ -225,7 +225,7 @@ struct od_ops {
39553 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39554 unsigned int freq_next, unsigned int relation);
39555 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39556-};
39557+} __no_const;
39558
39559 struct cs_ops {
39560 struct notifier_block *notifier_block;
39561diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39562index 18d4091..434be15 100644
39563--- a/drivers/cpufreq/cpufreq_ondemand.c
39564+++ b/drivers/cpufreq/cpufreq_ondemand.c
39565@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39566
39567 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39568
39569-static struct od_ops od_ops = {
39570+static struct od_ops od_ops __read_only = {
39571 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39572 .powersave_bias_target = generic_powersave_bias_target,
39573 .freq_increase = dbs_freq_increase,
39574@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39575 (struct cpufreq_policy *, unsigned int, unsigned int),
39576 unsigned int powersave_bias)
39577 {
39578- od_ops.powersave_bias_target = f;
39579+ pax_open_kernel();
39580+ *(void **)&od_ops.powersave_bias_target = f;
39581+ pax_close_kernel();
39582 od_set_powersave_bias(powersave_bias);
39583 }
39584 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39585
39586 void od_unregister_powersave_bias_handler(void)
39587 {
39588- od_ops.powersave_bias_target = generic_powersave_bias_target;
39589+ pax_open_kernel();
39590+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39591+ pax_close_kernel();
39592 od_set_powersave_bias(0);
39593 }
39594 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39595diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39596index de9ef4a..0b29fc9 100644
39597--- a/drivers/cpufreq/intel_pstate.c
39598+++ b/drivers/cpufreq/intel_pstate.c
39599@@ -125,10 +125,10 @@ struct pstate_funcs {
39600 struct cpu_defaults {
39601 struct pstate_adjust_policy pid_policy;
39602 struct pstate_funcs funcs;
39603-};
39604+} __do_const;
39605
39606 static struct pstate_adjust_policy pid_params;
39607-static struct pstate_funcs pstate_funcs;
39608+static struct pstate_funcs *pstate_funcs;
39609
39610 struct perf_limits {
39611 int no_turbo;
39612@@ -529,7 +529,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39613
39614 cpu->pstate.current_pstate = pstate;
39615
39616- pstate_funcs.set(cpu, pstate);
39617+ pstate_funcs->set(cpu, pstate);
39618 }
39619
39620 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39621@@ -551,12 +551,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39622 {
39623 sprintf(cpu->name, "Intel 2nd generation core");
39624
39625- cpu->pstate.min_pstate = pstate_funcs.get_min();
39626- cpu->pstate.max_pstate = pstate_funcs.get_max();
39627- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39628+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39629+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39630+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39631
39632- if (pstate_funcs.get_vid)
39633- pstate_funcs.get_vid(cpu);
39634+ if (pstate_funcs->get_vid)
39635+ pstate_funcs->get_vid(cpu);
39636 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39637 }
39638
39639@@ -838,9 +838,9 @@ static int intel_pstate_msrs_not_valid(void)
39640 rdmsrl(MSR_IA32_APERF, aperf);
39641 rdmsrl(MSR_IA32_MPERF, mperf);
39642
39643- if (!pstate_funcs.get_max() ||
39644- !pstate_funcs.get_min() ||
39645- !pstate_funcs.get_turbo())
39646+ if (!pstate_funcs->get_max() ||
39647+ !pstate_funcs->get_min() ||
39648+ !pstate_funcs->get_turbo())
39649 return -ENODEV;
39650
39651 rdmsrl(MSR_IA32_APERF, tmp);
39652@@ -854,7 +854,7 @@ static int intel_pstate_msrs_not_valid(void)
39653 return 0;
39654 }
39655
39656-static void copy_pid_params(struct pstate_adjust_policy *policy)
39657+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39658 {
39659 pid_params.sample_rate_ms = policy->sample_rate_ms;
39660 pid_params.p_gain_pct = policy->p_gain_pct;
39661@@ -866,11 +866,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39662
39663 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39664 {
39665- pstate_funcs.get_max = funcs->get_max;
39666- pstate_funcs.get_min = funcs->get_min;
39667- pstate_funcs.get_turbo = funcs->get_turbo;
39668- pstate_funcs.set = funcs->set;
39669- pstate_funcs.get_vid = funcs->get_vid;
39670+ pstate_funcs = funcs;
39671 }
39672
39673 #if IS_ENABLED(CONFIG_ACPI)
39674diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39675index 3d1cba9..0ab21d2 100644
39676--- a/drivers/cpufreq/p4-clockmod.c
39677+++ b/drivers/cpufreq/p4-clockmod.c
39678@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39679 case 0x0F: /* Core Duo */
39680 case 0x16: /* Celeron Core */
39681 case 0x1C: /* Atom */
39682- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39683+ pax_open_kernel();
39684+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39685+ pax_close_kernel();
39686 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39687 case 0x0D: /* Pentium M (Dothan) */
39688- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39689+ pax_open_kernel();
39690+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39691+ pax_close_kernel();
39692 /* fall through */
39693 case 0x09: /* Pentium M (Banias) */
39694 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39695@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39696
39697 /* on P-4s, the TSC runs with constant frequency independent whether
39698 * throttling is active or not. */
39699- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39700+ pax_open_kernel();
39701+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39702+ pax_close_kernel();
39703
39704 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39705 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39706diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39707index 724ffbd..f06aaaa 100644
39708--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39709+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39710@@ -18,14 +18,12 @@
39711 #include <asm/head.h>
39712 #include <asm/timer.h>
39713
39714-static struct cpufreq_driver *cpufreq_us3_driver;
39715-
39716 struct us3_freq_percpu_info {
39717 struct cpufreq_frequency_table table[4];
39718 };
39719
39720 /* Indexed by cpu number. */
39721-static struct us3_freq_percpu_info *us3_freq_table;
39722+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39723
39724 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39725 * in the Safari config register.
39726@@ -156,18 +154,28 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39727
39728 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39729 {
39730- if (cpufreq_us3_driver) {
39731- cpufreq_frequency_table_put_attr(policy->cpu);
39732- us3_freq_target(policy, 0);
39733- }
39734+ cpufreq_frequency_table_put_attr(policy->cpu);
39735+ us3_freq_target(policy, 0);
39736
39737 return 0;
39738 }
39739
39740+static int __init us3_freq_init(void);
39741+static void __exit us3_freq_exit(void);
39742+
39743+static struct cpufreq_driver cpufreq_us3_driver = {
39744+ .init = us3_freq_cpu_init,
39745+ .verify = cpufreq_generic_frequency_table_verify,
39746+ .target_index = us3_freq_target,
39747+ .get = us3_freq_get,
39748+ .exit = us3_freq_cpu_exit,
39749+ .name = "UltraSPARC-III",
39750+
39751+};
39752+
39753 static int __init us3_freq_init(void)
39754 {
39755 unsigned long manuf, impl, ver;
39756- int ret;
39757
39758 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39759 return -ENODEV;
39760@@ -180,55 +188,15 @@ static int __init us3_freq_init(void)
39761 (impl == CHEETAH_IMPL ||
39762 impl == CHEETAH_PLUS_IMPL ||
39763 impl == JAGUAR_IMPL ||
39764- impl == PANTHER_IMPL)) {
39765- struct cpufreq_driver *driver;
39766-
39767- ret = -ENOMEM;
39768- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39769- if (!driver)
39770- goto err_out;
39771-
39772- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39773- GFP_KERNEL);
39774- if (!us3_freq_table)
39775- goto err_out;
39776-
39777- driver->init = us3_freq_cpu_init;
39778- driver->verify = cpufreq_generic_frequency_table_verify;
39779- driver->target_index = us3_freq_target;
39780- driver->get = us3_freq_get;
39781- driver->exit = us3_freq_cpu_exit;
39782- strcpy(driver->name, "UltraSPARC-III");
39783-
39784- cpufreq_us3_driver = driver;
39785- ret = cpufreq_register_driver(driver);
39786- if (ret)
39787- goto err_out;
39788-
39789- return 0;
39790-
39791-err_out:
39792- if (driver) {
39793- kfree(driver);
39794- cpufreq_us3_driver = NULL;
39795- }
39796- kfree(us3_freq_table);
39797- us3_freq_table = NULL;
39798- return ret;
39799- }
39800+ impl == PANTHER_IMPL))
39801+ return cpufreq_register_driver(&cpufreq_us3_driver);
39802
39803 return -ENODEV;
39804 }
39805
39806 static void __exit us3_freq_exit(void)
39807 {
39808- if (cpufreq_us3_driver) {
39809- cpufreq_unregister_driver(cpufreq_us3_driver);
39810- kfree(cpufreq_us3_driver);
39811- cpufreq_us3_driver = NULL;
39812- kfree(us3_freq_table);
39813- us3_freq_table = NULL;
39814- }
39815+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39816 }
39817
39818 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39819diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39820index 4e1daca..e707b61 100644
39821--- a/drivers/cpufreq/speedstep-centrino.c
39822+++ b/drivers/cpufreq/speedstep-centrino.c
39823@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39824 !cpu_has(cpu, X86_FEATURE_EST))
39825 return -ENODEV;
39826
39827- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39828- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39829+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39830+ pax_open_kernel();
39831+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39832+ pax_close_kernel();
39833+ }
39834
39835 if (policy->cpu != 0)
39836 return -ENODEV;
39837diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39838index 06dbe7c..c2c8671 100644
39839--- a/drivers/cpuidle/driver.c
39840+++ b/drivers/cpuidle/driver.c
39841@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39842
39843 static void poll_idle_init(struct cpuidle_driver *drv)
39844 {
39845- struct cpuidle_state *state = &drv->states[0];
39846+ cpuidle_state_no_const *state = &drv->states[0];
39847
39848 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39849 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39850diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39851index ca89412..a7b9c49 100644
39852--- a/drivers/cpuidle/governor.c
39853+++ b/drivers/cpuidle/governor.c
39854@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39855 mutex_lock(&cpuidle_lock);
39856 if (__cpuidle_find_governor(gov->name) == NULL) {
39857 ret = 0;
39858- list_add_tail(&gov->governor_list, &cpuidle_governors);
39859+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39860 if (!cpuidle_curr_governor ||
39861 cpuidle_curr_governor->rating < gov->rating)
39862 cpuidle_switch_governor(gov);
39863diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39864index e918b6d..f87ea80 100644
39865--- a/drivers/cpuidle/sysfs.c
39866+++ b/drivers/cpuidle/sysfs.c
39867@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39868 NULL
39869 };
39870
39871-static struct attribute_group cpuidle_attr_group = {
39872+static attribute_group_no_const cpuidle_attr_group = {
39873 .attrs = cpuidle_default_attrs,
39874 .name = "cpuidle",
39875 };
39876diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39877index 12fea3e..1e28f47 100644
39878--- a/drivers/crypto/hifn_795x.c
39879+++ b/drivers/crypto/hifn_795x.c
39880@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39881 MODULE_PARM_DESC(hifn_pll_ref,
39882 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39883
39884-static atomic_t hifn_dev_number;
39885+static atomic_unchecked_t hifn_dev_number;
39886
39887 #define ACRYPTO_OP_DECRYPT 0
39888 #define ACRYPTO_OP_ENCRYPT 1
39889@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39890 goto err_out_disable_pci_device;
39891
39892 snprintf(name, sizeof(name), "hifn%d",
39893- atomic_inc_return(&hifn_dev_number)-1);
39894+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39895
39896 err = pci_request_regions(pdev, name);
39897 if (err)
39898diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39899index a0b2f7e..1b6f028 100644
39900--- a/drivers/devfreq/devfreq.c
39901+++ b/drivers/devfreq/devfreq.c
39902@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39903 goto err_out;
39904 }
39905
39906- list_add(&governor->node, &devfreq_governor_list);
39907+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39908
39909 list_for_each_entry(devfreq, &devfreq_list, node) {
39910 int ret = 0;
39911@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39912 }
39913 }
39914
39915- list_del(&governor->node);
39916+ pax_list_del((struct list_head *)&governor->node);
39917 err_out:
39918 mutex_unlock(&devfreq_list_lock);
39919
39920diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39921index 2e7b394..1371a64 100644
39922--- a/drivers/dma/sh/shdma-base.c
39923+++ b/drivers/dma/sh/shdma-base.c
39924@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39925 schan->slave_id = -EINVAL;
39926 }
39927
39928- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39929- sdev->desc_size, GFP_KERNEL);
39930+ schan->desc = kcalloc(sdev->desc_size,
39931+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39932 if (!schan->desc) {
39933 ret = -ENOMEM;
39934 goto edescalloc;
39935diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39936index 0d765c0..60b7480 100644
39937--- a/drivers/dma/sh/shdmac.c
39938+++ b/drivers/dma/sh/shdmac.c
39939@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39940 return ret;
39941 }
39942
39943-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39944+static struct notifier_block sh_dmae_nmi_notifier = {
39945 .notifier_call = sh_dmae_nmi_handler,
39946
39947 /* Run before NMI debug handler and KGDB */
39948diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39949index 592af5f..bb1d583 100644
39950--- a/drivers/edac/edac_device.c
39951+++ b/drivers/edac/edac_device.c
39952@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39953 */
39954 int edac_device_alloc_index(void)
39955 {
39956- static atomic_t device_indexes = ATOMIC_INIT(0);
39957+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39958
39959- return atomic_inc_return(&device_indexes) - 1;
39960+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39961 }
39962 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39963
39964diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39965index b335c6a..db65b44 100644
39966--- a/drivers/edac/edac_mc_sysfs.c
39967+++ b/drivers/edac/edac_mc_sysfs.c
39968@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39969 struct dev_ch_attribute {
39970 struct device_attribute attr;
39971 int channel;
39972-};
39973+} __do_const;
39974
39975 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39976 struct dev_ch_attribute dev_attr_legacy_##_name = \
39977@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39978 }
39979
39980 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39981+ pax_open_kernel();
39982 if (mci->get_sdram_scrub_rate) {
39983- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39984- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39985+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39986+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39987 }
39988 if (mci->set_sdram_scrub_rate) {
39989- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39990- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39991+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39992+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39993 }
39994+ pax_close_kernel();
39995 err = device_create_file(&mci->dev,
39996 &dev_attr_sdram_scrub_rate);
39997 if (err) {
39998diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39999index 2cf44b4d..6dd2dc7 100644
40000--- a/drivers/edac/edac_pci.c
40001+++ b/drivers/edac/edac_pci.c
40002@@ -29,7 +29,7 @@
40003
40004 static DEFINE_MUTEX(edac_pci_ctls_mutex);
40005 static LIST_HEAD(edac_pci_list);
40006-static atomic_t pci_indexes = ATOMIC_INIT(0);
40007+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
40008
40009 /*
40010 * edac_pci_alloc_ctl_info
40011@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
40012 */
40013 int edac_pci_alloc_index(void)
40014 {
40015- return atomic_inc_return(&pci_indexes) - 1;
40016+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
40017 }
40018 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
40019
40020diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
40021index e8658e4..22746d6 100644
40022--- a/drivers/edac/edac_pci_sysfs.c
40023+++ b/drivers/edac/edac_pci_sysfs.c
40024@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
40025 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
40026 static int edac_pci_poll_msec = 1000; /* one second workq period */
40027
40028-static atomic_t pci_parity_count = ATOMIC_INIT(0);
40029-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
40030+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
40031+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
40032
40033 static struct kobject *edac_pci_top_main_kobj;
40034 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
40035@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
40036 void *value;
40037 ssize_t(*show) (void *, char *);
40038 ssize_t(*store) (void *, const char *, size_t);
40039-};
40040+} __do_const;
40041
40042 /* Set of show/store abstract level functions for PCI Parity object */
40043 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
40044@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40045 edac_printk(KERN_CRIT, EDAC_PCI,
40046 "Signaled System Error on %s\n",
40047 pci_name(dev));
40048- atomic_inc(&pci_nonparity_count);
40049+ atomic_inc_unchecked(&pci_nonparity_count);
40050 }
40051
40052 if (status & (PCI_STATUS_PARITY)) {
40053@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40054 "Master Data Parity Error on %s\n",
40055 pci_name(dev));
40056
40057- atomic_inc(&pci_parity_count);
40058+ atomic_inc_unchecked(&pci_parity_count);
40059 }
40060
40061 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40062@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40063 "Detected Parity Error on %s\n",
40064 pci_name(dev));
40065
40066- atomic_inc(&pci_parity_count);
40067+ atomic_inc_unchecked(&pci_parity_count);
40068 }
40069 }
40070
40071@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40072 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
40073 "Signaled System Error on %s\n",
40074 pci_name(dev));
40075- atomic_inc(&pci_nonparity_count);
40076+ atomic_inc_unchecked(&pci_nonparity_count);
40077 }
40078
40079 if (status & (PCI_STATUS_PARITY)) {
40080@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40081 "Master Data Parity Error on "
40082 "%s\n", pci_name(dev));
40083
40084- atomic_inc(&pci_parity_count);
40085+ atomic_inc_unchecked(&pci_parity_count);
40086 }
40087
40088 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40089@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40090 "Detected Parity Error on %s\n",
40091 pci_name(dev));
40092
40093- atomic_inc(&pci_parity_count);
40094+ atomic_inc_unchecked(&pci_parity_count);
40095 }
40096 }
40097 }
40098@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
40099 if (!check_pci_errors)
40100 return;
40101
40102- before_count = atomic_read(&pci_parity_count);
40103+ before_count = atomic_read_unchecked(&pci_parity_count);
40104
40105 /* scan all PCI devices looking for a Parity Error on devices and
40106 * bridges.
40107@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
40108 /* Only if operator has selected panic on PCI Error */
40109 if (edac_pci_get_panic_on_pe()) {
40110 /* If the count is different 'after' from 'before' */
40111- if (before_count != atomic_read(&pci_parity_count))
40112+ if (before_count != atomic_read_unchecked(&pci_parity_count))
40113 panic("EDAC: PCI Parity Error");
40114 }
40115 }
40116diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
40117index 51b7e3a..aa8a3e8 100644
40118--- a/drivers/edac/mce_amd.h
40119+++ b/drivers/edac/mce_amd.h
40120@@ -77,7 +77,7 @@ struct amd_decoder_ops {
40121 bool (*mc0_mce)(u16, u8);
40122 bool (*mc1_mce)(u16, u8);
40123 bool (*mc2_mce)(u16, u8);
40124-};
40125+} __no_const;
40126
40127 void amd_report_gart_errors(bool);
40128 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
40129diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
40130index 57ea7f4..af06b76 100644
40131--- a/drivers/firewire/core-card.c
40132+++ b/drivers/firewire/core-card.c
40133@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
40134 const struct fw_card_driver *driver,
40135 struct device *device)
40136 {
40137- static atomic_t index = ATOMIC_INIT(-1);
40138+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
40139
40140- card->index = atomic_inc_return(&index);
40141+ card->index = atomic_inc_return_unchecked(&index);
40142 card->driver = driver;
40143 card->device = device;
40144 card->current_tlabel = 0;
40145@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40146
40147 void fw_core_remove_card(struct fw_card *card)
40148 {
40149- struct fw_card_driver dummy_driver = dummy_driver_template;
40150+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
40151
40152 card->driver->update_phy_reg(card, 4,
40153 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40154diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40155index 2c6d5e1..a2cca6b 100644
40156--- a/drivers/firewire/core-device.c
40157+++ b/drivers/firewire/core-device.c
40158@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40159 struct config_rom_attribute {
40160 struct device_attribute attr;
40161 u32 key;
40162-};
40163+} __do_const;
40164
40165 static ssize_t show_immediate(struct device *dev,
40166 struct device_attribute *dattr, char *buf)
40167diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40168index eb6935c..3cc2bfa 100644
40169--- a/drivers/firewire/core-transaction.c
40170+++ b/drivers/firewire/core-transaction.c
40171@@ -38,6 +38,7 @@
40172 #include <linux/timer.h>
40173 #include <linux/types.h>
40174 #include <linux/workqueue.h>
40175+#include <linux/sched.h>
40176
40177 #include <asm/byteorder.h>
40178
40179diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40180index f477308..2795f24 100644
40181--- a/drivers/firewire/core.h
40182+++ b/drivers/firewire/core.h
40183@@ -111,6 +111,7 @@ struct fw_card_driver {
40184
40185 int (*stop_iso)(struct fw_iso_context *ctx);
40186 };
40187+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40188
40189 void fw_card_initialize(struct fw_card *card,
40190 const struct fw_card_driver *driver, struct device *device);
40191diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40192index 586f2f7..3545ad2 100644
40193--- a/drivers/firewire/ohci.c
40194+++ b/drivers/firewire/ohci.c
40195@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
40196 be32_to_cpu(ohci->next_header));
40197 }
40198
40199+#ifndef CONFIG_GRKERNSEC
40200 if (param_remote_dma) {
40201 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40202 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40203 }
40204+#endif
40205
40206 spin_unlock_irq(&ohci->lock);
40207
40208@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40209 unsigned long flags;
40210 int n, ret = 0;
40211
40212+#ifndef CONFIG_GRKERNSEC
40213 if (param_remote_dma)
40214 return 0;
40215+#endif
40216
40217 /*
40218 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40219diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40220index 94a58a0..f5eba42 100644
40221--- a/drivers/firmware/dmi-id.c
40222+++ b/drivers/firmware/dmi-id.c
40223@@ -16,7 +16,7 @@
40224 struct dmi_device_attribute{
40225 struct device_attribute dev_attr;
40226 int field;
40227-};
40228+} __do_const;
40229 #define to_dmi_dev_attr(_dev_attr) \
40230 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40231
40232diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40233index 17afc51..0ef90cd 100644
40234--- a/drivers/firmware/dmi_scan.c
40235+++ b/drivers/firmware/dmi_scan.c
40236@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40237 if (buf == NULL)
40238 return -1;
40239
40240- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40241+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40242
40243 dmi_unmap(buf);
40244 return 0;
40245diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40246index 1491dd4..aa910db 100644
40247--- a/drivers/firmware/efi/cper.c
40248+++ b/drivers/firmware/efi/cper.c
40249@@ -41,12 +41,12 @@
40250 */
40251 u64 cper_next_record_id(void)
40252 {
40253- static atomic64_t seq;
40254+ static atomic64_unchecked_t seq;
40255
40256- if (!atomic64_read(&seq))
40257- atomic64_set(&seq, ((u64)get_seconds()) << 32);
40258+ if (!atomic64_read_unchecked(&seq))
40259+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40260
40261- return atomic64_inc_return(&seq);
40262+ return atomic64_inc_return_unchecked(&seq);
40263 }
40264 EXPORT_SYMBOL_GPL(cper_next_record_id);
40265
40266diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40267index 4753bac..02861a2 100644
40268--- a/drivers/firmware/efi/efi.c
40269+++ b/drivers/firmware/efi/efi.c
40270@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
40271 };
40272
40273 static struct efivars generic_efivars;
40274-static struct efivar_operations generic_ops;
40275+static efivar_operations_no_const generic_ops __read_only;
40276
40277 static int generic_ops_register(void)
40278 {
40279- generic_ops.get_variable = efi.get_variable;
40280- generic_ops.set_variable = efi.set_variable;
40281- generic_ops.get_next_variable = efi.get_next_variable;
40282- generic_ops.query_variable_store = efi_query_variable_store;
40283+ pax_open_kernel();
40284+ *(void **)&generic_ops.get_variable = efi.get_variable;
40285+ *(void **)&generic_ops.set_variable = efi.set_variable;
40286+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40287+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40288+ pax_close_kernel();
40289
40290 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40291 }
40292diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40293index 3dc2482..7bd2f61 100644
40294--- a/drivers/firmware/efi/efivars.c
40295+++ b/drivers/firmware/efi/efivars.c
40296@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40297 static int
40298 create_efivars_bin_attributes(void)
40299 {
40300- struct bin_attribute *attr;
40301+ bin_attribute_no_const *attr;
40302 int error;
40303
40304 /* new_var */
40305diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40306index 2a90ba6..07f3733 100644
40307--- a/drivers/firmware/google/memconsole.c
40308+++ b/drivers/firmware/google/memconsole.c
40309@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
40310 if (!found_memconsole())
40311 return -ENODEV;
40312
40313- memconsole_bin_attr.size = memconsole_length;
40314+ pax_open_kernel();
40315+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40316+ pax_close_kernel();
40317
40318 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40319
40320diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40321index 1e98a98..b444372 100644
40322--- a/drivers/gpio/gpio-em.c
40323+++ b/drivers/gpio/gpio-em.c
40324@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40325 struct em_gio_priv *p;
40326 struct resource *io[2], *irq[2];
40327 struct gpio_chip *gpio_chip;
40328- struct irq_chip *irq_chip;
40329+ irq_chip_no_const *irq_chip;
40330 const char *name = dev_name(&pdev->dev);
40331 int ret;
40332
40333diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40334index f5bf3c3..7baaa59 100644
40335--- a/drivers/gpio/gpio-ich.c
40336+++ b/drivers/gpio/gpio-ich.c
40337@@ -71,7 +71,7 @@ struct ichx_desc {
40338 /* Some chipsets have quirks, let these use their own request/get */
40339 int (*request)(struct gpio_chip *chip, unsigned offset);
40340 int (*get)(struct gpio_chip *chip, unsigned offset);
40341-};
40342+} __do_const;
40343
40344 static struct {
40345 spinlock_t lock;
40346diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40347index ca76ce7..68b384b 100644
40348--- a/drivers/gpio/gpio-rcar.c
40349+++ b/drivers/gpio/gpio-rcar.c
40350@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40351 struct gpio_rcar_priv *p;
40352 struct resource *io, *irq;
40353 struct gpio_chip *gpio_chip;
40354- struct irq_chip *irq_chip;
40355+ irq_chip_no_const *irq_chip;
40356 const char *name = dev_name(&pdev->dev);
40357 int ret;
40358
40359diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40360index 9902732..64b62dd 100644
40361--- a/drivers/gpio/gpio-vr41xx.c
40362+++ b/drivers/gpio/gpio-vr41xx.c
40363@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
40364 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40365 maskl, pendl, maskh, pendh);
40366
40367- atomic_inc(&irq_err_count);
40368+ atomic_inc_unchecked(&irq_err_count);
40369
40370 return -EINVAL;
40371 }
40372diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40373index 3b7d32d..05c2f74 100644
40374--- a/drivers/gpu/drm/drm_crtc.c
40375+++ b/drivers/gpu/drm/drm_crtc.c
40376@@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40377 goto done;
40378 }
40379
40380- if (copy_to_user(&enum_ptr[copied].name,
40381+ if (copy_to_user(enum_ptr[copied].name,
40382 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40383 ret = -EFAULT;
40384 goto done;
40385diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40386index 345be03..158368d 100644
40387--- a/drivers/gpu/drm/drm_drv.c
40388+++ b/drivers/gpu/drm/drm_drv.c
40389@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
40390 /**
40391 * Copy and IOCTL return string to user space
40392 */
40393-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
40394+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
40395 {
40396 int len;
40397
40398@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
40399 struct drm_file *file_priv = filp->private_data;
40400 struct drm_device *dev;
40401 const struct drm_ioctl_desc *ioctl = NULL;
40402- drm_ioctl_t *func;
40403+ drm_ioctl_no_const_t func;
40404 unsigned int nr = DRM_IOCTL_NR(cmd);
40405 int retcode = -EINVAL;
40406 char stack_kdata[128];
40407diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40408index 7f2af9a..1561914 100644
40409--- a/drivers/gpu/drm/drm_fops.c
40410+++ b/drivers/gpu/drm/drm_fops.c
40411@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
40412 if (drm_device_is_unplugged(dev))
40413 return -ENODEV;
40414
40415- if (!dev->open_count++)
40416+ if (local_inc_return(&dev->open_count) == 1)
40417 need_setup = 1;
40418 mutex_lock(&dev->struct_mutex);
40419 old_imapping = inode->i_mapping;
40420@@ -127,7 +127,7 @@ err_undo:
40421 iput(container_of(dev->dev_mapping, struct inode, i_data));
40422 dev->dev_mapping = old_mapping;
40423 mutex_unlock(&dev->struct_mutex);
40424- dev->open_count--;
40425+ local_dec(&dev->open_count);
40426 return retcode;
40427 }
40428 EXPORT_SYMBOL(drm_open);
40429@@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
40430
40431 mutex_lock(&drm_global_mutex);
40432
40433- DRM_DEBUG("open_count = %d\n", dev->open_count);
40434+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40435
40436 if (dev->driver->preclose)
40437 dev->driver->preclose(dev, file_priv);
40438@@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
40439 * Begin inline drm_release
40440 */
40441
40442- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40443+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40444 task_pid_nr(current),
40445 (long)old_encode_dev(file_priv->minor->device),
40446- dev->open_count);
40447+ local_read(&dev->open_count));
40448
40449 /* Release any auth tokens that might point to this file_priv,
40450 (do that under the drm_global_mutex) */
40451@@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
40452 * End inline drm_release
40453 */
40454
40455- if (!--dev->open_count) {
40456+ if (local_dec_and_test(&dev->open_count)) {
40457 retcode = drm_lastclose(dev);
40458 if (drm_device_is_unplugged(dev))
40459 drm_put_dev(dev);
40460diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40461index 3d2e91c..d31c4c9 100644
40462--- a/drivers/gpu/drm/drm_global.c
40463+++ b/drivers/gpu/drm/drm_global.c
40464@@ -36,7 +36,7 @@
40465 struct drm_global_item {
40466 struct mutex mutex;
40467 void *object;
40468- int refcount;
40469+ atomic_t refcount;
40470 };
40471
40472 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40473@@ -49,7 +49,7 @@ void drm_global_init(void)
40474 struct drm_global_item *item = &glob[i];
40475 mutex_init(&item->mutex);
40476 item->object = NULL;
40477- item->refcount = 0;
40478+ atomic_set(&item->refcount, 0);
40479 }
40480 }
40481
40482@@ -59,7 +59,7 @@ void drm_global_release(void)
40483 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40484 struct drm_global_item *item = &glob[i];
40485 BUG_ON(item->object != NULL);
40486- BUG_ON(item->refcount != 0);
40487+ BUG_ON(atomic_read(&item->refcount) != 0);
40488 }
40489 }
40490
40491@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40492 struct drm_global_item *item = &glob[ref->global_type];
40493
40494 mutex_lock(&item->mutex);
40495- if (item->refcount == 0) {
40496+ if (atomic_read(&item->refcount) == 0) {
40497 item->object = kzalloc(ref->size, GFP_KERNEL);
40498 if (unlikely(item->object == NULL)) {
40499 ret = -ENOMEM;
40500@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40501 goto out_err;
40502
40503 }
40504- ++item->refcount;
40505+ atomic_inc(&item->refcount);
40506 ref->object = item->object;
40507 mutex_unlock(&item->mutex);
40508 return 0;
40509@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40510 struct drm_global_item *item = &glob[ref->global_type];
40511
40512 mutex_lock(&item->mutex);
40513- BUG_ON(item->refcount == 0);
40514+ BUG_ON(atomic_read(&item->refcount) == 0);
40515 BUG_ON(ref->object != item->object);
40516- if (--item->refcount == 0) {
40517+ if (atomic_dec_and_test(&item->refcount)) {
40518 ref->release(ref);
40519 item->object = NULL;
40520 }
40521diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40522index 7473035..a48b9c5 100644
40523--- a/drivers/gpu/drm/drm_info.c
40524+++ b/drivers/gpu/drm/drm_info.c
40525@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40526 struct drm_local_map *map;
40527 struct drm_map_list *r_list;
40528
40529- /* Hardcoded from _DRM_FRAME_BUFFER,
40530- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40531- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40532- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40533+ static const char * const types[] = {
40534+ [_DRM_FRAME_BUFFER] = "FB",
40535+ [_DRM_REGISTERS] = "REG",
40536+ [_DRM_SHM] = "SHM",
40537+ [_DRM_AGP] = "AGP",
40538+ [_DRM_SCATTER_GATHER] = "SG",
40539+ [_DRM_CONSISTENT] = "PCI"};
40540 const char *type;
40541 int i;
40542
40543@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40544 map = r_list->map;
40545 if (!map)
40546 continue;
40547- if (map->type < 0 || map->type > 5)
40548+ if (map->type >= ARRAY_SIZE(types))
40549 type = "??";
40550 else
40551 type = types[map->type];
40552@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40553 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40554 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40555 vma->vm_flags & VM_IO ? 'i' : '-',
40556+#ifdef CONFIG_GRKERNSEC_HIDESYM
40557+ 0);
40558+#else
40559 vma->vm_pgoff);
40560+#endif
40561
40562 #if defined(__i386__)
40563 pgprot = pgprot_val(vma->vm_page_prot);
40564diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40565index 2f4c4343..dd12cd2 100644
40566--- a/drivers/gpu/drm/drm_ioc32.c
40567+++ b/drivers/gpu/drm/drm_ioc32.c
40568@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40569 request = compat_alloc_user_space(nbytes);
40570 if (!access_ok(VERIFY_WRITE, request, nbytes))
40571 return -EFAULT;
40572- list = (struct drm_buf_desc *) (request + 1);
40573+ list = (struct drm_buf_desc __user *) (request + 1);
40574
40575 if (__put_user(count, &request->count)
40576 || __put_user(list, &request->list))
40577@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40578 request = compat_alloc_user_space(nbytes);
40579 if (!access_ok(VERIFY_WRITE, request, nbytes))
40580 return -EFAULT;
40581- list = (struct drm_buf_pub *) (request + 1);
40582+ list = (struct drm_buf_pub __user *) (request + 1);
40583
40584 if (__put_user(count, &request->count)
40585 || __put_user(list, &request->list))
40586@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40587 return 0;
40588 }
40589
40590-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40591+drm_ioctl_compat_t drm_compat_ioctls[] = {
40592 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40593 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40594 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40595@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40596 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40597 {
40598 unsigned int nr = DRM_IOCTL_NR(cmd);
40599- drm_ioctl_compat_t *fn;
40600 int ret;
40601
40602 /* Assume that ioctls without an explicit compat routine will just
40603@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40604 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40605 return drm_ioctl(filp, cmd, arg);
40606
40607- fn = drm_compat_ioctls[nr];
40608-
40609- if (fn != NULL)
40610- ret = (*fn) (filp, cmd, arg);
40611+ if (drm_compat_ioctls[nr] != NULL)
40612+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40613 else
40614 ret = drm_ioctl(filp, cmd, arg);
40615
40616diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40617index 98a33c580..8fd1c2b 100644
40618--- a/drivers/gpu/drm/drm_stub.c
40619+++ b/drivers/gpu/drm/drm_stub.c
40620@@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
40621
40622 drm_device_set_unplugged(dev);
40623
40624- if (dev->open_count == 0) {
40625+ if (local_read(&dev->open_count) == 0) {
40626 drm_put_dev(dev);
40627 }
40628 mutex_unlock(&drm_global_mutex);
40629diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40630index c22c309..ae758c3 100644
40631--- a/drivers/gpu/drm/drm_sysfs.c
40632+++ b/drivers/gpu/drm/drm_sysfs.c
40633@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40634 */
40635 int drm_sysfs_device_add(struct drm_minor *minor)
40636 {
40637- char *minor_str;
40638+ const char *minor_str;
40639 int r;
40640
40641 if (minor->type == DRM_MINOR_CONTROL)
40642diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40643index d4d16ed..8fb0b51 100644
40644--- a/drivers/gpu/drm/i810/i810_drv.h
40645+++ b/drivers/gpu/drm/i810/i810_drv.h
40646@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40647 int page_flipping;
40648
40649 wait_queue_head_t irq_queue;
40650- atomic_t irq_received;
40651- atomic_t irq_emitted;
40652+ atomic_unchecked_t irq_received;
40653+ atomic_unchecked_t irq_emitted;
40654
40655 int front_offset;
40656 } drm_i810_private_t;
40657diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40658index b2b46c5..feb9fe7 100644
40659--- a/drivers/gpu/drm/i915/i915_debugfs.c
40660+++ b/drivers/gpu/drm/i915/i915_debugfs.c
40661@@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40662 I915_READ(GTIMR));
40663 }
40664 seq_printf(m, "Interrupts received: %d\n",
40665- atomic_read(&dev_priv->irq_received));
40666+ atomic_read_unchecked(&dev_priv->irq_received));
40667 for_each_ring(ring, dev_priv, i) {
40668 if (INTEL_INFO(dev)->gen >= 6) {
40669 seq_printf(m,
40670diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40671index 15a74f9..4278889 100644
40672--- a/drivers/gpu/drm/i915/i915_dma.c
40673+++ b/drivers/gpu/drm/i915/i915_dma.c
40674@@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40675 bool can_switch;
40676
40677 spin_lock(&dev->count_lock);
40678- can_switch = (dev->open_count == 0);
40679+ can_switch = (local_read(&dev->open_count) == 0);
40680 spin_unlock(&dev->count_lock);
40681 return can_switch;
40682 }
40683diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40684index 4677af9..cd79971 100644
40685--- a/drivers/gpu/drm/i915/i915_drv.h
40686+++ b/drivers/gpu/drm/i915/i915_drv.h
40687@@ -1362,7 +1362,7 @@ typedef struct drm_i915_private {
40688 drm_dma_handle_t *status_page_dmah;
40689 struct resource mch_res;
40690
40691- atomic_t irq_received;
40692+ atomic_unchecked_t irq_received;
40693
40694 /* protects the irq masks */
40695 spinlock_t irq_lock;
40696diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40697index 768e666..68cf44d 100644
40698--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40699+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40700@@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40701
40702 static int
40703 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40704- int count)
40705+ unsigned int count)
40706 {
40707- int i;
40708+ unsigned int i;
40709 unsigned relocs_total = 0;
40710 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40711
40712diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40713index 3c59584..500f2e9 100644
40714--- a/drivers/gpu/drm/i915/i915_ioc32.c
40715+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40716@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40717 (unsigned long)request);
40718 }
40719
40720-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40721+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40722 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40723 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40724 [DRM_I915_GETPARAM] = compat_i915_getparam,
40725@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40726 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40727 {
40728 unsigned int nr = DRM_IOCTL_NR(cmd);
40729- drm_ioctl_compat_t *fn = NULL;
40730 int ret;
40731
40732 if (nr < DRM_COMMAND_BASE)
40733 return drm_compat_ioctl(filp, cmd, arg);
40734
40735- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40736- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40737-
40738- if (fn != NULL)
40739+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40740+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40741 ret = (*fn) (filp, cmd, arg);
40742- else
40743+ } else
40744 ret = drm_ioctl(filp, cmd, arg);
40745
40746 return ret;
40747diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40748index 4050450..f67c5c1 100644
40749--- a/drivers/gpu/drm/i915/i915_irq.c
40750+++ b/drivers/gpu/drm/i915/i915_irq.c
40751@@ -1448,7 +1448,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40752 int pipe;
40753 u32 pipe_stats[I915_MAX_PIPES];
40754
40755- atomic_inc(&dev_priv->irq_received);
40756+ atomic_inc_unchecked(&dev_priv->irq_received);
40757
40758 while (true) {
40759 iir = I915_READ(VLV_IIR);
40760@@ -1761,7 +1761,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40761 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40762 irqreturn_t ret = IRQ_NONE;
40763
40764- atomic_inc(&dev_priv->irq_received);
40765+ atomic_inc_unchecked(&dev_priv->irq_received);
40766
40767 /* We get interrupts on unclaimed registers, so check for this before we
40768 * do any I915_{READ,WRITE}. */
40769@@ -1831,7 +1831,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40770 uint32_t tmp = 0;
40771 enum pipe pipe;
40772
40773- atomic_inc(&dev_priv->irq_received);
40774+ atomic_inc_unchecked(&dev_priv->irq_received);
40775
40776 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40777 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40778@@ -2655,7 +2655,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40779 {
40780 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40781
40782- atomic_set(&dev_priv->irq_received, 0);
40783+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40784
40785 I915_WRITE(HWSTAM, 0xeffe);
40786
40787@@ -2673,7 +2673,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40788 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40789 int pipe;
40790
40791- atomic_set(&dev_priv->irq_received, 0);
40792+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40793
40794 /* VLV magic */
40795 I915_WRITE(VLV_IMR, 0);
40796@@ -2704,7 +2704,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40797 struct drm_i915_private *dev_priv = dev->dev_private;
40798 int pipe;
40799
40800- atomic_set(&dev_priv->irq_received, 0);
40801+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40802
40803 I915_WRITE(GEN8_MASTER_IRQ, 0);
40804 POSTING_READ(GEN8_MASTER_IRQ);
40805@@ -3028,7 +3028,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40806 if (!dev_priv)
40807 return;
40808
40809- atomic_set(&dev_priv->irq_received, 0);
40810+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40811
40812 I915_WRITE(GEN8_MASTER_IRQ, 0);
40813
40814@@ -3122,7 +3122,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40815 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40816 int pipe;
40817
40818- atomic_set(&dev_priv->irq_received, 0);
40819+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40820
40821 for_each_pipe(pipe)
40822 I915_WRITE(PIPESTAT(pipe), 0);
40823@@ -3208,7 +3208,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40824 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40825 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40826
40827- atomic_inc(&dev_priv->irq_received);
40828+ atomic_inc_unchecked(&dev_priv->irq_received);
40829
40830 iir = I915_READ16(IIR);
40831 if (iir == 0)
40832@@ -3287,7 +3287,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40833 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40834 int pipe;
40835
40836- atomic_set(&dev_priv->irq_received, 0);
40837+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40838
40839 if (I915_HAS_HOTPLUG(dev)) {
40840 I915_WRITE(PORT_HOTPLUG_EN, 0);
40841@@ -3394,7 +3394,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40842 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40843 int pipe, ret = IRQ_NONE;
40844
40845- atomic_inc(&dev_priv->irq_received);
40846+ atomic_inc_unchecked(&dev_priv->irq_received);
40847
40848 iir = I915_READ(IIR);
40849 do {
40850@@ -3521,7 +3521,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40851 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40852 int pipe;
40853
40854- atomic_set(&dev_priv->irq_received, 0);
40855+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40856
40857 I915_WRITE(PORT_HOTPLUG_EN, 0);
40858 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40859@@ -3637,7 +3637,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40860 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40861 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40862
40863- atomic_inc(&dev_priv->irq_received);
40864+ atomic_inc_unchecked(&dev_priv->irq_received);
40865
40866 iir = I915_READ(IIR);
40867
40868diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40869index b6fb3eb..e0fa1e1 100644
40870--- a/drivers/gpu/drm/i915/intel_display.c
40871+++ b/drivers/gpu/drm/i915/intel_display.c
40872@@ -10798,13 +10798,13 @@ struct intel_quirk {
40873 int subsystem_vendor;
40874 int subsystem_device;
40875 void (*hook)(struct drm_device *dev);
40876-};
40877+} __do_const;
40878
40879 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40880 struct intel_dmi_quirk {
40881 void (*hook)(struct drm_device *dev);
40882 const struct dmi_system_id (*dmi_id_list)[];
40883-};
40884+} __do_const;
40885
40886 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40887 {
40888@@ -10812,18 +10812,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40889 return 1;
40890 }
40891
40892-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40893+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40894 {
40895- .dmi_id_list = &(const struct dmi_system_id[]) {
40896- {
40897- .callback = intel_dmi_reverse_brightness,
40898- .ident = "NCR Corporation",
40899- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40900- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40901- },
40902- },
40903- { } /* terminating entry */
40904+ .callback = intel_dmi_reverse_brightness,
40905+ .ident = "NCR Corporation",
40906+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40907+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40908 },
40909+ },
40910+ { } /* terminating entry */
40911+};
40912+
40913+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40914+ {
40915+ .dmi_id_list = &intel_dmi_quirks_table,
40916 .hook = quirk_invert_brightness,
40917 },
40918 };
40919diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40920index fe45321..836fdca 100644
40921--- a/drivers/gpu/drm/mga/mga_drv.h
40922+++ b/drivers/gpu/drm/mga/mga_drv.h
40923@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40924 u32 clear_cmd;
40925 u32 maccess;
40926
40927- atomic_t vbl_received; /**< Number of vblanks received. */
40928+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40929 wait_queue_head_t fence_queue;
40930- atomic_t last_fence_retired;
40931+ atomic_unchecked_t last_fence_retired;
40932 u32 next_fence_to_post;
40933
40934 unsigned int fb_cpp;
40935diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40936index 86b4bb8..ae237ad 100644
40937--- a/drivers/gpu/drm/mga/mga_ioc32.c
40938+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40939@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40940 return 0;
40941 }
40942
40943-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40944+drm_ioctl_compat_t mga_compat_ioctls[] = {
40945 [DRM_MGA_INIT] = compat_mga_init,
40946 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40947 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40948@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40949 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40950 {
40951 unsigned int nr = DRM_IOCTL_NR(cmd);
40952- drm_ioctl_compat_t *fn = NULL;
40953 int ret;
40954
40955 if (nr < DRM_COMMAND_BASE)
40956 return drm_compat_ioctl(filp, cmd, arg);
40957
40958- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40959- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40960-
40961- if (fn != NULL)
40962+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40963+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40964 ret = (*fn) (filp, cmd, arg);
40965- else
40966+ } else
40967 ret = drm_ioctl(filp, cmd, arg);
40968
40969 return ret;
40970diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40971index 1b071b8..de8601a 100644
40972--- a/drivers/gpu/drm/mga/mga_irq.c
40973+++ b/drivers/gpu/drm/mga/mga_irq.c
40974@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40975 if (crtc != 0)
40976 return 0;
40977
40978- return atomic_read(&dev_priv->vbl_received);
40979+ return atomic_read_unchecked(&dev_priv->vbl_received);
40980 }
40981
40982
40983@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40984 /* VBLANK interrupt */
40985 if (status & MGA_VLINEPEN) {
40986 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40987- atomic_inc(&dev_priv->vbl_received);
40988+ atomic_inc_unchecked(&dev_priv->vbl_received);
40989 drm_handle_vblank(dev, 0);
40990 handled = 1;
40991 }
40992@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40993 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40994 MGA_WRITE(MGA_PRIMEND, prim_end);
40995
40996- atomic_inc(&dev_priv->last_fence_retired);
40997+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40998 wake_up(&dev_priv->fence_queue);
40999 handled = 1;
41000 }
41001@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
41002 * using fences.
41003 */
41004 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
41005- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
41006+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
41007 - *sequence) <= (1 << 23)));
41008
41009 *sequence = cur_fence;
41010diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
41011index 4c3feaa..26391ce 100644
41012--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
41013+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
41014@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
41015 struct bit_table {
41016 const char id;
41017 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
41018-};
41019+} __no_const;
41020
41021 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
41022
41023diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
41024index 23ca7a5..b6c955d 100644
41025--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
41026+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
41027@@ -97,7 +97,6 @@ struct nouveau_drm {
41028 struct drm_global_reference mem_global_ref;
41029 struct ttm_bo_global_ref bo_global_ref;
41030 struct ttm_bo_device bdev;
41031- atomic_t validate_sequence;
41032 int (*move)(struct nouveau_channel *,
41033 struct ttm_buffer_object *,
41034 struct ttm_mem_reg *, struct ttm_mem_reg *);
41035diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41036index c1a7e5a..38b8539 100644
41037--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41038+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41039@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
41040 unsigned long arg)
41041 {
41042 unsigned int nr = DRM_IOCTL_NR(cmd);
41043- drm_ioctl_compat_t *fn = NULL;
41044+ drm_ioctl_compat_t fn = NULL;
41045 int ret;
41046
41047 if (nr < DRM_COMMAND_BASE)
41048diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41049index d45d50d..72a5dd2 100644
41050--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
41051+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41052@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41053 }
41054
41055 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
41056- nouveau_vram_manager_init,
41057- nouveau_vram_manager_fini,
41058- nouveau_vram_manager_new,
41059- nouveau_vram_manager_del,
41060- nouveau_vram_manager_debug
41061+ .init = nouveau_vram_manager_init,
41062+ .takedown = nouveau_vram_manager_fini,
41063+ .get_node = nouveau_vram_manager_new,
41064+ .put_node = nouveau_vram_manager_del,
41065+ .debug = nouveau_vram_manager_debug
41066 };
41067
41068 static int
41069@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41070 }
41071
41072 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
41073- nouveau_gart_manager_init,
41074- nouveau_gart_manager_fini,
41075- nouveau_gart_manager_new,
41076- nouveau_gart_manager_del,
41077- nouveau_gart_manager_debug
41078+ .init = nouveau_gart_manager_init,
41079+ .takedown = nouveau_gart_manager_fini,
41080+ .get_node = nouveau_gart_manager_new,
41081+ .put_node = nouveau_gart_manager_del,
41082+ .debug = nouveau_gart_manager_debug
41083 };
41084
41085 #include <core/subdev/vm/nv04.h>
41086@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41087 }
41088
41089 const struct ttm_mem_type_manager_func nv04_gart_manager = {
41090- nv04_gart_manager_init,
41091- nv04_gart_manager_fini,
41092- nv04_gart_manager_new,
41093- nv04_gart_manager_del,
41094- nv04_gart_manager_debug
41095+ .init = nv04_gart_manager_init,
41096+ .takedown = nv04_gart_manager_fini,
41097+ .get_node = nv04_gart_manager_new,
41098+ .put_node = nv04_gart_manager_del,
41099+ .debug = nv04_gart_manager_debug
41100 };
41101
41102 int
41103diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
41104index 471347e..5adc6b9 100644
41105--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
41106+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
41107@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
41108 bool can_switch;
41109
41110 spin_lock(&dev->count_lock);
41111- can_switch = (dev->open_count == 0);
41112+ can_switch = (local_read(&dev->open_count) == 0);
41113 spin_unlock(&dev->count_lock);
41114 return can_switch;
41115 }
41116diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
41117index eb89653..613cf71 100644
41118--- a/drivers/gpu/drm/qxl/qxl_cmd.c
41119+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
41120@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
41121 int ret;
41122
41123 mutex_lock(&qdev->async_io_mutex);
41124- irq_num = atomic_read(&qdev->irq_received_io_cmd);
41125+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41126 if (qdev->last_sent_io_cmd > irq_num) {
41127 if (intr)
41128 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41129- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41130+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41131 else
41132 ret = wait_event_timeout(qdev->io_cmd_event,
41133- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41134+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41135 /* 0 is timeout, just bail the "hw" has gone away */
41136 if (ret <= 0)
41137 goto out;
41138- irq_num = atomic_read(&qdev->irq_received_io_cmd);
41139+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41140 }
41141 outb(val, addr);
41142 qdev->last_sent_io_cmd = irq_num + 1;
41143 if (intr)
41144 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41145- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41146+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41147 else
41148 ret = wait_event_timeout(qdev->io_cmd_event,
41149- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41150+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41151 out:
41152 if (ret > 0)
41153 ret = 0;
41154diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
41155index c3c2bbd..bc3c0fb 100644
41156--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
41157+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
41158@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
41159 struct drm_info_node *node = (struct drm_info_node *) m->private;
41160 struct qxl_device *qdev = node->minor->dev->dev_private;
41161
41162- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
41163- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
41164- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
41165- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
41166+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
41167+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
41168+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
41169+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
41170 seq_printf(m, "%d\n", qdev->irq_received_error);
41171 return 0;
41172 }
41173diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
41174index 36ed40b..0397633 100644
41175--- a/drivers/gpu/drm/qxl/qxl_drv.h
41176+++ b/drivers/gpu/drm/qxl/qxl_drv.h
41177@@ -290,10 +290,10 @@ struct qxl_device {
41178 unsigned int last_sent_io_cmd;
41179
41180 /* interrupt handling */
41181- atomic_t irq_received;
41182- atomic_t irq_received_display;
41183- atomic_t irq_received_cursor;
41184- atomic_t irq_received_io_cmd;
41185+ atomic_unchecked_t irq_received;
41186+ atomic_unchecked_t irq_received_display;
41187+ atomic_unchecked_t irq_received_cursor;
41188+ atomic_unchecked_t irq_received_io_cmd;
41189 unsigned irq_received_error;
41190 wait_queue_head_t display_event;
41191 wait_queue_head_t cursor_event;
41192diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
41193index 0bb86e6..d41416d 100644
41194--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
41195+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
41196@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41197
41198 /* TODO copy slow path code from i915 */
41199 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
41200- 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);
41201+ 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);
41202
41203 {
41204 struct qxl_drawable *draw = fb_cmd;
41205@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41206 struct drm_qxl_reloc reloc;
41207
41208 if (copy_from_user(&reloc,
41209- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
41210+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
41211 sizeof(reloc))) {
41212 ret = -EFAULT;
41213 goto out_free_bos;
41214@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
41215
41216 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
41217
41218- struct drm_qxl_command *commands =
41219- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
41220+ struct drm_qxl_command __user *commands =
41221+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
41222
41223- if (copy_from_user(&user_cmd, &commands[cmd_num],
41224+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
41225 sizeof(user_cmd)))
41226 return -EFAULT;
41227
41228diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
41229index 28f84b4..fb3e224 100644
41230--- a/drivers/gpu/drm/qxl/qxl_irq.c
41231+++ b/drivers/gpu/drm/qxl/qxl_irq.c
41232@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
41233
41234 pending = xchg(&qdev->ram_header->int_pending, 0);
41235
41236- atomic_inc(&qdev->irq_received);
41237+ atomic_inc_unchecked(&qdev->irq_received);
41238
41239 if (pending & QXL_INTERRUPT_DISPLAY) {
41240- atomic_inc(&qdev->irq_received_display);
41241+ atomic_inc_unchecked(&qdev->irq_received_display);
41242 wake_up_all(&qdev->display_event);
41243 qxl_queue_garbage_collect(qdev, false);
41244 }
41245 if (pending & QXL_INTERRUPT_CURSOR) {
41246- atomic_inc(&qdev->irq_received_cursor);
41247+ atomic_inc_unchecked(&qdev->irq_received_cursor);
41248 wake_up_all(&qdev->cursor_event);
41249 }
41250 if (pending & QXL_INTERRUPT_IO_CMD) {
41251- atomic_inc(&qdev->irq_received_io_cmd);
41252+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
41253 wake_up_all(&qdev->io_cmd_event);
41254 }
41255 if (pending & QXL_INTERRUPT_ERROR) {
41256@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41257 init_waitqueue_head(&qdev->io_cmd_event);
41258 INIT_WORK(&qdev->client_monitors_config_work,
41259 qxl_client_monitors_config_work_func);
41260- atomic_set(&qdev->irq_received, 0);
41261- atomic_set(&qdev->irq_received_display, 0);
41262- atomic_set(&qdev->irq_received_cursor, 0);
41263- atomic_set(&qdev->irq_received_io_cmd, 0);
41264+ atomic_set_unchecked(&qdev->irq_received, 0);
41265+ atomic_set_unchecked(&qdev->irq_received_display, 0);
41266+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41267+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41268 qdev->irq_received_error = 0;
41269 ret = drm_irq_install(qdev->ddev);
41270 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41271diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41272index c82c1d6a9..6158c02 100644
41273--- a/drivers/gpu/drm/qxl/qxl_ttm.c
41274+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41275@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41276 }
41277 }
41278
41279-static struct vm_operations_struct qxl_ttm_vm_ops;
41280+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41281 static const struct vm_operations_struct *ttm_vm_ops;
41282
41283 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41284@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41285 return r;
41286 if (unlikely(ttm_vm_ops == NULL)) {
41287 ttm_vm_ops = vma->vm_ops;
41288+ pax_open_kernel();
41289 qxl_ttm_vm_ops = *ttm_vm_ops;
41290 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41291+ pax_close_kernel();
41292 }
41293 vma->vm_ops = &qxl_ttm_vm_ops;
41294 return 0;
41295@@ -561,25 +563,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41296 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41297 {
41298 #if defined(CONFIG_DEBUG_FS)
41299- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41300- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41301- unsigned i;
41302+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41303+ {
41304+ .name = "qxl_mem_mm",
41305+ .show = &qxl_mm_dump_table,
41306+ },
41307+ {
41308+ .name = "qxl_surf_mm",
41309+ .show = &qxl_mm_dump_table,
41310+ }
41311+ };
41312
41313- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41314- if (i == 0)
41315- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41316- else
41317- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41318- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41319- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41320- qxl_mem_types_list[i].driver_features = 0;
41321- if (i == 0)
41322- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41323- else
41324- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41325+ pax_open_kernel();
41326+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41327+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41328+ pax_close_kernel();
41329
41330- }
41331- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41332+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41333 #else
41334 return 0;
41335 #endif
41336diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41337index 59459fe..be26b31 100644
41338--- a/drivers/gpu/drm/r128/r128_cce.c
41339+++ b/drivers/gpu/drm/r128/r128_cce.c
41340@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41341
41342 /* GH: Simple idle check.
41343 */
41344- atomic_set(&dev_priv->idle_count, 0);
41345+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41346
41347 /* We don't support anything other than bus-mastering ring mode,
41348 * but the ring can be in either AGP or PCI space for the ring
41349diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41350index 5bf3f5f..7000661 100644
41351--- a/drivers/gpu/drm/r128/r128_drv.h
41352+++ b/drivers/gpu/drm/r128/r128_drv.h
41353@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
41354 int is_pci;
41355 unsigned long cce_buffers_offset;
41356
41357- atomic_t idle_count;
41358+ atomic_unchecked_t idle_count;
41359
41360 int page_flipping;
41361 int current_page;
41362 u32 crtc_offset;
41363 u32 crtc_offset_cntl;
41364
41365- atomic_t vbl_received;
41366+ atomic_unchecked_t vbl_received;
41367
41368 u32 color_fmt;
41369 unsigned int front_offset;
41370diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41371index b0d0fd3..a6fbbe4 100644
41372--- a/drivers/gpu/drm/r128/r128_ioc32.c
41373+++ b/drivers/gpu/drm/r128/r128_ioc32.c
41374@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41375 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41376 }
41377
41378-drm_ioctl_compat_t *r128_compat_ioctls[] = {
41379+drm_ioctl_compat_t r128_compat_ioctls[] = {
41380 [DRM_R128_INIT] = compat_r128_init,
41381 [DRM_R128_DEPTH] = compat_r128_depth,
41382 [DRM_R128_STIPPLE] = compat_r128_stipple,
41383@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41384 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41385 {
41386 unsigned int nr = DRM_IOCTL_NR(cmd);
41387- drm_ioctl_compat_t *fn = NULL;
41388 int ret;
41389
41390 if (nr < DRM_COMMAND_BASE)
41391 return drm_compat_ioctl(filp, cmd, arg);
41392
41393- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
41394- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41395-
41396- if (fn != NULL)
41397+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
41398+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41399 ret = (*fn) (filp, cmd, arg);
41400- else
41401+ } else
41402 ret = drm_ioctl(filp, cmd, arg);
41403
41404 return ret;
41405diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41406index c2ae496..30b5993 100644
41407--- a/drivers/gpu/drm/r128/r128_irq.c
41408+++ b/drivers/gpu/drm/r128/r128_irq.c
41409@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41410 if (crtc != 0)
41411 return 0;
41412
41413- return atomic_read(&dev_priv->vbl_received);
41414+ return atomic_read_unchecked(&dev_priv->vbl_received);
41415 }
41416
41417 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41418@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41419 /* VBLANK interrupt */
41420 if (status & R128_CRTC_VBLANK_INT) {
41421 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41422- atomic_inc(&dev_priv->vbl_received);
41423+ atomic_inc_unchecked(&dev_priv->vbl_received);
41424 drm_handle_vblank(dev, 0);
41425 return IRQ_HANDLED;
41426 }
41427diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41428index e806dac..f81d32f 100644
41429--- a/drivers/gpu/drm/r128/r128_state.c
41430+++ b/drivers/gpu/drm/r128/r128_state.c
41431@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41432
41433 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41434 {
41435- if (atomic_read(&dev_priv->idle_count) == 0)
41436+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41437 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41438 else
41439- atomic_set(&dev_priv->idle_count, 0);
41440+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41441 }
41442
41443 #endif
41444diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41445index 4a85bb6..aaea819 100644
41446--- a/drivers/gpu/drm/radeon/mkregtable.c
41447+++ b/drivers/gpu/drm/radeon/mkregtable.c
41448@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41449 regex_t mask_rex;
41450 regmatch_t match[4];
41451 char buf[1024];
41452- size_t end;
41453+ long end;
41454 int len;
41455 int done = 0;
41456 int r;
41457 unsigned o;
41458 struct offset *offset;
41459 char last_reg_s[10];
41460- int last_reg;
41461+ unsigned long last_reg;
41462
41463 if (regcomp
41464 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41465diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41466index 0bf6f4a..18e2437 100644
41467--- a/drivers/gpu/drm/radeon/radeon_device.c
41468+++ b/drivers/gpu/drm/radeon/radeon_device.c
41469@@ -1128,7 +1128,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41470 bool can_switch;
41471
41472 spin_lock(&dev->count_lock);
41473- can_switch = (dev->open_count == 0);
41474+ can_switch = (local_read(&dev->open_count) == 0);
41475 spin_unlock(&dev->count_lock);
41476 return can_switch;
41477 }
41478diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41479index dafd812..1bf20c7 100644
41480--- a/drivers/gpu/drm/radeon/radeon_drv.h
41481+++ b/drivers/gpu/drm/radeon/radeon_drv.h
41482@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
41483
41484 /* SW interrupt */
41485 wait_queue_head_t swi_queue;
41486- atomic_t swi_emitted;
41487+ atomic_unchecked_t swi_emitted;
41488 int vblank_crtc;
41489 uint32_t irq_enable_reg;
41490 uint32_t r500_disp_irq_reg;
41491diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41492index bdb0f93..5ff558f 100644
41493--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41494+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41495@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41496 request = compat_alloc_user_space(sizeof(*request));
41497 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41498 || __put_user(req32.param, &request->param)
41499- || __put_user((void __user *)(unsigned long)req32.value,
41500+ || __put_user((unsigned long)req32.value,
41501 &request->value))
41502 return -EFAULT;
41503
41504@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41505 #define compat_radeon_cp_setparam NULL
41506 #endif /* X86_64 || IA64 */
41507
41508-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41509+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41510 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41511 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41512 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41513@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41514 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41515 {
41516 unsigned int nr = DRM_IOCTL_NR(cmd);
41517- drm_ioctl_compat_t *fn = NULL;
41518 int ret;
41519
41520 if (nr < DRM_COMMAND_BASE)
41521 return drm_compat_ioctl(filp, cmd, arg);
41522
41523- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
41524- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41525-
41526- if (fn != NULL)
41527+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
41528+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41529 ret = (*fn) (filp, cmd, arg);
41530- else
41531+ } else
41532 ret = drm_ioctl(filp, cmd, arg);
41533
41534 return ret;
41535diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41536index 244b19b..c19226d 100644
41537--- a/drivers/gpu/drm/radeon/radeon_irq.c
41538+++ b/drivers/gpu/drm/radeon/radeon_irq.c
41539@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41540 unsigned int ret;
41541 RING_LOCALS;
41542
41543- atomic_inc(&dev_priv->swi_emitted);
41544- ret = atomic_read(&dev_priv->swi_emitted);
41545+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41546+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41547
41548 BEGIN_RING(4);
41549 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41550@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41551 drm_radeon_private_t *dev_priv =
41552 (drm_radeon_private_t *) dev->dev_private;
41553
41554- atomic_set(&dev_priv->swi_emitted, 0);
41555+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41556 init_waitqueue_head(&dev_priv->swi_queue);
41557
41558 dev->max_vblank_count = 0x001fffff;
41559diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41560index 956ab7f..fbd36d8 100644
41561--- a/drivers/gpu/drm/radeon/radeon_state.c
41562+++ b/drivers/gpu/drm/radeon/radeon_state.c
41563@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41564 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41565 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41566
41567- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41568+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41569 sarea_priv->nbox * sizeof(depth_boxes[0])))
41570 return -EFAULT;
41571
41572@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41573 {
41574 drm_radeon_private_t *dev_priv = dev->dev_private;
41575 drm_radeon_getparam_t *param = data;
41576- int value;
41577+ int value = 0;
41578
41579 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41580
41581diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41582index 040a2a1..eae4e54 100644
41583--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41584+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41585@@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41586 man->size = size >> PAGE_SHIFT;
41587 }
41588
41589-static struct vm_operations_struct radeon_ttm_vm_ops;
41590+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41591 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41592
41593 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41594@@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41595 }
41596 if (unlikely(ttm_vm_ops == NULL)) {
41597 ttm_vm_ops = vma->vm_ops;
41598+ pax_open_kernel();
41599 radeon_ttm_vm_ops = *ttm_vm_ops;
41600 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41601+ pax_close_kernel();
41602 }
41603 vma->vm_ops = &radeon_ttm_vm_ops;
41604 return 0;
41605diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41606index 9336006..ce78aa7 100644
41607--- a/drivers/gpu/drm/tegra/dc.c
41608+++ b/drivers/gpu/drm/tegra/dc.c
41609@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41610 }
41611
41612 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41613- dc->debugfs_files[i].data = dc;
41614+ *(void **)&dc->debugfs_files[i].data = dc;
41615
41616 err = drm_debugfs_create_files(dc->debugfs_files,
41617 ARRAY_SIZE(debugfs_files),
41618diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41619index d452faab..f8cbc6a 100644
41620--- a/drivers/gpu/drm/tegra/dsi.c
41621+++ b/drivers/gpu/drm/tegra/dsi.c
41622@@ -53,7 +53,7 @@ struct tegra_dsi {
41623 struct clk *clk_lp;
41624 struct clk *clk;
41625
41626- struct drm_info_list *debugfs_files;
41627+ drm_info_list_no_const *debugfs_files;
41628 struct drm_minor *minor;
41629 struct dentry *debugfs;
41630
41631diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41632index 6928015..c9853e7 100644
41633--- a/drivers/gpu/drm/tegra/hdmi.c
41634+++ b/drivers/gpu/drm/tegra/hdmi.c
41635@@ -59,7 +59,7 @@ struct tegra_hdmi {
41636 bool stereo;
41637 bool dvi;
41638
41639- struct drm_info_list *debugfs_files;
41640+ drm_info_list_no_const *debugfs_files;
41641 struct drm_minor *minor;
41642 struct dentry *debugfs;
41643 };
41644diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41645index c58eba33..83c2728 100644
41646--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41647+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41648@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41649 }
41650
41651 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41652- ttm_bo_man_init,
41653- ttm_bo_man_takedown,
41654- ttm_bo_man_get_node,
41655- ttm_bo_man_put_node,
41656- ttm_bo_man_debug
41657+ .init = ttm_bo_man_init,
41658+ .takedown = ttm_bo_man_takedown,
41659+ .get_node = ttm_bo_man_get_node,
41660+ .put_node = ttm_bo_man_put_node,
41661+ .debug = ttm_bo_man_debug
41662 };
41663 EXPORT_SYMBOL(ttm_bo_manager_func);
41664diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41665index dbc2def..0a9f710 100644
41666--- a/drivers/gpu/drm/ttm/ttm_memory.c
41667+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41668@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41669 zone->glob = glob;
41670 glob->zone_kernel = zone;
41671 ret = kobject_init_and_add(
41672- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41673+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41674 if (unlikely(ret != 0)) {
41675 kobject_put(&zone->kobj);
41676 return ret;
41677@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41678 zone->glob = glob;
41679 glob->zone_dma32 = zone;
41680 ret = kobject_init_and_add(
41681- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41682+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41683 if (unlikely(ret != 0)) {
41684 kobject_put(&zone->kobj);
41685 return ret;
41686diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41687index 863bef9..cba15cf 100644
41688--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41689+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41690@@ -391,9 +391,9 @@ out:
41691 static unsigned long
41692 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41693 {
41694- static atomic_t start_pool = ATOMIC_INIT(0);
41695+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41696 unsigned i;
41697- unsigned pool_offset = atomic_add_return(1, &start_pool);
41698+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41699 struct ttm_page_pool *pool;
41700 int shrink_pages = sc->nr_to_scan;
41701 unsigned long freed = 0;
41702diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41703index dbadd49..1b7457b 100644
41704--- a/drivers/gpu/drm/udl/udl_fb.c
41705+++ b/drivers/gpu/drm/udl/udl_fb.c
41706@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41707 fb_deferred_io_cleanup(info);
41708 kfree(info->fbdefio);
41709 info->fbdefio = NULL;
41710- info->fbops->fb_mmap = udl_fb_mmap;
41711 }
41712
41713 pr_warn("released /dev/fb%d user=%d count=%d\n",
41714diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41715index ad02732..144f5ed 100644
41716--- a/drivers/gpu/drm/via/via_drv.h
41717+++ b/drivers/gpu/drm/via/via_drv.h
41718@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41719 typedef uint32_t maskarray_t[5];
41720
41721 typedef struct drm_via_irq {
41722- atomic_t irq_received;
41723+ atomic_unchecked_t irq_received;
41724 uint32_t pending_mask;
41725 uint32_t enable_mask;
41726 wait_queue_head_t irq_queue;
41727@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41728 struct timeval last_vblank;
41729 int last_vblank_valid;
41730 unsigned usec_per_vblank;
41731- atomic_t vbl_received;
41732+ atomic_unchecked_t vbl_received;
41733 drm_via_state_t hc_state;
41734 char pci_buf[VIA_PCI_BUF_SIZE];
41735 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41736diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41737index 1319433..a993b0c 100644
41738--- a/drivers/gpu/drm/via/via_irq.c
41739+++ b/drivers/gpu/drm/via/via_irq.c
41740@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41741 if (crtc != 0)
41742 return 0;
41743
41744- return atomic_read(&dev_priv->vbl_received);
41745+ return atomic_read_unchecked(&dev_priv->vbl_received);
41746 }
41747
41748 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41749@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41750
41751 status = VIA_READ(VIA_REG_INTERRUPT);
41752 if (status & VIA_IRQ_VBLANK_PENDING) {
41753- atomic_inc(&dev_priv->vbl_received);
41754- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41755+ atomic_inc_unchecked(&dev_priv->vbl_received);
41756+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41757 do_gettimeofday(&cur_vblank);
41758 if (dev_priv->last_vblank_valid) {
41759 dev_priv->usec_per_vblank =
41760@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41761 dev_priv->last_vblank = cur_vblank;
41762 dev_priv->last_vblank_valid = 1;
41763 }
41764- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41765+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41766 DRM_DEBUG("US per vblank is: %u\n",
41767 dev_priv->usec_per_vblank);
41768 }
41769@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41770
41771 for (i = 0; i < dev_priv->num_irqs; ++i) {
41772 if (status & cur_irq->pending_mask) {
41773- atomic_inc(&cur_irq->irq_received);
41774+ atomic_inc_unchecked(&cur_irq->irq_received);
41775 wake_up(&cur_irq->irq_queue);
41776 handled = 1;
41777 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41778@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41779 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41780 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41781 masks[irq][4]));
41782- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41783+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41784 } else {
41785 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41786 (((cur_irq_sequence =
41787- atomic_read(&cur_irq->irq_received)) -
41788+ atomic_read_unchecked(&cur_irq->irq_received)) -
41789 *sequence) <= (1 << 23)));
41790 }
41791 *sequence = cur_irq_sequence;
41792@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41793 }
41794
41795 for (i = 0; i < dev_priv->num_irqs; ++i) {
41796- atomic_set(&cur_irq->irq_received, 0);
41797+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41798 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41799 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41800 init_waitqueue_head(&cur_irq->irq_queue);
41801@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41802 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41803 case VIA_IRQ_RELATIVE:
41804 irqwait->request.sequence +=
41805- atomic_read(&cur_irq->irq_received);
41806+ atomic_read_unchecked(&cur_irq->irq_received);
41807 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41808 case VIA_IRQ_ABSOLUTE:
41809 break;
41810diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41811index 0783155..b29e18e 100644
41812--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41813+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41814@@ -437,7 +437,7 @@ struct vmw_private {
41815 * Fencing and IRQs.
41816 */
41817
41818- atomic_t marker_seq;
41819+ atomic_unchecked_t marker_seq;
41820 wait_queue_head_t fence_queue;
41821 wait_queue_head_t fifo_queue;
41822 int fence_queue_waiters; /* Protected by hw_mutex */
41823diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41824index 6ccd993..618d592 100644
41825--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41826+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41827@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41828 (unsigned int) min,
41829 (unsigned int) fifo->capabilities);
41830
41831- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41832+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41833 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41834 vmw_marker_queue_init(&fifo->marker_queue);
41835 return vmw_fifo_send_fence(dev_priv, &dummy);
41836@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41837 if (reserveable)
41838 iowrite32(bytes, fifo_mem +
41839 SVGA_FIFO_RESERVED);
41840- return fifo_mem + (next_cmd >> 2);
41841+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41842 } else {
41843 need_bounce = true;
41844 }
41845@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41846
41847 fm = vmw_fifo_reserve(dev_priv, bytes);
41848 if (unlikely(fm == NULL)) {
41849- *seqno = atomic_read(&dev_priv->marker_seq);
41850+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41851 ret = -ENOMEM;
41852 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41853 false, 3*HZ);
41854@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41855 }
41856
41857 do {
41858- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41859+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41860 } while (*seqno == 0);
41861
41862 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41863diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41864index b1273e8..9c274fd 100644
41865--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41866+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41867@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41868 }
41869
41870 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41871- vmw_gmrid_man_init,
41872- vmw_gmrid_man_takedown,
41873- vmw_gmrid_man_get_node,
41874- vmw_gmrid_man_put_node,
41875- vmw_gmrid_man_debug
41876+ .init = vmw_gmrid_man_init,
41877+ .takedown = vmw_gmrid_man_takedown,
41878+ .get_node = vmw_gmrid_man_get_node,
41879+ .put_node = vmw_gmrid_man_put_node,
41880+ .debug = vmw_gmrid_man_debug
41881 };
41882diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41883index 47b7094..698ba09 100644
41884--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41885+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41886@@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41887 int ret;
41888
41889 num_clips = arg->num_clips;
41890- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41891+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41892
41893 if (unlikely(num_clips == 0))
41894 return 0;
41895@@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41896 int ret;
41897
41898 num_clips = arg->num_clips;
41899- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41900+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41901
41902 if (unlikely(num_clips == 0))
41903 return 0;
41904diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41905index 0c42376..6febe77 100644
41906--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41907+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41908@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41909 * emitted. Then the fence is stale and signaled.
41910 */
41911
41912- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41913+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41914 > VMW_FENCE_WRAP);
41915
41916 return ret;
41917@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41918
41919 if (fifo_idle)
41920 down_read(&fifo_state->rwsem);
41921- signal_seq = atomic_read(&dev_priv->marker_seq);
41922+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41923 ret = 0;
41924
41925 for (;;) {
41926diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41927index 8a8725c2..afed796 100644
41928--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41929+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41930@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41931 while (!vmw_lag_lt(queue, us)) {
41932 spin_lock(&queue->lock);
41933 if (list_empty(&queue->head))
41934- seqno = atomic_read(&dev_priv->marker_seq);
41935+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41936 else {
41937 marker = list_first_entry(&queue->head,
41938 struct vmw_marker, head);
41939diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41940index ec0ae2d..dc0780b 100644
41941--- a/drivers/gpu/vga/vga_switcheroo.c
41942+++ b/drivers/gpu/vga/vga_switcheroo.c
41943@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41944
41945 /* this version is for the case where the power switch is separate
41946 to the device being powered down. */
41947-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41948+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41949 {
41950 /* copy over all the bus versions */
41951 if (dev->bus && dev->bus->pm) {
41952@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41953 return ret;
41954 }
41955
41956-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41957+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41958 {
41959 /* copy over all the bus versions */
41960 if (dev->bus && dev->bus->pm) {
41961diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41962index 8a5384c..cf63c18 100644
41963--- a/drivers/hid/hid-core.c
41964+++ b/drivers/hid/hid-core.c
41965@@ -2422,7 +2422,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41966
41967 int hid_add_device(struct hid_device *hdev)
41968 {
41969- static atomic_t id = ATOMIC_INIT(0);
41970+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41971 int ret;
41972
41973 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41974@@ -2456,7 +2456,7 @@ int hid_add_device(struct hid_device *hdev)
41975 /* XXX hack, any other cleaner solution after the driver core
41976 * is converted to allow more than 20 bytes as the device name? */
41977 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41978- hdev->vendor, hdev->product, atomic_inc_return(&id));
41979+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41980
41981 hid_debug_register(hdev, dev_name(&hdev->dev));
41982 ret = device_add(&hdev->dev);
41983diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41984index c13fb5b..55a3802 100644
41985--- a/drivers/hid/hid-wiimote-debug.c
41986+++ b/drivers/hid/hid-wiimote-debug.c
41987@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41988 else if (size == 0)
41989 return -EIO;
41990
41991- if (copy_to_user(u, buf, size))
41992+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41993 return -EFAULT;
41994
41995 *off += size;
41996diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41997index cedc6da..2c3da2a 100644
41998--- a/drivers/hid/uhid.c
41999+++ b/drivers/hid/uhid.c
42000@@ -47,7 +47,7 @@ struct uhid_device {
42001 struct mutex report_lock;
42002 wait_queue_head_t report_wait;
42003 atomic_t report_done;
42004- atomic_t report_id;
42005+ atomic_unchecked_t report_id;
42006 struct uhid_event report_buf;
42007 };
42008
42009@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
42010
42011 spin_lock_irqsave(&uhid->qlock, flags);
42012 ev->type = UHID_FEATURE;
42013- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
42014+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
42015 ev->u.feature.rnum = rnum;
42016 ev->u.feature.rtype = report_type;
42017
42018@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
42019 spin_lock_irqsave(&uhid->qlock, flags);
42020
42021 /* id for old report; drop it silently */
42022- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
42023+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
42024 goto unlock;
42025 if (atomic_read(&uhid->report_done))
42026 goto unlock;
42027diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42028index 69ea36f..8dbf4bb 100644
42029--- a/drivers/hv/channel.c
42030+++ b/drivers/hv/channel.c
42031@@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42032 int ret = 0;
42033 int t;
42034
42035- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42036- atomic_inc(&vmbus_connection.next_gpadl_handle);
42037+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42038+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42039
42040 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42041 if (ret)
42042diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42043index bcb4950..61dba6c 100644
42044--- a/drivers/hv/hv.c
42045+++ b/drivers/hv/hv.c
42046@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42047 u64 output_address = (output) ? virt_to_phys(output) : 0;
42048 u32 output_address_hi = output_address >> 32;
42049 u32 output_address_lo = output_address & 0xFFFFFFFF;
42050- void *hypercall_page = hv_context.hypercall_page;
42051+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42052
42053 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42054 "=a"(hv_status_lo) : "d" (control_hi),
42055@@ -154,7 +154,7 @@ int hv_init(void)
42056 /* See if the hypercall page is already set */
42057 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42058
42059- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42060+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42061
42062 if (!virtaddr)
42063 goto cleanup;
42064diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42065index 7e17a54..a50a33d 100644
42066--- a/drivers/hv/hv_balloon.c
42067+++ b/drivers/hv/hv_balloon.c
42068@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42069
42070 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42071 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42072-static atomic_t trans_id = ATOMIC_INIT(0);
42073+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42074
42075 static int dm_ring_size = (5 * PAGE_SIZE);
42076
42077@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
42078 pr_info("Memory hot add failed\n");
42079
42080 dm->state = DM_INITIALIZED;
42081- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42082+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42083 vmbus_sendpacket(dm->dev->channel, &resp,
42084 sizeof(struct dm_hot_add_response),
42085 (unsigned long)NULL,
42086@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
42087 memset(&status, 0, sizeof(struct dm_status));
42088 status.hdr.type = DM_STATUS_REPORT;
42089 status.hdr.size = sizeof(struct dm_status);
42090- status.hdr.trans_id = atomic_inc_return(&trans_id);
42091+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42092
42093 /*
42094 * The host expects the guest to report free memory.
42095@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
42096 * send the status. This can happen if we were interrupted
42097 * after we picked our transaction ID.
42098 */
42099- if (status.hdr.trans_id != atomic_read(&trans_id))
42100+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42101 return;
42102
42103 vmbus_sendpacket(dm->dev->channel, &status,
42104@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
42105 */
42106
42107 do {
42108- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42109+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42110 ret = vmbus_sendpacket(dm_device.dev->channel,
42111 bl_resp,
42112 bl_resp->hdr.size,
42113@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42114
42115 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42116 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42117- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42118+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42119 resp.hdr.size = sizeof(struct dm_unballoon_response);
42120
42121 vmbus_sendpacket(dm_device.dev->channel, &resp,
42122@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42123 memset(&version_req, 0, sizeof(struct dm_version_request));
42124 version_req.hdr.type = DM_VERSION_REQUEST;
42125 version_req.hdr.size = sizeof(struct dm_version_request);
42126- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42127+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42128 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42129 version_req.is_last_attempt = 1;
42130
42131@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
42132 memset(&version_req, 0, sizeof(struct dm_version_request));
42133 version_req.hdr.type = DM_VERSION_REQUEST;
42134 version_req.hdr.size = sizeof(struct dm_version_request);
42135- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42136+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42137 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42138 version_req.is_last_attempt = 0;
42139
42140@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
42141 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42142 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42143 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42144- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42145+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42146
42147 cap_msg.caps.cap_bits.balloon = 1;
42148 cap_msg.caps.cap_bits.hot_add = 1;
42149diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42150index e055176..c22ff1f 100644
42151--- a/drivers/hv/hyperv_vmbus.h
42152+++ b/drivers/hv/hyperv_vmbus.h
42153@@ -602,7 +602,7 @@ enum vmbus_connect_state {
42154 struct vmbus_connection {
42155 enum vmbus_connect_state conn_state;
42156
42157- atomic_t next_gpadl_handle;
42158+ atomic_unchecked_t next_gpadl_handle;
42159
42160 /*
42161 * Represents channel interrupts. Each bit position represents a
42162diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42163index 077bb1b..d433d74 100644
42164--- a/drivers/hv/vmbus_drv.c
42165+++ b/drivers/hv/vmbus_drv.c
42166@@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42167 {
42168 int ret = 0;
42169
42170- static atomic_t device_num = ATOMIC_INIT(0);
42171+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42172
42173 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42174- atomic_inc_return(&device_num));
42175+ atomic_inc_return_unchecked(&device_num));
42176
42177 child_device_obj->device.bus = &hv_bus;
42178 child_device_obj->device.parent = &hv_acpi_dev->dev;
42179diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42180index 579bdf9..75118b5 100644
42181--- a/drivers/hwmon/acpi_power_meter.c
42182+++ b/drivers/hwmon/acpi_power_meter.c
42183@@ -116,7 +116,7 @@ struct sensor_template {
42184 struct device_attribute *devattr,
42185 const char *buf, size_t count);
42186 int index;
42187-};
42188+} __do_const;
42189
42190 /* Averaging interval */
42191 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42192@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42193 struct sensor_template *attrs)
42194 {
42195 struct device *dev = &resource->acpi_dev->dev;
42196- struct sensor_device_attribute *sensors =
42197+ sensor_device_attribute_no_const *sensors =
42198 &resource->sensors[resource->num_sensors];
42199 int res = 0;
42200
42201diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42202index 3288f13..71cfb4e 100644
42203--- a/drivers/hwmon/applesmc.c
42204+++ b/drivers/hwmon/applesmc.c
42205@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42206 {
42207 struct applesmc_node_group *grp;
42208 struct applesmc_dev_attr *node;
42209- struct attribute *attr;
42210+ attribute_no_const *attr;
42211 int ret, i;
42212
42213 for (grp = groups; grp->format; grp++) {
42214diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42215index ae208f6..48b6c5b 100644
42216--- a/drivers/hwmon/asus_atk0110.c
42217+++ b/drivers/hwmon/asus_atk0110.c
42218@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42219 struct atk_sensor_data {
42220 struct list_head list;
42221 struct atk_data *data;
42222- struct device_attribute label_attr;
42223- struct device_attribute input_attr;
42224- struct device_attribute limit1_attr;
42225- struct device_attribute limit2_attr;
42226+ device_attribute_no_const label_attr;
42227+ device_attribute_no_const input_attr;
42228+ device_attribute_no_const limit1_attr;
42229+ device_attribute_no_const limit2_attr;
42230 char label_attr_name[ATTR_NAME_SIZE];
42231 char input_attr_name[ATTR_NAME_SIZE];
42232 char limit1_attr_name[ATTR_NAME_SIZE];
42233@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42234 static struct device_attribute atk_name_attr =
42235 __ATTR(name, 0444, atk_name_show, NULL);
42236
42237-static void atk_init_attribute(struct device_attribute *attr, char *name,
42238+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42239 sysfs_show_func show)
42240 {
42241 sysfs_attr_init(&attr->attr);
42242diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42243index 1599310..cd9525c 100644
42244--- a/drivers/hwmon/coretemp.c
42245+++ b/drivers/hwmon/coretemp.c
42246@@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42247 return NOTIFY_OK;
42248 }
42249
42250-static struct notifier_block coretemp_cpu_notifier __refdata = {
42251+static struct notifier_block coretemp_cpu_notifier = {
42252 .notifier_call = coretemp_cpu_callback,
42253 };
42254
42255diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42256index 632f1dc..57e6a58 100644
42257--- a/drivers/hwmon/ibmaem.c
42258+++ b/drivers/hwmon/ibmaem.c
42259@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
42260 struct aem_rw_sensor_template *rw)
42261 {
42262 struct device *dev = &data->pdev->dev;
42263- struct sensor_device_attribute *sensors = data->sensors;
42264+ sensor_device_attribute_no_const *sensors = data->sensors;
42265 int err;
42266
42267 /* Set up read-only sensors */
42268diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42269index 708081b..fe2d4ab 100644
42270--- a/drivers/hwmon/iio_hwmon.c
42271+++ b/drivers/hwmon/iio_hwmon.c
42272@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42273 {
42274 struct device *dev = &pdev->dev;
42275 struct iio_hwmon_state *st;
42276- struct sensor_device_attribute *a;
42277+ sensor_device_attribute_no_const *a;
42278 int ret, i;
42279 int in_i = 1, temp_i = 1, curr_i = 1;
42280 enum iio_chan_type type;
42281diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42282index 38d5a63..cf2c2ea 100644
42283--- a/drivers/hwmon/nct6775.c
42284+++ b/drivers/hwmon/nct6775.c
42285@@ -944,10 +944,10 @@ static struct attribute_group *
42286 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42287 int repeat)
42288 {
42289- struct attribute_group *group;
42290+ attribute_group_no_const *group;
42291 struct sensor_device_attr_u *su;
42292- struct sensor_device_attribute *a;
42293- struct sensor_device_attribute_2 *a2;
42294+ sensor_device_attribute_no_const *a;
42295+ sensor_device_attribute_2_no_const *a2;
42296 struct attribute **attrs;
42297 struct sensor_device_template **t;
42298 int i, count;
42299diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42300index 291d11f..3f0dbbd 100644
42301--- a/drivers/hwmon/pmbus/pmbus_core.c
42302+++ b/drivers/hwmon/pmbus/pmbus_core.c
42303@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42304 return 0;
42305 }
42306
42307-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42308+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42309 const char *name,
42310 umode_t mode,
42311 ssize_t (*show)(struct device *dev,
42312@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42313 dev_attr->store = store;
42314 }
42315
42316-static void pmbus_attr_init(struct sensor_device_attribute *a,
42317+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42318 const char *name,
42319 umode_t mode,
42320 ssize_t (*show)(struct device *dev,
42321@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42322 u16 reg, u8 mask)
42323 {
42324 struct pmbus_boolean *boolean;
42325- struct sensor_device_attribute *a;
42326+ sensor_device_attribute_no_const *a;
42327
42328 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42329 if (!boolean)
42330@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42331 bool update, bool readonly)
42332 {
42333 struct pmbus_sensor *sensor;
42334- struct device_attribute *a;
42335+ device_attribute_no_const *a;
42336
42337 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42338 if (!sensor)
42339@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42340 const char *lstring, int index)
42341 {
42342 struct pmbus_label *label;
42343- struct device_attribute *a;
42344+ device_attribute_no_const *a;
42345
42346 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42347 if (!label)
42348diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42349index 97cd45a..ac54d8b 100644
42350--- a/drivers/hwmon/sht15.c
42351+++ b/drivers/hwmon/sht15.c
42352@@ -169,7 +169,7 @@ struct sht15_data {
42353 int supply_uv;
42354 bool supply_uv_valid;
42355 struct work_struct update_supply_work;
42356- atomic_t interrupt_handled;
42357+ atomic_unchecked_t interrupt_handled;
42358 };
42359
42360 /**
42361@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42362 ret = gpio_direction_input(data->pdata->gpio_data);
42363 if (ret)
42364 return ret;
42365- atomic_set(&data->interrupt_handled, 0);
42366+ atomic_set_unchecked(&data->interrupt_handled, 0);
42367
42368 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42369 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42370 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42371 /* Only relevant if the interrupt hasn't occurred. */
42372- if (!atomic_read(&data->interrupt_handled))
42373+ if (!atomic_read_unchecked(&data->interrupt_handled))
42374 schedule_work(&data->read_work);
42375 }
42376 ret = wait_event_timeout(data->wait_queue,
42377@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42378
42379 /* First disable the interrupt */
42380 disable_irq_nosync(irq);
42381- atomic_inc(&data->interrupt_handled);
42382+ atomic_inc_unchecked(&data->interrupt_handled);
42383 /* Then schedule a reading work struct */
42384 if (data->state != SHT15_READING_NOTHING)
42385 schedule_work(&data->read_work);
42386@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42387 * If not, then start the interrupt again - care here as could
42388 * have gone low in meantime so verify it hasn't!
42389 */
42390- atomic_set(&data->interrupt_handled, 0);
42391+ atomic_set_unchecked(&data->interrupt_handled, 0);
42392 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42393 /* If still not occurred or another handler was scheduled */
42394 if (gpio_get_value(data->pdata->gpio_data)
42395- || atomic_read(&data->interrupt_handled))
42396+ || atomic_read_unchecked(&data->interrupt_handled))
42397 return;
42398 }
42399
42400diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42401index 38944e9..ae9e5ed 100644
42402--- a/drivers/hwmon/via-cputemp.c
42403+++ b/drivers/hwmon/via-cputemp.c
42404@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42405 return NOTIFY_OK;
42406 }
42407
42408-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42409+static struct notifier_block via_cputemp_cpu_notifier = {
42410 .notifier_call = via_cputemp_cpu_callback,
42411 };
42412
42413diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42414index 41fc683..a39cfea 100644
42415--- a/drivers/i2c/busses/i2c-amd756-s4882.c
42416+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42417@@ -43,7 +43,7 @@
42418 extern struct i2c_adapter amd756_smbus;
42419
42420 static struct i2c_adapter *s4882_adapter;
42421-static struct i2c_algorithm *s4882_algo;
42422+static i2c_algorithm_no_const *s4882_algo;
42423
42424 /* Wrapper access functions for multiplexed SMBus */
42425 static DEFINE_MUTEX(amd756_lock);
42426diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42427index 721f7eb..0fd2a09 100644
42428--- a/drivers/i2c/busses/i2c-diolan-u2c.c
42429+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42430@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42431 /* usb layer */
42432
42433 /* Send command to device, and get response. */
42434-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42435+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42436 {
42437 int ret = 0;
42438 int actual;
42439diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42440index b170bdf..3c76427 100644
42441--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42442+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42443@@ -41,7 +41,7 @@
42444 extern struct i2c_adapter *nforce2_smbus;
42445
42446 static struct i2c_adapter *s4985_adapter;
42447-static struct i2c_algorithm *s4985_algo;
42448+static i2c_algorithm_no_const *s4985_algo;
42449
42450 /* Wrapper access functions for multiplexed SMBus */
42451 static DEFINE_MUTEX(nforce2_lock);
42452diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42453index 80b47e8..1a6040d9 100644
42454--- a/drivers/i2c/i2c-dev.c
42455+++ b/drivers/i2c/i2c-dev.c
42456@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42457 break;
42458 }
42459
42460- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42461+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42462 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42463 if (IS_ERR(rdwr_pa[i].buf)) {
42464 res = PTR_ERR(rdwr_pa[i].buf);
42465diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42466index 0b510ba..4fbb5085 100644
42467--- a/drivers/ide/ide-cd.c
42468+++ b/drivers/ide/ide-cd.c
42469@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42470 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42471 if ((unsigned long)buf & alignment
42472 || blk_rq_bytes(rq) & q->dma_pad_mask
42473- || object_is_on_stack(buf))
42474+ || object_starts_on_stack(buf))
42475 drive->dma = 0;
42476 }
42477 }
42478diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42479index acc911a..8700c3c 100644
42480--- a/drivers/iio/industrialio-core.c
42481+++ b/drivers/iio/industrialio-core.c
42482@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42483 }
42484
42485 static
42486-int __iio_device_attr_init(struct device_attribute *dev_attr,
42487+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42488 const char *postfix,
42489 struct iio_chan_spec const *chan,
42490 ssize_t (*readfunc)(struct device *dev,
42491diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42492index c323917..6ddea8b 100644
42493--- a/drivers/infiniband/core/cm.c
42494+++ b/drivers/infiniband/core/cm.c
42495@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42496
42497 struct cm_counter_group {
42498 struct kobject obj;
42499- atomic_long_t counter[CM_ATTR_COUNT];
42500+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42501 };
42502
42503 struct cm_counter_attribute {
42504@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42505 struct ib_mad_send_buf *msg = NULL;
42506 int ret;
42507
42508- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42509+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42510 counter[CM_REQ_COUNTER]);
42511
42512 /* Quick state check to discard duplicate REQs. */
42513@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42514 if (!cm_id_priv)
42515 return;
42516
42517- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42518+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42519 counter[CM_REP_COUNTER]);
42520 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42521 if (ret)
42522@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42523 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42524 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42525 spin_unlock_irq(&cm_id_priv->lock);
42526- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42527+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42528 counter[CM_RTU_COUNTER]);
42529 goto out;
42530 }
42531@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42532 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42533 dreq_msg->local_comm_id);
42534 if (!cm_id_priv) {
42535- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42536+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42537 counter[CM_DREQ_COUNTER]);
42538 cm_issue_drep(work->port, work->mad_recv_wc);
42539 return -EINVAL;
42540@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42541 case IB_CM_MRA_REP_RCVD:
42542 break;
42543 case IB_CM_TIMEWAIT:
42544- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42545+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42546 counter[CM_DREQ_COUNTER]);
42547 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42548 goto unlock;
42549@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42550 cm_free_msg(msg);
42551 goto deref;
42552 case IB_CM_DREQ_RCVD:
42553- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42554+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42555 counter[CM_DREQ_COUNTER]);
42556 goto unlock;
42557 default:
42558@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42559 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42560 cm_id_priv->msg, timeout)) {
42561 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42562- atomic_long_inc(&work->port->
42563+ atomic_long_inc_unchecked(&work->port->
42564 counter_group[CM_RECV_DUPLICATES].
42565 counter[CM_MRA_COUNTER]);
42566 goto out;
42567@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42568 break;
42569 case IB_CM_MRA_REQ_RCVD:
42570 case IB_CM_MRA_REP_RCVD:
42571- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42572+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42573 counter[CM_MRA_COUNTER]);
42574 /* fall through */
42575 default:
42576@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42577 case IB_CM_LAP_IDLE:
42578 break;
42579 case IB_CM_MRA_LAP_SENT:
42580- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42581+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42582 counter[CM_LAP_COUNTER]);
42583 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42584 goto unlock;
42585@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42586 cm_free_msg(msg);
42587 goto deref;
42588 case IB_CM_LAP_RCVD:
42589- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42590+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42591 counter[CM_LAP_COUNTER]);
42592 goto unlock;
42593 default:
42594@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42595 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42596 if (cur_cm_id_priv) {
42597 spin_unlock_irq(&cm.lock);
42598- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42599+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42600 counter[CM_SIDR_REQ_COUNTER]);
42601 goto out; /* Duplicate message. */
42602 }
42603@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42604 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42605 msg->retries = 1;
42606
42607- atomic_long_add(1 + msg->retries,
42608+ atomic_long_add_unchecked(1 + msg->retries,
42609 &port->counter_group[CM_XMIT].counter[attr_index]);
42610 if (msg->retries)
42611- atomic_long_add(msg->retries,
42612+ atomic_long_add_unchecked(msg->retries,
42613 &port->counter_group[CM_XMIT_RETRIES].
42614 counter[attr_index]);
42615
42616@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42617 }
42618
42619 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42620- atomic_long_inc(&port->counter_group[CM_RECV].
42621+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42622 counter[attr_id - CM_ATTR_ID_OFFSET]);
42623
42624 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42625@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42626 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42627
42628 return sprintf(buf, "%ld\n",
42629- atomic_long_read(&group->counter[cm_attr->index]));
42630+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42631 }
42632
42633 static const struct sysfs_ops cm_counter_ops = {
42634diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42635index 9f5ad7c..588cd84 100644
42636--- a/drivers/infiniband/core/fmr_pool.c
42637+++ b/drivers/infiniband/core/fmr_pool.c
42638@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42639
42640 struct task_struct *thread;
42641
42642- atomic_t req_ser;
42643- atomic_t flush_ser;
42644+ atomic_unchecked_t req_ser;
42645+ atomic_unchecked_t flush_ser;
42646
42647 wait_queue_head_t force_wait;
42648 };
42649@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42650 struct ib_fmr_pool *pool = pool_ptr;
42651
42652 do {
42653- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42654+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42655 ib_fmr_batch_release(pool);
42656
42657- atomic_inc(&pool->flush_ser);
42658+ atomic_inc_unchecked(&pool->flush_ser);
42659 wake_up_interruptible(&pool->force_wait);
42660
42661 if (pool->flush_function)
42662@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42663 }
42664
42665 set_current_state(TASK_INTERRUPTIBLE);
42666- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42667+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42668 !kthread_should_stop())
42669 schedule();
42670 __set_current_state(TASK_RUNNING);
42671@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42672 pool->dirty_watermark = params->dirty_watermark;
42673 pool->dirty_len = 0;
42674 spin_lock_init(&pool->pool_lock);
42675- atomic_set(&pool->req_ser, 0);
42676- atomic_set(&pool->flush_ser, 0);
42677+ atomic_set_unchecked(&pool->req_ser, 0);
42678+ atomic_set_unchecked(&pool->flush_ser, 0);
42679 init_waitqueue_head(&pool->force_wait);
42680
42681 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42682@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42683 }
42684 spin_unlock_irq(&pool->pool_lock);
42685
42686- serial = atomic_inc_return(&pool->req_ser);
42687+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42688 wake_up_process(pool->thread);
42689
42690 if (wait_event_interruptible(pool->force_wait,
42691- atomic_read(&pool->flush_ser) - serial >= 0))
42692+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42693 return -EINTR;
42694
42695 return 0;
42696@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42697 } else {
42698 list_add_tail(&fmr->list, &pool->dirty_list);
42699 if (++pool->dirty_len >= pool->dirty_watermark) {
42700- atomic_inc(&pool->req_ser);
42701+ atomic_inc_unchecked(&pool->req_ser);
42702 wake_up_process(pool->thread);
42703 }
42704 }
42705diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42706index 41b1195..27971a0 100644
42707--- a/drivers/infiniband/hw/cxgb4/mem.c
42708+++ b/drivers/infiniband/hw/cxgb4/mem.c
42709@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42710 int err;
42711 struct fw_ri_tpte tpt;
42712 u32 stag_idx;
42713- static atomic_t key;
42714+ static atomic_unchecked_t key;
42715
42716 if (c4iw_fatal_error(rdev))
42717 return -EIO;
42718@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42719 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42720 rdev->stats.stag.max = rdev->stats.stag.cur;
42721 mutex_unlock(&rdev->stats.lock);
42722- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42723+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42724 }
42725 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42726 __func__, stag_state, type, pdid, stag_idx);
42727diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42728index 644c2c7..ecf0879 100644
42729--- a/drivers/infiniband/hw/ipath/ipath_dma.c
42730+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42731@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42732 }
42733
42734 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42735- ipath_mapping_error,
42736- ipath_dma_map_single,
42737- ipath_dma_unmap_single,
42738- ipath_dma_map_page,
42739- ipath_dma_unmap_page,
42740- ipath_map_sg,
42741- ipath_unmap_sg,
42742- ipath_sg_dma_address,
42743- ipath_sg_dma_len,
42744- ipath_sync_single_for_cpu,
42745- ipath_sync_single_for_device,
42746- ipath_dma_alloc_coherent,
42747- ipath_dma_free_coherent
42748+ .mapping_error = ipath_mapping_error,
42749+ .map_single = ipath_dma_map_single,
42750+ .unmap_single = ipath_dma_unmap_single,
42751+ .map_page = ipath_dma_map_page,
42752+ .unmap_page = ipath_dma_unmap_page,
42753+ .map_sg = ipath_map_sg,
42754+ .unmap_sg = ipath_unmap_sg,
42755+ .dma_address = ipath_sg_dma_address,
42756+ .dma_len = ipath_sg_dma_len,
42757+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
42758+ .sync_single_for_device = ipath_sync_single_for_device,
42759+ .alloc_coherent = ipath_dma_alloc_coherent,
42760+ .free_coherent = ipath_dma_free_coherent
42761 };
42762diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42763index 79b3dbc..96e5fcc 100644
42764--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42765+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42766@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42767 struct ib_atomic_eth *ateth;
42768 struct ipath_ack_entry *e;
42769 u64 vaddr;
42770- atomic64_t *maddr;
42771+ atomic64_unchecked_t *maddr;
42772 u64 sdata;
42773 u32 rkey;
42774 u8 next;
42775@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42776 IB_ACCESS_REMOTE_ATOMIC)))
42777 goto nack_acc_unlck;
42778 /* Perform atomic OP and save result. */
42779- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42780+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42781 sdata = be64_to_cpu(ateth->swap_data);
42782 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42783 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42784- (u64) atomic64_add_return(sdata, maddr) - sdata :
42785+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42786 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42787 be64_to_cpu(ateth->compare_data),
42788 sdata);
42789diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42790index 1f95bba..9530f87 100644
42791--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42792+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42793@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42794 unsigned long flags;
42795 struct ib_wc wc;
42796 u64 sdata;
42797- atomic64_t *maddr;
42798+ atomic64_unchecked_t *maddr;
42799 enum ib_wc_status send_status;
42800
42801 /*
42802@@ -382,11 +382,11 @@ again:
42803 IB_ACCESS_REMOTE_ATOMIC)))
42804 goto acc_err;
42805 /* Perform atomic OP and save result. */
42806- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42807+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42808 sdata = wqe->wr.wr.atomic.compare_add;
42809 *(u64 *) sqp->s_sge.sge.vaddr =
42810 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42811- (u64) atomic64_add_return(sdata, maddr) - sdata :
42812+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42813 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42814 sdata, wqe->wr.wr.atomic.swap);
42815 goto send_comp;
42816diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42817index f2a3f48..673ec79 100644
42818--- a/drivers/infiniband/hw/mlx4/mad.c
42819+++ b/drivers/infiniband/hw/mlx4/mad.c
42820@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42821
42822 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42823 {
42824- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42825+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42826 cpu_to_be64(0xff00000000000000LL);
42827 }
42828
42829diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42830index 25b2cdf..099ff97 100644
42831--- a/drivers/infiniband/hw/mlx4/mcg.c
42832+++ b/drivers/infiniband/hw/mlx4/mcg.c
42833@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42834 {
42835 char name[20];
42836
42837- atomic_set(&ctx->tid, 0);
42838+ atomic_set_unchecked(&ctx->tid, 0);
42839 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42840 ctx->mcg_wq = create_singlethread_workqueue(name);
42841 if (!ctx->mcg_wq)
42842diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42843index a230683..3723f2d 100644
42844--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42845+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42846@@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
42847 struct list_head mcg_mgid0_list;
42848 struct workqueue_struct *mcg_wq;
42849 struct mlx4_ib_demux_pv_ctx **tun;
42850- atomic_t tid;
42851+ atomic_unchecked_t tid;
42852 int flushing; /* flushing the work queue */
42853 };
42854
42855diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42856index 9d3e5c1..6f166df 100644
42857--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42858+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42859@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42860 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42861 }
42862
42863-int mthca_QUERY_FW(struct mthca_dev *dev)
42864+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42865 {
42866 struct mthca_mailbox *mailbox;
42867 u32 *outbox;
42868@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42869 CMD_TIME_CLASS_B);
42870 }
42871
42872-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42873+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42874 int num_mtt)
42875 {
42876 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42877@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42878 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42879 }
42880
42881-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42882+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42883 int eq_num)
42884 {
42885 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42886@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42887 CMD_TIME_CLASS_B);
42888 }
42889
42890-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42891+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42892 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42893 void *in_mad, void *response_mad)
42894 {
42895diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42896index 87897b9..7e79542 100644
42897--- a/drivers/infiniband/hw/mthca/mthca_main.c
42898+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42899@@ -692,7 +692,7 @@ err_close:
42900 return err;
42901 }
42902
42903-static int mthca_setup_hca(struct mthca_dev *dev)
42904+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42905 {
42906 int err;
42907
42908diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42909index ed9a989..6aa5dc2 100644
42910--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42911+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42912@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42913 * through the bitmaps)
42914 */
42915
42916-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42917+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42918 {
42919 int o;
42920 int m;
42921@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42922 return key;
42923 }
42924
42925-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42926+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42927 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42928 {
42929 struct mthca_mailbox *mailbox;
42930@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42931 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42932 }
42933
42934-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42935+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42936 u64 *buffer_list, int buffer_size_shift,
42937 int list_len, u64 iova, u64 total_size,
42938 u32 access, struct mthca_mr *mr)
42939diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42940index 42dde06..1257310 100644
42941--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42942+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42943@@ -764,7 +764,7 @@ unlock:
42944 return 0;
42945 }
42946
42947-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42948+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42949 {
42950 struct mthca_dev *dev = to_mdev(ibcq->device);
42951 struct mthca_cq *cq = to_mcq(ibcq);
42952diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42953index 353c7b0..c6ce921 100644
42954--- a/drivers/infiniband/hw/nes/nes.c
42955+++ b/drivers/infiniband/hw/nes/nes.c
42956@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42957 LIST_HEAD(nes_adapter_list);
42958 static LIST_HEAD(nes_dev_list);
42959
42960-atomic_t qps_destroyed;
42961+atomic_unchecked_t qps_destroyed;
42962
42963 static unsigned int ee_flsh_adapter;
42964 static unsigned int sysfs_nonidx_addr;
42965@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42966 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42967 struct nes_adapter *nesadapter = nesdev->nesadapter;
42968
42969- atomic_inc(&qps_destroyed);
42970+ atomic_inc_unchecked(&qps_destroyed);
42971
42972 /* Free the control structures */
42973
42974diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42975index 33cc589..3bd6538 100644
42976--- a/drivers/infiniband/hw/nes/nes.h
42977+++ b/drivers/infiniband/hw/nes/nes.h
42978@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42979 extern unsigned int wqm_quanta;
42980 extern struct list_head nes_adapter_list;
42981
42982-extern atomic_t cm_connects;
42983-extern atomic_t cm_accepts;
42984-extern atomic_t cm_disconnects;
42985-extern atomic_t cm_closes;
42986-extern atomic_t cm_connecteds;
42987-extern atomic_t cm_connect_reqs;
42988-extern atomic_t cm_rejects;
42989-extern atomic_t mod_qp_timouts;
42990-extern atomic_t qps_created;
42991-extern atomic_t qps_destroyed;
42992-extern atomic_t sw_qps_destroyed;
42993+extern atomic_unchecked_t cm_connects;
42994+extern atomic_unchecked_t cm_accepts;
42995+extern atomic_unchecked_t cm_disconnects;
42996+extern atomic_unchecked_t cm_closes;
42997+extern atomic_unchecked_t cm_connecteds;
42998+extern atomic_unchecked_t cm_connect_reqs;
42999+extern atomic_unchecked_t cm_rejects;
43000+extern atomic_unchecked_t mod_qp_timouts;
43001+extern atomic_unchecked_t qps_created;
43002+extern atomic_unchecked_t qps_destroyed;
43003+extern atomic_unchecked_t sw_qps_destroyed;
43004 extern u32 mh_detected;
43005 extern u32 mh_pauses_sent;
43006 extern u32 cm_packets_sent;
43007@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
43008 extern u32 cm_packets_received;
43009 extern u32 cm_packets_dropped;
43010 extern u32 cm_packets_retrans;
43011-extern atomic_t cm_listens_created;
43012-extern atomic_t cm_listens_destroyed;
43013+extern atomic_unchecked_t cm_listens_created;
43014+extern atomic_unchecked_t cm_listens_destroyed;
43015 extern u32 cm_backlog_drops;
43016-extern atomic_t cm_loopbacks;
43017-extern atomic_t cm_nodes_created;
43018-extern atomic_t cm_nodes_destroyed;
43019-extern atomic_t cm_accel_dropped_pkts;
43020-extern atomic_t cm_resets_recvd;
43021-extern atomic_t pau_qps_created;
43022-extern atomic_t pau_qps_destroyed;
43023+extern atomic_unchecked_t cm_loopbacks;
43024+extern atomic_unchecked_t cm_nodes_created;
43025+extern atomic_unchecked_t cm_nodes_destroyed;
43026+extern atomic_unchecked_t cm_accel_dropped_pkts;
43027+extern atomic_unchecked_t cm_resets_recvd;
43028+extern atomic_unchecked_t pau_qps_created;
43029+extern atomic_unchecked_t pau_qps_destroyed;
43030
43031 extern u32 int_mod_timer_init;
43032 extern u32 int_mod_cq_depth_256;
43033diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43034index 9c9f2f5..2559190 100644
43035--- a/drivers/infiniband/hw/nes/nes_cm.c
43036+++ b/drivers/infiniband/hw/nes/nes_cm.c
43037@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
43038 u32 cm_packets_retrans;
43039 u32 cm_packets_created;
43040 u32 cm_packets_received;
43041-atomic_t cm_listens_created;
43042-atomic_t cm_listens_destroyed;
43043+atomic_unchecked_t cm_listens_created;
43044+atomic_unchecked_t cm_listens_destroyed;
43045 u32 cm_backlog_drops;
43046-atomic_t cm_loopbacks;
43047-atomic_t cm_nodes_created;
43048-atomic_t cm_nodes_destroyed;
43049-atomic_t cm_accel_dropped_pkts;
43050-atomic_t cm_resets_recvd;
43051+atomic_unchecked_t cm_loopbacks;
43052+atomic_unchecked_t cm_nodes_created;
43053+atomic_unchecked_t cm_nodes_destroyed;
43054+atomic_unchecked_t cm_accel_dropped_pkts;
43055+atomic_unchecked_t cm_resets_recvd;
43056
43057 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43058 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43059@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
43060 /* instance of function pointers for client API */
43061 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43062 static struct nes_cm_ops nes_cm_api = {
43063- mini_cm_accelerated,
43064- mini_cm_listen,
43065- mini_cm_del_listen,
43066- mini_cm_connect,
43067- mini_cm_close,
43068- mini_cm_accept,
43069- mini_cm_reject,
43070- mini_cm_recv_pkt,
43071- mini_cm_dealloc_core,
43072- mini_cm_get,
43073- mini_cm_set
43074+ .accelerated = mini_cm_accelerated,
43075+ .listen = mini_cm_listen,
43076+ .stop_listener = mini_cm_del_listen,
43077+ .connect = mini_cm_connect,
43078+ .close = mini_cm_close,
43079+ .accept = mini_cm_accept,
43080+ .reject = mini_cm_reject,
43081+ .recv_pkt = mini_cm_recv_pkt,
43082+ .destroy_cm_core = mini_cm_dealloc_core,
43083+ .get = mini_cm_get,
43084+ .set = mini_cm_set
43085 };
43086
43087 static struct nes_cm_core *g_cm_core;
43088
43089-atomic_t cm_connects;
43090-atomic_t cm_accepts;
43091-atomic_t cm_disconnects;
43092-atomic_t cm_closes;
43093-atomic_t cm_connecteds;
43094-atomic_t cm_connect_reqs;
43095-atomic_t cm_rejects;
43096+atomic_unchecked_t cm_connects;
43097+atomic_unchecked_t cm_accepts;
43098+atomic_unchecked_t cm_disconnects;
43099+atomic_unchecked_t cm_closes;
43100+atomic_unchecked_t cm_connecteds;
43101+atomic_unchecked_t cm_connect_reqs;
43102+atomic_unchecked_t cm_rejects;
43103
43104 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43105 {
43106@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43107 kfree(listener);
43108 listener = NULL;
43109 ret = 0;
43110- atomic_inc(&cm_listens_destroyed);
43111+ atomic_inc_unchecked(&cm_listens_destroyed);
43112 } else {
43113 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43114 }
43115@@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43116 cm_node->rem_mac);
43117
43118 add_hte_node(cm_core, cm_node);
43119- atomic_inc(&cm_nodes_created);
43120+ atomic_inc_unchecked(&cm_nodes_created);
43121
43122 return cm_node;
43123 }
43124@@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43125 }
43126
43127 atomic_dec(&cm_core->node_cnt);
43128- atomic_inc(&cm_nodes_destroyed);
43129+ atomic_inc_unchecked(&cm_nodes_destroyed);
43130 nesqp = cm_node->nesqp;
43131 if (nesqp) {
43132 nesqp->cm_node = NULL;
43133@@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43134
43135 static void drop_packet(struct sk_buff *skb)
43136 {
43137- atomic_inc(&cm_accel_dropped_pkts);
43138+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43139 dev_kfree_skb_any(skb);
43140 }
43141
43142@@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43143 {
43144
43145 int reset = 0; /* whether to send reset in case of err.. */
43146- atomic_inc(&cm_resets_recvd);
43147+ atomic_inc_unchecked(&cm_resets_recvd);
43148 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43149 " refcnt=%d\n", cm_node, cm_node->state,
43150 atomic_read(&cm_node->ref_count));
43151@@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43152 rem_ref_cm_node(cm_node->cm_core, cm_node);
43153 return NULL;
43154 }
43155- atomic_inc(&cm_loopbacks);
43156+ atomic_inc_unchecked(&cm_loopbacks);
43157 loopbackremotenode->loopbackpartner = cm_node;
43158 loopbackremotenode->tcp_cntxt.rcv_wscale =
43159 NES_CM_DEFAULT_RCV_WND_SCALE;
43160@@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43161 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43162 else {
43163 rem_ref_cm_node(cm_core, cm_node);
43164- atomic_inc(&cm_accel_dropped_pkts);
43165+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43166 dev_kfree_skb_any(skb);
43167 }
43168 break;
43169@@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43170
43171 if ((cm_id) && (cm_id->event_handler)) {
43172 if (issue_disconn) {
43173- atomic_inc(&cm_disconnects);
43174+ atomic_inc_unchecked(&cm_disconnects);
43175 cm_event.event = IW_CM_EVENT_DISCONNECT;
43176 cm_event.status = disconn_status;
43177 cm_event.local_addr = cm_id->local_addr;
43178@@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43179 }
43180
43181 if (issue_close) {
43182- atomic_inc(&cm_closes);
43183+ atomic_inc_unchecked(&cm_closes);
43184 nes_disconnect(nesqp, 1);
43185
43186 cm_id->provider_data = nesqp;
43187@@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43188
43189 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43190 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43191- atomic_inc(&cm_accepts);
43192+ atomic_inc_unchecked(&cm_accepts);
43193
43194 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43195 netdev_refcnt_read(nesvnic->netdev));
43196@@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43197 struct nes_cm_core *cm_core;
43198 u8 *start_buff;
43199
43200- atomic_inc(&cm_rejects);
43201+ atomic_inc_unchecked(&cm_rejects);
43202 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43203 loopback = cm_node->loopbackpartner;
43204 cm_core = cm_node->cm_core;
43205@@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43206 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43207 ntohs(laddr->sin_port));
43208
43209- atomic_inc(&cm_connects);
43210+ atomic_inc_unchecked(&cm_connects);
43211 nesqp->active_conn = 1;
43212
43213 /* cache the cm_id in the qp */
43214@@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43215 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43216 return err;
43217 }
43218- atomic_inc(&cm_listens_created);
43219+ atomic_inc_unchecked(&cm_listens_created);
43220 }
43221
43222 cm_id->add_ref(cm_id);
43223@@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43224
43225 if (nesqp->destroyed)
43226 return;
43227- atomic_inc(&cm_connecteds);
43228+ atomic_inc_unchecked(&cm_connecteds);
43229 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43230 " local port 0x%04X. jiffies = %lu.\n",
43231 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43232@@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43233
43234 cm_id->add_ref(cm_id);
43235 ret = cm_id->event_handler(cm_id, &cm_event);
43236- atomic_inc(&cm_closes);
43237+ atomic_inc_unchecked(&cm_closes);
43238 cm_event.event = IW_CM_EVENT_CLOSE;
43239 cm_event.status = 0;
43240 cm_event.provider_data = cm_id->provider_data;
43241@@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43242 return;
43243 cm_id = cm_node->cm_id;
43244
43245- atomic_inc(&cm_connect_reqs);
43246+ atomic_inc_unchecked(&cm_connect_reqs);
43247 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43248 cm_node, cm_id, jiffies);
43249
43250@@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43251 return;
43252 cm_id = cm_node->cm_id;
43253
43254- atomic_inc(&cm_connect_reqs);
43255+ atomic_inc_unchecked(&cm_connect_reqs);
43256 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43257 cm_node, cm_id, jiffies);
43258
43259diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43260index 4166452..fc952c3 100644
43261--- a/drivers/infiniband/hw/nes/nes_mgt.c
43262+++ b/drivers/infiniband/hw/nes/nes_mgt.c
43263@@ -40,8 +40,8 @@
43264 #include "nes.h"
43265 #include "nes_mgt.h"
43266
43267-atomic_t pau_qps_created;
43268-atomic_t pau_qps_destroyed;
43269+atomic_unchecked_t pau_qps_created;
43270+atomic_unchecked_t pau_qps_destroyed;
43271
43272 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43273 {
43274@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43275 {
43276 struct sk_buff *skb;
43277 unsigned long flags;
43278- atomic_inc(&pau_qps_destroyed);
43279+ atomic_inc_unchecked(&pau_qps_destroyed);
43280
43281 /* Free packets that have not yet been forwarded */
43282 /* Lock is acquired by skb_dequeue when removing the skb */
43283@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43284 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43285 skb_queue_head_init(&nesqp->pau_list);
43286 spin_lock_init(&nesqp->pau_lock);
43287- atomic_inc(&pau_qps_created);
43288+ atomic_inc_unchecked(&pau_qps_created);
43289 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43290 }
43291
43292diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43293index 49eb511..a774366 100644
43294--- a/drivers/infiniband/hw/nes/nes_nic.c
43295+++ b/drivers/infiniband/hw/nes/nes_nic.c
43296@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43297 target_stat_values[++index] = mh_detected;
43298 target_stat_values[++index] = mh_pauses_sent;
43299 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43300- target_stat_values[++index] = atomic_read(&cm_connects);
43301- target_stat_values[++index] = atomic_read(&cm_accepts);
43302- target_stat_values[++index] = atomic_read(&cm_disconnects);
43303- target_stat_values[++index] = atomic_read(&cm_connecteds);
43304- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43305- target_stat_values[++index] = atomic_read(&cm_rejects);
43306- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43307- target_stat_values[++index] = atomic_read(&qps_created);
43308- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43309- target_stat_values[++index] = atomic_read(&qps_destroyed);
43310- target_stat_values[++index] = atomic_read(&cm_closes);
43311+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43312+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43313+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43314+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43315+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43316+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43317+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43318+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43319+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43320+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43321+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43322 target_stat_values[++index] = cm_packets_sent;
43323 target_stat_values[++index] = cm_packets_bounced;
43324 target_stat_values[++index] = cm_packets_created;
43325 target_stat_values[++index] = cm_packets_received;
43326 target_stat_values[++index] = cm_packets_dropped;
43327 target_stat_values[++index] = cm_packets_retrans;
43328- target_stat_values[++index] = atomic_read(&cm_listens_created);
43329- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43330+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43331+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43332 target_stat_values[++index] = cm_backlog_drops;
43333- target_stat_values[++index] = atomic_read(&cm_loopbacks);
43334- target_stat_values[++index] = atomic_read(&cm_nodes_created);
43335- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43336- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43337- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43338+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43339+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43340+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43341+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43342+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43343 target_stat_values[++index] = nesadapter->free_4kpbl;
43344 target_stat_values[++index] = nesadapter->free_256pbl;
43345 target_stat_values[++index] = int_mod_timer_init;
43346 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43347 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43348 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43349- target_stat_values[++index] = atomic_read(&pau_qps_created);
43350- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43351+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43352+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43353 }
43354
43355 /**
43356diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43357index eb62461..2b7fc71 100644
43358--- a/drivers/infiniband/hw/nes/nes_verbs.c
43359+++ b/drivers/infiniband/hw/nes/nes_verbs.c
43360@@ -46,9 +46,9 @@
43361
43362 #include <rdma/ib_umem.h>
43363
43364-atomic_t mod_qp_timouts;
43365-atomic_t qps_created;
43366-atomic_t sw_qps_destroyed;
43367+atomic_unchecked_t mod_qp_timouts;
43368+atomic_unchecked_t qps_created;
43369+atomic_unchecked_t sw_qps_destroyed;
43370
43371 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43372
43373@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43374 if (init_attr->create_flags)
43375 return ERR_PTR(-EINVAL);
43376
43377- atomic_inc(&qps_created);
43378+ atomic_inc_unchecked(&qps_created);
43379 switch (init_attr->qp_type) {
43380 case IB_QPT_RC:
43381 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43382@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43383 struct iw_cm_event cm_event;
43384 int ret = 0;
43385
43386- atomic_inc(&sw_qps_destroyed);
43387+ atomic_inc_unchecked(&sw_qps_destroyed);
43388 nesqp->destroyed = 1;
43389
43390 /* Blow away the connection if it exists. */
43391diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43392index 1946101..09766d2 100644
43393--- a/drivers/infiniband/hw/qib/qib.h
43394+++ b/drivers/infiniband/hw/qib/qib.h
43395@@ -52,6 +52,7 @@
43396 #include <linux/kref.h>
43397 #include <linux/sched.h>
43398 #include <linux/kthread.h>
43399+#include <linux/slab.h>
43400
43401 #include "qib_common.h"
43402 #include "qib_verbs.h"
43403diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43404index 24c41ba..102d71f 100644
43405--- a/drivers/input/gameport/gameport.c
43406+++ b/drivers/input/gameport/gameport.c
43407@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43408 */
43409 static void gameport_init_port(struct gameport *gameport)
43410 {
43411- static atomic_t gameport_no = ATOMIC_INIT(0);
43412+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43413
43414 __module_get(THIS_MODULE);
43415
43416 mutex_init(&gameport->drv_mutex);
43417 device_initialize(&gameport->dev);
43418 dev_set_name(&gameport->dev, "gameport%lu",
43419- (unsigned long)atomic_inc_return(&gameport_no) - 1);
43420+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43421 gameport->dev.bus = &gameport_bus;
43422 gameport->dev.release = gameport_release_port;
43423 if (gameport->parent)
43424diff --git a/drivers/input/input.c b/drivers/input/input.c
43425index 1c4c0db..6f7abe3 100644
43426--- a/drivers/input/input.c
43427+++ b/drivers/input/input.c
43428@@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
43429 */
43430 struct input_dev *input_allocate_device(void)
43431 {
43432- static atomic_t input_no = ATOMIC_INIT(0);
43433+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43434 struct input_dev *dev;
43435
43436 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43437@@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
43438 INIT_LIST_HEAD(&dev->node);
43439
43440 dev_set_name(&dev->dev, "input%ld",
43441- (unsigned long) atomic_inc_return(&input_no) - 1);
43442+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43443
43444 __module_get(THIS_MODULE);
43445 }
43446diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43447index 4a95b22..874c182 100644
43448--- a/drivers/input/joystick/sidewinder.c
43449+++ b/drivers/input/joystick/sidewinder.c
43450@@ -30,6 +30,7 @@
43451 #include <linux/kernel.h>
43452 #include <linux/module.h>
43453 #include <linux/slab.h>
43454+#include <linux/sched.h>
43455 #include <linux/input.h>
43456 #include <linux/gameport.h>
43457 #include <linux/jiffies.h>
43458diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43459index 603fe0d..f63decc 100644
43460--- a/drivers/input/joystick/xpad.c
43461+++ b/drivers/input/joystick/xpad.c
43462@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43463
43464 static int xpad_led_probe(struct usb_xpad *xpad)
43465 {
43466- static atomic_t led_seq = ATOMIC_INIT(0);
43467+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43468 long led_no;
43469 struct xpad_led *led;
43470 struct led_classdev *led_cdev;
43471@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43472 if (!led)
43473 return -ENOMEM;
43474
43475- led_no = (long)atomic_inc_return(&led_seq) - 1;
43476+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43477
43478 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43479 led->xpad = xpad;
43480diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43481index e204f26..8459f15 100644
43482--- a/drivers/input/misc/ims-pcu.c
43483+++ b/drivers/input/misc/ims-pcu.c
43484@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43485
43486 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43487 {
43488- static atomic_t device_no = ATOMIC_INIT(0);
43489+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43490
43491 const struct ims_pcu_device_info *info;
43492 u8 device_id;
43493@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43494 }
43495
43496 /* Device appears to be operable, complete initialization */
43497- pcu->device_no = atomic_inc_return(&device_no) - 1;
43498+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43499
43500 error = ims_pcu_setup_backlight(pcu);
43501 if (error)
43502diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43503index 2f0b39d..7370f13 100644
43504--- a/drivers/input/mouse/psmouse.h
43505+++ b/drivers/input/mouse/psmouse.h
43506@@ -116,7 +116,7 @@ struct psmouse_attribute {
43507 ssize_t (*set)(struct psmouse *psmouse, void *data,
43508 const char *buf, size_t count);
43509 bool protect;
43510-};
43511+} __do_const;
43512 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43513
43514 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43515diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43516index b604564..3f14ae4 100644
43517--- a/drivers/input/mousedev.c
43518+++ b/drivers/input/mousedev.c
43519@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43520
43521 spin_unlock_irq(&client->packet_lock);
43522
43523- if (copy_to_user(buffer, data, count))
43524+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
43525 return -EFAULT;
43526
43527 return count;
43528diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43529index b29134d..394deb0 100644
43530--- a/drivers/input/serio/serio.c
43531+++ b/drivers/input/serio/serio.c
43532@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43533 */
43534 static void serio_init_port(struct serio *serio)
43535 {
43536- static atomic_t serio_no = ATOMIC_INIT(0);
43537+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43538
43539 __module_get(THIS_MODULE);
43540
43541@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43542 mutex_init(&serio->drv_mutex);
43543 device_initialize(&serio->dev);
43544 dev_set_name(&serio->dev, "serio%ld",
43545- (long)atomic_inc_return(&serio_no) - 1);
43546+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
43547 serio->dev.bus = &serio_bus;
43548 serio->dev.release = serio_release_port;
43549 serio->dev.groups = serio_device_attr_groups;
43550diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43551index c9a02fe..0debc75 100644
43552--- a/drivers/input/serio/serio_raw.c
43553+++ b/drivers/input/serio/serio_raw.c
43554@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43555
43556 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43557 {
43558- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43559+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43560 struct serio_raw *serio_raw;
43561 int err;
43562
43563@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43564 }
43565
43566 snprintf(serio_raw->name, sizeof(serio_raw->name),
43567- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43568+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43569 kref_init(&serio_raw->kref);
43570 INIT_LIST_HEAD(&serio_raw->client_list);
43571 init_waitqueue_head(&serio_raw->wait);
43572diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43573index e5555fc..937986d 100644
43574--- a/drivers/iommu/iommu.c
43575+++ b/drivers/iommu/iommu.c
43576@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43577 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43578 {
43579 bus_register_notifier(bus, &iommu_bus_nb);
43580- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43581+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43582 }
43583
43584 /**
43585diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43586index 228632c9..edfe331 100644
43587--- a/drivers/iommu/irq_remapping.c
43588+++ b/drivers/iommu/irq_remapping.c
43589@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43590 void panic_if_irq_remap(const char *msg)
43591 {
43592 if (irq_remapping_enabled)
43593- panic(msg);
43594+ panic("%s", msg);
43595 }
43596
43597 static void ir_ack_apic_edge(struct irq_data *data)
43598@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43599
43600 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43601 {
43602- chip->irq_print_chip = ir_print_prefix;
43603- chip->irq_ack = ir_ack_apic_edge;
43604- chip->irq_eoi = ir_ack_apic_level;
43605- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43606+ pax_open_kernel();
43607+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43608+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43609+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43610+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43611+ pax_close_kernel();
43612 }
43613
43614 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43615diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43616index ac2d41b..c657aa4 100644
43617--- a/drivers/irqchip/irq-gic.c
43618+++ b/drivers/irqchip/irq-gic.c
43619@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43620 * Supported arch specific GIC irq extension.
43621 * Default make them NULL.
43622 */
43623-struct irq_chip gic_arch_extn = {
43624+irq_chip_no_const gic_arch_extn = {
43625 .irq_eoi = NULL,
43626 .irq_mask = NULL,
43627 .irq_unmask = NULL,
43628@@ -336,7 +336,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43629 chained_irq_exit(chip, desc);
43630 }
43631
43632-static struct irq_chip gic_chip = {
43633+static irq_chip_no_const gic_chip __read_only = {
43634 .name = "GIC",
43635 .irq_mask = gic_mask_irq,
43636 .irq_unmask = gic_unmask_irq,
43637diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43638index 8777065..a4a9967 100644
43639--- a/drivers/irqchip/irq-renesas-irqc.c
43640+++ b/drivers/irqchip/irq-renesas-irqc.c
43641@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43642 struct irqc_priv *p;
43643 struct resource *io;
43644 struct resource *irq;
43645- struct irq_chip *irq_chip;
43646+ irq_chip_no_const *irq_chip;
43647 const char *name = dev_name(&pdev->dev);
43648 int ret;
43649 int k;
43650diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43651index ac6f72b..81150f2 100644
43652--- a/drivers/isdn/capi/capi.c
43653+++ b/drivers/isdn/capi/capi.c
43654@@ -81,8 +81,8 @@ struct capiminor {
43655
43656 struct capi20_appl *ap;
43657 u32 ncci;
43658- atomic_t datahandle;
43659- atomic_t msgid;
43660+ atomic_unchecked_t datahandle;
43661+ atomic_unchecked_t msgid;
43662
43663 struct tty_port port;
43664 int ttyinstop;
43665@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43666 capimsg_setu16(s, 2, mp->ap->applid);
43667 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43668 capimsg_setu8 (s, 5, CAPI_RESP);
43669- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43670+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43671 capimsg_setu32(s, 8, mp->ncci);
43672 capimsg_setu16(s, 12, datahandle);
43673 }
43674@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43675 mp->outbytes -= len;
43676 spin_unlock_bh(&mp->outlock);
43677
43678- datahandle = atomic_inc_return(&mp->datahandle);
43679+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43680 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43681 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43682 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43683 capimsg_setu16(skb->data, 2, mp->ap->applid);
43684 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43685 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43686- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43687+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43688 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43689 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43690 capimsg_setu16(skb->data, 16, len); /* Data length */
43691diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43692index c44950d..10ac276 100644
43693--- a/drivers/isdn/gigaset/bas-gigaset.c
43694+++ b/drivers/isdn/gigaset/bas-gigaset.c
43695@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43696
43697
43698 static const struct gigaset_ops gigops = {
43699- gigaset_write_cmd,
43700- gigaset_write_room,
43701- gigaset_chars_in_buffer,
43702- gigaset_brkchars,
43703- gigaset_init_bchannel,
43704- gigaset_close_bchannel,
43705- gigaset_initbcshw,
43706- gigaset_freebcshw,
43707- gigaset_reinitbcshw,
43708- gigaset_initcshw,
43709- gigaset_freecshw,
43710- gigaset_set_modem_ctrl,
43711- gigaset_baud_rate,
43712- gigaset_set_line_ctrl,
43713- gigaset_isoc_send_skb,
43714- gigaset_isoc_input,
43715+ .write_cmd = gigaset_write_cmd,
43716+ .write_room = gigaset_write_room,
43717+ .chars_in_buffer = gigaset_chars_in_buffer,
43718+ .brkchars = gigaset_brkchars,
43719+ .init_bchannel = gigaset_init_bchannel,
43720+ .close_bchannel = gigaset_close_bchannel,
43721+ .initbcshw = gigaset_initbcshw,
43722+ .freebcshw = gigaset_freebcshw,
43723+ .reinitbcshw = gigaset_reinitbcshw,
43724+ .initcshw = gigaset_initcshw,
43725+ .freecshw = gigaset_freecshw,
43726+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43727+ .baud_rate = gigaset_baud_rate,
43728+ .set_line_ctrl = gigaset_set_line_ctrl,
43729+ .send_skb = gigaset_isoc_send_skb,
43730+ .handle_input = gigaset_isoc_input,
43731 };
43732
43733 /* bas_gigaset_init
43734diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43735index 600c79b..3752bab 100644
43736--- a/drivers/isdn/gigaset/interface.c
43737+++ b/drivers/isdn/gigaset/interface.c
43738@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43739 }
43740 tty->driver_data = cs;
43741
43742- ++cs->port.count;
43743+ atomic_inc(&cs->port.count);
43744
43745- if (cs->port.count == 1) {
43746+ if (atomic_read(&cs->port.count) == 1) {
43747 tty_port_tty_set(&cs->port, tty);
43748 cs->port.low_latency = 1;
43749 }
43750@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43751
43752 if (!cs->connected)
43753 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43754- else if (!cs->port.count)
43755+ else if (!atomic_read(&cs->port.count))
43756 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43757- else if (!--cs->port.count)
43758+ else if (!atomic_dec_return(&cs->port.count))
43759 tty_port_tty_set(&cs->port, NULL);
43760
43761 mutex_unlock(&cs->mutex);
43762diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43763index 8c91fd5..14f13ce 100644
43764--- a/drivers/isdn/gigaset/ser-gigaset.c
43765+++ b/drivers/isdn/gigaset/ser-gigaset.c
43766@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43767 }
43768
43769 static const struct gigaset_ops ops = {
43770- gigaset_write_cmd,
43771- gigaset_write_room,
43772- gigaset_chars_in_buffer,
43773- gigaset_brkchars,
43774- gigaset_init_bchannel,
43775- gigaset_close_bchannel,
43776- gigaset_initbcshw,
43777- gigaset_freebcshw,
43778- gigaset_reinitbcshw,
43779- gigaset_initcshw,
43780- gigaset_freecshw,
43781- gigaset_set_modem_ctrl,
43782- gigaset_baud_rate,
43783- gigaset_set_line_ctrl,
43784- gigaset_m10x_send_skb, /* asyncdata.c */
43785- gigaset_m10x_input, /* asyncdata.c */
43786+ .write_cmd = gigaset_write_cmd,
43787+ .write_room = gigaset_write_room,
43788+ .chars_in_buffer = gigaset_chars_in_buffer,
43789+ .brkchars = gigaset_brkchars,
43790+ .init_bchannel = gigaset_init_bchannel,
43791+ .close_bchannel = gigaset_close_bchannel,
43792+ .initbcshw = gigaset_initbcshw,
43793+ .freebcshw = gigaset_freebcshw,
43794+ .reinitbcshw = gigaset_reinitbcshw,
43795+ .initcshw = gigaset_initcshw,
43796+ .freecshw = gigaset_freecshw,
43797+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43798+ .baud_rate = gigaset_baud_rate,
43799+ .set_line_ctrl = gigaset_set_line_ctrl,
43800+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43801+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43802 };
43803
43804
43805diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43806index d0a41cb..b953e50 100644
43807--- a/drivers/isdn/gigaset/usb-gigaset.c
43808+++ b/drivers/isdn/gigaset/usb-gigaset.c
43809@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43810 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43811 memcpy(cs->hw.usb->bchars, buf, 6);
43812 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43813- 0, 0, &buf, 6, 2000);
43814+ 0, 0, buf, 6, 2000);
43815 }
43816
43817 static void gigaset_freebcshw(struct bc_state *bcs)
43818@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43819 }
43820
43821 static const struct gigaset_ops ops = {
43822- gigaset_write_cmd,
43823- gigaset_write_room,
43824- gigaset_chars_in_buffer,
43825- gigaset_brkchars,
43826- gigaset_init_bchannel,
43827- gigaset_close_bchannel,
43828- gigaset_initbcshw,
43829- gigaset_freebcshw,
43830- gigaset_reinitbcshw,
43831- gigaset_initcshw,
43832- gigaset_freecshw,
43833- gigaset_set_modem_ctrl,
43834- gigaset_baud_rate,
43835- gigaset_set_line_ctrl,
43836- gigaset_m10x_send_skb,
43837- gigaset_m10x_input,
43838+ .write_cmd = gigaset_write_cmd,
43839+ .write_room = gigaset_write_room,
43840+ .chars_in_buffer = gigaset_chars_in_buffer,
43841+ .brkchars = gigaset_brkchars,
43842+ .init_bchannel = gigaset_init_bchannel,
43843+ .close_bchannel = gigaset_close_bchannel,
43844+ .initbcshw = gigaset_initbcshw,
43845+ .freebcshw = gigaset_freebcshw,
43846+ .reinitbcshw = gigaset_reinitbcshw,
43847+ .initcshw = gigaset_initcshw,
43848+ .freecshw = gigaset_freecshw,
43849+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43850+ .baud_rate = gigaset_baud_rate,
43851+ .set_line_ctrl = gigaset_set_line_ctrl,
43852+ .send_skb = gigaset_m10x_send_skb,
43853+ .handle_input = gigaset_m10x_input,
43854 };
43855
43856 /*
43857diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43858index 4d9b195..455075c 100644
43859--- a/drivers/isdn/hardware/avm/b1.c
43860+++ b/drivers/isdn/hardware/avm/b1.c
43861@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43862 }
43863 if (left) {
43864 if (t4file->user) {
43865- if (copy_from_user(buf, dp, left))
43866+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43867 return -EFAULT;
43868 } else {
43869 memcpy(buf, dp, left);
43870@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43871 }
43872 if (left) {
43873 if (config->user) {
43874- if (copy_from_user(buf, dp, left))
43875+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43876 return -EFAULT;
43877 } else {
43878 memcpy(buf, dp, left);
43879diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43880index 9bb12ba..d4262f7 100644
43881--- a/drivers/isdn/i4l/isdn_common.c
43882+++ b/drivers/isdn/i4l/isdn_common.c
43883@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43884 } else
43885 return -EINVAL;
43886 case IIOCDBGVAR:
43887+ if (!capable(CAP_SYS_RAWIO))
43888+ return -EPERM;
43889 if (arg) {
43890 if (copy_to_user(argp, &dev, sizeof(ulong)))
43891 return -EFAULT;
43892diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43893index 91d5730..336523e 100644
43894--- a/drivers/isdn/i4l/isdn_concap.c
43895+++ b/drivers/isdn/i4l/isdn_concap.c
43896@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43897 }
43898
43899 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43900- &isdn_concap_dl_data_req,
43901- &isdn_concap_dl_connect_req,
43902- &isdn_concap_dl_disconn_req
43903+ .data_req = &isdn_concap_dl_data_req,
43904+ .connect_req = &isdn_concap_dl_connect_req,
43905+ .disconn_req = &isdn_concap_dl_disconn_req
43906 };
43907
43908 /* The following should better go into a dedicated source file such that
43909diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43910index 3c5f249..5fac4d0 100644
43911--- a/drivers/isdn/i4l/isdn_tty.c
43912+++ b/drivers/isdn/i4l/isdn_tty.c
43913@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43914
43915 #ifdef ISDN_DEBUG_MODEM_OPEN
43916 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43917- port->count);
43918+ atomic_read(&port->count));
43919 #endif
43920- port->count++;
43921+ atomic_inc(&port->count);
43922 port->tty = tty;
43923 /*
43924 * Start up serial port
43925@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43926 #endif
43927 return;
43928 }
43929- if ((tty->count == 1) && (port->count != 1)) {
43930+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43931 /*
43932 * Uh, oh. tty->count is 1, which means that the tty
43933 * structure will be freed. Info->count should always
43934@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43935 * serial port won't be shutdown.
43936 */
43937 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43938- "info->count is %d\n", port->count);
43939- port->count = 1;
43940+ "info->count is %d\n", atomic_read(&port->count));
43941+ atomic_set(&port->count, 1);
43942 }
43943- if (--port->count < 0) {
43944+ if (atomic_dec_return(&port->count) < 0) {
43945 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43946- info->line, port->count);
43947- port->count = 0;
43948+ info->line, atomic_read(&port->count));
43949+ atomic_set(&port->count, 0);
43950 }
43951- if (port->count) {
43952+ if (atomic_read(&port->count)) {
43953 #ifdef ISDN_DEBUG_MODEM_OPEN
43954 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43955 #endif
43956@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43957 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43958 return;
43959 isdn_tty_shutdown(info);
43960- port->count = 0;
43961+ atomic_set(&port->count, 0);
43962 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43963 port->tty = NULL;
43964 wake_up_interruptible(&port->open_wait);
43965@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43966 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43967 modem_info *info = &dev->mdm.info[i];
43968
43969- if (info->port.count == 0)
43970+ if (atomic_read(&info->port.count) == 0)
43971 continue;
43972 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43973 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43974diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43975index e2d4e58..40cd045 100644
43976--- a/drivers/isdn/i4l/isdn_x25iface.c
43977+++ b/drivers/isdn/i4l/isdn_x25iface.c
43978@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43979
43980
43981 static struct concap_proto_ops ix25_pops = {
43982- &isdn_x25iface_proto_new,
43983- &isdn_x25iface_proto_del,
43984- &isdn_x25iface_proto_restart,
43985- &isdn_x25iface_proto_close,
43986- &isdn_x25iface_xmit,
43987- &isdn_x25iface_receive,
43988- &isdn_x25iface_connect_ind,
43989- &isdn_x25iface_disconn_ind
43990+ .proto_new = &isdn_x25iface_proto_new,
43991+ .proto_del = &isdn_x25iface_proto_del,
43992+ .restart = &isdn_x25iface_proto_restart,
43993+ .close = &isdn_x25iface_proto_close,
43994+ .encap_and_xmit = &isdn_x25iface_xmit,
43995+ .data_ind = &isdn_x25iface_receive,
43996+ .connect_ind = &isdn_x25iface_connect_ind,
43997+ .disconn_ind = &isdn_x25iface_disconn_ind
43998 };
43999
44000 /* error message helper function */
44001diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44002index 53d487f..cae33fe 100644
44003--- a/drivers/isdn/icn/icn.c
44004+++ b/drivers/isdn/icn/icn.c
44005@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44006 if (count > len)
44007 count = len;
44008 if (user) {
44009- if (copy_from_user(msg, buf, count))
44010+ if (count > sizeof msg || copy_from_user(msg, buf, count))
44011 return -EFAULT;
44012 } else
44013 memcpy(msg, buf, count);
44014@@ -1155,7 +1155,7 @@ icn_command(isdn_ctrl *c, icn_card *card)
44015 ulong a;
44016 ulong flags;
44017 int i;
44018- char cbuf[60];
44019+ char cbuf[80];
44020 isdn_ctrl cmd;
44021 icn_cdef cdef;
44022 char __user *arg;
44023@@ -1309,7 +1309,6 @@ icn_command(isdn_ctrl *c, icn_card *card)
44024 break;
44025 if ((c->arg & 255) < ICN_BCH) {
44026 char *p;
44027- char dial[50];
44028 char dcode[4];
44029
44030 a = c->arg;
44031@@ -1321,10 +1320,10 @@ icn_command(isdn_ctrl *c, icn_card *card)
44032 } else
44033 /* Normal Dial */
44034 strcpy(dcode, "CAL");
44035- strcpy(dial, p);
44036- sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
44037- dcode, dial, c->parm.setup.si1,
44038- c->parm.setup.si2, c->parm.setup.eazmsn);
44039+ snprintf(cbuf, sizeof(cbuf),
44040+ "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
44041+ dcode, p, c->parm.setup.si1,
44042+ c->parm.setup.si2, c->parm.setup.eazmsn);
44043 i = icn_writecmd(cbuf, strlen(cbuf), 0, card);
44044 }
44045 break;
44046diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44047index a4f05c5..1433bc5 100644
44048--- a/drivers/isdn/mISDN/dsp_cmx.c
44049+++ b/drivers/isdn/mISDN/dsp_cmx.c
44050@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44051 static u16 dsp_count; /* last sample count */
44052 static int dsp_count_valid; /* if we have last sample count */
44053
44054-void
44055+void __intentional_overflow(-1)
44056 dsp_cmx_send(void *arg)
44057 {
44058 struct dsp_conf *conf;
44059diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44060index d93e245..e7ece6b 100644
44061--- a/drivers/leds/leds-clevo-mail.c
44062+++ b/drivers/leds/leds-clevo-mail.c
44063@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44064 * detected as working, but in reality it is not) as low as
44065 * possible.
44066 */
44067-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44068+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44069 {
44070 .callback = clevo_mail_led_dmi_callback,
44071 .ident = "Clevo D410J",
44072diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44073index 5b8f938..b73d657 100644
44074--- a/drivers/leds/leds-ss4200.c
44075+++ b/drivers/leds/leds-ss4200.c
44076@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44077 * detected as working, but in reality it is not) as low as
44078 * possible.
44079 */
44080-static struct dmi_system_id nas_led_whitelist[] __initdata = {
44081+static struct dmi_system_id nas_led_whitelist[] __initconst = {
44082 {
44083 .callback = ss4200_led_dmi_callback,
44084 .ident = "Intel SS4200-E",
44085diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44086index 0bf1e4e..b4bf44e 100644
44087--- a/drivers/lguest/core.c
44088+++ b/drivers/lguest/core.c
44089@@ -97,9 +97,17 @@ static __init int map_switcher(void)
44090 * The end address needs +1 because __get_vm_area allocates an
44091 * extra guard page, so we need space for that.
44092 */
44093+
44094+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44095+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44096+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44097+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44098+#else
44099 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44100 VM_ALLOC, switcher_addr, switcher_addr
44101 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44102+#endif
44103+
44104 if (!switcher_vma) {
44105 err = -ENOMEM;
44106 printk("lguest: could not map switcher pages high\n");
44107@@ -124,7 +132,7 @@ static __init int map_switcher(void)
44108 * Now the Switcher is mapped at the right address, we can't fail!
44109 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44110 */
44111- memcpy(switcher_vma->addr, start_switcher_text,
44112+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44113 end_switcher_text - start_switcher_text);
44114
44115 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44116diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44117index bfb39bb..08a603b 100644
44118--- a/drivers/lguest/page_tables.c
44119+++ b/drivers/lguest/page_tables.c
44120@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44121 /*:*/
44122
44123 #ifdef CONFIG_X86_PAE
44124-static void release_pmd(pmd_t *spmd)
44125+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44126 {
44127 /* If the entry's not present, there's nothing to release. */
44128 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44129diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44130index 922a1ac..9dd0c2a 100644
44131--- a/drivers/lguest/x86/core.c
44132+++ b/drivers/lguest/x86/core.c
44133@@ -59,7 +59,7 @@ static struct {
44134 /* Offset from where switcher.S was compiled to where we've copied it */
44135 static unsigned long switcher_offset(void)
44136 {
44137- return switcher_addr - (unsigned long)start_switcher_text;
44138+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44139 }
44140
44141 /* This cpu's struct lguest_pages (after the Switcher text page) */
44142@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44143 * These copies are pretty cheap, so we do them unconditionally: */
44144 /* Save the current Host top-level page directory.
44145 */
44146+
44147+#ifdef CONFIG_PAX_PER_CPU_PGD
44148+ pages->state.host_cr3 = read_cr3();
44149+#else
44150 pages->state.host_cr3 = __pa(current->mm->pgd);
44151+#endif
44152+
44153 /*
44154 * Set up the Guest's page tables to see this CPU's pages (and no
44155 * other CPU's pages).
44156@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44157 * compiled-in switcher code and the high-mapped copy we just made.
44158 */
44159 for (i = 0; i < IDT_ENTRIES; i++)
44160- default_idt_entries[i] += switcher_offset();
44161+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44162
44163 /*
44164 * Set up the Switcher's per-cpu areas.
44165@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44166 * it will be undisturbed when we switch. To change %cs and jump we
44167 * need this structure to feed to Intel's "lcall" instruction.
44168 */
44169- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44170+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44171 lguest_entry.segment = LGUEST_CS;
44172
44173 /*
44174diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44175index 40634b0..4f5855e 100644
44176--- a/drivers/lguest/x86/switcher_32.S
44177+++ b/drivers/lguest/x86/switcher_32.S
44178@@ -87,6 +87,7 @@
44179 #include <asm/page.h>
44180 #include <asm/segment.h>
44181 #include <asm/lguest.h>
44182+#include <asm/processor-flags.h>
44183
44184 // We mark the start of the code to copy
44185 // It's placed in .text tho it's never run here
44186@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44187 // Changes type when we load it: damn Intel!
44188 // For after we switch over our page tables
44189 // That entry will be read-only: we'd crash.
44190+
44191+#ifdef CONFIG_PAX_KERNEXEC
44192+ mov %cr0, %edx
44193+ xor $X86_CR0_WP, %edx
44194+ mov %edx, %cr0
44195+#endif
44196+
44197 movl $(GDT_ENTRY_TSS*8), %edx
44198 ltr %dx
44199
44200@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44201 // Let's clear it again for our return.
44202 // The GDT descriptor of the Host
44203 // Points to the table after two "size" bytes
44204- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44205+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44206 // Clear "used" from type field (byte 5, bit 2)
44207- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44208+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44209+
44210+#ifdef CONFIG_PAX_KERNEXEC
44211+ mov %cr0, %eax
44212+ xor $X86_CR0_WP, %eax
44213+ mov %eax, %cr0
44214+#endif
44215
44216 // Once our page table's switched, the Guest is live!
44217 // The Host fades as we run this final step.
44218@@ -295,13 +309,12 @@ deliver_to_host:
44219 // I consulted gcc, and it gave
44220 // These instructions, which I gladly credit:
44221 leal (%edx,%ebx,8), %eax
44222- movzwl (%eax),%edx
44223- movl 4(%eax), %eax
44224- xorw %ax, %ax
44225- orl %eax, %edx
44226+ movl 4(%eax), %edx
44227+ movw (%eax), %dx
44228 // Now the address of the handler's in %edx
44229 // We call it now: its "iret" drops us home.
44230- jmp *%edx
44231+ ljmp $__KERNEL_CS, $1f
44232+1: jmp *%edx
44233
44234 // Every interrupt can come to us here
44235 // But we must truly tell each apart.
44236diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44237index 7ef7461..5a09dac 100644
44238--- a/drivers/md/bcache/closure.h
44239+++ b/drivers/md/bcache/closure.h
44240@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44241 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44242 struct workqueue_struct *wq)
44243 {
44244- BUG_ON(object_is_on_stack(cl));
44245+ BUG_ON(object_starts_on_stack(cl));
44246 closure_set_ip(cl);
44247 cl->fn = fn;
44248 cl->wq = wq;
44249diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44250index 4195a01..42527ac 100644
44251--- a/drivers/md/bitmap.c
44252+++ b/drivers/md/bitmap.c
44253@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44254 chunk_kb ? "KB" : "B");
44255 if (bitmap->storage.file) {
44256 seq_printf(seq, ", file: ");
44257- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44258+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44259 }
44260
44261 seq_printf(seq, "\n");
44262diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44263index 5152142..623d141 100644
44264--- a/drivers/md/dm-ioctl.c
44265+++ b/drivers/md/dm-ioctl.c
44266@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44267 cmd == DM_LIST_VERSIONS_CMD)
44268 return 0;
44269
44270- if ((cmd == DM_DEV_CREATE_CMD)) {
44271+ if (cmd == DM_DEV_CREATE_CMD) {
44272 if (!*param->name) {
44273 DMWARN("name not supplied when creating device");
44274 return -EINVAL;
44275diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44276index 7dfdb5c..4caada6 100644
44277--- a/drivers/md/dm-raid1.c
44278+++ b/drivers/md/dm-raid1.c
44279@@ -40,7 +40,7 @@ enum dm_raid1_error {
44280
44281 struct mirror {
44282 struct mirror_set *ms;
44283- atomic_t error_count;
44284+ atomic_unchecked_t error_count;
44285 unsigned long error_type;
44286 struct dm_dev *dev;
44287 sector_t offset;
44288@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44289 struct mirror *m;
44290
44291 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44292- if (!atomic_read(&m->error_count))
44293+ if (!atomic_read_unchecked(&m->error_count))
44294 return m;
44295
44296 return NULL;
44297@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44298 * simple way to tell if a device has encountered
44299 * errors.
44300 */
44301- atomic_inc(&m->error_count);
44302+ atomic_inc_unchecked(&m->error_count);
44303
44304 if (test_and_set_bit(error_type, &m->error_type))
44305 return;
44306@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44307 struct mirror *m = get_default_mirror(ms);
44308
44309 do {
44310- if (likely(!atomic_read(&m->error_count)))
44311+ if (likely(!atomic_read_unchecked(&m->error_count)))
44312 return m;
44313
44314 if (m-- == ms->mirror)
44315@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44316 {
44317 struct mirror *default_mirror = get_default_mirror(m->ms);
44318
44319- return !atomic_read(&default_mirror->error_count);
44320+ return !atomic_read_unchecked(&default_mirror->error_count);
44321 }
44322
44323 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44324@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44325 */
44326 if (likely(region_in_sync(ms, region, 1)))
44327 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44328- else if (m && atomic_read(&m->error_count))
44329+ else if (m && atomic_read_unchecked(&m->error_count))
44330 m = NULL;
44331
44332 if (likely(m))
44333@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44334 }
44335
44336 ms->mirror[mirror].ms = ms;
44337- atomic_set(&(ms->mirror[mirror].error_count), 0);
44338+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44339 ms->mirror[mirror].error_type = 0;
44340 ms->mirror[mirror].offset = offset;
44341
44342@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44343 */
44344 static char device_status_char(struct mirror *m)
44345 {
44346- if (!atomic_read(&(m->error_count)))
44347+ if (!atomic_read_unchecked(&(m->error_count)))
44348 return 'A';
44349
44350 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44351diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44352index 28a9012..9c0f6a5 100644
44353--- a/drivers/md/dm-stats.c
44354+++ b/drivers/md/dm-stats.c
44355@@ -382,7 +382,7 @@ do_sync_free:
44356 synchronize_rcu_expedited();
44357 dm_stat_free(&s->rcu_head);
44358 } else {
44359- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44360+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44361 call_rcu(&s->rcu_head, dm_stat_free);
44362 }
44363 return 0;
44364@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44365 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44366 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44367 ));
44368- ACCESS_ONCE(last->last_sector) = end_sector;
44369- ACCESS_ONCE(last->last_rw) = bi_rw;
44370+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
44371+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44372 }
44373
44374 rcu_read_lock();
44375diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44376index d1600d2..4c3af3a 100644
44377--- a/drivers/md/dm-stripe.c
44378+++ b/drivers/md/dm-stripe.c
44379@@ -21,7 +21,7 @@ struct stripe {
44380 struct dm_dev *dev;
44381 sector_t physical_start;
44382
44383- atomic_t error_count;
44384+ atomic_unchecked_t error_count;
44385 };
44386
44387 struct stripe_c {
44388@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44389 kfree(sc);
44390 return r;
44391 }
44392- atomic_set(&(sc->stripe[i].error_count), 0);
44393+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44394 }
44395
44396 ti->private = sc;
44397@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44398 DMEMIT("%d ", sc->stripes);
44399 for (i = 0; i < sc->stripes; i++) {
44400 DMEMIT("%s ", sc->stripe[i].dev->name);
44401- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44402+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44403 'D' : 'A';
44404 }
44405 buffer[i] = '\0';
44406@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44407 */
44408 for (i = 0; i < sc->stripes; i++)
44409 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44410- atomic_inc(&(sc->stripe[i].error_count));
44411- if (atomic_read(&(sc->stripe[i].error_count)) <
44412+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
44413+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44414 DM_IO_ERROR_THRESHOLD)
44415 schedule_work(&sc->trigger_event);
44416 }
44417diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44418index 6a7f2b8..fea0bde 100644
44419--- a/drivers/md/dm-table.c
44420+++ b/drivers/md/dm-table.c
44421@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
44422 static int open_dev(struct dm_dev_internal *d, dev_t dev,
44423 struct mapped_device *md)
44424 {
44425- static char *_claim_ptr = "I belong to device-mapper";
44426+ static char _claim_ptr[] = "I belong to device-mapper";
44427 struct block_device *bdev;
44428
44429 int r;
44430@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44431 if (!dev_size)
44432 return 0;
44433
44434- if ((start >= dev_size) || (start + len > dev_size)) {
44435+ if ((start >= dev_size) || (len > dev_size - start)) {
44436 DMWARN("%s: %s too small for target: "
44437 "start=%llu, len=%llu, dev_size=%llu",
44438 dm_device_name(ti->table->md), bdevname(bdev, b),
44439diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44440index b086a94..74cb67e 100644
44441--- a/drivers/md/dm-thin-metadata.c
44442+++ b/drivers/md/dm-thin-metadata.c
44443@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44444 {
44445 pmd->info.tm = pmd->tm;
44446 pmd->info.levels = 2;
44447- pmd->info.value_type.context = pmd->data_sm;
44448+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44449 pmd->info.value_type.size = sizeof(__le64);
44450 pmd->info.value_type.inc = data_block_inc;
44451 pmd->info.value_type.dec = data_block_dec;
44452@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44453
44454 pmd->bl_info.tm = pmd->tm;
44455 pmd->bl_info.levels = 1;
44456- pmd->bl_info.value_type.context = pmd->data_sm;
44457+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44458 pmd->bl_info.value_type.size = sizeof(__le64);
44459 pmd->bl_info.value_type.inc = data_block_inc;
44460 pmd->bl_info.value_type.dec = data_block_dec;
44461diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44462index 8c53b09..f1fb2b0 100644
44463--- a/drivers/md/dm.c
44464+++ b/drivers/md/dm.c
44465@@ -185,9 +185,9 @@ struct mapped_device {
44466 /*
44467 * Event handling.
44468 */
44469- atomic_t event_nr;
44470+ atomic_unchecked_t event_nr;
44471 wait_queue_head_t eventq;
44472- atomic_t uevent_seq;
44473+ atomic_unchecked_t uevent_seq;
44474 struct list_head uevent_list;
44475 spinlock_t uevent_lock; /* Protect access to uevent_list */
44476
44477@@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
44478 spin_lock_init(&md->deferred_lock);
44479 atomic_set(&md->holders, 1);
44480 atomic_set(&md->open_count, 0);
44481- atomic_set(&md->event_nr, 0);
44482- atomic_set(&md->uevent_seq, 0);
44483+ atomic_set_unchecked(&md->event_nr, 0);
44484+ atomic_set_unchecked(&md->uevent_seq, 0);
44485 INIT_LIST_HEAD(&md->uevent_list);
44486 spin_lock_init(&md->uevent_lock);
44487
44488@@ -2043,7 +2043,7 @@ static void event_callback(void *context)
44489
44490 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44491
44492- atomic_inc(&md->event_nr);
44493+ atomic_inc_unchecked(&md->event_nr);
44494 wake_up(&md->eventq);
44495 }
44496
44497@@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44498
44499 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44500 {
44501- return atomic_add_return(1, &md->uevent_seq);
44502+ return atomic_add_return_unchecked(1, &md->uevent_seq);
44503 }
44504
44505 uint32_t dm_get_event_nr(struct mapped_device *md)
44506 {
44507- return atomic_read(&md->event_nr);
44508+ return atomic_read_unchecked(&md->event_nr);
44509 }
44510
44511 int dm_wait_event(struct mapped_device *md, int event_nr)
44512 {
44513 return wait_event_interruptible(md->eventq,
44514- (event_nr != atomic_read(&md->event_nr)));
44515+ (event_nr != atomic_read_unchecked(&md->event_nr)));
44516 }
44517
44518 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44519diff --git a/drivers/md/md.c b/drivers/md/md.c
44520index 8b013f8..93eed41 100644
44521--- a/drivers/md/md.c
44522+++ b/drivers/md/md.c
44523@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44524 * start build, activate spare
44525 */
44526 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44527-static atomic_t md_event_count;
44528+static atomic_unchecked_t md_event_count;
44529 void md_new_event(struct mddev *mddev)
44530 {
44531- atomic_inc(&md_event_count);
44532+ atomic_inc_unchecked(&md_event_count);
44533 wake_up(&md_event_waiters);
44534 }
44535 EXPORT_SYMBOL_GPL(md_new_event);
44536@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44537 */
44538 static void md_new_event_inintr(struct mddev *mddev)
44539 {
44540- atomic_inc(&md_event_count);
44541+ atomic_inc_unchecked(&md_event_count);
44542 wake_up(&md_event_waiters);
44543 }
44544
44545@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44546 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44547 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44548 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44549- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44550+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44551
44552 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44553 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44554@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44555 else
44556 sb->resync_offset = cpu_to_le64(0);
44557
44558- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44559+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44560
44561 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44562 sb->size = cpu_to_le64(mddev->dev_sectors);
44563@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44564 static ssize_t
44565 errors_show(struct md_rdev *rdev, char *page)
44566 {
44567- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44568+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44569 }
44570
44571 static ssize_t
44572@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44573 char *e;
44574 unsigned long n = simple_strtoul(buf, &e, 10);
44575 if (*buf && (*e == 0 || *e == '\n')) {
44576- atomic_set(&rdev->corrected_errors, n);
44577+ atomic_set_unchecked(&rdev->corrected_errors, n);
44578 return len;
44579 }
44580 return -EINVAL;
44581@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44582 rdev->sb_loaded = 0;
44583 rdev->bb_page = NULL;
44584 atomic_set(&rdev->nr_pending, 0);
44585- atomic_set(&rdev->read_errors, 0);
44586- atomic_set(&rdev->corrected_errors, 0);
44587+ atomic_set_unchecked(&rdev->read_errors, 0);
44588+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44589
44590 INIT_LIST_HEAD(&rdev->same_set);
44591 init_waitqueue_head(&rdev->blocked_wait);
44592@@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44593
44594 spin_unlock(&pers_lock);
44595 seq_printf(seq, "\n");
44596- seq->poll_event = atomic_read(&md_event_count);
44597+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44598 return 0;
44599 }
44600 if (v == (void*)2) {
44601@@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44602 return error;
44603
44604 seq = file->private_data;
44605- seq->poll_event = atomic_read(&md_event_count);
44606+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44607 return error;
44608 }
44609
44610@@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44611 /* always allow read */
44612 mask = POLLIN | POLLRDNORM;
44613
44614- if (seq->poll_event != atomic_read(&md_event_count))
44615+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44616 mask |= POLLERR | POLLPRI;
44617 return mask;
44618 }
44619@@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44620 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44621 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44622 (int)part_stat_read(&disk->part0, sectors[1]) -
44623- atomic_read(&disk->sync_io);
44624+ atomic_read_unchecked(&disk->sync_io);
44625 /* sync IO will cause sync_io to increase before the disk_stats
44626 * as sync_io is counted when a request starts, and
44627 * disk_stats is counted when it completes.
44628diff --git a/drivers/md/md.h b/drivers/md/md.h
44629index 07bba96..2d6788c 100644
44630--- a/drivers/md/md.h
44631+++ b/drivers/md/md.h
44632@@ -94,13 +94,13 @@ struct md_rdev {
44633 * only maintained for arrays that
44634 * support hot removal
44635 */
44636- atomic_t read_errors; /* number of consecutive read errors that
44637+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44638 * we have tried to ignore.
44639 */
44640 struct timespec last_read_error; /* monotonic time since our
44641 * last read error
44642 */
44643- atomic_t corrected_errors; /* number of corrected read errors,
44644+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44645 * for reporting to userspace and storing
44646 * in superblock.
44647 */
44648@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44649
44650 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44651 {
44652- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44653+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44654 }
44655
44656 struct md_personality
44657diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44658index 786b689..ea8c956 100644
44659--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44660+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44661@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44662 * Flick into a mode where all blocks get allocated in the new area.
44663 */
44664 smm->begin = old_len;
44665- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44666+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44667
44668 /*
44669 * Extend.
44670@@ -710,7 +710,7 @@ out:
44671 /*
44672 * Switch back to normal behaviour.
44673 */
44674- memcpy(sm, &ops, sizeof(*sm));
44675+ memcpy((void *)sm, &ops, sizeof(*sm));
44676 return r;
44677 }
44678
44679diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44680index 3e6d115..ffecdeb 100644
44681--- a/drivers/md/persistent-data/dm-space-map.h
44682+++ b/drivers/md/persistent-data/dm-space-map.h
44683@@ -71,6 +71,7 @@ struct dm_space_map {
44684 dm_sm_threshold_fn fn,
44685 void *context);
44686 };
44687+typedef struct dm_space_map __no_const dm_space_map_no_const;
44688
44689 /*----------------------------------------------------------------*/
44690
44691diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44692index 56e24c0..e1c8e1f 100644
44693--- a/drivers/md/raid1.c
44694+++ b/drivers/md/raid1.c
44695@@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44696 if (r1_sync_page_io(rdev, sect, s,
44697 bio->bi_io_vec[idx].bv_page,
44698 READ) != 0)
44699- atomic_add(s, &rdev->corrected_errors);
44700+ atomic_add_unchecked(s, &rdev->corrected_errors);
44701 }
44702 sectors -= s;
44703 sect += s;
44704@@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44705 test_bit(In_sync, &rdev->flags)) {
44706 if (r1_sync_page_io(rdev, sect, s,
44707 conf->tmppage, READ)) {
44708- atomic_add(s, &rdev->corrected_errors);
44709+ atomic_add_unchecked(s, &rdev->corrected_errors);
44710 printk(KERN_INFO
44711 "md/raid1:%s: read error corrected "
44712 "(%d sectors at %llu on %s)\n",
44713diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44714index cb882aa..9bd076e 100644
44715--- a/drivers/md/raid10.c
44716+++ b/drivers/md/raid10.c
44717@@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
44718 /* The write handler will notice the lack of
44719 * R10BIO_Uptodate and record any errors etc
44720 */
44721- atomic_add(r10_bio->sectors,
44722+ atomic_add_unchecked(r10_bio->sectors,
44723 &conf->mirrors[d].rdev->corrected_errors);
44724
44725 /* for reconstruct, we always reschedule after a read.
44726@@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44727 {
44728 struct timespec cur_time_mon;
44729 unsigned long hours_since_last;
44730- unsigned int read_errors = atomic_read(&rdev->read_errors);
44731+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44732
44733 ktime_get_ts(&cur_time_mon);
44734
44735@@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44736 * overflowing the shift of read_errors by hours_since_last.
44737 */
44738 if (hours_since_last >= 8 * sizeof(read_errors))
44739- atomic_set(&rdev->read_errors, 0);
44740+ atomic_set_unchecked(&rdev->read_errors, 0);
44741 else
44742- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44743+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44744 }
44745
44746 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44747@@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44748 return;
44749
44750 check_decay_read_errors(mddev, rdev);
44751- atomic_inc(&rdev->read_errors);
44752- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44753+ atomic_inc_unchecked(&rdev->read_errors);
44754+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44755 char b[BDEVNAME_SIZE];
44756 bdevname(rdev->bdev, b);
44757
44758@@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44759 "md/raid10:%s: %s: Raid device exceeded "
44760 "read_error threshold [cur %d:max %d]\n",
44761 mdname(mddev), b,
44762- atomic_read(&rdev->read_errors), max_read_errors);
44763+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44764 printk(KERN_NOTICE
44765 "md/raid10:%s: %s: Failing raid device\n",
44766 mdname(mddev), b);
44767@@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44768 sect +
44769 choose_data_offset(r10_bio, rdev)),
44770 bdevname(rdev->bdev, b));
44771- atomic_add(s, &rdev->corrected_errors);
44772+ atomic_add_unchecked(s, &rdev->corrected_errors);
44773 }
44774
44775 rdev_dec_pending(rdev, mddev);
44776diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44777index 16f5c21..522b82e 100644
44778--- a/drivers/md/raid5.c
44779+++ b/drivers/md/raid5.c
44780@@ -1707,6 +1707,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44781 return 1;
44782 }
44783
44784+#ifdef CONFIG_GRKERNSEC_HIDESYM
44785+static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44786+#endif
44787+
44788 static int grow_stripes(struct r5conf *conf, int num)
44789 {
44790 struct kmem_cache *sc;
44791@@ -1718,7 +1722,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44792 "raid%d-%s", conf->level, mdname(conf->mddev));
44793 else
44794 sprintf(conf->cache_name[0],
44795+#ifdef CONFIG_GRKERNSEC_HIDESYM
44796+ "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44797+#else
44798 "raid%d-%p", conf->level, conf->mddev);
44799+#endif
44800 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44801
44802 conf->active_name = 0;
44803@@ -1991,21 +1999,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44804 mdname(conf->mddev), STRIPE_SECTORS,
44805 (unsigned long long)s,
44806 bdevname(rdev->bdev, b));
44807- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44808+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44809 clear_bit(R5_ReadError, &sh->dev[i].flags);
44810 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44811 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44812 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44813
44814- if (atomic_read(&rdev->read_errors))
44815- atomic_set(&rdev->read_errors, 0);
44816+ if (atomic_read_unchecked(&rdev->read_errors))
44817+ atomic_set_unchecked(&rdev->read_errors, 0);
44818 } else {
44819 const char *bdn = bdevname(rdev->bdev, b);
44820 int retry = 0;
44821 int set_bad = 0;
44822
44823 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44824- atomic_inc(&rdev->read_errors);
44825+ atomic_inc_unchecked(&rdev->read_errors);
44826 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44827 printk_ratelimited(
44828 KERN_WARNING
44829@@ -2033,7 +2041,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44830 mdname(conf->mddev),
44831 (unsigned long long)s,
44832 bdn);
44833- } else if (atomic_read(&rdev->read_errors)
44834+ } else if (atomic_read_unchecked(&rdev->read_errors)
44835 > conf->max_nr_stripes)
44836 printk(KERN_WARNING
44837 "md/raid:%s: Too many read errors, failing device %s.\n",
44838diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44839index 983db75..ef9248c 100644
44840--- a/drivers/media/dvb-core/dvbdev.c
44841+++ b/drivers/media/dvb-core/dvbdev.c
44842@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44843 const struct dvb_device *template, void *priv, int type)
44844 {
44845 struct dvb_device *dvbdev;
44846- struct file_operations *dvbdevfops;
44847+ file_operations_no_const *dvbdevfops;
44848 struct device *clsdev;
44849 int minor;
44850 int id;
44851diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44852index 9b6c3bb..baeb5c7 100644
44853--- a/drivers/media/dvb-frontends/dib3000.h
44854+++ b/drivers/media/dvb-frontends/dib3000.h
44855@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44856 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44857 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44858 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44859-};
44860+} __no_const;
44861
44862 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44863 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44864diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44865index ed8cb90..5ef7f79 100644
44866--- a/drivers/media/pci/cx88/cx88-video.c
44867+++ b/drivers/media/pci/cx88/cx88-video.c
44868@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44869
44870 /* ------------------------------------------------------------------ */
44871
44872-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44873-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44874-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44875+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44876+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44877+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44878
44879 module_param_array(video_nr, int, NULL, 0444);
44880 module_param_array(vbi_nr, int, NULL, 0444);
44881diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44882index 802642d..5534900 100644
44883--- a/drivers/media/pci/ivtv/ivtv-driver.c
44884+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44885@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44886 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44887
44888 /* ivtv instance counter */
44889-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44890+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44891
44892 /* Parameter declarations */
44893 static int cardtype[IVTV_MAX_CARDS];
44894diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44895index dfd0a21..6bbb465 100644
44896--- a/drivers/media/platform/omap/omap_vout.c
44897+++ b/drivers/media/platform/omap/omap_vout.c
44898@@ -63,7 +63,6 @@ enum omap_vout_channels {
44899 OMAP_VIDEO2,
44900 };
44901
44902-static struct videobuf_queue_ops video_vbq_ops;
44903 /* Variables configurable through module params*/
44904 static u32 video1_numbuffers = 3;
44905 static u32 video2_numbuffers = 3;
44906@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44907 {
44908 struct videobuf_queue *q;
44909 struct omap_vout_device *vout = NULL;
44910+ static struct videobuf_queue_ops video_vbq_ops = {
44911+ .buf_setup = omap_vout_buffer_setup,
44912+ .buf_prepare = omap_vout_buffer_prepare,
44913+ .buf_release = omap_vout_buffer_release,
44914+ .buf_queue = omap_vout_buffer_queue,
44915+ };
44916
44917 vout = video_drvdata(file);
44918 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44919@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44920 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44921
44922 q = &vout->vbq;
44923- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44924- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44925- video_vbq_ops.buf_release = omap_vout_buffer_release;
44926- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44927 spin_lock_init(&vout->vbq_lock);
44928
44929 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44930diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44931index fb2acc5..a2fcbdc4 100644
44932--- a/drivers/media/platform/s5p-tv/mixer.h
44933+++ b/drivers/media/platform/s5p-tv/mixer.h
44934@@ -156,7 +156,7 @@ struct mxr_layer {
44935 /** layer index (unique identifier) */
44936 int idx;
44937 /** callbacks for layer methods */
44938- struct mxr_layer_ops ops;
44939+ struct mxr_layer_ops *ops;
44940 /** format array */
44941 const struct mxr_format **fmt_array;
44942 /** size of format array */
44943diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44944index 74344c7..a39e70e 100644
44945--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44946+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44947@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44948 {
44949 struct mxr_layer *layer;
44950 int ret;
44951- struct mxr_layer_ops ops = {
44952+ static struct mxr_layer_ops ops = {
44953 .release = mxr_graph_layer_release,
44954 .buffer_set = mxr_graph_buffer_set,
44955 .stream_set = mxr_graph_stream_set,
44956diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44957index b713403..53cb5ad 100644
44958--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44959+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44960@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44961 layer->update_buf = next;
44962 }
44963
44964- layer->ops.buffer_set(layer, layer->update_buf);
44965+ layer->ops->buffer_set(layer, layer->update_buf);
44966
44967 if (done && done != layer->shadow_buf)
44968 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44969diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44970index c5059ba..2649f28 100644
44971--- a/drivers/media/platform/s5p-tv/mixer_video.c
44972+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44973@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44974 layer->geo.src.height = layer->geo.src.full_height;
44975
44976 mxr_geometry_dump(mdev, &layer->geo);
44977- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44978+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44979 mxr_geometry_dump(mdev, &layer->geo);
44980 }
44981
44982@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44983 layer->geo.dst.full_width = mbus_fmt.width;
44984 layer->geo.dst.full_height = mbus_fmt.height;
44985 layer->geo.dst.field = mbus_fmt.field;
44986- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44987+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44988
44989 mxr_geometry_dump(mdev, &layer->geo);
44990 }
44991@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44992 /* set source size to highest accepted value */
44993 geo->src.full_width = max(geo->dst.full_width, pix->width);
44994 geo->src.full_height = max(geo->dst.full_height, pix->height);
44995- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44996+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44997 mxr_geometry_dump(mdev, &layer->geo);
44998 /* set cropping to total visible screen */
44999 geo->src.width = pix->width;
45000@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45001 geo->src.x_offset = 0;
45002 geo->src.y_offset = 0;
45003 /* assure consistency of geometry */
45004- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45005+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45006 mxr_geometry_dump(mdev, &layer->geo);
45007 /* set full size to lowest possible value */
45008 geo->src.full_width = 0;
45009 geo->src.full_height = 0;
45010- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45011+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45012 mxr_geometry_dump(mdev, &layer->geo);
45013
45014 /* returning results */
45015@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45016 target->width = s->r.width;
45017 target->height = s->r.height;
45018
45019- layer->ops.fix_geometry(layer, stage, s->flags);
45020+ layer->ops->fix_geometry(layer, stage, s->flags);
45021
45022 /* retrieve update selection rectangle */
45023 res.left = target->x_offset;
45024@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45025 mxr_output_get(mdev);
45026
45027 mxr_layer_update_output(layer);
45028- layer->ops.format_set(layer);
45029+ layer->ops->format_set(layer);
45030 /* enabling layer in hardware */
45031 spin_lock_irqsave(&layer->enq_slock, flags);
45032 layer->state = MXR_LAYER_STREAMING;
45033 spin_unlock_irqrestore(&layer->enq_slock, flags);
45034
45035- layer->ops.stream_set(layer, MXR_ENABLE);
45036+ layer->ops->stream_set(layer, MXR_ENABLE);
45037 mxr_streamer_get(mdev);
45038
45039 return 0;
45040@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
45041 spin_unlock_irqrestore(&layer->enq_slock, flags);
45042
45043 /* disabling layer in hardware */
45044- layer->ops.stream_set(layer, MXR_DISABLE);
45045+ layer->ops->stream_set(layer, MXR_DISABLE);
45046 /* remove one streamer */
45047 mxr_streamer_put(mdev);
45048 /* allow changes in output configuration */
45049@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45050
45051 void mxr_layer_release(struct mxr_layer *layer)
45052 {
45053- if (layer->ops.release)
45054- layer->ops.release(layer);
45055+ if (layer->ops->release)
45056+ layer->ops->release(layer);
45057 }
45058
45059 void mxr_base_layer_release(struct mxr_layer *layer)
45060@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45061
45062 layer->mdev = mdev;
45063 layer->idx = idx;
45064- layer->ops = *ops;
45065+ layer->ops = ops;
45066
45067 spin_lock_init(&layer->enq_slock);
45068 INIT_LIST_HEAD(&layer->enq_list);
45069diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45070index c9388c4..ce71ece 100644
45071--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45072+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45073@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45074 {
45075 struct mxr_layer *layer;
45076 int ret;
45077- struct mxr_layer_ops ops = {
45078+ static struct mxr_layer_ops ops = {
45079 .release = mxr_vp_layer_release,
45080 .buffer_set = mxr_vp_buffer_set,
45081 .stream_set = mxr_vp_stream_set,
45082diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
45083index 2d4e73b..8b4d5b6 100644
45084--- a/drivers/media/platform/vivi.c
45085+++ b/drivers/media/platform/vivi.c
45086@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
45087 MODULE_LICENSE("Dual BSD/GPL");
45088 MODULE_VERSION(VIVI_VERSION);
45089
45090-static unsigned video_nr = -1;
45091-module_param(video_nr, uint, 0644);
45092+static int video_nr = -1;
45093+module_param(video_nr, int, 0644);
45094 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
45095
45096 static unsigned n_devs = 1;
45097diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45098index 545c04c..a14bded 100644
45099--- a/drivers/media/radio/radio-cadet.c
45100+++ b/drivers/media/radio/radio-cadet.c
45101@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45102 unsigned char readbuf[RDS_BUFFER];
45103 int i = 0;
45104
45105+ if (count > RDS_BUFFER)
45106+ return -EFAULT;
45107 mutex_lock(&dev->lock);
45108 if (dev->rdsstat == 0)
45109 cadet_start_rds(dev);
45110@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45111 while (i < count && dev->rdsin != dev->rdsout)
45112 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45113
45114- if (i && copy_to_user(data, readbuf, i))
45115+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
45116 i = -EFAULT;
45117 unlock:
45118 mutex_unlock(&dev->lock);
45119diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45120index 5236035..c622c74 100644
45121--- a/drivers/media/radio/radio-maxiradio.c
45122+++ b/drivers/media/radio/radio-maxiradio.c
45123@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45124 /* TEA5757 pin mappings */
45125 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45126
45127-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45128+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45129
45130 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45131 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45132diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45133index 050b3bb..79f62b9 100644
45134--- a/drivers/media/radio/radio-shark.c
45135+++ b/drivers/media/radio/radio-shark.c
45136@@ -79,7 +79,7 @@ struct shark_device {
45137 u32 last_val;
45138 };
45139
45140-static atomic_t shark_instance = ATOMIC_INIT(0);
45141+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45142
45143 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45144 {
45145diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45146index 8654e0d..0608a64 100644
45147--- a/drivers/media/radio/radio-shark2.c
45148+++ b/drivers/media/radio/radio-shark2.c
45149@@ -74,7 +74,7 @@ struct shark_device {
45150 u8 *transfer_buffer;
45151 };
45152
45153-static atomic_t shark_instance = ATOMIC_INIT(0);
45154+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45155
45156 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45157 {
45158diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45159index 2fd9009..278cc1e 100644
45160--- a/drivers/media/radio/radio-si476x.c
45161+++ b/drivers/media/radio/radio-si476x.c
45162@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45163 struct si476x_radio *radio;
45164 struct v4l2_ctrl *ctrl;
45165
45166- static atomic_t instance = ATOMIC_INIT(0);
45167+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
45168
45169 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45170 if (!radio)
45171diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
45172index a1c641e..3007da9 100644
45173--- a/drivers/media/usb/dvb-usb/cxusb.c
45174+++ b/drivers/media/usb/dvb-usb/cxusb.c
45175@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
45176
45177 struct dib0700_adapter_state {
45178 int (*set_param_save) (struct dvb_frontend *);
45179-};
45180+} __no_const;
45181
45182 static int dib7070_set_param_override(struct dvb_frontend *fe)
45183 {
45184diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45185index ae0f56a..ec71784 100644
45186--- a/drivers/media/usb/dvb-usb/dw2102.c
45187+++ b/drivers/media/usb/dvb-usb/dw2102.c
45188@@ -118,7 +118,7 @@ struct su3000_state {
45189
45190 struct s6x0_state {
45191 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45192-};
45193+} __no_const;
45194
45195 /* debug */
45196 static int dvb_usb_dw2102_debug;
45197diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45198index fca336b..fb70ab7 100644
45199--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45200+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45201@@ -328,7 +328,7 @@ struct v4l2_buffer32 {
45202 __u32 reserved;
45203 };
45204
45205-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45206+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45207 enum v4l2_memory memory)
45208 {
45209 void __user *up_pln;
45210@@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45211 return 0;
45212 }
45213
45214-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45215+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45216 enum v4l2_memory memory)
45217 {
45218 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
45219@@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45220 * by passing a very big num_planes value */
45221 uplane = compat_alloc_user_space(num_planes *
45222 sizeof(struct v4l2_plane));
45223- kp->m.planes = uplane;
45224+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
45225
45226 while (--num_planes >= 0) {
45227 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
45228@@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45229 if (num_planes == 0)
45230 return 0;
45231
45232- uplane = kp->m.planes;
45233+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
45234 if (get_user(p, &up->m.planes))
45235 return -EFAULT;
45236 uplane32 = compat_ptr(p);
45237@@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
45238 get_user(kp->capability, &up->capability) ||
45239 get_user(kp->flags, &up->flags))
45240 return -EFAULT;
45241- kp->base = compat_ptr(tmp);
45242+ kp->base = (void __force_kernel *)compat_ptr(tmp);
45243 get_v4l2_pix_format(&kp->fmt, &up->fmt);
45244 return 0;
45245 }
45246@@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45247 n * sizeof(struct v4l2_ext_control32)))
45248 return -EFAULT;
45249 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
45250- kp->controls = kcontrols;
45251+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
45252 while (--n >= 0) {
45253 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
45254 return -EFAULT;
45255@@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45256 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
45257 {
45258 struct v4l2_ext_control32 __user *ucontrols;
45259- struct v4l2_ext_control __user *kcontrols = kp->controls;
45260+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
45261 int n = kp->count;
45262 compat_caddr_t p;
45263
45264@@ -774,7 +774,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
45265 put_user(kp->start_block, &up->start_block) ||
45266 put_user(kp->blocks, &up->blocks) ||
45267 put_user(tmp, &up->edid) ||
45268- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
45269+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
45270 return -EFAULT;
45271 return 0;
45272 }
45273diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
45274index 6ff002b..6b9316b 100644
45275--- a/drivers/media/v4l2-core/v4l2-ctrls.c
45276+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
45277@@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
45278 return 0;
45279
45280 case V4L2_CTRL_TYPE_STRING:
45281- len = strlen(c->string);
45282- if (len < ctrl->minimum)
45283+ len = strlen_user(c->string);
45284+ if (!len || len < ctrl->minimum)
45285 return -ERANGE;
45286 if ((len - ctrl->minimum) % ctrl->step)
45287 return -ERANGE;
45288diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
45289index 02d1b63..5fd6b16 100644
45290--- a/drivers/media/v4l2-core/v4l2-device.c
45291+++ b/drivers/media/v4l2-core/v4l2-device.c
45292@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
45293 EXPORT_SYMBOL_GPL(v4l2_device_put);
45294
45295 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
45296- atomic_t *instance)
45297+ atomic_unchecked_t *instance)
45298 {
45299- int num = atomic_inc_return(instance) - 1;
45300+ int num = atomic_inc_return_unchecked(instance) - 1;
45301 int len = strlen(basename);
45302
45303 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
45304diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
45305index 707aef7..93b8ac0 100644
45306--- a/drivers/media/v4l2-core/v4l2-ioctl.c
45307+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
45308@@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
45309 struct file *file, void *fh, void *p);
45310 } u;
45311 void (*debug)(const void *arg, bool write_only);
45312-};
45313+} __do_const;
45314+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
45315
45316 /* This control needs a priority check */
45317 #define INFO_FL_PRIO (1 << 0)
45318@@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
45319 struct video_device *vfd = video_devdata(file);
45320 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
45321 bool write_only = false;
45322- struct v4l2_ioctl_info default_info;
45323+ v4l2_ioctl_info_no_const default_info;
45324 const struct v4l2_ioctl_info *info;
45325 void *fh = file->private_data;
45326 struct v4l2_fh *vfh = NULL;
45327@@ -2197,7 +2198,7 @@ done:
45328 }
45329
45330 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45331- void * __user *user_ptr, void ***kernel_ptr)
45332+ void __user **user_ptr, void ***kernel_ptr)
45333 {
45334 int ret = 0;
45335
45336@@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45337 ret = -EINVAL;
45338 break;
45339 }
45340- *user_ptr = (void __user *)buf->m.planes;
45341+ *user_ptr = (void __force_user *)buf->m.planes;
45342 *kernel_ptr = (void *)&buf->m.planes;
45343 *array_size = sizeof(struct v4l2_plane) * buf->length;
45344 ret = 1;
45345@@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45346 ret = -EINVAL;
45347 break;
45348 }
45349- *user_ptr = (void __user *)ctrls->controls;
45350+ *user_ptr = (void __force_user *)ctrls->controls;
45351 *kernel_ptr = (void *)&ctrls->controls;
45352 *array_size = sizeof(struct v4l2_ext_control)
45353 * ctrls->count;
45354@@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
45355 }
45356
45357 if (has_array_args) {
45358- *kernel_ptr = user_ptr;
45359+ *kernel_ptr = (void __force_kernel *)user_ptr;
45360 if (copy_to_user(user_ptr, mbuf, array_size))
45361 err = -EFAULT;
45362 goto out_array_args;
45363diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
45364index 570b18a..f880314 100644
45365--- a/drivers/message/fusion/mptbase.c
45366+++ b/drivers/message/fusion/mptbase.c
45367@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45368 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
45369 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
45370
45371+#ifdef CONFIG_GRKERNSEC_HIDESYM
45372+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
45373+#else
45374 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
45375 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
45376+#endif
45377+
45378 /*
45379 * Rounding UP to nearest 4-kB boundary here...
45380 */
45381@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45382 ioc->facts.GlobalCredits);
45383
45384 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
45385+#ifdef CONFIG_GRKERNSEC_HIDESYM
45386+ NULL, NULL);
45387+#else
45388 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
45389+#endif
45390 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
45391 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
45392 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
45393diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
45394index 00d339c..2ea899d 100644
45395--- a/drivers/message/fusion/mptsas.c
45396+++ b/drivers/message/fusion/mptsas.c
45397@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
45398 return 0;
45399 }
45400
45401+static inline void
45402+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45403+{
45404+ if (phy_info->port_details) {
45405+ phy_info->port_details->rphy = rphy;
45406+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45407+ ioc->name, rphy));
45408+ }
45409+
45410+ if (rphy) {
45411+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45412+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45413+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45414+ ioc->name, rphy, rphy->dev.release));
45415+ }
45416+}
45417+
45418 /* no mutex */
45419 static void
45420 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
45421@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
45422 return NULL;
45423 }
45424
45425-static inline void
45426-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45427-{
45428- if (phy_info->port_details) {
45429- phy_info->port_details->rphy = rphy;
45430- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45431- ioc->name, rphy));
45432- }
45433-
45434- if (rphy) {
45435- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45436- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45437- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45438- ioc->name, rphy, rphy->dev.release));
45439- }
45440-}
45441-
45442 static inline struct sas_port *
45443 mptsas_get_port(struct mptsas_phyinfo *phy_info)
45444 {
45445diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
45446index 727819c..ad74694 100644
45447--- a/drivers/message/fusion/mptscsih.c
45448+++ b/drivers/message/fusion/mptscsih.c
45449@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
45450
45451 h = shost_priv(SChost);
45452
45453- if (h) {
45454- if (h->info_kbuf == NULL)
45455- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45456- return h->info_kbuf;
45457- h->info_kbuf[0] = '\0';
45458+ if (!h)
45459+ return NULL;
45460
45461- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45462- h->info_kbuf[size-1] = '\0';
45463- }
45464+ if (h->info_kbuf == NULL)
45465+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45466+ return h->info_kbuf;
45467+ h->info_kbuf[0] = '\0';
45468+
45469+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45470+ h->info_kbuf[size-1] = '\0';
45471
45472 return h->info_kbuf;
45473 }
45474diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
45475index b7d87cd..3fb36da 100644
45476--- a/drivers/message/i2o/i2o_proc.c
45477+++ b/drivers/message/i2o/i2o_proc.c
45478@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
45479 "Array Controller Device"
45480 };
45481
45482-static char *chtostr(char *tmp, u8 *chars, int n)
45483-{
45484- tmp[0] = 0;
45485- return strncat(tmp, (char *)chars, n);
45486-}
45487-
45488 static int i2o_report_query_status(struct seq_file *seq, int block_status,
45489 char *group)
45490 {
45491@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
45492 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
45493 {
45494 struct i2o_controller *c = (struct i2o_controller *)seq->private;
45495- static u32 work32[5];
45496- static u8 *work8 = (u8 *) work32;
45497- static u16 *work16 = (u16 *) work32;
45498+ u32 work32[5];
45499+ u8 *work8 = (u8 *) work32;
45500+ u16 *work16 = (u16 *) work32;
45501 int token;
45502 u32 hwcap;
45503
45504@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45505 } *result;
45506
45507 i2o_exec_execute_ddm_table ddm_table;
45508- char tmp[28 + 1];
45509
45510 result = kmalloc(sizeof(*result), GFP_KERNEL);
45511 if (!result)
45512@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45513
45514 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
45515 seq_printf(seq, "%-#8x", ddm_table.module_id);
45516- seq_printf(seq, "%-29s",
45517- chtostr(tmp, ddm_table.module_name_version, 28));
45518+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45519 seq_printf(seq, "%9d ", ddm_table.data_size);
45520 seq_printf(seq, "%8d", ddm_table.code_size);
45521
45522@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45523
45524 i2o_driver_result_table *result;
45525 i2o_driver_store_table *dst;
45526- char tmp[28 + 1];
45527
45528 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45529 if (result == NULL)
45530@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45531
45532 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45533 seq_printf(seq, "%-#8x", dst->module_id);
45534- seq_printf(seq, "%-29s",
45535- chtostr(tmp, dst->module_name_version, 28));
45536- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45537+ seq_printf(seq, "%-.28s", dst->module_name_version);
45538+ seq_printf(seq, "%-.8s", dst->date);
45539 seq_printf(seq, "%8d ", dst->module_size);
45540 seq_printf(seq, "%8d ", dst->mpb_size);
45541 seq_printf(seq, "0x%04x", dst->module_flags);
45542@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45543 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45544 {
45545 struct i2o_device *d = (struct i2o_device *)seq->private;
45546- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45547+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45548 // == (allow) 512d bytes (max)
45549- static u16 *work16 = (u16 *) work32;
45550+ u16 *work16 = (u16 *) work32;
45551 int token;
45552- char tmp[16 + 1];
45553
45554 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45555
45556@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45557 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45558 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45559 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45560- seq_printf(seq, "Vendor info : %s\n",
45561- chtostr(tmp, (u8 *) (work32 + 2), 16));
45562- seq_printf(seq, "Product info : %s\n",
45563- chtostr(tmp, (u8 *) (work32 + 6), 16));
45564- seq_printf(seq, "Description : %s\n",
45565- chtostr(tmp, (u8 *) (work32 + 10), 16));
45566- seq_printf(seq, "Product rev. : %s\n",
45567- chtostr(tmp, (u8 *) (work32 + 14), 8));
45568+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45569+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45570+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45571+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45572
45573 seq_printf(seq, "Serial number : ");
45574 print_serial_number(seq, (u8 *) (work32 + 16),
45575@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45576 u8 pad[256]; // allow up to 256 byte (max) serial number
45577 } result;
45578
45579- char tmp[24 + 1];
45580-
45581 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45582
45583 if (token < 0) {
45584@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45585 }
45586
45587 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45588- seq_printf(seq, "Module name : %s\n",
45589- chtostr(tmp, result.module_name, 24));
45590- seq_printf(seq, "Module revision : %s\n",
45591- chtostr(tmp, result.module_rev, 8));
45592+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
45593+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45594
45595 seq_printf(seq, "Serial number : ");
45596 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45597@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45598 u8 instance_number[4];
45599 } result;
45600
45601- char tmp[64 + 1];
45602-
45603 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45604
45605 if (token < 0) {
45606@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45607 return 0;
45608 }
45609
45610- seq_printf(seq, "Device name : %s\n",
45611- chtostr(tmp, result.device_name, 64));
45612- seq_printf(seq, "Service name : %s\n",
45613- chtostr(tmp, result.service_name, 64));
45614- seq_printf(seq, "Physical name : %s\n",
45615- chtostr(tmp, result.physical_location, 64));
45616- seq_printf(seq, "Instance number : %s\n",
45617- chtostr(tmp, result.instance_number, 4));
45618+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
45619+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
45620+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45621+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45622
45623 return 0;
45624 }
45625@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45626 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45627 {
45628 struct i2o_device *d = (struct i2o_device *)seq->private;
45629- static u32 work32[12];
45630- static u16 *work16 = (u16 *) work32;
45631- static u8 *work8 = (u8 *) work32;
45632+ u32 work32[12];
45633+ u16 *work16 = (u16 *) work32;
45634+ u8 *work8 = (u8 *) work32;
45635 int token;
45636
45637 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45638diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45639index a8c08f3..155fe3d 100644
45640--- a/drivers/message/i2o/iop.c
45641+++ b/drivers/message/i2o/iop.c
45642@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45643
45644 spin_lock_irqsave(&c->context_list_lock, flags);
45645
45646- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45647- atomic_inc(&c->context_list_counter);
45648+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45649+ atomic_inc_unchecked(&c->context_list_counter);
45650
45651- entry->context = atomic_read(&c->context_list_counter);
45652+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45653
45654 list_add(&entry->list, &c->context_list);
45655
45656@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45657
45658 #if BITS_PER_LONG == 64
45659 spin_lock_init(&c->context_list_lock);
45660- atomic_set(&c->context_list_counter, 0);
45661+ atomic_set_unchecked(&c->context_list_counter, 0);
45662 INIT_LIST_HEAD(&c->context_list);
45663 #endif
45664
45665diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45666index d1a22aa..d0f7bf7 100644
45667--- a/drivers/mfd/ab8500-debugfs.c
45668+++ b/drivers/mfd/ab8500-debugfs.c
45669@@ -100,7 +100,7 @@ static int irq_last;
45670 static u32 *irq_count;
45671 static int num_irqs;
45672
45673-static struct device_attribute **dev_attr;
45674+static device_attribute_no_const **dev_attr;
45675 static char **event_name;
45676
45677 static u8 avg_sample = SAMPLE_16;
45678diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45679index a83eed5..62a58a9 100644
45680--- a/drivers/mfd/max8925-i2c.c
45681+++ b/drivers/mfd/max8925-i2c.c
45682@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45683 const struct i2c_device_id *id)
45684 {
45685 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45686- static struct max8925_chip *chip;
45687+ struct max8925_chip *chip;
45688 struct device_node *node = client->dev.of_node;
45689
45690 if (node && !pdata) {
45691diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45692index d657331..0d9a80f 100644
45693--- a/drivers/mfd/tps65910.c
45694+++ b/drivers/mfd/tps65910.c
45695@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45696 struct tps65910_platform_data *pdata)
45697 {
45698 int ret = 0;
45699- static struct regmap_irq_chip *tps6591x_irqs_chip;
45700+ struct regmap_irq_chip *tps6591x_irqs_chip;
45701
45702 if (!irq) {
45703 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45704diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45705index 9aa6d1e..1631bfc 100644
45706--- a/drivers/mfd/twl4030-irq.c
45707+++ b/drivers/mfd/twl4030-irq.c
45708@@ -35,6 +35,7 @@
45709 #include <linux/of.h>
45710 #include <linux/irqdomain.h>
45711 #include <linux/i2c/twl.h>
45712+#include <asm/pgtable.h>
45713
45714 #include "twl-core.h"
45715
45716@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45717 * Install an irq handler for each of the SIH modules;
45718 * clone dummy irq_chip since PIH can't *do* anything
45719 */
45720- twl4030_irq_chip = dummy_irq_chip;
45721- twl4030_irq_chip.name = "twl4030";
45722+ pax_open_kernel();
45723+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45724+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45725
45726- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45727+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45728+ pax_close_kernel();
45729
45730 for (i = irq_base; i < irq_end; i++) {
45731 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45732diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45733index 464419b..64bae8d 100644
45734--- a/drivers/misc/c2port/core.c
45735+++ b/drivers/misc/c2port/core.c
45736@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45737 goto error_idr_alloc;
45738 c2dev->id = ret;
45739
45740- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45741+ pax_open_kernel();
45742+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45743+ pax_close_kernel();
45744
45745 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45746 "c2port%d", c2dev->id);
45747diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45748index 9c34e57..b981cda 100644
45749--- a/drivers/misc/eeprom/sunxi_sid.c
45750+++ b/drivers/misc/eeprom/sunxi_sid.c
45751@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45752
45753 platform_set_drvdata(pdev, sid_data);
45754
45755- sid_bin_attr.size = sid_data->keysize;
45756+ pax_open_kernel();
45757+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45758+ pax_close_kernel();
45759 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45760 return -ENODEV;
45761
45762diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45763index 36f5d52..32311c3 100644
45764--- a/drivers/misc/kgdbts.c
45765+++ b/drivers/misc/kgdbts.c
45766@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45767 char before[BREAK_INSTR_SIZE];
45768 char after[BREAK_INSTR_SIZE];
45769
45770- probe_kernel_read(before, (char *)kgdbts_break_test,
45771+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45772 BREAK_INSTR_SIZE);
45773 init_simple_test();
45774 ts.tst = plant_and_detach_test;
45775@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45776 /* Activate test with initial breakpoint */
45777 if (!is_early)
45778 kgdb_breakpoint();
45779- probe_kernel_read(after, (char *)kgdbts_break_test,
45780+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45781 BREAK_INSTR_SIZE);
45782 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45783 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45784diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45785index 036effe..b3a6336 100644
45786--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45787+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45788@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45789 * the lid is closed. This leads to interrupts as soon as a little move
45790 * is done.
45791 */
45792- atomic_inc(&lis3->count);
45793+ atomic_inc_unchecked(&lis3->count);
45794
45795 wake_up_interruptible(&lis3->misc_wait);
45796 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45797@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45798 if (lis3->pm_dev)
45799 pm_runtime_get_sync(lis3->pm_dev);
45800
45801- atomic_set(&lis3->count, 0);
45802+ atomic_set_unchecked(&lis3->count, 0);
45803 return 0;
45804 }
45805
45806@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45807 add_wait_queue(&lis3->misc_wait, &wait);
45808 while (true) {
45809 set_current_state(TASK_INTERRUPTIBLE);
45810- data = atomic_xchg(&lis3->count, 0);
45811+ data = atomic_xchg_unchecked(&lis3->count, 0);
45812 if (data)
45813 break;
45814
45815@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45816 struct lis3lv02d, miscdev);
45817
45818 poll_wait(file, &lis3->misc_wait, wait);
45819- if (atomic_read(&lis3->count))
45820+ if (atomic_read_unchecked(&lis3->count))
45821 return POLLIN | POLLRDNORM;
45822 return 0;
45823 }
45824diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45825index c439c82..1f20f57 100644
45826--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45827+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45828@@ -297,7 +297,7 @@ struct lis3lv02d {
45829 struct input_polled_dev *idev; /* input device */
45830 struct platform_device *pdev; /* platform device */
45831 struct regulator_bulk_data regulators[2];
45832- atomic_t count; /* interrupt count after last read */
45833+ atomic_unchecked_t count; /* interrupt count after last read */
45834 union axis_conversion ac; /* hw -> logical axis */
45835 int mapped_btns[3];
45836
45837diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45838index 2f30bad..c4c13d0 100644
45839--- a/drivers/misc/sgi-gru/gruhandles.c
45840+++ b/drivers/misc/sgi-gru/gruhandles.c
45841@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45842 unsigned long nsec;
45843
45844 nsec = CLKS2NSEC(clks);
45845- atomic_long_inc(&mcs_op_statistics[op].count);
45846- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45847+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45848+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45849 if (mcs_op_statistics[op].max < nsec)
45850 mcs_op_statistics[op].max = nsec;
45851 }
45852diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45853index 4f76359..cdfcb2e 100644
45854--- a/drivers/misc/sgi-gru/gruprocfs.c
45855+++ b/drivers/misc/sgi-gru/gruprocfs.c
45856@@ -32,9 +32,9 @@
45857
45858 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45859
45860-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45861+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45862 {
45863- unsigned long val = atomic_long_read(v);
45864+ unsigned long val = atomic_long_read_unchecked(v);
45865
45866 seq_printf(s, "%16lu %s\n", val, id);
45867 }
45868@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45869
45870 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45871 for (op = 0; op < mcsop_last; op++) {
45872- count = atomic_long_read(&mcs_op_statistics[op].count);
45873- total = atomic_long_read(&mcs_op_statistics[op].total);
45874+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45875+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45876 max = mcs_op_statistics[op].max;
45877 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45878 count ? total / count : 0, max);
45879diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45880index 5c3ce24..4915ccb 100644
45881--- a/drivers/misc/sgi-gru/grutables.h
45882+++ b/drivers/misc/sgi-gru/grutables.h
45883@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45884 * GRU statistics.
45885 */
45886 struct gru_stats_s {
45887- atomic_long_t vdata_alloc;
45888- atomic_long_t vdata_free;
45889- atomic_long_t gts_alloc;
45890- atomic_long_t gts_free;
45891- atomic_long_t gms_alloc;
45892- atomic_long_t gms_free;
45893- atomic_long_t gts_double_allocate;
45894- atomic_long_t assign_context;
45895- atomic_long_t assign_context_failed;
45896- atomic_long_t free_context;
45897- atomic_long_t load_user_context;
45898- atomic_long_t load_kernel_context;
45899- atomic_long_t lock_kernel_context;
45900- atomic_long_t unlock_kernel_context;
45901- atomic_long_t steal_user_context;
45902- atomic_long_t steal_kernel_context;
45903- atomic_long_t steal_context_failed;
45904- atomic_long_t nopfn;
45905- atomic_long_t asid_new;
45906- atomic_long_t asid_next;
45907- atomic_long_t asid_wrap;
45908- atomic_long_t asid_reuse;
45909- atomic_long_t intr;
45910- atomic_long_t intr_cbr;
45911- atomic_long_t intr_tfh;
45912- atomic_long_t intr_spurious;
45913- atomic_long_t intr_mm_lock_failed;
45914- atomic_long_t call_os;
45915- atomic_long_t call_os_wait_queue;
45916- atomic_long_t user_flush_tlb;
45917- atomic_long_t user_unload_context;
45918- atomic_long_t user_exception;
45919- atomic_long_t set_context_option;
45920- atomic_long_t check_context_retarget_intr;
45921- atomic_long_t check_context_unload;
45922- atomic_long_t tlb_dropin;
45923- atomic_long_t tlb_preload_page;
45924- atomic_long_t tlb_dropin_fail_no_asid;
45925- atomic_long_t tlb_dropin_fail_upm;
45926- atomic_long_t tlb_dropin_fail_invalid;
45927- atomic_long_t tlb_dropin_fail_range_active;
45928- atomic_long_t tlb_dropin_fail_idle;
45929- atomic_long_t tlb_dropin_fail_fmm;
45930- atomic_long_t tlb_dropin_fail_no_exception;
45931- atomic_long_t tfh_stale_on_fault;
45932- atomic_long_t mmu_invalidate_range;
45933- atomic_long_t mmu_invalidate_page;
45934- atomic_long_t flush_tlb;
45935- atomic_long_t flush_tlb_gru;
45936- atomic_long_t flush_tlb_gru_tgh;
45937- atomic_long_t flush_tlb_gru_zero_asid;
45938+ atomic_long_unchecked_t vdata_alloc;
45939+ atomic_long_unchecked_t vdata_free;
45940+ atomic_long_unchecked_t gts_alloc;
45941+ atomic_long_unchecked_t gts_free;
45942+ atomic_long_unchecked_t gms_alloc;
45943+ atomic_long_unchecked_t gms_free;
45944+ atomic_long_unchecked_t gts_double_allocate;
45945+ atomic_long_unchecked_t assign_context;
45946+ atomic_long_unchecked_t assign_context_failed;
45947+ atomic_long_unchecked_t free_context;
45948+ atomic_long_unchecked_t load_user_context;
45949+ atomic_long_unchecked_t load_kernel_context;
45950+ atomic_long_unchecked_t lock_kernel_context;
45951+ atomic_long_unchecked_t unlock_kernel_context;
45952+ atomic_long_unchecked_t steal_user_context;
45953+ atomic_long_unchecked_t steal_kernel_context;
45954+ atomic_long_unchecked_t steal_context_failed;
45955+ atomic_long_unchecked_t nopfn;
45956+ atomic_long_unchecked_t asid_new;
45957+ atomic_long_unchecked_t asid_next;
45958+ atomic_long_unchecked_t asid_wrap;
45959+ atomic_long_unchecked_t asid_reuse;
45960+ atomic_long_unchecked_t intr;
45961+ atomic_long_unchecked_t intr_cbr;
45962+ atomic_long_unchecked_t intr_tfh;
45963+ atomic_long_unchecked_t intr_spurious;
45964+ atomic_long_unchecked_t intr_mm_lock_failed;
45965+ atomic_long_unchecked_t call_os;
45966+ atomic_long_unchecked_t call_os_wait_queue;
45967+ atomic_long_unchecked_t user_flush_tlb;
45968+ atomic_long_unchecked_t user_unload_context;
45969+ atomic_long_unchecked_t user_exception;
45970+ atomic_long_unchecked_t set_context_option;
45971+ atomic_long_unchecked_t check_context_retarget_intr;
45972+ atomic_long_unchecked_t check_context_unload;
45973+ atomic_long_unchecked_t tlb_dropin;
45974+ atomic_long_unchecked_t tlb_preload_page;
45975+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45976+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45977+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45978+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45979+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45980+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45981+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45982+ atomic_long_unchecked_t tfh_stale_on_fault;
45983+ atomic_long_unchecked_t mmu_invalidate_range;
45984+ atomic_long_unchecked_t mmu_invalidate_page;
45985+ atomic_long_unchecked_t flush_tlb;
45986+ atomic_long_unchecked_t flush_tlb_gru;
45987+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45988+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45989
45990- atomic_long_t copy_gpa;
45991- atomic_long_t read_gpa;
45992+ atomic_long_unchecked_t copy_gpa;
45993+ atomic_long_unchecked_t read_gpa;
45994
45995- atomic_long_t mesq_receive;
45996- atomic_long_t mesq_receive_none;
45997- atomic_long_t mesq_send;
45998- atomic_long_t mesq_send_failed;
45999- atomic_long_t mesq_noop;
46000- atomic_long_t mesq_send_unexpected_error;
46001- atomic_long_t mesq_send_lb_overflow;
46002- atomic_long_t mesq_send_qlimit_reached;
46003- atomic_long_t mesq_send_amo_nacked;
46004- atomic_long_t mesq_send_put_nacked;
46005- atomic_long_t mesq_page_overflow;
46006- atomic_long_t mesq_qf_locked;
46007- atomic_long_t mesq_qf_noop_not_full;
46008- atomic_long_t mesq_qf_switch_head_failed;
46009- atomic_long_t mesq_qf_unexpected_error;
46010- atomic_long_t mesq_noop_unexpected_error;
46011- atomic_long_t mesq_noop_lb_overflow;
46012- atomic_long_t mesq_noop_qlimit_reached;
46013- atomic_long_t mesq_noop_amo_nacked;
46014- atomic_long_t mesq_noop_put_nacked;
46015- atomic_long_t mesq_noop_page_overflow;
46016+ atomic_long_unchecked_t mesq_receive;
46017+ atomic_long_unchecked_t mesq_receive_none;
46018+ atomic_long_unchecked_t mesq_send;
46019+ atomic_long_unchecked_t mesq_send_failed;
46020+ atomic_long_unchecked_t mesq_noop;
46021+ atomic_long_unchecked_t mesq_send_unexpected_error;
46022+ atomic_long_unchecked_t mesq_send_lb_overflow;
46023+ atomic_long_unchecked_t mesq_send_qlimit_reached;
46024+ atomic_long_unchecked_t mesq_send_amo_nacked;
46025+ atomic_long_unchecked_t mesq_send_put_nacked;
46026+ atomic_long_unchecked_t mesq_page_overflow;
46027+ atomic_long_unchecked_t mesq_qf_locked;
46028+ atomic_long_unchecked_t mesq_qf_noop_not_full;
46029+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
46030+ atomic_long_unchecked_t mesq_qf_unexpected_error;
46031+ atomic_long_unchecked_t mesq_noop_unexpected_error;
46032+ atomic_long_unchecked_t mesq_noop_lb_overflow;
46033+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
46034+ atomic_long_unchecked_t mesq_noop_amo_nacked;
46035+ atomic_long_unchecked_t mesq_noop_put_nacked;
46036+ atomic_long_unchecked_t mesq_noop_page_overflow;
46037
46038 };
46039
46040@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
46041 tghop_invalidate, mcsop_last};
46042
46043 struct mcs_op_statistic {
46044- atomic_long_t count;
46045- atomic_long_t total;
46046+ atomic_long_unchecked_t count;
46047+ atomic_long_unchecked_t total;
46048 unsigned long max;
46049 };
46050
46051@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
46052
46053 #define STAT(id) do { \
46054 if (gru_options & OPT_STATS) \
46055- atomic_long_inc(&gru_stats.id); \
46056+ atomic_long_inc_unchecked(&gru_stats.id); \
46057 } while (0)
46058
46059 #ifdef CONFIG_SGI_GRU_DEBUG
46060diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
46061index c862cd4..0d176fe 100644
46062--- a/drivers/misc/sgi-xp/xp.h
46063+++ b/drivers/misc/sgi-xp/xp.h
46064@@ -288,7 +288,7 @@ struct xpc_interface {
46065 xpc_notify_func, void *);
46066 void (*received) (short, int, void *);
46067 enum xp_retval (*partid_to_nasids) (short, void *);
46068-};
46069+} __no_const;
46070
46071 extern struct xpc_interface xpc_interface;
46072
46073diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
46074index 01be66d..e3a0c7e 100644
46075--- a/drivers/misc/sgi-xp/xp_main.c
46076+++ b/drivers/misc/sgi-xp/xp_main.c
46077@@ -78,13 +78,13 @@ xpc_notloaded(void)
46078 }
46079
46080 struct xpc_interface xpc_interface = {
46081- (void (*)(int))xpc_notloaded,
46082- (void (*)(int))xpc_notloaded,
46083- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46084- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46085+ .connect = (void (*)(int))xpc_notloaded,
46086+ .disconnect = (void (*)(int))xpc_notloaded,
46087+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46088+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46089 void *))xpc_notloaded,
46090- (void (*)(short, int, void *))xpc_notloaded,
46091- (enum xp_retval(*)(short, void *))xpc_notloaded
46092+ .received = (void (*)(short, int, void *))xpc_notloaded,
46093+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
46094 };
46095 EXPORT_SYMBOL_GPL(xpc_interface);
46096
46097diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
46098index b94d5f7..7f494c5 100644
46099--- a/drivers/misc/sgi-xp/xpc.h
46100+++ b/drivers/misc/sgi-xp/xpc.h
46101@@ -835,6 +835,7 @@ struct xpc_arch_operations {
46102 void (*received_payload) (struct xpc_channel *, void *);
46103 void (*notify_senders_of_disconnect) (struct xpc_channel *);
46104 };
46105+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
46106
46107 /* struct xpc_partition act_state values (for XPC HB) */
46108
46109@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
46110 /* found in xpc_main.c */
46111 extern struct device *xpc_part;
46112 extern struct device *xpc_chan;
46113-extern struct xpc_arch_operations xpc_arch_ops;
46114+extern xpc_arch_operations_no_const xpc_arch_ops;
46115 extern int xpc_disengage_timelimit;
46116 extern int xpc_disengage_timedout;
46117 extern int xpc_activate_IRQ_rcvd;
46118diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
46119index 82dc574..8539ab2 100644
46120--- a/drivers/misc/sgi-xp/xpc_main.c
46121+++ b/drivers/misc/sgi-xp/xpc_main.c
46122@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
46123 .notifier_call = xpc_system_die,
46124 };
46125
46126-struct xpc_arch_operations xpc_arch_ops;
46127+xpc_arch_operations_no_const xpc_arch_ops;
46128
46129 /*
46130 * Timer function to enforce the timelimit on the partition disengage.
46131@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
46132
46133 if (((die_args->trapnr == X86_TRAP_MF) ||
46134 (die_args->trapnr == X86_TRAP_XF)) &&
46135- !user_mode_vm(die_args->regs))
46136+ !user_mode(die_args->regs))
46137 xpc_die_deactivate();
46138
46139 break;
46140diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
46141index 7b5424f..ed1d6ac 100644
46142--- a/drivers/mmc/card/block.c
46143+++ b/drivers/mmc/card/block.c
46144@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
46145 if (idata->ic.postsleep_min_us)
46146 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
46147
46148- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
46149+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
46150 err = -EFAULT;
46151 goto cmd_rel_host;
46152 }
46153diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
46154index e5b5eeb..7bf2212 100644
46155--- a/drivers/mmc/core/mmc_ops.c
46156+++ b/drivers/mmc/core/mmc_ops.c
46157@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
46158 void *data_buf;
46159 int is_on_stack;
46160
46161- is_on_stack = object_is_on_stack(buf);
46162+ is_on_stack = object_starts_on_stack(buf);
46163 if (is_on_stack) {
46164 /*
46165 * dma onto stack is unsafe/nonportable, but callers to this
46166diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
46167index 6bf24ab..13d0293b 100644
46168--- a/drivers/mmc/host/dw_mmc.h
46169+++ b/drivers/mmc/host/dw_mmc.h
46170@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
46171 int (*parse_dt)(struct dw_mci *host);
46172 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
46173 struct dw_mci_tuning_data *tuning_data);
46174-};
46175+} __do_const;
46176 #endif /* _DW_MMC_H_ */
46177diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
46178index b931226..df6a085 100644
46179--- a/drivers/mmc/host/mmci.c
46180+++ b/drivers/mmc/host/mmci.c
46181@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
46182 }
46183
46184 if (variant->busy_detect) {
46185- mmci_ops.card_busy = mmci_card_busy;
46186+ pax_open_kernel();
46187+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
46188+ pax_close_kernel();
46189 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
46190 }
46191
46192diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
46193index b841bb7..d82712f5 100644
46194--- a/drivers/mmc/host/sdhci-esdhc-imx.c
46195+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
46196@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
46197 host->mmc->caps |= MMC_CAP_1_8V_DDR;
46198 }
46199
46200- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
46201- sdhci_esdhc_ops.platform_execute_tuning =
46202+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
46203+ pax_open_kernel();
46204+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
46205 esdhc_executing_tuning;
46206+ pax_close_kernel();
46207+ }
46208
46209 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
46210 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
46211diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
46212index 6debda9..2ba7427 100644
46213--- a/drivers/mmc/host/sdhci-s3c.c
46214+++ b/drivers/mmc/host/sdhci-s3c.c
46215@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
46216 * we can use overriding functions instead of default.
46217 */
46218 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
46219- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46220- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46221- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46222+ pax_open_kernel();
46223+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46224+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46225+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46226+ pax_close_kernel();
46227 }
46228
46229 /* It supports additional host capabilities if needed */
46230diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
46231index 096993f..f02c23b 100644
46232--- a/drivers/mtd/chips/cfi_cmdset_0020.c
46233+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
46234@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
46235 size_t totlen = 0, thislen;
46236 int ret = 0;
46237 size_t buflen = 0;
46238- static char *buffer;
46239+ char *buffer;
46240
46241 if (!ECCBUF_SIZE) {
46242 /* We should fall back to a general writev implementation.
46243diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
46244index c07cd57..61c4fbd 100644
46245--- a/drivers/mtd/nand/denali.c
46246+++ b/drivers/mtd/nand/denali.c
46247@@ -24,6 +24,7 @@
46248 #include <linux/slab.h>
46249 #include <linux/mtd/mtd.h>
46250 #include <linux/module.h>
46251+#include <linux/slab.h>
46252
46253 #include "denali.h"
46254
46255diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46256index ca6369f..0ce9fed 100644
46257--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46258+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46259@@ -369,7 +369,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
46260
46261 /* first try to map the upper buffer directly */
46262 if (virt_addr_valid(this->upper_buf) &&
46263- !object_is_on_stack(this->upper_buf)) {
46264+ !object_starts_on_stack(this->upper_buf)) {
46265 sg_init_one(sgl, this->upper_buf, this->upper_len);
46266 ret = dma_map_sg(this->dev, sgl, 1, dr);
46267 if (ret == 0)
46268diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
46269index 51b9d6a..52af9a7 100644
46270--- a/drivers/mtd/nftlmount.c
46271+++ b/drivers/mtd/nftlmount.c
46272@@ -24,6 +24,7 @@
46273 #include <asm/errno.h>
46274 #include <linux/delay.h>
46275 #include <linux/slab.h>
46276+#include <linux/sched.h>
46277 #include <linux/mtd/mtd.h>
46278 #include <linux/mtd/nand.h>
46279 #include <linux/mtd/nftl.h>
46280diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
46281index cf49c22..971b133 100644
46282--- a/drivers/mtd/sm_ftl.c
46283+++ b/drivers/mtd/sm_ftl.c
46284@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
46285 #define SM_CIS_VENDOR_OFFSET 0x59
46286 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
46287 {
46288- struct attribute_group *attr_group;
46289+ attribute_group_no_const *attr_group;
46290 struct attribute **attributes;
46291 struct sm_sysfs_attribute *vendor_attribute;
46292 char *vendor;
46293diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
46294index 91ec8cd..562ff5f 100644
46295--- a/drivers/net/bonding/bond_main.c
46296+++ b/drivers/net/bonding/bond_main.c
46297@@ -4552,6 +4552,7 @@ static void __exit bonding_exit(void)
46298
46299 bond_netlink_fini();
46300 unregister_pernet_subsys(&bond_net_ops);
46301+ rtnl_link_unregister(&bond_link_ops);
46302
46303 #ifdef CONFIG_NET_POLL_CONTROLLER
46304 /*
46305diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
46306index 70651f8..7eb1bdf 100644
46307--- a/drivers/net/bonding/bond_netlink.c
46308+++ b/drivers/net/bonding/bond_netlink.c
46309@@ -542,7 +542,7 @@ nla_put_failure:
46310 return -EMSGSIZE;
46311 }
46312
46313-struct rtnl_link_ops bond_link_ops __read_mostly = {
46314+struct rtnl_link_ops bond_link_ops = {
46315 .kind = "bond",
46316 .priv_size = sizeof(struct bonding),
46317 .setup = bond_setup,
46318diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
46319index 9e7d95d..d447b88 100644
46320--- a/drivers/net/can/Kconfig
46321+++ b/drivers/net/can/Kconfig
46322@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
46323
46324 config CAN_FLEXCAN
46325 tristate "Support for Freescale FLEXCAN based chips"
46326- depends on ARM || PPC
46327+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
46328 ---help---
46329 Say Y here if you want to support for Freescale FlexCAN.
46330
46331diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
46332index 455d4c3..3353ee7 100644
46333--- a/drivers/net/ethernet/8390/ax88796.c
46334+++ b/drivers/net/ethernet/8390/ax88796.c
46335@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
46336 if (ax->plat->reg_offsets)
46337 ei_local->reg_offset = ax->plat->reg_offsets;
46338 else {
46339+ resource_size_t _mem_size = mem_size;
46340+ do_div(_mem_size, 0x18);
46341 ei_local->reg_offset = ax->reg_offsets;
46342 for (ret = 0; ret < 0x18; ret++)
46343- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
46344+ ax->reg_offsets[ret] = _mem_size * ret;
46345 }
46346
46347 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
46348diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46349index a89a40f..5a8a2ac 100644
46350--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46351+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46352@@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
46353 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
46354 {
46355 /* RX_MODE controlling object */
46356- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
46357+ bnx2x_init_rx_mode_obj(bp);
46358
46359 /* multicast configuration controlling object */
46360 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
46361diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46362index 0fb6ff2..78fd55c 100644
46363--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46364+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46365@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
46366 return rc;
46367 }
46368
46369-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46370- struct bnx2x_rx_mode_obj *o)
46371+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
46372 {
46373 if (CHIP_IS_E1x(bp)) {
46374- o->wait_comp = bnx2x_empty_rx_mode_wait;
46375- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
46376+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
46377+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
46378 } else {
46379- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
46380- o->config_rx_mode = bnx2x_set_rx_mode_e2;
46381+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
46382+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
46383 }
46384 }
46385
46386diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46387index 00d7f21..2cddec4 100644
46388--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46389+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46390@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
46391
46392 /********************* RX MODE ****************/
46393
46394-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46395- struct bnx2x_rx_mode_obj *o);
46396+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
46397
46398 /**
46399 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
46400diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
46401index 04321e5..b51cdc4 100644
46402--- a/drivers/net/ethernet/broadcom/tg3.h
46403+++ b/drivers/net/ethernet/broadcom/tg3.h
46404@@ -150,6 +150,7 @@
46405 #define CHIPREV_ID_5750_A0 0x4000
46406 #define CHIPREV_ID_5750_A1 0x4001
46407 #define CHIPREV_ID_5750_A3 0x4003
46408+#define CHIPREV_ID_5750_C1 0x4201
46409 #define CHIPREV_ID_5750_C2 0x4202
46410 #define CHIPREV_ID_5752_A0_HW 0x5000
46411 #define CHIPREV_ID_5752_A0 0x6000
46412diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
46413index 13f9636..228040f 100644
46414--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
46415+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
46416@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
46417 }
46418
46419 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
46420- bna_cb_ioceth_enable,
46421- bna_cb_ioceth_disable,
46422- bna_cb_ioceth_hbfail,
46423- bna_cb_ioceth_reset
46424+ .enable_cbfn = bna_cb_ioceth_enable,
46425+ .disable_cbfn = bna_cb_ioceth_disable,
46426+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
46427+ .reset_cbfn = bna_cb_ioceth_reset
46428 };
46429
46430 static void bna_attr_init(struct bna_ioceth *ioceth)
46431diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46432index 8cffcdf..aadf043 100644
46433--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46434+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46435@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
46436 */
46437 struct l2t_skb_cb {
46438 arp_failure_handler_func arp_failure_handler;
46439-};
46440+} __no_const;
46441
46442 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
46443
46444diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46445index 34e2488..07e2079 100644
46446--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46447+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46448@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
46449
46450 int i;
46451 struct adapter *ap = netdev2adap(dev);
46452- static const unsigned int *reg_ranges;
46453+ const unsigned int *reg_ranges;
46454 int arr_size = 0, buf_size = 0;
46455
46456 if (is_t4(ap->params.chip)) {
46457diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
46458index c05b66d..ed69872 100644
46459--- a/drivers/net/ethernet/dec/tulip/de4x5.c
46460+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
46461@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46462 for (i=0; i<ETH_ALEN; i++) {
46463 tmp.addr[i] = dev->dev_addr[i];
46464 }
46465- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46466+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46467 break;
46468
46469 case DE4X5_SET_HWADDR: /* Set the hardware address */
46470@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46471 spin_lock_irqsave(&lp->lock, flags);
46472 memcpy(&statbuf, &lp->pktStats, ioc->len);
46473 spin_unlock_irqrestore(&lp->lock, flags);
46474- if (copy_to_user(ioc->data, &statbuf, ioc->len))
46475+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
46476 return -EFAULT;
46477 break;
46478 }
46479diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
46480index 36c8061..ca5e1e0 100644
46481--- a/drivers/net/ethernet/emulex/benet/be_main.c
46482+++ b/drivers/net/ethernet/emulex/benet/be_main.c
46483@@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
46484
46485 if (wrapped)
46486 newacc += 65536;
46487- ACCESS_ONCE(*acc) = newacc;
46488+ ACCESS_ONCE_RW(*acc) = newacc;
46489 }
46490
46491 static void populate_erx_stats(struct be_adapter *adapter,
46492diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
46493index c11ecbc..13bb299 100644
46494--- a/drivers/net/ethernet/faraday/ftgmac100.c
46495+++ b/drivers/net/ethernet/faraday/ftgmac100.c
46496@@ -30,6 +30,8 @@
46497 #include <linux/netdevice.h>
46498 #include <linux/phy.h>
46499 #include <linux/platform_device.h>
46500+#include <linux/interrupt.h>
46501+#include <linux/irqreturn.h>
46502 #include <net/ip.h>
46503
46504 #include "ftgmac100.h"
46505diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46506index 8be5b40..081bc1b 100644
46507--- a/drivers/net/ethernet/faraday/ftmac100.c
46508+++ b/drivers/net/ethernet/faraday/ftmac100.c
46509@@ -31,6 +31,8 @@
46510 #include <linux/module.h>
46511 #include <linux/netdevice.h>
46512 #include <linux/platform_device.h>
46513+#include <linux/interrupt.h>
46514+#include <linux/irqreturn.h>
46515
46516 #include "ftmac100.h"
46517
46518diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46519index e33ec6c..f54cfe7 100644
46520--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46521+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46522@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46523 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46524
46525 /* Update the base adjustement value. */
46526- ACCESS_ONCE(pf->ptp_base_adj) = incval;
46527+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46528 smp_mb(); /* Force the above update. */
46529 }
46530
46531diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46532index 5184e2a..acb28c3 100644
46533--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46534+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46535@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46536 }
46537
46538 /* update the base incval used to calculate frequency adjustment */
46539- ACCESS_ONCE(adapter->base_incval) = incval;
46540+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
46541 smp_mb();
46542
46543 /* need lock to prevent incorrect read while modifying cyclecounter */
46544diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46545index 089b713..28d87ae 100644
46546--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46547+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46548@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46549 struct __vxge_hw_fifo *fifo;
46550 struct vxge_hw_fifo_config *config;
46551 u32 txdl_size, txdl_per_memblock;
46552- struct vxge_hw_mempool_cbs fifo_mp_callback;
46553+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46554+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46555+ };
46556+
46557 struct __vxge_hw_virtualpath *vpath;
46558
46559 if ((vp == NULL) || (attr == NULL)) {
46560@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46561 goto exit;
46562 }
46563
46564- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46565-
46566 fifo->mempool =
46567 __vxge_hw_mempool_create(vpath->hldev,
46568 fifo->config->memblock_size,
46569diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46570index 90a2dda..47e620e 100644
46571--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46572+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46573@@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46574 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46575 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46576 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46577- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46578+ pax_open_kernel();
46579+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46580+ pax_close_kernel();
46581 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46582 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46583 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
46584diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46585index be7d7a6..a8983f8 100644
46586--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46587+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46588@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46589 case QLCNIC_NON_PRIV_FUNC:
46590 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46591 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46592- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46593+ pax_open_kernel();
46594+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46595+ pax_close_kernel();
46596 break;
46597 case QLCNIC_PRIV_FUNC:
46598 ahw->op_mode = QLCNIC_PRIV_FUNC;
46599 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46600- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46601+ pax_open_kernel();
46602+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46603+ pax_close_kernel();
46604 break;
46605 case QLCNIC_MGMT_FUNC:
46606 ahw->op_mode = QLCNIC_MGMT_FUNC;
46607 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46608- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46609+ pax_open_kernel();
46610+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46611+ pax_close_kernel();
46612 break;
46613 default:
46614 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46615diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
46616index 7d4f549..3e46c89 100644
46617--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
46618+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
46619@@ -1022,6 +1022,7 @@ static int qlcnic_dcb_peer_app_info(struct net_device *netdev,
46620 struct qlcnic_dcb_cee *peer;
46621 int i;
46622
46623+ memset(info, 0, sizeof(*info));
46624 *app_count = 0;
46625
46626 if (!test_bit(QLCNIC_DCB_STATE, &adapter->dcb->state))
46627diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46628index 7763962..c3499a7 100644
46629--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46630+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46631@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46632 struct qlcnic_dump_entry *entry;
46633 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46634 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
46635- static const struct qlcnic_dump_operations *fw_dump_ops;
46636+ const struct qlcnic_dump_operations *fw_dump_ops;
46637 struct device *dev = &adapter->pdev->dev;
46638 struct qlcnic_hardware_context *ahw;
46639 void *temp_buffer;
46640diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46641index 3ff7bc3..366091b 100644
46642--- a/drivers/net/ethernet/realtek/r8169.c
46643+++ b/drivers/net/ethernet/realtek/r8169.c
46644@@ -758,22 +758,22 @@ struct rtl8169_private {
46645 struct mdio_ops {
46646 void (*write)(struct rtl8169_private *, int, int);
46647 int (*read)(struct rtl8169_private *, int);
46648- } mdio_ops;
46649+ } __no_const mdio_ops;
46650
46651 struct pll_power_ops {
46652 void (*down)(struct rtl8169_private *);
46653 void (*up)(struct rtl8169_private *);
46654- } pll_power_ops;
46655+ } __no_const pll_power_ops;
46656
46657 struct jumbo_ops {
46658 void (*enable)(struct rtl8169_private *);
46659 void (*disable)(struct rtl8169_private *);
46660- } jumbo_ops;
46661+ } __no_const jumbo_ops;
46662
46663 struct csi_ops {
46664 void (*write)(struct rtl8169_private *, int, int);
46665 u32 (*read)(struct rtl8169_private *, int);
46666- } csi_ops;
46667+ } __no_const csi_ops;
46668
46669 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46670 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46671diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46672index d7a3682..9ce272a 100644
46673--- a/drivers/net/ethernet/sfc/ptp.c
46674+++ b/drivers/net/ethernet/sfc/ptp.c
46675@@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46676 ptp->start.dma_addr);
46677
46678 /* Clear flag that signals MC ready */
46679- ACCESS_ONCE(*start) = 0;
46680+ ACCESS_ONCE_RW(*start) = 0;
46681 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46682 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46683 EFX_BUG_ON_PARANOID(rc);
46684diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46685index 50617c5..b13724c 100644
46686--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46687+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46688@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46689
46690 writel(value, ioaddr + MMC_CNTRL);
46691
46692- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46693- MMC_CNTRL, value);
46694+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46695+// MMC_CNTRL, value);
46696 }
46697
46698 /* To mask all all interrupts.*/
46699diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46700index 7b594ce..1f6c5708 100644
46701--- a/drivers/net/hyperv/hyperv_net.h
46702+++ b/drivers/net/hyperv/hyperv_net.h
46703@@ -100,7 +100,7 @@ struct rndis_device {
46704
46705 enum rndis_device_state state;
46706 bool link_state;
46707- atomic_t new_req_id;
46708+ atomic_unchecked_t new_req_id;
46709
46710 spinlock_t request_lock;
46711 struct list_head req_list;
46712diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46713index b54fd25..9bd2bae 100644
46714--- a/drivers/net/hyperv/rndis_filter.c
46715+++ b/drivers/net/hyperv/rndis_filter.c
46716@@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46717 * template
46718 */
46719 set = &rndis_msg->msg.set_req;
46720- set->req_id = atomic_inc_return(&dev->new_req_id);
46721+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46722
46723 /* Add to the request list */
46724 spin_lock_irqsave(&dev->request_lock, flags);
46725@@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46726
46727 /* Setup the rndis set */
46728 halt = &request->request_msg.msg.halt_req;
46729- halt->req_id = atomic_inc_return(&dev->new_req_id);
46730+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46731
46732 /* Ignore return since this msg is optional. */
46733 rndis_filter_send_request(dev, request);
46734diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46735index bf0d55e..82bcfbd1 100644
46736--- a/drivers/net/ieee802154/fakehard.c
46737+++ b/drivers/net/ieee802154/fakehard.c
46738@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46739 phy->transmit_power = 0xbf;
46740
46741 dev->netdev_ops = &fake_ops;
46742- dev->ml_priv = &fake_mlme;
46743+ dev->ml_priv = (void *)&fake_mlme;
46744
46745 priv = netdev_priv(dev);
46746 priv->phy = phy;
46747diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46748index 20bb669..9a0e17e 100644
46749--- a/drivers/net/macvlan.c
46750+++ b/drivers/net/macvlan.c
46751@@ -991,13 +991,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46752 int macvlan_link_register(struct rtnl_link_ops *ops)
46753 {
46754 /* common fields */
46755- ops->priv_size = sizeof(struct macvlan_dev);
46756- ops->validate = macvlan_validate;
46757- ops->maxtype = IFLA_MACVLAN_MAX;
46758- ops->policy = macvlan_policy;
46759- ops->changelink = macvlan_changelink;
46760- ops->get_size = macvlan_get_size;
46761- ops->fill_info = macvlan_fill_info;
46762+ pax_open_kernel();
46763+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46764+ *(void **)&ops->validate = macvlan_validate;
46765+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46766+ *(const void **)&ops->policy = macvlan_policy;
46767+ *(void **)&ops->changelink = macvlan_changelink;
46768+ *(void **)&ops->get_size = macvlan_get_size;
46769+ *(void **)&ops->fill_info = macvlan_fill_info;
46770+ pax_close_kernel();
46771
46772 return rtnl_link_register(ops);
46773 };
46774@@ -1052,7 +1054,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46775 return NOTIFY_DONE;
46776 }
46777
46778-static struct notifier_block macvlan_notifier_block __read_mostly = {
46779+static struct notifier_block macvlan_notifier_block = {
46780 .notifier_call = macvlan_device_event,
46781 };
46782
46783diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46784index 3381c4f..dea5fd5 100644
46785--- a/drivers/net/macvtap.c
46786+++ b/drivers/net/macvtap.c
46787@@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46788 }
46789
46790 ret = 0;
46791- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46792+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46793 put_user(q->flags, &ifr->ifr_flags))
46794 ret = -EFAULT;
46795 macvtap_put_vlan(vlan);
46796@@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46797 return NOTIFY_DONE;
46798 }
46799
46800-static struct notifier_block macvtap_notifier_block __read_mostly = {
46801+static struct notifier_block macvtap_notifier_block = {
46802 .notifier_call = macvtap_device_event,
46803 };
46804
46805diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46806index daec9b0..6428fcb 100644
46807--- a/drivers/net/phy/mdio-bitbang.c
46808+++ b/drivers/net/phy/mdio-bitbang.c
46809@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46810 struct mdiobb_ctrl *ctrl = bus->priv;
46811
46812 module_put(ctrl->ops->owner);
46813+ mdiobus_unregister(bus);
46814 mdiobus_free(bus);
46815 }
46816 EXPORT_SYMBOL(free_mdio_bitbang);
46817diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46818index 72ff14b..11d442d 100644
46819--- a/drivers/net/ppp/ppp_generic.c
46820+++ b/drivers/net/ppp/ppp_generic.c
46821@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46822 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46823 struct ppp_stats stats;
46824 struct ppp_comp_stats cstats;
46825- char *vers;
46826
46827 switch (cmd) {
46828 case SIOCGPPPSTATS:
46829@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46830 break;
46831
46832 case SIOCGPPPVER:
46833- vers = PPP_VERSION;
46834- if (copy_to_user(addr, vers, strlen(vers) + 1))
46835+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46836 break;
46837 err = 0;
46838 break;
46839diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46840index 1252d9c..80e660b 100644
46841--- a/drivers/net/slip/slhc.c
46842+++ b/drivers/net/slip/slhc.c
46843@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46844 register struct tcphdr *thp;
46845 register struct iphdr *ip;
46846 register struct cstate *cs;
46847- int len, hdrlen;
46848+ long len, hdrlen;
46849 unsigned char *cp = icp;
46850
46851 /* We've got a compressed packet; read the change byte */
46852diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46853index c8624a8..f0a4f6a 100644
46854--- a/drivers/net/team/team.c
46855+++ b/drivers/net/team/team.c
46856@@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
46857 return NOTIFY_DONE;
46858 }
46859
46860-static struct notifier_block team_notifier_block __read_mostly = {
46861+static struct notifier_block team_notifier_block = {
46862 .notifier_call = team_device_event,
46863 };
46864
46865diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46866index 26f8635..c237839 100644
46867--- a/drivers/net/tun.c
46868+++ b/drivers/net/tun.c
46869@@ -1876,7 +1876,7 @@ unlock:
46870 }
46871
46872 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46873- unsigned long arg, int ifreq_len)
46874+ unsigned long arg, size_t ifreq_len)
46875 {
46876 struct tun_file *tfile = file->private_data;
46877 struct tun_struct *tun;
46878@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46879 unsigned int ifindex;
46880 int ret;
46881
46882+ if (ifreq_len > sizeof ifr)
46883+ return -EFAULT;
46884+
46885 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46886 if (copy_from_user(&ifr, argp, ifreq_len))
46887 return -EFAULT;
46888diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46889index 660bd5e..ac59452 100644
46890--- a/drivers/net/usb/hso.c
46891+++ b/drivers/net/usb/hso.c
46892@@ -71,7 +71,7 @@
46893 #include <asm/byteorder.h>
46894 #include <linux/serial_core.h>
46895 #include <linux/serial.h>
46896-
46897+#include <asm/local.h>
46898
46899 #define MOD_AUTHOR "Option Wireless"
46900 #define MOD_DESCRIPTION "USB High Speed Option driver"
46901@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46902 struct urb *urb;
46903
46904 urb = serial->rx_urb[0];
46905- if (serial->port.count > 0) {
46906+ if (atomic_read(&serial->port.count) > 0) {
46907 count = put_rxbuf_data(urb, serial);
46908 if (count == -1)
46909 return;
46910@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46911 DUMP1(urb->transfer_buffer, urb->actual_length);
46912
46913 /* Anyone listening? */
46914- if (serial->port.count == 0)
46915+ if (atomic_read(&serial->port.count) == 0)
46916 return;
46917
46918 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46919@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46920 tty_port_tty_set(&serial->port, tty);
46921
46922 /* check for port already opened, if not set the termios */
46923- serial->port.count++;
46924- if (serial->port.count == 1) {
46925+ if (atomic_inc_return(&serial->port.count) == 1) {
46926 serial->rx_state = RX_IDLE;
46927 /* Force default termio settings */
46928 _hso_serial_set_termios(tty, NULL);
46929@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46930 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46931 if (result) {
46932 hso_stop_serial_device(serial->parent);
46933- serial->port.count--;
46934+ atomic_dec(&serial->port.count);
46935 kref_put(&serial->parent->ref, hso_serial_ref_free);
46936 }
46937 } else {
46938@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46939
46940 /* reset the rts and dtr */
46941 /* do the actual close */
46942- serial->port.count--;
46943+ atomic_dec(&serial->port.count);
46944
46945- if (serial->port.count <= 0) {
46946- serial->port.count = 0;
46947+ if (atomic_read(&serial->port.count) <= 0) {
46948+ atomic_set(&serial->port.count, 0);
46949 tty_port_tty_set(&serial->port, NULL);
46950 if (!usb_gone)
46951 hso_stop_serial_device(serial->parent);
46952@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46953
46954 /* the actual setup */
46955 spin_lock_irqsave(&serial->serial_lock, flags);
46956- if (serial->port.count)
46957+ if (atomic_read(&serial->port.count))
46958 _hso_serial_set_termios(tty, old);
46959 else
46960 tty->termios = *old;
46961@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46962 D1("Pending read interrupt on port %d\n", i);
46963 spin_lock(&serial->serial_lock);
46964 if (serial->rx_state == RX_IDLE &&
46965- serial->port.count > 0) {
46966+ atomic_read(&serial->port.count) > 0) {
46967 /* Setup and send a ctrl req read on
46968 * port i */
46969 if (!serial->rx_urb_filled[0]) {
46970@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46971 /* Start all serial ports */
46972 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46973 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46974- if (dev2ser(serial_table[i])->port.count) {
46975+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46976 result =
46977 hso_start_serial_device(serial_table[i], GFP_NOIO);
46978 hso_kick_transmit(dev2ser(serial_table[i]));
46979diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46980index adb12f3..48005ab 100644
46981--- a/drivers/net/usb/r8152.c
46982+++ b/drivers/net/usb/r8152.c
46983@@ -513,7 +513,7 @@ struct r8152 {
46984 void (*disable)(struct r8152 *);
46985 void (*down)(struct r8152 *);
46986 void (*unload)(struct r8152 *);
46987- } rtl_ops;
46988+ } __no_const rtl_ops;
46989
46990 int intr_interval;
46991 u32 msg_enable;
46992diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46993index a2515887..6d13233 100644
46994--- a/drivers/net/usb/sierra_net.c
46995+++ b/drivers/net/usb/sierra_net.c
46996@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46997 /* atomic counter partially included in MAC address to make sure 2 devices
46998 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46999 */
47000-static atomic_t iface_counter = ATOMIC_INIT(0);
47001+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
47002
47003 /*
47004 * SYNC Timer Delay definition used to set the expiry time
47005@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
47006 dev->net->netdev_ops = &sierra_net_device_ops;
47007
47008 /* change MAC addr to include, ifacenum, and to be unique */
47009- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
47010+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
47011 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
47012
47013 /* we will have to manufacture ethernet headers, prepare template */
47014diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
47015index d091e52..568bb179 100644
47016--- a/drivers/net/vxlan.c
47017+++ b/drivers/net/vxlan.c
47018@@ -2847,7 +2847,7 @@ nla_put_failure:
47019 return -EMSGSIZE;
47020 }
47021
47022-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
47023+static struct rtnl_link_ops vxlan_link_ops = {
47024 .kind = "vxlan",
47025 .maxtype = IFLA_VXLAN_MAX,
47026 .policy = vxlan_policy,
47027@@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
47028 return NOTIFY_DONE;
47029 }
47030
47031-static struct notifier_block vxlan_notifier_block __read_mostly = {
47032+static struct notifier_block vxlan_notifier_block = {
47033 .notifier_call = vxlan_lowerdev_event,
47034 };
47035
47036diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
47037index 5920c99..ff2e4a5 100644
47038--- a/drivers/net/wan/lmc/lmc_media.c
47039+++ b/drivers/net/wan/lmc/lmc_media.c
47040@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
47041 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
47042
47043 lmc_media_t lmc_ds3_media = {
47044- lmc_ds3_init, /* special media init stuff */
47045- lmc_ds3_default, /* reset to default state */
47046- lmc_ds3_set_status, /* reset status to state provided */
47047- lmc_dummy_set_1, /* set clock source */
47048- lmc_dummy_set2_1, /* set line speed */
47049- lmc_ds3_set_100ft, /* set cable length */
47050- lmc_ds3_set_scram, /* set scrambler */
47051- lmc_ds3_get_link_status, /* get link status */
47052- lmc_dummy_set_1, /* set link status */
47053- lmc_ds3_set_crc_length, /* set CRC length */
47054- lmc_dummy_set_1, /* set T1 or E1 circuit type */
47055- lmc_ds3_watchdog
47056+ .init = lmc_ds3_init, /* special media init stuff */
47057+ .defaults = lmc_ds3_default, /* reset to default state */
47058+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
47059+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
47060+ .set_speed = lmc_dummy_set2_1, /* set line speed */
47061+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
47062+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
47063+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
47064+ .set_link_status = lmc_dummy_set_1, /* set link status */
47065+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
47066+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
47067+ .watchdog = lmc_ds3_watchdog
47068 };
47069
47070 lmc_media_t lmc_hssi_media = {
47071- lmc_hssi_init, /* special media init stuff */
47072- lmc_hssi_default, /* reset to default state */
47073- lmc_hssi_set_status, /* reset status to state provided */
47074- lmc_hssi_set_clock, /* set clock source */
47075- lmc_dummy_set2_1, /* set line speed */
47076- lmc_dummy_set_1, /* set cable length */
47077- lmc_dummy_set_1, /* set scrambler */
47078- lmc_hssi_get_link_status, /* get link status */
47079- lmc_hssi_set_link_status, /* set link status */
47080- lmc_hssi_set_crc_length, /* set CRC length */
47081- lmc_dummy_set_1, /* set T1 or E1 circuit type */
47082- lmc_hssi_watchdog
47083+ .init = lmc_hssi_init, /* special media init stuff */
47084+ .defaults = lmc_hssi_default, /* reset to default state */
47085+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
47086+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
47087+ .set_speed = lmc_dummy_set2_1, /* set line speed */
47088+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
47089+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47090+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
47091+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
47092+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
47093+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
47094+ .watchdog = lmc_hssi_watchdog
47095 };
47096
47097-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
47098- lmc_ssi_default, /* reset to default state */
47099- lmc_ssi_set_status, /* reset status to state provided */
47100- lmc_ssi_set_clock, /* set clock source */
47101- lmc_ssi_set_speed, /* set line speed */
47102- lmc_dummy_set_1, /* set cable length */
47103- lmc_dummy_set_1, /* set scrambler */
47104- lmc_ssi_get_link_status, /* get link status */
47105- lmc_ssi_set_link_status, /* set link status */
47106- lmc_ssi_set_crc_length, /* set CRC length */
47107- lmc_dummy_set_1, /* set T1 or E1 circuit type */
47108- lmc_ssi_watchdog
47109+lmc_media_t lmc_ssi_media = {
47110+ .init = lmc_ssi_init, /* special media init stuff */
47111+ .defaults = lmc_ssi_default, /* reset to default state */
47112+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
47113+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
47114+ .set_speed = lmc_ssi_set_speed, /* set line speed */
47115+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
47116+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47117+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
47118+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
47119+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
47120+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
47121+ .watchdog = lmc_ssi_watchdog
47122 };
47123
47124 lmc_media_t lmc_t1_media = {
47125- lmc_t1_init, /* special media init stuff */
47126- lmc_t1_default, /* reset to default state */
47127- lmc_t1_set_status, /* reset status to state provided */
47128- lmc_t1_set_clock, /* set clock source */
47129- lmc_dummy_set2_1, /* set line speed */
47130- lmc_dummy_set_1, /* set cable length */
47131- lmc_dummy_set_1, /* set scrambler */
47132- lmc_t1_get_link_status, /* get link status */
47133- lmc_dummy_set_1, /* set link status */
47134- lmc_t1_set_crc_length, /* set CRC length */
47135- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47136- lmc_t1_watchdog
47137+ .init = lmc_t1_init, /* special media init stuff */
47138+ .defaults = lmc_t1_default, /* reset to default state */
47139+ .set_status = lmc_t1_set_status, /* reset status to state provided */
47140+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
47141+ .set_speed = lmc_dummy_set2_1, /* set line speed */
47142+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
47143+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47144+ .get_link_status = lmc_t1_get_link_status, /* get link status */
47145+ .set_link_status = lmc_dummy_set_1, /* set link status */
47146+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
47147+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47148+ .watchdog = lmc_t1_watchdog
47149 };
47150
47151 static void
47152diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
47153index feacc3b..5bac0de 100644
47154--- a/drivers/net/wan/z85230.c
47155+++ b/drivers/net/wan/z85230.c
47156@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
47157
47158 struct z8530_irqhandler z8530_sync =
47159 {
47160- z8530_rx,
47161- z8530_tx,
47162- z8530_status
47163+ .rx = z8530_rx,
47164+ .tx = z8530_tx,
47165+ .status = z8530_status
47166 };
47167
47168 EXPORT_SYMBOL(z8530_sync);
47169@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
47170 }
47171
47172 static struct z8530_irqhandler z8530_dma_sync = {
47173- z8530_dma_rx,
47174- z8530_dma_tx,
47175- z8530_dma_status
47176+ .rx = z8530_dma_rx,
47177+ .tx = z8530_dma_tx,
47178+ .status = z8530_dma_status
47179 };
47180
47181 static struct z8530_irqhandler z8530_txdma_sync = {
47182- z8530_rx,
47183- z8530_dma_tx,
47184- z8530_dma_status
47185+ .rx = z8530_rx,
47186+ .tx = z8530_dma_tx,
47187+ .status = z8530_dma_status
47188 };
47189
47190 /**
47191@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
47192
47193 struct z8530_irqhandler z8530_nop=
47194 {
47195- z8530_rx_clear,
47196- z8530_tx_clear,
47197- z8530_status_clear
47198+ .rx = z8530_rx_clear,
47199+ .tx = z8530_tx_clear,
47200+ .status = z8530_status_clear
47201 };
47202
47203
47204diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
47205index 0b60295..b8bfa5b 100644
47206--- a/drivers/net/wimax/i2400m/rx.c
47207+++ b/drivers/net/wimax/i2400m/rx.c
47208@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
47209 if (i2400m->rx_roq == NULL)
47210 goto error_roq_alloc;
47211
47212- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
47213+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
47214 GFP_KERNEL);
47215 if (rd == NULL) {
47216 result = -ENOMEM;
47217diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
47218index edf4b57..68b51c0 100644
47219--- a/drivers/net/wireless/airo.c
47220+++ b/drivers/net/wireless/airo.c
47221@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
47222 struct airo_info *ai = dev->ml_priv;
47223 int ridcode;
47224 int enabled;
47225- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47226+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47227 unsigned char *iobuf;
47228
47229 /* Only super-user can write RIDs */
47230diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
47231index 99b3bfa..9559372 100644
47232--- a/drivers/net/wireless/at76c50x-usb.c
47233+++ b/drivers/net/wireless/at76c50x-usb.c
47234@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
47235 }
47236
47237 /* Convert timeout from the DFU status to jiffies */
47238-static inline unsigned long at76_get_timeout(struct dfu_status *s)
47239+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
47240 {
47241 return msecs_to_jiffies((s->poll_timeout[2] << 16)
47242 | (s->poll_timeout[1] << 8)
47243diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
47244index edc57ab..ff49e0a 100644
47245--- a/drivers/net/wireless/ath/ath10k/htc.c
47246+++ b/drivers/net/wireless/ath/ath10k/htc.c
47247@@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
47248 /* registered target arrival callback from the HIF layer */
47249 int ath10k_htc_init(struct ath10k *ar)
47250 {
47251- struct ath10k_hif_cb htc_callbacks;
47252+ static struct ath10k_hif_cb htc_callbacks = {
47253+ .rx_completion = ath10k_htc_rx_completion_handler,
47254+ .tx_completion = ath10k_htc_tx_completion_handler,
47255+ };
47256 struct ath10k_htc_ep *ep = NULL;
47257 struct ath10k_htc *htc = &ar->htc;
47258
47259@@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
47260 ath10k_htc_reset_endpoint_states(htc);
47261
47262 /* setup HIF layer callbacks */
47263- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
47264- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
47265 htc->ar = ar;
47266
47267 /* Get HIF default pipe for HTC message exchange */
47268diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
47269index 4716d33..a688310 100644
47270--- a/drivers/net/wireless/ath/ath10k/htc.h
47271+++ b/drivers/net/wireless/ath/ath10k/htc.h
47272@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
47273
47274 struct ath10k_htc_ops {
47275 void (*target_send_suspend_complete)(struct ath10k *ar);
47276-};
47277+} __no_const;
47278
47279 struct ath10k_htc_ep_ops {
47280 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
47281 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
47282 void (*ep_tx_credits)(struct ath10k *);
47283-};
47284+} __no_const;
47285
47286 /* service connection information */
47287 struct ath10k_htc_svc_conn_req {
47288diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47289index 741b38d..b7ae41b 100644
47290--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47291+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47292@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47293 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
47294 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
47295
47296- ACCESS_ONCE(ads->ds_link) = i->link;
47297- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
47298+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
47299+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
47300
47301 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
47302 ctl6 = SM(i->keytype, AR_EncrType);
47303@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47304
47305 if ((i->is_first || i->is_last) &&
47306 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
47307- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
47308+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
47309 | set11nTries(i->rates, 1)
47310 | set11nTries(i->rates, 2)
47311 | set11nTries(i->rates, 3)
47312 | (i->dur_update ? AR_DurUpdateEna : 0)
47313 | SM(0, AR_BurstDur);
47314
47315- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
47316+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
47317 | set11nRate(i->rates, 1)
47318 | set11nRate(i->rates, 2)
47319 | set11nRate(i->rates, 3);
47320 } else {
47321- ACCESS_ONCE(ads->ds_ctl2) = 0;
47322- ACCESS_ONCE(ads->ds_ctl3) = 0;
47323+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
47324+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
47325 }
47326
47327 if (!i->is_first) {
47328- ACCESS_ONCE(ads->ds_ctl0) = 0;
47329- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47330- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47331+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
47332+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47333+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47334 return;
47335 }
47336
47337@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47338 break;
47339 }
47340
47341- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47342+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47343 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47344 | SM(i->txpower, AR_XmitPower)
47345 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47346@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47347 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
47348 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
47349
47350- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47351- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47352+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47353+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47354
47355 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
47356 return;
47357
47358- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47359+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47360 | set11nPktDurRTSCTS(i->rates, 1);
47361
47362- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47363+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47364 | set11nPktDurRTSCTS(i->rates, 3);
47365
47366- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47367+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47368 | set11nRateFlags(i->rates, 1)
47369 | set11nRateFlags(i->rates, 2)
47370 | set11nRateFlags(i->rates, 3)
47371diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47372index 729ffbf..49f50e3 100644
47373--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47374+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47375@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47376 (i->qcu << AR_TxQcuNum_S) | desc_len;
47377
47378 checksum += val;
47379- ACCESS_ONCE(ads->info) = val;
47380+ ACCESS_ONCE_RW(ads->info) = val;
47381
47382 checksum += i->link;
47383- ACCESS_ONCE(ads->link) = i->link;
47384+ ACCESS_ONCE_RW(ads->link) = i->link;
47385
47386 checksum += i->buf_addr[0];
47387- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
47388+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
47389 checksum += i->buf_addr[1];
47390- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
47391+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
47392 checksum += i->buf_addr[2];
47393- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
47394+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
47395 checksum += i->buf_addr[3];
47396- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
47397+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
47398
47399 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
47400- ACCESS_ONCE(ads->ctl3) = val;
47401+ ACCESS_ONCE_RW(ads->ctl3) = val;
47402 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
47403- ACCESS_ONCE(ads->ctl5) = val;
47404+ ACCESS_ONCE_RW(ads->ctl5) = val;
47405 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
47406- ACCESS_ONCE(ads->ctl7) = val;
47407+ ACCESS_ONCE_RW(ads->ctl7) = val;
47408 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
47409- ACCESS_ONCE(ads->ctl9) = val;
47410+ ACCESS_ONCE_RW(ads->ctl9) = val;
47411
47412 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
47413- ACCESS_ONCE(ads->ctl10) = checksum;
47414+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
47415
47416 if (i->is_first || i->is_last) {
47417- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
47418+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
47419 | set11nTries(i->rates, 1)
47420 | set11nTries(i->rates, 2)
47421 | set11nTries(i->rates, 3)
47422 | (i->dur_update ? AR_DurUpdateEna : 0)
47423 | SM(0, AR_BurstDur);
47424
47425- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
47426+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
47427 | set11nRate(i->rates, 1)
47428 | set11nRate(i->rates, 2)
47429 | set11nRate(i->rates, 3);
47430 } else {
47431- ACCESS_ONCE(ads->ctl13) = 0;
47432- ACCESS_ONCE(ads->ctl14) = 0;
47433+ ACCESS_ONCE_RW(ads->ctl13) = 0;
47434+ ACCESS_ONCE_RW(ads->ctl14) = 0;
47435 }
47436
47437 ads->ctl20 = 0;
47438@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47439
47440 ctl17 = SM(i->keytype, AR_EncrType);
47441 if (!i->is_first) {
47442- ACCESS_ONCE(ads->ctl11) = 0;
47443- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47444- ACCESS_ONCE(ads->ctl15) = 0;
47445- ACCESS_ONCE(ads->ctl16) = 0;
47446- ACCESS_ONCE(ads->ctl17) = ctl17;
47447- ACCESS_ONCE(ads->ctl18) = 0;
47448- ACCESS_ONCE(ads->ctl19) = 0;
47449+ ACCESS_ONCE_RW(ads->ctl11) = 0;
47450+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47451+ ACCESS_ONCE_RW(ads->ctl15) = 0;
47452+ ACCESS_ONCE_RW(ads->ctl16) = 0;
47453+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47454+ ACCESS_ONCE_RW(ads->ctl18) = 0;
47455+ ACCESS_ONCE_RW(ads->ctl19) = 0;
47456 return;
47457 }
47458
47459- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47460+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47461 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47462 | SM(i->txpower, AR_XmitPower)
47463 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47464@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47465 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
47466 ctl12 |= SM(val, AR_PAPRDChainMask);
47467
47468- ACCESS_ONCE(ads->ctl12) = ctl12;
47469- ACCESS_ONCE(ads->ctl17) = ctl17;
47470+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
47471+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47472
47473- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47474+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47475 | set11nPktDurRTSCTS(i->rates, 1);
47476
47477- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47478+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47479 | set11nPktDurRTSCTS(i->rates, 3);
47480
47481- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
47482+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
47483 | set11nRateFlags(i->rates, 1)
47484 | set11nRateFlags(i->rates, 2)
47485 | set11nRateFlags(i->rates, 3)
47486 | SM(i->rtscts_rate, AR_RTSCTSRate);
47487
47488- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
47489+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
47490 }
47491
47492 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
47493diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
47494index 0acd4b5..0591c91 100644
47495--- a/drivers/net/wireless/ath/ath9k/hw.h
47496+++ b/drivers/net/wireless/ath/ath9k/hw.h
47497@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
47498
47499 /* ANI */
47500 void (*ani_cache_ini_regs)(struct ath_hw *ah);
47501-};
47502+} __no_const;
47503
47504 /**
47505 * struct ath_spec_scan - parameters for Atheros spectral scan
47506@@ -706,7 +706,7 @@ struct ath_hw_ops {
47507 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47508 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47509 #endif
47510-};
47511+} __no_const;
47512
47513 struct ath_nf_limits {
47514 s16 max;
47515diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47516index 92190da..f3a4c4c 100644
47517--- a/drivers/net/wireless/b43/phy_lp.c
47518+++ b/drivers/net/wireless/b43/phy_lp.c
47519@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47520 {
47521 struct ssb_bus *bus = dev->dev->sdev->bus;
47522
47523- static const struct b206x_channel *chandata = NULL;
47524+ const struct b206x_channel *chandata = NULL;
47525 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47526 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47527 u16 old_comm15, scale;
47528diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47529index 0487461..fd9e84a 100644
47530--- a/drivers/net/wireless/iwlegacy/3945-mac.c
47531+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47532@@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47533 */
47534 if (il3945_mod_params.disable_hw_scan) {
47535 D_INFO("Disabling hw_scan\n");
47536- il3945_mac_ops.hw_scan = NULL;
47537+ pax_open_kernel();
47538+ *(void **)&il3945_mac_ops.hw_scan = NULL;
47539+ pax_close_kernel();
47540 }
47541
47542 D_INFO("*** LOAD DRIVER ***\n");
47543diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47544index d2fe259..0c4c682 100644
47545--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47546+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47547@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47548 {
47549 struct iwl_priv *priv = file->private_data;
47550 char buf[64];
47551- int buf_size;
47552+ size_t buf_size;
47553 u32 offset, len;
47554
47555 memset(buf, 0, sizeof(buf));
47556@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47557 struct iwl_priv *priv = file->private_data;
47558
47559 char buf[8];
47560- int buf_size;
47561+ size_t buf_size;
47562 u32 reset_flag;
47563
47564 memset(buf, 0, sizeof(buf));
47565@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47566 {
47567 struct iwl_priv *priv = file->private_data;
47568 char buf[8];
47569- int buf_size;
47570+ size_t buf_size;
47571 int ht40;
47572
47573 memset(buf, 0, sizeof(buf));
47574@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47575 {
47576 struct iwl_priv *priv = file->private_data;
47577 char buf[8];
47578- int buf_size;
47579+ size_t buf_size;
47580 int value;
47581
47582 memset(buf, 0, sizeof(buf));
47583@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47584 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47585 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47586
47587-static const char *fmt_value = " %-30s %10u\n";
47588-static const char *fmt_hex = " %-30s 0x%02X\n";
47589-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47590-static const char *fmt_header =
47591+static const char fmt_value[] = " %-30s %10u\n";
47592+static const char fmt_hex[] = " %-30s 0x%02X\n";
47593+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47594+static const char fmt_header[] =
47595 "%-32s current cumulative delta max\n";
47596
47597 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47598@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47599 {
47600 struct iwl_priv *priv = file->private_data;
47601 char buf[8];
47602- int buf_size;
47603+ size_t buf_size;
47604 int clear;
47605
47606 memset(buf, 0, sizeof(buf));
47607@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47608 {
47609 struct iwl_priv *priv = file->private_data;
47610 char buf[8];
47611- int buf_size;
47612+ size_t buf_size;
47613 int trace;
47614
47615 memset(buf, 0, sizeof(buf));
47616@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47617 {
47618 struct iwl_priv *priv = file->private_data;
47619 char buf[8];
47620- int buf_size;
47621+ size_t buf_size;
47622 int missed;
47623
47624 memset(buf, 0, sizeof(buf));
47625@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47626
47627 struct iwl_priv *priv = file->private_data;
47628 char buf[8];
47629- int buf_size;
47630+ size_t buf_size;
47631 int plcp;
47632
47633 memset(buf, 0, sizeof(buf));
47634@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47635
47636 struct iwl_priv *priv = file->private_data;
47637 char buf[8];
47638- int buf_size;
47639+ size_t buf_size;
47640 int flush;
47641
47642 memset(buf, 0, sizeof(buf));
47643@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47644
47645 struct iwl_priv *priv = file->private_data;
47646 char buf[8];
47647- int buf_size;
47648+ size_t buf_size;
47649 int rts;
47650
47651 if (!priv->cfg->ht_params)
47652@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47653 {
47654 struct iwl_priv *priv = file->private_data;
47655 char buf[8];
47656- int buf_size;
47657+ size_t buf_size;
47658
47659 memset(buf, 0, sizeof(buf));
47660 buf_size = min(count, sizeof(buf) - 1);
47661@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47662 struct iwl_priv *priv = file->private_data;
47663 u32 event_log_flag;
47664 char buf[8];
47665- int buf_size;
47666+ size_t buf_size;
47667
47668 /* check that the interface is up */
47669 if (!iwl_is_ready(priv))
47670@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47671 struct iwl_priv *priv = file->private_data;
47672 char buf[8];
47673 u32 calib_disabled;
47674- int buf_size;
47675+ size_t buf_size;
47676
47677 memset(buf, 0, sizeof(buf));
47678 buf_size = min(count, sizeof(buf) - 1);
47679diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47680index ea7e70c..bc0c45f 100644
47681--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47682+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47683@@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47684 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47685 {
47686 struct iwl_nvm_data *data = priv->nvm_data;
47687- char *debug_msg;
47688+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47689
47690 if (data->sku_cap_11n_enable &&
47691 !priv->cfg->ht_params) {
47692@@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47693 return -EINVAL;
47694 }
47695
47696- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47697 IWL_DEBUG_INFO(priv, debug_msg,
47698 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47699 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47700diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47701index 8d42fd9..d923d65 100644
47702--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47703+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47704@@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47705 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47706
47707 char buf[8];
47708- int buf_size;
47709+ size_t buf_size;
47710 u32 reset_flag;
47711
47712 memset(buf, 0, sizeof(buf));
47713@@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47714 {
47715 struct iwl_trans *trans = file->private_data;
47716 char buf[8];
47717- int buf_size;
47718+ size_t buf_size;
47719 int csr;
47720
47721 memset(buf, 0, sizeof(buf));
47722diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47723index 69d4c31..bd0b316 100644
47724--- a/drivers/net/wireless/mac80211_hwsim.c
47725+++ b/drivers/net/wireless/mac80211_hwsim.c
47726@@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
47727 if (channels < 1)
47728 return -EINVAL;
47729
47730- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47731- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47732- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47733- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47734- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47735- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47736- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47737- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47738- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47739- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47740- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47741- mac80211_hwsim_assign_vif_chanctx;
47742- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47743- mac80211_hwsim_unassign_vif_chanctx;
47744+ pax_open_kernel();
47745+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47746+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47747+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47748+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47749+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47750+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47751+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47752+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47753+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47754+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47755+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47756+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47757+ pax_close_kernel();
47758
47759 spin_lock_init(&hwsim_radio_lock);
47760 INIT_LIST_HEAD(&hwsim_radios);
47761diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47762index 5028557..91cf394 100644
47763--- a/drivers/net/wireless/rndis_wlan.c
47764+++ b/drivers/net/wireless/rndis_wlan.c
47765@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47766
47767 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47768
47769- if (rts_threshold < 0 || rts_threshold > 2347)
47770+ if (rts_threshold > 2347)
47771 rts_threshold = 2347;
47772
47773 tmp = cpu_to_le32(rts_threshold);
47774diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47775index e3b885d..7a7de2f 100644
47776--- a/drivers/net/wireless/rt2x00/rt2x00.h
47777+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47778@@ -375,7 +375,7 @@ struct rt2x00_intf {
47779 * for hardware which doesn't support hardware
47780 * sequence counting.
47781 */
47782- atomic_t seqno;
47783+ atomic_unchecked_t seqno;
47784 };
47785
47786 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47787diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47788index 5642ccc..01f03eb 100644
47789--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47790+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47791@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47792 * sequence counter given by mac80211.
47793 */
47794 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47795- seqno = atomic_add_return(0x10, &intf->seqno);
47796+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47797 else
47798- seqno = atomic_read(&intf->seqno);
47799+ seqno = atomic_read_unchecked(&intf->seqno);
47800
47801 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47802 hdr->seq_ctrl |= cpu_to_le16(seqno);
47803diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47804index e2b3d9c..67a5184 100644
47805--- a/drivers/net/wireless/ti/wl1251/sdio.c
47806+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47807@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47808
47809 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47810
47811- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47812- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47813+ pax_open_kernel();
47814+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47815+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47816+ pax_close_kernel();
47817
47818 wl1251_info("using dedicated interrupt line");
47819 } else {
47820- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47821- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47822+ pax_open_kernel();
47823+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47824+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47825+ pax_close_kernel();
47826
47827 wl1251_info("using SDIO interrupt");
47828 }
47829diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47830index be7129b..4161356 100644
47831--- a/drivers/net/wireless/ti/wl12xx/main.c
47832+++ b/drivers/net/wireless/ti/wl12xx/main.c
47833@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47834 sizeof(wl->conf.mem));
47835
47836 /* read data preparation is only needed by wl127x */
47837- wl->ops->prepare_read = wl127x_prepare_read;
47838+ pax_open_kernel();
47839+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47840+ pax_close_kernel();
47841
47842 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47843 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47844@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47845 sizeof(wl->conf.mem));
47846
47847 /* read data preparation is only needed by wl127x */
47848- wl->ops->prepare_read = wl127x_prepare_read;
47849+ pax_open_kernel();
47850+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47851+ pax_close_kernel();
47852
47853 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47854 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47855diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47856index ec37b16..7e34d66 100644
47857--- a/drivers/net/wireless/ti/wl18xx/main.c
47858+++ b/drivers/net/wireless/ti/wl18xx/main.c
47859@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47860 }
47861
47862 if (!checksum_param) {
47863- wl18xx_ops.set_rx_csum = NULL;
47864- wl18xx_ops.init_vif = NULL;
47865+ pax_open_kernel();
47866+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47867+ *(void **)&wl18xx_ops.init_vif = NULL;
47868+ pax_close_kernel();
47869 }
47870
47871 /* Enable 11a Band only if we have 5G antennas */
47872diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47873index a912dc0..a8225ba 100644
47874--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47875+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47876@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47877 {
47878 struct zd_usb *usb = urb->context;
47879 struct zd_usb_interrupt *intr = &usb->intr;
47880- int len;
47881+ unsigned int len;
47882 u16 int_num;
47883
47884 ZD_ASSERT(in_interrupt());
47885diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47886index 683671a..4519fc2 100644
47887--- a/drivers/nfc/nfcwilink.c
47888+++ b/drivers/nfc/nfcwilink.c
47889@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47890
47891 static int nfcwilink_probe(struct platform_device *pdev)
47892 {
47893- static struct nfcwilink *drv;
47894+ struct nfcwilink *drv;
47895 int rc;
47896 __u32 protocols;
47897
47898diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47899index d93b2b6..ae50401 100644
47900--- a/drivers/oprofile/buffer_sync.c
47901+++ b/drivers/oprofile/buffer_sync.c
47902@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47903 if (cookie == NO_COOKIE)
47904 offset = pc;
47905 if (cookie == INVALID_COOKIE) {
47906- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47907+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47908 offset = pc;
47909 }
47910 if (cookie != last_cookie) {
47911@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47912 /* add userspace sample */
47913
47914 if (!mm) {
47915- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47916+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47917 return 0;
47918 }
47919
47920 cookie = lookup_dcookie(mm, s->eip, &offset);
47921
47922 if (cookie == INVALID_COOKIE) {
47923- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47924+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47925 return 0;
47926 }
47927
47928@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47929 /* ignore backtraces if failed to add a sample */
47930 if (state == sb_bt_start) {
47931 state = sb_bt_ignore;
47932- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47933+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47934 }
47935 }
47936 release_mm(mm);
47937diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47938index c0cc4e7..44d4e54 100644
47939--- a/drivers/oprofile/event_buffer.c
47940+++ b/drivers/oprofile/event_buffer.c
47941@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47942 }
47943
47944 if (buffer_pos == buffer_size) {
47945- atomic_inc(&oprofile_stats.event_lost_overflow);
47946+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47947 return;
47948 }
47949
47950diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47951index ed2c3ec..deda85a 100644
47952--- a/drivers/oprofile/oprof.c
47953+++ b/drivers/oprofile/oprof.c
47954@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47955 if (oprofile_ops.switch_events())
47956 return;
47957
47958- atomic_inc(&oprofile_stats.multiplex_counter);
47959+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47960 start_switch_worker();
47961 }
47962
47963diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47964index ee2cfce..7f8f699 100644
47965--- a/drivers/oprofile/oprofile_files.c
47966+++ b/drivers/oprofile/oprofile_files.c
47967@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47968
47969 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47970
47971-static ssize_t timeout_read(struct file *file, char __user *buf,
47972+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47973 size_t count, loff_t *offset)
47974 {
47975 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47976diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47977index 59659ce..6c860a0 100644
47978--- a/drivers/oprofile/oprofile_stats.c
47979+++ b/drivers/oprofile/oprofile_stats.c
47980@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47981 cpu_buf->sample_invalid_eip = 0;
47982 }
47983
47984- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47985- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47986- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47987- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47988- atomic_set(&oprofile_stats.multiplex_counter, 0);
47989+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47990+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47991+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47992+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47993+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47994 }
47995
47996
47997diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47998index 1fc622b..8c48fc3 100644
47999--- a/drivers/oprofile/oprofile_stats.h
48000+++ b/drivers/oprofile/oprofile_stats.h
48001@@ -13,11 +13,11 @@
48002 #include <linux/atomic.h>
48003
48004 struct oprofile_stat_struct {
48005- atomic_t sample_lost_no_mm;
48006- atomic_t sample_lost_no_mapping;
48007- atomic_t bt_lost_no_mapping;
48008- atomic_t event_lost_overflow;
48009- atomic_t multiplex_counter;
48010+ atomic_unchecked_t sample_lost_no_mm;
48011+ atomic_unchecked_t sample_lost_no_mapping;
48012+ atomic_unchecked_t bt_lost_no_mapping;
48013+ atomic_unchecked_t event_lost_overflow;
48014+ atomic_unchecked_t multiplex_counter;
48015 };
48016
48017 extern struct oprofile_stat_struct oprofile_stats;
48018diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
48019index 3f49345..c750d0b 100644
48020--- a/drivers/oprofile/oprofilefs.c
48021+++ b/drivers/oprofile/oprofilefs.c
48022@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
48023
48024 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
48025 {
48026- atomic_t *val = file->private_data;
48027- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
48028+ atomic_unchecked_t *val = file->private_data;
48029+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
48030 }
48031
48032
48033@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
48034
48035
48036 int oprofilefs_create_ro_atomic(struct dentry *root,
48037- char const *name, atomic_t *val)
48038+ char const *name, atomic_unchecked_t *val)
48039 {
48040 return __oprofilefs_create_file(root, name,
48041 &atomic_ro_fops, 0444, val);
48042diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
48043index 61be1d9..dec05d7 100644
48044--- a/drivers/oprofile/timer_int.c
48045+++ b/drivers/oprofile/timer_int.c
48046@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
48047 return NOTIFY_OK;
48048 }
48049
48050-static struct notifier_block __refdata oprofile_cpu_notifier = {
48051+static struct notifier_block oprofile_cpu_notifier = {
48052 .notifier_call = oprofile_cpu_notify,
48053 };
48054
48055diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
48056index 92ed045..62d39bd7 100644
48057--- a/drivers/parport/procfs.c
48058+++ b/drivers/parport/procfs.c
48059@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
48060
48061 *ppos += len;
48062
48063- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
48064+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
48065 }
48066
48067 #ifdef CONFIG_PARPORT_1284
48068@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
48069
48070 *ppos += len;
48071
48072- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
48073+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
48074 }
48075 #endif /* IEEE1284.3 support. */
48076
48077diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
48078index 8dcccff..35d701d 100644
48079--- a/drivers/pci/hotplug/acpiphp_ibm.c
48080+++ b/drivers/pci/hotplug/acpiphp_ibm.c
48081@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
48082 goto init_cleanup;
48083 }
48084
48085- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
48086+ pax_open_kernel();
48087+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
48088+ pax_close_kernel();
48089 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
48090
48091 return retval;
48092diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
48093index 7536eef..52dc8fa 100644
48094--- a/drivers/pci/hotplug/cpcihp_generic.c
48095+++ b/drivers/pci/hotplug/cpcihp_generic.c
48096@@ -73,7 +73,6 @@ static u16 port;
48097 static unsigned int enum_bit;
48098 static u8 enum_mask;
48099
48100-static struct cpci_hp_controller_ops generic_hpc_ops;
48101 static struct cpci_hp_controller generic_hpc;
48102
48103 static int __init validate_parameters(void)
48104@@ -139,6 +138,10 @@ static int query_enum(void)
48105 return ((value & enum_mask) == enum_mask);
48106 }
48107
48108+static struct cpci_hp_controller_ops generic_hpc_ops = {
48109+ .query_enum = query_enum,
48110+};
48111+
48112 static int __init cpcihp_generic_init(void)
48113 {
48114 int status;
48115@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
48116 pci_dev_put(dev);
48117
48118 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
48119- generic_hpc_ops.query_enum = query_enum;
48120 generic_hpc.ops = &generic_hpc_ops;
48121
48122 status = cpci_hp_register_controller(&generic_hpc);
48123diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
48124index e8c4a7c..7046f5c 100644
48125--- a/drivers/pci/hotplug/cpcihp_zt5550.c
48126+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
48127@@ -59,7 +59,6 @@
48128 /* local variables */
48129 static bool debug;
48130 static bool poll;
48131-static struct cpci_hp_controller_ops zt5550_hpc_ops;
48132 static struct cpci_hp_controller zt5550_hpc;
48133
48134 /* Primary cPCI bus bridge device */
48135@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
48136 return 0;
48137 }
48138
48139+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
48140+ .query_enum = zt5550_hc_query_enum,
48141+};
48142+
48143 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
48144 {
48145 int status;
48146@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
48147 dbg("returned from zt5550_hc_config");
48148
48149 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
48150- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
48151 zt5550_hpc.ops = &zt5550_hpc_ops;
48152 if(!poll) {
48153 zt5550_hpc.irq = hc_dev->irq;
48154 zt5550_hpc.irq_flags = IRQF_SHARED;
48155 zt5550_hpc.dev_id = hc_dev;
48156
48157- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48158- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48159- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48160+ pax_open_kernel();
48161+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48162+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48163+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48164+ pax_open_kernel();
48165 } else {
48166 info("using ENUM# polling mode");
48167 }
48168diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
48169index 76ba8a1..20ca857 100644
48170--- a/drivers/pci/hotplug/cpqphp_nvram.c
48171+++ b/drivers/pci/hotplug/cpqphp_nvram.c
48172@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
48173
48174 void compaq_nvram_init (void __iomem *rom_start)
48175 {
48176+
48177+#ifndef CONFIG_PAX_KERNEXEC
48178 if (rom_start) {
48179 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
48180 }
48181+#endif
48182+
48183 dbg("int15 entry = %p\n", compaq_int15_entry_point);
48184
48185 /* initialize our int15 lock */
48186diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
48187index cfa92a9..29539c5 100644
48188--- a/drivers/pci/hotplug/pci_hotplug_core.c
48189+++ b/drivers/pci/hotplug/pci_hotplug_core.c
48190@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
48191 return -EINVAL;
48192 }
48193
48194- slot->ops->owner = owner;
48195- slot->ops->mod_name = mod_name;
48196+ pax_open_kernel();
48197+ *(struct module **)&slot->ops->owner = owner;
48198+ *(const char **)&slot->ops->mod_name = mod_name;
48199+ pax_close_kernel();
48200
48201 mutex_lock(&pci_hp_mutex);
48202 /*
48203diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
48204index 53b58de..4479896 100644
48205--- a/drivers/pci/hotplug/pciehp_core.c
48206+++ b/drivers/pci/hotplug/pciehp_core.c
48207@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
48208 struct slot *slot = ctrl->slot;
48209 struct hotplug_slot *hotplug = NULL;
48210 struct hotplug_slot_info *info = NULL;
48211- struct hotplug_slot_ops *ops = NULL;
48212+ hotplug_slot_ops_no_const *ops = NULL;
48213 char name[SLOT_NAME_SIZE];
48214 int retval = -ENOMEM;
48215
48216diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
48217index fb02fc2..83dc2c3 100644
48218--- a/drivers/pci/msi.c
48219+++ b/drivers/pci/msi.c
48220@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
48221 {
48222 struct attribute **msi_attrs;
48223 struct attribute *msi_attr;
48224- struct device_attribute *msi_dev_attr;
48225- struct attribute_group *msi_irq_group;
48226+ device_attribute_no_const *msi_dev_attr;
48227+ attribute_group_no_const *msi_irq_group;
48228 const struct attribute_group **msi_irq_groups;
48229 struct msi_desc *entry;
48230 int ret = -ENOMEM;
48231@@ -589,7 +589,7 @@ error_attrs:
48232 count = 0;
48233 msi_attr = msi_attrs[count];
48234 while (msi_attr) {
48235- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
48236+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
48237 kfree(msi_attr->name);
48238 kfree(msi_dev_attr);
48239 ++count;
48240diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
48241index 276ef9c..1d33a36 100644
48242--- a/drivers/pci/pci-sysfs.c
48243+++ b/drivers/pci/pci-sysfs.c
48244@@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
48245 {
48246 /* allocate attribute structure, piggyback attribute name */
48247 int name_len = write_combine ? 13 : 10;
48248- struct bin_attribute *res_attr;
48249+ bin_attribute_no_const *res_attr;
48250 int retval;
48251
48252 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
48253@@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
48254 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
48255 {
48256 int retval;
48257- struct bin_attribute *attr;
48258+ bin_attribute_no_const *attr;
48259
48260 /* If the device has VPD, try to expose it in sysfs. */
48261 if (dev->vpd) {
48262@@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
48263 {
48264 int retval;
48265 int rom_size = 0;
48266- struct bin_attribute *attr;
48267+ bin_attribute_no_const *attr;
48268
48269 if (!sysfs_initialized)
48270 return -EACCES;
48271diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
48272index 4df38df..b6bb7fe 100644
48273--- a/drivers/pci/pci.h
48274+++ b/drivers/pci/pci.h
48275@@ -93,7 +93,7 @@ struct pci_vpd_ops {
48276 struct pci_vpd {
48277 unsigned int len;
48278 const struct pci_vpd_ops *ops;
48279- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
48280+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
48281 };
48282
48283 int pci_vpd_pci22_init(struct pci_dev *dev);
48284diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
48285index e1e7026..d28dd33 100644
48286--- a/drivers/pci/pcie/aspm.c
48287+++ b/drivers/pci/pcie/aspm.c
48288@@ -27,9 +27,9 @@
48289 #define MODULE_PARAM_PREFIX "pcie_aspm."
48290
48291 /* Note: those are not register definitions */
48292-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
48293-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
48294-#define ASPM_STATE_L1 (4) /* L1 state */
48295+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
48296+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
48297+#define ASPM_STATE_L1 (4U) /* L1 state */
48298 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
48299 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
48300
48301diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
48302index 6e34498..9911975 100644
48303--- a/drivers/pci/probe.c
48304+++ b/drivers/pci/probe.c
48305@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
48306 struct pci_bus_region region, inverted_region;
48307 bool bar_too_big = false, bar_disabled = false;
48308
48309- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
48310+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
48311
48312 /* No printks while decoding is disabled! */
48313 if (!dev->mmio_always_on) {
48314diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
48315index 46d1378..30e452b 100644
48316--- a/drivers/pci/proc.c
48317+++ b/drivers/pci/proc.c
48318@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
48319 static int __init pci_proc_init(void)
48320 {
48321 struct pci_dev *dev = NULL;
48322+
48323+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48324+#ifdef CONFIG_GRKERNSEC_PROC_USER
48325+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
48326+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48327+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48328+#endif
48329+#else
48330 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
48331+#endif
48332 proc_create("devices", 0, proc_bus_pci_dir,
48333 &proc_bus_pci_dev_operations);
48334 proc_initialized = 1;
48335diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
48336index 7f3aad0..7d604bb 100644
48337--- a/drivers/platform/chrome/chromeos_laptop.c
48338+++ b/drivers/platform/chrome/chromeos_laptop.c
48339@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
48340 .callback = chromeos_laptop_dmi_matched, \
48341 .driver_data = (void *)&board_
48342
48343-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
48344+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
48345 {
48346 .ident = "Samsung Series 5 550",
48347 .matches = {
48348diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
48349index c5e082f..d6307a0 100644
48350--- a/drivers/platform/x86/asus-wmi.c
48351+++ b/drivers/platform/x86/asus-wmi.c
48352@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
48353 int err;
48354 u32 retval = -1;
48355
48356+#ifdef CONFIG_GRKERNSEC_KMEM
48357+ return -EPERM;
48358+#endif
48359+
48360 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
48361
48362 if (err < 0)
48363@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
48364 int err;
48365 u32 retval = -1;
48366
48367+#ifdef CONFIG_GRKERNSEC_KMEM
48368+ return -EPERM;
48369+#endif
48370+
48371 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
48372 &retval);
48373
48374@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
48375 union acpi_object *obj;
48376 acpi_status status;
48377
48378+#ifdef CONFIG_GRKERNSEC_KMEM
48379+ return -EPERM;
48380+#endif
48381+
48382 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
48383 1, asus->debug.method_id,
48384 &input, &output);
48385diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
48386index 62f8030..c7f2a45 100644
48387--- a/drivers/platform/x86/msi-laptop.c
48388+++ b/drivers/platform/x86/msi-laptop.c
48389@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
48390
48391 if (!quirks->ec_read_only) {
48392 /* allow userland write sysfs file */
48393- dev_attr_bluetooth.store = store_bluetooth;
48394- dev_attr_wlan.store = store_wlan;
48395- dev_attr_threeg.store = store_threeg;
48396- dev_attr_bluetooth.attr.mode |= S_IWUSR;
48397- dev_attr_wlan.attr.mode |= S_IWUSR;
48398- dev_attr_threeg.attr.mode |= S_IWUSR;
48399+ pax_open_kernel();
48400+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
48401+ *(void **)&dev_attr_wlan.store = store_wlan;
48402+ *(void **)&dev_attr_threeg.store = store_threeg;
48403+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
48404+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
48405+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
48406+ pax_close_kernel();
48407 }
48408
48409 /* disable hardware control by fn key */
48410diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
48411index 70222f2..8c8ce66 100644
48412--- a/drivers/platform/x86/msi-wmi.c
48413+++ b/drivers/platform/x86/msi-wmi.c
48414@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
48415 static void msi_wmi_notify(u32 value, void *context)
48416 {
48417 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
48418- static struct key_entry *key;
48419+ struct key_entry *key;
48420 union acpi_object *obj;
48421 acpi_status status;
48422
48423diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
48424index 8f8551a..3ace3ca 100644
48425--- a/drivers/platform/x86/sony-laptop.c
48426+++ b/drivers/platform/x86/sony-laptop.c
48427@@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
48428 }
48429
48430 /* High speed charging function */
48431-static struct device_attribute *hsc_handle;
48432+static device_attribute_no_const *hsc_handle;
48433
48434 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
48435 struct device_attribute *attr,
48436diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
48437index e2a91c8..986cc9f 100644
48438--- a/drivers/platform/x86/thinkpad_acpi.c
48439+++ b/drivers/platform/x86/thinkpad_acpi.c
48440@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
48441 return 0;
48442 }
48443
48444-void static hotkey_mask_warn_incomplete_mask(void)
48445+static void hotkey_mask_warn_incomplete_mask(void)
48446 {
48447 /* log only what the user can fix... */
48448 const u32 wantedmask = hotkey_driver_mask &
48449@@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
48450 }
48451 }
48452
48453-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48454- struct tp_nvram_state *newn,
48455- const u32 event_mask)
48456-{
48457-
48458 #define TPACPI_COMPARE_KEY(__scancode, __member) \
48459 do { \
48460 if ((event_mask & (1 << __scancode)) && \
48461@@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48462 tpacpi_hotkey_send_key(__scancode); \
48463 } while (0)
48464
48465- void issue_volchange(const unsigned int oldvol,
48466- const unsigned int newvol)
48467- {
48468- unsigned int i = oldvol;
48469+static void issue_volchange(const unsigned int oldvol,
48470+ const unsigned int newvol,
48471+ const u32 event_mask)
48472+{
48473+ unsigned int i = oldvol;
48474
48475- while (i > newvol) {
48476- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
48477- i--;
48478- }
48479- while (i < newvol) {
48480- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48481- i++;
48482- }
48483+ while (i > newvol) {
48484+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
48485+ i--;
48486 }
48487+ while (i < newvol) {
48488+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48489+ i++;
48490+ }
48491+}
48492
48493- void issue_brightnesschange(const unsigned int oldbrt,
48494- const unsigned int newbrt)
48495- {
48496- unsigned int i = oldbrt;
48497+static void issue_brightnesschange(const unsigned int oldbrt,
48498+ const unsigned int newbrt,
48499+ const u32 event_mask)
48500+{
48501+ unsigned int i = oldbrt;
48502
48503- while (i > newbrt) {
48504- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48505- i--;
48506- }
48507- while (i < newbrt) {
48508- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48509- i++;
48510- }
48511+ while (i > newbrt) {
48512+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48513+ i--;
48514+ }
48515+ while (i < newbrt) {
48516+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48517+ i++;
48518 }
48519+}
48520
48521+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48522+ struct tp_nvram_state *newn,
48523+ const u32 event_mask)
48524+{
48525 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
48526 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
48527 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
48528@@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48529 oldn->volume_level != newn->volume_level) {
48530 /* recently muted, or repeated mute keypress, or
48531 * multiple presses ending in mute */
48532- issue_volchange(oldn->volume_level, newn->volume_level);
48533+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48534 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
48535 }
48536 } else {
48537@@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48538 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48539 }
48540 if (oldn->volume_level != newn->volume_level) {
48541- issue_volchange(oldn->volume_level, newn->volume_level);
48542+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48543 } else if (oldn->volume_toggle != newn->volume_toggle) {
48544 /* repeated vol up/down keypress at end of scale ? */
48545 if (newn->volume_level == 0)
48546@@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48547 /* handle brightness */
48548 if (oldn->brightness_level != newn->brightness_level) {
48549 issue_brightnesschange(oldn->brightness_level,
48550- newn->brightness_level);
48551+ newn->brightness_level,
48552+ event_mask);
48553 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
48554 /* repeated key presses that didn't change state */
48555 if (newn->brightness_level == 0)
48556@@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48557 && !tp_features.bright_unkfw)
48558 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48559 }
48560+}
48561
48562 #undef TPACPI_COMPARE_KEY
48563 #undef TPACPI_MAY_SEND_KEY
48564-}
48565
48566 /*
48567 * Polling driver
48568diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48569index 769d265..a3a05ca 100644
48570--- a/drivers/pnp/pnpbios/bioscalls.c
48571+++ b/drivers/pnp/pnpbios/bioscalls.c
48572@@ -58,7 +58,7 @@ do { \
48573 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48574 } while(0)
48575
48576-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48577+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48578 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48579
48580 /*
48581@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48582
48583 cpu = get_cpu();
48584 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48585+
48586+ pax_open_kernel();
48587 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48588+ pax_close_kernel();
48589
48590 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48591 spin_lock_irqsave(&pnp_bios_lock, flags);
48592@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48593 :"memory");
48594 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48595
48596+ pax_open_kernel();
48597 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48598+ pax_close_kernel();
48599+
48600 put_cpu();
48601
48602 /* If we get here and this is set then the PnP BIOS faulted on us. */
48603@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48604 return status;
48605 }
48606
48607-void pnpbios_calls_init(union pnp_bios_install_struct *header)
48608+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48609 {
48610 int i;
48611
48612@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48613 pnp_bios_callpoint.offset = header->fields.pm16offset;
48614 pnp_bios_callpoint.segment = PNP_CS16;
48615
48616+ pax_open_kernel();
48617+
48618 for_each_possible_cpu(i) {
48619 struct desc_struct *gdt = get_cpu_gdt_table(i);
48620 if (!gdt)
48621@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48622 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48623 (unsigned long)__va(header->fields.pm16dseg));
48624 }
48625+
48626+ pax_close_kernel();
48627 }
48628diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48629index bacddd1..65ea100 100644
48630--- a/drivers/pnp/resource.c
48631+++ b/drivers/pnp/resource.c
48632@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48633 return 1;
48634
48635 /* check if the resource is valid */
48636- if (*irq < 0 || *irq > 15)
48637+ if (*irq > 15)
48638 return 0;
48639
48640 /* check if the resource is reserved */
48641@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48642 return 1;
48643
48644 /* check if the resource is valid */
48645- if (*dma < 0 || *dma == 4 || *dma > 7)
48646+ if (*dma == 4 || *dma > 7)
48647 return 0;
48648
48649 /* check if the resource is reserved */
48650diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48651index 0c52e2a..3421ab7 100644
48652--- a/drivers/power/pda_power.c
48653+++ b/drivers/power/pda_power.c
48654@@ -37,7 +37,11 @@ static int polling;
48655
48656 #if IS_ENABLED(CONFIG_USB_PHY)
48657 static struct usb_phy *transceiver;
48658-static struct notifier_block otg_nb;
48659+static int otg_handle_notification(struct notifier_block *nb,
48660+ unsigned long event, void *unused);
48661+static struct notifier_block otg_nb = {
48662+ .notifier_call = otg_handle_notification
48663+};
48664 #endif
48665
48666 static struct regulator *ac_draw;
48667@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48668
48669 #if IS_ENABLED(CONFIG_USB_PHY)
48670 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48671- otg_nb.notifier_call = otg_handle_notification;
48672 ret = usb_register_notifier(transceiver, &otg_nb);
48673 if (ret) {
48674 dev_err(dev, "failure to register otg notifier\n");
48675diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48676index cc439fd..8fa30df 100644
48677--- a/drivers/power/power_supply.h
48678+++ b/drivers/power/power_supply.h
48679@@ -16,12 +16,12 @@ struct power_supply;
48680
48681 #ifdef CONFIG_SYSFS
48682
48683-extern void power_supply_init_attrs(struct device_type *dev_type);
48684+extern void power_supply_init_attrs(void);
48685 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48686
48687 #else
48688
48689-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48690+static inline void power_supply_init_attrs(void) {}
48691 #define power_supply_uevent NULL
48692
48693 #endif /* CONFIG_SYSFS */
48694diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48695index 2660664..75fcb04 100644
48696--- a/drivers/power/power_supply_core.c
48697+++ b/drivers/power/power_supply_core.c
48698@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48699 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48700 EXPORT_SYMBOL_GPL(power_supply_notifier);
48701
48702-static struct device_type power_supply_dev_type;
48703+extern const struct attribute_group *power_supply_attr_groups[];
48704+static struct device_type power_supply_dev_type = {
48705+ .groups = power_supply_attr_groups,
48706+};
48707
48708 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48709 struct power_supply *supply)
48710@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48711 return PTR_ERR(power_supply_class);
48712
48713 power_supply_class->dev_uevent = power_supply_uevent;
48714- power_supply_init_attrs(&power_supply_dev_type);
48715+ power_supply_init_attrs();
48716
48717 return 0;
48718 }
48719diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48720index 44420d1..967126e 100644
48721--- a/drivers/power/power_supply_sysfs.c
48722+++ b/drivers/power/power_supply_sysfs.c
48723@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48724 .is_visible = power_supply_attr_is_visible,
48725 };
48726
48727-static const struct attribute_group *power_supply_attr_groups[] = {
48728+const struct attribute_group *power_supply_attr_groups[] = {
48729 &power_supply_attr_group,
48730 NULL,
48731 };
48732
48733-void power_supply_init_attrs(struct device_type *dev_type)
48734+void power_supply_init_attrs(void)
48735 {
48736 int i;
48737
48738- dev_type->groups = power_supply_attr_groups;
48739-
48740 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48741 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48742 }
48743diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48744index 84419af..268ede8 100644
48745--- a/drivers/powercap/powercap_sys.c
48746+++ b/drivers/powercap/powercap_sys.c
48747@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48748 struct device_attribute name_attr;
48749 };
48750
48751+static ssize_t show_constraint_name(struct device *dev,
48752+ struct device_attribute *dev_attr,
48753+ char *buf);
48754+
48755 static struct powercap_constraint_attr
48756- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48757+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48758+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48759+ .power_limit_attr = {
48760+ .attr = {
48761+ .name = NULL,
48762+ .mode = S_IWUSR | S_IRUGO
48763+ },
48764+ .show = show_constraint_power_limit_uw,
48765+ .store = store_constraint_power_limit_uw
48766+ },
48767+
48768+ .time_window_attr = {
48769+ .attr = {
48770+ .name = NULL,
48771+ .mode = S_IWUSR | S_IRUGO
48772+ },
48773+ .show = show_constraint_time_window_us,
48774+ .store = store_constraint_time_window_us
48775+ },
48776+
48777+ .max_power_attr = {
48778+ .attr = {
48779+ .name = NULL,
48780+ .mode = S_IRUGO
48781+ },
48782+ .show = show_constraint_max_power_uw,
48783+ .store = NULL
48784+ },
48785+
48786+ .min_power_attr = {
48787+ .attr = {
48788+ .name = NULL,
48789+ .mode = S_IRUGO
48790+ },
48791+ .show = show_constraint_min_power_uw,
48792+ .store = NULL
48793+ },
48794+
48795+ .max_time_window_attr = {
48796+ .attr = {
48797+ .name = NULL,
48798+ .mode = S_IRUGO
48799+ },
48800+ .show = show_constraint_max_time_window_us,
48801+ .store = NULL
48802+ },
48803+
48804+ .min_time_window_attr = {
48805+ .attr = {
48806+ .name = NULL,
48807+ .mode = S_IRUGO
48808+ },
48809+ .show = show_constraint_min_time_window_us,
48810+ .store = NULL
48811+ },
48812+
48813+ .name_attr = {
48814+ .attr = {
48815+ .name = NULL,
48816+ .mode = S_IRUGO
48817+ },
48818+ .show = show_constraint_name,
48819+ .store = NULL
48820+ }
48821+ }
48822+};
48823
48824 /* A list of powercap control_types */
48825 static LIST_HEAD(powercap_cntrl_list);
48826@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48827 }
48828
48829 static int create_constraint_attribute(int id, const char *name,
48830- int mode,
48831- struct device_attribute *dev_attr,
48832- ssize_t (*show)(struct device *,
48833- struct device_attribute *, char *),
48834- ssize_t (*store)(struct device *,
48835- struct device_attribute *,
48836- const char *, size_t)
48837- )
48838+ struct device_attribute *dev_attr)
48839 {
48840+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48841
48842- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48843- id, name);
48844- if (!dev_attr->attr.name)
48845+ if (!name)
48846 return -ENOMEM;
48847- dev_attr->attr.mode = mode;
48848- dev_attr->show = show;
48849- dev_attr->store = store;
48850+
48851+ pax_open_kernel();
48852+ *(const char **)&dev_attr->attr.name = name;
48853+ pax_close_kernel();
48854
48855 return 0;
48856 }
48857@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48858
48859 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48860 ret = create_constraint_attribute(i, "power_limit_uw",
48861- S_IWUSR | S_IRUGO,
48862- &constraint_attrs[i].power_limit_attr,
48863- show_constraint_power_limit_uw,
48864- store_constraint_power_limit_uw);
48865+ &constraint_attrs[i].power_limit_attr);
48866 if (ret)
48867 goto err_alloc;
48868 ret = create_constraint_attribute(i, "time_window_us",
48869- S_IWUSR | S_IRUGO,
48870- &constraint_attrs[i].time_window_attr,
48871- show_constraint_time_window_us,
48872- store_constraint_time_window_us);
48873+ &constraint_attrs[i].time_window_attr);
48874 if (ret)
48875 goto err_alloc;
48876- ret = create_constraint_attribute(i, "name", S_IRUGO,
48877- &constraint_attrs[i].name_attr,
48878- show_constraint_name,
48879- NULL);
48880+ ret = create_constraint_attribute(i, "name",
48881+ &constraint_attrs[i].name_attr);
48882 if (ret)
48883 goto err_alloc;
48884- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48885- &constraint_attrs[i].max_power_attr,
48886- show_constraint_max_power_uw,
48887- NULL);
48888+ ret = create_constraint_attribute(i, "max_power_uw",
48889+ &constraint_attrs[i].max_power_attr);
48890 if (ret)
48891 goto err_alloc;
48892- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48893- &constraint_attrs[i].min_power_attr,
48894- show_constraint_min_power_uw,
48895- NULL);
48896+ ret = create_constraint_attribute(i, "min_power_uw",
48897+ &constraint_attrs[i].min_power_attr);
48898 if (ret)
48899 goto err_alloc;
48900 ret = create_constraint_attribute(i, "max_time_window_us",
48901- S_IRUGO,
48902- &constraint_attrs[i].max_time_window_attr,
48903- show_constraint_max_time_window_us,
48904- NULL);
48905+ &constraint_attrs[i].max_time_window_attr);
48906 if (ret)
48907 goto err_alloc;
48908 ret = create_constraint_attribute(i, "min_time_window_us",
48909- S_IRUGO,
48910- &constraint_attrs[i].min_time_window_attr,
48911- show_constraint_min_time_window_us,
48912- NULL);
48913+ &constraint_attrs[i].min_time_window_attr);
48914 if (ret)
48915 goto err_alloc;
48916
48917@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48918 power_zone->zone_dev_attrs[count++] =
48919 &dev_attr_max_energy_range_uj.attr;
48920 if (power_zone->ops->get_energy_uj) {
48921+ pax_open_kernel();
48922 if (power_zone->ops->reset_energy_uj)
48923- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48924+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48925 else
48926- dev_attr_energy_uj.attr.mode = S_IRUGO;
48927+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48928+ pax_close_kernel();
48929 power_zone->zone_dev_attrs[count++] =
48930 &dev_attr_energy_uj.attr;
48931 }
48932diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48933index afca1bc..86840b8 100644
48934--- a/drivers/regulator/core.c
48935+++ b/drivers/regulator/core.c
48936@@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48937 {
48938 const struct regulation_constraints *constraints = NULL;
48939 const struct regulator_init_data *init_data;
48940- static atomic_t regulator_no = ATOMIC_INIT(0);
48941+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48942 struct regulator_dev *rdev;
48943 struct device *dev;
48944 int ret, i;
48945@@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48946 rdev->dev.of_node = config->of_node;
48947 rdev->dev.parent = dev;
48948 dev_set_name(&rdev->dev, "regulator.%d",
48949- atomic_inc_return(&regulator_no) - 1);
48950+ atomic_inc_return_unchecked(&regulator_no) - 1);
48951 ret = device_register(&rdev->dev);
48952 if (ret != 0) {
48953 put_device(&rdev->dev);
48954diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48955index 8d94d3d..653b623 100644
48956--- a/drivers/regulator/max8660.c
48957+++ b/drivers/regulator/max8660.c
48958@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48959 max8660->shadow_regs[MAX8660_OVER1] = 5;
48960 } else {
48961 /* Otherwise devices can be toggled via software */
48962- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48963- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48964+ pax_open_kernel();
48965+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48966+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48967+ pax_close_kernel();
48968 }
48969
48970 /*
48971diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48972index 892aa1e..ebd1b9c 100644
48973--- a/drivers/regulator/max8973-regulator.c
48974+++ b/drivers/regulator/max8973-regulator.c
48975@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48976 if (!pdata || !pdata->enable_ext_control) {
48977 max->desc.enable_reg = MAX8973_VOUT;
48978 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48979- max->ops.enable = regulator_enable_regmap;
48980- max->ops.disable = regulator_disable_regmap;
48981- max->ops.is_enabled = regulator_is_enabled_regmap;
48982+ pax_open_kernel();
48983+ *(void **)&max->ops.enable = regulator_enable_regmap;
48984+ *(void **)&max->ops.disable = regulator_disable_regmap;
48985+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48986+ pax_close_kernel();
48987 }
48988
48989 if (pdata) {
48990diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48991index f374fa5..26f0683 100644
48992--- a/drivers/regulator/mc13892-regulator.c
48993+++ b/drivers/regulator/mc13892-regulator.c
48994@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48995 }
48996 mc13xxx_unlock(mc13892);
48997
48998- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48999+ pax_open_kernel();
49000+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
49001 = mc13892_vcam_set_mode;
49002- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
49003+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
49004 = mc13892_vcam_get_mode;
49005+ pax_close_kernel();
49006
49007 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
49008 ARRAY_SIZE(mc13892_regulators));
49009diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
49010index cae212f..58a3980 100644
49011--- a/drivers/rtc/rtc-cmos.c
49012+++ b/drivers/rtc/rtc-cmos.c
49013@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
49014 hpet_rtc_timer_init();
49015
49016 /* export at least the first block of NVRAM */
49017- nvram.size = address_space - NVRAM_OFFSET;
49018+ pax_open_kernel();
49019+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
49020+ pax_close_kernel();
49021 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
49022 if (retval < 0) {
49023 dev_dbg(dev, "can't create nvram file? %d\n", retval);
49024diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
49025index d049393..bb20be0 100644
49026--- a/drivers/rtc/rtc-dev.c
49027+++ b/drivers/rtc/rtc-dev.c
49028@@ -16,6 +16,7 @@
49029 #include <linux/module.h>
49030 #include <linux/rtc.h>
49031 #include <linux/sched.h>
49032+#include <linux/grsecurity.h>
49033 #include "rtc-core.h"
49034
49035 static dev_t rtc_devt;
49036@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
49037 if (copy_from_user(&tm, uarg, sizeof(tm)))
49038 return -EFAULT;
49039
49040+ gr_log_timechange();
49041+
49042 return rtc_set_time(rtc, &tm);
49043
49044 case RTC_PIE_ON:
49045diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
49046index 4e75345..09f8663 100644
49047--- a/drivers/rtc/rtc-ds1307.c
49048+++ b/drivers/rtc/rtc-ds1307.c
49049@@ -107,7 +107,7 @@ struct ds1307 {
49050 u8 offset; /* register's offset */
49051 u8 regs[11];
49052 u16 nvram_offset;
49053- struct bin_attribute *nvram;
49054+ bin_attribute_no_const *nvram;
49055 enum ds_type type;
49056 unsigned long flags;
49057 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
49058diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
49059index 11880c1..b823aa4 100644
49060--- a/drivers/rtc/rtc-m48t59.c
49061+++ b/drivers/rtc/rtc-m48t59.c
49062@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
49063 if (IS_ERR(m48t59->rtc))
49064 return PTR_ERR(m48t59->rtc);
49065
49066- m48t59_nvram_attr.size = pdata->offset;
49067+ pax_open_kernel();
49068+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
49069+ pax_close_kernel();
49070
49071 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
49072 if (ret)
49073diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
49074index 14b5f8d..cc9bd26 100644
49075--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
49076+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
49077@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
49078 for (bit = 0; bit < 8; bit++) {
49079
49080 if ((pci_status[i] & (0x1 << bit)) != 0) {
49081- static const char *s;
49082+ const char *s;
49083
49084 s = pci_status_strings[bit];
49085 if (i == 7/*TARG*/ && bit == 3)
49086@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
49087
49088 for (bit = 0; bit < 8; bit++) {
49089
49090- if ((split_status[i] & (0x1 << bit)) != 0) {
49091- static const char *s;
49092-
49093- s = split_status_strings[bit];
49094- printk(s, ahd_name(ahd),
49095+ if ((split_status[i] & (0x1 << bit)) != 0)
49096+ printk(split_status_strings[bit], ahd_name(ahd),
49097 split_status_source[i]);
49098- }
49099
49100 if (i > 1)
49101 continue;
49102
49103- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
49104- static const char *s;
49105-
49106- s = split_status_strings[bit];
49107- printk(s, ahd_name(ahd), "SG");
49108- }
49109+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
49110+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
49111 }
49112 }
49113 /*
49114diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
49115index e693af6..2e525b6 100644
49116--- a/drivers/scsi/bfa/bfa_fcpim.h
49117+++ b/drivers/scsi/bfa/bfa_fcpim.h
49118@@ -36,7 +36,7 @@ struct bfa_iotag_s {
49119
49120 struct bfa_itn_s {
49121 bfa_isr_func_t isr;
49122-};
49123+} __no_const;
49124
49125 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
49126 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
49127diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
49128index a3ab5cc..8143622 100644
49129--- a/drivers/scsi/bfa/bfa_fcs.c
49130+++ b/drivers/scsi/bfa/bfa_fcs.c
49131@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
49132 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
49133
49134 static struct bfa_fcs_mod_s fcs_modules[] = {
49135- { bfa_fcs_port_attach, NULL, NULL },
49136- { bfa_fcs_uf_attach, NULL, NULL },
49137- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
49138- bfa_fcs_fabric_modexit },
49139+ {
49140+ .attach = bfa_fcs_port_attach,
49141+ .modinit = NULL,
49142+ .modexit = NULL
49143+ },
49144+ {
49145+ .attach = bfa_fcs_uf_attach,
49146+ .modinit = NULL,
49147+ .modexit = NULL
49148+ },
49149+ {
49150+ .attach = bfa_fcs_fabric_attach,
49151+ .modinit = bfa_fcs_fabric_modinit,
49152+ .modexit = bfa_fcs_fabric_modexit
49153+ },
49154 };
49155
49156 /*
49157diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
49158index ff75ef8..2dfe00a 100644
49159--- a/drivers/scsi/bfa/bfa_fcs_lport.c
49160+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
49161@@ -89,15 +89,26 @@ static struct {
49162 void (*offline) (struct bfa_fcs_lport_s *port);
49163 } __port_action[] = {
49164 {
49165- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
49166- bfa_fcs_lport_unknown_offline}, {
49167- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
49168- bfa_fcs_lport_fab_offline}, {
49169- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
49170- bfa_fcs_lport_n2n_offline}, {
49171- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
49172- bfa_fcs_lport_loop_offline},
49173- };
49174+ .init = bfa_fcs_lport_unknown_init,
49175+ .online = bfa_fcs_lport_unknown_online,
49176+ .offline = bfa_fcs_lport_unknown_offline
49177+ },
49178+ {
49179+ .init = bfa_fcs_lport_fab_init,
49180+ .online = bfa_fcs_lport_fab_online,
49181+ .offline = bfa_fcs_lport_fab_offline
49182+ },
49183+ {
49184+ .init = bfa_fcs_lport_n2n_init,
49185+ .online = bfa_fcs_lport_n2n_online,
49186+ .offline = bfa_fcs_lport_n2n_offline
49187+ },
49188+ {
49189+ .init = bfa_fcs_lport_loop_init,
49190+ .online = bfa_fcs_lport_loop_online,
49191+ .offline = bfa_fcs_lport_loop_offline
49192+ },
49193+};
49194
49195 /*
49196 * fcs_port_sm FCS logical port state machine
49197diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
49198index 2e28392..9d865b6 100644
49199--- a/drivers/scsi/bfa/bfa_ioc.h
49200+++ b/drivers/scsi/bfa/bfa_ioc.h
49201@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
49202 bfa_ioc_disable_cbfn_t disable_cbfn;
49203 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
49204 bfa_ioc_reset_cbfn_t reset_cbfn;
49205-};
49206+} __no_const;
49207
49208 /*
49209 * IOC event notification mechanism.
49210@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
49211 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
49212 enum bfi_ioc_state fwstate);
49213 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
49214-};
49215+} __no_const;
49216
49217 /*
49218 * Queue element to wait for room in request queue. FIFO order is
49219diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
49220index a14c784..6de6790 100644
49221--- a/drivers/scsi/bfa/bfa_modules.h
49222+++ b/drivers/scsi/bfa/bfa_modules.h
49223@@ -78,12 +78,12 @@ enum {
49224 \
49225 extern struct bfa_module_s hal_mod_ ## __mod; \
49226 struct bfa_module_s hal_mod_ ## __mod = { \
49227- bfa_ ## __mod ## _meminfo, \
49228- bfa_ ## __mod ## _attach, \
49229- bfa_ ## __mod ## _detach, \
49230- bfa_ ## __mod ## _start, \
49231- bfa_ ## __mod ## _stop, \
49232- bfa_ ## __mod ## _iocdisable, \
49233+ .meminfo = bfa_ ## __mod ## _meminfo, \
49234+ .attach = bfa_ ## __mod ## _attach, \
49235+ .detach = bfa_ ## __mod ## _detach, \
49236+ .start = bfa_ ## __mod ## _start, \
49237+ .stop = bfa_ ## __mod ## _stop, \
49238+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
49239 }
49240
49241 #define BFA_CACHELINE_SZ (256)
49242diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
49243index 045c4e1..13de803 100644
49244--- a/drivers/scsi/fcoe/fcoe_sysfs.c
49245+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
49246@@ -33,8 +33,8 @@
49247 */
49248 #include "libfcoe.h"
49249
49250-static atomic_t ctlr_num;
49251-static atomic_t fcf_num;
49252+static atomic_unchecked_t ctlr_num;
49253+static atomic_unchecked_t fcf_num;
49254
49255 /*
49256 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
49257@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
49258 if (!ctlr)
49259 goto out;
49260
49261- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
49262+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
49263 ctlr->f = f;
49264 ctlr->mode = FIP_CONN_TYPE_FABRIC;
49265 INIT_LIST_HEAD(&ctlr->fcfs);
49266@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
49267 fcf->dev.parent = &ctlr->dev;
49268 fcf->dev.bus = &fcoe_bus_type;
49269 fcf->dev.type = &fcoe_fcf_device_type;
49270- fcf->id = atomic_inc_return(&fcf_num) - 1;
49271+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
49272 fcf->state = FCOE_FCF_STATE_UNKNOWN;
49273
49274 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
49275@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
49276 {
49277 int error;
49278
49279- atomic_set(&ctlr_num, 0);
49280- atomic_set(&fcf_num, 0);
49281+ atomic_set_unchecked(&ctlr_num, 0);
49282+ atomic_set_unchecked(&fcf_num, 0);
49283
49284 error = bus_register(&fcoe_bus_type);
49285 if (error)
49286diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
49287index f28ea07..34b16d3 100644
49288--- a/drivers/scsi/hosts.c
49289+++ b/drivers/scsi/hosts.c
49290@@ -42,7 +42,7 @@
49291 #include "scsi_logging.h"
49292
49293
49294-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49295+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49296
49297
49298 static void scsi_host_cls_release(struct device *dev)
49299@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
49300 * subtract one because we increment first then return, but we need to
49301 * know what the next host number was before increment
49302 */
49303- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
49304+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
49305 shost->dma_channel = 0xff;
49306
49307 /* These three are default values which can be overridden */
49308diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
49309index 868318a..e07ef3b 100644
49310--- a/drivers/scsi/hpsa.c
49311+++ b/drivers/scsi/hpsa.c
49312@@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
49313 unsigned long flags;
49314
49315 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
49316- return h->access.command_completed(h, q);
49317+ return h->access->command_completed(h, q);
49318
49319 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
49320 a = rq->head[rq->current_entry];
49321@@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
49322 while (!list_empty(&h->reqQ)) {
49323 c = list_entry(h->reqQ.next, struct CommandList, list);
49324 /* can't do anything if fifo is full */
49325- if ((h->access.fifo_full(h))) {
49326+ if ((h->access->fifo_full(h))) {
49327 h->fifo_recently_full = 1;
49328 dev_warn(&h->pdev->dev, "fifo full\n");
49329 break;
49330@@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
49331
49332 /* Tell the controller execute command */
49333 spin_unlock_irqrestore(&h->lock, flags);
49334- h->access.submit_command(h, c);
49335+ h->access->submit_command(h, c);
49336 spin_lock_irqsave(&h->lock, flags);
49337 }
49338 spin_unlock_irqrestore(&h->lock, flags);
49339@@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
49340
49341 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
49342 {
49343- return h->access.command_completed(h, q);
49344+ return h->access->command_completed(h, q);
49345 }
49346
49347 static inline bool interrupt_pending(struct ctlr_info *h)
49348 {
49349- return h->access.intr_pending(h);
49350+ return h->access->intr_pending(h);
49351 }
49352
49353 static inline long interrupt_not_for_us(struct ctlr_info *h)
49354 {
49355- return (h->access.intr_pending(h) == 0) ||
49356+ return (h->access->intr_pending(h) == 0) ||
49357 (h->interrupts_enabled == 0);
49358 }
49359
49360@@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
49361 if (prod_index < 0)
49362 return -ENODEV;
49363 h->product_name = products[prod_index].product_name;
49364- h->access = *(products[prod_index].access);
49365+ h->access = products[prod_index].access;
49366
49367 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
49368 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
49369@@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
49370 {
49371 unsigned long flags;
49372
49373- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49374+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49375 spin_lock_irqsave(&h->lock, flags);
49376 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
49377 spin_unlock_irqrestore(&h->lock, flags);
49378@@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
49379 }
49380
49381 /* make sure the board interrupts are off */
49382- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49383+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49384
49385 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
49386 goto clean2;
49387@@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
49388 * fake ones to scoop up any residual completions.
49389 */
49390 spin_lock_irqsave(&h->lock, flags);
49391- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49392+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49393 spin_unlock_irqrestore(&h->lock, flags);
49394 free_irqs(h);
49395 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
49396@@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
49397 dev_info(&h->pdev->dev, "Board READY.\n");
49398 dev_info(&h->pdev->dev,
49399 "Waiting for stale completions to drain.\n");
49400- h->access.set_intr_mask(h, HPSA_INTR_ON);
49401+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49402 msleep(10000);
49403- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49404+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49405
49406 rc = controller_reset_failed(h->cfgtable);
49407 if (rc)
49408@@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
49409 }
49410
49411 /* Turn the interrupts on so we can service requests */
49412- h->access.set_intr_mask(h, HPSA_INTR_ON);
49413+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49414
49415 hpsa_hba_inquiry(h);
49416 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
49417@@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
49418 * To write all data in the battery backed cache to disks
49419 */
49420 hpsa_flush_cache(h);
49421- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49422+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49423 hpsa_free_irqs_and_disable_msix(h);
49424 }
49425
49426@@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
49427 return;
49428 }
49429 /* Change the access methods to the performant access methods */
49430- h->access = SA5_performant_access;
49431+ h->access = &SA5_performant_access;
49432 h->transMethod = CFGTBL_Trans_Performant;
49433 }
49434
49435diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
49436index 01c3283..4655219 100644
49437--- a/drivers/scsi/hpsa.h
49438+++ b/drivers/scsi/hpsa.h
49439@@ -79,7 +79,7 @@ struct ctlr_info {
49440 unsigned int msix_vector;
49441 unsigned int msi_vector;
49442 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
49443- struct access_method access;
49444+ struct access_method *access;
49445
49446 /* queue and queue Info */
49447 struct list_head reqQ;
49448@@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
49449 }
49450
49451 static struct access_method SA5_access = {
49452- SA5_submit_command,
49453- SA5_intr_mask,
49454- SA5_fifo_full,
49455- SA5_intr_pending,
49456- SA5_completed,
49457+ .submit_command = SA5_submit_command,
49458+ .set_intr_mask = SA5_intr_mask,
49459+ .fifo_full = SA5_fifo_full,
49460+ .intr_pending = SA5_intr_pending,
49461+ .command_completed = SA5_completed,
49462 };
49463
49464 static struct access_method SA5_performant_access = {
49465- SA5_submit_command,
49466- SA5_performant_intr_mask,
49467- SA5_fifo_full,
49468- SA5_performant_intr_pending,
49469- SA5_performant_completed,
49470+ .submit_command = SA5_submit_command,
49471+ .set_intr_mask = SA5_performant_intr_mask,
49472+ .fifo_full = SA5_fifo_full,
49473+ .intr_pending = SA5_performant_intr_pending,
49474+ .command_completed = SA5_performant_completed,
49475 };
49476
49477 struct board_type {
49478diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
49479index 1b3a094..068e683 100644
49480--- a/drivers/scsi/libfc/fc_exch.c
49481+++ b/drivers/scsi/libfc/fc_exch.c
49482@@ -101,12 +101,12 @@ struct fc_exch_mgr {
49483 u16 pool_max_index;
49484
49485 struct {
49486- atomic_t no_free_exch;
49487- atomic_t no_free_exch_xid;
49488- atomic_t xid_not_found;
49489- atomic_t xid_busy;
49490- atomic_t seq_not_found;
49491- atomic_t non_bls_resp;
49492+ atomic_unchecked_t no_free_exch;
49493+ atomic_unchecked_t no_free_exch_xid;
49494+ atomic_unchecked_t xid_not_found;
49495+ atomic_unchecked_t xid_busy;
49496+ atomic_unchecked_t seq_not_found;
49497+ atomic_unchecked_t non_bls_resp;
49498 } stats;
49499 };
49500
49501@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
49502 /* allocate memory for exchange */
49503 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
49504 if (!ep) {
49505- atomic_inc(&mp->stats.no_free_exch);
49506+ atomic_inc_unchecked(&mp->stats.no_free_exch);
49507 goto out;
49508 }
49509 memset(ep, 0, sizeof(*ep));
49510@@ -874,7 +874,7 @@ out:
49511 return ep;
49512 err:
49513 spin_unlock_bh(&pool->lock);
49514- atomic_inc(&mp->stats.no_free_exch_xid);
49515+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49516 mempool_free(ep, mp->ep_pool);
49517 return NULL;
49518 }
49519@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49520 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49521 ep = fc_exch_find(mp, xid);
49522 if (!ep) {
49523- atomic_inc(&mp->stats.xid_not_found);
49524+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49525 reject = FC_RJT_OX_ID;
49526 goto out;
49527 }
49528@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49529 ep = fc_exch_find(mp, xid);
49530 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49531 if (ep) {
49532- atomic_inc(&mp->stats.xid_busy);
49533+ atomic_inc_unchecked(&mp->stats.xid_busy);
49534 reject = FC_RJT_RX_ID;
49535 goto rel;
49536 }
49537@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49538 }
49539 xid = ep->xid; /* get our XID */
49540 } else if (!ep) {
49541- atomic_inc(&mp->stats.xid_not_found);
49542+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49543 reject = FC_RJT_RX_ID; /* XID not found */
49544 goto out;
49545 }
49546@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49547 } else {
49548 sp = &ep->seq;
49549 if (sp->id != fh->fh_seq_id) {
49550- atomic_inc(&mp->stats.seq_not_found);
49551+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49552 if (f_ctl & FC_FC_END_SEQ) {
49553 /*
49554 * Update sequence_id based on incoming last
49555@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49556
49557 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49558 if (!ep) {
49559- atomic_inc(&mp->stats.xid_not_found);
49560+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49561 goto out;
49562 }
49563 if (ep->esb_stat & ESB_ST_COMPLETE) {
49564- atomic_inc(&mp->stats.xid_not_found);
49565+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49566 goto rel;
49567 }
49568 if (ep->rxid == FC_XID_UNKNOWN)
49569 ep->rxid = ntohs(fh->fh_rx_id);
49570 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49571- atomic_inc(&mp->stats.xid_not_found);
49572+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49573 goto rel;
49574 }
49575 if (ep->did != ntoh24(fh->fh_s_id) &&
49576 ep->did != FC_FID_FLOGI) {
49577- atomic_inc(&mp->stats.xid_not_found);
49578+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49579 goto rel;
49580 }
49581 sof = fr_sof(fp);
49582@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49583 sp->ssb_stat |= SSB_ST_RESP;
49584 sp->id = fh->fh_seq_id;
49585 } else if (sp->id != fh->fh_seq_id) {
49586- atomic_inc(&mp->stats.seq_not_found);
49587+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49588 goto rel;
49589 }
49590
49591@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49592 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49593
49594 if (!sp)
49595- atomic_inc(&mp->stats.xid_not_found);
49596+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49597 else
49598- atomic_inc(&mp->stats.non_bls_resp);
49599+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
49600
49601 fc_frame_free(fp);
49602 }
49603@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49604
49605 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49606 mp = ema->mp;
49607- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49608+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49609 st->fc_no_free_exch_xid +=
49610- atomic_read(&mp->stats.no_free_exch_xid);
49611- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49612- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49613- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49614- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49615+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49616+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49617+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49618+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49619+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49620 }
49621 }
49622 EXPORT_SYMBOL(fc_exch_update_stats);
49623diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49624index d289583..b745eec 100644
49625--- a/drivers/scsi/libsas/sas_ata.c
49626+++ b/drivers/scsi/libsas/sas_ata.c
49627@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49628 .postreset = ata_std_postreset,
49629 .error_handler = ata_std_error_handler,
49630 .post_internal_cmd = sas_ata_post_internal,
49631- .qc_defer = ata_std_qc_defer,
49632+ .qc_defer = ata_std_qc_defer,
49633 .qc_prep = ata_noop_qc_prep,
49634 .qc_issue = sas_ata_qc_issue,
49635 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49636diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49637index 4e1b75c..0bbdfa9 100644
49638--- a/drivers/scsi/lpfc/lpfc.h
49639+++ b/drivers/scsi/lpfc/lpfc.h
49640@@ -432,7 +432,7 @@ struct lpfc_vport {
49641 struct dentry *debug_nodelist;
49642 struct dentry *vport_debugfs_root;
49643 struct lpfc_debugfs_trc *disc_trc;
49644- atomic_t disc_trc_cnt;
49645+ atomic_unchecked_t disc_trc_cnt;
49646 #endif
49647 uint8_t stat_data_enabled;
49648 uint8_t stat_data_blocked;
49649@@ -865,8 +865,8 @@ struct lpfc_hba {
49650 struct timer_list fabric_block_timer;
49651 unsigned long bit_flags;
49652 #define FABRIC_COMANDS_BLOCKED 0
49653- atomic_t num_rsrc_err;
49654- atomic_t num_cmd_success;
49655+ atomic_unchecked_t num_rsrc_err;
49656+ atomic_unchecked_t num_cmd_success;
49657 unsigned long last_rsrc_error_time;
49658 unsigned long last_ramp_down_time;
49659 unsigned long last_ramp_up_time;
49660@@ -902,7 +902,7 @@ struct lpfc_hba {
49661
49662 struct dentry *debug_slow_ring_trc;
49663 struct lpfc_debugfs_trc *slow_ring_trc;
49664- atomic_t slow_ring_trc_cnt;
49665+ atomic_unchecked_t slow_ring_trc_cnt;
49666 /* iDiag debugfs sub-directory */
49667 struct dentry *idiag_root;
49668 struct dentry *idiag_pci_cfg;
49669diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49670index b800cc9..16b6a91 100644
49671--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49672+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49673@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49674
49675 #include <linux/debugfs.h>
49676
49677-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49678+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49679 static unsigned long lpfc_debugfs_start_time = 0L;
49680
49681 /* iDiag */
49682@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49683 lpfc_debugfs_enable = 0;
49684
49685 len = 0;
49686- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49687+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49688 (lpfc_debugfs_max_disc_trc - 1);
49689 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49690 dtp = vport->disc_trc + i;
49691@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49692 lpfc_debugfs_enable = 0;
49693
49694 len = 0;
49695- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49696+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49697 (lpfc_debugfs_max_slow_ring_trc - 1);
49698 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49699 dtp = phba->slow_ring_trc + i;
49700@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49701 !vport || !vport->disc_trc)
49702 return;
49703
49704- index = atomic_inc_return(&vport->disc_trc_cnt) &
49705+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49706 (lpfc_debugfs_max_disc_trc - 1);
49707 dtp = vport->disc_trc + index;
49708 dtp->fmt = fmt;
49709 dtp->data1 = data1;
49710 dtp->data2 = data2;
49711 dtp->data3 = data3;
49712- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49713+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49714 dtp->jif = jiffies;
49715 #endif
49716 return;
49717@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49718 !phba || !phba->slow_ring_trc)
49719 return;
49720
49721- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49722+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49723 (lpfc_debugfs_max_slow_ring_trc - 1);
49724 dtp = phba->slow_ring_trc + index;
49725 dtp->fmt = fmt;
49726 dtp->data1 = data1;
49727 dtp->data2 = data2;
49728 dtp->data3 = data3;
49729- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49730+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49731 dtp->jif = jiffies;
49732 #endif
49733 return;
49734@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49735 "slow_ring buffer\n");
49736 goto debug_failed;
49737 }
49738- atomic_set(&phba->slow_ring_trc_cnt, 0);
49739+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49740 memset(phba->slow_ring_trc, 0,
49741 (sizeof(struct lpfc_debugfs_trc) *
49742 lpfc_debugfs_max_slow_ring_trc));
49743@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49744 "buffer\n");
49745 goto debug_failed;
49746 }
49747- atomic_set(&vport->disc_trc_cnt, 0);
49748+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49749
49750 snprintf(name, sizeof(name), "discovery_trace");
49751 vport->debug_disc_trc =
49752diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49753index 68c94cc..8c27be5 100644
49754--- a/drivers/scsi/lpfc/lpfc_init.c
49755+++ b/drivers/scsi/lpfc/lpfc_init.c
49756@@ -10949,8 +10949,10 @@ lpfc_init(void)
49757 "misc_register returned with status %d", error);
49758
49759 if (lpfc_enable_npiv) {
49760- lpfc_transport_functions.vport_create = lpfc_vport_create;
49761- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49762+ pax_open_kernel();
49763+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49764+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49765+ pax_close_kernel();
49766 }
49767 lpfc_transport_template =
49768 fc_attach_transport(&lpfc_transport_functions);
49769diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49770index b2ede05..aaf482ca 100644
49771--- a/drivers/scsi/lpfc/lpfc_scsi.c
49772+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49773@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49774 uint32_t evt_posted;
49775
49776 spin_lock_irqsave(&phba->hbalock, flags);
49777- atomic_inc(&phba->num_rsrc_err);
49778+ atomic_inc_unchecked(&phba->num_rsrc_err);
49779 phba->last_rsrc_error_time = jiffies;
49780
49781 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49782@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49783 unsigned long flags;
49784 struct lpfc_hba *phba = vport->phba;
49785 uint32_t evt_posted;
49786- atomic_inc(&phba->num_cmd_success);
49787+ atomic_inc_unchecked(&phba->num_cmd_success);
49788
49789 if (vport->cfg_lun_queue_depth <= queue_depth)
49790 return;
49791@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49792 unsigned long num_rsrc_err, num_cmd_success;
49793 int i;
49794
49795- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49796- num_cmd_success = atomic_read(&phba->num_cmd_success);
49797+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49798+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49799
49800 /*
49801 * The error and success command counters are global per
49802@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49803 }
49804 }
49805 lpfc_destroy_vport_work_array(phba, vports);
49806- atomic_set(&phba->num_rsrc_err, 0);
49807- atomic_set(&phba->num_cmd_success, 0);
49808+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49809+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49810 }
49811
49812 /**
49813@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49814 }
49815 }
49816 lpfc_destroy_vport_work_array(phba, vports);
49817- atomic_set(&phba->num_rsrc_err, 0);
49818- atomic_set(&phba->num_cmd_success, 0);
49819+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49820+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49821 }
49822
49823 /**
49824diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49825index 6fd7d40..b444223 100644
49826--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49827+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49828@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49829 {
49830 struct scsi_device *sdev = to_scsi_device(dev);
49831 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49832- static struct _raid_device *raid_device;
49833+ struct _raid_device *raid_device;
49834 unsigned long flags;
49835 Mpi2RaidVolPage0_t vol_pg0;
49836 Mpi2ConfigReply_t mpi_reply;
49837@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49838 {
49839 struct scsi_device *sdev = to_scsi_device(dev);
49840 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49841- static struct _raid_device *raid_device;
49842+ struct _raid_device *raid_device;
49843 unsigned long flags;
49844 Mpi2RaidVolPage0_t vol_pg0;
49845 Mpi2ConfigReply_t mpi_reply;
49846@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49847 struct fw_event_work *fw_event)
49848 {
49849 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49850- static struct _raid_device *raid_device;
49851+ struct _raid_device *raid_device;
49852 unsigned long flags;
49853 u16 handle;
49854
49855@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49856 u64 sas_address;
49857 struct _sas_device *sas_device;
49858 struct _sas_node *expander_device;
49859- static struct _raid_device *raid_device;
49860+ struct _raid_device *raid_device;
49861 u8 retry_count;
49862 unsigned long flags;
49863
49864diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49865index be8ce54..94ed33a 100644
49866--- a/drivers/scsi/pmcraid.c
49867+++ b/drivers/scsi/pmcraid.c
49868@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49869 res->scsi_dev = scsi_dev;
49870 scsi_dev->hostdata = res;
49871 res->change_detected = 0;
49872- atomic_set(&res->read_failures, 0);
49873- atomic_set(&res->write_failures, 0);
49874+ atomic_set_unchecked(&res->read_failures, 0);
49875+ atomic_set_unchecked(&res->write_failures, 0);
49876 rc = 0;
49877 }
49878 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49879@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49880
49881 /* If this was a SCSI read/write command keep count of errors */
49882 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49883- atomic_inc(&res->read_failures);
49884+ atomic_inc_unchecked(&res->read_failures);
49885 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49886- atomic_inc(&res->write_failures);
49887+ atomic_inc_unchecked(&res->write_failures);
49888
49889 if (!RES_IS_GSCSI(res->cfg_entry) &&
49890 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49891@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49892 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49893 * hrrq_id assigned here in queuecommand
49894 */
49895- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49896+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49897 pinstance->num_hrrq;
49898 cmd->cmd_done = pmcraid_io_done;
49899
49900@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49901 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49902 * hrrq_id assigned here in queuecommand
49903 */
49904- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49905+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49906 pinstance->num_hrrq;
49907
49908 if (request_size) {
49909@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49910
49911 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49912 /* add resources only after host is added into system */
49913- if (!atomic_read(&pinstance->expose_resources))
49914+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49915 return;
49916
49917 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49918@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49919 init_waitqueue_head(&pinstance->reset_wait_q);
49920
49921 atomic_set(&pinstance->outstanding_cmds, 0);
49922- atomic_set(&pinstance->last_message_id, 0);
49923- atomic_set(&pinstance->expose_resources, 0);
49924+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49925+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49926
49927 INIT_LIST_HEAD(&pinstance->free_res_q);
49928 INIT_LIST_HEAD(&pinstance->used_res_q);
49929@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49930 /* Schedule worker thread to handle CCN and take care of adding and
49931 * removing devices to OS
49932 */
49933- atomic_set(&pinstance->expose_resources, 1);
49934+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49935 schedule_work(&pinstance->worker_q);
49936 return rc;
49937
49938diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49939index e1d150f..6c6df44 100644
49940--- a/drivers/scsi/pmcraid.h
49941+++ b/drivers/scsi/pmcraid.h
49942@@ -748,7 +748,7 @@ struct pmcraid_instance {
49943 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49944
49945 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49946- atomic_t last_message_id;
49947+ atomic_unchecked_t last_message_id;
49948
49949 /* configuration table */
49950 struct pmcraid_config_table *cfg_table;
49951@@ -777,7 +777,7 @@ struct pmcraid_instance {
49952 atomic_t outstanding_cmds;
49953
49954 /* should add/delete resources to mid-layer now ?*/
49955- atomic_t expose_resources;
49956+ atomic_unchecked_t expose_resources;
49957
49958
49959
49960@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49961 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49962 };
49963 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49964- atomic_t read_failures; /* count of failed READ commands */
49965- atomic_t write_failures; /* count of failed WRITE commands */
49966+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49967+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49968
49969 /* To indicate add/delete/modify during CCN */
49970 u8 change_detected;
49971diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49972index 4a0d7c9..3d658d7 100644
49973--- a/drivers/scsi/qla2xxx/qla_attr.c
49974+++ b/drivers/scsi/qla2xxx/qla_attr.c
49975@@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49976 return 0;
49977 }
49978
49979-struct fc_function_template qla2xxx_transport_functions = {
49980+fc_function_template_no_const qla2xxx_transport_functions = {
49981
49982 .show_host_node_name = 1,
49983 .show_host_port_name = 1,
49984@@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49985 .bsg_timeout = qla24xx_bsg_timeout,
49986 };
49987
49988-struct fc_function_template qla2xxx_transport_vport_functions = {
49989+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49990
49991 .show_host_node_name = 1,
49992 .show_host_port_name = 1,
49993diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49994index 1f42662..bf9836c 100644
49995--- a/drivers/scsi/qla2xxx/qla_gbl.h
49996+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49997@@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49998 struct device_attribute;
49999 extern struct device_attribute *qla2x00_host_attrs[];
50000 struct fc_function_template;
50001-extern struct fc_function_template qla2xxx_transport_functions;
50002-extern struct fc_function_template qla2xxx_transport_vport_functions;
50003+extern fc_function_template_no_const qla2xxx_transport_functions;
50004+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
50005 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
50006 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
50007 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
50008diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
50009index 83cb612..9b7b08c 100644
50010--- a/drivers/scsi/qla2xxx/qla_os.c
50011+++ b/drivers/scsi/qla2xxx/qla_os.c
50012@@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
50013 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
50014 /* Ok, a 64bit DMA mask is applicable. */
50015 ha->flags.enable_64bit_addressing = 1;
50016- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
50017- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
50018+ pax_open_kernel();
50019+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
50020+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
50021+ pax_close_kernel();
50022 return;
50023 }
50024 }
50025diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
50026index aa67bb9..06d0e2a 100644
50027--- a/drivers/scsi/qla4xxx/ql4_def.h
50028+++ b/drivers/scsi/qla4xxx/ql4_def.h
50029@@ -303,7 +303,7 @@ struct ddb_entry {
50030 * (4000 only) */
50031 atomic_t relogin_timer; /* Max Time to wait for
50032 * relogin to complete */
50033- atomic_t relogin_retry_count; /* Num of times relogin has been
50034+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
50035 * retried */
50036 uint32_t default_time2wait; /* Default Min time between
50037 * relogins (+aens) */
50038diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
50039index c21adc3..1b4155f 100644
50040--- a/drivers/scsi/qla4xxx/ql4_os.c
50041+++ b/drivers/scsi/qla4xxx/ql4_os.c
50042@@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
50043 */
50044 if (!iscsi_is_session_online(cls_sess)) {
50045 /* Reset retry relogin timer */
50046- atomic_inc(&ddb_entry->relogin_retry_count);
50047+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
50048 DEBUG2(ql4_printk(KERN_INFO, ha,
50049 "%s: index[%d] relogin timed out-retrying"
50050 " relogin (%d), retry (%d)\n", __func__,
50051 ddb_entry->fw_ddb_index,
50052- atomic_read(&ddb_entry->relogin_retry_count),
50053+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
50054 ddb_entry->default_time2wait + 4));
50055 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
50056 atomic_set(&ddb_entry->retry_relogin_timer,
50057@@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
50058
50059 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
50060 atomic_set(&ddb_entry->relogin_timer, 0);
50061- atomic_set(&ddb_entry->relogin_retry_count, 0);
50062+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
50063 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
50064 ddb_entry->default_relogin_timeout =
50065 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
50066diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
50067index d8afec8..3ec7152 100644
50068--- a/drivers/scsi/scsi.c
50069+++ b/drivers/scsi/scsi.c
50070@@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
50071 struct Scsi_Host *host = cmd->device->host;
50072 int rtn = 0;
50073
50074- atomic_inc(&cmd->device->iorequest_cnt);
50075+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
50076
50077 /* check if the device is still usable */
50078 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
50079diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
50080index 62ec84b..93159d8 100644
50081--- a/drivers/scsi/scsi_lib.c
50082+++ b/drivers/scsi/scsi_lib.c
50083@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
50084 shost = sdev->host;
50085 scsi_init_cmd_errh(cmd);
50086 cmd->result = DID_NO_CONNECT << 16;
50087- atomic_inc(&cmd->device->iorequest_cnt);
50088+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
50089
50090 /*
50091 * SCSI request completion path will do scsi_device_unbusy(),
50092@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
50093
50094 INIT_LIST_HEAD(&cmd->eh_entry);
50095
50096- atomic_inc(&cmd->device->iodone_cnt);
50097+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
50098 if (cmd->result)
50099- atomic_inc(&cmd->device->ioerr_cnt);
50100+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
50101
50102 disposition = scsi_decide_disposition(cmd);
50103 if (disposition != SUCCESS &&
50104diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
50105index 665acbf..d18fab4 100644
50106--- a/drivers/scsi/scsi_sysfs.c
50107+++ b/drivers/scsi/scsi_sysfs.c
50108@@ -734,7 +734,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
50109 char *buf) \
50110 { \
50111 struct scsi_device *sdev = to_scsi_device(dev); \
50112- unsigned long long count = atomic_read(&sdev->field); \
50113+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
50114 return snprintf(buf, 20, "0x%llx\n", count); \
50115 } \
50116 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
50117diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
50118index 84a1fdf..693b0d6 100644
50119--- a/drivers/scsi/scsi_tgt_lib.c
50120+++ b/drivers/scsi/scsi_tgt_lib.c
50121@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
50122 int err;
50123
50124 dprintk("%lx %u\n", uaddr, len);
50125- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
50126+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
50127 if (err) {
50128 /*
50129 * TODO: need to fixup sg_tablesize, max_segment_size,
50130diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
50131index 4628fd5..a94a1c2 100644
50132--- a/drivers/scsi/scsi_transport_fc.c
50133+++ b/drivers/scsi/scsi_transport_fc.c
50134@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
50135 * Netlink Infrastructure
50136 */
50137
50138-static atomic_t fc_event_seq;
50139+static atomic_unchecked_t fc_event_seq;
50140
50141 /**
50142 * fc_get_event_number - Obtain the next sequential FC event number
50143@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
50144 u32
50145 fc_get_event_number(void)
50146 {
50147- return atomic_add_return(1, &fc_event_seq);
50148+ return atomic_add_return_unchecked(1, &fc_event_seq);
50149 }
50150 EXPORT_SYMBOL(fc_get_event_number);
50151
50152@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
50153 {
50154 int error;
50155
50156- atomic_set(&fc_event_seq, 0);
50157+ atomic_set_unchecked(&fc_event_seq, 0);
50158
50159 error = transport_class_register(&fc_host_class);
50160 if (error)
50161@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
50162 char *cp;
50163
50164 *val = simple_strtoul(buf, &cp, 0);
50165- if ((*cp && (*cp != '\n')) || (*val < 0))
50166+ if (*cp && (*cp != '\n'))
50167 return -EINVAL;
50168 /*
50169 * Check for overflow; dev_loss_tmo is u32
50170diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
50171index fd8ffe6..fd0bebf 100644
50172--- a/drivers/scsi/scsi_transport_iscsi.c
50173+++ b/drivers/scsi/scsi_transport_iscsi.c
50174@@ -79,7 +79,7 @@ struct iscsi_internal {
50175 struct transport_container session_cont;
50176 };
50177
50178-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
50179+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
50180 static struct workqueue_struct *iscsi_eh_timer_workq;
50181
50182 static DEFINE_IDA(iscsi_sess_ida);
50183@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
50184 int err;
50185
50186 ihost = shost->shost_data;
50187- session->sid = atomic_add_return(1, &iscsi_session_nr);
50188+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
50189
50190 if (target_id == ISCSI_MAX_TARGET) {
50191 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
50192@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
50193 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
50194 ISCSI_TRANSPORT_VERSION);
50195
50196- atomic_set(&iscsi_session_nr, 0);
50197+ atomic_set_unchecked(&iscsi_session_nr, 0);
50198
50199 err = class_register(&iscsi_transport_class);
50200 if (err)
50201diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
50202index d47ffc8..30f46a9 100644
50203--- a/drivers/scsi/scsi_transport_srp.c
50204+++ b/drivers/scsi/scsi_transport_srp.c
50205@@ -36,7 +36,7 @@
50206 #include "scsi_transport_srp_internal.h"
50207
50208 struct srp_host_attrs {
50209- atomic_t next_port_id;
50210+ atomic_unchecked_t next_port_id;
50211 };
50212 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
50213
50214@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
50215 struct Scsi_Host *shost = dev_to_shost(dev);
50216 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
50217
50218- atomic_set(&srp_host->next_port_id, 0);
50219+ atomic_set_unchecked(&srp_host->next_port_id, 0);
50220 return 0;
50221 }
50222
50223@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
50224 rport_fast_io_fail_timedout);
50225 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
50226
50227- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
50228+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
50229 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
50230
50231 transport_setup_device(&rport->dev);
50232diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
50233index 36d1a23..3f33303 100644
50234--- a/drivers/scsi/sd.c
50235+++ b/drivers/scsi/sd.c
50236@@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
50237 sdkp->disk = gd;
50238 sdkp->index = index;
50239 atomic_set(&sdkp->openers, 0);
50240- atomic_set(&sdkp->device->ioerr_cnt, 0);
50241+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
50242
50243 if (!sdp->request_queue->rq_timeout) {
50244 if (sdp->type != TYPE_MOD)
50245diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
50246index df5e961..df6b97f 100644
50247--- a/drivers/scsi/sg.c
50248+++ b/drivers/scsi/sg.c
50249@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
50250 sdp->disk->disk_name,
50251 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
50252 NULL,
50253- (char *)arg);
50254+ (char __user *)arg);
50255 case BLKTRACESTART:
50256 return blk_trace_startstop(sdp->device->request_queue, 1);
50257 case BLKTRACESTOP:
50258diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
50259index fbf3b22..f5c8b60 100644
50260--- a/drivers/spi/spi.c
50261+++ b/drivers/spi/spi.c
50262@@ -1980,7 +1980,7 @@ int spi_bus_unlock(struct spi_master *master)
50263 EXPORT_SYMBOL_GPL(spi_bus_unlock);
50264
50265 /* portable code must never pass more than 32 bytes */
50266-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
50267+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
50268
50269 static u8 *buf;
50270
50271diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
50272index 2c61783..4d49e4e 100644
50273--- a/drivers/staging/android/timed_output.c
50274+++ b/drivers/staging/android/timed_output.c
50275@@ -25,7 +25,7 @@
50276 #include "timed_output.h"
50277
50278 static struct class *timed_output_class;
50279-static atomic_t device_count;
50280+static atomic_unchecked_t device_count;
50281
50282 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
50283 char *buf)
50284@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
50285 timed_output_class = class_create(THIS_MODULE, "timed_output");
50286 if (IS_ERR(timed_output_class))
50287 return PTR_ERR(timed_output_class);
50288- atomic_set(&device_count, 0);
50289+ atomic_set_unchecked(&device_count, 0);
50290 timed_output_class->dev_groups = timed_output_groups;
50291 }
50292
50293@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
50294 if (ret < 0)
50295 return ret;
50296
50297- tdev->index = atomic_inc_return(&device_count);
50298+ tdev->index = atomic_inc_return_unchecked(&device_count);
50299 tdev->dev = device_create(timed_output_class, NULL,
50300 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
50301 if (IS_ERR(tdev->dev))
50302diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
50303index fe47cd3..19a1bd1 100644
50304--- a/drivers/staging/gdm724x/gdm_tty.c
50305+++ b/drivers/staging/gdm724x/gdm_tty.c
50306@@ -44,7 +44,7 @@
50307 #define gdm_tty_send_control(n, r, v, d, l) (\
50308 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
50309
50310-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
50311+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
50312
50313 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
50314 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
50315diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
50316index 236ed66..dd9cd74 100644
50317--- a/drivers/staging/imx-drm/imx-drm-core.c
50318+++ b/drivers/staging/imx-drm/imx-drm-core.c
50319@@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
50320 goto err_busy;
50321 }
50322
50323- if (imxdrm->drm->open_count) {
50324+ if (local_read(&imxdrm->drm->open_count)) {
50325 ret = -EBUSY;
50326 goto err_busy;
50327 }
50328@@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
50329
50330 mutex_lock(&imxdrm->mutex);
50331
50332- if (imxdrm->drm->open_count) {
50333+ if (local_read(&imxdrm->drm->open_count)) {
50334 ret = -EBUSY;
50335 goto err_busy;
50336 }
50337@@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
50338
50339 mutex_lock(&imxdrm->mutex);
50340
50341- if (imxdrm->drm->open_count) {
50342+ if (local_read(&imxdrm->drm->open_count)) {
50343 ret = -EBUSY;
50344 goto err_busy;
50345 }
50346diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
50347index 3f8020c..649fded 100644
50348--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
50349+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
50350@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
50351 return 0;
50352 }
50353
50354-sfw_test_client_ops_t brw_test_client;
50355-void brw_init_test_client(void)
50356-{
50357- brw_test_client.tso_init = brw_client_init;
50358- brw_test_client.tso_fini = brw_client_fini;
50359- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
50360- brw_test_client.tso_done_rpc = brw_client_done_rpc;
50361+sfw_test_client_ops_t brw_test_client = {
50362+ .tso_init = brw_client_init,
50363+ .tso_fini = brw_client_fini,
50364+ .tso_prep_rpc = brw_client_prep_rpc,
50365+ .tso_done_rpc = brw_client_done_rpc,
50366 };
50367
50368 srpc_service_t brw_test_service;
50369diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
50370index 050723a..fa6fdf1 100644
50371--- a/drivers/staging/lustre/lnet/selftest/framework.c
50372+++ b/drivers/staging/lustre/lnet/selftest/framework.c
50373@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
50374
50375 extern sfw_test_client_ops_t ping_test_client;
50376 extern srpc_service_t ping_test_service;
50377-extern void ping_init_test_client(void);
50378 extern void ping_init_test_service(void);
50379
50380 extern sfw_test_client_ops_t brw_test_client;
50381 extern srpc_service_t brw_test_service;
50382-extern void brw_init_test_client(void);
50383 extern void brw_init_test_service(void);
50384
50385
50386@@ -1684,12 +1682,10 @@ sfw_startup (void)
50387 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
50388 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
50389
50390- brw_init_test_client();
50391 brw_init_test_service();
50392 rc = sfw_register_test(&brw_test_service, &brw_test_client);
50393 LASSERT (rc == 0);
50394
50395- ping_init_test_client();
50396 ping_init_test_service();
50397 rc = sfw_register_test(&ping_test_service, &ping_test_client);
50398 LASSERT (rc == 0);
50399diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
50400index 750cac4..e4d751f 100644
50401--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
50402+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
50403@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
50404 return 0;
50405 }
50406
50407-sfw_test_client_ops_t ping_test_client;
50408-void ping_init_test_client(void)
50409-{
50410- ping_test_client.tso_init = ping_client_init;
50411- ping_test_client.tso_fini = ping_client_fini;
50412- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
50413- ping_test_client.tso_done_rpc = ping_client_done_rpc;
50414-}
50415+sfw_test_client_ops_t ping_test_client = {
50416+ .tso_init = ping_client_init,
50417+ .tso_fini = ping_client_fini,
50418+ .tso_prep_rpc = ping_client_prep_rpc,
50419+ .tso_done_rpc = ping_client_done_rpc,
50420+};
50421
50422 srpc_service_t ping_test_service;
50423 void ping_init_test_service(void)
50424diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50425index ec4bb5e..740c6dd 100644
50426--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
50427+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50428@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
50429 ldlm_completion_callback lcs_completion;
50430 ldlm_blocking_callback lcs_blocking;
50431 ldlm_glimpse_callback lcs_glimpse;
50432-};
50433+} __no_const;
50434
50435 /* ldlm_lockd.c */
50436 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
50437diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
50438index c3470ce..2bef527 100644
50439--- a/drivers/staging/lustre/lustre/include/obd.h
50440+++ b/drivers/staging/lustre/lustre/include/obd.h
50441@@ -1426,7 +1426,7 @@ struct md_ops {
50442 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
50443 * wrapper function in include/linux/obd_class.h.
50444 */
50445-};
50446+} __no_const;
50447
50448 struct lsm_operations {
50449 void (*lsm_free)(struct lov_stripe_md *);
50450diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50451index c9aae13..60ea292 100644
50452--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50453+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50454@@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
50455 int added = (mode == LCK_NL);
50456 int overlaps = 0;
50457 int splitted = 0;
50458- const struct ldlm_callback_suite null_cbs = { NULL };
50459+ const struct ldlm_callback_suite null_cbs = { };
50460
50461 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
50462 LPU64" end "LPU64"\n", *flags,
50463diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50464index e947b91..f408990 100644
50465--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50466+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50467@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
50468 int LL_PROC_PROTO(proc_console_max_delay_cs)
50469 {
50470 int rc, max_delay_cs;
50471- ctl_table_t dummy = *table;
50472+ ctl_table_no_const dummy = *table;
50473 cfs_duration_t d;
50474
50475 dummy.data = &max_delay_cs;
50476@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
50477 int LL_PROC_PROTO(proc_console_min_delay_cs)
50478 {
50479 int rc, min_delay_cs;
50480- ctl_table_t dummy = *table;
50481+ ctl_table_no_const dummy = *table;
50482 cfs_duration_t d;
50483
50484 dummy.data = &min_delay_cs;
50485@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
50486 int LL_PROC_PROTO(proc_console_backoff)
50487 {
50488 int rc, backoff;
50489- ctl_table_t dummy = *table;
50490+ ctl_table_no_const dummy = *table;
50491
50492 dummy.data = &backoff;
50493 dummy.proc_handler = &proc_dointvec;
50494diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
50495index 24ae26d..9d09cab 100644
50496--- a/drivers/staging/lustre/lustre/libcfs/module.c
50497+++ b/drivers/staging/lustre/lustre/libcfs/module.c
50498@@ -313,11 +313,11 @@ out:
50499
50500
50501 struct cfs_psdev_ops libcfs_psdev_ops = {
50502- libcfs_psdev_open,
50503- libcfs_psdev_release,
50504- NULL,
50505- NULL,
50506- libcfs_ioctl
50507+ .p_open = libcfs_psdev_open,
50508+ .p_close = libcfs_psdev_release,
50509+ .p_read = NULL,
50510+ .p_write = NULL,
50511+ .p_ioctl = libcfs_ioctl
50512 };
50513
50514 extern int insert_proc(void);
50515diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50516index 52b7731..d604da0 100644
50517--- a/drivers/staging/lustre/lustre/llite/dir.c
50518+++ b/drivers/staging/lustre/lustre/llite/dir.c
50519@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50520 int mode;
50521 int err;
50522
50523- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50524+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50525 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50526 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50527 lump);
50528diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50529index 480b7c4..6846324 100644
50530--- a/drivers/staging/media/solo6x10/solo6x10-core.c
50531+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50532@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50533
50534 static int solo_sysfs_init(struct solo_dev *solo_dev)
50535 {
50536- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50537+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50538 struct device *dev = &solo_dev->dev;
50539 const char *driver;
50540 int i;
50541diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50542index 1db18c7..35e6afc 100644
50543--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50544+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50545@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50546
50547 int solo_g723_init(struct solo_dev *solo_dev)
50548 {
50549- static struct snd_device_ops ops = { NULL };
50550+ static struct snd_device_ops ops = { };
50551 struct snd_card *card;
50552 struct snd_kcontrol_new kctl;
50553 char name[32];
50554diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50555index 7f2f247..d999137 100644
50556--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50557+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50558@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50559
50560 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50561 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50562- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50563+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50564 if (p2m_id < 0)
50565 p2m_id = -p2m_id;
50566 }
50567diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50568index 8964f8b..36eb087 100644
50569--- a/drivers/staging/media/solo6x10/solo6x10.h
50570+++ b/drivers/staging/media/solo6x10/solo6x10.h
50571@@ -237,7 +237,7 @@ struct solo_dev {
50572
50573 /* P2M DMA Engine */
50574 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50575- atomic_t p2m_count;
50576+ atomic_unchecked_t p2m_count;
50577 int p2m_jiffies;
50578 unsigned int p2m_timeouts;
50579
50580diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50581index a0f4868..139f1fb 100644
50582--- a/drivers/staging/octeon/ethernet-rx.c
50583+++ b/drivers/staging/octeon/ethernet-rx.c
50584@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50585 /* Increment RX stats for virtual ports */
50586 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50587 #ifdef CONFIG_64BIT
50588- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50589- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50590+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50591+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50592 #else
50593- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50594- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50595+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50596+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50597 #endif
50598 }
50599 netif_receive_skb(skb);
50600@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50601 dev->name);
50602 */
50603 #ifdef CONFIG_64BIT
50604- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50605+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50606 #else
50607- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50608+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50609 #endif
50610 dev_kfree_skb_irq(skb);
50611 }
50612diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50613index 089dc4b..c9a687e 100644
50614--- a/drivers/staging/octeon/ethernet.c
50615+++ b/drivers/staging/octeon/ethernet.c
50616@@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50617 * since the RX tasklet also increments it.
50618 */
50619 #ifdef CONFIG_64BIT
50620- atomic64_add(rx_status.dropped_packets,
50621- (atomic64_t *)&priv->stats.rx_dropped);
50622+ atomic64_add_unchecked(rx_status.dropped_packets,
50623+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50624 #else
50625- atomic_add(rx_status.dropped_packets,
50626- (atomic_t *)&priv->stats.rx_dropped);
50627+ atomic_add_unchecked(rx_status.dropped_packets,
50628+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
50629 #endif
50630 }
50631
50632diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50633index c274b34..f84de76 100644
50634--- a/drivers/staging/rtl8188eu/include/hal_intf.h
50635+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50636@@ -271,7 +271,7 @@ struct hal_ops {
50637 s32 (*c2h_handler)(struct adapter *padapter,
50638 struct c2h_evt_hdr *c2h_evt);
50639 c2h_id_filter c2h_id_filter_ccx;
50640-};
50641+} __no_const;
50642
50643 enum rt_eeprom_type {
50644 EEPROM_93C46,
50645diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50646index 3d1dfcc..ff5620a 100644
50647--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50648+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50649@@ -126,7 +126,7 @@ struct _io_ops {
50650 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50651 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50652 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50653-};
50654+} __no_const;
50655
50656 struct io_req {
50657 struct list_head list;
50658diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50659index dc23395..cf7e9b1 100644
50660--- a/drivers/staging/rtl8712/rtl871x_io.h
50661+++ b/drivers/staging/rtl8712/rtl871x_io.h
50662@@ -108,7 +108,7 @@ struct _io_ops {
50663 u8 *pmem);
50664 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50665 u8 *pmem);
50666-};
50667+} __no_const;
50668
50669 struct io_req {
50670 struct list_head list;
50671diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50672index 1f5088b..0e59820 100644
50673--- a/drivers/staging/sbe-2t3e3/netdev.c
50674+++ b/drivers/staging/sbe-2t3e3/netdev.c
50675@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50676 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50677
50678 if (rlen)
50679- if (copy_to_user(data, &resp, rlen))
50680+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50681 return -EFAULT;
50682
50683 return 0;
50684diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50685index a863a98..d272795 100644
50686--- a/drivers/staging/usbip/vhci.h
50687+++ b/drivers/staging/usbip/vhci.h
50688@@ -83,7 +83,7 @@ struct vhci_hcd {
50689 unsigned resuming:1;
50690 unsigned long re_timeout;
50691
50692- atomic_t seqnum;
50693+ atomic_unchecked_t seqnum;
50694
50695 /*
50696 * NOTE:
50697diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50698index 72391ef..7c6717a 100644
50699--- a/drivers/staging/usbip/vhci_hcd.c
50700+++ b/drivers/staging/usbip/vhci_hcd.c
50701@@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
50702
50703 spin_lock(&vdev->priv_lock);
50704
50705- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50706+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50707 if (priv->seqnum == 0xffff)
50708 dev_info(&urb->dev->dev, "seqnum max\n");
50709
50710@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50711 return -ENOMEM;
50712 }
50713
50714- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50715+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50716 if (unlink->seqnum == 0xffff)
50717 pr_info("seqnum max\n");
50718
50719@@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
50720 vdev->rhport = rhport;
50721 }
50722
50723- atomic_set(&vhci->seqnum, 0);
50724+ atomic_set_unchecked(&vhci->seqnum, 0);
50725 spin_lock_init(&vhci->lock);
50726
50727 hcd->power_budget = 0; /* no limit */
50728diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50729index d07fcb5..358e1e1 100644
50730--- a/drivers/staging/usbip/vhci_rx.c
50731+++ b/drivers/staging/usbip/vhci_rx.c
50732@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50733 if (!urb) {
50734 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50735 pr_info("max seqnum %d\n",
50736- atomic_read(&the_controller->seqnum));
50737+ atomic_read_unchecked(&the_controller->seqnum));
50738 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50739 return;
50740 }
50741diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50742index 6eecd53..29317c6 100644
50743--- a/drivers/staging/vt6655/hostap.c
50744+++ b/drivers/staging/vt6655/hostap.c
50745@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50746 *
50747 */
50748
50749+static net_device_ops_no_const apdev_netdev_ops;
50750+
50751 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50752 {
50753 PSDevice apdev_priv;
50754 struct net_device *dev = pDevice->dev;
50755 int ret;
50756- const struct net_device_ops apdev_netdev_ops = {
50757- .ndo_start_xmit = pDevice->tx_80211,
50758- };
50759
50760 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50761
50762@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50763 *apdev_priv = *pDevice;
50764 eth_hw_addr_inherit(pDevice->apdev, dev);
50765
50766+ /* only half broken now */
50767+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50768 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50769
50770 pDevice->apdev->type = ARPHRD_IEEE80211;
50771diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50772index 67ba48b..24e602f 100644
50773--- a/drivers/staging/vt6656/hostap.c
50774+++ b/drivers/staging/vt6656/hostap.c
50775@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50776 *
50777 */
50778
50779+static net_device_ops_no_const apdev_netdev_ops;
50780+
50781 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50782 {
50783 struct vnt_private *apdev_priv;
50784 struct net_device *dev = pDevice->dev;
50785 int ret;
50786- const struct net_device_ops apdev_netdev_ops = {
50787- .ndo_start_xmit = pDevice->tx_80211,
50788- };
50789
50790 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50791
50792@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50793 *apdev_priv = *pDevice;
50794 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50795
50796+ /* only half broken now */
50797+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50798 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50799
50800 pDevice->apdev->type = ARPHRD_IEEE80211;
50801diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50802index 24884ca..26c8220 100644
50803--- a/drivers/target/sbp/sbp_target.c
50804+++ b/drivers/target/sbp/sbp_target.c
50805@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50806
50807 #define SESSION_MAINTENANCE_INTERVAL HZ
50808
50809-static atomic_t login_id = ATOMIC_INIT(0);
50810+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50811
50812 static void session_maintenance_work(struct work_struct *);
50813 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50814@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50815 login->lun = se_lun;
50816 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50817 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50818- login->login_id = atomic_inc_return(&login_id);
50819+ login->login_id = atomic_inc_return_unchecked(&login_id);
50820
50821 login->tgt_agt = sbp_target_agent_register(login);
50822 if (IS_ERR(login->tgt_agt)) {
50823diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50824index 26416c1..e796a3d 100644
50825--- a/drivers/target/target_core_device.c
50826+++ b/drivers/target/target_core_device.c
50827@@ -1524,7 +1524,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50828 spin_lock_init(&dev->se_tmr_lock);
50829 spin_lock_init(&dev->qf_cmd_lock);
50830 sema_init(&dev->caw_sem, 1);
50831- atomic_set(&dev->dev_ordered_id, 0);
50832+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50833 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50834 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50835 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50836diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50837index 98b48d4..f4297e5 100644
50838--- a/drivers/target/target_core_transport.c
50839+++ b/drivers/target/target_core_transport.c
50840@@ -1137,7 +1137,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50841 * Used to determine when ORDERED commands should go from
50842 * Dormant to Active status.
50843 */
50844- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50845+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50846 smp_mb__after_atomic_inc();
50847 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50848 cmd->se_ordered_id, cmd->sam_task_attr,
50849diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50850index 04b1be7..5eff86d 100644
50851--- a/drivers/thermal/of-thermal.c
50852+++ b/drivers/thermal/of-thermal.c
50853@@ -30,6 +30,7 @@
50854 #include <linux/err.h>
50855 #include <linux/export.h>
50856 #include <linux/string.h>
50857+#include <linux/mm.h>
50858
50859 #include "thermal_core.h"
50860
50861@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50862 tz->get_trend = get_trend;
50863 tz->sensor_data = data;
50864
50865- tzd->ops->get_temp = of_thermal_get_temp;
50866- tzd->ops->get_trend = of_thermal_get_trend;
50867+ pax_open_kernel();
50868+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50869+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50870+ pax_close_kernel();
50871 mutex_unlock(&tzd->lock);
50872
50873 return tzd;
50874@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50875 return;
50876
50877 mutex_lock(&tzd->lock);
50878- tzd->ops->get_temp = NULL;
50879- tzd->ops->get_trend = NULL;
50880+ pax_open_kernel();
50881+ *(void **)&tzd->ops->get_temp = NULL;
50882+ *(void **)&tzd->ops->get_trend = NULL;
50883+ pax_close_kernel();
50884
50885 tz->get_temp = NULL;
50886 tz->get_trend = NULL;
50887diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50888index a57bb5a..1f727d33 100644
50889--- a/drivers/tty/cyclades.c
50890+++ b/drivers/tty/cyclades.c
50891@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50892 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50893 info->port.count);
50894 #endif
50895- info->port.count++;
50896+ atomic_inc(&info->port.count);
50897 #ifdef CY_DEBUG_COUNT
50898 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50899- current->pid, info->port.count);
50900+ current->pid, atomic_read(&info->port.count));
50901 #endif
50902
50903 /*
50904@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50905 for (j = 0; j < cy_card[i].nports; j++) {
50906 info = &cy_card[i].ports[j];
50907
50908- if (info->port.count) {
50909+ if (atomic_read(&info->port.count)) {
50910 /* XXX is the ldisc num worth this? */
50911 struct tty_struct *tty;
50912 struct tty_ldisc *ld;
50913diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50914index 0ff7fda..dbc7d52 100644
50915--- a/drivers/tty/hvc/hvc_console.c
50916+++ b/drivers/tty/hvc/hvc_console.c
50917@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50918
50919 spin_lock_irqsave(&hp->port.lock, flags);
50920 /* Check and then increment for fast path open. */
50921- if (hp->port.count++ > 0) {
50922+ if (atomic_inc_return(&hp->port.count) > 1) {
50923 spin_unlock_irqrestore(&hp->port.lock, flags);
50924 hvc_kick();
50925 return 0;
50926@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50927
50928 spin_lock_irqsave(&hp->port.lock, flags);
50929
50930- if (--hp->port.count == 0) {
50931+ if (atomic_dec_return(&hp->port.count) == 0) {
50932 spin_unlock_irqrestore(&hp->port.lock, flags);
50933 /* We are done with the tty pointer now. */
50934 tty_port_tty_set(&hp->port, NULL);
50935@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50936 */
50937 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50938 } else {
50939- if (hp->port.count < 0)
50940+ if (atomic_read(&hp->port.count) < 0)
50941 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50942- hp->vtermno, hp->port.count);
50943+ hp->vtermno, atomic_read(&hp->port.count));
50944 spin_unlock_irqrestore(&hp->port.lock, flags);
50945 }
50946 }
50947@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50948 * open->hangup case this can be called after the final close so prevent
50949 * that from happening for now.
50950 */
50951- if (hp->port.count <= 0) {
50952+ if (atomic_read(&hp->port.count) <= 0) {
50953 spin_unlock_irqrestore(&hp->port.lock, flags);
50954 return;
50955 }
50956
50957- hp->port.count = 0;
50958+ atomic_set(&hp->port.count, 0);
50959 spin_unlock_irqrestore(&hp->port.lock, flags);
50960 tty_port_tty_set(&hp->port, NULL);
50961
50962@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50963 return -EPIPE;
50964
50965 /* FIXME what's this (unprotected) check for? */
50966- if (hp->port.count <= 0)
50967+ if (atomic_read(&hp->port.count) <= 0)
50968 return -EIO;
50969
50970 spin_lock_irqsave(&hp->lock, flags);
50971diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50972index 81e939e..95ead10 100644
50973--- a/drivers/tty/hvc/hvcs.c
50974+++ b/drivers/tty/hvc/hvcs.c
50975@@ -83,6 +83,7 @@
50976 #include <asm/hvcserver.h>
50977 #include <asm/uaccess.h>
50978 #include <asm/vio.h>
50979+#include <asm/local.h>
50980
50981 /*
50982 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50983@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50984
50985 spin_lock_irqsave(&hvcsd->lock, flags);
50986
50987- if (hvcsd->port.count > 0) {
50988+ if (atomic_read(&hvcsd->port.count) > 0) {
50989 spin_unlock_irqrestore(&hvcsd->lock, flags);
50990 printk(KERN_INFO "HVCS: vterm state unchanged. "
50991 "The hvcs device node is still in use.\n");
50992@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50993 }
50994 }
50995
50996- hvcsd->port.count = 0;
50997+ atomic_set(&hvcsd->port.count, 0);
50998 hvcsd->port.tty = tty;
50999 tty->driver_data = hvcsd;
51000
51001@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
51002 unsigned long flags;
51003
51004 spin_lock_irqsave(&hvcsd->lock, flags);
51005- hvcsd->port.count++;
51006+ atomic_inc(&hvcsd->port.count);
51007 hvcsd->todo_mask |= HVCS_SCHED_READ;
51008 spin_unlock_irqrestore(&hvcsd->lock, flags);
51009
51010@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
51011 hvcsd = tty->driver_data;
51012
51013 spin_lock_irqsave(&hvcsd->lock, flags);
51014- if (--hvcsd->port.count == 0) {
51015+ if (atomic_dec_and_test(&hvcsd->port.count)) {
51016
51017 vio_disable_interrupts(hvcsd->vdev);
51018
51019@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
51020
51021 free_irq(irq, hvcsd);
51022 return;
51023- } else if (hvcsd->port.count < 0) {
51024+ } else if (atomic_read(&hvcsd->port.count) < 0) {
51025 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
51026 " is missmanaged.\n",
51027- hvcsd->vdev->unit_address, hvcsd->port.count);
51028+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
51029 }
51030
51031 spin_unlock_irqrestore(&hvcsd->lock, flags);
51032@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
51033
51034 spin_lock_irqsave(&hvcsd->lock, flags);
51035 /* Preserve this so that we know how many kref refs to put */
51036- temp_open_count = hvcsd->port.count;
51037+ temp_open_count = atomic_read(&hvcsd->port.count);
51038
51039 /*
51040 * Don't kref put inside the spinlock because the destruction
51041@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
51042 tty->driver_data = NULL;
51043 hvcsd->port.tty = NULL;
51044
51045- hvcsd->port.count = 0;
51046+ atomic_set(&hvcsd->port.count, 0);
51047
51048 /* This will drop any buffered data on the floor which is OK in a hangup
51049 * scenario. */
51050@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
51051 * the middle of a write operation? This is a crummy place to do this
51052 * but we want to keep it all in the spinlock.
51053 */
51054- if (hvcsd->port.count <= 0) {
51055+ if (atomic_read(&hvcsd->port.count) <= 0) {
51056 spin_unlock_irqrestore(&hvcsd->lock, flags);
51057 return -ENODEV;
51058 }
51059@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
51060 {
51061 struct hvcs_struct *hvcsd = tty->driver_data;
51062
51063- if (!hvcsd || hvcsd->port.count <= 0)
51064+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
51065 return 0;
51066
51067 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
51068diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
51069index 4190199..06d5bfa 100644
51070--- a/drivers/tty/hvc/hvsi.c
51071+++ b/drivers/tty/hvc/hvsi.c
51072@@ -85,7 +85,7 @@ struct hvsi_struct {
51073 int n_outbuf;
51074 uint32_t vtermno;
51075 uint32_t virq;
51076- atomic_t seqno; /* HVSI packet sequence number */
51077+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
51078 uint16_t mctrl;
51079 uint8_t state; /* HVSI protocol state */
51080 uint8_t flags;
51081@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
51082
51083 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
51084 packet.hdr.len = sizeof(struct hvsi_query_response);
51085- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51086+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51087 packet.verb = VSV_SEND_VERSION_NUMBER;
51088 packet.u.version = HVSI_VERSION;
51089 packet.query_seqno = query_seqno+1;
51090@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
51091
51092 packet.hdr.type = VS_QUERY_PACKET_HEADER;
51093 packet.hdr.len = sizeof(struct hvsi_query);
51094- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51095+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51096 packet.verb = verb;
51097
51098 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
51099@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
51100 int wrote;
51101
51102 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
51103- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51104+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51105 packet.hdr.len = sizeof(struct hvsi_control);
51106 packet.verb = VSV_SET_MODEM_CTL;
51107 packet.mask = HVSI_TSDTR;
51108@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
51109 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
51110
51111 packet.hdr.type = VS_DATA_PACKET_HEADER;
51112- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51113+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51114 packet.hdr.len = count + sizeof(struct hvsi_header);
51115 memcpy(&packet.data, buf, count);
51116
51117@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
51118 struct hvsi_control packet __ALIGNED__;
51119
51120 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
51121- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51122+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51123 packet.hdr.len = 6;
51124 packet.verb = VSV_CLOSE_PROTOCOL;
51125
51126@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
51127
51128 tty_port_tty_set(&hp->port, tty);
51129 spin_lock_irqsave(&hp->lock, flags);
51130- hp->port.count++;
51131+ atomic_inc(&hp->port.count);
51132 atomic_set(&hp->seqno, 0);
51133 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
51134 spin_unlock_irqrestore(&hp->lock, flags);
51135@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51136
51137 spin_lock_irqsave(&hp->lock, flags);
51138
51139- if (--hp->port.count == 0) {
51140+ if (atomic_dec_return(&hp->port.count) == 0) {
51141 tty_port_tty_set(&hp->port, NULL);
51142 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
51143
51144@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51145
51146 spin_lock_irqsave(&hp->lock, flags);
51147 }
51148- } else if (hp->port.count < 0)
51149+ } else if (atomic_read(&hp->port.count) < 0)
51150 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
51151- hp - hvsi_ports, hp->port.count);
51152+ hp - hvsi_ports, atomic_read(&hp->port.count));
51153
51154 spin_unlock_irqrestore(&hp->lock, flags);
51155 }
51156@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
51157 tty_port_tty_set(&hp->port, NULL);
51158
51159 spin_lock_irqsave(&hp->lock, flags);
51160- hp->port.count = 0;
51161+ atomic_set(&hp->port.count, 0);
51162 hp->n_outbuf = 0;
51163 spin_unlock_irqrestore(&hp->lock, flags);
51164 }
51165diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
51166index 7ae6c29..05c6dba 100644
51167--- a/drivers/tty/hvc/hvsi_lib.c
51168+++ b/drivers/tty/hvc/hvsi_lib.c
51169@@ -8,7 +8,7 @@
51170
51171 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
51172 {
51173- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
51174+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
51175
51176 /* Assumes that always succeeds, works in practice */
51177 return pv->put_chars(pv->termno, (char *)packet, packet->len);
51178@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
51179
51180 /* Reset state */
51181 pv->established = 0;
51182- atomic_set(&pv->seqno, 0);
51183+ atomic_set_unchecked(&pv->seqno, 0);
51184
51185 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
51186
51187diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
51188index 17ee3bf..8d2520d 100644
51189--- a/drivers/tty/ipwireless/tty.c
51190+++ b/drivers/tty/ipwireless/tty.c
51191@@ -28,6 +28,7 @@
51192 #include <linux/tty_driver.h>
51193 #include <linux/tty_flip.h>
51194 #include <linux/uaccess.h>
51195+#include <asm/local.h>
51196
51197 #include "tty.h"
51198 #include "network.h"
51199@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51200 mutex_unlock(&tty->ipw_tty_mutex);
51201 return -ENODEV;
51202 }
51203- if (tty->port.count == 0)
51204+ if (atomic_read(&tty->port.count) == 0)
51205 tty->tx_bytes_queued = 0;
51206
51207- tty->port.count++;
51208+ atomic_inc(&tty->port.count);
51209
51210 tty->port.tty = linux_tty;
51211 linux_tty->driver_data = tty;
51212@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51213
51214 static void do_ipw_close(struct ipw_tty *tty)
51215 {
51216- tty->port.count--;
51217-
51218- if (tty->port.count == 0) {
51219+ if (atomic_dec_return(&tty->port.count) == 0) {
51220 struct tty_struct *linux_tty = tty->port.tty;
51221
51222 if (linux_tty != NULL) {
51223@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
51224 return;
51225
51226 mutex_lock(&tty->ipw_tty_mutex);
51227- if (tty->port.count == 0) {
51228+ if (atomic_read(&tty->port.count) == 0) {
51229 mutex_unlock(&tty->ipw_tty_mutex);
51230 return;
51231 }
51232@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
51233
51234 mutex_lock(&tty->ipw_tty_mutex);
51235
51236- if (!tty->port.count) {
51237+ if (!atomic_read(&tty->port.count)) {
51238 mutex_unlock(&tty->ipw_tty_mutex);
51239 return;
51240 }
51241@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
51242 return -ENODEV;
51243
51244 mutex_lock(&tty->ipw_tty_mutex);
51245- if (!tty->port.count) {
51246+ if (!atomic_read(&tty->port.count)) {
51247 mutex_unlock(&tty->ipw_tty_mutex);
51248 return -EINVAL;
51249 }
51250@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
51251 if (!tty)
51252 return -ENODEV;
51253
51254- if (!tty->port.count)
51255+ if (!atomic_read(&tty->port.count))
51256 return -EINVAL;
51257
51258 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
51259@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
51260 if (!tty)
51261 return 0;
51262
51263- if (!tty->port.count)
51264+ if (!atomic_read(&tty->port.count))
51265 return 0;
51266
51267 return tty->tx_bytes_queued;
51268@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
51269 if (!tty)
51270 return -ENODEV;
51271
51272- if (!tty->port.count)
51273+ if (!atomic_read(&tty->port.count))
51274 return -EINVAL;
51275
51276 return get_control_lines(tty);
51277@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
51278 if (!tty)
51279 return -ENODEV;
51280
51281- if (!tty->port.count)
51282+ if (!atomic_read(&tty->port.count))
51283 return -EINVAL;
51284
51285 return set_control_lines(tty, set, clear);
51286@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
51287 if (!tty)
51288 return -ENODEV;
51289
51290- if (!tty->port.count)
51291+ if (!atomic_read(&tty->port.count))
51292 return -EINVAL;
51293
51294 /* FIXME: Exactly how is the tty object locked here .. */
51295@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
51296 * are gone */
51297 mutex_lock(&ttyj->ipw_tty_mutex);
51298 }
51299- while (ttyj->port.count)
51300+ while (atomic_read(&ttyj->port.count))
51301 do_ipw_close(ttyj);
51302 ipwireless_disassociate_network_ttys(network,
51303 ttyj->channel_idx);
51304diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
51305index 1deaca4..c8582d4 100644
51306--- a/drivers/tty/moxa.c
51307+++ b/drivers/tty/moxa.c
51308@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
51309 }
51310
51311 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
51312- ch->port.count++;
51313+ atomic_inc(&ch->port.count);
51314 tty->driver_data = ch;
51315 tty_port_tty_set(&ch->port, tty);
51316 mutex_lock(&ch->port.mutex);
51317diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
51318index 2ebe47b..3205833 100644
51319--- a/drivers/tty/n_gsm.c
51320+++ b/drivers/tty/n_gsm.c
51321@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
51322 spin_lock_init(&dlci->lock);
51323 mutex_init(&dlci->mutex);
51324 dlci->fifo = &dlci->_fifo;
51325- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
51326+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
51327 kfree(dlci);
51328 return NULL;
51329 }
51330@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
51331 struct gsm_dlci *dlci = tty->driver_data;
51332 struct tty_port *port = &dlci->port;
51333
51334- port->count++;
51335+ atomic_inc(&port->count);
51336 tty_port_tty_set(port, tty);
51337
51338 dlci->modem_rx = 0;
51339diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
51340index e36d1f5..9938e3e 100644
51341--- a/drivers/tty/n_tty.c
51342+++ b/drivers/tty/n_tty.c
51343@@ -115,7 +115,7 @@ struct n_tty_data {
51344 int minimum_to_wake;
51345
51346 /* consumer-published */
51347- size_t read_tail;
51348+ size_t read_tail __intentional_overflow(-1);
51349 size_t line_start;
51350
51351 /* protected by output lock */
51352@@ -2519,6 +2519,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
51353 {
51354 *ops = tty_ldisc_N_TTY;
51355 ops->owner = NULL;
51356- ops->refcount = ops->flags = 0;
51357+ atomic_set(&ops->refcount, 0);
51358+ ops->flags = 0;
51359 }
51360 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
51361diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
51362index 25c9bc7..24077b7 100644
51363--- a/drivers/tty/pty.c
51364+++ b/drivers/tty/pty.c
51365@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
51366 panic("Couldn't register Unix98 pts driver");
51367
51368 /* Now create the /dev/ptmx special device */
51369+ pax_open_kernel();
51370 tty_default_fops(&ptmx_fops);
51371- ptmx_fops.open = ptmx_open;
51372+ *(void **)&ptmx_fops.open = ptmx_open;
51373+ pax_close_kernel();
51374
51375 cdev_init(&ptmx_cdev, &ptmx_fops);
51376 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
51377diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
51378index 383c4c7..d408e21 100644
51379--- a/drivers/tty/rocket.c
51380+++ b/drivers/tty/rocket.c
51381@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51382 tty->driver_data = info;
51383 tty_port_tty_set(port, tty);
51384
51385- if (port->count++ == 0) {
51386+ if (atomic_inc_return(&port->count) == 1) {
51387 atomic_inc(&rp_num_ports_open);
51388
51389 #ifdef ROCKET_DEBUG_OPEN
51390@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51391 #endif
51392 }
51393 #ifdef ROCKET_DEBUG_OPEN
51394- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
51395+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
51396 #endif
51397
51398 /*
51399@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
51400 spin_unlock_irqrestore(&info->port.lock, flags);
51401 return;
51402 }
51403- if (info->port.count)
51404+ if (atomic_read(&info->port.count))
51405 atomic_dec(&rp_num_ports_open);
51406 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
51407 spin_unlock_irqrestore(&info->port.lock, flags);
51408diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
51409index 1274499..f541382 100644
51410--- a/drivers/tty/serial/ioc4_serial.c
51411+++ b/drivers/tty/serial/ioc4_serial.c
51412@@ -437,7 +437,7 @@ struct ioc4_soft {
51413 } is_intr_info[MAX_IOC4_INTR_ENTS];
51414
51415 /* Number of entries active in the above array */
51416- atomic_t is_num_intrs;
51417+ atomic_unchecked_t is_num_intrs;
51418 } is_intr_type[IOC4_NUM_INTR_TYPES];
51419
51420 /* is_ir_lock must be held while
51421@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
51422 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
51423 || (type == IOC4_OTHER_INTR_TYPE)));
51424
51425- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
51426+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
51427 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
51428
51429 /* Save off the lower level interrupt handler */
51430@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
51431
51432 soft = arg;
51433 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
51434- num_intrs = (int)atomic_read(
51435+ num_intrs = (int)atomic_read_unchecked(
51436 &soft->is_intr_type[intr_type].is_num_intrs);
51437
51438 this_mir = this_ir = pending_intrs(soft, intr_type);
51439diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
51440index a260cde..6b2b5ce 100644
51441--- a/drivers/tty/serial/kgdboc.c
51442+++ b/drivers/tty/serial/kgdboc.c
51443@@ -24,8 +24,9 @@
51444 #define MAX_CONFIG_LEN 40
51445
51446 static struct kgdb_io kgdboc_io_ops;
51447+static struct kgdb_io kgdboc_io_ops_console;
51448
51449-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
51450+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
51451 static int configured = -1;
51452
51453 static char config[MAX_CONFIG_LEN];
51454@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
51455 kgdboc_unregister_kbd();
51456 if (configured == 1)
51457 kgdb_unregister_io_module(&kgdboc_io_ops);
51458+ else if (configured == 2)
51459+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
51460 }
51461
51462 static int configure_kgdboc(void)
51463@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
51464 int err;
51465 char *cptr = config;
51466 struct console *cons;
51467+ int is_console = 0;
51468
51469 err = kgdboc_option_setup(config);
51470 if (err || !strlen(config) || isspace(config[0]))
51471 goto noconfig;
51472
51473 err = -ENODEV;
51474- kgdboc_io_ops.is_console = 0;
51475 kgdb_tty_driver = NULL;
51476
51477 kgdboc_use_kms = 0;
51478@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51479 int idx;
51480 if (cons->device && cons->device(cons, &idx) == p &&
51481 idx == tty_line) {
51482- kgdboc_io_ops.is_console = 1;
51483+ is_console = 1;
51484 break;
51485 }
51486 cons = cons->next;
51487@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51488 kgdb_tty_line = tty_line;
51489
51490 do_register:
51491- err = kgdb_register_io_module(&kgdboc_io_ops);
51492+ if (is_console) {
51493+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
51494+ configured = 2;
51495+ } else {
51496+ err = kgdb_register_io_module(&kgdboc_io_ops);
51497+ configured = 1;
51498+ }
51499 if (err)
51500 goto noconfig;
51501
51502@@ -205,8 +214,6 @@ do_register:
51503 if (err)
51504 goto nmi_con_failed;
51505
51506- configured = 1;
51507-
51508 return 0;
51509
51510 nmi_con_failed:
51511@@ -223,7 +230,7 @@ noconfig:
51512 static int __init init_kgdboc(void)
51513 {
51514 /* Already configured? */
51515- if (configured == 1)
51516+ if (configured >= 1)
51517 return 0;
51518
51519 return configure_kgdboc();
51520@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51521 if (config[len - 1] == '\n')
51522 config[len - 1] = '\0';
51523
51524- if (configured == 1)
51525+ if (configured >= 1)
51526 cleanup_kgdboc();
51527
51528 /* Go and configure with the new params. */
51529@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51530 .post_exception = kgdboc_post_exp_handler,
51531 };
51532
51533+static struct kgdb_io kgdboc_io_ops_console = {
51534+ .name = "kgdboc",
51535+ .read_char = kgdboc_get_char,
51536+ .write_char = kgdboc_put_char,
51537+ .pre_exception = kgdboc_pre_exp_handler,
51538+ .post_exception = kgdboc_post_exp_handler,
51539+ .is_console = 1
51540+};
51541+
51542 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51543 /* This is only available if kgdboc is a built in for early debugging */
51544 static int __init kgdboc_early_init(char *opt)
51545diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51546index b5d779c..3622cfe 100644
51547--- a/drivers/tty/serial/msm_serial.c
51548+++ b/drivers/tty/serial/msm_serial.c
51549@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
51550 .cons = MSM_CONSOLE,
51551 };
51552
51553-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51554+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51555
51556 static const struct of_device_id msm_uartdm_table[] = {
51557 { .compatible = "qcom,msm-uartdm" },
51558@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51559 int irq;
51560
51561 if (pdev->id == -1)
51562- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51563+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51564
51565 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51566 return -ENXIO;
51567diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51568index 9cd706d..6ff2de7 100644
51569--- a/drivers/tty/serial/samsung.c
51570+++ b/drivers/tty/serial/samsung.c
51571@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51572 }
51573 }
51574
51575+static int s3c64xx_serial_startup(struct uart_port *port);
51576 static int s3c24xx_serial_startup(struct uart_port *port)
51577 {
51578 struct s3c24xx_uart_port *ourport = to_ourport(port);
51579 int ret;
51580
51581+ /* Startup sequence is different for s3c64xx and higher SoC's */
51582+ if (s3c24xx_serial_has_interrupt_mask(port))
51583+ return s3c64xx_serial_startup(port);
51584+
51585 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51586 port->mapbase, port->membase);
51587
51588@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51589 /* setup info for port */
51590 port->dev = &platdev->dev;
51591
51592- /* Startup sequence is different for s3c64xx and higher SoC's */
51593- if (s3c24xx_serial_has_interrupt_mask(port))
51594- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51595-
51596 port->uartclk = 1;
51597
51598 if (cfg->uart_flags & UPF_CONS_FLOW) {
51599diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51600index ece2049..fba2524 100644
51601--- a/drivers/tty/serial/serial_core.c
51602+++ b/drivers/tty/serial/serial_core.c
51603@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
51604 uart_flush_buffer(tty);
51605 uart_shutdown(tty, state);
51606 spin_lock_irqsave(&port->lock, flags);
51607- port->count = 0;
51608+ atomic_set(&port->count, 0);
51609 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51610 spin_unlock_irqrestore(&port->lock, flags);
51611 tty_port_tty_set(port, NULL);
51612@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51613 goto end;
51614 }
51615
51616- port->count++;
51617+ atomic_inc(&port->count);
51618 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51619 retval = -ENXIO;
51620 goto err_dec_count;
51621@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51622 /*
51623 * Make sure the device is in D0 state.
51624 */
51625- if (port->count == 1)
51626+ if (atomic_read(&port->count) == 1)
51627 uart_change_pm(state, UART_PM_STATE_ON);
51628
51629 /*
51630@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51631 end:
51632 return retval;
51633 err_dec_count:
51634- port->count--;
51635+ atomic_inc(&port->count);
51636 mutex_unlock(&port->mutex);
51637 goto end;
51638 }
51639diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51640index 5ae14b4..2c1288f 100644
51641--- a/drivers/tty/synclink.c
51642+++ b/drivers/tty/synclink.c
51643@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51644
51645 if (debug_level >= DEBUG_LEVEL_INFO)
51646 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51647- __FILE__,__LINE__, info->device_name, info->port.count);
51648+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51649
51650 if (tty_port_close_start(&info->port, tty, filp) == 0)
51651 goto cleanup;
51652@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51653 cleanup:
51654 if (debug_level >= DEBUG_LEVEL_INFO)
51655 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51656- tty->driver->name, info->port.count);
51657+ tty->driver->name, atomic_read(&info->port.count));
51658
51659 } /* end of mgsl_close() */
51660
51661@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51662
51663 mgsl_flush_buffer(tty);
51664 shutdown(info);
51665-
51666- info->port.count = 0;
51667+
51668+ atomic_set(&info->port.count, 0);
51669 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51670 info->port.tty = NULL;
51671
51672@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51673
51674 if (debug_level >= DEBUG_LEVEL_INFO)
51675 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51676- __FILE__,__LINE__, tty->driver->name, port->count );
51677+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51678
51679 spin_lock_irqsave(&info->irq_spinlock, flags);
51680 if (!tty_hung_up_p(filp)) {
51681 extra_count = true;
51682- port->count--;
51683+ atomic_dec(&port->count);
51684 }
51685 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51686 port->blocked_open++;
51687@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51688
51689 if (debug_level >= DEBUG_LEVEL_INFO)
51690 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51691- __FILE__,__LINE__, tty->driver->name, port->count );
51692+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51693
51694 tty_unlock(tty);
51695 schedule();
51696@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51697
51698 /* FIXME: Racy on hangup during close wait */
51699 if (extra_count)
51700- port->count++;
51701+ atomic_inc(&port->count);
51702 port->blocked_open--;
51703
51704 if (debug_level >= DEBUG_LEVEL_INFO)
51705 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51706- __FILE__,__LINE__, tty->driver->name, port->count );
51707+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51708
51709 if (!retval)
51710 port->flags |= ASYNC_NORMAL_ACTIVE;
51711@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51712
51713 if (debug_level >= DEBUG_LEVEL_INFO)
51714 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51715- __FILE__,__LINE__,tty->driver->name, info->port.count);
51716+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51717
51718 /* If port is closing, signal caller to try again */
51719 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51720@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51721 spin_unlock_irqrestore(&info->netlock, flags);
51722 goto cleanup;
51723 }
51724- info->port.count++;
51725+ atomic_inc(&info->port.count);
51726 spin_unlock_irqrestore(&info->netlock, flags);
51727
51728- if (info->port.count == 1) {
51729+ if (atomic_read(&info->port.count) == 1) {
51730 /* 1st open on this device, init hardware */
51731 retval = startup(info);
51732 if (retval < 0)
51733@@ -3446,8 +3446,8 @@ cleanup:
51734 if (retval) {
51735 if (tty->count == 1)
51736 info->port.tty = NULL; /* tty layer will release tty struct */
51737- if(info->port.count)
51738- info->port.count--;
51739+ if (atomic_read(&info->port.count))
51740+ atomic_dec(&info->port.count);
51741 }
51742
51743 return retval;
51744@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51745 unsigned short new_crctype;
51746
51747 /* return error if TTY interface open */
51748- if (info->port.count)
51749+ if (atomic_read(&info->port.count))
51750 return -EBUSY;
51751
51752 switch (encoding)
51753@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51754
51755 /* arbitrate between network and tty opens */
51756 spin_lock_irqsave(&info->netlock, flags);
51757- if (info->port.count != 0 || info->netcount != 0) {
51758+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51759 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51760 spin_unlock_irqrestore(&info->netlock, flags);
51761 return -EBUSY;
51762@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51763 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51764
51765 /* return error if TTY interface open */
51766- if (info->port.count)
51767+ if (atomic_read(&info->port.count))
51768 return -EBUSY;
51769
51770 if (cmd != SIOCWANDEV)
51771diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51772index c359a91..959fc26 100644
51773--- a/drivers/tty/synclink_gt.c
51774+++ b/drivers/tty/synclink_gt.c
51775@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51776 tty->driver_data = info;
51777 info->port.tty = tty;
51778
51779- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51780+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51781
51782 /* If port is closing, signal caller to try again */
51783 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51784@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51785 mutex_unlock(&info->port.mutex);
51786 goto cleanup;
51787 }
51788- info->port.count++;
51789+ atomic_inc(&info->port.count);
51790 spin_unlock_irqrestore(&info->netlock, flags);
51791
51792- if (info->port.count == 1) {
51793+ if (atomic_read(&info->port.count) == 1) {
51794 /* 1st open on this device, init hardware */
51795 retval = startup(info);
51796 if (retval < 0) {
51797@@ -715,8 +715,8 @@ cleanup:
51798 if (retval) {
51799 if (tty->count == 1)
51800 info->port.tty = NULL; /* tty layer will release tty struct */
51801- if(info->port.count)
51802- info->port.count--;
51803+ if(atomic_read(&info->port.count))
51804+ atomic_dec(&info->port.count);
51805 }
51806
51807 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51808@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51809
51810 if (sanity_check(info, tty->name, "close"))
51811 return;
51812- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51813+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51814
51815 if (tty_port_close_start(&info->port, tty, filp) == 0)
51816 goto cleanup;
51817@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51818 tty_port_close_end(&info->port, tty);
51819 info->port.tty = NULL;
51820 cleanup:
51821- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51822+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51823 }
51824
51825 static void hangup(struct tty_struct *tty)
51826@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51827 shutdown(info);
51828
51829 spin_lock_irqsave(&info->port.lock, flags);
51830- info->port.count = 0;
51831+ atomic_set(&info->port.count, 0);
51832 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51833 info->port.tty = NULL;
51834 spin_unlock_irqrestore(&info->port.lock, flags);
51835@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51836 unsigned short new_crctype;
51837
51838 /* return error if TTY interface open */
51839- if (info->port.count)
51840+ if (atomic_read(&info->port.count))
51841 return -EBUSY;
51842
51843 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51844@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51845
51846 /* arbitrate between network and tty opens */
51847 spin_lock_irqsave(&info->netlock, flags);
51848- if (info->port.count != 0 || info->netcount != 0) {
51849+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51850 DBGINFO(("%s hdlc_open busy\n", dev->name));
51851 spin_unlock_irqrestore(&info->netlock, flags);
51852 return -EBUSY;
51853@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51854 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51855
51856 /* return error if TTY interface open */
51857- if (info->port.count)
51858+ if (atomic_read(&info->port.count))
51859 return -EBUSY;
51860
51861 if (cmd != SIOCWANDEV)
51862@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51863 if (port == NULL)
51864 continue;
51865 spin_lock(&port->lock);
51866- if ((port->port.count || port->netcount) &&
51867+ if ((atomic_read(&port->port.count) || port->netcount) &&
51868 port->pending_bh && !port->bh_running &&
51869 !port->bh_requested) {
51870 DBGISR(("%s bh queued\n", port->device_name));
51871@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51872 spin_lock_irqsave(&info->lock, flags);
51873 if (!tty_hung_up_p(filp)) {
51874 extra_count = true;
51875- port->count--;
51876+ atomic_dec(&port->count);
51877 }
51878 spin_unlock_irqrestore(&info->lock, flags);
51879 port->blocked_open++;
51880@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51881 remove_wait_queue(&port->open_wait, &wait);
51882
51883 if (extra_count)
51884- port->count++;
51885+ atomic_inc(&port->count);
51886 port->blocked_open--;
51887
51888 if (!retval)
51889diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51890index 144202e..4ccb07d 100644
51891--- a/drivers/tty/synclinkmp.c
51892+++ b/drivers/tty/synclinkmp.c
51893@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51894
51895 if (debug_level >= DEBUG_LEVEL_INFO)
51896 printk("%s(%d):%s open(), old ref count = %d\n",
51897- __FILE__,__LINE__,tty->driver->name, info->port.count);
51898+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51899
51900 /* If port is closing, signal caller to try again */
51901 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51902@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51903 spin_unlock_irqrestore(&info->netlock, flags);
51904 goto cleanup;
51905 }
51906- info->port.count++;
51907+ atomic_inc(&info->port.count);
51908 spin_unlock_irqrestore(&info->netlock, flags);
51909
51910- if (info->port.count == 1) {
51911+ if (atomic_read(&info->port.count) == 1) {
51912 /* 1st open on this device, init hardware */
51913 retval = startup(info);
51914 if (retval < 0)
51915@@ -796,8 +796,8 @@ cleanup:
51916 if (retval) {
51917 if (tty->count == 1)
51918 info->port.tty = NULL; /* tty layer will release tty struct */
51919- if(info->port.count)
51920- info->port.count--;
51921+ if(atomic_read(&info->port.count))
51922+ atomic_dec(&info->port.count);
51923 }
51924
51925 return retval;
51926@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51927
51928 if (debug_level >= DEBUG_LEVEL_INFO)
51929 printk("%s(%d):%s close() entry, count=%d\n",
51930- __FILE__,__LINE__, info->device_name, info->port.count);
51931+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51932
51933 if (tty_port_close_start(&info->port, tty, filp) == 0)
51934 goto cleanup;
51935@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51936 cleanup:
51937 if (debug_level >= DEBUG_LEVEL_INFO)
51938 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51939- tty->driver->name, info->port.count);
51940+ tty->driver->name, atomic_read(&info->port.count));
51941 }
51942
51943 /* Called by tty_hangup() when a hangup is signaled.
51944@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51945 shutdown(info);
51946
51947 spin_lock_irqsave(&info->port.lock, flags);
51948- info->port.count = 0;
51949+ atomic_set(&info->port.count, 0);
51950 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51951 info->port.tty = NULL;
51952 spin_unlock_irqrestore(&info->port.lock, flags);
51953@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51954 unsigned short new_crctype;
51955
51956 /* return error if TTY interface open */
51957- if (info->port.count)
51958+ if (atomic_read(&info->port.count))
51959 return -EBUSY;
51960
51961 switch (encoding)
51962@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51963
51964 /* arbitrate between network and tty opens */
51965 spin_lock_irqsave(&info->netlock, flags);
51966- if (info->port.count != 0 || info->netcount != 0) {
51967+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51968 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51969 spin_unlock_irqrestore(&info->netlock, flags);
51970 return -EBUSY;
51971@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51972 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51973
51974 /* return error if TTY interface open */
51975- if (info->port.count)
51976+ if (atomic_read(&info->port.count))
51977 return -EBUSY;
51978
51979 if (cmd != SIOCWANDEV)
51980@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51981 * do not request bottom half processing if the
51982 * device is not open in a normal mode.
51983 */
51984- if ( port && (port->port.count || port->netcount) &&
51985+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51986 port->pending_bh && !port->bh_running &&
51987 !port->bh_requested ) {
51988 if ( debug_level >= DEBUG_LEVEL_ISR )
51989@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51990
51991 if (debug_level >= DEBUG_LEVEL_INFO)
51992 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51993- __FILE__,__LINE__, tty->driver->name, port->count );
51994+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51995
51996 spin_lock_irqsave(&info->lock, flags);
51997 if (!tty_hung_up_p(filp)) {
51998 extra_count = true;
51999- port->count--;
52000+ atomic_dec(&port->count);
52001 }
52002 spin_unlock_irqrestore(&info->lock, flags);
52003 port->blocked_open++;
52004@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
52005
52006 if (debug_level >= DEBUG_LEVEL_INFO)
52007 printk("%s(%d):%s block_til_ready() count=%d\n",
52008- __FILE__,__LINE__, tty->driver->name, port->count );
52009+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
52010
52011 tty_unlock(tty);
52012 schedule();
52013@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
52014 remove_wait_queue(&port->open_wait, &wait);
52015
52016 if (extra_count)
52017- port->count++;
52018+ atomic_inc(&port->count);
52019 port->blocked_open--;
52020
52021 if (debug_level >= DEBUG_LEVEL_INFO)
52022 printk("%s(%d):%s block_til_ready() after, count=%d\n",
52023- __FILE__,__LINE__, tty->driver->name, port->count );
52024+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
52025
52026 if (!retval)
52027 port->flags |= ASYNC_NORMAL_ACTIVE;
52028diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
52029index ce396ec..04a37be 100644
52030--- a/drivers/tty/sysrq.c
52031+++ b/drivers/tty/sysrq.c
52032@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
52033 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
52034 size_t count, loff_t *ppos)
52035 {
52036- if (count) {
52037+ if (count && capable(CAP_SYS_ADMIN)) {
52038 char c;
52039
52040 if (get_user(c, buf))
52041diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
52042index d3448a9..28e8db0 100644
52043--- a/drivers/tty/tty_io.c
52044+++ b/drivers/tty/tty_io.c
52045@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
52046
52047 void tty_default_fops(struct file_operations *fops)
52048 {
52049- *fops = tty_fops;
52050+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
52051 }
52052
52053 /*
52054diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
52055index 2d822aa..a566234 100644
52056--- a/drivers/tty/tty_ldisc.c
52057+++ b/drivers/tty/tty_ldisc.c
52058@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
52059 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52060 tty_ldiscs[disc] = new_ldisc;
52061 new_ldisc->num = disc;
52062- new_ldisc->refcount = 0;
52063+ atomic_set(&new_ldisc->refcount, 0);
52064 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
52065
52066 return ret;
52067@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
52068 return -EINVAL;
52069
52070 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52071- if (tty_ldiscs[disc]->refcount)
52072+ if (atomic_read(&tty_ldiscs[disc]->refcount))
52073 ret = -EBUSY;
52074 else
52075 tty_ldiscs[disc] = NULL;
52076@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
52077 if (ldops) {
52078 ret = ERR_PTR(-EAGAIN);
52079 if (try_module_get(ldops->owner)) {
52080- ldops->refcount++;
52081+ atomic_inc(&ldops->refcount);
52082 ret = ldops;
52083 }
52084 }
52085@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
52086 unsigned long flags;
52087
52088 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52089- ldops->refcount--;
52090+ atomic_dec(&ldops->refcount);
52091 module_put(ldops->owner);
52092 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
52093 }
52094diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
52095index 3f746c8..2f2fcaa 100644
52096--- a/drivers/tty/tty_port.c
52097+++ b/drivers/tty/tty_port.c
52098@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
52099 unsigned long flags;
52100
52101 spin_lock_irqsave(&port->lock, flags);
52102- port->count = 0;
52103+ atomic_set(&port->count, 0);
52104 port->flags &= ~ASYNC_NORMAL_ACTIVE;
52105 tty = port->tty;
52106 if (tty)
52107@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
52108 /* The port lock protects the port counts */
52109 spin_lock_irqsave(&port->lock, flags);
52110 if (!tty_hung_up_p(filp))
52111- port->count--;
52112+ atomic_dec(&port->count);
52113 port->blocked_open++;
52114 spin_unlock_irqrestore(&port->lock, flags);
52115
52116@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
52117 we must not mess that up further */
52118 spin_lock_irqsave(&port->lock, flags);
52119 if (!tty_hung_up_p(filp))
52120- port->count++;
52121+ atomic_inc(&port->count);
52122 port->blocked_open--;
52123 if (retval == 0)
52124 port->flags |= ASYNC_NORMAL_ACTIVE;
52125@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
52126 return 0;
52127 }
52128
52129- if (tty->count == 1 && port->count != 1) {
52130+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
52131 printk(KERN_WARNING
52132 "tty_port_close_start: tty->count = 1 port count = %d.\n",
52133- port->count);
52134- port->count = 1;
52135+ atomic_read(&port->count));
52136+ atomic_set(&port->count, 1);
52137 }
52138- if (--port->count < 0) {
52139+ if (atomic_dec_return(&port->count) < 0) {
52140 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
52141- port->count);
52142- port->count = 0;
52143+ atomic_read(&port->count));
52144+ atomic_set(&port->count, 0);
52145 }
52146
52147- if (port->count) {
52148+ if (atomic_read(&port->count)) {
52149 spin_unlock_irqrestore(&port->lock, flags);
52150 return 0;
52151 }
52152@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
52153 {
52154 spin_lock_irq(&port->lock);
52155 if (!tty_hung_up_p(filp))
52156- ++port->count;
52157+ atomic_inc(&port->count);
52158 spin_unlock_irq(&port->lock);
52159 tty_port_tty_set(port, tty);
52160
52161diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
52162index d0e3a44..5f8b754 100644
52163--- a/drivers/tty/vt/keyboard.c
52164+++ b/drivers/tty/vt/keyboard.c
52165@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
52166 kbd->kbdmode == VC_OFF) &&
52167 value != KVAL(K_SAK))
52168 return; /* SAK is allowed even in raw mode */
52169+
52170+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52171+ {
52172+ void *func = fn_handler[value];
52173+ if (func == fn_show_state || func == fn_show_ptregs ||
52174+ func == fn_show_mem)
52175+ return;
52176+ }
52177+#endif
52178+
52179 fn_handler[value](vc);
52180 }
52181
52182@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52183 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
52184 return -EFAULT;
52185
52186- if (!capable(CAP_SYS_TTY_CONFIG))
52187- perm = 0;
52188-
52189 switch (cmd) {
52190 case KDGKBENT:
52191 /* Ensure another thread doesn't free it under us */
52192@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52193 spin_unlock_irqrestore(&kbd_event_lock, flags);
52194 return put_user(val, &user_kbe->kb_value);
52195 case KDSKBENT:
52196+ if (!capable(CAP_SYS_TTY_CONFIG))
52197+ perm = 0;
52198+
52199 if (!perm)
52200 return -EPERM;
52201 if (!i && v == K_NOSUCHMAP) {
52202@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52203 int i, j, k;
52204 int ret;
52205
52206- if (!capable(CAP_SYS_TTY_CONFIG))
52207- perm = 0;
52208-
52209 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
52210 if (!kbs) {
52211 ret = -ENOMEM;
52212@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52213 kfree(kbs);
52214 return ((p && *p) ? -EOVERFLOW : 0);
52215 case KDSKBSENT:
52216+ if (!capable(CAP_SYS_TTY_CONFIG))
52217+ perm = 0;
52218+
52219 if (!perm) {
52220 ret = -EPERM;
52221 goto reterr;
52222diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
52223index a673e5b..36e5d32 100644
52224--- a/drivers/uio/uio.c
52225+++ b/drivers/uio/uio.c
52226@@ -25,6 +25,7 @@
52227 #include <linux/kobject.h>
52228 #include <linux/cdev.h>
52229 #include <linux/uio_driver.h>
52230+#include <asm/local.h>
52231
52232 #define UIO_MAX_DEVICES (1U << MINORBITS)
52233
52234@@ -32,7 +33,7 @@ struct uio_device {
52235 struct module *owner;
52236 struct device *dev;
52237 int minor;
52238- atomic_t event;
52239+ atomic_unchecked_t event;
52240 struct fasync_struct *async_queue;
52241 wait_queue_head_t wait;
52242 struct uio_info *info;
52243@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
52244 struct device_attribute *attr, char *buf)
52245 {
52246 struct uio_device *idev = dev_get_drvdata(dev);
52247- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
52248+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
52249 }
52250 static DEVICE_ATTR_RO(event);
52251
52252@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
52253 {
52254 struct uio_device *idev = info->uio_dev;
52255
52256- atomic_inc(&idev->event);
52257+ atomic_inc_unchecked(&idev->event);
52258 wake_up_interruptible(&idev->wait);
52259 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
52260 }
52261@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
52262 }
52263
52264 listener->dev = idev;
52265- listener->event_count = atomic_read(&idev->event);
52266+ listener->event_count = atomic_read_unchecked(&idev->event);
52267 filep->private_data = listener;
52268
52269 if (idev->info->open) {
52270@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
52271 return -EIO;
52272
52273 poll_wait(filep, &idev->wait, wait);
52274- if (listener->event_count != atomic_read(&idev->event))
52275+ if (listener->event_count != atomic_read_unchecked(&idev->event))
52276 return POLLIN | POLLRDNORM;
52277 return 0;
52278 }
52279@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
52280 do {
52281 set_current_state(TASK_INTERRUPTIBLE);
52282
52283- event_count = atomic_read(&idev->event);
52284+ event_count = atomic_read_unchecked(&idev->event);
52285 if (event_count != listener->event_count) {
52286 if (copy_to_user(buf, &event_count, count))
52287 retval = -EFAULT;
52288@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
52289 static int uio_find_mem_index(struct vm_area_struct *vma)
52290 {
52291 struct uio_device *idev = vma->vm_private_data;
52292+ unsigned long size;
52293
52294 if (vma->vm_pgoff < MAX_UIO_MAPS) {
52295- if (idev->info->mem[vma->vm_pgoff].size == 0)
52296+ size = idev->info->mem[vma->vm_pgoff].size;
52297+ if (size == 0)
52298+ return -1;
52299+ if (vma->vm_end - vma->vm_start > size)
52300 return -1;
52301 return (int)vma->vm_pgoff;
52302 }
52303@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
52304 idev->owner = owner;
52305 idev->info = info;
52306 init_waitqueue_head(&idev->wait);
52307- atomic_set(&idev->event, 0);
52308+ atomic_set_unchecked(&idev->event, 0);
52309
52310 ret = uio_get_minor(idev);
52311 if (ret)
52312diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
52313index 813d4d3..a71934f 100644
52314--- a/drivers/usb/atm/cxacru.c
52315+++ b/drivers/usb/atm/cxacru.c
52316@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
52317 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
52318 if (ret < 2)
52319 return -EINVAL;
52320- if (index < 0 || index > 0x7f)
52321+ if (index > 0x7f)
52322 return -EINVAL;
52323 pos += tmp;
52324
52325diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
52326index dada014..1d0d517 100644
52327--- a/drivers/usb/atm/usbatm.c
52328+++ b/drivers/usb/atm/usbatm.c
52329@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52330 if (printk_ratelimit())
52331 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
52332 __func__, vpi, vci);
52333- atomic_inc(&vcc->stats->rx_err);
52334+ atomic_inc_unchecked(&vcc->stats->rx_err);
52335 return;
52336 }
52337
52338@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52339 if (length > ATM_MAX_AAL5_PDU) {
52340 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
52341 __func__, length, vcc);
52342- atomic_inc(&vcc->stats->rx_err);
52343+ atomic_inc_unchecked(&vcc->stats->rx_err);
52344 goto out;
52345 }
52346
52347@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52348 if (sarb->len < pdu_length) {
52349 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
52350 __func__, pdu_length, sarb->len, vcc);
52351- atomic_inc(&vcc->stats->rx_err);
52352+ atomic_inc_unchecked(&vcc->stats->rx_err);
52353 goto out;
52354 }
52355
52356 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
52357 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
52358 __func__, vcc);
52359- atomic_inc(&vcc->stats->rx_err);
52360+ atomic_inc_unchecked(&vcc->stats->rx_err);
52361 goto out;
52362 }
52363
52364@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52365 if (printk_ratelimit())
52366 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
52367 __func__, length);
52368- atomic_inc(&vcc->stats->rx_drop);
52369+ atomic_inc_unchecked(&vcc->stats->rx_drop);
52370 goto out;
52371 }
52372
52373@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52374
52375 vcc->push(vcc, skb);
52376
52377- atomic_inc(&vcc->stats->rx);
52378+ atomic_inc_unchecked(&vcc->stats->rx);
52379 out:
52380 skb_trim(sarb, 0);
52381 }
52382@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
52383 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
52384
52385 usbatm_pop(vcc, skb);
52386- atomic_inc(&vcc->stats->tx);
52387+ atomic_inc_unchecked(&vcc->stats->tx);
52388
52389 skb = skb_dequeue(&instance->sndqueue);
52390 }
52391@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
52392 if (!left--)
52393 return sprintf(page,
52394 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
52395- atomic_read(&atm_dev->stats.aal5.tx),
52396- atomic_read(&atm_dev->stats.aal5.tx_err),
52397- atomic_read(&atm_dev->stats.aal5.rx),
52398- atomic_read(&atm_dev->stats.aal5.rx_err),
52399- atomic_read(&atm_dev->stats.aal5.rx_drop));
52400+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
52401+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
52402+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
52403+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
52404+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
52405
52406 if (!left--) {
52407 if (instance->disconnected)
52408diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
52409index 2a3bbdf..91d72cf 100644
52410--- a/drivers/usb/core/devices.c
52411+++ b/drivers/usb/core/devices.c
52412@@ -126,7 +126,7 @@ static const char format_endpt[] =
52413 * time it gets called.
52414 */
52415 static struct device_connect_event {
52416- atomic_t count;
52417+ atomic_unchecked_t count;
52418 wait_queue_head_t wait;
52419 } device_event = {
52420 .count = ATOMIC_INIT(1),
52421@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
52422
52423 void usbfs_conn_disc_event(void)
52424 {
52425- atomic_add(2, &device_event.count);
52426+ atomic_add_unchecked(2, &device_event.count);
52427 wake_up(&device_event.wait);
52428 }
52429
52430@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
52431
52432 poll_wait(file, &device_event.wait, wait);
52433
52434- event_count = atomic_read(&device_event.count);
52435+ event_count = atomic_read_unchecked(&device_event.count);
52436 if (file->f_version != event_count) {
52437 file->f_version = event_count;
52438 return POLLIN | POLLRDNORM;
52439diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
52440index 90e18f6..5eeda46 100644
52441--- a/drivers/usb/core/devio.c
52442+++ b/drivers/usb/core/devio.c
52443@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52444 struct dev_state *ps = file->private_data;
52445 struct usb_device *dev = ps->dev;
52446 ssize_t ret = 0;
52447- unsigned len;
52448+ size_t len;
52449 loff_t pos;
52450 int i;
52451
52452@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52453 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
52454 struct usb_config_descriptor *config =
52455 (struct usb_config_descriptor *)dev->rawdescriptors[i];
52456- unsigned int length = le16_to_cpu(config->wTotalLength);
52457+ size_t length = le16_to_cpu(config->wTotalLength);
52458
52459 if (*ppos < pos + length) {
52460
52461 /* The descriptor may claim to be longer than it
52462 * really is. Here is the actual allocated length. */
52463- unsigned alloclen =
52464+ size_t alloclen =
52465 le16_to_cpu(dev->config[i].desc.wTotalLength);
52466
52467- len = length - (*ppos - pos);
52468+ len = length + pos - *ppos;
52469 if (len > nbytes)
52470 len = nbytes;
52471
52472 /* Simply don't write (skip over) unallocated parts */
52473 if (alloclen > (*ppos - pos)) {
52474- alloclen -= (*ppos - pos);
52475+ alloclen = alloclen + pos - *ppos;
52476 if (copy_to_user(buf,
52477 dev->rawdescriptors[i] + (*ppos - pos),
52478 min(len, alloclen))) {
52479diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52480index 2518c32..1c201bb 100644
52481--- a/drivers/usb/core/hcd.c
52482+++ b/drivers/usb/core/hcd.c
52483@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52484 */
52485 usb_get_urb(urb);
52486 atomic_inc(&urb->use_count);
52487- atomic_inc(&urb->dev->urbnum);
52488+ atomic_inc_unchecked(&urb->dev->urbnum);
52489 usbmon_urb_submit(&hcd->self, urb);
52490
52491 /* NOTE requirements on root-hub callers (usbfs and the hub
52492@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52493 urb->hcpriv = NULL;
52494 INIT_LIST_HEAD(&urb->urb_list);
52495 atomic_dec(&urb->use_count);
52496- atomic_dec(&urb->dev->urbnum);
52497+ atomic_dec_unchecked(&urb->dev->urbnum);
52498 if (atomic_read(&urb->reject))
52499 wake_up(&usb_kill_urb_queue);
52500 usb_put_urb(urb);
52501diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52502index 3baa51b..92907cf 100644
52503--- a/drivers/usb/core/hub.c
52504+++ b/drivers/usb/core/hub.c
52505@@ -27,6 +27,7 @@
52506 #include <linux/freezer.h>
52507 #include <linux/random.h>
52508 #include <linux/pm_qos.h>
52509+#include <linux/grsecurity.h>
52510
52511 #include <asm/uaccess.h>
52512 #include <asm/byteorder.h>
52513@@ -4483,6 +4484,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52514 goto done;
52515 return;
52516 }
52517+
52518+ if (gr_handle_new_usb())
52519+ goto done;
52520+
52521 if (hub_is_superspeed(hub->hdev))
52522 unit_load = 150;
52523 else
52524diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52525index f829a1a..e6c334a 100644
52526--- a/drivers/usb/core/message.c
52527+++ b/drivers/usb/core/message.c
52528@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52529 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52530 * error number.
52531 */
52532-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52533+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52534 __u8 requesttype, __u16 value, __u16 index, void *data,
52535 __u16 size, int timeout)
52536 {
52537@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52538 * If successful, 0. Otherwise a negative error number. The number of actual
52539 * bytes transferred will be stored in the @actual_length paramater.
52540 */
52541-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52542+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52543 void *data, int len, int *actual_length, int timeout)
52544 {
52545 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52546@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52547 * bytes transferred will be stored in the @actual_length parameter.
52548 *
52549 */
52550-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52551+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52552 void *data, int len, int *actual_length, int timeout)
52553 {
52554 struct urb *urb;
52555diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52556index 1236c60..d47a51c 100644
52557--- a/drivers/usb/core/sysfs.c
52558+++ b/drivers/usb/core/sysfs.c
52559@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52560 struct usb_device *udev;
52561
52562 udev = to_usb_device(dev);
52563- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52564+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52565 }
52566 static DEVICE_ATTR_RO(urbnum);
52567
52568diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52569index 4d11449..f4ccabf 100644
52570--- a/drivers/usb/core/usb.c
52571+++ b/drivers/usb/core/usb.c
52572@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52573 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52574 dev->state = USB_STATE_ATTACHED;
52575 dev->lpm_disable_count = 1;
52576- atomic_set(&dev->urbnum, 0);
52577+ atomic_set_unchecked(&dev->urbnum, 0);
52578
52579 INIT_LIST_HEAD(&dev->ep0.urb_list);
52580 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52581diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52582index 2da0a5a..4870e09 100644
52583--- a/drivers/usb/dwc3/gadget.c
52584+++ b/drivers/usb/dwc3/gadget.c
52585@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52586 if (!usb_endpoint_xfer_isoc(desc))
52587 return 0;
52588
52589- memset(&trb_link, 0, sizeof(trb_link));
52590-
52591 /* Link TRB for ISOC. The HWO bit is never reset */
52592 trb_st_hw = &dep->trb_pool[0];
52593
52594diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52595index 8cfc319..4868255 100644
52596--- a/drivers/usb/early/ehci-dbgp.c
52597+++ b/drivers/usb/early/ehci-dbgp.c
52598@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52599
52600 #ifdef CONFIG_KGDB
52601 static struct kgdb_io kgdbdbgp_io_ops;
52602-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52603+static struct kgdb_io kgdbdbgp_io_ops_console;
52604+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52605 #else
52606 #define dbgp_kgdb_mode (0)
52607 #endif
52608@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52609 .write_char = kgdbdbgp_write_char,
52610 };
52611
52612+static struct kgdb_io kgdbdbgp_io_ops_console = {
52613+ .name = "kgdbdbgp",
52614+ .read_char = kgdbdbgp_read_char,
52615+ .write_char = kgdbdbgp_write_char,
52616+ .is_console = 1
52617+};
52618+
52619 static int kgdbdbgp_wait_time;
52620
52621 static int __init kgdbdbgp_parse_config(char *str)
52622@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52623 ptr++;
52624 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52625 }
52626- kgdb_register_io_module(&kgdbdbgp_io_ops);
52627- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52628+ if (early_dbgp_console.index != -1)
52629+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52630+ else
52631+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52632
52633 return 0;
52634 }
52635diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52636index 2b4c82d..06a8ee6 100644
52637--- a/drivers/usb/gadget/f_uac1.c
52638+++ b/drivers/usb/gadget/f_uac1.c
52639@@ -13,6 +13,7 @@
52640 #include <linux/kernel.h>
52641 #include <linux/device.h>
52642 #include <linux/atomic.h>
52643+#include <linux/module.h>
52644
52645 #include "u_uac1.h"
52646
52647diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52648index ad0aca8..8ff84865 100644
52649--- a/drivers/usb/gadget/u_serial.c
52650+++ b/drivers/usb/gadget/u_serial.c
52651@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52652 spin_lock_irq(&port->port_lock);
52653
52654 /* already open? Great. */
52655- if (port->port.count) {
52656+ if (atomic_read(&port->port.count)) {
52657 status = 0;
52658- port->port.count++;
52659+ atomic_inc(&port->port.count);
52660
52661 /* currently opening/closing? wait ... */
52662 } else if (port->openclose) {
52663@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52664 tty->driver_data = port;
52665 port->port.tty = tty;
52666
52667- port->port.count = 1;
52668+ atomic_set(&port->port.count, 1);
52669 port->openclose = false;
52670
52671 /* if connected, start the I/O stream */
52672@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52673
52674 spin_lock_irq(&port->port_lock);
52675
52676- if (port->port.count != 1) {
52677- if (port->port.count == 0)
52678+ if (atomic_read(&port->port.count) != 1) {
52679+ if (atomic_read(&port->port.count) == 0)
52680 WARN_ON(1);
52681 else
52682- --port->port.count;
52683+ atomic_dec(&port->port.count);
52684 goto exit;
52685 }
52686
52687@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52688 * and sleep if necessary
52689 */
52690 port->openclose = true;
52691- port->port.count = 0;
52692+ atomic_set(&port->port.count, 0);
52693
52694 gser = port->port_usb;
52695 if (gser && gser->disconnect)
52696@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52697 int cond;
52698
52699 spin_lock_irq(&port->port_lock);
52700- cond = (port->port.count == 0) && !port->openclose;
52701+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52702 spin_unlock_irq(&port->port_lock);
52703 return cond;
52704 }
52705@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52706 /* if it's already open, start I/O ... and notify the serial
52707 * protocol about open/close status (connect/disconnect).
52708 */
52709- if (port->port.count) {
52710+ if (atomic_read(&port->port.count)) {
52711 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52712 gs_start_io(port);
52713 if (gser->connect)
52714@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52715
52716 port->port_usb = NULL;
52717 gser->ioport = NULL;
52718- if (port->port.count > 0 || port->openclose) {
52719+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52720 wake_up_interruptible(&port->drain_wait);
52721 if (port->port.tty)
52722 tty_hangup(port->port.tty);
52723@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52724
52725 /* finally, free any unused/unusable I/O buffers */
52726 spin_lock_irqsave(&port->port_lock, flags);
52727- if (port->port.count == 0 && !port->openclose)
52728+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52729 gs_buf_free(&port->port_write_buf);
52730 gs_free_requests(gser->out, &port->read_pool, NULL);
52731 gs_free_requests(gser->out, &port->read_queue, NULL);
52732diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52733index 7a55fea..cc0ed4f 100644
52734--- a/drivers/usb/gadget/u_uac1.c
52735+++ b/drivers/usb/gadget/u_uac1.c
52736@@ -16,6 +16,7 @@
52737 #include <linux/ctype.h>
52738 #include <linux/random.h>
52739 #include <linux/syscalls.h>
52740+#include <linux/module.h>
52741
52742 #include "u_uac1.h"
52743
52744diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52745index 7ae0c4d..35521b7 100644
52746--- a/drivers/usb/host/ehci-hub.c
52747+++ b/drivers/usb/host/ehci-hub.c
52748@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52749 urb->transfer_flags = URB_DIR_IN;
52750 usb_get_urb(urb);
52751 atomic_inc(&urb->use_count);
52752- atomic_inc(&urb->dev->urbnum);
52753+ atomic_inc_unchecked(&urb->dev->urbnum);
52754 urb->setup_dma = dma_map_single(
52755 hcd->self.controller,
52756 urb->setup_packet,
52757@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52758 urb->status = -EINPROGRESS;
52759 usb_get_urb(urb);
52760 atomic_inc(&urb->use_count);
52761- atomic_inc(&urb->dev->urbnum);
52762+ atomic_inc_unchecked(&urb->dev->urbnum);
52763 retval = submit_single_step_set_feature(hcd, urb, 0);
52764 if (!retval && !wait_for_completion_timeout(&done,
52765 msecs_to_jiffies(2000))) {
52766diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52767index ba6a5d6..f88f7f3 100644
52768--- a/drivers/usb/misc/appledisplay.c
52769+++ b/drivers/usb/misc/appledisplay.c
52770@@ -83,7 +83,7 @@ struct appledisplay {
52771 spinlock_t lock;
52772 };
52773
52774-static atomic_t count_displays = ATOMIC_INIT(0);
52775+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52776 static struct workqueue_struct *wq;
52777
52778 static void appledisplay_complete(struct urb *urb)
52779@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52780
52781 /* Register backlight device */
52782 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52783- atomic_inc_return(&count_displays) - 1);
52784+ atomic_inc_return_unchecked(&count_displays) - 1);
52785 memset(&props, 0, sizeof(struct backlight_properties));
52786 props.type = BACKLIGHT_RAW;
52787 props.max_brightness = 0xff;
52788diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52789index 8d7fc48..01c4986 100644
52790--- a/drivers/usb/serial/console.c
52791+++ b/drivers/usb/serial/console.c
52792@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52793
52794 info->port = port;
52795
52796- ++port->port.count;
52797+ atomic_inc(&port->port.count);
52798 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52799 if (serial->type->set_termios) {
52800 /*
52801@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52802 }
52803 /* Now that any required fake tty operations are completed restore
52804 * the tty port count */
52805- --port->port.count;
52806+ atomic_dec(&port->port.count);
52807 /* The console is special in terms of closing the device so
52808 * indicate this port is now acting as a system console. */
52809 port->port.console = 1;
52810@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52811 free_tty:
52812 kfree(tty);
52813 reset_open_count:
52814- port->port.count = 0;
52815+ atomic_set(&port->port.count, 0);
52816 usb_autopm_put_interface(serial->interface);
52817 error_get_interface:
52818 usb_serial_put(serial);
52819@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52820 static void usb_console_write(struct console *co,
52821 const char *buf, unsigned count)
52822 {
52823- static struct usbcons_info *info = &usbcons_info;
52824+ struct usbcons_info *info = &usbcons_info;
52825 struct usb_serial_port *port = info->port;
52826 struct usb_serial *serial;
52827 int retval = -ENODEV;
52828diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52829index 75f70f0..d467e1a 100644
52830--- a/drivers/usb/storage/usb.h
52831+++ b/drivers/usb/storage/usb.h
52832@@ -63,7 +63,7 @@ struct us_unusual_dev {
52833 __u8 useProtocol;
52834 __u8 useTransport;
52835 int (*initFunction)(struct us_data *);
52836-};
52837+} __do_const;
52838
52839
52840 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52841diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52842index a2ef84b..aa7c2b8 100644
52843--- a/drivers/usb/wusbcore/wa-hc.h
52844+++ b/drivers/usb/wusbcore/wa-hc.h
52845@@ -225,7 +225,7 @@ struct wahc {
52846 spinlock_t xfer_list_lock;
52847 struct work_struct xfer_enqueue_work;
52848 struct work_struct xfer_error_work;
52849- atomic_t xfer_id_count;
52850+ atomic_unchecked_t xfer_id_count;
52851
52852 kernel_ulong_t quirks;
52853 };
52854@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52855 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52856 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52857 wa->dto_in_use = 0;
52858- atomic_set(&wa->xfer_id_count, 1);
52859+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52860 }
52861
52862 /**
52863diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52864index 3cd96e9..bd7c58d 100644
52865--- a/drivers/usb/wusbcore/wa-xfer.c
52866+++ b/drivers/usb/wusbcore/wa-xfer.c
52867@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52868 */
52869 static void wa_xfer_id_init(struct wa_xfer *xfer)
52870 {
52871- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52872+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52873 }
52874
52875 /* Return the xfer's ID. */
52876diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52877index 21271d8..45b55a0 100644
52878--- a/drivers/vfio/vfio.c
52879+++ b/drivers/vfio/vfio.c
52880@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52881 return 0;
52882
52883 /* TODO Prevent device auto probing */
52884- WARN("Device %s added to live group %d!\n", dev_name(dev),
52885+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52886 iommu_group_id(group->iommu_group));
52887
52888 return 0;
52889diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52890index 5174eba..451e6bc 100644
52891--- a/drivers/vhost/vringh.c
52892+++ b/drivers/vhost/vringh.c
52893@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52894 /* Userspace access helpers: in this case, addresses are really userspace. */
52895 static inline int getu16_user(u16 *val, const u16 *p)
52896 {
52897- return get_user(*val, (__force u16 __user *)p);
52898+ return get_user(*val, (u16 __force_user *)p);
52899 }
52900
52901 static inline int putu16_user(u16 *p, u16 val)
52902 {
52903- return put_user(val, (__force u16 __user *)p);
52904+ return put_user(val, (u16 __force_user *)p);
52905 }
52906
52907 static inline int copydesc_user(void *dst, const void *src, size_t len)
52908 {
52909- return copy_from_user(dst, (__force void __user *)src, len) ?
52910+ return copy_from_user(dst, (void __force_user *)src, len) ?
52911 -EFAULT : 0;
52912 }
52913
52914@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52915 const struct vring_used_elem *src,
52916 unsigned int num)
52917 {
52918- return copy_to_user((__force void __user *)dst, src,
52919+ return copy_to_user((void __force_user *)dst, src,
52920 sizeof(*dst) * num) ? -EFAULT : 0;
52921 }
52922
52923 static inline int xfer_from_user(void *src, void *dst, size_t len)
52924 {
52925- return copy_from_user(dst, (__force void __user *)src, len) ?
52926+ return copy_from_user(dst, (void __force_user *)src, len) ?
52927 -EFAULT : 0;
52928 }
52929
52930 static inline int xfer_to_user(void *dst, void *src, size_t len)
52931 {
52932- return copy_to_user((__force void __user *)dst, src, len) ?
52933+ return copy_to_user((void __force_user *)dst, src, len) ?
52934 -EFAULT : 0;
52935 }
52936
52937@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52938 vrh->last_used_idx = 0;
52939 vrh->vring.num = num;
52940 /* vring expects kernel addresses, but only used via accessors. */
52941- vrh->vring.desc = (__force struct vring_desc *)desc;
52942- vrh->vring.avail = (__force struct vring_avail *)avail;
52943- vrh->vring.used = (__force struct vring_used *)used;
52944+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52945+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52946+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52947 return 0;
52948 }
52949 EXPORT_SYMBOL(vringh_init_user);
52950@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52951
52952 static inline int putu16_kern(u16 *p, u16 val)
52953 {
52954- ACCESS_ONCE(*p) = val;
52955+ ACCESS_ONCE_RW(*p) = val;
52956 return 0;
52957 }
52958
52959diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52960index 1b0b233..6f34c2c 100644
52961--- a/drivers/video/arcfb.c
52962+++ b/drivers/video/arcfb.c
52963@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52964 return -ENOSPC;
52965
52966 err = 0;
52967- if ((count + p) > fbmemlength) {
52968+ if (count > (fbmemlength - p)) {
52969 count = fbmemlength - p;
52970 err = -ENOSPC;
52971 }
52972diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52973index 52108be..c7c110d 100644
52974--- a/drivers/video/aty/aty128fb.c
52975+++ b/drivers/video/aty/aty128fb.c
52976@@ -149,7 +149,7 @@ enum {
52977 };
52978
52979 /* Must match above enum */
52980-static char * const r128_family[] = {
52981+static const char * const r128_family[] = {
52982 "AGP",
52983 "PCI",
52984 "PRO AGP",
52985diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52986index 28fafbf..ae91651 100644
52987--- a/drivers/video/aty/atyfb_base.c
52988+++ b/drivers/video/aty/atyfb_base.c
52989@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52990 par->accel_flags = var->accel_flags; /* hack */
52991
52992 if (var->accel_flags) {
52993- info->fbops->fb_sync = atyfb_sync;
52994+ pax_open_kernel();
52995+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52996+ pax_close_kernel();
52997 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52998 } else {
52999- info->fbops->fb_sync = NULL;
53000+ pax_open_kernel();
53001+ *(void **)&info->fbops->fb_sync = NULL;
53002+ pax_close_kernel();
53003 info->flags |= FBINFO_HWACCEL_DISABLED;
53004 }
53005
53006diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
53007index 0fe02e2..ab01b26 100644
53008--- a/drivers/video/aty/mach64_cursor.c
53009+++ b/drivers/video/aty/mach64_cursor.c
53010@@ -8,6 +8,7 @@
53011 #include "../fb_draw.h"
53012
53013 #include <asm/io.h>
53014+#include <asm/pgtable.h>
53015
53016 #ifdef __sparc__
53017 #include <asm/fbio.h>
53018@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
53019 info->sprite.buf_align = 16; /* and 64 lines tall. */
53020 info->sprite.flags = FB_PIXMAP_IO;
53021
53022- info->fbops->fb_cursor = atyfb_cursor;
53023+ pax_open_kernel();
53024+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
53025+ pax_close_kernel();
53026
53027 return 0;
53028 }
53029diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
53030index 84a110a..96312c3 100644
53031--- a/drivers/video/backlight/kb3886_bl.c
53032+++ b/drivers/video/backlight/kb3886_bl.c
53033@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
53034 static unsigned long kb3886bl_flags;
53035 #define KB3886BL_SUSPENDED 0x01
53036
53037-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
53038+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
53039 {
53040 .ident = "Sahara Touch-iT",
53041 .matches = {
53042diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
53043index 900aa4e..6d49418 100644
53044--- a/drivers/video/fb_defio.c
53045+++ b/drivers/video/fb_defio.c
53046@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
53047
53048 BUG_ON(!fbdefio);
53049 mutex_init(&fbdefio->lock);
53050- info->fbops->fb_mmap = fb_deferred_io_mmap;
53051+ pax_open_kernel();
53052+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
53053+ pax_close_kernel();
53054 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
53055 INIT_LIST_HEAD(&fbdefio->pagelist);
53056 if (fbdefio->delay == 0) /* set a default of 1 s */
53057@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
53058 page->mapping = NULL;
53059 }
53060
53061- info->fbops->fb_mmap = NULL;
53062+ *(void **)&info->fbops->fb_mmap = NULL;
53063 mutex_destroy(&fbdefio->lock);
53064 }
53065 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
53066diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
53067index 7309ac7..be3c49c 100644
53068--- a/drivers/video/fbmem.c
53069+++ b/drivers/video/fbmem.c
53070@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
53071 image->dx += image->width + 8;
53072 }
53073 } else if (rotate == FB_ROTATE_UD) {
53074- for (x = 0; x < num && image->dx >= 0; x++) {
53075+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
53076 info->fbops->fb_imageblit(info, image);
53077 image->dx -= image->width + 8;
53078 }
53079@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
53080 image->dy += image->height + 8;
53081 }
53082 } else if (rotate == FB_ROTATE_CCW) {
53083- for (x = 0; x < num && image->dy >= 0; x++) {
53084+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
53085 info->fbops->fb_imageblit(info, image);
53086 image->dy -= image->height + 8;
53087 }
53088@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
53089 return -EFAULT;
53090 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
53091 return -EINVAL;
53092- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
53093+ if (con2fb.framebuffer >= FB_MAX)
53094 return -EINVAL;
53095 if (!registered_fb[con2fb.framebuffer])
53096 request_module("fb%d", con2fb.framebuffer);
53097@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
53098 __u32 data;
53099 int err;
53100
53101- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
53102+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
53103
53104 data = (__u32) (unsigned long) fix->smem_start;
53105 err |= put_user(data, &fix32->smem_start);
53106diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
53107index 130708f..cdac1a9 100644
53108--- a/drivers/video/hyperv_fb.c
53109+++ b/drivers/video/hyperv_fb.c
53110@@ -233,7 +233,7 @@ static uint screen_fb_size;
53111 static inline int synthvid_send(struct hv_device *hdev,
53112 struct synthvid_msg *msg)
53113 {
53114- static atomic64_t request_id = ATOMIC64_INIT(0);
53115+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
53116 int ret;
53117
53118 msg->pipe_hdr.type = PIPE_MSG_DATA;
53119@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
53120
53121 ret = vmbus_sendpacket(hdev->channel, msg,
53122 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
53123- atomic64_inc_return(&request_id),
53124+ atomic64_inc_return_unchecked(&request_id),
53125 VM_PKT_DATA_INBAND, 0);
53126
53127 if (ret)
53128diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
53129index 7672d2e..b56437f 100644
53130--- a/drivers/video/i810/i810_accel.c
53131+++ b/drivers/video/i810/i810_accel.c
53132@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
53133 }
53134 }
53135 printk("ringbuffer lockup!!!\n");
53136+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
53137 i810_report_error(mmio);
53138 par->dev_flags |= LOCKUP;
53139 info->pixmap.scan_align = 1;
53140diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53141index 3c14e43..2630570 100644
53142--- a/drivers/video/logo/logo_linux_clut224.ppm
53143+++ b/drivers/video/logo/logo_linux_clut224.ppm
53144@@ -2,1603 +2,1123 @@ P3
53145 # Standard 224-color Linux logo
53146 80 80
53147 255
53148- 0 0 0 0 0 0 0 0 0 0 0 0
53149- 0 0 0 0 0 0 0 0 0 0 0 0
53150- 0 0 0 0 0 0 0 0 0 0 0 0
53151- 0 0 0 0 0 0 0 0 0 0 0 0
53152- 0 0 0 0 0 0 0 0 0 0 0 0
53153- 0 0 0 0 0 0 0 0 0 0 0 0
53154- 0 0 0 0 0 0 0 0 0 0 0 0
53155- 0 0 0 0 0 0 0 0 0 0 0 0
53156- 0 0 0 0 0 0 0 0 0 0 0 0
53157- 6 6 6 6 6 6 10 10 10 10 10 10
53158- 10 10 10 6 6 6 6 6 6 6 6 6
53159- 0 0 0 0 0 0 0 0 0 0 0 0
53160- 0 0 0 0 0 0 0 0 0 0 0 0
53161- 0 0 0 0 0 0 0 0 0 0 0 0
53162- 0 0 0 0 0 0 0 0 0 0 0 0
53163- 0 0 0 0 0 0 0 0 0 0 0 0
53164- 0 0 0 0 0 0 0 0 0 0 0 0
53165- 0 0 0 0 0 0 0 0 0 0 0 0
53166- 0 0 0 0 0 0 0 0 0 0 0 0
53167- 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 6 6 6 10 10 10 14 14 14
53177- 22 22 22 26 26 26 30 30 30 34 34 34
53178- 30 30 30 30 30 30 26 26 26 18 18 18
53179- 14 14 14 10 10 10 6 6 6 0 0 0
53180- 0 0 0 0 0 0 0 0 0 0 0 0
53181- 0 0 0 0 0 0 0 0 0 0 0 0
53182- 0 0 0 0 0 0 0 0 0 0 0 0
53183- 0 0 0 0 0 0 0 0 0 0 0 0
53184- 0 0 0 0 0 0 0 0 0 0 0 0
53185- 0 0 0 0 0 0 0 0 0 0 0 0
53186- 0 0 0 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 1 0 0 1 0 0 0
53190- 0 0 0 0 0 0 0 0 0 0 0 0
53191- 0 0 0 0 0 0 0 0 0 0 0 0
53192- 0 0 0 0 0 0 0 0 0 0 0 0
53193- 0 0 0 0 0 0 0 0 0 0 0 0
53194- 0 0 0 0 0 0 0 0 0 0 0 0
53195- 0 0 0 0 0 0 0 0 0 0 0 0
53196- 6 6 6 14 14 14 26 26 26 42 42 42
53197- 54 54 54 66 66 66 78 78 78 78 78 78
53198- 78 78 78 74 74 74 66 66 66 54 54 54
53199- 42 42 42 26 26 26 18 18 18 10 10 10
53200- 6 6 6 0 0 0 0 0 0 0 0 0
53201- 0 0 0 0 0 0 0 0 0 0 0 0
53202- 0 0 0 0 0 0 0 0 0 0 0 0
53203- 0 0 0 0 0 0 0 0 0 0 0 0
53204- 0 0 0 0 0 0 0 0 0 0 0 0
53205- 0 0 0 0 0 0 0 0 0 0 0 0
53206- 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 1 0 0 0 0 0 0 0 0 0
53210- 0 0 0 0 0 0 0 0 0 0 0 0
53211- 0 0 0 0 0 0 0 0 0 0 0 0
53212- 0 0 0 0 0 0 0 0 0 0 0 0
53213- 0 0 0 0 0 0 0 0 0 0 0 0
53214- 0 0 0 0 0 0 0 0 0 0 0 0
53215- 0 0 0 0 0 0 0 0 0 10 10 10
53216- 22 22 22 42 42 42 66 66 66 86 86 86
53217- 66 66 66 38 38 38 38 38 38 22 22 22
53218- 26 26 26 34 34 34 54 54 54 66 66 66
53219- 86 86 86 70 70 70 46 46 46 26 26 26
53220- 14 14 14 6 6 6 0 0 0 0 0 0
53221- 0 0 0 0 0 0 0 0 0 0 0 0
53222- 0 0 0 0 0 0 0 0 0 0 0 0
53223- 0 0 0 0 0 0 0 0 0 0 0 0
53224- 0 0 0 0 0 0 0 0 0 0 0 0
53225- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
53230- 0 0 0 0 0 0 0 0 0 0 0 0
53231- 0 0 0 0 0 0 0 0 0 0 0 0
53232- 0 0 0 0 0 0 0 0 0 0 0 0
53233- 0 0 0 0 0 0 0 0 0 0 0 0
53234- 0 0 0 0 0 0 0 0 0 0 0 0
53235- 0 0 0 0 0 0 10 10 10 26 26 26
53236- 50 50 50 82 82 82 58 58 58 6 6 6
53237- 2 2 6 2 2 6 2 2 6 2 2 6
53238- 2 2 6 2 2 6 2 2 6 2 2 6
53239- 6 6 6 54 54 54 86 86 86 66 66 66
53240- 38 38 38 18 18 18 6 6 6 0 0 0
53241- 0 0 0 0 0 0 0 0 0 0 0 0
53242- 0 0 0 0 0 0 0 0 0 0 0 0
53243- 0 0 0 0 0 0 0 0 0 0 0 0
53244- 0 0 0 0 0 0 0 0 0 0 0 0
53245- 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
53256- 78 78 78 34 34 34 2 2 6 2 2 6
53257- 2 2 6 2 2 6 2 2 6 2 2 6
53258- 2 2 6 2 2 6 2 2 6 2 2 6
53259- 2 2 6 2 2 6 6 6 6 70 70 70
53260- 78 78 78 46 46 46 22 22 22 6 6 6
53261- 0 0 0 0 0 0 0 0 0 0 0 0
53262- 0 0 0 0 0 0 0 0 0 0 0 0
53263- 0 0 0 0 0 0 0 0 0 0 0 0
53264- 0 0 0 0 0 0 0 0 0 0 0 0
53265- 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
53270- 0 0 0 0 0 0 0 0 0 0 0 0
53271- 0 0 0 0 0 0 0 0 0 0 0 0
53272- 0 0 0 0 0 0 0 0 0 0 0 0
53273- 0 0 0 0 0 0 0 0 0 0 0 0
53274- 0 0 0 0 0 0 0 0 0 0 0 0
53275- 6 6 6 18 18 18 42 42 42 82 82 82
53276- 26 26 26 2 2 6 2 2 6 2 2 6
53277- 2 2 6 2 2 6 2 2 6 2 2 6
53278- 2 2 6 2 2 6 2 2 6 14 14 14
53279- 46 46 46 34 34 34 6 6 6 2 2 6
53280- 42 42 42 78 78 78 42 42 42 18 18 18
53281- 6 6 6 0 0 0 0 0 0 0 0 0
53282- 0 0 0 0 0 0 0 0 0 0 0 0
53283- 0 0 0 0 0 0 0 0 0 0 0 0
53284- 0 0 0 0 0 0 0 0 0 0 0 0
53285- 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 1 0 0 0
53290- 0 0 0 0 0 0 0 0 0 0 0 0
53291- 0 0 0 0 0 0 0 0 0 0 0 0
53292- 0 0 0 0 0 0 0 0 0 0 0 0
53293- 0 0 0 0 0 0 0 0 0 0 0 0
53294- 0 0 0 0 0 0 0 0 0 0 0 0
53295- 10 10 10 30 30 30 66 66 66 58 58 58
53296- 2 2 6 2 2 6 2 2 6 2 2 6
53297- 2 2 6 2 2 6 2 2 6 2 2 6
53298- 2 2 6 2 2 6 2 2 6 26 26 26
53299- 86 86 86 101 101 101 46 46 46 10 10 10
53300- 2 2 6 58 58 58 70 70 70 34 34 34
53301- 10 10 10 0 0 0 0 0 0 0 0 0
53302- 0 0 0 0 0 0 0 0 0 0 0 0
53303- 0 0 0 0 0 0 0 0 0 0 0 0
53304- 0 0 0 0 0 0 0 0 0 0 0 0
53305- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
53310- 0 0 0 0 0 0 0 0 0 0 0 0
53311- 0 0 0 0 0 0 0 0 0 0 0 0
53312- 0 0 0 0 0 0 0 0 0 0 0 0
53313- 0 0 0 0 0 0 0 0 0 0 0 0
53314- 0 0 0 0 0 0 0 0 0 0 0 0
53315- 14 14 14 42 42 42 86 86 86 10 10 10
53316- 2 2 6 2 2 6 2 2 6 2 2 6
53317- 2 2 6 2 2 6 2 2 6 2 2 6
53318- 2 2 6 2 2 6 2 2 6 30 30 30
53319- 94 94 94 94 94 94 58 58 58 26 26 26
53320- 2 2 6 6 6 6 78 78 78 54 54 54
53321- 22 22 22 6 6 6 0 0 0 0 0 0
53322- 0 0 0 0 0 0 0 0 0 0 0 0
53323- 0 0 0 0 0 0 0 0 0 0 0 0
53324- 0 0 0 0 0 0 0 0 0 0 0 0
53325- 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0
53334- 0 0 0 0 0 0 0 0 0 6 6 6
53335- 22 22 22 62 62 62 62 62 62 2 2 6
53336- 2 2 6 2 2 6 2 2 6 2 2 6
53337- 2 2 6 2 2 6 2 2 6 2 2 6
53338- 2 2 6 2 2 6 2 2 6 26 26 26
53339- 54 54 54 38 38 38 18 18 18 10 10 10
53340- 2 2 6 2 2 6 34 34 34 82 82 82
53341- 38 38 38 14 14 14 0 0 0 0 0 0
53342- 0 0 0 0 0 0 0 0 0 0 0 0
53343- 0 0 0 0 0 0 0 0 0 0 0 0
53344- 0 0 0 0 0 0 0 0 0 0 0 0
53345- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 0
53350- 0 0 0 0 0 0 0 0 0 0 0 0
53351- 0 0 0 0 0 0 0 0 0 0 0 0
53352- 0 0 0 0 0 0 0 0 0 0 0 0
53353- 0 0 0 0 0 0 0 0 0 0 0 0
53354- 0 0 0 0 0 0 0 0 0 6 6 6
53355- 30 30 30 78 78 78 30 30 30 2 2 6
53356- 2 2 6 2 2 6 2 2 6 2 2 6
53357- 2 2 6 2 2 6 2 2 6 2 2 6
53358- 2 2 6 2 2 6 2 2 6 10 10 10
53359- 10 10 10 2 2 6 2 2 6 2 2 6
53360- 2 2 6 2 2 6 2 2 6 78 78 78
53361- 50 50 50 18 18 18 6 6 6 0 0 0
53362- 0 0 0 0 0 0 0 0 0 0 0 0
53363- 0 0 0 0 0 0 0 0 0 0 0 0
53364- 0 0 0 0 0 0 0 0 0 0 0 0
53365- 0 0 0 0 0 0 0 0 0 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 1 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 10 10 10
53375- 38 38 38 86 86 86 14 14 14 2 2 6
53376- 2 2 6 2 2 6 2 2 6 2 2 6
53377- 2 2 6 2 2 6 2 2 6 2 2 6
53378- 2 2 6 2 2 6 2 2 6 2 2 6
53379- 2 2 6 2 2 6 2 2 6 2 2 6
53380- 2 2 6 2 2 6 2 2 6 54 54 54
53381- 66 66 66 26 26 26 6 6 6 0 0 0
53382- 0 0 0 0 0 0 0 0 0 0 0 0
53383- 0 0 0 0 0 0 0 0 0 0 0 0
53384- 0 0 0 0 0 0 0 0 0 0 0 0
53385- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 0
53390- 0 0 0 0 0 0 0 0 0 0 0 0
53391- 0 0 0 0 0 0 0 0 0 0 0 0
53392- 0 0 0 0 0 0 0 0 0 0 0 0
53393- 0 0 0 0 0 0 0 0 0 0 0 0
53394- 0 0 0 0 0 0 0 0 0 14 14 14
53395- 42 42 42 82 82 82 2 2 6 2 2 6
53396- 2 2 6 6 6 6 10 10 10 2 2 6
53397- 2 2 6 2 2 6 2 2 6 2 2 6
53398- 2 2 6 2 2 6 2 2 6 6 6 6
53399- 14 14 14 10 10 10 2 2 6 2 2 6
53400- 2 2 6 2 2 6 2 2 6 18 18 18
53401- 82 82 82 34 34 34 10 10 10 0 0 0
53402- 0 0 0 0 0 0 0 0 0 0 0 0
53403- 0 0 0 0 0 0 0 0 0 0 0 0
53404- 0 0 0 0 0 0 0 0 0 0 0 0
53405- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 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 14 14 14
53415- 46 46 46 86 86 86 2 2 6 2 2 6
53416- 6 6 6 6 6 6 22 22 22 34 34 34
53417- 6 6 6 2 2 6 2 2 6 2 2 6
53418- 2 2 6 2 2 6 18 18 18 34 34 34
53419- 10 10 10 50 50 50 22 22 22 2 2 6
53420- 2 2 6 2 2 6 2 2 6 10 10 10
53421- 86 86 86 42 42 42 14 14 14 0 0 0
53422- 0 0 0 0 0 0 0 0 0 0 0 0
53423- 0 0 0 0 0 0 0 0 0 0 0 0
53424- 0 0 0 0 0 0 0 0 0 0 0 0
53425- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 0 0 0
53430- 0 0 0 0 0 0 0 0 0 0 0 0
53431- 0 0 0 0 0 0 0 0 0 0 0 0
53432- 0 0 0 0 0 0 0 0 0 0 0 0
53433- 0 0 0 0 0 0 0 0 0 0 0 0
53434- 0 0 0 0 0 0 0 0 0 14 14 14
53435- 46 46 46 86 86 86 2 2 6 2 2 6
53436- 38 38 38 116 116 116 94 94 94 22 22 22
53437- 22 22 22 2 2 6 2 2 6 2 2 6
53438- 14 14 14 86 86 86 138 138 138 162 162 162
53439-154 154 154 38 38 38 26 26 26 6 6 6
53440- 2 2 6 2 2 6 2 2 6 2 2 6
53441- 86 86 86 46 46 46 14 14 14 0 0 0
53442- 0 0 0 0 0 0 0 0 0 0 0 0
53443- 0 0 0 0 0 0 0 0 0 0 0 0
53444- 0 0 0 0 0 0 0 0 0 0 0 0
53445- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
53453- 0 0 0 0 0 0 0 0 0 0 0 0
53454- 0 0 0 0 0 0 0 0 0 14 14 14
53455- 46 46 46 86 86 86 2 2 6 14 14 14
53456-134 134 134 198 198 198 195 195 195 116 116 116
53457- 10 10 10 2 2 6 2 2 6 6 6 6
53458-101 98 89 187 187 187 210 210 210 218 218 218
53459-214 214 214 134 134 134 14 14 14 6 6 6
53460- 2 2 6 2 2 6 2 2 6 2 2 6
53461- 86 86 86 50 50 50 18 18 18 6 6 6
53462- 0 0 0 0 0 0 0 0 0 0 0 0
53463- 0 0 0 0 0 0 0 0 0 0 0 0
53464- 0 0 0 0 0 0 0 0 0 0 0 0
53465- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0
53469- 0 0 1 0 0 1 0 0 1 0 0 0
53470- 0 0 0 0 0 0 0 0 0 0 0 0
53471- 0 0 0 0 0 0 0 0 0 0 0 0
53472- 0 0 0 0 0 0 0 0 0 0 0 0
53473- 0 0 0 0 0 0 0 0 0 0 0 0
53474- 0 0 0 0 0 0 0 0 0 14 14 14
53475- 46 46 46 86 86 86 2 2 6 54 54 54
53476-218 218 218 195 195 195 226 226 226 246 246 246
53477- 58 58 58 2 2 6 2 2 6 30 30 30
53478-210 210 210 253 253 253 174 174 174 123 123 123
53479-221 221 221 234 234 234 74 74 74 2 2 6
53480- 2 2 6 2 2 6 2 2 6 2 2 6
53481- 70 70 70 58 58 58 22 22 22 6 6 6
53482- 0 0 0 0 0 0 0 0 0 0 0 0
53483- 0 0 0 0 0 0 0 0 0 0 0 0
53484- 0 0 0 0 0 0 0 0 0 0 0 0
53485- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
53495- 46 46 46 82 82 82 2 2 6 106 106 106
53496-170 170 170 26 26 26 86 86 86 226 226 226
53497-123 123 123 10 10 10 14 14 14 46 46 46
53498-231 231 231 190 190 190 6 6 6 70 70 70
53499- 90 90 90 238 238 238 158 158 158 2 2 6
53500- 2 2 6 2 2 6 2 2 6 2 2 6
53501- 70 70 70 58 58 58 22 22 22 6 6 6
53502- 0 0 0 0 0 0 0 0 0 0 0 0
53503- 0 0 0 0 0 0 0 0 0 0 0 0
53504- 0 0 0 0 0 0 0 0 0 0 0 0
53505- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0
53509- 0 0 1 0 0 1 0 0 1 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 14 14 14
53515- 42 42 42 86 86 86 6 6 6 116 116 116
53516-106 106 106 6 6 6 70 70 70 149 149 149
53517-128 128 128 18 18 18 38 38 38 54 54 54
53518-221 221 221 106 106 106 2 2 6 14 14 14
53519- 46 46 46 190 190 190 198 198 198 2 2 6
53520- 2 2 6 2 2 6 2 2 6 2 2 6
53521- 74 74 74 62 62 62 22 22 22 6 6 6
53522- 0 0 0 0 0 0 0 0 0 0 0 0
53523- 0 0 0 0 0 0 0 0 0 0 0 0
53524- 0 0 0 0 0 0 0 0 0 0 0 0
53525- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0
53529- 0 0 1 0 0 0 0 0 1 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 14 14 14
53535- 42 42 42 94 94 94 14 14 14 101 101 101
53536-128 128 128 2 2 6 18 18 18 116 116 116
53537-118 98 46 121 92 8 121 92 8 98 78 10
53538-162 162 162 106 106 106 2 2 6 2 2 6
53539- 2 2 6 195 195 195 195 195 195 6 6 6
53540- 2 2 6 2 2 6 2 2 6 2 2 6
53541- 74 74 74 62 62 62 22 22 22 6 6 6
53542- 0 0 0 0 0 0 0 0 0 0 0 0
53543- 0 0 0 0 0 0 0 0 0 0 0 0
53544- 0 0 0 0 0 0 0 0 0 0 0 0
53545- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1
53549- 0 0 1 0 0 0 0 0 1 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 10 10 10
53555- 38 38 38 90 90 90 14 14 14 58 58 58
53556-210 210 210 26 26 26 54 38 6 154 114 10
53557-226 170 11 236 186 11 225 175 15 184 144 12
53558-215 174 15 175 146 61 37 26 9 2 2 6
53559- 70 70 70 246 246 246 138 138 138 2 2 6
53560- 2 2 6 2 2 6 2 2 6 2 2 6
53561- 70 70 70 66 66 66 26 26 26 6 6 6
53562- 0 0 0 0 0 0 0 0 0 0 0 0
53563- 0 0 0 0 0 0 0 0 0 0 0 0
53564- 0 0 0 0 0 0 0 0 0 0 0 0
53565- 0 0 0 0 0 0 0 0 0 0 0 0
53566- 0 0 0 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 10 10 10
53575- 38 38 38 86 86 86 14 14 14 10 10 10
53576-195 195 195 188 164 115 192 133 9 225 175 15
53577-239 182 13 234 190 10 232 195 16 232 200 30
53578-245 207 45 241 208 19 232 195 16 184 144 12
53579-218 194 134 211 206 186 42 42 42 2 2 6
53580- 2 2 6 2 2 6 2 2 6 2 2 6
53581- 50 50 50 74 74 74 30 30 30 6 6 6
53582- 0 0 0 0 0 0 0 0 0 0 0 0
53583- 0 0 0 0 0 0 0 0 0 0 0 0
53584- 0 0 0 0 0 0 0 0 0 0 0 0
53585- 0 0 0 0 0 0 0 0 0 0 0 0
53586- 0 0 0 0 0 0 0 0 0 0 0 0
53587- 0 0 0 0 0 0 0 0 0 0 0 0
53588- 0 0 0 0 0 0 0 0 0 0 0 0
53589- 0 0 0 0 0 0 0 0 0 0 0 0
53590- 0 0 0 0 0 0 0 0 0 0 0 0
53591- 0 0 0 0 0 0 0 0 0 0 0 0
53592- 0 0 0 0 0 0 0 0 0 0 0 0
53593- 0 0 0 0 0 0 0 0 0 0 0 0
53594- 0 0 0 0 0 0 0 0 0 10 10 10
53595- 34 34 34 86 86 86 14 14 14 2 2 6
53596-121 87 25 192 133 9 219 162 10 239 182 13
53597-236 186 11 232 195 16 241 208 19 244 214 54
53598-246 218 60 246 218 38 246 215 20 241 208 19
53599-241 208 19 226 184 13 121 87 25 2 2 6
53600- 2 2 6 2 2 6 2 2 6 2 2 6
53601- 50 50 50 82 82 82 34 34 34 10 10 10
53602- 0 0 0 0 0 0 0 0 0 0 0 0
53603- 0 0 0 0 0 0 0 0 0 0 0 0
53604- 0 0 0 0 0 0 0 0 0 0 0 0
53605- 0 0 0 0 0 0 0 0 0 0 0 0
53606- 0 0 0 0 0 0 0 0 0 0 0 0
53607- 0 0 0 0 0 0 0 0 0 0 0 0
53608- 0 0 0 0 0 0 0 0 0 0 0 0
53609- 0 0 0 0 0 0 0 0 0 0 0 0
53610- 0 0 0 0 0 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 10 10 10
53615- 34 34 34 82 82 82 30 30 30 61 42 6
53616-180 123 7 206 145 10 230 174 11 239 182 13
53617-234 190 10 238 202 15 241 208 19 246 218 74
53618-246 218 38 246 215 20 246 215 20 246 215 20
53619-226 184 13 215 174 15 184 144 12 6 6 6
53620- 2 2 6 2 2 6 2 2 6 2 2 6
53621- 26 26 26 94 94 94 42 42 42 14 14 14
53622- 0 0 0 0 0 0 0 0 0 0 0 0
53623- 0 0 0 0 0 0 0 0 0 0 0 0
53624- 0 0 0 0 0 0 0 0 0 0 0 0
53625- 0 0 0 0 0 0 0 0 0 0 0 0
53626- 0 0 0 0 0 0 0 0 0 0 0 0
53627- 0 0 0 0 0 0 0 0 0 0 0 0
53628- 0 0 0 0 0 0 0 0 0 0 0 0
53629- 0 0 0 0 0 0 0 0 0 0 0 0
53630- 0 0 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 10 10 10
53635- 30 30 30 78 78 78 50 50 50 104 69 6
53636-192 133 9 216 158 10 236 178 12 236 186 11
53637-232 195 16 241 208 19 244 214 54 245 215 43
53638-246 215 20 246 215 20 241 208 19 198 155 10
53639-200 144 11 216 158 10 156 118 10 2 2 6
53640- 2 2 6 2 2 6 2 2 6 2 2 6
53641- 6 6 6 90 90 90 54 54 54 18 18 18
53642- 6 6 6 0 0 0 0 0 0 0 0 0
53643- 0 0 0 0 0 0 0 0 0 0 0 0
53644- 0 0 0 0 0 0 0 0 0 0 0 0
53645- 0 0 0 0 0 0 0 0 0 0 0 0
53646- 0 0 0 0 0 0 0 0 0 0 0 0
53647- 0 0 0 0 0 0 0 0 0 0 0 0
53648- 0 0 0 0 0 0 0 0 0 0 0 0
53649- 0 0 0 0 0 0 0 0 0 0 0 0
53650- 0 0 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 10 10 10
53655- 30 30 30 78 78 78 46 46 46 22 22 22
53656-137 92 6 210 162 10 239 182 13 238 190 10
53657-238 202 15 241 208 19 246 215 20 246 215 20
53658-241 208 19 203 166 17 185 133 11 210 150 10
53659-216 158 10 210 150 10 102 78 10 2 2 6
53660- 6 6 6 54 54 54 14 14 14 2 2 6
53661- 2 2 6 62 62 62 74 74 74 30 30 30
53662- 10 10 10 0 0 0 0 0 0 0 0 0
53663- 0 0 0 0 0 0 0 0 0 0 0 0
53664- 0 0 0 0 0 0 0 0 0 0 0 0
53665- 0 0 0 0 0 0 0 0 0 0 0 0
53666- 0 0 0 0 0 0 0 0 0 0 0 0
53667- 0 0 0 0 0 0 0 0 0 0 0 0
53668- 0 0 0 0 0 0 0 0 0 0 0 0
53669- 0 0 0 0 0 0 0 0 0 0 0 0
53670- 0 0 0 0 0 0 0 0 0 0 0 0
53671- 0 0 0 0 0 0 0 0 0 0 0 0
53672- 0 0 0 0 0 0 0 0 0 0 0 0
53673- 0 0 0 0 0 0 0 0 0 0 0 0
53674- 0 0 0 0 0 0 0 0 0 10 10 10
53675- 34 34 34 78 78 78 50 50 50 6 6 6
53676- 94 70 30 139 102 15 190 146 13 226 184 13
53677-232 200 30 232 195 16 215 174 15 190 146 13
53678-168 122 10 192 133 9 210 150 10 213 154 11
53679-202 150 34 182 157 106 101 98 89 2 2 6
53680- 2 2 6 78 78 78 116 116 116 58 58 58
53681- 2 2 6 22 22 22 90 90 90 46 46 46
53682- 18 18 18 6 6 6 0 0 0 0 0 0
53683- 0 0 0 0 0 0 0 0 0 0 0 0
53684- 0 0 0 0 0 0 0 0 0 0 0 0
53685- 0 0 0 0 0 0 0 0 0 0 0 0
53686- 0 0 0 0 0 0 0 0 0 0 0 0
53687- 0 0 0 0 0 0 0 0 0 0 0 0
53688- 0 0 0 0 0 0 0 0 0 0 0 0
53689- 0 0 0 0 0 0 0 0 0 0 0 0
53690- 0 0 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 10 10 10
53695- 38 38 38 86 86 86 50 50 50 6 6 6
53696-128 128 128 174 154 114 156 107 11 168 122 10
53697-198 155 10 184 144 12 197 138 11 200 144 11
53698-206 145 10 206 145 10 197 138 11 188 164 115
53699-195 195 195 198 198 198 174 174 174 14 14 14
53700- 2 2 6 22 22 22 116 116 116 116 116 116
53701- 22 22 22 2 2 6 74 74 74 70 70 70
53702- 30 30 30 10 10 10 0 0 0 0 0 0
53703- 0 0 0 0 0 0 0 0 0 0 0 0
53704- 0 0 0 0 0 0 0 0 0 0 0 0
53705- 0 0 0 0 0 0 0 0 0 0 0 0
53706- 0 0 0 0 0 0 0 0 0 0 0 0
53707- 0 0 0 0 0 0 0 0 0 0 0 0
53708- 0 0 0 0 0 0 0 0 0 0 0 0
53709- 0 0 0 0 0 0 0 0 0 0 0 0
53710- 0 0 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 6 6 6 18 18 18
53715- 50 50 50 101 101 101 26 26 26 10 10 10
53716-138 138 138 190 190 190 174 154 114 156 107 11
53717-197 138 11 200 144 11 197 138 11 192 133 9
53718-180 123 7 190 142 34 190 178 144 187 187 187
53719-202 202 202 221 221 221 214 214 214 66 66 66
53720- 2 2 6 2 2 6 50 50 50 62 62 62
53721- 6 6 6 2 2 6 10 10 10 90 90 90
53722- 50 50 50 18 18 18 6 6 6 0 0 0
53723- 0 0 0 0 0 0 0 0 0 0 0 0
53724- 0 0 0 0 0 0 0 0 0 0 0 0
53725- 0 0 0 0 0 0 0 0 0 0 0 0
53726- 0 0 0 0 0 0 0 0 0 0 0 0
53727- 0 0 0 0 0 0 0 0 0 0 0 0
53728- 0 0 0 0 0 0 0 0 0 0 0 0
53729- 0 0 0 0 0 0 0 0 0 0 0 0
53730- 0 0 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 10 10 10 34 34 34
53735- 74 74 74 74 74 74 2 2 6 6 6 6
53736-144 144 144 198 198 198 190 190 190 178 166 146
53737-154 121 60 156 107 11 156 107 11 168 124 44
53738-174 154 114 187 187 187 190 190 190 210 210 210
53739-246 246 246 253 253 253 253 253 253 182 182 182
53740- 6 6 6 2 2 6 2 2 6 2 2 6
53741- 2 2 6 2 2 6 2 2 6 62 62 62
53742- 74 74 74 34 34 34 14 14 14 0 0 0
53743- 0 0 0 0 0 0 0 0 0 0 0 0
53744- 0 0 0 0 0 0 0 0 0 0 0 0
53745- 0 0 0 0 0 0 0 0 0 0 0 0
53746- 0 0 0 0 0 0 0 0 0 0 0 0
53747- 0 0 0 0 0 0 0 0 0 0 0 0
53748- 0 0 0 0 0 0 0 0 0 0 0 0
53749- 0 0 0 0 0 0 0 0 0 0 0 0
53750- 0 0 0 0 0 0 0 0 0 0 0 0
53751- 0 0 0 0 0 0 0 0 0 0 0 0
53752- 0 0 0 0 0 0 0 0 0 0 0 0
53753- 0 0 0 0 0 0 0 0 0 0 0 0
53754- 0 0 0 10 10 10 22 22 22 54 54 54
53755- 94 94 94 18 18 18 2 2 6 46 46 46
53756-234 234 234 221 221 221 190 190 190 190 190 190
53757-190 190 190 187 187 187 187 187 187 190 190 190
53758-190 190 190 195 195 195 214 214 214 242 242 242
53759-253 253 253 253 253 253 253 253 253 253 253 253
53760- 82 82 82 2 2 6 2 2 6 2 2 6
53761- 2 2 6 2 2 6 2 2 6 14 14 14
53762- 86 86 86 54 54 54 22 22 22 6 6 6
53763- 0 0 0 0 0 0 0 0 0 0 0 0
53764- 0 0 0 0 0 0 0 0 0 0 0 0
53765- 0 0 0 0 0 0 0 0 0 0 0 0
53766- 0 0 0 0 0 0 0 0 0 0 0 0
53767- 0 0 0 0 0 0 0 0 0 0 0 0
53768- 0 0 0 0 0 0 0 0 0 0 0 0
53769- 0 0 0 0 0 0 0 0 0 0 0 0
53770- 0 0 0 0 0 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- 6 6 6 18 18 18 46 46 46 90 90 90
53775- 46 46 46 18 18 18 6 6 6 182 182 182
53776-253 253 253 246 246 246 206 206 206 190 190 190
53777-190 190 190 190 190 190 190 190 190 190 190 190
53778-206 206 206 231 231 231 250 250 250 253 253 253
53779-253 253 253 253 253 253 253 253 253 253 253 253
53780-202 202 202 14 14 14 2 2 6 2 2 6
53781- 2 2 6 2 2 6 2 2 6 2 2 6
53782- 42 42 42 86 86 86 42 42 42 18 18 18
53783- 6 6 6 0 0 0 0 0 0 0 0 0
53784- 0 0 0 0 0 0 0 0 0 0 0 0
53785- 0 0 0 0 0 0 0 0 0 0 0 0
53786- 0 0 0 0 0 0 0 0 0 0 0 0
53787- 0 0 0 0 0 0 0 0 0 0 0 0
53788- 0 0 0 0 0 0 0 0 0 0 0 0
53789- 0 0 0 0 0 0 0 0 0 0 0 0
53790- 0 0 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 6 6 6
53794- 14 14 14 38 38 38 74 74 74 66 66 66
53795- 2 2 6 6 6 6 90 90 90 250 250 250
53796-253 253 253 253 253 253 238 238 238 198 198 198
53797-190 190 190 190 190 190 195 195 195 221 221 221
53798-246 246 246 253 253 253 253 253 253 253 253 253
53799-253 253 253 253 253 253 253 253 253 253 253 253
53800-253 253 253 82 82 82 2 2 6 2 2 6
53801- 2 2 6 2 2 6 2 2 6 2 2 6
53802- 2 2 6 78 78 78 70 70 70 34 34 34
53803- 14 14 14 6 6 6 0 0 0 0 0 0
53804- 0 0 0 0 0 0 0 0 0 0 0 0
53805- 0 0 0 0 0 0 0 0 0 0 0 0
53806- 0 0 0 0 0 0 0 0 0 0 0 0
53807- 0 0 0 0 0 0 0 0 0 0 0 0
53808- 0 0 0 0 0 0 0 0 0 0 0 0
53809- 0 0 0 0 0 0 0 0 0 0 0 0
53810- 0 0 0 0 0 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 14 14 14
53814- 34 34 34 66 66 66 78 78 78 6 6 6
53815- 2 2 6 18 18 18 218 218 218 253 253 253
53816-253 253 253 253 253 253 253 253 253 246 246 246
53817-226 226 226 231 231 231 246 246 246 253 253 253
53818-253 253 253 253 253 253 253 253 253 253 253 253
53819-253 253 253 253 253 253 253 253 253 253 253 253
53820-253 253 253 178 178 178 2 2 6 2 2 6
53821- 2 2 6 2 2 6 2 2 6 2 2 6
53822- 2 2 6 18 18 18 90 90 90 62 62 62
53823- 30 30 30 10 10 10 0 0 0 0 0 0
53824- 0 0 0 0 0 0 0 0 0 0 0 0
53825- 0 0 0 0 0 0 0 0 0 0 0 0
53826- 0 0 0 0 0 0 0 0 0 0 0 0
53827- 0 0 0 0 0 0 0 0 0 0 0 0
53828- 0 0 0 0 0 0 0 0 0 0 0 0
53829- 0 0 0 0 0 0 0 0 0 0 0 0
53830- 0 0 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 10 10 10 26 26 26
53834- 58 58 58 90 90 90 18 18 18 2 2 6
53835- 2 2 6 110 110 110 253 253 253 253 253 253
53836-253 253 253 253 253 253 253 253 253 253 253 253
53837-250 250 250 253 253 253 253 253 253 253 253 253
53838-253 253 253 253 253 253 253 253 253 253 253 253
53839-253 253 253 253 253 253 253 253 253 253 253 253
53840-253 253 253 231 231 231 18 18 18 2 2 6
53841- 2 2 6 2 2 6 2 2 6 2 2 6
53842- 2 2 6 2 2 6 18 18 18 94 94 94
53843- 54 54 54 26 26 26 10 10 10 0 0 0
53844- 0 0 0 0 0 0 0 0 0 0 0 0
53845- 0 0 0 0 0 0 0 0 0 0 0 0
53846- 0 0 0 0 0 0 0 0 0 0 0 0
53847- 0 0 0 0 0 0 0 0 0 0 0 0
53848- 0 0 0 0 0 0 0 0 0 0 0 0
53849- 0 0 0 0 0 0 0 0 0 0 0 0
53850- 0 0 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 6 6 6 22 22 22 50 50 50
53854- 90 90 90 26 26 26 2 2 6 2 2 6
53855- 14 14 14 195 195 195 250 250 250 253 253 253
53856-253 253 253 253 253 253 253 253 253 253 253 253
53857-253 253 253 253 253 253 253 253 253 253 253 253
53858-253 253 253 253 253 253 253 253 253 253 253 253
53859-253 253 253 253 253 253 253 253 253 253 253 253
53860-250 250 250 242 242 242 54 54 54 2 2 6
53861- 2 2 6 2 2 6 2 2 6 2 2 6
53862- 2 2 6 2 2 6 2 2 6 38 38 38
53863- 86 86 86 50 50 50 22 22 22 6 6 6
53864- 0 0 0 0 0 0 0 0 0 0 0 0
53865- 0 0 0 0 0 0 0 0 0 0 0 0
53866- 0 0 0 0 0 0 0 0 0 0 0 0
53867- 0 0 0 0 0 0 0 0 0 0 0 0
53868- 0 0 0 0 0 0 0 0 0 0 0 0
53869- 0 0 0 0 0 0 0 0 0 0 0 0
53870- 0 0 0 0 0 0 0 0 0 0 0 0
53871- 0 0 0 0 0 0 0 0 0 0 0 0
53872- 0 0 0 0 0 0 0 0 0 0 0 0
53873- 6 6 6 14 14 14 38 38 38 82 82 82
53874- 34 34 34 2 2 6 2 2 6 2 2 6
53875- 42 42 42 195 195 195 246 246 246 253 253 253
53876-253 253 253 253 253 253 253 253 253 250 250 250
53877-242 242 242 242 242 242 250 250 250 253 253 253
53878-253 253 253 253 253 253 253 253 253 253 253 253
53879-253 253 253 250 250 250 246 246 246 238 238 238
53880-226 226 226 231 231 231 101 101 101 6 6 6
53881- 2 2 6 2 2 6 2 2 6 2 2 6
53882- 2 2 6 2 2 6 2 2 6 2 2 6
53883- 38 38 38 82 82 82 42 42 42 14 14 14
53884- 6 6 6 0 0 0 0 0 0 0 0 0
53885- 0 0 0 0 0 0 0 0 0 0 0 0
53886- 0 0 0 0 0 0 0 0 0 0 0 0
53887- 0 0 0 0 0 0 0 0 0 0 0 0
53888- 0 0 0 0 0 0 0 0 0 0 0 0
53889- 0 0 0 0 0 0 0 0 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- 10 10 10 26 26 26 62 62 62 66 66 66
53894- 2 2 6 2 2 6 2 2 6 6 6 6
53895- 70 70 70 170 170 170 206 206 206 234 234 234
53896-246 246 246 250 250 250 250 250 250 238 238 238
53897-226 226 226 231 231 231 238 238 238 250 250 250
53898-250 250 250 250 250 250 246 246 246 231 231 231
53899-214 214 214 206 206 206 202 202 202 202 202 202
53900-198 198 198 202 202 202 182 182 182 18 18 18
53901- 2 2 6 2 2 6 2 2 6 2 2 6
53902- 2 2 6 2 2 6 2 2 6 2 2 6
53903- 2 2 6 62 62 62 66 66 66 30 30 30
53904- 10 10 10 0 0 0 0 0 0 0 0 0
53905- 0 0 0 0 0 0 0 0 0 0 0 0
53906- 0 0 0 0 0 0 0 0 0 0 0 0
53907- 0 0 0 0 0 0 0 0 0 0 0 0
53908- 0 0 0 0 0 0 0 0 0 0 0 0
53909- 0 0 0 0 0 0 0 0 0 0 0 0
53910- 0 0 0 0 0 0 0 0 0 0 0 0
53911- 0 0 0 0 0 0 0 0 0 0 0 0
53912- 0 0 0 0 0 0 0 0 0 0 0 0
53913- 14 14 14 42 42 42 82 82 82 18 18 18
53914- 2 2 6 2 2 6 2 2 6 10 10 10
53915- 94 94 94 182 182 182 218 218 218 242 242 242
53916-250 250 250 253 253 253 253 253 253 250 250 250
53917-234 234 234 253 253 253 253 253 253 253 253 253
53918-253 253 253 253 253 253 253 253 253 246 246 246
53919-238 238 238 226 226 226 210 210 210 202 202 202
53920-195 195 195 195 195 195 210 210 210 158 158 158
53921- 6 6 6 14 14 14 50 50 50 14 14 14
53922- 2 2 6 2 2 6 2 2 6 2 2 6
53923- 2 2 6 6 6 6 86 86 86 46 46 46
53924- 18 18 18 6 6 6 0 0 0 0 0 0
53925- 0 0 0 0 0 0 0 0 0 0 0 0
53926- 0 0 0 0 0 0 0 0 0 0 0 0
53927- 0 0 0 0 0 0 0 0 0 0 0 0
53928- 0 0 0 0 0 0 0 0 0 0 0 0
53929- 0 0 0 0 0 0 0 0 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 6 6 6
53933- 22 22 22 54 54 54 70 70 70 2 2 6
53934- 2 2 6 10 10 10 2 2 6 22 22 22
53935-166 166 166 231 231 231 250 250 250 253 253 253
53936-253 253 253 253 253 253 253 253 253 250 250 250
53937-242 242 242 253 253 253 253 253 253 253 253 253
53938-253 253 253 253 253 253 253 253 253 253 253 253
53939-253 253 253 253 253 253 253 253 253 246 246 246
53940-231 231 231 206 206 206 198 198 198 226 226 226
53941- 94 94 94 2 2 6 6 6 6 38 38 38
53942- 30 30 30 2 2 6 2 2 6 2 2 6
53943- 2 2 6 2 2 6 62 62 62 66 66 66
53944- 26 26 26 10 10 10 0 0 0 0 0 0
53945- 0 0 0 0 0 0 0 0 0 0 0 0
53946- 0 0 0 0 0 0 0 0 0 0 0 0
53947- 0 0 0 0 0 0 0 0 0 0 0 0
53948- 0 0 0 0 0 0 0 0 0 0 0 0
53949- 0 0 0 0 0 0 0 0 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 10 10 10
53953- 30 30 30 74 74 74 50 50 50 2 2 6
53954- 26 26 26 26 26 26 2 2 6 106 106 106
53955-238 238 238 253 253 253 253 253 253 253 253 253
53956-253 253 253 253 253 253 253 253 253 253 253 253
53957-253 253 253 253 253 253 253 253 253 253 253 253
53958-253 253 253 253 253 253 253 253 253 253 253 253
53959-253 253 253 253 253 253 253 253 253 253 253 253
53960-253 253 253 246 246 246 218 218 218 202 202 202
53961-210 210 210 14 14 14 2 2 6 2 2 6
53962- 30 30 30 22 22 22 2 2 6 2 2 6
53963- 2 2 6 2 2 6 18 18 18 86 86 86
53964- 42 42 42 14 14 14 0 0 0 0 0 0
53965- 0 0 0 0 0 0 0 0 0 0 0 0
53966- 0 0 0 0 0 0 0 0 0 0 0 0
53967- 0 0 0 0 0 0 0 0 0 0 0 0
53968- 0 0 0 0 0 0 0 0 0 0 0 0
53969- 0 0 0 0 0 0 0 0 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 14 14 14
53973- 42 42 42 90 90 90 22 22 22 2 2 6
53974- 42 42 42 2 2 6 18 18 18 218 218 218
53975-253 253 253 253 253 253 253 253 253 253 253 253
53976-253 253 253 253 253 253 253 253 253 253 253 253
53977-253 253 253 253 253 253 253 253 253 253 253 253
53978-253 253 253 253 253 253 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 250 250 250 221 221 221
53981-218 218 218 101 101 101 2 2 6 14 14 14
53982- 18 18 18 38 38 38 10 10 10 2 2 6
53983- 2 2 6 2 2 6 2 2 6 78 78 78
53984- 58 58 58 22 22 22 6 6 6 0 0 0
53985- 0 0 0 0 0 0 0 0 0 0 0 0
53986- 0 0 0 0 0 0 0 0 0 0 0 0
53987- 0 0 0 0 0 0 0 0 0 0 0 0
53988- 0 0 0 0 0 0 0 0 0 0 0 0
53989- 0 0 0 0 0 0 0 0 0 0 0 0
53990- 0 0 0 0 0 0 0 0 0 0 0 0
53991- 0 0 0 0 0 0 0 0 0 0 0 0
53992- 0 0 0 0 0 0 6 6 6 18 18 18
53993- 54 54 54 82 82 82 2 2 6 26 26 26
53994- 22 22 22 2 2 6 123 123 123 253 253 253
53995-253 253 253 253 253 253 253 253 253 253 253 253
53996-253 253 253 253 253 253 253 253 253 253 253 253
53997-253 253 253 253 253 253 253 253 253 253 253 253
53998-253 253 253 253 253 253 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 253 253 253 250 250 250
54001-238 238 238 198 198 198 6 6 6 38 38 38
54002- 58 58 58 26 26 26 38 38 38 2 2 6
54003- 2 2 6 2 2 6 2 2 6 46 46 46
54004- 78 78 78 30 30 30 10 10 10 0 0 0
54005- 0 0 0 0 0 0 0 0 0 0 0 0
54006- 0 0 0 0 0 0 0 0 0 0 0 0
54007- 0 0 0 0 0 0 0 0 0 0 0 0
54008- 0 0 0 0 0 0 0 0 0 0 0 0
54009- 0 0 0 0 0 0 0 0 0 0 0 0
54010- 0 0 0 0 0 0 0 0 0 0 0 0
54011- 0 0 0 0 0 0 0 0 0 0 0 0
54012- 0 0 0 0 0 0 10 10 10 30 30 30
54013- 74 74 74 58 58 58 2 2 6 42 42 42
54014- 2 2 6 22 22 22 231 231 231 253 253 253
54015-253 253 253 253 253 253 253 253 253 253 253 253
54016-253 253 253 253 253 253 253 253 253 250 250 250
54017-253 253 253 253 253 253 253 253 253 253 253 253
54018-253 253 253 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 253 253 253 253 253 253
54021-253 253 253 246 246 246 46 46 46 38 38 38
54022- 42 42 42 14 14 14 38 38 38 14 14 14
54023- 2 2 6 2 2 6 2 2 6 6 6 6
54024- 86 86 86 46 46 46 14 14 14 0 0 0
54025- 0 0 0 0 0 0 0 0 0 0 0 0
54026- 0 0 0 0 0 0 0 0 0 0 0 0
54027- 0 0 0 0 0 0 0 0 0 0 0 0
54028- 0 0 0 0 0 0 0 0 0 0 0 0
54029- 0 0 0 0 0 0 0 0 0 0 0 0
54030- 0 0 0 0 0 0 0 0 0 0 0 0
54031- 0 0 0 0 0 0 0 0 0 0 0 0
54032- 0 0 0 6 6 6 14 14 14 42 42 42
54033- 90 90 90 18 18 18 18 18 18 26 26 26
54034- 2 2 6 116 116 116 253 253 253 253 253 253
54035-253 253 253 253 253 253 253 253 253 253 253 253
54036-253 253 253 253 253 253 250 250 250 238 238 238
54037-253 253 253 253 253 253 253 253 253 253 253 253
54038-253 253 253 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 253 253 253 253 253 253
54041-253 253 253 253 253 253 94 94 94 6 6 6
54042- 2 2 6 2 2 6 10 10 10 34 34 34
54043- 2 2 6 2 2 6 2 2 6 2 2 6
54044- 74 74 74 58 58 58 22 22 22 6 6 6
54045- 0 0 0 0 0 0 0 0 0 0 0 0
54046- 0 0 0 0 0 0 0 0 0 0 0 0
54047- 0 0 0 0 0 0 0 0 0 0 0 0
54048- 0 0 0 0 0 0 0 0 0 0 0 0
54049- 0 0 0 0 0 0 0 0 0 0 0 0
54050- 0 0 0 0 0 0 0 0 0 0 0 0
54051- 0 0 0 0 0 0 0 0 0 0 0 0
54052- 0 0 0 10 10 10 26 26 26 66 66 66
54053- 82 82 82 2 2 6 38 38 38 6 6 6
54054- 14 14 14 210 210 210 253 253 253 253 253 253
54055-253 253 253 253 253 253 253 253 253 253 253 253
54056-253 253 253 253 253 253 246 246 246 242 242 242
54057-253 253 253 253 253 253 253 253 253 253 253 253
54058-253 253 253 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 253 253 253 253 253 253
54061-253 253 253 253 253 253 144 144 144 2 2 6
54062- 2 2 6 2 2 6 2 2 6 46 46 46
54063- 2 2 6 2 2 6 2 2 6 2 2 6
54064- 42 42 42 74 74 74 30 30 30 10 10 10
54065- 0 0 0 0 0 0 0 0 0 0 0 0
54066- 0 0 0 0 0 0 0 0 0 0 0 0
54067- 0 0 0 0 0 0 0 0 0 0 0 0
54068- 0 0 0 0 0 0 0 0 0 0 0 0
54069- 0 0 0 0 0 0 0 0 0 0 0 0
54070- 0 0 0 0 0 0 0 0 0 0 0 0
54071- 0 0 0 0 0 0 0 0 0 0 0 0
54072- 6 6 6 14 14 14 42 42 42 90 90 90
54073- 26 26 26 6 6 6 42 42 42 2 2 6
54074- 74 74 74 250 250 250 253 253 253 253 253 253
54075-253 253 253 253 253 253 253 253 253 253 253 253
54076-253 253 253 253 253 253 242 242 242 242 242 242
54077-253 253 253 253 253 253 253 253 253 253 253 253
54078-253 253 253 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 253 253 253 253 253 253
54081-253 253 253 253 253 253 182 182 182 2 2 6
54082- 2 2 6 2 2 6 2 2 6 46 46 46
54083- 2 2 6 2 2 6 2 2 6 2 2 6
54084- 10 10 10 86 86 86 38 38 38 10 10 10
54085- 0 0 0 0 0 0 0 0 0 0 0 0
54086- 0 0 0 0 0 0 0 0 0 0 0 0
54087- 0 0 0 0 0 0 0 0 0 0 0 0
54088- 0 0 0 0 0 0 0 0 0 0 0 0
54089- 0 0 0 0 0 0 0 0 0 0 0 0
54090- 0 0 0 0 0 0 0 0 0 0 0 0
54091- 0 0 0 0 0 0 0 0 0 0 0 0
54092- 10 10 10 26 26 26 66 66 66 82 82 82
54093- 2 2 6 22 22 22 18 18 18 2 2 6
54094-149 149 149 253 253 253 253 253 253 253 253 253
54095-253 253 253 253 253 253 253 253 253 253 253 253
54096-253 253 253 253 253 253 234 234 234 242 242 242
54097-253 253 253 253 253 253 253 253 253 253 253 253
54098-253 253 253 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 253 253 253 253 253 253
54101-253 253 253 253 253 253 206 206 206 2 2 6
54102- 2 2 6 2 2 6 2 2 6 38 38 38
54103- 2 2 6 2 2 6 2 2 6 2 2 6
54104- 6 6 6 86 86 86 46 46 46 14 14 14
54105- 0 0 0 0 0 0 0 0 0 0 0 0
54106- 0 0 0 0 0 0 0 0 0 0 0 0
54107- 0 0 0 0 0 0 0 0 0 0 0 0
54108- 0 0 0 0 0 0 0 0 0 0 0 0
54109- 0 0 0 0 0 0 0 0 0 0 0 0
54110- 0 0 0 0 0 0 0 0 0 0 0 0
54111- 0 0 0 0 0 0 0 0 0 6 6 6
54112- 18 18 18 46 46 46 86 86 86 18 18 18
54113- 2 2 6 34 34 34 10 10 10 6 6 6
54114-210 210 210 253 253 253 253 253 253 253 253 253
54115-253 253 253 253 253 253 253 253 253 253 253 253
54116-253 253 253 253 253 253 234 234 234 242 242 242
54117-253 253 253 253 253 253 253 253 253 253 253 253
54118-253 253 253 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 253 253 253 253 253 253
54121-253 253 253 253 253 253 221 221 221 6 6 6
54122- 2 2 6 2 2 6 6 6 6 30 30 30
54123- 2 2 6 2 2 6 2 2 6 2 2 6
54124- 2 2 6 82 82 82 54 54 54 18 18 18
54125- 6 6 6 0 0 0 0 0 0 0 0 0
54126- 0 0 0 0 0 0 0 0 0 0 0 0
54127- 0 0 0 0 0 0 0 0 0 0 0 0
54128- 0 0 0 0 0 0 0 0 0 0 0 0
54129- 0 0 0 0 0 0 0 0 0 0 0 0
54130- 0 0 0 0 0 0 0 0 0 0 0 0
54131- 0 0 0 0 0 0 0 0 0 10 10 10
54132- 26 26 26 66 66 66 62 62 62 2 2 6
54133- 2 2 6 38 38 38 10 10 10 26 26 26
54134-238 238 238 253 253 253 253 253 253 253 253 253
54135-253 253 253 253 253 253 253 253 253 253 253 253
54136-253 253 253 253 253 253 231 231 231 238 238 238
54137-253 253 253 253 253 253 253 253 253 253 253 253
54138-253 253 253 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 253 253 253 253 253 253
54141-253 253 253 253 253 253 231 231 231 6 6 6
54142- 2 2 6 2 2 6 10 10 10 30 30 30
54143- 2 2 6 2 2 6 2 2 6 2 2 6
54144- 2 2 6 66 66 66 58 58 58 22 22 22
54145- 6 6 6 0 0 0 0 0 0 0 0 0
54146- 0 0 0 0 0 0 0 0 0 0 0 0
54147- 0 0 0 0 0 0 0 0 0 0 0 0
54148- 0 0 0 0 0 0 0 0 0 0 0 0
54149- 0 0 0 0 0 0 0 0 0 0 0 0
54150- 0 0 0 0 0 0 0 0 0 0 0 0
54151- 0 0 0 0 0 0 0 0 0 10 10 10
54152- 38 38 38 78 78 78 6 6 6 2 2 6
54153- 2 2 6 46 46 46 14 14 14 42 42 42
54154-246 246 246 253 253 253 253 253 253 253 253 253
54155-253 253 253 253 253 253 253 253 253 253 253 253
54156-253 253 253 253 253 253 231 231 231 242 242 242
54157-253 253 253 253 253 253 253 253 253 253 253 253
54158-253 253 253 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 253 253 253 253 253 253
54161-253 253 253 253 253 253 234 234 234 10 10 10
54162- 2 2 6 2 2 6 22 22 22 14 14 14
54163- 2 2 6 2 2 6 2 2 6 2 2 6
54164- 2 2 6 66 66 66 62 62 62 22 22 22
54165- 6 6 6 0 0 0 0 0 0 0 0 0
54166- 0 0 0 0 0 0 0 0 0 0 0 0
54167- 0 0 0 0 0 0 0 0 0 0 0 0
54168- 0 0 0 0 0 0 0 0 0 0 0 0
54169- 0 0 0 0 0 0 0 0 0 0 0 0
54170- 0 0 0 0 0 0 0 0 0 0 0 0
54171- 0 0 0 0 0 0 6 6 6 18 18 18
54172- 50 50 50 74 74 74 2 2 6 2 2 6
54173- 14 14 14 70 70 70 34 34 34 62 62 62
54174-250 250 250 253 253 253 253 253 253 253 253 253
54175-253 253 253 253 253 253 253 253 253 253 253 253
54176-253 253 253 253 253 253 231 231 231 246 246 246
54177-253 253 253 253 253 253 253 253 253 253 253 253
54178-253 253 253 253 253 253 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 253 253 253 253 253 253
54181-253 253 253 253 253 253 234 234 234 14 14 14
54182- 2 2 6 2 2 6 30 30 30 2 2 6
54183- 2 2 6 2 2 6 2 2 6 2 2 6
54184- 2 2 6 66 66 66 62 62 62 22 22 22
54185- 6 6 6 0 0 0 0 0 0 0 0 0
54186- 0 0 0 0 0 0 0 0 0 0 0 0
54187- 0 0 0 0 0 0 0 0 0 0 0 0
54188- 0 0 0 0 0 0 0 0 0 0 0 0
54189- 0 0 0 0 0 0 0 0 0 0 0 0
54190- 0 0 0 0 0 0 0 0 0 0 0 0
54191- 0 0 0 0 0 0 6 6 6 18 18 18
54192- 54 54 54 62 62 62 2 2 6 2 2 6
54193- 2 2 6 30 30 30 46 46 46 70 70 70
54194-250 250 250 253 253 253 253 253 253 253 253 253
54195-253 253 253 253 253 253 253 253 253 253 253 253
54196-253 253 253 253 253 253 231 231 231 246 246 246
54197-253 253 253 253 253 253 253 253 253 253 253 253
54198-253 253 253 253 253 253 253 253 253 253 253 253
54199-253 253 253 253 253 253 253 253 253 253 253 253
54200-253 253 253 253 253 253 253 253 253 253 253 253
54201-253 253 253 253 253 253 226 226 226 10 10 10
54202- 2 2 6 6 6 6 30 30 30 2 2 6
54203- 2 2 6 2 2 6 2 2 6 2 2 6
54204- 2 2 6 66 66 66 58 58 58 22 22 22
54205- 6 6 6 0 0 0 0 0 0 0 0 0
54206- 0 0 0 0 0 0 0 0 0 0 0 0
54207- 0 0 0 0 0 0 0 0 0 0 0 0
54208- 0 0 0 0 0 0 0 0 0 0 0 0
54209- 0 0 0 0 0 0 0 0 0 0 0 0
54210- 0 0 0 0 0 0 0 0 0 0 0 0
54211- 0 0 0 0 0 0 6 6 6 22 22 22
54212- 58 58 58 62 62 62 2 2 6 2 2 6
54213- 2 2 6 2 2 6 30 30 30 78 78 78
54214-250 250 250 253 253 253 253 253 253 253 253 253
54215-253 253 253 253 253 253 253 253 253 253 253 253
54216-253 253 253 253 253 253 231 231 231 246 246 246
54217-253 253 253 253 253 253 253 253 253 253 253 253
54218-253 253 253 253 253 253 253 253 253 253 253 253
54219-253 253 253 253 253 253 253 253 253 253 253 253
54220-253 253 253 253 253 253 253 253 253 253 253 253
54221-253 253 253 253 253 253 206 206 206 2 2 6
54222- 22 22 22 34 34 34 18 14 6 22 22 22
54223- 26 26 26 18 18 18 6 6 6 2 2 6
54224- 2 2 6 82 82 82 54 54 54 18 18 18
54225- 6 6 6 0 0 0 0 0 0 0 0 0
54226- 0 0 0 0 0 0 0 0 0 0 0 0
54227- 0 0 0 0 0 0 0 0 0 0 0 0
54228- 0 0 0 0 0 0 0 0 0 0 0 0
54229- 0 0 0 0 0 0 0 0 0 0 0 0
54230- 0 0 0 0 0 0 0 0 0 0 0 0
54231- 0 0 0 0 0 0 6 6 6 26 26 26
54232- 62 62 62 106 106 106 74 54 14 185 133 11
54233-210 162 10 121 92 8 6 6 6 62 62 62
54234-238 238 238 253 253 253 253 253 253 253 253 253
54235-253 253 253 253 253 253 253 253 253 253 253 253
54236-253 253 253 253 253 253 231 231 231 246 246 246
54237-253 253 253 253 253 253 253 253 253 253 253 253
54238-253 253 253 253 253 253 253 253 253 253 253 253
54239-253 253 253 253 253 253 253 253 253 253 253 253
54240-253 253 253 253 253 253 253 253 253 253 253 253
54241-253 253 253 253 253 253 158 158 158 18 18 18
54242- 14 14 14 2 2 6 2 2 6 2 2 6
54243- 6 6 6 18 18 18 66 66 66 38 38 38
54244- 6 6 6 94 94 94 50 50 50 18 18 18
54245- 6 6 6 0 0 0 0 0 0 0 0 0
54246- 0 0 0 0 0 0 0 0 0 0 0 0
54247- 0 0 0 0 0 0 0 0 0 0 0 0
54248- 0 0 0 0 0 0 0 0 0 0 0 0
54249- 0 0 0 0 0 0 0 0 0 0 0 0
54250- 0 0 0 0 0 0 0 0 0 6 6 6
54251- 10 10 10 10 10 10 18 18 18 38 38 38
54252- 78 78 78 142 134 106 216 158 10 242 186 14
54253-246 190 14 246 190 14 156 118 10 10 10 10
54254- 90 90 90 238 238 238 253 253 253 253 253 253
54255-253 253 253 253 253 253 253 253 253 253 253 253
54256-253 253 253 253 253 253 231 231 231 250 250 250
54257-253 253 253 253 253 253 253 253 253 253 253 253
54258-253 253 253 253 253 253 253 253 253 253 253 253
54259-253 253 253 253 253 253 253 253 253 253 253 253
54260-253 253 253 253 253 253 253 253 253 246 230 190
54261-238 204 91 238 204 91 181 142 44 37 26 9
54262- 2 2 6 2 2 6 2 2 6 2 2 6
54263- 2 2 6 2 2 6 38 38 38 46 46 46
54264- 26 26 26 106 106 106 54 54 54 18 18 18
54265- 6 6 6 0 0 0 0 0 0 0 0 0
54266- 0 0 0 0 0 0 0 0 0 0 0 0
54267- 0 0 0 0 0 0 0 0 0 0 0 0
54268- 0 0 0 0 0 0 0 0 0 0 0 0
54269- 0 0 0 0 0 0 0 0 0 0 0 0
54270- 0 0 0 6 6 6 14 14 14 22 22 22
54271- 30 30 30 38 38 38 50 50 50 70 70 70
54272-106 106 106 190 142 34 226 170 11 242 186 14
54273-246 190 14 246 190 14 246 190 14 154 114 10
54274- 6 6 6 74 74 74 226 226 226 253 253 253
54275-253 253 253 253 253 253 253 253 253 253 253 253
54276-253 253 253 253 253 253 231 231 231 250 250 250
54277-253 253 253 253 253 253 253 253 253 253 253 253
54278-253 253 253 253 253 253 253 253 253 253 253 253
54279-253 253 253 253 253 253 253 253 253 253 253 253
54280-253 253 253 253 253 253 253 253 253 228 184 62
54281-241 196 14 241 208 19 232 195 16 38 30 10
54282- 2 2 6 2 2 6 2 2 6 2 2 6
54283- 2 2 6 6 6 6 30 30 30 26 26 26
54284-203 166 17 154 142 90 66 66 66 26 26 26
54285- 6 6 6 0 0 0 0 0 0 0 0 0
54286- 0 0 0 0 0 0 0 0 0 0 0 0
54287- 0 0 0 0 0 0 0 0 0 0 0 0
54288- 0 0 0 0 0 0 0 0 0 0 0 0
54289- 0 0 0 0 0 0 0 0 0 0 0 0
54290- 6 6 6 18 18 18 38 38 38 58 58 58
54291- 78 78 78 86 86 86 101 101 101 123 123 123
54292-175 146 61 210 150 10 234 174 13 246 186 14
54293-246 190 14 246 190 14 246 190 14 238 190 10
54294-102 78 10 2 2 6 46 46 46 198 198 198
54295-253 253 253 253 253 253 253 253 253 253 253 253
54296-253 253 253 253 253 253 234 234 234 242 242 242
54297-253 253 253 253 253 253 253 253 253 253 253 253
54298-253 253 253 253 253 253 253 253 253 253 253 253
54299-253 253 253 253 253 253 253 253 253 253 253 253
54300-253 253 253 253 253 253 253 253 253 224 178 62
54301-242 186 14 241 196 14 210 166 10 22 18 6
54302- 2 2 6 2 2 6 2 2 6 2 2 6
54303- 2 2 6 2 2 6 6 6 6 121 92 8
54304-238 202 15 232 195 16 82 82 82 34 34 34
54305- 10 10 10 0 0 0 0 0 0 0 0 0
54306- 0 0 0 0 0 0 0 0 0 0 0 0
54307- 0 0 0 0 0 0 0 0 0 0 0 0
54308- 0 0 0 0 0 0 0 0 0 0 0 0
54309- 0 0 0 0 0 0 0 0 0 0 0 0
54310- 14 14 14 38 38 38 70 70 70 154 122 46
54311-190 142 34 200 144 11 197 138 11 197 138 11
54312-213 154 11 226 170 11 242 186 14 246 190 14
54313-246 190 14 246 190 14 246 190 14 246 190 14
54314-225 175 15 46 32 6 2 2 6 22 22 22
54315-158 158 158 250 250 250 253 253 253 253 253 253
54316-253 253 253 253 253 253 253 253 253 253 253 253
54317-253 253 253 253 253 253 253 253 253 253 253 253
54318-253 253 253 253 253 253 253 253 253 253 253 253
54319-253 253 253 253 253 253 253 253 253 253 253 253
54320-253 253 253 250 250 250 242 242 242 224 178 62
54321-239 182 13 236 186 11 213 154 11 46 32 6
54322- 2 2 6 2 2 6 2 2 6 2 2 6
54323- 2 2 6 2 2 6 61 42 6 225 175 15
54324-238 190 10 236 186 11 112 100 78 42 42 42
54325- 14 14 14 0 0 0 0 0 0 0 0 0
54326- 0 0 0 0 0 0 0 0 0 0 0 0
54327- 0 0 0 0 0 0 0 0 0 0 0 0
54328- 0 0 0 0 0 0 0 0 0 0 0 0
54329- 0 0 0 0 0 0 0 0 0 6 6 6
54330- 22 22 22 54 54 54 154 122 46 213 154 11
54331-226 170 11 230 174 11 226 170 11 226 170 11
54332-236 178 12 242 186 14 246 190 14 246 190 14
54333-246 190 14 246 190 14 246 190 14 246 190 14
54334-241 196 14 184 144 12 10 10 10 2 2 6
54335- 6 6 6 116 116 116 242 242 242 253 253 253
54336-253 253 253 253 253 253 253 253 253 253 253 253
54337-253 253 253 253 253 253 253 253 253 253 253 253
54338-253 253 253 253 253 253 253 253 253 253 253 253
54339-253 253 253 253 253 253 253 253 253 253 253 253
54340-253 253 253 231 231 231 198 198 198 214 170 54
54341-236 178 12 236 178 12 210 150 10 137 92 6
54342- 18 14 6 2 2 6 2 2 6 2 2 6
54343- 6 6 6 70 47 6 200 144 11 236 178 12
54344-239 182 13 239 182 13 124 112 88 58 58 58
54345- 22 22 22 6 6 6 0 0 0 0 0 0
54346- 0 0 0 0 0 0 0 0 0 0 0 0
54347- 0 0 0 0 0 0 0 0 0 0 0 0
54348- 0 0 0 0 0 0 0 0 0 0 0 0
54349- 0 0 0 0 0 0 0 0 0 10 10 10
54350- 30 30 30 70 70 70 180 133 36 226 170 11
54351-239 182 13 242 186 14 242 186 14 246 186 14
54352-246 190 14 246 190 14 246 190 14 246 190 14
54353-246 190 14 246 190 14 246 190 14 246 190 14
54354-246 190 14 232 195 16 98 70 6 2 2 6
54355- 2 2 6 2 2 6 66 66 66 221 221 221
54356-253 253 253 253 253 253 253 253 253 253 253 253
54357-253 253 253 253 253 253 253 253 253 253 253 253
54358-253 253 253 253 253 253 253 253 253 253 253 253
54359-253 253 253 253 253 253 253 253 253 253 253 253
54360-253 253 253 206 206 206 198 198 198 214 166 58
54361-230 174 11 230 174 11 216 158 10 192 133 9
54362-163 110 8 116 81 8 102 78 10 116 81 8
54363-167 114 7 197 138 11 226 170 11 239 182 13
54364-242 186 14 242 186 14 162 146 94 78 78 78
54365- 34 34 34 14 14 14 6 6 6 0 0 0
54366- 0 0 0 0 0 0 0 0 0 0 0 0
54367- 0 0 0 0 0 0 0 0 0 0 0 0
54368- 0 0 0 0 0 0 0 0 0 0 0 0
54369- 0 0 0 0 0 0 0 0 0 6 6 6
54370- 30 30 30 78 78 78 190 142 34 226 170 11
54371-239 182 13 246 190 14 246 190 14 246 190 14
54372-246 190 14 246 190 14 246 190 14 246 190 14
54373-246 190 14 246 190 14 246 190 14 246 190 14
54374-246 190 14 241 196 14 203 166 17 22 18 6
54375- 2 2 6 2 2 6 2 2 6 38 38 38
54376-218 218 218 253 253 253 253 253 253 253 253 253
54377-253 253 253 253 253 253 253 253 253 253 253 253
54378-253 253 253 253 253 253 253 253 253 253 253 253
54379-253 253 253 253 253 253 253 253 253 253 253 253
54380-250 250 250 206 206 206 198 198 198 202 162 69
54381-226 170 11 236 178 12 224 166 10 210 150 10
54382-200 144 11 197 138 11 192 133 9 197 138 11
54383-210 150 10 226 170 11 242 186 14 246 190 14
54384-246 190 14 246 186 14 225 175 15 124 112 88
54385- 62 62 62 30 30 30 14 14 14 6 6 6
54386- 0 0 0 0 0 0 0 0 0 0 0 0
54387- 0 0 0 0 0 0 0 0 0 0 0 0
54388- 0 0 0 0 0 0 0 0 0 0 0 0
54389- 0 0 0 0 0 0 0 0 0 10 10 10
54390- 30 30 30 78 78 78 174 135 50 224 166 10
54391-239 182 13 246 190 14 246 190 14 246 190 14
54392-246 190 14 246 190 14 246 190 14 246 190 14
54393-246 190 14 246 190 14 246 190 14 246 190 14
54394-246 190 14 246 190 14 241 196 14 139 102 15
54395- 2 2 6 2 2 6 2 2 6 2 2 6
54396- 78 78 78 250 250 250 253 253 253 253 253 253
54397-253 253 253 253 253 253 253 253 253 253 253 253
54398-253 253 253 253 253 253 253 253 253 253 253 253
54399-253 253 253 253 253 253 253 253 253 253 253 253
54400-250 250 250 214 214 214 198 198 198 190 150 46
54401-219 162 10 236 178 12 234 174 13 224 166 10
54402-216 158 10 213 154 11 213 154 11 216 158 10
54403-226 170 11 239 182 13 246 190 14 246 190 14
54404-246 190 14 246 190 14 242 186 14 206 162 42
54405-101 101 101 58 58 58 30 30 30 14 14 14
54406- 6 6 6 0 0 0 0 0 0 0 0 0
54407- 0 0 0 0 0 0 0 0 0 0 0 0
54408- 0 0 0 0 0 0 0 0 0 0 0 0
54409- 0 0 0 0 0 0 0 0 0 10 10 10
54410- 30 30 30 74 74 74 174 135 50 216 158 10
54411-236 178 12 246 190 14 246 190 14 246 190 14
54412-246 190 14 246 190 14 246 190 14 246 190 14
54413-246 190 14 246 190 14 246 190 14 246 190 14
54414-246 190 14 246 190 14 241 196 14 226 184 13
54415- 61 42 6 2 2 6 2 2 6 2 2 6
54416- 22 22 22 238 238 238 253 253 253 253 253 253
54417-253 253 253 253 253 253 253 253 253 253 253 253
54418-253 253 253 253 253 253 253 253 253 253 253 253
54419-253 253 253 253 253 253 253 253 253 253 253 253
54420-253 253 253 226 226 226 187 187 187 180 133 36
54421-216 158 10 236 178 12 239 182 13 236 178 12
54422-230 174 11 226 170 11 226 170 11 230 174 11
54423-236 178 12 242 186 14 246 190 14 246 190 14
54424-246 190 14 246 190 14 246 186 14 239 182 13
54425-206 162 42 106 106 106 66 66 66 34 34 34
54426- 14 14 14 6 6 6 0 0 0 0 0 0
54427- 0 0 0 0 0 0 0 0 0 0 0 0
54428- 0 0 0 0 0 0 0 0 0 0 0 0
54429- 0 0 0 0 0 0 0 0 0 6 6 6
54430- 26 26 26 70 70 70 163 133 67 213 154 11
54431-236 178 12 246 190 14 246 190 14 246 190 14
54432-246 190 14 246 190 14 246 190 14 246 190 14
54433-246 190 14 246 190 14 246 190 14 246 190 14
54434-246 190 14 246 190 14 246 190 14 241 196 14
54435-190 146 13 18 14 6 2 2 6 2 2 6
54436- 46 46 46 246 246 246 253 253 253 253 253 253
54437-253 253 253 253 253 253 253 253 253 253 253 253
54438-253 253 253 253 253 253 253 253 253 253 253 253
54439-253 253 253 253 253 253 253 253 253 253 253 253
54440-253 253 253 221 221 221 86 86 86 156 107 11
54441-216 158 10 236 178 12 242 186 14 246 186 14
54442-242 186 14 239 182 13 239 182 13 242 186 14
54443-242 186 14 246 186 14 246 190 14 246 190 14
54444-246 190 14 246 190 14 246 190 14 246 190 14
54445-242 186 14 225 175 15 142 122 72 66 66 66
54446- 30 30 30 10 10 10 0 0 0 0 0 0
54447- 0 0 0 0 0 0 0 0 0 0 0 0
54448- 0 0 0 0 0 0 0 0 0 0 0 0
54449- 0 0 0 0 0 0 0 0 0 6 6 6
54450- 26 26 26 70 70 70 163 133 67 210 150 10
54451-236 178 12 246 190 14 246 190 14 246 190 14
54452-246 190 14 246 190 14 246 190 14 246 190 14
54453-246 190 14 246 190 14 246 190 14 246 190 14
54454-246 190 14 246 190 14 246 190 14 246 190 14
54455-232 195 16 121 92 8 34 34 34 106 106 106
54456-221 221 221 253 253 253 253 253 253 253 253 253
54457-253 253 253 253 253 253 253 253 253 253 253 253
54458-253 253 253 253 253 253 253 253 253 253 253 253
54459-253 253 253 253 253 253 253 253 253 253 253 253
54460-242 242 242 82 82 82 18 14 6 163 110 8
54461-216 158 10 236 178 12 242 186 14 246 190 14
54462-246 190 14 246 190 14 246 190 14 246 190 14
54463-246 190 14 246 190 14 246 190 14 246 190 14
54464-246 190 14 246 190 14 246 190 14 246 190 14
54465-246 190 14 246 190 14 242 186 14 163 133 67
54466- 46 46 46 18 18 18 6 6 6 0 0 0
54467- 0 0 0 0 0 0 0 0 0 0 0 0
54468- 0 0 0 0 0 0 0 0 0 0 0 0
54469- 0 0 0 0 0 0 0 0 0 10 10 10
54470- 30 30 30 78 78 78 163 133 67 210 150 10
54471-236 178 12 246 186 14 246 190 14 246 190 14
54472-246 190 14 246 190 14 246 190 14 246 190 14
54473-246 190 14 246 190 14 246 190 14 246 190 14
54474-246 190 14 246 190 14 246 190 14 246 190 14
54475-241 196 14 215 174 15 190 178 144 253 253 253
54476-253 253 253 253 253 253 253 253 253 253 253 253
54477-253 253 253 253 253 253 253 253 253 253 253 253
54478-253 253 253 253 253 253 253 253 253 253 253 253
54479-253 253 253 253 253 253 253 253 253 218 218 218
54480- 58 58 58 2 2 6 22 18 6 167 114 7
54481-216 158 10 236 178 12 246 186 14 246 190 14
54482-246 190 14 246 190 14 246 190 14 246 190 14
54483-246 190 14 246 190 14 246 190 14 246 190 14
54484-246 190 14 246 190 14 246 190 14 246 190 14
54485-246 190 14 246 186 14 242 186 14 190 150 46
54486- 54 54 54 22 22 22 6 6 6 0 0 0
54487- 0 0 0 0 0 0 0 0 0 0 0 0
54488- 0 0 0 0 0 0 0 0 0 0 0 0
54489- 0 0 0 0 0 0 0 0 0 14 14 14
54490- 38 38 38 86 86 86 180 133 36 213 154 11
54491-236 178 12 246 186 14 246 190 14 246 190 14
54492-246 190 14 246 190 14 246 190 14 246 190 14
54493-246 190 14 246 190 14 246 190 14 246 190 14
54494-246 190 14 246 190 14 246 190 14 246 190 14
54495-246 190 14 232 195 16 190 146 13 214 214 214
54496-253 253 253 253 253 253 253 253 253 253 253 253
54497-253 253 253 253 253 253 253 253 253 253 253 253
54498-253 253 253 253 253 253 253 253 253 253 253 253
54499-253 253 253 250 250 250 170 170 170 26 26 26
54500- 2 2 6 2 2 6 37 26 9 163 110 8
54501-219 162 10 239 182 13 246 186 14 246 190 14
54502-246 190 14 246 190 14 246 190 14 246 190 14
54503-246 190 14 246 190 14 246 190 14 246 190 14
54504-246 190 14 246 190 14 246 190 14 246 190 14
54505-246 186 14 236 178 12 224 166 10 142 122 72
54506- 46 46 46 18 18 18 6 6 6 0 0 0
54507- 0 0 0 0 0 0 0 0 0 0 0 0
54508- 0 0 0 0 0 0 0 0 0 0 0 0
54509- 0 0 0 0 0 0 6 6 6 18 18 18
54510- 50 50 50 109 106 95 192 133 9 224 166 10
54511-242 186 14 246 190 14 246 190 14 246 190 14
54512-246 190 14 246 190 14 246 190 14 246 190 14
54513-246 190 14 246 190 14 246 190 14 246 190 14
54514-246 190 14 246 190 14 246 190 14 246 190 14
54515-242 186 14 226 184 13 210 162 10 142 110 46
54516-226 226 226 253 253 253 253 253 253 253 253 253
54517-253 253 253 253 253 253 253 253 253 253 253 253
54518-253 253 253 253 253 253 253 253 253 253 253 253
54519-198 198 198 66 66 66 2 2 6 2 2 6
54520- 2 2 6 2 2 6 50 34 6 156 107 11
54521-219 162 10 239 182 13 246 186 14 246 190 14
54522-246 190 14 246 190 14 246 190 14 246 190 14
54523-246 190 14 246 190 14 246 190 14 246 190 14
54524-246 190 14 246 190 14 246 190 14 242 186 14
54525-234 174 13 213 154 11 154 122 46 66 66 66
54526- 30 30 30 10 10 10 0 0 0 0 0 0
54527- 0 0 0 0 0 0 0 0 0 0 0 0
54528- 0 0 0 0 0 0 0 0 0 0 0 0
54529- 0 0 0 0 0 0 6 6 6 22 22 22
54530- 58 58 58 154 121 60 206 145 10 234 174 13
54531-242 186 14 246 186 14 246 190 14 246 190 14
54532-246 190 14 246 190 14 246 190 14 246 190 14
54533-246 190 14 246 190 14 246 190 14 246 190 14
54534-246 190 14 246 190 14 246 190 14 246 190 14
54535-246 186 14 236 178 12 210 162 10 163 110 8
54536- 61 42 6 138 138 138 218 218 218 250 250 250
54537-253 253 253 253 253 253 253 253 253 250 250 250
54538-242 242 242 210 210 210 144 144 144 66 66 66
54539- 6 6 6 2 2 6 2 2 6 2 2 6
54540- 2 2 6 2 2 6 61 42 6 163 110 8
54541-216 158 10 236 178 12 246 190 14 246 190 14
54542-246 190 14 246 190 14 246 190 14 246 190 14
54543-246 190 14 246 190 14 246 190 14 246 190 14
54544-246 190 14 239 182 13 230 174 11 216 158 10
54545-190 142 34 124 112 88 70 70 70 38 38 38
54546- 18 18 18 6 6 6 0 0 0 0 0 0
54547- 0 0 0 0 0 0 0 0 0 0 0 0
54548- 0 0 0 0 0 0 0 0 0 0 0 0
54549- 0 0 0 0 0 0 6 6 6 22 22 22
54550- 62 62 62 168 124 44 206 145 10 224 166 10
54551-236 178 12 239 182 13 242 186 14 242 186 14
54552-246 186 14 246 190 14 246 190 14 246 190 14
54553-246 190 14 246 190 14 246 190 14 246 190 14
54554-246 190 14 246 190 14 246 190 14 246 190 14
54555-246 190 14 236 178 12 216 158 10 175 118 6
54556- 80 54 7 2 2 6 6 6 6 30 30 30
54557- 54 54 54 62 62 62 50 50 50 38 38 38
54558- 14 14 14 2 2 6 2 2 6 2 2 6
54559- 2 2 6 2 2 6 2 2 6 2 2 6
54560- 2 2 6 6 6 6 80 54 7 167 114 7
54561-213 154 11 236 178 12 246 190 14 246 190 14
54562-246 190 14 246 190 14 246 190 14 246 190 14
54563-246 190 14 242 186 14 239 182 13 239 182 13
54564-230 174 11 210 150 10 174 135 50 124 112 88
54565- 82 82 82 54 54 54 34 34 34 18 18 18
54566- 6 6 6 0 0 0 0 0 0 0 0 0
54567- 0 0 0 0 0 0 0 0 0 0 0 0
54568- 0 0 0 0 0 0 0 0 0 0 0 0
54569- 0 0 0 0 0 0 6 6 6 18 18 18
54570- 50 50 50 158 118 36 192 133 9 200 144 11
54571-216 158 10 219 162 10 224 166 10 226 170 11
54572-230 174 11 236 178 12 239 182 13 239 182 13
54573-242 186 14 246 186 14 246 190 14 246 190 14
54574-246 190 14 246 190 14 246 190 14 246 190 14
54575-246 186 14 230 174 11 210 150 10 163 110 8
54576-104 69 6 10 10 10 2 2 6 2 2 6
54577- 2 2 6 2 2 6 2 2 6 2 2 6
54578- 2 2 6 2 2 6 2 2 6 2 2 6
54579- 2 2 6 2 2 6 2 2 6 2 2 6
54580- 2 2 6 6 6 6 91 60 6 167 114 7
54581-206 145 10 230 174 11 242 186 14 246 190 14
54582-246 190 14 246 190 14 246 186 14 242 186 14
54583-239 182 13 230 174 11 224 166 10 213 154 11
54584-180 133 36 124 112 88 86 86 86 58 58 58
54585- 38 38 38 22 22 22 10 10 10 6 6 6
54586- 0 0 0 0 0 0 0 0 0 0 0 0
54587- 0 0 0 0 0 0 0 0 0 0 0 0
54588- 0 0 0 0 0 0 0 0 0 0 0 0
54589- 0 0 0 0 0 0 0 0 0 14 14 14
54590- 34 34 34 70 70 70 138 110 50 158 118 36
54591-167 114 7 180 123 7 192 133 9 197 138 11
54592-200 144 11 206 145 10 213 154 11 219 162 10
54593-224 166 10 230 174 11 239 182 13 242 186 14
54594-246 186 14 246 186 14 246 186 14 246 186 14
54595-239 182 13 216 158 10 185 133 11 152 99 6
54596-104 69 6 18 14 6 2 2 6 2 2 6
54597- 2 2 6 2 2 6 2 2 6 2 2 6
54598- 2 2 6 2 2 6 2 2 6 2 2 6
54599- 2 2 6 2 2 6 2 2 6 2 2 6
54600- 2 2 6 6 6 6 80 54 7 152 99 6
54601-192 133 9 219 162 10 236 178 12 239 182 13
54602-246 186 14 242 186 14 239 182 13 236 178 12
54603-224 166 10 206 145 10 192 133 9 154 121 60
54604- 94 94 94 62 62 62 42 42 42 22 22 22
54605- 14 14 14 6 6 6 0 0 0 0 0 0
54606- 0 0 0 0 0 0 0 0 0 0 0 0
54607- 0 0 0 0 0 0 0 0 0 0 0 0
54608- 0 0 0 0 0 0 0 0 0 0 0 0
54609- 0 0 0 0 0 0 0 0 0 6 6 6
54610- 18 18 18 34 34 34 58 58 58 78 78 78
54611-101 98 89 124 112 88 142 110 46 156 107 11
54612-163 110 8 167 114 7 175 118 6 180 123 7
54613-185 133 11 197 138 11 210 150 10 219 162 10
54614-226 170 11 236 178 12 236 178 12 234 174 13
54615-219 162 10 197 138 11 163 110 8 130 83 6
54616- 91 60 6 10 10 10 2 2 6 2 2 6
54617- 18 18 18 38 38 38 38 38 38 38 38 38
54618- 38 38 38 38 38 38 38 38 38 38 38 38
54619- 38 38 38 38 38 38 26 26 26 2 2 6
54620- 2 2 6 6 6 6 70 47 6 137 92 6
54621-175 118 6 200 144 11 219 162 10 230 174 11
54622-234 174 13 230 174 11 219 162 10 210 150 10
54623-192 133 9 163 110 8 124 112 88 82 82 82
54624- 50 50 50 30 30 30 14 14 14 6 6 6
54625- 0 0 0 0 0 0 0 0 0 0 0 0
54626- 0 0 0 0 0 0 0 0 0 0 0 0
54627- 0 0 0 0 0 0 0 0 0 0 0 0
54628- 0 0 0 0 0 0 0 0 0 0 0 0
54629- 0 0 0 0 0 0 0 0 0 0 0 0
54630- 6 6 6 14 14 14 22 22 22 34 34 34
54631- 42 42 42 58 58 58 74 74 74 86 86 86
54632-101 98 89 122 102 70 130 98 46 121 87 25
54633-137 92 6 152 99 6 163 110 8 180 123 7
54634-185 133 11 197 138 11 206 145 10 200 144 11
54635-180 123 7 156 107 11 130 83 6 104 69 6
54636- 50 34 6 54 54 54 110 110 110 101 98 89
54637- 86 86 86 82 82 82 78 78 78 78 78 78
54638- 78 78 78 78 78 78 78 78 78 78 78 78
54639- 78 78 78 82 82 82 86 86 86 94 94 94
54640-106 106 106 101 101 101 86 66 34 124 80 6
54641-156 107 11 180 123 7 192 133 9 200 144 11
54642-206 145 10 200 144 11 192 133 9 175 118 6
54643-139 102 15 109 106 95 70 70 70 42 42 42
54644- 22 22 22 10 10 10 0 0 0 0 0 0
54645- 0 0 0 0 0 0 0 0 0 0 0 0
54646- 0 0 0 0 0 0 0 0 0 0 0 0
54647- 0 0 0 0 0 0 0 0 0 0 0 0
54648- 0 0 0 0 0 0 0 0 0 0 0 0
54649- 0 0 0 0 0 0 0 0 0 0 0 0
54650- 0 0 0 0 0 0 6 6 6 10 10 10
54651- 14 14 14 22 22 22 30 30 30 38 38 38
54652- 50 50 50 62 62 62 74 74 74 90 90 90
54653-101 98 89 112 100 78 121 87 25 124 80 6
54654-137 92 6 152 99 6 152 99 6 152 99 6
54655-138 86 6 124 80 6 98 70 6 86 66 30
54656-101 98 89 82 82 82 58 58 58 46 46 46
54657- 38 38 38 34 34 34 34 34 34 34 34 34
54658- 34 34 34 34 34 34 34 34 34 34 34 34
54659- 34 34 34 34 34 34 38 38 38 42 42 42
54660- 54 54 54 82 82 82 94 86 76 91 60 6
54661-134 86 6 156 107 11 167 114 7 175 118 6
54662-175 118 6 167 114 7 152 99 6 121 87 25
54663-101 98 89 62 62 62 34 34 34 18 18 18
54664- 6 6 6 0 0 0 0 0 0 0 0 0
54665- 0 0 0 0 0 0 0 0 0 0 0 0
54666- 0 0 0 0 0 0 0 0 0 0 0 0
54667- 0 0 0 0 0 0 0 0 0 0 0 0
54668- 0 0 0 0 0 0 0 0 0 0 0 0
54669- 0 0 0 0 0 0 0 0 0 0 0 0
54670- 0 0 0 0 0 0 0 0 0 0 0 0
54671- 0 0 0 6 6 6 6 6 6 10 10 10
54672- 18 18 18 22 22 22 30 30 30 42 42 42
54673- 50 50 50 66 66 66 86 86 86 101 98 89
54674-106 86 58 98 70 6 104 69 6 104 69 6
54675-104 69 6 91 60 6 82 62 34 90 90 90
54676- 62 62 62 38 38 38 22 22 22 14 14 14
54677- 10 10 10 10 10 10 10 10 10 10 10 10
54678- 10 10 10 10 10 10 6 6 6 10 10 10
54679- 10 10 10 10 10 10 10 10 10 14 14 14
54680- 22 22 22 42 42 42 70 70 70 89 81 66
54681- 80 54 7 104 69 6 124 80 6 137 92 6
54682-134 86 6 116 81 8 100 82 52 86 86 86
54683- 58 58 58 30 30 30 14 14 14 6 6 6
54684- 0 0 0 0 0 0 0 0 0 0 0 0
54685- 0 0 0 0 0 0 0 0 0 0 0 0
54686- 0 0 0 0 0 0 0 0 0 0 0 0
54687- 0 0 0 0 0 0 0 0 0 0 0 0
54688- 0 0 0 0 0 0 0 0 0 0 0 0
54689- 0 0 0 0 0 0 0 0 0 0 0 0
54690- 0 0 0 0 0 0 0 0 0 0 0 0
54691- 0 0 0 0 0 0 0 0 0 0 0 0
54692- 0 0 0 6 6 6 10 10 10 14 14 14
54693- 18 18 18 26 26 26 38 38 38 54 54 54
54694- 70 70 70 86 86 86 94 86 76 89 81 66
54695- 89 81 66 86 86 86 74 74 74 50 50 50
54696- 30 30 30 14 14 14 6 6 6 0 0 0
54697- 0 0 0 0 0 0 0 0 0 0 0 0
54698- 0 0 0 0 0 0 0 0 0 0 0 0
54699- 0 0 0 0 0 0 0 0 0 0 0 0
54700- 6 6 6 18 18 18 34 34 34 58 58 58
54701- 82 82 82 89 81 66 89 81 66 89 81 66
54702- 94 86 66 94 86 76 74 74 74 50 50 50
54703- 26 26 26 14 14 14 6 6 6 0 0 0
54704- 0 0 0 0 0 0 0 0 0 0 0 0
54705- 0 0 0 0 0 0 0 0 0 0 0 0
54706- 0 0 0 0 0 0 0 0 0 0 0 0
54707- 0 0 0 0 0 0 0 0 0 0 0 0
54708- 0 0 0 0 0 0 0 0 0 0 0 0
54709- 0 0 0 0 0 0 0 0 0 0 0 0
54710- 0 0 0 0 0 0 0 0 0 0 0 0
54711- 0 0 0 0 0 0 0 0 0 0 0 0
54712- 0 0 0 0 0 0 0 0 0 0 0 0
54713- 6 6 6 6 6 6 14 14 14 18 18 18
54714- 30 30 30 38 38 38 46 46 46 54 54 54
54715- 50 50 50 42 42 42 30 30 30 18 18 18
54716- 10 10 10 0 0 0 0 0 0 0 0 0
54717- 0 0 0 0 0 0 0 0 0 0 0 0
54718- 0 0 0 0 0 0 0 0 0 0 0 0
54719- 0 0 0 0 0 0 0 0 0 0 0 0
54720- 0 0 0 6 6 6 14 14 14 26 26 26
54721- 38 38 38 50 50 50 58 58 58 58 58 58
54722- 54 54 54 42 42 42 30 30 30 18 18 18
54723- 10 10 10 0 0 0 0 0 0 0 0 0
54724- 0 0 0 0 0 0 0 0 0 0 0 0
54725- 0 0 0 0 0 0 0 0 0 0 0 0
54726- 0 0 0 0 0 0 0 0 0 0 0 0
54727- 0 0 0 0 0 0 0 0 0 0 0 0
54728- 0 0 0 0 0 0 0 0 0 0 0 0
54729- 0 0 0 0 0 0 0 0 0 0 0 0
54730- 0 0 0 0 0 0 0 0 0 0 0 0
54731- 0 0 0 0 0 0 0 0 0 0 0 0
54732- 0 0 0 0 0 0 0 0 0 0 0 0
54733- 0 0 0 0 0 0 0 0 0 6 6 6
54734- 6 6 6 10 10 10 14 14 14 18 18 18
54735- 18 18 18 14 14 14 10 10 10 6 6 6
54736- 0 0 0 0 0 0 0 0 0 0 0 0
54737- 0 0 0 0 0 0 0 0 0 0 0 0
54738- 0 0 0 0 0 0 0 0 0 0 0 0
54739- 0 0 0 0 0 0 0 0 0 0 0 0
54740- 0 0 0 0 0 0 0 0 0 6 6 6
54741- 14 14 14 18 18 18 22 22 22 22 22 22
54742- 18 18 18 14 14 14 10 10 10 6 6 6
54743- 0 0 0 0 0 0 0 0 0 0 0 0
54744- 0 0 0 0 0 0 0 0 0 0 0 0
54745- 0 0 0 0 0 0 0 0 0 0 0 0
54746- 0 0 0 0 0 0 0 0 0 0 0 0
54747- 0 0 0 0 0 0 0 0 0 0 0 0
54748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54761+4 4 4 4 4 4
54762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54775+4 4 4 4 4 4
54776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54789+4 4 4 4 4 4
54790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54803+4 4 4 4 4 4
54804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54817+4 4 4 4 4 4
54818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54827+4 4 4 4 4 4 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 4 4 4
54829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54831+4 4 4 4 4 4
54832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54836+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54837+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54841+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54842+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54843+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54845+4 4 4 4 4 4
54846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54850+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54851+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54852+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54855+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54856+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54857+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54858+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54859+4 4 4 4 4 4
54860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54864+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54865+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54866+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54869+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54870+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54871+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54872+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54873+4 4 4 4 4 4
54874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54877+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54878+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54879+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54880+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54882+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54883+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54884+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54885+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54886+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54887+4 4 4 4 4 4
54888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54891+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54892+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54893+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54894+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54895+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54896+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54897+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54898+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54899+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54900+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54901+4 4 4 4 4 4
54902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54905+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54906+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54907+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54908+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54909+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54910+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54911+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54912+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54913+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54914+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54915+4 4 4 4 4 4
54916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54918+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54919+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54920+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54921+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54922+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54923+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54924+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54925+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54926+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54927+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54928+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54929+4 4 4 4 4 4
54930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54932+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54933+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54934+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54935+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54936+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54937+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54938+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54939+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54940+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54941+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54942+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54943+4 4 4 4 4 4
54944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54946+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54947+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54948+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54949+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54950+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54951+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54952+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54953+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54954+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54955+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54956+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54957+4 4 4 4 4 4
54958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54960+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54961+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54962+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54963+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54964+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54965+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54966+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54967+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54968+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54969+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54970+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54971+4 4 4 4 4 4
54972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54973+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54974+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54975+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54976+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54977+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54978+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54979+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54980+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54981+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54982+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54983+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54984+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54985+4 4 4 4 4 4
54986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54987+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54988+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54989+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54990+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54991+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54992+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54993+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54994+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54995+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54996+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54997+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54998+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54999+0 0 0 4 4 4
55000+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55001+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
55002+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
55003+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
55004+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
55005+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
55006+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
55007+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
55008+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
55009+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
55010+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
55011+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
55012+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
55013+2 0 0 0 0 0
55014+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
55015+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
55016+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
55017+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
55018+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
55019+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
55020+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
55021+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
55022+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
55023+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
55024+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
55025+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
55026+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
55027+37 38 37 0 0 0
55028+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55029+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
55030+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
55031+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
55032+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
55033+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
55034+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
55035+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
55036+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
55037+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
55038+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
55039+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
55040+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
55041+85 115 134 4 0 0
55042+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
55043+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
55044+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
55045+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
55046+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
55047+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
55048+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
55049+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
55050+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
55051+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
55052+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
55053+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
55054+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
55055+60 73 81 4 0 0
55056+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
55057+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
55058+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
55059+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
55060+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
55061+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
55062+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
55063+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
55064+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
55065+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
55066+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
55067+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
55068+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
55069+16 19 21 4 0 0
55070+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
55071+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
55072+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
55073+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
55074+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
55075+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55076+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55077+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55078+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55079+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55080+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55081+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55082+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55083+4 0 0 4 3 3
55084+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55085+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55086+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55088+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55089+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55090+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55091+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55092+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55093+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55094+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55095+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55096+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55097+3 2 2 4 4 4
55098+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55099+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55100+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55101+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55102+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55103+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55104+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55105+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55106+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55107+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55108+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55109+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55110+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55111+4 4 4 4 4 4
55112+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55113+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55114+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55115+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55116+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55117+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55118+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55119+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55120+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55121+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55122+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55123+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55124+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55125+4 4 4 4 4 4
55126+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55127+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55128+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55129+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55130+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55131+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55132+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55133+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55134+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55135+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55136+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55137+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55138+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55139+5 5 5 5 5 5
55140+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55141+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55142+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55143+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55144+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55145+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55146+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55147+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55148+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55149+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55150+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55151+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55152+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55153+5 5 5 4 4 4
55154+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55155+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55156+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55157+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55158+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55159+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55160+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55161+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55162+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55163+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55164+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55165+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55167+4 4 4 4 4 4
55168+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55169+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55170+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55171+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55172+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55173+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55174+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55175+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55176+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55177+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55178+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55179+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55181+4 4 4 4 4 4
55182+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55183+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55184+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55185+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55186+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55187+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55188+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55189+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55190+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55191+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55192+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55195+4 4 4 4 4 4
55196+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55197+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55198+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55199+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55200+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55201+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55202+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55203+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55204+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55205+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55206+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55209+4 4 4 4 4 4
55210+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55211+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55212+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55213+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55214+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55215+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55216+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55217+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55218+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55219+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55220+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55223+4 4 4 4 4 4
55224+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55225+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55226+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55227+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55228+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55229+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55230+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55231+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55232+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55233+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55234+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55237+4 4 4 4 4 4
55238+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55239+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55240+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55241+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55242+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55243+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55244+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55245+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55246+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55247+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55248+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55251+4 4 4 4 4 4
55252+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55253+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55254+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55255+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55256+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55257+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55258+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55259+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55260+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55261+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55262+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55265+4 4 4 4 4 4
55266+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55267+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55268+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55269+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55270+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55271+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55272+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55273+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55274+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55275+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55276+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55279+4 4 4 4 4 4
55280+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55281+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55282+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55283+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55284+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55285+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55286+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55287+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55288+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55289+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55290+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55293+4 4 4 4 4 4
55294+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55295+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55296+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55297+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55298+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55299+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55300+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55301+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55302+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55303+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55304+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55307+4 4 4 4 4 4
55308+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55309+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55310+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55311+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55312+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55313+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55314+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55315+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55316+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55317+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55318+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55321+4 4 4 4 4 4
55322+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55323+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55324+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55325+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55326+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55327+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55328+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55329+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55330+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55331+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55332+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55335+4 4 4 4 4 4
55336+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55337+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55338+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55339+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55340+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55341+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55342+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55343+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55344+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55345+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55346+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55349+4 4 4 4 4 4
55350+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55351+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55352+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55353+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55354+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55355+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55356+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55357+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55358+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55359+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55360+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55363+4 4 4 4 4 4
55364+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55365+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55366+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55367+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55368+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55369+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55370+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55371+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55372+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55373+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55374+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55377+4 4 4 4 4 4
55378+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55379+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55380+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55381+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55382+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55383+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55384+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55385+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55386+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55387+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55388+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55391+4 4 4 4 4 4
55392+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55393+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55394+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55395+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55396+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55397+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55398+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55399+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55400+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55401+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55402+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55405+4 4 4 4 4 4
55406+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55407+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55408+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55409+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55410+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55411+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55412+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55413+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55414+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55415+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55416+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55419+4 4 4 4 4 4
55420+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55421+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55422+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55423+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55424+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55425+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55426+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55427+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55428+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55429+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55430+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55433+4 4 4 4 4 4
55434+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55435+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55436+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55437+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55438+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55439+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55440+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55441+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55442+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55443+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55444+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55447+4 4 4 4 4 4
55448+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55449+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55450+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55451+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55452+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55453+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55454+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55455+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55456+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55457+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55458+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55461+4 4 4 4 4 4
55462+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55463+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55464+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55465+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55466+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55467+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55468+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55469+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55470+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55471+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55472+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55475+4 4 4 4 4 4
55476+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55477+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55478+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55479+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55480+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55481+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55482+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55483+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55484+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55485+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55486+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55489+4 4 4 4 4 4
55490+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55491+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55492+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55493+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55494+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55495+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55496+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55497+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55498+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55499+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55500+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55503+4 4 4 4 4 4
55504+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55505+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55506+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55507+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55508+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55509+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55510+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55511+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55512+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55513+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55514+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55517+4 4 4 4 4 4
55518+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55519+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55520+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55521+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55522+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55523+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55524+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55525+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55526+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55527+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55528+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55531+4 4 4 4 4 4
55532+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55533+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55534+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55535+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55536+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55537+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55538+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55539+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55540+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55541+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55542+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55545+4 4 4 4 4 4
55546+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55547+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55548+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55549+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55550+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55551+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55552+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55553+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55554+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55555+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55556+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55559+4 4 4 4 4 4
55560+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55561+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55562+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55563+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55564+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55565+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55566+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55567+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55568+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55569+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55573+4 4 4 4 4 4
55574+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55575+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55576+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55577+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55578+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55579+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55580+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55581+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55582+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55583+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55587+4 4 4 4 4 4
55588+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55589+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55590+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55591+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55592+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55593+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55594+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55595+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55596+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55597+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55601+4 4 4 4 4 4
55602+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55603+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55604+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55605+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55606+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55607+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55608+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55609+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55610+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55611+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55615+4 4 4 4 4 4
55616+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55617+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55618+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55619+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55620+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55621+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55622+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55623+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55624+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55629+4 4 4 4 4 4
55630+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55631+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55632+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55633+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55634+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55635+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55636+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55637+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55638+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55643+4 4 4 4 4 4
55644+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55645+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55646+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55647+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55648+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55649+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55650+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55651+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55652+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55657+4 4 4 4 4 4
55658+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55659+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55660+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55661+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55662+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55663+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55664+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55665+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55671+4 4 4 4 4 4
55672+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55673+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55674+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55675+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55676+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55677+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55678+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55679+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55685+4 4 4 4 4 4
55686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55687+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55688+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55689+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55690+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55691+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55692+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55693+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55699+4 4 4 4 4 4
55700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55701+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55702+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55703+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55704+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55705+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55706+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55707+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55713+4 4 4 4 4 4
55714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55715+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55716+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55717+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55718+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55719+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55720+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55721+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55727+4 4 4 4 4 4
55728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55730+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55731+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55732+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55733+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55734+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55735+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55741+4 4 4 4 4 4
55742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55745+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55746+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55747+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55748+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55755+4 4 4 4 4 4
55756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55759+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55760+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55761+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55762+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55769+4 4 4 4 4 4
55770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55773+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55774+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55775+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55776+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55783+4 4 4 4 4 4
55784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55787+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55788+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55789+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55790+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
55791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55797+4 4 4 4 4 4
55798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55802+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55803+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55804+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55811+4 4 4 4 4 4
55812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55816+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55817+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55818+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55825+4 4 4 4 4 4
55826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55830+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55831+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55832+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55839+4 4 4 4 4 4
55840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55844+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55845+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55853+4 4 4 4 4 4
55854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55858+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55859+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55867+4 4 4 4 4 4
55868diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55869index a01147f..5d896f8 100644
55870--- a/drivers/video/matrox/matroxfb_DAC1064.c
55871+++ b/drivers/video/matrox/matroxfb_DAC1064.c
55872@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55873
55874 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55875 struct matrox_switch matrox_mystique = {
55876- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55877+ .preinit = MGA1064_preinit,
55878+ .reset = MGA1064_reset,
55879+ .init = MGA1064_init,
55880+ .restore = MGA1064_restore,
55881 };
55882 EXPORT_SYMBOL(matrox_mystique);
55883 #endif
55884
55885 #ifdef CONFIG_FB_MATROX_G
55886 struct matrox_switch matrox_G100 = {
55887- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55888+ .preinit = MGAG100_preinit,
55889+ .reset = MGAG100_reset,
55890+ .init = MGAG100_init,
55891+ .restore = MGAG100_restore,
55892 };
55893 EXPORT_SYMBOL(matrox_G100);
55894 #endif
55895diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55896index 195ad7c..09743fc 100644
55897--- a/drivers/video/matrox/matroxfb_Ti3026.c
55898+++ b/drivers/video/matrox/matroxfb_Ti3026.c
55899@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55900 }
55901
55902 struct matrox_switch matrox_millennium = {
55903- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55904+ .preinit = Ti3026_preinit,
55905+ .reset = Ti3026_reset,
55906+ .init = Ti3026_init,
55907+ .restore = Ti3026_restore
55908 };
55909 EXPORT_SYMBOL(matrox_millennium);
55910 #endif
55911diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55912index fe92eed..106e085 100644
55913--- a/drivers/video/mb862xx/mb862xxfb_accel.c
55914+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55915@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55916 struct mb862xxfb_par *par = info->par;
55917
55918 if (info->var.bits_per_pixel == 32) {
55919- info->fbops->fb_fillrect = cfb_fillrect;
55920- info->fbops->fb_copyarea = cfb_copyarea;
55921- info->fbops->fb_imageblit = cfb_imageblit;
55922+ pax_open_kernel();
55923+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55924+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55925+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55926+ pax_close_kernel();
55927 } else {
55928 outreg(disp, GC_L0EM, 3);
55929- info->fbops->fb_fillrect = mb86290fb_fillrect;
55930- info->fbops->fb_copyarea = mb86290fb_copyarea;
55931- info->fbops->fb_imageblit = mb86290fb_imageblit;
55932+ pax_open_kernel();
55933+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55934+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55935+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55936+ pax_close_kernel();
55937 }
55938 outreg(draw, GDC_REG_DRAW_BASE, 0);
55939 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55940diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55941index def0412..fed6529 100644
55942--- a/drivers/video/nvidia/nvidia.c
55943+++ b/drivers/video/nvidia/nvidia.c
55944@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55945 info->fix.line_length = (info->var.xres_virtual *
55946 info->var.bits_per_pixel) >> 3;
55947 if (info->var.accel_flags) {
55948- info->fbops->fb_imageblit = nvidiafb_imageblit;
55949- info->fbops->fb_fillrect = nvidiafb_fillrect;
55950- info->fbops->fb_copyarea = nvidiafb_copyarea;
55951- info->fbops->fb_sync = nvidiafb_sync;
55952+ pax_open_kernel();
55953+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55954+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55955+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55956+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55957+ pax_close_kernel();
55958 info->pixmap.scan_align = 4;
55959 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55960 info->flags |= FBINFO_READS_FAST;
55961 NVResetGraphics(info);
55962 } else {
55963- info->fbops->fb_imageblit = cfb_imageblit;
55964- info->fbops->fb_fillrect = cfb_fillrect;
55965- info->fbops->fb_copyarea = cfb_copyarea;
55966- info->fbops->fb_sync = NULL;
55967+ pax_open_kernel();
55968+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55969+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55970+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55971+ *(void **)&info->fbops->fb_sync = NULL;
55972+ pax_close_kernel();
55973 info->pixmap.scan_align = 1;
55974 info->flags |= FBINFO_HWACCEL_DISABLED;
55975 info->flags &= ~FBINFO_READS_FAST;
55976@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55977 info->pixmap.size = 8 * 1024;
55978 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55979
55980- if (!hwcur)
55981- info->fbops->fb_cursor = NULL;
55982+ if (!hwcur) {
55983+ pax_open_kernel();
55984+ *(void **)&info->fbops->fb_cursor = NULL;
55985+ pax_close_kernel();
55986+ }
55987
55988 info->var.accel_flags = (!noaccel);
55989
55990diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55991index 669a81f..e216d76 100644
55992--- a/drivers/video/omap2/dss/display.c
55993+++ b/drivers/video/omap2/dss/display.c
55994@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55995 snprintf(dssdev->alias, sizeof(dssdev->alias),
55996 "display%d", disp_num_counter++);
55997
55998+ pax_open_kernel();
55999 if (drv && drv->get_resolution == NULL)
56000- drv->get_resolution = omapdss_default_get_resolution;
56001+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
56002 if (drv && drv->get_recommended_bpp == NULL)
56003- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
56004+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
56005 if (drv && drv->get_timings == NULL)
56006- drv->get_timings = omapdss_default_get_timings;
56007+ *(void **)&drv->get_timings = omapdss_default_get_timings;
56008+ pax_close_kernel();
56009
56010 mutex_lock(&panel_list_mutex);
56011 list_add_tail(&dssdev->panel_list, &panel_list);
56012diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
56013index 83433cb..71e9b98 100644
56014--- a/drivers/video/s1d13xxxfb.c
56015+++ b/drivers/video/s1d13xxxfb.c
56016@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
56017
56018 switch(prod_id) {
56019 case S1D13506_PROD_ID: /* activate acceleration */
56020- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
56021- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
56022+ pax_open_kernel();
56023+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
56024+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
56025+ pax_close_kernel();
56026 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
56027 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
56028 break;
56029diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
56030index 2bcc84a..29dd1ea 100644
56031--- a/drivers/video/sh_mobile_lcdcfb.c
56032+++ b/drivers/video/sh_mobile_lcdcfb.c
56033@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
56034 }
56035
56036 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
56037- lcdc_sys_write_index,
56038- lcdc_sys_write_data,
56039- lcdc_sys_read_data,
56040+ .write_index = lcdc_sys_write_index,
56041+ .write_data = lcdc_sys_write_data,
56042+ .read_data = lcdc_sys_read_data,
56043 };
56044
56045 static int sh_mobile_lcdc_sginit(struct fb_info *info,
56046diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
56047index d513ed6..90b0de9 100644
56048--- a/drivers/video/smscufx.c
56049+++ b/drivers/video/smscufx.c
56050@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
56051 fb_deferred_io_cleanup(info);
56052 kfree(info->fbdefio);
56053 info->fbdefio = NULL;
56054- info->fbops->fb_mmap = ufx_ops_mmap;
56055+ pax_open_kernel();
56056+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
56057+ pax_close_kernel();
56058 }
56059
56060 pr_debug("released /dev/fb%d user=%d count=%d",
56061diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
56062index 77b890e..458e666 100644
56063--- a/drivers/video/udlfb.c
56064+++ b/drivers/video/udlfb.c
56065@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
56066 dlfb_urb_completion(urb);
56067
56068 error:
56069- atomic_add(bytes_sent, &dev->bytes_sent);
56070- atomic_add(bytes_identical, &dev->bytes_identical);
56071- atomic_add(width*height*2, &dev->bytes_rendered);
56072+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56073+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56074+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
56075 end_cycles = get_cycles();
56076- atomic_add(((unsigned int) ((end_cycles - start_cycles)
56077+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56078 >> 10)), /* Kcycles */
56079 &dev->cpu_kcycles_used);
56080
56081@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
56082 dlfb_urb_completion(urb);
56083
56084 error:
56085- atomic_add(bytes_sent, &dev->bytes_sent);
56086- atomic_add(bytes_identical, &dev->bytes_identical);
56087- atomic_add(bytes_rendered, &dev->bytes_rendered);
56088+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56089+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56090+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
56091 end_cycles = get_cycles();
56092- atomic_add(((unsigned int) ((end_cycles - start_cycles)
56093+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56094 >> 10)), /* Kcycles */
56095 &dev->cpu_kcycles_used);
56096 }
56097@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
56098 fb_deferred_io_cleanup(info);
56099 kfree(info->fbdefio);
56100 info->fbdefio = NULL;
56101- info->fbops->fb_mmap = dlfb_ops_mmap;
56102+ pax_open_kernel();
56103+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
56104+ pax_close_kernel();
56105 }
56106
56107 pr_warn("released /dev/fb%d user=%d count=%d\n",
56108@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
56109 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56110 struct dlfb_data *dev = fb_info->par;
56111 return snprintf(buf, PAGE_SIZE, "%u\n",
56112- atomic_read(&dev->bytes_rendered));
56113+ atomic_read_unchecked(&dev->bytes_rendered));
56114 }
56115
56116 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56117@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56118 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56119 struct dlfb_data *dev = fb_info->par;
56120 return snprintf(buf, PAGE_SIZE, "%u\n",
56121- atomic_read(&dev->bytes_identical));
56122+ atomic_read_unchecked(&dev->bytes_identical));
56123 }
56124
56125 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56126@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56127 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56128 struct dlfb_data *dev = fb_info->par;
56129 return snprintf(buf, PAGE_SIZE, "%u\n",
56130- atomic_read(&dev->bytes_sent));
56131+ atomic_read_unchecked(&dev->bytes_sent));
56132 }
56133
56134 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56135@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56136 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56137 struct dlfb_data *dev = fb_info->par;
56138 return snprintf(buf, PAGE_SIZE, "%u\n",
56139- atomic_read(&dev->cpu_kcycles_used));
56140+ atomic_read_unchecked(&dev->cpu_kcycles_used));
56141 }
56142
56143 static ssize_t edid_show(
56144@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
56145 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56146 struct dlfb_data *dev = fb_info->par;
56147
56148- atomic_set(&dev->bytes_rendered, 0);
56149- atomic_set(&dev->bytes_identical, 0);
56150- atomic_set(&dev->bytes_sent, 0);
56151- atomic_set(&dev->cpu_kcycles_used, 0);
56152+ atomic_set_unchecked(&dev->bytes_rendered, 0);
56153+ atomic_set_unchecked(&dev->bytes_identical, 0);
56154+ atomic_set_unchecked(&dev->bytes_sent, 0);
56155+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
56156
56157 return count;
56158 }
56159diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
56160index 256fba7..6e75516 100644
56161--- a/drivers/video/uvesafb.c
56162+++ b/drivers/video/uvesafb.c
56163@@ -19,6 +19,7 @@
56164 #include <linux/io.h>
56165 #include <linux/mutex.h>
56166 #include <linux/slab.h>
56167+#include <linux/moduleloader.h>
56168 #include <video/edid.h>
56169 #include <video/uvesafb.h>
56170 #ifdef CONFIG_X86
56171@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
56172 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
56173 par->pmi_setpal = par->ypan = 0;
56174 } else {
56175+
56176+#ifdef CONFIG_PAX_KERNEXEC
56177+#ifdef CONFIG_MODULES
56178+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
56179+#endif
56180+ if (!par->pmi_code) {
56181+ par->pmi_setpal = par->ypan = 0;
56182+ return 0;
56183+ }
56184+#endif
56185+
56186 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
56187 + task->t.regs.edi);
56188+
56189+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56190+ pax_open_kernel();
56191+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
56192+ pax_close_kernel();
56193+
56194+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
56195+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
56196+#else
56197 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
56198 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
56199+#endif
56200+
56201 printk(KERN_INFO "uvesafb: protected mode interface info at "
56202 "%04x:%04x\n",
56203 (u16)task->t.regs.es, (u16)task->t.regs.edi);
56204@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
56205 par->ypan = ypan;
56206
56207 if (par->pmi_setpal || par->ypan) {
56208+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
56209 if (__supported_pte_mask & _PAGE_NX) {
56210 par->pmi_setpal = par->ypan = 0;
56211 printk(KERN_WARNING "uvesafb: NX protection is active, "
56212 "better not use the PMI.\n");
56213- } else {
56214+ } else
56215+#endif
56216 uvesafb_vbe_getpmi(task, par);
56217- }
56218 }
56219 #else
56220 /* The protected mode interface is not available on non-x86. */
56221@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56222 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
56223
56224 /* Disable blanking if the user requested so. */
56225- if (!blank)
56226- info->fbops->fb_blank = NULL;
56227+ if (!blank) {
56228+ pax_open_kernel();
56229+ *(void **)&info->fbops->fb_blank = NULL;
56230+ pax_close_kernel();
56231+ }
56232
56233 /*
56234 * Find out how much IO memory is required for the mode with
56235@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56236 info->flags = FBINFO_FLAG_DEFAULT |
56237 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
56238
56239- if (!par->ypan)
56240- info->fbops->fb_pan_display = NULL;
56241+ if (!par->ypan) {
56242+ pax_open_kernel();
56243+ *(void **)&info->fbops->fb_pan_display = NULL;
56244+ pax_close_kernel();
56245+ }
56246 }
56247
56248 static void uvesafb_init_mtrr(struct fb_info *info)
56249@@ -1792,6 +1822,11 @@ out_mode:
56250 out:
56251 kfree(par->vbe_modes);
56252
56253+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56254+ if (par->pmi_code)
56255+ module_free_exec(NULL, par->pmi_code);
56256+#endif
56257+
56258 framebuffer_release(info);
56259 return err;
56260 }
56261@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
56262 kfree(par->vbe_modes);
56263 kfree(par->vbe_state_orig);
56264 kfree(par->vbe_state_saved);
56265+
56266+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56267+ if (par->pmi_code)
56268+ module_free_exec(NULL, par->pmi_code);
56269+#endif
56270+
56271 }
56272
56273 framebuffer_release(info);
56274diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
56275index 1c7da3b..56ea0bd 100644
56276--- a/drivers/video/vesafb.c
56277+++ b/drivers/video/vesafb.c
56278@@ -9,6 +9,7 @@
56279 */
56280
56281 #include <linux/module.h>
56282+#include <linux/moduleloader.h>
56283 #include <linux/kernel.h>
56284 #include <linux/errno.h>
56285 #include <linux/string.h>
56286@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
56287 static int vram_total; /* Set total amount of memory */
56288 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
56289 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
56290-static void (*pmi_start)(void) __read_mostly;
56291-static void (*pmi_pal) (void) __read_mostly;
56292+static void (*pmi_start)(void) __read_only;
56293+static void (*pmi_pal) (void) __read_only;
56294 static int depth __read_mostly;
56295 static int vga_compat __read_mostly;
56296 /* --------------------------------------------------------------------- */
56297@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
56298 unsigned int size_remap;
56299 unsigned int size_total;
56300 char *option = NULL;
56301+ void *pmi_code = NULL;
56302
56303 /* ignore error return of fb_get_options */
56304 fb_get_options("vesafb", &option);
56305@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
56306 size_remap = size_total;
56307 vesafb_fix.smem_len = size_remap;
56308
56309-#ifndef __i386__
56310- screen_info.vesapm_seg = 0;
56311-#endif
56312-
56313 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
56314 printk(KERN_WARNING
56315 "vesafb: cannot reserve video memory at 0x%lx\n",
56316@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
56317 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
56318 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
56319
56320+#ifdef __i386__
56321+
56322+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56323+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
56324+ if (!pmi_code)
56325+#elif !defined(CONFIG_PAX_KERNEXEC)
56326+ if (0)
56327+#endif
56328+
56329+#endif
56330+ screen_info.vesapm_seg = 0;
56331+
56332 if (screen_info.vesapm_seg) {
56333- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
56334- screen_info.vesapm_seg,screen_info.vesapm_off);
56335+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
56336+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
56337 }
56338
56339 if (screen_info.vesapm_seg < 0xc000)
56340@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
56341
56342 if (ypan || pmi_setpal) {
56343 unsigned short *pmi_base;
56344+
56345 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
56346- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
56347- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
56348+
56349+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56350+ pax_open_kernel();
56351+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
56352+#else
56353+ pmi_code = pmi_base;
56354+#endif
56355+
56356+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
56357+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
56358+
56359+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56360+ pmi_start = ktva_ktla(pmi_start);
56361+ pmi_pal = ktva_ktla(pmi_pal);
56362+ pax_close_kernel();
56363+#endif
56364+
56365 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
56366 if (pmi_base[3]) {
56367 printk(KERN_INFO "vesafb: pmi: ports = ");
56368@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
56369 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
56370 (ypan ? FBINFO_HWACCEL_YPAN : 0);
56371
56372- if (!ypan)
56373- info->fbops->fb_pan_display = NULL;
56374+ if (!ypan) {
56375+ pax_open_kernel();
56376+ *(void **)&info->fbops->fb_pan_display = NULL;
56377+ pax_close_kernel();
56378+ }
56379
56380 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
56381 err = -ENOMEM;
56382@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
56383 fb_info(info, "%s frame buffer device\n", info->fix.id);
56384 return 0;
56385 err:
56386+
56387+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56388+ module_free_exec(NULL, pmi_code);
56389+#endif
56390+
56391 if (info->screen_base)
56392 iounmap(info->screen_base);
56393 framebuffer_release(info);
56394diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
56395index 88714ae..16c2e11 100644
56396--- a/drivers/video/via/via_clock.h
56397+++ b/drivers/video/via/via_clock.h
56398@@ -56,7 +56,7 @@ struct via_clock {
56399
56400 void (*set_engine_pll_state)(u8 state);
56401 void (*set_engine_pll)(struct via_pll_config config);
56402-};
56403+} __no_const;
56404
56405
56406 static inline u32 get_pll_internal_frequency(u32 ref_freq,
56407diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
56408index fef20db..d28b1ab 100644
56409--- a/drivers/xen/xenfs/xenstored.c
56410+++ b/drivers/xen/xenfs/xenstored.c
56411@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
56412 static int xsd_kva_open(struct inode *inode, struct file *file)
56413 {
56414 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
56415+#ifdef CONFIG_GRKERNSEC_HIDESYM
56416+ NULL);
56417+#else
56418 xen_store_interface);
56419+#endif
56420+
56421 if (!file->private_data)
56422 return -ENOMEM;
56423 return 0;
56424diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
56425index c71e886..61d3d44b 100644
56426--- a/fs/9p/vfs_addr.c
56427+++ b/fs/9p/vfs_addr.c
56428@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
56429
56430 retval = v9fs_file_write_internal(inode,
56431 v9inode->writeback_fid,
56432- (__force const char __user *)buffer,
56433+ (const char __force_user *)buffer,
56434 len, &offset, 0);
56435 if (retval > 0)
56436 retval = 0;
56437diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
56438index bb7991c..481e21a 100644
56439--- a/fs/9p/vfs_inode.c
56440+++ b/fs/9p/vfs_inode.c
56441@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56442 void
56443 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56444 {
56445- char *s = nd_get_link(nd);
56446+ const char *s = nd_get_link(nd);
56447
56448 p9_debug(P9_DEBUG_VFS, " %s %s\n",
56449 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
56450diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
56451index 370b24c..ff0be7b 100644
56452--- a/fs/Kconfig.binfmt
56453+++ b/fs/Kconfig.binfmt
56454@@ -103,7 +103,7 @@ config HAVE_AOUT
56455
56456 config BINFMT_AOUT
56457 tristate "Kernel support for a.out and ECOFF binaries"
56458- depends on HAVE_AOUT
56459+ depends on HAVE_AOUT && BROKEN
56460 ---help---
56461 A.out (Assembler.OUTput) is a set of formats for libraries and
56462 executables used in the earliest versions of UNIX. Linux used
56463diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56464index ce25d75..dc09eeb 100644
56465--- a/fs/afs/inode.c
56466+++ b/fs/afs/inode.c
56467@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56468 struct afs_vnode *vnode;
56469 struct super_block *sb;
56470 struct inode *inode;
56471- static atomic_t afs_autocell_ino;
56472+ static atomic_unchecked_t afs_autocell_ino;
56473
56474 _enter("{%x:%u},%*.*s,",
56475 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56476@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56477 data.fid.unique = 0;
56478 data.fid.vnode = 0;
56479
56480- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56481+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56482 afs_iget5_autocell_test, afs_iget5_set,
56483 &data);
56484 if (!inode) {
56485diff --git a/fs/aio.c b/fs/aio.c
56486index 04cd768..25949c1 100644
56487--- a/fs/aio.c
56488+++ b/fs/aio.c
56489@@ -375,7 +375,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56490 size += sizeof(struct io_event) * nr_events;
56491
56492 nr_pages = PFN_UP(size);
56493- if (nr_pages < 0)
56494+ if (nr_pages <= 0)
56495 return -EINVAL;
56496
56497 file = aio_private_file(ctx, nr_pages);
56498diff --git a/fs/attr.c b/fs/attr.c
56499index 6530ced..4a827e2 100644
56500--- a/fs/attr.c
56501+++ b/fs/attr.c
56502@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56503 unsigned long limit;
56504
56505 limit = rlimit(RLIMIT_FSIZE);
56506+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56507 if (limit != RLIM_INFINITY && offset > limit)
56508 goto out_sig;
56509 if (offset > inode->i_sb->s_maxbytes)
56510diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56511index 116fd38..c04182da 100644
56512--- a/fs/autofs4/waitq.c
56513+++ b/fs/autofs4/waitq.c
56514@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56515 {
56516 unsigned long sigpipe, flags;
56517 mm_segment_t fs;
56518- const char *data = (const char *)addr;
56519+ const char __user *data = (const char __force_user *)addr;
56520 ssize_t wr = 0;
56521
56522 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56523@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56524 return 1;
56525 }
56526
56527+#ifdef CONFIG_GRKERNSEC_HIDESYM
56528+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56529+#endif
56530+
56531 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56532 enum autofs_notify notify)
56533 {
56534@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56535
56536 /* If this is a direct mount request create a dummy name */
56537 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56538+#ifdef CONFIG_GRKERNSEC_HIDESYM
56539+ /* this name does get written to userland via autofs4_write() */
56540+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56541+#else
56542 qstr.len = sprintf(name, "%p", dentry);
56543+#endif
56544 else {
56545 qstr.len = autofs4_getpath(sbi, dentry, &name);
56546 if (!qstr.len) {
56547diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56548index 2722387..56059b5 100644
56549--- a/fs/befs/endian.h
56550+++ b/fs/befs/endian.h
56551@@ -11,7 +11,7 @@
56552
56553 #include <asm/byteorder.h>
56554
56555-static inline u64
56556+static inline u64 __intentional_overflow(-1)
56557 fs64_to_cpu(const struct super_block *sb, fs64 n)
56558 {
56559 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56560@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56561 return (__force fs64)cpu_to_be64(n);
56562 }
56563
56564-static inline u32
56565+static inline u32 __intentional_overflow(-1)
56566 fs32_to_cpu(const struct super_block *sb, fs32 n)
56567 {
56568 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56569@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56570 return (__force fs32)cpu_to_be32(n);
56571 }
56572
56573-static inline u16
56574+static inline u16 __intentional_overflow(-1)
56575 fs16_to_cpu(const struct super_block *sb, fs16 n)
56576 {
56577 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56578diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56579index ca0ba15..0fa3257 100644
56580--- a/fs/binfmt_aout.c
56581+++ b/fs/binfmt_aout.c
56582@@ -16,6 +16,7 @@
56583 #include <linux/string.h>
56584 #include <linux/fs.h>
56585 #include <linux/file.h>
56586+#include <linux/security.h>
56587 #include <linux/stat.h>
56588 #include <linux/fcntl.h>
56589 #include <linux/ptrace.h>
56590@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56591 #endif
56592 # define START_STACK(u) ((void __user *)u.start_stack)
56593
56594+ memset(&dump, 0, sizeof(dump));
56595+
56596 fs = get_fs();
56597 set_fs(KERNEL_DS);
56598 has_dumped = 1;
56599@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56600
56601 /* If the size of the dump file exceeds the rlimit, then see what would happen
56602 if we wrote the stack, but not the data area. */
56603+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56604 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56605 dump.u_dsize = 0;
56606
56607 /* Make sure we have enough room to write the stack and data areas. */
56608+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56609 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56610 dump.u_ssize = 0;
56611
56612@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56613 rlim = rlimit(RLIMIT_DATA);
56614 if (rlim >= RLIM_INFINITY)
56615 rlim = ~0;
56616+
56617+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56618 if (ex.a_data + ex.a_bss > rlim)
56619 return -ENOMEM;
56620
56621@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56622
56623 install_exec_creds(bprm);
56624
56625+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56626+ current->mm->pax_flags = 0UL;
56627+#endif
56628+
56629+#ifdef CONFIG_PAX_PAGEEXEC
56630+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56631+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56632+
56633+#ifdef CONFIG_PAX_EMUTRAMP
56634+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56635+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56636+#endif
56637+
56638+#ifdef CONFIG_PAX_MPROTECT
56639+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56640+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56641+#endif
56642+
56643+ }
56644+#endif
56645+
56646 if (N_MAGIC(ex) == OMAGIC) {
56647 unsigned long text_addr, map_size;
56648 loff_t pos;
56649@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56650 }
56651
56652 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56653- PROT_READ | PROT_WRITE | PROT_EXEC,
56654+ PROT_READ | PROT_WRITE,
56655 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56656 fd_offset + ex.a_text);
56657 if (error != N_DATADDR(ex)) {
56658diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56659index 67be295..83e2f86 100644
56660--- a/fs/binfmt_elf.c
56661+++ b/fs/binfmt_elf.c
56662@@ -34,6 +34,7 @@
56663 #include <linux/utsname.h>
56664 #include <linux/coredump.h>
56665 #include <linux/sched.h>
56666+#include <linux/xattr.h>
56667 #include <asm/uaccess.h>
56668 #include <asm/param.h>
56669 #include <asm/page.h>
56670@@ -48,7 +49,7 @@
56671 static int load_elf_binary(struct linux_binprm *bprm);
56672 static int load_elf_library(struct file *);
56673 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56674- int, int, unsigned long);
56675+ int, int, unsigned long) __intentional_overflow(-1);
56676
56677 /*
56678 * If we don't support core dumping, then supply a NULL so we
56679@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56680 #define elf_core_dump NULL
56681 #endif
56682
56683+#ifdef CONFIG_PAX_MPROTECT
56684+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56685+#endif
56686+
56687+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56688+static void elf_handle_mmap(struct file *file);
56689+#endif
56690+
56691 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56692 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56693 #else
56694@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56695 .load_binary = load_elf_binary,
56696 .load_shlib = load_elf_library,
56697 .core_dump = elf_core_dump,
56698+
56699+#ifdef CONFIG_PAX_MPROTECT
56700+ .handle_mprotect= elf_handle_mprotect,
56701+#endif
56702+
56703+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56704+ .handle_mmap = elf_handle_mmap,
56705+#endif
56706+
56707 .min_coredump = ELF_EXEC_PAGESIZE,
56708 };
56709
56710@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56711
56712 static int set_brk(unsigned long start, unsigned long end)
56713 {
56714+ unsigned long e = end;
56715+
56716 start = ELF_PAGEALIGN(start);
56717 end = ELF_PAGEALIGN(end);
56718 if (end > start) {
56719@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56720 if (BAD_ADDR(addr))
56721 return addr;
56722 }
56723- current->mm->start_brk = current->mm->brk = end;
56724+ current->mm->start_brk = current->mm->brk = e;
56725 return 0;
56726 }
56727
56728@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56729 elf_addr_t __user *u_rand_bytes;
56730 const char *k_platform = ELF_PLATFORM;
56731 const char *k_base_platform = ELF_BASE_PLATFORM;
56732- unsigned char k_rand_bytes[16];
56733+ u32 k_rand_bytes[4];
56734 int items;
56735 elf_addr_t *elf_info;
56736 int ei_index = 0;
56737 const struct cred *cred = current_cred();
56738 struct vm_area_struct *vma;
56739+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56740
56741 /*
56742 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56743@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56744 * Generate 16 random bytes for userspace PRNG seeding.
56745 */
56746 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56747- u_rand_bytes = (elf_addr_t __user *)
56748- STACK_ALLOC(p, sizeof(k_rand_bytes));
56749+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56750+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56751+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56752+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56753+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56754+ u_rand_bytes = (elf_addr_t __user *) p;
56755 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56756 return -EFAULT;
56757
56758@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56759 return -EFAULT;
56760 current->mm->env_end = p;
56761
56762+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56763+
56764 /* Put the elf_info on the stack in the right place. */
56765 sp = (elf_addr_t __user *)envp + 1;
56766- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56767+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56768 return -EFAULT;
56769 return 0;
56770 }
56771@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56772 an ELF header */
56773
56774 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56775- struct file *interpreter, unsigned long *interp_map_addr,
56776- unsigned long no_base)
56777+ struct file *interpreter, unsigned long no_base)
56778 {
56779 struct elf_phdr *elf_phdata;
56780 struct elf_phdr *eppnt;
56781- unsigned long load_addr = 0;
56782+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56783 int load_addr_set = 0;
56784 unsigned long last_bss = 0, elf_bss = 0;
56785- unsigned long error = ~0UL;
56786+ unsigned long error = -EINVAL;
56787 unsigned long total_size;
56788 int retval, i, size;
56789
56790@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56791 goto out_close;
56792 }
56793
56794+#ifdef CONFIG_PAX_SEGMEXEC
56795+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56796+ pax_task_size = SEGMEXEC_TASK_SIZE;
56797+#endif
56798+
56799 eppnt = elf_phdata;
56800 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56801 if (eppnt->p_type == PT_LOAD) {
56802@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56803 map_addr = elf_map(interpreter, load_addr + vaddr,
56804 eppnt, elf_prot, elf_type, total_size);
56805 total_size = 0;
56806- if (!*interp_map_addr)
56807- *interp_map_addr = map_addr;
56808 error = map_addr;
56809 if (BAD_ADDR(map_addr))
56810 goto out_close;
56811@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56812 k = load_addr + eppnt->p_vaddr;
56813 if (BAD_ADDR(k) ||
56814 eppnt->p_filesz > eppnt->p_memsz ||
56815- eppnt->p_memsz > TASK_SIZE ||
56816- TASK_SIZE - eppnt->p_memsz < k) {
56817+ eppnt->p_memsz > pax_task_size ||
56818+ pax_task_size - eppnt->p_memsz < k) {
56819 error = -ENOMEM;
56820 goto out_close;
56821 }
56822@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56823 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56824
56825 /* Map the last of the bss segment */
56826- error = vm_brk(elf_bss, last_bss - elf_bss);
56827- if (BAD_ADDR(error))
56828- goto out_close;
56829+ if (last_bss > elf_bss) {
56830+ error = vm_brk(elf_bss, last_bss - elf_bss);
56831+ if (BAD_ADDR(error))
56832+ goto out_close;
56833+ }
56834 }
56835
56836 error = load_addr;
56837@@ -538,6 +569,336 @@ out:
56838 return error;
56839 }
56840
56841+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56842+#ifdef CONFIG_PAX_SOFTMODE
56843+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56844+{
56845+ unsigned long pax_flags = 0UL;
56846+
56847+#ifdef CONFIG_PAX_PAGEEXEC
56848+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56849+ pax_flags |= MF_PAX_PAGEEXEC;
56850+#endif
56851+
56852+#ifdef CONFIG_PAX_SEGMEXEC
56853+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56854+ pax_flags |= MF_PAX_SEGMEXEC;
56855+#endif
56856+
56857+#ifdef CONFIG_PAX_EMUTRAMP
56858+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56859+ pax_flags |= MF_PAX_EMUTRAMP;
56860+#endif
56861+
56862+#ifdef CONFIG_PAX_MPROTECT
56863+ if (elf_phdata->p_flags & PF_MPROTECT)
56864+ pax_flags |= MF_PAX_MPROTECT;
56865+#endif
56866+
56867+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56868+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56869+ pax_flags |= MF_PAX_RANDMMAP;
56870+#endif
56871+
56872+ return pax_flags;
56873+}
56874+#endif
56875+
56876+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56877+{
56878+ unsigned long pax_flags = 0UL;
56879+
56880+#ifdef CONFIG_PAX_PAGEEXEC
56881+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56882+ pax_flags |= MF_PAX_PAGEEXEC;
56883+#endif
56884+
56885+#ifdef CONFIG_PAX_SEGMEXEC
56886+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56887+ pax_flags |= MF_PAX_SEGMEXEC;
56888+#endif
56889+
56890+#ifdef CONFIG_PAX_EMUTRAMP
56891+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56892+ pax_flags |= MF_PAX_EMUTRAMP;
56893+#endif
56894+
56895+#ifdef CONFIG_PAX_MPROTECT
56896+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56897+ pax_flags |= MF_PAX_MPROTECT;
56898+#endif
56899+
56900+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56901+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56902+ pax_flags |= MF_PAX_RANDMMAP;
56903+#endif
56904+
56905+ return pax_flags;
56906+}
56907+#endif
56908+
56909+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56910+#ifdef CONFIG_PAX_SOFTMODE
56911+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56912+{
56913+ unsigned long pax_flags = 0UL;
56914+
56915+#ifdef CONFIG_PAX_PAGEEXEC
56916+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56917+ pax_flags |= MF_PAX_PAGEEXEC;
56918+#endif
56919+
56920+#ifdef CONFIG_PAX_SEGMEXEC
56921+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56922+ pax_flags |= MF_PAX_SEGMEXEC;
56923+#endif
56924+
56925+#ifdef CONFIG_PAX_EMUTRAMP
56926+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56927+ pax_flags |= MF_PAX_EMUTRAMP;
56928+#endif
56929+
56930+#ifdef CONFIG_PAX_MPROTECT
56931+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56932+ pax_flags |= MF_PAX_MPROTECT;
56933+#endif
56934+
56935+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56936+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56937+ pax_flags |= MF_PAX_RANDMMAP;
56938+#endif
56939+
56940+ return pax_flags;
56941+}
56942+#endif
56943+
56944+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56945+{
56946+ unsigned long pax_flags = 0UL;
56947+
56948+#ifdef CONFIG_PAX_PAGEEXEC
56949+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56950+ pax_flags |= MF_PAX_PAGEEXEC;
56951+#endif
56952+
56953+#ifdef CONFIG_PAX_SEGMEXEC
56954+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56955+ pax_flags |= MF_PAX_SEGMEXEC;
56956+#endif
56957+
56958+#ifdef CONFIG_PAX_EMUTRAMP
56959+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56960+ pax_flags |= MF_PAX_EMUTRAMP;
56961+#endif
56962+
56963+#ifdef CONFIG_PAX_MPROTECT
56964+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56965+ pax_flags |= MF_PAX_MPROTECT;
56966+#endif
56967+
56968+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56969+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56970+ pax_flags |= MF_PAX_RANDMMAP;
56971+#endif
56972+
56973+ return pax_flags;
56974+}
56975+#endif
56976+
56977+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56978+static unsigned long pax_parse_defaults(void)
56979+{
56980+ unsigned long pax_flags = 0UL;
56981+
56982+#ifdef CONFIG_PAX_SOFTMODE
56983+ if (pax_softmode)
56984+ return pax_flags;
56985+#endif
56986+
56987+#ifdef CONFIG_PAX_PAGEEXEC
56988+ pax_flags |= MF_PAX_PAGEEXEC;
56989+#endif
56990+
56991+#ifdef CONFIG_PAX_SEGMEXEC
56992+ pax_flags |= MF_PAX_SEGMEXEC;
56993+#endif
56994+
56995+#ifdef CONFIG_PAX_MPROTECT
56996+ pax_flags |= MF_PAX_MPROTECT;
56997+#endif
56998+
56999+#ifdef CONFIG_PAX_RANDMMAP
57000+ if (randomize_va_space)
57001+ pax_flags |= MF_PAX_RANDMMAP;
57002+#endif
57003+
57004+ return pax_flags;
57005+}
57006+
57007+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
57008+{
57009+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
57010+
57011+#ifdef CONFIG_PAX_EI_PAX
57012+
57013+#ifdef CONFIG_PAX_SOFTMODE
57014+ if (pax_softmode)
57015+ return pax_flags;
57016+#endif
57017+
57018+ pax_flags = 0UL;
57019+
57020+#ifdef CONFIG_PAX_PAGEEXEC
57021+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
57022+ pax_flags |= MF_PAX_PAGEEXEC;
57023+#endif
57024+
57025+#ifdef CONFIG_PAX_SEGMEXEC
57026+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
57027+ pax_flags |= MF_PAX_SEGMEXEC;
57028+#endif
57029+
57030+#ifdef CONFIG_PAX_EMUTRAMP
57031+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
57032+ pax_flags |= MF_PAX_EMUTRAMP;
57033+#endif
57034+
57035+#ifdef CONFIG_PAX_MPROTECT
57036+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
57037+ pax_flags |= MF_PAX_MPROTECT;
57038+#endif
57039+
57040+#ifdef CONFIG_PAX_ASLR
57041+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
57042+ pax_flags |= MF_PAX_RANDMMAP;
57043+#endif
57044+
57045+#endif
57046+
57047+ return pax_flags;
57048+
57049+}
57050+
57051+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
57052+{
57053+
57054+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57055+ unsigned long i;
57056+
57057+ for (i = 0UL; i < elf_ex->e_phnum; i++)
57058+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
57059+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
57060+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
57061+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
57062+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
57063+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
57064+ return PAX_PARSE_FLAGS_FALLBACK;
57065+
57066+#ifdef CONFIG_PAX_SOFTMODE
57067+ if (pax_softmode)
57068+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
57069+ else
57070+#endif
57071+
57072+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
57073+ break;
57074+ }
57075+#endif
57076+
57077+ return PAX_PARSE_FLAGS_FALLBACK;
57078+}
57079+
57080+static unsigned long pax_parse_xattr_pax(struct file * const file)
57081+{
57082+
57083+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
57084+ ssize_t xattr_size, i;
57085+ unsigned char xattr_value[sizeof("pemrs") - 1];
57086+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
57087+
57088+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
57089+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
57090+ return PAX_PARSE_FLAGS_FALLBACK;
57091+
57092+ for (i = 0; i < xattr_size; i++)
57093+ switch (xattr_value[i]) {
57094+ default:
57095+ return PAX_PARSE_FLAGS_FALLBACK;
57096+
57097+#define parse_flag(option1, option2, flag) \
57098+ case option1: \
57099+ if (pax_flags_hardmode & MF_PAX_##flag) \
57100+ return PAX_PARSE_FLAGS_FALLBACK;\
57101+ pax_flags_hardmode |= MF_PAX_##flag; \
57102+ break; \
57103+ case option2: \
57104+ if (pax_flags_softmode & MF_PAX_##flag) \
57105+ return PAX_PARSE_FLAGS_FALLBACK;\
57106+ pax_flags_softmode |= MF_PAX_##flag; \
57107+ break;
57108+
57109+ parse_flag('p', 'P', PAGEEXEC);
57110+ parse_flag('e', 'E', EMUTRAMP);
57111+ parse_flag('m', 'M', MPROTECT);
57112+ parse_flag('r', 'R', RANDMMAP);
57113+ parse_flag('s', 'S', SEGMEXEC);
57114+
57115+#undef parse_flag
57116+ }
57117+
57118+ if (pax_flags_hardmode & pax_flags_softmode)
57119+ return PAX_PARSE_FLAGS_FALLBACK;
57120+
57121+#ifdef CONFIG_PAX_SOFTMODE
57122+ if (pax_softmode)
57123+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
57124+ else
57125+#endif
57126+
57127+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
57128+#else
57129+ return PAX_PARSE_FLAGS_FALLBACK;
57130+#endif
57131+
57132+}
57133+
57134+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
57135+{
57136+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
57137+
57138+ pax_flags = pax_parse_defaults();
57139+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
57140+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
57141+ xattr_pax_flags = pax_parse_xattr_pax(file);
57142+
57143+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57144+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57145+ pt_pax_flags != xattr_pax_flags)
57146+ return -EINVAL;
57147+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57148+ pax_flags = xattr_pax_flags;
57149+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57150+ pax_flags = pt_pax_flags;
57151+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57152+ pax_flags = ei_pax_flags;
57153+
57154+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
57155+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57156+ if ((__supported_pte_mask & _PAGE_NX))
57157+ pax_flags &= ~MF_PAX_SEGMEXEC;
57158+ else
57159+ pax_flags &= ~MF_PAX_PAGEEXEC;
57160+ }
57161+#endif
57162+
57163+ if (0 > pax_check_flags(&pax_flags))
57164+ return -EINVAL;
57165+
57166+ current->mm->pax_flags = pax_flags;
57167+ return 0;
57168+}
57169+#endif
57170+
57171 /*
57172 * These are the functions used to load ELF style executables and shared
57173 * libraries. There is no binary dependent code anywhere else.
57174@@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
57175 {
57176 unsigned int random_variable = 0;
57177
57178+#ifdef CONFIG_PAX_RANDUSTACK
57179+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
57180+ return stack_top - current->mm->delta_stack;
57181+#endif
57182+
57183 if ((current->flags & PF_RANDOMIZE) &&
57184 !(current->personality & ADDR_NO_RANDOMIZE)) {
57185 random_variable = get_random_int() & STACK_RND_MASK;
57186@@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57187 unsigned long load_addr = 0, load_bias = 0;
57188 int load_addr_set = 0;
57189 char * elf_interpreter = NULL;
57190- unsigned long error;
57191+ unsigned long error = 0;
57192 struct elf_phdr *elf_ppnt, *elf_phdata;
57193 unsigned long elf_bss, elf_brk;
57194 int retval, i;
57195@@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
57196 unsigned long start_code, end_code, start_data, end_data;
57197 unsigned long reloc_func_desc __maybe_unused = 0;
57198 int executable_stack = EXSTACK_DEFAULT;
57199- unsigned long def_flags = 0;
57200 struct pt_regs *regs = current_pt_regs();
57201 struct {
57202 struct elfhdr elf_ex;
57203 struct elfhdr interp_elf_ex;
57204 } *loc;
57205+ unsigned long pax_task_size;
57206
57207 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
57208 if (!loc) {
57209@@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
57210 goto out_free_dentry;
57211
57212 /* OK, This is the point of no return */
57213- current->mm->def_flags = def_flags;
57214+ current->mm->def_flags = 0;
57215
57216 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
57217 may depend on the personality. */
57218 SET_PERSONALITY(loc->elf_ex);
57219+
57220+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57221+ current->mm->pax_flags = 0UL;
57222+#endif
57223+
57224+#ifdef CONFIG_PAX_DLRESOLVE
57225+ current->mm->call_dl_resolve = 0UL;
57226+#endif
57227+
57228+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
57229+ current->mm->call_syscall = 0UL;
57230+#endif
57231+
57232+#ifdef CONFIG_PAX_ASLR
57233+ current->mm->delta_mmap = 0UL;
57234+ current->mm->delta_stack = 0UL;
57235+#endif
57236+
57237+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57238+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
57239+ send_sig(SIGKILL, current, 0);
57240+ goto out_free_dentry;
57241+ }
57242+#endif
57243+
57244+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57245+ pax_set_initial_flags(bprm);
57246+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
57247+ if (pax_set_initial_flags_func)
57248+ (pax_set_initial_flags_func)(bprm);
57249+#endif
57250+
57251+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
57252+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
57253+ current->mm->context.user_cs_limit = PAGE_SIZE;
57254+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
57255+ }
57256+#endif
57257+
57258+#ifdef CONFIG_PAX_SEGMEXEC
57259+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
57260+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
57261+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
57262+ pax_task_size = SEGMEXEC_TASK_SIZE;
57263+ current->mm->def_flags |= VM_NOHUGEPAGE;
57264+ } else
57265+#endif
57266+
57267+ pax_task_size = TASK_SIZE;
57268+
57269+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
57270+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57271+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
57272+ put_cpu();
57273+ }
57274+#endif
57275+
57276+#ifdef CONFIG_PAX_ASLR
57277+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57278+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
57279+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
57280+ }
57281+#endif
57282+
57283+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57284+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57285+ executable_stack = EXSTACK_DISABLE_X;
57286+ current->personality &= ~READ_IMPLIES_EXEC;
57287+ } else
57288+#endif
57289+
57290 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
57291 current->personality |= READ_IMPLIES_EXEC;
57292
57293@@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
57294 #else
57295 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
57296 #endif
57297+
57298+#ifdef CONFIG_PAX_RANDMMAP
57299+ /* PaX: randomize base address at the default exe base if requested */
57300+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
57301+#ifdef CONFIG_SPARC64
57302+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
57303+#else
57304+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
57305+#endif
57306+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
57307+ elf_flags |= MAP_FIXED;
57308+ }
57309+#endif
57310+
57311 }
57312
57313 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
57314@@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
57315 * allowed task size. Note that p_filesz must always be
57316 * <= p_memsz so it is only necessary to check p_memsz.
57317 */
57318- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57319- elf_ppnt->p_memsz > TASK_SIZE ||
57320- TASK_SIZE - elf_ppnt->p_memsz < k) {
57321+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57322+ elf_ppnt->p_memsz > pax_task_size ||
57323+ pax_task_size - elf_ppnt->p_memsz < k) {
57324 /* set_brk can never work. Avoid overflows. */
57325 send_sig(SIGKILL, current, 0);
57326 retval = -EINVAL;
57327@@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
57328 goto out_free_dentry;
57329 }
57330 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
57331- send_sig(SIGSEGV, current, 0);
57332- retval = -EFAULT; /* Nobody gets to see this, but.. */
57333- goto out_free_dentry;
57334+ /*
57335+ * This bss-zeroing can fail if the ELF
57336+ * file specifies odd protections. So
57337+ * we don't check the return value
57338+ */
57339 }
57340
57341+#ifdef CONFIG_PAX_RANDMMAP
57342+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57343+ unsigned long start, size, flags;
57344+ vm_flags_t vm_flags;
57345+
57346+ start = ELF_PAGEALIGN(elf_brk);
57347+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
57348+ flags = MAP_FIXED | MAP_PRIVATE;
57349+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
57350+
57351+ down_write(&current->mm->mmap_sem);
57352+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
57353+ retval = -ENOMEM;
57354+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
57355+// if (current->personality & ADDR_NO_RANDOMIZE)
57356+// vm_flags |= VM_READ | VM_MAYREAD;
57357+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
57358+ retval = IS_ERR_VALUE(start) ? start : 0;
57359+ }
57360+ up_write(&current->mm->mmap_sem);
57361+ if (retval == 0)
57362+ retval = set_brk(start + size, start + size + PAGE_SIZE);
57363+ if (retval < 0) {
57364+ send_sig(SIGKILL, current, 0);
57365+ goto out_free_dentry;
57366+ }
57367+ }
57368+#endif
57369+
57370 if (elf_interpreter) {
57371- unsigned long interp_map_addr = 0;
57372-
57373 elf_entry = load_elf_interp(&loc->interp_elf_ex,
57374 interpreter,
57375- &interp_map_addr,
57376 load_bias);
57377 if (!IS_ERR((void *)elf_entry)) {
57378 /*
57379@@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
57380 * Decide what to dump of a segment, part, all or none.
57381 */
57382 static unsigned long vma_dump_size(struct vm_area_struct *vma,
57383- unsigned long mm_flags)
57384+ unsigned long mm_flags, long signr)
57385 {
57386 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
57387
57388@@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
57389 if (vma->vm_file == NULL)
57390 return 0;
57391
57392- if (FILTER(MAPPED_PRIVATE))
57393+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
57394 goto whole;
57395
57396 /*
57397@@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
57398 {
57399 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
57400 int i = 0;
57401- do
57402+ do {
57403 i += 2;
57404- while (auxv[i - 2] != AT_NULL);
57405+ } while (auxv[i - 2] != AT_NULL);
57406 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
57407 }
57408
57409@@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
57410 {
57411 mm_segment_t old_fs = get_fs();
57412 set_fs(KERNEL_DS);
57413- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
57414+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
57415 set_fs(old_fs);
57416 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
57417 }
57418@@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
57419 }
57420
57421 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
57422- unsigned long mm_flags)
57423+ struct coredump_params *cprm)
57424 {
57425 struct vm_area_struct *vma;
57426 size_t size = 0;
57427
57428 for (vma = first_vma(current, gate_vma); vma != NULL;
57429 vma = next_vma(vma, gate_vma))
57430- size += vma_dump_size(vma, mm_flags);
57431+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57432 return size;
57433 }
57434
57435@@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57436
57437 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
57438
57439- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
57440+ offset += elf_core_vma_data_size(gate_vma, cprm);
57441 offset += elf_core_extra_data_size();
57442 e_shoff = offset;
57443
57444@@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57445 phdr.p_offset = offset;
57446 phdr.p_vaddr = vma->vm_start;
57447 phdr.p_paddr = 0;
57448- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
57449+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57450 phdr.p_memsz = vma->vm_end - vma->vm_start;
57451 offset += phdr.p_filesz;
57452 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57453@@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57454 unsigned long addr;
57455 unsigned long end;
57456
57457- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57458+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57459
57460 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57461 struct page *page;
57462@@ -2199,6 +2678,167 @@ out:
57463
57464 #endif /* CONFIG_ELF_CORE */
57465
57466+#ifdef CONFIG_PAX_MPROTECT
57467+/* PaX: non-PIC ELF libraries need relocations on their executable segments
57468+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57469+ * we'll remove VM_MAYWRITE for good on RELRO segments.
57470+ *
57471+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57472+ * basis because we want to allow the common case and not the special ones.
57473+ */
57474+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57475+{
57476+ struct elfhdr elf_h;
57477+ struct elf_phdr elf_p;
57478+ unsigned long i;
57479+ unsigned long oldflags;
57480+ bool is_textrel_rw, is_textrel_rx, is_relro;
57481+
57482+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57483+ return;
57484+
57485+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57486+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57487+
57488+#ifdef CONFIG_PAX_ELFRELOCS
57489+ /* possible TEXTREL */
57490+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57491+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57492+#else
57493+ is_textrel_rw = false;
57494+ is_textrel_rx = false;
57495+#endif
57496+
57497+ /* possible RELRO */
57498+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57499+
57500+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57501+ return;
57502+
57503+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57504+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57505+
57506+#ifdef CONFIG_PAX_ETEXECRELOCS
57507+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57508+#else
57509+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57510+#endif
57511+
57512+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57513+ !elf_check_arch(&elf_h) ||
57514+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57515+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57516+ return;
57517+
57518+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57519+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57520+ return;
57521+ switch (elf_p.p_type) {
57522+ case PT_DYNAMIC:
57523+ if (!is_textrel_rw && !is_textrel_rx)
57524+ continue;
57525+ i = 0UL;
57526+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57527+ elf_dyn dyn;
57528+
57529+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57530+ break;
57531+ if (dyn.d_tag == DT_NULL)
57532+ break;
57533+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57534+ gr_log_textrel(vma);
57535+ if (is_textrel_rw)
57536+ vma->vm_flags |= VM_MAYWRITE;
57537+ else
57538+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57539+ vma->vm_flags &= ~VM_MAYWRITE;
57540+ break;
57541+ }
57542+ i++;
57543+ }
57544+ is_textrel_rw = false;
57545+ is_textrel_rx = false;
57546+ continue;
57547+
57548+ case PT_GNU_RELRO:
57549+ if (!is_relro)
57550+ continue;
57551+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57552+ vma->vm_flags &= ~VM_MAYWRITE;
57553+ is_relro = false;
57554+ continue;
57555+
57556+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57557+ case PT_PAX_FLAGS: {
57558+ const char *msg_mprotect = "", *msg_emutramp = "";
57559+ char *buffer_lib, *buffer_exe;
57560+
57561+ if (elf_p.p_flags & PF_NOMPROTECT)
57562+ msg_mprotect = "MPROTECT disabled";
57563+
57564+#ifdef CONFIG_PAX_EMUTRAMP
57565+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57566+ msg_emutramp = "EMUTRAMP enabled";
57567+#endif
57568+
57569+ if (!msg_mprotect[0] && !msg_emutramp[0])
57570+ continue;
57571+
57572+ if (!printk_ratelimit())
57573+ continue;
57574+
57575+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57576+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57577+ if (buffer_lib && buffer_exe) {
57578+ char *path_lib, *path_exe;
57579+
57580+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57581+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57582+
57583+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57584+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57585+
57586+ }
57587+ free_page((unsigned long)buffer_exe);
57588+ free_page((unsigned long)buffer_lib);
57589+ continue;
57590+ }
57591+#endif
57592+
57593+ }
57594+ }
57595+}
57596+#endif
57597+
57598+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57599+
57600+extern int grsec_enable_log_rwxmaps;
57601+
57602+static void elf_handle_mmap(struct file *file)
57603+{
57604+ struct elfhdr elf_h;
57605+ struct elf_phdr elf_p;
57606+ unsigned long i;
57607+
57608+ if (!grsec_enable_log_rwxmaps)
57609+ return;
57610+
57611+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57612+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57613+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57614+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57615+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57616+ return;
57617+
57618+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57619+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57620+ return;
57621+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57622+ gr_log_ptgnustack(file);
57623+ }
57624+}
57625+#endif
57626+
57627 static int __init init_elf_binfmt(void)
57628 {
57629 register_binfmt(&elf_format);
57630diff --git a/fs/bio.c b/fs/bio.c
57631index 8754e7b..0669094 100644
57632--- a/fs/bio.c
57633+++ b/fs/bio.c
57634@@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57635 /*
57636 * Overflow, abort
57637 */
57638- if (end < start)
57639+ if (end < start || end - start > INT_MAX - nr_pages)
57640 return ERR_PTR(-EINVAL);
57641
57642 nr_pages += end - start;
57643@@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57644 /*
57645 * Overflow, abort
57646 */
57647- if (end < start)
57648+ if (end < start || end - start > INT_MAX - nr_pages)
57649 return ERR_PTR(-EINVAL);
57650
57651 nr_pages += end - start;
57652@@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57653 const int read = bio_data_dir(bio) == READ;
57654 struct bio_map_data *bmd = bio->bi_private;
57655 int i;
57656- char *p = bmd->sgvecs[0].iov_base;
57657+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57658
57659 bio_for_each_segment_all(bvec, bio, i) {
57660 char *addr = page_address(bvec->bv_page);
57661diff --git a/fs/block_dev.c b/fs/block_dev.c
57662index 1e86823..8e34695 100644
57663--- a/fs/block_dev.c
57664+++ b/fs/block_dev.c
57665@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57666 else if (bdev->bd_contains == bdev)
57667 return true; /* is a whole device which isn't held */
57668
57669- else if (whole->bd_holder == bd_may_claim)
57670+ else if (whole->bd_holder == (void *)bd_may_claim)
57671 return true; /* is a partition of a device that is being partitioned */
57672 else if (whole->bd_holder != NULL)
57673 return false; /* is a partition of a held device */
57674diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57675index cbd3a7d6f..c6a2881 100644
57676--- a/fs/btrfs/ctree.c
57677+++ b/fs/btrfs/ctree.c
57678@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57679 free_extent_buffer(buf);
57680 add_root_to_dirty_list(root);
57681 } else {
57682- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57683- parent_start = parent->start;
57684- else
57685+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57686+ if (parent)
57687+ parent_start = parent->start;
57688+ else
57689+ parent_start = 0;
57690+ } else
57691 parent_start = 0;
57692
57693 WARN_ON(trans->transid != btrfs_header_generation(parent));
57694diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57695index 451b00c..a2cccee 100644
57696--- a/fs/btrfs/delayed-inode.c
57697+++ b/fs/btrfs/delayed-inode.c
57698@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57699
57700 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57701 {
57702- int seq = atomic_inc_return(&delayed_root->items_seq);
57703+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57704 if ((atomic_dec_return(&delayed_root->items) <
57705 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57706 waitqueue_active(&delayed_root->wait))
57707@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57708
57709 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57710 {
57711- int val = atomic_read(&delayed_root->items_seq);
57712+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57713
57714 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57715 return 1;
57716@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57717 int seq;
57718 int ret;
57719
57720- seq = atomic_read(&delayed_root->items_seq);
57721+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57722
57723 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57724 if (ret)
57725diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57726index f70119f..ab5894d 100644
57727--- a/fs/btrfs/delayed-inode.h
57728+++ b/fs/btrfs/delayed-inode.h
57729@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57730 */
57731 struct list_head prepare_list;
57732 atomic_t items; /* for delayed items */
57733- atomic_t items_seq; /* for delayed items */
57734+ atomic_unchecked_t items_seq; /* for delayed items */
57735 int nodes; /* for delayed nodes */
57736 wait_queue_head_t wait;
57737 };
57738@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57739 struct btrfs_delayed_root *delayed_root)
57740 {
57741 atomic_set(&delayed_root->items, 0);
57742- atomic_set(&delayed_root->items_seq, 0);
57743+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57744 delayed_root->nodes = 0;
57745 spin_lock_init(&delayed_root->lock);
57746 init_waitqueue_head(&delayed_root->wait);
57747diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57748index a6d8efa..2f062cf 100644
57749--- a/fs/btrfs/ioctl.c
57750+++ b/fs/btrfs/ioctl.c
57751@@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57752 for (i = 0; i < num_types; i++) {
57753 struct btrfs_space_info *tmp;
57754
57755+ /* Don't copy in more than we allocated */
57756 if (!slot_count)
57757 break;
57758
57759+ slot_count--;
57760+
57761 info = NULL;
57762 rcu_read_lock();
57763 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57764@@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57765 memcpy(dest, &space, sizeof(space));
57766 dest++;
57767 space_args.total_spaces++;
57768- slot_count--;
57769 }
57770- if (!slot_count)
57771- break;
57772 }
57773 up_read(&info->groups_sem);
57774 }
57775diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57776index d04db81..96e54f1 100644
57777--- a/fs/btrfs/super.c
57778+++ b/fs/btrfs/super.c
57779@@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57780 function, line, errstr);
57781 return;
57782 }
57783- ACCESS_ONCE(trans->transaction->aborted) = errno;
57784+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57785 /* Wake up anybody who may be waiting on this transaction */
57786 wake_up(&root->fs_info->transaction_wait);
57787 wake_up(&root->fs_info->transaction_blocked_wait);
57788diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57789index 865f4cf..f321e86 100644
57790--- a/fs/btrfs/sysfs.c
57791+++ b/fs/btrfs/sysfs.c
57792@@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57793 for (set = 0; set < FEAT_MAX; set++) {
57794 int i;
57795 struct attribute *attrs[2];
57796- struct attribute_group agroup = {
57797+ attribute_group_no_const agroup = {
57798 .name = "features",
57799 .attrs = attrs,
57800 };
57801diff --git a/fs/buffer.c b/fs/buffer.c
57802index 27265a8..289f488 100644
57803--- a/fs/buffer.c
57804+++ b/fs/buffer.c
57805@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57806 bh_cachep = kmem_cache_create("buffer_head",
57807 sizeof(struct buffer_head), 0,
57808 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57809- SLAB_MEM_SPREAD),
57810+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57811 NULL);
57812
57813 /*
57814diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57815index 622f469..e8d2d55 100644
57816--- a/fs/cachefiles/bind.c
57817+++ b/fs/cachefiles/bind.c
57818@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57819 args);
57820
57821 /* start by checking things over */
57822- ASSERT(cache->fstop_percent >= 0 &&
57823- cache->fstop_percent < cache->fcull_percent &&
57824+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57825 cache->fcull_percent < cache->frun_percent &&
57826 cache->frun_percent < 100);
57827
57828- ASSERT(cache->bstop_percent >= 0 &&
57829- cache->bstop_percent < cache->bcull_percent &&
57830+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57831 cache->bcull_percent < cache->brun_percent &&
57832 cache->brun_percent < 100);
57833
57834diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57835index 0a1467b..6a53245 100644
57836--- a/fs/cachefiles/daemon.c
57837+++ b/fs/cachefiles/daemon.c
57838@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57839 if (n > buflen)
57840 return -EMSGSIZE;
57841
57842- if (copy_to_user(_buffer, buffer, n) != 0)
57843+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57844 return -EFAULT;
57845
57846 return n;
57847@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57848 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57849 return -EIO;
57850
57851- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57852+ if (datalen > PAGE_SIZE - 1)
57853 return -EOPNOTSUPP;
57854
57855 /* drag the command string into the kernel so we can parse it */
57856@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57857 if (args[0] != '%' || args[1] != '\0')
57858 return -EINVAL;
57859
57860- if (fstop < 0 || fstop >= cache->fcull_percent)
57861+ if (fstop >= cache->fcull_percent)
57862 return cachefiles_daemon_range_error(cache, args);
57863
57864 cache->fstop_percent = fstop;
57865@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57866 if (args[0] != '%' || args[1] != '\0')
57867 return -EINVAL;
57868
57869- if (bstop < 0 || bstop >= cache->bcull_percent)
57870+ if (bstop >= cache->bcull_percent)
57871 return cachefiles_daemon_range_error(cache, args);
57872
57873 cache->bstop_percent = bstop;
57874diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57875index 5349473..d6c0b93 100644
57876--- a/fs/cachefiles/internal.h
57877+++ b/fs/cachefiles/internal.h
57878@@ -59,7 +59,7 @@ struct cachefiles_cache {
57879 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57880 struct rb_root active_nodes; /* active nodes (can't be culled) */
57881 rwlock_t active_lock; /* lock for active_nodes */
57882- atomic_t gravecounter; /* graveyard uniquifier */
57883+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57884 unsigned frun_percent; /* when to stop culling (% files) */
57885 unsigned fcull_percent; /* when to start culling (% files) */
57886 unsigned fstop_percent; /* when to stop allocating (% files) */
57887@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57888 * proc.c
57889 */
57890 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57891-extern atomic_t cachefiles_lookup_histogram[HZ];
57892-extern atomic_t cachefiles_mkdir_histogram[HZ];
57893-extern atomic_t cachefiles_create_histogram[HZ];
57894+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57895+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57896+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57897
57898 extern int __init cachefiles_proc_init(void);
57899 extern void cachefiles_proc_cleanup(void);
57900 static inline
57901-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57902+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57903 {
57904 unsigned long jif = jiffies - start_jif;
57905 if (jif >= HZ)
57906 jif = HZ - 1;
57907- atomic_inc(&histogram[jif]);
57908+ atomic_inc_unchecked(&histogram[jif]);
57909 }
57910
57911 #else
57912diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57913index ca65f39..48921e3 100644
57914--- a/fs/cachefiles/namei.c
57915+++ b/fs/cachefiles/namei.c
57916@@ -317,7 +317,7 @@ try_again:
57917 /* first step is to make up a grave dentry in the graveyard */
57918 sprintf(nbuffer, "%08x%08x",
57919 (uint32_t) get_seconds(),
57920- (uint32_t) atomic_inc_return(&cache->gravecounter));
57921+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57922
57923 /* do the multiway lock magic */
57924 trap = lock_rename(cache->graveyard, dir);
57925diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57926index eccd339..4c1d995 100644
57927--- a/fs/cachefiles/proc.c
57928+++ b/fs/cachefiles/proc.c
57929@@ -14,9 +14,9 @@
57930 #include <linux/seq_file.h>
57931 #include "internal.h"
57932
57933-atomic_t cachefiles_lookup_histogram[HZ];
57934-atomic_t cachefiles_mkdir_histogram[HZ];
57935-atomic_t cachefiles_create_histogram[HZ];
57936+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57937+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57938+atomic_unchecked_t cachefiles_create_histogram[HZ];
57939
57940 /*
57941 * display the latency histogram
57942@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57943 return 0;
57944 default:
57945 index = (unsigned long) v - 3;
57946- x = atomic_read(&cachefiles_lookup_histogram[index]);
57947- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57948- z = atomic_read(&cachefiles_create_histogram[index]);
57949+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57950+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57951+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57952 if (x == 0 && y == 0 && z == 0)
57953 return 0;
57954
57955diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57956index ebaff36..7e3ea26 100644
57957--- a/fs/cachefiles/rdwr.c
57958+++ b/fs/cachefiles/rdwr.c
57959@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57960 old_fs = get_fs();
57961 set_fs(KERNEL_DS);
57962 ret = file->f_op->write(
57963- file, (const void __user *) data, len, &pos);
57964+ file, (const void __force_user *) data, len, &pos);
57965 set_fs(old_fs);
57966 kunmap(page);
57967 file_end_write(file);
57968diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57969index 5e0982a..b7e82bc 100644
57970--- a/fs/ceph/dir.c
57971+++ b/fs/ceph/dir.c
57972@@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57973 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57974 struct ceph_mds_client *mdsc = fsc->mdsc;
57975 unsigned frag = fpos_frag(ctx->pos);
57976- int off = fpos_off(ctx->pos);
57977+ unsigned int off = fpos_off(ctx->pos);
57978 int err;
57979 u32 ftype;
57980 struct ceph_mds_reply_info_parsed *rinfo;
57981diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57982index 10a4ccb..92dbc5e 100644
57983--- a/fs/ceph/super.c
57984+++ b/fs/ceph/super.c
57985@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57986 /*
57987 * construct our own bdi so we can control readahead, etc.
57988 */
57989-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57990+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57991
57992 static int ceph_register_bdi(struct super_block *sb,
57993 struct ceph_fs_client *fsc)
57994@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57995 default_backing_dev_info.ra_pages;
57996
57997 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57998- atomic_long_inc_return(&bdi_seq));
57999+ atomic_long_inc_return_unchecked(&bdi_seq));
58000 if (!err)
58001 sb->s_bdi = &fsc->backing_dev_info;
58002 return err;
58003diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
58004index f3ac415..3d2420c 100644
58005--- a/fs/cifs/cifs_debug.c
58006+++ b/fs/cifs/cifs_debug.c
58007@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
58008
58009 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
58010 #ifdef CONFIG_CIFS_STATS2
58011- atomic_set(&totBufAllocCount, 0);
58012- atomic_set(&totSmBufAllocCount, 0);
58013+ atomic_set_unchecked(&totBufAllocCount, 0);
58014+ atomic_set_unchecked(&totSmBufAllocCount, 0);
58015 #endif /* CONFIG_CIFS_STATS2 */
58016 spin_lock(&cifs_tcp_ses_lock);
58017 list_for_each(tmp1, &cifs_tcp_ses_list) {
58018@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
58019 tcon = list_entry(tmp3,
58020 struct cifs_tcon,
58021 tcon_list);
58022- atomic_set(&tcon->num_smbs_sent, 0);
58023+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
58024 if (server->ops->clear_stats)
58025 server->ops->clear_stats(tcon);
58026 }
58027@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
58028 smBufAllocCount.counter, cifs_min_small);
58029 #ifdef CONFIG_CIFS_STATS2
58030 seq_printf(m, "Total Large %d Small %d Allocations\n",
58031- atomic_read(&totBufAllocCount),
58032- atomic_read(&totSmBufAllocCount));
58033+ atomic_read_unchecked(&totBufAllocCount),
58034+ atomic_read_unchecked(&totSmBufAllocCount));
58035 #endif /* CONFIG_CIFS_STATS2 */
58036
58037 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
58038@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
58039 if (tcon->need_reconnect)
58040 seq_puts(m, "\tDISCONNECTED ");
58041 seq_printf(m, "\nSMBs: %d",
58042- atomic_read(&tcon->num_smbs_sent));
58043+ atomic_read_unchecked(&tcon->num_smbs_sent));
58044 if (server->ops->print_stats)
58045 server->ops->print_stats(m, tcon);
58046 }
58047diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
58048index 7c6b73c..a8f0db2 100644
58049--- a/fs/cifs/cifsfs.c
58050+++ b/fs/cifs/cifsfs.c
58051@@ -1068,7 +1068,7 @@ cifs_init_request_bufs(void)
58052 */
58053 cifs_req_cachep = kmem_cache_create("cifs_request",
58054 CIFSMaxBufSize + max_hdr_size, 0,
58055- SLAB_HWCACHE_ALIGN, NULL);
58056+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
58057 if (cifs_req_cachep == NULL)
58058 return -ENOMEM;
58059
58060@@ -1095,7 +1095,7 @@ cifs_init_request_bufs(void)
58061 efficient to alloc 1 per page off the slab compared to 17K (5page)
58062 alloc of large cifs buffers even when page debugging is on */
58063 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
58064- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
58065+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
58066 NULL);
58067 if (cifs_sm_req_cachep == NULL) {
58068 mempool_destroy(cifs_req_poolp);
58069@@ -1180,8 +1180,8 @@ init_cifs(void)
58070 atomic_set(&bufAllocCount, 0);
58071 atomic_set(&smBufAllocCount, 0);
58072 #ifdef CONFIG_CIFS_STATS2
58073- atomic_set(&totBufAllocCount, 0);
58074- atomic_set(&totSmBufAllocCount, 0);
58075+ atomic_set_unchecked(&totBufAllocCount, 0);
58076+ atomic_set_unchecked(&totSmBufAllocCount, 0);
58077 #endif /* CONFIG_CIFS_STATS2 */
58078
58079 atomic_set(&midCount, 0);
58080diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
58081index 30f6e92..e915ba5 100644
58082--- a/fs/cifs/cifsglob.h
58083+++ b/fs/cifs/cifsglob.h
58084@@ -806,35 +806,35 @@ struct cifs_tcon {
58085 __u16 Flags; /* optional support bits */
58086 enum statusEnum tidStatus;
58087 #ifdef CONFIG_CIFS_STATS
58088- atomic_t num_smbs_sent;
58089+ atomic_unchecked_t num_smbs_sent;
58090 union {
58091 struct {
58092- atomic_t num_writes;
58093- atomic_t num_reads;
58094- atomic_t num_flushes;
58095- atomic_t num_oplock_brks;
58096- atomic_t num_opens;
58097- atomic_t num_closes;
58098- atomic_t num_deletes;
58099- atomic_t num_mkdirs;
58100- atomic_t num_posixopens;
58101- atomic_t num_posixmkdirs;
58102- atomic_t num_rmdirs;
58103- atomic_t num_renames;
58104- atomic_t num_t2renames;
58105- atomic_t num_ffirst;
58106- atomic_t num_fnext;
58107- atomic_t num_fclose;
58108- atomic_t num_hardlinks;
58109- atomic_t num_symlinks;
58110- atomic_t num_locks;
58111- atomic_t num_acl_get;
58112- atomic_t num_acl_set;
58113+ atomic_unchecked_t num_writes;
58114+ atomic_unchecked_t num_reads;
58115+ atomic_unchecked_t num_flushes;
58116+ atomic_unchecked_t num_oplock_brks;
58117+ atomic_unchecked_t num_opens;
58118+ atomic_unchecked_t num_closes;
58119+ atomic_unchecked_t num_deletes;
58120+ atomic_unchecked_t num_mkdirs;
58121+ atomic_unchecked_t num_posixopens;
58122+ atomic_unchecked_t num_posixmkdirs;
58123+ atomic_unchecked_t num_rmdirs;
58124+ atomic_unchecked_t num_renames;
58125+ atomic_unchecked_t num_t2renames;
58126+ atomic_unchecked_t num_ffirst;
58127+ atomic_unchecked_t num_fnext;
58128+ atomic_unchecked_t num_fclose;
58129+ atomic_unchecked_t num_hardlinks;
58130+ atomic_unchecked_t num_symlinks;
58131+ atomic_unchecked_t num_locks;
58132+ atomic_unchecked_t num_acl_get;
58133+ atomic_unchecked_t num_acl_set;
58134 } cifs_stats;
58135 #ifdef CONFIG_CIFS_SMB2
58136 struct {
58137- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58138- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58139+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58140+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58141 } smb2_stats;
58142 #endif /* CONFIG_CIFS_SMB2 */
58143 } stats;
58144@@ -1170,7 +1170,7 @@ convert_delimiter(char *path, char delim)
58145 }
58146
58147 #ifdef CONFIG_CIFS_STATS
58148-#define cifs_stats_inc atomic_inc
58149+#define cifs_stats_inc atomic_inc_unchecked
58150
58151 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
58152 unsigned int bytes)
58153@@ -1536,8 +1536,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
58154 /* Various Debug counters */
58155 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
58156 #ifdef CONFIG_CIFS_STATS2
58157-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
58158-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
58159+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
58160+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
58161 #endif
58162 GLOBAL_EXTERN atomic_t smBufAllocCount;
58163 GLOBAL_EXTERN atomic_t midCount;
58164diff --git a/fs/cifs/file.c b/fs/cifs/file.c
58165index 87c4dd0..a90f115 100644
58166--- a/fs/cifs/file.c
58167+++ b/fs/cifs/file.c
58168@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
58169 index = mapping->writeback_index; /* Start from prev offset */
58170 end = -1;
58171 } else {
58172- index = wbc->range_start >> PAGE_CACHE_SHIFT;
58173- end = wbc->range_end >> PAGE_CACHE_SHIFT;
58174- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
58175+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
58176 range_whole = true;
58177+ index = 0;
58178+ end = ULONG_MAX;
58179+ } else {
58180+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
58181+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
58182+ }
58183 scanned = true;
58184 }
58185 retry:
58186diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
58187index 3b0c62e..f7d090c 100644
58188--- a/fs/cifs/misc.c
58189+++ b/fs/cifs/misc.c
58190@@ -170,7 +170,7 @@ cifs_buf_get(void)
58191 memset(ret_buf, 0, buf_size + 3);
58192 atomic_inc(&bufAllocCount);
58193 #ifdef CONFIG_CIFS_STATS2
58194- atomic_inc(&totBufAllocCount);
58195+ atomic_inc_unchecked(&totBufAllocCount);
58196 #endif /* CONFIG_CIFS_STATS2 */
58197 }
58198
58199@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
58200 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
58201 atomic_inc(&smBufAllocCount);
58202 #ifdef CONFIG_CIFS_STATS2
58203- atomic_inc(&totSmBufAllocCount);
58204+ atomic_inc_unchecked(&totSmBufAllocCount);
58205 #endif /* CONFIG_CIFS_STATS2 */
58206
58207 }
58208diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
58209index d1fdfa8..94558f8 100644
58210--- a/fs/cifs/smb1ops.c
58211+++ b/fs/cifs/smb1ops.c
58212@@ -626,27 +626,27 @@ static void
58213 cifs_clear_stats(struct cifs_tcon *tcon)
58214 {
58215 #ifdef CONFIG_CIFS_STATS
58216- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
58217- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
58218- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
58219- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58220- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
58221- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
58222- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58223- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
58224- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
58225- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
58226- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
58227- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
58228- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
58229- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
58230- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
58231- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
58232- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
58233- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
58234- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
58235- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
58236- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
58237+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
58238+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
58239+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
58240+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58241+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
58242+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
58243+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58244+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
58245+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
58246+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
58247+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
58248+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
58249+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
58250+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
58251+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
58252+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
58253+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
58254+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
58255+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
58256+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
58257+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
58258 #endif
58259 }
58260
58261@@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58262 {
58263 #ifdef CONFIG_CIFS_STATS
58264 seq_printf(m, " Oplocks breaks: %d",
58265- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
58266+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
58267 seq_printf(m, "\nReads: %d Bytes: %llu",
58268- atomic_read(&tcon->stats.cifs_stats.num_reads),
58269+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
58270 (long long)(tcon->bytes_read));
58271 seq_printf(m, "\nWrites: %d Bytes: %llu",
58272- atomic_read(&tcon->stats.cifs_stats.num_writes),
58273+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
58274 (long long)(tcon->bytes_written));
58275 seq_printf(m, "\nFlushes: %d",
58276- atomic_read(&tcon->stats.cifs_stats.num_flushes));
58277+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
58278 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
58279- atomic_read(&tcon->stats.cifs_stats.num_locks),
58280- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
58281- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
58282+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
58283+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
58284+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
58285 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
58286- atomic_read(&tcon->stats.cifs_stats.num_opens),
58287- atomic_read(&tcon->stats.cifs_stats.num_closes),
58288- atomic_read(&tcon->stats.cifs_stats.num_deletes));
58289+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
58290+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
58291+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
58292 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
58293- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
58294- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
58295+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
58296+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
58297 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
58298- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
58299- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
58300+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
58301+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
58302 seq_printf(m, "\nRenames: %d T2 Renames %d",
58303- atomic_read(&tcon->stats.cifs_stats.num_renames),
58304- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
58305+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
58306+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
58307 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
58308- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
58309- atomic_read(&tcon->stats.cifs_stats.num_fnext),
58310- atomic_read(&tcon->stats.cifs_stats.num_fclose));
58311+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
58312+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
58313+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
58314 #endif
58315 }
58316
58317diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
58318index 35ddc3e..563e809 100644
58319--- a/fs/cifs/smb2ops.c
58320+++ b/fs/cifs/smb2ops.c
58321@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
58322 #ifdef CONFIG_CIFS_STATS
58323 int i;
58324 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
58325- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58326- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58327+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58328+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58329 }
58330 #endif
58331 }
58332@@ -405,65 +405,65 @@ static void
58333 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58334 {
58335 #ifdef CONFIG_CIFS_STATS
58336- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58337- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58338+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58339+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58340 seq_printf(m, "\nNegotiates: %d sent %d failed",
58341- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
58342- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
58343+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
58344+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
58345 seq_printf(m, "\nSessionSetups: %d sent %d failed",
58346- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
58347- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
58348+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
58349+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
58350 seq_printf(m, "\nLogoffs: %d sent %d failed",
58351- atomic_read(&sent[SMB2_LOGOFF_HE]),
58352- atomic_read(&failed[SMB2_LOGOFF_HE]));
58353+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
58354+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
58355 seq_printf(m, "\nTreeConnects: %d sent %d failed",
58356- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
58357- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
58358+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
58359+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
58360 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
58361- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
58362- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
58363+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
58364+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
58365 seq_printf(m, "\nCreates: %d sent %d failed",
58366- atomic_read(&sent[SMB2_CREATE_HE]),
58367- atomic_read(&failed[SMB2_CREATE_HE]));
58368+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
58369+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
58370 seq_printf(m, "\nCloses: %d sent %d failed",
58371- atomic_read(&sent[SMB2_CLOSE_HE]),
58372- atomic_read(&failed[SMB2_CLOSE_HE]));
58373+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
58374+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
58375 seq_printf(m, "\nFlushes: %d sent %d failed",
58376- atomic_read(&sent[SMB2_FLUSH_HE]),
58377- atomic_read(&failed[SMB2_FLUSH_HE]));
58378+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
58379+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
58380 seq_printf(m, "\nReads: %d sent %d failed",
58381- atomic_read(&sent[SMB2_READ_HE]),
58382- atomic_read(&failed[SMB2_READ_HE]));
58383+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
58384+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
58385 seq_printf(m, "\nWrites: %d sent %d failed",
58386- atomic_read(&sent[SMB2_WRITE_HE]),
58387- atomic_read(&failed[SMB2_WRITE_HE]));
58388+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
58389+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
58390 seq_printf(m, "\nLocks: %d sent %d failed",
58391- atomic_read(&sent[SMB2_LOCK_HE]),
58392- atomic_read(&failed[SMB2_LOCK_HE]));
58393+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
58394+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
58395 seq_printf(m, "\nIOCTLs: %d sent %d failed",
58396- atomic_read(&sent[SMB2_IOCTL_HE]),
58397- atomic_read(&failed[SMB2_IOCTL_HE]));
58398+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
58399+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
58400 seq_printf(m, "\nCancels: %d sent %d failed",
58401- atomic_read(&sent[SMB2_CANCEL_HE]),
58402- atomic_read(&failed[SMB2_CANCEL_HE]));
58403+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
58404+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
58405 seq_printf(m, "\nEchos: %d sent %d failed",
58406- atomic_read(&sent[SMB2_ECHO_HE]),
58407- atomic_read(&failed[SMB2_ECHO_HE]));
58408+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
58409+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
58410 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
58411- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
58412- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
58413+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
58414+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58415 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58416- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58417- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58418+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58419+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58420 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58421- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58422- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58423+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58424+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58425 seq_printf(m, "\nSetInfos: %d sent %d failed",
58426- atomic_read(&sent[SMB2_SET_INFO_HE]),
58427- atomic_read(&failed[SMB2_SET_INFO_HE]));
58428+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58429+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58430 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58431- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58432- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58433+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58434+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58435 #endif
58436 }
58437
58438diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58439index 8603447..f9caeee 100644
58440--- a/fs/cifs/smb2pdu.c
58441+++ b/fs/cifs/smb2pdu.c
58442@@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58443 default:
58444 cifs_dbg(VFS, "info level %u isn't supported\n",
58445 srch_inf->info_level);
58446- rc = -EINVAL;
58447- goto qdir_exit;
58448+ return -EINVAL;
58449 }
58450
58451 req->FileIndex = cpu_to_le32(index);
58452diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58453index 1da168c..8bc7ff6 100644
58454--- a/fs/coda/cache.c
58455+++ b/fs/coda/cache.c
58456@@ -24,7 +24,7 @@
58457 #include "coda_linux.h"
58458 #include "coda_cache.h"
58459
58460-static atomic_t permission_epoch = ATOMIC_INIT(0);
58461+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58462
58463 /* replace or extend an acl cache hit */
58464 void coda_cache_enter(struct inode *inode, int mask)
58465@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58466 struct coda_inode_info *cii = ITOC(inode);
58467
58468 spin_lock(&cii->c_lock);
58469- cii->c_cached_epoch = atomic_read(&permission_epoch);
58470+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58471 if (!uid_eq(cii->c_uid, current_fsuid())) {
58472 cii->c_uid = current_fsuid();
58473 cii->c_cached_perm = mask;
58474@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58475 {
58476 struct coda_inode_info *cii = ITOC(inode);
58477 spin_lock(&cii->c_lock);
58478- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58479+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58480 spin_unlock(&cii->c_lock);
58481 }
58482
58483 /* remove all acl caches */
58484 void coda_cache_clear_all(struct super_block *sb)
58485 {
58486- atomic_inc(&permission_epoch);
58487+ atomic_inc_unchecked(&permission_epoch);
58488 }
58489
58490
58491@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58492 spin_lock(&cii->c_lock);
58493 hit = (mask & cii->c_cached_perm) == mask &&
58494 uid_eq(cii->c_uid, current_fsuid()) &&
58495- cii->c_cached_epoch == atomic_read(&permission_epoch);
58496+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58497 spin_unlock(&cii->c_lock);
58498
58499 return hit;
58500diff --git a/fs/compat.c b/fs/compat.c
58501index 6af20de..fec3fbb 100644
58502--- a/fs/compat.c
58503+++ b/fs/compat.c
58504@@ -54,7 +54,7 @@
58505 #include <asm/ioctls.h>
58506 #include "internal.h"
58507
58508-int compat_log = 1;
58509+int compat_log = 0;
58510
58511 int compat_printk(const char *fmt, ...)
58512 {
58513@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
58514
58515 set_fs(KERNEL_DS);
58516 /* The __user pointer cast is valid because of the set_fs() */
58517- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58518+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58519 set_fs(oldfs);
58520 /* truncating is ok because it's a user address */
58521 if (!ret)
58522@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58523 goto out;
58524
58525 ret = -EINVAL;
58526- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58527+ if (nr_segs > UIO_MAXIOV)
58528 goto out;
58529 if (nr_segs > fast_segs) {
58530 ret = -ENOMEM;
58531@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
58532 struct compat_readdir_callback {
58533 struct dir_context ctx;
58534 struct compat_old_linux_dirent __user *dirent;
58535+ struct file * file;
58536 int result;
58537 };
58538
58539@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58540 buf->result = -EOVERFLOW;
58541 return -EOVERFLOW;
58542 }
58543+
58544+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58545+ return 0;
58546+
58547 buf->result++;
58548 dirent = buf->dirent;
58549 if (!access_ok(VERIFY_WRITE, dirent,
58550@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
58551 if (!f.file)
58552 return -EBADF;
58553
58554+ buf.file = f.file;
58555 error = iterate_dir(f.file, &buf.ctx);
58556 if (buf.result)
58557 error = buf.result;
58558@@ -901,6 +907,7 @@ struct compat_getdents_callback {
58559 struct dir_context ctx;
58560 struct compat_linux_dirent __user *current_dir;
58561 struct compat_linux_dirent __user *previous;
58562+ struct file * file;
58563 int count;
58564 int error;
58565 };
58566@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58567 buf->error = -EOVERFLOW;
58568 return -EOVERFLOW;
58569 }
58570+
58571+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58572+ return 0;
58573+
58574 dirent = buf->previous;
58575 if (dirent) {
58576 if (__put_user(offset, &dirent->d_off))
58577@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
58578 if (!f.file)
58579 return -EBADF;
58580
58581+ buf.file = f.file;
58582 error = iterate_dir(f.file, &buf.ctx);
58583 if (error >= 0)
58584 error = buf.error;
58585@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
58586 struct dir_context ctx;
58587 struct linux_dirent64 __user *current_dir;
58588 struct linux_dirent64 __user *previous;
58589+ struct file * file;
58590 int count;
58591 int error;
58592 };
58593@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58594 buf->error = -EINVAL; /* only used if we fail.. */
58595 if (reclen > buf->count)
58596 return -EINVAL;
58597+
58598+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58599+ return 0;
58600+
58601 dirent = buf->previous;
58602
58603 if (dirent) {
58604@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
58605 if (!f.file)
58606 return -EBADF;
58607
58608+ buf.file = f.file;
58609 error = iterate_dir(f.file, &buf.ctx);
58610 if (error >= 0)
58611 error = buf.error;
58612diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58613index a81147e..20bf2b5 100644
58614--- a/fs/compat_binfmt_elf.c
58615+++ b/fs/compat_binfmt_elf.c
58616@@ -30,11 +30,13 @@
58617 #undef elf_phdr
58618 #undef elf_shdr
58619 #undef elf_note
58620+#undef elf_dyn
58621 #undef elf_addr_t
58622 #define elfhdr elf32_hdr
58623 #define elf_phdr elf32_phdr
58624 #define elf_shdr elf32_shdr
58625 #define elf_note elf32_note
58626+#define elf_dyn Elf32_Dyn
58627 #define elf_addr_t Elf32_Addr
58628
58629 /*
58630diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58631index 3881610..ab3df0b 100644
58632--- a/fs/compat_ioctl.c
58633+++ b/fs/compat_ioctl.c
58634@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58635 return -EFAULT;
58636 if (__get_user(udata, &ss32->iomem_base))
58637 return -EFAULT;
58638- ss.iomem_base = compat_ptr(udata);
58639+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58640 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58641 __get_user(ss.port_high, &ss32->port_high))
58642 return -EFAULT;
58643@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58644 for (i = 0; i < nmsgs; i++) {
58645 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58646 return -EFAULT;
58647- if (get_user(datap, &umsgs[i].buf) ||
58648- put_user(compat_ptr(datap), &tmsgs[i].buf))
58649+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58650+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58651 return -EFAULT;
58652 }
58653 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58654@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58655 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58656 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58657 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58658- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58659+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58660 return -EFAULT;
58661
58662 return ioctl_preallocate(file, p);
58663@@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58664 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58665 {
58666 unsigned int a, b;
58667- a = *(unsigned int *)p;
58668- b = *(unsigned int *)q;
58669+ a = *(const unsigned int *)p;
58670+ b = *(const unsigned int *)q;
58671 if (a > b)
58672 return 1;
58673 if (a < b)
58674diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58675index e081acb..911df21 100644
58676--- a/fs/configfs/dir.c
58677+++ b/fs/configfs/dir.c
58678@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58679 }
58680 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58681 struct configfs_dirent *next;
58682- const char *name;
58683+ const unsigned char * name;
58684+ char d_name[sizeof(next->s_dentry->d_iname)];
58685 int len;
58686 struct inode *inode = NULL;
58687
58688@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58689 continue;
58690
58691 name = configfs_get_name(next);
58692- len = strlen(name);
58693+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58694+ len = next->s_dentry->d_name.len;
58695+ memcpy(d_name, name, len);
58696+ name = d_name;
58697+ } else
58698+ len = strlen(name);
58699
58700 /*
58701 * We'll have a dentry and an inode for
58702diff --git a/fs/coredump.c b/fs/coredump.c
58703index 0b2528f..836c55f 100644
58704--- a/fs/coredump.c
58705+++ b/fs/coredump.c
58706@@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58707 struct pipe_inode_info *pipe = file->private_data;
58708
58709 pipe_lock(pipe);
58710- pipe->readers++;
58711- pipe->writers--;
58712+ atomic_inc(&pipe->readers);
58713+ atomic_dec(&pipe->writers);
58714 wake_up_interruptible_sync(&pipe->wait);
58715 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58716 pipe_unlock(pipe);
58717@@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58718 * We actually want wait_event_freezable() but then we need
58719 * to clear TIF_SIGPENDING and improve dump_interrupted().
58720 */
58721- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58722+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58723
58724 pipe_lock(pipe);
58725- pipe->readers--;
58726- pipe->writers++;
58727+ atomic_dec(&pipe->readers);
58728+ atomic_inc(&pipe->writers);
58729 pipe_unlock(pipe);
58730 }
58731
58732@@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58733 struct files_struct *displaced;
58734 bool need_nonrelative = false;
58735 bool core_dumped = false;
58736- static atomic_t core_dump_count = ATOMIC_INIT(0);
58737+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58738+ long signr = siginfo->si_signo;
58739+ int dumpable;
58740 struct coredump_params cprm = {
58741 .siginfo = siginfo,
58742 .regs = signal_pt_regs(),
58743@@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58744 .mm_flags = mm->flags,
58745 };
58746
58747- audit_core_dumps(siginfo->si_signo);
58748+ audit_core_dumps(signr);
58749+
58750+ dumpable = __get_dumpable(cprm.mm_flags);
58751+
58752+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58753+ gr_handle_brute_attach(dumpable);
58754
58755 binfmt = mm->binfmt;
58756 if (!binfmt || !binfmt->core_dump)
58757 goto fail;
58758- if (!__get_dumpable(cprm.mm_flags))
58759+ if (!dumpable)
58760 goto fail;
58761
58762 cred = prepare_creds();
58763@@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58764 need_nonrelative = true;
58765 }
58766
58767- retval = coredump_wait(siginfo->si_signo, &core_state);
58768+ retval = coredump_wait(signr, &core_state);
58769 if (retval < 0)
58770 goto fail_creds;
58771
58772@@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58773 }
58774 cprm.limit = RLIM_INFINITY;
58775
58776- dump_count = atomic_inc_return(&core_dump_count);
58777+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58778 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58779 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58780 task_tgid_vnr(current), current->comm);
58781@@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58782 } else {
58783 struct inode *inode;
58784
58785+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58786+
58787 if (cprm.limit < binfmt->min_coredump)
58788 goto fail_unlock;
58789
58790@@ -673,7 +682,7 @@ close_fail:
58791 filp_close(cprm.file, NULL);
58792 fail_dropcount:
58793 if (ispipe)
58794- atomic_dec(&core_dump_count);
58795+ atomic_dec_unchecked(&core_dump_count);
58796 fail_unlock:
58797 kfree(cn.corename);
58798 coredump_finish(mm, core_dumped);
58799@@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58800 struct file *file = cprm->file;
58801 loff_t pos = file->f_pos;
58802 ssize_t n;
58803+
58804+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58805 if (cprm->written + nr > cprm->limit)
58806 return 0;
58807 while (nr) {
58808diff --git a/fs/dcache.c b/fs/dcache.c
58809index 7f3b400..9c911f2 100644
58810--- a/fs/dcache.c
58811+++ b/fs/dcache.c
58812@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58813 */
58814 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58815 if (name->len > DNAME_INLINE_LEN-1) {
58816- dname = kmalloc(name->len + 1, GFP_KERNEL);
58817+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58818 if (!dname) {
58819 kmem_cache_free(dentry_cache, dentry);
58820 return NULL;
58821@@ -3430,7 +3430,8 @@ void __init vfs_caches_init(unsigned long mempages)
58822 mempages -= reserve;
58823
58824 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58825- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58826+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58827+ SLAB_NO_SANITIZE, NULL);
58828
58829 dcache_init();
58830 inode_init();
58831diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58832index 9c0444c..628490c 100644
58833--- a/fs/debugfs/inode.c
58834+++ b/fs/debugfs/inode.c
58835@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58836 */
58837 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58838 {
58839+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58840+ return __create_file(name, S_IFDIR | S_IRWXU,
58841+#else
58842 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58843+#endif
58844 parent, NULL, NULL);
58845 }
58846 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58847diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58848index b167ca4..a224e19 100644
58849--- a/fs/ecryptfs/inode.c
58850+++ b/fs/ecryptfs/inode.c
58851@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58852 old_fs = get_fs();
58853 set_fs(get_ds());
58854 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58855- (char __user *)lower_buf,
58856+ (char __force_user *)lower_buf,
58857 PATH_MAX);
58858 set_fs(old_fs);
58859 if (rc < 0)
58860diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58861index e4141f2..d8263e8 100644
58862--- a/fs/ecryptfs/miscdev.c
58863+++ b/fs/ecryptfs/miscdev.c
58864@@ -304,7 +304,7 @@ check_list:
58865 goto out_unlock_msg_ctx;
58866 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58867 if (msg_ctx->msg) {
58868- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58869+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58870 goto out_unlock_msg_ctx;
58871 i += packet_length_size;
58872 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58873diff --git a/fs/exec.c b/fs/exec.c
58874index 31e46b1..88754df 100644
58875--- a/fs/exec.c
58876+++ b/fs/exec.c
58877@@ -55,8 +55,20 @@
58878 #include <linux/pipe_fs_i.h>
58879 #include <linux/oom.h>
58880 #include <linux/compat.h>
58881+#include <linux/random.h>
58882+#include <linux/seq_file.h>
58883+#include <linux/coredump.h>
58884+#include <linux/mman.h>
58885+
58886+#ifdef CONFIG_PAX_REFCOUNT
58887+#include <linux/kallsyms.h>
58888+#include <linux/kdebug.h>
58889+#endif
58890+
58891+#include <trace/events/fs.h>
58892
58893 #include <asm/uaccess.h>
58894+#include <asm/sections.h>
58895 #include <asm/mmu_context.h>
58896 #include <asm/tlb.h>
58897
58898@@ -65,19 +77,34 @@
58899
58900 #include <trace/events/sched.h>
58901
58902+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58903+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58904+{
58905+ 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");
58906+}
58907+#endif
58908+
58909+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58910+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58911+EXPORT_SYMBOL(pax_set_initial_flags_func);
58912+#endif
58913+
58914 int suid_dumpable = 0;
58915
58916 static LIST_HEAD(formats);
58917 static DEFINE_RWLOCK(binfmt_lock);
58918
58919+extern int gr_process_kernel_exec_ban(void);
58920+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58921+
58922 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58923 {
58924 BUG_ON(!fmt);
58925 if (WARN_ON(!fmt->load_binary))
58926 return;
58927 write_lock(&binfmt_lock);
58928- insert ? list_add(&fmt->lh, &formats) :
58929- list_add_tail(&fmt->lh, &formats);
58930+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58931+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58932 write_unlock(&binfmt_lock);
58933 }
58934
58935@@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
58936 void unregister_binfmt(struct linux_binfmt * fmt)
58937 {
58938 write_lock(&binfmt_lock);
58939- list_del(&fmt->lh);
58940+ pax_list_del((struct list_head *)&fmt->lh);
58941 write_unlock(&binfmt_lock);
58942 }
58943
58944@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58945 int write)
58946 {
58947 struct page *page;
58948- int ret;
58949
58950-#ifdef CONFIG_STACK_GROWSUP
58951- if (write) {
58952- ret = expand_downwards(bprm->vma, pos);
58953- if (ret < 0)
58954- return NULL;
58955- }
58956-#endif
58957- ret = get_user_pages(current, bprm->mm, pos,
58958- 1, write, 1, &page, NULL);
58959- if (ret <= 0)
58960+ if (0 > expand_downwards(bprm->vma, pos))
58961+ return NULL;
58962+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58963 return NULL;
58964
58965 if (write) {
58966@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58967 if (size <= ARG_MAX)
58968 return page;
58969
58970+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58971+ // only allow 512KB for argv+env on suid/sgid binaries
58972+ // to prevent easy ASLR exhaustion
58973+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58974+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58975+ (size > (512 * 1024))) {
58976+ put_page(page);
58977+ return NULL;
58978+ }
58979+#endif
58980+
58981 /*
58982 * Limit to 1/4-th the stack size for the argv+env strings.
58983 * This ensures that:
58984@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58985 vma->vm_end = STACK_TOP_MAX;
58986 vma->vm_start = vma->vm_end - PAGE_SIZE;
58987 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58988+
58989+#ifdef CONFIG_PAX_SEGMEXEC
58990+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58991+#endif
58992+
58993 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58994 INIT_LIST_HEAD(&vma->anon_vma_chain);
58995
58996@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58997 mm->stack_vm = mm->total_vm = 1;
58998 up_write(&mm->mmap_sem);
58999 bprm->p = vma->vm_end - sizeof(void *);
59000+
59001+#ifdef CONFIG_PAX_RANDUSTACK
59002+ if (randomize_va_space)
59003+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
59004+#endif
59005+
59006 return 0;
59007 err:
59008 up_write(&mm->mmap_sem);
59009@@ -396,7 +437,7 @@ struct user_arg_ptr {
59010 } ptr;
59011 };
59012
59013-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
59014+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
59015 {
59016 const char __user *native;
59017
59018@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
59019 compat_uptr_t compat;
59020
59021 if (get_user(compat, argv.ptr.compat + nr))
59022- return ERR_PTR(-EFAULT);
59023+ return (const char __force_user *)ERR_PTR(-EFAULT);
59024
59025 return compat_ptr(compat);
59026 }
59027 #endif
59028
59029 if (get_user(native, argv.ptr.native + nr))
59030- return ERR_PTR(-EFAULT);
59031+ return (const char __force_user *)ERR_PTR(-EFAULT);
59032
59033 return native;
59034 }
59035@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
59036 if (!p)
59037 break;
59038
59039- if (IS_ERR(p))
59040+ if (IS_ERR((const char __force_kernel *)p))
59041 return -EFAULT;
59042
59043 if (i >= max)
59044@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
59045
59046 ret = -EFAULT;
59047 str = get_user_arg_ptr(argv, argc);
59048- if (IS_ERR(str))
59049+ if (IS_ERR((const char __force_kernel *)str))
59050 goto out;
59051
59052 len = strnlen_user(str, MAX_ARG_STRLEN);
59053@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
59054 int r;
59055 mm_segment_t oldfs = get_fs();
59056 struct user_arg_ptr argv = {
59057- .ptr.native = (const char __user *const __user *)__argv,
59058+ .ptr.native = (const char __user * const __force_user *)__argv,
59059 };
59060
59061 set_fs(KERNEL_DS);
59062@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
59063 unsigned long new_end = old_end - shift;
59064 struct mmu_gather tlb;
59065
59066- BUG_ON(new_start > new_end);
59067+ if (new_start >= new_end || new_start < mmap_min_addr)
59068+ return -ENOMEM;
59069
59070 /*
59071 * ensure there are no vmas between where we want to go
59072@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
59073 if (vma != find_vma(mm, new_start))
59074 return -EFAULT;
59075
59076+#ifdef CONFIG_PAX_SEGMEXEC
59077+ BUG_ON(pax_find_mirror_vma(vma));
59078+#endif
59079+
59080 /*
59081 * cover the whole range: [new_start, old_end)
59082 */
59083@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59084 stack_top = arch_align_stack(stack_top);
59085 stack_top = PAGE_ALIGN(stack_top);
59086
59087- if (unlikely(stack_top < mmap_min_addr) ||
59088- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
59089- return -ENOMEM;
59090-
59091 stack_shift = vma->vm_end - stack_top;
59092
59093 bprm->p -= stack_shift;
59094@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
59095 bprm->exec -= stack_shift;
59096
59097 down_write(&mm->mmap_sem);
59098+
59099+ /* Move stack pages down in memory. */
59100+ if (stack_shift) {
59101+ ret = shift_arg_pages(vma, stack_shift);
59102+ if (ret)
59103+ goto out_unlock;
59104+ }
59105+
59106 vm_flags = VM_STACK_FLAGS;
59107
59108+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59109+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59110+ vm_flags &= ~VM_EXEC;
59111+
59112+#ifdef CONFIG_PAX_MPROTECT
59113+ if (mm->pax_flags & MF_PAX_MPROTECT)
59114+ vm_flags &= ~VM_MAYEXEC;
59115+#endif
59116+
59117+ }
59118+#endif
59119+
59120 /*
59121 * Adjust stack execute permissions; explicitly enable for
59122 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
59123@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59124 goto out_unlock;
59125 BUG_ON(prev != vma);
59126
59127- /* Move stack pages down in memory. */
59128- if (stack_shift) {
59129- ret = shift_arg_pages(vma, stack_shift);
59130- if (ret)
59131- goto out_unlock;
59132- }
59133-
59134 /* mprotect_fixup is overkill to remove the temporary stack flags */
59135 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
59136
59137@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
59138 #endif
59139 current->mm->start_stack = bprm->p;
59140 ret = expand_stack(vma, stack_base);
59141+
59142+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
59143+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
59144+ unsigned long size;
59145+ vm_flags_t vm_flags;
59146+
59147+ size = STACK_TOP - vma->vm_end;
59148+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
59149+
59150+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
59151+
59152+#ifdef CONFIG_X86
59153+ if (!ret) {
59154+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
59155+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
59156+ }
59157+#endif
59158+
59159+ }
59160+#endif
59161+
59162 if (ret)
59163 ret = -EFAULT;
59164
59165@@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
59166
59167 fsnotify_open(file);
59168
59169+ trace_open_exec(name->name);
59170+
59171 err = deny_write_access(file);
59172 if (err)
59173 goto exit;
59174@@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
59175 old_fs = get_fs();
59176 set_fs(get_ds());
59177 /* The cast to a user pointer is valid due to the set_fs() */
59178- result = vfs_read(file, (void __user *)addr, count, &pos);
59179+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
59180 set_fs(old_fs);
59181 return result;
59182 }
59183@@ -846,6 +924,7 @@ static int exec_mmap(struct mm_struct *mm)
59184 tsk->mm = mm;
59185 tsk->active_mm = mm;
59186 activate_mm(active_mm, mm);
59187+ populate_stack();
59188 task_unlock(tsk);
59189 if (old_mm) {
59190 up_read(&old_mm->mmap_sem);
59191@@ -1258,7 +1337,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
59192 }
59193 rcu_read_unlock();
59194
59195- if (p->fs->users > n_fs)
59196+ if (atomic_read(&p->fs->users) > n_fs)
59197 bprm->unsafe |= LSM_UNSAFE_SHARE;
59198 else
59199 p->fs->in_exec = 1;
59200@@ -1434,6 +1513,31 @@ static int exec_binprm(struct linux_binprm *bprm)
59201 return ret;
59202 }
59203
59204+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59205+static DEFINE_PER_CPU(u64, exec_counter);
59206+static int __init init_exec_counters(void)
59207+{
59208+ unsigned int cpu;
59209+
59210+ for_each_possible_cpu(cpu) {
59211+ per_cpu(exec_counter, cpu) = (u64)cpu;
59212+ }
59213+
59214+ return 0;
59215+}
59216+early_initcall(init_exec_counters);
59217+static inline void increment_exec_counter(void)
59218+{
59219+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
59220+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
59221+}
59222+#else
59223+static inline void increment_exec_counter(void) {}
59224+#endif
59225+
59226+extern void gr_handle_exec_args(struct linux_binprm *bprm,
59227+ struct user_arg_ptr argv);
59228+
59229 /*
59230 * sys_execve() executes a new program.
59231 */
59232@@ -1441,6 +1545,11 @@ static int do_execve_common(struct filename *filename,
59233 struct user_arg_ptr argv,
59234 struct user_arg_ptr envp)
59235 {
59236+#ifdef CONFIG_GRKERNSEC
59237+ struct file *old_exec_file;
59238+ struct acl_subject_label *old_acl;
59239+ struct rlimit old_rlim[RLIM_NLIMITS];
59240+#endif
59241 struct linux_binprm *bprm;
59242 struct file *file;
59243 struct files_struct *displaced;
59244@@ -1449,6 +1558,8 @@ static int do_execve_common(struct filename *filename,
59245 if (IS_ERR(filename))
59246 return PTR_ERR(filename);
59247
59248+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
59249+
59250 /*
59251 * We move the actual failure in case of RLIMIT_NPROC excess from
59252 * set*uid() to execve() because too many poorly written programs
59253@@ -1486,11 +1597,21 @@ static int do_execve_common(struct filename *filename,
59254 if (IS_ERR(file))
59255 goto out_unmark;
59256
59257+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
59258+ retval = -EPERM;
59259+ goto out_unmark;
59260+ }
59261+
59262 sched_exec();
59263
59264 bprm->file = file;
59265 bprm->filename = bprm->interp = filename->name;
59266
59267+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
59268+ retval = -EACCES;
59269+ goto out_unmark;
59270+ }
59271+
59272 retval = bprm_mm_init(bprm);
59273 if (retval)
59274 goto out_unmark;
59275@@ -1507,24 +1628,70 @@ static int do_execve_common(struct filename *filename,
59276 if (retval < 0)
59277 goto out;
59278
59279+#ifdef CONFIG_GRKERNSEC
59280+ old_acl = current->acl;
59281+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
59282+ old_exec_file = current->exec_file;
59283+ get_file(file);
59284+ current->exec_file = file;
59285+#endif
59286+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59287+ /* limit suid stack to 8MB
59288+ * we saved the old limits above and will restore them if this exec fails
59289+ */
59290+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
59291+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
59292+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
59293+#endif
59294+
59295+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
59296+ retval = -EPERM;
59297+ goto out_fail;
59298+ }
59299+
59300+ if (!gr_tpe_allow(file)) {
59301+ retval = -EACCES;
59302+ goto out_fail;
59303+ }
59304+
59305+ if (gr_check_crash_exec(file)) {
59306+ retval = -EACCES;
59307+ goto out_fail;
59308+ }
59309+
59310+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
59311+ bprm->unsafe);
59312+ if (retval < 0)
59313+ goto out_fail;
59314+
59315 retval = copy_strings_kernel(1, &bprm->filename, bprm);
59316 if (retval < 0)
59317- goto out;
59318+ goto out_fail;
59319
59320 bprm->exec = bprm->p;
59321 retval = copy_strings(bprm->envc, envp, bprm);
59322 if (retval < 0)
59323- goto out;
59324+ goto out_fail;
59325
59326 retval = copy_strings(bprm->argc, argv, bprm);
59327 if (retval < 0)
59328- goto out;
59329+ goto out_fail;
59330+
59331+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
59332+
59333+ gr_handle_exec_args(bprm, argv);
59334
59335 retval = exec_binprm(bprm);
59336 if (retval < 0)
59337- goto out;
59338+ goto out_fail;
59339+#ifdef CONFIG_GRKERNSEC
59340+ if (old_exec_file)
59341+ fput(old_exec_file);
59342+#endif
59343
59344 /* execve succeeded */
59345+
59346+ increment_exec_counter();
59347 current->fs->in_exec = 0;
59348 current->in_execve = 0;
59349 acct_update_integrals(current);
59350@@ -1535,6 +1702,14 @@ static int do_execve_common(struct filename *filename,
59351 put_files_struct(displaced);
59352 return retval;
59353
59354+out_fail:
59355+#ifdef CONFIG_GRKERNSEC
59356+ current->acl = old_acl;
59357+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
59358+ fput(current->exec_file);
59359+ current->exec_file = old_exec_file;
59360+#endif
59361+
59362 out:
59363 if (bprm->mm) {
59364 acct_arg_size(bprm, 0);
59365@@ -1626,3 +1801,312 @@ asmlinkage long compat_sys_execve(const char __user * filename,
59366 return compat_do_execve(getname(filename), argv, envp);
59367 }
59368 #endif
59369+
59370+int pax_check_flags(unsigned long *flags)
59371+{
59372+ int retval = 0;
59373+
59374+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
59375+ if (*flags & MF_PAX_SEGMEXEC)
59376+ {
59377+ *flags &= ~MF_PAX_SEGMEXEC;
59378+ retval = -EINVAL;
59379+ }
59380+#endif
59381+
59382+ if ((*flags & MF_PAX_PAGEEXEC)
59383+
59384+#ifdef CONFIG_PAX_PAGEEXEC
59385+ && (*flags & MF_PAX_SEGMEXEC)
59386+#endif
59387+
59388+ )
59389+ {
59390+ *flags &= ~MF_PAX_PAGEEXEC;
59391+ retval = -EINVAL;
59392+ }
59393+
59394+ if ((*flags & MF_PAX_MPROTECT)
59395+
59396+#ifdef CONFIG_PAX_MPROTECT
59397+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59398+#endif
59399+
59400+ )
59401+ {
59402+ *flags &= ~MF_PAX_MPROTECT;
59403+ retval = -EINVAL;
59404+ }
59405+
59406+ if ((*flags & MF_PAX_EMUTRAMP)
59407+
59408+#ifdef CONFIG_PAX_EMUTRAMP
59409+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59410+#endif
59411+
59412+ )
59413+ {
59414+ *flags &= ~MF_PAX_EMUTRAMP;
59415+ retval = -EINVAL;
59416+ }
59417+
59418+ return retval;
59419+}
59420+
59421+EXPORT_SYMBOL(pax_check_flags);
59422+
59423+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59424+char *pax_get_path(const struct path *path, char *buf, int buflen)
59425+{
59426+ char *pathname = d_path(path, buf, buflen);
59427+
59428+ if (IS_ERR(pathname))
59429+ goto toolong;
59430+
59431+ pathname = mangle_path(buf, pathname, "\t\n\\");
59432+ if (!pathname)
59433+ goto toolong;
59434+
59435+ *pathname = 0;
59436+ return buf;
59437+
59438+toolong:
59439+ return "<path too long>";
59440+}
59441+EXPORT_SYMBOL(pax_get_path);
59442+
59443+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59444+{
59445+ struct task_struct *tsk = current;
59446+ struct mm_struct *mm = current->mm;
59447+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59448+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59449+ char *path_exec = NULL;
59450+ char *path_fault = NULL;
59451+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
59452+ siginfo_t info = { };
59453+
59454+ if (buffer_exec && buffer_fault) {
59455+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59456+
59457+ down_read(&mm->mmap_sem);
59458+ vma = mm->mmap;
59459+ while (vma && (!vma_exec || !vma_fault)) {
59460+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59461+ vma_exec = vma;
59462+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59463+ vma_fault = vma;
59464+ vma = vma->vm_next;
59465+ }
59466+ if (vma_exec)
59467+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59468+ if (vma_fault) {
59469+ start = vma_fault->vm_start;
59470+ end = vma_fault->vm_end;
59471+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59472+ if (vma_fault->vm_file)
59473+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59474+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59475+ path_fault = "<heap>";
59476+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59477+ path_fault = "<stack>";
59478+ else
59479+ path_fault = "<anonymous mapping>";
59480+ }
59481+ up_read(&mm->mmap_sem);
59482+ }
59483+ if (tsk->signal->curr_ip)
59484+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59485+ else
59486+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59487+ 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),
59488+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59489+ free_page((unsigned long)buffer_exec);
59490+ free_page((unsigned long)buffer_fault);
59491+ pax_report_insns(regs, pc, sp);
59492+ info.si_signo = SIGKILL;
59493+ info.si_errno = 0;
59494+ info.si_code = SI_KERNEL;
59495+ info.si_pid = 0;
59496+ info.si_uid = 0;
59497+ do_coredump(&info);
59498+}
59499+#endif
59500+
59501+#ifdef CONFIG_PAX_REFCOUNT
59502+void pax_report_refcount_overflow(struct pt_regs *regs)
59503+{
59504+ if (current->signal->curr_ip)
59505+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59506+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
59507+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59508+ else
59509+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59510+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59511+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59512+ preempt_disable();
59513+ show_regs(regs);
59514+ preempt_enable();
59515+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59516+}
59517+#endif
59518+
59519+#ifdef CONFIG_PAX_USERCOPY
59520+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59521+static noinline int check_stack_object(const void *obj, unsigned long len)
59522+{
59523+ const void * const stack = task_stack_page(current);
59524+ const void * const stackend = stack + THREAD_SIZE;
59525+
59526+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59527+ const void *frame = NULL;
59528+ const void *oldframe;
59529+#endif
59530+
59531+ if (obj + len < obj)
59532+ return -1;
59533+
59534+ if (obj + len <= stack || stackend <= obj)
59535+ return 0;
59536+
59537+ if (obj < stack || stackend < obj + len)
59538+ return -1;
59539+
59540+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59541+ oldframe = __builtin_frame_address(1);
59542+ if (oldframe)
59543+ frame = __builtin_frame_address(2);
59544+ /*
59545+ low ----------------------------------------------> high
59546+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
59547+ ^----------------^
59548+ allow copies only within here
59549+ */
59550+ while (stack <= frame && frame < stackend) {
59551+ /* if obj + len extends past the last frame, this
59552+ check won't pass and the next frame will be 0,
59553+ causing us to bail out and correctly report
59554+ the copy as invalid
59555+ */
59556+ if (obj + len <= frame)
59557+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59558+ oldframe = frame;
59559+ frame = *(const void * const *)frame;
59560+ }
59561+ return -1;
59562+#else
59563+ return 1;
59564+#endif
59565+}
59566+
59567+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59568+{
59569+ if (current->signal->curr_ip)
59570+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59571+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59572+ else
59573+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59574+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59575+ dump_stack();
59576+ gr_handle_kernel_exploit();
59577+ do_group_exit(SIGKILL);
59578+}
59579+#endif
59580+
59581+#ifdef CONFIG_PAX_USERCOPY
59582+
59583+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59584+{
59585+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59586+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59587+#ifdef CONFIG_MODULES
59588+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59589+#else
59590+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59591+#endif
59592+
59593+#else
59594+ unsigned long textlow = (unsigned long)_stext;
59595+ unsigned long texthigh = (unsigned long)_etext;
59596+
59597+#ifdef CONFIG_X86_64
59598+ /* check against linear mapping as well */
59599+ if (high > (unsigned long)__va(__pa(textlow)) &&
59600+ low < (unsigned long)__va(__pa(texthigh)))
59601+ return true;
59602+#endif
59603+
59604+#endif
59605+
59606+ if (high <= textlow || low >= texthigh)
59607+ return false;
59608+ else
59609+ return true;
59610+}
59611+#endif
59612+
59613+void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
59614+{
59615+#ifdef CONFIG_PAX_USERCOPY
59616+ const char *type;
59617+#endif
59618+
59619+#ifndef CONFIG_STACK_GROWSUP
59620+ unsigned long stackstart = (unsigned long)task_stack_page(current);
59621+ unsigned long currentsp = (unsigned long)&stackstart;
59622+ if (unlikely((currentsp < stackstart + 512 ||
59623+ currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
59624+ BUG();
59625+#endif
59626+
59627+#ifndef CONFIG_PAX_USERCOPY_DEBUG
59628+ if (const_size)
59629+ return;
59630+#endif
59631+
59632+#ifdef CONFIG_PAX_USERCOPY
59633+ if (!n)
59634+ return;
59635+
59636+ type = check_heap_object(ptr, n);
59637+ if (!type) {
59638+ int ret = check_stack_object(ptr, n);
59639+ if (ret == 1 || ret == 2)
59640+ return;
59641+ if (ret == 0) {
59642+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59643+ type = "<kernel text>";
59644+ else
59645+ return;
59646+ } else
59647+ type = "<process stack>";
59648+ }
59649+
59650+ pax_report_usercopy(ptr, n, to_user, type);
59651+#endif
59652+
59653+}
59654+EXPORT_SYMBOL(__check_object_size);
59655+
59656+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59657+void pax_track_stack(void)
59658+{
59659+ unsigned long sp = (unsigned long)&sp;
59660+ if (sp < current_thread_info()->lowest_stack &&
59661+ sp > (unsigned long)task_stack_page(current))
59662+ current_thread_info()->lowest_stack = sp;
59663+ if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
59664+ BUG();
59665+}
59666+EXPORT_SYMBOL(pax_track_stack);
59667+#endif
59668+
59669+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59670+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59671+{
59672+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59673+ dump_stack();
59674+ do_group_exit(SIGKILL);
59675+}
59676+EXPORT_SYMBOL(report_size_overflow);
59677+#endif
59678diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59679index 9f9992b..8b59411 100644
59680--- a/fs/ext2/balloc.c
59681+++ b/fs/ext2/balloc.c
59682@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59683
59684 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59685 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59686- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59687+ if (free_blocks < root_blocks + 1 &&
59688 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59689 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59690- !in_group_p (sbi->s_resgid))) {
59691+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59692 return 0;
59693 }
59694 return 1;
59695diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59696index 9142614..97484fa 100644
59697--- a/fs/ext2/xattr.c
59698+++ b/fs/ext2/xattr.c
59699@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59700 struct buffer_head *bh = NULL;
59701 struct ext2_xattr_entry *entry;
59702 char *end;
59703- size_t rest = buffer_size;
59704+ size_t rest = buffer_size, total_size = 0;
59705 int error;
59706
59707 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59708@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59709 buffer += size;
59710 }
59711 rest -= size;
59712+ total_size += size;
59713 }
59714 }
59715- error = buffer_size - rest; /* total size */
59716+ error = total_size;
59717
59718 cleanup:
59719 brelse(bh);
59720diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59721index 22548f5..41521d8 100644
59722--- a/fs/ext3/balloc.c
59723+++ b/fs/ext3/balloc.c
59724@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59725
59726 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59727 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59728- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59729+ if (free_blocks < root_blocks + 1 &&
59730 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59731 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59732- !in_group_p (sbi->s_resgid))) {
59733+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59734 return 0;
59735 }
59736 return 1;
59737diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59738index c6874be..f8a6ae8 100644
59739--- a/fs/ext3/xattr.c
59740+++ b/fs/ext3/xattr.c
59741@@ -330,7 +330,7 @@ static int
59742 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59743 char *buffer, size_t buffer_size)
59744 {
59745- size_t rest = buffer_size;
59746+ size_t rest = buffer_size, total_size = 0;
59747
59748 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59749 const struct xattr_handler *handler =
59750@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59751 buffer += size;
59752 }
59753 rest -= size;
59754+ total_size += size;
59755 }
59756 }
59757- return buffer_size - rest;
59758+ return total_size;
59759 }
59760
59761 static int
59762diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59763index 6ea7b14..8fa16d9 100644
59764--- a/fs/ext4/balloc.c
59765+++ b/fs/ext4/balloc.c
59766@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59767 /* Hm, nope. Are (enough) root reserved clusters available? */
59768 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59769 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59770- capable(CAP_SYS_RESOURCE) ||
59771- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59772+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59773+ capable_nolog(CAP_SYS_RESOURCE)) {
59774
59775 if (free_clusters >= (nclusters + dirty_clusters +
59776 resv_clusters))
59777diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59778index 3a603a8..9b868ba 100644
59779--- a/fs/ext4/ext4.h
59780+++ b/fs/ext4/ext4.h
59781@@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59782 unsigned long s_mb_last_start;
59783
59784 /* stats for buddy allocator */
59785- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59786- atomic_t s_bal_success; /* we found long enough chunks */
59787- atomic_t s_bal_allocated; /* in blocks */
59788- atomic_t s_bal_ex_scanned; /* total extents scanned */
59789- atomic_t s_bal_goals; /* goal hits */
59790- atomic_t s_bal_breaks; /* too long searches */
59791- atomic_t s_bal_2orders; /* 2^order hits */
59792+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59793+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59794+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59795+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59796+ atomic_unchecked_t s_bal_goals; /* goal hits */
59797+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59798+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59799 spinlock_t s_bal_lock;
59800 unsigned long s_mb_buddies_generated;
59801 unsigned long long s_mb_generation_time;
59802- atomic_t s_mb_lost_chunks;
59803- atomic_t s_mb_preallocated;
59804- atomic_t s_mb_discarded;
59805+ atomic_unchecked_t s_mb_lost_chunks;
59806+ atomic_unchecked_t s_mb_preallocated;
59807+ atomic_unchecked_t s_mb_discarded;
59808 atomic_t s_lock_busy;
59809
59810 /* locality groups */
59811diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59812index 04a5c75..09894fa 100644
59813--- a/fs/ext4/mballoc.c
59814+++ b/fs/ext4/mballoc.c
59815@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59816 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59817
59818 if (EXT4_SB(sb)->s_mb_stats)
59819- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59820+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59821
59822 break;
59823 }
59824@@ -2189,7 +2189,7 @@ repeat:
59825 ac->ac_status = AC_STATUS_CONTINUE;
59826 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59827 cr = 3;
59828- atomic_inc(&sbi->s_mb_lost_chunks);
59829+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59830 goto repeat;
59831 }
59832 }
59833@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59834 if (sbi->s_mb_stats) {
59835 ext4_msg(sb, KERN_INFO,
59836 "mballoc: %u blocks %u reqs (%u success)",
59837- atomic_read(&sbi->s_bal_allocated),
59838- atomic_read(&sbi->s_bal_reqs),
59839- atomic_read(&sbi->s_bal_success));
59840+ atomic_read_unchecked(&sbi->s_bal_allocated),
59841+ atomic_read_unchecked(&sbi->s_bal_reqs),
59842+ atomic_read_unchecked(&sbi->s_bal_success));
59843 ext4_msg(sb, KERN_INFO,
59844 "mballoc: %u extents scanned, %u goal hits, "
59845 "%u 2^N hits, %u breaks, %u lost",
59846- atomic_read(&sbi->s_bal_ex_scanned),
59847- atomic_read(&sbi->s_bal_goals),
59848- atomic_read(&sbi->s_bal_2orders),
59849- atomic_read(&sbi->s_bal_breaks),
59850- atomic_read(&sbi->s_mb_lost_chunks));
59851+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59852+ atomic_read_unchecked(&sbi->s_bal_goals),
59853+ atomic_read_unchecked(&sbi->s_bal_2orders),
59854+ atomic_read_unchecked(&sbi->s_bal_breaks),
59855+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59856 ext4_msg(sb, KERN_INFO,
59857 "mballoc: %lu generated and it took %Lu",
59858 sbi->s_mb_buddies_generated,
59859 sbi->s_mb_generation_time);
59860 ext4_msg(sb, KERN_INFO,
59861 "mballoc: %u preallocated, %u discarded",
59862- atomic_read(&sbi->s_mb_preallocated),
59863- atomic_read(&sbi->s_mb_discarded));
59864+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59865+ atomic_read_unchecked(&sbi->s_mb_discarded));
59866 }
59867
59868 free_percpu(sbi->s_locality_groups);
59869@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59870 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59871
59872 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59873- atomic_inc(&sbi->s_bal_reqs);
59874- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59875+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59876+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59877 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59878- atomic_inc(&sbi->s_bal_success);
59879- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59880+ atomic_inc_unchecked(&sbi->s_bal_success);
59881+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59882 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59883 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59884- atomic_inc(&sbi->s_bal_goals);
59885+ atomic_inc_unchecked(&sbi->s_bal_goals);
59886 if (ac->ac_found > sbi->s_mb_max_to_scan)
59887- atomic_inc(&sbi->s_bal_breaks);
59888+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59889 }
59890
59891 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59892@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59893 trace_ext4_mb_new_inode_pa(ac, pa);
59894
59895 ext4_mb_use_inode_pa(ac, pa);
59896- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59897+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59898
59899 ei = EXT4_I(ac->ac_inode);
59900 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59901@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59902 trace_ext4_mb_new_group_pa(ac, pa);
59903
59904 ext4_mb_use_group_pa(ac, pa);
59905- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59906+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59907
59908 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59909 lg = ac->ac_lg;
59910@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59911 * from the bitmap and continue.
59912 */
59913 }
59914- atomic_add(free, &sbi->s_mb_discarded);
59915+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59916
59917 return err;
59918 }
59919@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59920 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59921 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59922 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59923- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59924+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59925 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59926
59927 return 0;
59928diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59929index 04434ad..6404663 100644
59930--- a/fs/ext4/mmp.c
59931+++ b/fs/ext4/mmp.c
59932@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59933 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59934 const char *function, unsigned int line, const char *msg)
59935 {
59936- __ext4_warning(sb, function, line, msg);
59937+ __ext4_warning(sb, function, line, "%s", msg);
59938 __ext4_warning(sb, function, line,
59939 "MMP failure info: last update time: %llu, last update "
59940 "node: %s, last update device: %s\n",
59941diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59942index 710fed2..a82e4e8 100644
59943--- a/fs/ext4/super.c
59944+++ b/fs/ext4/super.c
59945@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59946 }
59947
59948 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59949-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59950+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59951 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59952
59953 #ifdef CONFIG_QUOTA
59954@@ -2450,7 +2450,7 @@ struct ext4_attr {
59955 int offset;
59956 int deprecated_val;
59957 } u;
59958-};
59959+} __do_const;
59960
59961 static int parse_strtoull(const char *buf,
59962 unsigned long long max, unsigned long long *value)
59963diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59964index 55e611c..cfad16d 100644
59965--- a/fs/ext4/xattr.c
59966+++ b/fs/ext4/xattr.c
59967@@ -381,7 +381,7 @@ static int
59968 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59969 char *buffer, size_t buffer_size)
59970 {
59971- size_t rest = buffer_size;
59972+ size_t rest = buffer_size, total_size = 0;
59973
59974 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59975 const struct xattr_handler *handler =
59976@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59977 buffer += size;
59978 }
59979 rest -= size;
59980+ total_size += size;
59981 }
59982 }
59983- return buffer_size - rest;
59984+ return total_size;
59985 }
59986
59987 static int
59988diff --git a/fs/fcntl.c b/fs/fcntl.c
59989index ef68665..5deacdc 100644
59990--- a/fs/fcntl.c
59991+++ b/fs/fcntl.c
59992@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59993 if (err)
59994 return err;
59995
59996+ if (gr_handle_chroot_fowner(pid, type))
59997+ return -ENOENT;
59998+ if (gr_check_protected_task_fowner(pid, type))
59999+ return -EACCES;
60000+
60001 f_modown(filp, pid, type, force);
60002 return 0;
60003 }
60004diff --git a/fs/fhandle.c b/fs/fhandle.c
60005index 999ff5c..ac037c9 100644
60006--- a/fs/fhandle.c
60007+++ b/fs/fhandle.c
60008@@ -8,6 +8,7 @@
60009 #include <linux/fs_struct.h>
60010 #include <linux/fsnotify.h>
60011 #include <linux/personality.h>
60012+#include <linux/grsecurity.h>
60013 #include <asm/uaccess.h>
60014 #include "internal.h"
60015 #include "mount.h"
60016@@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
60017 } else
60018 retval = 0;
60019 /* copy the mount id */
60020- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
60021- sizeof(*mnt_id)) ||
60022+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
60023 copy_to_user(ufh, handle,
60024 sizeof(struct file_handle) + handle_bytes))
60025 retval = -EFAULT;
60026@@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
60027 * the directory. Ideally we would like CAP_DAC_SEARCH.
60028 * But we don't have that
60029 */
60030- if (!capable(CAP_DAC_READ_SEARCH)) {
60031+ if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
60032 retval = -EPERM;
60033 goto out_err;
60034 }
60035diff --git a/fs/file.c b/fs/file.c
60036index eb56a13..ccee850 100644
60037--- a/fs/file.c
60038+++ b/fs/file.c
60039@@ -16,6 +16,7 @@
60040 #include <linux/slab.h>
60041 #include <linux/vmalloc.h>
60042 #include <linux/file.h>
60043+#include <linux/security.h>
60044 #include <linux/fdtable.h>
60045 #include <linux/bitops.h>
60046 #include <linux/interrupt.h>
60047@@ -141,7 +142,7 @@ out:
60048 * Return <0 error code on error; 1 on successful completion.
60049 * The files->file_lock should be held on entry, and will be held on exit.
60050 */
60051-static int expand_fdtable(struct files_struct *files, int nr)
60052+static int expand_fdtable(struct files_struct *files, unsigned int nr)
60053 __releases(files->file_lock)
60054 __acquires(files->file_lock)
60055 {
60056@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
60057 * expanded and execution may have blocked.
60058 * The files->file_lock should be held on entry, and will be held on exit.
60059 */
60060-static int expand_files(struct files_struct *files, int nr)
60061+static int expand_files(struct files_struct *files, unsigned int nr)
60062 {
60063 struct fdtable *fdt;
60064
60065@@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
60066 if (!file)
60067 return __close_fd(files, fd);
60068
60069+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
60070 if (fd >= rlimit(RLIMIT_NOFILE))
60071 return -EBADF;
60072
60073@@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
60074 if (unlikely(oldfd == newfd))
60075 return -EINVAL;
60076
60077+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
60078 if (newfd >= rlimit(RLIMIT_NOFILE))
60079 return -EBADF;
60080
60081@@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
60082 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
60083 {
60084 int err;
60085+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
60086 if (from >= rlimit(RLIMIT_NOFILE))
60087 return -EINVAL;
60088 err = alloc_fd(from, flags);
60089diff --git a/fs/filesystems.c b/fs/filesystems.c
60090index 92567d9..fcd8cbf 100644
60091--- a/fs/filesystems.c
60092+++ b/fs/filesystems.c
60093@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
60094 int len = dot ? dot - name : strlen(name);
60095
60096 fs = __get_fs_type(name, len);
60097+#ifdef CONFIG_GRKERNSEC_MODHARDEN
60098+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
60099+#else
60100 if (!fs && (request_module("fs-%.*s", len, name) == 0))
60101+#endif
60102 fs = __get_fs_type(name, len);
60103
60104 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
60105diff --git a/fs/fs_struct.c b/fs/fs_struct.c
60106index 7dca743..543d620 100644
60107--- a/fs/fs_struct.c
60108+++ b/fs/fs_struct.c
60109@@ -4,6 +4,7 @@
60110 #include <linux/path.h>
60111 #include <linux/slab.h>
60112 #include <linux/fs_struct.h>
60113+#include <linux/grsecurity.h>
60114 #include "internal.h"
60115
60116 /*
60117@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
60118 write_seqcount_begin(&fs->seq);
60119 old_root = fs->root;
60120 fs->root = *path;
60121+ gr_set_chroot_entries(current, path);
60122 write_seqcount_end(&fs->seq);
60123 spin_unlock(&fs->lock);
60124 if (old_root.dentry)
60125@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
60126 int hits = 0;
60127 spin_lock(&fs->lock);
60128 write_seqcount_begin(&fs->seq);
60129+ /* this root replacement is only done by pivot_root,
60130+ leave grsec's chroot tagging alone for this task
60131+ so that a pivoted root isn't treated as a chroot
60132+ */
60133 hits += replace_path(&fs->root, old_root, new_root);
60134 hits += replace_path(&fs->pwd, old_root, new_root);
60135 write_seqcount_end(&fs->seq);
60136@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
60137 task_lock(tsk);
60138 spin_lock(&fs->lock);
60139 tsk->fs = NULL;
60140- kill = !--fs->users;
60141+ gr_clear_chroot_entries(tsk);
60142+ kill = !atomic_dec_return(&fs->users);
60143 spin_unlock(&fs->lock);
60144 task_unlock(tsk);
60145 if (kill)
60146@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60147 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
60148 /* We don't need to lock fs - think why ;-) */
60149 if (fs) {
60150- fs->users = 1;
60151+ atomic_set(&fs->users, 1);
60152 fs->in_exec = 0;
60153 spin_lock_init(&fs->lock);
60154 seqcount_init(&fs->seq);
60155@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60156 spin_lock(&old->lock);
60157 fs->root = old->root;
60158 path_get(&fs->root);
60159+ /* instead of calling gr_set_chroot_entries here,
60160+ we call it from every caller of this function
60161+ */
60162 fs->pwd = old->pwd;
60163 path_get(&fs->pwd);
60164 spin_unlock(&old->lock);
60165@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
60166
60167 task_lock(current);
60168 spin_lock(&fs->lock);
60169- kill = !--fs->users;
60170+ kill = !atomic_dec_return(&fs->users);
60171 current->fs = new_fs;
60172+ gr_set_chroot_entries(current, &new_fs->root);
60173 spin_unlock(&fs->lock);
60174 task_unlock(current);
60175
60176@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
60177
60178 int current_umask(void)
60179 {
60180- return current->fs->umask;
60181+ return current->fs->umask | gr_acl_umask();
60182 }
60183 EXPORT_SYMBOL(current_umask);
60184
60185 /* to be mentioned only in INIT_TASK */
60186 struct fs_struct init_fs = {
60187- .users = 1,
60188+ .users = ATOMIC_INIT(1),
60189 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
60190 .seq = SEQCNT_ZERO(init_fs.seq),
60191 .umask = 0022,
60192diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
60193index 29d7feb..303644d 100644
60194--- a/fs/fscache/cookie.c
60195+++ b/fs/fscache/cookie.c
60196@@ -19,7 +19,7 @@
60197
60198 struct kmem_cache *fscache_cookie_jar;
60199
60200-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
60201+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
60202
60203 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
60204 static int fscache_alloc_object(struct fscache_cache *cache,
60205@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
60206 parent ? (char *) parent->def->name : "<no-parent>",
60207 def->name, netfs_data, enable);
60208
60209- fscache_stat(&fscache_n_acquires);
60210+ fscache_stat_unchecked(&fscache_n_acquires);
60211
60212 /* if there's no parent cookie, then we don't create one here either */
60213 if (!parent) {
60214- fscache_stat(&fscache_n_acquires_null);
60215+ fscache_stat_unchecked(&fscache_n_acquires_null);
60216 _leave(" [no parent]");
60217 return NULL;
60218 }
60219@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60220 /* allocate and initialise a cookie */
60221 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
60222 if (!cookie) {
60223- fscache_stat(&fscache_n_acquires_oom);
60224+ fscache_stat_unchecked(&fscache_n_acquires_oom);
60225 _leave(" [ENOMEM]");
60226 return NULL;
60227 }
60228@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
60229
60230 switch (cookie->def->type) {
60231 case FSCACHE_COOKIE_TYPE_INDEX:
60232- fscache_stat(&fscache_n_cookie_index);
60233+ fscache_stat_unchecked(&fscache_n_cookie_index);
60234 break;
60235 case FSCACHE_COOKIE_TYPE_DATAFILE:
60236- fscache_stat(&fscache_n_cookie_data);
60237+ fscache_stat_unchecked(&fscache_n_cookie_data);
60238 break;
60239 default:
60240- fscache_stat(&fscache_n_cookie_special);
60241+ fscache_stat_unchecked(&fscache_n_cookie_special);
60242 break;
60243 }
60244
60245@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60246 } else {
60247 atomic_dec(&parent->n_children);
60248 __fscache_cookie_put(cookie);
60249- fscache_stat(&fscache_n_acquires_nobufs);
60250+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
60251 _leave(" = NULL");
60252 return NULL;
60253 }
60254@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60255 }
60256 }
60257
60258- fscache_stat(&fscache_n_acquires_ok);
60259+ fscache_stat_unchecked(&fscache_n_acquires_ok);
60260 _leave(" = %p", cookie);
60261 return cookie;
60262 }
60263@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
60264 cache = fscache_select_cache_for_object(cookie->parent);
60265 if (!cache) {
60266 up_read(&fscache_addremove_sem);
60267- fscache_stat(&fscache_n_acquires_no_cache);
60268+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
60269 _leave(" = -ENOMEDIUM [no cache]");
60270 return -ENOMEDIUM;
60271 }
60272@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
60273 object = cache->ops->alloc_object(cache, cookie);
60274 fscache_stat_d(&fscache_n_cop_alloc_object);
60275 if (IS_ERR(object)) {
60276- fscache_stat(&fscache_n_object_no_alloc);
60277+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
60278 ret = PTR_ERR(object);
60279 goto error;
60280 }
60281
60282- fscache_stat(&fscache_n_object_alloc);
60283+ fscache_stat_unchecked(&fscache_n_object_alloc);
60284
60285- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
60286+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
60287
60288 _debug("ALLOC OBJ%x: %s {%lx}",
60289 object->debug_id, cookie->def->name, object->events);
60290@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
60291
60292 _enter("{%s}", cookie->def->name);
60293
60294- fscache_stat(&fscache_n_invalidates);
60295+ fscache_stat_unchecked(&fscache_n_invalidates);
60296
60297 /* Only permit invalidation of data files. Invalidating an index will
60298 * require the caller to release all its attachments to the tree rooted
60299@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
60300 {
60301 struct fscache_object *object;
60302
60303- fscache_stat(&fscache_n_updates);
60304+ fscache_stat_unchecked(&fscache_n_updates);
60305
60306 if (!cookie) {
60307- fscache_stat(&fscache_n_updates_null);
60308+ fscache_stat_unchecked(&fscache_n_updates_null);
60309 _leave(" [no cookie]");
60310 return;
60311 }
60312@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
60313 */
60314 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
60315 {
60316- fscache_stat(&fscache_n_relinquishes);
60317+ fscache_stat_unchecked(&fscache_n_relinquishes);
60318 if (retire)
60319- fscache_stat(&fscache_n_relinquishes_retire);
60320+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
60321
60322 if (!cookie) {
60323- fscache_stat(&fscache_n_relinquishes_null);
60324+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
60325 _leave(" [no cookie]");
60326 return;
60327 }
60328@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
60329 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
60330 goto inconsistent;
60331
60332- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60333+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60334
60335 __fscache_use_cookie(cookie);
60336 if (fscache_submit_op(object, op) < 0)
60337diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
60338index 4226f66..0fb3f45 100644
60339--- a/fs/fscache/internal.h
60340+++ b/fs/fscache/internal.h
60341@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
60342 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
60343 extern int fscache_wait_for_operation_activation(struct fscache_object *,
60344 struct fscache_operation *,
60345- atomic_t *,
60346- atomic_t *,
60347+ atomic_unchecked_t *,
60348+ atomic_unchecked_t *,
60349 void (*)(struct fscache_operation *));
60350 extern void fscache_invalidate_writes(struct fscache_cookie *);
60351
60352@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
60353 * stats.c
60354 */
60355 #ifdef CONFIG_FSCACHE_STATS
60356-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60357-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60358+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60359+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60360
60361-extern atomic_t fscache_n_op_pend;
60362-extern atomic_t fscache_n_op_run;
60363-extern atomic_t fscache_n_op_enqueue;
60364-extern atomic_t fscache_n_op_deferred_release;
60365-extern atomic_t fscache_n_op_release;
60366-extern atomic_t fscache_n_op_gc;
60367-extern atomic_t fscache_n_op_cancelled;
60368-extern atomic_t fscache_n_op_rejected;
60369+extern atomic_unchecked_t fscache_n_op_pend;
60370+extern atomic_unchecked_t fscache_n_op_run;
60371+extern atomic_unchecked_t fscache_n_op_enqueue;
60372+extern atomic_unchecked_t fscache_n_op_deferred_release;
60373+extern atomic_unchecked_t fscache_n_op_release;
60374+extern atomic_unchecked_t fscache_n_op_gc;
60375+extern atomic_unchecked_t fscache_n_op_cancelled;
60376+extern atomic_unchecked_t fscache_n_op_rejected;
60377
60378-extern atomic_t fscache_n_attr_changed;
60379-extern atomic_t fscache_n_attr_changed_ok;
60380-extern atomic_t fscache_n_attr_changed_nobufs;
60381-extern atomic_t fscache_n_attr_changed_nomem;
60382-extern atomic_t fscache_n_attr_changed_calls;
60383+extern atomic_unchecked_t fscache_n_attr_changed;
60384+extern atomic_unchecked_t fscache_n_attr_changed_ok;
60385+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
60386+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
60387+extern atomic_unchecked_t fscache_n_attr_changed_calls;
60388
60389-extern atomic_t fscache_n_allocs;
60390-extern atomic_t fscache_n_allocs_ok;
60391-extern atomic_t fscache_n_allocs_wait;
60392-extern atomic_t fscache_n_allocs_nobufs;
60393-extern atomic_t fscache_n_allocs_intr;
60394-extern atomic_t fscache_n_allocs_object_dead;
60395-extern atomic_t fscache_n_alloc_ops;
60396-extern atomic_t fscache_n_alloc_op_waits;
60397+extern atomic_unchecked_t fscache_n_allocs;
60398+extern atomic_unchecked_t fscache_n_allocs_ok;
60399+extern atomic_unchecked_t fscache_n_allocs_wait;
60400+extern atomic_unchecked_t fscache_n_allocs_nobufs;
60401+extern atomic_unchecked_t fscache_n_allocs_intr;
60402+extern atomic_unchecked_t fscache_n_allocs_object_dead;
60403+extern atomic_unchecked_t fscache_n_alloc_ops;
60404+extern atomic_unchecked_t fscache_n_alloc_op_waits;
60405
60406-extern atomic_t fscache_n_retrievals;
60407-extern atomic_t fscache_n_retrievals_ok;
60408-extern atomic_t fscache_n_retrievals_wait;
60409-extern atomic_t fscache_n_retrievals_nodata;
60410-extern atomic_t fscache_n_retrievals_nobufs;
60411-extern atomic_t fscache_n_retrievals_intr;
60412-extern atomic_t fscache_n_retrievals_nomem;
60413-extern atomic_t fscache_n_retrievals_object_dead;
60414-extern atomic_t fscache_n_retrieval_ops;
60415-extern atomic_t fscache_n_retrieval_op_waits;
60416+extern atomic_unchecked_t fscache_n_retrievals;
60417+extern atomic_unchecked_t fscache_n_retrievals_ok;
60418+extern atomic_unchecked_t fscache_n_retrievals_wait;
60419+extern atomic_unchecked_t fscache_n_retrievals_nodata;
60420+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
60421+extern atomic_unchecked_t fscache_n_retrievals_intr;
60422+extern atomic_unchecked_t fscache_n_retrievals_nomem;
60423+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
60424+extern atomic_unchecked_t fscache_n_retrieval_ops;
60425+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
60426
60427-extern atomic_t fscache_n_stores;
60428-extern atomic_t fscache_n_stores_ok;
60429-extern atomic_t fscache_n_stores_again;
60430-extern atomic_t fscache_n_stores_nobufs;
60431-extern atomic_t fscache_n_stores_oom;
60432-extern atomic_t fscache_n_store_ops;
60433-extern atomic_t fscache_n_store_calls;
60434-extern atomic_t fscache_n_store_pages;
60435-extern atomic_t fscache_n_store_radix_deletes;
60436-extern atomic_t fscache_n_store_pages_over_limit;
60437+extern atomic_unchecked_t fscache_n_stores;
60438+extern atomic_unchecked_t fscache_n_stores_ok;
60439+extern atomic_unchecked_t fscache_n_stores_again;
60440+extern atomic_unchecked_t fscache_n_stores_nobufs;
60441+extern atomic_unchecked_t fscache_n_stores_oom;
60442+extern atomic_unchecked_t fscache_n_store_ops;
60443+extern atomic_unchecked_t fscache_n_store_calls;
60444+extern atomic_unchecked_t fscache_n_store_pages;
60445+extern atomic_unchecked_t fscache_n_store_radix_deletes;
60446+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60447
60448-extern atomic_t fscache_n_store_vmscan_not_storing;
60449-extern atomic_t fscache_n_store_vmscan_gone;
60450-extern atomic_t fscache_n_store_vmscan_busy;
60451-extern atomic_t fscache_n_store_vmscan_cancelled;
60452-extern atomic_t fscache_n_store_vmscan_wait;
60453+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60454+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60455+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60456+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60457+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60458
60459-extern atomic_t fscache_n_marks;
60460-extern atomic_t fscache_n_uncaches;
60461+extern atomic_unchecked_t fscache_n_marks;
60462+extern atomic_unchecked_t fscache_n_uncaches;
60463
60464-extern atomic_t fscache_n_acquires;
60465-extern atomic_t fscache_n_acquires_null;
60466-extern atomic_t fscache_n_acquires_no_cache;
60467-extern atomic_t fscache_n_acquires_ok;
60468-extern atomic_t fscache_n_acquires_nobufs;
60469-extern atomic_t fscache_n_acquires_oom;
60470+extern atomic_unchecked_t fscache_n_acquires;
60471+extern atomic_unchecked_t fscache_n_acquires_null;
60472+extern atomic_unchecked_t fscache_n_acquires_no_cache;
60473+extern atomic_unchecked_t fscache_n_acquires_ok;
60474+extern atomic_unchecked_t fscache_n_acquires_nobufs;
60475+extern atomic_unchecked_t fscache_n_acquires_oom;
60476
60477-extern atomic_t fscache_n_invalidates;
60478-extern atomic_t fscache_n_invalidates_run;
60479+extern atomic_unchecked_t fscache_n_invalidates;
60480+extern atomic_unchecked_t fscache_n_invalidates_run;
60481
60482-extern atomic_t fscache_n_updates;
60483-extern atomic_t fscache_n_updates_null;
60484-extern atomic_t fscache_n_updates_run;
60485+extern atomic_unchecked_t fscache_n_updates;
60486+extern atomic_unchecked_t fscache_n_updates_null;
60487+extern atomic_unchecked_t fscache_n_updates_run;
60488
60489-extern atomic_t fscache_n_relinquishes;
60490-extern atomic_t fscache_n_relinquishes_null;
60491-extern atomic_t fscache_n_relinquishes_waitcrt;
60492-extern atomic_t fscache_n_relinquishes_retire;
60493+extern atomic_unchecked_t fscache_n_relinquishes;
60494+extern atomic_unchecked_t fscache_n_relinquishes_null;
60495+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60496+extern atomic_unchecked_t fscache_n_relinquishes_retire;
60497
60498-extern atomic_t fscache_n_cookie_index;
60499-extern atomic_t fscache_n_cookie_data;
60500-extern atomic_t fscache_n_cookie_special;
60501+extern atomic_unchecked_t fscache_n_cookie_index;
60502+extern atomic_unchecked_t fscache_n_cookie_data;
60503+extern atomic_unchecked_t fscache_n_cookie_special;
60504
60505-extern atomic_t fscache_n_object_alloc;
60506-extern atomic_t fscache_n_object_no_alloc;
60507-extern atomic_t fscache_n_object_lookups;
60508-extern atomic_t fscache_n_object_lookups_negative;
60509-extern atomic_t fscache_n_object_lookups_positive;
60510-extern atomic_t fscache_n_object_lookups_timed_out;
60511-extern atomic_t fscache_n_object_created;
60512-extern atomic_t fscache_n_object_avail;
60513-extern atomic_t fscache_n_object_dead;
60514+extern atomic_unchecked_t fscache_n_object_alloc;
60515+extern atomic_unchecked_t fscache_n_object_no_alloc;
60516+extern atomic_unchecked_t fscache_n_object_lookups;
60517+extern atomic_unchecked_t fscache_n_object_lookups_negative;
60518+extern atomic_unchecked_t fscache_n_object_lookups_positive;
60519+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60520+extern atomic_unchecked_t fscache_n_object_created;
60521+extern atomic_unchecked_t fscache_n_object_avail;
60522+extern atomic_unchecked_t fscache_n_object_dead;
60523
60524-extern atomic_t fscache_n_checkaux_none;
60525-extern atomic_t fscache_n_checkaux_okay;
60526-extern atomic_t fscache_n_checkaux_update;
60527-extern atomic_t fscache_n_checkaux_obsolete;
60528+extern atomic_unchecked_t fscache_n_checkaux_none;
60529+extern atomic_unchecked_t fscache_n_checkaux_okay;
60530+extern atomic_unchecked_t fscache_n_checkaux_update;
60531+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60532
60533 extern atomic_t fscache_n_cop_alloc_object;
60534 extern atomic_t fscache_n_cop_lookup_object;
60535@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60536 atomic_inc(stat);
60537 }
60538
60539+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60540+{
60541+ atomic_inc_unchecked(stat);
60542+}
60543+
60544 static inline void fscache_stat_d(atomic_t *stat)
60545 {
60546 atomic_dec(stat);
60547@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60548
60549 #define __fscache_stat(stat) (NULL)
60550 #define fscache_stat(stat) do {} while (0)
60551+#define fscache_stat_unchecked(stat) do {} while (0)
60552 #define fscache_stat_d(stat) do {} while (0)
60553 #endif
60554
60555diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60556index d3b4539..ed0c659 100644
60557--- a/fs/fscache/object.c
60558+++ b/fs/fscache/object.c
60559@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60560 _debug("LOOKUP \"%s\" in \"%s\"",
60561 cookie->def->name, object->cache->tag->name);
60562
60563- fscache_stat(&fscache_n_object_lookups);
60564+ fscache_stat_unchecked(&fscache_n_object_lookups);
60565 fscache_stat(&fscache_n_cop_lookup_object);
60566 ret = object->cache->ops->lookup_object(object);
60567 fscache_stat_d(&fscache_n_cop_lookup_object);
60568@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60569 if (ret == -ETIMEDOUT) {
60570 /* probably stuck behind another object, so move this one to
60571 * the back of the queue */
60572- fscache_stat(&fscache_n_object_lookups_timed_out);
60573+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60574 _leave(" [timeout]");
60575 return NO_TRANSIT;
60576 }
60577@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60578 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60579
60580 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60581- fscache_stat(&fscache_n_object_lookups_negative);
60582+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60583
60584 /* Allow write requests to begin stacking up and read requests to begin
60585 * returning ENODATA.
60586@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60587 /* if we were still looking up, then we must have a positive lookup
60588 * result, in which case there may be data available */
60589 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60590- fscache_stat(&fscache_n_object_lookups_positive);
60591+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60592
60593 /* We do (presumably) have data */
60594 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60595@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60596 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60597 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60598 } else {
60599- fscache_stat(&fscache_n_object_created);
60600+ fscache_stat_unchecked(&fscache_n_object_created);
60601 }
60602
60603 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60604@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60605 fscache_stat_d(&fscache_n_cop_lookup_complete);
60606
60607 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60608- fscache_stat(&fscache_n_object_avail);
60609+ fscache_stat_unchecked(&fscache_n_object_avail);
60610
60611 _leave("");
60612 return transit_to(JUMPSTART_DEPS);
60613@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60614
60615 /* this just shifts the object release to the work processor */
60616 fscache_put_object(object);
60617- fscache_stat(&fscache_n_object_dead);
60618+ fscache_stat_unchecked(&fscache_n_object_dead);
60619
60620 _leave("");
60621 return transit_to(OBJECT_DEAD);
60622@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60623 enum fscache_checkaux result;
60624
60625 if (!object->cookie->def->check_aux) {
60626- fscache_stat(&fscache_n_checkaux_none);
60627+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60628 return FSCACHE_CHECKAUX_OKAY;
60629 }
60630
60631@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60632 switch (result) {
60633 /* entry okay as is */
60634 case FSCACHE_CHECKAUX_OKAY:
60635- fscache_stat(&fscache_n_checkaux_okay);
60636+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60637 break;
60638
60639 /* entry requires update */
60640 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60641- fscache_stat(&fscache_n_checkaux_update);
60642+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60643 break;
60644
60645 /* entry requires deletion */
60646 case FSCACHE_CHECKAUX_OBSOLETE:
60647- fscache_stat(&fscache_n_checkaux_obsolete);
60648+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60649 break;
60650
60651 default:
60652@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60653 {
60654 const struct fscache_state *s;
60655
60656- fscache_stat(&fscache_n_invalidates_run);
60657+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60658 fscache_stat(&fscache_n_cop_invalidate_object);
60659 s = _fscache_invalidate_object(object, event);
60660 fscache_stat_d(&fscache_n_cop_invalidate_object);
60661@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60662 {
60663 _enter("{OBJ%x},%d", object->debug_id, event);
60664
60665- fscache_stat(&fscache_n_updates_run);
60666+ fscache_stat_unchecked(&fscache_n_updates_run);
60667 fscache_stat(&fscache_n_cop_update_object);
60668 object->cache->ops->update_object(object);
60669 fscache_stat_d(&fscache_n_cop_update_object);
60670diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60671index 318071a..379938b 100644
60672--- a/fs/fscache/operation.c
60673+++ b/fs/fscache/operation.c
60674@@ -17,7 +17,7 @@
60675 #include <linux/slab.h>
60676 #include "internal.h"
60677
60678-atomic_t fscache_op_debug_id;
60679+atomic_unchecked_t fscache_op_debug_id;
60680 EXPORT_SYMBOL(fscache_op_debug_id);
60681
60682 /**
60683@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60684 ASSERTCMP(atomic_read(&op->usage), >, 0);
60685 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60686
60687- fscache_stat(&fscache_n_op_enqueue);
60688+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60689 switch (op->flags & FSCACHE_OP_TYPE) {
60690 case FSCACHE_OP_ASYNC:
60691 _debug("queue async");
60692@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60693 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60694 if (op->processor)
60695 fscache_enqueue_operation(op);
60696- fscache_stat(&fscache_n_op_run);
60697+ fscache_stat_unchecked(&fscache_n_op_run);
60698 }
60699
60700 /*
60701@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60702 if (object->n_in_progress > 0) {
60703 atomic_inc(&op->usage);
60704 list_add_tail(&op->pend_link, &object->pending_ops);
60705- fscache_stat(&fscache_n_op_pend);
60706+ fscache_stat_unchecked(&fscache_n_op_pend);
60707 } else if (!list_empty(&object->pending_ops)) {
60708 atomic_inc(&op->usage);
60709 list_add_tail(&op->pend_link, &object->pending_ops);
60710- fscache_stat(&fscache_n_op_pend);
60711+ fscache_stat_unchecked(&fscache_n_op_pend);
60712 fscache_start_operations(object);
60713 } else {
60714 ASSERTCMP(object->n_in_progress, ==, 0);
60715@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60716 object->n_exclusive++; /* reads and writes must wait */
60717 atomic_inc(&op->usage);
60718 list_add_tail(&op->pend_link, &object->pending_ops);
60719- fscache_stat(&fscache_n_op_pend);
60720+ fscache_stat_unchecked(&fscache_n_op_pend);
60721 ret = 0;
60722 } else {
60723 /* If we're in any other state, there must have been an I/O
60724@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60725 if (object->n_exclusive > 0) {
60726 atomic_inc(&op->usage);
60727 list_add_tail(&op->pend_link, &object->pending_ops);
60728- fscache_stat(&fscache_n_op_pend);
60729+ fscache_stat_unchecked(&fscache_n_op_pend);
60730 } else if (!list_empty(&object->pending_ops)) {
60731 atomic_inc(&op->usage);
60732 list_add_tail(&op->pend_link, &object->pending_ops);
60733- fscache_stat(&fscache_n_op_pend);
60734+ fscache_stat_unchecked(&fscache_n_op_pend);
60735 fscache_start_operations(object);
60736 } else {
60737 ASSERTCMP(object->n_exclusive, ==, 0);
60738@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60739 object->n_ops++;
60740 atomic_inc(&op->usage);
60741 list_add_tail(&op->pend_link, &object->pending_ops);
60742- fscache_stat(&fscache_n_op_pend);
60743+ fscache_stat_unchecked(&fscache_n_op_pend);
60744 ret = 0;
60745 } else if (fscache_object_is_dying(object)) {
60746- fscache_stat(&fscache_n_op_rejected);
60747+ fscache_stat_unchecked(&fscache_n_op_rejected);
60748 op->state = FSCACHE_OP_ST_CANCELLED;
60749 ret = -ENOBUFS;
60750 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60751@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60752 ret = -EBUSY;
60753 if (op->state == FSCACHE_OP_ST_PENDING) {
60754 ASSERT(!list_empty(&op->pend_link));
60755- fscache_stat(&fscache_n_op_cancelled);
60756+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60757 list_del_init(&op->pend_link);
60758 if (do_cancel)
60759 do_cancel(op);
60760@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60761 while (!list_empty(&object->pending_ops)) {
60762 op = list_entry(object->pending_ops.next,
60763 struct fscache_operation, pend_link);
60764- fscache_stat(&fscache_n_op_cancelled);
60765+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60766 list_del_init(&op->pend_link);
60767
60768 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60769@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60770 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60771 op->state = FSCACHE_OP_ST_DEAD;
60772
60773- fscache_stat(&fscache_n_op_release);
60774+ fscache_stat_unchecked(&fscache_n_op_release);
60775
60776 if (op->release) {
60777 op->release(op);
60778@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60779 * lock, and defer it otherwise */
60780 if (!spin_trylock(&object->lock)) {
60781 _debug("defer put");
60782- fscache_stat(&fscache_n_op_deferred_release);
60783+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60784
60785 cache = object->cache;
60786 spin_lock(&cache->op_gc_list_lock);
60787@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60788
60789 _debug("GC DEFERRED REL OBJ%x OP%x",
60790 object->debug_id, op->debug_id);
60791- fscache_stat(&fscache_n_op_gc);
60792+ fscache_stat_unchecked(&fscache_n_op_gc);
60793
60794 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60795 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60796diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60797index 7f5c658..6c1e164 100644
60798--- a/fs/fscache/page.c
60799+++ b/fs/fscache/page.c
60800@@ -61,7 +61,7 @@ try_again:
60801 val = radix_tree_lookup(&cookie->stores, page->index);
60802 if (!val) {
60803 rcu_read_unlock();
60804- fscache_stat(&fscache_n_store_vmscan_not_storing);
60805+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60806 __fscache_uncache_page(cookie, page);
60807 return true;
60808 }
60809@@ -91,11 +91,11 @@ try_again:
60810 spin_unlock(&cookie->stores_lock);
60811
60812 if (xpage) {
60813- fscache_stat(&fscache_n_store_vmscan_cancelled);
60814- fscache_stat(&fscache_n_store_radix_deletes);
60815+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60816+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60817 ASSERTCMP(xpage, ==, page);
60818 } else {
60819- fscache_stat(&fscache_n_store_vmscan_gone);
60820+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60821 }
60822
60823 wake_up_bit(&cookie->flags, 0);
60824@@ -110,11 +110,11 @@ page_busy:
60825 * sleeping on memory allocation, so we may need to impose a timeout
60826 * too. */
60827 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60828- fscache_stat(&fscache_n_store_vmscan_busy);
60829+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60830 return false;
60831 }
60832
60833- fscache_stat(&fscache_n_store_vmscan_wait);
60834+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60835 __fscache_wait_on_page_write(cookie, page);
60836 gfp &= ~__GFP_WAIT;
60837 goto try_again;
60838@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60839 FSCACHE_COOKIE_STORING_TAG);
60840 if (!radix_tree_tag_get(&cookie->stores, page->index,
60841 FSCACHE_COOKIE_PENDING_TAG)) {
60842- fscache_stat(&fscache_n_store_radix_deletes);
60843+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60844 xpage = radix_tree_delete(&cookie->stores, page->index);
60845 }
60846 spin_unlock(&cookie->stores_lock);
60847@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60848
60849 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60850
60851- fscache_stat(&fscache_n_attr_changed_calls);
60852+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60853
60854 if (fscache_object_is_active(object)) {
60855 fscache_stat(&fscache_n_cop_attr_changed);
60856@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60857
60858 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60859
60860- fscache_stat(&fscache_n_attr_changed);
60861+ fscache_stat_unchecked(&fscache_n_attr_changed);
60862
60863 op = kzalloc(sizeof(*op), GFP_KERNEL);
60864 if (!op) {
60865- fscache_stat(&fscache_n_attr_changed_nomem);
60866+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60867 _leave(" = -ENOMEM");
60868 return -ENOMEM;
60869 }
60870@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60871 if (fscache_submit_exclusive_op(object, op) < 0)
60872 goto nobufs;
60873 spin_unlock(&cookie->lock);
60874- fscache_stat(&fscache_n_attr_changed_ok);
60875+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60876 fscache_put_operation(op);
60877 _leave(" = 0");
60878 return 0;
60879@@ -225,7 +225,7 @@ nobufs:
60880 kfree(op);
60881 if (wake_cookie)
60882 __fscache_wake_unused_cookie(cookie);
60883- fscache_stat(&fscache_n_attr_changed_nobufs);
60884+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60885 _leave(" = %d", -ENOBUFS);
60886 return -ENOBUFS;
60887 }
60888@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60889 /* allocate a retrieval operation and attempt to submit it */
60890 op = kzalloc(sizeof(*op), GFP_NOIO);
60891 if (!op) {
60892- fscache_stat(&fscache_n_retrievals_nomem);
60893+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60894 return NULL;
60895 }
60896
60897@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60898 return 0;
60899 }
60900
60901- fscache_stat(&fscache_n_retrievals_wait);
60902+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60903
60904 jif = jiffies;
60905 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60906 fscache_wait_bit_interruptible,
60907 TASK_INTERRUPTIBLE) != 0) {
60908- fscache_stat(&fscache_n_retrievals_intr);
60909+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60910 _leave(" = -ERESTARTSYS");
60911 return -ERESTARTSYS;
60912 }
60913@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60914 */
60915 int fscache_wait_for_operation_activation(struct fscache_object *object,
60916 struct fscache_operation *op,
60917- atomic_t *stat_op_waits,
60918- atomic_t *stat_object_dead,
60919+ atomic_unchecked_t *stat_op_waits,
60920+ atomic_unchecked_t *stat_object_dead,
60921 void (*do_cancel)(struct fscache_operation *))
60922 {
60923 int ret;
60924@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60925
60926 _debug(">>> WT");
60927 if (stat_op_waits)
60928- fscache_stat(stat_op_waits);
60929+ fscache_stat_unchecked(stat_op_waits);
60930 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60931 fscache_wait_bit_interruptible,
60932 TASK_INTERRUPTIBLE) != 0) {
60933@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60934 check_if_dead:
60935 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60936 if (stat_object_dead)
60937- fscache_stat(stat_object_dead);
60938+ fscache_stat_unchecked(stat_object_dead);
60939 _leave(" = -ENOBUFS [cancelled]");
60940 return -ENOBUFS;
60941 }
60942@@ -366,7 +366,7 @@ check_if_dead:
60943 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60944 fscache_cancel_op(op, do_cancel);
60945 if (stat_object_dead)
60946- fscache_stat(stat_object_dead);
60947+ fscache_stat_unchecked(stat_object_dead);
60948 return -ENOBUFS;
60949 }
60950 return 0;
60951@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60952
60953 _enter("%p,%p,,,", cookie, page);
60954
60955- fscache_stat(&fscache_n_retrievals);
60956+ fscache_stat_unchecked(&fscache_n_retrievals);
60957
60958 if (hlist_empty(&cookie->backing_objects))
60959 goto nobufs;
60960@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60961 goto nobufs_unlock_dec;
60962 spin_unlock(&cookie->lock);
60963
60964- fscache_stat(&fscache_n_retrieval_ops);
60965+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60966
60967 /* pin the netfs read context in case we need to do the actual netfs
60968 * read because we've encountered a cache read failure */
60969@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60970
60971 error:
60972 if (ret == -ENOMEM)
60973- fscache_stat(&fscache_n_retrievals_nomem);
60974+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60975 else if (ret == -ERESTARTSYS)
60976- fscache_stat(&fscache_n_retrievals_intr);
60977+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60978 else if (ret == -ENODATA)
60979- fscache_stat(&fscache_n_retrievals_nodata);
60980+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60981 else if (ret < 0)
60982- fscache_stat(&fscache_n_retrievals_nobufs);
60983+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60984 else
60985- fscache_stat(&fscache_n_retrievals_ok);
60986+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60987
60988 fscache_put_retrieval(op);
60989 _leave(" = %d", ret);
60990@@ -490,7 +490,7 @@ nobufs_unlock:
60991 __fscache_wake_unused_cookie(cookie);
60992 kfree(op);
60993 nobufs:
60994- fscache_stat(&fscache_n_retrievals_nobufs);
60995+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60996 _leave(" = -ENOBUFS");
60997 return -ENOBUFS;
60998 }
60999@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
61000
61001 _enter("%p,,%d,,,", cookie, *nr_pages);
61002
61003- fscache_stat(&fscache_n_retrievals);
61004+ fscache_stat_unchecked(&fscache_n_retrievals);
61005
61006 if (hlist_empty(&cookie->backing_objects))
61007 goto nobufs;
61008@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
61009 goto nobufs_unlock_dec;
61010 spin_unlock(&cookie->lock);
61011
61012- fscache_stat(&fscache_n_retrieval_ops);
61013+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
61014
61015 /* pin the netfs read context in case we need to do the actual netfs
61016 * read because we've encountered a cache read failure */
61017@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
61018
61019 error:
61020 if (ret == -ENOMEM)
61021- fscache_stat(&fscache_n_retrievals_nomem);
61022+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
61023 else if (ret == -ERESTARTSYS)
61024- fscache_stat(&fscache_n_retrievals_intr);
61025+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
61026 else if (ret == -ENODATA)
61027- fscache_stat(&fscache_n_retrievals_nodata);
61028+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
61029 else if (ret < 0)
61030- fscache_stat(&fscache_n_retrievals_nobufs);
61031+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
61032 else
61033- fscache_stat(&fscache_n_retrievals_ok);
61034+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
61035
61036 fscache_put_retrieval(op);
61037 _leave(" = %d", ret);
61038@@ -621,7 +621,7 @@ nobufs_unlock:
61039 if (wake_cookie)
61040 __fscache_wake_unused_cookie(cookie);
61041 nobufs:
61042- fscache_stat(&fscache_n_retrievals_nobufs);
61043+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
61044 _leave(" = -ENOBUFS");
61045 return -ENOBUFS;
61046 }
61047@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
61048
61049 _enter("%p,%p,,,", cookie, page);
61050
61051- fscache_stat(&fscache_n_allocs);
61052+ fscache_stat_unchecked(&fscache_n_allocs);
61053
61054 if (hlist_empty(&cookie->backing_objects))
61055 goto nobufs;
61056@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
61057 goto nobufs_unlock_dec;
61058 spin_unlock(&cookie->lock);
61059
61060- fscache_stat(&fscache_n_alloc_ops);
61061+ fscache_stat_unchecked(&fscache_n_alloc_ops);
61062
61063 ret = fscache_wait_for_operation_activation(
61064 object, &op->op,
61065@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
61066
61067 error:
61068 if (ret == -ERESTARTSYS)
61069- fscache_stat(&fscache_n_allocs_intr);
61070+ fscache_stat_unchecked(&fscache_n_allocs_intr);
61071 else if (ret < 0)
61072- fscache_stat(&fscache_n_allocs_nobufs);
61073+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61074 else
61075- fscache_stat(&fscache_n_allocs_ok);
61076+ fscache_stat_unchecked(&fscache_n_allocs_ok);
61077
61078 fscache_put_retrieval(op);
61079 _leave(" = %d", ret);
61080@@ -715,7 +715,7 @@ nobufs_unlock:
61081 if (wake_cookie)
61082 __fscache_wake_unused_cookie(cookie);
61083 nobufs:
61084- fscache_stat(&fscache_n_allocs_nobufs);
61085+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61086 _leave(" = -ENOBUFS");
61087 return -ENOBUFS;
61088 }
61089@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61090
61091 spin_lock(&cookie->stores_lock);
61092
61093- fscache_stat(&fscache_n_store_calls);
61094+ fscache_stat_unchecked(&fscache_n_store_calls);
61095
61096 /* find a page to store */
61097 page = NULL;
61098@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61099 page = results[0];
61100 _debug("gang %d [%lx]", n, page->index);
61101 if (page->index > op->store_limit) {
61102- fscache_stat(&fscache_n_store_pages_over_limit);
61103+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
61104 goto superseded;
61105 }
61106
61107@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61108 spin_unlock(&cookie->stores_lock);
61109 spin_unlock(&object->lock);
61110
61111- fscache_stat(&fscache_n_store_pages);
61112+ fscache_stat_unchecked(&fscache_n_store_pages);
61113 fscache_stat(&fscache_n_cop_write_page);
61114 ret = object->cache->ops->write_page(op, page);
61115 fscache_stat_d(&fscache_n_cop_write_page);
61116@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61117 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61118 ASSERT(PageFsCache(page));
61119
61120- fscache_stat(&fscache_n_stores);
61121+ fscache_stat_unchecked(&fscache_n_stores);
61122
61123 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
61124 _leave(" = -ENOBUFS [invalidating]");
61125@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61126 spin_unlock(&cookie->stores_lock);
61127 spin_unlock(&object->lock);
61128
61129- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
61130+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61131 op->store_limit = object->store_limit;
61132
61133 __fscache_use_cookie(cookie);
61134@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61135
61136 spin_unlock(&cookie->lock);
61137 radix_tree_preload_end();
61138- fscache_stat(&fscache_n_store_ops);
61139- fscache_stat(&fscache_n_stores_ok);
61140+ fscache_stat_unchecked(&fscache_n_store_ops);
61141+ fscache_stat_unchecked(&fscache_n_stores_ok);
61142
61143 /* the work queue now carries its own ref on the object */
61144 fscache_put_operation(&op->op);
61145@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61146 return 0;
61147
61148 already_queued:
61149- fscache_stat(&fscache_n_stores_again);
61150+ fscache_stat_unchecked(&fscache_n_stores_again);
61151 already_pending:
61152 spin_unlock(&cookie->stores_lock);
61153 spin_unlock(&object->lock);
61154 spin_unlock(&cookie->lock);
61155 radix_tree_preload_end();
61156 kfree(op);
61157- fscache_stat(&fscache_n_stores_ok);
61158+ fscache_stat_unchecked(&fscache_n_stores_ok);
61159 _leave(" = 0");
61160 return 0;
61161
61162@@ -1024,14 +1024,14 @@ nobufs:
61163 kfree(op);
61164 if (wake_cookie)
61165 __fscache_wake_unused_cookie(cookie);
61166- fscache_stat(&fscache_n_stores_nobufs);
61167+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
61168 _leave(" = -ENOBUFS");
61169 return -ENOBUFS;
61170
61171 nomem_free:
61172 kfree(op);
61173 nomem:
61174- fscache_stat(&fscache_n_stores_oom);
61175+ fscache_stat_unchecked(&fscache_n_stores_oom);
61176 _leave(" = -ENOMEM");
61177 return -ENOMEM;
61178 }
61179@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
61180 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61181 ASSERTCMP(page, !=, NULL);
61182
61183- fscache_stat(&fscache_n_uncaches);
61184+ fscache_stat_unchecked(&fscache_n_uncaches);
61185
61186 /* cache withdrawal may beat us to it */
61187 if (!PageFsCache(page))
61188@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
61189 struct fscache_cookie *cookie = op->op.object->cookie;
61190
61191 #ifdef CONFIG_FSCACHE_STATS
61192- atomic_inc(&fscache_n_marks);
61193+ atomic_inc_unchecked(&fscache_n_marks);
61194 #endif
61195
61196 _debug("- mark %p{%lx}", page, page->index);
61197diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
61198index 40d13c7..ddf52b9 100644
61199--- a/fs/fscache/stats.c
61200+++ b/fs/fscache/stats.c
61201@@ -18,99 +18,99 @@
61202 /*
61203 * operation counters
61204 */
61205-atomic_t fscache_n_op_pend;
61206-atomic_t fscache_n_op_run;
61207-atomic_t fscache_n_op_enqueue;
61208-atomic_t fscache_n_op_requeue;
61209-atomic_t fscache_n_op_deferred_release;
61210-atomic_t fscache_n_op_release;
61211-atomic_t fscache_n_op_gc;
61212-atomic_t fscache_n_op_cancelled;
61213-atomic_t fscache_n_op_rejected;
61214+atomic_unchecked_t fscache_n_op_pend;
61215+atomic_unchecked_t fscache_n_op_run;
61216+atomic_unchecked_t fscache_n_op_enqueue;
61217+atomic_unchecked_t fscache_n_op_requeue;
61218+atomic_unchecked_t fscache_n_op_deferred_release;
61219+atomic_unchecked_t fscache_n_op_release;
61220+atomic_unchecked_t fscache_n_op_gc;
61221+atomic_unchecked_t fscache_n_op_cancelled;
61222+atomic_unchecked_t fscache_n_op_rejected;
61223
61224-atomic_t fscache_n_attr_changed;
61225-atomic_t fscache_n_attr_changed_ok;
61226-atomic_t fscache_n_attr_changed_nobufs;
61227-atomic_t fscache_n_attr_changed_nomem;
61228-atomic_t fscache_n_attr_changed_calls;
61229+atomic_unchecked_t fscache_n_attr_changed;
61230+atomic_unchecked_t fscache_n_attr_changed_ok;
61231+atomic_unchecked_t fscache_n_attr_changed_nobufs;
61232+atomic_unchecked_t fscache_n_attr_changed_nomem;
61233+atomic_unchecked_t fscache_n_attr_changed_calls;
61234
61235-atomic_t fscache_n_allocs;
61236-atomic_t fscache_n_allocs_ok;
61237-atomic_t fscache_n_allocs_wait;
61238-atomic_t fscache_n_allocs_nobufs;
61239-atomic_t fscache_n_allocs_intr;
61240-atomic_t fscache_n_allocs_object_dead;
61241-atomic_t fscache_n_alloc_ops;
61242-atomic_t fscache_n_alloc_op_waits;
61243+atomic_unchecked_t fscache_n_allocs;
61244+atomic_unchecked_t fscache_n_allocs_ok;
61245+atomic_unchecked_t fscache_n_allocs_wait;
61246+atomic_unchecked_t fscache_n_allocs_nobufs;
61247+atomic_unchecked_t fscache_n_allocs_intr;
61248+atomic_unchecked_t fscache_n_allocs_object_dead;
61249+atomic_unchecked_t fscache_n_alloc_ops;
61250+atomic_unchecked_t fscache_n_alloc_op_waits;
61251
61252-atomic_t fscache_n_retrievals;
61253-atomic_t fscache_n_retrievals_ok;
61254-atomic_t fscache_n_retrievals_wait;
61255-atomic_t fscache_n_retrievals_nodata;
61256-atomic_t fscache_n_retrievals_nobufs;
61257-atomic_t fscache_n_retrievals_intr;
61258-atomic_t fscache_n_retrievals_nomem;
61259-atomic_t fscache_n_retrievals_object_dead;
61260-atomic_t fscache_n_retrieval_ops;
61261-atomic_t fscache_n_retrieval_op_waits;
61262+atomic_unchecked_t fscache_n_retrievals;
61263+atomic_unchecked_t fscache_n_retrievals_ok;
61264+atomic_unchecked_t fscache_n_retrievals_wait;
61265+atomic_unchecked_t fscache_n_retrievals_nodata;
61266+atomic_unchecked_t fscache_n_retrievals_nobufs;
61267+atomic_unchecked_t fscache_n_retrievals_intr;
61268+atomic_unchecked_t fscache_n_retrievals_nomem;
61269+atomic_unchecked_t fscache_n_retrievals_object_dead;
61270+atomic_unchecked_t fscache_n_retrieval_ops;
61271+atomic_unchecked_t fscache_n_retrieval_op_waits;
61272
61273-atomic_t fscache_n_stores;
61274-atomic_t fscache_n_stores_ok;
61275-atomic_t fscache_n_stores_again;
61276-atomic_t fscache_n_stores_nobufs;
61277-atomic_t fscache_n_stores_oom;
61278-atomic_t fscache_n_store_ops;
61279-atomic_t fscache_n_store_calls;
61280-atomic_t fscache_n_store_pages;
61281-atomic_t fscache_n_store_radix_deletes;
61282-atomic_t fscache_n_store_pages_over_limit;
61283+atomic_unchecked_t fscache_n_stores;
61284+atomic_unchecked_t fscache_n_stores_ok;
61285+atomic_unchecked_t fscache_n_stores_again;
61286+atomic_unchecked_t fscache_n_stores_nobufs;
61287+atomic_unchecked_t fscache_n_stores_oom;
61288+atomic_unchecked_t fscache_n_store_ops;
61289+atomic_unchecked_t fscache_n_store_calls;
61290+atomic_unchecked_t fscache_n_store_pages;
61291+atomic_unchecked_t fscache_n_store_radix_deletes;
61292+atomic_unchecked_t fscache_n_store_pages_over_limit;
61293
61294-atomic_t fscache_n_store_vmscan_not_storing;
61295-atomic_t fscache_n_store_vmscan_gone;
61296-atomic_t fscache_n_store_vmscan_busy;
61297-atomic_t fscache_n_store_vmscan_cancelled;
61298-atomic_t fscache_n_store_vmscan_wait;
61299+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
61300+atomic_unchecked_t fscache_n_store_vmscan_gone;
61301+atomic_unchecked_t fscache_n_store_vmscan_busy;
61302+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
61303+atomic_unchecked_t fscache_n_store_vmscan_wait;
61304
61305-atomic_t fscache_n_marks;
61306-atomic_t fscache_n_uncaches;
61307+atomic_unchecked_t fscache_n_marks;
61308+atomic_unchecked_t fscache_n_uncaches;
61309
61310-atomic_t fscache_n_acquires;
61311-atomic_t fscache_n_acquires_null;
61312-atomic_t fscache_n_acquires_no_cache;
61313-atomic_t fscache_n_acquires_ok;
61314-atomic_t fscache_n_acquires_nobufs;
61315-atomic_t fscache_n_acquires_oom;
61316+atomic_unchecked_t fscache_n_acquires;
61317+atomic_unchecked_t fscache_n_acquires_null;
61318+atomic_unchecked_t fscache_n_acquires_no_cache;
61319+atomic_unchecked_t fscache_n_acquires_ok;
61320+atomic_unchecked_t fscache_n_acquires_nobufs;
61321+atomic_unchecked_t fscache_n_acquires_oom;
61322
61323-atomic_t fscache_n_invalidates;
61324-atomic_t fscache_n_invalidates_run;
61325+atomic_unchecked_t fscache_n_invalidates;
61326+atomic_unchecked_t fscache_n_invalidates_run;
61327
61328-atomic_t fscache_n_updates;
61329-atomic_t fscache_n_updates_null;
61330-atomic_t fscache_n_updates_run;
61331+atomic_unchecked_t fscache_n_updates;
61332+atomic_unchecked_t fscache_n_updates_null;
61333+atomic_unchecked_t fscache_n_updates_run;
61334
61335-atomic_t fscache_n_relinquishes;
61336-atomic_t fscache_n_relinquishes_null;
61337-atomic_t fscache_n_relinquishes_waitcrt;
61338-atomic_t fscache_n_relinquishes_retire;
61339+atomic_unchecked_t fscache_n_relinquishes;
61340+atomic_unchecked_t fscache_n_relinquishes_null;
61341+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
61342+atomic_unchecked_t fscache_n_relinquishes_retire;
61343
61344-atomic_t fscache_n_cookie_index;
61345-atomic_t fscache_n_cookie_data;
61346-atomic_t fscache_n_cookie_special;
61347+atomic_unchecked_t fscache_n_cookie_index;
61348+atomic_unchecked_t fscache_n_cookie_data;
61349+atomic_unchecked_t fscache_n_cookie_special;
61350
61351-atomic_t fscache_n_object_alloc;
61352-atomic_t fscache_n_object_no_alloc;
61353-atomic_t fscache_n_object_lookups;
61354-atomic_t fscache_n_object_lookups_negative;
61355-atomic_t fscache_n_object_lookups_positive;
61356-atomic_t fscache_n_object_lookups_timed_out;
61357-atomic_t fscache_n_object_created;
61358-atomic_t fscache_n_object_avail;
61359-atomic_t fscache_n_object_dead;
61360+atomic_unchecked_t fscache_n_object_alloc;
61361+atomic_unchecked_t fscache_n_object_no_alloc;
61362+atomic_unchecked_t fscache_n_object_lookups;
61363+atomic_unchecked_t fscache_n_object_lookups_negative;
61364+atomic_unchecked_t fscache_n_object_lookups_positive;
61365+atomic_unchecked_t fscache_n_object_lookups_timed_out;
61366+atomic_unchecked_t fscache_n_object_created;
61367+atomic_unchecked_t fscache_n_object_avail;
61368+atomic_unchecked_t fscache_n_object_dead;
61369
61370-atomic_t fscache_n_checkaux_none;
61371-atomic_t fscache_n_checkaux_okay;
61372-atomic_t fscache_n_checkaux_update;
61373-atomic_t fscache_n_checkaux_obsolete;
61374+atomic_unchecked_t fscache_n_checkaux_none;
61375+atomic_unchecked_t fscache_n_checkaux_okay;
61376+atomic_unchecked_t fscache_n_checkaux_update;
61377+atomic_unchecked_t fscache_n_checkaux_obsolete;
61378
61379 atomic_t fscache_n_cop_alloc_object;
61380 atomic_t fscache_n_cop_lookup_object;
61381@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
61382 seq_puts(m, "FS-Cache statistics\n");
61383
61384 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
61385- atomic_read(&fscache_n_cookie_index),
61386- atomic_read(&fscache_n_cookie_data),
61387- atomic_read(&fscache_n_cookie_special));
61388+ atomic_read_unchecked(&fscache_n_cookie_index),
61389+ atomic_read_unchecked(&fscache_n_cookie_data),
61390+ atomic_read_unchecked(&fscache_n_cookie_special));
61391
61392 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
61393- atomic_read(&fscache_n_object_alloc),
61394- atomic_read(&fscache_n_object_no_alloc),
61395- atomic_read(&fscache_n_object_avail),
61396- atomic_read(&fscache_n_object_dead));
61397+ atomic_read_unchecked(&fscache_n_object_alloc),
61398+ atomic_read_unchecked(&fscache_n_object_no_alloc),
61399+ atomic_read_unchecked(&fscache_n_object_avail),
61400+ atomic_read_unchecked(&fscache_n_object_dead));
61401 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
61402- atomic_read(&fscache_n_checkaux_none),
61403- atomic_read(&fscache_n_checkaux_okay),
61404- atomic_read(&fscache_n_checkaux_update),
61405- atomic_read(&fscache_n_checkaux_obsolete));
61406+ atomic_read_unchecked(&fscache_n_checkaux_none),
61407+ atomic_read_unchecked(&fscache_n_checkaux_okay),
61408+ atomic_read_unchecked(&fscache_n_checkaux_update),
61409+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
61410
61411 seq_printf(m, "Pages : mrk=%u unc=%u\n",
61412- atomic_read(&fscache_n_marks),
61413- atomic_read(&fscache_n_uncaches));
61414+ atomic_read_unchecked(&fscache_n_marks),
61415+ atomic_read_unchecked(&fscache_n_uncaches));
61416
61417 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
61418 " oom=%u\n",
61419- atomic_read(&fscache_n_acquires),
61420- atomic_read(&fscache_n_acquires_null),
61421- atomic_read(&fscache_n_acquires_no_cache),
61422- atomic_read(&fscache_n_acquires_ok),
61423- atomic_read(&fscache_n_acquires_nobufs),
61424- atomic_read(&fscache_n_acquires_oom));
61425+ atomic_read_unchecked(&fscache_n_acquires),
61426+ atomic_read_unchecked(&fscache_n_acquires_null),
61427+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
61428+ atomic_read_unchecked(&fscache_n_acquires_ok),
61429+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
61430+ atomic_read_unchecked(&fscache_n_acquires_oom));
61431
61432 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
61433- atomic_read(&fscache_n_object_lookups),
61434- atomic_read(&fscache_n_object_lookups_negative),
61435- atomic_read(&fscache_n_object_lookups_positive),
61436- atomic_read(&fscache_n_object_created),
61437- atomic_read(&fscache_n_object_lookups_timed_out));
61438+ atomic_read_unchecked(&fscache_n_object_lookups),
61439+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
61440+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
61441+ atomic_read_unchecked(&fscache_n_object_created),
61442+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61443
61444 seq_printf(m, "Invals : n=%u run=%u\n",
61445- atomic_read(&fscache_n_invalidates),
61446- atomic_read(&fscache_n_invalidates_run));
61447+ atomic_read_unchecked(&fscache_n_invalidates),
61448+ atomic_read_unchecked(&fscache_n_invalidates_run));
61449
61450 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61451- atomic_read(&fscache_n_updates),
61452- atomic_read(&fscache_n_updates_null),
61453- atomic_read(&fscache_n_updates_run));
61454+ atomic_read_unchecked(&fscache_n_updates),
61455+ atomic_read_unchecked(&fscache_n_updates_null),
61456+ atomic_read_unchecked(&fscache_n_updates_run));
61457
61458 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61459- atomic_read(&fscache_n_relinquishes),
61460- atomic_read(&fscache_n_relinquishes_null),
61461- atomic_read(&fscache_n_relinquishes_waitcrt),
61462- atomic_read(&fscache_n_relinquishes_retire));
61463+ atomic_read_unchecked(&fscache_n_relinquishes),
61464+ atomic_read_unchecked(&fscache_n_relinquishes_null),
61465+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61466+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
61467
61468 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61469- atomic_read(&fscache_n_attr_changed),
61470- atomic_read(&fscache_n_attr_changed_ok),
61471- atomic_read(&fscache_n_attr_changed_nobufs),
61472- atomic_read(&fscache_n_attr_changed_nomem),
61473- atomic_read(&fscache_n_attr_changed_calls));
61474+ atomic_read_unchecked(&fscache_n_attr_changed),
61475+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
61476+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61477+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61478+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
61479
61480 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61481- atomic_read(&fscache_n_allocs),
61482- atomic_read(&fscache_n_allocs_ok),
61483- atomic_read(&fscache_n_allocs_wait),
61484- atomic_read(&fscache_n_allocs_nobufs),
61485- atomic_read(&fscache_n_allocs_intr));
61486+ atomic_read_unchecked(&fscache_n_allocs),
61487+ atomic_read_unchecked(&fscache_n_allocs_ok),
61488+ atomic_read_unchecked(&fscache_n_allocs_wait),
61489+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
61490+ atomic_read_unchecked(&fscache_n_allocs_intr));
61491 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61492- atomic_read(&fscache_n_alloc_ops),
61493- atomic_read(&fscache_n_alloc_op_waits),
61494- atomic_read(&fscache_n_allocs_object_dead));
61495+ atomic_read_unchecked(&fscache_n_alloc_ops),
61496+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
61497+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
61498
61499 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61500 " int=%u oom=%u\n",
61501- atomic_read(&fscache_n_retrievals),
61502- atomic_read(&fscache_n_retrievals_ok),
61503- atomic_read(&fscache_n_retrievals_wait),
61504- atomic_read(&fscache_n_retrievals_nodata),
61505- atomic_read(&fscache_n_retrievals_nobufs),
61506- atomic_read(&fscache_n_retrievals_intr),
61507- atomic_read(&fscache_n_retrievals_nomem));
61508+ atomic_read_unchecked(&fscache_n_retrievals),
61509+ atomic_read_unchecked(&fscache_n_retrievals_ok),
61510+ atomic_read_unchecked(&fscache_n_retrievals_wait),
61511+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
61512+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61513+ atomic_read_unchecked(&fscache_n_retrievals_intr),
61514+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
61515 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61516- atomic_read(&fscache_n_retrieval_ops),
61517- atomic_read(&fscache_n_retrieval_op_waits),
61518- atomic_read(&fscache_n_retrievals_object_dead));
61519+ atomic_read_unchecked(&fscache_n_retrieval_ops),
61520+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61521+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61522
61523 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61524- atomic_read(&fscache_n_stores),
61525- atomic_read(&fscache_n_stores_ok),
61526- atomic_read(&fscache_n_stores_again),
61527- atomic_read(&fscache_n_stores_nobufs),
61528- atomic_read(&fscache_n_stores_oom));
61529+ atomic_read_unchecked(&fscache_n_stores),
61530+ atomic_read_unchecked(&fscache_n_stores_ok),
61531+ atomic_read_unchecked(&fscache_n_stores_again),
61532+ atomic_read_unchecked(&fscache_n_stores_nobufs),
61533+ atomic_read_unchecked(&fscache_n_stores_oom));
61534 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61535- atomic_read(&fscache_n_store_ops),
61536- atomic_read(&fscache_n_store_calls),
61537- atomic_read(&fscache_n_store_pages),
61538- atomic_read(&fscache_n_store_radix_deletes),
61539- atomic_read(&fscache_n_store_pages_over_limit));
61540+ atomic_read_unchecked(&fscache_n_store_ops),
61541+ atomic_read_unchecked(&fscache_n_store_calls),
61542+ atomic_read_unchecked(&fscache_n_store_pages),
61543+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
61544+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61545
61546 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61547- atomic_read(&fscache_n_store_vmscan_not_storing),
61548- atomic_read(&fscache_n_store_vmscan_gone),
61549- atomic_read(&fscache_n_store_vmscan_busy),
61550- atomic_read(&fscache_n_store_vmscan_cancelled),
61551- atomic_read(&fscache_n_store_vmscan_wait));
61552+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61553+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61554+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61555+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61556+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61557
61558 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61559- atomic_read(&fscache_n_op_pend),
61560- atomic_read(&fscache_n_op_run),
61561- atomic_read(&fscache_n_op_enqueue),
61562- atomic_read(&fscache_n_op_cancelled),
61563- atomic_read(&fscache_n_op_rejected));
61564+ atomic_read_unchecked(&fscache_n_op_pend),
61565+ atomic_read_unchecked(&fscache_n_op_run),
61566+ atomic_read_unchecked(&fscache_n_op_enqueue),
61567+ atomic_read_unchecked(&fscache_n_op_cancelled),
61568+ atomic_read_unchecked(&fscache_n_op_rejected));
61569 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61570- atomic_read(&fscache_n_op_deferred_release),
61571- atomic_read(&fscache_n_op_release),
61572- atomic_read(&fscache_n_op_gc));
61573+ atomic_read_unchecked(&fscache_n_op_deferred_release),
61574+ atomic_read_unchecked(&fscache_n_op_release),
61575+ atomic_read_unchecked(&fscache_n_op_gc));
61576
61577 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61578 atomic_read(&fscache_n_cop_alloc_object),
61579diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61580index b96a49b..9bfdc47 100644
61581--- a/fs/fuse/cuse.c
61582+++ b/fs/fuse/cuse.c
61583@@ -606,10 +606,12 @@ static int __init cuse_init(void)
61584 INIT_LIST_HEAD(&cuse_conntbl[i]);
61585
61586 /* inherit and extend fuse_dev_operations */
61587- cuse_channel_fops = fuse_dev_operations;
61588- cuse_channel_fops.owner = THIS_MODULE;
61589- cuse_channel_fops.open = cuse_channel_open;
61590- cuse_channel_fops.release = cuse_channel_release;
61591+ pax_open_kernel();
61592+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61593+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61594+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
61595+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
61596+ pax_close_kernel();
61597
61598 cuse_class = class_create(THIS_MODULE, "cuse");
61599 if (IS_ERR(cuse_class))
61600diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61601index 0a648bb..8d463f1 100644
61602--- a/fs/fuse/dev.c
61603+++ b/fs/fuse/dev.c
61604@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61605 ret = 0;
61606 pipe_lock(pipe);
61607
61608- if (!pipe->readers) {
61609+ if (!atomic_read(&pipe->readers)) {
61610 send_sig(SIGPIPE, current, 0);
61611 if (!ret)
61612 ret = -EPIPE;
61613@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61614 page_nr++;
61615 ret += buf->len;
61616
61617- if (pipe->files)
61618+ if (atomic_read(&pipe->files))
61619 do_wakeup = 1;
61620 }
61621
61622diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61623index 1d1292c..bba17ea 100644
61624--- a/fs/fuse/dir.c
61625+++ b/fs/fuse/dir.c
61626@@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
61627 return link;
61628 }
61629
61630-static void free_link(char *link)
61631+static void free_link(const char *link)
61632 {
61633 if (!IS_ERR(link))
61634 free_page((unsigned long) link);
61635diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61636index fe649d3..c679164 100644
61637--- a/fs/hostfs/hostfs_kern.c
61638+++ b/fs/hostfs/hostfs_kern.c
61639@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61640
61641 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61642 {
61643- char *s = nd_get_link(nd);
61644+ const char *s = nd_get_link(nd);
61645 if (!IS_ERR(s))
61646 __putname(s);
61647 }
61648diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61649index d19b30a..ef89c36 100644
61650--- a/fs/hugetlbfs/inode.c
61651+++ b/fs/hugetlbfs/inode.c
61652@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61653 struct mm_struct *mm = current->mm;
61654 struct vm_area_struct *vma;
61655 struct hstate *h = hstate_file(file);
61656+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61657 struct vm_unmapped_area_info info;
61658
61659 if (len & ~huge_page_mask(h))
61660@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61661 return addr;
61662 }
61663
61664+#ifdef CONFIG_PAX_RANDMMAP
61665+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61666+#endif
61667+
61668 if (addr) {
61669 addr = ALIGN(addr, huge_page_size(h));
61670 vma = find_vma(mm, addr);
61671- if (TASK_SIZE - len >= addr &&
61672- (!vma || addr + len <= vma->vm_start))
61673+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61674 return addr;
61675 }
61676
61677 info.flags = 0;
61678 info.length = len;
61679 info.low_limit = TASK_UNMAPPED_BASE;
61680+
61681+#ifdef CONFIG_PAX_RANDMMAP
61682+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61683+ info.low_limit += mm->delta_mmap;
61684+#endif
61685+
61686 info.high_limit = TASK_SIZE;
61687 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61688 info.align_offset = 0;
61689@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61690 };
61691 MODULE_ALIAS_FS("hugetlbfs");
61692
61693-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61694+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61695
61696 static int can_do_hugetlb_shm(void)
61697 {
61698diff --git a/fs/inode.c b/fs/inode.c
61699index e846a32..6b22e15 100644
61700--- a/fs/inode.c
61701+++ b/fs/inode.c
61702@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61703
61704 #ifdef CONFIG_SMP
61705 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61706- static atomic_t shared_last_ino;
61707- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61708+ static atomic_unchecked_t shared_last_ino;
61709+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61710
61711 res = next - LAST_INO_BATCH;
61712 }
61713diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61714index 4a6cf28..d3a29d3 100644
61715--- a/fs/jffs2/erase.c
61716+++ b/fs/jffs2/erase.c
61717@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61718 struct jffs2_unknown_node marker = {
61719 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61720 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61721- .totlen = cpu_to_je32(c->cleanmarker_size)
61722+ .totlen = cpu_to_je32(c->cleanmarker_size),
61723+ .hdr_crc = cpu_to_je32(0)
61724 };
61725
61726 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61727diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61728index a6597d6..41b30ec 100644
61729--- a/fs/jffs2/wbuf.c
61730+++ b/fs/jffs2/wbuf.c
61731@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61732 {
61733 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61734 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61735- .totlen = constant_cpu_to_je32(8)
61736+ .totlen = constant_cpu_to_je32(8),
61737+ .hdr_crc = constant_cpu_to_je32(0)
61738 };
61739
61740 /*
61741diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61742index e2b7483..855bca3 100644
61743--- a/fs/jfs/super.c
61744+++ b/fs/jfs/super.c
61745@@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
61746
61747 jfs_inode_cachep =
61748 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61749- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61750+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61751 init_once);
61752 if (jfs_inode_cachep == NULL)
61753 return -ENOMEM;
61754diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61755index 39c0143..d54fad4 100644
61756--- a/fs/kernfs/dir.c
61757+++ b/fs/kernfs/dir.c
61758@@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
61759 *
61760 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61761 */
61762-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61763+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61764 {
61765 unsigned long hash = init_name_hash();
61766 unsigned int len = strlen(name);
61767diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61768index d29640b..32d2b6b 100644
61769--- a/fs/kernfs/file.c
61770+++ b/fs/kernfs/file.c
61771@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61772
61773 struct kernfs_open_node {
61774 atomic_t refcnt;
61775- atomic_t event;
61776+ atomic_unchecked_t event;
61777 wait_queue_head_t poll;
61778 struct list_head files; /* goes through kernfs_open_file.list */
61779 };
61780@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61781 {
61782 struct kernfs_open_file *of = sf->private;
61783
61784- of->event = atomic_read(&of->kn->attr.open->event);
61785+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61786
61787 return of->kn->attr.ops->seq_show(sf, v);
61788 }
61789@@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61790 return ret;
61791 }
61792
61793-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61794- void *buf, int len, int write)
61795+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61796+ void *buf, size_t len, int write)
61797 {
61798 struct file *file = vma->vm_file;
61799 struct kernfs_open_file *of = kernfs_of(file);
61800- int ret;
61801+ ssize_t ret;
61802
61803 if (!of->vm_ops)
61804 return -EINVAL;
61805@@ -559,7 +559,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61806 return -ENOMEM;
61807
61808 atomic_set(&new_on->refcnt, 0);
61809- atomic_set(&new_on->event, 1);
61810+ atomic_set_unchecked(&new_on->event, 1);
61811 init_waitqueue_head(&new_on->poll);
61812 INIT_LIST_HEAD(&new_on->files);
61813 goto retry;
61814@@ -756,7 +756,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61815
61816 kernfs_put_active(kn);
61817
61818- if (of->event != atomic_read(&on->event))
61819+ if (of->event != atomic_read_unchecked(&on->event))
61820 goto trigger;
61821
61822 return DEFAULT_POLLMASK;
61823@@ -781,7 +781,7 @@ void kernfs_notify(struct kernfs_node *kn)
61824 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61825 on = kn->attr.open;
61826 if (on) {
61827- atomic_inc(&on->event);
61828+ atomic_inc_unchecked(&on->event);
61829 wake_up_interruptible(&on->poll);
61830 }
61831 }
61832diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61833index 4d45705..b35e0bd 100644
61834--- a/fs/kernfs/symlink.c
61835+++ b/fs/kernfs/symlink.c
61836@@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61837 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61838 void *cookie)
61839 {
61840- char *page = nd_get_link(nd);
61841+ const char *page = nd_get_link(nd);
61842 if (!IS_ERR(page))
61843 free_page((unsigned long)page);
61844 }
61845diff --git a/fs/libfs.c b/fs/libfs.c
61846index a184424..944ddce 100644
61847--- a/fs/libfs.c
61848+++ b/fs/libfs.c
61849@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61850
61851 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61852 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61853+ char d_name[sizeof(next->d_iname)];
61854+ const unsigned char *name;
61855+
61856 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61857 if (!simple_positive(next)) {
61858 spin_unlock(&next->d_lock);
61859@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61860
61861 spin_unlock(&next->d_lock);
61862 spin_unlock(&dentry->d_lock);
61863- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61864+ name = next->d_name.name;
61865+ if (name == next->d_iname) {
61866+ memcpy(d_name, name, next->d_name.len);
61867+ name = d_name;
61868+ }
61869+ if (!dir_emit(ctx, name, next->d_name.len,
61870 next->d_inode->i_ino, dt_type(next->d_inode)))
61871 return 0;
61872 spin_lock(&dentry->d_lock);
61873@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61874 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61875 void *cookie)
61876 {
61877- char *s = nd_get_link(nd);
61878+ const char *s = nd_get_link(nd);
61879 if (!IS_ERR(s))
61880 kfree(s);
61881 }
61882diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61883index acd3947..1f896e2 100644
61884--- a/fs/lockd/clntproc.c
61885+++ b/fs/lockd/clntproc.c
61886@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61887 /*
61888 * Cookie counter for NLM requests
61889 */
61890-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61891+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61892
61893 void nlmclnt_next_cookie(struct nlm_cookie *c)
61894 {
61895- u32 cookie = atomic_inc_return(&nlm_cookie);
61896+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61897
61898 memcpy(c->data, &cookie, 4);
61899 c->len=4;
61900diff --git a/fs/locks.c b/fs/locks.c
61901index 4dd39b9..12d6aaf 100644
61902--- a/fs/locks.c
61903+++ b/fs/locks.c
61904@@ -2218,16 +2218,16 @@ void locks_remove_flock(struct file *filp)
61905 return;
61906
61907 if (filp->f_op->flock) {
61908- struct file_lock fl = {
61909+ struct file_lock flock = {
61910 .fl_pid = current->tgid,
61911 .fl_file = filp,
61912 .fl_flags = FL_FLOCK,
61913 .fl_type = F_UNLCK,
61914 .fl_end = OFFSET_MAX,
61915 };
61916- filp->f_op->flock(filp, F_SETLKW, &fl);
61917- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61918- fl.fl_ops->fl_release_private(&fl);
61919+ filp->f_op->flock(filp, F_SETLKW, &flock);
61920+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61921+ flock.fl_ops->fl_release_private(&flock);
61922 }
61923
61924 spin_lock(&inode->i_lock);
61925diff --git a/fs/mount.h b/fs/mount.h
61926index b29e42f..5ea7fdf 100644
61927--- a/fs/mount.h
61928+++ b/fs/mount.h
61929@@ -11,7 +11,7 @@ struct mnt_namespace {
61930 u64 seq; /* Sequence number to prevent loops */
61931 wait_queue_head_t poll;
61932 int event;
61933-};
61934+} __randomize_layout;
61935
61936 struct mnt_pcp {
61937 int mnt_count;
61938@@ -57,7 +57,7 @@ struct mount {
61939 int mnt_expiry_mark; /* true if marked for expiry */
61940 int mnt_pinned;
61941 struct path mnt_ex_mountpoint;
61942-};
61943+} __randomize_layout;
61944
61945 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61946
61947diff --git a/fs/namei.c b/fs/namei.c
61948index 8274c8d..922e189 100644
61949--- a/fs/namei.c
61950+++ b/fs/namei.c
61951@@ -330,17 +330,34 @@ int generic_permission(struct inode *inode, int mask)
61952 if (ret != -EACCES)
61953 return ret;
61954
61955+#ifdef CONFIG_GRKERNSEC
61956+ /* we'll block if we have to log due to a denied capability use */
61957+ if (mask & MAY_NOT_BLOCK)
61958+ return -ECHILD;
61959+#endif
61960+
61961 if (S_ISDIR(inode->i_mode)) {
61962 /* DACs are overridable for directories */
61963- if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61964- return 0;
61965 if (!(mask & MAY_WRITE))
61966- if (capable_wrt_inode_uidgid(inode,
61967+ if (capable_wrt_inode_uidgid_nolog(inode,
61968+ CAP_DAC_OVERRIDE) ||
61969+ capable_wrt_inode_uidgid(inode,
61970 CAP_DAC_READ_SEARCH))
61971 return 0;
61972+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61973+ return 0;
61974 return -EACCES;
61975 }
61976 /*
61977+ * Searching includes executable on directories, else just read.
61978+ */
61979+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61980+ if (mask == MAY_READ)
61981+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61982+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61983+ return 0;
61984+
61985+ /*
61986 * Read/write DACs are always overridable.
61987 * Executable DACs are overridable when there is
61988 * at least one exec bit set.
61989@@ -349,14 +366,6 @@ int generic_permission(struct inode *inode, int mask)
61990 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61991 return 0;
61992
61993- /*
61994- * Searching includes executable on directories, else just read.
61995- */
61996- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61997- if (mask == MAY_READ)
61998- if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61999- return 0;
62000-
62001 return -EACCES;
62002 }
62003
62004@@ -822,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
62005 {
62006 struct dentry *dentry = link->dentry;
62007 int error;
62008- char *s;
62009+ const char *s;
62010
62011 BUG_ON(nd->flags & LOOKUP_RCU);
62012
62013@@ -843,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
62014 if (error)
62015 goto out_put_nd_path;
62016
62017+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
62018+ dentry->d_inode, dentry, nd->path.mnt)) {
62019+ error = -EACCES;
62020+ goto out_put_nd_path;
62021+ }
62022+
62023 nd->last_type = LAST_BIND;
62024 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
62025 error = PTR_ERR(*p);
62026@@ -1591,6 +1606,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
62027 if (res)
62028 break;
62029 res = walk_component(nd, path, LOOKUP_FOLLOW);
62030+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
62031+ res = -EACCES;
62032 put_link(nd, &link, cookie);
62033 } while (res > 0);
62034
62035@@ -1664,7 +1681,7 @@ EXPORT_SYMBOL(full_name_hash);
62036 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
62037 {
62038 unsigned long a, b, adata, bdata, mask, hash, len;
62039- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
62040+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
62041
62042 hash = a = 0;
62043 len = -sizeof(unsigned long);
62044@@ -1948,6 +1965,8 @@ static int path_lookupat(int dfd, const char *name,
62045 if (err)
62046 break;
62047 err = lookup_last(nd, &path);
62048+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
62049+ err = -EACCES;
62050 put_link(nd, &link, cookie);
62051 }
62052 }
62053@@ -1955,6 +1974,13 @@ static int path_lookupat(int dfd, const char *name,
62054 if (!err)
62055 err = complete_walk(nd);
62056
62057+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
62058+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62059+ path_put(&nd->path);
62060+ err = -ENOENT;
62061+ }
62062+ }
62063+
62064 if (!err && nd->flags & LOOKUP_DIRECTORY) {
62065 if (!d_is_directory(nd->path.dentry)) {
62066 path_put(&nd->path);
62067@@ -1982,8 +2008,15 @@ static int filename_lookup(int dfd, struct filename *name,
62068 retval = path_lookupat(dfd, name->name,
62069 flags | LOOKUP_REVAL, nd);
62070
62071- if (likely(!retval))
62072+ if (likely(!retval)) {
62073 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
62074+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
62075+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
62076+ path_put(&nd->path);
62077+ return -ENOENT;
62078+ }
62079+ }
62080+ }
62081 return retval;
62082 }
62083
62084@@ -2557,6 +2590,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
62085 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
62086 return -EPERM;
62087
62088+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
62089+ return -EPERM;
62090+ if (gr_handle_rawio(inode))
62091+ return -EPERM;
62092+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
62093+ return -EACCES;
62094+
62095 return 0;
62096 }
62097
62098@@ -2788,7 +2828,7 @@ looked_up:
62099 * cleared otherwise prior to returning.
62100 */
62101 static int lookup_open(struct nameidata *nd, struct path *path,
62102- struct file *file,
62103+ struct path *link, struct file *file,
62104 const struct open_flags *op,
62105 bool got_write, int *opened)
62106 {
62107@@ -2823,6 +2863,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62108 /* Negative dentry, just create the file */
62109 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
62110 umode_t mode = op->mode;
62111+
62112+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
62113+ error = -EACCES;
62114+ goto out_dput;
62115+ }
62116+
62117+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
62118+ error = -EACCES;
62119+ goto out_dput;
62120+ }
62121+
62122 if (!IS_POSIXACL(dir->d_inode))
62123 mode &= ~current_umask();
62124 /*
62125@@ -2844,6 +2895,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62126 nd->flags & LOOKUP_EXCL);
62127 if (error)
62128 goto out_dput;
62129+ else
62130+ gr_handle_create(dentry, nd->path.mnt);
62131 }
62132 out_no_open:
62133 path->dentry = dentry;
62134@@ -2858,7 +2911,7 @@ out_dput:
62135 /*
62136 * Handle the last step of open()
62137 */
62138-static int do_last(struct nameidata *nd, struct path *path,
62139+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
62140 struct file *file, const struct open_flags *op,
62141 int *opened, struct filename *name)
62142 {
62143@@ -2908,6 +2961,15 @@ static int do_last(struct nameidata *nd, struct path *path,
62144 if (error)
62145 return error;
62146
62147+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
62148+ error = -ENOENT;
62149+ goto out;
62150+ }
62151+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62152+ error = -EACCES;
62153+ goto out;
62154+ }
62155+
62156 audit_inode(name, dir, LOOKUP_PARENT);
62157 error = -EISDIR;
62158 /* trailing slashes? */
62159@@ -2927,7 +2989,7 @@ retry_lookup:
62160 */
62161 }
62162 mutex_lock(&dir->d_inode->i_mutex);
62163- error = lookup_open(nd, path, file, op, got_write, opened);
62164+ error = lookup_open(nd, path, link, file, op, got_write, opened);
62165 mutex_unlock(&dir->d_inode->i_mutex);
62166
62167 if (error <= 0) {
62168@@ -2951,11 +3013,28 @@ retry_lookup:
62169 goto finish_open_created;
62170 }
62171
62172+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
62173+ error = -ENOENT;
62174+ goto exit_dput;
62175+ }
62176+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
62177+ error = -EACCES;
62178+ goto exit_dput;
62179+ }
62180+
62181 /*
62182 * create/update audit record if it already exists.
62183 */
62184- if (d_is_positive(path->dentry))
62185+ if (d_is_positive(path->dentry)) {
62186+ /* only check if O_CREAT is specified, all other checks need to go
62187+ into may_open */
62188+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
62189+ error = -EACCES;
62190+ goto exit_dput;
62191+ }
62192+
62193 audit_inode(name, path->dentry, 0);
62194+ }
62195
62196 /*
62197 * If atomic_open() acquired write access it is dropped now due to
62198@@ -2996,6 +3075,11 @@ finish_lookup:
62199 }
62200 }
62201 BUG_ON(inode != path->dentry->d_inode);
62202+ /* if we're resolving a symlink to another symlink */
62203+ if (link && gr_handle_symlink_owner(link, inode)) {
62204+ error = -EACCES;
62205+ goto out;
62206+ }
62207 return 1;
62208 }
62209
62210@@ -3005,7 +3089,6 @@ finish_lookup:
62211 save_parent.dentry = nd->path.dentry;
62212 save_parent.mnt = mntget(path->mnt);
62213 nd->path.dentry = path->dentry;
62214-
62215 }
62216 nd->inode = inode;
62217 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
62218@@ -3015,7 +3098,18 @@ finish_open:
62219 path_put(&save_parent);
62220 return error;
62221 }
62222+
62223+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62224+ error = -ENOENT;
62225+ goto out;
62226+ }
62227+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62228+ error = -EACCES;
62229+ goto out;
62230+ }
62231+
62232 audit_inode(name, nd->path.dentry, 0);
62233+
62234 error = -EISDIR;
62235 if ((open_flag & O_CREAT) &&
62236 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
62237@@ -3179,7 +3273,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62238 if (unlikely(error))
62239 goto out;
62240
62241- error = do_last(nd, &path, file, op, &opened, pathname);
62242+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
62243 while (unlikely(error > 0)) { /* trailing symlink */
62244 struct path link = path;
62245 void *cookie;
62246@@ -3197,7 +3291,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62247 error = follow_link(&link, nd, &cookie);
62248 if (unlikely(error))
62249 break;
62250- error = do_last(nd, &path, file, op, &opened, pathname);
62251+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
62252 put_link(nd, &link, cookie);
62253 }
62254 out:
62255@@ -3297,9 +3391,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
62256 goto unlock;
62257
62258 error = -EEXIST;
62259- if (d_is_positive(dentry))
62260+ if (d_is_positive(dentry)) {
62261+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
62262+ error = -ENOENT;
62263 goto fail;
62264-
62265+ }
62266 /*
62267 * Special case - lookup gave negative, but... we had foo/bar/
62268 * From the vfs_mknod() POV we just have a negative dentry -
62269@@ -3351,6 +3447,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
62270 }
62271 EXPORT_SYMBOL(user_path_create);
62272
62273+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
62274+{
62275+ struct filename *tmp = getname(pathname);
62276+ struct dentry *res;
62277+ if (IS_ERR(tmp))
62278+ return ERR_CAST(tmp);
62279+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
62280+ if (IS_ERR(res))
62281+ putname(tmp);
62282+ else
62283+ *to = tmp;
62284+ return res;
62285+}
62286+
62287 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
62288 {
62289 int error = may_create(dir, dentry);
62290@@ -3413,6 +3523,17 @@ retry:
62291
62292 if (!IS_POSIXACL(path.dentry->d_inode))
62293 mode &= ~current_umask();
62294+
62295+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
62296+ error = -EPERM;
62297+ goto out;
62298+ }
62299+
62300+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
62301+ error = -EACCES;
62302+ goto out;
62303+ }
62304+
62305 error = security_path_mknod(&path, dentry, mode, dev);
62306 if (error)
62307 goto out;
62308@@ -3429,6 +3550,8 @@ retry:
62309 break;
62310 }
62311 out:
62312+ if (!error)
62313+ gr_handle_create(dentry, path.mnt);
62314 done_path_create(&path, dentry);
62315 if (retry_estale(error, lookup_flags)) {
62316 lookup_flags |= LOOKUP_REVAL;
62317@@ -3481,9 +3604,16 @@ retry:
62318
62319 if (!IS_POSIXACL(path.dentry->d_inode))
62320 mode &= ~current_umask();
62321+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
62322+ error = -EACCES;
62323+ goto out;
62324+ }
62325 error = security_path_mkdir(&path, dentry, mode);
62326 if (!error)
62327 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
62328+ if (!error)
62329+ gr_handle_create(dentry, path.mnt);
62330+out:
62331 done_path_create(&path, dentry);
62332 if (retry_estale(error, lookup_flags)) {
62333 lookup_flags |= LOOKUP_REVAL;
62334@@ -3564,6 +3694,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
62335 struct filename *name;
62336 struct dentry *dentry;
62337 struct nameidata nd;
62338+ ino_t saved_ino = 0;
62339+ dev_t saved_dev = 0;
62340 unsigned int lookup_flags = 0;
62341 retry:
62342 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62343@@ -3596,10 +3728,21 @@ retry:
62344 error = -ENOENT;
62345 goto exit3;
62346 }
62347+
62348+ saved_ino = dentry->d_inode->i_ino;
62349+ saved_dev = gr_get_dev_from_dentry(dentry);
62350+
62351+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
62352+ error = -EACCES;
62353+ goto exit3;
62354+ }
62355+
62356 error = security_path_rmdir(&nd.path, dentry);
62357 if (error)
62358 goto exit3;
62359 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
62360+ if (!error && (saved_dev || saved_ino))
62361+ gr_handle_delete(saved_ino, saved_dev);
62362 exit3:
62363 dput(dentry);
62364 exit2:
62365@@ -3689,6 +3832,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
62366 struct nameidata nd;
62367 struct inode *inode = NULL;
62368 struct inode *delegated_inode = NULL;
62369+ ino_t saved_ino = 0;
62370+ dev_t saved_dev = 0;
62371 unsigned int lookup_flags = 0;
62372 retry:
62373 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62374@@ -3715,10 +3860,22 @@ retry_deleg:
62375 if (d_is_negative(dentry))
62376 goto slashes;
62377 ihold(inode);
62378+
62379+ if (inode->i_nlink <= 1) {
62380+ saved_ino = inode->i_ino;
62381+ saved_dev = gr_get_dev_from_dentry(dentry);
62382+ }
62383+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
62384+ error = -EACCES;
62385+ goto exit2;
62386+ }
62387+
62388 error = security_path_unlink(&nd.path, dentry);
62389 if (error)
62390 goto exit2;
62391 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
62392+ if (!error && (saved_ino || saved_dev))
62393+ gr_handle_delete(saved_ino, saved_dev);
62394 exit2:
62395 dput(dentry);
62396 }
62397@@ -3806,9 +3963,17 @@ retry:
62398 if (IS_ERR(dentry))
62399 goto out_putname;
62400
62401+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
62402+ error = -EACCES;
62403+ goto out;
62404+ }
62405+
62406 error = security_path_symlink(&path, dentry, from->name);
62407 if (!error)
62408 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
62409+ if (!error)
62410+ gr_handle_create(dentry, path.mnt);
62411+out:
62412 done_path_create(&path, dentry);
62413 if (retry_estale(error, lookup_flags)) {
62414 lookup_flags |= LOOKUP_REVAL;
62415@@ -3911,6 +4076,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
62416 struct dentry *new_dentry;
62417 struct path old_path, new_path;
62418 struct inode *delegated_inode = NULL;
62419+ struct filename *to = NULL;
62420 int how = 0;
62421 int error;
62422
62423@@ -3934,7 +4100,7 @@ retry:
62424 if (error)
62425 return error;
62426
62427- new_dentry = user_path_create(newdfd, newname, &new_path,
62428+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62429 (how & LOOKUP_REVAL));
62430 error = PTR_ERR(new_dentry);
62431 if (IS_ERR(new_dentry))
62432@@ -3946,11 +4112,28 @@ retry:
62433 error = may_linkat(&old_path);
62434 if (unlikely(error))
62435 goto out_dput;
62436+
62437+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62438+ old_path.dentry->d_inode,
62439+ old_path.dentry->d_inode->i_mode, to)) {
62440+ error = -EACCES;
62441+ goto out_dput;
62442+ }
62443+
62444+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62445+ old_path.dentry, old_path.mnt, to)) {
62446+ error = -EACCES;
62447+ goto out_dput;
62448+ }
62449+
62450 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62451 if (error)
62452 goto out_dput;
62453 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62454+ if (!error)
62455+ gr_handle_create(new_dentry, new_path.mnt);
62456 out_dput:
62457+ putname(to);
62458 done_path_create(&new_path, new_dentry);
62459 if (delegated_inode) {
62460 error = break_deleg_wait(&delegated_inode);
62461@@ -4237,6 +4420,12 @@ retry_deleg:
62462 if (new_dentry == trap)
62463 goto exit5;
62464
62465+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62466+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
62467+ to);
62468+ if (error)
62469+ goto exit5;
62470+
62471 error = security_path_rename(&oldnd.path, old_dentry,
62472 &newnd.path, new_dentry);
62473 if (error)
62474@@ -4244,6 +4433,9 @@ retry_deleg:
62475 error = vfs_rename(old_dir->d_inode, old_dentry,
62476 new_dir->d_inode, new_dentry,
62477 &delegated_inode);
62478+ if (!error)
62479+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62480+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
62481 exit5:
62482 dput(new_dentry);
62483 exit4:
62484@@ -4280,6 +4472,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62485
62486 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
62487 {
62488+ char tmpbuf[64];
62489+ const char *newlink;
62490 int len;
62491
62492 len = PTR_ERR(link);
62493@@ -4289,7 +4483,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
62494 len = strlen(link);
62495 if (len > (unsigned) buflen)
62496 len = buflen;
62497- if (copy_to_user(buffer, link, len))
62498+
62499+ if (len < sizeof(tmpbuf)) {
62500+ memcpy(tmpbuf, link, len);
62501+ newlink = tmpbuf;
62502+ } else
62503+ newlink = link;
62504+
62505+ if (copy_to_user(buffer, newlink, len))
62506 len = -EFAULT;
62507 out:
62508 return len;
62509diff --git a/fs/namespace.c b/fs/namespace.c
62510index 65233a5..82ac953 100644
62511--- a/fs/namespace.c
62512+++ b/fs/namespace.c
62513@@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
62514 if (!(sb->s_flags & MS_RDONLY))
62515 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62516 up_write(&sb->s_umount);
62517+
62518+ gr_log_remount(mnt->mnt_devname, retval);
62519+
62520 return retval;
62521 }
62522
62523@@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
62524 }
62525 unlock_mount_hash();
62526 namespace_unlock();
62527+
62528+ gr_log_unmount(mnt->mnt_devname, retval);
62529+
62530 return retval;
62531 }
62532
62533@@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
62534 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62535 */
62536
62537-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62538+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62539 {
62540 struct path path;
62541 struct mount *mnt;
62542@@ -1422,7 +1428,7 @@ out:
62543 /*
62544 * The 2.0 compatible umount. No flags.
62545 */
62546-SYSCALL_DEFINE1(oldumount, char __user *, name)
62547+SYSCALL_DEFINE1(oldumount, const char __user *, name)
62548 {
62549 return sys_umount(name, 0);
62550 }
62551@@ -2431,6 +2437,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62552 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62553 MS_STRICTATIME);
62554
62555+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62556+ retval = -EPERM;
62557+ goto dput_out;
62558+ }
62559+
62560+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62561+ retval = -EPERM;
62562+ goto dput_out;
62563+ }
62564+
62565 if (flags & MS_REMOUNT)
62566 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62567 data_page);
62568@@ -2445,6 +2461,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62569 dev_name, data_page);
62570 dput_out:
62571 path_put(&path);
62572+
62573+ gr_log_mount(dev_name, dir_name, retval);
62574+
62575 return retval;
62576 }
62577
62578@@ -2462,7 +2481,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62579 * number incrementing at 10Ghz will take 12,427 years to wrap which
62580 * is effectively never, so we can ignore the possibility.
62581 */
62582-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62583+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62584
62585 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62586 {
62587@@ -2477,7 +2496,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62588 kfree(new_ns);
62589 return ERR_PTR(ret);
62590 }
62591- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62592+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62593 atomic_set(&new_ns->count, 1);
62594 new_ns->root = NULL;
62595 INIT_LIST_HEAD(&new_ns->list);
62596@@ -2487,7 +2506,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62597 return new_ns;
62598 }
62599
62600-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62601+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62602 struct user_namespace *user_ns, struct fs_struct *new_fs)
62603 {
62604 struct mnt_namespace *new_ns;
62605@@ -2608,8 +2627,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62606 }
62607 EXPORT_SYMBOL(mount_subtree);
62608
62609-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62610- char __user *, type, unsigned long, flags, void __user *, data)
62611+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62612+ const char __user *, type, unsigned long, flags, void __user *, data)
62613 {
62614 int ret;
62615 char *kernel_type;
62616@@ -2722,6 +2741,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62617 if (error)
62618 goto out2;
62619
62620+ if (gr_handle_chroot_pivot()) {
62621+ error = -EPERM;
62622+ goto out2;
62623+ }
62624+
62625 get_fs_root(current->fs, &root);
62626 old_mp = lock_mount(&old);
62627 error = PTR_ERR(old_mp);
62628@@ -2990,7 +3014,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62629 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62630 return -EPERM;
62631
62632- if (fs->users != 1)
62633+ if (atomic_read(&fs->users) != 1)
62634 return -EINVAL;
62635
62636 get_mnt_ns(mnt_ns);
62637diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62638index f4ccfe6..a5cf064 100644
62639--- a/fs/nfs/callback_xdr.c
62640+++ b/fs/nfs/callback_xdr.c
62641@@ -51,7 +51,7 @@ struct callback_op {
62642 callback_decode_arg_t decode_args;
62643 callback_encode_res_t encode_res;
62644 long res_maxsize;
62645-};
62646+} __do_const;
62647
62648 static struct callback_op callback_ops[];
62649
62650diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62651index 360114a..ac6e265 100644
62652--- a/fs/nfs/inode.c
62653+++ b/fs/nfs/inode.c
62654@@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62655 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62656 }
62657
62658-static atomic_long_t nfs_attr_generation_counter;
62659+static atomic_long_unchecked_t nfs_attr_generation_counter;
62660
62661 static unsigned long nfs_read_attr_generation_counter(void)
62662 {
62663- return atomic_long_read(&nfs_attr_generation_counter);
62664+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62665 }
62666
62667 unsigned long nfs_inc_attr_generation_counter(void)
62668 {
62669- return atomic_long_inc_return(&nfs_attr_generation_counter);
62670+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62671 }
62672
62673 void nfs_fattr_init(struct nfs_fattr *fattr)
62674diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62675index 9a914e8..e89c0ea 100644
62676--- a/fs/nfsd/nfs4proc.c
62677+++ b/fs/nfsd/nfs4proc.c
62678@@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62679 nfsd4op_rsize op_rsize_bop;
62680 stateid_getter op_get_currentstateid;
62681 stateid_setter op_set_currentstateid;
62682-};
62683+} __do_const;
62684
62685 static struct nfsd4_operation nfsd4_ops[];
62686
62687diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62688index 16e8fa7..b0803f6 100644
62689--- a/fs/nfsd/nfs4xdr.c
62690+++ b/fs/nfsd/nfs4xdr.c
62691@@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62692
62693 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62694
62695-static nfsd4_dec nfsd4_dec_ops[] = {
62696+static const nfsd4_dec nfsd4_dec_ops[] = {
62697 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62698 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62699 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62700diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62701index f8f060f..c4ba09a 100644
62702--- a/fs/nfsd/nfscache.c
62703+++ b/fs/nfsd/nfscache.c
62704@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62705 {
62706 struct svc_cacherep *rp = rqstp->rq_cacherep;
62707 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62708- int len;
62709+ long len;
62710 size_t bufsize = 0;
62711
62712 if (!rp)
62713 return;
62714
62715- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62716- len >>= 2;
62717+ if (statp) {
62718+ len = (char*)statp - (char*)resv->iov_base;
62719+ len = resv->iov_len - len;
62720+ len >>= 2;
62721+ }
62722
62723 /* Don't cache excessive amounts of data and XDR failures */
62724 if (!statp || len > (256 >> 2)) {
62725diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62726index eea5ad1..5a84ac7 100644
62727--- a/fs/nfsd/vfs.c
62728+++ b/fs/nfsd/vfs.c
62729@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62730 } else {
62731 oldfs = get_fs();
62732 set_fs(KERNEL_DS);
62733- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62734+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62735 set_fs(oldfs);
62736 }
62737
62738@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62739
62740 /* Write the data. */
62741 oldfs = get_fs(); set_fs(KERNEL_DS);
62742- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62743+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62744 set_fs(oldfs);
62745 if (host_err < 0)
62746 goto out_nfserr;
62747@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62748 */
62749
62750 oldfs = get_fs(); set_fs(KERNEL_DS);
62751- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62752+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62753 set_fs(oldfs);
62754
62755 if (host_err < 0)
62756diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62757index 52ccd34..43a53b1 100644
62758--- a/fs/nls/nls_base.c
62759+++ b/fs/nls/nls_base.c
62760@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62761
62762 int __register_nls(struct nls_table *nls, struct module *owner)
62763 {
62764- struct nls_table ** tmp = &tables;
62765+ struct nls_table *tmp = tables;
62766
62767 if (nls->next)
62768 return -EBUSY;
62769
62770- nls->owner = owner;
62771+ pax_open_kernel();
62772+ *(void **)&nls->owner = owner;
62773+ pax_close_kernel();
62774 spin_lock(&nls_lock);
62775- while (*tmp) {
62776- if (nls == *tmp) {
62777+ while (tmp) {
62778+ if (nls == tmp) {
62779 spin_unlock(&nls_lock);
62780 return -EBUSY;
62781 }
62782- tmp = &(*tmp)->next;
62783+ tmp = tmp->next;
62784 }
62785- nls->next = tables;
62786+ pax_open_kernel();
62787+ *(struct nls_table **)&nls->next = tables;
62788+ pax_close_kernel();
62789 tables = nls;
62790 spin_unlock(&nls_lock);
62791 return 0;
62792@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62793
62794 int unregister_nls(struct nls_table * nls)
62795 {
62796- struct nls_table ** tmp = &tables;
62797+ struct nls_table * const * tmp = &tables;
62798
62799 spin_lock(&nls_lock);
62800 while (*tmp) {
62801 if (nls == *tmp) {
62802- *tmp = nls->next;
62803+ pax_open_kernel();
62804+ *(struct nls_table **)tmp = nls->next;
62805+ pax_close_kernel();
62806 spin_unlock(&nls_lock);
62807 return 0;
62808 }
62809diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62810index 162b3f1..6076a7c 100644
62811--- a/fs/nls/nls_euc-jp.c
62812+++ b/fs/nls/nls_euc-jp.c
62813@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62814 p_nls = load_nls("cp932");
62815
62816 if (p_nls) {
62817- table.charset2upper = p_nls->charset2upper;
62818- table.charset2lower = p_nls->charset2lower;
62819+ pax_open_kernel();
62820+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62821+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62822+ pax_close_kernel();
62823 return register_nls(&table);
62824 }
62825
62826diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62827index a80a741..7b96e1b 100644
62828--- a/fs/nls/nls_koi8-ru.c
62829+++ b/fs/nls/nls_koi8-ru.c
62830@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62831 p_nls = load_nls("koi8-u");
62832
62833 if (p_nls) {
62834- table.charset2upper = p_nls->charset2upper;
62835- table.charset2lower = p_nls->charset2lower;
62836+ pax_open_kernel();
62837+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62838+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62839+ pax_close_kernel();
62840 return register_nls(&table);
62841 }
62842
62843diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62844index 287a22c..4e56e4e 100644
62845--- a/fs/notify/fanotify/fanotify_user.c
62846+++ b/fs/notify/fanotify/fanotify_user.c
62847@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62848
62849 fd = fanotify_event_metadata.fd;
62850 ret = -EFAULT;
62851- if (copy_to_user(buf, &fanotify_event_metadata,
62852- fanotify_event_metadata.event_len))
62853+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62854+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62855 goto out_close_fd;
62856
62857 ret = prepare_for_access_response(group, event, fd);
62858@@ -742,6 +742,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
62859 oevent->path.mnt = NULL;
62860 oevent->path.dentry = NULL;
62861
62862+ if (force_o_largefile())
62863+ event_f_flags |= O_LARGEFILE;
62864 group->fanotify_data.f_flags = event_f_flags;
62865 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62866 oevent->response = 0;
62867diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62868index 1e58402..bb2d6f4 100644
62869--- a/fs/notify/notification.c
62870+++ b/fs/notify/notification.c
62871@@ -48,7 +48,7 @@
62872 #include <linux/fsnotify_backend.h>
62873 #include "fsnotify.h"
62874
62875-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62876+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62877
62878 /**
62879 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62880@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62881 */
62882 u32 fsnotify_get_cookie(void)
62883 {
62884- return atomic_inc_return(&fsnotify_sync_cookie);
62885+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62886 }
62887 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62888
62889diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62890index 9e38daf..5727cae 100644
62891--- a/fs/ntfs/dir.c
62892+++ b/fs/ntfs/dir.c
62893@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62894 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62895 ~(s64)(ndir->itype.index.block_size - 1)));
62896 /* Bounds checks. */
62897- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62898+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62899 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62900 "inode 0x%lx or driver bug.", vdir->i_ino);
62901 goto err_out;
62902diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62903index db9bd8a..8338fb6 100644
62904--- a/fs/ntfs/file.c
62905+++ b/fs/ntfs/file.c
62906@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62907 char *addr;
62908 size_t total = 0;
62909 unsigned len;
62910- int left;
62911+ unsigned left;
62912
62913 do {
62914 len = PAGE_CACHE_SIZE - ofs;
62915diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62916index 82650d5..db37dcf 100644
62917--- a/fs/ntfs/super.c
62918+++ b/fs/ntfs/super.c
62919@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62920 if (!silent)
62921 ntfs_error(sb, "Primary boot sector is invalid.");
62922 } else if (!silent)
62923- ntfs_error(sb, read_err_str, "primary");
62924+ ntfs_error(sb, read_err_str, "%s", "primary");
62925 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62926 if (bh_primary)
62927 brelse(bh_primary);
62928@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62929 goto hotfix_primary_boot_sector;
62930 brelse(bh_backup);
62931 } else if (!silent)
62932- ntfs_error(sb, read_err_str, "backup");
62933+ ntfs_error(sb, read_err_str, "%s", "backup");
62934 /* Try to read NT3.51- backup boot sector. */
62935 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62936 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62937@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62938 "sector.");
62939 brelse(bh_backup);
62940 } else if (!silent)
62941- ntfs_error(sb, read_err_str, "backup");
62942+ ntfs_error(sb, read_err_str, "%s", "backup");
62943 /* We failed. Cleanup and return. */
62944 if (bh_primary)
62945 brelse(bh_primary);
62946diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62947index 0440134..d52c93a 100644
62948--- a/fs/ocfs2/localalloc.c
62949+++ b/fs/ocfs2/localalloc.c
62950@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62951 goto bail;
62952 }
62953
62954- atomic_inc(&osb->alloc_stats.moves);
62955+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62956
62957 bail:
62958 if (handle)
62959diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62960index 553f53c..aaf5133 100644
62961--- a/fs/ocfs2/ocfs2.h
62962+++ b/fs/ocfs2/ocfs2.h
62963@@ -235,11 +235,11 @@ enum ocfs2_vol_state
62964
62965 struct ocfs2_alloc_stats
62966 {
62967- atomic_t moves;
62968- atomic_t local_data;
62969- atomic_t bitmap_data;
62970- atomic_t bg_allocs;
62971- atomic_t bg_extends;
62972+ atomic_unchecked_t moves;
62973+ atomic_unchecked_t local_data;
62974+ atomic_unchecked_t bitmap_data;
62975+ atomic_unchecked_t bg_allocs;
62976+ atomic_unchecked_t bg_extends;
62977 };
62978
62979 enum ocfs2_local_alloc_state
62980diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62981index 47ae266..6e8b793 100644
62982--- a/fs/ocfs2/suballoc.c
62983+++ b/fs/ocfs2/suballoc.c
62984@@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62985 mlog_errno(status);
62986 goto bail;
62987 }
62988- atomic_inc(&osb->alloc_stats.bg_extends);
62989+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62990
62991 /* You should never ask for this much metadata */
62992 BUG_ON(bits_wanted >
62993@@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62994 mlog_errno(status);
62995 goto bail;
62996 }
62997- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62998+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62999
63000 *suballoc_loc = res.sr_bg_blkno;
63001 *suballoc_bit_start = res.sr_bit_offset;
63002@@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
63003 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
63004 res->sr_bits);
63005
63006- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63007+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63008
63009 BUG_ON(res->sr_bits != 1);
63010
63011@@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
63012 mlog_errno(status);
63013 goto bail;
63014 }
63015- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63016+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
63017
63018 BUG_ON(res.sr_bits != 1);
63019
63020@@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
63021 cluster_start,
63022 num_clusters);
63023 if (!status)
63024- atomic_inc(&osb->alloc_stats.local_data);
63025+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
63026 } else {
63027 if (min_clusters > (osb->bitmap_cpg - 1)) {
63028 /* The only paths asking for contiguousness
63029@@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
63030 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
63031 res.sr_bg_blkno,
63032 res.sr_bit_offset);
63033- atomic_inc(&osb->alloc_stats.bitmap_data);
63034+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
63035 *num_clusters = res.sr_bits;
63036 }
63037 }
63038diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
63039index 49d84f8..4807e0b 100644
63040--- a/fs/ocfs2/super.c
63041+++ b/fs/ocfs2/super.c
63042@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
63043 "%10s => GlobalAllocs: %d LocalAllocs: %d "
63044 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
63045 "Stats",
63046- atomic_read(&osb->alloc_stats.bitmap_data),
63047- atomic_read(&osb->alloc_stats.local_data),
63048- atomic_read(&osb->alloc_stats.bg_allocs),
63049- atomic_read(&osb->alloc_stats.moves),
63050- atomic_read(&osb->alloc_stats.bg_extends));
63051+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
63052+ atomic_read_unchecked(&osb->alloc_stats.local_data),
63053+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
63054+ atomic_read_unchecked(&osb->alloc_stats.moves),
63055+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
63056
63057 out += snprintf(buf + out, len - out,
63058 "%10s => State: %u Descriptor: %llu Size: %u bits "
63059@@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
63060 spin_lock_init(&osb->osb_xattr_lock);
63061 ocfs2_init_steal_slots(osb);
63062
63063- atomic_set(&osb->alloc_stats.moves, 0);
63064- atomic_set(&osb->alloc_stats.local_data, 0);
63065- atomic_set(&osb->alloc_stats.bitmap_data, 0);
63066- atomic_set(&osb->alloc_stats.bg_allocs, 0);
63067- atomic_set(&osb->alloc_stats.bg_extends, 0);
63068+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
63069+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
63070+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
63071+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
63072+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
63073
63074 /* Copy the blockcheck stats from the superblock probe */
63075 osb->osb_ecc_stats = *stats;
63076diff --git a/fs/open.c b/fs/open.c
63077index 2ed7325..4e77ac3 100644
63078--- a/fs/open.c
63079+++ b/fs/open.c
63080@@ -32,6 +32,8 @@
63081 #include <linux/dnotify.h>
63082 #include <linux/compat.h>
63083
63084+#define CREATE_TRACE_POINTS
63085+#include <trace/events/fs.h>
63086 #include "internal.h"
63087
63088 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
63089@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
63090 error = locks_verify_truncate(inode, NULL, length);
63091 if (!error)
63092 error = security_path_truncate(path);
63093+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
63094+ error = -EACCES;
63095 if (!error)
63096 error = do_truncate(path->dentry, length, 0, NULL);
63097
63098@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
63099 error = locks_verify_truncate(inode, f.file, length);
63100 if (!error)
63101 error = security_path_truncate(&f.file->f_path);
63102+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
63103+ error = -EACCES;
63104 if (!error)
63105 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
63106 sb_end_write(inode->i_sb);
63107@@ -361,6 +367,9 @@ retry:
63108 if (__mnt_is_readonly(path.mnt))
63109 res = -EROFS;
63110
63111+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
63112+ res = -EACCES;
63113+
63114 out_path_release:
63115 path_put(&path);
63116 if (retry_estale(res, lookup_flags)) {
63117@@ -392,6 +401,8 @@ retry:
63118 if (error)
63119 goto dput_and_out;
63120
63121+ gr_log_chdir(path.dentry, path.mnt);
63122+
63123 set_fs_pwd(current->fs, &path);
63124
63125 dput_and_out:
63126@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
63127 goto out_putf;
63128
63129 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
63130+
63131+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
63132+ error = -EPERM;
63133+
63134+ if (!error)
63135+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
63136+
63137 if (!error)
63138 set_fs_pwd(current->fs, &f.file->f_path);
63139 out_putf:
63140@@ -450,7 +468,13 @@ retry:
63141 if (error)
63142 goto dput_and_out;
63143
63144+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
63145+ goto dput_and_out;
63146+
63147 set_fs_root(current->fs, &path);
63148+
63149+ gr_handle_chroot_chdir(&path);
63150+
63151 error = 0;
63152 dput_and_out:
63153 path_put(&path);
63154@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
63155 return error;
63156 retry_deleg:
63157 mutex_lock(&inode->i_mutex);
63158+
63159+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
63160+ error = -EACCES;
63161+ goto out_unlock;
63162+ }
63163+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
63164+ error = -EACCES;
63165+ goto out_unlock;
63166+ }
63167+
63168 error = security_path_chmod(path, mode);
63169 if (error)
63170 goto out_unlock;
63171@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
63172 uid = make_kuid(current_user_ns(), user);
63173 gid = make_kgid(current_user_ns(), group);
63174
63175+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
63176+ return -EACCES;
63177+
63178 newattrs.ia_valid = ATTR_CTIME;
63179 if (user != (uid_t) -1) {
63180 if (!uid_valid(uid))
63181@@ -982,6 +1019,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
63182 } else {
63183 fsnotify_open(f);
63184 fd_install(fd, f);
63185+ trace_do_sys_open(tmp->name, flags, mode);
63186 }
63187 }
63188 putname(tmp);
63189diff --git a/fs/pipe.c b/fs/pipe.c
63190index 78fd0d0..f71fc09 100644
63191--- a/fs/pipe.c
63192+++ b/fs/pipe.c
63193@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
63194
63195 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
63196 {
63197- if (pipe->files)
63198+ if (atomic_read(&pipe->files))
63199 mutex_lock_nested(&pipe->mutex, subclass);
63200 }
63201
63202@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
63203
63204 void pipe_unlock(struct pipe_inode_info *pipe)
63205 {
63206- if (pipe->files)
63207+ if (atomic_read(&pipe->files))
63208 mutex_unlock(&pipe->mutex);
63209 }
63210 EXPORT_SYMBOL(pipe_unlock);
63211@@ -449,9 +449,9 @@ redo:
63212 }
63213 if (bufs) /* More to do? */
63214 continue;
63215- if (!pipe->writers)
63216+ if (!atomic_read(&pipe->writers))
63217 break;
63218- if (!pipe->waiting_writers) {
63219+ if (!atomic_read(&pipe->waiting_writers)) {
63220 /* syscall merging: Usually we must not sleep
63221 * if O_NONBLOCK is set, or if we got some data.
63222 * But if a writer sleeps in kernel space, then
63223@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
63224 ret = 0;
63225 __pipe_lock(pipe);
63226
63227- if (!pipe->readers) {
63228+ if (!atomic_read(&pipe->readers)) {
63229 send_sig(SIGPIPE, current, 0);
63230 ret = -EPIPE;
63231 goto out;
63232@@ -562,7 +562,7 @@ redo1:
63233 for (;;) {
63234 int bufs;
63235
63236- if (!pipe->readers) {
63237+ if (!atomic_read(&pipe->readers)) {
63238 send_sig(SIGPIPE, current, 0);
63239 if (!ret)
63240 ret = -EPIPE;
63241@@ -653,9 +653,9 @@ redo2:
63242 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63243 do_wakeup = 0;
63244 }
63245- pipe->waiting_writers++;
63246+ atomic_inc(&pipe->waiting_writers);
63247 pipe_wait(pipe);
63248- pipe->waiting_writers--;
63249+ atomic_dec(&pipe->waiting_writers);
63250 }
63251 out:
63252 __pipe_unlock(pipe);
63253@@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63254 mask = 0;
63255 if (filp->f_mode & FMODE_READ) {
63256 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
63257- if (!pipe->writers && filp->f_version != pipe->w_counter)
63258+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
63259 mask |= POLLHUP;
63260 }
63261
63262@@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63263 * Most Unices do not set POLLERR for FIFOs but on Linux they
63264 * behave exactly like pipes for poll().
63265 */
63266- if (!pipe->readers)
63267+ if (!atomic_read(&pipe->readers))
63268 mask |= POLLERR;
63269 }
63270
63271@@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
63272 int kill = 0;
63273
63274 spin_lock(&inode->i_lock);
63275- if (!--pipe->files) {
63276+ if (atomic_dec_and_test(&pipe->files)) {
63277 inode->i_pipe = NULL;
63278 kill = 1;
63279 }
63280@@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
63281
63282 __pipe_lock(pipe);
63283 if (file->f_mode & FMODE_READ)
63284- pipe->readers--;
63285+ atomic_dec(&pipe->readers);
63286 if (file->f_mode & FMODE_WRITE)
63287- pipe->writers--;
63288+ atomic_dec(&pipe->writers);
63289
63290- if (pipe->readers || pipe->writers) {
63291+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
63292 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
63293 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63294 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
63295@@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
63296 kfree(pipe);
63297 }
63298
63299-static struct vfsmount *pipe_mnt __read_mostly;
63300+struct vfsmount *pipe_mnt __read_mostly;
63301
63302 /*
63303 * pipefs_dname() is called from d_path().
63304@@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
63305 goto fail_iput;
63306
63307 inode->i_pipe = pipe;
63308- pipe->files = 2;
63309- pipe->readers = pipe->writers = 1;
63310+ atomic_set(&pipe->files, 2);
63311+ atomic_set(&pipe->readers, 1);
63312+ atomic_set(&pipe->writers, 1);
63313 inode->i_fop = &pipefifo_fops;
63314
63315 /*
63316@@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
63317 spin_lock(&inode->i_lock);
63318 if (inode->i_pipe) {
63319 pipe = inode->i_pipe;
63320- pipe->files++;
63321+ atomic_inc(&pipe->files);
63322 spin_unlock(&inode->i_lock);
63323 } else {
63324 spin_unlock(&inode->i_lock);
63325 pipe = alloc_pipe_info();
63326 if (!pipe)
63327 return -ENOMEM;
63328- pipe->files = 1;
63329+ atomic_set(&pipe->files, 1);
63330 spin_lock(&inode->i_lock);
63331 if (unlikely(inode->i_pipe)) {
63332- inode->i_pipe->files++;
63333+ atomic_inc(&inode->i_pipe->files);
63334 spin_unlock(&inode->i_lock);
63335 free_pipe_info(pipe);
63336 pipe = inode->i_pipe;
63337@@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
63338 * opened, even when there is no process writing the FIFO.
63339 */
63340 pipe->r_counter++;
63341- if (pipe->readers++ == 0)
63342+ if (atomic_inc_return(&pipe->readers) == 1)
63343 wake_up_partner(pipe);
63344
63345- if (!is_pipe && !pipe->writers) {
63346+ if (!is_pipe && !atomic_read(&pipe->writers)) {
63347 if ((filp->f_flags & O_NONBLOCK)) {
63348 /* suppress POLLHUP until we have
63349 * seen a writer */
63350@@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
63351 * errno=ENXIO when there is no process reading the FIFO.
63352 */
63353 ret = -ENXIO;
63354- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
63355+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
63356 goto err;
63357
63358 pipe->w_counter++;
63359- if (!pipe->writers++)
63360+ if (atomic_inc_return(&pipe->writers) == 1)
63361 wake_up_partner(pipe);
63362
63363- if (!is_pipe && !pipe->readers) {
63364+ if (!is_pipe && !atomic_read(&pipe->readers)) {
63365 if (wait_for_partner(pipe, &pipe->r_counter))
63366 goto err_wr;
63367 }
63368@@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
63369 * the process can at least talk to itself.
63370 */
63371
63372- pipe->readers++;
63373- pipe->writers++;
63374+ atomic_inc(&pipe->readers);
63375+ atomic_inc(&pipe->writers);
63376 pipe->r_counter++;
63377 pipe->w_counter++;
63378- if (pipe->readers == 1 || pipe->writers == 1)
63379+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
63380 wake_up_partner(pipe);
63381 break;
63382
63383@@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
63384 return 0;
63385
63386 err_rd:
63387- if (!--pipe->readers)
63388+ if (atomic_dec_and_test(&pipe->readers))
63389 wake_up_interruptible(&pipe->wait);
63390 ret = -ERESTARTSYS;
63391 goto err;
63392
63393 err_wr:
63394- if (!--pipe->writers)
63395+ if (atomic_dec_and_test(&pipe->writers))
63396 wake_up_interruptible(&pipe->wait);
63397 ret = -ERESTARTSYS;
63398 goto err;
63399diff --git a/fs/posix_acl.c b/fs/posix_acl.c
63400index 0855f77..6787d50 100644
63401--- a/fs/posix_acl.c
63402+++ b/fs/posix_acl.c
63403@@ -20,6 +20,7 @@
63404 #include <linux/xattr.h>
63405 #include <linux/export.h>
63406 #include <linux/user_namespace.h>
63407+#include <linux/grsecurity.h>
63408
63409 struct posix_acl **acl_by_type(struct inode *inode, int type)
63410 {
63411@@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
63412 }
63413 }
63414 if (mode_p)
63415- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63416+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63417 return not_equiv;
63418 }
63419 EXPORT_SYMBOL(posix_acl_equiv_mode);
63420@@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
63421 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
63422 }
63423
63424- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63425+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63426 return not_equiv;
63427 }
63428
63429@@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
63430 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63431 int err = -ENOMEM;
63432 if (clone) {
63433+ *mode_p &= ~gr_acl_umask();
63434+
63435 err = posix_acl_create_masq(clone, mode_p);
63436 if (err < 0) {
63437 posix_acl_release(clone);
63438@@ -659,11 +662,12 @@ struct posix_acl *
63439 posix_acl_from_xattr(struct user_namespace *user_ns,
63440 const void *value, size_t size)
63441 {
63442- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63443- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63444+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63445+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63446 int count;
63447 struct posix_acl *acl;
63448 struct posix_acl_entry *acl_e;
63449+ umode_t umask = gr_acl_umask();
63450
63451 if (!value)
63452 return NULL;
63453@@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63454
63455 switch(acl_e->e_tag) {
63456 case ACL_USER_OBJ:
63457+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63458+ break;
63459 case ACL_GROUP_OBJ:
63460 case ACL_MASK:
63461+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63462+ break;
63463 case ACL_OTHER:
63464+ acl_e->e_perm &= ~(umask & S_IRWXO);
63465 break;
63466
63467 case ACL_USER:
63468+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63469 acl_e->e_uid =
63470 make_kuid(user_ns,
63471 le32_to_cpu(entry->e_id));
63472@@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63473 goto fail;
63474 break;
63475 case ACL_GROUP:
63476+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63477 acl_e->e_gid =
63478 make_kgid(user_ns,
63479 le32_to_cpu(entry->e_id));
63480diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63481index 2183fcf..3c32a98 100644
63482--- a/fs/proc/Kconfig
63483+++ b/fs/proc/Kconfig
63484@@ -30,7 +30,7 @@ config PROC_FS
63485
63486 config PROC_KCORE
63487 bool "/proc/kcore support" if !ARM
63488- depends on PROC_FS && MMU
63489+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63490 help
63491 Provides a virtual ELF core file of the live kernel. This can
63492 be read with gdb and other ELF tools. No modifications can be
63493@@ -38,8 +38,8 @@ config PROC_KCORE
63494
63495 config PROC_VMCORE
63496 bool "/proc/vmcore support"
63497- depends on PROC_FS && CRASH_DUMP
63498- default y
63499+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63500+ default n
63501 help
63502 Exports the dump image of crashed kernel in ELF format.
63503
63504@@ -63,8 +63,8 @@ config PROC_SYSCTL
63505 limited in memory.
63506
63507 config PROC_PAGE_MONITOR
63508- default y
63509- depends on PROC_FS && MMU
63510+ default n
63511+ depends on PROC_FS && MMU && !GRKERNSEC
63512 bool "Enable /proc page monitoring" if EXPERT
63513 help
63514 Various /proc files exist to monitor process memory utilization:
63515diff --git a/fs/proc/array.c b/fs/proc/array.c
63516index 656e401..b5b86b9 100644
63517--- a/fs/proc/array.c
63518+++ b/fs/proc/array.c
63519@@ -60,6 +60,7 @@
63520 #include <linux/tty.h>
63521 #include <linux/string.h>
63522 #include <linux/mman.h>
63523+#include <linux/grsecurity.h>
63524 #include <linux/proc_fs.h>
63525 #include <linux/ioport.h>
63526 #include <linux/uaccess.h>
63527@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63528 seq_putc(m, '\n');
63529 }
63530
63531+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63532+static inline void task_pax(struct seq_file *m, struct task_struct *p)
63533+{
63534+ if (p->mm)
63535+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63536+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63537+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63538+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63539+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63540+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63541+ else
63542+ seq_printf(m, "PaX:\t-----\n");
63543+}
63544+#endif
63545+
63546 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63547 struct pid *pid, struct task_struct *task)
63548 {
63549@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63550 task_cpus_allowed(m, task);
63551 cpuset_task_status_allowed(m, task);
63552 task_context_switch_counts(m, task);
63553+
63554+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63555+ task_pax(m, task);
63556+#endif
63557+
63558+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63559+ task_grsec_rbac(m, task);
63560+#endif
63561+
63562 return 0;
63563 }
63564
63565+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63566+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63567+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63568+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63569+#endif
63570+
63571 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63572 struct pid *pid, struct task_struct *task, int whole)
63573 {
63574@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63575 char tcomm[sizeof(task->comm)];
63576 unsigned long flags;
63577
63578+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63579+ if (current->exec_id != m->exec_id) {
63580+ gr_log_badprocpid("stat");
63581+ return 0;
63582+ }
63583+#endif
63584+
63585 state = *get_task_state(task);
63586 vsize = eip = esp = 0;
63587 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63588@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63589 gtime = task_gtime(task);
63590 }
63591
63592+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63593+ if (PAX_RAND_FLAGS(mm)) {
63594+ eip = 0;
63595+ esp = 0;
63596+ wchan = 0;
63597+ }
63598+#endif
63599+#ifdef CONFIG_GRKERNSEC_HIDESYM
63600+ wchan = 0;
63601+ eip =0;
63602+ esp =0;
63603+#endif
63604+
63605 /* scale priority and nice values from timeslices to -20..20 */
63606 /* to make it look like a "normal" Unix priority/nice value */
63607 priority = task_prio(task);
63608@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63609 seq_put_decimal_ull(m, ' ', vsize);
63610 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63611 seq_put_decimal_ull(m, ' ', rsslim);
63612+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63613+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63614+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63615+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63616+#else
63617 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63618 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63619 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63620+#endif
63621 seq_put_decimal_ull(m, ' ', esp);
63622 seq_put_decimal_ull(m, ' ', eip);
63623 /* The signal information here is obsolete.
63624@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63625 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63626 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63627
63628- if (mm && permitted) {
63629+ if (mm && permitted
63630+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63631+ && !PAX_RAND_FLAGS(mm)
63632+#endif
63633+ ) {
63634 seq_put_decimal_ull(m, ' ', mm->start_data);
63635 seq_put_decimal_ull(m, ' ', mm->end_data);
63636 seq_put_decimal_ull(m, ' ', mm->start_brk);
63637@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63638 struct pid *pid, struct task_struct *task)
63639 {
63640 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63641- struct mm_struct *mm = get_task_mm(task);
63642+ struct mm_struct *mm;
63643
63644+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63645+ if (current->exec_id != m->exec_id) {
63646+ gr_log_badprocpid("statm");
63647+ return 0;
63648+ }
63649+#endif
63650+ mm = get_task_mm(task);
63651 if (mm) {
63652 size = task_statm(mm, &shared, &text, &data, &resident);
63653 mmput(mm);
63654@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63655 return 0;
63656 }
63657
63658+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63659+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63660+{
63661+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63662+}
63663+#endif
63664+
63665 #ifdef CONFIG_CHECKPOINT_RESTORE
63666 static struct pid *
63667 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63668diff --git a/fs/proc/base.c b/fs/proc/base.c
63669index b976062..584d0bc 100644
63670--- a/fs/proc/base.c
63671+++ b/fs/proc/base.c
63672@@ -113,6 +113,14 @@ struct pid_entry {
63673 union proc_op op;
63674 };
63675
63676+struct getdents_callback {
63677+ struct linux_dirent __user * current_dir;
63678+ struct linux_dirent __user * previous;
63679+ struct file * file;
63680+ int count;
63681+ int error;
63682+};
63683+
63684 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63685 .name = (NAME), \
63686 .len = sizeof(NAME) - 1, \
63687@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
63688 if (!mm->arg_end)
63689 goto out_mm; /* Shh! No looking before we're done */
63690
63691+ if (gr_acl_handle_procpidmem(task))
63692+ goto out_mm;
63693+
63694 len = mm->arg_end - mm->arg_start;
63695
63696 if (len > PAGE_SIZE)
63697@@ -237,12 +248,28 @@ out:
63698 return res;
63699 }
63700
63701+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63702+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63703+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63704+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63705+#endif
63706+
63707 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63708 {
63709 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63710 int res = PTR_ERR(mm);
63711 if (mm && !IS_ERR(mm)) {
63712 unsigned int nwords = 0;
63713+
63714+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63715+ /* allow if we're currently ptracing this task */
63716+ if (PAX_RAND_FLAGS(mm) &&
63717+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63718+ mmput(mm);
63719+ return 0;
63720+ }
63721+#endif
63722+
63723 do {
63724 nwords += 2;
63725 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63726@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63727 }
63728
63729
63730-#ifdef CONFIG_KALLSYMS
63731+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63732 /*
63733 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63734 * Returns the resolved symbol. If that fails, simply return the address.
63735@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
63736 mutex_unlock(&task->signal->cred_guard_mutex);
63737 }
63738
63739-#ifdef CONFIG_STACKTRACE
63740+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63741
63742 #define MAX_STACK_TRACE_DEPTH 64
63743
63744@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63745 return count;
63746 }
63747
63748-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63749+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63750 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63751 {
63752 long nr;
63753@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63754 /************************************************************************/
63755
63756 /* permission checks */
63757-static int proc_fd_access_allowed(struct inode *inode)
63758+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63759 {
63760 struct task_struct *task;
63761 int allowed = 0;
63762@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63763 */
63764 task = get_proc_task(inode);
63765 if (task) {
63766- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63767+ if (log)
63768+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63769+ else
63770+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63771 put_task_struct(task);
63772 }
63773 return allowed;
63774@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63775 struct task_struct *task,
63776 int hide_pid_min)
63777 {
63778+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63779+ return false;
63780+
63781+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63782+ rcu_read_lock();
63783+ {
63784+ const struct cred *tmpcred = current_cred();
63785+ const struct cred *cred = __task_cred(task);
63786+
63787+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63788+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63789+ || in_group_p(grsec_proc_gid)
63790+#endif
63791+ ) {
63792+ rcu_read_unlock();
63793+ return true;
63794+ }
63795+ }
63796+ rcu_read_unlock();
63797+
63798+ if (!pid->hide_pid)
63799+ return false;
63800+#endif
63801+
63802 if (pid->hide_pid < hide_pid_min)
63803 return true;
63804 if (in_group_p(pid->pid_gid))
63805 return true;
63806+
63807 return ptrace_may_access(task, PTRACE_MODE_READ);
63808 }
63809
63810@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63811 put_task_struct(task);
63812
63813 if (!has_perms) {
63814+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63815+ {
63816+#else
63817 if (pid->hide_pid == 2) {
63818+#endif
63819 /*
63820 * Let's make getdents(), stat(), and open()
63821 * consistent with each other. If a process
63822@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63823 if (!task)
63824 return -ESRCH;
63825
63826+ if (gr_acl_handle_procpidmem(task)) {
63827+ put_task_struct(task);
63828+ return -EPERM;
63829+ }
63830+
63831 mm = mm_access(task, mode);
63832 put_task_struct(task);
63833
63834@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63835
63836 file->private_data = mm;
63837
63838+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63839+ file->f_version = current->exec_id;
63840+#endif
63841+
63842 return 0;
63843 }
63844
63845@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63846 ssize_t copied;
63847 char *page;
63848
63849+#ifdef CONFIG_GRKERNSEC
63850+ if (write)
63851+ return -EPERM;
63852+#endif
63853+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63854+ if (file->f_version != current->exec_id) {
63855+ gr_log_badprocpid("mem");
63856+ return 0;
63857+ }
63858+#endif
63859+
63860 if (!mm)
63861 return 0;
63862
63863@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63864 goto free;
63865
63866 while (count > 0) {
63867- int this_len = min_t(int, count, PAGE_SIZE);
63868+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63869
63870 if (write && copy_from_user(page, buf, this_len)) {
63871 copied = -EFAULT;
63872@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63873 if (!mm)
63874 return 0;
63875
63876+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63877+ if (file->f_version != current->exec_id) {
63878+ gr_log_badprocpid("environ");
63879+ return 0;
63880+ }
63881+#endif
63882+
63883 page = (char *)__get_free_page(GFP_TEMPORARY);
63884 if (!page)
63885 return -ENOMEM;
63886@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63887 goto free;
63888 while (count > 0) {
63889 size_t this_len, max_len;
63890- int retval;
63891+ ssize_t retval;
63892
63893 if (src >= (mm->env_end - mm->env_start))
63894 break;
63895@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63896 int error = -EACCES;
63897
63898 /* Are we allowed to snoop on the tasks file descriptors? */
63899- if (!proc_fd_access_allowed(inode))
63900+ if (!proc_fd_access_allowed(inode, 0))
63901 goto out;
63902
63903 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63904@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63905 struct path path;
63906
63907 /* Are we allowed to snoop on the tasks file descriptors? */
63908- if (!proc_fd_access_allowed(inode))
63909- goto out;
63910+ /* logging this is needed for learning on chromium to work properly,
63911+ but we don't want to flood the logs from 'ps' which does a readlink
63912+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63913+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63914+ */
63915+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63916+ if (!proc_fd_access_allowed(inode,0))
63917+ goto out;
63918+ } else {
63919+ if (!proc_fd_access_allowed(inode,1))
63920+ goto out;
63921+ }
63922
63923 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63924 if (error)
63925@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63926 rcu_read_lock();
63927 cred = __task_cred(task);
63928 inode->i_uid = cred->euid;
63929+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63930+ inode->i_gid = grsec_proc_gid;
63931+#else
63932 inode->i_gid = cred->egid;
63933+#endif
63934 rcu_read_unlock();
63935 }
63936 security_task_to_inode(task, inode);
63937@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63938 return -ENOENT;
63939 }
63940 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63941+#ifdef CONFIG_GRKERNSEC_PROC_USER
63942+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63943+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63944+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63945+#endif
63946 task_dumpable(task)) {
63947 cred = __task_cred(task);
63948 stat->uid = cred->euid;
63949+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63950+ stat->gid = grsec_proc_gid;
63951+#else
63952 stat->gid = cred->egid;
63953+#endif
63954 }
63955 }
63956 rcu_read_unlock();
63957@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63958
63959 if (task) {
63960 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63961+#ifdef CONFIG_GRKERNSEC_PROC_USER
63962+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63963+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63964+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63965+#endif
63966 task_dumpable(task)) {
63967 rcu_read_lock();
63968 cred = __task_cred(task);
63969 inode->i_uid = cred->euid;
63970+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63971+ inode->i_gid = grsec_proc_gid;
63972+#else
63973 inode->i_gid = cred->egid;
63974+#endif
63975 rcu_read_unlock();
63976 } else {
63977 inode->i_uid = GLOBAL_ROOT_UID;
63978@@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63979 if (!task)
63980 goto out_no_task;
63981
63982+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63983+ goto out;
63984+
63985 /*
63986 * Yes, it does not scale. And it should not. Don't add
63987 * new entries into /proc/<tgid>/ without very good reasons.
63988@@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63989 if (!task)
63990 return -ENOENT;
63991
63992+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63993+ goto out;
63994+
63995 if (!dir_emit_dots(file, ctx))
63996 goto out;
63997
63998@@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63999 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
64000 #endif
64001 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
64002-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
64003+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
64004 INF("syscall", S_IRUGO, proc_pid_syscall),
64005 #endif
64006 INF("cmdline", S_IRUGO, proc_pid_cmdline),
64007@@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
64008 #ifdef CONFIG_SECURITY
64009 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
64010 #endif
64011-#ifdef CONFIG_KALLSYMS
64012+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64013 INF("wchan", S_IRUGO, proc_pid_wchan),
64014 #endif
64015-#ifdef CONFIG_STACKTRACE
64016+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64017 ONE("stack", S_IRUGO, proc_pid_stack),
64018 #endif
64019 #ifdef CONFIG_SCHEDSTATS
64020@@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
64021 #ifdef CONFIG_HARDWALL
64022 INF("hardwall", S_IRUGO, proc_pid_hardwall),
64023 #endif
64024+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64025+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
64026+#endif
64027 #ifdef CONFIG_USER_NS
64028 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
64029 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
64030@@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
64031 if (!inode)
64032 goto out;
64033
64034+#ifdef CONFIG_GRKERNSEC_PROC_USER
64035+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
64036+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64037+ inode->i_gid = grsec_proc_gid;
64038+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
64039+#else
64040 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
64041+#endif
64042 inode->i_op = &proc_tgid_base_inode_operations;
64043 inode->i_fop = &proc_tgid_base_operations;
64044 inode->i_flags|=S_IMMUTABLE;
64045@@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
64046 if (!task)
64047 goto out;
64048
64049+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
64050+ goto out_put_task;
64051+
64052 result = proc_pid_instantiate(dir, dentry, task, NULL);
64053+out_put_task:
64054 put_task_struct(task);
64055 out:
64056 return ERR_PTR(result);
64057@@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
64058 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
64059 #endif
64060 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
64061-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
64062+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
64063 INF("syscall", S_IRUGO, proc_pid_syscall),
64064 #endif
64065 INF("cmdline", S_IRUGO, proc_pid_cmdline),
64066@@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
64067 #ifdef CONFIG_SECURITY
64068 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
64069 #endif
64070-#ifdef CONFIG_KALLSYMS
64071+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64072 INF("wchan", S_IRUGO, proc_pid_wchan),
64073 #endif
64074-#ifdef CONFIG_STACKTRACE
64075+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64076 ONE("stack", S_IRUGO, proc_pid_stack),
64077 #endif
64078 #ifdef CONFIG_SCHEDSTATS
64079diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
64080index cbd82df..c0407d2 100644
64081--- a/fs/proc/cmdline.c
64082+++ b/fs/proc/cmdline.c
64083@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
64084
64085 static int __init proc_cmdline_init(void)
64086 {
64087+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64088+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
64089+#else
64090 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
64091+#endif
64092 return 0;
64093 }
64094 fs_initcall(proc_cmdline_init);
64095diff --git a/fs/proc/devices.c b/fs/proc/devices.c
64096index 50493ed..248166b 100644
64097--- a/fs/proc/devices.c
64098+++ b/fs/proc/devices.c
64099@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
64100
64101 static int __init proc_devices_init(void)
64102 {
64103+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64104+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
64105+#else
64106 proc_create("devices", 0, NULL, &proc_devinfo_operations);
64107+#endif
64108 return 0;
64109 }
64110 fs_initcall(proc_devices_init);
64111diff --git a/fs/proc/fd.c b/fs/proc/fd.c
64112index 985ea88..d118a0a 100644
64113--- a/fs/proc/fd.c
64114+++ b/fs/proc/fd.c
64115@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
64116 if (!task)
64117 return -ENOENT;
64118
64119- files = get_files_struct(task);
64120+ if (!gr_acl_handle_procpidmem(task))
64121+ files = get_files_struct(task);
64122 put_task_struct(task);
64123
64124 if (files) {
64125@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
64126 */
64127 int proc_fd_permission(struct inode *inode, int mask)
64128 {
64129+ struct task_struct *task;
64130 int rv = generic_permission(inode, mask);
64131- if (rv == 0)
64132- return 0;
64133+
64134 if (task_tgid(current) == proc_pid(inode))
64135 rv = 0;
64136+
64137+ task = get_proc_task(inode);
64138+ if (task == NULL)
64139+ return rv;
64140+
64141+ if (gr_acl_handle_procpidmem(task))
64142+ rv = -EACCES;
64143+
64144+ put_task_struct(task);
64145+
64146 return rv;
64147 }
64148
64149diff --git a/fs/proc/generic.c b/fs/proc/generic.c
64150index b7f268e..3bea6b7 100644
64151--- a/fs/proc/generic.c
64152+++ b/fs/proc/generic.c
64153@@ -23,6 +23,7 @@
64154 #include <linux/bitops.h>
64155 #include <linux/spinlock.h>
64156 #include <linux/completion.h>
64157+#include <linux/grsecurity.h>
64158 #include <asm/uaccess.h>
64159
64160 #include "internal.h"
64161@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
64162 return proc_lookup_de(PDE(dir), dir, dentry);
64163 }
64164
64165+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
64166+ unsigned int flags)
64167+{
64168+ if (gr_proc_is_restricted())
64169+ return ERR_PTR(-EACCES);
64170+
64171+ return proc_lookup_de(PDE(dir), dir, dentry);
64172+}
64173+
64174 /*
64175 * This returns non-zero if at EOF, so that the /proc
64176 * root directory can use this and check if it should
64177@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
64178 return proc_readdir_de(PDE(inode), file, ctx);
64179 }
64180
64181+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
64182+{
64183+ struct inode *inode = file_inode(file);
64184+
64185+ if (gr_proc_is_restricted())
64186+ return -EACCES;
64187+
64188+ return proc_readdir_de(PDE(inode), file, ctx);
64189+}
64190+
64191 /*
64192 * These are the generic /proc directory operations. They
64193 * use the in-memory "struct proc_dir_entry" tree to parse
64194@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
64195 .iterate = proc_readdir,
64196 };
64197
64198+static const struct file_operations proc_dir_restricted_operations = {
64199+ .llseek = generic_file_llseek,
64200+ .read = generic_read_dir,
64201+ .iterate = proc_readdir_restrict,
64202+};
64203+
64204 /*
64205 * proc directories can do almost nothing..
64206 */
64207@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
64208 .setattr = proc_notify_change,
64209 };
64210
64211+static const struct inode_operations proc_dir_restricted_inode_operations = {
64212+ .lookup = proc_lookup_restrict,
64213+ .getattr = proc_getattr,
64214+ .setattr = proc_notify_change,
64215+};
64216+
64217 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
64218 {
64219 struct proc_dir_entry *tmp;
64220@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
64221 return ret;
64222
64223 if (S_ISDIR(dp->mode)) {
64224- dp->proc_fops = &proc_dir_operations;
64225- dp->proc_iops = &proc_dir_inode_operations;
64226+ if (dp->restricted) {
64227+ dp->proc_fops = &proc_dir_restricted_operations;
64228+ dp->proc_iops = &proc_dir_restricted_inode_operations;
64229+ } else {
64230+ dp->proc_fops = &proc_dir_operations;
64231+ dp->proc_iops = &proc_dir_inode_operations;
64232+ }
64233 dir->nlink++;
64234 } else if (S_ISLNK(dp->mode)) {
64235 dp->proc_iops = &proc_link_inode_operations;
64236@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
64237 }
64238 EXPORT_SYMBOL_GPL(proc_mkdir_data);
64239
64240+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
64241+ struct proc_dir_entry *parent, void *data)
64242+{
64243+ struct proc_dir_entry *ent;
64244+
64245+ if (mode == 0)
64246+ mode = S_IRUGO | S_IXUGO;
64247+
64248+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
64249+ if (ent) {
64250+ ent->data = data;
64251+ ent->restricted = 1;
64252+ if (proc_register(parent, ent) < 0) {
64253+ kfree(ent);
64254+ ent = NULL;
64255+ }
64256+ }
64257+ return ent;
64258+}
64259+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
64260+
64261 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
64262 struct proc_dir_entry *parent)
64263 {
64264@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
64265 }
64266 EXPORT_SYMBOL(proc_mkdir);
64267
64268+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
64269+ struct proc_dir_entry *parent)
64270+{
64271+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
64272+}
64273+EXPORT_SYMBOL(proc_mkdir_restrict);
64274+
64275 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
64276 struct proc_dir_entry *parent,
64277 const struct file_operations *proc_fops,
64278diff --git a/fs/proc/inode.c b/fs/proc/inode.c
64279index 124fc43..8afbb02 100644
64280--- a/fs/proc/inode.c
64281+++ b/fs/proc/inode.c
64282@@ -23,11 +23,17 @@
64283 #include <linux/slab.h>
64284 #include <linux/mount.h>
64285 #include <linux/magic.h>
64286+#include <linux/grsecurity.h>
64287
64288 #include <asm/uaccess.h>
64289
64290 #include "internal.h"
64291
64292+#ifdef CONFIG_PROC_SYSCTL
64293+extern const struct inode_operations proc_sys_inode_operations;
64294+extern const struct inode_operations proc_sys_dir_operations;
64295+#endif
64296+
64297 static void proc_evict_inode(struct inode *inode)
64298 {
64299 struct proc_dir_entry *de;
64300@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
64301 ns = PROC_I(inode)->ns.ns;
64302 if (ns_ops && ns)
64303 ns_ops->put(ns);
64304+
64305+#ifdef CONFIG_PROC_SYSCTL
64306+ if (inode->i_op == &proc_sys_inode_operations ||
64307+ inode->i_op == &proc_sys_dir_operations)
64308+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
64309+#endif
64310+
64311 }
64312
64313 static struct kmem_cache * proc_inode_cachep;
64314@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
64315 if (de->mode) {
64316 inode->i_mode = de->mode;
64317 inode->i_uid = de->uid;
64318+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64319+ inode->i_gid = grsec_proc_gid;
64320+#else
64321 inode->i_gid = de->gid;
64322+#endif
64323 }
64324 if (de->size)
64325 inode->i_size = de->size;
64326diff --git a/fs/proc/internal.h b/fs/proc/internal.h
64327index 651d09a..6a4b495 100644
64328--- a/fs/proc/internal.h
64329+++ b/fs/proc/internal.h
64330@@ -46,9 +46,10 @@ struct proc_dir_entry {
64331 struct completion *pde_unload_completion;
64332 struct list_head pde_openers; /* who did ->open, but not ->release */
64333 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
64334+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
64335 u8 namelen;
64336 char name[];
64337-};
64338+} __randomize_layout;
64339
64340 union proc_op {
64341 int (*proc_get_link)(struct dentry *, struct path *);
64342@@ -67,7 +68,7 @@ struct proc_inode {
64343 struct ctl_table *sysctl_entry;
64344 struct proc_ns ns;
64345 struct inode vfs_inode;
64346-};
64347+} __randomize_layout;
64348
64349 /*
64350 * General functions
64351@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
64352 struct pid *, struct task_struct *);
64353 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
64354 struct pid *, struct task_struct *);
64355+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64356+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
64357+#endif
64358
64359 /*
64360 * base.c
64361@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
64362 extern spinlock_t proc_subdir_lock;
64363
64364 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
64365+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
64366 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
64367 struct dentry *);
64368 extern int proc_readdir(struct file *, struct dir_context *);
64369+extern int proc_readdir_restrict(struct file *, struct dir_context *);
64370 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
64371
64372 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
64373diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
64374index a352d57..cb94a5c 100644
64375--- a/fs/proc/interrupts.c
64376+++ b/fs/proc/interrupts.c
64377@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
64378
64379 static int __init proc_interrupts_init(void)
64380 {
64381+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64382+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
64383+#else
64384 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
64385+#endif
64386 return 0;
64387 }
64388 fs_initcall(proc_interrupts_init);
64389diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
64390index 39e6ef3..2f9cb5e 100644
64391--- a/fs/proc/kcore.c
64392+++ b/fs/proc/kcore.c
64393@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64394 * the addresses in the elf_phdr on our list.
64395 */
64396 start = kc_offset_to_vaddr(*fpos - elf_buflen);
64397- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
64398+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
64399+ if (tsz > buflen)
64400 tsz = buflen;
64401-
64402+
64403 while (buflen) {
64404 struct kcore_list *m;
64405
64406@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64407 kfree(elf_buf);
64408 } else {
64409 if (kern_addr_valid(start)) {
64410- unsigned long n;
64411+ char *elf_buf;
64412+ mm_segment_t oldfs;
64413
64414- n = copy_to_user(buffer, (char *)start, tsz);
64415- /*
64416- * We cannot distinguish between fault on source
64417- * and fault on destination. When this happens
64418- * we clear too and hope it will trigger the
64419- * EFAULT again.
64420- */
64421- if (n) {
64422- if (clear_user(buffer + tsz - n,
64423- n))
64424+ elf_buf = kmalloc(tsz, GFP_KERNEL);
64425+ if (!elf_buf)
64426+ return -ENOMEM;
64427+ oldfs = get_fs();
64428+ set_fs(KERNEL_DS);
64429+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
64430+ set_fs(oldfs);
64431+ if (copy_to_user(buffer, elf_buf, tsz)) {
64432+ kfree(elf_buf);
64433 return -EFAULT;
64434+ }
64435 }
64436+ set_fs(oldfs);
64437+ kfree(elf_buf);
64438 } else {
64439 if (clear_user(buffer, tsz))
64440 return -EFAULT;
64441@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64442
64443 static int open_kcore(struct inode *inode, struct file *filp)
64444 {
64445+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64446+ return -EPERM;
64447+#endif
64448 if (!capable(CAP_SYS_RAWIO))
64449 return -EPERM;
64450 if (kcore_need_update)
64451diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64452index 136e548..1f88922 100644
64453--- a/fs/proc/meminfo.c
64454+++ b/fs/proc/meminfo.c
64455@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64456 vmi.used >> 10,
64457 vmi.largest_chunk >> 10
64458 #ifdef CONFIG_MEMORY_FAILURE
64459- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64460+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64461 #endif
64462 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64463 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64464diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64465index d4a3574..b421ce9 100644
64466--- a/fs/proc/nommu.c
64467+++ b/fs/proc/nommu.c
64468@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64469
64470 if (file) {
64471 seq_pad(m, ' ');
64472- seq_path(m, &file->f_path, "");
64473+ seq_path(m, &file->f_path, "\n\\");
64474 }
64475
64476 seq_putc(m, '\n');
64477diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64478index 4677bb7..94067cd 100644
64479--- a/fs/proc/proc_net.c
64480+++ b/fs/proc/proc_net.c
64481@@ -23,6 +23,7 @@
64482 #include <linux/nsproxy.h>
64483 #include <net/net_namespace.h>
64484 #include <linux/seq_file.h>
64485+#include <linux/grsecurity.h>
64486
64487 #include "internal.h"
64488
64489@@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
64490 return maybe_get_net(PDE_NET(PDE(inode)));
64491 }
64492
64493+extern const struct seq_operations dev_seq_ops;
64494+
64495 int seq_open_net(struct inode *ino, struct file *f,
64496 const struct seq_operations *ops, int size)
64497 {
64498@@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
64499
64500 BUG_ON(size < sizeof(*p));
64501
64502+ /* only permit access to /proc/net/dev */
64503+ if (ops != &dev_seq_ops && gr_proc_is_restricted())
64504+ return -EACCES;
64505+
64506 net = get_proc_net(ino);
64507 if (net == NULL)
64508 return -ENXIO;
64509@@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
64510 int err;
64511 struct net *net;
64512
64513+ if (gr_proc_is_restricted())
64514+ return -EACCES;
64515+
64516 err = -ENXIO;
64517 net = get_proc_net(inode);
64518 if (net == NULL)
64519diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64520index 7129046..6914844 100644
64521--- a/fs/proc/proc_sysctl.c
64522+++ b/fs/proc/proc_sysctl.c
64523@@ -11,13 +11,21 @@
64524 #include <linux/namei.h>
64525 #include <linux/mm.h>
64526 #include <linux/module.h>
64527+#include <linux/nsproxy.h>
64528+#ifdef CONFIG_GRKERNSEC
64529+#include <net/net_namespace.h>
64530+#endif
64531 #include "internal.h"
64532
64533+extern int gr_handle_chroot_sysctl(const int op);
64534+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64535+ const int op);
64536+
64537 static const struct dentry_operations proc_sys_dentry_operations;
64538 static const struct file_operations proc_sys_file_operations;
64539-static const struct inode_operations proc_sys_inode_operations;
64540+const struct inode_operations proc_sys_inode_operations;
64541 static const struct file_operations proc_sys_dir_file_operations;
64542-static const struct inode_operations proc_sys_dir_operations;
64543+const struct inode_operations proc_sys_dir_operations;
64544
64545 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64546 {
64547@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64548
64549 err = NULL;
64550 d_set_d_op(dentry, &proc_sys_dentry_operations);
64551+
64552+ gr_handle_proc_create(dentry, inode);
64553+
64554 d_add(dentry, inode);
64555
64556 out:
64557@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64558 struct inode *inode = file_inode(filp);
64559 struct ctl_table_header *head = grab_header(inode);
64560 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64561+ int op = write ? MAY_WRITE : MAY_READ;
64562 ssize_t error;
64563 size_t res;
64564
64565@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64566 * and won't be until we finish.
64567 */
64568 error = -EPERM;
64569- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64570+ if (sysctl_perm(head, table, op))
64571 goto out;
64572
64573 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64574@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64575 if (!table->proc_handler)
64576 goto out;
64577
64578+#ifdef CONFIG_GRKERNSEC
64579+ error = -EPERM;
64580+ if (gr_handle_chroot_sysctl(op))
64581+ goto out;
64582+ dget(filp->f_path.dentry);
64583+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64584+ dput(filp->f_path.dentry);
64585+ goto out;
64586+ }
64587+ dput(filp->f_path.dentry);
64588+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64589+ goto out;
64590+ if (write) {
64591+ if (current->nsproxy->net_ns != table->extra2) {
64592+ if (!capable(CAP_SYS_ADMIN))
64593+ goto out;
64594+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64595+ goto out;
64596+ }
64597+#endif
64598+
64599 /* careful: calling conventions are nasty here */
64600 res = count;
64601 error = table->proc_handler(table, write, buf, &res, ppos);
64602@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64603 return false;
64604 } else {
64605 d_set_d_op(child, &proc_sys_dentry_operations);
64606+
64607+ gr_handle_proc_create(child, inode);
64608+
64609 d_add(child, inode);
64610 }
64611 } else {
64612@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64613 if ((*pos)++ < ctx->pos)
64614 return true;
64615
64616+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64617+ return 0;
64618+
64619 if (unlikely(S_ISLNK(table->mode)))
64620 res = proc_sys_link_fill_cache(file, ctx, head, table);
64621 else
64622@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64623 if (IS_ERR(head))
64624 return PTR_ERR(head);
64625
64626+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64627+ return -ENOENT;
64628+
64629 generic_fillattr(inode, stat);
64630 if (table)
64631 stat->mode = (stat->mode & S_IFMT) | table->mode;
64632@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64633 .llseek = generic_file_llseek,
64634 };
64635
64636-static const struct inode_operations proc_sys_inode_operations = {
64637+const struct inode_operations proc_sys_inode_operations = {
64638 .permission = proc_sys_permission,
64639 .setattr = proc_sys_setattr,
64640 .getattr = proc_sys_getattr,
64641 };
64642
64643-static const struct inode_operations proc_sys_dir_operations = {
64644+const struct inode_operations proc_sys_dir_operations = {
64645 .lookup = proc_sys_lookup,
64646 .permission = proc_sys_permission,
64647 .setattr = proc_sys_setattr,
64648@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64649 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64650 const char *name, int namelen)
64651 {
64652- struct ctl_table *table;
64653+ ctl_table_no_const *table;
64654 struct ctl_dir *new;
64655 struct ctl_node *node;
64656 char *new_name;
64657@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64658 return NULL;
64659
64660 node = (struct ctl_node *)(new + 1);
64661- table = (struct ctl_table *)(node + 1);
64662+ table = (ctl_table_no_const *)(node + 1);
64663 new_name = (char *)(table + 2);
64664 memcpy(new_name, name, namelen);
64665 new_name[namelen] = '\0';
64666@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64667 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64668 struct ctl_table_root *link_root)
64669 {
64670- struct ctl_table *link_table, *entry, *link;
64671+ ctl_table_no_const *link_table, *link;
64672+ struct ctl_table *entry;
64673 struct ctl_table_header *links;
64674 struct ctl_node *node;
64675 char *link_name;
64676@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64677 return NULL;
64678
64679 node = (struct ctl_node *)(links + 1);
64680- link_table = (struct ctl_table *)(node + nr_entries);
64681+ link_table = (ctl_table_no_const *)(node + nr_entries);
64682 link_name = (char *)&link_table[nr_entries + 1];
64683
64684 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64685@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64686 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64687 struct ctl_table *table)
64688 {
64689- struct ctl_table *ctl_table_arg = NULL;
64690- struct ctl_table *entry, *files;
64691+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64692+ struct ctl_table *entry;
64693 int nr_files = 0;
64694 int nr_dirs = 0;
64695 int err = -ENOMEM;
64696@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64697 nr_files++;
64698 }
64699
64700- files = table;
64701 /* If there are mixed files and directories we need a new table */
64702 if (nr_dirs && nr_files) {
64703- struct ctl_table *new;
64704+ ctl_table_no_const *new;
64705 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64706 GFP_KERNEL);
64707 if (!files)
64708@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64709 /* Register everything except a directory full of subdirectories */
64710 if (nr_files || !nr_dirs) {
64711 struct ctl_table_header *header;
64712- header = __register_sysctl_table(set, path, files);
64713+ header = __register_sysctl_table(set, path, files ? files : table);
64714 if (!header) {
64715 kfree(ctl_table_arg);
64716 goto out;
64717diff --git a/fs/proc/root.c b/fs/proc/root.c
64718index 87dbcbe..55e1b4d 100644
64719--- a/fs/proc/root.c
64720+++ b/fs/proc/root.c
64721@@ -186,7 +186,15 @@ void __init proc_root_init(void)
64722 #ifdef CONFIG_PROC_DEVICETREE
64723 proc_device_tree_init();
64724 #endif
64725+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64726+#ifdef CONFIG_GRKERNSEC_PROC_USER
64727+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64728+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64729+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64730+#endif
64731+#else
64732 proc_mkdir("bus", NULL);
64733+#endif
64734 proc_sys_init();
64735 }
64736
64737diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64738index 6f599c6..bd00271 100644
64739--- a/fs/proc/stat.c
64740+++ b/fs/proc/stat.c
64741@@ -11,6 +11,7 @@
64742 #include <linux/irqnr.h>
64743 #include <asm/cputime.h>
64744 #include <linux/tick.h>
64745+#include <linux/grsecurity.h>
64746
64747 #ifndef arch_irq_stat_cpu
64748 #define arch_irq_stat_cpu(cpu) 0
64749@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64750 u64 sum_softirq = 0;
64751 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64752 struct timespec boottime;
64753+ int unrestricted = 1;
64754+
64755+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64756+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64757+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64758+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64759+ && !in_group_p(grsec_proc_gid)
64760+#endif
64761+ )
64762+ unrestricted = 0;
64763+#endif
64764+#endif
64765
64766 user = nice = system = idle = iowait =
64767 irq = softirq = steal = 0;
64768@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64769 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64770 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64771 idle += get_idle_time(i);
64772- iowait += get_iowait_time(i);
64773- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64774- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64775- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64776- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64777- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64778- sum += kstat_cpu_irqs_sum(i);
64779- sum += arch_irq_stat_cpu(i);
64780+ if (unrestricted) {
64781+ iowait += get_iowait_time(i);
64782+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64783+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64784+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64785+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64786+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64787+ sum += kstat_cpu_irqs_sum(i);
64788+ sum += arch_irq_stat_cpu(i);
64789+ for (j = 0; j < NR_SOFTIRQS; j++) {
64790+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64791
64792- for (j = 0; j < NR_SOFTIRQS; j++) {
64793- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64794-
64795- per_softirq_sums[j] += softirq_stat;
64796- sum_softirq += softirq_stat;
64797+ per_softirq_sums[j] += softirq_stat;
64798+ sum_softirq += softirq_stat;
64799+ }
64800 }
64801 }
64802- sum += arch_irq_stat();
64803+ if (unrestricted)
64804+ sum += arch_irq_stat();
64805
64806 seq_puts(p, "cpu ");
64807 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64808@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64809 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64810 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64811 idle = get_idle_time(i);
64812- iowait = get_iowait_time(i);
64813- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64814- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64815- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64816- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64817- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64818+ if (unrestricted) {
64819+ iowait = get_iowait_time(i);
64820+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64821+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64822+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64823+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64824+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64825+ }
64826 seq_printf(p, "cpu%d", i);
64827 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64828 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64829@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64830
64831 /* sum again ? it could be updated? */
64832 for_each_irq_nr(j)
64833- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64834+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64835
64836 seq_printf(p,
64837 "\nctxt %llu\n"
64838@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64839 "processes %lu\n"
64840 "procs_running %lu\n"
64841 "procs_blocked %lu\n",
64842- nr_context_switches(),
64843+ unrestricted ? nr_context_switches() : 0ULL,
64844 (unsigned long)jif,
64845- total_forks,
64846- nr_running(),
64847- nr_iowait());
64848+ unrestricted ? total_forks : 0UL,
64849+ unrestricted ? nr_running() : 0UL,
64850+ unrestricted ? nr_iowait() : 0UL);
64851
64852 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64853
64854diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64855index 8f78819..ba6c272 100644
64856--- a/fs/proc/task_mmu.c
64857+++ b/fs/proc/task_mmu.c
64858@@ -12,12 +12,19 @@
64859 #include <linux/swap.h>
64860 #include <linux/swapops.h>
64861 #include <linux/mmu_notifier.h>
64862+#include <linux/grsecurity.h>
64863
64864 #include <asm/elf.h>
64865 #include <asm/uaccess.h>
64866 #include <asm/tlbflush.h>
64867 #include "internal.h"
64868
64869+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64870+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64871+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
64872+ _mm->pax_flags & MF_PAX_SEGMEXEC))
64873+#endif
64874+
64875 void task_mem(struct seq_file *m, struct mm_struct *mm)
64876 {
64877 unsigned long data, text, lib, swap;
64878@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64879 "VmExe:\t%8lu kB\n"
64880 "VmLib:\t%8lu kB\n"
64881 "VmPTE:\t%8lu kB\n"
64882- "VmSwap:\t%8lu kB\n",
64883- hiwater_vm << (PAGE_SHIFT-10),
64884+ "VmSwap:\t%8lu kB\n"
64885+
64886+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64887+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64888+#endif
64889+
64890+ ,hiwater_vm << (PAGE_SHIFT-10),
64891 total_vm << (PAGE_SHIFT-10),
64892 mm->locked_vm << (PAGE_SHIFT-10),
64893 mm->pinned_vm << (PAGE_SHIFT-10),
64894@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64895 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64896 (PTRS_PER_PTE * sizeof(pte_t) *
64897 atomic_long_read(&mm->nr_ptes)) >> 10,
64898- swap << (PAGE_SHIFT-10));
64899+ swap << (PAGE_SHIFT-10)
64900+
64901+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64902+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64903+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64904+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64905+#else
64906+ , mm->context.user_cs_base
64907+ , mm->context.user_cs_limit
64908+#endif
64909+#endif
64910+
64911+ );
64912 }
64913
64914 unsigned long task_vsize(struct mm_struct *mm)
64915@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64916 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64917 }
64918
64919- /* We don't show the stack guard page in /proc/maps */
64920+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64921+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64922+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64923+#else
64924 start = vma->vm_start;
64925- if (stack_guard_page_start(vma, start))
64926- start += PAGE_SIZE;
64927 end = vma->vm_end;
64928- if (stack_guard_page_end(vma, end))
64929- end -= PAGE_SIZE;
64930+#endif
64931
64932 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64933 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64934@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64935 flags & VM_WRITE ? 'w' : '-',
64936 flags & VM_EXEC ? 'x' : '-',
64937 flags & VM_MAYSHARE ? 's' : 'p',
64938+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64939+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64940+#else
64941 pgoff,
64942+#endif
64943 MAJOR(dev), MINOR(dev), ino);
64944
64945 /*
64946@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64947 */
64948 if (file) {
64949 seq_pad(m, ' ');
64950- seq_path(m, &file->f_path, "\n");
64951+ seq_path(m, &file->f_path, "\n\\");
64952 goto done;
64953 }
64954
64955@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64956 * Thread stack in /proc/PID/task/TID/maps or
64957 * the main process stack.
64958 */
64959- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64960- vma->vm_end >= mm->start_stack)) {
64961+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64962+ (vma->vm_start <= mm->start_stack &&
64963+ vma->vm_end >= mm->start_stack)) {
64964 name = "[stack]";
64965 } else {
64966 /* Thread stack in /proc/PID/maps */
64967@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64968 struct proc_maps_private *priv = m->private;
64969 struct task_struct *task = priv->task;
64970
64971+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64972+ if (current->exec_id != m->exec_id) {
64973+ gr_log_badprocpid("maps");
64974+ return 0;
64975+ }
64976+#endif
64977+
64978 show_map_vma(m, vma, is_pid);
64979
64980 if (m->count < m->size) /* vma is copied successfully */
64981@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64982 .private = &mss,
64983 };
64984
64985+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64986+ if (current->exec_id != m->exec_id) {
64987+ gr_log_badprocpid("smaps");
64988+ return 0;
64989+ }
64990+#endif
64991 memset(&mss, 0, sizeof mss);
64992- mss.vma = vma;
64993- /* mmap_sem is held in m_start */
64994- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64995- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64996-
64997+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64998+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64999+#endif
65000+ mss.vma = vma;
65001+ /* mmap_sem is held in m_start */
65002+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
65003+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
65004+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65005+ }
65006+#endif
65007 show_map_vma(m, vma, is_pid);
65008
65009 seq_printf(m,
65010@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
65011 "KernelPageSize: %8lu kB\n"
65012 "MMUPageSize: %8lu kB\n"
65013 "Locked: %8lu kB\n",
65014+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65015+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
65016+#else
65017 (vma->vm_end - vma->vm_start) >> 10,
65018+#endif
65019 mss.resident >> 10,
65020 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
65021 mss.shared_clean >> 10,
65022@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
65023 char buffer[64];
65024 int nid;
65025
65026+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65027+ if (current->exec_id != m->exec_id) {
65028+ gr_log_badprocpid("numa_maps");
65029+ return 0;
65030+ }
65031+#endif
65032+
65033 if (!mm)
65034 return 0;
65035
65036@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
65037 mpol_to_str(buffer, sizeof(buffer), pol);
65038 mpol_cond_put(pol);
65039
65040+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65041+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
65042+#else
65043 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
65044+#endif
65045
65046 if (file) {
65047 seq_printf(m, " file=");
65048- seq_path(m, &file->f_path, "\n\t= ");
65049+ seq_path(m, &file->f_path, "\n\t\\= ");
65050 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
65051 seq_printf(m, " heap");
65052 } else {
65053diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
65054index 678455d..ebd3245 100644
65055--- a/fs/proc/task_nommu.c
65056+++ b/fs/proc/task_nommu.c
65057@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
65058 else
65059 bytes += kobjsize(mm);
65060
65061- if (current->fs && current->fs->users > 1)
65062+ if (current->fs && atomic_read(&current->fs->users) > 1)
65063 sbytes += kobjsize(current->fs);
65064 else
65065 bytes += kobjsize(current->fs);
65066@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
65067
65068 if (file) {
65069 seq_pad(m, ' ');
65070- seq_path(m, &file->f_path, "");
65071+ seq_path(m, &file->f_path, "\n\\");
65072 } else if (mm) {
65073 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
65074
65075diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
65076index 88d4585..c10bfeb 100644
65077--- a/fs/proc/vmcore.c
65078+++ b/fs/proc/vmcore.c
65079@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
65080 nr_bytes = count;
65081
65082 /* If pfn is not ram, return zeros for sparse dump files */
65083- if (pfn_is_ram(pfn) == 0)
65084- memset(buf, 0, nr_bytes);
65085- else {
65086+ if (pfn_is_ram(pfn) == 0) {
65087+ if (userbuf) {
65088+ if (clear_user((char __force_user *)buf, nr_bytes))
65089+ return -EFAULT;
65090+ } else
65091+ memset(buf, 0, nr_bytes);
65092+ } else {
65093 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
65094 offset, userbuf);
65095 if (tmp < 0)
65096@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
65097 static int copy_to(void *target, void *src, size_t size, int userbuf)
65098 {
65099 if (userbuf) {
65100- if (copy_to_user((char __user *) target, src, size))
65101+ if (copy_to_user((char __force_user *) target, src, size))
65102 return -EFAULT;
65103 } else {
65104 memcpy(target, src, size);
65105@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65106 if (*fpos < m->offset + m->size) {
65107 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
65108 start = m->paddr + *fpos - m->offset;
65109- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
65110+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
65111 if (tmp < 0)
65112 return tmp;
65113 buflen -= tsz;
65114@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65115 static ssize_t read_vmcore(struct file *file, char __user *buffer,
65116 size_t buflen, loff_t *fpos)
65117 {
65118- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
65119+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
65120 }
65121
65122 /*
65123diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
65124index b00fcc9..e0c6381 100644
65125--- a/fs/qnx6/qnx6.h
65126+++ b/fs/qnx6/qnx6.h
65127@@ -74,7 +74,7 @@ enum {
65128 BYTESEX_BE,
65129 };
65130
65131-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65132+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65133 {
65134 if (sbi->s_bytesex == BYTESEX_LE)
65135 return le64_to_cpu((__force __le64)n);
65136@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
65137 return (__force __fs64)cpu_to_be64(n);
65138 }
65139
65140-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65141+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65142 {
65143 if (sbi->s_bytesex == BYTESEX_LE)
65144 return le32_to_cpu((__force __le32)n);
65145diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
65146index 72d2917..c917c12 100644
65147--- a/fs/quota/netlink.c
65148+++ b/fs/quota/netlink.c
65149@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
65150 void quota_send_warning(struct kqid qid, dev_t dev,
65151 const char warntype)
65152 {
65153- static atomic_t seq;
65154+ static atomic_unchecked_t seq;
65155 struct sk_buff *skb;
65156 void *msg_head;
65157 int ret;
65158@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
65159 "VFS: Not enough memory to send quota warning.\n");
65160 return;
65161 }
65162- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
65163+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
65164 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
65165 if (!msg_head) {
65166 printk(KERN_ERR
65167diff --git a/fs/read_write.c b/fs/read_write.c
65168index 28cc9c8..208e4fb 100644
65169--- a/fs/read_write.c
65170+++ b/fs/read_write.c
65171@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
65172
65173 old_fs = get_fs();
65174 set_fs(get_ds());
65175- p = (__force const char __user *)buf;
65176+ p = (const char __force_user *)buf;
65177 if (count > MAX_RW_COUNT)
65178 count = MAX_RW_COUNT;
65179 if (file->f_op->write)
65180diff --git a/fs/readdir.c b/fs/readdir.c
65181index 5b53d99..a6c3049 100644
65182--- a/fs/readdir.c
65183+++ b/fs/readdir.c
65184@@ -17,6 +17,7 @@
65185 #include <linux/security.h>
65186 #include <linux/syscalls.h>
65187 #include <linux/unistd.h>
65188+#include <linux/namei.h>
65189
65190 #include <asm/uaccess.h>
65191
65192@@ -69,6 +70,7 @@ struct old_linux_dirent {
65193 struct readdir_callback {
65194 struct dir_context ctx;
65195 struct old_linux_dirent __user * dirent;
65196+ struct file * file;
65197 int result;
65198 };
65199
65200@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
65201 buf->result = -EOVERFLOW;
65202 return -EOVERFLOW;
65203 }
65204+
65205+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65206+ return 0;
65207+
65208 buf->result++;
65209 dirent = buf->dirent;
65210 if (!access_ok(VERIFY_WRITE, dirent,
65211@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
65212 if (!f.file)
65213 return -EBADF;
65214
65215+ buf.file = f.file;
65216 error = iterate_dir(f.file, &buf.ctx);
65217 if (buf.result)
65218 error = buf.result;
65219@@ -142,6 +149,7 @@ struct getdents_callback {
65220 struct dir_context ctx;
65221 struct linux_dirent __user * current_dir;
65222 struct linux_dirent __user * previous;
65223+ struct file * file;
65224 int count;
65225 int error;
65226 };
65227@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
65228 buf->error = -EOVERFLOW;
65229 return -EOVERFLOW;
65230 }
65231+
65232+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65233+ return 0;
65234+
65235 dirent = buf->previous;
65236 if (dirent) {
65237 if (__put_user(offset, &dirent->d_off))
65238@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
65239 if (!f.file)
65240 return -EBADF;
65241
65242+ buf.file = f.file;
65243 error = iterate_dir(f.file, &buf.ctx);
65244 if (error >= 0)
65245 error = buf.error;
65246@@ -226,6 +239,7 @@ struct getdents_callback64 {
65247 struct dir_context ctx;
65248 struct linux_dirent64 __user * current_dir;
65249 struct linux_dirent64 __user * previous;
65250+ struct file *file;
65251 int count;
65252 int error;
65253 };
65254@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
65255 buf->error = -EINVAL; /* only used if we fail.. */
65256 if (reclen > buf->count)
65257 return -EINVAL;
65258+
65259+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65260+ return 0;
65261+
65262 dirent = buf->previous;
65263 if (dirent) {
65264 if (__put_user(offset, &dirent->d_off))
65265@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
65266 if (!f.file)
65267 return -EBADF;
65268
65269+ buf.file = f.file;
65270 error = iterate_dir(f.file, &buf.ctx);
65271 if (error >= 0)
65272 error = buf.error;
65273diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
65274index 9a3c68c..767933e 100644
65275--- a/fs/reiserfs/do_balan.c
65276+++ b/fs/reiserfs/do_balan.c
65277@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
65278 return;
65279 }
65280
65281- atomic_inc(&(fs_generation(tb->tb_sb)));
65282+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
65283 do_balance_starts(tb);
65284
65285 /* balance leaf returns 0 except if combining L R and S into
65286diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
65287index ee382ef..f4eb6eb5 100644
65288--- a/fs/reiserfs/item_ops.c
65289+++ b/fs/reiserfs/item_ops.c
65290@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
65291 }
65292
65293 static struct item_operations errcatch_ops = {
65294- errcatch_bytes_number,
65295- errcatch_decrement_key,
65296- errcatch_is_left_mergeable,
65297- errcatch_print_item,
65298- errcatch_check_item,
65299+ .bytes_number = errcatch_bytes_number,
65300+ .decrement_key = errcatch_decrement_key,
65301+ .is_left_mergeable = errcatch_is_left_mergeable,
65302+ .print_item = errcatch_print_item,
65303+ .check_item = errcatch_check_item,
65304
65305- errcatch_create_vi,
65306- errcatch_check_left,
65307- errcatch_check_right,
65308- errcatch_part_size,
65309- errcatch_unit_num,
65310- errcatch_print_vi
65311+ .create_vi = errcatch_create_vi,
65312+ .check_left = errcatch_check_left,
65313+ .check_right = errcatch_check_right,
65314+ .part_size = errcatch_part_size,
65315+ .unit_num = errcatch_unit_num,
65316+ .print_vi = errcatch_print_vi
65317 };
65318
65319 //////////////////////////////////////////////////////////////////////////////
65320diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
65321index 02b0b7d..c85018b 100644
65322--- a/fs/reiserfs/procfs.c
65323+++ b/fs/reiserfs/procfs.c
65324@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
65325 "SMALL_TAILS " : "NO_TAILS ",
65326 replay_only(sb) ? "REPLAY_ONLY " : "",
65327 convert_reiserfs(sb) ? "CONV " : "",
65328- atomic_read(&r->s_generation_counter),
65329+ atomic_read_unchecked(&r->s_generation_counter),
65330 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
65331 SF(s_do_balance), SF(s_unneeded_left_neighbor),
65332 SF(s_good_search_by_key_reada), SF(s_bmaps),
65333diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
65334index 8d06adf..7e1c9f8 100644
65335--- a/fs/reiserfs/reiserfs.h
65336+++ b/fs/reiserfs/reiserfs.h
65337@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
65338 /* Comment? -Hans */
65339 wait_queue_head_t s_wait;
65340 /* To be obsoleted soon by per buffer seals.. -Hans */
65341- atomic_t s_generation_counter; // increased by one every time the
65342+ atomic_unchecked_t s_generation_counter; // increased by one every time the
65343 // tree gets re-balanced
65344 unsigned long s_properties; /* File system properties. Currently holds
65345 on-disk FS format */
65346@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
65347 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
65348
65349 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
65350-#define get_generation(s) atomic_read (&fs_generation(s))
65351+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
65352 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
65353 #define __fs_changed(gen,s) (gen != get_generation (s))
65354 #define fs_changed(gen,s) \
65355diff --git a/fs/select.c b/fs/select.c
65356index 467bb1c..cf9d65a 100644
65357--- a/fs/select.c
65358+++ b/fs/select.c
65359@@ -20,6 +20,7 @@
65360 #include <linux/export.h>
65361 #include <linux/slab.h>
65362 #include <linux/poll.h>
65363+#include <linux/security.h>
65364 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
65365 #include <linux/file.h>
65366 #include <linux/fdtable.h>
65367@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
65368 struct poll_list *walk = head;
65369 unsigned long todo = nfds;
65370
65371+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
65372 if (nfds > rlimit(RLIMIT_NOFILE))
65373 return -EINVAL;
65374
65375diff --git a/fs/seq_file.c b/fs/seq_file.c
65376index 1d641bb..c2f4743 100644
65377--- a/fs/seq_file.c
65378+++ b/fs/seq_file.c
65379@@ -10,6 +10,8 @@
65380 #include <linux/seq_file.h>
65381 #include <linux/slab.h>
65382 #include <linux/cred.h>
65383+#include <linux/sched.h>
65384+#include <linux/grsecurity.h>
65385
65386 #include <asm/uaccess.h>
65387 #include <asm/page.h>
65388@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
65389 #ifdef CONFIG_USER_NS
65390 p->user_ns = file->f_cred->user_ns;
65391 #endif
65392+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65393+ p->exec_id = current->exec_id;
65394+#endif
65395
65396 /*
65397 * Wrappers around seq_open(e.g. swaps_open) need to be
65398@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
65399 }
65400 EXPORT_SYMBOL(seq_open);
65401
65402+
65403+int seq_open_restrict(struct file *file, const struct seq_operations *op)
65404+{
65405+ if (gr_proc_is_restricted())
65406+ return -EACCES;
65407+
65408+ return seq_open(file, op);
65409+}
65410+EXPORT_SYMBOL(seq_open_restrict);
65411+
65412 static int traverse(struct seq_file *m, loff_t offset)
65413 {
65414 loff_t pos = 0, index;
65415@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
65416 return 0;
65417 }
65418 if (!m->buf) {
65419- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65420+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65421 if (!m->buf)
65422 return -ENOMEM;
65423 }
65424@@ -137,7 +152,7 @@ Eoverflow:
65425 m->op->stop(m, p);
65426 kfree(m->buf);
65427 m->count = 0;
65428- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65429+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65430 return !m->buf ? -ENOMEM : -EAGAIN;
65431 }
65432
65433@@ -153,7 +168,7 @@ Eoverflow:
65434 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65435 {
65436 struct seq_file *m = file->private_data;
65437- size_t copied = 0;
65438+ ssize_t copied = 0;
65439 loff_t pos;
65440 size_t n;
65441 void *p;
65442@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65443
65444 /* grab buffer if we didn't have one */
65445 if (!m->buf) {
65446- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65447+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65448 if (!m->buf)
65449 goto Enomem;
65450 }
65451@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65452 m->op->stop(m, p);
65453 kfree(m->buf);
65454 m->count = 0;
65455- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65456+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65457 if (!m->buf)
65458 goto Enomem;
65459 m->version = 0;
65460@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65461 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65462 void *data)
65463 {
65464- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65465+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65466 int res = -ENOMEM;
65467
65468 if (op) {
65469@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65470 }
65471 EXPORT_SYMBOL(single_open_size);
65472
65473+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65474+ void *data)
65475+{
65476+ if (gr_proc_is_restricted())
65477+ return -EACCES;
65478+
65479+ return single_open(file, show, data);
65480+}
65481+EXPORT_SYMBOL(single_open_restrict);
65482+
65483+
65484 int single_release(struct inode *inode, struct file *file)
65485 {
65486 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65487diff --git a/fs/splice.c b/fs/splice.c
65488index 12028fa..a6f2619 100644
65489--- a/fs/splice.c
65490+++ b/fs/splice.c
65491@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65492 pipe_lock(pipe);
65493
65494 for (;;) {
65495- if (!pipe->readers) {
65496+ if (!atomic_read(&pipe->readers)) {
65497 send_sig(SIGPIPE, current, 0);
65498 if (!ret)
65499 ret = -EPIPE;
65500@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65501 page_nr++;
65502 ret += buf->len;
65503
65504- if (pipe->files)
65505+ if (atomic_read(&pipe->files))
65506 do_wakeup = 1;
65507
65508 if (!--spd->nr_pages)
65509@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65510 do_wakeup = 0;
65511 }
65512
65513- pipe->waiting_writers++;
65514+ atomic_inc(&pipe->waiting_writers);
65515 pipe_wait(pipe);
65516- pipe->waiting_writers--;
65517+ atomic_dec(&pipe->waiting_writers);
65518 }
65519
65520 pipe_unlock(pipe);
65521@@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65522 old_fs = get_fs();
65523 set_fs(get_ds());
65524 /* The cast to a user pointer is valid due to the set_fs() */
65525- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65526+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65527 set_fs(old_fs);
65528
65529 return res;
65530@@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65531 old_fs = get_fs();
65532 set_fs(get_ds());
65533 /* The cast to a user pointer is valid due to the set_fs() */
65534- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65535+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65536 set_fs(old_fs);
65537
65538 return res;
65539@@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65540 goto err;
65541
65542 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65543- vec[i].iov_base = (void __user *) page_address(page);
65544+ vec[i].iov_base = (void __force_user *) page_address(page);
65545 vec[i].iov_len = this_len;
65546 spd.pages[i] = page;
65547 spd.nr_pages++;
65548@@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65549 ops->release(pipe, buf);
65550 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65551 pipe->nrbufs--;
65552- if (pipe->files)
65553+ if (atomic_read(&pipe->files))
65554 sd->need_wakeup = true;
65555 }
65556
65557@@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65558 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65559 {
65560 while (!pipe->nrbufs) {
65561- if (!pipe->writers)
65562+ if (!atomic_read(&pipe->writers))
65563 return 0;
65564
65565- if (!pipe->waiting_writers && sd->num_spliced)
65566+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65567 return 0;
65568
65569 if (sd->flags & SPLICE_F_NONBLOCK)
65570@@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65571 * out of the pipe right after the splice_to_pipe(). So set
65572 * PIPE_READERS appropriately.
65573 */
65574- pipe->readers = 1;
65575+ atomic_set(&pipe->readers, 1);
65576
65577 current->splice_pipe = pipe;
65578 }
65579@@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65580
65581 partial[buffers].offset = off;
65582 partial[buffers].len = plen;
65583+ partial[buffers].private = 0;
65584
65585 off = 0;
65586 len -= plen;
65587@@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65588 ret = -ERESTARTSYS;
65589 break;
65590 }
65591- if (!pipe->writers)
65592+ if (!atomic_read(&pipe->writers))
65593 break;
65594- if (!pipe->waiting_writers) {
65595+ if (!atomic_read(&pipe->waiting_writers)) {
65596 if (flags & SPLICE_F_NONBLOCK) {
65597 ret = -EAGAIN;
65598 break;
65599@@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65600 pipe_lock(pipe);
65601
65602 while (pipe->nrbufs >= pipe->buffers) {
65603- if (!pipe->readers) {
65604+ if (!atomic_read(&pipe->readers)) {
65605 send_sig(SIGPIPE, current, 0);
65606 ret = -EPIPE;
65607 break;
65608@@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65609 ret = -ERESTARTSYS;
65610 break;
65611 }
65612- pipe->waiting_writers++;
65613+ atomic_inc(&pipe->waiting_writers);
65614 pipe_wait(pipe);
65615- pipe->waiting_writers--;
65616+ atomic_dec(&pipe->waiting_writers);
65617 }
65618
65619 pipe_unlock(pipe);
65620@@ -1880,14 +1881,14 @@ retry:
65621 pipe_double_lock(ipipe, opipe);
65622
65623 do {
65624- if (!opipe->readers) {
65625+ if (!atomic_read(&opipe->readers)) {
65626 send_sig(SIGPIPE, current, 0);
65627 if (!ret)
65628 ret = -EPIPE;
65629 break;
65630 }
65631
65632- if (!ipipe->nrbufs && !ipipe->writers)
65633+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65634 break;
65635
65636 /*
65637@@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65638 pipe_double_lock(ipipe, opipe);
65639
65640 do {
65641- if (!opipe->readers) {
65642+ if (!atomic_read(&opipe->readers)) {
65643 send_sig(SIGPIPE, current, 0);
65644 if (!ret)
65645 ret = -EPIPE;
65646@@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65647 * return EAGAIN if we have the potential of some data in the
65648 * future, otherwise just return 0
65649 */
65650- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65651+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65652 ret = -EAGAIN;
65653
65654 pipe_unlock(ipipe);
65655diff --git a/fs/stat.c b/fs/stat.c
65656index ae0c3ce..9ee641c 100644
65657--- a/fs/stat.c
65658+++ b/fs/stat.c
65659@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65660 stat->gid = inode->i_gid;
65661 stat->rdev = inode->i_rdev;
65662 stat->size = i_size_read(inode);
65663- stat->atime = inode->i_atime;
65664- stat->mtime = inode->i_mtime;
65665+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65666+ stat->atime = inode->i_ctime;
65667+ stat->mtime = inode->i_ctime;
65668+ } else {
65669+ stat->atime = inode->i_atime;
65670+ stat->mtime = inode->i_mtime;
65671+ }
65672 stat->ctime = inode->i_ctime;
65673 stat->blksize = (1 << inode->i_blkbits);
65674 stat->blocks = inode->i_blocks;
65675@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65676 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65677 {
65678 struct inode *inode = path->dentry->d_inode;
65679+ int retval;
65680
65681- if (inode->i_op->getattr)
65682- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65683+ if (inode->i_op->getattr) {
65684+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65685+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65686+ stat->atime = stat->ctime;
65687+ stat->mtime = stat->ctime;
65688+ }
65689+ return retval;
65690+ }
65691
65692 generic_fillattr(inode, stat);
65693 return 0;
65694diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65695index ee0d761..b346c58 100644
65696--- a/fs/sysfs/dir.c
65697+++ b/fs/sysfs/dir.c
65698@@ -62,9 +62,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65699 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65700 {
65701 struct kernfs_node *parent, *kn;
65702+ const char *name;
65703+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65704+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65705+ const char *parent_name;
65706+#endif
65707
65708 BUG_ON(!kobj);
65709
65710+ name = kobject_name(kobj);
65711+
65712 if (kobj->parent)
65713 parent = kobj->parent->sd;
65714 else
65715@@ -73,11 +80,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65716 if (!parent)
65717 return -ENOENT;
65718
65719- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65720- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65721+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65722+ parent_name = parent->name;
65723+ mode = S_IRWXU;
65724+
65725+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65726+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65727+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65728+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65729+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65730+#endif
65731+
65732+ kn = kernfs_create_dir_ns(parent, name,
65733+ mode, kobj, ns);
65734 if (IS_ERR(kn)) {
65735 if (PTR_ERR(kn) == -EEXIST)
65736- sysfs_warn_dup(parent, kobject_name(kobj));
65737+ sysfs_warn_dup(parent, name);
65738 return PTR_ERR(kn);
65739 }
65740
65741diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65742index 69d4889..a810bd4 100644
65743--- a/fs/sysv/sysv.h
65744+++ b/fs/sysv/sysv.h
65745@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65746 #endif
65747 }
65748
65749-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65750+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65751 {
65752 if (sbi->s_bytesex == BYTESEX_PDP)
65753 return PDP_swab((__force __u32)n);
65754diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65755index e18b988..f1d4ad0f 100644
65756--- a/fs/ubifs/io.c
65757+++ b/fs/ubifs/io.c
65758@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65759 return err;
65760 }
65761
65762-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65763+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65764 {
65765 int err;
65766
65767diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65768index c175b4d..8f36a16 100644
65769--- a/fs/udf/misc.c
65770+++ b/fs/udf/misc.c
65771@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65772
65773 u8 udf_tag_checksum(const struct tag *t)
65774 {
65775- u8 *data = (u8 *)t;
65776+ const u8 *data = (const u8 *)t;
65777 u8 checksum = 0;
65778 int i;
65779 for (i = 0; i < sizeof(struct tag); ++i)
65780diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65781index 8d974c4..b82f6ec 100644
65782--- a/fs/ufs/swab.h
65783+++ b/fs/ufs/swab.h
65784@@ -22,7 +22,7 @@ enum {
65785 BYTESEX_BE
65786 };
65787
65788-static inline u64
65789+static inline u64 __intentional_overflow(-1)
65790 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65791 {
65792 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65793@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65794 return (__force __fs64)cpu_to_be64(n);
65795 }
65796
65797-static inline u32
65798+static inline u32 __intentional_overflow(-1)
65799 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65800 {
65801 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65802diff --git a/fs/utimes.c b/fs/utimes.c
65803index aa138d6..5f3a811 100644
65804--- a/fs/utimes.c
65805+++ b/fs/utimes.c
65806@@ -1,6 +1,7 @@
65807 #include <linux/compiler.h>
65808 #include <linux/file.h>
65809 #include <linux/fs.h>
65810+#include <linux/security.h>
65811 #include <linux/linkage.h>
65812 #include <linux/mount.h>
65813 #include <linux/namei.h>
65814@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65815 }
65816 }
65817 retry_deleg:
65818+
65819+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65820+ error = -EACCES;
65821+ goto mnt_drop_write_and_out;
65822+ }
65823+
65824 mutex_lock(&inode->i_mutex);
65825 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65826 mutex_unlock(&inode->i_mutex);
65827diff --git a/fs/xattr.c b/fs/xattr.c
65828index 3377dff..f394815 100644
65829--- a/fs/xattr.c
65830+++ b/fs/xattr.c
65831@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65832 return rc;
65833 }
65834
65835+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65836+ssize_t
65837+pax_getxattr(struct dentry *dentry, void *value, size_t size)
65838+{
65839+ struct inode *inode = dentry->d_inode;
65840+ ssize_t error;
65841+
65842+ error = inode_permission(inode, MAY_EXEC);
65843+ if (error)
65844+ return error;
65845+
65846+ if (inode->i_op->getxattr)
65847+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65848+ else
65849+ error = -EOPNOTSUPP;
65850+
65851+ return error;
65852+}
65853+EXPORT_SYMBOL(pax_getxattr);
65854+#endif
65855+
65856 ssize_t
65857 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65858 {
65859@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65860 * Extended attribute SET operations
65861 */
65862 static long
65863-setxattr(struct dentry *d, const char __user *name, const void __user *value,
65864+setxattr(struct path *path, const char __user *name, const void __user *value,
65865 size_t size, int flags)
65866 {
65867 int error;
65868@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65869 posix_acl_fix_xattr_from_user(kvalue, size);
65870 }
65871
65872- error = vfs_setxattr(d, kname, kvalue, size, flags);
65873+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65874+ error = -EACCES;
65875+ goto out;
65876+ }
65877+
65878+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65879 out:
65880 if (vvalue)
65881 vfree(vvalue);
65882@@ -377,7 +403,7 @@ retry:
65883 return error;
65884 error = mnt_want_write(path.mnt);
65885 if (!error) {
65886- error = setxattr(path.dentry, name, value, size, flags);
65887+ error = setxattr(&path, name, value, size, flags);
65888 mnt_drop_write(path.mnt);
65889 }
65890 path_put(&path);
65891@@ -401,7 +427,7 @@ retry:
65892 return error;
65893 error = mnt_want_write(path.mnt);
65894 if (!error) {
65895- error = setxattr(path.dentry, name, value, size, flags);
65896+ error = setxattr(&path, name, value, size, flags);
65897 mnt_drop_write(path.mnt);
65898 }
65899 path_put(&path);
65900@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65901 const void __user *,value, size_t, size, int, flags)
65902 {
65903 struct fd f = fdget(fd);
65904- struct dentry *dentry;
65905 int error = -EBADF;
65906
65907 if (!f.file)
65908 return error;
65909- dentry = f.file->f_path.dentry;
65910- audit_inode(NULL, dentry, 0);
65911+ audit_inode(NULL, f.file->f_path.dentry, 0);
65912 error = mnt_want_write_file(f.file);
65913 if (!error) {
65914- error = setxattr(dentry, name, value, size, flags);
65915+ error = setxattr(&f.file->f_path, name, value, size, flags);
65916 mnt_drop_write_file(f.file);
65917 }
65918 fdput(f);
65919@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65920 * Extended attribute REMOVE operations
65921 */
65922 static long
65923-removexattr(struct dentry *d, const char __user *name)
65924+removexattr(struct path *path, const char __user *name)
65925 {
65926 int error;
65927 char kname[XATTR_NAME_MAX + 1];
65928@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65929 if (error < 0)
65930 return error;
65931
65932- return vfs_removexattr(d, kname);
65933+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65934+ return -EACCES;
65935+
65936+ return vfs_removexattr(path->dentry, kname);
65937 }
65938
65939 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65940@@ -652,7 +679,7 @@ retry:
65941 return error;
65942 error = mnt_want_write(path.mnt);
65943 if (!error) {
65944- error = removexattr(path.dentry, name);
65945+ error = removexattr(&path, name);
65946 mnt_drop_write(path.mnt);
65947 }
65948 path_put(&path);
65949@@ -675,7 +702,7 @@ retry:
65950 return error;
65951 error = mnt_want_write(path.mnt);
65952 if (!error) {
65953- error = removexattr(path.dentry, name);
65954+ error = removexattr(&path, name);
65955 mnt_drop_write(path.mnt);
65956 }
65957 path_put(&path);
65958@@ -689,16 +716,16 @@ retry:
65959 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65960 {
65961 struct fd f = fdget(fd);
65962- struct dentry *dentry;
65963+ struct path *path;
65964 int error = -EBADF;
65965
65966 if (!f.file)
65967 return error;
65968- dentry = f.file->f_path.dentry;
65969- audit_inode(NULL, dentry, 0);
65970+ path = &f.file->f_path;
65971+ audit_inode(NULL, path->dentry, 0);
65972 error = mnt_want_write_file(f.file);
65973 if (!error) {
65974- error = removexattr(dentry, name);
65975+ error = removexattr(path, name);
65976 mnt_drop_write_file(f.file);
65977 }
65978 fdput(f);
65979diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65980index 152543c..d80c361 100644
65981--- a/fs/xfs/xfs_bmap.c
65982+++ b/fs/xfs/xfs_bmap.c
65983@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65984
65985 #else
65986 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65987-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65988+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65989 #endif /* DEBUG */
65990
65991 /*
65992diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65993index aead369..0dfecfd 100644
65994--- a/fs/xfs/xfs_dir2_readdir.c
65995+++ b/fs/xfs/xfs_dir2_readdir.c
65996@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65997 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65998 filetype = dp->d_ops->sf_get_ftype(sfep);
65999 ctx->pos = off & 0x7fffffff;
66000- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
66001+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
66002+ char name[sfep->namelen];
66003+ memcpy(name, sfep->name, sfep->namelen);
66004+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
66005+ return 0;
66006+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
66007 xfs_dir3_get_dtype(mp, filetype)))
66008 return 0;
66009 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
66010diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
66011index 78e62cc..eec3706 100644
66012--- a/fs/xfs/xfs_ioctl.c
66013+++ b/fs/xfs/xfs_ioctl.c
66014@@ -122,7 +122,7 @@ xfs_find_handle(
66015 }
66016
66017 error = -EFAULT;
66018- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
66019+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
66020 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
66021 goto out_put;
66022
66023diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
66024new file mode 100644
66025index 0000000..bfd482c
66026--- /dev/null
66027+++ b/grsecurity/Kconfig
66028@@ -0,0 +1,1176 @@
66029+#
66030+# grecurity configuration
66031+#
66032+menu "Memory Protections"
66033+depends on GRKERNSEC
66034+
66035+config GRKERNSEC_KMEM
66036+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
66037+ default y if GRKERNSEC_CONFIG_AUTO
66038+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
66039+ help
66040+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
66041+ be written to or read from to modify or leak the contents of the running
66042+ kernel. /dev/port will also not be allowed to be opened, writing to
66043+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
66044+ If you have module support disabled, enabling this will close up several
66045+ ways that are currently used to insert malicious code into the running
66046+ kernel.
66047+
66048+ Even with this feature enabled, we still highly recommend that
66049+ you use the RBAC system, as it is still possible for an attacker to
66050+ modify the running kernel through other more obscure methods.
66051+
66052+ It is highly recommended that you say Y here if you meet all the
66053+ conditions above.
66054+
66055+config GRKERNSEC_VM86
66056+ bool "Restrict VM86 mode"
66057+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66058+ depends on X86_32
66059+
66060+ help
66061+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
66062+ make use of a special execution mode on 32bit x86 processors called
66063+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
66064+ video cards and will still work with this option enabled. The purpose
66065+ of the option is to prevent exploitation of emulation errors in
66066+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
66067+ Nearly all users should be able to enable this option.
66068+
66069+config GRKERNSEC_IO
66070+ bool "Disable privileged I/O"
66071+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66072+ depends on X86
66073+ select RTC_CLASS
66074+ select RTC_INTF_DEV
66075+ select RTC_DRV_CMOS
66076+
66077+ help
66078+ If you say Y here, all ioperm and iopl calls will return an error.
66079+ Ioperm and iopl can be used to modify the running kernel.
66080+ Unfortunately, some programs need this access to operate properly,
66081+ the most notable of which are XFree86 and hwclock. hwclock can be
66082+ remedied by having RTC support in the kernel, so real-time
66083+ clock support is enabled if this option is enabled, to ensure
66084+ that hwclock operates correctly. If hwclock still does not work,
66085+ either update udev or symlink /dev/rtc to /dev/rtc0.
66086+
66087+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
66088+ you may not be able to boot into a graphical environment with this
66089+ option enabled. In this case, you should use the RBAC system instead.
66090+
66091+config GRKERNSEC_JIT_HARDEN
66092+ bool "Harden BPF JIT against spray attacks"
66093+ default y if GRKERNSEC_CONFIG_AUTO
66094+ depends on BPF_JIT && X86
66095+ help
66096+ If you say Y here, the native code generated by the kernel's Berkeley
66097+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
66098+ attacks that attempt to fit attacker-beneficial instructions in
66099+ 32bit immediate fields of JIT-generated native instructions. The
66100+ attacker will generally aim to cause an unintended instruction sequence
66101+ of JIT-generated native code to execute by jumping into the middle of
66102+ a generated instruction. This feature effectively randomizes the 32bit
66103+ immediate constants present in the generated code to thwart such attacks.
66104+
66105+ If you're using KERNEXEC, it's recommended that you enable this option
66106+ to supplement the hardening of the kernel.
66107+
66108+config GRKERNSEC_PERF_HARDEN
66109+ bool "Disable unprivileged PERF_EVENTS usage by default"
66110+ default y if GRKERNSEC_CONFIG_AUTO
66111+ depends on PERF_EVENTS
66112+ help
66113+ If you say Y here, the range of acceptable values for the
66114+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
66115+ default to a new value: 3. When the sysctl is set to this value, no
66116+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
66117+
66118+ Though PERF_EVENTS can be used legitimately for performance monitoring
66119+ and low-level application profiling, it is forced on regardless of
66120+ configuration, has been at fault for several vulnerabilities, and
66121+ creates new opportunities for side channels and other information leaks.
66122+
66123+ This feature puts PERF_EVENTS into a secure default state and permits
66124+ the administrator to change out of it temporarily if unprivileged
66125+ application profiling is needed.
66126+
66127+config GRKERNSEC_RAND_THREADSTACK
66128+ bool "Insert random gaps between thread stacks"
66129+ default y if GRKERNSEC_CONFIG_AUTO
66130+ depends on PAX_RANDMMAP && !PPC
66131+ help
66132+ If you say Y here, a random-sized gap will be enforced between allocated
66133+ thread stacks. Glibc's NPTL and other threading libraries that
66134+ pass MAP_STACK to the kernel for thread stack allocation are supported.
66135+ The implementation currently provides 8 bits of entropy for the gap.
66136+
66137+ Many distributions do not compile threaded remote services with the
66138+ -fstack-check argument to GCC, causing the variable-sized stack-based
66139+ allocator, alloca(), to not probe the stack on allocation. This
66140+ permits an unbounded alloca() to skip over any guard page and potentially
66141+ modify another thread's stack reliably. An enforced random gap
66142+ reduces the reliability of such an attack and increases the chance
66143+ that such a read/write to another thread's stack instead lands in
66144+ an unmapped area, causing a crash and triggering grsecurity's
66145+ anti-bruteforcing logic.
66146+
66147+config GRKERNSEC_PROC_MEMMAP
66148+ bool "Harden ASLR against information leaks and entropy reduction"
66149+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
66150+ depends on PAX_NOEXEC || PAX_ASLR
66151+ help
66152+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
66153+ give no information about the addresses of its mappings if
66154+ PaX features that rely on random addresses are enabled on the task.
66155+ In addition to sanitizing this information and disabling other
66156+ dangerous sources of information, this option causes reads of sensitive
66157+ /proc/<pid> entries where the file descriptor was opened in a different
66158+ task than the one performing the read. Such attempts are logged.
66159+ This option also limits argv/env strings for suid/sgid binaries
66160+ to 512KB to prevent a complete exhaustion of the stack entropy provided
66161+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
66162+ binaries to prevent alternative mmap layouts from being abused.
66163+
66164+ If you use PaX it is essential that you say Y here as it closes up
66165+ several holes that make full ASLR useless locally.
66166+
66167+
66168+config GRKERNSEC_KSTACKOVERFLOW
66169+ bool "Prevent kernel stack overflows"
66170+ default y if GRKERNSEC_CONFIG_AUTO
66171+ depends on !IA64 && 64BIT
66172+ help
66173+ If you say Y here, the kernel's process stacks will be allocated
66174+ with vmalloc instead of the kernel's default allocator. This
66175+ introduces guard pages that in combination with the alloca checking
66176+ of the STACKLEAK feature prevents all forms of kernel process stack
66177+ overflow abuse. Note that this is different from kernel stack
66178+ buffer overflows.
66179+
66180+config GRKERNSEC_BRUTE
66181+ bool "Deter exploit bruteforcing"
66182+ default y if GRKERNSEC_CONFIG_AUTO
66183+ help
66184+ If you say Y here, attempts to bruteforce exploits against forking
66185+ daemons such as apache or sshd, as well as against suid/sgid binaries
66186+ will be deterred. When a child of a forking daemon is killed by PaX
66187+ or crashes due to an illegal instruction or other suspicious signal,
66188+ the parent process will be delayed 30 seconds upon every subsequent
66189+ fork until the administrator is able to assess the situation and
66190+ restart the daemon.
66191+ In the suid/sgid case, the attempt is logged, the user has all their
66192+ existing instances of the suid/sgid binary terminated and will
66193+ be unable to execute any suid/sgid binaries for 15 minutes.
66194+
66195+ It is recommended that you also enable signal logging in the auditing
66196+ section so that logs are generated when a process triggers a suspicious
66197+ signal.
66198+ If the sysctl option is enabled, a sysctl option with name
66199+ "deter_bruteforce" is created.
66200+
66201+config GRKERNSEC_MODHARDEN
66202+ bool "Harden module auto-loading"
66203+ default y if GRKERNSEC_CONFIG_AUTO
66204+ depends on MODULES
66205+ help
66206+ If you say Y here, module auto-loading in response to use of some
66207+ feature implemented by an unloaded module will be restricted to
66208+ root users. Enabling this option helps defend against attacks
66209+ by unprivileged users who abuse the auto-loading behavior to
66210+ cause a vulnerable module to load that is then exploited.
66211+
66212+ If this option prevents a legitimate use of auto-loading for a
66213+ non-root user, the administrator can execute modprobe manually
66214+ with the exact name of the module mentioned in the alert log.
66215+ Alternatively, the administrator can add the module to the list
66216+ of modules loaded at boot by modifying init scripts.
66217+
66218+ Modification of init scripts will most likely be needed on
66219+ Ubuntu servers with encrypted home directory support enabled,
66220+ as the first non-root user logging in will cause the ecb(aes),
66221+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
66222+
66223+config GRKERNSEC_HIDESYM
66224+ bool "Hide kernel symbols"
66225+ default y if GRKERNSEC_CONFIG_AUTO
66226+ select PAX_USERCOPY_SLABS
66227+ help
66228+ If you say Y here, getting information on loaded modules, and
66229+ displaying all kernel symbols through a syscall will be restricted
66230+ to users with CAP_SYS_MODULE. For software compatibility reasons,
66231+ /proc/kallsyms will be restricted to the root user. The RBAC
66232+ system can hide that entry even from root.
66233+
66234+ This option also prevents leaking of kernel addresses through
66235+ several /proc entries.
66236+
66237+ Note that this option is only effective provided the following
66238+ conditions are met:
66239+ 1) The kernel using grsecurity is not precompiled by some distribution
66240+ 2) You have also enabled GRKERNSEC_DMESG
66241+ 3) You are using the RBAC system and hiding other files such as your
66242+ kernel image and System.map. Alternatively, enabling this option
66243+ causes the permissions on /boot, /lib/modules, and the kernel
66244+ source directory to change at compile time to prevent
66245+ reading by non-root users.
66246+ If the above conditions are met, this option will aid in providing a
66247+ useful protection against local kernel exploitation of overflows
66248+ and arbitrary read/write vulnerabilities.
66249+
66250+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
66251+ in addition to this feature.
66252+
66253+config GRKERNSEC_RANDSTRUCT
66254+ bool "Randomize layout of sensitive kernel structures"
66255+ default y if GRKERNSEC_CONFIG_AUTO
66256+ select GRKERNSEC_HIDESYM
66257+ select MODVERSIONS if MODULES
66258+ help
66259+ If you say Y here, the layouts of a number of sensitive kernel
66260+ structures (task, fs, cred, etc) and all structures composed entirely
66261+ of function pointers (aka "ops" structs) will be randomized at compile-time.
66262+ This can introduce the requirement of an additional infoleak
66263+ vulnerability for exploits targeting these structure types.
66264+
66265+ Enabling this feature will introduce some performance impact, slightly
66266+ increase memory usage, and prevent the use of forensic tools like
66267+ Volatility against the system (unless the kernel source tree isn't
66268+ cleaned after kernel installation).
66269+
66270+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
66271+ It remains after a make clean to allow for external modules to be compiled
66272+ with the existing seed and will be removed by a make mrproper or
66273+ make distclean.
66274+
66275+ Note that the implementation requires gcc 4.6.4. or newer. You may need
66276+ to install the supporting headers explicitly in addition to the normal
66277+ gcc package.
66278+
66279+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
66280+ bool "Use cacheline-aware structure randomization"
66281+ depends on GRKERNSEC_RANDSTRUCT
66282+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
66283+ help
66284+ If you say Y here, the RANDSTRUCT randomization will make a best effort
66285+ at restricting randomization to cacheline-sized groups of elements. It
66286+ will further not randomize bitfields in structures. This reduces the
66287+ performance hit of RANDSTRUCT at the cost of weakened randomization.
66288+
66289+config GRKERNSEC_KERN_LOCKOUT
66290+ bool "Active kernel exploit response"
66291+ default y if GRKERNSEC_CONFIG_AUTO
66292+ depends on X86 || ARM || PPC || SPARC
66293+ help
66294+ If you say Y here, when a PaX alert is triggered due to suspicious
66295+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
66296+ or an OOPS occurs due to bad memory accesses, instead of just
66297+ terminating the offending process (and potentially allowing
66298+ a subsequent exploit from the same user), we will take one of two
66299+ actions:
66300+ If the user was root, we will panic the system
66301+ If the user was non-root, we will log the attempt, terminate
66302+ all processes owned by the user, then prevent them from creating
66303+ any new processes until the system is restarted
66304+ This deters repeated kernel exploitation/bruteforcing attempts
66305+ and is useful for later forensics.
66306+
66307+config GRKERNSEC_OLD_ARM_USERLAND
66308+ bool "Old ARM userland compatibility"
66309+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
66310+ help
66311+ If you say Y here, stubs of executable code to perform such operations
66312+ as "compare-exchange" will be placed at fixed locations in the ARM vector
66313+ table. This is unfortunately needed for old ARM userland meant to run
66314+ across a wide range of processors. Without this option enabled,
66315+ the get_tls and data memory barrier stubs will be emulated by the kernel,
66316+ which is enough for Linaro userlands or other userlands designed for v6
66317+ and newer ARM CPUs. It's recommended that you try without this option enabled
66318+ first, and only enable it if your userland does not boot (it will likely fail
66319+ at init time).
66320+
66321+endmenu
66322+menu "Role Based Access Control Options"
66323+depends on GRKERNSEC
66324+
66325+config GRKERNSEC_RBAC_DEBUG
66326+ bool
66327+
66328+config GRKERNSEC_NO_RBAC
66329+ bool "Disable RBAC system"
66330+ help
66331+ If you say Y here, the /dev/grsec device will be removed from the kernel,
66332+ preventing the RBAC system from being enabled. You should only say Y
66333+ here if you have no intention of using the RBAC system, so as to prevent
66334+ an attacker with root access from misusing the RBAC system to hide files
66335+ and processes when loadable module support and /dev/[k]mem have been
66336+ locked down.
66337+
66338+config GRKERNSEC_ACL_HIDEKERN
66339+ bool "Hide kernel processes"
66340+ help
66341+ If you say Y here, all kernel threads will be hidden to all
66342+ processes but those whose subject has the "view hidden processes"
66343+ flag.
66344+
66345+config GRKERNSEC_ACL_MAXTRIES
66346+ int "Maximum tries before password lockout"
66347+ default 3
66348+ help
66349+ This option enforces the maximum number of times a user can attempt
66350+ to authorize themselves with the grsecurity RBAC system before being
66351+ denied the ability to attempt authorization again for a specified time.
66352+ The lower the number, the harder it will be to brute-force a password.
66353+
66354+config GRKERNSEC_ACL_TIMEOUT
66355+ int "Time to wait after max password tries, in seconds"
66356+ default 30
66357+ help
66358+ This option specifies the time the user must wait after attempting to
66359+ authorize to the RBAC system with the maximum number of invalid
66360+ passwords. The higher the number, the harder it will be to brute-force
66361+ a password.
66362+
66363+endmenu
66364+menu "Filesystem Protections"
66365+depends on GRKERNSEC
66366+
66367+config GRKERNSEC_PROC
66368+ bool "Proc restrictions"
66369+ default y if GRKERNSEC_CONFIG_AUTO
66370+ help
66371+ If you say Y here, the permissions of the /proc filesystem
66372+ will be altered to enhance system security and privacy. You MUST
66373+ choose either a user only restriction or a user and group restriction.
66374+ Depending upon the option you choose, you can either restrict users to
66375+ see only the processes they themselves run, or choose a group that can
66376+ view all processes and files normally restricted to root if you choose
66377+ the "restrict to user only" option. NOTE: If you're running identd or
66378+ ntpd as a non-root user, you will have to run it as the group you
66379+ specify here.
66380+
66381+config GRKERNSEC_PROC_USER
66382+ bool "Restrict /proc to user only"
66383+ depends on GRKERNSEC_PROC
66384+ help
66385+ If you say Y here, non-root users will only be able to view their own
66386+ processes, and restricts them from viewing network-related information,
66387+ and viewing kernel symbol and module information.
66388+
66389+config GRKERNSEC_PROC_USERGROUP
66390+ bool "Allow special group"
66391+ default y if GRKERNSEC_CONFIG_AUTO
66392+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
66393+ help
66394+ If you say Y here, you will be able to select a group that will be
66395+ able to view all processes and network-related information. If you've
66396+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
66397+ remain hidden. This option is useful if you want to run identd as
66398+ a non-root user. The group you select may also be chosen at boot time
66399+ via "grsec_proc_gid=" on the kernel commandline.
66400+
66401+config GRKERNSEC_PROC_GID
66402+ int "GID for special group"
66403+ depends on GRKERNSEC_PROC_USERGROUP
66404+ default 1001
66405+
66406+config GRKERNSEC_PROC_ADD
66407+ bool "Additional restrictions"
66408+ default y if GRKERNSEC_CONFIG_AUTO
66409+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
66410+ help
66411+ If you say Y here, additional restrictions will be placed on
66412+ /proc that keep normal users from viewing device information and
66413+ slabinfo information that could be useful for exploits.
66414+
66415+config GRKERNSEC_LINK
66416+ bool "Linking restrictions"
66417+ default y if GRKERNSEC_CONFIG_AUTO
66418+ help
66419+ If you say Y here, /tmp race exploits will be prevented, since users
66420+ will no longer be able to follow symlinks owned by other users in
66421+ world-writable +t directories (e.g. /tmp), unless the owner of the
66422+ symlink is the owner of the directory. users will also not be
66423+ able to hardlink to files they do not own. If the sysctl option is
66424+ enabled, a sysctl option with name "linking_restrictions" is created.
66425+
66426+config GRKERNSEC_SYMLINKOWN
66427+ bool "Kernel-enforced SymlinksIfOwnerMatch"
66428+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66429+ help
66430+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
66431+ that prevents it from being used as a security feature. As Apache
66432+ verifies the symlink by performing a stat() against the target of
66433+ the symlink before it is followed, an attacker can setup a symlink
66434+ to point to a same-owned file, then replace the symlink with one
66435+ that targets another user's file just after Apache "validates" the
66436+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
66437+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
66438+ will be in place for the group you specify. If the sysctl option
66439+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
66440+ created.
66441+
66442+config GRKERNSEC_SYMLINKOWN_GID
66443+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66444+ depends on GRKERNSEC_SYMLINKOWN
66445+ default 1006
66446+ help
66447+ Setting this GID determines what group kernel-enforced
66448+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66449+ is enabled, a sysctl option with name "symlinkown_gid" is created.
66450+
66451+config GRKERNSEC_FIFO
66452+ bool "FIFO restrictions"
66453+ default y if GRKERNSEC_CONFIG_AUTO
66454+ help
66455+ If you say Y here, users will not be able to write to FIFOs they don't
66456+ own in world-writable +t directories (e.g. /tmp), unless the owner of
66457+ the FIFO is the same owner of the directory it's held in. If the sysctl
66458+ option is enabled, a sysctl option with name "fifo_restrictions" is
66459+ created.
66460+
66461+config GRKERNSEC_SYSFS_RESTRICT
66462+ bool "Sysfs/debugfs restriction"
66463+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66464+ depends on SYSFS
66465+ help
66466+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66467+ any filesystem normally mounted under it (e.g. debugfs) will be
66468+ mostly accessible only by root. These filesystems generally provide access
66469+ to hardware and debug information that isn't appropriate for unprivileged
66470+ users of the system. Sysfs and debugfs have also become a large source
66471+ of new vulnerabilities, ranging from infoleaks to local compromise.
66472+ There has been very little oversight with an eye toward security involved
66473+ in adding new exporters of information to these filesystems, so their
66474+ use is discouraged.
66475+ For reasons of compatibility, a few directories have been whitelisted
66476+ for access by non-root users:
66477+ /sys/fs/selinux
66478+ /sys/fs/fuse
66479+ /sys/devices/system/cpu
66480+
66481+config GRKERNSEC_ROFS
66482+ bool "Runtime read-only mount protection"
66483+ depends on SYSCTL
66484+ help
66485+ If you say Y here, a sysctl option with name "romount_protect" will
66486+ be created. By setting this option to 1 at runtime, filesystems
66487+ will be protected in the following ways:
66488+ * No new writable mounts will be allowed
66489+ * Existing read-only mounts won't be able to be remounted read/write
66490+ * Write operations will be denied on all block devices
66491+ This option acts independently of grsec_lock: once it is set to 1,
66492+ it cannot be turned off. Therefore, please be mindful of the resulting
66493+ behavior if this option is enabled in an init script on a read-only
66494+ filesystem.
66495+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66496+ and GRKERNSEC_IO should be enabled and module loading disabled via
66497+ config or at runtime.
66498+ This feature is mainly intended for secure embedded systems.
66499+
66500+
66501+config GRKERNSEC_DEVICE_SIDECHANNEL
66502+ bool "Eliminate stat/notify-based device sidechannels"
66503+ default y if GRKERNSEC_CONFIG_AUTO
66504+ help
66505+ If you say Y here, timing analyses on block or character
66506+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66507+ will be thwarted for unprivileged users. If a process without
66508+ CAP_MKNOD stats such a device, the last access and last modify times
66509+ will match the device's create time. No access or modify events
66510+ will be triggered through inotify/dnotify/fanotify for such devices.
66511+ This feature will prevent attacks that may at a minimum
66512+ allow an attacker to determine the administrator's password length.
66513+
66514+config GRKERNSEC_CHROOT
66515+ bool "Chroot jail restrictions"
66516+ default y if GRKERNSEC_CONFIG_AUTO
66517+ help
66518+ If you say Y here, you will be able to choose several options that will
66519+ make breaking out of a chrooted jail much more difficult. If you
66520+ encounter no software incompatibilities with the following options, it
66521+ is recommended that you enable each one.
66522+
66523+ Note that the chroot restrictions are not intended to apply to "chroots"
66524+ to directories that are simple bind mounts of the global root filesystem.
66525+ For several other reasons, a user shouldn't expect any significant
66526+ security by performing such a chroot.
66527+
66528+config GRKERNSEC_CHROOT_MOUNT
66529+ bool "Deny mounts"
66530+ default y if GRKERNSEC_CONFIG_AUTO
66531+ depends on GRKERNSEC_CHROOT
66532+ help
66533+ If you say Y here, processes inside a chroot will not be able to
66534+ mount or remount filesystems. If the sysctl option is enabled, a
66535+ sysctl option with name "chroot_deny_mount" is created.
66536+
66537+config GRKERNSEC_CHROOT_DOUBLE
66538+ bool "Deny double-chroots"
66539+ default y if GRKERNSEC_CONFIG_AUTO
66540+ depends on GRKERNSEC_CHROOT
66541+ help
66542+ If you say Y here, processes inside a chroot will not be able to chroot
66543+ again outside the chroot. This is a widely used method of breaking
66544+ out of a chroot jail and should not be allowed. If the sysctl
66545+ option is enabled, a sysctl option with name
66546+ "chroot_deny_chroot" is created.
66547+
66548+config GRKERNSEC_CHROOT_PIVOT
66549+ bool "Deny pivot_root in chroot"
66550+ default y if GRKERNSEC_CONFIG_AUTO
66551+ depends on GRKERNSEC_CHROOT
66552+ help
66553+ If you say Y here, processes inside a chroot will not be able to use
66554+ a function called pivot_root() that was introduced in Linux 2.3.41. It
66555+ works similar to chroot in that it changes the root filesystem. This
66556+ function could be misused in a chrooted process to attempt to break out
66557+ of the chroot, and therefore should not be allowed. If the sysctl
66558+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
66559+ created.
66560+
66561+config GRKERNSEC_CHROOT_CHDIR
66562+ bool "Enforce chdir(\"/\") on all chroots"
66563+ default y if GRKERNSEC_CONFIG_AUTO
66564+ depends on GRKERNSEC_CHROOT
66565+ help
66566+ If you say Y here, the current working directory of all newly-chrooted
66567+ applications will be set to the the root directory of the chroot.
66568+ The man page on chroot(2) states:
66569+ Note that this call does not change the current working
66570+ directory, so that `.' can be outside the tree rooted at
66571+ `/'. In particular, the super-user can escape from a
66572+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66573+
66574+ It is recommended that you say Y here, since it's not known to break
66575+ any software. If the sysctl option is enabled, a sysctl option with
66576+ name "chroot_enforce_chdir" is created.
66577+
66578+config GRKERNSEC_CHROOT_CHMOD
66579+ bool "Deny (f)chmod +s"
66580+ default y if GRKERNSEC_CONFIG_AUTO
66581+ depends on GRKERNSEC_CHROOT
66582+ help
66583+ If you say Y here, processes inside a chroot will not be able to chmod
66584+ or fchmod files to make them have suid or sgid bits. This protects
66585+ against another published method of breaking a chroot. If the sysctl
66586+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
66587+ created.
66588+
66589+config GRKERNSEC_CHROOT_FCHDIR
66590+ bool "Deny fchdir and fhandle out of chroot"
66591+ default y if GRKERNSEC_CONFIG_AUTO
66592+ depends on GRKERNSEC_CHROOT
66593+ help
66594+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
66595+ to a file descriptor of the chrooting process that points to a directory
66596+ outside the filesystem will be stopped. Additionally, this option prevents
66597+ use of the recently-created syscall for opening files by a guessable "file
66598+ handle" inside a chroot. If the sysctl option is enabled, a sysctl option
66599+ with name "chroot_deny_fchdir" is created.
66600+
66601+config GRKERNSEC_CHROOT_MKNOD
66602+ bool "Deny mknod"
66603+ default y if GRKERNSEC_CONFIG_AUTO
66604+ depends on GRKERNSEC_CHROOT
66605+ help
66606+ If you say Y here, processes inside a chroot will not be allowed to
66607+ mknod. The problem with using mknod inside a chroot is that it
66608+ would allow an attacker to create a device entry that is the same
66609+ as one on the physical root of your system, which could range from
66610+ anything from the console device to a device for your harddrive (which
66611+ they could then use to wipe the drive or steal data). It is recommended
66612+ that you say Y here, unless you run into software incompatibilities.
66613+ If the sysctl option is enabled, a sysctl option with name
66614+ "chroot_deny_mknod" is created.
66615+
66616+config GRKERNSEC_CHROOT_SHMAT
66617+ bool "Deny shmat() out of chroot"
66618+ default y if GRKERNSEC_CONFIG_AUTO
66619+ depends on GRKERNSEC_CHROOT
66620+ help
66621+ If you say Y here, processes inside a chroot will not be able to attach
66622+ to shared memory segments that were created outside of the chroot jail.
66623+ It is recommended that you say Y here. If the sysctl option is enabled,
66624+ a sysctl option with name "chroot_deny_shmat" is created.
66625+
66626+config GRKERNSEC_CHROOT_UNIX
66627+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
66628+ default y if GRKERNSEC_CONFIG_AUTO
66629+ depends on GRKERNSEC_CHROOT
66630+ help
66631+ If you say Y here, processes inside a chroot will not be able to
66632+ connect to abstract (meaning not belonging to a filesystem) Unix
66633+ domain sockets that were bound outside of a chroot. It is recommended
66634+ that you say Y here. If the sysctl option is enabled, a sysctl option
66635+ with name "chroot_deny_unix" is created.
66636+
66637+config GRKERNSEC_CHROOT_FINDTASK
66638+ bool "Protect outside processes"
66639+ default y if GRKERNSEC_CONFIG_AUTO
66640+ depends on GRKERNSEC_CHROOT
66641+ help
66642+ If you say Y here, processes inside a chroot will not be able to
66643+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66644+ getsid, or view any process outside of the chroot. If the sysctl
66645+ option is enabled, a sysctl option with name "chroot_findtask" is
66646+ created.
66647+
66648+config GRKERNSEC_CHROOT_NICE
66649+ bool "Restrict priority changes"
66650+ default y if GRKERNSEC_CONFIG_AUTO
66651+ depends on GRKERNSEC_CHROOT
66652+ help
66653+ If you say Y here, processes inside a chroot will not be able to raise
66654+ the priority of processes in the chroot, or alter the priority of
66655+ processes outside the chroot. This provides more security than simply
66656+ removing CAP_SYS_NICE from the process' capability set. If the
66657+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66658+ is created.
66659+
66660+config GRKERNSEC_CHROOT_SYSCTL
66661+ bool "Deny sysctl writes"
66662+ default y if GRKERNSEC_CONFIG_AUTO
66663+ depends on GRKERNSEC_CHROOT
66664+ help
66665+ If you say Y here, an attacker in a chroot will not be able to
66666+ write to sysctl entries, either by sysctl(2) or through a /proc
66667+ interface. It is strongly recommended that you say Y here. If the
66668+ sysctl option is enabled, a sysctl option with name
66669+ "chroot_deny_sysctl" is created.
66670+
66671+config GRKERNSEC_CHROOT_CAPS
66672+ bool "Capability restrictions"
66673+ default y if GRKERNSEC_CONFIG_AUTO
66674+ depends on GRKERNSEC_CHROOT
66675+ help
66676+ If you say Y here, the capabilities on all processes within a
66677+ chroot jail will be lowered to stop module insertion, raw i/o,
66678+ system and net admin tasks, rebooting the system, modifying immutable
66679+ files, modifying IPC owned by another, and changing the system time.
66680+ This is left an option because it can break some apps. Disable this
66681+ if your chrooted apps are having problems performing those kinds of
66682+ tasks. If the sysctl option is enabled, a sysctl option with
66683+ name "chroot_caps" is created.
66684+
66685+config GRKERNSEC_CHROOT_INITRD
66686+ bool "Exempt initrd tasks from restrictions"
66687+ default y if GRKERNSEC_CONFIG_AUTO
66688+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66689+ help
66690+ If you say Y here, tasks started prior to init will be exempted from
66691+ grsecurity's chroot restrictions. This option is mainly meant to
66692+ resolve Plymouth's performing privileged operations unnecessarily
66693+ in a chroot.
66694+
66695+endmenu
66696+menu "Kernel Auditing"
66697+depends on GRKERNSEC
66698+
66699+config GRKERNSEC_AUDIT_GROUP
66700+ bool "Single group for auditing"
66701+ help
66702+ If you say Y here, the exec and chdir logging features will only operate
66703+ on a group you specify. This option is recommended if you only want to
66704+ watch certain users instead of having a large amount of logs from the
66705+ entire system. If the sysctl option is enabled, a sysctl option with
66706+ name "audit_group" is created.
66707+
66708+config GRKERNSEC_AUDIT_GID
66709+ int "GID for auditing"
66710+ depends on GRKERNSEC_AUDIT_GROUP
66711+ default 1007
66712+
66713+config GRKERNSEC_EXECLOG
66714+ bool "Exec logging"
66715+ help
66716+ If you say Y here, all execve() calls will be logged (since the
66717+ other exec*() calls are frontends to execve(), all execution
66718+ will be logged). Useful for shell-servers that like to keep track
66719+ of their users. If the sysctl option is enabled, a sysctl option with
66720+ name "exec_logging" is created.
66721+ WARNING: This option when enabled will produce a LOT of logs, especially
66722+ on an active system.
66723+
66724+config GRKERNSEC_RESLOG
66725+ bool "Resource logging"
66726+ default y if GRKERNSEC_CONFIG_AUTO
66727+ help
66728+ If you say Y here, all attempts to overstep resource limits will
66729+ be logged with the resource name, the requested size, and the current
66730+ limit. It is highly recommended that you say Y here. If the sysctl
66731+ option is enabled, a sysctl option with name "resource_logging" is
66732+ created. If the RBAC system is enabled, the sysctl value is ignored.
66733+
66734+config GRKERNSEC_CHROOT_EXECLOG
66735+ bool "Log execs within chroot"
66736+ help
66737+ If you say Y here, all executions inside a chroot jail will be logged
66738+ to syslog. This can cause a large amount of logs if certain
66739+ applications (eg. djb's daemontools) are installed on the system, and
66740+ is therefore left as an option. If the sysctl option is enabled, a
66741+ sysctl option with name "chroot_execlog" is created.
66742+
66743+config GRKERNSEC_AUDIT_PTRACE
66744+ bool "Ptrace logging"
66745+ help
66746+ If you say Y here, all attempts to attach to a process via ptrace
66747+ will be logged. If the sysctl option is enabled, a sysctl option
66748+ with name "audit_ptrace" is created.
66749+
66750+config GRKERNSEC_AUDIT_CHDIR
66751+ bool "Chdir logging"
66752+ help
66753+ If you say Y here, all chdir() calls will be logged. If the sysctl
66754+ option is enabled, a sysctl option with name "audit_chdir" is created.
66755+
66756+config GRKERNSEC_AUDIT_MOUNT
66757+ bool "(Un)Mount logging"
66758+ help
66759+ If you say Y here, all mounts and unmounts will be logged. If the
66760+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66761+ created.
66762+
66763+config GRKERNSEC_SIGNAL
66764+ bool "Signal logging"
66765+ default y if GRKERNSEC_CONFIG_AUTO
66766+ help
66767+ If you say Y here, certain important signals will be logged, such as
66768+ SIGSEGV, which will as a result inform you of when a error in a program
66769+ occurred, which in some cases could mean a possible exploit attempt.
66770+ If the sysctl option is enabled, a sysctl option with name
66771+ "signal_logging" is created.
66772+
66773+config GRKERNSEC_FORKFAIL
66774+ bool "Fork failure logging"
66775+ help
66776+ If you say Y here, all failed fork() attempts will be logged.
66777+ This could suggest a fork bomb, or someone attempting to overstep
66778+ their process limit. If the sysctl option is enabled, a sysctl option
66779+ with name "forkfail_logging" is created.
66780+
66781+config GRKERNSEC_TIME
66782+ bool "Time change logging"
66783+ default y if GRKERNSEC_CONFIG_AUTO
66784+ help
66785+ If you say Y here, any changes of the system clock will be logged.
66786+ If the sysctl option is enabled, a sysctl option with name
66787+ "timechange_logging" is created.
66788+
66789+config GRKERNSEC_PROC_IPADDR
66790+ bool "/proc/<pid>/ipaddr support"
66791+ default y if GRKERNSEC_CONFIG_AUTO
66792+ help
66793+ If you say Y here, a new entry will be added to each /proc/<pid>
66794+ directory that contains the IP address of the person using the task.
66795+ The IP is carried across local TCP and AF_UNIX stream sockets.
66796+ This information can be useful for IDS/IPSes to perform remote response
66797+ to a local attack. The entry is readable by only the owner of the
66798+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66799+ the RBAC system), and thus does not create privacy concerns.
66800+
66801+config GRKERNSEC_RWXMAP_LOG
66802+ bool 'Denied RWX mmap/mprotect logging'
66803+ default y if GRKERNSEC_CONFIG_AUTO
66804+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66805+ help
66806+ If you say Y here, calls to mmap() and mprotect() with explicit
66807+ usage of PROT_WRITE and PROT_EXEC together will be logged when
66808+ denied by the PAX_MPROTECT feature. This feature will also
66809+ log other problematic scenarios that can occur when PAX_MPROTECT
66810+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
66811+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66812+ is created.
66813+
66814+endmenu
66815+
66816+menu "Executable Protections"
66817+depends on GRKERNSEC
66818+
66819+config GRKERNSEC_DMESG
66820+ bool "Dmesg(8) restriction"
66821+ default y if GRKERNSEC_CONFIG_AUTO
66822+ help
66823+ If you say Y here, non-root users will not be able to use dmesg(8)
66824+ to view the contents of the kernel's circular log buffer.
66825+ The kernel's log buffer often contains kernel addresses and other
66826+ identifying information useful to an attacker in fingerprinting a
66827+ system for a targeted exploit.
66828+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
66829+ created.
66830+
66831+config GRKERNSEC_HARDEN_PTRACE
66832+ bool "Deter ptrace-based process snooping"
66833+ default y if GRKERNSEC_CONFIG_AUTO
66834+ help
66835+ If you say Y here, TTY sniffers and other malicious monitoring
66836+ programs implemented through ptrace will be defeated. If you
66837+ have been using the RBAC system, this option has already been
66838+ enabled for several years for all users, with the ability to make
66839+ fine-grained exceptions.
66840+
66841+ This option only affects the ability of non-root users to ptrace
66842+ processes that are not a descendent of the ptracing process.
66843+ This means that strace ./binary and gdb ./binary will still work,
66844+ but attaching to arbitrary processes will not. If the sysctl
66845+ option is enabled, a sysctl option with name "harden_ptrace" is
66846+ created.
66847+
66848+config GRKERNSEC_PTRACE_READEXEC
66849+ bool "Require read access to ptrace sensitive binaries"
66850+ default y if GRKERNSEC_CONFIG_AUTO
66851+ help
66852+ If you say Y here, unprivileged users will not be able to ptrace unreadable
66853+ binaries. This option is useful in environments that
66854+ remove the read bits (e.g. file mode 4711) from suid binaries to
66855+ prevent infoleaking of their contents. This option adds
66856+ consistency to the use of that file mode, as the binary could normally
66857+ be read out when run without privileges while ptracing.
66858+
66859+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66860+ is created.
66861+
66862+config GRKERNSEC_SETXID
66863+ bool "Enforce consistent multithreaded privileges"
66864+ default y if GRKERNSEC_CONFIG_AUTO
66865+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66866+ help
66867+ If you say Y here, a change from a root uid to a non-root uid
66868+ in a multithreaded application will cause the resulting uids,
66869+ gids, supplementary groups, and capabilities in that thread
66870+ to be propagated to the other threads of the process. In most
66871+ cases this is unnecessary, as glibc will emulate this behavior
66872+ on behalf of the application. Other libcs do not act in the
66873+ same way, allowing the other threads of the process to continue
66874+ running with root privileges. If the sysctl option is enabled,
66875+ a sysctl option with name "consistent_setxid" is created.
66876+
66877+config GRKERNSEC_HARDEN_IPC
66878+ bool "Disallow access to overly-permissive IPC objects"
66879+ default y if GRKERNSEC_CONFIG_AUTO
66880+ depends on SYSVIPC
66881+ help
66882+ If you say Y here, access to overly-permissive IPC objects (shared
66883+ memory, message queues, and semaphores) will be denied for processes
66884+ given the following criteria beyond normal permission checks:
66885+ 1) If the IPC object is world-accessible and the euid doesn't match
66886+ that of the creator or current uid for the IPC object
66887+ 2) If the IPC object is group-accessible and the egid doesn't
66888+ match that of the creator or current gid for the IPC object
66889+ It's a common error to grant too much permission to these objects,
66890+ with impact ranging from denial of service and information leaking to
66891+ privilege escalation. This feature was developed in response to
66892+ research by Tim Brown:
66893+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66894+ who found hundreds of such insecure usages. Processes with
66895+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66896+ If the sysctl option is enabled, a sysctl option with name
66897+ "harden_ipc" is created.
66898+
66899+config GRKERNSEC_TPE
66900+ bool "Trusted Path Execution (TPE)"
66901+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66902+ help
66903+ If you say Y here, you will be able to choose a gid to add to the
66904+ supplementary groups of users you want to mark as "untrusted."
66905+ These users will not be able to execute any files that are not in
66906+ root-owned directories writable only by root. If the sysctl option
66907+ is enabled, a sysctl option with name "tpe" is created.
66908+
66909+config GRKERNSEC_TPE_ALL
66910+ bool "Partially restrict all non-root users"
66911+ depends on GRKERNSEC_TPE
66912+ help
66913+ If you say Y here, all non-root users will be covered under
66914+ a weaker TPE restriction. This is separate from, and in addition to,
66915+ the main TPE options that you have selected elsewhere. Thus, if a
66916+ "trusted" GID is chosen, this restriction applies to even that GID.
66917+ Under this restriction, all non-root users will only be allowed to
66918+ execute files in directories they own that are not group or
66919+ world-writable, or in directories owned by root and writable only by
66920+ root. If the sysctl option is enabled, a sysctl option with name
66921+ "tpe_restrict_all" is created.
66922+
66923+config GRKERNSEC_TPE_INVERT
66924+ bool "Invert GID option"
66925+ depends on GRKERNSEC_TPE
66926+ help
66927+ If you say Y here, the group you specify in the TPE configuration will
66928+ decide what group TPE restrictions will be *disabled* for. This
66929+ option is useful if you want TPE restrictions to be applied to most
66930+ users on the system. If the sysctl option is enabled, a sysctl option
66931+ with name "tpe_invert" is created. Unlike other sysctl options, this
66932+ entry will default to on for backward-compatibility.
66933+
66934+config GRKERNSEC_TPE_GID
66935+ int
66936+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66937+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66938+
66939+config GRKERNSEC_TPE_UNTRUSTED_GID
66940+ int "GID for TPE-untrusted users"
66941+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66942+ default 1005
66943+ help
66944+ Setting this GID determines what group TPE restrictions will be
66945+ *enabled* for. If the sysctl option is enabled, a sysctl option
66946+ with name "tpe_gid" is created.
66947+
66948+config GRKERNSEC_TPE_TRUSTED_GID
66949+ int "GID for TPE-trusted users"
66950+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66951+ default 1005
66952+ help
66953+ Setting this GID determines what group TPE restrictions will be
66954+ *disabled* for. If the sysctl option is enabled, a sysctl option
66955+ with name "tpe_gid" is created.
66956+
66957+endmenu
66958+menu "Network Protections"
66959+depends on GRKERNSEC
66960+
66961+config GRKERNSEC_RANDNET
66962+ bool "Larger entropy pools"
66963+ default y if GRKERNSEC_CONFIG_AUTO
66964+ help
66965+ If you say Y here, the entropy pools used for many features of Linux
66966+ and grsecurity will be doubled in size. Since several grsecurity
66967+ features use additional randomness, it is recommended that you say Y
66968+ here. Saying Y here has a similar effect as modifying
66969+ /proc/sys/kernel/random/poolsize.
66970+
66971+config GRKERNSEC_BLACKHOLE
66972+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66973+ default y if GRKERNSEC_CONFIG_AUTO
66974+ depends on NET
66975+ help
66976+ If you say Y here, neither TCP resets nor ICMP
66977+ destination-unreachable packets will be sent in response to packets
66978+ sent to ports for which no associated listening process exists.
66979+ This feature supports both IPV4 and IPV6 and exempts the
66980+ loopback interface from blackholing. Enabling this feature
66981+ makes a host more resilient to DoS attacks and reduces network
66982+ visibility against scanners.
66983+
66984+ The blackhole feature as-implemented is equivalent to the FreeBSD
66985+ blackhole feature, as it prevents RST responses to all packets, not
66986+ just SYNs. Under most application behavior this causes no
66987+ problems, but applications (like haproxy) may not close certain
66988+ connections in a way that cleanly terminates them on the remote
66989+ end, leaving the remote host in LAST_ACK state. Because of this
66990+ side-effect and to prevent intentional LAST_ACK DoSes, this
66991+ feature also adds automatic mitigation against such attacks.
66992+ The mitigation drastically reduces the amount of time a socket
66993+ can spend in LAST_ACK state. If you're using haproxy and not
66994+ all servers it connects to have this option enabled, consider
66995+ disabling this feature on the haproxy host.
66996+
66997+ If the sysctl option is enabled, two sysctl options with names
66998+ "ip_blackhole" and "lastack_retries" will be created.
66999+ While "ip_blackhole" takes the standard zero/non-zero on/off
67000+ toggle, "lastack_retries" uses the same kinds of values as
67001+ "tcp_retries1" and "tcp_retries2". The default value of 4
67002+ prevents a socket from lasting more than 45 seconds in LAST_ACK
67003+ state.
67004+
67005+config GRKERNSEC_NO_SIMULT_CONNECT
67006+ bool "Disable TCP Simultaneous Connect"
67007+ default y if GRKERNSEC_CONFIG_AUTO
67008+ depends on NET
67009+ help
67010+ If you say Y here, a feature by Willy Tarreau will be enabled that
67011+ removes a weakness in Linux's strict implementation of TCP that
67012+ allows two clients to connect to each other without either entering
67013+ a listening state. The weakness allows an attacker to easily prevent
67014+ a client from connecting to a known server provided the source port
67015+ for the connection is guessed correctly.
67016+
67017+ As the weakness could be used to prevent an antivirus or IPS from
67018+ fetching updates, or prevent an SSL gateway from fetching a CRL,
67019+ it should be eliminated by enabling this option. Though Linux is
67020+ one of few operating systems supporting simultaneous connect, it
67021+ has no legitimate use in practice and is rarely supported by firewalls.
67022+
67023+config GRKERNSEC_SOCKET
67024+ bool "Socket restrictions"
67025+ depends on NET
67026+ help
67027+ If you say Y here, you will be able to choose from several options.
67028+ If you assign a GID on your system and add it to the supplementary
67029+ groups of users you want to restrict socket access to, this patch
67030+ will perform up to three things, based on the option(s) you choose.
67031+
67032+config GRKERNSEC_SOCKET_ALL
67033+ bool "Deny any sockets to group"
67034+ depends on GRKERNSEC_SOCKET
67035+ help
67036+ If you say Y here, you will be able to choose a GID of whose users will
67037+ be unable to connect to other hosts from your machine or run server
67038+ applications from your machine. If the sysctl option is enabled, a
67039+ sysctl option with name "socket_all" is created.
67040+
67041+config GRKERNSEC_SOCKET_ALL_GID
67042+ int "GID to deny all sockets for"
67043+ depends on GRKERNSEC_SOCKET_ALL
67044+ default 1004
67045+ help
67046+ Here you can choose the GID to disable socket access for. Remember to
67047+ add the users you want socket access disabled for to the GID
67048+ specified here. If the sysctl option is enabled, a sysctl option
67049+ with name "socket_all_gid" is created.
67050+
67051+config GRKERNSEC_SOCKET_CLIENT
67052+ bool "Deny client sockets to group"
67053+ depends on GRKERNSEC_SOCKET
67054+ help
67055+ If you say Y here, you will be able to choose a GID of whose users will
67056+ be unable to connect to other hosts from your machine, but will be
67057+ able to run servers. If this option is enabled, all users in the group
67058+ you specify will have to use passive mode when initiating ftp transfers
67059+ from the shell on your machine. If the sysctl option is enabled, a
67060+ sysctl option with name "socket_client" is created.
67061+
67062+config GRKERNSEC_SOCKET_CLIENT_GID
67063+ int "GID to deny client sockets for"
67064+ depends on GRKERNSEC_SOCKET_CLIENT
67065+ default 1003
67066+ help
67067+ Here you can choose the GID to disable client socket access for.
67068+ Remember to add the users you want client socket access disabled for to
67069+ the GID specified here. If the sysctl option is enabled, a sysctl
67070+ option with name "socket_client_gid" is created.
67071+
67072+config GRKERNSEC_SOCKET_SERVER
67073+ bool "Deny server sockets to group"
67074+ depends on GRKERNSEC_SOCKET
67075+ help
67076+ If you say Y here, you will be able to choose a GID of whose users will
67077+ be unable to run server applications from your machine. If the sysctl
67078+ option is enabled, a sysctl option with name "socket_server" is created.
67079+
67080+config GRKERNSEC_SOCKET_SERVER_GID
67081+ int "GID to deny server sockets for"
67082+ depends on GRKERNSEC_SOCKET_SERVER
67083+ default 1002
67084+ help
67085+ Here you can choose the GID to disable server socket access for.
67086+ Remember to add the users you want server socket access disabled for to
67087+ the GID specified here. If the sysctl option is enabled, a sysctl
67088+ option with name "socket_server_gid" is created.
67089+
67090+endmenu
67091+
67092+menu "Physical Protections"
67093+depends on GRKERNSEC
67094+
67095+config GRKERNSEC_DENYUSB
67096+ bool "Deny new USB connections after toggle"
67097+ default y if GRKERNSEC_CONFIG_AUTO
67098+ depends on SYSCTL && USB_SUPPORT
67099+ help
67100+ If you say Y here, a new sysctl option with name "deny_new_usb"
67101+ will be created. Setting its value to 1 will prevent any new
67102+ USB devices from being recognized by the OS. Any attempted USB
67103+ device insertion will be logged. This option is intended to be
67104+ used against custom USB devices designed to exploit vulnerabilities
67105+ in various USB device drivers.
67106+
67107+ For greatest effectiveness, this sysctl should be set after any
67108+ relevant init scripts. This option is safe to enable in distros
67109+ as each user can choose whether or not to toggle the sysctl.
67110+
67111+config GRKERNSEC_DENYUSB_FORCE
67112+ bool "Reject all USB devices not connected at boot"
67113+ select USB
67114+ depends on GRKERNSEC_DENYUSB
67115+ help
67116+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
67117+ that doesn't involve a sysctl entry. This option should only be
67118+ enabled if you're sure you want to deny all new USB connections
67119+ at runtime and don't want to modify init scripts. This should not
67120+ be enabled by distros. It forces the core USB code to be built
67121+ into the kernel image so that all devices connected at boot time
67122+ can be recognized and new USB device connections can be prevented
67123+ prior to init running.
67124+
67125+endmenu
67126+
67127+menu "Sysctl Support"
67128+depends on GRKERNSEC && SYSCTL
67129+
67130+config GRKERNSEC_SYSCTL
67131+ bool "Sysctl support"
67132+ default y if GRKERNSEC_CONFIG_AUTO
67133+ help
67134+ If you say Y here, you will be able to change the options that
67135+ grsecurity runs with at bootup, without having to recompile your
67136+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
67137+ to enable (1) or disable (0) various features. All the sysctl entries
67138+ are mutable until the "grsec_lock" entry is set to a non-zero value.
67139+ All features enabled in the kernel configuration are disabled at boot
67140+ if you do not say Y to the "Turn on features by default" option.
67141+ All options should be set at startup, and the grsec_lock entry should
67142+ be set to a non-zero value after all the options are set.
67143+ *THIS IS EXTREMELY IMPORTANT*
67144+
67145+config GRKERNSEC_SYSCTL_DISTRO
67146+ bool "Extra sysctl support for distro makers (READ HELP)"
67147+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
67148+ help
67149+ If you say Y here, additional sysctl options will be created
67150+ for features that affect processes running as root. Therefore,
67151+ it is critical when using this option that the grsec_lock entry be
67152+ enabled after boot. Only distros with prebuilt kernel packages
67153+ with this option enabled that can ensure grsec_lock is enabled
67154+ after boot should use this option.
67155+ *Failure to set grsec_lock after boot makes all grsec features
67156+ this option covers useless*
67157+
67158+ Currently this option creates the following sysctl entries:
67159+ "Disable Privileged I/O": "disable_priv_io"
67160+
67161+config GRKERNSEC_SYSCTL_ON
67162+ bool "Turn on features by default"
67163+ default y if GRKERNSEC_CONFIG_AUTO
67164+ depends on GRKERNSEC_SYSCTL
67165+ help
67166+ If you say Y here, instead of having all features enabled in the
67167+ kernel configuration disabled at boot time, the features will be
67168+ enabled at boot time. It is recommended you say Y here unless
67169+ there is some reason you would want all sysctl-tunable features to
67170+ be disabled by default. As mentioned elsewhere, it is important
67171+ to enable the grsec_lock entry once you have finished modifying
67172+ the sysctl entries.
67173+
67174+endmenu
67175+menu "Logging Options"
67176+depends on GRKERNSEC
67177+
67178+config GRKERNSEC_FLOODTIME
67179+ int "Seconds in between log messages (minimum)"
67180+ default 10
67181+ help
67182+ This option allows you to enforce the number of seconds between
67183+ grsecurity log messages. The default should be suitable for most
67184+ people, however, if you choose to change it, choose a value small enough
67185+ to allow informative logs to be produced, but large enough to
67186+ prevent flooding.
67187+
67188+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
67189+ any rate limiting on grsecurity log messages.
67190+
67191+config GRKERNSEC_FLOODBURST
67192+ int "Number of messages in a burst (maximum)"
67193+ default 6
67194+ help
67195+ This option allows you to choose the maximum number of messages allowed
67196+ within the flood time interval you chose in a separate option. The
67197+ default should be suitable for most people, however if you find that
67198+ many of your logs are being interpreted as flooding, you may want to
67199+ raise this value.
67200+
67201+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
67202+ any rate limiting on grsecurity log messages.
67203+
67204+endmenu
67205diff --git a/grsecurity/Makefile b/grsecurity/Makefile
67206new file mode 100644
67207index 0000000..30ababb
67208--- /dev/null
67209+++ b/grsecurity/Makefile
67210@@ -0,0 +1,54 @@
67211+# grsecurity – access control and security hardening for Linux
67212+# All code in this directory and various hooks located throughout the Linux kernel are
67213+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
67214+# http://www.grsecurity.net spender@grsecurity.net
67215+#
67216+# This program is free software; you can redistribute it and/or
67217+# modify it under the terms of the GNU General Public License version 2
67218+# as published by the Free Software Foundation.
67219+#
67220+# This program is distributed in the hope that it will be useful,
67221+# but WITHOUT ANY WARRANTY; without even the implied warranty of
67222+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67223+# GNU General Public License for more details.
67224+#
67225+# You should have received a copy of the GNU General Public License
67226+# along with this program; if not, write to the Free Software
67227+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
67228+
67229+KBUILD_CFLAGS += -Werror
67230+
67231+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
67232+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
67233+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
67234+ grsec_usb.o grsec_ipc.o grsec_proc.o
67235+
67236+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
67237+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
67238+ gracl_learn.o grsec_log.o gracl_policy.o
67239+ifdef CONFIG_COMPAT
67240+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
67241+endif
67242+
67243+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
67244+
67245+ifdef CONFIG_NET
67246+obj-y += grsec_sock.o
67247+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
67248+endif
67249+
67250+ifndef CONFIG_GRKERNSEC
67251+obj-y += grsec_disabled.o
67252+endif
67253+
67254+ifdef CONFIG_GRKERNSEC_HIDESYM
67255+extra-y := grsec_hidesym.o
67256+$(obj)/grsec_hidesym.o:
67257+ @-chmod -f 500 /boot
67258+ @-chmod -f 500 /lib/modules
67259+ @-chmod -f 500 /lib64/modules
67260+ @-chmod -f 500 /lib32/modules
67261+ @-chmod -f 700 .
67262+ @-chmod -f 700 $(objtree)
67263+ @echo ' grsec: protected kernel image paths'
67264+endif
67265diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
67266new file mode 100644
67267index 0000000..e56396f
67268--- /dev/null
67269+++ b/grsecurity/gracl.c
67270@@ -0,0 +1,2679 @@
67271+#include <linux/kernel.h>
67272+#include <linux/module.h>
67273+#include <linux/sched.h>
67274+#include <linux/mm.h>
67275+#include <linux/file.h>
67276+#include <linux/fs.h>
67277+#include <linux/namei.h>
67278+#include <linux/mount.h>
67279+#include <linux/tty.h>
67280+#include <linux/proc_fs.h>
67281+#include <linux/lglock.h>
67282+#include <linux/slab.h>
67283+#include <linux/vmalloc.h>
67284+#include <linux/types.h>
67285+#include <linux/sysctl.h>
67286+#include <linux/netdevice.h>
67287+#include <linux/ptrace.h>
67288+#include <linux/gracl.h>
67289+#include <linux/gralloc.h>
67290+#include <linux/security.h>
67291+#include <linux/grinternal.h>
67292+#include <linux/pid_namespace.h>
67293+#include <linux/stop_machine.h>
67294+#include <linux/fdtable.h>
67295+#include <linux/percpu.h>
67296+#include <linux/lglock.h>
67297+#include <linux/hugetlb.h>
67298+#include <linux/posix-timers.h>
67299+#include <linux/prefetch.h>
67300+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67301+#include <linux/magic.h>
67302+#include <linux/pagemap.h>
67303+#include "../fs/btrfs/async-thread.h"
67304+#include "../fs/btrfs/ctree.h"
67305+#include "../fs/btrfs/btrfs_inode.h"
67306+#endif
67307+#include "../fs/mount.h"
67308+
67309+#include <asm/uaccess.h>
67310+#include <asm/errno.h>
67311+#include <asm/mman.h>
67312+
67313+#define FOR_EACH_ROLE_START(role) \
67314+ role = running_polstate.role_list; \
67315+ while (role) {
67316+
67317+#define FOR_EACH_ROLE_END(role) \
67318+ role = role->prev; \
67319+ }
67320+
67321+extern struct path gr_real_root;
67322+
67323+static struct gr_policy_state running_polstate;
67324+struct gr_policy_state *polstate = &running_polstate;
67325+extern struct gr_alloc_state *current_alloc_state;
67326+
67327+extern char *gr_shared_page[4];
67328+DEFINE_RWLOCK(gr_inode_lock);
67329+
67330+static unsigned int gr_status __read_only = GR_STATUS_INIT;
67331+
67332+#ifdef CONFIG_NET
67333+extern struct vfsmount *sock_mnt;
67334+#endif
67335+
67336+extern struct vfsmount *pipe_mnt;
67337+extern struct vfsmount *shm_mnt;
67338+
67339+#ifdef CONFIG_HUGETLBFS
67340+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
67341+#endif
67342+
67343+extern u16 acl_sp_role_value;
67344+extern struct acl_object_label *fakefs_obj_rw;
67345+extern struct acl_object_label *fakefs_obj_rwx;
67346+
67347+int gr_acl_is_enabled(void)
67348+{
67349+ return (gr_status & GR_READY);
67350+}
67351+
67352+void gr_enable_rbac_system(void)
67353+{
67354+ pax_open_kernel();
67355+ gr_status |= GR_READY;
67356+ pax_close_kernel();
67357+}
67358+
67359+int gr_rbac_disable(void *unused)
67360+{
67361+ pax_open_kernel();
67362+ gr_status &= ~GR_READY;
67363+ pax_close_kernel();
67364+
67365+ return 0;
67366+}
67367+
67368+static inline dev_t __get_dev(const struct dentry *dentry)
67369+{
67370+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67371+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67372+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67373+ else
67374+#endif
67375+ return dentry->d_sb->s_dev;
67376+}
67377+
67378+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67379+{
67380+ return __get_dev(dentry);
67381+}
67382+
67383+static char gr_task_roletype_to_char(struct task_struct *task)
67384+{
67385+ switch (task->role->roletype &
67386+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
67387+ GR_ROLE_SPECIAL)) {
67388+ case GR_ROLE_DEFAULT:
67389+ return 'D';
67390+ case GR_ROLE_USER:
67391+ return 'U';
67392+ case GR_ROLE_GROUP:
67393+ return 'G';
67394+ case GR_ROLE_SPECIAL:
67395+ return 'S';
67396+ }
67397+
67398+ return 'X';
67399+}
67400+
67401+char gr_roletype_to_char(void)
67402+{
67403+ return gr_task_roletype_to_char(current);
67404+}
67405+
67406+__inline__ int
67407+gr_acl_tpe_check(void)
67408+{
67409+ if (unlikely(!(gr_status & GR_READY)))
67410+ return 0;
67411+ if (current->role->roletype & GR_ROLE_TPE)
67412+ return 1;
67413+ else
67414+ return 0;
67415+}
67416+
67417+int
67418+gr_handle_rawio(const struct inode *inode)
67419+{
67420+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67421+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
67422+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
67423+ !capable(CAP_SYS_RAWIO))
67424+ return 1;
67425+#endif
67426+ return 0;
67427+}
67428+
67429+int
67430+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
67431+{
67432+ if (likely(lena != lenb))
67433+ return 0;
67434+
67435+ return !memcmp(a, b, lena);
67436+}
67437+
67438+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
67439+{
67440+ *buflen -= namelen;
67441+ if (*buflen < 0)
67442+ return -ENAMETOOLONG;
67443+ *buffer -= namelen;
67444+ memcpy(*buffer, str, namelen);
67445+ return 0;
67446+}
67447+
67448+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67449+{
67450+ return prepend(buffer, buflen, name->name, name->len);
67451+}
67452+
67453+static int prepend_path(const struct path *path, struct path *root,
67454+ char **buffer, int *buflen)
67455+{
67456+ struct dentry *dentry = path->dentry;
67457+ struct vfsmount *vfsmnt = path->mnt;
67458+ struct mount *mnt = real_mount(vfsmnt);
67459+ bool slash = false;
67460+ int error = 0;
67461+
67462+ while (dentry != root->dentry || vfsmnt != root->mnt) {
67463+ struct dentry * parent;
67464+
67465+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67466+ /* Global root? */
67467+ if (!mnt_has_parent(mnt)) {
67468+ goto out;
67469+ }
67470+ dentry = mnt->mnt_mountpoint;
67471+ mnt = mnt->mnt_parent;
67472+ vfsmnt = &mnt->mnt;
67473+ continue;
67474+ }
67475+ parent = dentry->d_parent;
67476+ prefetch(parent);
67477+ spin_lock(&dentry->d_lock);
67478+ error = prepend_name(buffer, buflen, &dentry->d_name);
67479+ spin_unlock(&dentry->d_lock);
67480+ if (!error)
67481+ error = prepend(buffer, buflen, "/", 1);
67482+ if (error)
67483+ break;
67484+
67485+ slash = true;
67486+ dentry = parent;
67487+ }
67488+
67489+out:
67490+ if (!error && !slash)
67491+ error = prepend(buffer, buflen, "/", 1);
67492+
67493+ return error;
67494+}
67495+
67496+/* this must be called with mount_lock and rename_lock held */
67497+
67498+static char *__our_d_path(const struct path *path, struct path *root,
67499+ char *buf, int buflen)
67500+{
67501+ char *res = buf + buflen;
67502+ int error;
67503+
67504+ prepend(&res, &buflen, "\0", 1);
67505+ error = prepend_path(path, root, &res, &buflen);
67506+ if (error)
67507+ return ERR_PTR(error);
67508+
67509+ return res;
67510+}
67511+
67512+static char *
67513+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67514+{
67515+ char *retval;
67516+
67517+ retval = __our_d_path(path, root, buf, buflen);
67518+ if (unlikely(IS_ERR(retval)))
67519+ retval = strcpy(buf, "<path too long>");
67520+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67521+ retval[1] = '\0';
67522+
67523+ return retval;
67524+}
67525+
67526+static char *
67527+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67528+ char *buf, int buflen)
67529+{
67530+ struct path path;
67531+ char *res;
67532+
67533+ path.dentry = (struct dentry *)dentry;
67534+ path.mnt = (struct vfsmount *)vfsmnt;
67535+
67536+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67537+ by the RBAC system */
67538+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
67539+
67540+ return res;
67541+}
67542+
67543+static char *
67544+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67545+ char *buf, int buflen)
67546+{
67547+ char *res;
67548+ struct path path;
67549+ struct path root;
67550+ struct task_struct *reaper = init_pid_ns.child_reaper;
67551+
67552+ path.dentry = (struct dentry *)dentry;
67553+ path.mnt = (struct vfsmount *)vfsmnt;
67554+
67555+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67556+ get_fs_root(reaper->fs, &root);
67557+
67558+ read_seqlock_excl(&mount_lock);
67559+ write_seqlock(&rename_lock);
67560+ res = gen_full_path(&path, &root, buf, buflen);
67561+ write_sequnlock(&rename_lock);
67562+ read_sequnlock_excl(&mount_lock);
67563+
67564+ path_put(&root);
67565+ return res;
67566+}
67567+
67568+char *
67569+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67570+{
67571+ char *ret;
67572+ read_seqlock_excl(&mount_lock);
67573+ write_seqlock(&rename_lock);
67574+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67575+ PAGE_SIZE);
67576+ write_sequnlock(&rename_lock);
67577+ read_sequnlock_excl(&mount_lock);
67578+ return ret;
67579+}
67580+
67581+static char *
67582+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67583+{
67584+ char *ret;
67585+ char *buf;
67586+ int buflen;
67587+
67588+ read_seqlock_excl(&mount_lock);
67589+ write_seqlock(&rename_lock);
67590+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67591+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67592+ buflen = (int)(ret - buf);
67593+ if (buflen >= 5)
67594+ prepend(&ret, &buflen, "/proc", 5);
67595+ else
67596+ ret = strcpy(buf, "<path too long>");
67597+ write_sequnlock(&rename_lock);
67598+ read_sequnlock_excl(&mount_lock);
67599+ return ret;
67600+}
67601+
67602+char *
67603+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67604+{
67605+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67606+ PAGE_SIZE);
67607+}
67608+
67609+char *
67610+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67611+{
67612+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67613+ PAGE_SIZE);
67614+}
67615+
67616+char *
67617+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67618+{
67619+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67620+ PAGE_SIZE);
67621+}
67622+
67623+char *
67624+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67625+{
67626+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67627+ PAGE_SIZE);
67628+}
67629+
67630+char *
67631+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67632+{
67633+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67634+ PAGE_SIZE);
67635+}
67636+
67637+__inline__ __u32
67638+to_gr_audit(const __u32 reqmode)
67639+{
67640+ /* masks off auditable permission flags, then shifts them to create
67641+ auditing flags, and adds the special case of append auditing if
67642+ we're requesting write */
67643+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67644+}
67645+
67646+struct acl_role_label *
67647+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67648+ const gid_t gid)
67649+{
67650+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67651+ struct acl_role_label *match;
67652+ struct role_allowed_ip *ipp;
67653+ unsigned int x;
67654+ u32 curr_ip = task->signal->saved_ip;
67655+
67656+ match = state->acl_role_set.r_hash[index];
67657+
67658+ while (match) {
67659+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67660+ for (x = 0; x < match->domain_child_num; x++) {
67661+ if (match->domain_children[x] == uid)
67662+ goto found;
67663+ }
67664+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67665+ break;
67666+ match = match->next;
67667+ }
67668+found:
67669+ if (match == NULL) {
67670+ try_group:
67671+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67672+ match = state->acl_role_set.r_hash[index];
67673+
67674+ while (match) {
67675+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67676+ for (x = 0; x < match->domain_child_num; x++) {
67677+ if (match->domain_children[x] == gid)
67678+ goto found2;
67679+ }
67680+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67681+ break;
67682+ match = match->next;
67683+ }
67684+found2:
67685+ if (match == NULL)
67686+ match = state->default_role;
67687+ if (match->allowed_ips == NULL)
67688+ return match;
67689+ else {
67690+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67691+ if (likely
67692+ ((ntohl(curr_ip) & ipp->netmask) ==
67693+ (ntohl(ipp->addr) & ipp->netmask)))
67694+ return match;
67695+ }
67696+ match = state->default_role;
67697+ }
67698+ } else if (match->allowed_ips == NULL) {
67699+ return match;
67700+ } else {
67701+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67702+ if (likely
67703+ ((ntohl(curr_ip) & ipp->netmask) ==
67704+ (ntohl(ipp->addr) & ipp->netmask)))
67705+ return match;
67706+ }
67707+ goto try_group;
67708+ }
67709+
67710+ return match;
67711+}
67712+
67713+static struct acl_role_label *
67714+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67715+ const gid_t gid)
67716+{
67717+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67718+}
67719+
67720+struct acl_subject_label *
67721+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67722+ const struct acl_role_label *role)
67723+{
67724+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67725+ struct acl_subject_label *match;
67726+
67727+ match = role->subj_hash[index];
67728+
67729+ while (match && (match->inode != ino || match->device != dev ||
67730+ (match->mode & GR_DELETED))) {
67731+ match = match->next;
67732+ }
67733+
67734+ if (match && !(match->mode & GR_DELETED))
67735+ return match;
67736+ else
67737+ return NULL;
67738+}
67739+
67740+struct acl_subject_label *
67741+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67742+ const struct acl_role_label *role)
67743+{
67744+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67745+ struct acl_subject_label *match;
67746+
67747+ match = role->subj_hash[index];
67748+
67749+ while (match && (match->inode != ino || match->device != dev ||
67750+ !(match->mode & GR_DELETED))) {
67751+ match = match->next;
67752+ }
67753+
67754+ if (match && (match->mode & GR_DELETED))
67755+ return match;
67756+ else
67757+ return NULL;
67758+}
67759+
67760+static struct acl_object_label *
67761+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67762+ const struct acl_subject_label *subj)
67763+{
67764+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67765+ struct acl_object_label *match;
67766+
67767+ match = subj->obj_hash[index];
67768+
67769+ while (match && (match->inode != ino || match->device != dev ||
67770+ (match->mode & GR_DELETED))) {
67771+ match = match->next;
67772+ }
67773+
67774+ if (match && !(match->mode & GR_DELETED))
67775+ return match;
67776+ else
67777+ return NULL;
67778+}
67779+
67780+static struct acl_object_label *
67781+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67782+ const struct acl_subject_label *subj)
67783+{
67784+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67785+ struct acl_object_label *match;
67786+
67787+ match = subj->obj_hash[index];
67788+
67789+ while (match && (match->inode != ino || match->device != dev ||
67790+ !(match->mode & GR_DELETED))) {
67791+ match = match->next;
67792+ }
67793+
67794+ if (match && (match->mode & GR_DELETED))
67795+ return match;
67796+
67797+ match = subj->obj_hash[index];
67798+
67799+ while (match && (match->inode != ino || match->device != dev ||
67800+ (match->mode & GR_DELETED))) {
67801+ match = match->next;
67802+ }
67803+
67804+ if (match && !(match->mode & GR_DELETED))
67805+ return match;
67806+ else
67807+ return NULL;
67808+}
67809+
67810+struct name_entry *
67811+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67812+{
67813+ unsigned int len = strlen(name);
67814+ unsigned int key = full_name_hash(name, len);
67815+ unsigned int index = key % state->name_set.n_size;
67816+ struct name_entry *match;
67817+
67818+ match = state->name_set.n_hash[index];
67819+
67820+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67821+ match = match->next;
67822+
67823+ return match;
67824+}
67825+
67826+static struct name_entry *
67827+lookup_name_entry(const char *name)
67828+{
67829+ return __lookup_name_entry(&running_polstate, name);
67830+}
67831+
67832+static struct name_entry *
67833+lookup_name_entry_create(const char *name)
67834+{
67835+ unsigned int len = strlen(name);
67836+ unsigned int key = full_name_hash(name, len);
67837+ unsigned int index = key % running_polstate.name_set.n_size;
67838+ struct name_entry *match;
67839+
67840+ match = running_polstate.name_set.n_hash[index];
67841+
67842+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67843+ !match->deleted))
67844+ match = match->next;
67845+
67846+ if (match && match->deleted)
67847+ return match;
67848+
67849+ match = running_polstate.name_set.n_hash[index];
67850+
67851+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67852+ match->deleted))
67853+ match = match->next;
67854+
67855+ if (match && !match->deleted)
67856+ return match;
67857+ else
67858+ return NULL;
67859+}
67860+
67861+static struct inodev_entry *
67862+lookup_inodev_entry(const ino_t ino, const dev_t dev)
67863+{
67864+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67865+ struct inodev_entry *match;
67866+
67867+ match = running_polstate.inodev_set.i_hash[index];
67868+
67869+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67870+ match = match->next;
67871+
67872+ return match;
67873+}
67874+
67875+void
67876+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67877+{
67878+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67879+ state->inodev_set.i_size);
67880+ struct inodev_entry **curr;
67881+
67882+ entry->prev = NULL;
67883+
67884+ curr = &state->inodev_set.i_hash[index];
67885+ if (*curr != NULL)
67886+ (*curr)->prev = entry;
67887+
67888+ entry->next = *curr;
67889+ *curr = entry;
67890+
67891+ return;
67892+}
67893+
67894+static void
67895+insert_inodev_entry(struct inodev_entry *entry)
67896+{
67897+ __insert_inodev_entry(&running_polstate, entry);
67898+}
67899+
67900+void
67901+insert_acl_obj_label(struct acl_object_label *obj,
67902+ struct acl_subject_label *subj)
67903+{
67904+ unsigned int index =
67905+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67906+ struct acl_object_label **curr;
67907+
67908+ obj->prev = NULL;
67909+
67910+ curr = &subj->obj_hash[index];
67911+ if (*curr != NULL)
67912+ (*curr)->prev = obj;
67913+
67914+ obj->next = *curr;
67915+ *curr = obj;
67916+
67917+ return;
67918+}
67919+
67920+void
67921+insert_acl_subj_label(struct acl_subject_label *obj,
67922+ struct acl_role_label *role)
67923+{
67924+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67925+ struct acl_subject_label **curr;
67926+
67927+ obj->prev = NULL;
67928+
67929+ curr = &role->subj_hash[index];
67930+ if (*curr != NULL)
67931+ (*curr)->prev = obj;
67932+
67933+ obj->next = *curr;
67934+ *curr = obj;
67935+
67936+ return;
67937+}
67938+
67939+/* derived from glibc fnmatch() 0: match, 1: no match*/
67940+
67941+static int
67942+glob_match(const char *p, const char *n)
67943+{
67944+ char c;
67945+
67946+ while ((c = *p++) != '\0') {
67947+ switch (c) {
67948+ case '?':
67949+ if (*n == '\0')
67950+ return 1;
67951+ else if (*n == '/')
67952+ return 1;
67953+ break;
67954+ case '\\':
67955+ if (*n != c)
67956+ return 1;
67957+ break;
67958+ case '*':
67959+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67960+ if (*n == '/')
67961+ return 1;
67962+ else if (c == '?') {
67963+ if (*n == '\0')
67964+ return 1;
67965+ else
67966+ ++n;
67967+ }
67968+ }
67969+ if (c == '\0') {
67970+ return 0;
67971+ } else {
67972+ const char *endp;
67973+
67974+ if ((endp = strchr(n, '/')) == NULL)
67975+ endp = n + strlen(n);
67976+
67977+ if (c == '[') {
67978+ for (--p; n < endp; ++n)
67979+ if (!glob_match(p, n))
67980+ return 0;
67981+ } else if (c == '/') {
67982+ while (*n != '\0' && *n != '/')
67983+ ++n;
67984+ if (*n == '/' && !glob_match(p, n + 1))
67985+ return 0;
67986+ } else {
67987+ for (--p; n < endp; ++n)
67988+ if (*n == c && !glob_match(p, n))
67989+ return 0;
67990+ }
67991+
67992+ return 1;
67993+ }
67994+ case '[':
67995+ {
67996+ int not;
67997+ char cold;
67998+
67999+ if (*n == '\0' || *n == '/')
68000+ return 1;
68001+
68002+ not = (*p == '!' || *p == '^');
68003+ if (not)
68004+ ++p;
68005+
68006+ c = *p++;
68007+ for (;;) {
68008+ unsigned char fn = (unsigned char)*n;
68009+
68010+ if (c == '\0')
68011+ return 1;
68012+ else {
68013+ if (c == fn)
68014+ goto matched;
68015+ cold = c;
68016+ c = *p++;
68017+
68018+ if (c == '-' && *p != ']') {
68019+ unsigned char cend = *p++;
68020+
68021+ if (cend == '\0')
68022+ return 1;
68023+
68024+ if (cold <= fn && fn <= cend)
68025+ goto matched;
68026+
68027+ c = *p++;
68028+ }
68029+ }
68030+
68031+ if (c == ']')
68032+ break;
68033+ }
68034+ if (!not)
68035+ return 1;
68036+ break;
68037+ matched:
68038+ while (c != ']') {
68039+ if (c == '\0')
68040+ return 1;
68041+
68042+ c = *p++;
68043+ }
68044+ if (not)
68045+ return 1;
68046+ }
68047+ break;
68048+ default:
68049+ if (c != *n)
68050+ return 1;
68051+ }
68052+
68053+ ++n;
68054+ }
68055+
68056+ if (*n == '\0')
68057+ return 0;
68058+
68059+ if (*n == '/')
68060+ return 0;
68061+
68062+ return 1;
68063+}
68064+
68065+static struct acl_object_label *
68066+chk_glob_label(struct acl_object_label *globbed,
68067+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
68068+{
68069+ struct acl_object_label *tmp;
68070+
68071+ if (*path == NULL)
68072+ *path = gr_to_filename_nolock(dentry, mnt);
68073+
68074+ tmp = globbed;
68075+
68076+ while (tmp) {
68077+ if (!glob_match(tmp->filename, *path))
68078+ return tmp;
68079+ tmp = tmp->next;
68080+ }
68081+
68082+ return NULL;
68083+}
68084+
68085+static struct acl_object_label *
68086+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68087+ const ino_t curr_ino, const dev_t curr_dev,
68088+ const struct acl_subject_label *subj, char **path, const int checkglob)
68089+{
68090+ struct acl_subject_label *tmpsubj;
68091+ struct acl_object_label *retval;
68092+ struct acl_object_label *retval2;
68093+
68094+ tmpsubj = (struct acl_subject_label *) subj;
68095+ read_lock(&gr_inode_lock);
68096+ do {
68097+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
68098+ if (retval) {
68099+ if (checkglob && retval->globbed) {
68100+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
68101+ if (retval2)
68102+ retval = retval2;
68103+ }
68104+ break;
68105+ }
68106+ } while ((tmpsubj = tmpsubj->parent_subject));
68107+ read_unlock(&gr_inode_lock);
68108+
68109+ return retval;
68110+}
68111+
68112+static __inline__ struct acl_object_label *
68113+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68114+ struct dentry *curr_dentry,
68115+ const struct acl_subject_label *subj, char **path, const int checkglob)
68116+{
68117+ int newglob = checkglob;
68118+ ino_t inode;
68119+ dev_t device;
68120+
68121+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
68122+ as we don't want a / * rule to match instead of the / object
68123+ don't do this for create lookups that call this function though, since they're looking up
68124+ on the parent and thus need globbing checks on all paths
68125+ */
68126+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
68127+ newglob = GR_NO_GLOB;
68128+
68129+ spin_lock(&curr_dentry->d_lock);
68130+ inode = curr_dentry->d_inode->i_ino;
68131+ device = __get_dev(curr_dentry);
68132+ spin_unlock(&curr_dentry->d_lock);
68133+
68134+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
68135+}
68136+
68137+#ifdef CONFIG_HUGETLBFS
68138+static inline bool
68139+is_hugetlbfs_mnt(const struct vfsmount *mnt)
68140+{
68141+ int i;
68142+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
68143+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
68144+ return true;
68145+ }
68146+
68147+ return false;
68148+}
68149+#endif
68150+
68151+static struct acl_object_label *
68152+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68153+ const struct acl_subject_label *subj, char *path, const int checkglob)
68154+{
68155+ struct dentry *dentry = (struct dentry *) l_dentry;
68156+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68157+ struct mount *real_mnt = real_mount(mnt);
68158+ struct acl_object_label *retval;
68159+ struct dentry *parent;
68160+
68161+ read_seqlock_excl(&mount_lock);
68162+ write_seqlock(&rename_lock);
68163+
68164+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
68165+#ifdef CONFIG_NET
68166+ mnt == sock_mnt ||
68167+#endif
68168+#ifdef CONFIG_HUGETLBFS
68169+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
68170+#endif
68171+ /* ignore Eric Biederman */
68172+ IS_PRIVATE(l_dentry->d_inode))) {
68173+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
68174+ goto out;
68175+ }
68176+
68177+ for (;;) {
68178+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68179+ break;
68180+
68181+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68182+ if (!mnt_has_parent(real_mnt))
68183+ break;
68184+
68185+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68186+ if (retval != NULL)
68187+ goto out;
68188+
68189+ dentry = real_mnt->mnt_mountpoint;
68190+ real_mnt = real_mnt->mnt_parent;
68191+ mnt = &real_mnt->mnt;
68192+ continue;
68193+ }
68194+
68195+ parent = dentry->d_parent;
68196+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68197+ if (retval != NULL)
68198+ goto out;
68199+
68200+ dentry = parent;
68201+ }
68202+
68203+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68204+
68205+ /* gr_real_root is pinned so we don't have to hold a reference */
68206+ if (retval == NULL)
68207+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
68208+out:
68209+ write_sequnlock(&rename_lock);
68210+ read_sequnlock_excl(&mount_lock);
68211+
68212+ BUG_ON(retval == NULL);
68213+
68214+ return retval;
68215+}
68216+
68217+static __inline__ struct acl_object_label *
68218+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68219+ const struct acl_subject_label *subj)
68220+{
68221+ char *path = NULL;
68222+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
68223+}
68224+
68225+static __inline__ struct acl_object_label *
68226+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68227+ const struct acl_subject_label *subj)
68228+{
68229+ char *path = NULL;
68230+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
68231+}
68232+
68233+static __inline__ struct acl_object_label *
68234+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68235+ const struct acl_subject_label *subj, char *path)
68236+{
68237+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
68238+}
68239+
68240+struct acl_subject_label *
68241+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68242+ const struct acl_role_label *role)
68243+{
68244+ struct dentry *dentry = (struct dentry *) l_dentry;
68245+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68246+ struct mount *real_mnt = real_mount(mnt);
68247+ struct acl_subject_label *retval;
68248+ struct dentry *parent;
68249+
68250+ read_seqlock_excl(&mount_lock);
68251+ write_seqlock(&rename_lock);
68252+
68253+ for (;;) {
68254+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68255+ break;
68256+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68257+ if (!mnt_has_parent(real_mnt))
68258+ break;
68259+
68260+ spin_lock(&dentry->d_lock);
68261+ read_lock(&gr_inode_lock);
68262+ retval =
68263+ lookup_acl_subj_label(dentry->d_inode->i_ino,
68264+ __get_dev(dentry), role);
68265+ read_unlock(&gr_inode_lock);
68266+ spin_unlock(&dentry->d_lock);
68267+ if (retval != NULL)
68268+ goto out;
68269+
68270+ dentry = real_mnt->mnt_mountpoint;
68271+ real_mnt = real_mnt->mnt_parent;
68272+ mnt = &real_mnt->mnt;
68273+ continue;
68274+ }
68275+
68276+ spin_lock(&dentry->d_lock);
68277+ read_lock(&gr_inode_lock);
68278+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68279+ __get_dev(dentry), role);
68280+ read_unlock(&gr_inode_lock);
68281+ parent = dentry->d_parent;
68282+ spin_unlock(&dentry->d_lock);
68283+
68284+ if (retval != NULL)
68285+ goto out;
68286+
68287+ dentry = parent;
68288+ }
68289+
68290+ spin_lock(&dentry->d_lock);
68291+ read_lock(&gr_inode_lock);
68292+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68293+ __get_dev(dentry), role);
68294+ read_unlock(&gr_inode_lock);
68295+ spin_unlock(&dentry->d_lock);
68296+
68297+ if (unlikely(retval == NULL)) {
68298+ /* gr_real_root is pinned, we don't need to hold a reference */
68299+ read_lock(&gr_inode_lock);
68300+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
68301+ __get_dev(gr_real_root.dentry), role);
68302+ read_unlock(&gr_inode_lock);
68303+ }
68304+out:
68305+ write_sequnlock(&rename_lock);
68306+ read_sequnlock_excl(&mount_lock);
68307+
68308+ BUG_ON(retval == NULL);
68309+
68310+ return retval;
68311+}
68312+
68313+void
68314+assign_special_role(const char *rolename)
68315+{
68316+ struct acl_object_label *obj;
68317+ struct acl_role_label *r;
68318+ struct acl_role_label *assigned = NULL;
68319+ struct task_struct *tsk;
68320+ struct file *filp;
68321+
68322+ FOR_EACH_ROLE_START(r)
68323+ if (!strcmp(rolename, r->rolename) &&
68324+ (r->roletype & GR_ROLE_SPECIAL)) {
68325+ assigned = r;
68326+ break;
68327+ }
68328+ FOR_EACH_ROLE_END(r)
68329+
68330+ if (!assigned)
68331+ return;
68332+
68333+ read_lock(&tasklist_lock);
68334+ read_lock(&grsec_exec_file_lock);
68335+
68336+ tsk = current->real_parent;
68337+ if (tsk == NULL)
68338+ goto out_unlock;
68339+
68340+ filp = tsk->exec_file;
68341+ if (filp == NULL)
68342+ goto out_unlock;
68343+
68344+ tsk->is_writable = 0;
68345+ tsk->inherited = 0;
68346+
68347+ tsk->acl_sp_role = 1;
68348+ tsk->acl_role_id = ++acl_sp_role_value;
68349+ tsk->role = assigned;
68350+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
68351+
68352+ /* ignore additional mmap checks for processes that are writable
68353+ by the default ACL */
68354+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68355+ if (unlikely(obj->mode & GR_WRITE))
68356+ tsk->is_writable = 1;
68357+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
68358+ if (unlikely(obj->mode & GR_WRITE))
68359+ tsk->is_writable = 1;
68360+
68361+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68362+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
68363+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
68364+#endif
68365+
68366+out_unlock:
68367+ read_unlock(&grsec_exec_file_lock);
68368+ read_unlock(&tasklist_lock);
68369+ return;
68370+}
68371+
68372+
68373+static void
68374+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
68375+{
68376+ struct task_struct *task = current;
68377+ const struct cred *cred = current_cred();
68378+
68379+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
68380+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68381+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68382+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
68383+
68384+ return;
68385+}
68386+
68387+static void
68388+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
68389+{
68390+ struct task_struct *task = current;
68391+ const struct cred *cred = current_cred();
68392+
68393+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68394+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68395+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68396+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
68397+
68398+ return;
68399+}
68400+
68401+static void
68402+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
68403+{
68404+ struct task_struct *task = current;
68405+ const struct cred *cred = current_cred();
68406+
68407+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68408+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68409+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68410+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
68411+
68412+ return;
68413+}
68414+
68415+static void
68416+gr_set_proc_res(struct task_struct *task)
68417+{
68418+ struct acl_subject_label *proc;
68419+ unsigned short i;
68420+
68421+ proc = task->acl;
68422+
68423+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
68424+ return;
68425+
68426+ for (i = 0; i < RLIM_NLIMITS; i++) {
68427+ if (!(proc->resmask & (1U << i)))
68428+ continue;
68429+
68430+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
68431+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
68432+
68433+ if (i == RLIMIT_CPU)
68434+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
68435+ }
68436+
68437+ return;
68438+}
68439+
68440+/* both of the below must be called with
68441+ rcu_read_lock();
68442+ read_lock(&tasklist_lock);
68443+ read_lock(&grsec_exec_file_lock);
68444+*/
68445+
68446+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68447+{
68448+ char *tmpname;
68449+ struct acl_subject_label *tmpsubj;
68450+ struct file *filp;
68451+ struct name_entry *nmatch;
68452+
68453+ filp = task->exec_file;
68454+ if (filp == NULL)
68455+ return NULL;
68456+
68457+ /* the following is to apply the correct subject
68458+ on binaries running when the RBAC system
68459+ is enabled, when the binaries have been
68460+ replaced or deleted since their execution
68461+ -----
68462+ when the RBAC system starts, the inode/dev
68463+ from exec_file will be one the RBAC system
68464+ is unaware of. It only knows the inode/dev
68465+ of the present file on disk, or the absence
68466+ of it.
68467+ */
68468+
68469+ if (filename)
68470+ nmatch = __lookup_name_entry(state, filename);
68471+ else {
68472+ preempt_disable();
68473+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68474+
68475+ nmatch = __lookup_name_entry(state, tmpname);
68476+ preempt_enable();
68477+ }
68478+ tmpsubj = NULL;
68479+ if (nmatch) {
68480+ if (nmatch->deleted)
68481+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68482+ else
68483+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68484+ }
68485+ /* this also works for the reload case -- if we don't match a potentially inherited subject
68486+ then we fall back to a normal lookup based on the binary's ino/dev
68487+ */
68488+ if (tmpsubj == NULL)
68489+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68490+
68491+ return tmpsubj;
68492+}
68493+
68494+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68495+{
68496+ return __gr_get_subject_for_task(&running_polstate, task, filename);
68497+}
68498+
68499+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68500+{
68501+ struct acl_object_label *obj;
68502+ struct file *filp;
68503+
68504+ filp = task->exec_file;
68505+
68506+ task->acl = subj;
68507+ task->is_writable = 0;
68508+ /* ignore additional mmap checks for processes that are writable
68509+ by the default ACL */
68510+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68511+ if (unlikely(obj->mode & GR_WRITE))
68512+ task->is_writable = 1;
68513+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68514+ if (unlikely(obj->mode & GR_WRITE))
68515+ task->is_writable = 1;
68516+
68517+ gr_set_proc_res(task);
68518+
68519+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68520+ 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);
68521+#endif
68522+}
68523+
68524+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68525+{
68526+ __gr_apply_subject_to_task(&running_polstate, task, subj);
68527+}
68528+
68529+__u32
68530+gr_search_file(const struct dentry * dentry, const __u32 mode,
68531+ const struct vfsmount * mnt)
68532+{
68533+ __u32 retval = mode;
68534+ struct acl_subject_label *curracl;
68535+ struct acl_object_label *currobj;
68536+
68537+ if (unlikely(!(gr_status & GR_READY)))
68538+ return (mode & ~GR_AUDITS);
68539+
68540+ curracl = current->acl;
68541+
68542+ currobj = chk_obj_label(dentry, mnt, curracl);
68543+ retval = currobj->mode & mode;
68544+
68545+ /* if we're opening a specified transfer file for writing
68546+ (e.g. /dev/initctl), then transfer our role to init
68547+ */
68548+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68549+ current->role->roletype & GR_ROLE_PERSIST)) {
68550+ struct task_struct *task = init_pid_ns.child_reaper;
68551+
68552+ if (task->role != current->role) {
68553+ struct acl_subject_label *subj;
68554+
68555+ task->acl_sp_role = 0;
68556+ task->acl_role_id = current->acl_role_id;
68557+ task->role = current->role;
68558+ rcu_read_lock();
68559+ read_lock(&grsec_exec_file_lock);
68560+ subj = gr_get_subject_for_task(task, NULL);
68561+ gr_apply_subject_to_task(task, subj);
68562+ read_unlock(&grsec_exec_file_lock);
68563+ rcu_read_unlock();
68564+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68565+ }
68566+ }
68567+
68568+ if (unlikely
68569+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68570+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68571+ __u32 new_mode = mode;
68572+
68573+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68574+
68575+ retval = new_mode;
68576+
68577+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68578+ new_mode |= GR_INHERIT;
68579+
68580+ if (!(mode & GR_NOLEARN))
68581+ gr_log_learn(dentry, mnt, new_mode);
68582+ }
68583+
68584+ return retval;
68585+}
68586+
68587+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68588+ const struct dentry *parent,
68589+ const struct vfsmount *mnt)
68590+{
68591+ struct name_entry *match;
68592+ struct acl_object_label *matchpo;
68593+ struct acl_subject_label *curracl;
68594+ char *path;
68595+
68596+ if (unlikely(!(gr_status & GR_READY)))
68597+ return NULL;
68598+
68599+ preempt_disable();
68600+ path = gr_to_filename_rbac(new_dentry, mnt);
68601+ match = lookup_name_entry_create(path);
68602+
68603+ curracl = current->acl;
68604+
68605+ if (match) {
68606+ read_lock(&gr_inode_lock);
68607+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68608+ read_unlock(&gr_inode_lock);
68609+
68610+ if (matchpo) {
68611+ preempt_enable();
68612+ return matchpo;
68613+ }
68614+ }
68615+
68616+ // lookup parent
68617+
68618+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68619+
68620+ preempt_enable();
68621+ return matchpo;
68622+}
68623+
68624+__u32
68625+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68626+ const struct vfsmount * mnt, const __u32 mode)
68627+{
68628+ struct acl_object_label *matchpo;
68629+ __u32 retval;
68630+
68631+ if (unlikely(!(gr_status & GR_READY)))
68632+ return (mode & ~GR_AUDITS);
68633+
68634+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
68635+
68636+ retval = matchpo->mode & mode;
68637+
68638+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68639+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68640+ __u32 new_mode = mode;
68641+
68642+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68643+
68644+ gr_log_learn(new_dentry, mnt, new_mode);
68645+ return new_mode;
68646+ }
68647+
68648+ return retval;
68649+}
68650+
68651+__u32
68652+gr_check_link(const struct dentry * new_dentry,
68653+ const struct dentry * parent_dentry,
68654+ const struct vfsmount * parent_mnt,
68655+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68656+{
68657+ struct acl_object_label *obj;
68658+ __u32 oldmode, newmode;
68659+ __u32 needmode;
68660+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68661+ GR_DELETE | GR_INHERIT;
68662+
68663+ if (unlikely(!(gr_status & GR_READY)))
68664+ return (GR_CREATE | GR_LINK);
68665+
68666+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68667+ oldmode = obj->mode;
68668+
68669+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68670+ newmode = obj->mode;
68671+
68672+ needmode = newmode & checkmodes;
68673+
68674+ // old name for hardlink must have at least the permissions of the new name
68675+ if ((oldmode & needmode) != needmode)
68676+ goto bad;
68677+
68678+ // if old name had restrictions/auditing, make sure the new name does as well
68679+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68680+
68681+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68682+ if (is_privileged_binary(old_dentry))
68683+ needmode |= GR_SETID;
68684+
68685+ if ((newmode & needmode) != needmode)
68686+ goto bad;
68687+
68688+ // enforce minimum permissions
68689+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68690+ return newmode;
68691+bad:
68692+ needmode = oldmode;
68693+ if (is_privileged_binary(old_dentry))
68694+ needmode |= GR_SETID;
68695+
68696+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68697+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68698+ return (GR_CREATE | GR_LINK);
68699+ } else if (newmode & GR_SUPPRESS)
68700+ return GR_SUPPRESS;
68701+ else
68702+ return 0;
68703+}
68704+
68705+int
68706+gr_check_hidden_task(const struct task_struct *task)
68707+{
68708+ if (unlikely(!(gr_status & GR_READY)))
68709+ return 0;
68710+
68711+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68712+ return 1;
68713+
68714+ return 0;
68715+}
68716+
68717+int
68718+gr_check_protected_task(const struct task_struct *task)
68719+{
68720+ if (unlikely(!(gr_status & GR_READY) || !task))
68721+ return 0;
68722+
68723+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68724+ task->acl != current->acl)
68725+ return 1;
68726+
68727+ return 0;
68728+}
68729+
68730+int
68731+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68732+{
68733+ struct task_struct *p;
68734+ int ret = 0;
68735+
68736+ if (unlikely(!(gr_status & GR_READY) || !pid))
68737+ return ret;
68738+
68739+ read_lock(&tasklist_lock);
68740+ do_each_pid_task(pid, type, p) {
68741+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68742+ p->acl != current->acl) {
68743+ ret = 1;
68744+ goto out;
68745+ }
68746+ } while_each_pid_task(pid, type, p);
68747+out:
68748+ read_unlock(&tasklist_lock);
68749+
68750+ return ret;
68751+}
68752+
68753+void
68754+gr_copy_label(struct task_struct *tsk)
68755+{
68756+ struct task_struct *p = current;
68757+
68758+ tsk->inherited = p->inherited;
68759+ tsk->acl_sp_role = 0;
68760+ tsk->acl_role_id = p->acl_role_id;
68761+ tsk->acl = p->acl;
68762+ tsk->role = p->role;
68763+ tsk->signal->used_accept = 0;
68764+ tsk->signal->curr_ip = p->signal->curr_ip;
68765+ tsk->signal->saved_ip = p->signal->saved_ip;
68766+ if (p->exec_file)
68767+ get_file(p->exec_file);
68768+ tsk->exec_file = p->exec_file;
68769+ tsk->is_writable = p->is_writable;
68770+ if (unlikely(p->signal->used_accept)) {
68771+ p->signal->curr_ip = 0;
68772+ p->signal->saved_ip = 0;
68773+ }
68774+
68775+ return;
68776+}
68777+
68778+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68779+
68780+int
68781+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68782+{
68783+ unsigned int i;
68784+ __u16 num;
68785+ uid_t *uidlist;
68786+ uid_t curuid;
68787+ int realok = 0;
68788+ int effectiveok = 0;
68789+ int fsok = 0;
68790+ uid_t globalreal, globaleffective, globalfs;
68791+
68792+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68793+ struct user_struct *user;
68794+
68795+ if (!uid_valid(real))
68796+ goto skipit;
68797+
68798+ /* find user based on global namespace */
68799+
68800+ globalreal = GR_GLOBAL_UID(real);
68801+
68802+ user = find_user(make_kuid(&init_user_ns, globalreal));
68803+ if (user == NULL)
68804+ goto skipit;
68805+
68806+ if (gr_process_kernel_setuid_ban(user)) {
68807+ /* for find_user */
68808+ free_uid(user);
68809+ return 1;
68810+ }
68811+
68812+ /* for find_user */
68813+ free_uid(user);
68814+
68815+skipit:
68816+#endif
68817+
68818+ if (unlikely(!(gr_status & GR_READY)))
68819+ return 0;
68820+
68821+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68822+ gr_log_learn_uid_change(real, effective, fs);
68823+
68824+ num = current->acl->user_trans_num;
68825+ uidlist = current->acl->user_transitions;
68826+
68827+ if (uidlist == NULL)
68828+ return 0;
68829+
68830+ if (!uid_valid(real)) {
68831+ realok = 1;
68832+ globalreal = (uid_t)-1;
68833+ } else {
68834+ globalreal = GR_GLOBAL_UID(real);
68835+ }
68836+ if (!uid_valid(effective)) {
68837+ effectiveok = 1;
68838+ globaleffective = (uid_t)-1;
68839+ } else {
68840+ globaleffective = GR_GLOBAL_UID(effective);
68841+ }
68842+ if (!uid_valid(fs)) {
68843+ fsok = 1;
68844+ globalfs = (uid_t)-1;
68845+ } else {
68846+ globalfs = GR_GLOBAL_UID(fs);
68847+ }
68848+
68849+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
68850+ for (i = 0; i < num; i++) {
68851+ curuid = uidlist[i];
68852+ if (globalreal == curuid)
68853+ realok = 1;
68854+ if (globaleffective == curuid)
68855+ effectiveok = 1;
68856+ if (globalfs == curuid)
68857+ fsok = 1;
68858+ }
68859+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
68860+ for (i = 0; i < num; i++) {
68861+ curuid = uidlist[i];
68862+ if (globalreal == curuid)
68863+ break;
68864+ if (globaleffective == curuid)
68865+ break;
68866+ if (globalfs == curuid)
68867+ break;
68868+ }
68869+ /* not in deny list */
68870+ if (i == num) {
68871+ realok = 1;
68872+ effectiveok = 1;
68873+ fsok = 1;
68874+ }
68875+ }
68876+
68877+ if (realok && effectiveok && fsok)
68878+ return 0;
68879+ else {
68880+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68881+ return 1;
68882+ }
68883+}
68884+
68885+int
68886+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68887+{
68888+ unsigned int i;
68889+ __u16 num;
68890+ gid_t *gidlist;
68891+ gid_t curgid;
68892+ int realok = 0;
68893+ int effectiveok = 0;
68894+ int fsok = 0;
68895+ gid_t globalreal, globaleffective, globalfs;
68896+
68897+ if (unlikely(!(gr_status & GR_READY)))
68898+ return 0;
68899+
68900+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68901+ gr_log_learn_gid_change(real, effective, fs);
68902+
68903+ num = current->acl->group_trans_num;
68904+ gidlist = current->acl->group_transitions;
68905+
68906+ if (gidlist == NULL)
68907+ return 0;
68908+
68909+ if (!gid_valid(real)) {
68910+ realok = 1;
68911+ globalreal = (gid_t)-1;
68912+ } else {
68913+ globalreal = GR_GLOBAL_GID(real);
68914+ }
68915+ if (!gid_valid(effective)) {
68916+ effectiveok = 1;
68917+ globaleffective = (gid_t)-1;
68918+ } else {
68919+ globaleffective = GR_GLOBAL_GID(effective);
68920+ }
68921+ if (!gid_valid(fs)) {
68922+ fsok = 1;
68923+ globalfs = (gid_t)-1;
68924+ } else {
68925+ globalfs = GR_GLOBAL_GID(fs);
68926+ }
68927+
68928+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68929+ for (i = 0; i < num; i++) {
68930+ curgid = gidlist[i];
68931+ if (globalreal == curgid)
68932+ realok = 1;
68933+ if (globaleffective == curgid)
68934+ effectiveok = 1;
68935+ if (globalfs == curgid)
68936+ fsok = 1;
68937+ }
68938+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68939+ for (i = 0; i < num; i++) {
68940+ curgid = gidlist[i];
68941+ if (globalreal == curgid)
68942+ break;
68943+ if (globaleffective == curgid)
68944+ break;
68945+ if (globalfs == curgid)
68946+ break;
68947+ }
68948+ /* not in deny list */
68949+ if (i == num) {
68950+ realok = 1;
68951+ effectiveok = 1;
68952+ fsok = 1;
68953+ }
68954+ }
68955+
68956+ if (realok && effectiveok && fsok)
68957+ return 0;
68958+ else {
68959+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68960+ return 1;
68961+ }
68962+}
68963+
68964+extern int gr_acl_is_capable(const int cap);
68965+
68966+void
68967+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68968+{
68969+ struct acl_role_label *role = task->role;
68970+ struct acl_subject_label *subj = NULL;
68971+ struct acl_object_label *obj;
68972+ struct file *filp;
68973+ uid_t uid;
68974+ gid_t gid;
68975+
68976+ if (unlikely(!(gr_status & GR_READY)))
68977+ return;
68978+
68979+ uid = GR_GLOBAL_UID(kuid);
68980+ gid = GR_GLOBAL_GID(kgid);
68981+
68982+ filp = task->exec_file;
68983+
68984+ /* kernel process, we'll give them the kernel role */
68985+ if (unlikely(!filp)) {
68986+ task->role = running_polstate.kernel_role;
68987+ task->acl = running_polstate.kernel_role->root_label;
68988+ return;
68989+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68990+ /* save the current ip at time of role lookup so that the proper
68991+ IP will be learned for role_allowed_ip */
68992+ task->signal->saved_ip = task->signal->curr_ip;
68993+ role = lookup_acl_role_label(task, uid, gid);
68994+ }
68995+
68996+ /* don't change the role if we're not a privileged process */
68997+ if (role && task->role != role &&
68998+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68999+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
69000+ return;
69001+
69002+ /* perform subject lookup in possibly new role
69003+ we can use this result below in the case where role == task->role
69004+ */
69005+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
69006+
69007+ /* if we changed uid/gid, but result in the same role
69008+ and are using inheritance, don't lose the inherited subject
69009+ if current subject is other than what normal lookup
69010+ would result in, we arrived via inheritance, don't
69011+ lose subject
69012+ */
69013+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
69014+ (subj == task->acl)))
69015+ task->acl = subj;
69016+
69017+ /* leave task->inherited unaffected */
69018+
69019+ task->role = role;
69020+
69021+ task->is_writable = 0;
69022+
69023+ /* ignore additional mmap checks for processes that are writable
69024+ by the default ACL */
69025+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69026+ if (unlikely(obj->mode & GR_WRITE))
69027+ task->is_writable = 1;
69028+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
69029+ if (unlikely(obj->mode & GR_WRITE))
69030+ task->is_writable = 1;
69031+
69032+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69033+ 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);
69034+#endif
69035+
69036+ gr_set_proc_res(task);
69037+
69038+ return;
69039+}
69040+
69041+int
69042+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
69043+ const int unsafe_flags)
69044+{
69045+ struct task_struct *task = current;
69046+ struct acl_subject_label *newacl;
69047+ struct acl_object_label *obj;
69048+ __u32 retmode;
69049+
69050+ if (unlikely(!(gr_status & GR_READY)))
69051+ return 0;
69052+
69053+ newacl = chk_subj_label(dentry, mnt, task->role);
69054+
69055+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
69056+ did an exec
69057+ */
69058+ rcu_read_lock();
69059+ read_lock(&tasklist_lock);
69060+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
69061+ (task->parent->acl->mode & GR_POVERRIDE))) {
69062+ read_unlock(&tasklist_lock);
69063+ rcu_read_unlock();
69064+ goto skip_check;
69065+ }
69066+ read_unlock(&tasklist_lock);
69067+ rcu_read_unlock();
69068+
69069+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
69070+ !(task->role->roletype & GR_ROLE_GOD) &&
69071+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
69072+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
69073+ if (unsafe_flags & LSM_UNSAFE_SHARE)
69074+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
69075+ else
69076+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
69077+ return -EACCES;
69078+ }
69079+
69080+skip_check:
69081+
69082+ obj = chk_obj_label(dentry, mnt, task->acl);
69083+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
69084+
69085+ if (!(task->acl->mode & GR_INHERITLEARN) &&
69086+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
69087+ if (obj->nested)
69088+ task->acl = obj->nested;
69089+ else
69090+ task->acl = newacl;
69091+ task->inherited = 0;
69092+ } else {
69093+ task->inherited = 1;
69094+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
69095+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
69096+ }
69097+
69098+ task->is_writable = 0;
69099+
69100+ /* ignore additional mmap checks for processes that are writable
69101+ by the default ACL */
69102+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
69103+ if (unlikely(obj->mode & GR_WRITE))
69104+ task->is_writable = 1;
69105+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
69106+ if (unlikely(obj->mode & GR_WRITE))
69107+ task->is_writable = 1;
69108+
69109+ gr_set_proc_res(task);
69110+
69111+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69112+ 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);
69113+#endif
69114+ return 0;
69115+}
69116+
69117+/* always called with valid inodev ptr */
69118+static void
69119+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
69120+{
69121+ struct acl_object_label *matchpo;
69122+ struct acl_subject_label *matchps;
69123+ struct acl_subject_label *subj;
69124+ struct acl_role_label *role;
69125+ unsigned int x;
69126+
69127+ FOR_EACH_ROLE_START(role)
69128+ FOR_EACH_SUBJECT_START(role, subj, x)
69129+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69130+ matchpo->mode |= GR_DELETED;
69131+ FOR_EACH_SUBJECT_END(subj,x)
69132+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
69133+ /* nested subjects aren't in the role's subj_hash table */
69134+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69135+ matchpo->mode |= GR_DELETED;
69136+ FOR_EACH_NESTED_SUBJECT_END(subj)
69137+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
69138+ matchps->mode |= GR_DELETED;
69139+ FOR_EACH_ROLE_END(role)
69140+
69141+ inodev->nentry->deleted = 1;
69142+
69143+ return;
69144+}
69145+
69146+void
69147+gr_handle_delete(const ino_t ino, const dev_t dev)
69148+{
69149+ struct inodev_entry *inodev;
69150+
69151+ if (unlikely(!(gr_status & GR_READY)))
69152+ return;
69153+
69154+ write_lock(&gr_inode_lock);
69155+ inodev = lookup_inodev_entry(ino, dev);
69156+ if (inodev != NULL)
69157+ do_handle_delete(inodev, ino, dev);
69158+ write_unlock(&gr_inode_lock);
69159+
69160+ return;
69161+}
69162+
69163+static void
69164+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
69165+ const ino_t newinode, const dev_t newdevice,
69166+ struct acl_subject_label *subj)
69167+{
69168+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
69169+ struct acl_object_label *match;
69170+
69171+ match = subj->obj_hash[index];
69172+
69173+ while (match && (match->inode != oldinode ||
69174+ match->device != olddevice ||
69175+ !(match->mode & GR_DELETED)))
69176+ match = match->next;
69177+
69178+ if (match && (match->inode == oldinode)
69179+ && (match->device == olddevice)
69180+ && (match->mode & GR_DELETED)) {
69181+ if (match->prev == NULL) {
69182+ subj->obj_hash[index] = match->next;
69183+ if (match->next != NULL)
69184+ match->next->prev = NULL;
69185+ } else {
69186+ match->prev->next = match->next;
69187+ if (match->next != NULL)
69188+ match->next->prev = match->prev;
69189+ }
69190+ match->prev = NULL;
69191+ match->next = NULL;
69192+ match->inode = newinode;
69193+ match->device = newdevice;
69194+ match->mode &= ~GR_DELETED;
69195+
69196+ insert_acl_obj_label(match, subj);
69197+ }
69198+
69199+ return;
69200+}
69201+
69202+static void
69203+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
69204+ const ino_t newinode, const dev_t newdevice,
69205+ struct acl_role_label *role)
69206+{
69207+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
69208+ struct acl_subject_label *match;
69209+
69210+ match = role->subj_hash[index];
69211+
69212+ while (match && (match->inode != oldinode ||
69213+ match->device != olddevice ||
69214+ !(match->mode & GR_DELETED)))
69215+ match = match->next;
69216+
69217+ if (match && (match->inode == oldinode)
69218+ && (match->device == olddevice)
69219+ && (match->mode & GR_DELETED)) {
69220+ if (match->prev == NULL) {
69221+ role->subj_hash[index] = match->next;
69222+ if (match->next != NULL)
69223+ match->next->prev = NULL;
69224+ } else {
69225+ match->prev->next = match->next;
69226+ if (match->next != NULL)
69227+ match->next->prev = match->prev;
69228+ }
69229+ match->prev = NULL;
69230+ match->next = NULL;
69231+ match->inode = newinode;
69232+ match->device = newdevice;
69233+ match->mode &= ~GR_DELETED;
69234+
69235+ insert_acl_subj_label(match, role);
69236+ }
69237+
69238+ return;
69239+}
69240+
69241+static void
69242+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
69243+ const ino_t newinode, const dev_t newdevice)
69244+{
69245+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
69246+ struct inodev_entry *match;
69247+
69248+ match = running_polstate.inodev_set.i_hash[index];
69249+
69250+ while (match && (match->nentry->inode != oldinode ||
69251+ match->nentry->device != olddevice || !match->nentry->deleted))
69252+ match = match->next;
69253+
69254+ if (match && (match->nentry->inode == oldinode)
69255+ && (match->nentry->device == olddevice) &&
69256+ match->nentry->deleted) {
69257+ if (match->prev == NULL) {
69258+ running_polstate.inodev_set.i_hash[index] = match->next;
69259+ if (match->next != NULL)
69260+ match->next->prev = NULL;
69261+ } else {
69262+ match->prev->next = match->next;
69263+ if (match->next != NULL)
69264+ match->next->prev = match->prev;
69265+ }
69266+ match->prev = NULL;
69267+ match->next = NULL;
69268+ match->nentry->inode = newinode;
69269+ match->nentry->device = newdevice;
69270+ match->nentry->deleted = 0;
69271+
69272+ insert_inodev_entry(match);
69273+ }
69274+
69275+ return;
69276+}
69277+
69278+static void
69279+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
69280+{
69281+ struct acl_subject_label *subj;
69282+ struct acl_role_label *role;
69283+ unsigned int x;
69284+
69285+ FOR_EACH_ROLE_START(role)
69286+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
69287+
69288+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
69289+ if ((subj->inode == ino) && (subj->device == dev)) {
69290+ subj->inode = ino;
69291+ subj->device = dev;
69292+ }
69293+ /* nested subjects aren't in the role's subj_hash table */
69294+ update_acl_obj_label(matchn->inode, matchn->device,
69295+ ino, dev, subj);
69296+ FOR_EACH_NESTED_SUBJECT_END(subj)
69297+ FOR_EACH_SUBJECT_START(role, subj, x)
69298+ update_acl_obj_label(matchn->inode, matchn->device,
69299+ ino, dev, subj);
69300+ FOR_EACH_SUBJECT_END(subj,x)
69301+ FOR_EACH_ROLE_END(role)
69302+
69303+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
69304+
69305+ return;
69306+}
69307+
69308+static void
69309+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
69310+ const struct vfsmount *mnt)
69311+{
69312+ ino_t ino = dentry->d_inode->i_ino;
69313+ dev_t dev = __get_dev(dentry);
69314+
69315+ __do_handle_create(matchn, ino, dev);
69316+
69317+ return;
69318+}
69319+
69320+void
69321+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69322+{
69323+ struct name_entry *matchn;
69324+
69325+ if (unlikely(!(gr_status & GR_READY)))
69326+ return;
69327+
69328+ preempt_disable();
69329+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
69330+
69331+ if (unlikely((unsigned long)matchn)) {
69332+ write_lock(&gr_inode_lock);
69333+ do_handle_create(matchn, dentry, mnt);
69334+ write_unlock(&gr_inode_lock);
69335+ }
69336+ preempt_enable();
69337+
69338+ return;
69339+}
69340+
69341+void
69342+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69343+{
69344+ struct name_entry *matchn;
69345+
69346+ if (unlikely(!(gr_status & GR_READY)))
69347+ return;
69348+
69349+ preempt_disable();
69350+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
69351+
69352+ if (unlikely((unsigned long)matchn)) {
69353+ write_lock(&gr_inode_lock);
69354+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
69355+ write_unlock(&gr_inode_lock);
69356+ }
69357+ preempt_enable();
69358+
69359+ return;
69360+}
69361+
69362+void
69363+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69364+ struct dentry *old_dentry,
69365+ struct dentry *new_dentry,
69366+ struct vfsmount *mnt, const __u8 replace)
69367+{
69368+ struct name_entry *matchn;
69369+ struct inodev_entry *inodev;
69370+ struct inode *inode = new_dentry->d_inode;
69371+ ino_t old_ino = old_dentry->d_inode->i_ino;
69372+ dev_t old_dev = __get_dev(old_dentry);
69373+
69374+ /* vfs_rename swaps the name and parent link for old_dentry and
69375+ new_dentry
69376+ at this point, old_dentry has the new name, parent link, and inode
69377+ for the renamed file
69378+ if a file is being replaced by a rename, new_dentry has the inode
69379+ and name for the replaced file
69380+ */
69381+
69382+ if (unlikely(!(gr_status & GR_READY)))
69383+ return;
69384+
69385+ preempt_disable();
69386+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
69387+
69388+ /* we wouldn't have to check d_inode if it weren't for
69389+ NFS silly-renaming
69390+ */
69391+
69392+ write_lock(&gr_inode_lock);
69393+ if (unlikely(replace && inode)) {
69394+ ino_t new_ino = inode->i_ino;
69395+ dev_t new_dev = __get_dev(new_dentry);
69396+
69397+ inodev = lookup_inodev_entry(new_ino, new_dev);
69398+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
69399+ do_handle_delete(inodev, new_ino, new_dev);
69400+ }
69401+
69402+ inodev = lookup_inodev_entry(old_ino, old_dev);
69403+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
69404+ do_handle_delete(inodev, old_ino, old_dev);
69405+
69406+ if (unlikely((unsigned long)matchn))
69407+ do_handle_create(matchn, old_dentry, mnt);
69408+
69409+ write_unlock(&gr_inode_lock);
69410+ preempt_enable();
69411+
69412+ return;
69413+}
69414+
69415+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
69416+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
69417+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69418+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69419+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69420+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69421+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69422+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69423+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69424+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69425+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69426+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69427+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69428+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69429+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69430+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69431+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69432+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69433+};
69434+
69435+void
69436+gr_learn_resource(const struct task_struct *task,
69437+ const int res, const unsigned long wanted, const int gt)
69438+{
69439+ struct acl_subject_label *acl;
69440+ const struct cred *cred;
69441+
69442+ if (unlikely((gr_status & GR_READY) &&
69443+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69444+ goto skip_reslog;
69445+
69446+ gr_log_resource(task, res, wanted, gt);
69447+skip_reslog:
69448+
69449+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69450+ return;
69451+
69452+ acl = task->acl;
69453+
69454+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69455+ !(acl->resmask & (1U << (unsigned short) res))))
69456+ return;
69457+
69458+ if (wanted >= acl->res[res].rlim_cur) {
69459+ unsigned long res_add;
69460+
69461+ res_add = wanted + res_learn_bumps[res];
69462+
69463+ acl->res[res].rlim_cur = res_add;
69464+
69465+ if (wanted > acl->res[res].rlim_max)
69466+ acl->res[res].rlim_max = res_add;
69467+
69468+ /* only log the subject filename, since resource logging is supported for
69469+ single-subject learning only */
69470+ rcu_read_lock();
69471+ cred = __task_cred(task);
69472+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69473+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69474+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69475+ "", (unsigned long) res, &task->signal->saved_ip);
69476+ rcu_read_unlock();
69477+ }
69478+
69479+ return;
69480+}
69481+EXPORT_SYMBOL_GPL(gr_learn_resource);
69482+#endif
69483+
69484+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69485+void
69486+pax_set_initial_flags(struct linux_binprm *bprm)
69487+{
69488+ struct task_struct *task = current;
69489+ struct acl_subject_label *proc;
69490+ unsigned long flags;
69491+
69492+ if (unlikely(!(gr_status & GR_READY)))
69493+ return;
69494+
69495+ flags = pax_get_flags(task);
69496+
69497+ proc = task->acl;
69498+
69499+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69500+ flags &= ~MF_PAX_PAGEEXEC;
69501+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69502+ flags &= ~MF_PAX_SEGMEXEC;
69503+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69504+ flags &= ~MF_PAX_RANDMMAP;
69505+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69506+ flags &= ~MF_PAX_EMUTRAMP;
69507+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69508+ flags &= ~MF_PAX_MPROTECT;
69509+
69510+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69511+ flags |= MF_PAX_PAGEEXEC;
69512+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69513+ flags |= MF_PAX_SEGMEXEC;
69514+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69515+ flags |= MF_PAX_RANDMMAP;
69516+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69517+ flags |= MF_PAX_EMUTRAMP;
69518+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69519+ flags |= MF_PAX_MPROTECT;
69520+
69521+ pax_set_flags(task, flags);
69522+
69523+ return;
69524+}
69525+#endif
69526+
69527+int
69528+gr_handle_proc_ptrace(struct task_struct *task)
69529+{
69530+ struct file *filp;
69531+ struct task_struct *tmp = task;
69532+ struct task_struct *curtemp = current;
69533+ __u32 retmode;
69534+
69535+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69536+ if (unlikely(!(gr_status & GR_READY)))
69537+ return 0;
69538+#endif
69539+
69540+ read_lock(&tasklist_lock);
69541+ read_lock(&grsec_exec_file_lock);
69542+ filp = task->exec_file;
69543+
69544+ while (task_pid_nr(tmp) > 0) {
69545+ if (tmp == curtemp)
69546+ break;
69547+ tmp = tmp->real_parent;
69548+ }
69549+
69550+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69551+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69552+ read_unlock(&grsec_exec_file_lock);
69553+ read_unlock(&tasklist_lock);
69554+ return 1;
69555+ }
69556+
69557+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69558+ if (!(gr_status & GR_READY)) {
69559+ read_unlock(&grsec_exec_file_lock);
69560+ read_unlock(&tasklist_lock);
69561+ return 0;
69562+ }
69563+#endif
69564+
69565+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69566+ read_unlock(&grsec_exec_file_lock);
69567+ read_unlock(&tasklist_lock);
69568+
69569+ if (retmode & GR_NOPTRACE)
69570+ return 1;
69571+
69572+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69573+ && (current->acl != task->acl || (current->acl != current->role->root_label
69574+ && task_pid_nr(current) != task_pid_nr(task))))
69575+ return 1;
69576+
69577+ return 0;
69578+}
69579+
69580+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69581+{
69582+ if (unlikely(!(gr_status & GR_READY)))
69583+ return;
69584+
69585+ if (!(current->role->roletype & GR_ROLE_GOD))
69586+ return;
69587+
69588+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69589+ p->role->rolename, gr_task_roletype_to_char(p),
69590+ p->acl->filename);
69591+}
69592+
69593+int
69594+gr_handle_ptrace(struct task_struct *task, const long request)
69595+{
69596+ struct task_struct *tmp = task;
69597+ struct task_struct *curtemp = current;
69598+ __u32 retmode;
69599+
69600+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69601+ if (unlikely(!(gr_status & GR_READY)))
69602+ return 0;
69603+#endif
69604+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69605+ read_lock(&tasklist_lock);
69606+ while (task_pid_nr(tmp) > 0) {
69607+ if (tmp == curtemp)
69608+ break;
69609+ tmp = tmp->real_parent;
69610+ }
69611+
69612+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69613+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69614+ read_unlock(&tasklist_lock);
69615+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69616+ return 1;
69617+ }
69618+ read_unlock(&tasklist_lock);
69619+ }
69620+
69621+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69622+ if (!(gr_status & GR_READY))
69623+ return 0;
69624+#endif
69625+
69626+ read_lock(&grsec_exec_file_lock);
69627+ if (unlikely(!task->exec_file)) {
69628+ read_unlock(&grsec_exec_file_lock);
69629+ return 0;
69630+ }
69631+
69632+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69633+ read_unlock(&grsec_exec_file_lock);
69634+
69635+ if (retmode & GR_NOPTRACE) {
69636+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69637+ return 1;
69638+ }
69639+
69640+ if (retmode & GR_PTRACERD) {
69641+ switch (request) {
69642+ case PTRACE_SEIZE:
69643+ case PTRACE_POKETEXT:
69644+ case PTRACE_POKEDATA:
69645+ case PTRACE_POKEUSR:
69646+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69647+ case PTRACE_SETREGS:
69648+ case PTRACE_SETFPREGS:
69649+#endif
69650+#ifdef CONFIG_X86
69651+ case PTRACE_SETFPXREGS:
69652+#endif
69653+#ifdef CONFIG_ALTIVEC
69654+ case PTRACE_SETVRREGS:
69655+#endif
69656+ return 1;
69657+ default:
69658+ return 0;
69659+ }
69660+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
69661+ !(current->role->roletype & GR_ROLE_GOD) &&
69662+ (current->acl != task->acl)) {
69663+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69664+ return 1;
69665+ }
69666+
69667+ return 0;
69668+}
69669+
69670+static int is_writable_mmap(const struct file *filp)
69671+{
69672+ struct task_struct *task = current;
69673+ struct acl_object_label *obj, *obj2;
69674+
69675+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69676+ !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))) {
69677+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69678+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69679+ task->role->root_label);
69680+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69681+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69682+ return 1;
69683+ }
69684+ }
69685+ return 0;
69686+}
69687+
69688+int
69689+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69690+{
69691+ __u32 mode;
69692+
69693+ if (unlikely(!file || !(prot & PROT_EXEC)))
69694+ return 1;
69695+
69696+ if (is_writable_mmap(file))
69697+ return 0;
69698+
69699+ mode =
69700+ gr_search_file(file->f_path.dentry,
69701+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69702+ file->f_path.mnt);
69703+
69704+ if (!gr_tpe_allow(file))
69705+ return 0;
69706+
69707+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69708+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69709+ return 0;
69710+ } else if (unlikely(!(mode & GR_EXEC))) {
69711+ return 0;
69712+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69713+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69714+ return 1;
69715+ }
69716+
69717+ return 1;
69718+}
69719+
69720+int
69721+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69722+{
69723+ __u32 mode;
69724+
69725+ if (unlikely(!file || !(prot & PROT_EXEC)))
69726+ return 1;
69727+
69728+ if (is_writable_mmap(file))
69729+ return 0;
69730+
69731+ mode =
69732+ gr_search_file(file->f_path.dentry,
69733+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69734+ file->f_path.mnt);
69735+
69736+ if (!gr_tpe_allow(file))
69737+ return 0;
69738+
69739+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69740+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69741+ return 0;
69742+ } else if (unlikely(!(mode & GR_EXEC))) {
69743+ return 0;
69744+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69745+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69746+ return 1;
69747+ }
69748+
69749+ return 1;
69750+}
69751+
69752+void
69753+gr_acl_handle_psacct(struct task_struct *task, const long code)
69754+{
69755+ unsigned long runtime, cputime;
69756+ cputime_t utime, stime;
69757+ unsigned int wday, cday;
69758+ __u8 whr, chr;
69759+ __u8 wmin, cmin;
69760+ __u8 wsec, csec;
69761+ struct timespec timeval;
69762+
69763+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69764+ !(task->acl->mode & GR_PROCACCT)))
69765+ return;
69766+
69767+ do_posix_clock_monotonic_gettime(&timeval);
69768+ runtime = timeval.tv_sec - task->start_time.tv_sec;
69769+ wday = runtime / (60 * 60 * 24);
69770+ runtime -= wday * (60 * 60 * 24);
69771+ whr = runtime / (60 * 60);
69772+ runtime -= whr * (60 * 60);
69773+ wmin = runtime / 60;
69774+ runtime -= wmin * 60;
69775+ wsec = runtime;
69776+
69777+ task_cputime(task, &utime, &stime);
69778+ cputime = cputime_to_secs(utime + stime);
69779+ cday = cputime / (60 * 60 * 24);
69780+ cputime -= cday * (60 * 60 * 24);
69781+ chr = cputime / (60 * 60);
69782+ cputime -= chr * (60 * 60);
69783+ cmin = cputime / 60;
69784+ cputime -= cmin * 60;
69785+ csec = cputime;
69786+
69787+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69788+
69789+ return;
69790+}
69791+
69792+#ifdef CONFIG_TASKSTATS
69793+int gr_is_taskstats_denied(int pid)
69794+{
69795+ struct task_struct *task;
69796+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69797+ const struct cred *cred;
69798+#endif
69799+ int ret = 0;
69800+
69801+ /* restrict taskstats viewing to un-chrooted root users
69802+ who have the 'view' subject flag if the RBAC system is enabled
69803+ */
69804+
69805+ rcu_read_lock();
69806+ read_lock(&tasklist_lock);
69807+ task = find_task_by_vpid(pid);
69808+ if (task) {
69809+#ifdef CONFIG_GRKERNSEC_CHROOT
69810+ if (proc_is_chrooted(task))
69811+ ret = -EACCES;
69812+#endif
69813+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69814+ cred = __task_cred(task);
69815+#ifdef CONFIG_GRKERNSEC_PROC_USER
69816+ if (gr_is_global_nonroot(cred->uid))
69817+ ret = -EACCES;
69818+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69819+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69820+ ret = -EACCES;
69821+#endif
69822+#endif
69823+ if (gr_status & GR_READY) {
69824+ if (!(task->acl->mode & GR_VIEW))
69825+ ret = -EACCES;
69826+ }
69827+ } else
69828+ ret = -ENOENT;
69829+
69830+ read_unlock(&tasklist_lock);
69831+ rcu_read_unlock();
69832+
69833+ return ret;
69834+}
69835+#endif
69836+
69837+/* AUXV entries are filled via a descendant of search_binary_handler
69838+ after we've already applied the subject for the target
69839+*/
69840+int gr_acl_enable_at_secure(void)
69841+{
69842+ if (unlikely(!(gr_status & GR_READY)))
69843+ return 0;
69844+
69845+ if (current->acl->mode & GR_ATSECURE)
69846+ return 1;
69847+
69848+ return 0;
69849+}
69850+
69851+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69852+{
69853+ struct task_struct *task = current;
69854+ struct dentry *dentry = file->f_path.dentry;
69855+ struct vfsmount *mnt = file->f_path.mnt;
69856+ struct acl_object_label *obj, *tmp;
69857+ struct acl_subject_label *subj;
69858+ unsigned int bufsize;
69859+ int is_not_root;
69860+ char *path;
69861+ dev_t dev = __get_dev(dentry);
69862+
69863+ if (unlikely(!(gr_status & GR_READY)))
69864+ return 1;
69865+
69866+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69867+ return 1;
69868+
69869+ /* ignore Eric Biederman */
69870+ if (IS_PRIVATE(dentry->d_inode))
69871+ return 1;
69872+
69873+ subj = task->acl;
69874+ read_lock(&gr_inode_lock);
69875+ do {
69876+ obj = lookup_acl_obj_label(ino, dev, subj);
69877+ if (obj != NULL) {
69878+ read_unlock(&gr_inode_lock);
69879+ return (obj->mode & GR_FIND) ? 1 : 0;
69880+ }
69881+ } while ((subj = subj->parent_subject));
69882+ read_unlock(&gr_inode_lock);
69883+
69884+ /* this is purely an optimization since we're looking for an object
69885+ for the directory we're doing a readdir on
69886+ if it's possible for any globbed object to match the entry we're
69887+ filling into the directory, then the object we find here will be
69888+ an anchor point with attached globbed objects
69889+ */
69890+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69891+ if (obj->globbed == NULL)
69892+ return (obj->mode & GR_FIND) ? 1 : 0;
69893+
69894+ is_not_root = ((obj->filename[0] == '/') &&
69895+ (obj->filename[1] == '\0')) ? 0 : 1;
69896+ bufsize = PAGE_SIZE - namelen - is_not_root;
69897+
69898+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69899+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69900+ return 1;
69901+
69902+ preempt_disable();
69903+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69904+ bufsize);
69905+
69906+ bufsize = strlen(path);
69907+
69908+ /* if base is "/", don't append an additional slash */
69909+ if (is_not_root)
69910+ *(path + bufsize) = '/';
69911+ memcpy(path + bufsize + is_not_root, name, namelen);
69912+ *(path + bufsize + namelen + is_not_root) = '\0';
69913+
69914+ tmp = obj->globbed;
69915+ while (tmp) {
69916+ if (!glob_match(tmp->filename, path)) {
69917+ preempt_enable();
69918+ return (tmp->mode & GR_FIND) ? 1 : 0;
69919+ }
69920+ tmp = tmp->next;
69921+ }
69922+ preempt_enable();
69923+ return (obj->mode & GR_FIND) ? 1 : 0;
69924+}
69925+
69926+void gr_put_exec_file(struct task_struct *task)
69927+{
69928+ struct file *filp;
69929+
69930+ write_lock(&grsec_exec_file_lock);
69931+ filp = task->exec_file;
69932+ task->exec_file = NULL;
69933+ write_unlock(&grsec_exec_file_lock);
69934+
69935+ if (filp)
69936+ fput(filp);
69937+
69938+ return;
69939+}
69940+
69941+
69942+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69943+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69944+#endif
69945+#ifdef CONFIG_SECURITY
69946+EXPORT_SYMBOL_GPL(gr_check_user_change);
69947+EXPORT_SYMBOL_GPL(gr_check_group_change);
69948+#endif
69949+
69950diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69951new file mode 100644
69952index 0000000..18ffbbd
69953--- /dev/null
69954+++ b/grsecurity/gracl_alloc.c
69955@@ -0,0 +1,105 @@
69956+#include <linux/kernel.h>
69957+#include <linux/mm.h>
69958+#include <linux/slab.h>
69959+#include <linux/vmalloc.h>
69960+#include <linux/gracl.h>
69961+#include <linux/grsecurity.h>
69962+
69963+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69964+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69965+
69966+static __inline__ int
69967+alloc_pop(void)
69968+{
69969+ if (current_alloc_state->alloc_stack_next == 1)
69970+ return 0;
69971+
69972+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69973+
69974+ current_alloc_state->alloc_stack_next--;
69975+
69976+ return 1;
69977+}
69978+
69979+static __inline__ int
69980+alloc_push(void *buf)
69981+{
69982+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69983+ return 1;
69984+
69985+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69986+
69987+ current_alloc_state->alloc_stack_next++;
69988+
69989+ return 0;
69990+}
69991+
69992+void *
69993+acl_alloc(unsigned long len)
69994+{
69995+ void *ret = NULL;
69996+
69997+ if (!len || len > PAGE_SIZE)
69998+ goto out;
69999+
70000+ ret = kmalloc(len, GFP_KERNEL);
70001+
70002+ if (ret) {
70003+ if (alloc_push(ret)) {
70004+ kfree(ret);
70005+ ret = NULL;
70006+ }
70007+ }
70008+
70009+out:
70010+ return ret;
70011+}
70012+
70013+void *
70014+acl_alloc_num(unsigned long num, unsigned long len)
70015+{
70016+ if (!len || (num > (PAGE_SIZE / len)))
70017+ return NULL;
70018+
70019+ return acl_alloc(num * len);
70020+}
70021+
70022+void
70023+acl_free_all(void)
70024+{
70025+ if (!current_alloc_state->alloc_stack)
70026+ return;
70027+
70028+ while (alloc_pop()) ;
70029+
70030+ if (current_alloc_state->alloc_stack) {
70031+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
70032+ kfree(current_alloc_state->alloc_stack);
70033+ else
70034+ vfree(current_alloc_state->alloc_stack);
70035+ }
70036+
70037+ current_alloc_state->alloc_stack = NULL;
70038+ current_alloc_state->alloc_stack_size = 1;
70039+ current_alloc_state->alloc_stack_next = 1;
70040+
70041+ return;
70042+}
70043+
70044+int
70045+acl_alloc_stack_init(unsigned long size)
70046+{
70047+ if ((size * sizeof (void *)) <= PAGE_SIZE)
70048+ current_alloc_state->alloc_stack =
70049+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
70050+ else
70051+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
70052+
70053+ current_alloc_state->alloc_stack_size = size;
70054+ current_alloc_state->alloc_stack_next = 1;
70055+
70056+ if (!current_alloc_state->alloc_stack)
70057+ return 0;
70058+ else
70059+ return 1;
70060+}
70061diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
70062new file mode 100644
70063index 0000000..bdd51ea
70064--- /dev/null
70065+++ b/grsecurity/gracl_cap.c
70066@@ -0,0 +1,110 @@
70067+#include <linux/kernel.h>
70068+#include <linux/module.h>
70069+#include <linux/sched.h>
70070+#include <linux/gracl.h>
70071+#include <linux/grsecurity.h>
70072+#include <linux/grinternal.h>
70073+
70074+extern const char *captab_log[];
70075+extern int captab_log_entries;
70076+
70077+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
70078+{
70079+ struct acl_subject_label *curracl;
70080+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70081+ kernel_cap_t cap_audit = __cap_empty_set;
70082+
70083+ if (!gr_acl_is_enabled())
70084+ return 1;
70085+
70086+ curracl = task->acl;
70087+
70088+ cap_drop = curracl->cap_lower;
70089+ cap_mask = curracl->cap_mask;
70090+ cap_audit = curracl->cap_invert_audit;
70091+
70092+ while ((curracl = curracl->parent_subject)) {
70093+ /* if the cap isn't specified in the current computed mask but is specified in the
70094+ current level subject, and is lowered in the current level subject, then add
70095+ it to the set of dropped capabilities
70096+ otherwise, add the current level subject's mask to the current computed mask
70097+ */
70098+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70099+ cap_raise(cap_mask, cap);
70100+ if (cap_raised(curracl->cap_lower, cap))
70101+ cap_raise(cap_drop, cap);
70102+ if (cap_raised(curracl->cap_invert_audit, cap))
70103+ cap_raise(cap_audit, cap);
70104+ }
70105+ }
70106+
70107+ if (!cap_raised(cap_drop, cap)) {
70108+ if (cap_raised(cap_audit, cap))
70109+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
70110+ return 1;
70111+ }
70112+
70113+ curracl = task->acl;
70114+
70115+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
70116+ && cap_raised(cred->cap_effective, cap)) {
70117+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
70118+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
70119+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
70120+ gr_to_filename(task->exec_file->f_path.dentry,
70121+ task->exec_file->f_path.mnt) : curracl->filename,
70122+ curracl->filename, 0UL,
70123+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
70124+ return 1;
70125+ }
70126+
70127+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
70128+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
70129+
70130+ return 0;
70131+}
70132+
70133+int
70134+gr_acl_is_capable(const int cap)
70135+{
70136+ return gr_task_acl_is_capable(current, current_cred(), cap);
70137+}
70138+
70139+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
70140+{
70141+ struct acl_subject_label *curracl;
70142+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70143+
70144+ if (!gr_acl_is_enabled())
70145+ return 1;
70146+
70147+ curracl = task->acl;
70148+
70149+ cap_drop = curracl->cap_lower;
70150+ cap_mask = curracl->cap_mask;
70151+
70152+ while ((curracl = curracl->parent_subject)) {
70153+ /* if the cap isn't specified in the current computed mask but is specified in the
70154+ current level subject, and is lowered in the current level subject, then add
70155+ it to the set of dropped capabilities
70156+ otherwise, add the current level subject's mask to the current computed mask
70157+ */
70158+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70159+ cap_raise(cap_mask, cap);
70160+ if (cap_raised(curracl->cap_lower, cap))
70161+ cap_raise(cap_drop, cap);
70162+ }
70163+ }
70164+
70165+ if (!cap_raised(cap_drop, cap))
70166+ return 1;
70167+
70168+ return 0;
70169+}
70170+
70171+int
70172+gr_acl_is_capable_nolog(const int cap)
70173+{
70174+ return gr_task_acl_is_capable_nolog(current, cap);
70175+}
70176+
70177diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
70178new file mode 100644
70179index 0000000..ca25605
70180--- /dev/null
70181+++ b/grsecurity/gracl_compat.c
70182@@ -0,0 +1,270 @@
70183+#include <linux/kernel.h>
70184+#include <linux/gracl.h>
70185+#include <linux/compat.h>
70186+#include <linux/gracl_compat.h>
70187+
70188+#include <asm/uaccess.h>
70189+
70190+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
70191+{
70192+ struct gr_arg_wrapper_compat uwrapcompat;
70193+
70194+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
70195+ return -EFAULT;
70196+
70197+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
70198+ (uwrapcompat.version != 0x2901)) ||
70199+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
70200+ return -EINVAL;
70201+
70202+ uwrap->arg = compat_ptr(uwrapcompat.arg);
70203+ uwrap->version = uwrapcompat.version;
70204+ uwrap->size = sizeof(struct gr_arg);
70205+
70206+ return 0;
70207+}
70208+
70209+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
70210+{
70211+ struct gr_arg_compat argcompat;
70212+
70213+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
70214+ return -EFAULT;
70215+
70216+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
70217+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
70218+ arg->role_db.num_roles = argcompat.role_db.num_roles;
70219+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
70220+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
70221+ arg->role_db.num_objects = argcompat.role_db.num_objects;
70222+
70223+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
70224+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
70225+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
70226+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
70227+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
70228+ arg->segv_device = argcompat.segv_device;
70229+ arg->segv_inode = argcompat.segv_inode;
70230+ arg->segv_uid = argcompat.segv_uid;
70231+ arg->num_sprole_pws = argcompat.num_sprole_pws;
70232+ arg->mode = argcompat.mode;
70233+
70234+ return 0;
70235+}
70236+
70237+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
70238+{
70239+ struct acl_object_label_compat objcompat;
70240+
70241+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
70242+ return -EFAULT;
70243+
70244+ obj->filename = compat_ptr(objcompat.filename);
70245+ obj->inode = objcompat.inode;
70246+ obj->device = objcompat.device;
70247+ obj->mode = objcompat.mode;
70248+
70249+ obj->nested = compat_ptr(objcompat.nested);
70250+ obj->globbed = compat_ptr(objcompat.globbed);
70251+
70252+ obj->prev = compat_ptr(objcompat.prev);
70253+ obj->next = compat_ptr(objcompat.next);
70254+
70255+ return 0;
70256+}
70257+
70258+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70259+{
70260+ unsigned int i;
70261+ struct acl_subject_label_compat subjcompat;
70262+
70263+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
70264+ return -EFAULT;
70265+
70266+ subj->filename = compat_ptr(subjcompat.filename);
70267+ subj->inode = subjcompat.inode;
70268+ subj->device = subjcompat.device;
70269+ subj->mode = subjcompat.mode;
70270+ subj->cap_mask = subjcompat.cap_mask;
70271+ subj->cap_lower = subjcompat.cap_lower;
70272+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
70273+
70274+ for (i = 0; i < GR_NLIMITS; i++) {
70275+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
70276+ subj->res[i].rlim_cur = RLIM_INFINITY;
70277+ else
70278+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
70279+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
70280+ subj->res[i].rlim_max = RLIM_INFINITY;
70281+ else
70282+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
70283+ }
70284+ subj->resmask = subjcompat.resmask;
70285+
70286+ subj->user_trans_type = subjcompat.user_trans_type;
70287+ subj->group_trans_type = subjcompat.group_trans_type;
70288+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
70289+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
70290+ subj->user_trans_num = subjcompat.user_trans_num;
70291+ subj->group_trans_num = subjcompat.group_trans_num;
70292+
70293+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
70294+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
70295+ subj->ip_type = subjcompat.ip_type;
70296+ subj->ips = compat_ptr(subjcompat.ips);
70297+ subj->ip_num = subjcompat.ip_num;
70298+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
70299+
70300+ subj->crashes = subjcompat.crashes;
70301+ subj->expires = subjcompat.expires;
70302+
70303+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
70304+ subj->hash = compat_ptr(subjcompat.hash);
70305+ subj->prev = compat_ptr(subjcompat.prev);
70306+ subj->next = compat_ptr(subjcompat.next);
70307+
70308+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
70309+ subj->obj_hash_size = subjcompat.obj_hash_size;
70310+ subj->pax_flags = subjcompat.pax_flags;
70311+
70312+ return 0;
70313+}
70314+
70315+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
70316+{
70317+ struct acl_role_label_compat rolecompat;
70318+
70319+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
70320+ return -EFAULT;
70321+
70322+ role->rolename = compat_ptr(rolecompat.rolename);
70323+ role->uidgid = rolecompat.uidgid;
70324+ role->roletype = rolecompat.roletype;
70325+
70326+ role->auth_attempts = rolecompat.auth_attempts;
70327+ role->expires = rolecompat.expires;
70328+
70329+ role->root_label = compat_ptr(rolecompat.root_label);
70330+ role->hash = compat_ptr(rolecompat.hash);
70331+
70332+ role->prev = compat_ptr(rolecompat.prev);
70333+ role->next = compat_ptr(rolecompat.next);
70334+
70335+ role->transitions = compat_ptr(rolecompat.transitions);
70336+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
70337+ role->domain_children = compat_ptr(rolecompat.domain_children);
70338+ role->domain_child_num = rolecompat.domain_child_num;
70339+
70340+ role->umask = rolecompat.umask;
70341+
70342+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
70343+ role->subj_hash_size = rolecompat.subj_hash_size;
70344+
70345+ return 0;
70346+}
70347+
70348+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70349+{
70350+ struct role_allowed_ip_compat roleip_compat;
70351+
70352+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
70353+ return -EFAULT;
70354+
70355+ roleip->addr = roleip_compat.addr;
70356+ roleip->netmask = roleip_compat.netmask;
70357+
70358+ roleip->prev = compat_ptr(roleip_compat.prev);
70359+ roleip->next = compat_ptr(roleip_compat.next);
70360+
70361+ return 0;
70362+}
70363+
70364+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
70365+{
70366+ struct role_transition_compat trans_compat;
70367+
70368+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
70369+ return -EFAULT;
70370+
70371+ trans->rolename = compat_ptr(trans_compat.rolename);
70372+
70373+ trans->prev = compat_ptr(trans_compat.prev);
70374+ trans->next = compat_ptr(trans_compat.next);
70375+
70376+ return 0;
70377+
70378+}
70379+
70380+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70381+{
70382+ struct gr_hash_struct_compat hash_compat;
70383+
70384+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
70385+ return -EFAULT;
70386+
70387+ hash->table = compat_ptr(hash_compat.table);
70388+ hash->nametable = compat_ptr(hash_compat.nametable);
70389+ hash->first = compat_ptr(hash_compat.first);
70390+
70391+ hash->table_size = hash_compat.table_size;
70392+ hash->used_size = hash_compat.used_size;
70393+
70394+ hash->type = hash_compat.type;
70395+
70396+ return 0;
70397+}
70398+
70399+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
70400+{
70401+ compat_uptr_t ptrcompat;
70402+
70403+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
70404+ return -EFAULT;
70405+
70406+ *(void **)ptr = compat_ptr(ptrcompat);
70407+
70408+ return 0;
70409+}
70410+
70411+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70412+{
70413+ struct acl_ip_label_compat ip_compat;
70414+
70415+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
70416+ return -EFAULT;
70417+
70418+ ip->iface = compat_ptr(ip_compat.iface);
70419+ ip->addr = ip_compat.addr;
70420+ ip->netmask = ip_compat.netmask;
70421+ ip->low = ip_compat.low;
70422+ ip->high = ip_compat.high;
70423+ ip->mode = ip_compat.mode;
70424+ ip->type = ip_compat.type;
70425+
70426+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70427+
70428+ ip->prev = compat_ptr(ip_compat.prev);
70429+ ip->next = compat_ptr(ip_compat.next);
70430+
70431+ return 0;
70432+}
70433+
70434+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70435+{
70436+ struct sprole_pw_compat pw_compat;
70437+
70438+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70439+ return -EFAULT;
70440+
70441+ pw->rolename = compat_ptr(pw_compat.rolename);
70442+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70443+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70444+
70445+ return 0;
70446+}
70447+
70448+size_t get_gr_arg_wrapper_size_compat(void)
70449+{
70450+ return sizeof(struct gr_arg_wrapper_compat);
70451+}
70452+
70453diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70454new file mode 100644
70455index 0000000..a89b1f4
70456--- /dev/null
70457+++ b/grsecurity/gracl_fs.c
70458@@ -0,0 +1,437 @@
70459+#include <linux/kernel.h>
70460+#include <linux/sched.h>
70461+#include <linux/types.h>
70462+#include <linux/fs.h>
70463+#include <linux/file.h>
70464+#include <linux/stat.h>
70465+#include <linux/grsecurity.h>
70466+#include <linux/grinternal.h>
70467+#include <linux/gracl.h>
70468+
70469+umode_t
70470+gr_acl_umask(void)
70471+{
70472+ if (unlikely(!gr_acl_is_enabled()))
70473+ return 0;
70474+
70475+ return current->role->umask;
70476+}
70477+
70478+__u32
70479+gr_acl_handle_hidden_file(const struct dentry * dentry,
70480+ const struct vfsmount * mnt)
70481+{
70482+ __u32 mode;
70483+
70484+ if (unlikely(d_is_negative(dentry)))
70485+ return GR_FIND;
70486+
70487+ mode =
70488+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70489+
70490+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70491+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70492+ return mode;
70493+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70494+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70495+ return 0;
70496+ } else if (unlikely(!(mode & GR_FIND)))
70497+ return 0;
70498+
70499+ return GR_FIND;
70500+}
70501+
70502+__u32
70503+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70504+ int acc_mode)
70505+{
70506+ __u32 reqmode = GR_FIND;
70507+ __u32 mode;
70508+
70509+ if (unlikely(d_is_negative(dentry)))
70510+ return reqmode;
70511+
70512+ if (acc_mode & MAY_APPEND)
70513+ reqmode |= GR_APPEND;
70514+ else if (acc_mode & MAY_WRITE)
70515+ reqmode |= GR_WRITE;
70516+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70517+ reqmode |= GR_READ;
70518+
70519+ mode =
70520+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70521+ mnt);
70522+
70523+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70524+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70525+ reqmode & GR_READ ? " reading" : "",
70526+ reqmode & GR_WRITE ? " writing" : reqmode &
70527+ GR_APPEND ? " appending" : "");
70528+ return reqmode;
70529+ } else
70530+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70531+ {
70532+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70533+ reqmode & GR_READ ? " reading" : "",
70534+ reqmode & GR_WRITE ? " writing" : reqmode &
70535+ GR_APPEND ? " appending" : "");
70536+ return 0;
70537+ } else if (unlikely((mode & reqmode) != reqmode))
70538+ return 0;
70539+
70540+ return reqmode;
70541+}
70542+
70543+__u32
70544+gr_acl_handle_creat(const struct dentry * dentry,
70545+ const struct dentry * p_dentry,
70546+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70547+ const int imode)
70548+{
70549+ __u32 reqmode = GR_WRITE | GR_CREATE;
70550+ __u32 mode;
70551+
70552+ if (acc_mode & MAY_APPEND)
70553+ reqmode |= GR_APPEND;
70554+ // if a directory was required or the directory already exists, then
70555+ // don't count this open as a read
70556+ if ((acc_mode & MAY_READ) &&
70557+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70558+ reqmode |= GR_READ;
70559+ if ((open_flags & O_CREAT) &&
70560+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70561+ reqmode |= GR_SETID;
70562+
70563+ mode =
70564+ gr_check_create(dentry, p_dentry, p_mnt,
70565+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70566+
70567+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70568+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70569+ reqmode & GR_READ ? " reading" : "",
70570+ reqmode & GR_WRITE ? " writing" : reqmode &
70571+ GR_APPEND ? " appending" : "");
70572+ return reqmode;
70573+ } else
70574+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70575+ {
70576+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70577+ reqmode & GR_READ ? " reading" : "",
70578+ reqmode & GR_WRITE ? " writing" : reqmode &
70579+ GR_APPEND ? " appending" : "");
70580+ return 0;
70581+ } else if (unlikely((mode & reqmode) != reqmode))
70582+ return 0;
70583+
70584+ return reqmode;
70585+}
70586+
70587+__u32
70588+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70589+ const int fmode)
70590+{
70591+ __u32 mode, reqmode = GR_FIND;
70592+
70593+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70594+ reqmode |= GR_EXEC;
70595+ if (fmode & S_IWOTH)
70596+ reqmode |= GR_WRITE;
70597+ if (fmode & S_IROTH)
70598+ reqmode |= GR_READ;
70599+
70600+ mode =
70601+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70602+ mnt);
70603+
70604+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70605+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70606+ reqmode & GR_READ ? " reading" : "",
70607+ reqmode & GR_WRITE ? " writing" : "",
70608+ reqmode & GR_EXEC ? " executing" : "");
70609+ return reqmode;
70610+ } else
70611+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70612+ {
70613+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70614+ reqmode & GR_READ ? " reading" : "",
70615+ reqmode & GR_WRITE ? " writing" : "",
70616+ reqmode & GR_EXEC ? " executing" : "");
70617+ return 0;
70618+ } else if (unlikely((mode & reqmode) != reqmode))
70619+ return 0;
70620+
70621+ return reqmode;
70622+}
70623+
70624+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70625+{
70626+ __u32 mode;
70627+
70628+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70629+
70630+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70631+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70632+ return mode;
70633+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70634+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70635+ return 0;
70636+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70637+ return 0;
70638+
70639+ return (reqmode);
70640+}
70641+
70642+__u32
70643+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70644+{
70645+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70646+}
70647+
70648+__u32
70649+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70650+{
70651+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70652+}
70653+
70654+__u32
70655+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70656+{
70657+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70658+}
70659+
70660+__u32
70661+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70662+{
70663+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70664+}
70665+
70666+__u32
70667+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70668+ umode_t *modeptr)
70669+{
70670+ umode_t mode;
70671+
70672+ *modeptr &= ~gr_acl_umask();
70673+ mode = *modeptr;
70674+
70675+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70676+ return 1;
70677+
70678+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70679+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70680+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70681+ GR_CHMOD_ACL_MSG);
70682+ } else {
70683+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70684+ }
70685+}
70686+
70687+__u32
70688+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70689+{
70690+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70691+}
70692+
70693+__u32
70694+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70695+{
70696+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70697+}
70698+
70699+__u32
70700+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70701+{
70702+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70703+}
70704+
70705+__u32
70706+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70707+{
70708+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70709+}
70710+
70711+__u32
70712+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70713+{
70714+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70715+ GR_UNIXCONNECT_ACL_MSG);
70716+}
70717+
70718+/* hardlinks require at minimum create and link permission,
70719+ any additional privilege required is based on the
70720+ privilege of the file being linked to
70721+*/
70722+__u32
70723+gr_acl_handle_link(const struct dentry * new_dentry,
70724+ const struct dentry * parent_dentry,
70725+ const struct vfsmount * parent_mnt,
70726+ const struct dentry * old_dentry,
70727+ const struct vfsmount * old_mnt, const struct filename *to)
70728+{
70729+ __u32 mode;
70730+ __u32 needmode = GR_CREATE | GR_LINK;
70731+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70732+
70733+ mode =
70734+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70735+ old_mnt);
70736+
70737+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70738+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70739+ return mode;
70740+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70741+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70742+ return 0;
70743+ } else if (unlikely((mode & needmode) != needmode))
70744+ return 0;
70745+
70746+ return 1;
70747+}
70748+
70749+__u32
70750+gr_acl_handle_symlink(const struct dentry * new_dentry,
70751+ const struct dentry * parent_dentry,
70752+ const struct vfsmount * parent_mnt, const struct filename *from)
70753+{
70754+ __u32 needmode = GR_WRITE | GR_CREATE;
70755+ __u32 mode;
70756+
70757+ mode =
70758+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
70759+ GR_CREATE | GR_AUDIT_CREATE |
70760+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70761+
70762+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70763+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70764+ return mode;
70765+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70766+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70767+ return 0;
70768+ } else if (unlikely((mode & needmode) != needmode))
70769+ return 0;
70770+
70771+ return (GR_WRITE | GR_CREATE);
70772+}
70773+
70774+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)
70775+{
70776+ __u32 mode;
70777+
70778+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70779+
70780+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70781+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70782+ return mode;
70783+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70784+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70785+ return 0;
70786+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70787+ return 0;
70788+
70789+ return (reqmode);
70790+}
70791+
70792+__u32
70793+gr_acl_handle_mknod(const struct dentry * new_dentry,
70794+ const struct dentry * parent_dentry,
70795+ const struct vfsmount * parent_mnt,
70796+ const int mode)
70797+{
70798+ __u32 reqmode = GR_WRITE | GR_CREATE;
70799+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70800+ reqmode |= GR_SETID;
70801+
70802+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70803+ reqmode, GR_MKNOD_ACL_MSG);
70804+}
70805+
70806+__u32
70807+gr_acl_handle_mkdir(const struct dentry *new_dentry,
70808+ const struct dentry *parent_dentry,
70809+ const struct vfsmount *parent_mnt)
70810+{
70811+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70812+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70813+}
70814+
70815+#define RENAME_CHECK_SUCCESS(old, new) \
70816+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70817+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70818+
70819+int
70820+gr_acl_handle_rename(struct dentry *new_dentry,
70821+ struct dentry *parent_dentry,
70822+ const struct vfsmount *parent_mnt,
70823+ struct dentry *old_dentry,
70824+ struct inode *old_parent_inode,
70825+ struct vfsmount *old_mnt, const struct filename *newname)
70826+{
70827+ __u32 comp1, comp2;
70828+ int error = 0;
70829+
70830+ if (unlikely(!gr_acl_is_enabled()))
70831+ return 0;
70832+
70833+ if (d_is_negative(new_dentry)) {
70834+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70835+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70836+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70837+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70838+ GR_DELETE | GR_AUDIT_DELETE |
70839+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70840+ GR_SUPPRESS, old_mnt);
70841+ } else {
70842+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70843+ GR_CREATE | GR_DELETE |
70844+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70845+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70846+ GR_SUPPRESS, parent_mnt);
70847+ comp2 =
70848+ gr_search_file(old_dentry,
70849+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70850+ GR_DELETE | GR_AUDIT_DELETE |
70851+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70852+ }
70853+
70854+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70855+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70856+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70857+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70858+ && !(comp2 & GR_SUPPRESS)) {
70859+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70860+ error = -EACCES;
70861+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70862+ error = -EACCES;
70863+
70864+ return error;
70865+}
70866+
70867+void
70868+gr_acl_handle_exit(void)
70869+{
70870+ u16 id;
70871+ char *rolename;
70872+
70873+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70874+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70875+ id = current->acl_role_id;
70876+ rolename = current->role->rolename;
70877+ gr_set_acls(1);
70878+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70879+ }
70880+
70881+ gr_put_exec_file(current);
70882+ return;
70883+}
70884+
70885+int
70886+gr_acl_handle_procpidmem(const struct task_struct *task)
70887+{
70888+ if (unlikely(!gr_acl_is_enabled()))
70889+ return 0;
70890+
70891+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70892+ return -EACCES;
70893+
70894+ return 0;
70895+}
70896diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70897new file mode 100644
70898index 0000000..f056b81
70899--- /dev/null
70900+++ b/grsecurity/gracl_ip.c
70901@@ -0,0 +1,386 @@
70902+#include <linux/kernel.h>
70903+#include <asm/uaccess.h>
70904+#include <asm/errno.h>
70905+#include <net/sock.h>
70906+#include <linux/file.h>
70907+#include <linux/fs.h>
70908+#include <linux/net.h>
70909+#include <linux/in.h>
70910+#include <linux/skbuff.h>
70911+#include <linux/ip.h>
70912+#include <linux/udp.h>
70913+#include <linux/types.h>
70914+#include <linux/sched.h>
70915+#include <linux/netdevice.h>
70916+#include <linux/inetdevice.h>
70917+#include <linux/gracl.h>
70918+#include <linux/grsecurity.h>
70919+#include <linux/grinternal.h>
70920+
70921+#define GR_BIND 0x01
70922+#define GR_CONNECT 0x02
70923+#define GR_INVERT 0x04
70924+#define GR_BINDOVERRIDE 0x08
70925+#define GR_CONNECTOVERRIDE 0x10
70926+#define GR_SOCK_FAMILY 0x20
70927+
70928+static const char * gr_protocols[IPPROTO_MAX] = {
70929+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70930+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70931+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70932+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70933+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70934+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70935+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70936+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70937+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70938+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70939+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70940+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70941+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70942+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70943+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70944+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70945+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70946+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70947+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70948+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70949+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70950+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70951+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70952+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70953+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70954+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70955+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70956+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70957+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70958+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70959+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70960+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70961+ };
70962+
70963+static const char * gr_socktypes[SOCK_MAX] = {
70964+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70965+ "unknown:7", "unknown:8", "unknown:9", "packet"
70966+ };
70967+
70968+static const char * gr_sockfamilies[AF_MAX+1] = {
70969+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70970+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70971+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70972+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70973+ };
70974+
70975+const char *
70976+gr_proto_to_name(unsigned char proto)
70977+{
70978+ return gr_protocols[proto];
70979+}
70980+
70981+const char *
70982+gr_socktype_to_name(unsigned char type)
70983+{
70984+ return gr_socktypes[type];
70985+}
70986+
70987+const char *
70988+gr_sockfamily_to_name(unsigned char family)
70989+{
70990+ return gr_sockfamilies[family];
70991+}
70992+
70993+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70994+
70995+int
70996+gr_search_socket(const int domain, const int type, const int protocol)
70997+{
70998+ struct acl_subject_label *curr;
70999+ const struct cred *cred = current_cred();
71000+
71001+ if (unlikely(!gr_acl_is_enabled()))
71002+ goto exit;
71003+
71004+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
71005+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
71006+ goto exit; // let the kernel handle it
71007+
71008+ curr = current->acl;
71009+
71010+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
71011+ /* the family is allowed, if this is PF_INET allow it only if
71012+ the extra sock type/protocol checks pass */
71013+ if (domain == PF_INET)
71014+ goto inet_check;
71015+ goto exit;
71016+ } else {
71017+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71018+ __u32 fakeip = 0;
71019+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71020+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71021+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71022+ gr_to_filename(current->exec_file->f_path.dentry,
71023+ current->exec_file->f_path.mnt) :
71024+ curr->filename, curr->filename,
71025+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
71026+ &current->signal->saved_ip);
71027+ goto exit;
71028+ }
71029+ goto exit_fail;
71030+ }
71031+
71032+inet_check:
71033+ /* the rest of this checking is for IPv4 only */
71034+ if (!curr->ips)
71035+ goto exit;
71036+
71037+ if ((curr->ip_type & (1U << type)) &&
71038+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
71039+ goto exit;
71040+
71041+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71042+ /* we don't place acls on raw sockets , and sometimes
71043+ dgram/ip sockets are opened for ioctl and not
71044+ bind/connect, so we'll fake a bind learn log */
71045+ if (type == SOCK_RAW || type == SOCK_PACKET) {
71046+ __u32 fakeip = 0;
71047+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71048+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71049+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71050+ gr_to_filename(current->exec_file->f_path.dentry,
71051+ current->exec_file->f_path.mnt) :
71052+ curr->filename, curr->filename,
71053+ &fakeip, 0, type,
71054+ protocol, GR_CONNECT, &current->signal->saved_ip);
71055+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
71056+ __u32 fakeip = 0;
71057+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71058+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71059+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71060+ gr_to_filename(current->exec_file->f_path.dentry,
71061+ current->exec_file->f_path.mnt) :
71062+ curr->filename, curr->filename,
71063+ &fakeip, 0, type,
71064+ protocol, GR_BIND, &current->signal->saved_ip);
71065+ }
71066+ /* we'll log when they use connect or bind */
71067+ goto exit;
71068+ }
71069+
71070+exit_fail:
71071+ if (domain == PF_INET)
71072+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
71073+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
71074+ else if (rcu_access_pointer(net_families[domain]) != NULL)
71075+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
71076+ gr_socktype_to_name(type), protocol);
71077+
71078+ return 0;
71079+exit:
71080+ return 1;
71081+}
71082+
71083+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)
71084+{
71085+ if ((ip->mode & mode) &&
71086+ (ip_port >= ip->low) &&
71087+ (ip_port <= ip->high) &&
71088+ ((ntohl(ip_addr) & our_netmask) ==
71089+ (ntohl(our_addr) & our_netmask))
71090+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
71091+ && (ip->type & (1U << type))) {
71092+ if (ip->mode & GR_INVERT)
71093+ return 2; // specifically denied
71094+ else
71095+ return 1; // allowed
71096+ }
71097+
71098+ return 0; // not specifically allowed, may continue parsing
71099+}
71100+
71101+static int
71102+gr_search_connectbind(const int full_mode, struct sock *sk,
71103+ struct sockaddr_in *addr, const int type)
71104+{
71105+ char iface[IFNAMSIZ] = {0};
71106+ struct acl_subject_label *curr;
71107+ struct acl_ip_label *ip;
71108+ struct inet_sock *isk;
71109+ struct net_device *dev;
71110+ struct in_device *idev;
71111+ unsigned long i;
71112+ int ret;
71113+ int mode = full_mode & (GR_BIND | GR_CONNECT);
71114+ __u32 ip_addr = 0;
71115+ __u32 our_addr;
71116+ __u32 our_netmask;
71117+ char *p;
71118+ __u16 ip_port = 0;
71119+ const struct cred *cred = current_cred();
71120+
71121+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
71122+ return 0;
71123+
71124+ curr = current->acl;
71125+ isk = inet_sk(sk);
71126+
71127+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
71128+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
71129+ addr->sin_addr.s_addr = curr->inaddr_any_override;
71130+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
71131+ struct sockaddr_in saddr;
71132+ int err;
71133+
71134+ saddr.sin_family = AF_INET;
71135+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
71136+ saddr.sin_port = isk->inet_sport;
71137+
71138+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71139+ if (err)
71140+ return err;
71141+
71142+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71143+ if (err)
71144+ return err;
71145+ }
71146+
71147+ if (!curr->ips)
71148+ return 0;
71149+
71150+ ip_addr = addr->sin_addr.s_addr;
71151+ ip_port = ntohs(addr->sin_port);
71152+
71153+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71154+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71155+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71156+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71157+ gr_to_filename(current->exec_file->f_path.dentry,
71158+ current->exec_file->f_path.mnt) :
71159+ curr->filename, curr->filename,
71160+ &ip_addr, ip_port, type,
71161+ sk->sk_protocol, mode, &current->signal->saved_ip);
71162+ return 0;
71163+ }
71164+
71165+ for (i = 0; i < curr->ip_num; i++) {
71166+ ip = *(curr->ips + i);
71167+ if (ip->iface != NULL) {
71168+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
71169+ p = strchr(iface, ':');
71170+ if (p != NULL)
71171+ *p = '\0';
71172+ dev = dev_get_by_name(sock_net(sk), iface);
71173+ if (dev == NULL)
71174+ continue;
71175+ idev = in_dev_get(dev);
71176+ if (idev == NULL) {
71177+ dev_put(dev);
71178+ continue;
71179+ }
71180+ rcu_read_lock();
71181+ for_ifa(idev) {
71182+ if (!strcmp(ip->iface, ifa->ifa_label)) {
71183+ our_addr = ifa->ifa_address;
71184+ our_netmask = 0xffffffff;
71185+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71186+ if (ret == 1) {
71187+ rcu_read_unlock();
71188+ in_dev_put(idev);
71189+ dev_put(dev);
71190+ return 0;
71191+ } else if (ret == 2) {
71192+ rcu_read_unlock();
71193+ in_dev_put(idev);
71194+ dev_put(dev);
71195+ goto denied;
71196+ }
71197+ }
71198+ } endfor_ifa(idev);
71199+ rcu_read_unlock();
71200+ in_dev_put(idev);
71201+ dev_put(dev);
71202+ } else {
71203+ our_addr = ip->addr;
71204+ our_netmask = ip->netmask;
71205+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71206+ if (ret == 1)
71207+ return 0;
71208+ else if (ret == 2)
71209+ goto denied;
71210+ }
71211+ }
71212+
71213+denied:
71214+ if (mode == GR_BIND)
71215+ 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));
71216+ else if (mode == GR_CONNECT)
71217+ 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));
71218+
71219+ return -EACCES;
71220+}
71221+
71222+int
71223+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
71224+{
71225+ /* always allow disconnection of dgram sockets with connect */
71226+ if (addr->sin_family == AF_UNSPEC)
71227+ return 0;
71228+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
71229+}
71230+
71231+int
71232+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
71233+{
71234+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
71235+}
71236+
71237+int gr_search_listen(struct socket *sock)
71238+{
71239+ struct sock *sk = sock->sk;
71240+ struct sockaddr_in addr;
71241+
71242+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71243+ addr.sin_port = inet_sk(sk)->inet_sport;
71244+
71245+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71246+}
71247+
71248+int gr_search_accept(struct socket *sock)
71249+{
71250+ struct sock *sk = sock->sk;
71251+ struct sockaddr_in addr;
71252+
71253+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71254+ addr.sin_port = inet_sk(sk)->inet_sport;
71255+
71256+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71257+}
71258+
71259+int
71260+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
71261+{
71262+ if (addr)
71263+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
71264+ else {
71265+ struct sockaddr_in sin;
71266+ const struct inet_sock *inet = inet_sk(sk);
71267+
71268+ sin.sin_addr.s_addr = inet->inet_daddr;
71269+ sin.sin_port = inet->inet_dport;
71270+
71271+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71272+ }
71273+}
71274+
71275+int
71276+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
71277+{
71278+ struct sockaddr_in sin;
71279+
71280+ if (unlikely(skb->len < sizeof (struct udphdr)))
71281+ return 0; // skip this packet
71282+
71283+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
71284+ sin.sin_port = udp_hdr(skb)->source;
71285+
71286+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71287+}
71288diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
71289new file mode 100644
71290index 0000000..25f54ef
71291--- /dev/null
71292+++ b/grsecurity/gracl_learn.c
71293@@ -0,0 +1,207 @@
71294+#include <linux/kernel.h>
71295+#include <linux/mm.h>
71296+#include <linux/sched.h>
71297+#include <linux/poll.h>
71298+#include <linux/string.h>
71299+#include <linux/file.h>
71300+#include <linux/types.h>
71301+#include <linux/vmalloc.h>
71302+#include <linux/grinternal.h>
71303+
71304+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
71305+ size_t count, loff_t *ppos);
71306+extern int gr_acl_is_enabled(void);
71307+
71308+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
71309+static int gr_learn_attached;
71310+
71311+/* use a 512k buffer */
71312+#define LEARN_BUFFER_SIZE (512 * 1024)
71313+
71314+static DEFINE_SPINLOCK(gr_learn_lock);
71315+static DEFINE_MUTEX(gr_learn_user_mutex);
71316+
71317+/* we need to maintain two buffers, so that the kernel context of grlearn
71318+ uses a semaphore around the userspace copying, and the other kernel contexts
71319+ use a spinlock when copying into the buffer, since they cannot sleep
71320+*/
71321+static char *learn_buffer;
71322+static char *learn_buffer_user;
71323+static int learn_buffer_len;
71324+static int learn_buffer_user_len;
71325+
71326+static ssize_t
71327+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
71328+{
71329+ DECLARE_WAITQUEUE(wait, current);
71330+ ssize_t retval = 0;
71331+
71332+ add_wait_queue(&learn_wait, &wait);
71333+ set_current_state(TASK_INTERRUPTIBLE);
71334+ do {
71335+ mutex_lock(&gr_learn_user_mutex);
71336+ spin_lock(&gr_learn_lock);
71337+ if (learn_buffer_len)
71338+ break;
71339+ spin_unlock(&gr_learn_lock);
71340+ mutex_unlock(&gr_learn_user_mutex);
71341+ if (file->f_flags & O_NONBLOCK) {
71342+ retval = -EAGAIN;
71343+ goto out;
71344+ }
71345+ if (signal_pending(current)) {
71346+ retval = -ERESTARTSYS;
71347+ goto out;
71348+ }
71349+
71350+ schedule();
71351+ } while (1);
71352+
71353+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
71354+ learn_buffer_user_len = learn_buffer_len;
71355+ retval = learn_buffer_len;
71356+ learn_buffer_len = 0;
71357+
71358+ spin_unlock(&gr_learn_lock);
71359+
71360+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
71361+ retval = -EFAULT;
71362+
71363+ mutex_unlock(&gr_learn_user_mutex);
71364+out:
71365+ set_current_state(TASK_RUNNING);
71366+ remove_wait_queue(&learn_wait, &wait);
71367+ return retval;
71368+}
71369+
71370+static unsigned int
71371+poll_learn(struct file * file, poll_table * wait)
71372+{
71373+ poll_wait(file, &learn_wait, wait);
71374+
71375+ if (learn_buffer_len)
71376+ return (POLLIN | POLLRDNORM);
71377+
71378+ return 0;
71379+}
71380+
71381+void
71382+gr_clear_learn_entries(void)
71383+{
71384+ char *tmp;
71385+
71386+ mutex_lock(&gr_learn_user_mutex);
71387+ spin_lock(&gr_learn_lock);
71388+ tmp = learn_buffer;
71389+ learn_buffer = NULL;
71390+ spin_unlock(&gr_learn_lock);
71391+ if (tmp)
71392+ vfree(tmp);
71393+ if (learn_buffer_user != NULL) {
71394+ vfree(learn_buffer_user);
71395+ learn_buffer_user = NULL;
71396+ }
71397+ learn_buffer_len = 0;
71398+ mutex_unlock(&gr_learn_user_mutex);
71399+
71400+ return;
71401+}
71402+
71403+void
71404+gr_add_learn_entry(const char *fmt, ...)
71405+{
71406+ va_list args;
71407+ unsigned int len;
71408+
71409+ if (!gr_learn_attached)
71410+ return;
71411+
71412+ spin_lock(&gr_learn_lock);
71413+
71414+ /* leave a gap at the end so we know when it's "full" but don't have to
71415+ compute the exact length of the string we're trying to append
71416+ */
71417+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71418+ spin_unlock(&gr_learn_lock);
71419+ wake_up_interruptible(&learn_wait);
71420+ return;
71421+ }
71422+ if (learn_buffer == NULL) {
71423+ spin_unlock(&gr_learn_lock);
71424+ return;
71425+ }
71426+
71427+ va_start(args, fmt);
71428+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71429+ va_end(args);
71430+
71431+ learn_buffer_len += len + 1;
71432+
71433+ spin_unlock(&gr_learn_lock);
71434+ wake_up_interruptible(&learn_wait);
71435+
71436+ return;
71437+}
71438+
71439+static int
71440+open_learn(struct inode *inode, struct file *file)
71441+{
71442+ if (file->f_mode & FMODE_READ && gr_learn_attached)
71443+ return -EBUSY;
71444+ if (file->f_mode & FMODE_READ) {
71445+ int retval = 0;
71446+ mutex_lock(&gr_learn_user_mutex);
71447+ if (learn_buffer == NULL)
71448+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71449+ if (learn_buffer_user == NULL)
71450+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71451+ if (learn_buffer == NULL) {
71452+ retval = -ENOMEM;
71453+ goto out_error;
71454+ }
71455+ if (learn_buffer_user == NULL) {
71456+ retval = -ENOMEM;
71457+ goto out_error;
71458+ }
71459+ learn_buffer_len = 0;
71460+ learn_buffer_user_len = 0;
71461+ gr_learn_attached = 1;
71462+out_error:
71463+ mutex_unlock(&gr_learn_user_mutex);
71464+ return retval;
71465+ }
71466+ return 0;
71467+}
71468+
71469+static int
71470+close_learn(struct inode *inode, struct file *file)
71471+{
71472+ if (file->f_mode & FMODE_READ) {
71473+ char *tmp = NULL;
71474+ mutex_lock(&gr_learn_user_mutex);
71475+ spin_lock(&gr_learn_lock);
71476+ tmp = learn_buffer;
71477+ learn_buffer = NULL;
71478+ spin_unlock(&gr_learn_lock);
71479+ if (tmp)
71480+ vfree(tmp);
71481+ if (learn_buffer_user != NULL) {
71482+ vfree(learn_buffer_user);
71483+ learn_buffer_user = NULL;
71484+ }
71485+ learn_buffer_len = 0;
71486+ learn_buffer_user_len = 0;
71487+ gr_learn_attached = 0;
71488+ mutex_unlock(&gr_learn_user_mutex);
71489+ }
71490+
71491+ return 0;
71492+}
71493+
71494+const struct file_operations grsec_fops = {
71495+ .read = read_learn,
71496+ .write = write_grsec_handler,
71497+ .open = open_learn,
71498+ .release = close_learn,
71499+ .poll = poll_learn,
71500+};
71501diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71502new file mode 100644
71503index 0000000..361a099
71504--- /dev/null
71505+++ b/grsecurity/gracl_policy.c
71506@@ -0,0 +1,1782 @@
71507+#include <linux/kernel.h>
71508+#include <linux/module.h>
71509+#include <linux/sched.h>
71510+#include <linux/mm.h>
71511+#include <linux/file.h>
71512+#include <linux/fs.h>
71513+#include <linux/namei.h>
71514+#include <linux/mount.h>
71515+#include <linux/tty.h>
71516+#include <linux/proc_fs.h>
71517+#include <linux/lglock.h>
71518+#include <linux/slab.h>
71519+#include <linux/vmalloc.h>
71520+#include <linux/types.h>
71521+#include <linux/sysctl.h>
71522+#include <linux/netdevice.h>
71523+#include <linux/ptrace.h>
71524+#include <linux/gracl.h>
71525+#include <linux/gralloc.h>
71526+#include <linux/security.h>
71527+#include <linux/grinternal.h>
71528+#include <linux/pid_namespace.h>
71529+#include <linux/stop_machine.h>
71530+#include <linux/fdtable.h>
71531+#include <linux/percpu.h>
71532+#include <linux/lglock.h>
71533+#include <linux/hugetlb.h>
71534+#include <linux/posix-timers.h>
71535+#include "../fs/mount.h"
71536+
71537+#include <asm/uaccess.h>
71538+#include <asm/errno.h>
71539+#include <asm/mman.h>
71540+
71541+extern struct gr_policy_state *polstate;
71542+
71543+#define FOR_EACH_ROLE_START(role) \
71544+ role = polstate->role_list; \
71545+ while (role) {
71546+
71547+#define FOR_EACH_ROLE_END(role) \
71548+ role = role->prev; \
71549+ }
71550+
71551+struct path gr_real_root;
71552+
71553+extern struct gr_alloc_state *current_alloc_state;
71554+
71555+u16 acl_sp_role_value;
71556+
71557+static DEFINE_MUTEX(gr_dev_mutex);
71558+
71559+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71560+extern void gr_clear_learn_entries(void);
71561+
71562+static struct gr_arg gr_usermode;
71563+static unsigned char gr_system_salt[GR_SALT_LEN];
71564+static unsigned char gr_system_sum[GR_SHA_LEN];
71565+
71566+static unsigned int gr_auth_attempts = 0;
71567+static unsigned long gr_auth_expires = 0UL;
71568+
71569+struct acl_object_label *fakefs_obj_rw;
71570+struct acl_object_label *fakefs_obj_rwx;
71571+
71572+extern int gr_init_uidset(void);
71573+extern void gr_free_uidset(void);
71574+extern void gr_remove_uid(uid_t uid);
71575+extern int gr_find_uid(uid_t uid);
71576+
71577+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71578+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71579+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71580+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71581+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);
71582+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71583+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71584+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71585+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71586+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71587+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71588+extern void assign_special_role(const char *rolename);
71589+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71590+extern int gr_rbac_disable(void *unused);
71591+extern void gr_enable_rbac_system(void);
71592+
71593+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71594+{
71595+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71596+ return -EFAULT;
71597+
71598+ return 0;
71599+}
71600+
71601+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71602+{
71603+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71604+ return -EFAULT;
71605+
71606+ return 0;
71607+}
71608+
71609+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71610+{
71611+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71612+ return -EFAULT;
71613+
71614+ return 0;
71615+}
71616+
71617+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71618+{
71619+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71620+ return -EFAULT;
71621+
71622+ return 0;
71623+}
71624+
71625+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71626+{
71627+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71628+ return -EFAULT;
71629+
71630+ return 0;
71631+}
71632+
71633+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71634+{
71635+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71636+ return -EFAULT;
71637+
71638+ return 0;
71639+}
71640+
71641+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71642+{
71643+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71644+ return -EFAULT;
71645+
71646+ return 0;
71647+}
71648+
71649+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71650+{
71651+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71652+ return -EFAULT;
71653+
71654+ return 0;
71655+}
71656+
71657+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71658+{
71659+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71660+ return -EFAULT;
71661+
71662+ return 0;
71663+}
71664+
71665+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71666+{
71667+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71668+ return -EFAULT;
71669+
71670+ if (((uwrap->version != GRSECURITY_VERSION) &&
71671+ (uwrap->version != 0x2901)) ||
71672+ (uwrap->size != sizeof(struct gr_arg)))
71673+ return -EINVAL;
71674+
71675+ return 0;
71676+}
71677+
71678+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71679+{
71680+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71681+ return -EFAULT;
71682+
71683+ return 0;
71684+}
71685+
71686+static size_t get_gr_arg_wrapper_size_normal(void)
71687+{
71688+ return sizeof(struct gr_arg_wrapper);
71689+}
71690+
71691+#ifdef CONFIG_COMPAT
71692+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71693+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71694+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71695+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71696+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71697+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71698+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71699+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71700+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71701+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71702+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71703+extern size_t get_gr_arg_wrapper_size_compat(void);
71704+
71705+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71706+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71707+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71708+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71709+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71710+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71711+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71712+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71713+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71714+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71715+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71716+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71717+
71718+#else
71719+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71720+#define copy_gr_arg copy_gr_arg_normal
71721+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71722+#define copy_acl_object_label copy_acl_object_label_normal
71723+#define copy_acl_subject_label copy_acl_subject_label_normal
71724+#define copy_acl_role_label copy_acl_role_label_normal
71725+#define copy_acl_ip_label copy_acl_ip_label_normal
71726+#define copy_pointer_from_array copy_pointer_from_array_normal
71727+#define copy_sprole_pw copy_sprole_pw_normal
71728+#define copy_role_transition copy_role_transition_normal
71729+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71730+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71731+#endif
71732+
71733+static struct acl_subject_label *
71734+lookup_subject_map(const struct acl_subject_label *userp)
71735+{
71736+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71737+ struct subject_map *match;
71738+
71739+ match = polstate->subj_map_set.s_hash[index];
71740+
71741+ while (match && match->user != userp)
71742+ match = match->next;
71743+
71744+ if (match != NULL)
71745+ return match->kernel;
71746+ else
71747+ return NULL;
71748+}
71749+
71750+static void
71751+insert_subj_map_entry(struct subject_map *subjmap)
71752+{
71753+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71754+ struct subject_map **curr;
71755+
71756+ subjmap->prev = NULL;
71757+
71758+ curr = &polstate->subj_map_set.s_hash[index];
71759+ if (*curr != NULL)
71760+ (*curr)->prev = subjmap;
71761+
71762+ subjmap->next = *curr;
71763+ *curr = subjmap;
71764+
71765+ return;
71766+}
71767+
71768+static void
71769+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71770+{
71771+ unsigned int index =
71772+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71773+ struct acl_role_label **curr;
71774+ struct acl_role_label *tmp, *tmp2;
71775+
71776+ curr = &polstate->acl_role_set.r_hash[index];
71777+
71778+ /* simple case, slot is empty, just set it to our role */
71779+ if (*curr == NULL) {
71780+ *curr = role;
71781+ } else {
71782+ /* example:
71783+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
71784+ 2 -> 3
71785+ */
71786+ /* first check to see if we can already be reached via this slot */
71787+ tmp = *curr;
71788+ while (tmp && tmp != role)
71789+ tmp = tmp->next;
71790+ if (tmp == role) {
71791+ /* we don't need to add ourselves to this slot's chain */
71792+ return;
71793+ }
71794+ /* we need to add ourselves to this chain, two cases */
71795+ if (role->next == NULL) {
71796+ /* simple case, append the current chain to our role */
71797+ role->next = *curr;
71798+ *curr = role;
71799+ } else {
71800+ /* 1 -> 2 -> 3 -> 4
71801+ 2 -> 3 -> 4
71802+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71803+ */
71804+ /* trickier case: walk our role's chain until we find
71805+ the role for the start of the current slot's chain */
71806+ tmp = role;
71807+ tmp2 = *curr;
71808+ while (tmp->next && tmp->next != tmp2)
71809+ tmp = tmp->next;
71810+ if (tmp->next == tmp2) {
71811+ /* from example above, we found 3, so just
71812+ replace this slot's chain with ours */
71813+ *curr = role;
71814+ } else {
71815+ /* we didn't find a subset of our role's chain
71816+ in the current slot's chain, so append their
71817+ chain to ours, and set us as the first role in
71818+ the slot's chain
71819+
71820+ we could fold this case with the case above,
71821+ but making it explicit for clarity
71822+ */
71823+ tmp->next = tmp2;
71824+ *curr = role;
71825+ }
71826+ }
71827+ }
71828+
71829+ return;
71830+}
71831+
71832+static void
71833+insert_acl_role_label(struct acl_role_label *role)
71834+{
71835+ int i;
71836+
71837+ if (polstate->role_list == NULL) {
71838+ polstate->role_list = role;
71839+ role->prev = NULL;
71840+ } else {
71841+ role->prev = polstate->role_list;
71842+ polstate->role_list = role;
71843+ }
71844+
71845+ /* used for hash chains */
71846+ role->next = NULL;
71847+
71848+ if (role->roletype & GR_ROLE_DOMAIN) {
71849+ for (i = 0; i < role->domain_child_num; i++)
71850+ __insert_acl_role_label(role, role->domain_children[i]);
71851+ } else
71852+ __insert_acl_role_label(role, role->uidgid);
71853+}
71854+
71855+static int
71856+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71857+{
71858+ struct name_entry **curr, *nentry;
71859+ struct inodev_entry *ientry;
71860+ unsigned int len = strlen(name);
71861+ unsigned int key = full_name_hash(name, len);
71862+ unsigned int index = key % polstate->name_set.n_size;
71863+
71864+ curr = &polstate->name_set.n_hash[index];
71865+
71866+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71867+ curr = &((*curr)->next);
71868+
71869+ if (*curr != NULL)
71870+ return 1;
71871+
71872+ nentry = acl_alloc(sizeof (struct name_entry));
71873+ if (nentry == NULL)
71874+ return 0;
71875+ ientry = acl_alloc(sizeof (struct inodev_entry));
71876+ if (ientry == NULL)
71877+ return 0;
71878+ ientry->nentry = nentry;
71879+
71880+ nentry->key = key;
71881+ nentry->name = name;
71882+ nentry->inode = inode;
71883+ nentry->device = device;
71884+ nentry->len = len;
71885+ nentry->deleted = deleted;
71886+
71887+ nentry->prev = NULL;
71888+ curr = &polstate->name_set.n_hash[index];
71889+ if (*curr != NULL)
71890+ (*curr)->prev = nentry;
71891+ nentry->next = *curr;
71892+ *curr = nentry;
71893+
71894+ /* insert us into the table searchable by inode/dev */
71895+ __insert_inodev_entry(polstate, ientry);
71896+
71897+ return 1;
71898+}
71899+
71900+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71901+
71902+static void *
71903+create_table(__u32 * len, int elementsize)
71904+{
71905+ unsigned int table_sizes[] = {
71906+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71907+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71908+ 4194301, 8388593, 16777213, 33554393, 67108859
71909+ };
71910+ void *newtable = NULL;
71911+ unsigned int pwr = 0;
71912+
71913+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71914+ table_sizes[pwr] <= *len)
71915+ pwr++;
71916+
71917+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71918+ return newtable;
71919+
71920+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71921+ newtable =
71922+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71923+ else
71924+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71925+
71926+ *len = table_sizes[pwr];
71927+
71928+ return newtable;
71929+}
71930+
71931+static int
71932+init_variables(const struct gr_arg *arg, bool reload)
71933+{
71934+ struct task_struct *reaper = init_pid_ns.child_reaper;
71935+ unsigned int stacksize;
71936+
71937+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71938+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71939+ polstate->name_set.n_size = arg->role_db.num_objects;
71940+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71941+
71942+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71943+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71944+ return 1;
71945+
71946+ if (!reload) {
71947+ if (!gr_init_uidset())
71948+ return 1;
71949+ }
71950+
71951+ /* set up the stack that holds allocation info */
71952+
71953+ stacksize = arg->role_db.num_pointers + 5;
71954+
71955+ if (!acl_alloc_stack_init(stacksize))
71956+ return 1;
71957+
71958+ if (!reload) {
71959+ /* grab reference for the real root dentry and vfsmount */
71960+ get_fs_root(reaper->fs, &gr_real_root);
71961+
71962+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71963+ 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);
71964+#endif
71965+
71966+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71967+ if (fakefs_obj_rw == NULL)
71968+ return 1;
71969+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71970+
71971+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71972+ if (fakefs_obj_rwx == NULL)
71973+ return 1;
71974+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71975+ }
71976+
71977+ polstate->subj_map_set.s_hash =
71978+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71979+ polstate->acl_role_set.r_hash =
71980+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71981+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71982+ polstate->inodev_set.i_hash =
71983+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71984+
71985+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71986+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71987+ return 1;
71988+
71989+ memset(polstate->subj_map_set.s_hash, 0,
71990+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71991+ memset(polstate->acl_role_set.r_hash, 0,
71992+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71993+ memset(polstate->name_set.n_hash, 0,
71994+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71995+ memset(polstate->inodev_set.i_hash, 0,
71996+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71997+
71998+ return 0;
71999+}
72000+
72001+/* free information not needed after startup
72002+ currently contains user->kernel pointer mappings for subjects
72003+*/
72004+
72005+static void
72006+free_init_variables(void)
72007+{
72008+ __u32 i;
72009+
72010+ if (polstate->subj_map_set.s_hash) {
72011+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
72012+ if (polstate->subj_map_set.s_hash[i]) {
72013+ kfree(polstate->subj_map_set.s_hash[i]);
72014+ polstate->subj_map_set.s_hash[i] = NULL;
72015+ }
72016+ }
72017+
72018+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
72019+ PAGE_SIZE)
72020+ kfree(polstate->subj_map_set.s_hash);
72021+ else
72022+ vfree(polstate->subj_map_set.s_hash);
72023+ }
72024+
72025+ return;
72026+}
72027+
72028+static void
72029+free_variables(bool reload)
72030+{
72031+ struct acl_subject_label *s;
72032+ struct acl_role_label *r;
72033+ struct task_struct *task, *task2;
72034+ unsigned int x;
72035+
72036+ if (!reload) {
72037+ gr_clear_learn_entries();
72038+
72039+ read_lock(&tasklist_lock);
72040+ do_each_thread(task2, task) {
72041+ task->acl_sp_role = 0;
72042+ task->acl_role_id = 0;
72043+ task->inherited = 0;
72044+ task->acl = NULL;
72045+ task->role = NULL;
72046+ } while_each_thread(task2, task);
72047+ read_unlock(&tasklist_lock);
72048+
72049+ kfree(fakefs_obj_rw);
72050+ fakefs_obj_rw = NULL;
72051+ kfree(fakefs_obj_rwx);
72052+ fakefs_obj_rwx = NULL;
72053+
72054+ /* release the reference to the real root dentry and vfsmount */
72055+ path_put(&gr_real_root);
72056+ memset(&gr_real_root, 0, sizeof(gr_real_root));
72057+ }
72058+
72059+ /* free all object hash tables */
72060+
72061+ FOR_EACH_ROLE_START(r)
72062+ if (r->subj_hash == NULL)
72063+ goto next_role;
72064+ FOR_EACH_SUBJECT_START(r, s, x)
72065+ if (s->obj_hash == NULL)
72066+ break;
72067+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
72068+ kfree(s->obj_hash);
72069+ else
72070+ vfree(s->obj_hash);
72071+ FOR_EACH_SUBJECT_END(s, x)
72072+ FOR_EACH_NESTED_SUBJECT_START(r, s)
72073+ if (s->obj_hash == NULL)
72074+ break;
72075+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
72076+ kfree(s->obj_hash);
72077+ else
72078+ vfree(s->obj_hash);
72079+ FOR_EACH_NESTED_SUBJECT_END(s)
72080+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
72081+ kfree(r->subj_hash);
72082+ else
72083+ vfree(r->subj_hash);
72084+ r->subj_hash = NULL;
72085+next_role:
72086+ FOR_EACH_ROLE_END(r)
72087+
72088+ acl_free_all();
72089+
72090+ if (polstate->acl_role_set.r_hash) {
72091+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
72092+ PAGE_SIZE)
72093+ kfree(polstate->acl_role_set.r_hash);
72094+ else
72095+ vfree(polstate->acl_role_set.r_hash);
72096+ }
72097+ if (polstate->name_set.n_hash) {
72098+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
72099+ PAGE_SIZE)
72100+ kfree(polstate->name_set.n_hash);
72101+ else
72102+ vfree(polstate->name_set.n_hash);
72103+ }
72104+
72105+ if (polstate->inodev_set.i_hash) {
72106+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
72107+ PAGE_SIZE)
72108+ kfree(polstate->inodev_set.i_hash);
72109+ else
72110+ vfree(polstate->inodev_set.i_hash);
72111+ }
72112+
72113+ if (!reload)
72114+ gr_free_uidset();
72115+
72116+ memset(&polstate->name_set, 0, sizeof (struct name_db));
72117+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
72118+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
72119+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
72120+
72121+ polstate->default_role = NULL;
72122+ polstate->kernel_role = NULL;
72123+ polstate->role_list = NULL;
72124+
72125+ return;
72126+}
72127+
72128+static struct acl_subject_label *
72129+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
72130+
72131+static int alloc_and_copy_string(char **name, unsigned int maxlen)
72132+{
72133+ unsigned int len = strnlen_user(*name, maxlen);
72134+ char *tmp;
72135+
72136+ if (!len || len >= maxlen)
72137+ return -EINVAL;
72138+
72139+ if ((tmp = (char *) acl_alloc(len)) == NULL)
72140+ return -ENOMEM;
72141+
72142+ if (copy_from_user(tmp, *name, len))
72143+ return -EFAULT;
72144+
72145+ tmp[len-1] = '\0';
72146+ *name = tmp;
72147+
72148+ return 0;
72149+}
72150+
72151+static int
72152+copy_user_glob(struct acl_object_label *obj)
72153+{
72154+ struct acl_object_label *g_tmp, **guser;
72155+ int error;
72156+
72157+ if (obj->globbed == NULL)
72158+ return 0;
72159+
72160+ guser = &obj->globbed;
72161+ while (*guser) {
72162+ g_tmp = (struct acl_object_label *)
72163+ acl_alloc(sizeof (struct acl_object_label));
72164+ if (g_tmp == NULL)
72165+ return -ENOMEM;
72166+
72167+ if (copy_acl_object_label(g_tmp, *guser))
72168+ return -EFAULT;
72169+
72170+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
72171+ if (error)
72172+ return error;
72173+
72174+ *guser = g_tmp;
72175+ guser = &(g_tmp->next);
72176+ }
72177+
72178+ return 0;
72179+}
72180+
72181+static int
72182+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
72183+ struct acl_role_label *role)
72184+{
72185+ struct acl_object_label *o_tmp;
72186+ int ret;
72187+
72188+ while (userp) {
72189+ if ((o_tmp = (struct acl_object_label *)
72190+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
72191+ return -ENOMEM;
72192+
72193+ if (copy_acl_object_label(o_tmp, userp))
72194+ return -EFAULT;
72195+
72196+ userp = o_tmp->prev;
72197+
72198+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
72199+ if (ret)
72200+ return ret;
72201+
72202+ insert_acl_obj_label(o_tmp, subj);
72203+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
72204+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
72205+ return -ENOMEM;
72206+
72207+ ret = copy_user_glob(o_tmp);
72208+ if (ret)
72209+ return ret;
72210+
72211+ if (o_tmp->nested) {
72212+ int already_copied;
72213+
72214+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
72215+ if (IS_ERR(o_tmp->nested))
72216+ return PTR_ERR(o_tmp->nested);
72217+
72218+ /* insert into nested subject list if we haven't copied this one yet
72219+ to prevent duplicate entries */
72220+ if (!already_copied) {
72221+ o_tmp->nested->next = role->hash->first;
72222+ role->hash->first = o_tmp->nested;
72223+ }
72224+ }
72225+ }
72226+
72227+ return 0;
72228+}
72229+
72230+static __u32
72231+count_user_subjs(struct acl_subject_label *userp)
72232+{
72233+ struct acl_subject_label s_tmp;
72234+ __u32 num = 0;
72235+
72236+ while (userp) {
72237+ if (copy_acl_subject_label(&s_tmp, userp))
72238+ break;
72239+
72240+ userp = s_tmp.prev;
72241+ }
72242+
72243+ return num;
72244+}
72245+
72246+static int
72247+copy_user_allowedips(struct acl_role_label *rolep)
72248+{
72249+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
72250+
72251+ ruserip = rolep->allowed_ips;
72252+
72253+ while (ruserip) {
72254+ rlast = rtmp;
72255+
72256+ if ((rtmp = (struct role_allowed_ip *)
72257+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
72258+ return -ENOMEM;
72259+
72260+ if (copy_role_allowed_ip(rtmp, ruserip))
72261+ return -EFAULT;
72262+
72263+ ruserip = rtmp->prev;
72264+
72265+ if (!rlast) {
72266+ rtmp->prev = NULL;
72267+ rolep->allowed_ips = rtmp;
72268+ } else {
72269+ rlast->next = rtmp;
72270+ rtmp->prev = rlast;
72271+ }
72272+
72273+ if (!ruserip)
72274+ rtmp->next = NULL;
72275+ }
72276+
72277+ return 0;
72278+}
72279+
72280+static int
72281+copy_user_transitions(struct acl_role_label *rolep)
72282+{
72283+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
72284+ int error;
72285+
72286+ rusertp = rolep->transitions;
72287+
72288+ while (rusertp) {
72289+ rlast = rtmp;
72290+
72291+ if ((rtmp = (struct role_transition *)
72292+ acl_alloc(sizeof (struct role_transition))) == NULL)
72293+ return -ENOMEM;
72294+
72295+ if (copy_role_transition(rtmp, rusertp))
72296+ return -EFAULT;
72297+
72298+ rusertp = rtmp->prev;
72299+
72300+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
72301+ if (error)
72302+ return error;
72303+
72304+ if (!rlast) {
72305+ rtmp->prev = NULL;
72306+ rolep->transitions = rtmp;
72307+ } else {
72308+ rlast->next = rtmp;
72309+ rtmp->prev = rlast;
72310+ }
72311+
72312+ if (!rusertp)
72313+ rtmp->next = NULL;
72314+ }
72315+
72316+ return 0;
72317+}
72318+
72319+static __u32 count_user_objs(const struct acl_object_label __user *userp)
72320+{
72321+ struct acl_object_label o_tmp;
72322+ __u32 num = 0;
72323+
72324+ while (userp) {
72325+ if (copy_acl_object_label(&o_tmp, userp))
72326+ break;
72327+
72328+ userp = o_tmp.prev;
72329+ num++;
72330+ }
72331+
72332+ return num;
72333+}
72334+
72335+static struct acl_subject_label *
72336+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
72337+{
72338+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
72339+ __u32 num_objs;
72340+ struct acl_ip_label **i_tmp, *i_utmp2;
72341+ struct gr_hash_struct ghash;
72342+ struct subject_map *subjmap;
72343+ unsigned int i_num;
72344+ int err;
72345+
72346+ if (already_copied != NULL)
72347+ *already_copied = 0;
72348+
72349+ s_tmp = lookup_subject_map(userp);
72350+
72351+ /* we've already copied this subject into the kernel, just return
72352+ the reference to it, and don't copy it over again
72353+ */
72354+ if (s_tmp) {
72355+ if (already_copied != NULL)
72356+ *already_copied = 1;
72357+ return(s_tmp);
72358+ }
72359+
72360+ if ((s_tmp = (struct acl_subject_label *)
72361+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
72362+ return ERR_PTR(-ENOMEM);
72363+
72364+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
72365+ if (subjmap == NULL)
72366+ return ERR_PTR(-ENOMEM);
72367+
72368+ subjmap->user = userp;
72369+ subjmap->kernel = s_tmp;
72370+ insert_subj_map_entry(subjmap);
72371+
72372+ if (copy_acl_subject_label(s_tmp, userp))
72373+ return ERR_PTR(-EFAULT);
72374+
72375+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
72376+ if (err)
72377+ return ERR_PTR(err);
72378+
72379+ if (!strcmp(s_tmp->filename, "/"))
72380+ role->root_label = s_tmp;
72381+
72382+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
72383+ return ERR_PTR(-EFAULT);
72384+
72385+ /* copy user and group transition tables */
72386+
72387+ if (s_tmp->user_trans_num) {
72388+ uid_t *uidlist;
72389+
72390+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
72391+ if (uidlist == NULL)
72392+ return ERR_PTR(-ENOMEM);
72393+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
72394+ return ERR_PTR(-EFAULT);
72395+
72396+ s_tmp->user_transitions = uidlist;
72397+ }
72398+
72399+ if (s_tmp->group_trans_num) {
72400+ gid_t *gidlist;
72401+
72402+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
72403+ if (gidlist == NULL)
72404+ return ERR_PTR(-ENOMEM);
72405+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
72406+ return ERR_PTR(-EFAULT);
72407+
72408+ s_tmp->group_transitions = gidlist;
72409+ }
72410+
72411+ /* set up object hash table */
72412+ num_objs = count_user_objs(ghash.first);
72413+
72414+ s_tmp->obj_hash_size = num_objs;
72415+ s_tmp->obj_hash =
72416+ (struct acl_object_label **)
72417+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72418+
72419+ if (!s_tmp->obj_hash)
72420+ return ERR_PTR(-ENOMEM);
72421+
72422+ memset(s_tmp->obj_hash, 0,
72423+ s_tmp->obj_hash_size *
72424+ sizeof (struct acl_object_label *));
72425+
72426+ /* add in objects */
72427+ err = copy_user_objs(ghash.first, s_tmp, role);
72428+
72429+ if (err)
72430+ return ERR_PTR(err);
72431+
72432+ /* set pointer for parent subject */
72433+ if (s_tmp->parent_subject) {
72434+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72435+
72436+ if (IS_ERR(s_tmp2))
72437+ return s_tmp2;
72438+
72439+ s_tmp->parent_subject = s_tmp2;
72440+ }
72441+
72442+ /* add in ip acls */
72443+
72444+ if (!s_tmp->ip_num) {
72445+ s_tmp->ips = NULL;
72446+ goto insert;
72447+ }
72448+
72449+ i_tmp =
72450+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72451+ sizeof (struct acl_ip_label *));
72452+
72453+ if (!i_tmp)
72454+ return ERR_PTR(-ENOMEM);
72455+
72456+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72457+ *(i_tmp + i_num) =
72458+ (struct acl_ip_label *)
72459+ acl_alloc(sizeof (struct acl_ip_label));
72460+ if (!*(i_tmp + i_num))
72461+ return ERR_PTR(-ENOMEM);
72462+
72463+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72464+ return ERR_PTR(-EFAULT);
72465+
72466+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72467+ return ERR_PTR(-EFAULT);
72468+
72469+ if ((*(i_tmp + i_num))->iface == NULL)
72470+ continue;
72471+
72472+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72473+ if (err)
72474+ return ERR_PTR(err);
72475+ }
72476+
72477+ s_tmp->ips = i_tmp;
72478+
72479+insert:
72480+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72481+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72482+ return ERR_PTR(-ENOMEM);
72483+
72484+ return s_tmp;
72485+}
72486+
72487+static int
72488+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72489+{
72490+ struct acl_subject_label s_pre;
72491+ struct acl_subject_label * ret;
72492+ int err;
72493+
72494+ while (userp) {
72495+ if (copy_acl_subject_label(&s_pre, userp))
72496+ return -EFAULT;
72497+
72498+ ret = do_copy_user_subj(userp, role, NULL);
72499+
72500+ err = PTR_ERR(ret);
72501+ if (IS_ERR(ret))
72502+ return err;
72503+
72504+ insert_acl_subj_label(ret, role);
72505+
72506+ userp = s_pre.prev;
72507+ }
72508+
72509+ return 0;
72510+}
72511+
72512+static int
72513+copy_user_acl(struct gr_arg *arg)
72514+{
72515+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72516+ struct acl_subject_label *subj_list;
72517+ struct sprole_pw *sptmp;
72518+ struct gr_hash_struct *ghash;
72519+ uid_t *domainlist;
72520+ unsigned int r_num;
72521+ int err = 0;
72522+ __u16 i;
72523+ __u32 num_subjs;
72524+
72525+ /* we need a default and kernel role */
72526+ if (arg->role_db.num_roles < 2)
72527+ return -EINVAL;
72528+
72529+ /* copy special role authentication info from userspace */
72530+
72531+ polstate->num_sprole_pws = arg->num_sprole_pws;
72532+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72533+
72534+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72535+ return -ENOMEM;
72536+
72537+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72538+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72539+ if (!sptmp)
72540+ return -ENOMEM;
72541+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72542+ return -EFAULT;
72543+
72544+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72545+ if (err)
72546+ return err;
72547+
72548+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72549+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72550+#endif
72551+
72552+ polstate->acl_special_roles[i] = sptmp;
72553+ }
72554+
72555+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72556+
72557+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72558+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
72559+
72560+ if (!r_tmp)
72561+ return -ENOMEM;
72562+
72563+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72564+ return -EFAULT;
72565+
72566+ if (copy_acl_role_label(r_tmp, r_utmp2))
72567+ return -EFAULT;
72568+
72569+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72570+ if (err)
72571+ return err;
72572+
72573+ if (!strcmp(r_tmp->rolename, "default")
72574+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72575+ polstate->default_role = r_tmp;
72576+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72577+ polstate->kernel_role = r_tmp;
72578+ }
72579+
72580+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72581+ return -ENOMEM;
72582+
72583+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
72584+ return -EFAULT;
72585+
72586+ r_tmp->hash = ghash;
72587+
72588+ num_subjs = count_user_subjs(r_tmp->hash->first);
72589+
72590+ r_tmp->subj_hash_size = num_subjs;
72591+ r_tmp->subj_hash =
72592+ (struct acl_subject_label **)
72593+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72594+
72595+ if (!r_tmp->subj_hash)
72596+ return -ENOMEM;
72597+
72598+ err = copy_user_allowedips(r_tmp);
72599+ if (err)
72600+ return err;
72601+
72602+ /* copy domain info */
72603+ if (r_tmp->domain_children != NULL) {
72604+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72605+ if (domainlist == NULL)
72606+ return -ENOMEM;
72607+
72608+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72609+ return -EFAULT;
72610+
72611+ r_tmp->domain_children = domainlist;
72612+ }
72613+
72614+ err = copy_user_transitions(r_tmp);
72615+ if (err)
72616+ return err;
72617+
72618+ memset(r_tmp->subj_hash, 0,
72619+ r_tmp->subj_hash_size *
72620+ sizeof (struct acl_subject_label *));
72621+
72622+ /* acquire the list of subjects, then NULL out
72623+ the list prior to parsing the subjects for this role,
72624+ as during this parsing the list is replaced with a list
72625+ of *nested* subjects for the role
72626+ */
72627+ subj_list = r_tmp->hash->first;
72628+
72629+ /* set nested subject list to null */
72630+ r_tmp->hash->first = NULL;
72631+
72632+ err = copy_user_subjs(subj_list, r_tmp);
72633+
72634+ if (err)
72635+ return err;
72636+
72637+ insert_acl_role_label(r_tmp);
72638+ }
72639+
72640+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72641+ return -EINVAL;
72642+
72643+ return err;
72644+}
72645+
72646+static int gracl_reload_apply_policies(void *reload)
72647+{
72648+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72649+ struct task_struct *task, *task2;
72650+ struct acl_role_label *role, *rtmp;
72651+ struct acl_subject_label *subj;
72652+ const struct cred *cred;
72653+ int role_applied;
72654+ int ret = 0;
72655+
72656+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72657+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72658+
72659+ /* first make sure we'll be able to apply the new policy cleanly */
72660+ do_each_thread(task2, task) {
72661+ if (task->exec_file == NULL)
72662+ continue;
72663+ role_applied = 0;
72664+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72665+ /* preserve special roles */
72666+ FOR_EACH_ROLE_START(role)
72667+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72668+ rtmp = task->role;
72669+ task->role = role;
72670+ role_applied = 1;
72671+ break;
72672+ }
72673+ FOR_EACH_ROLE_END(role)
72674+ }
72675+ if (!role_applied) {
72676+ cred = __task_cred(task);
72677+ rtmp = task->role;
72678+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72679+ }
72680+ /* this handles non-nested inherited subjects, nested subjects will still
72681+ be dropped currently */
72682+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72683+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72684+ /* change the role back so that we've made no modifications to the policy */
72685+ task->role = rtmp;
72686+
72687+ if (subj == NULL || task->tmpacl == NULL) {
72688+ ret = -EINVAL;
72689+ goto out;
72690+ }
72691+ } while_each_thread(task2, task);
72692+
72693+ /* now actually apply the policy */
72694+
72695+ do_each_thread(task2, task) {
72696+ if (task->exec_file) {
72697+ role_applied = 0;
72698+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72699+ /* preserve special roles */
72700+ FOR_EACH_ROLE_START(role)
72701+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72702+ task->role = role;
72703+ role_applied = 1;
72704+ break;
72705+ }
72706+ FOR_EACH_ROLE_END(role)
72707+ }
72708+ if (!role_applied) {
72709+ cred = __task_cred(task);
72710+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72711+ }
72712+ /* this handles non-nested inherited subjects, nested subjects will still
72713+ be dropped currently */
72714+ if (!reload_state->oldmode && task->inherited)
72715+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72716+ else {
72717+ /* looked up and tagged to the task previously */
72718+ subj = task->tmpacl;
72719+ }
72720+ /* subj will be non-null */
72721+ __gr_apply_subject_to_task(polstate, task, subj);
72722+ if (reload_state->oldmode) {
72723+ task->acl_role_id = 0;
72724+ task->acl_sp_role = 0;
72725+ task->inherited = 0;
72726+ }
72727+ } else {
72728+ // it's a kernel process
72729+ task->role = polstate->kernel_role;
72730+ task->acl = polstate->kernel_role->root_label;
72731+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72732+ task->acl->mode &= ~GR_PROCFIND;
72733+#endif
72734+ }
72735+ } while_each_thread(task2, task);
72736+
72737+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72738+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72739+
72740+out:
72741+
72742+ return ret;
72743+}
72744+
72745+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72746+{
72747+ struct gr_reload_state new_reload_state = { };
72748+ int err;
72749+
72750+ new_reload_state.oldpolicy_ptr = polstate;
72751+ new_reload_state.oldalloc_ptr = current_alloc_state;
72752+ new_reload_state.oldmode = oldmode;
72753+
72754+ current_alloc_state = &new_reload_state.newalloc;
72755+ polstate = &new_reload_state.newpolicy;
72756+
72757+ /* everything relevant is now saved off, copy in the new policy */
72758+ if (init_variables(args, true)) {
72759+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72760+ err = -ENOMEM;
72761+ goto error;
72762+ }
72763+
72764+ err = copy_user_acl(args);
72765+ free_init_variables();
72766+ if (err)
72767+ goto error;
72768+ /* the new policy is copied in, with the old policy available via saved_state
72769+ first go through applying roles, making sure to preserve special roles
72770+ then apply new subjects, making sure to preserve inherited and nested subjects,
72771+ though currently only inherited subjects will be preserved
72772+ */
72773+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72774+ if (err)
72775+ goto error;
72776+
72777+ /* we've now applied the new policy, so restore the old policy state to free it */
72778+ polstate = &new_reload_state.oldpolicy;
72779+ current_alloc_state = &new_reload_state.oldalloc;
72780+ free_variables(true);
72781+
72782+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72783+ to running_polstate/current_alloc_state inside stop_machine
72784+ */
72785+ err = 0;
72786+ goto out;
72787+error:
72788+ /* on error of loading the new policy, we'll just keep the previous
72789+ policy set around
72790+ */
72791+ free_variables(true);
72792+
72793+ /* doesn't affect runtime, but maintains consistent state */
72794+out:
72795+ polstate = new_reload_state.oldpolicy_ptr;
72796+ current_alloc_state = new_reload_state.oldalloc_ptr;
72797+
72798+ return err;
72799+}
72800+
72801+static int
72802+gracl_init(struct gr_arg *args)
72803+{
72804+ int error = 0;
72805+
72806+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72807+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72808+
72809+ if (init_variables(args, false)) {
72810+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72811+ error = -ENOMEM;
72812+ goto out;
72813+ }
72814+
72815+ error = copy_user_acl(args);
72816+ free_init_variables();
72817+ if (error)
72818+ goto out;
72819+
72820+ error = gr_set_acls(0);
72821+ if (error)
72822+ goto out;
72823+
72824+ gr_enable_rbac_system();
72825+
72826+ return 0;
72827+
72828+out:
72829+ free_variables(false);
72830+ return error;
72831+}
72832+
72833+static int
72834+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72835+ unsigned char **sum)
72836+{
72837+ struct acl_role_label *r;
72838+ struct role_allowed_ip *ipp;
72839+ struct role_transition *trans;
72840+ unsigned int i;
72841+ int found = 0;
72842+ u32 curr_ip = current->signal->curr_ip;
72843+
72844+ current->signal->saved_ip = curr_ip;
72845+
72846+ /* check transition table */
72847+
72848+ for (trans = current->role->transitions; trans; trans = trans->next) {
72849+ if (!strcmp(rolename, trans->rolename)) {
72850+ found = 1;
72851+ break;
72852+ }
72853+ }
72854+
72855+ if (!found)
72856+ return 0;
72857+
72858+ /* handle special roles that do not require authentication
72859+ and check ip */
72860+
72861+ FOR_EACH_ROLE_START(r)
72862+ if (!strcmp(rolename, r->rolename) &&
72863+ (r->roletype & GR_ROLE_SPECIAL)) {
72864+ found = 0;
72865+ if (r->allowed_ips != NULL) {
72866+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72867+ if ((ntohl(curr_ip) & ipp->netmask) ==
72868+ (ntohl(ipp->addr) & ipp->netmask))
72869+ found = 1;
72870+ }
72871+ } else
72872+ found = 2;
72873+ if (!found)
72874+ return 0;
72875+
72876+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72877+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72878+ *salt = NULL;
72879+ *sum = NULL;
72880+ return 1;
72881+ }
72882+ }
72883+ FOR_EACH_ROLE_END(r)
72884+
72885+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72886+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72887+ *salt = polstate->acl_special_roles[i]->salt;
72888+ *sum = polstate->acl_special_roles[i]->sum;
72889+ return 1;
72890+ }
72891+ }
72892+
72893+ return 0;
72894+}
72895+
72896+int gr_check_secure_terminal(struct task_struct *task)
72897+{
72898+ struct task_struct *p, *p2, *p3;
72899+ struct files_struct *files;
72900+ struct fdtable *fdt;
72901+ struct file *our_file = NULL, *file;
72902+ int i;
72903+
72904+ if (task->signal->tty == NULL)
72905+ return 1;
72906+
72907+ files = get_files_struct(task);
72908+ if (files != NULL) {
72909+ rcu_read_lock();
72910+ fdt = files_fdtable(files);
72911+ for (i=0; i < fdt->max_fds; i++) {
72912+ file = fcheck_files(files, i);
72913+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72914+ get_file(file);
72915+ our_file = file;
72916+ }
72917+ }
72918+ rcu_read_unlock();
72919+ put_files_struct(files);
72920+ }
72921+
72922+ if (our_file == NULL)
72923+ return 1;
72924+
72925+ read_lock(&tasklist_lock);
72926+ do_each_thread(p2, p) {
72927+ files = get_files_struct(p);
72928+ if (files == NULL ||
72929+ (p->signal && p->signal->tty == task->signal->tty)) {
72930+ if (files != NULL)
72931+ put_files_struct(files);
72932+ continue;
72933+ }
72934+ rcu_read_lock();
72935+ fdt = files_fdtable(files);
72936+ for (i=0; i < fdt->max_fds; i++) {
72937+ file = fcheck_files(files, i);
72938+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72939+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72940+ p3 = task;
72941+ while (task_pid_nr(p3) > 0) {
72942+ if (p3 == p)
72943+ break;
72944+ p3 = p3->real_parent;
72945+ }
72946+ if (p3 == p)
72947+ break;
72948+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72949+ gr_handle_alertkill(p);
72950+ rcu_read_unlock();
72951+ put_files_struct(files);
72952+ read_unlock(&tasklist_lock);
72953+ fput(our_file);
72954+ return 0;
72955+ }
72956+ }
72957+ rcu_read_unlock();
72958+ put_files_struct(files);
72959+ } while_each_thread(p2, p);
72960+ read_unlock(&tasklist_lock);
72961+
72962+ fput(our_file);
72963+ return 1;
72964+}
72965+
72966+ssize_t
72967+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72968+{
72969+ struct gr_arg_wrapper uwrap;
72970+ unsigned char *sprole_salt = NULL;
72971+ unsigned char *sprole_sum = NULL;
72972+ int error = 0;
72973+ int error2 = 0;
72974+ size_t req_count = 0;
72975+ unsigned char oldmode = 0;
72976+
72977+ mutex_lock(&gr_dev_mutex);
72978+
72979+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72980+ error = -EPERM;
72981+ goto out;
72982+ }
72983+
72984+#ifdef CONFIG_COMPAT
72985+ pax_open_kernel();
72986+ if (is_compat_task()) {
72987+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72988+ copy_gr_arg = &copy_gr_arg_compat;
72989+ copy_acl_object_label = &copy_acl_object_label_compat;
72990+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72991+ copy_acl_role_label = &copy_acl_role_label_compat;
72992+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72993+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72994+ copy_role_transition = &copy_role_transition_compat;
72995+ copy_sprole_pw = &copy_sprole_pw_compat;
72996+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72997+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72998+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72999+ } else {
73000+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
73001+ copy_gr_arg = &copy_gr_arg_normal;
73002+ copy_acl_object_label = &copy_acl_object_label_normal;
73003+ copy_acl_subject_label = &copy_acl_subject_label_normal;
73004+ copy_acl_role_label = &copy_acl_role_label_normal;
73005+ copy_acl_ip_label = &copy_acl_ip_label_normal;
73006+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
73007+ copy_role_transition = &copy_role_transition_normal;
73008+ copy_sprole_pw = &copy_sprole_pw_normal;
73009+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
73010+ copy_pointer_from_array = &copy_pointer_from_array_normal;
73011+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
73012+ }
73013+ pax_close_kernel();
73014+#endif
73015+
73016+ req_count = get_gr_arg_wrapper_size();
73017+
73018+ if (count != req_count) {
73019+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
73020+ error = -EINVAL;
73021+ goto out;
73022+ }
73023+
73024+
73025+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
73026+ gr_auth_expires = 0;
73027+ gr_auth_attempts = 0;
73028+ }
73029+
73030+ error = copy_gr_arg_wrapper(buf, &uwrap);
73031+ if (error)
73032+ goto out;
73033+
73034+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
73035+ if (error)
73036+ goto out;
73037+
73038+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
73039+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73040+ time_after(gr_auth_expires, get_seconds())) {
73041+ error = -EBUSY;
73042+ goto out;
73043+ }
73044+
73045+ /* if non-root trying to do anything other than use a special role,
73046+ do not attempt authentication, do not count towards authentication
73047+ locking
73048+ */
73049+
73050+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
73051+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
73052+ gr_is_global_nonroot(current_uid())) {
73053+ error = -EPERM;
73054+ goto out;
73055+ }
73056+
73057+ /* ensure pw and special role name are null terminated */
73058+
73059+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
73060+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
73061+
73062+ /* Okay.
73063+ * We have our enough of the argument structure..(we have yet
73064+ * to copy_from_user the tables themselves) . Copy the tables
73065+ * only if we need them, i.e. for loading operations. */
73066+
73067+ switch (gr_usermode.mode) {
73068+ case GR_STATUS:
73069+ if (gr_acl_is_enabled()) {
73070+ error = 1;
73071+ if (!gr_check_secure_terminal(current))
73072+ error = 3;
73073+ } else
73074+ error = 2;
73075+ goto out;
73076+ case GR_SHUTDOWN:
73077+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
73078+ stop_machine(gr_rbac_disable, NULL, NULL);
73079+ free_variables(false);
73080+ memset(&gr_usermode, 0, sizeof(gr_usermode));
73081+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
73082+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
73083+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
73084+ } else if (gr_acl_is_enabled()) {
73085+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
73086+ error = -EPERM;
73087+ } else {
73088+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
73089+ error = -EAGAIN;
73090+ }
73091+ break;
73092+ case GR_ENABLE:
73093+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
73094+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
73095+ else {
73096+ if (gr_acl_is_enabled())
73097+ error = -EAGAIN;
73098+ else
73099+ error = error2;
73100+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
73101+ }
73102+ break;
73103+ case GR_OLDRELOAD:
73104+ oldmode = 1;
73105+ case GR_RELOAD:
73106+ if (!gr_acl_is_enabled()) {
73107+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
73108+ error = -EAGAIN;
73109+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
73110+ error2 = gracl_reload(&gr_usermode, oldmode);
73111+ if (!error2)
73112+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
73113+ else {
73114+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73115+ error = error2;
73116+ }
73117+ } else {
73118+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73119+ error = -EPERM;
73120+ }
73121+ break;
73122+ case GR_SEGVMOD:
73123+ if (unlikely(!gr_acl_is_enabled())) {
73124+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
73125+ error = -EAGAIN;
73126+ break;
73127+ }
73128+
73129+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
73130+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
73131+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
73132+ struct acl_subject_label *segvacl;
73133+ segvacl =
73134+ lookup_acl_subj_label(gr_usermode.segv_inode,
73135+ gr_usermode.segv_device,
73136+ current->role);
73137+ if (segvacl) {
73138+ segvacl->crashes = 0;
73139+ segvacl->expires = 0;
73140+ }
73141+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
73142+ gr_remove_uid(gr_usermode.segv_uid);
73143+ }
73144+ } else {
73145+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
73146+ error = -EPERM;
73147+ }
73148+ break;
73149+ case GR_SPROLE:
73150+ case GR_SPROLEPAM:
73151+ if (unlikely(!gr_acl_is_enabled())) {
73152+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
73153+ error = -EAGAIN;
73154+ break;
73155+ }
73156+
73157+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
73158+ current->role->expires = 0;
73159+ current->role->auth_attempts = 0;
73160+ }
73161+
73162+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73163+ time_after(current->role->expires, get_seconds())) {
73164+ error = -EBUSY;
73165+ goto out;
73166+ }
73167+
73168+ if (lookup_special_role_auth
73169+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
73170+ && ((!sprole_salt && !sprole_sum)
73171+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
73172+ char *p = "";
73173+ assign_special_role(gr_usermode.sp_role);
73174+ read_lock(&tasklist_lock);
73175+ if (current->real_parent)
73176+ p = current->real_parent->role->rolename;
73177+ read_unlock(&tasklist_lock);
73178+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
73179+ p, acl_sp_role_value);
73180+ } else {
73181+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
73182+ error = -EPERM;
73183+ if(!(current->role->auth_attempts++))
73184+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73185+
73186+ goto out;
73187+ }
73188+ break;
73189+ case GR_UNSPROLE:
73190+ if (unlikely(!gr_acl_is_enabled())) {
73191+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
73192+ error = -EAGAIN;
73193+ break;
73194+ }
73195+
73196+ if (current->role->roletype & GR_ROLE_SPECIAL) {
73197+ char *p = "";
73198+ int i = 0;
73199+
73200+ read_lock(&tasklist_lock);
73201+ if (current->real_parent) {
73202+ p = current->real_parent->role->rolename;
73203+ i = current->real_parent->acl_role_id;
73204+ }
73205+ read_unlock(&tasklist_lock);
73206+
73207+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
73208+ gr_set_acls(1);
73209+ } else {
73210+ error = -EPERM;
73211+ goto out;
73212+ }
73213+ break;
73214+ default:
73215+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
73216+ error = -EINVAL;
73217+ break;
73218+ }
73219+
73220+ if (error != -EPERM)
73221+ goto out;
73222+
73223+ if(!(gr_auth_attempts++))
73224+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73225+
73226+ out:
73227+ mutex_unlock(&gr_dev_mutex);
73228+
73229+ if (!error)
73230+ error = req_count;
73231+
73232+ return error;
73233+}
73234+
73235+int
73236+gr_set_acls(const int type)
73237+{
73238+ struct task_struct *task, *task2;
73239+ struct acl_role_label *role = current->role;
73240+ struct acl_subject_label *subj;
73241+ __u16 acl_role_id = current->acl_role_id;
73242+ const struct cred *cred;
73243+ int ret;
73244+
73245+ rcu_read_lock();
73246+ read_lock(&tasklist_lock);
73247+ read_lock(&grsec_exec_file_lock);
73248+ do_each_thread(task2, task) {
73249+ /* check to see if we're called from the exit handler,
73250+ if so, only replace ACLs that have inherited the admin
73251+ ACL */
73252+
73253+ if (type && (task->role != role ||
73254+ task->acl_role_id != acl_role_id))
73255+ continue;
73256+
73257+ task->acl_role_id = 0;
73258+ task->acl_sp_role = 0;
73259+ task->inherited = 0;
73260+
73261+ if (task->exec_file) {
73262+ cred = __task_cred(task);
73263+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
73264+ subj = __gr_get_subject_for_task(polstate, task, NULL);
73265+ if (subj == NULL) {
73266+ ret = -EINVAL;
73267+ read_unlock(&grsec_exec_file_lock);
73268+ read_unlock(&tasklist_lock);
73269+ rcu_read_unlock();
73270+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
73271+ return ret;
73272+ }
73273+ __gr_apply_subject_to_task(polstate, task, subj);
73274+ } else {
73275+ // it's a kernel process
73276+ task->role = polstate->kernel_role;
73277+ task->acl = polstate->kernel_role->root_label;
73278+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
73279+ task->acl->mode &= ~GR_PROCFIND;
73280+#endif
73281+ }
73282+ } while_each_thread(task2, task);
73283+ read_unlock(&grsec_exec_file_lock);
73284+ read_unlock(&tasklist_lock);
73285+ rcu_read_unlock();
73286+
73287+ return 0;
73288+}
73289diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
73290new file mode 100644
73291index 0000000..39645c9
73292--- /dev/null
73293+++ b/grsecurity/gracl_res.c
73294@@ -0,0 +1,68 @@
73295+#include <linux/kernel.h>
73296+#include <linux/sched.h>
73297+#include <linux/gracl.h>
73298+#include <linux/grinternal.h>
73299+
73300+static const char *restab_log[] = {
73301+ [RLIMIT_CPU] = "RLIMIT_CPU",
73302+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
73303+ [RLIMIT_DATA] = "RLIMIT_DATA",
73304+ [RLIMIT_STACK] = "RLIMIT_STACK",
73305+ [RLIMIT_CORE] = "RLIMIT_CORE",
73306+ [RLIMIT_RSS] = "RLIMIT_RSS",
73307+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
73308+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
73309+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
73310+ [RLIMIT_AS] = "RLIMIT_AS",
73311+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
73312+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
73313+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
73314+ [RLIMIT_NICE] = "RLIMIT_NICE",
73315+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
73316+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
73317+ [GR_CRASH_RES] = "RLIMIT_CRASH"
73318+};
73319+
73320+void
73321+gr_log_resource(const struct task_struct *task,
73322+ const int res, const unsigned long wanted, const int gt)
73323+{
73324+ const struct cred *cred;
73325+ unsigned long rlim;
73326+
73327+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
73328+ return;
73329+
73330+ // not yet supported resource
73331+ if (unlikely(!restab_log[res]))
73332+ return;
73333+
73334+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
73335+ rlim = task_rlimit_max(task, res);
73336+ else
73337+ rlim = task_rlimit(task, res);
73338+
73339+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
73340+ return;
73341+
73342+ rcu_read_lock();
73343+ cred = __task_cred(task);
73344+
73345+ if (res == RLIMIT_NPROC &&
73346+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
73347+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
73348+ goto out_rcu_unlock;
73349+ else if (res == RLIMIT_MEMLOCK &&
73350+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
73351+ goto out_rcu_unlock;
73352+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
73353+ goto out_rcu_unlock;
73354+ rcu_read_unlock();
73355+
73356+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
73357+
73358+ return;
73359+out_rcu_unlock:
73360+ rcu_read_unlock();
73361+ return;
73362+}
73363diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
73364new file mode 100644
73365index 0000000..2040e61
73366--- /dev/null
73367+++ b/grsecurity/gracl_segv.c
73368@@ -0,0 +1,313 @@
73369+#include <linux/kernel.h>
73370+#include <linux/mm.h>
73371+#include <asm/uaccess.h>
73372+#include <asm/errno.h>
73373+#include <asm/mman.h>
73374+#include <net/sock.h>
73375+#include <linux/file.h>
73376+#include <linux/fs.h>
73377+#include <linux/net.h>
73378+#include <linux/in.h>
73379+#include <linux/slab.h>
73380+#include <linux/types.h>
73381+#include <linux/sched.h>
73382+#include <linux/timer.h>
73383+#include <linux/gracl.h>
73384+#include <linux/grsecurity.h>
73385+#include <linux/grinternal.h>
73386+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73387+#include <linux/magic.h>
73388+#include <linux/pagemap.h>
73389+#include "../fs/btrfs/async-thread.h"
73390+#include "../fs/btrfs/ctree.h"
73391+#include "../fs/btrfs/btrfs_inode.h"
73392+#endif
73393+
73394+static struct crash_uid *uid_set;
73395+static unsigned short uid_used;
73396+static DEFINE_SPINLOCK(gr_uid_lock);
73397+extern rwlock_t gr_inode_lock;
73398+extern struct acl_subject_label *
73399+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
73400+ struct acl_role_label *role);
73401+
73402+static inline dev_t __get_dev(const struct dentry *dentry)
73403+{
73404+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73405+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
73406+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
73407+ else
73408+#endif
73409+ return dentry->d_sb->s_dev;
73410+}
73411+
73412+int
73413+gr_init_uidset(void)
73414+{
73415+ uid_set =
73416+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73417+ uid_used = 0;
73418+
73419+ return uid_set ? 1 : 0;
73420+}
73421+
73422+void
73423+gr_free_uidset(void)
73424+{
73425+ if (uid_set) {
73426+ struct crash_uid *tmpset;
73427+ spin_lock(&gr_uid_lock);
73428+ tmpset = uid_set;
73429+ uid_set = NULL;
73430+ uid_used = 0;
73431+ spin_unlock(&gr_uid_lock);
73432+ if (tmpset)
73433+ kfree(tmpset);
73434+ }
73435+
73436+ return;
73437+}
73438+
73439+int
73440+gr_find_uid(const uid_t uid)
73441+{
73442+ struct crash_uid *tmp = uid_set;
73443+ uid_t buid;
73444+ int low = 0, high = uid_used - 1, mid;
73445+
73446+ while (high >= low) {
73447+ mid = (low + high) >> 1;
73448+ buid = tmp[mid].uid;
73449+ if (buid == uid)
73450+ return mid;
73451+ if (buid > uid)
73452+ high = mid - 1;
73453+ if (buid < uid)
73454+ low = mid + 1;
73455+ }
73456+
73457+ return -1;
73458+}
73459+
73460+static __inline__ void
73461+gr_insertsort(void)
73462+{
73463+ unsigned short i, j;
73464+ struct crash_uid index;
73465+
73466+ for (i = 1; i < uid_used; i++) {
73467+ index = uid_set[i];
73468+ j = i;
73469+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73470+ uid_set[j] = uid_set[j - 1];
73471+ j--;
73472+ }
73473+ uid_set[j] = index;
73474+ }
73475+
73476+ return;
73477+}
73478+
73479+static __inline__ void
73480+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73481+{
73482+ int loc;
73483+ uid_t uid = GR_GLOBAL_UID(kuid);
73484+
73485+ if (uid_used == GR_UIDTABLE_MAX)
73486+ return;
73487+
73488+ loc = gr_find_uid(uid);
73489+
73490+ if (loc >= 0) {
73491+ uid_set[loc].expires = expires;
73492+ return;
73493+ }
73494+
73495+ uid_set[uid_used].uid = uid;
73496+ uid_set[uid_used].expires = expires;
73497+ uid_used++;
73498+
73499+ gr_insertsort();
73500+
73501+ return;
73502+}
73503+
73504+void
73505+gr_remove_uid(const unsigned short loc)
73506+{
73507+ unsigned short i;
73508+
73509+ for (i = loc + 1; i < uid_used; i++)
73510+ uid_set[i - 1] = uid_set[i];
73511+
73512+ uid_used--;
73513+
73514+ return;
73515+}
73516+
73517+int
73518+gr_check_crash_uid(const kuid_t kuid)
73519+{
73520+ int loc;
73521+ int ret = 0;
73522+ uid_t uid;
73523+
73524+ if (unlikely(!gr_acl_is_enabled()))
73525+ return 0;
73526+
73527+ uid = GR_GLOBAL_UID(kuid);
73528+
73529+ spin_lock(&gr_uid_lock);
73530+ loc = gr_find_uid(uid);
73531+
73532+ if (loc < 0)
73533+ goto out_unlock;
73534+
73535+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
73536+ gr_remove_uid(loc);
73537+ else
73538+ ret = 1;
73539+
73540+out_unlock:
73541+ spin_unlock(&gr_uid_lock);
73542+ return ret;
73543+}
73544+
73545+static __inline__ int
73546+proc_is_setxid(const struct cred *cred)
73547+{
73548+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73549+ !uid_eq(cred->uid, cred->fsuid))
73550+ return 1;
73551+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73552+ !gid_eq(cred->gid, cred->fsgid))
73553+ return 1;
73554+
73555+ return 0;
73556+}
73557+
73558+extern int gr_fake_force_sig(int sig, struct task_struct *t);
73559+
73560+void
73561+gr_handle_crash(struct task_struct *task, const int sig)
73562+{
73563+ struct acl_subject_label *curr;
73564+ struct task_struct *tsk, *tsk2;
73565+ const struct cred *cred;
73566+ const struct cred *cred2;
73567+
73568+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73569+ return;
73570+
73571+ if (unlikely(!gr_acl_is_enabled()))
73572+ return;
73573+
73574+ curr = task->acl;
73575+
73576+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
73577+ return;
73578+
73579+ if (time_before_eq(curr->expires, get_seconds())) {
73580+ curr->expires = 0;
73581+ curr->crashes = 0;
73582+ }
73583+
73584+ curr->crashes++;
73585+
73586+ if (!curr->expires)
73587+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73588+
73589+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73590+ time_after(curr->expires, get_seconds())) {
73591+ rcu_read_lock();
73592+ cred = __task_cred(task);
73593+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73594+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73595+ spin_lock(&gr_uid_lock);
73596+ gr_insert_uid(cred->uid, curr->expires);
73597+ spin_unlock(&gr_uid_lock);
73598+ curr->expires = 0;
73599+ curr->crashes = 0;
73600+ read_lock(&tasklist_lock);
73601+ do_each_thread(tsk2, tsk) {
73602+ cred2 = __task_cred(tsk);
73603+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
73604+ gr_fake_force_sig(SIGKILL, tsk);
73605+ } while_each_thread(tsk2, tsk);
73606+ read_unlock(&tasklist_lock);
73607+ } else {
73608+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73609+ read_lock(&tasklist_lock);
73610+ read_lock(&grsec_exec_file_lock);
73611+ do_each_thread(tsk2, tsk) {
73612+ if (likely(tsk != task)) {
73613+ // if this thread has the same subject as the one that triggered
73614+ // RES_CRASH and it's the same binary, kill it
73615+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73616+ gr_fake_force_sig(SIGKILL, tsk);
73617+ }
73618+ } while_each_thread(tsk2, tsk);
73619+ read_unlock(&grsec_exec_file_lock);
73620+ read_unlock(&tasklist_lock);
73621+ }
73622+ rcu_read_unlock();
73623+ }
73624+
73625+ return;
73626+}
73627+
73628+int
73629+gr_check_crash_exec(const struct file *filp)
73630+{
73631+ struct acl_subject_label *curr;
73632+
73633+ if (unlikely(!gr_acl_is_enabled()))
73634+ return 0;
73635+
73636+ read_lock(&gr_inode_lock);
73637+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73638+ __get_dev(filp->f_path.dentry),
73639+ current->role);
73640+ read_unlock(&gr_inode_lock);
73641+
73642+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73643+ (!curr->crashes && !curr->expires))
73644+ return 0;
73645+
73646+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73647+ time_after(curr->expires, get_seconds()))
73648+ return 1;
73649+ else if (time_before_eq(curr->expires, get_seconds())) {
73650+ curr->crashes = 0;
73651+ curr->expires = 0;
73652+ }
73653+
73654+ return 0;
73655+}
73656+
73657+void
73658+gr_handle_alertkill(struct task_struct *task)
73659+{
73660+ struct acl_subject_label *curracl;
73661+ __u32 curr_ip;
73662+ struct task_struct *p, *p2;
73663+
73664+ if (unlikely(!gr_acl_is_enabled()))
73665+ return;
73666+
73667+ curracl = task->acl;
73668+ curr_ip = task->signal->curr_ip;
73669+
73670+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73671+ read_lock(&tasklist_lock);
73672+ do_each_thread(p2, p) {
73673+ if (p->signal->curr_ip == curr_ip)
73674+ gr_fake_force_sig(SIGKILL, p);
73675+ } while_each_thread(p2, p);
73676+ read_unlock(&tasklist_lock);
73677+ } else if (curracl->mode & GR_KILLPROC)
73678+ gr_fake_force_sig(SIGKILL, task);
73679+
73680+ return;
73681+}
73682diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73683new file mode 100644
73684index 0000000..98011b0
73685--- /dev/null
73686+++ b/grsecurity/gracl_shm.c
73687@@ -0,0 +1,40 @@
73688+#include <linux/kernel.h>
73689+#include <linux/mm.h>
73690+#include <linux/sched.h>
73691+#include <linux/file.h>
73692+#include <linux/ipc.h>
73693+#include <linux/gracl.h>
73694+#include <linux/grsecurity.h>
73695+#include <linux/grinternal.h>
73696+
73697+int
73698+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73699+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73700+{
73701+ struct task_struct *task;
73702+
73703+ if (!gr_acl_is_enabled())
73704+ return 1;
73705+
73706+ rcu_read_lock();
73707+ read_lock(&tasklist_lock);
73708+
73709+ task = find_task_by_vpid(shm_cprid);
73710+
73711+ if (unlikely(!task))
73712+ task = find_task_by_vpid(shm_lapid);
73713+
73714+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73715+ (task_pid_nr(task) == shm_lapid)) &&
73716+ (task->acl->mode & GR_PROTSHM) &&
73717+ (task->acl != current->acl))) {
73718+ read_unlock(&tasklist_lock);
73719+ rcu_read_unlock();
73720+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73721+ return 0;
73722+ }
73723+ read_unlock(&tasklist_lock);
73724+ rcu_read_unlock();
73725+
73726+ return 1;
73727+}
73728diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73729new file mode 100644
73730index 0000000..bc0be01
73731--- /dev/null
73732+++ b/grsecurity/grsec_chdir.c
73733@@ -0,0 +1,19 @@
73734+#include <linux/kernel.h>
73735+#include <linux/sched.h>
73736+#include <linux/fs.h>
73737+#include <linux/file.h>
73738+#include <linux/grsecurity.h>
73739+#include <linux/grinternal.h>
73740+
73741+void
73742+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73743+{
73744+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73745+ if ((grsec_enable_chdir && grsec_enable_group &&
73746+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73747+ !grsec_enable_group)) {
73748+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73749+ }
73750+#endif
73751+ return;
73752+}
73753diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73754new file mode 100644
73755index 0000000..baa635c
73756--- /dev/null
73757+++ b/grsecurity/grsec_chroot.c
73758@@ -0,0 +1,387 @@
73759+#include <linux/kernel.h>
73760+#include <linux/module.h>
73761+#include <linux/sched.h>
73762+#include <linux/file.h>
73763+#include <linux/fs.h>
73764+#include <linux/mount.h>
73765+#include <linux/types.h>
73766+#include "../fs/mount.h"
73767+#include <linux/grsecurity.h>
73768+#include <linux/grinternal.h>
73769+
73770+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73771+int gr_init_ran;
73772+#endif
73773+
73774+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73775+{
73776+#ifdef CONFIG_GRKERNSEC
73777+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73778+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73779+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73780+ && gr_init_ran
73781+#endif
73782+ )
73783+ task->gr_is_chrooted = 1;
73784+ else {
73785+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73786+ if (task_pid_nr(task) == 1 && !gr_init_ran)
73787+ gr_init_ran = 1;
73788+#endif
73789+ task->gr_is_chrooted = 0;
73790+ }
73791+
73792+ task->gr_chroot_dentry = path->dentry;
73793+#endif
73794+ return;
73795+}
73796+
73797+void gr_clear_chroot_entries(struct task_struct *task)
73798+{
73799+#ifdef CONFIG_GRKERNSEC
73800+ task->gr_is_chrooted = 0;
73801+ task->gr_chroot_dentry = NULL;
73802+#endif
73803+ return;
73804+}
73805+
73806+int
73807+gr_handle_chroot_unix(const pid_t pid)
73808+{
73809+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73810+ struct task_struct *p;
73811+
73812+ if (unlikely(!grsec_enable_chroot_unix))
73813+ return 1;
73814+
73815+ if (likely(!proc_is_chrooted(current)))
73816+ return 1;
73817+
73818+ rcu_read_lock();
73819+ read_lock(&tasklist_lock);
73820+ p = find_task_by_vpid_unrestricted(pid);
73821+ if (unlikely(p && !have_same_root(current, p))) {
73822+ read_unlock(&tasklist_lock);
73823+ rcu_read_unlock();
73824+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73825+ return 0;
73826+ }
73827+ read_unlock(&tasklist_lock);
73828+ rcu_read_unlock();
73829+#endif
73830+ return 1;
73831+}
73832+
73833+int
73834+gr_handle_chroot_nice(void)
73835+{
73836+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73837+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73838+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73839+ return -EPERM;
73840+ }
73841+#endif
73842+ return 0;
73843+}
73844+
73845+int
73846+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73847+{
73848+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73849+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73850+ && proc_is_chrooted(current)) {
73851+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73852+ return -EACCES;
73853+ }
73854+#endif
73855+ return 0;
73856+}
73857+
73858+int
73859+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73860+{
73861+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73862+ struct task_struct *p;
73863+ int ret = 0;
73864+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73865+ return ret;
73866+
73867+ read_lock(&tasklist_lock);
73868+ do_each_pid_task(pid, type, p) {
73869+ if (!have_same_root(current, p)) {
73870+ ret = 1;
73871+ goto out;
73872+ }
73873+ } while_each_pid_task(pid, type, p);
73874+out:
73875+ read_unlock(&tasklist_lock);
73876+ return ret;
73877+#endif
73878+ return 0;
73879+}
73880+
73881+int
73882+gr_pid_is_chrooted(struct task_struct *p)
73883+{
73884+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73885+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73886+ return 0;
73887+
73888+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73889+ !have_same_root(current, p)) {
73890+ return 1;
73891+ }
73892+#endif
73893+ return 0;
73894+}
73895+
73896+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73897+
73898+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73899+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73900+{
73901+ struct path path, currentroot;
73902+ int ret = 0;
73903+
73904+ path.dentry = (struct dentry *)u_dentry;
73905+ path.mnt = (struct vfsmount *)u_mnt;
73906+ get_fs_root(current->fs, &currentroot);
73907+ if (path_is_under(&path, &currentroot))
73908+ ret = 1;
73909+ path_put(&currentroot);
73910+
73911+ return ret;
73912+}
73913+#endif
73914+
73915+int
73916+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73917+{
73918+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73919+ if (!grsec_enable_chroot_fchdir)
73920+ return 1;
73921+
73922+ if (!proc_is_chrooted(current))
73923+ return 1;
73924+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73925+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73926+ return 0;
73927+ }
73928+#endif
73929+ return 1;
73930+}
73931+
73932+int
73933+gr_chroot_fhandle(void)
73934+{
73935+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73936+ if (!grsec_enable_chroot_fchdir)
73937+ return 1;
73938+
73939+ if (!proc_is_chrooted(current))
73940+ return 1;
73941+ else {
73942+ gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
73943+ return 0;
73944+ }
73945+#endif
73946+ return 1;
73947+}
73948+
73949+int
73950+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73951+ const time_t shm_createtime)
73952+{
73953+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73954+ struct task_struct *p;
73955+ time_t starttime;
73956+
73957+ if (unlikely(!grsec_enable_chroot_shmat))
73958+ return 1;
73959+
73960+ if (likely(!proc_is_chrooted(current)))
73961+ return 1;
73962+
73963+ rcu_read_lock();
73964+ read_lock(&tasklist_lock);
73965+
73966+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73967+ starttime = p->start_time.tv_sec;
73968+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73969+ if (have_same_root(current, p)) {
73970+ goto allow;
73971+ } else {
73972+ read_unlock(&tasklist_lock);
73973+ rcu_read_unlock();
73974+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73975+ return 0;
73976+ }
73977+ }
73978+ /* creator exited, pid reuse, fall through to next check */
73979+ }
73980+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73981+ if (unlikely(!have_same_root(current, p))) {
73982+ read_unlock(&tasklist_lock);
73983+ rcu_read_unlock();
73984+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73985+ return 0;
73986+ }
73987+ }
73988+
73989+allow:
73990+ read_unlock(&tasklist_lock);
73991+ rcu_read_unlock();
73992+#endif
73993+ return 1;
73994+}
73995+
73996+void
73997+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73998+{
73999+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74000+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
74001+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
74002+#endif
74003+ return;
74004+}
74005+
74006+int
74007+gr_handle_chroot_mknod(const struct dentry *dentry,
74008+ const struct vfsmount *mnt, const int mode)
74009+{
74010+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74011+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
74012+ proc_is_chrooted(current)) {
74013+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
74014+ return -EPERM;
74015+ }
74016+#endif
74017+ return 0;
74018+}
74019+
74020+int
74021+gr_handle_chroot_mount(const struct dentry *dentry,
74022+ const struct vfsmount *mnt, const char *dev_name)
74023+{
74024+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74025+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
74026+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
74027+ return -EPERM;
74028+ }
74029+#endif
74030+ return 0;
74031+}
74032+
74033+int
74034+gr_handle_chroot_pivot(void)
74035+{
74036+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74037+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
74038+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
74039+ return -EPERM;
74040+ }
74041+#endif
74042+ return 0;
74043+}
74044+
74045+int
74046+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
74047+{
74048+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74049+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
74050+ !gr_is_outside_chroot(dentry, mnt)) {
74051+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
74052+ return -EPERM;
74053+ }
74054+#endif
74055+ return 0;
74056+}
74057+
74058+extern const char *captab_log[];
74059+extern int captab_log_entries;
74060+
74061+int
74062+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74063+{
74064+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74065+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
74066+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
74067+ if (cap_raised(chroot_caps, cap)) {
74068+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
74069+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
74070+ }
74071+ return 0;
74072+ }
74073+ }
74074+#endif
74075+ return 1;
74076+}
74077+
74078+int
74079+gr_chroot_is_capable(const int cap)
74080+{
74081+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74082+ return gr_task_chroot_is_capable(current, current_cred(), cap);
74083+#endif
74084+ return 1;
74085+}
74086+
74087+int
74088+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
74089+{
74090+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74091+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
74092+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
74093+ if (cap_raised(chroot_caps, cap)) {
74094+ return 0;
74095+ }
74096+ }
74097+#endif
74098+ return 1;
74099+}
74100+
74101+int
74102+gr_chroot_is_capable_nolog(const int cap)
74103+{
74104+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74105+ return gr_task_chroot_is_capable_nolog(current, cap);
74106+#endif
74107+ return 1;
74108+}
74109+
74110+int
74111+gr_handle_chroot_sysctl(const int op)
74112+{
74113+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74114+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
74115+ proc_is_chrooted(current))
74116+ return -EACCES;
74117+#endif
74118+ return 0;
74119+}
74120+
74121+void
74122+gr_handle_chroot_chdir(const struct path *path)
74123+{
74124+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74125+ if (grsec_enable_chroot_chdir)
74126+ set_fs_pwd(current->fs, path);
74127+#endif
74128+ return;
74129+}
74130+
74131+int
74132+gr_handle_chroot_chmod(const struct dentry *dentry,
74133+ const struct vfsmount *mnt, const int mode)
74134+{
74135+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74136+ /* allow chmod +s on directories, but not files */
74137+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
74138+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
74139+ proc_is_chrooted(current)) {
74140+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
74141+ return -EPERM;
74142+ }
74143+#endif
74144+ return 0;
74145+}
74146diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
74147new file mode 100644
74148index 0000000..4d6fce8
74149--- /dev/null
74150+++ b/grsecurity/grsec_disabled.c
74151@@ -0,0 +1,433 @@
74152+#include <linux/kernel.h>
74153+#include <linux/module.h>
74154+#include <linux/sched.h>
74155+#include <linux/file.h>
74156+#include <linux/fs.h>
74157+#include <linux/kdev_t.h>
74158+#include <linux/net.h>
74159+#include <linux/in.h>
74160+#include <linux/ip.h>
74161+#include <linux/skbuff.h>
74162+#include <linux/sysctl.h>
74163+
74164+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
74165+void
74166+pax_set_initial_flags(struct linux_binprm *bprm)
74167+{
74168+ return;
74169+}
74170+#endif
74171+
74172+#ifdef CONFIG_SYSCTL
74173+__u32
74174+gr_handle_sysctl(const struct ctl_table * table, const int op)
74175+{
74176+ return 0;
74177+}
74178+#endif
74179+
74180+#ifdef CONFIG_TASKSTATS
74181+int gr_is_taskstats_denied(int pid)
74182+{
74183+ return 0;
74184+}
74185+#endif
74186+
74187+int
74188+gr_acl_is_enabled(void)
74189+{
74190+ return 0;
74191+}
74192+
74193+void
74194+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
74195+{
74196+ return;
74197+}
74198+
74199+int
74200+gr_handle_rawio(const struct inode *inode)
74201+{
74202+ return 0;
74203+}
74204+
74205+void
74206+gr_acl_handle_psacct(struct task_struct *task, const long code)
74207+{
74208+ return;
74209+}
74210+
74211+int
74212+gr_handle_ptrace(struct task_struct *task, const long request)
74213+{
74214+ return 0;
74215+}
74216+
74217+int
74218+gr_handle_proc_ptrace(struct task_struct *task)
74219+{
74220+ return 0;
74221+}
74222+
74223+int
74224+gr_set_acls(const int type)
74225+{
74226+ return 0;
74227+}
74228+
74229+int
74230+gr_check_hidden_task(const struct task_struct *tsk)
74231+{
74232+ return 0;
74233+}
74234+
74235+int
74236+gr_check_protected_task(const struct task_struct *task)
74237+{
74238+ return 0;
74239+}
74240+
74241+int
74242+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
74243+{
74244+ return 0;
74245+}
74246+
74247+void
74248+gr_copy_label(struct task_struct *tsk)
74249+{
74250+ return;
74251+}
74252+
74253+void
74254+gr_set_pax_flags(struct task_struct *task)
74255+{
74256+ return;
74257+}
74258+
74259+int
74260+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
74261+ const int unsafe_share)
74262+{
74263+ return 0;
74264+}
74265+
74266+void
74267+gr_handle_delete(const ino_t ino, const dev_t dev)
74268+{
74269+ return;
74270+}
74271+
74272+void
74273+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
74274+{
74275+ return;
74276+}
74277+
74278+void
74279+gr_handle_crash(struct task_struct *task, const int sig)
74280+{
74281+ return;
74282+}
74283+
74284+int
74285+gr_check_crash_exec(const struct file *filp)
74286+{
74287+ return 0;
74288+}
74289+
74290+int
74291+gr_check_crash_uid(const kuid_t uid)
74292+{
74293+ return 0;
74294+}
74295+
74296+void
74297+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74298+ struct dentry *old_dentry,
74299+ struct dentry *new_dentry,
74300+ struct vfsmount *mnt, const __u8 replace)
74301+{
74302+ return;
74303+}
74304+
74305+int
74306+gr_search_socket(const int family, const int type, const int protocol)
74307+{
74308+ return 1;
74309+}
74310+
74311+int
74312+gr_search_connectbind(const int mode, const struct socket *sock,
74313+ const struct sockaddr_in *addr)
74314+{
74315+ return 0;
74316+}
74317+
74318+void
74319+gr_handle_alertkill(struct task_struct *task)
74320+{
74321+ return;
74322+}
74323+
74324+__u32
74325+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
74326+{
74327+ return 1;
74328+}
74329+
74330+__u32
74331+gr_acl_handle_hidden_file(const struct dentry * dentry,
74332+ const struct vfsmount * mnt)
74333+{
74334+ return 1;
74335+}
74336+
74337+__u32
74338+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74339+ int acc_mode)
74340+{
74341+ return 1;
74342+}
74343+
74344+__u32
74345+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74346+{
74347+ return 1;
74348+}
74349+
74350+__u32
74351+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
74352+{
74353+ return 1;
74354+}
74355+
74356+int
74357+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
74358+ unsigned int *vm_flags)
74359+{
74360+ return 1;
74361+}
74362+
74363+__u32
74364+gr_acl_handle_truncate(const struct dentry * dentry,
74365+ const struct vfsmount * mnt)
74366+{
74367+ return 1;
74368+}
74369+
74370+__u32
74371+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
74372+{
74373+ return 1;
74374+}
74375+
74376+__u32
74377+gr_acl_handle_access(const struct dentry * dentry,
74378+ const struct vfsmount * mnt, const int fmode)
74379+{
74380+ return 1;
74381+}
74382+
74383+__u32
74384+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
74385+ umode_t *mode)
74386+{
74387+ return 1;
74388+}
74389+
74390+__u32
74391+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
74392+{
74393+ return 1;
74394+}
74395+
74396+__u32
74397+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
74398+{
74399+ return 1;
74400+}
74401+
74402+__u32
74403+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
74404+{
74405+ return 1;
74406+}
74407+
74408+void
74409+grsecurity_init(void)
74410+{
74411+ return;
74412+}
74413+
74414+umode_t gr_acl_umask(void)
74415+{
74416+ return 0;
74417+}
74418+
74419+__u32
74420+gr_acl_handle_mknod(const struct dentry * new_dentry,
74421+ const struct dentry * parent_dentry,
74422+ const struct vfsmount * parent_mnt,
74423+ const int mode)
74424+{
74425+ return 1;
74426+}
74427+
74428+__u32
74429+gr_acl_handle_mkdir(const struct dentry * new_dentry,
74430+ const struct dentry * parent_dentry,
74431+ const struct vfsmount * parent_mnt)
74432+{
74433+ return 1;
74434+}
74435+
74436+__u32
74437+gr_acl_handle_symlink(const struct dentry * new_dentry,
74438+ const struct dentry * parent_dentry,
74439+ const struct vfsmount * parent_mnt, const struct filename *from)
74440+{
74441+ return 1;
74442+}
74443+
74444+__u32
74445+gr_acl_handle_link(const struct dentry * new_dentry,
74446+ const struct dentry * parent_dentry,
74447+ const struct vfsmount * parent_mnt,
74448+ const struct dentry * old_dentry,
74449+ const struct vfsmount * old_mnt, const struct filename *to)
74450+{
74451+ return 1;
74452+}
74453+
74454+int
74455+gr_acl_handle_rename(const struct dentry *new_dentry,
74456+ const struct dentry *parent_dentry,
74457+ const struct vfsmount *parent_mnt,
74458+ const struct dentry *old_dentry,
74459+ const struct inode *old_parent_inode,
74460+ const struct vfsmount *old_mnt, const struct filename *newname)
74461+{
74462+ return 0;
74463+}
74464+
74465+int
74466+gr_acl_handle_filldir(const struct file *file, const char *name,
74467+ const int namelen, const ino_t ino)
74468+{
74469+ return 1;
74470+}
74471+
74472+int
74473+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74474+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
74475+{
74476+ return 1;
74477+}
74478+
74479+int
74480+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74481+{
74482+ return 0;
74483+}
74484+
74485+int
74486+gr_search_accept(const struct socket *sock)
74487+{
74488+ return 0;
74489+}
74490+
74491+int
74492+gr_search_listen(const struct socket *sock)
74493+{
74494+ return 0;
74495+}
74496+
74497+int
74498+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74499+{
74500+ return 0;
74501+}
74502+
74503+__u32
74504+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74505+{
74506+ return 1;
74507+}
74508+
74509+__u32
74510+gr_acl_handle_creat(const struct dentry * dentry,
74511+ const struct dentry * p_dentry,
74512+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74513+ const int imode)
74514+{
74515+ return 1;
74516+}
74517+
74518+void
74519+gr_acl_handle_exit(void)
74520+{
74521+ return;
74522+}
74523+
74524+int
74525+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74526+{
74527+ return 1;
74528+}
74529+
74530+void
74531+gr_set_role_label(const kuid_t uid, const kgid_t gid)
74532+{
74533+ return;
74534+}
74535+
74536+int
74537+gr_acl_handle_procpidmem(const struct task_struct *task)
74538+{
74539+ return 0;
74540+}
74541+
74542+int
74543+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74544+{
74545+ return 0;
74546+}
74547+
74548+int
74549+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74550+{
74551+ return 0;
74552+}
74553+
74554+int
74555+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74556+{
74557+ return 0;
74558+}
74559+
74560+int
74561+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74562+{
74563+ return 0;
74564+}
74565+
74566+int gr_acl_enable_at_secure(void)
74567+{
74568+ return 0;
74569+}
74570+
74571+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74572+{
74573+ return dentry->d_sb->s_dev;
74574+}
74575+
74576+void gr_put_exec_file(struct task_struct *task)
74577+{
74578+ return;
74579+}
74580+
74581+#ifdef CONFIG_SECURITY
74582+EXPORT_SYMBOL_GPL(gr_check_user_change);
74583+EXPORT_SYMBOL_GPL(gr_check_group_change);
74584+#endif
74585diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74586new file mode 100644
74587index 0000000..f35f454
74588--- /dev/null
74589+++ b/grsecurity/grsec_exec.c
74590@@ -0,0 +1,187 @@
74591+#include <linux/kernel.h>
74592+#include <linux/sched.h>
74593+#include <linux/file.h>
74594+#include <linux/binfmts.h>
74595+#include <linux/fs.h>
74596+#include <linux/types.h>
74597+#include <linux/grdefs.h>
74598+#include <linux/grsecurity.h>
74599+#include <linux/grinternal.h>
74600+#include <linux/capability.h>
74601+#include <linux/module.h>
74602+#include <linux/compat.h>
74603+
74604+#include <asm/uaccess.h>
74605+
74606+#ifdef CONFIG_GRKERNSEC_EXECLOG
74607+static char gr_exec_arg_buf[132];
74608+static DEFINE_MUTEX(gr_exec_arg_mutex);
74609+#endif
74610+
74611+struct user_arg_ptr {
74612+#ifdef CONFIG_COMPAT
74613+ bool is_compat;
74614+#endif
74615+ union {
74616+ const char __user *const __user *native;
74617+#ifdef CONFIG_COMPAT
74618+ const compat_uptr_t __user *compat;
74619+#endif
74620+ } ptr;
74621+};
74622+
74623+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74624+
74625+void
74626+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74627+{
74628+#ifdef CONFIG_GRKERNSEC_EXECLOG
74629+ char *grarg = gr_exec_arg_buf;
74630+ unsigned int i, x, execlen = 0;
74631+ char c;
74632+
74633+ if (!((grsec_enable_execlog && grsec_enable_group &&
74634+ in_group_p(grsec_audit_gid))
74635+ || (grsec_enable_execlog && !grsec_enable_group)))
74636+ return;
74637+
74638+ mutex_lock(&gr_exec_arg_mutex);
74639+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
74640+
74641+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
74642+ const char __user *p;
74643+ unsigned int len;
74644+
74645+ p = get_user_arg_ptr(argv, i);
74646+ if (IS_ERR(p))
74647+ goto log;
74648+
74649+ len = strnlen_user(p, 128 - execlen);
74650+ if (len > 128 - execlen)
74651+ len = 128 - execlen;
74652+ else if (len > 0)
74653+ len--;
74654+ if (copy_from_user(grarg + execlen, p, len))
74655+ goto log;
74656+
74657+ /* rewrite unprintable characters */
74658+ for (x = 0; x < len; x++) {
74659+ c = *(grarg + execlen + x);
74660+ if (c < 32 || c > 126)
74661+ *(grarg + execlen + x) = ' ';
74662+ }
74663+
74664+ execlen += len;
74665+ *(grarg + execlen) = ' ';
74666+ *(grarg + execlen + 1) = '\0';
74667+ execlen++;
74668+ }
74669+
74670+ log:
74671+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74672+ bprm->file->f_path.mnt, grarg);
74673+ mutex_unlock(&gr_exec_arg_mutex);
74674+#endif
74675+ return;
74676+}
74677+
74678+#ifdef CONFIG_GRKERNSEC
74679+extern int gr_acl_is_capable(const int cap);
74680+extern int gr_acl_is_capable_nolog(const int cap);
74681+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74682+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74683+extern int gr_chroot_is_capable(const int cap);
74684+extern int gr_chroot_is_capable_nolog(const int cap);
74685+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74686+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74687+#endif
74688+
74689+const char *captab_log[] = {
74690+ "CAP_CHOWN",
74691+ "CAP_DAC_OVERRIDE",
74692+ "CAP_DAC_READ_SEARCH",
74693+ "CAP_FOWNER",
74694+ "CAP_FSETID",
74695+ "CAP_KILL",
74696+ "CAP_SETGID",
74697+ "CAP_SETUID",
74698+ "CAP_SETPCAP",
74699+ "CAP_LINUX_IMMUTABLE",
74700+ "CAP_NET_BIND_SERVICE",
74701+ "CAP_NET_BROADCAST",
74702+ "CAP_NET_ADMIN",
74703+ "CAP_NET_RAW",
74704+ "CAP_IPC_LOCK",
74705+ "CAP_IPC_OWNER",
74706+ "CAP_SYS_MODULE",
74707+ "CAP_SYS_RAWIO",
74708+ "CAP_SYS_CHROOT",
74709+ "CAP_SYS_PTRACE",
74710+ "CAP_SYS_PACCT",
74711+ "CAP_SYS_ADMIN",
74712+ "CAP_SYS_BOOT",
74713+ "CAP_SYS_NICE",
74714+ "CAP_SYS_RESOURCE",
74715+ "CAP_SYS_TIME",
74716+ "CAP_SYS_TTY_CONFIG",
74717+ "CAP_MKNOD",
74718+ "CAP_LEASE",
74719+ "CAP_AUDIT_WRITE",
74720+ "CAP_AUDIT_CONTROL",
74721+ "CAP_SETFCAP",
74722+ "CAP_MAC_OVERRIDE",
74723+ "CAP_MAC_ADMIN",
74724+ "CAP_SYSLOG",
74725+ "CAP_WAKE_ALARM"
74726+};
74727+
74728+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74729+
74730+int gr_is_capable(const int cap)
74731+{
74732+#ifdef CONFIG_GRKERNSEC
74733+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74734+ return 1;
74735+ return 0;
74736+#else
74737+ return 1;
74738+#endif
74739+}
74740+
74741+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74742+{
74743+#ifdef CONFIG_GRKERNSEC
74744+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74745+ return 1;
74746+ return 0;
74747+#else
74748+ return 1;
74749+#endif
74750+}
74751+
74752+int gr_is_capable_nolog(const int cap)
74753+{
74754+#ifdef CONFIG_GRKERNSEC
74755+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74756+ return 1;
74757+ return 0;
74758+#else
74759+ return 1;
74760+#endif
74761+}
74762+
74763+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74764+{
74765+#ifdef CONFIG_GRKERNSEC
74766+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74767+ return 1;
74768+ return 0;
74769+#else
74770+ return 1;
74771+#endif
74772+}
74773+
74774+EXPORT_SYMBOL_GPL(gr_is_capable);
74775+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74776+EXPORT_SYMBOL_GPL(gr_task_is_capable);
74777+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74778diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74779new file mode 100644
74780index 0000000..06cc6ea
74781--- /dev/null
74782+++ b/grsecurity/grsec_fifo.c
74783@@ -0,0 +1,24 @@
74784+#include <linux/kernel.h>
74785+#include <linux/sched.h>
74786+#include <linux/fs.h>
74787+#include <linux/file.h>
74788+#include <linux/grinternal.h>
74789+
74790+int
74791+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74792+ const struct dentry *dir, const int flag, const int acc_mode)
74793+{
74794+#ifdef CONFIG_GRKERNSEC_FIFO
74795+ const struct cred *cred = current_cred();
74796+
74797+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74798+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74799+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74800+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74801+ if (!inode_permission(dentry->d_inode, acc_mode))
74802+ 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));
74803+ return -EACCES;
74804+ }
74805+#endif
74806+ return 0;
74807+}
74808diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74809new file mode 100644
74810index 0000000..8ca18bf
74811--- /dev/null
74812+++ b/grsecurity/grsec_fork.c
74813@@ -0,0 +1,23 @@
74814+#include <linux/kernel.h>
74815+#include <linux/sched.h>
74816+#include <linux/grsecurity.h>
74817+#include <linux/grinternal.h>
74818+#include <linux/errno.h>
74819+
74820+void
74821+gr_log_forkfail(const int retval)
74822+{
74823+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74824+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74825+ switch (retval) {
74826+ case -EAGAIN:
74827+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74828+ break;
74829+ case -ENOMEM:
74830+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74831+ break;
74832+ }
74833+ }
74834+#endif
74835+ return;
74836+}
74837diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74838new file mode 100644
74839index 0000000..ae6c028
74840--- /dev/null
74841+++ b/grsecurity/grsec_init.c
74842@@ -0,0 +1,272 @@
74843+#include <linux/kernel.h>
74844+#include <linux/sched.h>
74845+#include <linux/mm.h>
74846+#include <linux/gracl.h>
74847+#include <linux/slab.h>
74848+#include <linux/vmalloc.h>
74849+#include <linux/percpu.h>
74850+#include <linux/module.h>
74851+
74852+int grsec_enable_ptrace_readexec;
74853+int grsec_enable_setxid;
74854+int grsec_enable_symlinkown;
74855+kgid_t grsec_symlinkown_gid;
74856+int grsec_enable_brute;
74857+int grsec_enable_link;
74858+int grsec_enable_dmesg;
74859+int grsec_enable_harden_ptrace;
74860+int grsec_enable_harden_ipc;
74861+int grsec_enable_fifo;
74862+int grsec_enable_execlog;
74863+int grsec_enable_signal;
74864+int grsec_enable_forkfail;
74865+int grsec_enable_audit_ptrace;
74866+int grsec_enable_time;
74867+int grsec_enable_group;
74868+kgid_t grsec_audit_gid;
74869+int grsec_enable_chdir;
74870+int grsec_enable_mount;
74871+int grsec_enable_rofs;
74872+int grsec_deny_new_usb;
74873+int grsec_enable_chroot_findtask;
74874+int grsec_enable_chroot_mount;
74875+int grsec_enable_chroot_shmat;
74876+int grsec_enable_chroot_fchdir;
74877+int grsec_enable_chroot_double;
74878+int grsec_enable_chroot_pivot;
74879+int grsec_enable_chroot_chdir;
74880+int grsec_enable_chroot_chmod;
74881+int grsec_enable_chroot_mknod;
74882+int grsec_enable_chroot_nice;
74883+int grsec_enable_chroot_execlog;
74884+int grsec_enable_chroot_caps;
74885+int grsec_enable_chroot_sysctl;
74886+int grsec_enable_chroot_unix;
74887+int grsec_enable_tpe;
74888+kgid_t grsec_tpe_gid;
74889+int grsec_enable_blackhole;
74890+#ifdef CONFIG_IPV6_MODULE
74891+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74892+#endif
74893+int grsec_lastack_retries;
74894+int grsec_enable_tpe_all;
74895+int grsec_enable_tpe_invert;
74896+int grsec_enable_socket_all;
74897+kgid_t grsec_socket_all_gid;
74898+int grsec_enable_socket_client;
74899+kgid_t grsec_socket_client_gid;
74900+int grsec_enable_socket_server;
74901+kgid_t grsec_socket_server_gid;
74902+int grsec_resource_logging;
74903+int grsec_disable_privio;
74904+int grsec_enable_log_rwxmaps;
74905+int grsec_lock;
74906+
74907+DEFINE_SPINLOCK(grsec_alert_lock);
74908+unsigned long grsec_alert_wtime = 0;
74909+unsigned long grsec_alert_fyet = 0;
74910+
74911+DEFINE_SPINLOCK(grsec_audit_lock);
74912+
74913+DEFINE_RWLOCK(grsec_exec_file_lock);
74914+
74915+char *gr_shared_page[4];
74916+
74917+char *gr_alert_log_fmt;
74918+char *gr_audit_log_fmt;
74919+char *gr_alert_log_buf;
74920+char *gr_audit_log_buf;
74921+
74922+void __init
74923+grsecurity_init(void)
74924+{
74925+ int j;
74926+ /* create the per-cpu shared pages */
74927+
74928+#ifdef CONFIG_X86
74929+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74930+#endif
74931+
74932+ for (j = 0; j < 4; j++) {
74933+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74934+ if (gr_shared_page[j] == NULL) {
74935+ panic("Unable to allocate grsecurity shared page");
74936+ return;
74937+ }
74938+ }
74939+
74940+ /* allocate log buffers */
74941+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74942+ if (!gr_alert_log_fmt) {
74943+ panic("Unable to allocate grsecurity alert log format buffer");
74944+ return;
74945+ }
74946+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74947+ if (!gr_audit_log_fmt) {
74948+ panic("Unable to allocate grsecurity audit log format buffer");
74949+ return;
74950+ }
74951+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74952+ if (!gr_alert_log_buf) {
74953+ panic("Unable to allocate grsecurity alert log buffer");
74954+ return;
74955+ }
74956+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74957+ if (!gr_audit_log_buf) {
74958+ panic("Unable to allocate grsecurity audit log buffer");
74959+ return;
74960+ }
74961+
74962+#ifdef CONFIG_GRKERNSEC_IO
74963+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74964+ grsec_disable_privio = 1;
74965+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74966+ grsec_disable_privio = 1;
74967+#else
74968+ grsec_disable_privio = 0;
74969+#endif
74970+#endif
74971+
74972+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74973+ /* for backward compatibility, tpe_invert always defaults to on if
74974+ enabled in the kernel
74975+ */
74976+ grsec_enable_tpe_invert = 1;
74977+#endif
74978+
74979+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74980+#ifndef CONFIG_GRKERNSEC_SYSCTL
74981+ grsec_lock = 1;
74982+#endif
74983+
74984+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74985+ grsec_enable_log_rwxmaps = 1;
74986+#endif
74987+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74988+ grsec_enable_group = 1;
74989+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74990+#endif
74991+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74992+ grsec_enable_ptrace_readexec = 1;
74993+#endif
74994+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74995+ grsec_enable_chdir = 1;
74996+#endif
74997+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74998+ grsec_enable_harden_ptrace = 1;
74999+#endif
75000+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75001+ grsec_enable_harden_ipc = 1;
75002+#endif
75003+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75004+ grsec_enable_mount = 1;
75005+#endif
75006+#ifdef CONFIG_GRKERNSEC_LINK
75007+ grsec_enable_link = 1;
75008+#endif
75009+#ifdef CONFIG_GRKERNSEC_BRUTE
75010+ grsec_enable_brute = 1;
75011+#endif
75012+#ifdef CONFIG_GRKERNSEC_DMESG
75013+ grsec_enable_dmesg = 1;
75014+#endif
75015+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75016+ grsec_enable_blackhole = 1;
75017+ grsec_lastack_retries = 4;
75018+#endif
75019+#ifdef CONFIG_GRKERNSEC_FIFO
75020+ grsec_enable_fifo = 1;
75021+#endif
75022+#ifdef CONFIG_GRKERNSEC_EXECLOG
75023+ grsec_enable_execlog = 1;
75024+#endif
75025+#ifdef CONFIG_GRKERNSEC_SETXID
75026+ grsec_enable_setxid = 1;
75027+#endif
75028+#ifdef CONFIG_GRKERNSEC_SIGNAL
75029+ grsec_enable_signal = 1;
75030+#endif
75031+#ifdef CONFIG_GRKERNSEC_FORKFAIL
75032+ grsec_enable_forkfail = 1;
75033+#endif
75034+#ifdef CONFIG_GRKERNSEC_TIME
75035+ grsec_enable_time = 1;
75036+#endif
75037+#ifdef CONFIG_GRKERNSEC_RESLOG
75038+ grsec_resource_logging = 1;
75039+#endif
75040+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75041+ grsec_enable_chroot_findtask = 1;
75042+#endif
75043+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75044+ grsec_enable_chroot_unix = 1;
75045+#endif
75046+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75047+ grsec_enable_chroot_mount = 1;
75048+#endif
75049+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75050+ grsec_enable_chroot_fchdir = 1;
75051+#endif
75052+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75053+ grsec_enable_chroot_shmat = 1;
75054+#endif
75055+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75056+ grsec_enable_audit_ptrace = 1;
75057+#endif
75058+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75059+ grsec_enable_chroot_double = 1;
75060+#endif
75061+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75062+ grsec_enable_chroot_pivot = 1;
75063+#endif
75064+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75065+ grsec_enable_chroot_chdir = 1;
75066+#endif
75067+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75068+ grsec_enable_chroot_chmod = 1;
75069+#endif
75070+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75071+ grsec_enable_chroot_mknod = 1;
75072+#endif
75073+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75074+ grsec_enable_chroot_nice = 1;
75075+#endif
75076+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75077+ grsec_enable_chroot_execlog = 1;
75078+#endif
75079+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75080+ grsec_enable_chroot_caps = 1;
75081+#endif
75082+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75083+ grsec_enable_chroot_sysctl = 1;
75084+#endif
75085+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75086+ grsec_enable_symlinkown = 1;
75087+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
75088+#endif
75089+#ifdef CONFIG_GRKERNSEC_TPE
75090+ grsec_enable_tpe = 1;
75091+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
75092+#ifdef CONFIG_GRKERNSEC_TPE_ALL
75093+ grsec_enable_tpe_all = 1;
75094+#endif
75095+#endif
75096+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75097+ grsec_enable_socket_all = 1;
75098+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
75099+#endif
75100+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75101+ grsec_enable_socket_client = 1;
75102+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
75103+#endif
75104+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75105+ grsec_enable_socket_server = 1;
75106+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
75107+#endif
75108+#endif
75109+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
75110+ grsec_deny_new_usb = 1;
75111+#endif
75112+
75113+ return;
75114+}
75115diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
75116new file mode 100644
75117index 0000000..1773300
75118--- /dev/null
75119+++ b/grsecurity/grsec_ipc.c
75120@@ -0,0 +1,48 @@
75121+#include <linux/kernel.h>
75122+#include <linux/mm.h>
75123+#include <linux/sched.h>
75124+#include <linux/file.h>
75125+#include <linux/ipc.h>
75126+#include <linux/ipc_namespace.h>
75127+#include <linux/grsecurity.h>
75128+#include <linux/grinternal.h>
75129+
75130+int
75131+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
75132+{
75133+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75134+ int write;
75135+ int orig_granted_mode;
75136+ kuid_t euid;
75137+ kgid_t egid;
75138+
75139+ if (!grsec_enable_harden_ipc)
75140+ return 1;
75141+
75142+ euid = current_euid();
75143+ egid = current_egid();
75144+
75145+ write = requested_mode & 00002;
75146+ orig_granted_mode = ipcp->mode;
75147+
75148+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
75149+ orig_granted_mode >>= 6;
75150+ else {
75151+ /* if likely wrong permissions, lock to user */
75152+ if (orig_granted_mode & 0007)
75153+ orig_granted_mode = 0;
75154+ /* otherwise do a egid-only check */
75155+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
75156+ orig_granted_mode >>= 3;
75157+ /* otherwise, no access */
75158+ else
75159+ orig_granted_mode = 0;
75160+ }
75161+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
75162+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
75163+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
75164+ return 0;
75165+ }
75166+#endif
75167+ return 1;
75168+}
75169diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
75170new file mode 100644
75171index 0000000..5e05e20
75172--- /dev/null
75173+++ b/grsecurity/grsec_link.c
75174@@ -0,0 +1,58 @@
75175+#include <linux/kernel.h>
75176+#include <linux/sched.h>
75177+#include <linux/fs.h>
75178+#include <linux/file.h>
75179+#include <linux/grinternal.h>
75180+
75181+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
75182+{
75183+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75184+ const struct inode *link_inode = link->dentry->d_inode;
75185+
75186+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
75187+ /* ignore root-owned links, e.g. /proc/self */
75188+ gr_is_global_nonroot(link_inode->i_uid) && target &&
75189+ !uid_eq(link_inode->i_uid, target->i_uid)) {
75190+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
75191+ return 1;
75192+ }
75193+#endif
75194+ return 0;
75195+}
75196+
75197+int
75198+gr_handle_follow_link(const struct inode *parent,
75199+ const struct inode *inode,
75200+ const struct dentry *dentry, const struct vfsmount *mnt)
75201+{
75202+#ifdef CONFIG_GRKERNSEC_LINK
75203+ const struct cred *cred = current_cred();
75204+
75205+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
75206+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
75207+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
75208+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
75209+ return -EACCES;
75210+ }
75211+#endif
75212+ return 0;
75213+}
75214+
75215+int
75216+gr_handle_hardlink(const struct dentry *dentry,
75217+ const struct vfsmount *mnt,
75218+ struct inode *inode, const int mode, const struct filename *to)
75219+{
75220+#ifdef CONFIG_GRKERNSEC_LINK
75221+ const struct cred *cred = current_cred();
75222+
75223+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
75224+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
75225+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
75226+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
75227+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
75228+ return -EPERM;
75229+ }
75230+#endif
75231+ return 0;
75232+}
75233diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
75234new file mode 100644
75235index 0000000..dbe0a6b
75236--- /dev/null
75237+++ b/grsecurity/grsec_log.c
75238@@ -0,0 +1,341 @@
75239+#include <linux/kernel.h>
75240+#include <linux/sched.h>
75241+#include <linux/file.h>
75242+#include <linux/tty.h>
75243+#include <linux/fs.h>
75244+#include <linux/mm.h>
75245+#include <linux/grinternal.h>
75246+
75247+#ifdef CONFIG_TREE_PREEMPT_RCU
75248+#define DISABLE_PREEMPT() preempt_disable()
75249+#define ENABLE_PREEMPT() preempt_enable()
75250+#else
75251+#define DISABLE_PREEMPT()
75252+#define ENABLE_PREEMPT()
75253+#endif
75254+
75255+#define BEGIN_LOCKS(x) \
75256+ DISABLE_PREEMPT(); \
75257+ rcu_read_lock(); \
75258+ read_lock(&tasklist_lock); \
75259+ read_lock(&grsec_exec_file_lock); \
75260+ if (x != GR_DO_AUDIT) \
75261+ spin_lock(&grsec_alert_lock); \
75262+ else \
75263+ spin_lock(&grsec_audit_lock)
75264+
75265+#define END_LOCKS(x) \
75266+ if (x != GR_DO_AUDIT) \
75267+ spin_unlock(&grsec_alert_lock); \
75268+ else \
75269+ spin_unlock(&grsec_audit_lock); \
75270+ read_unlock(&grsec_exec_file_lock); \
75271+ read_unlock(&tasklist_lock); \
75272+ rcu_read_unlock(); \
75273+ ENABLE_PREEMPT(); \
75274+ if (x == GR_DONT_AUDIT) \
75275+ gr_handle_alertkill(current)
75276+
75277+enum {
75278+ FLOODING,
75279+ NO_FLOODING
75280+};
75281+
75282+extern char *gr_alert_log_fmt;
75283+extern char *gr_audit_log_fmt;
75284+extern char *gr_alert_log_buf;
75285+extern char *gr_audit_log_buf;
75286+
75287+static int gr_log_start(int audit)
75288+{
75289+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
75290+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
75291+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75292+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
75293+ unsigned long curr_secs = get_seconds();
75294+
75295+ if (audit == GR_DO_AUDIT)
75296+ goto set_fmt;
75297+
75298+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
75299+ grsec_alert_wtime = curr_secs;
75300+ grsec_alert_fyet = 0;
75301+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
75302+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
75303+ grsec_alert_fyet++;
75304+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
75305+ grsec_alert_wtime = curr_secs;
75306+ grsec_alert_fyet++;
75307+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
75308+ return FLOODING;
75309+ }
75310+ else return FLOODING;
75311+
75312+set_fmt:
75313+#endif
75314+ memset(buf, 0, PAGE_SIZE);
75315+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
75316+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
75317+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75318+ } else if (current->signal->curr_ip) {
75319+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
75320+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
75321+ } else if (gr_acl_is_enabled()) {
75322+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
75323+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75324+ } else {
75325+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
75326+ strcpy(buf, fmt);
75327+ }
75328+
75329+ return NO_FLOODING;
75330+}
75331+
75332+static void gr_log_middle(int audit, const char *msg, va_list ap)
75333+ __attribute__ ((format (printf, 2, 0)));
75334+
75335+static void gr_log_middle(int audit, const char *msg, va_list ap)
75336+{
75337+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75338+ unsigned int len = strlen(buf);
75339+
75340+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75341+
75342+ return;
75343+}
75344+
75345+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75346+ __attribute__ ((format (printf, 2, 3)));
75347+
75348+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75349+{
75350+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75351+ unsigned int len = strlen(buf);
75352+ va_list ap;
75353+
75354+ va_start(ap, msg);
75355+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75356+ va_end(ap);
75357+
75358+ return;
75359+}
75360+
75361+static void gr_log_end(int audit, int append_default)
75362+{
75363+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75364+ if (append_default) {
75365+ struct task_struct *task = current;
75366+ struct task_struct *parent = task->real_parent;
75367+ const struct cred *cred = __task_cred(task);
75368+ const struct cred *pcred = __task_cred(parent);
75369+ unsigned int len = strlen(buf);
75370+
75371+ 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));
75372+ }
75373+
75374+ printk("%s\n", buf);
75375+
75376+ return;
75377+}
75378+
75379+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
75380+{
75381+ int logtype;
75382+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
75383+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
75384+ void *voidptr = NULL;
75385+ int num1 = 0, num2 = 0;
75386+ unsigned long ulong1 = 0, ulong2 = 0;
75387+ struct dentry *dentry = NULL;
75388+ struct vfsmount *mnt = NULL;
75389+ struct file *file = NULL;
75390+ struct task_struct *task = NULL;
75391+ struct vm_area_struct *vma = NULL;
75392+ const struct cred *cred, *pcred;
75393+ va_list ap;
75394+
75395+ BEGIN_LOCKS(audit);
75396+ logtype = gr_log_start(audit);
75397+ if (logtype == FLOODING) {
75398+ END_LOCKS(audit);
75399+ return;
75400+ }
75401+ va_start(ap, argtypes);
75402+ switch (argtypes) {
75403+ case GR_TTYSNIFF:
75404+ task = va_arg(ap, struct task_struct *);
75405+ 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));
75406+ break;
75407+ case GR_SYSCTL_HIDDEN:
75408+ str1 = va_arg(ap, char *);
75409+ gr_log_middle_varargs(audit, msg, result, str1);
75410+ break;
75411+ case GR_RBAC:
75412+ dentry = va_arg(ap, struct dentry *);
75413+ mnt = va_arg(ap, struct vfsmount *);
75414+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75415+ break;
75416+ case GR_RBAC_STR:
75417+ dentry = va_arg(ap, struct dentry *);
75418+ mnt = va_arg(ap, struct vfsmount *);
75419+ str1 = va_arg(ap, char *);
75420+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75421+ break;
75422+ case GR_STR_RBAC:
75423+ str1 = va_arg(ap, char *);
75424+ dentry = va_arg(ap, struct dentry *);
75425+ mnt = va_arg(ap, struct vfsmount *);
75426+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75427+ break;
75428+ case GR_RBAC_MODE2:
75429+ dentry = va_arg(ap, struct dentry *);
75430+ mnt = va_arg(ap, struct vfsmount *);
75431+ str1 = va_arg(ap, char *);
75432+ str2 = va_arg(ap, char *);
75433+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75434+ break;
75435+ case GR_RBAC_MODE3:
75436+ dentry = va_arg(ap, struct dentry *);
75437+ mnt = va_arg(ap, struct vfsmount *);
75438+ str1 = va_arg(ap, char *);
75439+ str2 = va_arg(ap, char *);
75440+ str3 = va_arg(ap, char *);
75441+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75442+ break;
75443+ case GR_FILENAME:
75444+ dentry = va_arg(ap, struct dentry *);
75445+ mnt = va_arg(ap, struct vfsmount *);
75446+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75447+ break;
75448+ case GR_STR_FILENAME:
75449+ str1 = va_arg(ap, char *);
75450+ dentry = va_arg(ap, struct dentry *);
75451+ mnt = va_arg(ap, struct vfsmount *);
75452+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75453+ break;
75454+ case GR_FILENAME_STR:
75455+ dentry = va_arg(ap, struct dentry *);
75456+ mnt = va_arg(ap, struct vfsmount *);
75457+ str1 = va_arg(ap, char *);
75458+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75459+ break;
75460+ case GR_FILENAME_TWO_INT:
75461+ dentry = va_arg(ap, struct dentry *);
75462+ mnt = va_arg(ap, struct vfsmount *);
75463+ num1 = va_arg(ap, int);
75464+ num2 = va_arg(ap, int);
75465+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75466+ break;
75467+ case GR_FILENAME_TWO_INT_STR:
75468+ dentry = va_arg(ap, struct dentry *);
75469+ mnt = va_arg(ap, struct vfsmount *);
75470+ num1 = va_arg(ap, int);
75471+ num2 = va_arg(ap, int);
75472+ str1 = va_arg(ap, char *);
75473+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75474+ break;
75475+ case GR_TEXTREL:
75476+ file = va_arg(ap, struct file *);
75477+ ulong1 = va_arg(ap, unsigned long);
75478+ ulong2 = va_arg(ap, unsigned long);
75479+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75480+ break;
75481+ case GR_PTRACE:
75482+ task = va_arg(ap, struct task_struct *);
75483+ 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));
75484+ break;
75485+ case GR_RESOURCE:
75486+ task = va_arg(ap, struct task_struct *);
75487+ cred = __task_cred(task);
75488+ pcred = __task_cred(task->real_parent);
75489+ ulong1 = va_arg(ap, unsigned long);
75490+ str1 = va_arg(ap, char *);
75491+ ulong2 = va_arg(ap, unsigned long);
75492+ 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));
75493+ break;
75494+ case GR_CAP:
75495+ task = va_arg(ap, struct task_struct *);
75496+ cred = __task_cred(task);
75497+ pcred = __task_cred(task->real_parent);
75498+ str1 = va_arg(ap, char *);
75499+ 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));
75500+ break;
75501+ case GR_SIG:
75502+ str1 = va_arg(ap, char *);
75503+ voidptr = va_arg(ap, void *);
75504+ gr_log_middle_varargs(audit, msg, str1, voidptr);
75505+ break;
75506+ case GR_SIG2:
75507+ task = va_arg(ap, struct task_struct *);
75508+ cred = __task_cred(task);
75509+ pcred = __task_cred(task->real_parent);
75510+ num1 = va_arg(ap, int);
75511+ 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));
75512+ break;
75513+ case GR_CRASH1:
75514+ task = va_arg(ap, struct task_struct *);
75515+ cred = __task_cred(task);
75516+ pcred = __task_cred(task->real_parent);
75517+ ulong1 = va_arg(ap, unsigned long);
75518+ 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);
75519+ break;
75520+ case GR_CRASH2:
75521+ task = va_arg(ap, struct task_struct *);
75522+ cred = __task_cred(task);
75523+ pcred = __task_cred(task->real_parent);
75524+ ulong1 = va_arg(ap, unsigned long);
75525+ 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);
75526+ break;
75527+ case GR_RWXMAP:
75528+ file = va_arg(ap, struct file *);
75529+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75530+ break;
75531+ case GR_RWXMAPVMA:
75532+ vma = va_arg(ap, struct vm_area_struct *);
75533+ if (vma->vm_file)
75534+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75535+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75536+ str1 = "<stack>";
75537+ else if (vma->vm_start <= current->mm->brk &&
75538+ vma->vm_end >= current->mm->start_brk)
75539+ str1 = "<heap>";
75540+ else
75541+ str1 = "<anonymous mapping>";
75542+ gr_log_middle_varargs(audit, msg, str1);
75543+ break;
75544+ case GR_PSACCT:
75545+ {
75546+ unsigned int wday, cday;
75547+ __u8 whr, chr;
75548+ __u8 wmin, cmin;
75549+ __u8 wsec, csec;
75550+ char cur_tty[64] = { 0 };
75551+ char parent_tty[64] = { 0 };
75552+
75553+ task = va_arg(ap, struct task_struct *);
75554+ wday = va_arg(ap, unsigned int);
75555+ cday = va_arg(ap, unsigned int);
75556+ whr = va_arg(ap, int);
75557+ chr = va_arg(ap, int);
75558+ wmin = va_arg(ap, int);
75559+ cmin = va_arg(ap, int);
75560+ wsec = va_arg(ap, int);
75561+ csec = va_arg(ap, int);
75562+ ulong1 = va_arg(ap, unsigned long);
75563+ cred = __task_cred(task);
75564+ pcred = __task_cred(task->real_parent);
75565+
75566+ 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));
75567+ }
75568+ break;
75569+ default:
75570+ gr_log_middle(audit, msg, ap);
75571+ }
75572+ va_end(ap);
75573+ // these don't need DEFAULTSECARGS printed on the end
75574+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75575+ gr_log_end(audit, 0);
75576+ else
75577+ gr_log_end(audit, 1);
75578+ END_LOCKS(audit);
75579+}
75580diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75581new file mode 100644
75582index 0000000..0e39d8c
75583--- /dev/null
75584+++ b/grsecurity/grsec_mem.c
75585@@ -0,0 +1,48 @@
75586+#include <linux/kernel.h>
75587+#include <linux/sched.h>
75588+#include <linux/mm.h>
75589+#include <linux/mman.h>
75590+#include <linux/module.h>
75591+#include <linux/grinternal.h>
75592+
75593+void gr_handle_msr_write(void)
75594+{
75595+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75596+ return;
75597+}
75598+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75599+
75600+void
75601+gr_handle_ioperm(void)
75602+{
75603+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75604+ return;
75605+}
75606+
75607+void
75608+gr_handle_iopl(void)
75609+{
75610+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75611+ return;
75612+}
75613+
75614+void
75615+gr_handle_mem_readwrite(u64 from, u64 to)
75616+{
75617+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75618+ return;
75619+}
75620+
75621+void
75622+gr_handle_vm86(void)
75623+{
75624+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75625+ return;
75626+}
75627+
75628+void
75629+gr_log_badprocpid(const char *entry)
75630+{
75631+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75632+ return;
75633+}
75634diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75635new file mode 100644
75636index 0000000..cd9e124
75637--- /dev/null
75638+++ b/grsecurity/grsec_mount.c
75639@@ -0,0 +1,65 @@
75640+#include <linux/kernel.h>
75641+#include <linux/sched.h>
75642+#include <linux/mount.h>
75643+#include <linux/major.h>
75644+#include <linux/grsecurity.h>
75645+#include <linux/grinternal.h>
75646+
75647+void
75648+gr_log_remount(const char *devname, const int retval)
75649+{
75650+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75651+ if (grsec_enable_mount && (retval >= 0))
75652+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75653+#endif
75654+ return;
75655+}
75656+
75657+void
75658+gr_log_unmount(const char *devname, const int retval)
75659+{
75660+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75661+ if (grsec_enable_mount && (retval >= 0))
75662+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75663+#endif
75664+ return;
75665+}
75666+
75667+void
75668+gr_log_mount(const char *from, const char *to, const int retval)
75669+{
75670+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75671+ if (grsec_enable_mount && (retval >= 0))
75672+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75673+#endif
75674+ return;
75675+}
75676+
75677+int
75678+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75679+{
75680+#ifdef CONFIG_GRKERNSEC_ROFS
75681+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75682+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75683+ return -EPERM;
75684+ } else
75685+ return 0;
75686+#endif
75687+ return 0;
75688+}
75689+
75690+int
75691+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75692+{
75693+#ifdef CONFIG_GRKERNSEC_ROFS
75694+ struct inode *inode = dentry->d_inode;
75695+
75696+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75697+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75698+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75699+ return -EPERM;
75700+ } else
75701+ return 0;
75702+#endif
75703+ return 0;
75704+}
75705diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75706new file mode 100644
75707index 0000000..6ee9d50
75708--- /dev/null
75709+++ b/grsecurity/grsec_pax.c
75710@@ -0,0 +1,45 @@
75711+#include <linux/kernel.h>
75712+#include <linux/sched.h>
75713+#include <linux/mm.h>
75714+#include <linux/file.h>
75715+#include <linux/grinternal.h>
75716+#include <linux/grsecurity.h>
75717+
75718+void
75719+gr_log_textrel(struct vm_area_struct * vma)
75720+{
75721+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75722+ if (grsec_enable_log_rwxmaps)
75723+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75724+#endif
75725+ return;
75726+}
75727+
75728+void gr_log_ptgnustack(struct file *file)
75729+{
75730+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75731+ if (grsec_enable_log_rwxmaps)
75732+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75733+#endif
75734+ return;
75735+}
75736+
75737+void
75738+gr_log_rwxmmap(struct file *file)
75739+{
75740+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75741+ if (grsec_enable_log_rwxmaps)
75742+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75743+#endif
75744+ return;
75745+}
75746+
75747+void
75748+gr_log_rwxmprotect(struct vm_area_struct *vma)
75749+{
75750+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75751+ if (grsec_enable_log_rwxmaps)
75752+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75753+#endif
75754+ return;
75755+}
75756diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75757new file mode 100644
75758index 0000000..2005a3a
75759--- /dev/null
75760+++ b/grsecurity/grsec_proc.c
75761@@ -0,0 +1,20 @@
75762+#include <linux/kernel.h>
75763+#include <linux/sched.h>
75764+#include <linux/grsecurity.h>
75765+#include <linux/grinternal.h>
75766+
75767+int gr_proc_is_restricted(void)
75768+{
75769+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75770+ const struct cred *cred = current_cred();
75771+#endif
75772+
75773+#ifdef CONFIG_GRKERNSEC_PROC_USER
75774+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75775+ return -EACCES;
75776+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75777+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75778+ return -EACCES;
75779+#endif
75780+ return 0;
75781+}
75782diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75783new file mode 100644
75784index 0000000..f7f29aa
75785--- /dev/null
75786+++ b/grsecurity/grsec_ptrace.c
75787@@ -0,0 +1,30 @@
75788+#include <linux/kernel.h>
75789+#include <linux/sched.h>
75790+#include <linux/grinternal.h>
75791+#include <linux/security.h>
75792+
75793+void
75794+gr_audit_ptrace(struct task_struct *task)
75795+{
75796+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75797+ if (grsec_enable_audit_ptrace)
75798+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75799+#endif
75800+ return;
75801+}
75802+
75803+int
75804+gr_ptrace_readexec(struct file *file, int unsafe_flags)
75805+{
75806+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75807+ const struct dentry *dentry = file->f_path.dentry;
75808+ const struct vfsmount *mnt = file->f_path.mnt;
75809+
75810+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75811+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75812+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75813+ return -EACCES;
75814+ }
75815+#endif
75816+ return 0;
75817+}
75818diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75819new file mode 100644
75820index 0000000..3860c7e
75821--- /dev/null
75822+++ b/grsecurity/grsec_sig.c
75823@@ -0,0 +1,236 @@
75824+#include <linux/kernel.h>
75825+#include <linux/sched.h>
75826+#include <linux/fs.h>
75827+#include <linux/delay.h>
75828+#include <linux/grsecurity.h>
75829+#include <linux/grinternal.h>
75830+#include <linux/hardirq.h>
75831+
75832+char *signames[] = {
75833+ [SIGSEGV] = "Segmentation fault",
75834+ [SIGILL] = "Illegal instruction",
75835+ [SIGABRT] = "Abort",
75836+ [SIGBUS] = "Invalid alignment/Bus error"
75837+};
75838+
75839+void
75840+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75841+{
75842+#ifdef CONFIG_GRKERNSEC_SIGNAL
75843+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75844+ (sig == SIGABRT) || (sig == SIGBUS))) {
75845+ if (task_pid_nr(t) == task_pid_nr(current)) {
75846+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75847+ } else {
75848+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75849+ }
75850+ }
75851+#endif
75852+ return;
75853+}
75854+
75855+int
75856+gr_handle_signal(const struct task_struct *p, const int sig)
75857+{
75858+#ifdef CONFIG_GRKERNSEC
75859+ /* ignore the 0 signal for protected task checks */
75860+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75861+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75862+ return -EPERM;
75863+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75864+ return -EPERM;
75865+ }
75866+#endif
75867+ return 0;
75868+}
75869+
75870+#ifdef CONFIG_GRKERNSEC
75871+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75872+
75873+int gr_fake_force_sig(int sig, struct task_struct *t)
75874+{
75875+ unsigned long int flags;
75876+ int ret, blocked, ignored;
75877+ struct k_sigaction *action;
75878+
75879+ spin_lock_irqsave(&t->sighand->siglock, flags);
75880+ action = &t->sighand->action[sig-1];
75881+ ignored = action->sa.sa_handler == SIG_IGN;
75882+ blocked = sigismember(&t->blocked, sig);
75883+ if (blocked || ignored) {
75884+ action->sa.sa_handler = SIG_DFL;
75885+ if (blocked) {
75886+ sigdelset(&t->blocked, sig);
75887+ recalc_sigpending_and_wake(t);
75888+ }
75889+ }
75890+ if (action->sa.sa_handler == SIG_DFL)
75891+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
75892+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75893+
75894+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
75895+
75896+ return ret;
75897+}
75898+#endif
75899+
75900+#define GR_USER_BAN_TIME (15 * 60)
75901+#define GR_DAEMON_BRUTE_TIME (30 * 60)
75902+
75903+void gr_handle_brute_attach(int dumpable)
75904+{
75905+#ifdef CONFIG_GRKERNSEC_BRUTE
75906+ struct task_struct *p = current;
75907+ kuid_t uid = GLOBAL_ROOT_UID;
75908+ int daemon = 0;
75909+
75910+ if (!grsec_enable_brute)
75911+ return;
75912+
75913+ rcu_read_lock();
75914+ read_lock(&tasklist_lock);
75915+ read_lock(&grsec_exec_file_lock);
75916+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75917+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75918+ p->real_parent->brute = 1;
75919+ daemon = 1;
75920+ } else {
75921+ const struct cred *cred = __task_cred(p), *cred2;
75922+ struct task_struct *tsk, *tsk2;
75923+
75924+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75925+ struct user_struct *user;
75926+
75927+ uid = cred->uid;
75928+
75929+ /* this is put upon execution past expiration */
75930+ user = find_user(uid);
75931+ if (user == NULL)
75932+ goto unlock;
75933+ user->suid_banned = 1;
75934+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75935+ if (user->suid_ban_expires == ~0UL)
75936+ user->suid_ban_expires--;
75937+
75938+ /* only kill other threads of the same binary, from the same user */
75939+ do_each_thread(tsk2, tsk) {
75940+ cred2 = __task_cred(tsk);
75941+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75942+ gr_fake_force_sig(SIGKILL, tsk);
75943+ } while_each_thread(tsk2, tsk);
75944+ }
75945+ }
75946+unlock:
75947+ read_unlock(&grsec_exec_file_lock);
75948+ read_unlock(&tasklist_lock);
75949+ rcu_read_unlock();
75950+
75951+ if (gr_is_global_nonroot(uid))
75952+ 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);
75953+ else if (daemon)
75954+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75955+
75956+#endif
75957+ return;
75958+}
75959+
75960+void gr_handle_brute_check(void)
75961+{
75962+#ifdef CONFIG_GRKERNSEC_BRUTE
75963+ struct task_struct *p = current;
75964+
75965+ if (unlikely(p->brute)) {
75966+ if (!grsec_enable_brute)
75967+ p->brute = 0;
75968+ else if (time_before(get_seconds(), p->brute_expires))
75969+ msleep(30 * 1000);
75970+ }
75971+#endif
75972+ return;
75973+}
75974+
75975+void gr_handle_kernel_exploit(void)
75976+{
75977+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75978+ const struct cred *cred;
75979+ struct task_struct *tsk, *tsk2;
75980+ struct user_struct *user;
75981+ kuid_t uid;
75982+
75983+ if (in_irq() || in_serving_softirq() || in_nmi())
75984+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75985+
75986+ uid = current_uid();
75987+
75988+ if (gr_is_global_root(uid))
75989+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75990+ else {
75991+ /* kill all the processes of this user, hold a reference
75992+ to their creds struct, and prevent them from creating
75993+ another process until system reset
75994+ */
75995+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75996+ GR_GLOBAL_UID(uid));
75997+ /* we intentionally leak this ref */
75998+ user = get_uid(current->cred->user);
75999+ if (user)
76000+ user->kernel_banned = 1;
76001+
76002+ /* kill all processes of this user */
76003+ read_lock(&tasklist_lock);
76004+ do_each_thread(tsk2, tsk) {
76005+ cred = __task_cred(tsk);
76006+ if (uid_eq(cred->uid, uid))
76007+ gr_fake_force_sig(SIGKILL, tsk);
76008+ } while_each_thread(tsk2, tsk);
76009+ read_unlock(&tasklist_lock);
76010+ }
76011+#endif
76012+}
76013+
76014+#ifdef CONFIG_GRKERNSEC_BRUTE
76015+static bool suid_ban_expired(struct user_struct *user)
76016+{
76017+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
76018+ user->suid_banned = 0;
76019+ user->suid_ban_expires = 0;
76020+ free_uid(user);
76021+ return true;
76022+ }
76023+
76024+ return false;
76025+}
76026+#endif
76027+
76028+int gr_process_kernel_exec_ban(void)
76029+{
76030+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76031+ if (unlikely(current->cred->user->kernel_banned))
76032+ return -EPERM;
76033+#endif
76034+ return 0;
76035+}
76036+
76037+int gr_process_kernel_setuid_ban(struct user_struct *user)
76038+{
76039+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76040+ if (unlikely(user->kernel_banned))
76041+ gr_fake_force_sig(SIGKILL, current);
76042+#endif
76043+ return 0;
76044+}
76045+
76046+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
76047+{
76048+#ifdef CONFIG_GRKERNSEC_BRUTE
76049+ struct user_struct *user = current->cred->user;
76050+ if (unlikely(user->suid_banned)) {
76051+ if (suid_ban_expired(user))
76052+ return 0;
76053+ /* disallow execution of suid binaries only */
76054+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
76055+ return -EPERM;
76056+ }
76057+#endif
76058+ return 0;
76059+}
76060diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
76061new file mode 100644
76062index 0000000..c0aef3a
76063--- /dev/null
76064+++ b/grsecurity/grsec_sock.c
76065@@ -0,0 +1,244 @@
76066+#include <linux/kernel.h>
76067+#include <linux/module.h>
76068+#include <linux/sched.h>
76069+#include <linux/file.h>
76070+#include <linux/net.h>
76071+#include <linux/in.h>
76072+#include <linux/ip.h>
76073+#include <net/sock.h>
76074+#include <net/inet_sock.h>
76075+#include <linux/grsecurity.h>
76076+#include <linux/grinternal.h>
76077+#include <linux/gracl.h>
76078+
76079+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
76080+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
76081+
76082+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
76083+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
76084+
76085+#ifdef CONFIG_UNIX_MODULE
76086+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
76087+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
76088+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
76089+EXPORT_SYMBOL_GPL(gr_handle_create);
76090+#endif
76091+
76092+#ifdef CONFIG_GRKERNSEC
76093+#define gr_conn_table_size 32749
76094+struct conn_table_entry {
76095+ struct conn_table_entry *next;
76096+ struct signal_struct *sig;
76097+};
76098+
76099+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
76100+DEFINE_SPINLOCK(gr_conn_table_lock);
76101+
76102+extern const char * gr_socktype_to_name(unsigned char type);
76103+extern const char * gr_proto_to_name(unsigned char proto);
76104+extern const char * gr_sockfamily_to_name(unsigned char family);
76105+
76106+static __inline__ int
76107+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
76108+{
76109+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
76110+}
76111+
76112+static __inline__ int
76113+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
76114+ __u16 sport, __u16 dport)
76115+{
76116+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
76117+ sig->gr_sport == sport && sig->gr_dport == dport))
76118+ return 1;
76119+ else
76120+ return 0;
76121+}
76122+
76123+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
76124+{
76125+ struct conn_table_entry **match;
76126+ unsigned int index;
76127+
76128+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76129+ sig->gr_sport, sig->gr_dport,
76130+ gr_conn_table_size);
76131+
76132+ newent->sig = sig;
76133+
76134+ match = &gr_conn_table[index];
76135+ newent->next = *match;
76136+ *match = newent;
76137+
76138+ return;
76139+}
76140+
76141+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
76142+{
76143+ struct conn_table_entry *match, *last = NULL;
76144+ unsigned int index;
76145+
76146+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76147+ sig->gr_sport, sig->gr_dport,
76148+ gr_conn_table_size);
76149+
76150+ match = gr_conn_table[index];
76151+ while (match && !conn_match(match->sig,
76152+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
76153+ sig->gr_dport)) {
76154+ last = match;
76155+ match = match->next;
76156+ }
76157+
76158+ if (match) {
76159+ if (last)
76160+ last->next = match->next;
76161+ else
76162+ gr_conn_table[index] = NULL;
76163+ kfree(match);
76164+ }
76165+
76166+ return;
76167+}
76168+
76169+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
76170+ __u16 sport, __u16 dport)
76171+{
76172+ struct conn_table_entry *match;
76173+ unsigned int index;
76174+
76175+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
76176+
76177+ match = gr_conn_table[index];
76178+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
76179+ match = match->next;
76180+
76181+ if (match)
76182+ return match->sig;
76183+ else
76184+ return NULL;
76185+}
76186+
76187+#endif
76188+
76189+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
76190+{
76191+#ifdef CONFIG_GRKERNSEC
76192+ struct signal_struct *sig = task->signal;
76193+ struct conn_table_entry *newent;
76194+
76195+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
76196+ if (newent == NULL)
76197+ return;
76198+ /* no bh lock needed since we are called with bh disabled */
76199+ spin_lock(&gr_conn_table_lock);
76200+ gr_del_task_from_ip_table_nolock(sig);
76201+ sig->gr_saddr = inet->inet_rcv_saddr;
76202+ sig->gr_daddr = inet->inet_daddr;
76203+ sig->gr_sport = inet->inet_sport;
76204+ sig->gr_dport = inet->inet_dport;
76205+ gr_add_to_task_ip_table_nolock(sig, newent);
76206+ spin_unlock(&gr_conn_table_lock);
76207+#endif
76208+ return;
76209+}
76210+
76211+void gr_del_task_from_ip_table(struct task_struct *task)
76212+{
76213+#ifdef CONFIG_GRKERNSEC
76214+ spin_lock_bh(&gr_conn_table_lock);
76215+ gr_del_task_from_ip_table_nolock(task->signal);
76216+ spin_unlock_bh(&gr_conn_table_lock);
76217+#endif
76218+ return;
76219+}
76220+
76221+void
76222+gr_attach_curr_ip(const struct sock *sk)
76223+{
76224+#ifdef CONFIG_GRKERNSEC
76225+ struct signal_struct *p, *set;
76226+ const struct inet_sock *inet = inet_sk(sk);
76227+
76228+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
76229+ return;
76230+
76231+ set = current->signal;
76232+
76233+ spin_lock_bh(&gr_conn_table_lock);
76234+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
76235+ inet->inet_dport, inet->inet_sport);
76236+ if (unlikely(p != NULL)) {
76237+ set->curr_ip = p->curr_ip;
76238+ set->used_accept = 1;
76239+ gr_del_task_from_ip_table_nolock(p);
76240+ spin_unlock_bh(&gr_conn_table_lock);
76241+ return;
76242+ }
76243+ spin_unlock_bh(&gr_conn_table_lock);
76244+
76245+ set->curr_ip = inet->inet_daddr;
76246+ set->used_accept = 1;
76247+#endif
76248+ return;
76249+}
76250+
76251+int
76252+gr_handle_sock_all(const int family, const int type, const int protocol)
76253+{
76254+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76255+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
76256+ (family != AF_UNIX)) {
76257+ if (family == AF_INET)
76258+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
76259+ else
76260+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
76261+ return -EACCES;
76262+ }
76263+#endif
76264+ return 0;
76265+}
76266+
76267+int
76268+gr_handle_sock_server(const struct sockaddr *sck)
76269+{
76270+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76271+ if (grsec_enable_socket_server &&
76272+ in_group_p(grsec_socket_server_gid) &&
76273+ sck && (sck->sa_family != AF_UNIX) &&
76274+ (sck->sa_family != AF_LOCAL)) {
76275+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76276+ return -EACCES;
76277+ }
76278+#endif
76279+ return 0;
76280+}
76281+
76282+int
76283+gr_handle_sock_server_other(const struct sock *sck)
76284+{
76285+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76286+ if (grsec_enable_socket_server &&
76287+ in_group_p(grsec_socket_server_gid) &&
76288+ sck && (sck->sk_family != AF_UNIX) &&
76289+ (sck->sk_family != AF_LOCAL)) {
76290+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76291+ return -EACCES;
76292+ }
76293+#endif
76294+ return 0;
76295+}
76296+
76297+int
76298+gr_handle_sock_client(const struct sockaddr *sck)
76299+{
76300+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76301+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
76302+ sck && (sck->sa_family != AF_UNIX) &&
76303+ (sck->sa_family != AF_LOCAL)) {
76304+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
76305+ return -EACCES;
76306+ }
76307+#endif
76308+ return 0;
76309+}
76310diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
76311new file mode 100644
76312index 0000000..8159888
76313--- /dev/null
76314+++ b/grsecurity/grsec_sysctl.c
76315@@ -0,0 +1,479 @@
76316+#include <linux/kernel.h>
76317+#include <linux/sched.h>
76318+#include <linux/sysctl.h>
76319+#include <linux/grsecurity.h>
76320+#include <linux/grinternal.h>
76321+
76322+int
76323+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
76324+{
76325+#ifdef CONFIG_GRKERNSEC_SYSCTL
76326+ if (dirname == NULL || name == NULL)
76327+ return 0;
76328+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
76329+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
76330+ return -EACCES;
76331+ }
76332+#endif
76333+ return 0;
76334+}
76335+
76336+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
76337+static int __maybe_unused __read_only one = 1;
76338+#endif
76339+
76340+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
76341+ defined(CONFIG_GRKERNSEC_DENYUSB)
76342+struct ctl_table grsecurity_table[] = {
76343+#ifdef CONFIG_GRKERNSEC_SYSCTL
76344+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
76345+#ifdef CONFIG_GRKERNSEC_IO
76346+ {
76347+ .procname = "disable_priv_io",
76348+ .data = &grsec_disable_privio,
76349+ .maxlen = sizeof(int),
76350+ .mode = 0600,
76351+ .proc_handler = &proc_dointvec,
76352+ },
76353+#endif
76354+#endif
76355+#ifdef CONFIG_GRKERNSEC_LINK
76356+ {
76357+ .procname = "linking_restrictions",
76358+ .data = &grsec_enable_link,
76359+ .maxlen = sizeof(int),
76360+ .mode = 0600,
76361+ .proc_handler = &proc_dointvec,
76362+ },
76363+#endif
76364+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76365+ {
76366+ .procname = "enforce_symlinksifowner",
76367+ .data = &grsec_enable_symlinkown,
76368+ .maxlen = sizeof(int),
76369+ .mode = 0600,
76370+ .proc_handler = &proc_dointvec,
76371+ },
76372+ {
76373+ .procname = "symlinkown_gid",
76374+ .data = &grsec_symlinkown_gid,
76375+ .maxlen = sizeof(int),
76376+ .mode = 0600,
76377+ .proc_handler = &proc_dointvec,
76378+ },
76379+#endif
76380+#ifdef CONFIG_GRKERNSEC_BRUTE
76381+ {
76382+ .procname = "deter_bruteforce",
76383+ .data = &grsec_enable_brute,
76384+ .maxlen = sizeof(int),
76385+ .mode = 0600,
76386+ .proc_handler = &proc_dointvec,
76387+ },
76388+#endif
76389+#ifdef CONFIG_GRKERNSEC_FIFO
76390+ {
76391+ .procname = "fifo_restrictions",
76392+ .data = &grsec_enable_fifo,
76393+ .maxlen = sizeof(int),
76394+ .mode = 0600,
76395+ .proc_handler = &proc_dointvec,
76396+ },
76397+#endif
76398+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76399+ {
76400+ .procname = "ptrace_readexec",
76401+ .data = &grsec_enable_ptrace_readexec,
76402+ .maxlen = sizeof(int),
76403+ .mode = 0600,
76404+ .proc_handler = &proc_dointvec,
76405+ },
76406+#endif
76407+#ifdef CONFIG_GRKERNSEC_SETXID
76408+ {
76409+ .procname = "consistent_setxid",
76410+ .data = &grsec_enable_setxid,
76411+ .maxlen = sizeof(int),
76412+ .mode = 0600,
76413+ .proc_handler = &proc_dointvec,
76414+ },
76415+#endif
76416+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76417+ {
76418+ .procname = "ip_blackhole",
76419+ .data = &grsec_enable_blackhole,
76420+ .maxlen = sizeof(int),
76421+ .mode = 0600,
76422+ .proc_handler = &proc_dointvec,
76423+ },
76424+ {
76425+ .procname = "lastack_retries",
76426+ .data = &grsec_lastack_retries,
76427+ .maxlen = sizeof(int),
76428+ .mode = 0600,
76429+ .proc_handler = &proc_dointvec,
76430+ },
76431+#endif
76432+#ifdef CONFIG_GRKERNSEC_EXECLOG
76433+ {
76434+ .procname = "exec_logging",
76435+ .data = &grsec_enable_execlog,
76436+ .maxlen = sizeof(int),
76437+ .mode = 0600,
76438+ .proc_handler = &proc_dointvec,
76439+ },
76440+#endif
76441+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76442+ {
76443+ .procname = "rwxmap_logging",
76444+ .data = &grsec_enable_log_rwxmaps,
76445+ .maxlen = sizeof(int),
76446+ .mode = 0600,
76447+ .proc_handler = &proc_dointvec,
76448+ },
76449+#endif
76450+#ifdef CONFIG_GRKERNSEC_SIGNAL
76451+ {
76452+ .procname = "signal_logging",
76453+ .data = &grsec_enable_signal,
76454+ .maxlen = sizeof(int),
76455+ .mode = 0600,
76456+ .proc_handler = &proc_dointvec,
76457+ },
76458+#endif
76459+#ifdef CONFIG_GRKERNSEC_FORKFAIL
76460+ {
76461+ .procname = "forkfail_logging",
76462+ .data = &grsec_enable_forkfail,
76463+ .maxlen = sizeof(int),
76464+ .mode = 0600,
76465+ .proc_handler = &proc_dointvec,
76466+ },
76467+#endif
76468+#ifdef CONFIG_GRKERNSEC_TIME
76469+ {
76470+ .procname = "timechange_logging",
76471+ .data = &grsec_enable_time,
76472+ .maxlen = sizeof(int),
76473+ .mode = 0600,
76474+ .proc_handler = &proc_dointvec,
76475+ },
76476+#endif
76477+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76478+ {
76479+ .procname = "chroot_deny_shmat",
76480+ .data = &grsec_enable_chroot_shmat,
76481+ .maxlen = sizeof(int),
76482+ .mode = 0600,
76483+ .proc_handler = &proc_dointvec,
76484+ },
76485+#endif
76486+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76487+ {
76488+ .procname = "chroot_deny_unix",
76489+ .data = &grsec_enable_chroot_unix,
76490+ .maxlen = sizeof(int),
76491+ .mode = 0600,
76492+ .proc_handler = &proc_dointvec,
76493+ },
76494+#endif
76495+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76496+ {
76497+ .procname = "chroot_deny_mount",
76498+ .data = &grsec_enable_chroot_mount,
76499+ .maxlen = sizeof(int),
76500+ .mode = 0600,
76501+ .proc_handler = &proc_dointvec,
76502+ },
76503+#endif
76504+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76505+ {
76506+ .procname = "chroot_deny_fchdir",
76507+ .data = &grsec_enable_chroot_fchdir,
76508+ .maxlen = sizeof(int),
76509+ .mode = 0600,
76510+ .proc_handler = &proc_dointvec,
76511+ },
76512+#endif
76513+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76514+ {
76515+ .procname = "chroot_deny_chroot",
76516+ .data = &grsec_enable_chroot_double,
76517+ .maxlen = sizeof(int),
76518+ .mode = 0600,
76519+ .proc_handler = &proc_dointvec,
76520+ },
76521+#endif
76522+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76523+ {
76524+ .procname = "chroot_deny_pivot",
76525+ .data = &grsec_enable_chroot_pivot,
76526+ .maxlen = sizeof(int),
76527+ .mode = 0600,
76528+ .proc_handler = &proc_dointvec,
76529+ },
76530+#endif
76531+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76532+ {
76533+ .procname = "chroot_enforce_chdir",
76534+ .data = &grsec_enable_chroot_chdir,
76535+ .maxlen = sizeof(int),
76536+ .mode = 0600,
76537+ .proc_handler = &proc_dointvec,
76538+ },
76539+#endif
76540+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76541+ {
76542+ .procname = "chroot_deny_chmod",
76543+ .data = &grsec_enable_chroot_chmod,
76544+ .maxlen = sizeof(int),
76545+ .mode = 0600,
76546+ .proc_handler = &proc_dointvec,
76547+ },
76548+#endif
76549+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76550+ {
76551+ .procname = "chroot_deny_mknod",
76552+ .data = &grsec_enable_chroot_mknod,
76553+ .maxlen = sizeof(int),
76554+ .mode = 0600,
76555+ .proc_handler = &proc_dointvec,
76556+ },
76557+#endif
76558+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76559+ {
76560+ .procname = "chroot_restrict_nice",
76561+ .data = &grsec_enable_chroot_nice,
76562+ .maxlen = sizeof(int),
76563+ .mode = 0600,
76564+ .proc_handler = &proc_dointvec,
76565+ },
76566+#endif
76567+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76568+ {
76569+ .procname = "chroot_execlog",
76570+ .data = &grsec_enable_chroot_execlog,
76571+ .maxlen = sizeof(int),
76572+ .mode = 0600,
76573+ .proc_handler = &proc_dointvec,
76574+ },
76575+#endif
76576+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76577+ {
76578+ .procname = "chroot_caps",
76579+ .data = &grsec_enable_chroot_caps,
76580+ .maxlen = sizeof(int),
76581+ .mode = 0600,
76582+ .proc_handler = &proc_dointvec,
76583+ },
76584+#endif
76585+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76586+ {
76587+ .procname = "chroot_deny_sysctl",
76588+ .data = &grsec_enable_chroot_sysctl,
76589+ .maxlen = sizeof(int),
76590+ .mode = 0600,
76591+ .proc_handler = &proc_dointvec,
76592+ },
76593+#endif
76594+#ifdef CONFIG_GRKERNSEC_TPE
76595+ {
76596+ .procname = "tpe",
76597+ .data = &grsec_enable_tpe,
76598+ .maxlen = sizeof(int),
76599+ .mode = 0600,
76600+ .proc_handler = &proc_dointvec,
76601+ },
76602+ {
76603+ .procname = "tpe_gid",
76604+ .data = &grsec_tpe_gid,
76605+ .maxlen = sizeof(int),
76606+ .mode = 0600,
76607+ .proc_handler = &proc_dointvec,
76608+ },
76609+#endif
76610+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76611+ {
76612+ .procname = "tpe_invert",
76613+ .data = &grsec_enable_tpe_invert,
76614+ .maxlen = sizeof(int),
76615+ .mode = 0600,
76616+ .proc_handler = &proc_dointvec,
76617+ },
76618+#endif
76619+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76620+ {
76621+ .procname = "tpe_restrict_all",
76622+ .data = &grsec_enable_tpe_all,
76623+ .maxlen = sizeof(int),
76624+ .mode = 0600,
76625+ .proc_handler = &proc_dointvec,
76626+ },
76627+#endif
76628+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76629+ {
76630+ .procname = "socket_all",
76631+ .data = &grsec_enable_socket_all,
76632+ .maxlen = sizeof(int),
76633+ .mode = 0600,
76634+ .proc_handler = &proc_dointvec,
76635+ },
76636+ {
76637+ .procname = "socket_all_gid",
76638+ .data = &grsec_socket_all_gid,
76639+ .maxlen = sizeof(int),
76640+ .mode = 0600,
76641+ .proc_handler = &proc_dointvec,
76642+ },
76643+#endif
76644+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76645+ {
76646+ .procname = "socket_client",
76647+ .data = &grsec_enable_socket_client,
76648+ .maxlen = sizeof(int),
76649+ .mode = 0600,
76650+ .proc_handler = &proc_dointvec,
76651+ },
76652+ {
76653+ .procname = "socket_client_gid",
76654+ .data = &grsec_socket_client_gid,
76655+ .maxlen = sizeof(int),
76656+ .mode = 0600,
76657+ .proc_handler = &proc_dointvec,
76658+ },
76659+#endif
76660+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76661+ {
76662+ .procname = "socket_server",
76663+ .data = &grsec_enable_socket_server,
76664+ .maxlen = sizeof(int),
76665+ .mode = 0600,
76666+ .proc_handler = &proc_dointvec,
76667+ },
76668+ {
76669+ .procname = "socket_server_gid",
76670+ .data = &grsec_socket_server_gid,
76671+ .maxlen = sizeof(int),
76672+ .mode = 0600,
76673+ .proc_handler = &proc_dointvec,
76674+ },
76675+#endif
76676+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76677+ {
76678+ .procname = "audit_group",
76679+ .data = &grsec_enable_group,
76680+ .maxlen = sizeof(int),
76681+ .mode = 0600,
76682+ .proc_handler = &proc_dointvec,
76683+ },
76684+ {
76685+ .procname = "audit_gid",
76686+ .data = &grsec_audit_gid,
76687+ .maxlen = sizeof(int),
76688+ .mode = 0600,
76689+ .proc_handler = &proc_dointvec,
76690+ },
76691+#endif
76692+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76693+ {
76694+ .procname = "audit_chdir",
76695+ .data = &grsec_enable_chdir,
76696+ .maxlen = sizeof(int),
76697+ .mode = 0600,
76698+ .proc_handler = &proc_dointvec,
76699+ },
76700+#endif
76701+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76702+ {
76703+ .procname = "audit_mount",
76704+ .data = &grsec_enable_mount,
76705+ .maxlen = sizeof(int),
76706+ .mode = 0600,
76707+ .proc_handler = &proc_dointvec,
76708+ },
76709+#endif
76710+#ifdef CONFIG_GRKERNSEC_DMESG
76711+ {
76712+ .procname = "dmesg",
76713+ .data = &grsec_enable_dmesg,
76714+ .maxlen = sizeof(int),
76715+ .mode = 0600,
76716+ .proc_handler = &proc_dointvec,
76717+ },
76718+#endif
76719+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76720+ {
76721+ .procname = "chroot_findtask",
76722+ .data = &grsec_enable_chroot_findtask,
76723+ .maxlen = sizeof(int),
76724+ .mode = 0600,
76725+ .proc_handler = &proc_dointvec,
76726+ },
76727+#endif
76728+#ifdef CONFIG_GRKERNSEC_RESLOG
76729+ {
76730+ .procname = "resource_logging",
76731+ .data = &grsec_resource_logging,
76732+ .maxlen = sizeof(int),
76733+ .mode = 0600,
76734+ .proc_handler = &proc_dointvec,
76735+ },
76736+#endif
76737+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76738+ {
76739+ .procname = "audit_ptrace",
76740+ .data = &grsec_enable_audit_ptrace,
76741+ .maxlen = sizeof(int),
76742+ .mode = 0600,
76743+ .proc_handler = &proc_dointvec,
76744+ },
76745+#endif
76746+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76747+ {
76748+ .procname = "harden_ptrace",
76749+ .data = &grsec_enable_harden_ptrace,
76750+ .maxlen = sizeof(int),
76751+ .mode = 0600,
76752+ .proc_handler = &proc_dointvec,
76753+ },
76754+#endif
76755+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76756+ {
76757+ .procname = "harden_ipc",
76758+ .data = &grsec_enable_harden_ipc,
76759+ .maxlen = sizeof(int),
76760+ .mode = 0600,
76761+ .proc_handler = &proc_dointvec,
76762+ },
76763+#endif
76764+ {
76765+ .procname = "grsec_lock",
76766+ .data = &grsec_lock,
76767+ .maxlen = sizeof(int),
76768+ .mode = 0600,
76769+ .proc_handler = &proc_dointvec,
76770+ },
76771+#endif
76772+#ifdef CONFIG_GRKERNSEC_ROFS
76773+ {
76774+ .procname = "romount_protect",
76775+ .data = &grsec_enable_rofs,
76776+ .maxlen = sizeof(int),
76777+ .mode = 0600,
76778+ .proc_handler = &proc_dointvec_minmax,
76779+ .extra1 = &one,
76780+ .extra2 = &one,
76781+ },
76782+#endif
76783+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76784+ {
76785+ .procname = "deny_new_usb",
76786+ .data = &grsec_deny_new_usb,
76787+ .maxlen = sizeof(int),
76788+ .mode = 0600,
76789+ .proc_handler = &proc_dointvec,
76790+ },
76791+#endif
76792+ { }
76793+};
76794+#endif
76795diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76796new file mode 100644
76797index 0000000..61b514e
76798--- /dev/null
76799+++ b/grsecurity/grsec_time.c
76800@@ -0,0 +1,16 @@
76801+#include <linux/kernel.h>
76802+#include <linux/sched.h>
76803+#include <linux/grinternal.h>
76804+#include <linux/module.h>
76805+
76806+void
76807+gr_log_timechange(void)
76808+{
76809+#ifdef CONFIG_GRKERNSEC_TIME
76810+ if (grsec_enable_time)
76811+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76812+#endif
76813+ return;
76814+}
76815+
76816+EXPORT_SYMBOL_GPL(gr_log_timechange);
76817diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76818new file mode 100644
76819index 0000000..ee57dcf
76820--- /dev/null
76821+++ b/grsecurity/grsec_tpe.c
76822@@ -0,0 +1,73 @@
76823+#include <linux/kernel.h>
76824+#include <linux/sched.h>
76825+#include <linux/file.h>
76826+#include <linux/fs.h>
76827+#include <linux/grinternal.h>
76828+
76829+extern int gr_acl_tpe_check(void);
76830+
76831+int
76832+gr_tpe_allow(const struct file *file)
76833+{
76834+#ifdef CONFIG_GRKERNSEC
76835+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76836+ const struct cred *cred = current_cred();
76837+ char *msg = NULL;
76838+ char *msg2 = NULL;
76839+
76840+ // never restrict root
76841+ if (gr_is_global_root(cred->uid))
76842+ return 1;
76843+
76844+ if (grsec_enable_tpe) {
76845+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76846+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76847+ msg = "not being in trusted group";
76848+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76849+ msg = "being in untrusted group";
76850+#else
76851+ if (in_group_p(grsec_tpe_gid))
76852+ msg = "being in untrusted group";
76853+#endif
76854+ }
76855+ if (!msg && gr_acl_tpe_check())
76856+ msg = "being in untrusted role";
76857+
76858+ // not in any affected group/role
76859+ if (!msg)
76860+ goto next_check;
76861+
76862+ if (gr_is_global_nonroot(inode->i_uid))
76863+ msg2 = "file in non-root-owned directory";
76864+ else if (inode->i_mode & S_IWOTH)
76865+ msg2 = "file in world-writable directory";
76866+ else if (inode->i_mode & S_IWGRP)
76867+ msg2 = "file in group-writable directory";
76868+
76869+ if (msg && msg2) {
76870+ char fullmsg[70] = {0};
76871+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76872+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76873+ return 0;
76874+ }
76875+ msg = NULL;
76876+next_check:
76877+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76878+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76879+ return 1;
76880+
76881+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76882+ msg = "directory not owned by user";
76883+ else if (inode->i_mode & S_IWOTH)
76884+ msg = "file in world-writable directory";
76885+ else if (inode->i_mode & S_IWGRP)
76886+ msg = "file in group-writable directory";
76887+
76888+ if (msg) {
76889+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76890+ return 0;
76891+ }
76892+#endif
76893+#endif
76894+ return 1;
76895+}
76896diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76897new file mode 100644
76898index 0000000..ae02d8e
76899--- /dev/null
76900+++ b/grsecurity/grsec_usb.c
76901@@ -0,0 +1,15 @@
76902+#include <linux/kernel.h>
76903+#include <linux/grinternal.h>
76904+#include <linux/module.h>
76905+
76906+int gr_handle_new_usb(void)
76907+{
76908+#ifdef CONFIG_GRKERNSEC_DENYUSB
76909+ if (grsec_deny_new_usb) {
76910+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76911+ return 1;
76912+ }
76913+#endif
76914+ return 0;
76915+}
76916+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76917diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76918new file mode 100644
76919index 0000000..9f7b1ac
76920--- /dev/null
76921+++ b/grsecurity/grsum.c
76922@@ -0,0 +1,61 @@
76923+#include <linux/err.h>
76924+#include <linux/kernel.h>
76925+#include <linux/sched.h>
76926+#include <linux/mm.h>
76927+#include <linux/scatterlist.h>
76928+#include <linux/crypto.h>
76929+#include <linux/gracl.h>
76930+
76931+
76932+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76933+#error "crypto and sha256 must be built into the kernel"
76934+#endif
76935+
76936+int
76937+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76938+{
76939+ char *p;
76940+ struct crypto_hash *tfm;
76941+ struct hash_desc desc;
76942+ struct scatterlist sg;
76943+ unsigned char temp_sum[GR_SHA_LEN];
76944+ volatile int retval = 0;
76945+ volatile int dummy = 0;
76946+ unsigned int i;
76947+
76948+ sg_init_table(&sg, 1);
76949+
76950+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76951+ if (IS_ERR(tfm)) {
76952+ /* should never happen, since sha256 should be built in */
76953+ return 1;
76954+ }
76955+
76956+ desc.tfm = tfm;
76957+ desc.flags = 0;
76958+
76959+ crypto_hash_init(&desc);
76960+
76961+ p = salt;
76962+ sg_set_buf(&sg, p, GR_SALT_LEN);
76963+ crypto_hash_update(&desc, &sg, sg.length);
76964+
76965+ p = entry->pw;
76966+ sg_set_buf(&sg, p, strlen(p));
76967+
76968+ crypto_hash_update(&desc, &sg, sg.length);
76969+
76970+ crypto_hash_final(&desc, temp_sum);
76971+
76972+ memset(entry->pw, 0, GR_PW_LEN);
76973+
76974+ for (i = 0; i < GR_SHA_LEN; i++)
76975+ if (sum[i] != temp_sum[i])
76976+ retval = 1;
76977+ else
76978+ dummy = 1; // waste a cycle
76979+
76980+ crypto_free_hash(tfm);
76981+
76982+ return retval;
76983+}
76984diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76985index 77ff547..181834f 100644
76986--- a/include/asm-generic/4level-fixup.h
76987+++ b/include/asm-generic/4level-fixup.h
76988@@ -13,8 +13,10 @@
76989 #define pmd_alloc(mm, pud, address) \
76990 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76991 NULL: pmd_offset(pud, address))
76992+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76993
76994 #define pud_alloc(mm, pgd, address) (pgd)
76995+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76996 #define pud_offset(pgd, start) (pgd)
76997 #define pud_none(pud) 0
76998 #define pud_bad(pud) 0
76999diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
77000index b7babf0..97f4c4f 100644
77001--- a/include/asm-generic/atomic-long.h
77002+++ b/include/asm-generic/atomic-long.h
77003@@ -22,6 +22,12 @@
77004
77005 typedef atomic64_t atomic_long_t;
77006
77007+#ifdef CONFIG_PAX_REFCOUNT
77008+typedef atomic64_unchecked_t atomic_long_unchecked_t;
77009+#else
77010+typedef atomic64_t atomic_long_unchecked_t;
77011+#endif
77012+
77013 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
77014
77015 static inline long atomic_long_read(atomic_long_t *l)
77016@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77017 return (long)atomic64_read(v);
77018 }
77019
77020+#ifdef CONFIG_PAX_REFCOUNT
77021+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77022+{
77023+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77024+
77025+ return (long)atomic64_read_unchecked(v);
77026+}
77027+#endif
77028+
77029 static inline void atomic_long_set(atomic_long_t *l, long i)
77030 {
77031 atomic64_t *v = (atomic64_t *)l;
77032@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77033 atomic64_set(v, i);
77034 }
77035
77036+#ifdef CONFIG_PAX_REFCOUNT
77037+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77038+{
77039+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77040+
77041+ atomic64_set_unchecked(v, i);
77042+}
77043+#endif
77044+
77045 static inline void atomic_long_inc(atomic_long_t *l)
77046 {
77047 atomic64_t *v = (atomic64_t *)l;
77048@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77049 atomic64_inc(v);
77050 }
77051
77052+#ifdef CONFIG_PAX_REFCOUNT
77053+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77054+{
77055+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77056+
77057+ atomic64_inc_unchecked(v);
77058+}
77059+#endif
77060+
77061 static inline void atomic_long_dec(atomic_long_t *l)
77062 {
77063 atomic64_t *v = (atomic64_t *)l;
77064@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77065 atomic64_dec(v);
77066 }
77067
77068+#ifdef CONFIG_PAX_REFCOUNT
77069+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77070+{
77071+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77072+
77073+ atomic64_dec_unchecked(v);
77074+}
77075+#endif
77076+
77077 static inline void atomic_long_add(long i, atomic_long_t *l)
77078 {
77079 atomic64_t *v = (atomic64_t *)l;
77080@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77081 atomic64_add(i, v);
77082 }
77083
77084+#ifdef CONFIG_PAX_REFCOUNT
77085+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77086+{
77087+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77088+
77089+ atomic64_add_unchecked(i, v);
77090+}
77091+#endif
77092+
77093 static inline void atomic_long_sub(long i, atomic_long_t *l)
77094 {
77095 atomic64_t *v = (atomic64_t *)l;
77096@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77097 atomic64_sub(i, v);
77098 }
77099
77100+#ifdef CONFIG_PAX_REFCOUNT
77101+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77102+{
77103+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77104+
77105+ atomic64_sub_unchecked(i, v);
77106+}
77107+#endif
77108+
77109 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77110 {
77111 atomic64_t *v = (atomic64_t *)l;
77112@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
77113 return atomic64_add_negative(i, v);
77114 }
77115
77116-static inline long atomic_long_add_return(long i, atomic_long_t *l)
77117+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
77118 {
77119 atomic64_t *v = (atomic64_t *)l;
77120
77121 return (long)atomic64_add_return(i, v);
77122 }
77123
77124+#ifdef CONFIG_PAX_REFCOUNT
77125+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77126+{
77127+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77128+
77129+ return (long)atomic64_add_return_unchecked(i, v);
77130+}
77131+#endif
77132+
77133 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77134 {
77135 atomic64_t *v = (atomic64_t *)l;
77136@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77137 return (long)atomic64_inc_return(v);
77138 }
77139
77140+#ifdef CONFIG_PAX_REFCOUNT
77141+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77142+{
77143+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77144+
77145+ return (long)atomic64_inc_return_unchecked(v);
77146+}
77147+#endif
77148+
77149 static inline long atomic_long_dec_return(atomic_long_t *l)
77150 {
77151 atomic64_t *v = (atomic64_t *)l;
77152@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77153
77154 typedef atomic_t atomic_long_t;
77155
77156+#ifdef CONFIG_PAX_REFCOUNT
77157+typedef atomic_unchecked_t atomic_long_unchecked_t;
77158+#else
77159+typedef atomic_t atomic_long_unchecked_t;
77160+#endif
77161+
77162 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
77163 static inline long atomic_long_read(atomic_long_t *l)
77164 {
77165@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77166 return (long)atomic_read(v);
77167 }
77168
77169+#ifdef CONFIG_PAX_REFCOUNT
77170+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77171+{
77172+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77173+
77174+ return (long)atomic_read_unchecked(v);
77175+}
77176+#endif
77177+
77178 static inline void atomic_long_set(atomic_long_t *l, long i)
77179 {
77180 atomic_t *v = (atomic_t *)l;
77181@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77182 atomic_set(v, i);
77183 }
77184
77185+#ifdef CONFIG_PAX_REFCOUNT
77186+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77187+{
77188+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77189+
77190+ atomic_set_unchecked(v, i);
77191+}
77192+#endif
77193+
77194 static inline void atomic_long_inc(atomic_long_t *l)
77195 {
77196 atomic_t *v = (atomic_t *)l;
77197@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77198 atomic_inc(v);
77199 }
77200
77201+#ifdef CONFIG_PAX_REFCOUNT
77202+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77203+{
77204+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77205+
77206+ atomic_inc_unchecked(v);
77207+}
77208+#endif
77209+
77210 static inline void atomic_long_dec(atomic_long_t *l)
77211 {
77212 atomic_t *v = (atomic_t *)l;
77213@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77214 atomic_dec(v);
77215 }
77216
77217+#ifdef CONFIG_PAX_REFCOUNT
77218+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77219+{
77220+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77221+
77222+ atomic_dec_unchecked(v);
77223+}
77224+#endif
77225+
77226 static inline void atomic_long_add(long i, atomic_long_t *l)
77227 {
77228 atomic_t *v = (atomic_t *)l;
77229@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77230 atomic_add(i, v);
77231 }
77232
77233+#ifdef CONFIG_PAX_REFCOUNT
77234+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77235+{
77236+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77237+
77238+ atomic_add_unchecked(i, v);
77239+}
77240+#endif
77241+
77242 static inline void atomic_long_sub(long i, atomic_long_t *l)
77243 {
77244 atomic_t *v = (atomic_t *)l;
77245@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77246 atomic_sub(i, v);
77247 }
77248
77249+#ifdef CONFIG_PAX_REFCOUNT
77250+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77251+{
77252+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77253+
77254+ atomic_sub_unchecked(i, v);
77255+}
77256+#endif
77257+
77258 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77259 {
77260 atomic_t *v = (atomic_t *)l;
77261@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
77262 return (long)atomic_add_return(i, v);
77263 }
77264
77265+#ifdef CONFIG_PAX_REFCOUNT
77266+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77267+{
77268+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77269+
77270+ return (long)atomic_add_return_unchecked(i, v);
77271+}
77272+
77273+#endif
77274+
77275 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77276 {
77277 atomic_t *v = (atomic_t *)l;
77278@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77279 return (long)atomic_inc_return(v);
77280 }
77281
77282+#ifdef CONFIG_PAX_REFCOUNT
77283+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77284+{
77285+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77286+
77287+ return (long)atomic_inc_return_unchecked(v);
77288+}
77289+#endif
77290+
77291 static inline long atomic_long_dec_return(atomic_long_t *l)
77292 {
77293 atomic_t *v = (atomic_t *)l;
77294@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77295
77296 #endif /* BITS_PER_LONG == 64 */
77297
77298+#ifdef CONFIG_PAX_REFCOUNT
77299+static inline void pax_refcount_needs_these_functions(void)
77300+{
77301+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
77302+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
77303+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
77304+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
77305+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
77306+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
77307+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
77308+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
77309+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
77310+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
77311+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
77312+#ifdef CONFIG_X86
77313+ atomic_clear_mask_unchecked(0, NULL);
77314+ atomic_set_mask_unchecked(0, NULL);
77315+#endif
77316+
77317+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
77318+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
77319+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
77320+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
77321+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
77322+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
77323+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
77324+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
77325+}
77326+#else
77327+#define atomic_read_unchecked(v) atomic_read(v)
77328+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
77329+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
77330+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
77331+#define atomic_inc_unchecked(v) atomic_inc(v)
77332+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
77333+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
77334+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
77335+#define atomic_dec_unchecked(v) atomic_dec(v)
77336+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
77337+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
77338+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
77339+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
77340+
77341+#define atomic_long_read_unchecked(v) atomic_long_read(v)
77342+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
77343+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
77344+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
77345+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
77346+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
77347+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
77348+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
77349+#endif
77350+
77351 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
77352diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
77353index 33bd2de..f31bff97 100644
77354--- a/include/asm-generic/atomic.h
77355+++ b/include/asm-generic/atomic.h
77356@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
77357 * Atomically clears the bits set in @mask from @v
77358 */
77359 #ifndef atomic_clear_mask
77360-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
77361+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
77362 {
77363 unsigned long flags;
77364
77365diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
77366index b18ce4f..2ee2843 100644
77367--- a/include/asm-generic/atomic64.h
77368+++ b/include/asm-generic/atomic64.h
77369@@ -16,6 +16,8 @@ typedef struct {
77370 long long counter;
77371 } atomic64_t;
77372
77373+typedef atomic64_t atomic64_unchecked_t;
77374+
77375 #define ATOMIC64_INIT(i) { (i) }
77376
77377 extern long long atomic64_read(const atomic64_t *v);
77378@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
77379 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
77380 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
77381
77382+#define atomic64_read_unchecked(v) atomic64_read(v)
77383+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
77384+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
77385+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
77386+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
77387+#define atomic64_inc_unchecked(v) atomic64_inc(v)
77388+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
77389+#define atomic64_dec_unchecked(v) atomic64_dec(v)
77390+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
77391+
77392 #endif /* _ASM_GENERIC_ATOMIC64_H */
77393diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
77394index 6f692f8..2ad9dd2 100644
77395--- a/include/asm-generic/barrier.h
77396+++ b/include/asm-generic/barrier.h
77397@@ -66,7 +66,7 @@
77398 do { \
77399 compiletime_assert_atomic_type(*p); \
77400 smp_mb(); \
77401- ACCESS_ONCE(*p) = (v); \
77402+ ACCESS_ONCE_RW(*p) = (v); \
77403 } while (0)
77404
77405 #define smp_load_acquire(p) \
77406diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77407index a60a7cc..0fe12f2 100644
77408--- a/include/asm-generic/bitops/__fls.h
77409+++ b/include/asm-generic/bitops/__fls.h
77410@@ -9,7 +9,7 @@
77411 *
77412 * Undefined if no set bit exists, so code should check against 0 first.
77413 */
77414-static __always_inline unsigned long __fls(unsigned long word)
77415+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77416 {
77417 int num = BITS_PER_LONG - 1;
77418
77419diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77420index 0576d1f..dad6c71 100644
77421--- a/include/asm-generic/bitops/fls.h
77422+++ b/include/asm-generic/bitops/fls.h
77423@@ -9,7 +9,7 @@
77424 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77425 */
77426
77427-static __always_inline int fls(int x)
77428+static __always_inline int __intentional_overflow(-1) fls(int x)
77429 {
77430 int r = 32;
77431
77432diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77433index b097cf8..3d40e14 100644
77434--- a/include/asm-generic/bitops/fls64.h
77435+++ b/include/asm-generic/bitops/fls64.h
77436@@ -15,7 +15,7 @@
77437 * at position 64.
77438 */
77439 #if BITS_PER_LONG == 32
77440-static __always_inline int fls64(__u64 x)
77441+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77442 {
77443 __u32 h = x >> 32;
77444 if (h)
77445@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77446 return fls(x);
77447 }
77448 #elif BITS_PER_LONG == 64
77449-static __always_inline int fls64(__u64 x)
77450+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77451 {
77452 if (x == 0)
77453 return 0;
77454diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77455index 1bfcfe5..e04c5c9 100644
77456--- a/include/asm-generic/cache.h
77457+++ b/include/asm-generic/cache.h
77458@@ -6,7 +6,7 @@
77459 * cache lines need to provide their own cache.h.
77460 */
77461
77462-#define L1_CACHE_SHIFT 5
77463-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77464+#define L1_CACHE_SHIFT 5UL
77465+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77466
77467 #endif /* __ASM_GENERIC_CACHE_H */
77468diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77469index 0d68a1e..b74a761 100644
77470--- a/include/asm-generic/emergency-restart.h
77471+++ b/include/asm-generic/emergency-restart.h
77472@@ -1,7 +1,7 @@
77473 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77474 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77475
77476-static inline void machine_emergency_restart(void)
77477+static inline __noreturn void machine_emergency_restart(void)
77478 {
77479 machine_restart(NULL);
77480 }
77481diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77482index 90f99c7..00ce236 100644
77483--- a/include/asm-generic/kmap_types.h
77484+++ b/include/asm-generic/kmap_types.h
77485@@ -2,9 +2,9 @@
77486 #define _ASM_GENERIC_KMAP_TYPES_H
77487
77488 #ifdef __WITH_KM_FENCE
77489-# define KM_TYPE_NR 41
77490+# define KM_TYPE_NR 42
77491 #else
77492-# define KM_TYPE_NR 20
77493+# define KM_TYPE_NR 21
77494 #endif
77495
77496 #endif
77497diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77498index 9ceb03b..62b0b8f 100644
77499--- a/include/asm-generic/local.h
77500+++ b/include/asm-generic/local.h
77501@@ -23,24 +23,37 @@ typedef struct
77502 atomic_long_t a;
77503 } local_t;
77504
77505+typedef struct {
77506+ atomic_long_unchecked_t a;
77507+} local_unchecked_t;
77508+
77509 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77510
77511 #define local_read(l) atomic_long_read(&(l)->a)
77512+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77513 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77514+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77515 #define local_inc(l) atomic_long_inc(&(l)->a)
77516+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77517 #define local_dec(l) atomic_long_dec(&(l)->a)
77518+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77519 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77520+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77521 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77522+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77523
77524 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77525 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77526 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77527 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77528 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77529+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77530 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77531 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77532+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77533
77534 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77535+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77536 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77537 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77538 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77539diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77540index 725612b..9cc513a 100644
77541--- a/include/asm-generic/pgtable-nopmd.h
77542+++ b/include/asm-generic/pgtable-nopmd.h
77543@@ -1,14 +1,19 @@
77544 #ifndef _PGTABLE_NOPMD_H
77545 #define _PGTABLE_NOPMD_H
77546
77547-#ifndef __ASSEMBLY__
77548-
77549 #include <asm-generic/pgtable-nopud.h>
77550
77551-struct mm_struct;
77552-
77553 #define __PAGETABLE_PMD_FOLDED
77554
77555+#define PMD_SHIFT PUD_SHIFT
77556+#define PTRS_PER_PMD 1
77557+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77558+#define PMD_MASK (~(PMD_SIZE-1))
77559+
77560+#ifndef __ASSEMBLY__
77561+
77562+struct mm_struct;
77563+
77564 /*
77565 * Having the pmd type consist of a pud gets the size right, and allows
77566 * us to conceptually access the pud entry that this pmd is folded into
77567@@ -16,11 +21,6 @@ struct mm_struct;
77568 */
77569 typedef struct { pud_t pud; } pmd_t;
77570
77571-#define PMD_SHIFT PUD_SHIFT
77572-#define PTRS_PER_PMD 1
77573-#define PMD_SIZE (1UL << PMD_SHIFT)
77574-#define PMD_MASK (~(PMD_SIZE-1))
77575-
77576 /*
77577 * The "pud_xxx()" functions here are trivial for a folded two-level
77578 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77579diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77580index 810431d..0ec4804f 100644
77581--- a/include/asm-generic/pgtable-nopud.h
77582+++ b/include/asm-generic/pgtable-nopud.h
77583@@ -1,10 +1,15 @@
77584 #ifndef _PGTABLE_NOPUD_H
77585 #define _PGTABLE_NOPUD_H
77586
77587-#ifndef __ASSEMBLY__
77588-
77589 #define __PAGETABLE_PUD_FOLDED
77590
77591+#define PUD_SHIFT PGDIR_SHIFT
77592+#define PTRS_PER_PUD 1
77593+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77594+#define PUD_MASK (~(PUD_SIZE-1))
77595+
77596+#ifndef __ASSEMBLY__
77597+
77598 /*
77599 * Having the pud type consist of a pgd gets the size right, and allows
77600 * us to conceptually access the pgd entry that this pud is folded into
77601@@ -12,11 +17,6 @@
77602 */
77603 typedef struct { pgd_t pgd; } pud_t;
77604
77605-#define PUD_SHIFT PGDIR_SHIFT
77606-#define PTRS_PER_PUD 1
77607-#define PUD_SIZE (1UL << PUD_SHIFT)
77608-#define PUD_MASK (~(PUD_SIZE-1))
77609-
77610 /*
77611 * The "pgd_xxx()" functions here are trivial for a folded two-level
77612 * setup: the pud is never bad, and a pud always exists (as it's folded
77613@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77614 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77615
77616 #define pgd_populate(mm, pgd, pud) do { } while (0)
77617+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77618 /*
77619 * (puds are folded into pgds so this doesn't get actually called,
77620 * but the define is needed for a generic inline function.)
77621diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77622index 38a7437..47f62a4 100644
77623--- a/include/asm-generic/pgtable.h
77624+++ b/include/asm-generic/pgtable.h
77625@@ -802,6 +802,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77626 }
77627 #endif /* CONFIG_NUMA_BALANCING */
77628
77629+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77630+#ifdef CONFIG_PAX_KERNEXEC
77631+#error KERNEXEC requires pax_open_kernel
77632+#else
77633+static inline unsigned long pax_open_kernel(void) { return 0; }
77634+#endif
77635+#endif
77636+
77637+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77638+#ifdef CONFIG_PAX_KERNEXEC
77639+#error KERNEXEC requires pax_close_kernel
77640+#else
77641+static inline unsigned long pax_close_kernel(void) { return 0; }
77642+#endif
77643+#endif
77644+
77645 #endif /* CONFIG_MMU */
77646
77647 #endif /* !__ASSEMBLY__ */
77648diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77649index 72d8803..cb9749c 100644
77650--- a/include/asm-generic/uaccess.h
77651+++ b/include/asm-generic/uaccess.h
77652@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77653 return __clear_user(to, n);
77654 }
77655
77656+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77657+#ifdef CONFIG_PAX_MEMORY_UDEREF
77658+#error UDEREF requires pax_open_userland
77659+#else
77660+static inline unsigned long pax_open_userland(void) { return 0; }
77661+#endif
77662+#endif
77663+
77664+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77665+#ifdef CONFIG_PAX_MEMORY_UDEREF
77666+#error UDEREF requires pax_close_userland
77667+#else
77668+static inline unsigned long pax_close_userland(void) { return 0; }
77669+#endif
77670+#endif
77671+
77672 #endif /* __ASM_GENERIC_UACCESS_H */
77673diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77674index bc2121f..2f41f9a 100644
77675--- a/include/asm-generic/vmlinux.lds.h
77676+++ b/include/asm-generic/vmlinux.lds.h
77677@@ -232,6 +232,7 @@
77678 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77679 VMLINUX_SYMBOL(__start_rodata) = .; \
77680 *(.rodata) *(.rodata.*) \
77681+ *(.data..read_only) \
77682 *(__vermagic) /* Kernel version magic */ \
77683 . = ALIGN(8); \
77684 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77685@@ -716,17 +717,18 @@
77686 * section in the linker script will go there too. @phdr should have
77687 * a leading colon.
77688 *
77689- * Note that this macros defines __per_cpu_load as an absolute symbol.
77690+ * Note that this macros defines per_cpu_load as an absolute symbol.
77691 * If there is no need to put the percpu section at a predetermined
77692 * address, use PERCPU_SECTION.
77693 */
77694 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77695- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77696- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77697+ per_cpu_load = .; \
77698+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77699 - LOAD_OFFSET) { \
77700+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77701 PERCPU_INPUT(cacheline) \
77702 } phdr \
77703- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77704+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77705
77706 /**
77707 * PERCPU_SECTION - define output section for percpu area, simple version
77708diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77709index e73c19e..5b89e00 100644
77710--- a/include/crypto/algapi.h
77711+++ b/include/crypto/algapi.h
77712@@ -34,7 +34,7 @@ struct crypto_type {
77713 unsigned int maskclear;
77714 unsigned int maskset;
77715 unsigned int tfmsize;
77716-};
77717+} __do_const;
77718
77719 struct crypto_instance {
77720 struct crypto_alg alg;
77721diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77722index 04a7f31..668d424 100644
77723--- a/include/drm/drmP.h
77724+++ b/include/drm/drmP.h
77725@@ -67,6 +67,7 @@
77726 #include <linux/workqueue.h>
77727 #include <linux/poll.h>
77728 #include <asm/pgalloc.h>
77729+#include <asm/local.h>
77730 #include <drm/drm.h>
77731 #include <drm/drm_sarea.h>
77732 #include <drm/drm_vma_manager.h>
77733@@ -297,10 +298,12 @@ do { \
77734 * \param cmd command.
77735 * \param arg argument.
77736 */
77737-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77738+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77739+ struct drm_file *file_priv);
77740+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77741 struct drm_file *file_priv);
77742
77743-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77744+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77745 unsigned long arg);
77746
77747 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77748@@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77749 struct drm_ioctl_desc {
77750 unsigned int cmd;
77751 int flags;
77752- drm_ioctl_t *func;
77753+ drm_ioctl_t func;
77754 unsigned int cmd_drv;
77755 const char *name;
77756-};
77757+} __do_const;
77758
77759 /**
77760 * Creates a driver or general drm_ioctl_desc array entry for the given
77761@@ -1022,7 +1025,8 @@ struct drm_info_list {
77762 int (*show)(struct seq_file*, void*); /** show callback */
77763 u32 driver_features; /**< Required driver features for this entry */
77764 void *data;
77765-};
77766+} __do_const;
77767+typedef struct drm_info_list __no_const drm_info_list_no_const;
77768
77769 /**
77770 * debugfs node structure. This structure represents a debugfs file.
77771@@ -1106,7 +1110,7 @@ struct drm_device {
77772
77773 /** \name Usage Counters */
77774 /*@{ */
77775- int open_count; /**< Outstanding files open */
77776+ local_t open_count; /**< Outstanding files open */
77777 int buf_use; /**< Buffers in use -- cannot alloc */
77778 atomic_t buf_alloc; /**< Buffer allocation in progress */
77779 /*@} */
77780diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77781index b1388b5..e1d1163 100644
77782--- a/include/drm/drm_crtc_helper.h
77783+++ b/include/drm/drm_crtc_helper.h
77784@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77785 struct drm_connector *connector);
77786 /* disable encoder when not in use - more explicit than dpms off */
77787 void (*disable)(struct drm_encoder *encoder);
77788-};
77789+} __no_const;
77790
77791 /**
77792 * drm_connector_helper_funcs - helper operations for connectors
77793diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77794index 940ece4..8cb727f 100644
77795--- a/include/drm/i915_pciids.h
77796+++ b/include/drm/i915_pciids.h
77797@@ -37,7 +37,7 @@
77798 */
77799 #define INTEL_VGA_DEVICE(id, info) { \
77800 0x8086, id, \
77801- ~0, ~0, \
77802+ PCI_ANY_ID, PCI_ANY_ID, \
77803 0x030000, 0xff0000, \
77804 (unsigned long) info }
77805
77806diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77807index 72dcbe8..8db58d7 100644
77808--- a/include/drm/ttm/ttm_memory.h
77809+++ b/include/drm/ttm/ttm_memory.h
77810@@ -48,7 +48,7 @@
77811
77812 struct ttm_mem_shrink {
77813 int (*do_shrink) (struct ttm_mem_shrink *);
77814-};
77815+} __no_const;
77816
77817 /**
77818 * struct ttm_mem_global - Global memory accounting structure.
77819diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77820index 49a8284..9643967 100644
77821--- a/include/drm/ttm/ttm_page_alloc.h
77822+++ b/include/drm/ttm/ttm_page_alloc.h
77823@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77824 */
77825 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77826
77827+struct device;
77828 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77829 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77830
77831diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77832index 4b840e8..155d235 100644
77833--- a/include/keys/asymmetric-subtype.h
77834+++ b/include/keys/asymmetric-subtype.h
77835@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77836 /* Verify the signature on a key of this subtype (optional) */
77837 int (*verify_signature)(const struct key *key,
77838 const struct public_key_signature *sig);
77839-};
77840+} __do_const;
77841
77842 /**
77843 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77844diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77845index c1da539..1dcec55 100644
77846--- a/include/linux/atmdev.h
77847+++ b/include/linux/atmdev.h
77848@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77849 #endif
77850
77851 struct k_atm_aal_stats {
77852-#define __HANDLE_ITEM(i) atomic_t i
77853+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77854 __AAL_STAT_ITEMS
77855 #undef __HANDLE_ITEM
77856 };
77857@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77858 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77859 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77860 struct module *owner;
77861-};
77862+} __do_const ;
77863
77864 struct atmphy_ops {
77865 int (*start)(struct atm_dev *dev);
77866diff --git a/include/linux/audit.h b/include/linux/audit.h
77867index ec1464d..833274b 100644
77868--- a/include/linux/audit.h
77869+++ b/include/linux/audit.h
77870@@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
77871 extern unsigned int audit_serial(void);
77872 extern int auditsc_get_stamp(struct audit_context *ctx,
77873 struct timespec *t, unsigned int *serial);
77874-extern int audit_set_loginuid(kuid_t loginuid);
77875+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77876
77877 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77878 {
77879diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77880index b4a745d..e3c0942 100644
77881--- a/include/linux/binfmts.h
77882+++ b/include/linux/binfmts.h
77883@@ -45,7 +45,7 @@ struct linux_binprm {
77884 unsigned interp_data;
77885 unsigned long loader, exec;
77886 char tcomm[TASK_COMM_LEN];
77887-};
77888+} __randomize_layout;
77889
77890 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77891 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77892@@ -74,8 +74,10 @@ struct linux_binfmt {
77893 int (*load_binary)(struct linux_binprm *);
77894 int (*load_shlib)(struct file *);
77895 int (*core_dump)(struct coredump_params *cprm);
77896+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77897+ void (*handle_mmap)(struct file *);
77898 unsigned long min_coredump; /* minimal dump size */
77899-};
77900+} __do_const __randomize_layout;
77901
77902 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77903
77904diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77905index be5fd38..d71192a 100644
77906--- a/include/linux/bitops.h
77907+++ b/include/linux/bitops.h
77908@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77909 * @word: value to rotate
77910 * @shift: bits to roll
77911 */
77912-static inline __u32 rol32(__u32 word, unsigned int shift)
77913+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77914 {
77915 return (word << shift) | (word >> (32 - shift));
77916 }
77917@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77918 * @word: value to rotate
77919 * @shift: bits to roll
77920 */
77921-static inline __u32 ror32(__u32 word, unsigned int shift)
77922+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77923 {
77924 return (word >> shift) | (word << (32 - shift));
77925 }
77926@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77927 return (__s32)(value << shift) >> shift;
77928 }
77929
77930-static inline unsigned fls_long(unsigned long l)
77931+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77932 {
77933 if (sizeof(l) == 4)
77934 return fls(l);
77935diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77936index 4afa4f8..1ed7824 100644
77937--- a/include/linux/blkdev.h
77938+++ b/include/linux/blkdev.h
77939@@ -1572,7 +1572,7 @@ struct block_device_operations {
77940 /* this callback is with swap_lock and sometimes page table lock held */
77941 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77942 struct module *owner;
77943-};
77944+} __do_const;
77945
77946 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77947 unsigned long);
77948diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77949index afc1343..9735539 100644
77950--- a/include/linux/blktrace_api.h
77951+++ b/include/linux/blktrace_api.h
77952@@ -25,7 +25,7 @@ struct blk_trace {
77953 struct dentry *dropped_file;
77954 struct dentry *msg_file;
77955 struct list_head running_list;
77956- atomic_t dropped;
77957+ atomic_unchecked_t dropped;
77958 };
77959
77960 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77961diff --git a/include/linux/cache.h b/include/linux/cache.h
77962index 17e7e82..1d7da26 100644
77963--- a/include/linux/cache.h
77964+++ b/include/linux/cache.h
77965@@ -16,6 +16,14 @@
77966 #define __read_mostly
77967 #endif
77968
77969+#ifndef __read_only
77970+#ifdef CONFIG_PAX_KERNEXEC
77971+#error KERNEXEC requires __read_only
77972+#else
77973+#define __read_only __read_mostly
77974+#endif
77975+#endif
77976+
77977 #ifndef ____cacheline_aligned
77978 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77979 #endif
77980diff --git a/include/linux/capability.h b/include/linux/capability.h
77981index 84b13ad..d7b6550 100644
77982--- a/include/linux/capability.h
77983+++ b/include/linux/capability.h
77984@@ -212,8 +212,13 @@ extern bool capable(int cap);
77985 extern bool ns_capable(struct user_namespace *ns, int cap);
77986 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
77987 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77988+extern bool capable_nolog(int cap);
77989+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77990+extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
77991
77992 /* audit system wants to get cap info from files as well */
77993 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77994
77995+extern int is_privileged_binary(const struct dentry *dentry);
77996+
77997 #endif /* !_LINUX_CAPABILITY_H */
77998diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77999index 8609d57..86e4d79 100644
78000--- a/include/linux/cdrom.h
78001+++ b/include/linux/cdrom.h
78002@@ -87,7 +87,6 @@ struct cdrom_device_ops {
78003
78004 /* driver specifications */
78005 const int capability; /* capability flags */
78006- int n_minors; /* number of active minor devices */
78007 /* handle uniform packets for scsi type devices (scsi,atapi) */
78008 int (*generic_packet) (struct cdrom_device_info *,
78009 struct packet_command *);
78010diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
78011index 4ce9056..86caac6 100644
78012--- a/include/linux/cleancache.h
78013+++ b/include/linux/cleancache.h
78014@@ -31,7 +31,7 @@ struct cleancache_ops {
78015 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
78016 void (*invalidate_inode)(int, struct cleancache_filekey);
78017 void (*invalidate_fs)(int);
78018-};
78019+} __no_const;
78020
78021 extern struct cleancache_ops *
78022 cleancache_register_ops(struct cleancache_ops *ops);
78023diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
78024index 939533d..cf0a57c 100644
78025--- a/include/linux/clk-provider.h
78026+++ b/include/linux/clk-provider.h
78027@@ -166,6 +166,7 @@ struct clk_ops {
78028 unsigned long parent_accuracy);
78029 void (*init)(struct clk_hw *hw);
78030 };
78031+typedef struct clk_ops __no_const clk_ops_no_const;
78032
78033 /**
78034 * struct clk_init_data - holds init data that's common to all clocks and is
78035diff --git a/include/linux/compat.h b/include/linux/compat.h
78036index 3f448c6..df3ce1d 100644
78037--- a/include/linux/compat.h
78038+++ b/include/linux/compat.h
78039@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
78040 compat_size_t __user *len_ptr);
78041
78042 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
78043-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
78044+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
78045 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
78046 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
78047 compat_ssize_t msgsz, int msgflg);
78048@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
78049 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
78050 compat_ulong_t addr, compat_ulong_t data);
78051 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
78052- compat_long_t addr, compat_long_t data);
78053+ compat_ulong_t addr, compat_ulong_t data);
78054
78055 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
78056 /*
78057diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
78058index 2507fd2..55203f8 100644
78059--- a/include/linux/compiler-gcc4.h
78060+++ b/include/linux/compiler-gcc4.h
78061@@ -39,9 +39,34 @@
78062 # define __compiletime_warning(message) __attribute__((warning(message)))
78063 # define __compiletime_error(message) __attribute__((error(message)))
78064 #endif /* __CHECKER__ */
78065+
78066+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
78067+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
78068+#define __bos0(ptr) __bos((ptr), 0)
78069+#define __bos1(ptr) __bos((ptr), 1)
78070 #endif /* GCC_VERSION >= 40300 */
78071
78072 #if GCC_VERSION >= 40500
78073+
78074+#ifdef RANDSTRUCT_PLUGIN
78075+#define __randomize_layout __attribute__((randomize_layout))
78076+#define __no_randomize_layout __attribute__((no_randomize_layout))
78077+#endif
78078+
78079+#ifdef CONSTIFY_PLUGIN
78080+#define __no_const __attribute__((no_const))
78081+#define __do_const __attribute__((do_const))
78082+#endif
78083+
78084+#ifdef SIZE_OVERFLOW_PLUGIN
78085+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
78086+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
78087+#endif
78088+
78089+#ifdef LATENT_ENTROPY_PLUGIN
78090+#define __latent_entropy __attribute__((latent_entropy))
78091+#endif
78092+
78093 /*
78094 * Mark a position in code as unreachable. This can be used to
78095 * suppress control flow warnings after asm blocks that transfer
78096diff --git a/include/linux/compiler.h b/include/linux/compiler.h
78097index 2472740..4857634 100644
78098--- a/include/linux/compiler.h
78099+++ b/include/linux/compiler.h
78100@@ -5,11 +5,14 @@
78101
78102 #ifdef __CHECKER__
78103 # define __user __attribute__((noderef, address_space(1)))
78104+# define __force_user __force __user
78105 # define __kernel __attribute__((address_space(0)))
78106+# define __force_kernel __force __kernel
78107 # define __safe __attribute__((safe))
78108 # define __force __attribute__((force))
78109 # define __nocast __attribute__((nocast))
78110 # define __iomem __attribute__((noderef, address_space(2)))
78111+# define __force_iomem __force __iomem
78112 # define __must_hold(x) __attribute__((context(x,1,1)))
78113 # define __acquires(x) __attribute__((context(x,0,1)))
78114 # define __releases(x) __attribute__((context(x,1,0)))
78115@@ -17,20 +20,37 @@
78116 # define __release(x) __context__(x,-1)
78117 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
78118 # define __percpu __attribute__((noderef, address_space(3)))
78119+# define __force_percpu __force __percpu
78120 #ifdef CONFIG_SPARSE_RCU_POINTER
78121 # define __rcu __attribute__((noderef, address_space(4)))
78122+# define __force_rcu __force __rcu
78123 #else
78124 # define __rcu
78125+# define __force_rcu
78126 #endif
78127 extern void __chk_user_ptr(const volatile void __user *);
78128 extern void __chk_io_ptr(const volatile void __iomem *);
78129 #else
78130-# define __user
78131-# define __kernel
78132+# ifdef CHECKER_PLUGIN
78133+//# define __user
78134+//# define __force_user
78135+//# define __kernel
78136+//# define __force_kernel
78137+# else
78138+# ifdef STRUCTLEAK_PLUGIN
78139+# define __user __attribute__((user))
78140+# else
78141+# define __user
78142+# endif
78143+# define __force_user
78144+# define __kernel
78145+# define __force_kernel
78146+# endif
78147 # define __safe
78148 # define __force
78149 # define __nocast
78150 # define __iomem
78151+# define __force_iomem
78152 # define __chk_user_ptr(x) (void)0
78153 # define __chk_io_ptr(x) (void)0
78154 # define __builtin_warning(x, y...) (1)
78155@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
78156 # define __release(x) (void)0
78157 # define __cond_lock(x,c) (c)
78158 # define __percpu
78159+# define __force_percpu
78160 # define __rcu
78161+# define __force_rcu
78162 #endif
78163
78164 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
78165@@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78166 # define __attribute_const__ /* unimplemented */
78167 #endif
78168
78169+#ifndef __randomize_layout
78170+# define __randomize_layout
78171+#endif
78172+
78173+#ifndef __no_randomize_layout
78174+# define __no_randomize_layout
78175+#endif
78176+
78177+#ifndef __no_const
78178+# define __no_const
78179+#endif
78180+
78181+#ifndef __do_const
78182+# define __do_const
78183+#endif
78184+
78185+#ifndef __size_overflow
78186+# define __size_overflow(...)
78187+#endif
78188+
78189+#ifndef __intentional_overflow
78190+# define __intentional_overflow(...)
78191+#endif
78192+
78193+#ifndef __latent_entropy
78194+# define __latent_entropy
78195+#endif
78196+
78197 /*
78198 * Tell gcc if a function is cold. The compiler will assume any path
78199 * directly leading to the call is unlikely.
78200@@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78201 #define __cold
78202 #endif
78203
78204+#ifndef __alloc_size
78205+#define __alloc_size(...)
78206+#endif
78207+
78208+#ifndef __bos
78209+#define __bos(ptr, arg)
78210+#endif
78211+
78212+#ifndef __bos0
78213+#define __bos0(ptr)
78214+#endif
78215+
78216+#ifndef __bos1
78217+#define __bos1(ptr)
78218+#endif
78219+
78220 /* Simple shorthand for a section definition */
78221 #ifndef __section
78222 # define __section(S) __attribute__ ((__section__(#S)))
78223@@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78224 * use is to mediate communication between process-level code and irq/NMI
78225 * handlers, all running on the same CPU.
78226 */
78227-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
78228+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
78229+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
78230
78231 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
78232 #ifdef CONFIG_KPROBES
78233diff --git a/include/linux/completion.h b/include/linux/completion.h
78234index 5d5aaae..0ea9b84 100644
78235--- a/include/linux/completion.h
78236+++ b/include/linux/completion.h
78237@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
78238
78239 extern void wait_for_completion(struct completion *);
78240 extern void wait_for_completion_io(struct completion *);
78241-extern int wait_for_completion_interruptible(struct completion *x);
78242-extern int wait_for_completion_killable(struct completion *x);
78243+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
78244+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
78245 extern unsigned long wait_for_completion_timeout(struct completion *x,
78246- unsigned long timeout);
78247+ unsigned long timeout) __intentional_overflow(-1);
78248 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
78249- unsigned long timeout);
78250+ unsigned long timeout) __intentional_overflow(-1);
78251 extern long wait_for_completion_interruptible_timeout(
78252- struct completion *x, unsigned long timeout);
78253+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78254 extern long wait_for_completion_killable_timeout(
78255- struct completion *x, unsigned long timeout);
78256+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78257 extern bool try_wait_for_completion(struct completion *x);
78258 extern bool completion_done(struct completion *x);
78259
78260diff --git a/include/linux/configfs.h b/include/linux/configfs.h
78261index 34025df..d94bbbc 100644
78262--- a/include/linux/configfs.h
78263+++ b/include/linux/configfs.h
78264@@ -125,7 +125,7 @@ struct configfs_attribute {
78265 const char *ca_name;
78266 struct module *ca_owner;
78267 umode_t ca_mode;
78268-};
78269+} __do_const;
78270
78271 /*
78272 * Users often need to create attribute structures for their configurable
78273diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
78274index 4d89e0e..5281847 100644
78275--- a/include/linux/cpufreq.h
78276+++ b/include/linux/cpufreq.h
78277@@ -191,6 +191,7 @@ struct global_attr {
78278 ssize_t (*store)(struct kobject *a, struct attribute *b,
78279 const char *c, size_t count);
78280 };
78281+typedef struct global_attr __no_const global_attr_no_const;
78282
78283 #define define_one_global_ro(_name) \
78284 static struct global_attr _name = \
78285@@ -232,7 +233,7 @@ struct cpufreq_driver {
78286 bool boost_supported;
78287 bool boost_enabled;
78288 int (*set_boost) (int state);
78289-};
78290+} __do_const;
78291
78292 /* flags */
78293 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
78294diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
78295index 50fcbb0..9d2dbd9 100644
78296--- a/include/linux/cpuidle.h
78297+++ b/include/linux/cpuidle.h
78298@@ -50,7 +50,8 @@ struct cpuidle_state {
78299 int index);
78300
78301 int (*enter_dead) (struct cpuidle_device *dev, int index);
78302-};
78303+} __do_const;
78304+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
78305
78306 /* Idle State Flags */
78307 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
78308@@ -192,7 +193,7 @@ struct cpuidle_governor {
78309 void (*reflect) (struct cpuidle_device *dev, int index);
78310
78311 struct module *owner;
78312-};
78313+} __do_const;
78314
78315 #ifdef CONFIG_CPU_IDLE
78316 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
78317diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
78318index d08e4d2..95fad61 100644
78319--- a/include/linux/cpumask.h
78320+++ b/include/linux/cpumask.h
78321@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78322 }
78323
78324 /* Valid inputs for n are -1 and 0. */
78325-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78326+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78327 {
78328 return n+1;
78329 }
78330
78331-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78332+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78333 {
78334 return n+1;
78335 }
78336
78337-static inline unsigned int cpumask_next_and(int n,
78338+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
78339 const struct cpumask *srcp,
78340 const struct cpumask *andp)
78341 {
78342@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78343 *
78344 * Returns >= nr_cpu_ids if no further cpus set.
78345 */
78346-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78347+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78348 {
78349 /* -1 is a legal arg here. */
78350 if (n != -1)
78351@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78352 *
78353 * Returns >= nr_cpu_ids if no further cpus unset.
78354 */
78355-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78356+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78357 {
78358 /* -1 is a legal arg here. */
78359 if (n != -1)
78360@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78361 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
78362 }
78363
78364-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
78365+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
78366 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
78367
78368 /**
78369diff --git a/include/linux/cred.h b/include/linux/cred.h
78370index 04421e8..a85afd4 100644
78371--- a/include/linux/cred.h
78372+++ b/include/linux/cred.h
78373@@ -35,7 +35,7 @@ struct group_info {
78374 int nblocks;
78375 kgid_t small_block[NGROUPS_SMALL];
78376 kgid_t *blocks[0];
78377-};
78378+} __randomize_layout;
78379
78380 /**
78381 * get_group_info - Get a reference to a group info structure
78382@@ -136,7 +136,7 @@ struct cred {
78383 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
78384 struct group_info *group_info; /* supplementary groups for euid/fsgid */
78385 struct rcu_head rcu; /* RCU deletion hook */
78386-};
78387+} __randomize_layout;
78388
78389 extern void __put_cred(struct cred *);
78390 extern void exit_creds(struct task_struct *);
78391@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78392 static inline void validate_process_creds(void)
78393 {
78394 }
78395+static inline void validate_task_creds(struct task_struct *task)
78396+{
78397+}
78398 #endif
78399
78400 /**
78401@@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
78402
78403 #define task_uid(task) (task_cred_xxx((task), uid))
78404 #define task_euid(task) (task_cred_xxx((task), euid))
78405+#define task_securebits(task) (task_cred_xxx((task), securebits))
78406
78407 #define current_cred_xxx(xxx) \
78408 ({ \
78409diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78410index b92eadf..b4ecdc1 100644
78411--- a/include/linux/crypto.h
78412+++ b/include/linux/crypto.h
78413@@ -373,7 +373,7 @@ struct cipher_tfm {
78414 const u8 *key, unsigned int keylen);
78415 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78416 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78417-};
78418+} __no_const;
78419
78420 struct hash_tfm {
78421 int (*init)(struct hash_desc *desc);
78422@@ -394,13 +394,13 @@ struct compress_tfm {
78423 int (*cot_decompress)(struct crypto_tfm *tfm,
78424 const u8 *src, unsigned int slen,
78425 u8 *dst, unsigned int *dlen);
78426-};
78427+} __no_const;
78428
78429 struct rng_tfm {
78430 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78431 unsigned int dlen);
78432 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78433-};
78434+} __no_const;
78435
78436 #define crt_ablkcipher crt_u.ablkcipher
78437 #define crt_aead crt_u.aead
78438diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78439index 653589e..4ef254a 100644
78440--- a/include/linux/ctype.h
78441+++ b/include/linux/ctype.h
78442@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78443 * Fast implementation of tolower() for internal usage. Do not use in your
78444 * code.
78445 */
78446-static inline char _tolower(const char c)
78447+static inline unsigned char _tolower(const unsigned char c)
78448 {
78449 return c | 0x20;
78450 }
78451diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78452index bf72e9a..4ca7927 100644
78453--- a/include/linux/dcache.h
78454+++ b/include/linux/dcache.h
78455@@ -133,7 +133,7 @@ struct dentry {
78456 } d_u;
78457 struct list_head d_subdirs; /* our children */
78458 struct hlist_node d_alias; /* inode alias list */
78459-};
78460+} __randomize_layout;
78461
78462 /*
78463 * dentry->d_lock spinlock nesting subclasses:
78464diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78465index 7925bf0..d5143d2 100644
78466--- a/include/linux/decompress/mm.h
78467+++ b/include/linux/decompress/mm.h
78468@@ -77,7 +77,7 @@ static void free(void *where)
78469 * warnings when not needed (indeed large_malloc / large_free are not
78470 * needed by inflate */
78471
78472-#define malloc(a) kmalloc(a, GFP_KERNEL)
78473+#define malloc(a) kmalloc((a), GFP_KERNEL)
78474 #define free(a) kfree(a)
78475
78476 #define large_malloc(a) vmalloc(a)
78477diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78478index d48dc00..211ee54 100644
78479--- a/include/linux/devfreq.h
78480+++ b/include/linux/devfreq.h
78481@@ -114,7 +114,7 @@ struct devfreq_governor {
78482 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78483 int (*event_handler)(struct devfreq *devfreq,
78484 unsigned int event, void *data);
78485-};
78486+} __do_const;
78487
78488 /**
78489 * struct devfreq - Device devfreq structure
78490diff --git a/include/linux/device.h b/include/linux/device.h
78491index 952b010..d5b7691 100644
78492--- a/include/linux/device.h
78493+++ b/include/linux/device.h
78494@@ -310,7 +310,7 @@ struct subsys_interface {
78495 struct list_head node;
78496 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78497 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78498-};
78499+} __do_const;
78500
78501 int subsys_interface_register(struct subsys_interface *sif);
78502 void subsys_interface_unregister(struct subsys_interface *sif);
78503@@ -506,7 +506,7 @@ struct device_type {
78504 void (*release)(struct device *dev);
78505
78506 const struct dev_pm_ops *pm;
78507-};
78508+} __do_const;
78509
78510 /* interface for exporting device attributes */
78511 struct device_attribute {
78512@@ -516,11 +516,12 @@ struct device_attribute {
78513 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78514 const char *buf, size_t count);
78515 };
78516+typedef struct device_attribute __no_const device_attribute_no_const;
78517
78518 struct dev_ext_attribute {
78519 struct device_attribute attr;
78520 void *var;
78521-};
78522+} __do_const;
78523
78524 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78525 char *buf);
78526diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78527index fd4aee2..1f28db9 100644
78528--- a/include/linux/dma-mapping.h
78529+++ b/include/linux/dma-mapping.h
78530@@ -54,7 +54,7 @@ struct dma_map_ops {
78531 u64 (*get_required_mask)(struct device *dev);
78532 #endif
78533 int is_phys;
78534-};
78535+} __do_const;
78536
78537 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78538
78539diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78540index 0a5f552..6661a5a 100644
78541--- a/include/linux/dmaengine.h
78542+++ b/include/linux/dmaengine.h
78543@@ -1151,9 +1151,9 @@ struct dma_pinned_list {
78544 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78545 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78546
78547-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78548+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78549 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78550-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78551+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78552 struct dma_pinned_list *pinned_list, struct page *page,
78553 unsigned int offset, size_t len);
78554
78555diff --git a/include/linux/efi.h b/include/linux/efi.h
78556index 0a819e7..8ed47f1 100644
78557--- a/include/linux/efi.h
78558+++ b/include/linux/efi.h
78559@@ -768,6 +768,7 @@ struct efivar_operations {
78560 efi_set_variable_t *set_variable;
78561 efi_query_variable_store_t *query_variable_store;
78562 };
78563+typedef struct efivar_operations __no_const efivar_operations_no_const;
78564
78565 struct efivars {
78566 /*
78567diff --git a/include/linux/elf.h b/include/linux/elf.h
78568index 67a5fa7..b817372 100644
78569--- a/include/linux/elf.h
78570+++ b/include/linux/elf.h
78571@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78572 #define elf_note elf32_note
78573 #define elf_addr_t Elf32_Off
78574 #define Elf_Half Elf32_Half
78575+#define elf_dyn Elf32_Dyn
78576
78577 #else
78578
78579@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78580 #define elf_note elf64_note
78581 #define elf_addr_t Elf64_Off
78582 #define Elf_Half Elf64_Half
78583+#define elf_dyn Elf64_Dyn
78584
78585 #endif
78586
78587diff --git a/include/linux/err.h b/include/linux/err.h
78588index 15f92e0..e825a8e 100644
78589--- a/include/linux/err.h
78590+++ b/include/linux/err.h
78591@@ -19,12 +19,12 @@
78592
78593 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78594
78595-static inline void * __must_check ERR_PTR(long error)
78596+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78597 {
78598 return (void *) error;
78599 }
78600
78601-static inline long __must_check PTR_ERR(__force const void *ptr)
78602+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78603 {
78604 return (long) ptr;
78605 }
78606diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78607index 21c59af..6057a03 100644
78608--- a/include/linux/extcon.h
78609+++ b/include/linux/extcon.h
78610@@ -135,7 +135,7 @@ struct extcon_dev {
78611 /* /sys/class/extcon/.../mutually_exclusive/... */
78612 struct attribute_group attr_g_muex;
78613 struct attribute **attrs_muex;
78614- struct device_attribute *d_attrs_muex;
78615+ device_attribute_no_const *d_attrs_muex;
78616 };
78617
78618 /**
78619diff --git a/include/linux/fb.h b/include/linux/fb.h
78620index fe6ac95..898d41d 100644
78621--- a/include/linux/fb.h
78622+++ b/include/linux/fb.h
78623@@ -304,7 +304,7 @@ struct fb_ops {
78624 /* called at KDB enter and leave time to prepare the console */
78625 int (*fb_debug_enter)(struct fb_info *info);
78626 int (*fb_debug_leave)(struct fb_info *info);
78627-};
78628+} __do_const;
78629
78630 #ifdef CONFIG_FB_TILEBLITTING
78631 #define FB_TILE_CURSOR_NONE 0
78632diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78633index 70e8e21..1939916 100644
78634--- a/include/linux/fdtable.h
78635+++ b/include/linux/fdtable.h
78636@@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78637 void put_files_struct(struct files_struct *fs);
78638 void reset_files_struct(struct files_struct *);
78639 int unshare_files(struct files_struct **);
78640-struct files_struct *dup_fd(struct files_struct *, int *);
78641+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78642 void do_close_on_exec(struct files_struct *);
78643 int iterate_fd(struct files_struct *, unsigned,
78644 int (*)(const void *, struct file *, unsigned),
78645diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78646index 8293262..2b3b8bd 100644
78647--- a/include/linux/frontswap.h
78648+++ b/include/linux/frontswap.h
78649@@ -11,7 +11,7 @@ struct frontswap_ops {
78650 int (*load)(unsigned, pgoff_t, struct page *);
78651 void (*invalidate_page)(unsigned, pgoff_t);
78652 void (*invalidate_area)(unsigned);
78653-};
78654+} __no_const;
78655
78656 extern bool frontswap_enabled;
78657 extern struct frontswap_ops *
78658diff --git a/include/linux/fs.h b/include/linux/fs.h
78659index 23b2a35..8764ab7 100644
78660--- a/include/linux/fs.h
78661+++ b/include/linux/fs.h
78662@@ -426,7 +426,7 @@ struct address_space {
78663 spinlock_t private_lock; /* for use by the address_space */
78664 struct list_head private_list; /* ditto */
78665 void *private_data; /* ditto */
78666-} __attribute__((aligned(sizeof(long))));
78667+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78668 /*
78669 * On most architectures that alignment is already the case; but
78670 * must be enforced here for CRIS, to let the least significant bit
78671@@ -469,7 +469,7 @@ struct block_device {
78672 int bd_fsfreeze_count;
78673 /* Mutex for freeze */
78674 struct mutex bd_fsfreeze_mutex;
78675-};
78676+} __randomize_layout;
78677
78678 /*
78679 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78680@@ -613,7 +613,7 @@ struct inode {
78681 atomic_t i_readcount; /* struct files open RO */
78682 #endif
78683 void *i_private; /* fs or device private pointer */
78684-};
78685+} __randomize_layout;
78686
78687 static inline int inode_unhashed(struct inode *inode)
78688 {
78689@@ -812,7 +812,7 @@ struct file {
78690 #ifdef CONFIG_DEBUG_WRITECOUNT
78691 unsigned long f_mnt_write_state;
78692 #endif
78693-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78694+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78695
78696 struct file_handle {
78697 __u32 handle_bytes;
78698@@ -982,7 +982,7 @@ struct file_lock {
78699 int state; /* state of grant or error if -ve */
78700 } afs;
78701 } fl_u;
78702-};
78703+} __randomize_layout;
78704
78705 /* The following constant reflects the upper bound of the file/locking space */
78706 #ifndef OFFSET_MAX
78707@@ -1329,7 +1329,7 @@ struct super_block {
78708 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78709 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78710 struct rcu_head rcu;
78711-};
78712+} __randomize_layout;
78713
78714 extern struct timespec current_fs_time(struct super_block *sb);
78715
78716@@ -1551,7 +1551,8 @@ struct file_operations {
78717 long (*fallocate)(struct file *file, int mode, loff_t offset,
78718 loff_t len);
78719 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78720-};
78721+} __do_const __randomize_layout;
78722+typedef struct file_operations __no_const file_operations_no_const;
78723
78724 struct inode_operations {
78725 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78726@@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
78727 return !IS_DEADDIR(inode);
78728 }
78729
78730+static inline bool is_sidechannel_device(const struct inode *inode)
78731+{
78732+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78733+ umode_t mode = inode->i_mode;
78734+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78735+#else
78736+ return false;
78737+#endif
78738+}
78739+
78740 #endif /* _LINUX_FS_H */
78741diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78742index 0efc3e6..fd23610 100644
78743--- a/include/linux/fs_struct.h
78744+++ b/include/linux/fs_struct.h
78745@@ -6,13 +6,13 @@
78746 #include <linux/seqlock.h>
78747
78748 struct fs_struct {
78749- int users;
78750+ atomic_t users;
78751 spinlock_t lock;
78752 seqcount_t seq;
78753 int umask;
78754 int in_exec;
78755 struct path root, pwd;
78756-};
78757+} __randomize_layout;
78758
78759 extern struct kmem_cache *fs_cachep;
78760
78761diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78762index 7714849..a4a5c7a 100644
78763--- a/include/linux/fscache-cache.h
78764+++ b/include/linux/fscache-cache.h
78765@@ -113,7 +113,7 @@ struct fscache_operation {
78766 fscache_operation_release_t release;
78767 };
78768
78769-extern atomic_t fscache_op_debug_id;
78770+extern atomic_unchecked_t fscache_op_debug_id;
78771 extern void fscache_op_work_func(struct work_struct *work);
78772
78773 extern void fscache_enqueue_operation(struct fscache_operation *);
78774@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78775 INIT_WORK(&op->work, fscache_op_work_func);
78776 atomic_set(&op->usage, 1);
78777 op->state = FSCACHE_OP_ST_INITIALISED;
78778- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78779+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78780 op->processor = processor;
78781 op->release = release;
78782 INIT_LIST_HEAD(&op->pend_link);
78783diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78784index 115bb81..e7b812b 100644
78785--- a/include/linux/fscache.h
78786+++ b/include/linux/fscache.h
78787@@ -152,7 +152,7 @@ struct fscache_cookie_def {
78788 * - this is mandatory for any object that may have data
78789 */
78790 void (*now_uncached)(void *cookie_netfs_data);
78791-};
78792+} __do_const;
78793
78794 /*
78795 * fscache cached network filesystem type
78796diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78797index 1c804b0..1432c2b 100644
78798--- a/include/linux/fsnotify.h
78799+++ b/include/linux/fsnotify.h
78800@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78801 struct inode *inode = file_inode(file);
78802 __u32 mask = FS_ACCESS;
78803
78804+ if (is_sidechannel_device(inode))
78805+ return;
78806+
78807 if (S_ISDIR(inode->i_mode))
78808 mask |= FS_ISDIR;
78809
78810@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78811 struct inode *inode = file_inode(file);
78812 __u32 mask = FS_MODIFY;
78813
78814+ if (is_sidechannel_device(inode))
78815+ return;
78816+
78817 if (S_ISDIR(inode->i_mode))
78818 mask |= FS_ISDIR;
78819
78820@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78821 */
78822 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78823 {
78824- return kstrdup(name, GFP_KERNEL);
78825+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78826 }
78827
78828 /*
78829diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78830index 9f3c275..8bdff5d 100644
78831--- a/include/linux/genhd.h
78832+++ b/include/linux/genhd.h
78833@@ -194,7 +194,7 @@ struct gendisk {
78834 struct kobject *slave_dir;
78835
78836 struct timer_rand_state *random;
78837- atomic_t sync_io; /* RAID */
78838+ atomic_unchecked_t sync_io; /* RAID */
78839 struct disk_events *ev;
78840 #ifdef CONFIG_BLK_DEV_INTEGRITY
78841 struct blk_integrity *integrity;
78842@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78843 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78844
78845 /* drivers/char/random.c */
78846-extern void add_disk_randomness(struct gendisk *disk);
78847+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78848 extern void rand_initialize_disk(struct gendisk *disk);
78849
78850 static inline sector_t get_start_sect(struct block_device *bdev)
78851diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78852index c0894dd..2fbf10c 100644
78853--- a/include/linux/genl_magic_func.h
78854+++ b/include/linux/genl_magic_func.h
78855@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78856 },
78857
78858 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78859-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78860+static struct genl_ops ZZZ_genl_ops[] = {
78861 #include GENL_MAGIC_INCLUDE_FILE
78862 };
78863
78864diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78865index 39b81dc..819dc51 100644
78866--- a/include/linux/gfp.h
78867+++ b/include/linux/gfp.h
78868@@ -36,6 +36,13 @@ struct vm_area_struct;
78869 #define ___GFP_NO_KSWAPD 0x400000u
78870 #define ___GFP_OTHER_NODE 0x800000u
78871 #define ___GFP_WRITE 0x1000000u
78872+
78873+#ifdef CONFIG_PAX_USERCOPY_SLABS
78874+#define ___GFP_USERCOPY 0x2000000u
78875+#else
78876+#define ___GFP_USERCOPY 0
78877+#endif
78878+
78879 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78880
78881 /*
78882@@ -93,6 +100,7 @@ struct vm_area_struct;
78883 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78884 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78885 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78886+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78887
78888 /*
78889 * This may seem redundant, but it's a way of annotating false positives vs.
78890@@ -100,7 +108,7 @@ struct vm_area_struct;
78891 */
78892 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78893
78894-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78895+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78896 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78897
78898 /* This equals 0, but use constants in case they ever change */
78899@@ -158,6 +166,8 @@ struct vm_area_struct;
78900 /* 4GB DMA on some platforms */
78901 #define GFP_DMA32 __GFP_DMA32
78902
78903+#define GFP_USERCOPY __GFP_USERCOPY
78904+
78905 /* Convert GFP flags to their corresponding migrate type */
78906 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78907 {
78908diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78909new file mode 100644
78910index 0000000..edb2cb6
78911--- /dev/null
78912+++ b/include/linux/gracl.h
78913@@ -0,0 +1,340 @@
78914+#ifndef GR_ACL_H
78915+#define GR_ACL_H
78916+
78917+#include <linux/grdefs.h>
78918+#include <linux/resource.h>
78919+#include <linux/capability.h>
78920+#include <linux/dcache.h>
78921+#include <asm/resource.h>
78922+
78923+/* Major status information */
78924+
78925+#define GR_VERSION "grsecurity 3.0"
78926+#define GRSECURITY_VERSION 0x3000
78927+
78928+enum {
78929+ GR_SHUTDOWN = 0,
78930+ GR_ENABLE = 1,
78931+ GR_SPROLE = 2,
78932+ GR_OLDRELOAD = 3,
78933+ GR_SEGVMOD = 4,
78934+ GR_STATUS = 5,
78935+ GR_UNSPROLE = 6,
78936+ GR_PASSSET = 7,
78937+ GR_SPROLEPAM = 8,
78938+ GR_RELOAD = 9,
78939+};
78940+
78941+/* Password setup definitions
78942+ * kernel/grhash.c */
78943+enum {
78944+ GR_PW_LEN = 128,
78945+ GR_SALT_LEN = 16,
78946+ GR_SHA_LEN = 32,
78947+};
78948+
78949+enum {
78950+ GR_SPROLE_LEN = 64,
78951+};
78952+
78953+enum {
78954+ GR_NO_GLOB = 0,
78955+ GR_REG_GLOB,
78956+ GR_CREATE_GLOB
78957+};
78958+
78959+#define GR_NLIMITS 32
78960+
78961+/* Begin Data Structures */
78962+
78963+struct sprole_pw {
78964+ unsigned char *rolename;
78965+ unsigned char salt[GR_SALT_LEN];
78966+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78967+};
78968+
78969+struct name_entry {
78970+ __u32 key;
78971+ ino_t inode;
78972+ dev_t device;
78973+ char *name;
78974+ __u16 len;
78975+ __u8 deleted;
78976+ struct name_entry *prev;
78977+ struct name_entry *next;
78978+};
78979+
78980+struct inodev_entry {
78981+ struct name_entry *nentry;
78982+ struct inodev_entry *prev;
78983+ struct inodev_entry *next;
78984+};
78985+
78986+struct acl_role_db {
78987+ struct acl_role_label **r_hash;
78988+ __u32 r_size;
78989+};
78990+
78991+struct inodev_db {
78992+ struct inodev_entry **i_hash;
78993+ __u32 i_size;
78994+};
78995+
78996+struct name_db {
78997+ struct name_entry **n_hash;
78998+ __u32 n_size;
78999+};
79000+
79001+struct crash_uid {
79002+ uid_t uid;
79003+ unsigned long expires;
79004+};
79005+
79006+struct gr_hash_struct {
79007+ void **table;
79008+ void **nametable;
79009+ void *first;
79010+ __u32 table_size;
79011+ __u32 used_size;
79012+ int type;
79013+};
79014+
79015+/* Userspace Grsecurity ACL data structures */
79016+
79017+struct acl_subject_label {
79018+ char *filename;
79019+ ino_t inode;
79020+ dev_t device;
79021+ __u32 mode;
79022+ kernel_cap_t cap_mask;
79023+ kernel_cap_t cap_lower;
79024+ kernel_cap_t cap_invert_audit;
79025+
79026+ struct rlimit res[GR_NLIMITS];
79027+ __u32 resmask;
79028+
79029+ __u8 user_trans_type;
79030+ __u8 group_trans_type;
79031+ uid_t *user_transitions;
79032+ gid_t *group_transitions;
79033+ __u16 user_trans_num;
79034+ __u16 group_trans_num;
79035+
79036+ __u32 sock_families[2];
79037+ __u32 ip_proto[8];
79038+ __u32 ip_type;
79039+ struct acl_ip_label **ips;
79040+ __u32 ip_num;
79041+ __u32 inaddr_any_override;
79042+
79043+ __u32 crashes;
79044+ unsigned long expires;
79045+
79046+ struct acl_subject_label *parent_subject;
79047+ struct gr_hash_struct *hash;
79048+ struct acl_subject_label *prev;
79049+ struct acl_subject_label *next;
79050+
79051+ struct acl_object_label **obj_hash;
79052+ __u32 obj_hash_size;
79053+ __u16 pax_flags;
79054+};
79055+
79056+struct role_allowed_ip {
79057+ __u32 addr;
79058+ __u32 netmask;
79059+
79060+ struct role_allowed_ip *prev;
79061+ struct role_allowed_ip *next;
79062+};
79063+
79064+struct role_transition {
79065+ char *rolename;
79066+
79067+ struct role_transition *prev;
79068+ struct role_transition *next;
79069+};
79070+
79071+struct acl_role_label {
79072+ char *rolename;
79073+ uid_t uidgid;
79074+ __u16 roletype;
79075+
79076+ __u16 auth_attempts;
79077+ unsigned long expires;
79078+
79079+ struct acl_subject_label *root_label;
79080+ struct gr_hash_struct *hash;
79081+
79082+ struct acl_role_label *prev;
79083+ struct acl_role_label *next;
79084+
79085+ struct role_transition *transitions;
79086+ struct role_allowed_ip *allowed_ips;
79087+ uid_t *domain_children;
79088+ __u16 domain_child_num;
79089+
79090+ umode_t umask;
79091+
79092+ struct acl_subject_label **subj_hash;
79093+ __u32 subj_hash_size;
79094+};
79095+
79096+struct user_acl_role_db {
79097+ struct acl_role_label **r_table;
79098+ __u32 num_pointers; /* Number of allocations to track */
79099+ __u32 num_roles; /* Number of roles */
79100+ __u32 num_domain_children; /* Number of domain children */
79101+ __u32 num_subjects; /* Number of subjects */
79102+ __u32 num_objects; /* Number of objects */
79103+};
79104+
79105+struct acl_object_label {
79106+ char *filename;
79107+ ino_t inode;
79108+ dev_t device;
79109+ __u32 mode;
79110+
79111+ struct acl_subject_label *nested;
79112+ struct acl_object_label *globbed;
79113+
79114+ /* next two structures not used */
79115+
79116+ struct acl_object_label *prev;
79117+ struct acl_object_label *next;
79118+};
79119+
79120+struct acl_ip_label {
79121+ char *iface;
79122+ __u32 addr;
79123+ __u32 netmask;
79124+ __u16 low, high;
79125+ __u8 mode;
79126+ __u32 type;
79127+ __u32 proto[8];
79128+
79129+ /* next two structures not used */
79130+
79131+ struct acl_ip_label *prev;
79132+ struct acl_ip_label *next;
79133+};
79134+
79135+struct gr_arg {
79136+ struct user_acl_role_db role_db;
79137+ unsigned char pw[GR_PW_LEN];
79138+ unsigned char salt[GR_SALT_LEN];
79139+ unsigned char sum[GR_SHA_LEN];
79140+ unsigned char sp_role[GR_SPROLE_LEN];
79141+ struct sprole_pw *sprole_pws;
79142+ dev_t segv_device;
79143+ ino_t segv_inode;
79144+ uid_t segv_uid;
79145+ __u16 num_sprole_pws;
79146+ __u16 mode;
79147+};
79148+
79149+struct gr_arg_wrapper {
79150+ struct gr_arg *arg;
79151+ __u32 version;
79152+ __u32 size;
79153+};
79154+
79155+struct subject_map {
79156+ struct acl_subject_label *user;
79157+ struct acl_subject_label *kernel;
79158+ struct subject_map *prev;
79159+ struct subject_map *next;
79160+};
79161+
79162+struct acl_subj_map_db {
79163+ struct subject_map **s_hash;
79164+ __u32 s_size;
79165+};
79166+
79167+struct gr_policy_state {
79168+ struct sprole_pw **acl_special_roles;
79169+ __u16 num_sprole_pws;
79170+ struct acl_role_label *kernel_role;
79171+ struct acl_role_label *role_list;
79172+ struct acl_role_label *default_role;
79173+ struct acl_role_db acl_role_set;
79174+ struct acl_subj_map_db subj_map_set;
79175+ struct name_db name_set;
79176+ struct inodev_db inodev_set;
79177+};
79178+
79179+struct gr_alloc_state {
79180+ unsigned long alloc_stack_next;
79181+ unsigned long alloc_stack_size;
79182+ void **alloc_stack;
79183+};
79184+
79185+struct gr_reload_state {
79186+ struct gr_policy_state oldpolicy;
79187+ struct gr_alloc_state oldalloc;
79188+ struct gr_policy_state newpolicy;
79189+ struct gr_alloc_state newalloc;
79190+ struct gr_policy_state *oldpolicy_ptr;
79191+ struct gr_alloc_state *oldalloc_ptr;
79192+ unsigned char oldmode;
79193+};
79194+
79195+/* End Data Structures Section */
79196+
79197+/* Hash functions generated by empirical testing by Brad Spengler
79198+ Makes good use of the low bits of the inode. Generally 0-1 times
79199+ in loop for successful match. 0-3 for unsuccessful match.
79200+ Shift/add algorithm with modulus of table size and an XOR*/
79201+
79202+static __inline__ unsigned int
79203+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
79204+{
79205+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
79206+}
79207+
79208+ static __inline__ unsigned int
79209+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
79210+{
79211+ return ((const unsigned long)userp % sz);
79212+}
79213+
79214+static __inline__ unsigned int
79215+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
79216+{
79217+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
79218+}
79219+
79220+static __inline__ unsigned int
79221+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
79222+{
79223+ return full_name_hash((const unsigned char *)name, len) % sz;
79224+}
79225+
79226+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
79227+ subj = NULL; \
79228+ iter = 0; \
79229+ while (iter < role->subj_hash_size) { \
79230+ if (subj == NULL) \
79231+ subj = role->subj_hash[iter]; \
79232+ if (subj == NULL) { \
79233+ iter++; \
79234+ continue; \
79235+ }
79236+
79237+#define FOR_EACH_SUBJECT_END(subj,iter) \
79238+ subj = subj->next; \
79239+ if (subj == NULL) \
79240+ iter++; \
79241+ }
79242+
79243+
79244+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
79245+ subj = role->hash->first; \
79246+ while (subj != NULL) {
79247+
79248+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
79249+ subj = subj->next; \
79250+ }
79251+
79252+#endif
79253+
79254diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
79255new file mode 100644
79256index 0000000..33ebd1f
79257--- /dev/null
79258+++ b/include/linux/gracl_compat.h
79259@@ -0,0 +1,156 @@
79260+#ifndef GR_ACL_COMPAT_H
79261+#define GR_ACL_COMPAT_H
79262+
79263+#include <linux/resource.h>
79264+#include <asm/resource.h>
79265+
79266+struct sprole_pw_compat {
79267+ compat_uptr_t rolename;
79268+ unsigned char salt[GR_SALT_LEN];
79269+ unsigned char sum[GR_SHA_LEN];
79270+};
79271+
79272+struct gr_hash_struct_compat {
79273+ compat_uptr_t table;
79274+ compat_uptr_t nametable;
79275+ compat_uptr_t first;
79276+ __u32 table_size;
79277+ __u32 used_size;
79278+ int type;
79279+};
79280+
79281+struct acl_subject_label_compat {
79282+ compat_uptr_t filename;
79283+ compat_ino_t inode;
79284+ __u32 device;
79285+ __u32 mode;
79286+ kernel_cap_t cap_mask;
79287+ kernel_cap_t cap_lower;
79288+ kernel_cap_t cap_invert_audit;
79289+
79290+ struct compat_rlimit res[GR_NLIMITS];
79291+ __u32 resmask;
79292+
79293+ __u8 user_trans_type;
79294+ __u8 group_trans_type;
79295+ compat_uptr_t user_transitions;
79296+ compat_uptr_t group_transitions;
79297+ __u16 user_trans_num;
79298+ __u16 group_trans_num;
79299+
79300+ __u32 sock_families[2];
79301+ __u32 ip_proto[8];
79302+ __u32 ip_type;
79303+ compat_uptr_t ips;
79304+ __u32 ip_num;
79305+ __u32 inaddr_any_override;
79306+
79307+ __u32 crashes;
79308+ compat_ulong_t expires;
79309+
79310+ compat_uptr_t parent_subject;
79311+ compat_uptr_t hash;
79312+ compat_uptr_t prev;
79313+ compat_uptr_t next;
79314+
79315+ compat_uptr_t obj_hash;
79316+ __u32 obj_hash_size;
79317+ __u16 pax_flags;
79318+};
79319+
79320+struct role_allowed_ip_compat {
79321+ __u32 addr;
79322+ __u32 netmask;
79323+
79324+ compat_uptr_t prev;
79325+ compat_uptr_t next;
79326+};
79327+
79328+struct role_transition_compat {
79329+ compat_uptr_t rolename;
79330+
79331+ compat_uptr_t prev;
79332+ compat_uptr_t next;
79333+};
79334+
79335+struct acl_role_label_compat {
79336+ compat_uptr_t rolename;
79337+ uid_t uidgid;
79338+ __u16 roletype;
79339+
79340+ __u16 auth_attempts;
79341+ compat_ulong_t expires;
79342+
79343+ compat_uptr_t root_label;
79344+ compat_uptr_t hash;
79345+
79346+ compat_uptr_t prev;
79347+ compat_uptr_t next;
79348+
79349+ compat_uptr_t transitions;
79350+ compat_uptr_t allowed_ips;
79351+ compat_uptr_t domain_children;
79352+ __u16 domain_child_num;
79353+
79354+ umode_t umask;
79355+
79356+ compat_uptr_t subj_hash;
79357+ __u32 subj_hash_size;
79358+};
79359+
79360+struct user_acl_role_db_compat {
79361+ compat_uptr_t r_table;
79362+ __u32 num_pointers;
79363+ __u32 num_roles;
79364+ __u32 num_domain_children;
79365+ __u32 num_subjects;
79366+ __u32 num_objects;
79367+};
79368+
79369+struct acl_object_label_compat {
79370+ compat_uptr_t filename;
79371+ compat_ino_t inode;
79372+ __u32 device;
79373+ __u32 mode;
79374+
79375+ compat_uptr_t nested;
79376+ compat_uptr_t globbed;
79377+
79378+ compat_uptr_t prev;
79379+ compat_uptr_t next;
79380+};
79381+
79382+struct acl_ip_label_compat {
79383+ compat_uptr_t iface;
79384+ __u32 addr;
79385+ __u32 netmask;
79386+ __u16 low, high;
79387+ __u8 mode;
79388+ __u32 type;
79389+ __u32 proto[8];
79390+
79391+ compat_uptr_t prev;
79392+ compat_uptr_t next;
79393+};
79394+
79395+struct gr_arg_compat {
79396+ struct user_acl_role_db_compat role_db;
79397+ unsigned char pw[GR_PW_LEN];
79398+ unsigned char salt[GR_SALT_LEN];
79399+ unsigned char sum[GR_SHA_LEN];
79400+ unsigned char sp_role[GR_SPROLE_LEN];
79401+ compat_uptr_t sprole_pws;
79402+ __u32 segv_device;
79403+ compat_ino_t segv_inode;
79404+ uid_t segv_uid;
79405+ __u16 num_sprole_pws;
79406+ __u16 mode;
79407+};
79408+
79409+struct gr_arg_wrapper_compat {
79410+ compat_uptr_t arg;
79411+ __u32 version;
79412+ __u32 size;
79413+};
79414+
79415+#endif
79416diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79417new file mode 100644
79418index 0000000..323ecf2
79419--- /dev/null
79420+++ b/include/linux/gralloc.h
79421@@ -0,0 +1,9 @@
79422+#ifndef __GRALLOC_H
79423+#define __GRALLOC_H
79424+
79425+void acl_free_all(void);
79426+int acl_alloc_stack_init(unsigned long size);
79427+void *acl_alloc(unsigned long len);
79428+void *acl_alloc_num(unsigned long num, unsigned long len);
79429+
79430+#endif
79431diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79432new file mode 100644
79433index 0000000..be66033
79434--- /dev/null
79435+++ b/include/linux/grdefs.h
79436@@ -0,0 +1,140 @@
79437+#ifndef GRDEFS_H
79438+#define GRDEFS_H
79439+
79440+/* Begin grsecurity status declarations */
79441+
79442+enum {
79443+ GR_READY = 0x01,
79444+ GR_STATUS_INIT = 0x00 // disabled state
79445+};
79446+
79447+/* Begin ACL declarations */
79448+
79449+/* Role flags */
79450+
79451+enum {
79452+ GR_ROLE_USER = 0x0001,
79453+ GR_ROLE_GROUP = 0x0002,
79454+ GR_ROLE_DEFAULT = 0x0004,
79455+ GR_ROLE_SPECIAL = 0x0008,
79456+ GR_ROLE_AUTH = 0x0010,
79457+ GR_ROLE_NOPW = 0x0020,
79458+ GR_ROLE_GOD = 0x0040,
79459+ GR_ROLE_LEARN = 0x0080,
79460+ GR_ROLE_TPE = 0x0100,
79461+ GR_ROLE_DOMAIN = 0x0200,
79462+ GR_ROLE_PAM = 0x0400,
79463+ GR_ROLE_PERSIST = 0x0800
79464+};
79465+
79466+/* ACL Subject and Object mode flags */
79467+enum {
79468+ GR_DELETED = 0x80000000
79469+};
79470+
79471+/* ACL Object-only mode flags */
79472+enum {
79473+ GR_READ = 0x00000001,
79474+ GR_APPEND = 0x00000002,
79475+ GR_WRITE = 0x00000004,
79476+ GR_EXEC = 0x00000008,
79477+ GR_FIND = 0x00000010,
79478+ GR_INHERIT = 0x00000020,
79479+ GR_SETID = 0x00000040,
79480+ GR_CREATE = 0x00000080,
79481+ GR_DELETE = 0x00000100,
79482+ GR_LINK = 0x00000200,
79483+ GR_AUDIT_READ = 0x00000400,
79484+ GR_AUDIT_APPEND = 0x00000800,
79485+ GR_AUDIT_WRITE = 0x00001000,
79486+ GR_AUDIT_EXEC = 0x00002000,
79487+ GR_AUDIT_FIND = 0x00004000,
79488+ GR_AUDIT_INHERIT= 0x00008000,
79489+ GR_AUDIT_SETID = 0x00010000,
79490+ GR_AUDIT_CREATE = 0x00020000,
79491+ GR_AUDIT_DELETE = 0x00040000,
79492+ GR_AUDIT_LINK = 0x00080000,
79493+ GR_PTRACERD = 0x00100000,
79494+ GR_NOPTRACE = 0x00200000,
79495+ GR_SUPPRESS = 0x00400000,
79496+ GR_NOLEARN = 0x00800000,
79497+ GR_INIT_TRANSFER= 0x01000000
79498+};
79499+
79500+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79501+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79502+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79503+
79504+/* ACL subject-only mode flags */
79505+enum {
79506+ GR_KILL = 0x00000001,
79507+ GR_VIEW = 0x00000002,
79508+ GR_PROTECTED = 0x00000004,
79509+ GR_LEARN = 0x00000008,
79510+ GR_OVERRIDE = 0x00000010,
79511+ /* just a placeholder, this mode is only used in userspace */
79512+ GR_DUMMY = 0x00000020,
79513+ GR_PROTSHM = 0x00000040,
79514+ GR_KILLPROC = 0x00000080,
79515+ GR_KILLIPPROC = 0x00000100,
79516+ /* just a placeholder, this mode is only used in userspace */
79517+ GR_NOTROJAN = 0x00000200,
79518+ GR_PROTPROCFD = 0x00000400,
79519+ GR_PROCACCT = 0x00000800,
79520+ GR_RELAXPTRACE = 0x00001000,
79521+ //GR_NESTED = 0x00002000,
79522+ GR_INHERITLEARN = 0x00004000,
79523+ GR_PROCFIND = 0x00008000,
79524+ GR_POVERRIDE = 0x00010000,
79525+ GR_KERNELAUTH = 0x00020000,
79526+ GR_ATSECURE = 0x00040000,
79527+ GR_SHMEXEC = 0x00080000
79528+};
79529+
79530+enum {
79531+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79532+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79533+ GR_PAX_ENABLE_MPROTECT = 0x0004,
79534+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
79535+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79536+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79537+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79538+ GR_PAX_DISABLE_MPROTECT = 0x0400,
79539+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
79540+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79541+};
79542+
79543+enum {
79544+ GR_ID_USER = 0x01,
79545+ GR_ID_GROUP = 0x02,
79546+};
79547+
79548+enum {
79549+ GR_ID_ALLOW = 0x01,
79550+ GR_ID_DENY = 0x02,
79551+};
79552+
79553+#define GR_CRASH_RES 31
79554+#define GR_UIDTABLE_MAX 500
79555+
79556+/* begin resource learning section */
79557+enum {
79558+ GR_RLIM_CPU_BUMP = 60,
79559+ GR_RLIM_FSIZE_BUMP = 50000,
79560+ GR_RLIM_DATA_BUMP = 10000,
79561+ GR_RLIM_STACK_BUMP = 1000,
79562+ GR_RLIM_CORE_BUMP = 10000,
79563+ GR_RLIM_RSS_BUMP = 500000,
79564+ GR_RLIM_NPROC_BUMP = 1,
79565+ GR_RLIM_NOFILE_BUMP = 5,
79566+ GR_RLIM_MEMLOCK_BUMP = 50000,
79567+ GR_RLIM_AS_BUMP = 500000,
79568+ GR_RLIM_LOCKS_BUMP = 2,
79569+ GR_RLIM_SIGPENDING_BUMP = 5,
79570+ GR_RLIM_MSGQUEUE_BUMP = 10000,
79571+ GR_RLIM_NICE_BUMP = 1,
79572+ GR_RLIM_RTPRIO_BUMP = 1,
79573+ GR_RLIM_RTTIME_BUMP = 1000000
79574+};
79575+
79576+#endif
79577diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79578new file mode 100644
79579index 0000000..d25522e
79580--- /dev/null
79581+++ b/include/linux/grinternal.h
79582@@ -0,0 +1,229 @@
79583+#ifndef __GRINTERNAL_H
79584+#define __GRINTERNAL_H
79585+
79586+#ifdef CONFIG_GRKERNSEC
79587+
79588+#include <linux/fs.h>
79589+#include <linux/mnt_namespace.h>
79590+#include <linux/nsproxy.h>
79591+#include <linux/gracl.h>
79592+#include <linux/grdefs.h>
79593+#include <linux/grmsg.h>
79594+
79595+void gr_add_learn_entry(const char *fmt, ...)
79596+ __attribute__ ((format (printf, 1, 2)));
79597+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79598+ const struct vfsmount *mnt);
79599+__u32 gr_check_create(const struct dentry *new_dentry,
79600+ const struct dentry *parent,
79601+ const struct vfsmount *mnt, const __u32 mode);
79602+int gr_check_protected_task(const struct task_struct *task);
79603+__u32 to_gr_audit(const __u32 reqmode);
79604+int gr_set_acls(const int type);
79605+int gr_acl_is_enabled(void);
79606+char gr_roletype_to_char(void);
79607+
79608+void gr_handle_alertkill(struct task_struct *task);
79609+char *gr_to_filename(const struct dentry *dentry,
79610+ const struct vfsmount *mnt);
79611+char *gr_to_filename1(const struct dentry *dentry,
79612+ const struct vfsmount *mnt);
79613+char *gr_to_filename2(const struct dentry *dentry,
79614+ const struct vfsmount *mnt);
79615+char *gr_to_filename3(const struct dentry *dentry,
79616+ const struct vfsmount *mnt);
79617+
79618+extern int grsec_enable_ptrace_readexec;
79619+extern int grsec_enable_harden_ptrace;
79620+extern int grsec_enable_link;
79621+extern int grsec_enable_fifo;
79622+extern int grsec_enable_execve;
79623+extern int grsec_enable_shm;
79624+extern int grsec_enable_execlog;
79625+extern int grsec_enable_signal;
79626+extern int grsec_enable_audit_ptrace;
79627+extern int grsec_enable_forkfail;
79628+extern int grsec_enable_time;
79629+extern int grsec_enable_rofs;
79630+extern int grsec_deny_new_usb;
79631+extern int grsec_enable_chroot_shmat;
79632+extern int grsec_enable_chroot_mount;
79633+extern int grsec_enable_chroot_double;
79634+extern int grsec_enable_chroot_pivot;
79635+extern int grsec_enable_chroot_chdir;
79636+extern int grsec_enable_chroot_chmod;
79637+extern int grsec_enable_chroot_mknod;
79638+extern int grsec_enable_chroot_fchdir;
79639+extern int grsec_enable_chroot_nice;
79640+extern int grsec_enable_chroot_execlog;
79641+extern int grsec_enable_chroot_caps;
79642+extern int grsec_enable_chroot_sysctl;
79643+extern int grsec_enable_chroot_unix;
79644+extern int grsec_enable_symlinkown;
79645+extern kgid_t grsec_symlinkown_gid;
79646+extern int grsec_enable_tpe;
79647+extern kgid_t grsec_tpe_gid;
79648+extern int grsec_enable_tpe_all;
79649+extern int grsec_enable_tpe_invert;
79650+extern int grsec_enable_socket_all;
79651+extern kgid_t grsec_socket_all_gid;
79652+extern int grsec_enable_socket_client;
79653+extern kgid_t grsec_socket_client_gid;
79654+extern int grsec_enable_socket_server;
79655+extern kgid_t grsec_socket_server_gid;
79656+extern kgid_t grsec_audit_gid;
79657+extern int grsec_enable_group;
79658+extern int grsec_enable_log_rwxmaps;
79659+extern int grsec_enable_mount;
79660+extern int grsec_enable_chdir;
79661+extern int grsec_resource_logging;
79662+extern int grsec_enable_blackhole;
79663+extern int grsec_lastack_retries;
79664+extern int grsec_enable_brute;
79665+extern int grsec_enable_harden_ipc;
79666+extern int grsec_lock;
79667+
79668+extern spinlock_t grsec_alert_lock;
79669+extern unsigned long grsec_alert_wtime;
79670+extern unsigned long grsec_alert_fyet;
79671+
79672+extern spinlock_t grsec_audit_lock;
79673+
79674+extern rwlock_t grsec_exec_file_lock;
79675+
79676+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79677+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79678+ (tsk)->exec_file->f_path.mnt) : "/")
79679+
79680+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79681+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79682+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79683+
79684+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79685+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
79686+ (tsk)->exec_file->f_path.mnt) : "/")
79687+
79688+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79689+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79690+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79691+
79692+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79693+
79694+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79695+
79696+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79697+{
79698+ if (file1 && file2) {
79699+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
79700+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
79701+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79702+ return true;
79703+ }
79704+
79705+ return false;
79706+}
79707+
79708+#define GR_CHROOT_CAPS {{ \
79709+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79710+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79711+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79712+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79713+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79714+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79715+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79716+
79717+#define security_learn(normal_msg,args...) \
79718+({ \
79719+ read_lock(&grsec_exec_file_lock); \
79720+ gr_add_learn_entry(normal_msg "\n", ## args); \
79721+ read_unlock(&grsec_exec_file_lock); \
79722+})
79723+
79724+enum {
79725+ GR_DO_AUDIT,
79726+ GR_DONT_AUDIT,
79727+ /* used for non-audit messages that we shouldn't kill the task on */
79728+ GR_DONT_AUDIT_GOOD
79729+};
79730+
79731+enum {
79732+ GR_TTYSNIFF,
79733+ GR_RBAC,
79734+ GR_RBAC_STR,
79735+ GR_STR_RBAC,
79736+ GR_RBAC_MODE2,
79737+ GR_RBAC_MODE3,
79738+ GR_FILENAME,
79739+ GR_SYSCTL_HIDDEN,
79740+ GR_NOARGS,
79741+ GR_ONE_INT,
79742+ GR_ONE_INT_TWO_STR,
79743+ GR_ONE_STR,
79744+ GR_STR_INT,
79745+ GR_TWO_STR_INT,
79746+ GR_TWO_INT,
79747+ GR_TWO_U64,
79748+ GR_THREE_INT,
79749+ GR_FIVE_INT_TWO_STR,
79750+ GR_TWO_STR,
79751+ GR_THREE_STR,
79752+ GR_FOUR_STR,
79753+ GR_STR_FILENAME,
79754+ GR_FILENAME_STR,
79755+ GR_FILENAME_TWO_INT,
79756+ GR_FILENAME_TWO_INT_STR,
79757+ GR_TEXTREL,
79758+ GR_PTRACE,
79759+ GR_RESOURCE,
79760+ GR_CAP,
79761+ GR_SIG,
79762+ GR_SIG2,
79763+ GR_CRASH1,
79764+ GR_CRASH2,
79765+ GR_PSACCT,
79766+ GR_RWXMAP,
79767+ GR_RWXMAPVMA
79768+};
79769+
79770+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79771+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79772+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79773+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79774+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79775+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79776+#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)
79777+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79778+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79779+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79780+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79781+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79782+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79783+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79784+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79785+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79786+#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)
79787+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79788+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79789+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79790+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79791+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79792+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79793+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79794+#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)
79795+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79796+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79797+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79798+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79799+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79800+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79801+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79802+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79803+#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)
79804+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79805+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79806+
79807+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79808+
79809+#endif
79810+
79811+#endif
79812diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79813new file mode 100644
79814index 0000000..b02ba9d
79815--- /dev/null
79816+++ b/include/linux/grmsg.h
79817@@ -0,0 +1,117 @@
79818+#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"
79819+#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"
79820+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79821+#define GR_STOPMOD_MSG "denied modification of module state by "
79822+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79823+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79824+#define GR_IOPERM_MSG "denied use of ioperm() by "
79825+#define GR_IOPL_MSG "denied use of iopl() by "
79826+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79827+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79828+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79829+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79830+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79831+#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"
79832+#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"
79833+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79834+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79835+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79836+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79837+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79838+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79839+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79840+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79841+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79842+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79843+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79844+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79845+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79846+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79847+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79848+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79849+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79850+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79851+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79852+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79853+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79854+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79855+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79856+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79857+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79858+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79859+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79860+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79861+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79862+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79863+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79864+#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
79865+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79866+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79867+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79868+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79869+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79870+#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"
79871+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79872+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79873+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79874+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79875+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79876+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79877+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79878+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79879+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79880+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79881+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79882+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79883+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79884+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79885+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79886+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79887+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79888+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79889+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79890+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79891+#define GR_FAILFORK_MSG "failed fork with errno %s by "
79892+#define GR_NICE_CHROOT_MSG "denied priority change by "
79893+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79894+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79895+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79896+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79897+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79898+#define GR_TIME_MSG "time set by "
79899+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79900+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79901+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79902+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79903+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79904+#define GR_BIND_MSG "denied bind() by "
79905+#define GR_CONNECT_MSG "denied connect() by "
79906+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79907+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79908+#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"
79909+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79910+#define GR_CAP_ACL_MSG "use of %s denied for "
79911+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79912+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79913+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79914+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79915+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79916+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79917+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79918+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79919+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79920+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79921+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79922+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79923+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79924+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79925+#define GR_VM86_MSG "denied use of vm86 by "
79926+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79927+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79928+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79929+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79930+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79931+#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 "
79932+#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 "
79933+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79934+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79935diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79936new file mode 100644
79937index 0000000..5c4bdee
79938--- /dev/null
79939+++ b/include/linux/grsecurity.h
79940@@ -0,0 +1,249 @@
79941+#ifndef GR_SECURITY_H
79942+#define GR_SECURITY_H
79943+#include <linux/fs.h>
79944+#include <linux/fs_struct.h>
79945+#include <linux/binfmts.h>
79946+#include <linux/gracl.h>
79947+
79948+/* notify of brain-dead configs */
79949+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79950+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79951+#endif
79952+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79953+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79954+#endif
79955+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79956+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79957+#endif
79958+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79959+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79960+#endif
79961+
79962+int gr_handle_new_usb(void);
79963+
79964+void gr_handle_brute_attach(int dumpable);
79965+void gr_handle_brute_check(void);
79966+void gr_handle_kernel_exploit(void);
79967+
79968+char gr_roletype_to_char(void);
79969+
79970+int gr_proc_is_restricted(void);
79971+
79972+int gr_acl_enable_at_secure(void);
79973+
79974+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79975+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79976+
79977+void gr_del_task_from_ip_table(struct task_struct *p);
79978+
79979+int gr_pid_is_chrooted(struct task_struct *p);
79980+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79981+int gr_handle_chroot_nice(void);
79982+int gr_handle_chroot_sysctl(const int op);
79983+int gr_handle_chroot_setpriority(struct task_struct *p,
79984+ const int niceval);
79985+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79986+int gr_chroot_fhandle(void);
79987+int gr_handle_chroot_chroot(const struct dentry *dentry,
79988+ const struct vfsmount *mnt);
79989+void gr_handle_chroot_chdir(const struct path *path);
79990+int gr_handle_chroot_chmod(const struct dentry *dentry,
79991+ const struct vfsmount *mnt, const int mode);
79992+int gr_handle_chroot_mknod(const struct dentry *dentry,
79993+ const struct vfsmount *mnt, const int mode);
79994+int gr_handle_chroot_mount(const struct dentry *dentry,
79995+ const struct vfsmount *mnt,
79996+ const char *dev_name);
79997+int gr_handle_chroot_pivot(void);
79998+int gr_handle_chroot_unix(const pid_t pid);
79999+
80000+int gr_handle_rawio(const struct inode *inode);
80001+
80002+void gr_handle_ioperm(void);
80003+void gr_handle_iopl(void);
80004+void gr_handle_msr_write(void);
80005+
80006+umode_t gr_acl_umask(void);
80007+
80008+int gr_tpe_allow(const struct file *file);
80009+
80010+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
80011+void gr_clear_chroot_entries(struct task_struct *task);
80012+
80013+void gr_log_forkfail(const int retval);
80014+void gr_log_timechange(void);
80015+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
80016+void gr_log_chdir(const struct dentry *dentry,
80017+ const struct vfsmount *mnt);
80018+void gr_log_chroot_exec(const struct dentry *dentry,
80019+ const struct vfsmount *mnt);
80020+void gr_log_remount(const char *devname, const int retval);
80021+void gr_log_unmount(const char *devname, const int retval);
80022+void gr_log_mount(const char *from, const char *to, const int retval);
80023+void gr_log_textrel(struct vm_area_struct *vma);
80024+void gr_log_ptgnustack(struct file *file);
80025+void gr_log_rwxmmap(struct file *file);
80026+void gr_log_rwxmprotect(struct vm_area_struct *vma);
80027+
80028+int gr_handle_follow_link(const struct inode *parent,
80029+ const struct inode *inode,
80030+ const struct dentry *dentry,
80031+ const struct vfsmount *mnt);
80032+int gr_handle_fifo(const struct dentry *dentry,
80033+ const struct vfsmount *mnt,
80034+ const struct dentry *dir, const int flag,
80035+ const int acc_mode);
80036+int gr_handle_hardlink(const struct dentry *dentry,
80037+ const struct vfsmount *mnt,
80038+ struct inode *inode,
80039+ const int mode, const struct filename *to);
80040+
80041+int gr_is_capable(const int cap);
80042+int gr_is_capable_nolog(const int cap);
80043+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
80044+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
80045+
80046+void gr_copy_label(struct task_struct *tsk);
80047+void gr_handle_crash(struct task_struct *task, const int sig);
80048+int gr_handle_signal(const struct task_struct *p, const int sig);
80049+int gr_check_crash_uid(const kuid_t uid);
80050+int gr_check_protected_task(const struct task_struct *task);
80051+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
80052+int gr_acl_handle_mmap(const struct file *file,
80053+ const unsigned long prot);
80054+int gr_acl_handle_mprotect(const struct file *file,
80055+ const unsigned long prot);
80056+int gr_check_hidden_task(const struct task_struct *tsk);
80057+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
80058+ const struct vfsmount *mnt);
80059+__u32 gr_acl_handle_utime(const struct dentry *dentry,
80060+ const struct vfsmount *mnt);
80061+__u32 gr_acl_handle_access(const struct dentry *dentry,
80062+ const struct vfsmount *mnt, const int fmode);
80063+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
80064+ const struct vfsmount *mnt, umode_t *mode);
80065+__u32 gr_acl_handle_chown(const struct dentry *dentry,
80066+ const struct vfsmount *mnt);
80067+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
80068+ const struct vfsmount *mnt);
80069+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
80070+ const struct vfsmount *mnt);
80071+int gr_handle_ptrace(struct task_struct *task, const long request);
80072+int gr_handle_proc_ptrace(struct task_struct *task);
80073+__u32 gr_acl_handle_execve(const struct dentry *dentry,
80074+ const struct vfsmount *mnt);
80075+int gr_check_crash_exec(const struct file *filp);
80076+int gr_acl_is_enabled(void);
80077+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
80078+ const kgid_t gid);
80079+int gr_set_proc_label(const struct dentry *dentry,
80080+ const struct vfsmount *mnt,
80081+ const int unsafe_flags);
80082+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
80083+ const struct vfsmount *mnt);
80084+__u32 gr_acl_handle_open(const struct dentry *dentry,
80085+ const struct vfsmount *mnt, int acc_mode);
80086+__u32 gr_acl_handle_creat(const struct dentry *dentry,
80087+ const struct dentry *p_dentry,
80088+ const struct vfsmount *p_mnt,
80089+ int open_flags, int acc_mode, const int imode);
80090+void gr_handle_create(const struct dentry *dentry,
80091+ const struct vfsmount *mnt);
80092+void gr_handle_proc_create(const struct dentry *dentry,
80093+ const struct inode *inode);
80094+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
80095+ const struct dentry *parent_dentry,
80096+ const struct vfsmount *parent_mnt,
80097+ const int mode);
80098+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
80099+ const struct dentry *parent_dentry,
80100+ const struct vfsmount *parent_mnt);
80101+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
80102+ const struct vfsmount *mnt);
80103+void gr_handle_delete(const ino_t ino, const dev_t dev);
80104+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
80105+ const struct vfsmount *mnt);
80106+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
80107+ const struct dentry *parent_dentry,
80108+ const struct vfsmount *parent_mnt,
80109+ const struct filename *from);
80110+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
80111+ const struct dentry *parent_dentry,
80112+ const struct vfsmount *parent_mnt,
80113+ const struct dentry *old_dentry,
80114+ const struct vfsmount *old_mnt, const struct filename *to);
80115+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
80116+int gr_acl_handle_rename(struct dentry *new_dentry,
80117+ struct dentry *parent_dentry,
80118+ const struct vfsmount *parent_mnt,
80119+ struct dentry *old_dentry,
80120+ struct inode *old_parent_inode,
80121+ struct vfsmount *old_mnt, const struct filename *newname);
80122+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
80123+ struct dentry *old_dentry,
80124+ struct dentry *new_dentry,
80125+ struct vfsmount *mnt, const __u8 replace);
80126+__u32 gr_check_link(const struct dentry *new_dentry,
80127+ const struct dentry *parent_dentry,
80128+ const struct vfsmount *parent_mnt,
80129+ const struct dentry *old_dentry,
80130+ const struct vfsmount *old_mnt);
80131+int gr_acl_handle_filldir(const struct file *file, const char *name,
80132+ const unsigned int namelen, const ino_t ino);
80133+
80134+__u32 gr_acl_handle_unix(const struct dentry *dentry,
80135+ const struct vfsmount *mnt);
80136+void gr_acl_handle_exit(void);
80137+void gr_acl_handle_psacct(struct task_struct *task, const long code);
80138+int gr_acl_handle_procpidmem(const struct task_struct *task);
80139+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
80140+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
80141+void gr_audit_ptrace(struct task_struct *task);
80142+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
80143+void gr_put_exec_file(struct task_struct *task);
80144+
80145+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
80146+
80147+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
80148+extern void gr_learn_resource(const struct task_struct *task, const int res,
80149+ const unsigned long wanted, const int gt);
80150+#else
80151+static inline void gr_learn_resource(const struct task_struct *task, const int res,
80152+ const unsigned long wanted, const int gt)
80153+{
80154+}
80155+#endif
80156+
80157+#ifdef CONFIG_GRKERNSEC_RESLOG
80158+extern void gr_log_resource(const struct task_struct *task, const int res,
80159+ const unsigned long wanted, const int gt);
80160+#else
80161+static inline void gr_log_resource(const struct task_struct *task, const int res,
80162+ const unsigned long wanted, const int gt)
80163+{
80164+}
80165+#endif
80166+
80167+#ifdef CONFIG_GRKERNSEC
80168+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
80169+void gr_handle_vm86(void);
80170+void gr_handle_mem_readwrite(u64 from, u64 to);
80171+
80172+void gr_log_badprocpid(const char *entry);
80173+
80174+extern int grsec_enable_dmesg;
80175+extern int grsec_disable_privio;
80176+
80177+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80178+extern kgid_t grsec_proc_gid;
80179+#endif
80180+
80181+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
80182+extern int grsec_enable_chroot_findtask;
80183+#endif
80184+#ifdef CONFIG_GRKERNSEC_SETXID
80185+extern int grsec_enable_setxid;
80186+#endif
80187+#endif
80188+
80189+#endif
80190diff --git a/include/linux/grsock.h b/include/linux/grsock.h
80191new file mode 100644
80192index 0000000..e7ffaaf
80193--- /dev/null
80194+++ b/include/linux/grsock.h
80195@@ -0,0 +1,19 @@
80196+#ifndef __GRSOCK_H
80197+#define __GRSOCK_H
80198+
80199+extern void gr_attach_curr_ip(const struct sock *sk);
80200+extern int gr_handle_sock_all(const int family, const int type,
80201+ const int protocol);
80202+extern int gr_handle_sock_server(const struct sockaddr *sck);
80203+extern int gr_handle_sock_server_other(const struct sock *sck);
80204+extern int gr_handle_sock_client(const struct sockaddr *sck);
80205+extern int gr_search_connect(struct socket * sock,
80206+ struct sockaddr_in * addr);
80207+extern int gr_search_bind(struct socket * sock,
80208+ struct sockaddr_in * addr);
80209+extern int gr_search_listen(struct socket * sock);
80210+extern int gr_search_accept(struct socket * sock);
80211+extern int gr_search_socket(const int domain, const int type,
80212+ const int protocol);
80213+
80214+#endif
80215diff --git a/include/linux/hash.h b/include/linux/hash.h
80216index bd1754c..8240892 100644
80217--- a/include/linux/hash.h
80218+++ b/include/linux/hash.h
80219@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
80220 struct fast_hash_ops {
80221 u32 (*hash)(const void *data, u32 len, u32 seed);
80222 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
80223-};
80224+} __no_const;
80225
80226 /**
80227 * arch_fast_hash - Caclulates a hash over a given buffer that can have
80228diff --git a/include/linux/highmem.h b/include/linux/highmem.h
80229index 7fb31da..08b5114 100644
80230--- a/include/linux/highmem.h
80231+++ b/include/linux/highmem.h
80232@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
80233 kunmap_atomic(kaddr);
80234 }
80235
80236+static inline void sanitize_highpage(struct page *page)
80237+{
80238+ void *kaddr;
80239+ unsigned long flags;
80240+
80241+ local_irq_save(flags);
80242+ kaddr = kmap_atomic(page);
80243+ clear_page(kaddr);
80244+ kunmap_atomic(kaddr);
80245+ local_irq_restore(flags);
80246+}
80247+
80248 static inline void zero_user_segments(struct page *page,
80249 unsigned start1, unsigned end1,
80250 unsigned start2, unsigned end2)
80251diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
80252index 1c7b89a..7dda400 100644
80253--- a/include/linux/hwmon-sysfs.h
80254+++ b/include/linux/hwmon-sysfs.h
80255@@ -25,7 +25,8 @@
80256 struct sensor_device_attribute{
80257 struct device_attribute dev_attr;
80258 int index;
80259-};
80260+} __do_const;
80261+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
80262 #define to_sensor_dev_attr(_dev_attr) \
80263 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
80264
80265@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
80266 struct device_attribute dev_attr;
80267 u8 index;
80268 u8 nr;
80269-};
80270+} __do_const;
80271+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
80272 #define to_sensor_dev_attr_2(_dev_attr) \
80273 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
80274
80275diff --git a/include/linux/i2c.h b/include/linux/i2c.h
80276index deddeb8..bcaf62d 100644
80277--- a/include/linux/i2c.h
80278+++ b/include/linux/i2c.h
80279@@ -378,6 +378,7 @@ struct i2c_algorithm {
80280 /* To determine what the adapter supports */
80281 u32 (*functionality) (struct i2c_adapter *);
80282 };
80283+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
80284
80285 /**
80286 * struct i2c_bus_recovery_info - I2C bus recovery information
80287diff --git a/include/linux/i2o.h b/include/linux/i2o.h
80288index d23c3c2..eb63c81 100644
80289--- a/include/linux/i2o.h
80290+++ b/include/linux/i2o.h
80291@@ -565,7 +565,7 @@ struct i2o_controller {
80292 struct i2o_device *exec; /* Executive */
80293 #if BITS_PER_LONG == 64
80294 spinlock_t context_list_lock; /* lock for context_list */
80295- atomic_t context_list_counter; /* needed for unique contexts */
80296+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
80297 struct list_head context_list; /* list of context id's
80298 and pointers */
80299 #endif
80300diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
80301index aff7ad8..3942bbd 100644
80302--- a/include/linux/if_pppox.h
80303+++ b/include/linux/if_pppox.h
80304@@ -76,7 +76,7 @@ struct pppox_proto {
80305 int (*ioctl)(struct socket *sock, unsigned int cmd,
80306 unsigned long arg);
80307 struct module *owner;
80308-};
80309+} __do_const;
80310
80311 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
80312 extern void unregister_pppox_proto(int proto_num);
80313diff --git a/include/linux/init.h b/include/linux/init.h
80314index e168880..d9b489d 100644
80315--- a/include/linux/init.h
80316+++ b/include/linux/init.h
80317@@ -37,9 +37,17 @@
80318 * section.
80319 */
80320
80321+#define add_init_latent_entropy __latent_entropy
80322+
80323+#ifdef CONFIG_MEMORY_HOTPLUG
80324+#define add_meminit_latent_entropy
80325+#else
80326+#define add_meminit_latent_entropy __latent_entropy
80327+#endif
80328+
80329 /* These are for everybody (although not all archs will actually
80330 discard it in modules) */
80331-#define __init __section(.init.text) __cold notrace
80332+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
80333 #define __initdata __section(.init.data)
80334 #define __initconst __constsection(.init.rodata)
80335 #define __exitdata __section(.exit.data)
80336@@ -100,7 +108,7 @@
80337 #define __cpuexitconst
80338
80339 /* Used for MEMORY_HOTPLUG */
80340-#define __meminit __section(.meminit.text) __cold notrace
80341+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
80342 #define __meminitdata __section(.meminit.data)
80343 #define __meminitconst __constsection(.meminit.rodata)
80344 #define __memexit __section(.memexit.text) __exitused __cold notrace
80345diff --git a/include/linux/init_task.h b/include/linux/init_task.h
80346index 6df7f9f..d0bf699 100644
80347--- a/include/linux/init_task.h
80348+++ b/include/linux/init_task.h
80349@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
80350
80351 #define INIT_TASK_COMM "swapper"
80352
80353+#ifdef CONFIG_X86
80354+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
80355+#else
80356+#define INIT_TASK_THREAD_INFO
80357+#endif
80358+
80359 #ifdef CONFIG_RT_MUTEXES
80360 # define INIT_RT_MUTEXES(tsk) \
80361 .pi_waiters = RB_ROOT, \
80362@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
80363 RCU_POINTER_INITIALIZER(cred, &init_cred), \
80364 .comm = INIT_TASK_COMM, \
80365 .thread = INIT_THREAD, \
80366+ INIT_TASK_THREAD_INFO \
80367 .fs = &init_fs, \
80368 .files = &init_files, \
80369 .signal = &init_signals, \
80370diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
80371index 203c43d..605836b 100644
80372--- a/include/linux/interrupt.h
80373+++ b/include/linux/interrupt.h
80374@@ -411,8 +411,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
80375
80376 struct softirq_action
80377 {
80378- void (*action)(struct softirq_action *);
80379-};
80380+ void (*action)(void);
80381+} __no_const;
80382
80383 asmlinkage void do_softirq(void);
80384 asmlinkage void __do_softirq(void);
80385@@ -426,7 +426,7 @@ static inline void do_softirq_own_stack(void)
80386 }
80387 #endif
80388
80389-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80390+extern void open_softirq(int nr, void (*action)(void));
80391 extern void softirq_init(void);
80392 extern void __raise_softirq_irqoff(unsigned int nr);
80393
80394diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80395index b96a5b2..2732d1c 100644
80396--- a/include/linux/iommu.h
80397+++ b/include/linux/iommu.h
80398@@ -131,7 +131,7 @@ struct iommu_ops {
80399 u32 (*domain_get_windows)(struct iommu_domain *domain);
80400
80401 unsigned long pgsize_bitmap;
80402-};
80403+} __do_const;
80404
80405 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80406 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80407diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80408index 89b7c24..382af74 100644
80409--- a/include/linux/ioport.h
80410+++ b/include/linux/ioport.h
80411@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80412 int adjust_resource(struct resource *res, resource_size_t start,
80413 resource_size_t size);
80414 resource_size_t resource_alignment(struct resource *res);
80415-static inline resource_size_t resource_size(const struct resource *res)
80416+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80417 {
80418 return res->end - res->start + 1;
80419 }
80420diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80421index 35e7eca..6afb7ad 100644
80422--- a/include/linux/ipc_namespace.h
80423+++ b/include/linux/ipc_namespace.h
80424@@ -69,7 +69,7 @@ struct ipc_namespace {
80425 struct user_namespace *user_ns;
80426
80427 unsigned int proc_inum;
80428-};
80429+} __randomize_layout;
80430
80431 extern struct ipc_namespace init_ipc_ns;
80432 extern atomic_t nr_ipc_ns;
80433diff --git a/include/linux/irq.h b/include/linux/irq.h
80434index ef1ac9f..e1db06c 100644
80435--- a/include/linux/irq.h
80436+++ b/include/linux/irq.h
80437@@ -338,7 +338,8 @@ struct irq_chip {
80438 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
80439
80440 unsigned long flags;
80441-};
80442+} __do_const;
80443+typedef struct irq_chip __no_const irq_chip_no_const;
80444
80445 /*
80446 * irq_chip specific flags
80447diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80448index 0ceb389..eed3fb8 100644
80449--- a/include/linux/irqchip/arm-gic.h
80450+++ b/include/linux/irqchip/arm-gic.h
80451@@ -73,9 +73,11 @@
80452
80453 #ifndef __ASSEMBLY__
80454
80455+#include <linux/irq.h>
80456+
80457 struct device_node;
80458
80459-extern struct irq_chip gic_arch_extn;
80460+extern irq_chip_no_const gic_arch_extn;
80461
80462 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80463 u32 offset, struct device_node *);
80464diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80465index 1f44466..b481806 100644
80466--- a/include/linux/jiffies.h
80467+++ b/include/linux/jiffies.h
80468@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80469 /*
80470 * Convert various time units to each other:
80471 */
80472-extern unsigned int jiffies_to_msecs(const unsigned long j);
80473-extern unsigned int jiffies_to_usecs(const unsigned long j);
80474+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80475+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80476
80477-static inline u64 jiffies_to_nsecs(const unsigned long j)
80478+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80479 {
80480 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80481 }
80482
80483-extern unsigned long msecs_to_jiffies(const unsigned int m);
80484-extern unsigned long usecs_to_jiffies(const unsigned int u);
80485+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80486+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80487 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80488 extern void jiffies_to_timespec(const unsigned long jiffies,
80489- struct timespec *value);
80490-extern unsigned long timeval_to_jiffies(const struct timeval *value);
80491+ struct timespec *value) __intentional_overflow(-1);
80492+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80493 extern void jiffies_to_timeval(const unsigned long jiffies,
80494 struct timeval *value);
80495
80496diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80497index 6883e19..e854fcb 100644
80498--- a/include/linux/kallsyms.h
80499+++ b/include/linux/kallsyms.h
80500@@ -15,7 +15,8 @@
80501
80502 struct module;
80503
80504-#ifdef CONFIG_KALLSYMS
80505+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80506+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80507 /* Lookup the address for a symbol. Returns 0 if not found. */
80508 unsigned long kallsyms_lookup_name(const char *name);
80509
80510@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80511 /* Stupid that this does nothing, but I didn't create this mess. */
80512 #define __print_symbol(fmt, addr)
80513 #endif /*CONFIG_KALLSYMS*/
80514+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80515+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80516+extern unsigned long kallsyms_lookup_name(const char *name);
80517+extern void __print_symbol(const char *fmt, unsigned long address);
80518+extern int sprint_backtrace(char *buffer, unsigned long address);
80519+extern int sprint_symbol(char *buffer, unsigned long address);
80520+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80521+const char *kallsyms_lookup(unsigned long addr,
80522+ unsigned long *symbolsize,
80523+ unsigned long *offset,
80524+ char **modname, char *namebuf);
80525+extern int kallsyms_lookup_size_offset(unsigned long addr,
80526+ unsigned long *symbolsize,
80527+ unsigned long *offset);
80528+#endif
80529
80530 /* This macro allows us to keep printk typechecking */
80531 static __printf(1, 2)
80532diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80533index a74c3a8..28d3f21 100644
80534--- a/include/linux/key-type.h
80535+++ b/include/linux/key-type.h
80536@@ -131,7 +131,7 @@ struct key_type {
80537 /* internal fields */
80538 struct list_head link; /* link in types list */
80539 struct lock_class_key lock_class; /* key->sem lock class */
80540-};
80541+} __do_const;
80542
80543 extern struct key_type key_type_keyring;
80544
80545diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80546index 6b06d37..c134867 100644
80547--- a/include/linux/kgdb.h
80548+++ b/include/linux/kgdb.h
80549@@ -52,7 +52,7 @@ extern int kgdb_connected;
80550 extern int kgdb_io_module_registered;
80551
80552 extern atomic_t kgdb_setting_breakpoint;
80553-extern atomic_t kgdb_cpu_doing_single_step;
80554+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80555
80556 extern struct task_struct *kgdb_usethread;
80557 extern struct task_struct *kgdb_contthread;
80558@@ -254,7 +254,7 @@ struct kgdb_arch {
80559 void (*correct_hw_break)(void);
80560
80561 void (*enable_nmi)(bool on);
80562-};
80563+} __do_const;
80564
80565 /**
80566 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80567@@ -279,7 +279,7 @@ struct kgdb_io {
80568 void (*pre_exception) (void);
80569 void (*post_exception) (void);
80570 int is_console;
80571-};
80572+} __do_const;
80573
80574 extern struct kgdb_arch arch_kgdb_ops;
80575
80576diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80577index 0555cc6..40116ce 100644
80578--- a/include/linux/kmod.h
80579+++ b/include/linux/kmod.h
80580@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80581 * usually useless though. */
80582 extern __printf(2, 3)
80583 int __request_module(bool wait, const char *name, ...);
80584+extern __printf(3, 4)
80585+int ___request_module(bool wait, char *param_name, const char *name, ...);
80586 #define request_module(mod...) __request_module(true, mod)
80587 #define request_module_nowait(mod...) __request_module(false, mod)
80588 #define try_then_request_module(x, mod...) \
80589@@ -57,6 +59,9 @@ struct subprocess_info {
80590 struct work_struct work;
80591 struct completion *complete;
80592 char *path;
80593+#ifdef CONFIG_GRKERNSEC
80594+ char *origpath;
80595+#endif
80596 char **argv;
80597 char **envp;
80598 int wait;
80599diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80600index 926afb6..58dd6e5 100644
80601--- a/include/linux/kobject.h
80602+++ b/include/linux/kobject.h
80603@@ -116,7 +116,7 @@ struct kobj_type {
80604 struct attribute **default_attrs;
80605 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80606 const void *(*namespace)(struct kobject *kobj);
80607-};
80608+} __do_const;
80609
80610 struct kobj_uevent_env {
80611 char *envp[UEVENT_NUM_ENVP];
80612@@ -139,6 +139,7 @@ struct kobj_attribute {
80613 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80614 const char *buf, size_t count);
80615 };
80616+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80617
80618 extern const struct sysfs_ops kobj_sysfs_ops;
80619
80620@@ -166,7 +167,7 @@ struct kset {
80621 spinlock_t list_lock;
80622 struct kobject kobj;
80623 const struct kset_uevent_ops *uevent_ops;
80624-};
80625+} __randomize_layout;
80626
80627 extern void kset_init(struct kset *kset);
80628 extern int __must_check kset_register(struct kset *kset);
80629diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80630index df32d25..fb52e27 100644
80631--- a/include/linux/kobject_ns.h
80632+++ b/include/linux/kobject_ns.h
80633@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80634 const void *(*netlink_ns)(struct sock *sk);
80635 const void *(*initial_ns)(void);
80636 void (*drop_ns)(void *);
80637-};
80638+} __do_const;
80639
80640 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80641 int kobj_ns_type_registered(enum kobj_ns_type type);
80642diff --git a/include/linux/kref.h b/include/linux/kref.h
80643index 484604d..0f6c5b6 100644
80644--- a/include/linux/kref.h
80645+++ b/include/linux/kref.h
80646@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80647 static inline int kref_sub(struct kref *kref, unsigned int count,
80648 void (*release)(struct kref *kref))
80649 {
80650- WARN_ON(release == NULL);
80651+ BUG_ON(release == NULL);
80652
80653 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80654 release(kref);
80655diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80656index b8e9a43..632678d 100644
80657--- a/include/linux/kvm_host.h
80658+++ b/include/linux/kvm_host.h
80659@@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
80660 {
80661 }
80662 #endif
80663-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80664+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80665 struct module *module);
80666 void kvm_exit(void);
80667
80668@@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80669 struct kvm_guest_debug *dbg);
80670 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80671
80672-int kvm_arch_init(void *opaque);
80673+int kvm_arch_init(const void *opaque);
80674 void kvm_arch_exit(void);
80675
80676 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80677diff --git a/include/linux/libata.h b/include/linux/libata.h
80678index 3fee55e..42565b7 100644
80679--- a/include/linux/libata.h
80680+++ b/include/linux/libata.h
80681@@ -976,7 +976,7 @@ struct ata_port_operations {
80682 * fields must be pointers.
80683 */
80684 const struct ata_port_operations *inherits;
80685-};
80686+} __do_const;
80687
80688 struct ata_port_info {
80689 unsigned long flags;
80690diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80691index a6a42dd..6c5ebce 100644
80692--- a/include/linux/linkage.h
80693+++ b/include/linux/linkage.h
80694@@ -36,6 +36,7 @@
80695 #endif
80696
80697 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80698+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80699 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80700
80701 /*
80702diff --git a/include/linux/list.h b/include/linux/list.h
80703index ef95941..82db65a 100644
80704--- a/include/linux/list.h
80705+++ b/include/linux/list.h
80706@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80707 extern void list_del(struct list_head *entry);
80708 #endif
80709
80710+extern void __pax_list_add(struct list_head *new,
80711+ struct list_head *prev,
80712+ struct list_head *next);
80713+static inline void pax_list_add(struct list_head *new, struct list_head *head)
80714+{
80715+ __pax_list_add(new, head, head->next);
80716+}
80717+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80718+{
80719+ __pax_list_add(new, head->prev, head);
80720+}
80721+extern void pax_list_del(struct list_head *entry);
80722+
80723 /**
80724 * list_replace - replace old entry by new one
80725 * @old : the element to be replaced
80726@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80727 INIT_LIST_HEAD(entry);
80728 }
80729
80730+extern void pax_list_del_init(struct list_head *entry);
80731+
80732 /**
80733 * list_move - delete from one list and add as another's head
80734 * @list: the entry to move
80735diff --git a/include/linux/math64.h b/include/linux/math64.h
80736index c45c089..298841c 100644
80737--- a/include/linux/math64.h
80738+++ b/include/linux/math64.h
80739@@ -15,7 +15,7 @@
80740 * This is commonly provided by 32bit archs to provide an optimized 64bit
80741 * divide.
80742 */
80743-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80744+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80745 {
80746 *remainder = dividend % divisor;
80747 return dividend / divisor;
80748@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80749 /**
80750 * div64_u64 - unsigned 64bit divide with 64bit divisor
80751 */
80752-static inline u64 div64_u64(u64 dividend, u64 divisor)
80753+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80754 {
80755 return dividend / divisor;
80756 }
80757@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80758 #define div64_ul(x, y) div_u64((x), (y))
80759
80760 #ifndef div_u64_rem
80761-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80762+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80763 {
80764 *remainder = do_div(dividend, divisor);
80765 return dividend;
80766@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80767 #endif
80768
80769 #ifndef div64_u64
80770-extern u64 div64_u64(u64 dividend, u64 divisor);
80771+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80772 #endif
80773
80774 #ifndef div64_s64
80775@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80776 * divide.
80777 */
80778 #ifndef div_u64
80779-static inline u64 div_u64(u64 dividend, u32 divisor)
80780+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80781 {
80782 u32 remainder;
80783 return div_u64_rem(dividend, divisor, &remainder);
80784diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80785index 5f1ea75..5125ac5 100644
80786--- a/include/linux/mempolicy.h
80787+++ b/include/linux/mempolicy.h
80788@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80789 }
80790
80791 #define vma_policy(vma) ((vma)->vm_policy)
80792+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80793+{
80794+ vma->vm_policy = pol;
80795+}
80796
80797 static inline void mpol_get(struct mempolicy *pol)
80798 {
80799@@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80800 }
80801
80802 #define vma_policy(vma) NULL
80803+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80804+{
80805+}
80806
80807 static inline int
80808 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80809diff --git a/include/linux/mm.h b/include/linux/mm.h
80810index c1b7414..5ea2ad8 100644
80811--- a/include/linux/mm.h
80812+++ b/include/linux/mm.h
80813@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80814 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80815 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80816 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80817+
80818+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80819+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80820+#endif
80821+
80822 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80823
80824 #ifdef CONFIG_MEM_SOFT_DIRTY
80825@@ -229,8 +234,8 @@ struct vm_operations_struct {
80826 /* called by access_process_vm when get_user_pages() fails, typically
80827 * for use by special VMAs that can switch between memory and hardware
80828 */
80829- int (*access)(struct vm_area_struct *vma, unsigned long addr,
80830- void *buf, int len, int write);
80831+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80832+ void *buf, size_t len, int write);
80833 #ifdef CONFIG_NUMA
80834 /*
80835 * set_policy() op must add a reference to any non-NULL @new mempolicy
80836@@ -260,6 +265,7 @@ struct vm_operations_struct {
80837 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80838 unsigned long size, pgoff_t pgoff);
80839 };
80840+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80841
80842 struct mmu_gather;
80843 struct inode;
80844@@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80845 unsigned long *pfn);
80846 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80847 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80848-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80849- void *buf, int len, int write);
80850+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80851+ void *buf, size_t len, int write);
80852
80853 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80854 loff_t const holebegin, loff_t const holelen)
80855@@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80856 }
80857 #endif
80858
80859-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80860-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80861- void *buf, int len, int write);
80862+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80863+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80864+ void *buf, size_t len, int write);
80865
80866 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80867 unsigned long start, unsigned long nr_pages,
80868@@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
80869 int set_page_dirty_lock(struct page *page);
80870 int clear_page_dirty_for_io(struct page *page);
80871
80872-/* Is the vma a continuation of the stack vma above it? */
80873-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80874-{
80875- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80876-}
80877-
80878-static inline int stack_guard_page_start(struct vm_area_struct *vma,
80879- unsigned long addr)
80880-{
80881- return (vma->vm_flags & VM_GROWSDOWN) &&
80882- (vma->vm_start == addr) &&
80883- !vma_growsdown(vma->vm_prev, addr);
80884-}
80885-
80886-/* Is the vma a continuation of the stack vma below it? */
80887-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80888-{
80889- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80890-}
80891-
80892-static inline int stack_guard_page_end(struct vm_area_struct *vma,
80893- unsigned long addr)
80894-{
80895- return (vma->vm_flags & VM_GROWSUP) &&
80896- (vma->vm_end == addr) &&
80897- !vma_growsup(vma->vm_next, addr);
80898-}
80899-
80900 extern pid_t
80901 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80902
80903@@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80904 }
80905 #endif
80906
80907+#ifdef CONFIG_MMU
80908+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80909+#else
80910+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80911+{
80912+ return __pgprot(0);
80913+}
80914+#endif
80915+
80916 int vma_wants_writenotify(struct vm_area_struct *vma);
80917
80918 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80919@@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80920 {
80921 return 0;
80922 }
80923+
80924+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80925+ unsigned long address)
80926+{
80927+ return 0;
80928+}
80929 #else
80930 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80931+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80932 #endif
80933
80934 #ifdef __PAGETABLE_PMD_FOLDED
80935@@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80936 {
80937 return 0;
80938 }
80939+
80940+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80941+ unsigned long address)
80942+{
80943+ return 0;
80944+}
80945 #else
80946 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80947+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80948 #endif
80949
80950 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80951@@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80952 NULL: pud_offset(pgd, address);
80953 }
80954
80955+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80956+{
80957+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80958+ NULL: pud_offset(pgd, address);
80959+}
80960+
80961 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80962 {
80963 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80964 NULL: pmd_offset(pud, address);
80965 }
80966+
80967+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80968+{
80969+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80970+ NULL: pmd_offset(pud, address);
80971+}
80972 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80973
80974 #if USE_SPLIT_PTE_PTLOCKS
80975@@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80976 unsigned long addr, unsigned long len,
80977 unsigned long flags, struct page **pages);
80978
80979-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80980+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80981
80982 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80983 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80984@@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80985 unsigned long len, unsigned long prot, unsigned long flags,
80986 unsigned long pgoff, unsigned long *populate);
80987 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80988+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80989
80990 #ifdef CONFIG_MMU
80991 extern int __mm_populate(unsigned long addr, unsigned long len,
80992@@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
80993 unsigned long high_limit;
80994 unsigned long align_mask;
80995 unsigned long align_offset;
80996+ unsigned long threadstack_offset;
80997 };
80998
80999-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
81000-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
81001+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
81002+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
81003
81004 /*
81005 * Search for an unmapped address range.
81006@@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
81007 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
81008 */
81009 static inline unsigned long
81010-vm_unmapped_area(struct vm_unmapped_area_info *info)
81011+vm_unmapped_area(const struct vm_unmapped_area_info *info)
81012 {
81013 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
81014 return unmapped_area(info);
81015@@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
81016 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
81017 struct vm_area_struct **pprev);
81018
81019+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
81020+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
81021+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
81022+
81023 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
81024 NULL if none. Assume start_addr < end_addr. */
81025 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
81026@@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
81027 return vma;
81028 }
81029
81030-#ifdef CONFIG_MMU
81031-pgprot_t vm_get_page_prot(unsigned long vm_flags);
81032-#else
81033-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
81034-{
81035- return __pgprot(0);
81036-}
81037-#endif
81038-
81039 #ifdef CONFIG_NUMA_BALANCING
81040 unsigned long change_prot_numa(struct vm_area_struct *vma,
81041 unsigned long start, unsigned long end);
81042@@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
81043 static inline void vm_stat_account(struct mm_struct *mm,
81044 unsigned long flags, struct file *file, long pages)
81045 {
81046+
81047+#ifdef CONFIG_PAX_RANDMMAP
81048+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81049+#endif
81050+
81051 mm->total_vm += pages;
81052 }
81053 #endif /* CONFIG_PROC_FS */
81054@@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
81055 extern int sysctl_memory_failure_early_kill;
81056 extern int sysctl_memory_failure_recovery;
81057 extern void shake_page(struct page *p, int access);
81058-extern atomic_long_t num_poisoned_pages;
81059+extern atomic_long_unchecked_t num_poisoned_pages;
81060 extern int soft_offline_page(struct page *page, int flags);
81061
81062 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
81063@@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
81064 static inline void setup_nr_node_ids(void) {}
81065 #endif
81066
81067+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81068+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
81069+#else
81070+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
81071+#endif
81072+
81073 #endif /* __KERNEL__ */
81074 #endif /* _LINUX_MM_H */
81075diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
81076index 290901a..e99b01c 100644
81077--- a/include/linux/mm_types.h
81078+++ b/include/linux/mm_types.h
81079@@ -307,7 +307,9 @@ struct vm_area_struct {
81080 #ifdef CONFIG_NUMA
81081 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
81082 #endif
81083-};
81084+
81085+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
81086+} __randomize_layout;
81087
81088 struct core_thread {
81089 struct task_struct *task;
81090@@ -453,7 +455,25 @@ struct mm_struct {
81091 bool tlb_flush_pending;
81092 #endif
81093 struct uprobes_state uprobes_state;
81094-};
81095+
81096+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81097+ unsigned long pax_flags;
81098+#endif
81099+
81100+#ifdef CONFIG_PAX_DLRESOLVE
81101+ unsigned long call_dl_resolve;
81102+#endif
81103+
81104+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
81105+ unsigned long call_syscall;
81106+#endif
81107+
81108+#ifdef CONFIG_PAX_ASLR
81109+ unsigned long delta_mmap; /* randomized offset */
81110+ unsigned long delta_stack; /* randomized offset */
81111+#endif
81112+
81113+} __randomize_layout;
81114
81115 static inline void mm_init_cpumask(struct mm_struct *mm)
81116 {
81117diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
81118index c5d5278..f0b68c8 100644
81119--- a/include/linux/mmiotrace.h
81120+++ b/include/linux/mmiotrace.h
81121@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
81122 /* Called from ioremap.c */
81123 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
81124 void __iomem *addr);
81125-extern void mmiotrace_iounmap(volatile void __iomem *addr);
81126+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
81127
81128 /* For anyone to insert markers. Remember trailing newline. */
81129 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
81130@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
81131 {
81132 }
81133
81134-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
81135+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
81136 {
81137 }
81138
81139diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
81140index 9b61b9b..52147d6b 100644
81141--- a/include/linux/mmzone.h
81142+++ b/include/linux/mmzone.h
81143@@ -396,7 +396,7 @@ struct zone {
81144 unsigned long flags; /* zone flags, see below */
81145
81146 /* Zone statistics */
81147- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81148+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81149
81150 /*
81151 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
81152diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
81153index 45e9214..a7227d6 100644
81154--- a/include/linux/mod_devicetable.h
81155+++ b/include/linux/mod_devicetable.h
81156@@ -13,7 +13,7 @@
81157 typedef unsigned long kernel_ulong_t;
81158 #endif
81159
81160-#define PCI_ANY_ID (~0)
81161+#define PCI_ANY_ID ((__u16)~0)
81162
81163 struct pci_device_id {
81164 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
81165@@ -139,7 +139,7 @@ struct usb_device_id {
81166 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
81167 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
81168
81169-#define HID_ANY_ID (~0)
81170+#define HID_ANY_ID (~0U)
81171 #define HID_BUS_ANY 0xffff
81172 #define HID_GROUP_ANY 0x0000
81173
81174@@ -467,7 +467,7 @@ struct dmi_system_id {
81175 const char *ident;
81176 struct dmi_strmatch matches[4];
81177 void *driver_data;
81178-};
81179+} __do_const;
81180 /*
81181 * struct dmi_device_id appears during expansion of
81182 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
81183diff --git a/include/linux/module.h b/include/linux/module.h
81184index eaf60ff..641979a 100644
81185--- a/include/linux/module.h
81186+++ b/include/linux/module.h
81187@@ -17,9 +17,11 @@
81188 #include <linux/moduleparam.h>
81189 #include <linux/tracepoint.h>
81190 #include <linux/export.h>
81191+#include <linux/fs.h>
81192
81193 #include <linux/percpu.h>
81194 #include <asm/module.h>
81195+#include <asm/pgtable.h>
81196
81197 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
81198 #define MODULE_SIG_STRING "~Module signature appended~\n"
81199@@ -42,7 +44,7 @@ struct module_kobject {
81200 struct kobject *drivers_dir;
81201 struct module_param_attrs *mp;
81202 struct completion *kobj_completion;
81203-};
81204+} __randomize_layout;
81205
81206 struct module_attribute {
81207 struct attribute attr;
81208@@ -54,12 +56,13 @@ struct module_attribute {
81209 int (*test)(struct module *);
81210 void (*free)(struct module *);
81211 };
81212+typedef struct module_attribute __no_const module_attribute_no_const;
81213
81214 struct module_version_attribute {
81215 struct module_attribute mattr;
81216 const char *module_name;
81217 const char *version;
81218-} __attribute__ ((__aligned__(sizeof(void *))));
81219+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
81220
81221 extern ssize_t __modver_version_show(struct module_attribute *,
81222 struct module_kobject *, char *);
81223@@ -238,7 +241,7 @@ struct module {
81224
81225 /* Sysfs stuff. */
81226 struct module_kobject mkobj;
81227- struct module_attribute *modinfo_attrs;
81228+ module_attribute_no_const *modinfo_attrs;
81229 const char *version;
81230 const char *srcversion;
81231 struct kobject *holders_dir;
81232@@ -287,19 +290,16 @@ struct module {
81233 int (*init)(void);
81234
81235 /* If this is non-NULL, vfree after init() returns */
81236- void *module_init;
81237+ void *module_init_rx, *module_init_rw;
81238
81239 /* Here is the actual code + data, vfree'd on unload. */
81240- void *module_core;
81241+ void *module_core_rx, *module_core_rw;
81242
81243 /* Here are the sizes of the init and core sections */
81244- unsigned int init_size, core_size;
81245+ unsigned int init_size_rw, core_size_rw;
81246
81247 /* The size of the executable code in each section. */
81248- unsigned int init_text_size, core_text_size;
81249-
81250- /* Size of RO sections of the module (text+rodata) */
81251- unsigned int init_ro_size, core_ro_size;
81252+ unsigned int init_size_rx, core_size_rx;
81253
81254 /* Arch-specific module values */
81255 struct mod_arch_specific arch;
81256@@ -355,6 +355,10 @@ struct module {
81257 #ifdef CONFIG_EVENT_TRACING
81258 struct ftrace_event_call **trace_events;
81259 unsigned int num_trace_events;
81260+ struct file_operations trace_id;
81261+ struct file_operations trace_enable;
81262+ struct file_operations trace_format;
81263+ struct file_operations trace_filter;
81264 #endif
81265 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
81266 unsigned int num_ftrace_callsites;
81267@@ -378,7 +382,7 @@ struct module {
81268 ctor_fn_t *ctors;
81269 unsigned int num_ctors;
81270 #endif
81271-};
81272+} __randomize_layout;
81273 #ifndef MODULE_ARCH_INIT
81274 #define MODULE_ARCH_INIT {}
81275 #endif
81276@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
81277 bool is_module_percpu_address(unsigned long addr);
81278 bool is_module_text_address(unsigned long addr);
81279
81280+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
81281+{
81282+
81283+#ifdef CONFIG_PAX_KERNEXEC
81284+ if (ktla_ktva(addr) >= (unsigned long)start &&
81285+ ktla_ktva(addr) < (unsigned long)start + size)
81286+ return 1;
81287+#endif
81288+
81289+ return ((void *)addr >= start && (void *)addr < start + size);
81290+}
81291+
81292+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
81293+{
81294+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
81295+}
81296+
81297+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
81298+{
81299+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
81300+}
81301+
81302+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
81303+{
81304+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
81305+}
81306+
81307+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
81308+{
81309+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
81310+}
81311+
81312 static inline int within_module_core(unsigned long addr, const struct module *mod)
81313 {
81314- return (unsigned long)mod->module_core <= addr &&
81315- addr < (unsigned long)mod->module_core + mod->core_size;
81316+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
81317 }
81318
81319 static inline int within_module_init(unsigned long addr, const struct module *mod)
81320 {
81321- return (unsigned long)mod->module_init <= addr &&
81322- addr < (unsigned long)mod->module_init + mod->init_size;
81323+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
81324 }
81325
81326 /* Search for module by name: must hold module_mutex. */
81327diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
81328index 560ca53..ef621ef 100644
81329--- a/include/linux/moduleloader.h
81330+++ b/include/linux/moduleloader.h
81331@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
81332 sections. Returns NULL on failure. */
81333 void *module_alloc(unsigned long size);
81334
81335+#ifdef CONFIG_PAX_KERNEXEC
81336+void *module_alloc_exec(unsigned long size);
81337+#else
81338+#define module_alloc_exec(x) module_alloc(x)
81339+#endif
81340+
81341 /* Free memory returned from module_alloc. */
81342 void module_free(struct module *mod, void *module_region);
81343
81344+#ifdef CONFIG_PAX_KERNEXEC
81345+void module_free_exec(struct module *mod, void *module_region);
81346+#else
81347+#define module_free_exec(x, y) module_free((x), (y))
81348+#endif
81349+
81350 /*
81351 * Apply the given relocation to the (simplified) ELF. Return -error
81352 * or 0.
81353@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
81354 unsigned int relsec,
81355 struct module *me)
81356 {
81357+#ifdef CONFIG_MODULES
81358 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81359+#endif
81360 return -ENOEXEC;
81361 }
81362 #endif
81363@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
81364 unsigned int relsec,
81365 struct module *me)
81366 {
81367+#ifdef CONFIG_MODULES
81368 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81369+#endif
81370 return -ENOEXEC;
81371 }
81372 #endif
81373diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
81374index c3eb102..073c4a6 100644
81375--- a/include/linux/moduleparam.h
81376+++ b/include/linux/moduleparam.h
81377@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
81378 * @len is usually just sizeof(string).
81379 */
81380 #define module_param_string(name, string, len, perm) \
81381- static const struct kparam_string __param_string_##name \
81382+ static const struct kparam_string __param_string_##name __used \
81383 = { len, string }; \
81384 __module_param_call(MODULE_PARAM_PREFIX, name, \
81385 &param_ops_string, \
81386@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
81387 */
81388 #define module_param_array_named(name, array, type, nump, perm) \
81389 param_check_##type(name, &(array)[0]); \
81390- static const struct kparam_array __param_arr_##name \
81391+ static const struct kparam_array __param_arr_##name __used \
81392 = { .max = ARRAY_SIZE(array), .num = nump, \
81393 .ops = &param_ops_##type, \
81394 .elemsize = sizeof(array[0]), .elem = array }; \
81395diff --git a/include/linux/mount.h b/include/linux/mount.h
81396index 839bac2..a96b37c 100644
81397--- a/include/linux/mount.h
81398+++ b/include/linux/mount.h
81399@@ -59,7 +59,7 @@ struct vfsmount {
81400 struct dentry *mnt_root; /* root of the mounted tree */
81401 struct super_block *mnt_sb; /* pointer to superblock */
81402 int mnt_flags;
81403-};
81404+} __randomize_layout;
81405
81406 struct file; /* forward dec */
81407
81408diff --git a/include/linux/namei.h b/include/linux/namei.h
81409index 492de72..1bddcd4 100644
81410--- a/include/linux/namei.h
81411+++ b/include/linux/namei.h
81412@@ -19,7 +19,7 @@ struct nameidata {
81413 unsigned seq, m_seq;
81414 int last_type;
81415 unsigned depth;
81416- char *saved_names[MAX_NESTED_LINKS + 1];
81417+ const char *saved_names[MAX_NESTED_LINKS + 1];
81418 };
81419
81420 /*
81421@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81422
81423 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81424
81425-static inline void nd_set_link(struct nameidata *nd, char *path)
81426+static inline void nd_set_link(struct nameidata *nd, const char *path)
81427 {
81428 nd->saved_names[nd->depth] = path;
81429 }
81430
81431-static inline char *nd_get_link(struct nameidata *nd)
81432+static inline const char *nd_get_link(const struct nameidata *nd)
81433 {
81434 return nd->saved_names[nd->depth];
81435 }
81436diff --git a/include/linux/net.h b/include/linux/net.h
81437index 17d8339..81656c0 100644
81438--- a/include/linux/net.h
81439+++ b/include/linux/net.h
81440@@ -192,7 +192,7 @@ struct net_proto_family {
81441 int (*create)(struct net *net, struct socket *sock,
81442 int protocol, int kern);
81443 struct module *owner;
81444-};
81445+} __do_const;
81446
81447 struct iovec;
81448 struct kvec;
81449diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81450index 911718f..f673407 100644
81451--- a/include/linux/netdevice.h
81452+++ b/include/linux/netdevice.h
81453@@ -1147,6 +1147,7 @@ struct net_device_ops {
81454 void *priv);
81455 int (*ndo_get_lock_subclass)(struct net_device *dev);
81456 };
81457+typedef struct net_device_ops __no_const net_device_ops_no_const;
81458
81459 /*
81460 * The DEVICE structure.
81461@@ -1229,7 +1230,7 @@ struct net_device {
81462 int iflink;
81463
81464 struct net_device_stats stats;
81465- atomic_long_t rx_dropped; /* dropped packets by core network
81466+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
81467 * Do not use this in drivers.
81468 */
81469
81470diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81471index 2077489..a15e561 100644
81472--- a/include/linux/netfilter.h
81473+++ b/include/linux/netfilter.h
81474@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81475 #endif
81476 /* Use the module struct to lock set/get code in place */
81477 struct module *owner;
81478-};
81479+} __do_const;
81480
81481 /* Function to register/unregister hook points. */
81482 int nf_register_hook(struct nf_hook_ops *reg);
81483diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81484index 28c7436..2d6156a 100644
81485--- a/include/linux/netfilter/nfnetlink.h
81486+++ b/include/linux/netfilter/nfnetlink.h
81487@@ -19,7 +19,7 @@ struct nfnl_callback {
81488 const struct nlattr * const cda[]);
81489 const struct nla_policy *policy; /* netlink attribute policy */
81490 const u_int16_t attr_count; /* number of nlattr's */
81491-};
81492+} __do_const;
81493
81494 struct nfnetlink_subsystem {
81495 const char *name;
81496diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81497new file mode 100644
81498index 0000000..33f4af8
81499--- /dev/null
81500+++ b/include/linux/netfilter/xt_gradm.h
81501@@ -0,0 +1,9 @@
81502+#ifndef _LINUX_NETFILTER_XT_GRADM_H
81503+#define _LINUX_NETFILTER_XT_GRADM_H 1
81504+
81505+struct xt_gradm_mtinfo {
81506+ __u16 flags;
81507+ __u16 invflags;
81508+};
81509+
81510+#endif
81511diff --git a/include/linux/netlink.h b/include/linux/netlink.h
81512index aad8eea..034cda7 100644
81513--- a/include/linux/netlink.h
81514+++ b/include/linux/netlink.h
81515@@ -16,9 +16,10 @@ static inline struct nlmsghdr *nlmsg_hdr(const struct sk_buff *skb)
81516 }
81517
81518 enum netlink_skb_flags {
81519- NETLINK_SKB_MMAPED = 0x1, /* Packet data is mmaped */
81520- NETLINK_SKB_TX = 0x2, /* Packet was sent by userspace */
81521- NETLINK_SKB_DELIVERED = 0x4, /* Packet was delivered */
81522+ NETLINK_SKB_MMAPED = 0x1, /* Packet data is mmaped */
81523+ NETLINK_SKB_TX = 0x2, /* Packet was sent by userspace */
81524+ NETLINK_SKB_DELIVERED = 0x4, /* Packet was delivered */
81525+ NETLINK_SKB_DST = 0x8, /* Dst set in sendto or sendmsg */
81526 };
81527
81528 struct netlink_skb_parms {
81529@@ -169,4 +170,11 @@ struct netlink_tap {
81530 extern int netlink_add_tap(struct netlink_tap *nt);
81531 extern int netlink_remove_tap(struct netlink_tap *nt);
81532
81533+bool __netlink_ns_capable(const struct netlink_skb_parms *nsp,
81534+ struct user_namespace *ns, int cap);
81535+bool netlink_ns_capable(const struct sk_buff *skb,
81536+ struct user_namespace *ns, int cap);
81537+bool netlink_capable(const struct sk_buff *skb, int cap);
81538+bool netlink_net_capable(const struct sk_buff *skb, int cap);
81539+
81540 #endif /* __LINUX_NETLINK_H */
81541diff --git a/include/linux/nls.h b/include/linux/nls.h
81542index 520681b..1d67ed2 100644
81543--- a/include/linux/nls.h
81544+++ b/include/linux/nls.h
81545@@ -31,7 +31,7 @@ struct nls_table {
81546 const unsigned char *charset2upper;
81547 struct module *owner;
81548 struct nls_table *next;
81549-};
81550+} __do_const;
81551
81552 /* this value hold the maximum octet of charset */
81553 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81554diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81555index d14a4c3..a078786 100644
81556--- a/include/linux/notifier.h
81557+++ b/include/linux/notifier.h
81558@@ -54,7 +54,8 @@ struct notifier_block {
81559 notifier_fn_t notifier_call;
81560 struct notifier_block __rcu *next;
81561 int priority;
81562-};
81563+} __do_const;
81564+typedef struct notifier_block __no_const notifier_block_no_const;
81565
81566 struct atomic_notifier_head {
81567 spinlock_t lock;
81568diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81569index b2a0f15..4d7da32 100644
81570--- a/include/linux/oprofile.h
81571+++ b/include/linux/oprofile.h
81572@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81573 int oprofilefs_create_ro_ulong(struct dentry * root,
81574 char const * name, ulong * val);
81575
81576-/** Create a file for read-only access to an atomic_t. */
81577+/** Create a file for read-only access to an atomic_unchecked_t. */
81578 int oprofilefs_create_ro_atomic(struct dentry * root,
81579- char const * name, atomic_t * val);
81580+ char const * name, atomic_unchecked_t * val);
81581
81582 /** create a directory */
81583 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81584diff --git a/include/linux/padata.h b/include/linux/padata.h
81585index 4386946..f50c615 100644
81586--- a/include/linux/padata.h
81587+++ b/include/linux/padata.h
81588@@ -129,7 +129,7 @@ struct parallel_data {
81589 struct padata_serial_queue __percpu *squeue;
81590 atomic_t reorder_objects;
81591 atomic_t refcnt;
81592- atomic_t seq_nr;
81593+ atomic_unchecked_t seq_nr;
81594 struct padata_cpumask cpumask;
81595 spinlock_t lock ____cacheline_aligned;
81596 unsigned int processed;
81597diff --git a/include/linux/path.h b/include/linux/path.h
81598index d137218..be0c176 100644
81599--- a/include/linux/path.h
81600+++ b/include/linux/path.h
81601@@ -1,13 +1,15 @@
81602 #ifndef _LINUX_PATH_H
81603 #define _LINUX_PATH_H
81604
81605+#include <linux/compiler.h>
81606+
81607 struct dentry;
81608 struct vfsmount;
81609
81610 struct path {
81611 struct vfsmount *mnt;
81612 struct dentry *dentry;
81613-};
81614+} __randomize_layout;
81615
81616 extern void path_get(const struct path *);
81617 extern void path_put(const struct path *);
81618diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81619index 5f2e559..7d59314 100644
81620--- a/include/linux/pci_hotplug.h
81621+++ b/include/linux/pci_hotplug.h
81622@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81623 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81624 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81625 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81626-};
81627+} __do_const;
81628+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81629
81630 /**
81631 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81632diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81633index e56b07f..aef789b 100644
81634--- a/include/linux/perf_event.h
81635+++ b/include/linux/perf_event.h
81636@@ -328,8 +328,8 @@ struct perf_event {
81637
81638 enum perf_event_active_state state;
81639 unsigned int attach_state;
81640- local64_t count;
81641- atomic64_t child_count;
81642+ local64_t count; /* PaX: fix it one day */
81643+ atomic64_unchecked_t child_count;
81644
81645 /*
81646 * These are the total time in nanoseconds that the event
81647@@ -380,8 +380,8 @@ struct perf_event {
81648 * These accumulate total time (in nanoseconds) that children
81649 * events have been enabled and running, respectively.
81650 */
81651- atomic64_t child_total_time_enabled;
81652- atomic64_t child_total_time_running;
81653+ atomic64_unchecked_t child_total_time_enabled;
81654+ atomic64_unchecked_t child_total_time_running;
81655
81656 /*
81657 * Protect attach/detach and child_list:
81658@@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81659 entry->ip[entry->nr++] = ip;
81660 }
81661
81662-extern int sysctl_perf_event_paranoid;
81663+extern int sysctl_perf_event_legitimately_concerned;
81664 extern int sysctl_perf_event_mlock;
81665 extern int sysctl_perf_event_sample_rate;
81666 extern int sysctl_perf_cpu_time_max_percent;
81667@@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81668 loff_t *ppos);
81669
81670
81671+static inline bool perf_paranoid_any(void)
81672+{
81673+ return sysctl_perf_event_legitimately_concerned > 2;
81674+}
81675+
81676 static inline bool perf_paranoid_tracepoint_raw(void)
81677 {
81678- return sysctl_perf_event_paranoid > -1;
81679+ return sysctl_perf_event_legitimately_concerned > -1;
81680 }
81681
81682 static inline bool perf_paranoid_cpu(void)
81683 {
81684- return sysctl_perf_event_paranoid > 0;
81685+ return sysctl_perf_event_legitimately_concerned > 0;
81686 }
81687
81688 static inline bool perf_paranoid_kernel(void)
81689 {
81690- return sysctl_perf_event_paranoid > 1;
81691+ return sysctl_perf_event_legitimately_concerned > 1;
81692 }
81693
81694 extern void perf_event_init(void);
81695@@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
81696 struct device_attribute attr;
81697 u64 id;
81698 const char *event_str;
81699-};
81700+} __do_const;
81701
81702 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81703 static struct perf_pmu_events_attr _var = { \
81704diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81705index 7246ef3..1539ea4 100644
81706--- a/include/linux/pid_namespace.h
81707+++ b/include/linux/pid_namespace.h
81708@@ -43,7 +43,7 @@ struct pid_namespace {
81709 int hide_pid;
81710 int reboot; /* group exit code if this pidns was rebooted */
81711 unsigned int proc_inum;
81712-};
81713+} __randomize_layout;
81714
81715 extern struct pid_namespace init_pid_ns;
81716
81717diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81718index ab57526..94598804 100644
81719--- a/include/linux/pipe_fs_i.h
81720+++ b/include/linux/pipe_fs_i.h
81721@@ -47,10 +47,10 @@ struct pipe_inode_info {
81722 struct mutex mutex;
81723 wait_queue_head_t wait;
81724 unsigned int nrbufs, curbuf, buffers;
81725- unsigned int readers;
81726- unsigned int writers;
81727- unsigned int files;
81728- unsigned int waiting_writers;
81729+ atomic_t readers;
81730+ atomic_t writers;
81731+ atomic_t files;
81732+ atomic_t waiting_writers;
81733 unsigned int r_counter;
81734 unsigned int w_counter;
81735 struct page *tmp_page;
81736diff --git a/include/linux/pm.h b/include/linux/pm.h
81737index 8c6583a..febb84c 100644
81738--- a/include/linux/pm.h
81739+++ b/include/linux/pm.h
81740@@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81741 struct dev_pm_domain {
81742 struct dev_pm_ops ops;
81743 };
81744+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81745
81746 /*
81747 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81748diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81749index 7c1d252..0e7061d 100644
81750--- a/include/linux/pm_domain.h
81751+++ b/include/linux/pm_domain.h
81752@@ -44,11 +44,11 @@ struct gpd_dev_ops {
81753 int (*thaw_early)(struct device *dev);
81754 int (*thaw)(struct device *dev);
81755 bool (*active_wakeup)(struct device *dev);
81756-};
81757+} __no_const;
81758
81759 struct gpd_cpu_data {
81760 unsigned int saved_exit_latency;
81761- struct cpuidle_state *idle_state;
81762+ cpuidle_state_no_const *idle_state;
81763 };
81764
81765 struct generic_pm_domain {
81766diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81767index 16c9a62..f9f0838 100644
81768--- a/include/linux/pm_runtime.h
81769+++ b/include/linux/pm_runtime.h
81770@@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81771
81772 static inline void pm_runtime_mark_last_busy(struct device *dev)
81773 {
81774- ACCESS_ONCE(dev->power.last_busy) = jiffies;
81775+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81776 }
81777
81778 #else /* !CONFIG_PM_RUNTIME */
81779diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81780index 195aafc..49a7bc2 100644
81781--- a/include/linux/pnp.h
81782+++ b/include/linux/pnp.h
81783@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81784 struct pnp_fixup {
81785 char id[7];
81786 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81787-};
81788+} __do_const;
81789
81790 /* config parameters */
81791 #define PNP_CONFIG_NORMAL 0x0001
81792diff --git a/include/linux/poison.h b/include/linux/poison.h
81793index 2110a81..13a11bb 100644
81794--- a/include/linux/poison.h
81795+++ b/include/linux/poison.h
81796@@ -19,8 +19,8 @@
81797 * under normal circumstances, used to verify that nobody uses
81798 * non-initialized list entries.
81799 */
81800-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81801-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81802+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81803+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81804
81805 /********** include/linux/timer.h **********/
81806 /*
81807diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81808index d8b187c3..9a9257a 100644
81809--- a/include/linux/power/smartreflex.h
81810+++ b/include/linux/power/smartreflex.h
81811@@ -238,7 +238,7 @@ struct omap_sr_class_data {
81812 int (*notify)(struct omap_sr *sr, u32 status);
81813 u8 notify_flags;
81814 u8 class_type;
81815-};
81816+} __do_const;
81817
81818 /**
81819 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81820diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81821index 4ea1d37..80f4b33 100644
81822--- a/include/linux/ppp-comp.h
81823+++ b/include/linux/ppp-comp.h
81824@@ -84,7 +84,7 @@ struct compressor {
81825 struct module *owner;
81826 /* Extra skb space needed by the compressor algorithm */
81827 unsigned int comp_extra;
81828-};
81829+} __do_const;
81830
81831 /*
81832 * The return value from decompress routine is the length of the
81833diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81834index 1841b58..fbeebf8 100644
81835--- a/include/linux/preempt.h
81836+++ b/include/linux/preempt.h
81837@@ -29,11 +29,16 @@ extern void preempt_count_sub(int val);
81838 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81839 #endif
81840
81841+#define raw_preempt_count_add(val) __preempt_count_add(val)
81842+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81843+
81844 #define __preempt_count_inc() __preempt_count_add(1)
81845 #define __preempt_count_dec() __preempt_count_sub(1)
81846
81847 #define preempt_count_inc() preempt_count_add(1)
81848+#define raw_preempt_count_inc() raw_preempt_count_add(1)
81849 #define preempt_count_dec() preempt_count_sub(1)
81850+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81851
81852 #ifdef CONFIG_PREEMPT_COUNT
81853
81854@@ -43,6 +48,12 @@ do { \
81855 barrier(); \
81856 } while (0)
81857
81858+#define raw_preempt_disable() \
81859+do { \
81860+ raw_preempt_count_inc(); \
81861+ barrier(); \
81862+} while (0)
81863+
81864 #define sched_preempt_enable_no_resched() \
81865 do { \
81866 barrier(); \
81867@@ -51,6 +62,12 @@ do { \
81868
81869 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81870
81871+#define raw_preempt_enable_no_resched() \
81872+do { \
81873+ barrier(); \
81874+ raw_preempt_count_dec(); \
81875+} while (0)
81876+
81877 #ifdef CONFIG_PREEMPT
81878 #define preempt_enable() \
81879 do { \
81880@@ -115,8 +132,10 @@ do { \
81881 * region.
81882 */
81883 #define preempt_disable() barrier()
81884+#define raw_preempt_disable() barrier()
81885 #define sched_preempt_enable_no_resched() barrier()
81886 #define preempt_enable_no_resched() barrier()
81887+#define raw_preempt_enable_no_resched() barrier()
81888 #define preempt_enable() barrier()
81889 #define preempt_check_resched() do { } while (0)
81890
81891@@ -130,11 +149,13 @@ do { \
81892 /*
81893 * Modules have no business playing preemption tricks.
81894 */
81895+#ifndef CONFIG_PAX_KERNEXEC
81896 #undef sched_preempt_enable_no_resched
81897 #undef preempt_enable_no_resched
81898 #undef preempt_enable_no_resched_notrace
81899 #undef preempt_check_resched
81900 #endif
81901+#endif
81902
81903 #define preempt_set_need_resched() \
81904 do { \
81905diff --git a/include/linux/printk.h b/include/linux/printk.h
81906index fa47e27..c08e034 100644
81907--- a/include/linux/printk.h
81908+++ b/include/linux/printk.h
81909@@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
81910 void early_printk(const char *s, ...) { }
81911 #endif
81912
81913+extern int kptr_restrict;
81914+
81915 #ifdef CONFIG_PRINTK
81916 asmlinkage __printf(5, 0)
81917 int vprintk_emit(int facility, int level,
81918@@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81919
81920 extern int printk_delay_msec;
81921 extern int dmesg_restrict;
81922-extern int kptr_restrict;
81923
81924 extern void wake_up_klogd(void);
81925
81926diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81927index 608e60a..bbcb1a0 100644
81928--- a/include/linux/proc_fs.h
81929+++ b/include/linux/proc_fs.h
81930@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81931 extern struct proc_dir_entry *proc_symlink(const char *,
81932 struct proc_dir_entry *, const char *);
81933 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81934+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81935 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81936 struct proc_dir_entry *, void *);
81937+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81938+ struct proc_dir_entry *, void *);
81939 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81940 struct proc_dir_entry *);
81941
81942@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81943 return proc_create_data(name, mode, parent, proc_fops, NULL);
81944 }
81945
81946+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81947+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81948+{
81949+#ifdef CONFIG_GRKERNSEC_PROC_USER
81950+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81951+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81952+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81953+#else
81954+ return proc_create_data(name, mode, parent, proc_fops, NULL);
81955+#endif
81956+}
81957+
81958+
81959 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81960 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81961 extern void *PDE_DATA(const struct inode *);
81962@@ -73,7 +89,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81963 static inline struct proc_dir_entry *proc_net_mkdir(
81964 struct net *net, const char *name, struct proc_dir_entry *parent)
81965 {
81966- return proc_mkdir_data(name, 0, parent, net);
81967+ return proc_mkdir_data_restrict(name, 0, parent, net);
81968 }
81969
81970 #endif /* _LINUX_PROC_FS_H */
81971diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81972index 34a1e10..70f6bde 100644
81973--- a/include/linux/proc_ns.h
81974+++ b/include/linux/proc_ns.h
81975@@ -14,7 +14,7 @@ struct proc_ns_operations {
81976 void (*put)(void *ns);
81977 int (*install)(struct nsproxy *nsproxy, void *ns);
81978 unsigned int (*inum)(void *ns);
81979-};
81980+} __do_const __randomize_layout;
81981
81982 struct proc_ns {
81983 void *ns;
81984diff --git a/include/linux/quota.h b/include/linux/quota.h
81985index cc7494a..1e27036 100644
81986--- a/include/linux/quota.h
81987+++ b/include/linux/quota.h
81988@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81989
81990 extern bool qid_eq(struct kqid left, struct kqid right);
81991 extern bool qid_lt(struct kqid left, struct kqid right);
81992-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81993+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81994 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81995 extern bool qid_valid(struct kqid qid);
81996
81997diff --git a/include/linux/random.h b/include/linux/random.h
81998index 1cfce0e..b0b9235 100644
81999--- a/include/linux/random.h
82000+++ b/include/linux/random.h
82001@@ -9,9 +9,19 @@
82002 #include <uapi/linux/random.h>
82003
82004 extern void add_device_randomness(const void *, unsigned int);
82005+
82006+static inline void add_latent_entropy(void)
82007+{
82008+
82009+#ifdef LATENT_ENTROPY_PLUGIN
82010+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
82011+#endif
82012+
82013+}
82014+
82015 extern void add_input_randomness(unsigned int type, unsigned int code,
82016- unsigned int value);
82017-extern void add_interrupt_randomness(int irq, int irq_flags);
82018+ unsigned int value) __latent_entropy;
82019+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
82020
82021 extern void get_random_bytes(void *buf, int nbytes);
82022 extern void get_random_bytes_arch(void *buf, int nbytes);
82023@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
82024 extern const struct file_operations random_fops, urandom_fops;
82025 #endif
82026
82027-unsigned int get_random_int(void);
82028+unsigned int __intentional_overflow(-1) get_random_int(void);
82029 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
82030
82031-u32 prandom_u32(void);
82032+u32 prandom_u32(void) __intentional_overflow(-1);
82033 void prandom_bytes(void *buf, int nbytes);
82034 void prandom_seed(u32 seed);
82035 void prandom_reseed_late(void);
82036@@ -37,6 +47,11 @@ struct rnd_state {
82037 u32 prandom_u32_state(struct rnd_state *state);
82038 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
82039
82040+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
82041+{
82042+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
82043+}
82044+
82045 /**
82046 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
82047 * @ep_ro: right open interval endpoint
82048diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
82049index fea49b5..2ac22bb 100644
82050--- a/include/linux/rbtree_augmented.h
82051+++ b/include/linux/rbtree_augmented.h
82052@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
82053 old->rbaugmented = rbcompute(old); \
82054 } \
82055 rbstatic const struct rb_augment_callbacks rbname = { \
82056- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
82057+ .propagate = rbname ## _propagate, \
82058+ .copy = rbname ## _copy, \
82059+ .rotate = rbname ## _rotate \
82060 };
82061
82062
82063diff --git a/include/linux/rculist.h b/include/linux/rculist.h
82064index dbaf990..52e07b8 100644
82065--- a/include/linux/rculist.h
82066+++ b/include/linux/rculist.h
82067@@ -29,8 +29,8 @@
82068 */
82069 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
82070 {
82071- ACCESS_ONCE(list->next) = list;
82072- ACCESS_ONCE(list->prev) = list;
82073+ ACCESS_ONCE_RW(list->next) = list;
82074+ ACCESS_ONCE_RW(list->prev) = list;
82075 }
82076
82077 /*
82078@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
82079 struct list_head *prev, struct list_head *next);
82080 #endif
82081
82082+void __pax_list_add_rcu(struct list_head *new,
82083+ struct list_head *prev, struct list_head *next);
82084+
82085 /**
82086 * list_add_rcu - add a new entry to rcu-protected list
82087 * @new: new entry to be added
82088@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
82089 __list_add_rcu(new, head, head->next);
82090 }
82091
82092+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
82093+{
82094+ __pax_list_add_rcu(new, head, head->next);
82095+}
82096+
82097 /**
82098 * list_add_tail_rcu - add a new entry to rcu-protected list
82099 * @new: new entry to be added
82100@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
82101 __list_add_rcu(new, head->prev, head);
82102 }
82103
82104+static inline void pax_list_add_tail_rcu(struct list_head *new,
82105+ struct list_head *head)
82106+{
82107+ __pax_list_add_rcu(new, head->prev, head);
82108+}
82109+
82110 /**
82111 * list_del_rcu - deletes entry from list without re-initialization
82112 * @entry: the element to delete from the list.
82113@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
82114 entry->prev = LIST_POISON2;
82115 }
82116
82117+extern void pax_list_del_rcu(struct list_head *entry);
82118+
82119 /**
82120 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
82121 * @n: the element to delete from the hash list.
82122diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
82123index 72bf3a0..853347f 100644
82124--- a/include/linux/rcupdate.h
82125+++ b/include/linux/rcupdate.h
82126@@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
82127 #define rcu_assign_pointer(p, v) \
82128 do { \
82129 smp_wmb(); \
82130- ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
82131+ ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
82132 } while (0)
82133
82134
82135diff --git a/include/linux/reboot.h b/include/linux/reboot.h
82136index 9e7db9e..7d4fd72 100644
82137--- a/include/linux/reboot.h
82138+++ b/include/linux/reboot.h
82139@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
82140 */
82141
82142 extern void migrate_to_reboot_cpu(void);
82143-extern void machine_restart(char *cmd);
82144-extern void machine_halt(void);
82145-extern void machine_power_off(void);
82146+extern void machine_restart(char *cmd) __noreturn;
82147+extern void machine_halt(void) __noreturn;
82148+extern void machine_power_off(void) __noreturn;
82149
82150 extern void machine_shutdown(void);
82151 struct pt_regs;
82152@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
82153 */
82154
82155 extern void kernel_restart_prepare(char *cmd);
82156-extern void kernel_restart(char *cmd);
82157-extern void kernel_halt(void);
82158-extern void kernel_power_off(void);
82159+extern void kernel_restart(char *cmd) __noreturn;
82160+extern void kernel_halt(void) __noreturn;
82161+extern void kernel_power_off(void) __noreturn;
82162
82163 extern int C_A_D; /* for sysctl */
82164 void ctrl_alt_del(void);
82165@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
82166 * Emergency restart, callable from an interrupt handler.
82167 */
82168
82169-extern void emergency_restart(void);
82170+extern void emergency_restart(void) __noreturn;
82171 #include <asm/emergency-restart.h>
82172
82173 #endif /* _LINUX_REBOOT_H */
82174diff --git a/include/linux/regset.h b/include/linux/regset.h
82175index 8e0c9fe..ac4d221 100644
82176--- a/include/linux/regset.h
82177+++ b/include/linux/regset.h
82178@@ -161,7 +161,8 @@ struct user_regset {
82179 unsigned int align;
82180 unsigned int bias;
82181 unsigned int core_note_type;
82182-};
82183+} __do_const;
82184+typedef struct user_regset __no_const user_regset_no_const;
82185
82186 /**
82187 * struct user_regset_view - available regsets
82188diff --git a/include/linux/relay.h b/include/linux/relay.h
82189index d7c8359..818daf5 100644
82190--- a/include/linux/relay.h
82191+++ b/include/linux/relay.h
82192@@ -157,7 +157,7 @@ struct rchan_callbacks
82193 * The callback should return 0 if successful, negative if not.
82194 */
82195 int (*remove_buf_file)(struct dentry *dentry);
82196-};
82197+} __no_const;
82198
82199 /*
82200 * CONFIG_RELAY kernel API, kernel/relay.c
82201diff --git a/include/linux/rio.h b/include/linux/rio.h
82202index b71d573..2f940bd 100644
82203--- a/include/linux/rio.h
82204+++ b/include/linux/rio.h
82205@@ -355,7 +355,7 @@ struct rio_ops {
82206 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
82207 u64 rstart, u32 size, u32 flags);
82208 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
82209-};
82210+} __no_const;
82211
82212 #define RIO_RESOURCE_MEM 0x00000100
82213 #define RIO_RESOURCE_DOORBELL 0x00000200
82214diff --git a/include/linux/rmap.h b/include/linux/rmap.h
82215index b66c211..13d2915 100644
82216--- a/include/linux/rmap.h
82217+++ b/include/linux/rmap.h
82218@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
82219 void anon_vma_init(void); /* create anon_vma_cachep */
82220 int anon_vma_prepare(struct vm_area_struct *);
82221 void unlink_anon_vmas(struct vm_area_struct *);
82222-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
82223-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
82224+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
82225+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
82226
82227 static inline void anon_vma_merge(struct vm_area_struct *vma,
82228 struct vm_area_struct *next)
82229diff --git a/include/linux/sched.h b/include/linux/sched.h
82230index ccd0c6f..39c28a4 100644
82231--- a/include/linux/sched.h
82232+++ b/include/linux/sched.h
82233@@ -129,6 +129,7 @@ struct fs_struct;
82234 struct perf_event_context;
82235 struct blk_plug;
82236 struct filename;
82237+struct linux_binprm;
82238
82239 /*
82240 * List of flags we want to share for kernel threads,
82241@@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
82242 extern int in_sched_functions(unsigned long addr);
82243
82244 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
82245-extern signed long schedule_timeout(signed long timeout);
82246+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
82247 extern signed long schedule_timeout_interruptible(signed long timeout);
82248 extern signed long schedule_timeout_killable(signed long timeout);
82249 extern signed long schedule_timeout_uninterruptible(signed long timeout);
82250@@ -380,6 +381,19 @@ struct nsproxy;
82251 struct user_namespace;
82252
82253 #ifdef CONFIG_MMU
82254+
82255+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82256+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
82257+#else
82258+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82259+{
82260+ return 0;
82261+}
82262+#endif
82263+
82264+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
82265+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
82266+
82267 extern void arch_pick_mmap_layout(struct mm_struct *mm);
82268 extern unsigned long
82269 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
82270@@ -677,6 +691,17 @@ struct signal_struct {
82271 #ifdef CONFIG_TASKSTATS
82272 struct taskstats *stats;
82273 #endif
82274+
82275+#ifdef CONFIG_GRKERNSEC
82276+ u32 curr_ip;
82277+ u32 saved_ip;
82278+ u32 gr_saddr;
82279+ u32 gr_daddr;
82280+ u16 gr_sport;
82281+ u16 gr_dport;
82282+ u8 used_accept:1;
82283+#endif
82284+
82285 #ifdef CONFIG_AUDIT
82286 unsigned audit_tty;
82287 unsigned audit_tty_log_passwd;
82288@@ -703,7 +728,7 @@ struct signal_struct {
82289 struct mutex cred_guard_mutex; /* guard against foreign influences on
82290 * credential calculations
82291 * (notably. ptrace) */
82292-};
82293+} __randomize_layout;
82294
82295 /*
82296 * Bits in flags field of signal_struct.
82297@@ -757,6 +782,14 @@ struct user_struct {
82298 struct key *session_keyring; /* UID's default session keyring */
82299 #endif
82300
82301+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
82302+ unsigned char kernel_banned;
82303+#endif
82304+#ifdef CONFIG_GRKERNSEC_BRUTE
82305+ unsigned char suid_banned;
82306+ unsigned long suid_ban_expires;
82307+#endif
82308+
82309 /* Hash table maintenance information */
82310 struct hlist_node uidhash_node;
82311 kuid_t uid;
82312@@ -764,7 +797,7 @@ struct user_struct {
82313 #ifdef CONFIG_PERF_EVENTS
82314 atomic_long_t locked_vm;
82315 #endif
82316-};
82317+} __randomize_layout;
82318
82319 extern int uids_sysfs_init(void);
82320
82321@@ -1286,8 +1319,8 @@ struct task_struct {
82322 struct list_head thread_node;
82323
82324 struct completion *vfork_done; /* for vfork() */
82325- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
82326- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82327+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
82328+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82329
82330 cputime_t utime, stime, utimescaled, stimescaled;
82331 cputime_t gtime;
82332@@ -1312,11 +1345,6 @@ struct task_struct {
82333 struct task_cputime cputime_expires;
82334 struct list_head cpu_timers[3];
82335
82336-/* process credentials */
82337- const struct cred __rcu *real_cred; /* objective and real subjective task
82338- * credentials (COW) */
82339- const struct cred __rcu *cred; /* effective (overridable) subjective task
82340- * credentials (COW) */
82341 char comm[TASK_COMM_LEN]; /* executable name excluding path
82342 - access with [gs]et_task_comm (which lock
82343 it with task_lock())
82344@@ -1333,6 +1361,10 @@ struct task_struct {
82345 #endif
82346 /* CPU-specific state of this task */
82347 struct thread_struct thread;
82348+/* thread_info moved to task_struct */
82349+#ifdef CONFIG_X86
82350+ struct thread_info tinfo;
82351+#endif
82352 /* filesystem information */
82353 struct fs_struct *fs;
82354 /* open file information */
82355@@ -1409,6 +1441,10 @@ struct task_struct {
82356 gfp_t lockdep_reclaim_gfp;
82357 #endif
82358
82359+/* process credentials */
82360+ const struct cred __rcu *real_cred; /* objective and real subjective task
82361+ * credentials (COW) */
82362+
82363 /* journalling filesystem info */
82364 void *journal_info;
82365
82366@@ -1447,6 +1483,10 @@ struct task_struct {
82367 /* cg_list protected by css_set_lock and tsk->alloc_lock */
82368 struct list_head cg_list;
82369 #endif
82370+
82371+ const struct cred __rcu *cred; /* effective (overridable) subjective task
82372+ * credentials (COW) */
82373+
82374 #ifdef CONFIG_FUTEX
82375 struct robust_list_head __user *robust_list;
82376 #ifdef CONFIG_COMPAT
82377@@ -1581,7 +1621,78 @@ struct task_struct {
82378 unsigned int sequential_io;
82379 unsigned int sequential_io_avg;
82380 #endif
82381-};
82382+
82383+#ifdef CONFIG_GRKERNSEC
82384+ /* grsecurity */
82385+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82386+ u64 exec_id;
82387+#endif
82388+#ifdef CONFIG_GRKERNSEC_SETXID
82389+ const struct cred *delayed_cred;
82390+#endif
82391+ struct dentry *gr_chroot_dentry;
82392+ struct acl_subject_label *acl;
82393+ struct acl_subject_label *tmpacl;
82394+ struct acl_role_label *role;
82395+ struct file *exec_file;
82396+ unsigned long brute_expires;
82397+ u16 acl_role_id;
82398+ u8 inherited;
82399+ /* is this the task that authenticated to the special role */
82400+ u8 acl_sp_role;
82401+ u8 is_writable;
82402+ u8 brute;
82403+ u8 gr_is_chrooted;
82404+#endif
82405+
82406+} __randomize_layout;
82407+
82408+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82409+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82410+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82411+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82412+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82413+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82414+
82415+#ifdef CONFIG_PAX_SOFTMODE
82416+extern int pax_softmode;
82417+#endif
82418+
82419+extern int pax_check_flags(unsigned long *);
82420+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82421+
82422+/* if tsk != current then task_lock must be held on it */
82423+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82424+static inline unsigned long pax_get_flags(struct task_struct *tsk)
82425+{
82426+ if (likely(tsk->mm))
82427+ return tsk->mm->pax_flags;
82428+ else
82429+ return 0UL;
82430+}
82431+
82432+/* if tsk != current then task_lock must be held on it */
82433+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82434+{
82435+ if (likely(tsk->mm)) {
82436+ tsk->mm->pax_flags = flags;
82437+ return 0;
82438+ }
82439+ return -EINVAL;
82440+}
82441+#endif
82442+
82443+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82444+extern void pax_set_initial_flags(struct linux_binprm *bprm);
82445+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82446+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82447+#endif
82448+
82449+struct path;
82450+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82451+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82452+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82453+extern void pax_report_refcount_overflow(struct pt_regs *regs);
82454
82455 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82456 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82457@@ -1658,7 +1769,7 @@ struct pid_namespace;
82458 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82459 struct pid_namespace *ns);
82460
82461-static inline pid_t task_pid_nr(struct task_struct *tsk)
82462+static inline pid_t task_pid_nr(const struct task_struct *tsk)
82463 {
82464 return tsk->pid;
82465 }
82466@@ -2006,6 +2117,25 @@ extern u64 sched_clock_cpu(int cpu);
82467
82468 extern void sched_clock_init(void);
82469
82470+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82471+static inline void populate_stack(void)
82472+{
82473+ struct task_struct *curtask = current;
82474+ int c;
82475+ int *ptr = curtask->stack;
82476+ int *end = curtask->stack + THREAD_SIZE;
82477+
82478+ while (ptr < end) {
82479+ c = *(volatile int *)ptr;
82480+ ptr += PAGE_SIZE/sizeof(int);
82481+ }
82482+}
82483+#else
82484+static inline void populate_stack(void)
82485+{
82486+}
82487+#endif
82488+
82489 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
82490 static inline void sched_clock_tick(void)
82491 {
82492@@ -2130,7 +2260,9 @@ void yield(void);
82493 extern struct exec_domain default_exec_domain;
82494
82495 union thread_union {
82496+#ifndef CONFIG_X86
82497 struct thread_info thread_info;
82498+#endif
82499 unsigned long stack[THREAD_SIZE/sizeof(long)];
82500 };
82501
82502@@ -2163,6 +2295,7 @@ extern struct pid_namespace init_pid_ns;
82503 */
82504
82505 extern struct task_struct *find_task_by_vpid(pid_t nr);
82506+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82507 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82508 struct pid_namespace *ns);
82509
82510@@ -2325,7 +2458,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82511 extern void exit_itimers(struct signal_struct *);
82512 extern void flush_itimer_signals(void);
82513
82514-extern void do_group_exit(int);
82515+extern __noreturn void do_group_exit(int);
82516
82517 extern int allow_signal(int);
82518 extern int disallow_signal(int);
82519@@ -2526,9 +2659,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82520
82521 #endif
82522
82523-static inline int object_is_on_stack(void *obj)
82524+static inline int object_starts_on_stack(void *obj)
82525 {
82526- void *stack = task_stack_page(current);
82527+ const void *stack = task_stack_page(current);
82528
82529 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82530 }
82531diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82532index 8045a55..c959cd5 100644
82533--- a/include/linux/sched/sysctl.h
82534+++ b/include/linux/sched/sysctl.h
82535@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82536 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82537
82538 extern int sysctl_max_map_count;
82539+extern unsigned long sysctl_heap_stack_gap;
82540
82541 extern unsigned int sysctl_sched_latency;
82542 extern unsigned int sysctl_sched_min_granularity;
82543diff --git a/include/linux/security.h b/include/linux/security.h
82544index 2fc42d1..4d802f2 100644
82545--- a/include/linux/security.h
82546+++ b/include/linux/security.h
82547@@ -27,6 +27,7 @@
82548 #include <linux/slab.h>
82549 #include <linux/err.h>
82550 #include <linux/string.h>
82551+#include <linux/grsecurity.h>
82552
82553 struct linux_binprm;
82554 struct cred;
82555@@ -116,8 +117,6 @@ struct seq_file;
82556
82557 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82558
82559-void reset_security_ops(void);
82560-
82561 #ifdef CONFIG_MMU
82562 extern unsigned long mmap_min_addr;
82563 extern unsigned long dac_mmap_min_addr;
82564@@ -1719,7 +1718,7 @@ struct security_operations {
82565 struct audit_context *actx);
82566 void (*audit_rule_free) (void *lsmrule);
82567 #endif /* CONFIG_AUDIT */
82568-};
82569+} __randomize_layout;
82570
82571 /* prototypes */
82572 extern int security_init(void);
82573diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82574index dc368b8..e895209 100644
82575--- a/include/linux/semaphore.h
82576+++ b/include/linux/semaphore.h
82577@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82578 }
82579
82580 extern void down(struct semaphore *sem);
82581-extern int __must_check down_interruptible(struct semaphore *sem);
82582+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82583 extern int __must_check down_killable(struct semaphore *sem);
82584 extern int __must_check down_trylock(struct semaphore *sem);
82585 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82586diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82587index 52e0097..383f21d 100644
82588--- a/include/linux/seq_file.h
82589+++ b/include/linux/seq_file.h
82590@@ -27,6 +27,9 @@ struct seq_file {
82591 struct mutex lock;
82592 const struct seq_operations *op;
82593 int poll_event;
82594+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82595+ u64 exec_id;
82596+#endif
82597 #ifdef CONFIG_USER_NS
82598 struct user_namespace *user_ns;
82599 #endif
82600@@ -39,6 +42,7 @@ struct seq_operations {
82601 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82602 int (*show) (struct seq_file *m, void *v);
82603 };
82604+typedef struct seq_operations __no_const seq_operations_no_const;
82605
82606 #define SEQ_SKIP 1
82607
82608@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82609
82610 char *mangle_path(char *s, const char *p, const char *esc);
82611 int seq_open(struct file *, const struct seq_operations *);
82612+int seq_open_restrict(struct file *, const struct seq_operations *);
82613 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82614 loff_t seq_lseek(struct file *, loff_t, int);
82615 int seq_release(struct inode *, struct file *);
82616@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82617 }
82618
82619 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82620+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82621 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82622 int single_release(struct inode *, struct file *);
82623 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82624diff --git a/include/linux/shm.h b/include/linux/shm.h
82625index 1e2cd2e..0288750 100644
82626--- a/include/linux/shm.h
82627+++ b/include/linux/shm.h
82628@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82629
82630 /* The task created the shm object. NULL if the task is dead. */
82631 struct task_struct *shm_creator;
82632+#ifdef CONFIG_GRKERNSEC
82633+ time_t shm_createtime;
82634+ pid_t shm_lapid;
82635+#endif
82636 };
82637
82638 /* shm_mode upper byte flags */
82639diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82640index 15ede6a..80161c3 100644
82641--- a/include/linux/skbuff.h
82642+++ b/include/linux/skbuff.h
82643@@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82644 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82645 int node);
82646 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82647-static inline struct sk_buff *alloc_skb(unsigned int size,
82648+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82649 gfp_t priority)
82650 {
82651 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82652@@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82653 return skb->inner_transport_header - skb->inner_network_header;
82654 }
82655
82656-static inline int skb_network_offset(const struct sk_buff *skb)
82657+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82658 {
82659 return skb_network_header(skb) - skb->data;
82660 }
82661@@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82662 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82663 */
82664 #ifndef NET_SKB_PAD
82665-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82666+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82667 #endif
82668
82669 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82670@@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82671 int *err);
82672 unsigned int datagram_poll(struct file *file, struct socket *sock,
82673 struct poll_table_struct *wait);
82674-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82675+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82676 struct iovec *to, int size);
82677 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82678 struct iovec *iov);
82679@@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
82680 nf_bridge_put(skb->nf_bridge);
82681 skb->nf_bridge = NULL;
82682 #endif
82683+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82684+ skb->nf_trace = 0;
82685+#endif
82686 }
82687
82688 static inline void nf_reset_trace(struct sk_buff *skb)
82689diff --git a/include/linux/slab.h b/include/linux/slab.h
82690index b5b2df6..69f5734 100644
82691--- a/include/linux/slab.h
82692+++ b/include/linux/slab.h
82693@@ -14,15 +14,29 @@
82694 #include <linux/gfp.h>
82695 #include <linux/types.h>
82696 #include <linux/workqueue.h>
82697-
82698+#include <linux/err.h>
82699
82700 /*
82701 * Flags to pass to kmem_cache_create().
82702 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82703 */
82704 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82705+
82706+#ifdef CONFIG_PAX_USERCOPY_SLABS
82707+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82708+#else
82709+#define SLAB_USERCOPY 0x00000000UL
82710+#endif
82711+
82712 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82713 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82714+
82715+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82716+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82717+#else
82718+#define SLAB_NO_SANITIZE 0x00000000UL
82719+#endif
82720+
82721 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82722 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82723 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82724@@ -98,10 +112,13 @@
82725 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82726 * Both make kfree a no-op.
82727 */
82728-#define ZERO_SIZE_PTR ((void *)16)
82729+#define ZERO_SIZE_PTR \
82730+({ \
82731+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82732+ (void *)(-MAX_ERRNO-1L); \
82733+})
82734
82735-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82736- (unsigned long)ZERO_SIZE_PTR)
82737+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82738
82739 #include <linux/kmemleak.h>
82740
82741@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82742 void kfree(const void *);
82743 void kzfree(const void *);
82744 size_t ksize(const void *);
82745+const char *check_heap_object(const void *ptr, unsigned long n);
82746+bool is_usercopy_object(const void *ptr);
82747
82748 /*
82749 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82750@@ -174,7 +193,7 @@ struct kmem_cache {
82751 unsigned int align; /* Alignment as calculated */
82752 unsigned long flags; /* Active flags on the slab */
82753 const char *name; /* Slab name for sysfs */
82754- int refcount; /* Use counter */
82755+ atomic_t refcount; /* Use counter */
82756 void (*ctor)(void *); /* Called on object slot creation */
82757 struct list_head list; /* List of all slab caches on the system */
82758 };
82759@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82760 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82761 #endif
82762
82763+#ifdef CONFIG_PAX_USERCOPY_SLABS
82764+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82765+#endif
82766+
82767 /*
82768 * Figure out which kmalloc slab an allocation of a certain size
82769 * belongs to.
82770@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82771 * 2 = 120 .. 192 bytes
82772 * n = 2^(n-1) .. 2^n -1
82773 */
82774-static __always_inline int kmalloc_index(size_t size)
82775+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82776 {
82777 if (!size)
82778 return 0;
82779@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
82780 }
82781 #endif /* !CONFIG_SLOB */
82782
82783-void *__kmalloc(size_t size, gfp_t flags);
82784+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82785 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82786
82787 #ifdef CONFIG_NUMA
82788-void *__kmalloc_node(size_t size, gfp_t flags, int node);
82789+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82790 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82791 #else
82792 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82793diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82794index 8235dfb..47ce586 100644
82795--- a/include/linux/slab_def.h
82796+++ b/include/linux/slab_def.h
82797@@ -38,7 +38,7 @@ struct kmem_cache {
82798 /* 4) cache creation/removal */
82799 const char *name;
82800 struct list_head list;
82801- int refcount;
82802+ atomic_t refcount;
82803 int object_size;
82804 int align;
82805
82806@@ -54,10 +54,14 @@ struct kmem_cache {
82807 unsigned long node_allocs;
82808 unsigned long node_frees;
82809 unsigned long node_overflow;
82810- atomic_t allochit;
82811- atomic_t allocmiss;
82812- atomic_t freehit;
82813- atomic_t freemiss;
82814+ atomic_unchecked_t allochit;
82815+ atomic_unchecked_t allocmiss;
82816+ atomic_unchecked_t freehit;
82817+ atomic_unchecked_t freemiss;
82818+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82819+ atomic_unchecked_t sanitized;
82820+ atomic_unchecked_t not_sanitized;
82821+#endif
82822
82823 /*
82824 * If debugging is enabled, then the allocator can add additional
82825diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82826index f56bfa9..8378a26 100644
82827--- a/include/linux/slub_def.h
82828+++ b/include/linux/slub_def.h
82829@@ -74,7 +74,7 @@ struct kmem_cache {
82830 struct kmem_cache_order_objects max;
82831 struct kmem_cache_order_objects min;
82832 gfp_t allocflags; /* gfp flags to use on each alloc */
82833- int refcount; /* Refcount for slab cache destroy */
82834+ atomic_t refcount; /* Refcount for slab cache destroy */
82835 void (*ctor)(void *);
82836 int inuse; /* Offset to metadata */
82837 int align; /* Alignment */
82838diff --git a/include/linux/smp.h b/include/linux/smp.h
82839index 6ae004e..2743532 100644
82840--- a/include/linux/smp.h
82841+++ b/include/linux/smp.h
82842@@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
82843 #endif
82844
82845 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82846+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82847 #define put_cpu() preempt_enable()
82848+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82849
82850 /*
82851 * Callback to arch code if there's nosmp or maxcpus=0 on the
82852diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82853index 302ab80..3233276 100644
82854--- a/include/linux/sock_diag.h
82855+++ b/include/linux/sock_diag.h
82856@@ -11,7 +11,7 @@ struct sock;
82857 struct sock_diag_handler {
82858 __u8 family;
82859 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82860-};
82861+} __do_const;
82862
82863 int sock_diag_register(const struct sock_diag_handler *h);
82864 void sock_diag_unregister(const struct sock_diag_handler *h);
82865diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82866index 680f9a3..f13aeb0 100644
82867--- a/include/linux/sonet.h
82868+++ b/include/linux/sonet.h
82869@@ -7,7 +7,7 @@
82870 #include <uapi/linux/sonet.h>
82871
82872 struct k_sonet_stats {
82873-#define __HANDLE_ITEM(i) atomic_t i
82874+#define __HANDLE_ITEM(i) atomic_unchecked_t i
82875 __SONET_ITEMS
82876 #undef __HANDLE_ITEM
82877 };
82878diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82879index 07d8e53..dc934c9 100644
82880--- a/include/linux/sunrpc/addr.h
82881+++ b/include/linux/sunrpc/addr.h
82882@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82883 {
82884 switch (sap->sa_family) {
82885 case AF_INET:
82886- return ntohs(((struct sockaddr_in *)sap)->sin_port);
82887+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82888 case AF_INET6:
82889- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82890+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82891 }
82892 return 0;
82893 }
82894@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82895 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82896 const struct sockaddr *src)
82897 {
82898- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82899+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82900 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82901
82902 dsin->sin_family = ssin->sin_family;
82903@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82904 if (sa->sa_family != AF_INET6)
82905 return 0;
82906
82907- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82908+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82909 }
82910
82911 #endif /* _LINUX_SUNRPC_ADDR_H */
82912diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82913index 8af2804..c7414ef 100644
82914--- a/include/linux/sunrpc/clnt.h
82915+++ b/include/linux/sunrpc/clnt.h
82916@@ -97,7 +97,7 @@ struct rpc_procinfo {
82917 unsigned int p_timer; /* Which RTT timer to use */
82918 u32 p_statidx; /* Which procedure to account */
82919 const char * p_name; /* name of procedure */
82920-};
82921+} __do_const;
82922
82923 #ifdef __KERNEL__
82924
82925diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82926index 04e7632..2e2a8a3 100644
82927--- a/include/linux/sunrpc/svc.h
82928+++ b/include/linux/sunrpc/svc.h
82929@@ -412,7 +412,7 @@ struct svc_procedure {
82930 unsigned int pc_count; /* call count */
82931 unsigned int pc_cachetype; /* cache info (NFS) */
82932 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82933-};
82934+} __do_const;
82935
82936 /*
82937 * Function prototypes.
82938diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82939index 0b8e3e6..33e0a01 100644
82940--- a/include/linux/sunrpc/svc_rdma.h
82941+++ b/include/linux/sunrpc/svc_rdma.h
82942@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82943 extern unsigned int svcrdma_max_requests;
82944 extern unsigned int svcrdma_max_req_size;
82945
82946-extern atomic_t rdma_stat_recv;
82947-extern atomic_t rdma_stat_read;
82948-extern atomic_t rdma_stat_write;
82949-extern atomic_t rdma_stat_sq_starve;
82950-extern atomic_t rdma_stat_rq_starve;
82951-extern atomic_t rdma_stat_rq_poll;
82952-extern atomic_t rdma_stat_rq_prod;
82953-extern atomic_t rdma_stat_sq_poll;
82954-extern atomic_t rdma_stat_sq_prod;
82955+extern atomic_unchecked_t rdma_stat_recv;
82956+extern atomic_unchecked_t rdma_stat_read;
82957+extern atomic_unchecked_t rdma_stat_write;
82958+extern atomic_unchecked_t rdma_stat_sq_starve;
82959+extern atomic_unchecked_t rdma_stat_rq_starve;
82960+extern atomic_unchecked_t rdma_stat_rq_poll;
82961+extern atomic_unchecked_t rdma_stat_rq_prod;
82962+extern atomic_unchecked_t rdma_stat_sq_poll;
82963+extern atomic_unchecked_t rdma_stat_sq_prod;
82964
82965 #define RPCRDMA_VERSION 1
82966
82967diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82968index 8d71d65..f79586e 100644
82969--- a/include/linux/sunrpc/svcauth.h
82970+++ b/include/linux/sunrpc/svcauth.h
82971@@ -120,7 +120,7 @@ struct auth_ops {
82972 int (*release)(struct svc_rqst *rq);
82973 void (*domain_release)(struct auth_domain *);
82974 int (*set_client)(struct svc_rqst *rq);
82975-};
82976+} __do_const;
82977
82978 #define SVC_GARBAGE 1
82979 #define SVC_SYSERR 2
82980diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82981index a5ffd32..0935dea 100644
82982--- a/include/linux/swiotlb.h
82983+++ b/include/linux/swiotlb.h
82984@@ -60,7 +60,8 @@ extern void
82985
82986 extern void
82987 swiotlb_free_coherent(struct device *hwdev, size_t size,
82988- void *vaddr, dma_addr_t dma_handle);
82989+ void *vaddr, dma_addr_t dma_handle,
82990+ struct dma_attrs *attrs);
82991
82992 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82993 unsigned long offset, size_t size,
82994diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82995index a747a77..9e14df7 100644
82996--- a/include/linux/syscalls.h
82997+++ b/include/linux/syscalls.h
82998@@ -98,8 +98,14 @@ struct sigaltstack;
82999 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
83000
83001 #define __SC_DECL(t, a) t a
83002+#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))
83003 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
83004-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
83005+#define __SC_LONG(t, a) __typeof( \
83006+ __builtin_choose_expr( \
83007+ sizeof(t) > sizeof(int), \
83008+ (t) 0, \
83009+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
83010+ )) a
83011 #define __SC_CAST(t, a) (t) a
83012 #define __SC_ARGS(t, a) a
83013 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
83014@@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
83015 asmlinkage long sys_fsync(unsigned int fd);
83016 asmlinkage long sys_fdatasync(unsigned int fd);
83017 asmlinkage long sys_bdflush(int func, long data);
83018-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
83019- char __user *type, unsigned long flags,
83020+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
83021+ const char __user *type, unsigned long flags,
83022 void __user *data);
83023-asmlinkage long sys_umount(char __user *name, int flags);
83024-asmlinkage long sys_oldumount(char __user *name);
83025+asmlinkage long sys_umount(const char __user *name, int flags);
83026+asmlinkage long sys_oldumount(const char __user *name);
83027 asmlinkage long sys_truncate(const char __user *path, long length);
83028 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
83029 asmlinkage long sys_stat(const char __user *filename,
83030@@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
83031 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
83032 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
83033 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
83034- struct sockaddr __user *, int);
83035+ struct sockaddr __user *, int) __intentional_overflow(0);
83036 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
83037 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
83038 unsigned int vlen, unsigned flags);
83039diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
83040index 27b3b0b..e093dd9 100644
83041--- a/include/linux/syscore_ops.h
83042+++ b/include/linux/syscore_ops.h
83043@@ -16,7 +16,7 @@ struct syscore_ops {
83044 int (*suspend)(void);
83045 void (*resume)(void);
83046 void (*shutdown)(void);
83047-};
83048+} __do_const;
83049
83050 extern void register_syscore_ops(struct syscore_ops *ops);
83051 extern void unregister_syscore_ops(struct syscore_ops *ops);
83052diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
83053index 14a8ff2..fa95f3a 100644
83054--- a/include/linux/sysctl.h
83055+++ b/include/linux/sysctl.h
83056@@ -34,13 +34,13 @@ struct ctl_table_root;
83057 struct ctl_table_header;
83058 struct ctl_dir;
83059
83060-typedef struct ctl_table ctl_table;
83061-
83062 typedef int proc_handler (struct ctl_table *ctl, int write,
83063 void __user *buffer, size_t *lenp, loff_t *ppos);
83064
83065 extern int proc_dostring(struct ctl_table *, int,
83066 void __user *, size_t *, loff_t *);
83067+extern int proc_dostring_modpriv(struct ctl_table *, int,
83068+ void __user *, size_t *, loff_t *);
83069 extern int proc_dointvec(struct ctl_table *, int,
83070 void __user *, size_t *, loff_t *);
83071 extern int proc_dointvec_minmax(struct ctl_table *, int,
83072@@ -115,7 +115,9 @@ struct ctl_table
83073 struct ctl_table_poll *poll;
83074 void *extra1;
83075 void *extra2;
83076-};
83077+} __do_const __randomize_layout;
83078+typedef struct ctl_table __no_const ctl_table_no_const;
83079+typedef struct ctl_table ctl_table;
83080
83081 struct ctl_node {
83082 struct rb_node node;
83083diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
83084index 30b2ebe..37412ef 100644
83085--- a/include/linux/sysfs.h
83086+++ b/include/linux/sysfs.h
83087@@ -34,7 +34,8 @@ struct attribute {
83088 struct lock_class_key *key;
83089 struct lock_class_key skey;
83090 #endif
83091-};
83092+} __do_const;
83093+typedef struct attribute __no_const attribute_no_const;
83094
83095 /**
83096 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
83097@@ -63,7 +64,8 @@ struct attribute_group {
83098 struct attribute *, int);
83099 struct attribute **attrs;
83100 struct bin_attribute **bin_attrs;
83101-};
83102+} __do_const;
83103+typedef struct attribute_group __no_const attribute_group_no_const;
83104
83105 /**
83106 * Use these macros to make defining attributes easier. See include/linux/device.h
83107@@ -127,7 +129,8 @@ struct bin_attribute {
83108 char *, loff_t, size_t);
83109 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
83110 struct vm_area_struct *vma);
83111-};
83112+} __do_const;
83113+typedef struct bin_attribute __no_const bin_attribute_no_const;
83114
83115 /**
83116 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
83117diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
83118index 387fa7d..3fcde6b 100644
83119--- a/include/linux/sysrq.h
83120+++ b/include/linux/sysrq.h
83121@@ -16,6 +16,7 @@
83122
83123 #include <linux/errno.h>
83124 #include <linux/types.h>
83125+#include <linux/compiler.h>
83126
83127 /* Possible values of bitmask for enabling sysrq functions */
83128 /* 0x0001 is reserved for enable everything */
83129@@ -33,7 +34,7 @@ struct sysrq_key_op {
83130 char *help_msg;
83131 char *action_msg;
83132 int enable_mask;
83133-};
83134+} __do_const;
83135
83136 #ifdef CONFIG_MAGIC_SYSRQ
83137
83138diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
83139index a629e4b..3fea3d9 100644
83140--- a/include/linux/thread_info.h
83141+++ b/include/linux/thread_info.h
83142@@ -159,6 +159,13 @@ static inline bool test_and_clear_restore_sigmask(void)
83143 #error "no set_restore_sigmask() provided and default one won't work"
83144 #endif
83145
83146+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
83147+
83148+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
83149+{
83150+ __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
83151+}
83152+
83153 #endif /* __KERNEL__ */
83154
83155 #endif /* _LINUX_THREAD_INFO_H */
83156diff --git a/include/linux/tty.h b/include/linux/tty.h
83157index b90b5c2..e23a512 100644
83158--- a/include/linux/tty.h
83159+++ b/include/linux/tty.h
83160@@ -202,7 +202,7 @@ struct tty_port {
83161 const struct tty_port_operations *ops; /* Port operations */
83162 spinlock_t lock; /* Lock protecting tty field */
83163 int blocked_open; /* Waiting to open */
83164- int count; /* Usage count */
83165+ atomic_t count; /* Usage count */
83166 wait_queue_head_t open_wait; /* Open waiters */
83167 wait_queue_head_t close_wait; /* Close waiters */
83168 wait_queue_head_t delta_msr_wait; /* Modem status change */
83169@@ -284,7 +284,7 @@ struct tty_struct {
83170 /* If the tty has a pending do_SAK, queue it here - akpm */
83171 struct work_struct SAK_work;
83172 struct tty_port *port;
83173-};
83174+} __randomize_layout;
83175
83176 /* Each of a tty's open files has private_data pointing to tty_file_private */
83177 struct tty_file_private {
83178@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
83179 struct tty_struct *tty, struct file *filp);
83180 static inline int tty_port_users(struct tty_port *port)
83181 {
83182- return port->count + port->blocked_open;
83183+ return atomic_read(&port->count) + port->blocked_open;
83184 }
83185
83186 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
83187diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
83188index 756a609..89db85e 100644
83189--- a/include/linux/tty_driver.h
83190+++ b/include/linux/tty_driver.h
83191@@ -285,7 +285,7 @@ struct tty_operations {
83192 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
83193 #endif
83194 const struct file_operations *proc_fops;
83195-};
83196+} __do_const __randomize_layout;
83197
83198 struct tty_driver {
83199 int magic; /* magic number for this structure */
83200@@ -319,7 +319,7 @@ struct tty_driver {
83201
83202 const struct tty_operations *ops;
83203 struct list_head tty_drivers;
83204-};
83205+} __randomize_layout;
83206
83207 extern struct list_head tty_drivers;
83208
83209diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
83210index b8347c2..85d8b0f 100644
83211--- a/include/linux/tty_ldisc.h
83212+++ b/include/linux/tty_ldisc.h
83213@@ -213,7 +213,7 @@ struct tty_ldisc_ops {
83214
83215 struct module *owner;
83216
83217- int refcount;
83218+ atomic_t refcount;
83219 };
83220
83221 struct tty_ldisc {
83222diff --git a/include/linux/types.h b/include/linux/types.h
83223index 4d118ba..c3ee9bf 100644
83224--- a/include/linux/types.h
83225+++ b/include/linux/types.h
83226@@ -176,10 +176,26 @@ typedef struct {
83227 int counter;
83228 } atomic_t;
83229
83230+#ifdef CONFIG_PAX_REFCOUNT
83231+typedef struct {
83232+ int counter;
83233+} atomic_unchecked_t;
83234+#else
83235+typedef atomic_t atomic_unchecked_t;
83236+#endif
83237+
83238 #ifdef CONFIG_64BIT
83239 typedef struct {
83240 long counter;
83241 } atomic64_t;
83242+
83243+#ifdef CONFIG_PAX_REFCOUNT
83244+typedef struct {
83245+ long counter;
83246+} atomic64_unchecked_t;
83247+#else
83248+typedef atomic64_t atomic64_unchecked_t;
83249+#endif
83250 #endif
83251
83252 struct list_head {
83253diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
83254index ecd3319..8a36ded 100644
83255--- a/include/linux/uaccess.h
83256+++ b/include/linux/uaccess.h
83257@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
83258 long ret; \
83259 mm_segment_t old_fs = get_fs(); \
83260 \
83261- set_fs(KERNEL_DS); \
83262 pagefault_disable(); \
83263- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
83264- pagefault_enable(); \
83265+ set_fs(KERNEL_DS); \
83266+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
83267 set_fs(old_fs); \
83268+ pagefault_enable(); \
83269 ret; \
83270 })
83271
83272diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
83273index 2d1f9b6..d7a9fce 100644
83274--- a/include/linux/uidgid.h
83275+++ b/include/linux/uidgid.h
83276@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
83277
83278 #endif /* CONFIG_USER_NS */
83279
83280+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
83281+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
83282+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
83283+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
83284+
83285 #endif /* _LINUX_UIDGID_H */
83286diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
83287index 99c1b4d..562e6f3 100644
83288--- a/include/linux/unaligned/access_ok.h
83289+++ b/include/linux/unaligned/access_ok.h
83290@@ -4,34 +4,34 @@
83291 #include <linux/kernel.h>
83292 #include <asm/byteorder.h>
83293
83294-static inline u16 get_unaligned_le16(const void *p)
83295+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
83296 {
83297- return le16_to_cpup((__le16 *)p);
83298+ return le16_to_cpup((const __le16 *)p);
83299 }
83300
83301-static inline u32 get_unaligned_le32(const void *p)
83302+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
83303 {
83304- return le32_to_cpup((__le32 *)p);
83305+ return le32_to_cpup((const __le32 *)p);
83306 }
83307
83308-static inline u64 get_unaligned_le64(const void *p)
83309+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
83310 {
83311- return le64_to_cpup((__le64 *)p);
83312+ return le64_to_cpup((const __le64 *)p);
83313 }
83314
83315-static inline u16 get_unaligned_be16(const void *p)
83316+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
83317 {
83318- return be16_to_cpup((__be16 *)p);
83319+ return be16_to_cpup((const __be16 *)p);
83320 }
83321
83322-static inline u32 get_unaligned_be32(const void *p)
83323+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
83324 {
83325- return be32_to_cpup((__be32 *)p);
83326+ return be32_to_cpup((const __be32 *)p);
83327 }
83328
83329-static inline u64 get_unaligned_be64(const void *p)
83330+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
83331 {
83332- return be64_to_cpup((__be64 *)p);
83333+ return be64_to_cpup((const __be64 *)p);
83334 }
83335
83336 static inline void put_unaligned_le16(u16 val, void *p)
83337diff --git a/include/linux/usb.h b/include/linux/usb.h
83338index 7f6eb85..656e806 100644
83339--- a/include/linux/usb.h
83340+++ b/include/linux/usb.h
83341@@ -563,7 +563,7 @@ struct usb_device {
83342 int maxchild;
83343
83344 u32 quirks;
83345- atomic_t urbnum;
83346+ atomic_unchecked_t urbnum;
83347
83348 unsigned long active_duration;
83349
83350@@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
83351
83352 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
83353 __u8 request, __u8 requesttype, __u16 value, __u16 index,
83354- void *data, __u16 size, int timeout);
83355+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
83356 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
83357 void *data, int len, int *actual_length, int timeout);
83358 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
83359diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
83360index e452ba6..78f8e80 100644
83361--- a/include/linux/usb/renesas_usbhs.h
83362+++ b/include/linux/usb/renesas_usbhs.h
83363@@ -39,7 +39,7 @@ enum {
83364 */
83365 struct renesas_usbhs_driver_callback {
83366 int (*notify_hotplug)(struct platform_device *pdev);
83367-};
83368+} __no_const;
83369
83370 /*
83371 * callback functions for platform
83372diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83373index 4836ba3..603f6ee 100644
83374--- a/include/linux/user_namespace.h
83375+++ b/include/linux/user_namespace.h
83376@@ -33,7 +33,7 @@ struct user_namespace {
83377 struct key *persistent_keyring_register;
83378 struct rw_semaphore persistent_keyring_register_sem;
83379 #endif
83380-};
83381+} __randomize_layout;
83382
83383 extern struct user_namespace init_user_ns;
83384
83385diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83386index 239e277..22a5cf5 100644
83387--- a/include/linux/utsname.h
83388+++ b/include/linux/utsname.h
83389@@ -24,7 +24,7 @@ struct uts_namespace {
83390 struct new_utsname name;
83391 struct user_namespace *user_ns;
83392 unsigned int proc_inum;
83393-};
83394+} __randomize_layout;
83395 extern struct uts_namespace init_uts_ns;
83396
83397 #ifdef CONFIG_UTS_NS
83398diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83399index 6f8fbcf..4efc177 100644
83400--- a/include/linux/vermagic.h
83401+++ b/include/linux/vermagic.h
83402@@ -25,9 +25,42 @@
83403 #define MODULE_ARCH_VERMAGIC ""
83404 #endif
83405
83406+#ifdef CONFIG_PAX_REFCOUNT
83407+#define MODULE_PAX_REFCOUNT "REFCOUNT "
83408+#else
83409+#define MODULE_PAX_REFCOUNT ""
83410+#endif
83411+
83412+#ifdef CONSTIFY_PLUGIN
83413+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83414+#else
83415+#define MODULE_CONSTIFY_PLUGIN ""
83416+#endif
83417+
83418+#ifdef STACKLEAK_PLUGIN
83419+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83420+#else
83421+#define MODULE_STACKLEAK_PLUGIN ""
83422+#endif
83423+
83424+#ifdef RANDSTRUCT_PLUGIN
83425+#include <generated/randomize_layout_hash.h>
83426+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83427+#else
83428+#define MODULE_RANDSTRUCT_PLUGIN
83429+#endif
83430+
83431+#ifdef CONFIG_GRKERNSEC
83432+#define MODULE_GRSEC "GRSEC "
83433+#else
83434+#define MODULE_GRSEC ""
83435+#endif
83436+
83437 #define VERMAGIC_STRING \
83438 UTS_RELEASE " " \
83439 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83440 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83441- MODULE_ARCH_VERMAGIC
83442+ MODULE_ARCH_VERMAGIC \
83443+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83444+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83445
83446diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83447index 502073a..a7de024 100644
83448--- a/include/linux/vga_switcheroo.h
83449+++ b/include/linux/vga_switcheroo.h
83450@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83451
83452 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83453
83454-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83455-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83456+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83457+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83458 #else
83459
83460 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83461@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83462
83463 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83464
83465-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83466-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83467+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83468+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83469
83470 #endif
83471 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83472diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83473index 4b8a891..05f2361 100644
83474--- a/include/linux/vmalloc.h
83475+++ b/include/linux/vmalloc.h
83476@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83477 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83478 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83479 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83480+
83481+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83482+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83483+#endif
83484+
83485 /* bits [20..32] reserved for arch specific ioremap internals */
83486
83487 /*
83488@@ -72,6 +77,7 @@ extern void *vzalloc_node(unsigned long size, int node);
83489 extern void *vmalloc_exec(unsigned long size);
83490 extern void *vmalloc_32(unsigned long size);
83491 extern void *vmalloc_32_user(unsigned long size);
83492+extern void *vmalloc_stack(int node);
83493 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
83494 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
83495 unsigned long start, unsigned long end, gfp_t gfp_mask,
83496@@ -142,7 +148,7 @@ extern void free_vm_area(struct vm_struct *area);
83497
83498 /* for /dev/kmem */
83499 extern long vread(char *buf, char *addr, unsigned long count);
83500-extern long vwrite(char *buf, char *addr, unsigned long count);
83501+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83502
83503 /*
83504 * Internals. Dont't use..
83505diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83506index 67ce70c..d540954 100644
83507--- a/include/linux/vmstat.h
83508+++ b/include/linux/vmstat.h
83509@@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
83510 /*
83511 * Zone based page accounting with per cpu differentials.
83512 */
83513-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83514+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83515
83516 static inline void zone_page_state_add(long x, struct zone *zone,
83517 enum zone_stat_item item)
83518 {
83519- atomic_long_add(x, &zone->vm_stat[item]);
83520- atomic_long_add(x, &vm_stat[item]);
83521+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83522+ atomic_long_add_unchecked(x, &vm_stat[item]);
83523 }
83524
83525-static inline unsigned long global_page_state(enum zone_stat_item item)
83526+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83527 {
83528- long x = atomic_long_read(&vm_stat[item]);
83529+ long x = atomic_long_read_unchecked(&vm_stat[item]);
83530 #ifdef CONFIG_SMP
83531 if (x < 0)
83532 x = 0;
83533@@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83534 return x;
83535 }
83536
83537-static inline unsigned long zone_page_state(struct zone *zone,
83538+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83539 enum zone_stat_item item)
83540 {
83541- long x = atomic_long_read(&zone->vm_stat[item]);
83542+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83543 #ifdef CONFIG_SMP
83544 if (x < 0)
83545 x = 0;
83546@@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83547 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83548 enum zone_stat_item item)
83549 {
83550- long x = atomic_long_read(&zone->vm_stat[item]);
83551+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83552
83553 #ifdef CONFIG_SMP
83554 int cpu;
83555@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
83556
83557 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83558 {
83559- atomic_long_inc(&zone->vm_stat[item]);
83560- atomic_long_inc(&vm_stat[item]);
83561+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
83562+ atomic_long_inc_unchecked(&vm_stat[item]);
83563 }
83564
83565 static inline void __inc_zone_page_state(struct page *page,
83566@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
83567
83568 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83569 {
83570- atomic_long_dec(&zone->vm_stat[item]);
83571- atomic_long_dec(&vm_stat[item]);
83572+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
83573+ atomic_long_dec_unchecked(&vm_stat[item]);
83574 }
83575
83576 static inline void __dec_zone_page_state(struct page *page,
83577diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83578index 91b0a68..0e9adf6 100644
83579--- a/include/linux/xattr.h
83580+++ b/include/linux/xattr.h
83581@@ -28,7 +28,7 @@ struct xattr_handler {
83582 size_t size, int handler_flags);
83583 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83584 size_t size, int flags, int handler_flags);
83585-};
83586+} __do_const;
83587
83588 struct xattr {
83589 const char *name;
83590@@ -37,6 +37,9 @@ struct xattr {
83591 };
83592
83593 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83594+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83595+ssize_t pax_getxattr(struct dentry *, void *, size_t);
83596+#endif
83597 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83598 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83599 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83600diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83601index 9c5a6b4..09c9438 100644
83602--- a/include/linux/zlib.h
83603+++ b/include/linux/zlib.h
83604@@ -31,6 +31,7 @@
83605 #define _ZLIB_H
83606
83607 #include <linux/zconf.h>
83608+#include <linux/compiler.h>
83609
83610 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83611 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83612@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83613
83614 /* basic functions */
83615
83616-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83617+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83618 /*
83619 Returns the number of bytes that needs to be allocated for a per-
83620 stream workspace with the specified parameters. A pointer to this
83621diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83622index c768c9f..bdcaa5a 100644
83623--- a/include/media/v4l2-dev.h
83624+++ b/include/media/v4l2-dev.h
83625@@ -76,7 +76,7 @@ struct v4l2_file_operations {
83626 int (*mmap) (struct file *, struct vm_area_struct *);
83627 int (*open) (struct file *);
83628 int (*release) (struct file *);
83629-};
83630+} __do_const;
83631
83632 /*
83633 * Newer version of video_device, handled by videodev2.c
83634diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83635index c9b1593..a572459 100644
83636--- a/include/media/v4l2-device.h
83637+++ b/include/media/v4l2-device.h
83638@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83639 this function returns 0. If the name ends with a digit (e.g. cx18),
83640 then the name will be set to cx18-0 since cx180 looks really odd. */
83641 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83642- atomic_t *instance);
83643+ atomic_unchecked_t *instance);
83644
83645 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83646 Since the parent disappears this ensures that v4l2_dev doesn't have an
83647diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83648index 9a36d92..0aafe2a 100644
83649--- a/include/net/9p/transport.h
83650+++ b/include/net/9p/transport.h
83651@@ -60,7 +60,7 @@ struct p9_trans_module {
83652 int (*cancel) (struct p9_client *, struct p9_req_t *req);
83653 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83654 char *, char *, int , int, int, int);
83655-};
83656+} __do_const;
83657
83658 void v9fs_register_trans(struct p9_trans_module *m);
83659 void v9fs_unregister_trans(struct p9_trans_module *m);
83660diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83661index a175ba4..196eb82 100644
83662--- a/include/net/af_unix.h
83663+++ b/include/net/af_unix.h
83664@@ -36,7 +36,7 @@ struct unix_skb_parms {
83665 u32 secid; /* Security ID */
83666 #endif
83667 u32 consumed;
83668-};
83669+} __randomize_layout;
83670
83671 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83672 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83673diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83674index dbc4a89..4a59b5d 100644
83675--- a/include/net/bluetooth/l2cap.h
83676+++ b/include/net/bluetooth/l2cap.h
83677@@ -600,7 +600,7 @@ struct l2cap_ops {
83678 long (*get_sndtimeo) (struct l2cap_chan *chan);
83679 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83680 unsigned long len, int nb);
83681-};
83682+} __do_const;
83683
83684 struct l2cap_conn {
83685 struct hci_conn *hcon;
83686diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83687index f2ae33d..c457cf0 100644
83688--- a/include/net/caif/cfctrl.h
83689+++ b/include/net/caif/cfctrl.h
83690@@ -52,7 +52,7 @@ struct cfctrl_rsp {
83691 void (*radioset_rsp)(void);
83692 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83693 struct cflayer *client_layer);
83694-};
83695+} __no_const;
83696
83697 /* Link Setup Parameters for CAIF-Links. */
83698 struct cfctrl_link_param {
83699@@ -101,8 +101,8 @@ struct cfctrl_request_info {
83700 struct cfctrl {
83701 struct cfsrvl serv;
83702 struct cfctrl_rsp res;
83703- atomic_t req_seq_no;
83704- atomic_t rsp_seq_no;
83705+ atomic_unchecked_t req_seq_no;
83706+ atomic_unchecked_t rsp_seq_no;
83707 struct list_head list;
83708 /* Protects from simultaneous access to first_req list */
83709 spinlock_t info_list_lock;
83710diff --git a/include/net/flow.h b/include/net/flow.h
83711index d23e7fa..e188307 100644
83712--- a/include/net/flow.h
83713+++ b/include/net/flow.h
83714@@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
83715
83716 void flow_cache_flush(void);
83717 void flow_cache_flush_deferred(void);
83718-extern atomic_t flow_cache_genid;
83719+extern atomic_unchecked_t flow_cache_genid;
83720
83721 #endif
83722diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83723index 93695f0..766d71c 100644
83724--- a/include/net/genetlink.h
83725+++ b/include/net/genetlink.h
83726@@ -120,7 +120,7 @@ struct genl_ops {
83727 u8 cmd;
83728 u8 internal_flags;
83729 u8 flags;
83730-};
83731+} __do_const;
83732
83733 int __genl_register_family(struct genl_family *family);
83734
83735diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83736index 734d9b5..48a9a4b 100644
83737--- a/include/net/gro_cells.h
83738+++ b/include/net/gro_cells.h
83739@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83740 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83741
83742 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83743- atomic_long_inc(&dev->rx_dropped);
83744+ atomic_long_inc_unchecked(&dev->rx_dropped);
83745 kfree_skb(skb);
83746 return;
83747 }
83748diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83749index c55aeed..b3393f4 100644
83750--- a/include/net/inet_connection_sock.h
83751+++ b/include/net/inet_connection_sock.h
83752@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83753 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83754 int (*bind_conflict)(const struct sock *sk,
83755 const struct inet_bind_bucket *tb, bool relax);
83756-};
83757+} __do_const;
83758
83759 /** inet_connection_sock - INET connection oriented sock
83760 *
83761diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83762index 6efe73c..1a44af7 100644
83763--- a/include/net/inetpeer.h
83764+++ b/include/net/inetpeer.h
83765@@ -47,8 +47,8 @@ struct inet_peer {
83766 */
83767 union {
83768 struct {
83769- atomic_t rid; /* Frag reception counter */
83770- atomic_t ip_id_count; /* IP ID for the next packet */
83771+ atomic_unchecked_t rid; /* Frag reception counter */
83772+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83773 };
83774 struct rcu_head rcu;
83775 struct inet_peer *gc_next;
83776@@ -177,16 +177,9 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
83777 /* can be called with or without local BH being disabled */
83778 static inline int inet_getid(struct inet_peer *p, int more)
83779 {
83780- int old, new;
83781 more++;
83782 inet_peer_refcheck(p);
83783- do {
83784- old = atomic_read(&p->ip_id_count);
83785- new = old + more;
83786- if (!new)
83787- new = 1;
83788- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
83789- return new;
83790+ return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
83791 }
83792
83793 #endif /* _NET_INETPEER_H */
83794diff --git a/include/net/ip.h b/include/net/ip.h
83795index 23be0fd..0cb3e2c 100644
83796--- a/include/net/ip.h
83797+++ b/include/net/ip.h
83798@@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83799
83800 void inet_get_local_port_range(struct net *net, int *low, int *high);
83801
83802-extern unsigned long *sysctl_local_reserved_ports;
83803+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83804 static inline int inet_is_reserved_local_port(int port)
83805 {
83806 return test_bit(port, sysctl_local_reserved_ports);
83807diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83808index 9922093..a1755d6 100644
83809--- a/include/net/ip_fib.h
83810+++ b/include/net/ip_fib.h
83811@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83812
83813 #define FIB_RES_SADDR(net, res) \
83814 ((FIB_RES_NH(res).nh_saddr_genid == \
83815- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83816+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83817 FIB_RES_NH(res).nh_saddr : \
83818 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83819 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83820diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83821index 5679d92..2e7a690 100644
83822--- a/include/net/ip_vs.h
83823+++ b/include/net/ip_vs.h
83824@@ -558,7 +558,7 @@ struct ip_vs_conn {
83825 struct ip_vs_conn *control; /* Master control connection */
83826 atomic_t n_control; /* Number of controlled ones */
83827 struct ip_vs_dest *dest; /* real server */
83828- atomic_t in_pkts; /* incoming packet counter */
83829+ atomic_unchecked_t in_pkts; /* incoming packet counter */
83830
83831 /* packet transmitter for different forwarding methods. If it
83832 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83833@@ -705,7 +705,7 @@ struct ip_vs_dest {
83834 __be16 port; /* port number of the server */
83835 union nf_inet_addr addr; /* IP address of the server */
83836 volatile unsigned int flags; /* dest status flags */
83837- atomic_t conn_flags; /* flags to copy to conn */
83838+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
83839 atomic_t weight; /* server weight */
83840
83841 atomic_t refcnt; /* reference counter */
83842@@ -960,11 +960,11 @@ struct netns_ipvs {
83843 /* ip_vs_lblc */
83844 int sysctl_lblc_expiration;
83845 struct ctl_table_header *lblc_ctl_header;
83846- struct ctl_table *lblc_ctl_table;
83847+ ctl_table_no_const *lblc_ctl_table;
83848 /* ip_vs_lblcr */
83849 int sysctl_lblcr_expiration;
83850 struct ctl_table_header *lblcr_ctl_header;
83851- struct ctl_table *lblcr_ctl_table;
83852+ ctl_table_no_const *lblcr_ctl_table;
83853 /* ip_vs_est */
83854 struct list_head est_list; /* estimator list */
83855 spinlock_t est_lock;
83856diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83857index 8d4f588..2e37ad2 100644
83858--- a/include/net/irda/ircomm_tty.h
83859+++ b/include/net/irda/ircomm_tty.h
83860@@ -33,6 +33,7 @@
83861 #include <linux/termios.h>
83862 #include <linux/timer.h>
83863 #include <linux/tty.h> /* struct tty_struct */
83864+#include <asm/local.h>
83865
83866 #include <net/irda/irias_object.h>
83867 #include <net/irda/ircomm_core.h>
83868diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83869index 714cc9a..ea05f3e 100644
83870--- a/include/net/iucv/af_iucv.h
83871+++ b/include/net/iucv/af_iucv.h
83872@@ -149,7 +149,7 @@ struct iucv_skb_cb {
83873 struct iucv_sock_list {
83874 struct hlist_head head;
83875 rwlock_t lock;
83876- atomic_t autobind_name;
83877+ atomic_unchecked_t autobind_name;
83878 };
83879
83880 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83881diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83882index f3be818..bf46196 100644
83883--- a/include/net/llc_c_ac.h
83884+++ b/include/net/llc_c_ac.h
83885@@ -87,7 +87,7 @@
83886 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83887 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83888
83889-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83890+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83891
83892 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83893 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83894diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83895index 3948cf1..83b28c4 100644
83896--- a/include/net/llc_c_ev.h
83897+++ b/include/net/llc_c_ev.h
83898@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83899 return (struct llc_conn_state_ev *)skb->cb;
83900 }
83901
83902-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83903-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83904+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83905+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83906
83907 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83908 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83909diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83910index 0e79cfb..f46db31 100644
83911--- a/include/net/llc_c_st.h
83912+++ b/include/net/llc_c_st.h
83913@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83914 u8 next_state;
83915 llc_conn_ev_qfyr_t *ev_qualifiers;
83916 llc_conn_action_t *ev_actions;
83917-};
83918+} __do_const;
83919
83920 struct llc_conn_state {
83921 u8 current_state;
83922diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83923index a61b98c..aade1eb 100644
83924--- a/include/net/llc_s_ac.h
83925+++ b/include/net/llc_s_ac.h
83926@@ -23,7 +23,7 @@
83927 #define SAP_ACT_TEST_IND 9
83928
83929 /* All action functions must look like this */
83930-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83931+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83932
83933 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83934 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83935diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83936index 567c681..cd73ac02 100644
83937--- a/include/net/llc_s_st.h
83938+++ b/include/net/llc_s_st.h
83939@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83940 llc_sap_ev_t ev;
83941 u8 next_state;
83942 llc_sap_action_t *ev_actions;
83943-};
83944+} __do_const;
83945
83946 struct llc_sap_state {
83947 u8 curr_state;
83948diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83949index f4ab2fb..71a85ba 100644
83950--- a/include/net/mac80211.h
83951+++ b/include/net/mac80211.h
83952@@ -4476,7 +4476,7 @@ struct rate_control_ops {
83953 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83954 struct dentry *dir);
83955 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83956-};
83957+} __do_const;
83958
83959 static inline int rate_supported(struct ieee80211_sta *sta,
83960 enum ieee80211_band band,
83961diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83962index 7277caf..fd095bc 100644
83963--- a/include/net/neighbour.h
83964+++ b/include/net/neighbour.h
83965@@ -163,7 +163,7 @@ struct neigh_ops {
83966 void (*error_report)(struct neighbour *, struct sk_buff *);
83967 int (*output)(struct neighbour *, struct sk_buff *);
83968 int (*connected_output)(struct neighbour *, struct sk_buff *);
83969-};
83970+} __do_const;
83971
83972 struct pneigh_entry {
83973 struct pneigh_entry *next;
83974@@ -203,7 +203,6 @@ struct neigh_table {
83975 void (*proxy_redo)(struct sk_buff *skb);
83976 char *id;
83977 struct neigh_parms parms;
83978- /* HACK. gc_* should follow parms without a gap! */
83979 int gc_interval;
83980 int gc_thresh1;
83981 int gc_thresh2;
83982@@ -218,7 +217,7 @@ struct neigh_table {
83983 struct neigh_statistics __percpu *stats;
83984 struct neigh_hash_table __rcu *nht;
83985 struct pneigh_entry **phash_buckets;
83986-};
83987+} __randomize_layout;
83988
83989 static inline int neigh_parms_family(struct neigh_parms *p)
83990 {
83991diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83992index 991dcd9..ab58d00 100644
83993--- a/include/net/net_namespace.h
83994+++ b/include/net/net_namespace.h
83995@@ -124,8 +124,8 @@ struct net {
83996 struct netns_ipvs *ipvs;
83997 #endif
83998 struct sock *diag_nlsk;
83999- atomic_t fnhe_genid;
84000-};
84001+ atomic_unchecked_t fnhe_genid;
84002+} __randomize_layout;
84003
84004 /*
84005 * ifindex generation is per-net namespace, and loopback is
84006@@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
84007 #define __net_init __init
84008 #define __net_exit __exit_refok
84009 #define __net_initdata __initdata
84010+#ifdef CONSTIFY_PLUGIN
84011 #define __net_initconst __initconst
84012+#else
84013+#define __net_initconst __initdata
84014+#endif
84015 #endif
84016
84017 struct pernet_operations {
84018@@ -299,7 +303,7 @@ struct pernet_operations {
84019 void (*exit_batch)(struct list_head *net_exit_list);
84020 int *id;
84021 size_t size;
84022-};
84023+} __do_const;
84024
84025 /*
84026 * Use these carefully. If you implement a network device and it
84027@@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
84028
84029 static inline int rt_genid_ipv4(struct net *net)
84030 {
84031- return atomic_read(&net->ipv4.rt_genid);
84032+ return atomic_read_unchecked(&net->ipv4.rt_genid);
84033 }
84034
84035 static inline void rt_genid_bump_ipv4(struct net *net)
84036 {
84037- atomic_inc(&net->ipv4.rt_genid);
84038+ atomic_inc_unchecked(&net->ipv4.rt_genid);
84039 }
84040
84041 #if IS_ENABLED(CONFIG_IPV6)
84042 static inline int rt_genid_ipv6(struct net *net)
84043 {
84044- return atomic_read(&net->ipv6.rt_genid);
84045+ return atomic_read_unchecked(&net->ipv6.rt_genid);
84046 }
84047
84048 static inline void rt_genid_bump_ipv6(struct net *net)
84049 {
84050- atomic_inc(&net->ipv6.rt_genid);
84051+ atomic_inc_unchecked(&net->ipv6.rt_genid);
84052 }
84053 #else
84054 static inline int rt_genid_ipv6(struct net *net)
84055@@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
84056
84057 static inline int fnhe_genid(struct net *net)
84058 {
84059- return atomic_read(&net->fnhe_genid);
84060+ return atomic_read_unchecked(&net->fnhe_genid);
84061 }
84062
84063 static inline void fnhe_genid_bump(struct net *net)
84064 {
84065- atomic_inc(&net->fnhe_genid);
84066+ atomic_inc_unchecked(&net->fnhe_genid);
84067 }
84068
84069 #endif /* __NET_NET_NAMESPACE_H */
84070diff --git a/include/net/netdma.h b/include/net/netdma.h
84071index 8ba8ce2..99b7fff 100644
84072--- a/include/net/netdma.h
84073+++ b/include/net/netdma.h
84074@@ -24,7 +24,7 @@
84075 #include <linux/dmaengine.h>
84076 #include <linux/skbuff.h>
84077
84078-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
84079+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
84080 struct sk_buff *skb, int offset, struct iovec *to,
84081 size_t len, struct dma_pinned_list *pinned_list);
84082
84083diff --git a/include/net/netlink.h b/include/net/netlink.h
84084index 2b47eaa..6d5bcc2 100644
84085--- a/include/net/netlink.h
84086+++ b/include/net/netlink.h
84087@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
84088 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
84089 {
84090 if (mark)
84091- skb_trim(skb, (unsigned char *) mark - skb->data);
84092+ skb_trim(skb, (const unsigned char *) mark - skb->data);
84093 }
84094
84095 /**
84096diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
84097index fbcc7fa..03c7e51 100644
84098--- a/include/net/netns/conntrack.h
84099+++ b/include/net/netns/conntrack.h
84100@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
84101 struct nf_proto_net {
84102 #ifdef CONFIG_SYSCTL
84103 struct ctl_table_header *ctl_table_header;
84104- struct ctl_table *ctl_table;
84105+ ctl_table_no_const *ctl_table;
84106 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
84107 struct ctl_table_header *ctl_compat_header;
84108- struct ctl_table *ctl_compat_table;
84109+ ctl_table_no_const *ctl_compat_table;
84110 #endif
84111 #endif
84112 unsigned int users;
84113@@ -58,7 +58,7 @@ struct nf_ip_net {
84114 struct nf_icmp_net icmpv6;
84115 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
84116 struct ctl_table_header *ctl_table_header;
84117- struct ctl_table *ctl_table;
84118+ ctl_table_no_const *ctl_table;
84119 #endif
84120 };
84121
84122diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
84123index 80f500a..f0c23c2 100644
84124--- a/include/net/netns/ipv4.h
84125+++ b/include/net/netns/ipv4.h
84126@@ -74,7 +74,7 @@ struct netns_ipv4 {
84127
84128 kgid_t sysctl_ping_group_range[2];
84129
84130- atomic_t dev_addr_genid;
84131+ atomic_unchecked_t dev_addr_genid;
84132
84133 #ifdef CONFIG_IP_MROUTE
84134 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
84135@@ -84,6 +84,6 @@ struct netns_ipv4 {
84136 struct fib_rules_ops *mr_rules_ops;
84137 #endif
84138 #endif
84139- atomic_t rt_genid;
84140+ atomic_unchecked_t rt_genid;
84141 };
84142 #endif
84143diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
84144index 21edaf1..4c5faae 100644
84145--- a/include/net/netns/ipv6.h
84146+++ b/include/net/netns/ipv6.h
84147@@ -73,8 +73,8 @@ struct netns_ipv6 {
84148 struct fib_rules_ops *mr6_rules_ops;
84149 #endif
84150 #endif
84151- atomic_t dev_addr_genid;
84152- atomic_t rt_genid;
84153+ atomic_unchecked_t dev_addr_genid;
84154+ atomic_unchecked_t rt_genid;
84155 };
84156
84157 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
84158diff --git a/include/net/ping.h b/include/net/ping.h
84159index 026479b..d9b2829 100644
84160--- a/include/net/ping.h
84161+++ b/include/net/ping.h
84162@@ -54,7 +54,7 @@ struct ping_iter_state {
84163
84164 extern struct proto ping_prot;
84165 #if IS_ENABLED(CONFIG_IPV6)
84166-extern struct pingv6_ops pingv6_ops;
84167+extern struct pingv6_ops *pingv6_ops;
84168 #endif
84169
84170 struct pingfakehdr {
84171diff --git a/include/net/protocol.h b/include/net/protocol.h
84172index a7e986b..dc67bce 100644
84173--- a/include/net/protocol.h
84174+++ b/include/net/protocol.h
84175@@ -49,7 +49,7 @@ struct net_protocol {
84176 * socket lookup?
84177 */
84178 icmp_strict_tag_validation:1;
84179-};
84180+} __do_const;
84181
84182 #if IS_ENABLED(CONFIG_IPV6)
84183 struct inet6_protocol {
84184@@ -62,7 +62,7 @@ struct inet6_protocol {
84185 u8 type, u8 code, int offset,
84186 __be32 info);
84187 unsigned int flags; /* INET6_PROTO_xxx */
84188-};
84189+} __do_const;
84190
84191 #define INET6_PROTO_NOPOLICY 0x1
84192 #define INET6_PROTO_FINAL 0x2
84193diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
84194index 661e45d..54c39df 100644
84195--- a/include/net/rtnetlink.h
84196+++ b/include/net/rtnetlink.h
84197@@ -93,7 +93,7 @@ struct rtnl_link_ops {
84198 int (*fill_slave_info)(struct sk_buff *skb,
84199 const struct net_device *dev,
84200 const struct net_device *slave_dev);
84201-};
84202+} __do_const;
84203
84204 int __rtnl_link_register(struct rtnl_link_ops *ops);
84205 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
84206diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
84207index 4a5b9a3..ca27d73 100644
84208--- a/include/net/sctp/checksum.h
84209+++ b/include/net/sctp/checksum.h
84210@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
84211 unsigned int offset)
84212 {
84213 struct sctphdr *sh = sctp_hdr(skb);
84214- __le32 ret, old = sh->checksum;
84215- const struct skb_checksum_ops ops = {
84216+ __le32 ret, old = sh->checksum;
84217+ static const struct skb_checksum_ops ops = {
84218 .update = sctp_csum_update,
84219 .combine = sctp_csum_combine,
84220 };
84221diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
84222index 7f4eeb3..37e8fe1 100644
84223--- a/include/net/sctp/sm.h
84224+++ b/include/net/sctp/sm.h
84225@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
84226 typedef struct {
84227 sctp_state_fn_t *fn;
84228 const char *name;
84229-} sctp_sm_table_entry_t;
84230+} __do_const sctp_sm_table_entry_t;
84231
84232 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
84233 * currently in use.
84234@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
84235 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
84236
84237 /* Extern declarations for major data structures. */
84238-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84239+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84240
84241
84242 /* Get the size of a DATA chunk payload. */
84243diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
84244index 0dfcc92..7967849 100644
84245--- a/include/net/sctp/structs.h
84246+++ b/include/net/sctp/structs.h
84247@@ -507,7 +507,7 @@ struct sctp_pf {
84248 struct sctp_association *asoc);
84249 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
84250 struct sctp_af *af;
84251-};
84252+} __do_const;
84253
84254
84255 /* Structure to track chunk fragments that have been acked, but peer
84256diff --git a/include/net/sock.h b/include/net/sock.h
84257index b9586a1..b2948c0 100644
84258--- a/include/net/sock.h
84259+++ b/include/net/sock.h
84260@@ -348,7 +348,7 @@ struct sock {
84261 unsigned int sk_napi_id;
84262 unsigned int sk_ll_usec;
84263 #endif
84264- atomic_t sk_drops;
84265+ atomic_unchecked_t sk_drops;
84266 int sk_rcvbuf;
84267
84268 struct sk_filter __rcu *sk_filter;
84269@@ -1036,7 +1036,7 @@ struct proto {
84270 void (*destroy_cgroup)(struct mem_cgroup *memcg);
84271 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
84272 #endif
84273-};
84274+} __randomize_layout;
84275
84276 /*
84277 * Bits in struct cg_proto.flags
84278@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
84279 return ret >> PAGE_SHIFT;
84280 }
84281
84282-static inline long
84283+static inline long __intentional_overflow(-1)
84284 sk_memory_allocated(const struct sock *sk)
84285 {
84286 struct proto *prot = sk->sk_prot;
84287@@ -1368,7 +1368,7 @@ struct sock_iocb {
84288 struct scm_cookie *scm;
84289 struct msghdr *msg, async_msg;
84290 struct kiocb *kiocb;
84291-};
84292+} __randomize_layout;
84293
84294 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
84295 {
84296@@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
84297 }
84298
84299 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
84300- char __user *from, char *to,
84301+ char __user *from, unsigned char *to,
84302 int copy, int offset)
84303 {
84304 if (skb->ip_summed == CHECKSUM_NONE) {
84305@@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
84306 }
84307 }
84308
84309-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84310+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84311
84312 /**
84313 * sk_page_frag - return an appropriate page_frag
84314diff --git a/include/net/tcp.h b/include/net/tcp.h
84315index 743acce..44a58b0 100644
84316--- a/include/net/tcp.h
84317+++ b/include/net/tcp.h
84318@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
84319 void tcp_xmit_retransmit_queue(struct sock *);
84320 void tcp_simple_retransmit(struct sock *);
84321 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
84322-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84323+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84324
84325 void tcp_send_probe0(struct sock *);
84326 void tcp_send_partial(struct sock *);
84327@@ -710,8 +710,8 @@ struct tcp_skb_cb {
84328 struct inet6_skb_parm h6;
84329 #endif
84330 } header; /* For incoming frames */
84331- __u32 seq; /* Starting sequence number */
84332- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
84333+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
84334+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
84335 __u32 when; /* used to compute rtt's */
84336 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
84337
84338@@ -725,7 +725,7 @@ struct tcp_skb_cb {
84339
84340 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
84341 /* 1 byte hole */
84342- __u32 ack_seq; /* Sequence number ACK'd */
84343+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
84344 };
84345
84346 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
84347diff --git a/include/net/xfrm.h b/include/net/xfrm.h
84348index fb5654a..4457522 100644
84349--- a/include/net/xfrm.h
84350+++ b/include/net/xfrm.h
84351@@ -286,7 +286,6 @@ struct xfrm_dst;
84352 struct xfrm_policy_afinfo {
84353 unsigned short family;
84354 struct dst_ops *dst_ops;
84355- void (*garbage_collect)(struct net *net);
84356 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84357 const xfrm_address_t *saddr,
84358 const xfrm_address_t *daddr);
84359@@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
84360 struct net_device *dev,
84361 const struct flowi *fl);
84362 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84363-};
84364+} __do_const;
84365
84366 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84367 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84368@@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
84369 int (*transport_finish)(struct sk_buff *skb,
84370 int async);
84371 void (*local_error)(struct sk_buff *skb, u32 mtu);
84372-};
84373+} __do_const;
84374
84375 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84376 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84377@@ -428,7 +427,7 @@ struct xfrm_mode {
84378 struct module *owner;
84379 unsigned int encap;
84380 int flags;
84381-};
84382+} __do_const;
84383
84384 /* Flags for xfrm_mode. */
84385 enum {
84386@@ -525,7 +524,7 @@ struct xfrm_policy {
84387 struct timer_list timer;
84388
84389 struct flow_cache_object flo;
84390- atomic_t genid;
84391+ atomic_unchecked_t genid;
84392 u32 priority;
84393 u32 index;
84394 struct xfrm_mark mark;
84395@@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84396 }
84397
84398 void xfrm_garbage_collect(struct net *net);
84399+void xfrm_garbage_collect_deferred(struct net *net);
84400
84401 #else
84402
84403@@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84404 static inline void xfrm_garbage_collect(struct net *net)
84405 {
84406 }
84407+static inline void xfrm_garbage_collect_deferred(struct net *net)
84408+{
84409+}
84410 #endif
84411
84412 static __inline__
84413diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84414index 1017e0b..227aa4d 100644
84415--- a/include/rdma/iw_cm.h
84416+++ b/include/rdma/iw_cm.h
84417@@ -122,7 +122,7 @@ struct iw_cm_verbs {
84418 int backlog);
84419
84420 int (*destroy_listen)(struct iw_cm_id *cm_id);
84421-};
84422+} __no_const;
84423
84424 /**
84425 * iw_create_cm_id - Create an IW CM identifier.
84426diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84427index 52beadf..598734c 100644
84428--- a/include/scsi/libfc.h
84429+++ b/include/scsi/libfc.h
84430@@ -771,6 +771,7 @@ struct libfc_function_template {
84431 */
84432 void (*disc_stop_final) (struct fc_lport *);
84433 };
84434+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84435
84436 /**
84437 * struct fc_disc - Discovery context
84438@@ -875,7 +876,7 @@ struct fc_lport {
84439 struct fc_vport *vport;
84440
84441 /* Operational Information */
84442- struct libfc_function_template tt;
84443+ libfc_function_template_no_const tt;
84444 u8 link_up;
84445 u8 qfull;
84446 enum fc_lport_state state;
84447diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84448index b4f1eff..7fdbd46 100644
84449--- a/include/scsi/scsi_device.h
84450+++ b/include/scsi/scsi_device.h
84451@@ -180,9 +180,9 @@ struct scsi_device {
84452 unsigned int max_device_blocked; /* what device_blocked counts down from */
84453 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84454
84455- atomic_t iorequest_cnt;
84456- atomic_t iodone_cnt;
84457- atomic_t ioerr_cnt;
84458+ atomic_unchecked_t iorequest_cnt;
84459+ atomic_unchecked_t iodone_cnt;
84460+ atomic_unchecked_t ioerr_cnt;
84461
84462 struct device sdev_gendev,
84463 sdev_dev;
84464diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84465index b797e8f..8e2c3aa 100644
84466--- a/include/scsi/scsi_transport_fc.h
84467+++ b/include/scsi/scsi_transport_fc.h
84468@@ -751,7 +751,8 @@ struct fc_function_template {
84469 unsigned long show_host_system_hostname:1;
84470
84471 unsigned long disable_target_scan:1;
84472-};
84473+} __do_const;
84474+typedef struct fc_function_template __no_const fc_function_template_no_const;
84475
84476
84477 /**
84478diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84479index ae6c3b8..fd748ac 100644
84480--- a/include/sound/compress_driver.h
84481+++ b/include/sound/compress_driver.h
84482@@ -128,7 +128,7 @@ struct snd_compr_ops {
84483 struct snd_compr_caps *caps);
84484 int (*get_codec_caps) (struct snd_compr_stream *stream,
84485 struct snd_compr_codec_caps *codec);
84486-};
84487+} __no_const;
84488
84489 /**
84490 * struct snd_compr: Compressed device
84491diff --git a/include/sound/soc.h b/include/sound/soc.h
84492index 9a00147..d814573 100644
84493--- a/include/sound/soc.h
84494+++ b/include/sound/soc.h
84495@@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
84496 /* probe ordering - for components with runtime dependencies */
84497 int probe_order;
84498 int remove_order;
84499-};
84500+} __do_const;
84501
84502 /* SoC platform interface */
84503 struct snd_soc_platform_driver {
84504@@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
84505 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84506 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84507 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84508-};
84509+} __do_const;
84510
84511 struct snd_soc_platform {
84512 const char *name;
84513diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84514index 1772fad..282e3e2 100644
84515--- a/include/target/target_core_base.h
84516+++ b/include/target/target_core_base.h
84517@@ -754,7 +754,7 @@ struct se_device {
84518 atomic_long_t write_bytes;
84519 /* Active commands on this virtual SE device */
84520 atomic_t simple_cmds;
84521- atomic_t dev_ordered_id;
84522+ atomic_unchecked_t dev_ordered_id;
84523 atomic_t dev_ordered_sync;
84524 atomic_t dev_qf_count;
84525 int export_count;
84526diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84527new file mode 100644
84528index 0000000..fb634b7
84529--- /dev/null
84530+++ b/include/trace/events/fs.h
84531@@ -0,0 +1,53 @@
84532+#undef TRACE_SYSTEM
84533+#define TRACE_SYSTEM fs
84534+
84535+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84536+#define _TRACE_FS_H
84537+
84538+#include <linux/fs.h>
84539+#include <linux/tracepoint.h>
84540+
84541+TRACE_EVENT(do_sys_open,
84542+
84543+ TP_PROTO(const char *filename, int flags, int mode),
84544+
84545+ TP_ARGS(filename, flags, mode),
84546+
84547+ TP_STRUCT__entry(
84548+ __string( filename, filename )
84549+ __field( int, flags )
84550+ __field( int, mode )
84551+ ),
84552+
84553+ TP_fast_assign(
84554+ __assign_str(filename, filename);
84555+ __entry->flags = flags;
84556+ __entry->mode = mode;
84557+ ),
84558+
84559+ TP_printk("\"%s\" %x %o",
84560+ __get_str(filename), __entry->flags, __entry->mode)
84561+);
84562+
84563+TRACE_EVENT(open_exec,
84564+
84565+ TP_PROTO(const char *filename),
84566+
84567+ TP_ARGS(filename),
84568+
84569+ TP_STRUCT__entry(
84570+ __string( filename, filename )
84571+ ),
84572+
84573+ TP_fast_assign(
84574+ __assign_str(filename, filename);
84575+ ),
84576+
84577+ TP_printk("\"%s\"",
84578+ __get_str(filename))
84579+);
84580+
84581+#endif /* _TRACE_FS_H */
84582+
84583+/* This part must be outside protection */
84584+#include <trace/define_trace.h>
84585diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84586index 1c09820..7f5ec79 100644
84587--- a/include/trace/events/irq.h
84588+++ b/include/trace/events/irq.h
84589@@ -36,7 +36,7 @@ struct softirq_action;
84590 */
84591 TRACE_EVENT(irq_handler_entry,
84592
84593- TP_PROTO(int irq, struct irqaction *action),
84594+ TP_PROTO(int irq, const struct irqaction *action),
84595
84596 TP_ARGS(irq, action),
84597
84598@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84599 */
84600 TRACE_EVENT(irq_handler_exit,
84601
84602- TP_PROTO(int irq, struct irqaction *action, int ret),
84603+ TP_PROTO(int irq, const struct irqaction *action, int ret),
84604
84605 TP_ARGS(irq, action, ret),
84606
84607diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84608index 7caf44c..23c6f27 100644
84609--- a/include/uapi/linux/a.out.h
84610+++ b/include/uapi/linux/a.out.h
84611@@ -39,6 +39,14 @@ enum machine_type {
84612 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84613 };
84614
84615+/* Constants for the N_FLAGS field */
84616+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84617+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84618+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84619+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84620+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84621+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84622+
84623 #if !defined (N_MAGIC)
84624 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84625 #endif
84626diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84627index 22b6ad3..aeba37e 100644
84628--- a/include/uapi/linux/bcache.h
84629+++ b/include/uapi/linux/bcache.h
84630@@ -5,6 +5,7 @@
84631 * Bcache on disk data structures
84632 */
84633
84634+#include <linux/compiler.h>
84635 #include <asm/types.h>
84636
84637 #define BITMASK(name, type, field, offset, size) \
84638@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84639 /* Btree keys - all units are in sectors */
84640
84641 struct bkey {
84642- __u64 high;
84643- __u64 low;
84644+ __u64 high __intentional_overflow(-1);
84645+ __u64 low __intentional_overflow(-1);
84646 __u64 ptr[];
84647 };
84648
84649diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84650index d876736..ccce5c0 100644
84651--- a/include/uapi/linux/byteorder/little_endian.h
84652+++ b/include/uapi/linux/byteorder/little_endian.h
84653@@ -42,51 +42,51 @@
84654
84655 static inline __le64 __cpu_to_le64p(const __u64 *p)
84656 {
84657- return (__force __le64)*p;
84658+ return (__force const __le64)*p;
84659 }
84660-static inline __u64 __le64_to_cpup(const __le64 *p)
84661+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84662 {
84663- return (__force __u64)*p;
84664+ return (__force const __u64)*p;
84665 }
84666 static inline __le32 __cpu_to_le32p(const __u32 *p)
84667 {
84668- return (__force __le32)*p;
84669+ return (__force const __le32)*p;
84670 }
84671 static inline __u32 __le32_to_cpup(const __le32 *p)
84672 {
84673- return (__force __u32)*p;
84674+ return (__force const __u32)*p;
84675 }
84676 static inline __le16 __cpu_to_le16p(const __u16 *p)
84677 {
84678- return (__force __le16)*p;
84679+ return (__force const __le16)*p;
84680 }
84681 static inline __u16 __le16_to_cpup(const __le16 *p)
84682 {
84683- return (__force __u16)*p;
84684+ return (__force const __u16)*p;
84685 }
84686 static inline __be64 __cpu_to_be64p(const __u64 *p)
84687 {
84688- return (__force __be64)__swab64p(p);
84689+ return (__force const __be64)__swab64p(p);
84690 }
84691 static inline __u64 __be64_to_cpup(const __be64 *p)
84692 {
84693- return __swab64p((__u64 *)p);
84694+ return __swab64p((const __u64 *)p);
84695 }
84696 static inline __be32 __cpu_to_be32p(const __u32 *p)
84697 {
84698- return (__force __be32)__swab32p(p);
84699+ return (__force const __be32)__swab32p(p);
84700 }
84701-static inline __u32 __be32_to_cpup(const __be32 *p)
84702+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84703 {
84704- return __swab32p((__u32 *)p);
84705+ return __swab32p((const __u32 *)p);
84706 }
84707 static inline __be16 __cpu_to_be16p(const __u16 *p)
84708 {
84709- return (__force __be16)__swab16p(p);
84710+ return (__force const __be16)__swab16p(p);
84711 }
84712 static inline __u16 __be16_to_cpup(const __be16 *p)
84713 {
84714- return __swab16p((__u16 *)p);
84715+ return __swab16p((const __u16 *)p);
84716 }
84717 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84718 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84719diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84720index ef6103b..d4e65dd 100644
84721--- a/include/uapi/linux/elf.h
84722+++ b/include/uapi/linux/elf.h
84723@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84724 #define PT_GNU_EH_FRAME 0x6474e550
84725
84726 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84727+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84728+
84729+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84730+
84731+/* Constants for the e_flags field */
84732+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84733+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84734+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84735+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84736+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84737+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84738
84739 /*
84740 * Extended Numbering
84741@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84742 #define DT_DEBUG 21
84743 #define DT_TEXTREL 22
84744 #define DT_JMPREL 23
84745+#define DT_FLAGS 30
84746+ #define DF_TEXTREL 0x00000004
84747 #define DT_ENCODING 32
84748 #define OLD_DT_LOOS 0x60000000
84749 #define DT_LOOS 0x6000000d
84750@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84751 #define PF_W 0x2
84752 #define PF_X 0x1
84753
84754+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84755+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84756+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84757+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84758+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84759+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84760+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84761+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84762+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84763+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84764+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84765+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84766+
84767 typedef struct elf32_phdr{
84768 Elf32_Word p_type;
84769 Elf32_Off p_offset;
84770@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84771 #define EI_OSABI 7
84772 #define EI_PAD 8
84773
84774+#define EI_PAX 14
84775+
84776 #define ELFMAG0 0x7f /* EI_MAG */
84777 #define ELFMAG1 'E'
84778 #define ELFMAG2 'L'
84779diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84780index aa169c4..6a2771d 100644
84781--- a/include/uapi/linux/personality.h
84782+++ b/include/uapi/linux/personality.h
84783@@ -30,6 +30,7 @@ enum {
84784 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84785 ADDR_NO_RANDOMIZE | \
84786 ADDR_COMPAT_LAYOUT | \
84787+ ADDR_LIMIT_3GB | \
84788 MMAP_PAGE_ZERO)
84789
84790 /*
84791diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84792index 7530e74..e714828 100644
84793--- a/include/uapi/linux/screen_info.h
84794+++ b/include/uapi/linux/screen_info.h
84795@@ -43,7 +43,8 @@ struct screen_info {
84796 __u16 pages; /* 0x32 */
84797 __u16 vesa_attributes; /* 0x34 */
84798 __u32 capabilities; /* 0x36 */
84799- __u8 _reserved[6]; /* 0x3a */
84800+ __u16 vesapm_size; /* 0x3a */
84801+ __u8 _reserved[4]; /* 0x3c */
84802 } __attribute__((packed));
84803
84804 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84805diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84806index 0e011eb..82681b1 100644
84807--- a/include/uapi/linux/swab.h
84808+++ b/include/uapi/linux/swab.h
84809@@ -43,7 +43,7 @@
84810 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84811 */
84812
84813-static inline __attribute_const__ __u16 __fswab16(__u16 val)
84814+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84815 {
84816 #ifdef __HAVE_BUILTIN_BSWAP16__
84817 return __builtin_bswap16(val);
84818@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84819 #endif
84820 }
84821
84822-static inline __attribute_const__ __u32 __fswab32(__u32 val)
84823+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84824 {
84825 #ifdef __HAVE_BUILTIN_BSWAP32__
84826 return __builtin_bswap32(val);
84827@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84828 #endif
84829 }
84830
84831-static inline __attribute_const__ __u64 __fswab64(__u64 val)
84832+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84833 {
84834 #ifdef __HAVE_BUILTIN_BSWAP64__
84835 return __builtin_bswap64(val);
84836diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84837index 6d67213..552fdd9 100644
84838--- a/include/uapi/linux/sysctl.h
84839+++ b/include/uapi/linux/sysctl.h
84840@@ -155,8 +155,6 @@ enum
84841 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84842 };
84843
84844-
84845-
84846 /* CTL_VM names: */
84847 enum
84848 {
84849diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84850index fe94bb9..c9e51c2 100644
84851--- a/include/uapi/linux/videodev2.h
84852+++ b/include/uapi/linux/videodev2.h
84853@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
84854 union {
84855 __s32 value;
84856 __s64 value64;
84857- char *string;
84858+ char __user *string;
84859 };
84860 } __attribute__ ((packed));
84861
84862diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84863index c38355c..17a57bc 100644
84864--- a/include/uapi/linux/xattr.h
84865+++ b/include/uapi/linux/xattr.h
84866@@ -73,5 +73,9 @@
84867 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84868 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84869
84870+/* User namespace */
84871+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84872+#define XATTR_PAX_FLAGS_SUFFIX "flags"
84873+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84874
84875 #endif /* _UAPI_LINUX_XATTR_H */
84876diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84877index f9466fa..f4e2b81 100644
84878--- a/include/video/udlfb.h
84879+++ b/include/video/udlfb.h
84880@@ -53,10 +53,10 @@ struct dlfb_data {
84881 u32 pseudo_palette[256];
84882 int blank_mode; /*one of FB_BLANK_ */
84883 /* blit-only rendering path metrics, exposed through sysfs */
84884- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84885- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84886- atomic_t bytes_sent; /* to usb, after compression including overhead */
84887- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84888+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84889+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84890+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84891+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84892 };
84893
84894 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84895diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84896index 30f5362..8ed8ac9 100644
84897--- a/include/video/uvesafb.h
84898+++ b/include/video/uvesafb.h
84899@@ -122,6 +122,7 @@ struct uvesafb_par {
84900 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84901 u8 pmi_setpal; /* PMI for palette changes */
84902 u16 *pmi_base; /* protected mode interface location */
84903+ u8 *pmi_code; /* protected mode code location */
84904 void *pmi_start;
84905 void *pmi_pal;
84906 u8 *vbe_state_orig; /*
84907diff --git a/init/Kconfig b/init/Kconfig
84908index 93c5ef0..ac92caa 100644
84909--- a/init/Kconfig
84910+++ b/init/Kconfig
84911@@ -1079,6 +1079,7 @@ endif # CGROUPS
84912
84913 config CHECKPOINT_RESTORE
84914 bool "Checkpoint/restore support" if EXPERT
84915+ depends on !GRKERNSEC
84916 default n
84917 help
84918 Enables additional kernel features in a sake of checkpoint/restore.
84919@@ -1545,7 +1546,7 @@ config SLUB_DEBUG
84920
84921 config COMPAT_BRK
84922 bool "Disable heap randomization"
84923- default y
84924+ default n
84925 help
84926 Randomizing heap placement makes heap exploits harder, but it
84927 also breaks ancient binaries (including anything libc5 based).
84928@@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
84929 config STOP_MACHINE
84930 bool
84931 default y
84932- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84933+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84934 help
84935 Need stop_machine() primitive.
84936
84937diff --git a/init/Makefile b/init/Makefile
84938index 7bc47ee..6da2dc7 100644
84939--- a/init/Makefile
84940+++ b/init/Makefile
84941@@ -2,6 +2,9 @@
84942 # Makefile for the linux kernel.
84943 #
84944
84945+ccflags-y := $(GCC_PLUGINS_CFLAGS)
84946+asflags-y := $(GCC_PLUGINS_AFLAGS)
84947+
84948 obj-y := main.o version.o mounts.o
84949 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84950 obj-y += noinitramfs.o
84951diff --git a/init/do_mounts.c b/init/do_mounts.c
84952index 8e5addc..c96ea61 100644
84953--- a/init/do_mounts.c
84954+++ b/init/do_mounts.c
84955@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84956 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84957 {
84958 struct super_block *s;
84959- int err = sys_mount(name, "/root", fs, flags, data);
84960+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84961 if (err)
84962 return err;
84963
84964- sys_chdir("/root");
84965+ sys_chdir((const char __force_user *)"/root");
84966 s = current->fs->pwd.dentry->d_sb;
84967 ROOT_DEV = s->s_dev;
84968 printk(KERN_INFO
84969@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84970 va_start(args, fmt);
84971 vsprintf(buf, fmt, args);
84972 va_end(args);
84973- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84974+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84975 if (fd >= 0) {
84976 sys_ioctl(fd, FDEJECT, 0);
84977 sys_close(fd);
84978 }
84979 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84980- fd = sys_open("/dev/console", O_RDWR, 0);
84981+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84982 if (fd >= 0) {
84983 sys_ioctl(fd, TCGETS, (long)&termios);
84984 termios.c_lflag &= ~ICANON;
84985 sys_ioctl(fd, TCSETSF, (long)&termios);
84986- sys_read(fd, &c, 1);
84987+ sys_read(fd, (char __user *)&c, 1);
84988 termios.c_lflag |= ICANON;
84989 sys_ioctl(fd, TCSETSF, (long)&termios);
84990 sys_close(fd);
84991@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84992 mount_root();
84993 out:
84994 devtmpfs_mount("dev");
84995- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84996- sys_chroot(".");
84997+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84998+ sys_chroot((const char __force_user *)".");
84999 }
85000
85001 static bool is_tmpfs;
85002diff --git a/init/do_mounts.h b/init/do_mounts.h
85003index f5b978a..69dbfe8 100644
85004--- a/init/do_mounts.h
85005+++ b/init/do_mounts.h
85006@@ -15,15 +15,15 @@ extern int root_mountflags;
85007
85008 static inline int create_dev(char *name, dev_t dev)
85009 {
85010- sys_unlink(name);
85011- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
85012+ sys_unlink((char __force_user *)name);
85013+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
85014 }
85015
85016 #if BITS_PER_LONG == 32
85017 static inline u32 bstat(char *name)
85018 {
85019 struct stat64 stat;
85020- if (sys_stat64(name, &stat) != 0)
85021+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
85022 return 0;
85023 if (!S_ISBLK(stat.st_mode))
85024 return 0;
85025@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
85026 static inline u32 bstat(char *name)
85027 {
85028 struct stat stat;
85029- if (sys_newstat(name, &stat) != 0)
85030+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
85031 return 0;
85032 if (!S_ISBLK(stat.st_mode))
85033 return 0;
85034diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
85035index 3e0878e..8a9d7a0 100644
85036--- a/init/do_mounts_initrd.c
85037+++ b/init/do_mounts_initrd.c
85038@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
85039 {
85040 sys_unshare(CLONE_FS | CLONE_FILES);
85041 /* stdin/stdout/stderr for /linuxrc */
85042- sys_open("/dev/console", O_RDWR, 0);
85043+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
85044 sys_dup(0);
85045 sys_dup(0);
85046 /* move initrd over / and chdir/chroot in initrd root */
85047- sys_chdir("/root");
85048- sys_mount(".", "/", NULL, MS_MOVE, NULL);
85049- sys_chroot(".");
85050+ sys_chdir((const char __force_user *)"/root");
85051+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
85052+ sys_chroot((const char __force_user *)".");
85053 sys_setsid();
85054 return 0;
85055 }
85056@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
85057 create_dev("/dev/root.old", Root_RAM0);
85058 /* mount initrd on rootfs' /root */
85059 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
85060- sys_mkdir("/old", 0700);
85061- sys_chdir("/old");
85062+ sys_mkdir((const char __force_user *)"/old", 0700);
85063+ sys_chdir((const char __force_user *)"/old");
85064
85065 /* try loading default modules from initrd */
85066 load_default_modules();
85067@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
85068 current->flags &= ~PF_FREEZER_SKIP;
85069
85070 /* move initrd to rootfs' /old */
85071- sys_mount("..", ".", NULL, MS_MOVE, NULL);
85072+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
85073 /* switch root and cwd back to / of rootfs */
85074- sys_chroot("..");
85075+ sys_chroot((const char __force_user *)"..");
85076
85077 if (new_decode_dev(real_root_dev) == Root_RAM0) {
85078- sys_chdir("/old");
85079+ sys_chdir((const char __force_user *)"/old");
85080 return;
85081 }
85082
85083- sys_chdir("/");
85084+ sys_chdir((const char __force_user *)"/");
85085 ROOT_DEV = new_decode_dev(real_root_dev);
85086 mount_root();
85087
85088 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
85089- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
85090+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
85091 if (!error)
85092 printk("okay\n");
85093 else {
85094- int fd = sys_open("/dev/root.old", O_RDWR, 0);
85095+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
85096 if (error == -ENOENT)
85097 printk("/initrd does not exist. Ignored.\n");
85098 else
85099 printk("failed\n");
85100 printk(KERN_NOTICE "Unmounting old root\n");
85101- sys_umount("/old", MNT_DETACH);
85102+ sys_umount((char __force_user *)"/old", MNT_DETACH);
85103 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
85104 if (fd < 0) {
85105 error = fd;
85106@@ -127,11 +127,11 @@ int __init initrd_load(void)
85107 * mounted in the normal path.
85108 */
85109 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
85110- sys_unlink("/initrd.image");
85111+ sys_unlink((const char __force_user *)"/initrd.image");
85112 handle_initrd();
85113 return 1;
85114 }
85115 }
85116- sys_unlink("/initrd.image");
85117+ sys_unlink((const char __force_user *)"/initrd.image");
85118 return 0;
85119 }
85120diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
85121index 8cb6db5..d729f50 100644
85122--- a/init/do_mounts_md.c
85123+++ b/init/do_mounts_md.c
85124@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
85125 partitioned ? "_d" : "", minor,
85126 md_setup_args[ent].device_names);
85127
85128- fd = sys_open(name, 0, 0);
85129+ fd = sys_open((char __force_user *)name, 0, 0);
85130 if (fd < 0) {
85131 printk(KERN_ERR "md: open failed - cannot start "
85132 "array %s\n", name);
85133@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
85134 * array without it
85135 */
85136 sys_close(fd);
85137- fd = sys_open(name, 0, 0);
85138+ fd = sys_open((char __force_user *)name, 0, 0);
85139 sys_ioctl(fd, BLKRRPART, 0);
85140 }
85141 sys_close(fd);
85142@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
85143
85144 wait_for_device_probe();
85145
85146- fd = sys_open("/dev/md0", 0, 0);
85147+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
85148 if (fd >= 0) {
85149 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
85150 sys_close(fd);
85151diff --git a/init/init_task.c b/init/init_task.c
85152index ba0a7f36..2bcf1d5 100644
85153--- a/init/init_task.c
85154+++ b/init/init_task.c
85155@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
85156 * Initial thread structure. Alignment of this is handled by a special
85157 * linker map entry.
85158 */
85159+#ifdef CONFIG_X86
85160+union thread_union init_thread_union __init_task_data;
85161+#else
85162 union thread_union init_thread_union __init_task_data =
85163 { INIT_THREAD_INFO(init_task) };
85164+#endif
85165diff --git a/init/initramfs.c b/init/initramfs.c
85166index 93b6139..8d628b7 100644
85167--- a/init/initramfs.c
85168+++ b/init/initramfs.c
85169@@ -84,7 +84,7 @@ static void __init free_hash(void)
85170 }
85171 }
85172
85173-static long __init do_utime(char *filename, time_t mtime)
85174+static long __init do_utime(char __force_user *filename, time_t mtime)
85175 {
85176 struct timespec t[2];
85177
85178@@ -119,7 +119,7 @@ static void __init dir_utime(void)
85179 struct dir_entry *de, *tmp;
85180 list_for_each_entry_safe(de, tmp, &dir_list, list) {
85181 list_del(&de->list);
85182- do_utime(de->name, de->mtime);
85183+ do_utime((char __force_user *)de->name, de->mtime);
85184 kfree(de->name);
85185 kfree(de);
85186 }
85187@@ -281,7 +281,7 @@ static int __init maybe_link(void)
85188 if (nlink >= 2) {
85189 char *old = find_link(major, minor, ino, mode, collected);
85190 if (old)
85191- return (sys_link(old, collected) < 0) ? -1 : 1;
85192+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
85193 }
85194 return 0;
85195 }
85196@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
85197 {
85198 struct stat st;
85199
85200- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
85201+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
85202 if (S_ISDIR(st.st_mode))
85203- sys_rmdir(path);
85204+ sys_rmdir((char __force_user *)path);
85205 else
85206- sys_unlink(path);
85207+ sys_unlink((char __force_user *)path);
85208 }
85209 }
85210
85211@@ -315,7 +315,7 @@ static int __init do_name(void)
85212 int openflags = O_WRONLY|O_CREAT;
85213 if (ml != 1)
85214 openflags |= O_TRUNC;
85215- wfd = sys_open(collected, openflags, mode);
85216+ wfd = sys_open((char __force_user *)collected, openflags, mode);
85217
85218 if (wfd >= 0) {
85219 sys_fchown(wfd, uid, gid);
85220@@ -327,17 +327,17 @@ static int __init do_name(void)
85221 }
85222 }
85223 } else if (S_ISDIR(mode)) {
85224- sys_mkdir(collected, mode);
85225- sys_chown(collected, uid, gid);
85226- sys_chmod(collected, mode);
85227+ sys_mkdir((char __force_user *)collected, mode);
85228+ sys_chown((char __force_user *)collected, uid, gid);
85229+ sys_chmod((char __force_user *)collected, mode);
85230 dir_add(collected, mtime);
85231 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
85232 S_ISFIFO(mode) || S_ISSOCK(mode)) {
85233 if (maybe_link() == 0) {
85234- sys_mknod(collected, mode, rdev);
85235- sys_chown(collected, uid, gid);
85236- sys_chmod(collected, mode);
85237- do_utime(collected, mtime);
85238+ sys_mknod((char __force_user *)collected, mode, rdev);
85239+ sys_chown((char __force_user *)collected, uid, gid);
85240+ sys_chmod((char __force_user *)collected, mode);
85241+ do_utime((char __force_user *)collected, mtime);
85242 }
85243 }
85244 return 0;
85245@@ -346,15 +346,15 @@ static int __init do_name(void)
85246 static int __init do_copy(void)
85247 {
85248 if (count >= body_len) {
85249- sys_write(wfd, victim, body_len);
85250+ sys_write(wfd, (char __force_user *)victim, body_len);
85251 sys_close(wfd);
85252- do_utime(vcollected, mtime);
85253+ do_utime((char __force_user *)vcollected, mtime);
85254 kfree(vcollected);
85255 eat(body_len);
85256 state = SkipIt;
85257 return 0;
85258 } else {
85259- sys_write(wfd, victim, count);
85260+ sys_write(wfd, (char __force_user *)victim, count);
85261 body_len -= count;
85262 eat(count);
85263 return 1;
85264@@ -365,9 +365,9 @@ static int __init do_symlink(void)
85265 {
85266 collected[N_ALIGN(name_len) + body_len] = '\0';
85267 clean_path(collected, 0);
85268- sys_symlink(collected + N_ALIGN(name_len), collected);
85269- sys_lchown(collected, uid, gid);
85270- do_utime(collected, mtime);
85271+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
85272+ sys_lchown((char __force_user *)collected, uid, gid);
85273+ do_utime((char __force_user *)collected, mtime);
85274 state = SkipIt;
85275 next_state = Reset;
85276 return 0;
85277diff --git a/init/main.c b/init/main.c
85278index 9c7fd4c..650b4f1 100644
85279--- a/init/main.c
85280+++ b/init/main.c
85281@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
85282 static inline void mark_rodata_ro(void) { }
85283 #endif
85284
85285+extern void grsecurity_init(void);
85286+
85287 /*
85288 * Debug helper: via this flag we know that we are in 'early bootup code'
85289 * where only the boot processor is running with IRQ disabled. This means
85290@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
85291
85292 __setup("reset_devices", set_reset_devices);
85293
85294+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85295+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
85296+static int __init setup_grsec_proc_gid(char *str)
85297+{
85298+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
85299+ return 1;
85300+}
85301+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
85302+#endif
85303+
85304+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
85305+unsigned long pax_user_shadow_base __read_only;
85306+EXPORT_SYMBOL(pax_user_shadow_base);
85307+extern char pax_enter_kernel_user[];
85308+extern char pax_exit_kernel_user[];
85309+#endif
85310+
85311+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
85312+static int __init setup_pax_nouderef(char *str)
85313+{
85314+#ifdef CONFIG_X86_32
85315+ unsigned int cpu;
85316+ struct desc_struct *gdt;
85317+
85318+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
85319+ gdt = get_cpu_gdt_table(cpu);
85320+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
85321+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
85322+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
85323+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
85324+ }
85325+ loadsegment(ds, __KERNEL_DS);
85326+ loadsegment(es, __KERNEL_DS);
85327+ loadsegment(ss, __KERNEL_DS);
85328+#else
85329+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
85330+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
85331+ clone_pgd_mask = ~(pgdval_t)0UL;
85332+ pax_user_shadow_base = 0UL;
85333+ setup_clear_cpu_cap(X86_FEATURE_PCID);
85334+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
85335+#endif
85336+
85337+ return 0;
85338+}
85339+early_param("pax_nouderef", setup_pax_nouderef);
85340+
85341+#ifdef CONFIG_X86_64
85342+static int __init setup_pax_weakuderef(char *str)
85343+{
85344+ if (clone_pgd_mask != ~(pgdval_t)0UL)
85345+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
85346+ return 1;
85347+}
85348+__setup("pax_weakuderef", setup_pax_weakuderef);
85349+#endif
85350+#endif
85351+
85352+#ifdef CONFIG_PAX_SOFTMODE
85353+int pax_softmode;
85354+
85355+static int __init setup_pax_softmode(char *str)
85356+{
85357+ get_option(&str, &pax_softmode);
85358+ return 1;
85359+}
85360+__setup("pax_softmode=", setup_pax_softmode);
85361+#endif
85362+
85363 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85364 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85365 static const char *panic_later, *panic_param;
85366@@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85367 {
85368 int count = preempt_count();
85369 int ret;
85370- char msgbuf[64];
85371+ const char *msg1 = "", *msg2 = "";
85372
85373 if (initcall_debug)
85374 ret = do_one_initcall_debug(fn);
85375 else
85376 ret = fn();
85377
85378- msgbuf[0] = 0;
85379-
85380 if (preempt_count() != count) {
85381- sprintf(msgbuf, "preemption imbalance ");
85382+ msg1 = " preemption imbalance";
85383 preempt_count_set(count);
85384 }
85385 if (irqs_disabled()) {
85386- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85387+ msg2 = " disabled interrupts";
85388 local_irq_enable();
85389 }
85390- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85391+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85392
85393+ add_latent_entropy();
85394 return ret;
85395 }
85396
85397@@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
85398 {
85399 argv_init[0] = init_filename;
85400 return do_execve(getname_kernel(init_filename),
85401- (const char __user *const __user *)argv_init,
85402- (const char __user *const __user *)envp_init);
85403+ (const char __user *const __force_user *)argv_init,
85404+ (const char __user *const __force_user *)envp_init);
85405 }
85406
85407 static int try_to_run_init_process(const char *init_filename)
85408@@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
85409 return ret;
85410 }
85411
85412+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85413+extern int gr_init_ran;
85414+#endif
85415+
85416 static noinline void __init kernel_init_freeable(void);
85417
85418 static int __ref kernel_init(void *unused)
85419@@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
85420 ramdisk_execute_command, ret);
85421 }
85422
85423+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85424+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
85425+ gr_init_ran = 1;
85426+#endif
85427+
85428 /*
85429 * We try each of these until one succeeds.
85430 *
85431@@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
85432 do_basic_setup();
85433
85434 /* Open the /dev/console on the rootfs, this should never fail */
85435- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85436+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85437 pr_err("Warning: unable to open an initial console.\n");
85438
85439 (void) sys_dup(0);
85440@@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
85441 if (!ramdisk_execute_command)
85442 ramdisk_execute_command = "/init";
85443
85444- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85445+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85446 ramdisk_execute_command = NULL;
85447 prepare_namespace();
85448 }
85449
85450+ grsecurity_init();
85451+
85452 /*
85453 * Ok, we have completed the initial bootup, and
85454 * we're essentially up and running. Get rid of the
85455diff --git a/ipc/compat.c b/ipc/compat.c
85456index f486b00..442867f 100644
85457--- a/ipc/compat.c
85458+++ b/ipc/compat.c
85459@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85460 COMPAT_SHMLBA);
85461 if (err < 0)
85462 return err;
85463- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85464+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85465 }
85466 case SHMDT:
85467 return sys_shmdt(compat_ptr(ptr));
85468diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85469index 1702864..797fa84 100644
85470--- a/ipc/ipc_sysctl.c
85471+++ b/ipc/ipc_sysctl.c
85472@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85473 static int proc_ipc_dointvec(ctl_table *table, int write,
85474 void __user *buffer, size_t *lenp, loff_t *ppos)
85475 {
85476- struct ctl_table ipc_table;
85477+ ctl_table_no_const ipc_table;
85478
85479 memcpy(&ipc_table, table, sizeof(ipc_table));
85480 ipc_table.data = get_ipc(table);
85481@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85482 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85483 void __user *buffer, size_t *lenp, loff_t *ppos)
85484 {
85485- struct ctl_table ipc_table;
85486+ ctl_table_no_const ipc_table;
85487
85488 memcpy(&ipc_table, table, sizeof(ipc_table));
85489 ipc_table.data = get_ipc(table);
85490@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85491 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85492 void __user *buffer, size_t *lenp, loff_t *ppos)
85493 {
85494- struct ctl_table ipc_table;
85495+ ctl_table_no_const ipc_table;
85496 size_t lenp_bef = *lenp;
85497 int rc;
85498
85499@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85500 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85501 void __user *buffer, size_t *lenp, loff_t *ppos)
85502 {
85503- struct ctl_table ipc_table;
85504+ ctl_table_no_const ipc_table;
85505 memcpy(&ipc_table, table, sizeof(ipc_table));
85506 ipc_table.data = get_ipc(table);
85507
85508@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85509 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85510 void __user *buffer, size_t *lenp, loff_t *ppos)
85511 {
85512- struct ctl_table ipc_table;
85513+ ctl_table_no_const ipc_table;
85514 size_t lenp_bef = *lenp;
85515 int oldval;
85516 int rc;
85517diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85518index 5bb8bfe..a38ec05 100644
85519--- a/ipc/mq_sysctl.c
85520+++ b/ipc/mq_sysctl.c
85521@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85522 static int proc_mq_dointvec(ctl_table *table, int write,
85523 void __user *buffer, size_t *lenp, loff_t *ppos)
85524 {
85525- struct ctl_table mq_table;
85526+ ctl_table_no_const mq_table;
85527 memcpy(&mq_table, table, sizeof(mq_table));
85528 mq_table.data = get_mq(table);
85529
85530@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85531 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85532 void __user *buffer, size_t *lenp, loff_t *ppos)
85533 {
85534- struct ctl_table mq_table;
85535+ ctl_table_no_const mq_table;
85536 memcpy(&mq_table, table, sizeof(mq_table));
85537 mq_table.data = get_mq(table);
85538
85539diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85540index c3b3117..1efa933 100644
85541--- a/ipc/mqueue.c
85542+++ b/ipc/mqueue.c
85543@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85544 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85545 info->attr.mq_msgsize);
85546
85547+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85548 spin_lock(&mq_lock);
85549 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85550 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85551diff --git a/ipc/msg.c b/ipc/msg.c
85552index 6498531..b0ff3c8 100644
85553--- a/ipc/msg.c
85554+++ b/ipc/msg.c
85555@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85556 return security_msg_queue_associate(msq, msgflg);
85557 }
85558
85559+static struct ipc_ops msg_ops = {
85560+ .getnew = newque,
85561+ .associate = msg_security,
85562+ .more_checks = NULL
85563+};
85564+
85565 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85566 {
85567 struct ipc_namespace *ns;
85568- struct ipc_ops msg_ops;
85569 struct ipc_params msg_params;
85570
85571 ns = current->nsproxy->ipc_ns;
85572
85573- msg_ops.getnew = newque;
85574- msg_ops.associate = msg_security;
85575- msg_ops.more_checks = NULL;
85576-
85577 msg_params.key = key;
85578 msg_params.flg = msgflg;
85579
85580diff --git a/ipc/sem.c b/ipc/sem.c
85581index bee5554..e9af81dd 100644
85582--- a/ipc/sem.c
85583+++ b/ipc/sem.c
85584@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85585 return 0;
85586 }
85587
85588+static struct ipc_ops sem_ops = {
85589+ .getnew = newary,
85590+ .associate = sem_security,
85591+ .more_checks = sem_more_checks
85592+};
85593+
85594 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85595 {
85596 struct ipc_namespace *ns;
85597- struct ipc_ops sem_ops;
85598 struct ipc_params sem_params;
85599
85600 ns = current->nsproxy->ipc_ns;
85601@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85602 if (nsems < 0 || nsems > ns->sc_semmsl)
85603 return -EINVAL;
85604
85605- sem_ops.getnew = newary;
85606- sem_ops.associate = sem_security;
85607- sem_ops.more_checks = sem_more_checks;
85608-
85609 sem_params.key = key;
85610 sem_params.flg = semflg;
85611 sem_params.u.nsems = nsems;
85612diff --git a/ipc/shm.c b/ipc/shm.c
85613index 7645961..afc7f02 100644
85614--- a/ipc/shm.c
85615+++ b/ipc/shm.c
85616@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85617 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85618 #endif
85619
85620+#ifdef CONFIG_GRKERNSEC
85621+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85622+ const time_t shm_createtime, const kuid_t cuid,
85623+ const int shmid);
85624+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85625+ const time_t shm_createtime);
85626+#endif
85627+
85628 void shm_init_ns(struct ipc_namespace *ns)
85629 {
85630 ns->shm_ctlmax = SHMMAX;
85631@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85632 shp->shm_lprid = 0;
85633 shp->shm_atim = shp->shm_dtim = 0;
85634 shp->shm_ctim = get_seconds();
85635+#ifdef CONFIG_GRKERNSEC
85636+ {
85637+ struct timespec timeval;
85638+ do_posix_clock_monotonic_gettime(&timeval);
85639+
85640+ shp->shm_createtime = timeval.tv_sec;
85641+ }
85642+#endif
85643 shp->shm_segsz = size;
85644 shp->shm_nattch = 0;
85645 shp->shm_file = file;
85646@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85647 return 0;
85648 }
85649
85650+static struct ipc_ops shm_ops = {
85651+ .getnew = newseg,
85652+ .associate = shm_security,
85653+ .more_checks = shm_more_checks
85654+};
85655+
85656 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85657 {
85658 struct ipc_namespace *ns;
85659- struct ipc_ops shm_ops;
85660 struct ipc_params shm_params;
85661
85662 ns = current->nsproxy->ipc_ns;
85663
85664- shm_ops.getnew = newseg;
85665- shm_ops.associate = shm_security;
85666- shm_ops.more_checks = shm_more_checks;
85667-
85668 shm_params.key = key;
85669 shm_params.flg = shmflg;
85670 shm_params.u.size = size;
85671@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85672 f_mode = FMODE_READ | FMODE_WRITE;
85673 }
85674 if (shmflg & SHM_EXEC) {
85675+
85676+#ifdef CONFIG_PAX_MPROTECT
85677+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
85678+ goto out;
85679+#endif
85680+
85681 prot |= PROT_EXEC;
85682 acc_mode |= S_IXUGO;
85683 }
85684@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85685 if (err)
85686 goto out_unlock;
85687
85688+#ifdef CONFIG_GRKERNSEC
85689+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85690+ shp->shm_perm.cuid, shmid) ||
85691+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85692+ err = -EACCES;
85693+ goto out_unlock;
85694+ }
85695+#endif
85696+
85697 ipc_lock_object(&shp->shm_perm);
85698
85699 /* check if shm_destroy() is tearing down shp */
85700@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85701 path = shp->shm_file->f_path;
85702 path_get(&path);
85703 shp->shm_nattch++;
85704+#ifdef CONFIG_GRKERNSEC
85705+ shp->shm_lapid = current->pid;
85706+#endif
85707 size = i_size_read(path.dentry->d_inode);
85708 ipc_unlock_object(&shp->shm_perm);
85709 rcu_read_unlock();
85710diff --git a/ipc/util.c b/ipc/util.c
85711index e1b4c6d..8174204 100644
85712--- a/ipc/util.c
85713+++ b/ipc/util.c
85714@@ -71,6 +71,8 @@ struct ipc_proc_iface {
85715 int (*show)(struct seq_file *, void *);
85716 };
85717
85718+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85719+
85720 static void ipc_memory_notifier(struct work_struct *work)
85721 {
85722 ipcns_notify(IPCNS_MEMCHANGED);
85723@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85724 granted_mode >>= 6;
85725 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85726 granted_mode >>= 3;
85727+
85728+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85729+ return -1;
85730+
85731 /* is there some bit set in requested_mode but not in granted_mode? */
85732 if ((requested_mode & ~granted_mode & 0007) &&
85733 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85734diff --git a/kernel/acct.c b/kernel/acct.c
85735index 8d6e145..33e0b1e 100644
85736--- a/kernel/acct.c
85737+++ b/kernel/acct.c
85738@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85739 */
85740 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85741 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85742- file->f_op->write(file, (char *)&ac,
85743+ file->f_op->write(file, (char __force_user *)&ac,
85744 sizeof(acct_t), &file->f_pos);
85745 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85746 set_fs(fs);
85747diff --git a/kernel/audit.c b/kernel/audit.c
85748index d5f31c1..06646e1 100644
85749--- a/kernel/audit.c
85750+++ b/kernel/audit.c
85751@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85752 3) suppressed due to audit_rate_limit
85753 4) suppressed due to audit_backlog_limit
85754 */
85755-static atomic_t audit_lost = ATOMIC_INIT(0);
85756+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85757
85758 /* The netlink socket. */
85759 static struct sock *audit_sock;
85760@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85761 unsigned long now;
85762 int print;
85763
85764- atomic_inc(&audit_lost);
85765+ atomic_inc_unchecked(&audit_lost);
85766
85767 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85768
85769@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85770 if (print) {
85771 if (printk_ratelimit())
85772 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85773- atomic_read(&audit_lost),
85774+ atomic_read_unchecked(&audit_lost),
85775 audit_rate_limit,
85776 audit_backlog_limit);
85777 audit_panic(message);
85778@@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85779 s.pid = audit_pid;
85780 s.rate_limit = audit_rate_limit;
85781 s.backlog_limit = audit_backlog_limit;
85782- s.lost = atomic_read(&audit_lost);
85783+ s.lost = atomic_read_unchecked(&audit_lost);
85784 s.backlog = skb_queue_len(&audit_skb_queue);
85785 s.version = AUDIT_VERSION_LATEST;
85786 s.backlog_wait_time = audit_backlog_wait_time;
85787diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85788index 37e6216..3604797 100644
85789--- a/kernel/auditsc.c
85790+++ b/kernel/auditsc.c
85791@@ -1954,7 +1954,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85792 }
85793
85794 /* global counter which is incremented every time something logs in */
85795-static atomic_t session_id = ATOMIC_INIT(0);
85796+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85797
85798 static int audit_set_loginuid_perm(kuid_t loginuid)
85799 {
85800@@ -2023,7 +2023,7 @@ int audit_set_loginuid(kuid_t loginuid)
85801
85802 /* are we setting or clearing? */
85803 if (uid_valid(loginuid))
85804- sessionid = (unsigned int)atomic_inc_return(&session_id);
85805+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85806
85807 task->sessionid = sessionid;
85808 task->loginuid = loginuid;
85809diff --git a/kernel/capability.c b/kernel/capability.c
85810index 1191a44..7c81292 100644
85811--- a/kernel/capability.c
85812+++ b/kernel/capability.c
85813@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85814 * before modification is attempted and the application
85815 * fails.
85816 */
85817+ if (tocopy > ARRAY_SIZE(kdata))
85818+ return -EFAULT;
85819+
85820 if (copy_to_user(dataptr, kdata, tocopy
85821 * sizeof(struct __user_cap_data_struct))) {
85822 return -EFAULT;
85823@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
85824 int ret;
85825
85826 rcu_read_lock();
85827- ret = security_capable(__task_cred(t), ns, cap);
85828+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85829+ gr_task_is_capable(t, __task_cred(t), cap);
85830 rcu_read_unlock();
85831
85832- return (ret == 0);
85833+ return ret;
85834 }
85835
85836 /**
85837@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85838 int ret;
85839
85840 rcu_read_lock();
85841- ret = security_capable_noaudit(__task_cred(t), ns, cap);
85842+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85843 rcu_read_unlock();
85844
85845- return (ret == 0);
85846+ return ret;
85847 }
85848
85849 /**
85850@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85851 BUG();
85852 }
85853
85854- if (security_capable(current_cred(), ns, cap) == 0) {
85855+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85856 current->flags |= PF_SUPERPRIV;
85857 return true;
85858 }
85859@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85860 }
85861 EXPORT_SYMBOL(ns_capable);
85862
85863+bool ns_capable_nolog(struct user_namespace *ns, int cap)
85864+{
85865+ if (unlikely(!cap_valid(cap))) {
85866+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85867+ BUG();
85868+ }
85869+
85870+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85871+ current->flags |= PF_SUPERPRIV;
85872+ return true;
85873+ }
85874+ return false;
85875+}
85876+EXPORT_SYMBOL(ns_capable_nolog);
85877+
85878 /**
85879 * file_ns_capable - Determine if the file's opener had a capability in effect
85880 * @file: The file we want to check
85881@@ -432,6 +451,12 @@ bool capable(int cap)
85882 }
85883 EXPORT_SYMBOL(capable);
85884
85885+bool capable_nolog(int cap)
85886+{
85887+ return ns_capable_nolog(&init_user_ns, cap);
85888+}
85889+EXPORT_SYMBOL(capable_nolog);
85890+
85891 /**
85892 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
85893 * @inode: The inode in question
85894@@ -449,3 +474,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
85895 kgid_has_mapping(ns, inode->i_gid);
85896 }
85897 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
85898+
85899+bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
85900+{
85901+ struct user_namespace *ns = current_user_ns();
85902+
85903+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
85904+ kgid_has_mapping(ns, inode->i_gid);
85905+}
85906+EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
85907diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85908index 0c753dd..dd7d3d6 100644
85909--- a/kernel/cgroup.c
85910+++ b/kernel/cgroup.c
85911@@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85912 struct css_set *cset = link->cset;
85913 struct task_struct *task;
85914 int count = 0;
85915- seq_printf(seq, "css_set %p\n", cset);
85916+ seq_printf(seq, "css_set %pK\n", cset);
85917 list_for_each_entry(task, &cset->tasks, cg_list) {
85918 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
85919 seq_puts(seq, " ...\n");
85920diff --git a/kernel/compat.c b/kernel/compat.c
85921index 0a09e48..b46b3d78 100644
85922--- a/kernel/compat.c
85923+++ b/kernel/compat.c
85924@@ -13,6 +13,7 @@
85925
85926 #include <linux/linkage.h>
85927 #include <linux/compat.h>
85928+#include <linux/module.h>
85929 #include <linux/errno.h>
85930 #include <linux/time.h>
85931 #include <linux/signal.h>
85932@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85933 mm_segment_t oldfs;
85934 long ret;
85935
85936- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85937+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85938 oldfs = get_fs();
85939 set_fs(KERNEL_DS);
85940 ret = hrtimer_nanosleep_restart(restart);
85941@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
85942 oldfs = get_fs();
85943 set_fs(KERNEL_DS);
85944 ret = hrtimer_nanosleep(&tu,
85945- rmtp ? (struct timespec __user *)&rmt : NULL,
85946+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
85947 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85948 set_fs(oldfs);
85949
85950@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
85951 mm_segment_t old_fs = get_fs();
85952
85953 set_fs(KERNEL_DS);
85954- ret = sys_sigpending((old_sigset_t __user *) &s);
85955+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
85956 set_fs(old_fs);
85957 if (ret == 0)
85958 ret = put_user(s, set);
85959@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
85960 mm_segment_t old_fs = get_fs();
85961
85962 set_fs(KERNEL_DS);
85963- ret = sys_old_getrlimit(resource, &r);
85964+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85965 set_fs(old_fs);
85966
85967 if (!ret) {
85968@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85969 set_fs (KERNEL_DS);
85970 ret = sys_wait4(pid,
85971 (stat_addr ?
85972- (unsigned int __user *) &status : NULL),
85973- options, (struct rusage __user *) &r);
85974+ (unsigned int __force_user *) &status : NULL),
85975+ options, (struct rusage __force_user *) &r);
85976 set_fs (old_fs);
85977
85978 if (ret > 0) {
85979@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85980 memset(&info, 0, sizeof(info));
85981
85982 set_fs(KERNEL_DS);
85983- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85984- uru ? (struct rusage __user *)&ru : NULL);
85985+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85986+ uru ? (struct rusage __force_user *)&ru : NULL);
85987 set_fs(old_fs);
85988
85989 if ((ret < 0) || (info.si_signo == 0))
85990@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
85991 oldfs = get_fs();
85992 set_fs(KERNEL_DS);
85993 err = sys_timer_settime(timer_id, flags,
85994- (struct itimerspec __user *) &newts,
85995- (struct itimerspec __user *) &oldts);
85996+ (struct itimerspec __force_user *) &newts,
85997+ (struct itimerspec __force_user *) &oldts);
85998 set_fs(oldfs);
85999 if (!err && old && put_compat_itimerspec(old, &oldts))
86000 return -EFAULT;
86001@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
86002 oldfs = get_fs();
86003 set_fs(KERNEL_DS);
86004 err = sys_timer_gettime(timer_id,
86005- (struct itimerspec __user *) &ts);
86006+ (struct itimerspec __force_user *) &ts);
86007 set_fs(oldfs);
86008 if (!err && put_compat_itimerspec(setting, &ts))
86009 return -EFAULT;
86010@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
86011 oldfs = get_fs();
86012 set_fs(KERNEL_DS);
86013 err = sys_clock_settime(which_clock,
86014- (struct timespec __user *) &ts);
86015+ (struct timespec __force_user *) &ts);
86016 set_fs(oldfs);
86017 return err;
86018 }
86019@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
86020 oldfs = get_fs();
86021 set_fs(KERNEL_DS);
86022 err = sys_clock_gettime(which_clock,
86023- (struct timespec __user *) &ts);
86024+ (struct timespec __force_user *) &ts);
86025 set_fs(oldfs);
86026 if (!err && put_compat_timespec(&ts, tp))
86027 return -EFAULT;
86028@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
86029
86030 oldfs = get_fs();
86031 set_fs(KERNEL_DS);
86032- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
86033+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
86034 set_fs(oldfs);
86035
86036 err = compat_put_timex(utp, &txc);
86037@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
86038 oldfs = get_fs();
86039 set_fs(KERNEL_DS);
86040 err = sys_clock_getres(which_clock,
86041- (struct timespec __user *) &ts);
86042+ (struct timespec __force_user *) &ts);
86043 set_fs(oldfs);
86044 if (!err && tp && put_compat_timespec(&ts, tp))
86045 return -EFAULT;
86046@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
86047 long err;
86048 mm_segment_t oldfs;
86049 struct timespec tu;
86050- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
86051+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
86052
86053- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
86054+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
86055 oldfs = get_fs();
86056 set_fs(KERNEL_DS);
86057 err = clock_nanosleep_restart(restart);
86058@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
86059 oldfs = get_fs();
86060 set_fs(KERNEL_DS);
86061 err = sys_clock_nanosleep(which_clock, flags,
86062- (struct timespec __user *) &in,
86063- (struct timespec __user *) &out);
86064+ (struct timespec __force_user *) &in,
86065+ (struct timespec __force_user *) &out);
86066 set_fs(oldfs);
86067
86068 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
86069@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
86070 mm_segment_t old_fs = get_fs();
86071
86072 set_fs(KERNEL_DS);
86073- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
86074+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
86075 set_fs(old_fs);
86076 if (put_compat_timespec(&t, interval))
86077 return -EFAULT;
86078diff --git a/kernel/configs.c b/kernel/configs.c
86079index c18b1f1..b9a0132 100644
86080--- a/kernel/configs.c
86081+++ b/kernel/configs.c
86082@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
86083 struct proc_dir_entry *entry;
86084
86085 /* create the current config file */
86086+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
86087+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
86088+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
86089+ &ikconfig_file_ops);
86090+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86091+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
86092+ &ikconfig_file_ops);
86093+#endif
86094+#else
86095 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
86096 &ikconfig_file_ops);
86097+#endif
86098+
86099 if (!entry)
86100 return -ENOMEM;
86101
86102diff --git a/kernel/cred.c b/kernel/cred.c
86103index e0573a4..20fb164 100644
86104--- a/kernel/cred.c
86105+++ b/kernel/cred.c
86106@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
86107 validate_creds(cred);
86108 alter_cred_subscribers(cred, -1);
86109 put_cred(cred);
86110+
86111+#ifdef CONFIG_GRKERNSEC_SETXID
86112+ cred = (struct cred *) tsk->delayed_cred;
86113+ if (cred != NULL) {
86114+ tsk->delayed_cred = NULL;
86115+ validate_creds(cred);
86116+ alter_cred_subscribers(cred, -1);
86117+ put_cred(cred);
86118+ }
86119+#endif
86120 }
86121
86122 /**
86123@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
86124 * Always returns 0 thus allowing this function to be tail-called at the end
86125 * of, say, sys_setgid().
86126 */
86127-int commit_creds(struct cred *new)
86128+static int __commit_creds(struct cred *new)
86129 {
86130 struct task_struct *task = current;
86131 const struct cred *old = task->real_cred;
86132@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
86133
86134 get_cred(new); /* we will require a ref for the subj creds too */
86135
86136+ gr_set_role_label(task, new->uid, new->gid);
86137+
86138 /* dumpability changes */
86139 if (!uid_eq(old->euid, new->euid) ||
86140 !gid_eq(old->egid, new->egid) ||
86141@@ -479,6 +491,108 @@ int commit_creds(struct cred *new)
86142 put_cred(old);
86143 return 0;
86144 }
86145+#ifdef CONFIG_GRKERNSEC_SETXID
86146+extern int set_user(struct cred *new);
86147+
86148+void gr_delayed_cred_worker(void)
86149+{
86150+ const struct cred *new = current->delayed_cred;
86151+ struct cred *ncred;
86152+
86153+ current->delayed_cred = NULL;
86154+
86155+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
86156+ // from doing get_cred on it when queueing this
86157+ put_cred(new);
86158+ return;
86159+ } else if (new == NULL)
86160+ return;
86161+
86162+ ncred = prepare_creds();
86163+ if (!ncred)
86164+ goto die;
86165+ // uids
86166+ ncred->uid = new->uid;
86167+ ncred->euid = new->euid;
86168+ ncred->suid = new->suid;
86169+ ncred->fsuid = new->fsuid;
86170+ // gids
86171+ ncred->gid = new->gid;
86172+ ncred->egid = new->egid;
86173+ ncred->sgid = new->sgid;
86174+ ncred->fsgid = new->fsgid;
86175+ // groups
86176+ if (set_groups(ncred, new->group_info) < 0) {
86177+ abort_creds(ncred);
86178+ goto die;
86179+ }
86180+ // caps
86181+ ncred->securebits = new->securebits;
86182+ ncred->cap_inheritable = new->cap_inheritable;
86183+ ncred->cap_permitted = new->cap_permitted;
86184+ ncred->cap_effective = new->cap_effective;
86185+ ncred->cap_bset = new->cap_bset;
86186+
86187+ if (set_user(ncred)) {
86188+ abort_creds(ncred);
86189+ goto die;
86190+ }
86191+
86192+ // from doing get_cred on it when queueing this
86193+ put_cred(new);
86194+
86195+ __commit_creds(ncred);
86196+ return;
86197+die:
86198+ // from doing get_cred on it when queueing this
86199+ put_cred(new);
86200+ do_group_exit(SIGKILL);
86201+}
86202+#endif
86203+
86204+int commit_creds(struct cred *new)
86205+{
86206+#ifdef CONFIG_GRKERNSEC_SETXID
86207+ int ret;
86208+ int schedule_it = 0;
86209+ struct task_struct *t;
86210+ unsigned oldsecurebits = current_cred()->securebits;
86211+
86212+ /* we won't get called with tasklist_lock held for writing
86213+ and interrupts disabled as the cred struct in that case is
86214+ init_cred
86215+ */
86216+ if (grsec_enable_setxid && !current_is_single_threaded() &&
86217+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
86218+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
86219+ schedule_it = 1;
86220+ }
86221+ ret = __commit_creds(new);
86222+ if (schedule_it) {
86223+ rcu_read_lock();
86224+ read_lock(&tasklist_lock);
86225+ for (t = next_thread(current); t != current;
86226+ t = next_thread(t)) {
86227+ /* we'll check if the thread has uid 0 in
86228+ * the delayed worker routine
86229+ */
86230+ if (task_securebits(t) == oldsecurebits &&
86231+ t->delayed_cred == NULL) {
86232+ t->delayed_cred = get_cred(new);
86233+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
86234+ set_tsk_need_resched(t);
86235+ }
86236+ }
86237+ read_unlock(&tasklist_lock);
86238+ rcu_read_unlock();
86239+ }
86240+
86241+ return ret;
86242+#else
86243+ return __commit_creds(new);
86244+#endif
86245+}
86246+
86247 EXPORT_SYMBOL(commit_creds);
86248
86249 /**
86250diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
86251index 334b398..9145fb1 100644
86252--- a/kernel/debug/debug_core.c
86253+++ b/kernel/debug/debug_core.c
86254@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
86255 */
86256 static atomic_t masters_in_kgdb;
86257 static atomic_t slaves_in_kgdb;
86258-static atomic_t kgdb_break_tasklet_var;
86259+static atomic_unchecked_t kgdb_break_tasklet_var;
86260 atomic_t kgdb_setting_breakpoint;
86261
86262 struct task_struct *kgdb_usethread;
86263@@ -133,7 +133,7 @@ int kgdb_single_step;
86264 static pid_t kgdb_sstep_pid;
86265
86266 /* to keep track of the CPU which is doing the single stepping*/
86267-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86268+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86269
86270 /*
86271 * If you are debugging a problem where roundup (the collection of
86272@@ -541,7 +541,7 @@ return_normal:
86273 * kernel will only try for the value of sstep_tries before
86274 * giving up and continuing on.
86275 */
86276- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
86277+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
86278 (kgdb_info[cpu].task &&
86279 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
86280 atomic_set(&kgdb_active, -1);
86281@@ -639,8 +639,8 @@ cpu_master_loop:
86282 }
86283
86284 kgdb_restore:
86285- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
86286- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
86287+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
86288+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
86289 if (kgdb_info[sstep_cpu].task)
86290 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
86291 else
86292@@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
86293 static void kgdb_tasklet_bpt(unsigned long ing)
86294 {
86295 kgdb_breakpoint();
86296- atomic_set(&kgdb_break_tasklet_var, 0);
86297+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
86298 }
86299
86300 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
86301
86302 void kgdb_schedule_breakpoint(void)
86303 {
86304- if (atomic_read(&kgdb_break_tasklet_var) ||
86305+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
86306 atomic_read(&kgdb_active) != -1 ||
86307 atomic_read(&kgdb_setting_breakpoint))
86308 return;
86309- atomic_inc(&kgdb_break_tasklet_var);
86310+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
86311 tasklet_schedule(&kgdb_tasklet_breakpoint);
86312 }
86313 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
86314diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
86315index 0b097c8..11dd5c5 100644
86316--- a/kernel/debug/kdb/kdb_main.c
86317+++ b/kernel/debug/kdb/kdb_main.c
86318@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
86319 continue;
86320
86321 kdb_printf("%-20s%8u 0x%p ", mod->name,
86322- mod->core_size, (void *)mod);
86323+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
86324 #ifdef CONFIG_MODULE_UNLOAD
86325 kdb_printf("%4ld ", module_refcount(mod));
86326 #endif
86327@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
86328 kdb_printf(" (Loading)");
86329 else
86330 kdb_printf(" (Live)");
86331- kdb_printf(" 0x%p", mod->module_core);
86332+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
86333
86334 #ifdef CONFIG_MODULE_UNLOAD
86335 {
86336diff --git a/kernel/events/core.c b/kernel/events/core.c
86337index 0e7fea7..f869fde 100644
86338--- a/kernel/events/core.c
86339+++ b/kernel/events/core.c
86340@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
86341 * 0 - disallow raw tracepoint access for unpriv
86342 * 1 - disallow cpu events for unpriv
86343 * 2 - disallow kernel profiling for unpriv
86344+ * 3 - disallow all unpriv perf event use
86345 */
86346-int sysctl_perf_event_paranoid __read_mostly = 1;
86347+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86348+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
86349+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
86350+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
86351+#else
86352+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
86353+#endif
86354
86355 /* Minimum for 512 kiB + 1 user control page */
86356 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
86357@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
86358
86359 tmp *= sysctl_perf_cpu_time_max_percent;
86360 do_div(tmp, 100);
86361- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
86362+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86363 }
86364
86365 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86366@@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86367 update_perf_cpu_limits();
86368 }
86369
86370-static atomic64_t perf_event_id;
86371+static atomic64_unchecked_t perf_event_id;
86372
86373 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86374 enum event_type_t event_type);
86375@@ -3000,7 +3007,7 @@ static void __perf_event_read(void *info)
86376
86377 static inline u64 perf_event_count(struct perf_event *event)
86378 {
86379- return local64_read(&event->count) + atomic64_read(&event->child_count);
86380+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86381 }
86382
86383 static u64 perf_event_read(struct perf_event *event)
86384@@ -3365,9 +3372,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86385 mutex_lock(&event->child_mutex);
86386 total += perf_event_read(event);
86387 *enabled += event->total_time_enabled +
86388- atomic64_read(&event->child_total_time_enabled);
86389+ atomic64_read_unchecked(&event->child_total_time_enabled);
86390 *running += event->total_time_running +
86391- atomic64_read(&event->child_total_time_running);
86392+ atomic64_read_unchecked(&event->child_total_time_running);
86393
86394 list_for_each_entry(child, &event->child_list, child_list) {
86395 total += perf_event_read(child);
86396@@ -3796,10 +3803,10 @@ void perf_event_update_userpage(struct perf_event *event)
86397 userpg->offset -= local64_read(&event->hw.prev_count);
86398
86399 userpg->time_enabled = enabled +
86400- atomic64_read(&event->child_total_time_enabled);
86401+ atomic64_read_unchecked(&event->child_total_time_enabled);
86402
86403 userpg->time_running = running +
86404- atomic64_read(&event->child_total_time_running);
86405+ atomic64_read_unchecked(&event->child_total_time_running);
86406
86407 arch_perf_update_userpage(userpg, now);
86408
86409@@ -4350,7 +4357,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86410
86411 /* Data. */
86412 sp = perf_user_stack_pointer(regs);
86413- rem = __output_copy_user(handle, (void *) sp, dump_size);
86414+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86415 dyn_size = dump_size - rem;
86416
86417 perf_output_skip(handle, rem);
86418@@ -4441,11 +4448,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86419 values[n++] = perf_event_count(event);
86420 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86421 values[n++] = enabled +
86422- atomic64_read(&event->child_total_time_enabled);
86423+ atomic64_read_unchecked(&event->child_total_time_enabled);
86424 }
86425 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86426 values[n++] = running +
86427- atomic64_read(&event->child_total_time_running);
86428+ atomic64_read_unchecked(&event->child_total_time_running);
86429 }
86430 if (read_format & PERF_FORMAT_ID)
86431 values[n++] = primary_event_id(event);
86432@@ -6724,7 +6731,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86433 event->parent = parent_event;
86434
86435 event->ns = get_pid_ns(task_active_pid_ns(current));
86436- event->id = atomic64_inc_return(&perf_event_id);
86437+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
86438
86439 event->state = PERF_EVENT_STATE_INACTIVE;
86440
86441@@ -7024,6 +7031,11 @@ SYSCALL_DEFINE5(perf_event_open,
86442 if (flags & ~PERF_FLAG_ALL)
86443 return -EINVAL;
86444
86445+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86446+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86447+ return -EACCES;
86448+#endif
86449+
86450 err = perf_copy_attr(attr_uptr, &attr);
86451 if (err)
86452 return err;
86453@@ -7362,10 +7374,10 @@ static void sync_child_event(struct perf_event *child_event,
86454 /*
86455 * Add back the child's count to the parent's count:
86456 */
86457- atomic64_add(child_val, &parent_event->child_count);
86458- atomic64_add(child_event->total_time_enabled,
86459+ atomic64_add_unchecked(child_val, &parent_event->child_count);
86460+ atomic64_add_unchecked(child_event->total_time_enabled,
86461 &parent_event->child_total_time_enabled);
86462- atomic64_add(child_event->total_time_running,
86463+ atomic64_add_unchecked(child_event->total_time_running,
86464 &parent_event->child_total_time_running);
86465
86466 /*
86467diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86468index 569b2187..19940d9 100644
86469--- a/kernel/events/internal.h
86470+++ b/kernel/events/internal.h
86471@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86472 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86473 }
86474
86475-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86476+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86477 static inline unsigned long \
86478 func_name(struct perf_output_handle *handle, \
86479- const void *buf, unsigned long len) \
86480+ const void user *buf, unsigned long len) \
86481 { \
86482 unsigned long size, written; \
86483 \
86484@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86485 return 0;
86486 }
86487
86488-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86489+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86490
86491 static inline unsigned long
86492 memcpy_skip(void *dst, const void *src, unsigned long n)
86493@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86494 return 0;
86495 }
86496
86497-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86498+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86499
86500 #ifndef arch_perf_out_copy_user
86501 #define arch_perf_out_copy_user arch_perf_out_copy_user
86502@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86503 }
86504 #endif
86505
86506-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86507+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86508
86509 /* Callchain handling */
86510 extern struct perf_callchain_entry *
86511diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86512index 307d87c..6466cbe 100644
86513--- a/kernel/events/uprobes.c
86514+++ b/kernel/events/uprobes.c
86515@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86516 {
86517 struct page *page;
86518 uprobe_opcode_t opcode;
86519- int result;
86520+ long result;
86521
86522 pagefault_disable();
86523 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86524diff --git a/kernel/exit.c b/kernel/exit.c
86525index 81b3d67..ef189a4 100644
86526--- a/kernel/exit.c
86527+++ b/kernel/exit.c
86528@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86529 struct task_struct *leader;
86530 int zap_leader;
86531 repeat:
86532+#ifdef CONFIG_NET
86533+ gr_del_task_from_ip_table(p);
86534+#endif
86535+
86536 /* don't need to get the RCU readlock here - the process is dead and
86537 * can't be modifying its own credentials. But shut RCU-lockdep up */
86538 rcu_read_lock();
86539@@ -330,7 +334,7 @@ int allow_signal(int sig)
86540 * know it'll be handled, so that they don't get converted to
86541 * SIGKILL or just silently dropped.
86542 */
86543- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86544+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86545 recalc_sigpending();
86546 spin_unlock_irq(&current->sighand->siglock);
86547 return 0;
86548@@ -706,6 +710,8 @@ void do_exit(long code)
86549 struct task_struct *tsk = current;
86550 int group_dead;
86551
86552+ set_fs(USER_DS);
86553+
86554 profile_task_exit(tsk);
86555
86556 WARN_ON(blk_needs_flush_plug(tsk));
86557@@ -722,7 +728,6 @@ void do_exit(long code)
86558 * mm_release()->clear_child_tid() from writing to a user-controlled
86559 * kernel address.
86560 */
86561- set_fs(USER_DS);
86562
86563 ptrace_event(PTRACE_EVENT_EXIT, code);
86564
86565@@ -781,6 +786,9 @@ void do_exit(long code)
86566 tsk->exit_code = code;
86567 taskstats_exit(tsk, group_dead);
86568
86569+ gr_acl_handle_psacct(tsk, code);
86570+ gr_acl_handle_exit();
86571+
86572 exit_mm(tsk);
86573
86574 if (group_dead)
86575@@ -900,7 +908,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86576 * Take down every thread in the group. This is called by fatal signals
86577 * as well as by sys_exit_group (below).
86578 */
86579-void
86580+__noreturn void
86581 do_group_exit(int exit_code)
86582 {
86583 struct signal_struct *sig = current->signal;
86584diff --git a/kernel/fork.c b/kernel/fork.c
86585index a17621c..d9e4b37 100644
86586--- a/kernel/fork.c
86587+++ b/kernel/fork.c
86588@@ -137,6 +137,18 @@ void __weak arch_release_thread_info(struct thread_info *ti)
86589 {
86590 }
86591
86592+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86593+static struct thread_info *alloc_thread_info_node(struct task_struct *tsk,
86594+ int node)
86595+{
86596+ return vmalloc_stack(node);
86597+}
86598+
86599+static inline void free_thread_info(struct thread_info *ti)
86600+{
86601+ vfree(ti);
86602+}
86603+#else
86604 #ifndef CONFIG_ARCH_THREAD_INFO_ALLOCATOR
86605
86606 /*
86607@@ -179,6 +191,7 @@ void thread_info_cache_init(void)
86608 }
86609 # endif
86610 #endif
86611+#endif
86612
86613 /* SLAB cache for signal_struct structures (tsk->signal) */
86614 static struct kmem_cache *signal_cachep;
86615@@ -200,9 +213,11 @@ static struct kmem_cache *mm_cachep;
86616
86617 static void account_kernel_stack(struct thread_info *ti, int account)
86618 {
86619+#ifndef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86620 struct zone *zone = page_zone(virt_to_page(ti));
86621
86622 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
86623+#endif
86624 }
86625
86626 void free_task(struct task_struct *tsk)
86627@@ -319,7 +334,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86628 *stackend = STACK_END_MAGIC; /* for overflow detection */
86629
86630 #ifdef CONFIG_CC_STACKPROTECTOR
86631- tsk->stack_canary = get_random_int();
86632+ tsk->stack_canary = pax_get_random_long();
86633 #endif
86634
86635 /*
86636@@ -345,12 +360,80 @@ free_tsk:
86637 }
86638
86639 #ifdef CONFIG_MMU
86640-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86641+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86642+{
86643+ struct vm_area_struct *tmp;
86644+ unsigned long charge;
86645+ struct file *file;
86646+ int retval;
86647+
86648+ charge = 0;
86649+ if (mpnt->vm_flags & VM_ACCOUNT) {
86650+ unsigned long len = vma_pages(mpnt);
86651+
86652+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86653+ goto fail_nomem;
86654+ charge = len;
86655+ }
86656+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86657+ if (!tmp)
86658+ goto fail_nomem;
86659+ *tmp = *mpnt;
86660+ tmp->vm_mm = mm;
86661+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
86662+ retval = vma_dup_policy(mpnt, tmp);
86663+ if (retval)
86664+ goto fail_nomem_policy;
86665+ if (anon_vma_fork(tmp, mpnt))
86666+ goto fail_nomem_anon_vma_fork;
86667+ tmp->vm_flags &= ~VM_LOCKED;
86668+ tmp->vm_next = tmp->vm_prev = NULL;
86669+ tmp->vm_mirror = NULL;
86670+ file = tmp->vm_file;
86671+ if (file) {
86672+ struct inode *inode = file_inode(file);
86673+ struct address_space *mapping = file->f_mapping;
86674+
86675+ get_file(file);
86676+ if (tmp->vm_flags & VM_DENYWRITE)
86677+ atomic_dec(&inode->i_writecount);
86678+ mutex_lock(&mapping->i_mmap_mutex);
86679+ if (tmp->vm_flags & VM_SHARED)
86680+ mapping->i_mmap_writable++;
86681+ flush_dcache_mmap_lock(mapping);
86682+ /* insert tmp into the share list, just after mpnt */
86683+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86684+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86685+ else
86686+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86687+ flush_dcache_mmap_unlock(mapping);
86688+ mutex_unlock(&mapping->i_mmap_mutex);
86689+ }
86690+
86691+ /*
86692+ * Clear hugetlb-related page reserves for children. This only
86693+ * affects MAP_PRIVATE mappings. Faults generated by the child
86694+ * are not guaranteed to succeed, even if read-only
86695+ */
86696+ if (is_vm_hugetlb_page(tmp))
86697+ reset_vma_resv_huge_pages(tmp);
86698+
86699+ return tmp;
86700+
86701+fail_nomem_anon_vma_fork:
86702+ mpol_put(vma_policy(tmp));
86703+fail_nomem_policy:
86704+ kmem_cache_free(vm_area_cachep, tmp);
86705+fail_nomem:
86706+ vm_unacct_memory(charge);
86707+ return NULL;
86708+}
86709+
86710+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86711 {
86712 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86713 struct rb_node **rb_link, *rb_parent;
86714 int retval;
86715- unsigned long charge;
86716
86717 uprobe_start_dup_mmap();
86718 down_write(&oldmm->mmap_sem);
86719@@ -379,55 +462,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86720
86721 prev = NULL;
86722 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86723- struct file *file;
86724-
86725 if (mpnt->vm_flags & VM_DONTCOPY) {
86726 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86727 -vma_pages(mpnt));
86728 continue;
86729 }
86730- charge = 0;
86731- if (mpnt->vm_flags & VM_ACCOUNT) {
86732- unsigned long len = vma_pages(mpnt);
86733-
86734- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86735- goto fail_nomem;
86736- charge = len;
86737- }
86738- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86739- if (!tmp)
86740- goto fail_nomem;
86741- *tmp = *mpnt;
86742- INIT_LIST_HEAD(&tmp->anon_vma_chain);
86743- retval = vma_dup_policy(mpnt, tmp);
86744- if (retval)
86745- goto fail_nomem_policy;
86746- tmp->vm_mm = mm;
86747- if (anon_vma_fork(tmp, mpnt))
86748- goto fail_nomem_anon_vma_fork;
86749- tmp->vm_flags &= ~VM_LOCKED;
86750- tmp->vm_next = tmp->vm_prev = NULL;
86751- file = tmp->vm_file;
86752- if (file) {
86753- struct inode *inode = file_inode(file);
86754- struct address_space *mapping = file->f_mapping;
86755-
86756- get_file(file);
86757- if (tmp->vm_flags & VM_DENYWRITE)
86758- atomic_dec(&inode->i_writecount);
86759- mutex_lock(&mapping->i_mmap_mutex);
86760- if (tmp->vm_flags & VM_SHARED)
86761- mapping->i_mmap_writable++;
86762- flush_dcache_mmap_lock(mapping);
86763- /* insert tmp into the share list, just after mpnt */
86764- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86765- vma_nonlinear_insert(tmp,
86766- &mapping->i_mmap_nonlinear);
86767- else
86768- vma_interval_tree_insert_after(tmp, mpnt,
86769- &mapping->i_mmap);
86770- flush_dcache_mmap_unlock(mapping);
86771- mutex_unlock(&mapping->i_mmap_mutex);
86772+ tmp = dup_vma(mm, oldmm, mpnt);
86773+ if (!tmp) {
86774+ retval = -ENOMEM;
86775+ goto out;
86776 }
86777
86778 /*
86779@@ -459,6 +502,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86780 if (retval)
86781 goto out;
86782 }
86783+
86784+#ifdef CONFIG_PAX_SEGMEXEC
86785+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86786+ struct vm_area_struct *mpnt_m;
86787+
86788+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86789+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86790+
86791+ if (!mpnt->vm_mirror)
86792+ continue;
86793+
86794+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86795+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86796+ mpnt->vm_mirror = mpnt_m;
86797+ } else {
86798+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86799+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86800+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86801+ mpnt->vm_mirror->vm_mirror = mpnt;
86802+ }
86803+ }
86804+ BUG_ON(mpnt_m);
86805+ }
86806+#endif
86807+
86808 /* a new mm has just been created */
86809 arch_dup_mmap(oldmm, mm);
86810 retval = 0;
86811@@ -468,14 +536,6 @@ out:
86812 up_write(&oldmm->mmap_sem);
86813 uprobe_end_dup_mmap();
86814 return retval;
86815-fail_nomem_anon_vma_fork:
86816- mpol_put(vma_policy(tmp));
86817-fail_nomem_policy:
86818- kmem_cache_free(vm_area_cachep, tmp);
86819-fail_nomem:
86820- retval = -ENOMEM;
86821- vm_unacct_memory(charge);
86822- goto out;
86823 }
86824
86825 static inline int mm_alloc_pgd(struct mm_struct *mm)
86826@@ -689,8 +749,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86827 return ERR_PTR(err);
86828
86829 mm = get_task_mm(task);
86830- if (mm && mm != current->mm &&
86831- !ptrace_may_access(task, mode)) {
86832+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86833+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86834 mmput(mm);
86835 mm = ERR_PTR(-EACCES);
86836 }
86837@@ -906,13 +966,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86838 spin_unlock(&fs->lock);
86839 return -EAGAIN;
86840 }
86841- fs->users++;
86842+ atomic_inc(&fs->users);
86843 spin_unlock(&fs->lock);
86844 return 0;
86845 }
86846 tsk->fs = copy_fs_struct(fs);
86847 if (!tsk->fs)
86848 return -ENOMEM;
86849+ /* Carry through gr_chroot_dentry and is_chrooted instead
86850+ of recomputing it here. Already copied when the task struct
86851+ is duplicated. This allows pivot_root to not be treated as
86852+ a chroot
86853+ */
86854+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
86855+
86856 return 0;
86857 }
86858
86859@@ -1130,7 +1197,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86860 * parts of the process environment (as per the clone
86861 * flags). The actual kick-off is left to the caller.
86862 */
86863-static struct task_struct *copy_process(unsigned long clone_flags,
86864+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86865 unsigned long stack_start,
86866 unsigned long stack_size,
86867 int __user *child_tidptr,
86868@@ -1202,6 +1269,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86869 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86870 #endif
86871 retval = -EAGAIN;
86872+
86873+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86874+
86875 if (atomic_read(&p->real_cred->user->processes) >=
86876 task_rlimit(p, RLIMIT_NPROC)) {
86877 if (p->real_cred->user != INIT_USER &&
86878@@ -1449,6 +1519,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86879 goto bad_fork_free_pid;
86880 }
86881
86882+ /* synchronizes with gr_set_acls()
86883+ we need to call this past the point of no return for fork()
86884+ */
86885+ gr_copy_label(p);
86886+
86887 if (likely(p->pid)) {
86888 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86889
86890@@ -1537,6 +1612,8 @@ bad_fork_cleanup_count:
86891 bad_fork_free:
86892 free_task(p);
86893 fork_out:
86894+ gr_log_forkfail(retval);
86895+
86896 return ERR_PTR(retval);
86897 }
86898
86899@@ -1598,6 +1675,7 @@ long do_fork(unsigned long clone_flags,
86900
86901 p = copy_process(clone_flags, stack_start, stack_size,
86902 child_tidptr, NULL, trace);
86903+ add_latent_entropy();
86904 /*
86905 * Do this prior waking up the new thread - the thread pointer
86906 * might get invalid after that point, if the thread exits quickly.
86907@@ -1612,6 +1690,8 @@ long do_fork(unsigned long clone_flags,
86908 if (clone_flags & CLONE_PARENT_SETTID)
86909 put_user(nr, parent_tidptr);
86910
86911+ gr_handle_brute_check();
86912+
86913 if (clone_flags & CLONE_VFORK) {
86914 p->vfork_done = &vfork;
86915 init_completion(&vfork);
86916@@ -1728,7 +1808,7 @@ void __init proc_caches_init(void)
86917 mm_cachep = kmem_cache_create("mm_struct",
86918 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86919 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86920- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86921+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86922 mmap_init();
86923 nsproxy_cache_init();
86924 }
86925@@ -1768,7 +1848,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86926 return 0;
86927
86928 /* don't need lock here; in the worst case we'll do useless copy */
86929- if (fs->users == 1)
86930+ if (atomic_read(&fs->users) == 1)
86931 return 0;
86932
86933 *new_fsp = copy_fs_struct(fs);
86934@@ -1875,7 +1955,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86935 fs = current->fs;
86936 spin_lock(&fs->lock);
86937 current->fs = new_fs;
86938- if (--fs->users)
86939+ gr_set_chroot_entries(current, &current->fs->root);
86940+ if (atomic_dec_return(&fs->users))
86941 new_fs = NULL;
86942 else
86943 new_fs = fs;
86944diff --git a/kernel/futex.c b/kernel/futex.c
86945index e3087af..8e3b90f 100644
86946--- a/kernel/futex.c
86947+++ b/kernel/futex.c
86948@@ -54,6 +54,7 @@
86949 #include <linux/mount.h>
86950 #include <linux/pagemap.h>
86951 #include <linux/syscalls.h>
86952+#include <linux/ptrace.h>
86953 #include <linux/signal.h>
86954 #include <linux/export.h>
86955 #include <linux/magic.h>
86956@@ -188,7 +189,7 @@ struct futex_pi_state {
86957 atomic_t refcount;
86958
86959 union futex_key key;
86960-};
86961+} __randomize_layout;
86962
86963 /**
86964 * struct futex_q - The hashed futex queue entry, one per waiting task
86965@@ -222,7 +223,7 @@ struct futex_q {
86966 struct rt_mutex_waiter *rt_waiter;
86967 union futex_key *requeue_pi_key;
86968 u32 bitset;
86969-};
86970+} __randomize_layout;
86971
86972 static const struct futex_q futex_q_init = {
86973 /* list gets initialized in queue_me()*/
86974@@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86975 struct page *page, *page_head;
86976 int err, ro = 0;
86977
86978+#ifdef CONFIG_PAX_SEGMEXEC
86979+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86980+ return -EFAULT;
86981+#endif
86982+
86983 /*
86984 * The futex address must be "naturally" aligned.
86985 */
86986@@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86987
86988 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86989 {
86990- int ret;
86991+ unsigned long ret;
86992
86993 pagefault_disable();
86994 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86995@@ -3019,6 +3025,7 @@ static void __init futex_detect_cmpxchg(void)
86996 {
86997 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86998 u32 curval;
86999+ mm_segment_t oldfs;
87000
87001 /*
87002 * This will fail and we want it. Some arch implementations do
87003@@ -3030,8 +3037,11 @@ static void __init futex_detect_cmpxchg(void)
87004 * implementation, the non-functional ones will return
87005 * -ENOSYS.
87006 */
87007+ oldfs = get_fs();
87008+ set_fs(USER_DS);
87009 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
87010 futex_cmpxchg_enabled = 1;
87011+ set_fs(oldfs);
87012 #endif
87013 }
87014
87015diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
87016index f9f44fd..29885e4 100644
87017--- a/kernel/futex_compat.c
87018+++ b/kernel/futex_compat.c
87019@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
87020 return 0;
87021 }
87022
87023-static void __user *futex_uaddr(struct robust_list __user *entry,
87024+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
87025 compat_long_t futex_offset)
87026 {
87027 compat_uptr_t base = ptr_to_compat(entry);
87028diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
87029index f45b75b..bfac6d5 100644
87030--- a/kernel/gcov/base.c
87031+++ b/kernel/gcov/base.c
87032@@ -108,11 +108,6 @@ void gcov_enable_events(void)
87033 }
87034
87035 #ifdef CONFIG_MODULES
87036-static inline int within(void *addr, void *start, unsigned long size)
87037-{
87038- return ((addr >= start) && (addr < start + size));
87039-}
87040-
87041 /* Update list and generate events when modules are unloaded. */
87042 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
87043 void *data)
87044@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
87045
87046 /* Remove entries located in module from linked list. */
87047 while ((info = gcov_info_next(info))) {
87048- if (within(info, mod->module_core, mod->core_size)) {
87049+ if (within_module_core_rw((unsigned long)info, mod)) {
87050 gcov_info_unlink(prev, info);
87051 if (gcov_events_enabled)
87052 gcov_event(GCOV_REMOVE, info);
87053diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
87054index 04d0374..e7c3725 100644
87055--- a/kernel/hrtimer.c
87056+++ b/kernel/hrtimer.c
87057@@ -1461,7 +1461,7 @@ void hrtimer_peek_ahead_timers(void)
87058 local_irq_restore(flags);
87059 }
87060
87061-static void run_hrtimer_softirq(struct softirq_action *h)
87062+static __latent_entropy void run_hrtimer_softirq(void)
87063 {
87064 hrtimer_peek_ahead_timers();
87065 }
87066diff --git a/kernel/irq_work.c b/kernel/irq_work.c
87067index 55fcce6..0e4cf34 100644
87068--- a/kernel/irq_work.c
87069+++ b/kernel/irq_work.c
87070@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
87071 return NOTIFY_OK;
87072 }
87073
87074-static struct notifier_block cpu_notify;
87075+static struct notifier_block cpu_notify = {
87076+ .notifier_call = irq_work_cpu_notify,
87077+ .priority = 0,
87078+};
87079
87080 static __init int irq_work_init_cpu_notifier(void)
87081 {
87082- cpu_notify.notifier_call = irq_work_cpu_notify;
87083- cpu_notify.priority = 0;
87084 register_cpu_notifier(&cpu_notify);
87085 return 0;
87086 }
87087diff --git a/kernel/jump_label.c b/kernel/jump_label.c
87088index 9019f15..9a3c42e 100644
87089--- a/kernel/jump_label.c
87090+++ b/kernel/jump_label.c
87091@@ -14,6 +14,7 @@
87092 #include <linux/err.h>
87093 #include <linux/static_key.h>
87094 #include <linux/jump_label_ratelimit.h>
87095+#include <linux/mm.h>
87096
87097 #ifdef HAVE_JUMP_LABEL
87098
87099@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
87100
87101 size = (((unsigned long)stop - (unsigned long)start)
87102 / sizeof(struct jump_entry));
87103+ pax_open_kernel();
87104 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
87105+ pax_close_kernel();
87106 }
87107
87108 static void jump_label_update(struct static_key *key, int enable);
87109@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
87110 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
87111 struct jump_entry *iter;
87112
87113+ pax_open_kernel();
87114 for (iter = iter_start; iter < iter_stop; iter++) {
87115 if (within_module_init(iter->code, mod))
87116 iter->code = 0;
87117 }
87118+ pax_close_kernel();
87119 }
87120
87121 static int
87122diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
87123index 3127ad5..159d880 100644
87124--- a/kernel/kallsyms.c
87125+++ b/kernel/kallsyms.c
87126@@ -11,6 +11,9 @@
87127 * Changed the compression method from stem compression to "table lookup"
87128 * compression (see scripts/kallsyms.c for a more complete description)
87129 */
87130+#ifdef CONFIG_GRKERNSEC_HIDESYM
87131+#define __INCLUDED_BY_HIDESYM 1
87132+#endif
87133 #include <linux/kallsyms.h>
87134 #include <linux/module.h>
87135 #include <linux/init.h>
87136@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
87137
87138 static inline int is_kernel_inittext(unsigned long addr)
87139 {
87140+ if (system_state != SYSTEM_BOOTING)
87141+ return 0;
87142+
87143 if (addr >= (unsigned long)_sinittext
87144 && addr <= (unsigned long)_einittext)
87145 return 1;
87146 return 0;
87147 }
87148
87149+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87150+#ifdef CONFIG_MODULES
87151+static inline int is_module_text(unsigned long addr)
87152+{
87153+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
87154+ return 1;
87155+
87156+ addr = ktla_ktva(addr);
87157+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
87158+}
87159+#else
87160+static inline int is_module_text(unsigned long addr)
87161+{
87162+ return 0;
87163+}
87164+#endif
87165+#endif
87166+
87167 static inline int is_kernel_text(unsigned long addr)
87168 {
87169 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
87170@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
87171
87172 static inline int is_kernel(unsigned long addr)
87173 {
87174+
87175+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87176+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
87177+ return 1;
87178+
87179+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
87180+#else
87181 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
87182+#endif
87183+
87184 return 1;
87185 return in_gate_area_no_mm(addr);
87186 }
87187
87188 static int is_ksym_addr(unsigned long addr)
87189 {
87190+
87191+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87192+ if (is_module_text(addr))
87193+ return 0;
87194+#endif
87195+
87196 if (all_var)
87197 return is_kernel(addr);
87198
87199@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
87200
87201 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
87202 {
87203- iter->name[0] = '\0';
87204 iter->nameoff = get_symbol_offset(new_pos);
87205 iter->pos = new_pos;
87206 }
87207@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
87208 {
87209 struct kallsym_iter *iter = m->private;
87210
87211+#ifdef CONFIG_GRKERNSEC_HIDESYM
87212+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
87213+ return 0;
87214+#endif
87215+
87216 /* Some debugging symbols have no name. Ignore them. */
87217 if (!iter->name[0])
87218 return 0;
87219@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
87220 */
87221 type = iter->exported ? toupper(iter->type) :
87222 tolower(iter->type);
87223+
87224 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
87225 type, iter->name, iter->module_name);
87226 } else
87227@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
87228 struct kallsym_iter *iter;
87229 int ret;
87230
87231- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
87232+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
87233 if (!iter)
87234 return -ENOMEM;
87235 reset_iter(iter, 0);
87236diff --git a/kernel/kcmp.c b/kernel/kcmp.c
87237index e30ac0f..3528cac 100644
87238--- a/kernel/kcmp.c
87239+++ b/kernel/kcmp.c
87240@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
87241 struct task_struct *task1, *task2;
87242 int ret;
87243
87244+#ifdef CONFIG_GRKERNSEC
87245+ return -ENOSYS;
87246+#endif
87247+
87248 rcu_read_lock();
87249
87250 /*
87251diff --git a/kernel/kexec.c b/kernel/kexec.c
87252index 18ff0b9..40b0eab 100644
87253--- a/kernel/kexec.c
87254+++ b/kernel/kexec.c
87255@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
87256 unsigned long flags)
87257 {
87258 struct compat_kexec_segment in;
87259- struct kexec_segment out, __user *ksegments;
87260+ struct kexec_segment out;
87261+ struct kexec_segment __user *ksegments;
87262 unsigned long i, result;
87263
87264 /* Don't allow clients that don't understand the native
87265diff --git a/kernel/kmod.c b/kernel/kmod.c
87266index 6b375af..eaff670 100644
87267--- a/kernel/kmod.c
87268+++ b/kernel/kmod.c
87269@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
87270 kfree(info->argv);
87271 }
87272
87273-static int call_modprobe(char *module_name, int wait)
87274+static int call_modprobe(char *module_name, char *module_param, int wait)
87275 {
87276 struct subprocess_info *info;
87277 static char *envp[] = {
87278@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
87279 NULL
87280 };
87281
87282- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
87283+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
87284 if (!argv)
87285 goto out;
87286
87287@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
87288 argv[1] = "-q";
87289 argv[2] = "--";
87290 argv[3] = module_name; /* check free_modprobe_argv() */
87291- argv[4] = NULL;
87292+ argv[4] = module_param;
87293+ argv[5] = NULL;
87294
87295 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87296 NULL, free_modprobe_argv, NULL);
87297@@ -129,9 +130,8 @@ out:
87298 * If module auto-loading support is disabled then this function
87299 * becomes a no-operation.
87300 */
87301-int __request_module(bool wait, const char *fmt, ...)
87302+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87303 {
87304- va_list args;
87305 char module_name[MODULE_NAME_LEN];
87306 unsigned int max_modprobes;
87307 int ret;
87308@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87309 if (!modprobe_path[0])
87310 return 0;
87311
87312- va_start(args, fmt);
87313- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87314- va_end(args);
87315+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87316 if (ret >= MODULE_NAME_LEN)
87317 return -ENAMETOOLONG;
87318
87319@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87320 if (ret)
87321 return ret;
87322
87323+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87324+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87325+ /* hack to workaround consolekit/udisks stupidity */
87326+ read_lock(&tasklist_lock);
87327+ if (!strcmp(current->comm, "mount") &&
87328+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87329+ read_unlock(&tasklist_lock);
87330+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87331+ return -EPERM;
87332+ }
87333+ read_unlock(&tasklist_lock);
87334+ }
87335+#endif
87336+
87337 /* If modprobe needs a service that is in a module, we get a recursive
87338 * loop. Limit the number of running kmod threads to max_threads/2 or
87339 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87340@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87341
87342 trace_module_request(module_name, wait, _RET_IP_);
87343
87344- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87345+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87346
87347 atomic_dec(&kmod_concurrent);
87348 return ret;
87349 }
87350+
87351+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87352+{
87353+ va_list args;
87354+ int ret;
87355+
87356+ va_start(args, fmt);
87357+ ret = ____request_module(wait, module_param, fmt, args);
87358+ va_end(args);
87359+
87360+ return ret;
87361+}
87362+
87363+int __request_module(bool wait, const char *fmt, ...)
87364+{
87365+ va_list args;
87366+ int ret;
87367+
87368+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87369+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87370+ char module_param[MODULE_NAME_LEN];
87371+
87372+ memset(module_param, 0, sizeof(module_param));
87373+
87374+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87375+
87376+ va_start(args, fmt);
87377+ ret = ____request_module(wait, module_param, fmt, args);
87378+ va_end(args);
87379+
87380+ return ret;
87381+ }
87382+#endif
87383+
87384+ va_start(args, fmt);
87385+ ret = ____request_module(wait, NULL, fmt, args);
87386+ va_end(args);
87387+
87388+ return ret;
87389+}
87390+
87391 EXPORT_SYMBOL(__request_module);
87392 #endif /* CONFIG_MODULES */
87393
87394@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87395 */
87396 set_user_nice(current, 0);
87397
87398+#ifdef CONFIG_GRKERNSEC
87399+ /* this is race-free as far as userland is concerned as we copied
87400+ out the path to be used prior to this point and are now operating
87401+ on that copy
87402+ */
87403+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87404+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87405+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87406+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87407+ retval = -EPERM;
87408+ goto fail;
87409+ }
87410+#endif
87411+
87412 retval = -ENOMEM;
87413 new = prepare_kernel_cred(current);
87414 if (!new)
87415@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87416 commit_creds(new);
87417
87418 retval = do_execve(getname_kernel(sub_info->path),
87419- (const char __user *const __user *)sub_info->argv,
87420- (const char __user *const __user *)sub_info->envp);
87421+ (const char __user *const __force_user *)sub_info->argv,
87422+ (const char __user *const __force_user *)sub_info->envp);
87423 if (!retval)
87424 return 0;
87425
87426@@ -260,6 +327,10 @@ static int call_helper(void *data)
87427
87428 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87429 {
87430+#ifdef CONFIG_GRKERNSEC
87431+ kfree(info->path);
87432+ info->path = info->origpath;
87433+#endif
87434 if (info->cleanup)
87435 (*info->cleanup)(info);
87436 kfree(info);
87437@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87438 *
87439 * Thus the __user pointer cast is valid here.
87440 */
87441- sys_wait4(pid, (int __user *)&ret, 0, NULL);
87442+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87443
87444 /*
87445 * If ret is 0, either ____call_usermodehelper failed and the
87446@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87447 goto out;
87448
87449 INIT_WORK(&sub_info->work, __call_usermodehelper);
87450+#ifdef CONFIG_GRKERNSEC
87451+ sub_info->origpath = path;
87452+ sub_info->path = kstrdup(path, gfp_mask);
87453+#else
87454 sub_info->path = path;
87455+#endif
87456 sub_info->argv = argv;
87457 sub_info->envp = envp;
87458
87459@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87460 static int proc_cap_handler(struct ctl_table *table, int write,
87461 void __user *buffer, size_t *lenp, loff_t *ppos)
87462 {
87463- struct ctl_table t;
87464+ ctl_table_no_const t;
87465 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87466 kernel_cap_t new_cap;
87467 int err, i;
87468diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87469index ceeadfc..11c18b6 100644
87470--- a/kernel/kprobes.c
87471+++ b/kernel/kprobes.c
87472@@ -31,6 +31,9 @@
87473 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87474 * <prasanna@in.ibm.com> added function-return probes.
87475 */
87476+#ifdef CONFIG_GRKERNSEC_HIDESYM
87477+#define __INCLUDED_BY_HIDESYM 1
87478+#endif
87479 #include <linux/kprobes.h>
87480 #include <linux/hash.h>
87481 #include <linux/init.h>
87482@@ -135,12 +138,12 @@ enum kprobe_slot_state {
87483
87484 static void *alloc_insn_page(void)
87485 {
87486- return module_alloc(PAGE_SIZE);
87487+ return module_alloc_exec(PAGE_SIZE);
87488 }
87489
87490 static void free_insn_page(void *page)
87491 {
87492- module_free(NULL, page);
87493+ module_free_exec(NULL, page);
87494 }
87495
87496 struct kprobe_insn_cache kprobe_insn_slots = {
87497@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87498 kprobe_type = "k";
87499
87500 if (sym)
87501- seq_printf(pi, "%p %s %s+0x%x %s ",
87502+ seq_printf(pi, "%pK %s %s+0x%x %s ",
87503 p->addr, kprobe_type, sym, offset,
87504 (modname ? modname : " "));
87505 else
87506- seq_printf(pi, "%p %s %p ",
87507+ seq_printf(pi, "%pK %s %pK ",
87508 p->addr, kprobe_type, p->addr);
87509
87510 if (!pp)
87511diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87512index d945a94..0b7f45f 100644
87513--- a/kernel/ksysfs.c
87514+++ b/kernel/ksysfs.c
87515@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87516 {
87517 if (count+1 > UEVENT_HELPER_PATH_LEN)
87518 return -ENOENT;
87519+ if (!capable(CAP_SYS_ADMIN))
87520+ return -EPERM;
87521 memcpy(uevent_helper, buf, count);
87522 uevent_helper[count] = '\0';
87523 if (count && uevent_helper[count-1] == '\n')
87524@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87525 return count;
87526 }
87527
87528-static struct bin_attribute notes_attr = {
87529+static bin_attribute_no_const notes_attr __read_only = {
87530 .attr = {
87531 .name = "notes",
87532 .mode = S_IRUGO,
87533diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87534index eb8a547..321d8e1 100644
87535--- a/kernel/locking/lockdep.c
87536+++ b/kernel/locking/lockdep.c
87537@@ -597,6 +597,10 @@ static int static_obj(void *obj)
87538 end = (unsigned long) &_end,
87539 addr = (unsigned long) obj;
87540
87541+#ifdef CONFIG_PAX_KERNEXEC
87542+ start = ktla_ktva(start);
87543+#endif
87544+
87545 /*
87546 * static variable?
87547 */
87548@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87549 if (!static_obj(lock->key)) {
87550 debug_locks_off();
87551 printk("INFO: trying to register non-static key.\n");
87552+ printk("lock:%pS key:%pS.\n", lock, lock->key);
87553 printk("the code is fine but needs lockdep annotation.\n");
87554 printk("turning off the locking correctness validator.\n");
87555 dump_stack();
87556@@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87557 if (!class)
87558 return 0;
87559 }
87560- atomic_inc((atomic_t *)&class->ops);
87561+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87562 if (very_verbose(class)) {
87563 printk("\nacquire class [%p] %s", class->key, class->name);
87564 if (class->name_version > 1)
87565diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87566index ef43ac4..2720dfa 100644
87567--- a/kernel/locking/lockdep_proc.c
87568+++ b/kernel/locking/lockdep_proc.c
87569@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87570 return 0;
87571 }
87572
87573- seq_printf(m, "%p", class->key);
87574+ seq_printf(m, "%pK", class->key);
87575 #ifdef CONFIG_DEBUG_LOCKDEP
87576 seq_printf(m, " OPS:%8ld", class->ops);
87577 #endif
87578@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87579
87580 list_for_each_entry(entry, &class->locks_after, entry) {
87581 if (entry->distance == 1) {
87582- seq_printf(m, " -> [%p] ", entry->class->key);
87583+ seq_printf(m, " -> [%pK] ", entry->class->key);
87584 print_name(m, entry->class);
87585 seq_puts(m, "\n");
87586 }
87587@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87588 if (!class->key)
87589 continue;
87590
87591- seq_printf(m, "[%p] ", class->key);
87592+ seq_printf(m, "[%pK] ", class->key);
87593 print_name(m, class);
87594 seq_puts(m, "\n");
87595 }
87596@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87597 if (!i)
87598 seq_line(m, '-', 40-namelen, namelen);
87599
87600- snprintf(ip, sizeof(ip), "[<%p>]",
87601+ snprintf(ip, sizeof(ip), "[<%pK>]",
87602 (void *)class->contention_point[i]);
87603 seq_printf(m, "%40s %14lu %29s %pS\n",
87604 name, stats->contention_point[i],
87605@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87606 if (!i)
87607 seq_line(m, '-', 40-namelen, namelen);
87608
87609- snprintf(ip, sizeof(ip), "[<%p>]",
87610+ snprintf(ip, sizeof(ip), "[<%pK>]",
87611 (void *)class->contending_point[i]);
87612 seq_printf(m, "%40s %14lu %29s %pS\n",
87613 name, stats->contending_point[i],
87614diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87615index faf6f5b..dc9070a 100644
87616--- a/kernel/locking/mutex-debug.c
87617+++ b/kernel/locking/mutex-debug.c
87618@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87619 }
87620
87621 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87622- struct thread_info *ti)
87623+ struct task_struct *task)
87624 {
87625 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87626
87627 /* Mark the current thread as blocked on the lock: */
87628- ti->task->blocked_on = waiter;
87629+ task->blocked_on = waiter;
87630 }
87631
87632 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87633- struct thread_info *ti)
87634+ struct task_struct *task)
87635 {
87636 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87637- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87638- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87639- ti->task->blocked_on = NULL;
87640+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
87641+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87642+ task->blocked_on = NULL;
87643
87644 list_del_init(&waiter->list);
87645 waiter->task = NULL;
87646diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87647index 0799fd3..d06ae3b 100644
87648--- a/kernel/locking/mutex-debug.h
87649+++ b/kernel/locking/mutex-debug.h
87650@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87651 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87652 extern void debug_mutex_add_waiter(struct mutex *lock,
87653 struct mutex_waiter *waiter,
87654- struct thread_info *ti);
87655+ struct task_struct *task);
87656 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87657- struct thread_info *ti);
87658+ struct task_struct *task);
87659 extern void debug_mutex_unlock(struct mutex *lock);
87660 extern void debug_mutex_init(struct mutex *lock, const char *name,
87661 struct lock_class_key *key);
87662diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87663index 4dd6e4c..df52693 100644
87664--- a/kernel/locking/mutex.c
87665+++ b/kernel/locking/mutex.c
87666@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
87667 node->locked = 1;
87668 return;
87669 }
87670- ACCESS_ONCE(prev->next) = node;
87671+ ACCESS_ONCE_RW(prev->next) = node;
87672 smp_wmb();
87673 /* Wait until the lock holder passes the lock down */
87674 while (!ACCESS_ONCE(node->locked))
87675@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
87676 while (!(next = ACCESS_ONCE(node->next)))
87677 arch_mutex_cpu_relax();
87678 }
87679- ACCESS_ONCE(next->locked) = 1;
87680+ ACCESS_ONCE_RW(next->locked) = 1;
87681 smp_wmb();
87682 }
87683
87684@@ -520,7 +520,7 @@ slowpath:
87685 goto skip_wait;
87686
87687 debug_mutex_lock_common(lock, &waiter);
87688- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87689+ debug_mutex_add_waiter(lock, &waiter, task);
87690
87691 /* add waiting tasks to the end of the waitqueue (FIFO): */
87692 list_add_tail(&waiter.list, &lock->wait_list);
87693@@ -564,7 +564,7 @@ slowpath:
87694 schedule_preempt_disabled();
87695 spin_lock_mutex(&lock->wait_lock, flags);
87696 }
87697- mutex_remove_waiter(lock, &waiter, current_thread_info());
87698+ mutex_remove_waiter(lock, &waiter, task);
87699 /* set it to 0 if there are no waiters left: */
87700 if (likely(list_empty(&lock->wait_list)))
87701 atomic_set(&lock->count, 0);
87702@@ -601,7 +601,7 @@ skip_wait:
87703 return 0;
87704
87705 err:
87706- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87707+ mutex_remove_waiter(lock, &waiter, task);
87708 spin_unlock_mutex(&lock->wait_lock, flags);
87709 debug_mutex_free_waiter(&waiter);
87710 mutex_release(&lock->dep_map, 1, ip);
87711diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87712index 1d96dd0..994ff19 100644
87713--- a/kernel/locking/rtmutex-tester.c
87714+++ b/kernel/locking/rtmutex-tester.c
87715@@ -22,7 +22,7 @@
87716 #define MAX_RT_TEST_MUTEXES 8
87717
87718 static spinlock_t rttest_lock;
87719-static atomic_t rttest_event;
87720+static atomic_unchecked_t rttest_event;
87721
87722 struct test_thread_data {
87723 int opcode;
87724@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87725
87726 case RTTEST_LOCKCONT:
87727 td->mutexes[td->opdata] = 1;
87728- td->event = atomic_add_return(1, &rttest_event);
87729+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87730 return 0;
87731
87732 case RTTEST_RESET:
87733@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87734 return 0;
87735
87736 case RTTEST_RESETEVENT:
87737- atomic_set(&rttest_event, 0);
87738+ atomic_set_unchecked(&rttest_event, 0);
87739 return 0;
87740
87741 default:
87742@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87743 return ret;
87744
87745 td->mutexes[id] = 1;
87746- td->event = atomic_add_return(1, &rttest_event);
87747+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87748 rt_mutex_lock(&mutexes[id]);
87749- td->event = atomic_add_return(1, &rttest_event);
87750+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87751 td->mutexes[id] = 4;
87752 return 0;
87753
87754@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87755 return ret;
87756
87757 td->mutexes[id] = 1;
87758- td->event = atomic_add_return(1, &rttest_event);
87759+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87760 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87761- td->event = atomic_add_return(1, &rttest_event);
87762+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87763 td->mutexes[id] = ret ? 0 : 4;
87764 return ret ? -EINTR : 0;
87765
87766@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87767 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87768 return ret;
87769
87770- td->event = atomic_add_return(1, &rttest_event);
87771+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87772 rt_mutex_unlock(&mutexes[id]);
87773- td->event = atomic_add_return(1, &rttest_event);
87774+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87775 td->mutexes[id] = 0;
87776 return 0;
87777
87778@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87779 break;
87780
87781 td->mutexes[dat] = 2;
87782- td->event = atomic_add_return(1, &rttest_event);
87783+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87784 break;
87785
87786 default:
87787@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87788 return;
87789
87790 td->mutexes[dat] = 3;
87791- td->event = atomic_add_return(1, &rttest_event);
87792+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87793 break;
87794
87795 case RTTEST_LOCKNOWAIT:
87796@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87797 return;
87798
87799 td->mutexes[dat] = 1;
87800- td->event = atomic_add_return(1, &rttest_event);
87801+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87802 return;
87803
87804 default:
87805diff --git a/kernel/module.c b/kernel/module.c
87806index 6716a1f..9ddc1e1 100644
87807--- a/kernel/module.c
87808+++ b/kernel/module.c
87809@@ -61,6 +61,7 @@
87810 #include <linux/pfn.h>
87811 #include <linux/bsearch.h>
87812 #include <linux/fips.h>
87813+#include <linux/grsecurity.h>
87814 #include <uapi/linux/module.h>
87815 #include "module-internal.h"
87816
87817@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87818
87819 /* Bounds of module allocation, for speeding __module_address.
87820 * Protected by module_mutex. */
87821-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87822+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87823+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87824
87825 int register_module_notifier(struct notifier_block * nb)
87826 {
87827@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87828 return true;
87829
87830 list_for_each_entry_rcu(mod, &modules, list) {
87831- struct symsearch arr[] = {
87832+ struct symsearch modarr[] = {
87833 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87834 NOT_GPL_ONLY, false },
87835 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87836@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87837 if (mod->state == MODULE_STATE_UNFORMED)
87838 continue;
87839
87840- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87841+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87842 return true;
87843 }
87844 return false;
87845@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87846 if (!pcpusec->sh_size)
87847 return 0;
87848
87849- if (align > PAGE_SIZE) {
87850+ if (align-1 >= PAGE_SIZE) {
87851 pr_warn("%s: per-cpu alignment %li > %li\n",
87852 mod->name, align, PAGE_SIZE);
87853 align = PAGE_SIZE;
87854@@ -1059,7 +1061,7 @@ struct module_attribute module_uevent =
87855 static ssize_t show_coresize(struct module_attribute *mattr,
87856 struct module_kobject *mk, char *buffer)
87857 {
87858- return sprintf(buffer, "%u\n", mk->mod->core_size);
87859+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87860 }
87861
87862 static struct module_attribute modinfo_coresize =
87863@@ -1068,7 +1070,7 @@ static struct module_attribute modinfo_coresize =
87864 static ssize_t show_initsize(struct module_attribute *mattr,
87865 struct module_kobject *mk, char *buffer)
87866 {
87867- return sprintf(buffer, "%u\n", mk->mod->init_size);
87868+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87869 }
87870
87871 static struct module_attribute modinfo_initsize =
87872@@ -1160,12 +1162,29 @@ static int check_version(Elf_Shdr *sechdrs,
87873 goto bad_version;
87874 }
87875
87876+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87877+ /*
87878+ * avoid potentially printing jibberish on attempted load
87879+ * of a module randomized with a different seed
87880+ */
87881+ pr_warn("no symbol version for %s\n", symname);
87882+#else
87883 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87884+#endif
87885 return 0;
87886
87887 bad_version:
87888+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87889+ /*
87890+ * avoid potentially printing jibberish on attempted load
87891+ * of a module randomized with a different seed
87892+ */
87893+ printk("attempted module disagrees about version of symbol %s\n",
87894+ symname);
87895+#else
87896 printk("%s: disagrees about version of symbol %s\n",
87897 mod->name, symname);
87898+#endif
87899 return 0;
87900 }
87901
87902@@ -1281,7 +1300,7 @@ resolve_symbol_wait(struct module *mod,
87903 */
87904 #ifdef CONFIG_SYSFS
87905
87906-#ifdef CONFIG_KALLSYMS
87907+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87908 static inline bool sect_empty(const Elf_Shdr *sect)
87909 {
87910 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87911@@ -1421,7 +1440,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87912 {
87913 unsigned int notes, loaded, i;
87914 struct module_notes_attrs *notes_attrs;
87915- struct bin_attribute *nattr;
87916+ bin_attribute_no_const *nattr;
87917
87918 /* failed to create section attributes, so can't create notes */
87919 if (!mod->sect_attrs)
87920@@ -1533,7 +1552,7 @@ static void del_usage_links(struct module *mod)
87921 static int module_add_modinfo_attrs(struct module *mod)
87922 {
87923 struct module_attribute *attr;
87924- struct module_attribute *temp_attr;
87925+ module_attribute_no_const *temp_attr;
87926 int error = 0;
87927 int i;
87928
87929@@ -1754,21 +1773,21 @@ static void set_section_ro_nx(void *base,
87930
87931 static void unset_module_core_ro_nx(struct module *mod)
87932 {
87933- set_page_attributes(mod->module_core + mod->core_text_size,
87934- mod->module_core + mod->core_size,
87935+ set_page_attributes(mod->module_core_rw,
87936+ mod->module_core_rw + mod->core_size_rw,
87937 set_memory_x);
87938- set_page_attributes(mod->module_core,
87939- mod->module_core + mod->core_ro_size,
87940+ set_page_attributes(mod->module_core_rx,
87941+ mod->module_core_rx + mod->core_size_rx,
87942 set_memory_rw);
87943 }
87944
87945 static void unset_module_init_ro_nx(struct module *mod)
87946 {
87947- set_page_attributes(mod->module_init + mod->init_text_size,
87948- mod->module_init + mod->init_size,
87949+ set_page_attributes(mod->module_init_rw,
87950+ mod->module_init_rw + mod->init_size_rw,
87951 set_memory_x);
87952- set_page_attributes(mod->module_init,
87953- mod->module_init + mod->init_ro_size,
87954+ set_page_attributes(mod->module_init_rx,
87955+ mod->module_init_rx + mod->init_size_rx,
87956 set_memory_rw);
87957 }
87958
87959@@ -1781,14 +1800,14 @@ void set_all_modules_text_rw(void)
87960 list_for_each_entry_rcu(mod, &modules, list) {
87961 if (mod->state == MODULE_STATE_UNFORMED)
87962 continue;
87963- if ((mod->module_core) && (mod->core_text_size)) {
87964- set_page_attributes(mod->module_core,
87965- mod->module_core + mod->core_text_size,
87966+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87967+ set_page_attributes(mod->module_core_rx,
87968+ mod->module_core_rx + mod->core_size_rx,
87969 set_memory_rw);
87970 }
87971- if ((mod->module_init) && (mod->init_text_size)) {
87972- set_page_attributes(mod->module_init,
87973- mod->module_init + mod->init_text_size,
87974+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87975+ set_page_attributes(mod->module_init_rx,
87976+ mod->module_init_rx + mod->init_size_rx,
87977 set_memory_rw);
87978 }
87979 }
87980@@ -1804,14 +1823,14 @@ void set_all_modules_text_ro(void)
87981 list_for_each_entry_rcu(mod, &modules, list) {
87982 if (mod->state == MODULE_STATE_UNFORMED)
87983 continue;
87984- if ((mod->module_core) && (mod->core_text_size)) {
87985- set_page_attributes(mod->module_core,
87986- mod->module_core + mod->core_text_size,
87987+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87988+ set_page_attributes(mod->module_core_rx,
87989+ mod->module_core_rx + mod->core_size_rx,
87990 set_memory_ro);
87991 }
87992- if ((mod->module_init) && (mod->init_text_size)) {
87993- set_page_attributes(mod->module_init,
87994- mod->module_init + mod->init_text_size,
87995+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87996+ set_page_attributes(mod->module_init_rx,
87997+ mod->module_init_rx + mod->init_size_rx,
87998 set_memory_ro);
87999 }
88000 }
88001@@ -1862,16 +1881,19 @@ static void free_module(struct module *mod)
88002
88003 /* This may be NULL, but that's OK */
88004 unset_module_init_ro_nx(mod);
88005- module_free(mod, mod->module_init);
88006+ module_free(mod, mod->module_init_rw);
88007+ module_free_exec(mod, mod->module_init_rx);
88008 kfree(mod->args);
88009 percpu_modfree(mod);
88010
88011 /* Free lock-classes: */
88012- lockdep_free_key_range(mod->module_core, mod->core_size);
88013+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
88014+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
88015
88016 /* Finally, free the core (containing the module structure) */
88017 unset_module_core_ro_nx(mod);
88018- module_free(mod, mod->module_core);
88019+ module_free_exec(mod, mod->module_core_rx);
88020+ module_free(mod, mod->module_core_rw);
88021
88022 #ifdef CONFIG_MPU
88023 update_protections(current->mm);
88024@@ -1940,9 +1962,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88025 int ret = 0;
88026 const struct kernel_symbol *ksym;
88027
88028+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88029+ int is_fs_load = 0;
88030+ int register_filesystem_found = 0;
88031+ char *p;
88032+
88033+ p = strstr(mod->args, "grsec_modharden_fs");
88034+ if (p) {
88035+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
88036+ /* copy \0 as well */
88037+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
88038+ is_fs_load = 1;
88039+ }
88040+#endif
88041+
88042 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
88043 const char *name = info->strtab + sym[i].st_name;
88044
88045+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88046+ /* it's a real shame this will never get ripped and copied
88047+ upstream! ;(
88048+ */
88049+ if (is_fs_load && !strcmp(name, "register_filesystem"))
88050+ register_filesystem_found = 1;
88051+#endif
88052+
88053 switch (sym[i].st_shndx) {
88054 case SHN_COMMON:
88055 /* We compiled with -fno-common. These are not
88056@@ -1963,7 +2007,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88057 ksym = resolve_symbol_wait(mod, info, name);
88058 /* Ok if resolved. */
88059 if (ksym && !IS_ERR(ksym)) {
88060+ pax_open_kernel();
88061 sym[i].st_value = ksym->value;
88062+ pax_close_kernel();
88063 break;
88064 }
88065
88066@@ -1982,11 +2028,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88067 secbase = (unsigned long)mod_percpu(mod);
88068 else
88069 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
88070+ pax_open_kernel();
88071 sym[i].st_value += secbase;
88072+ pax_close_kernel();
88073 break;
88074 }
88075 }
88076
88077+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88078+ if (is_fs_load && !register_filesystem_found) {
88079+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
88080+ ret = -EPERM;
88081+ }
88082+#endif
88083+
88084 return ret;
88085 }
88086
88087@@ -2070,22 +2125,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
88088 || s->sh_entsize != ~0UL
88089 || strstarts(sname, ".init"))
88090 continue;
88091- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
88092+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88093+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
88094+ else
88095+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
88096 pr_debug("\t%s\n", sname);
88097 }
88098- switch (m) {
88099- case 0: /* executable */
88100- mod->core_size = debug_align(mod->core_size);
88101- mod->core_text_size = mod->core_size;
88102- break;
88103- case 1: /* RO: text and ro-data */
88104- mod->core_size = debug_align(mod->core_size);
88105- mod->core_ro_size = mod->core_size;
88106- break;
88107- case 3: /* whole core */
88108- mod->core_size = debug_align(mod->core_size);
88109- break;
88110- }
88111 }
88112
88113 pr_debug("Init section allocation order:\n");
88114@@ -2099,23 +2144,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
88115 || s->sh_entsize != ~0UL
88116 || !strstarts(sname, ".init"))
88117 continue;
88118- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
88119- | INIT_OFFSET_MASK);
88120+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88121+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
88122+ else
88123+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
88124+ s->sh_entsize |= INIT_OFFSET_MASK;
88125 pr_debug("\t%s\n", sname);
88126 }
88127- switch (m) {
88128- case 0: /* executable */
88129- mod->init_size = debug_align(mod->init_size);
88130- mod->init_text_size = mod->init_size;
88131- break;
88132- case 1: /* RO: text and ro-data */
88133- mod->init_size = debug_align(mod->init_size);
88134- mod->init_ro_size = mod->init_size;
88135- break;
88136- case 3: /* whole init */
88137- mod->init_size = debug_align(mod->init_size);
88138- break;
88139- }
88140 }
88141 }
88142
88143@@ -2288,7 +2323,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88144
88145 /* Put symbol section at end of init part of module. */
88146 symsect->sh_flags |= SHF_ALLOC;
88147- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
88148+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
88149 info->index.sym) | INIT_OFFSET_MASK;
88150 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
88151
88152@@ -2305,13 +2340,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88153 }
88154
88155 /* Append room for core symbols at end of core part. */
88156- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
88157- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
88158- mod->core_size += strtab_size;
88159+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
88160+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
88161+ mod->core_size_rx += strtab_size;
88162
88163 /* Put string table section at end of init part of module. */
88164 strsect->sh_flags |= SHF_ALLOC;
88165- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
88166+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
88167 info->index.str) | INIT_OFFSET_MASK;
88168 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
88169 }
88170@@ -2329,12 +2364,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88171 /* Make sure we get permanent strtab: don't use info->strtab. */
88172 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
88173
88174+ pax_open_kernel();
88175+
88176 /* Set types up while we still have access to sections. */
88177 for (i = 0; i < mod->num_symtab; i++)
88178 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
88179
88180- mod->core_symtab = dst = mod->module_core + info->symoffs;
88181- mod->core_strtab = s = mod->module_core + info->stroffs;
88182+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
88183+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
88184 src = mod->symtab;
88185 for (ndst = i = 0; i < mod->num_symtab; i++) {
88186 if (i == 0 ||
88187@@ -2346,6 +2383,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88188 }
88189 }
88190 mod->core_num_syms = ndst;
88191+
88192+ pax_close_kernel();
88193 }
88194 #else
88195 static inline void layout_symtab(struct module *mod, struct load_info *info)
88196@@ -2379,17 +2418,33 @@ void * __weak module_alloc(unsigned long size)
88197 return vmalloc_exec(size);
88198 }
88199
88200-static void *module_alloc_update_bounds(unsigned long size)
88201+static void *module_alloc_update_bounds_rw(unsigned long size)
88202 {
88203 void *ret = module_alloc(size);
88204
88205 if (ret) {
88206 mutex_lock(&module_mutex);
88207 /* Update module bounds. */
88208- if ((unsigned long)ret < module_addr_min)
88209- module_addr_min = (unsigned long)ret;
88210- if ((unsigned long)ret + size > module_addr_max)
88211- module_addr_max = (unsigned long)ret + size;
88212+ if ((unsigned long)ret < module_addr_min_rw)
88213+ module_addr_min_rw = (unsigned long)ret;
88214+ if ((unsigned long)ret + size > module_addr_max_rw)
88215+ module_addr_max_rw = (unsigned long)ret + size;
88216+ mutex_unlock(&module_mutex);
88217+ }
88218+ return ret;
88219+}
88220+
88221+static void *module_alloc_update_bounds_rx(unsigned long size)
88222+{
88223+ void *ret = module_alloc_exec(size);
88224+
88225+ if (ret) {
88226+ mutex_lock(&module_mutex);
88227+ /* Update module bounds. */
88228+ if ((unsigned long)ret < module_addr_min_rx)
88229+ module_addr_min_rx = (unsigned long)ret;
88230+ if ((unsigned long)ret + size > module_addr_max_rx)
88231+ module_addr_max_rx = (unsigned long)ret + size;
88232 mutex_unlock(&module_mutex);
88233 }
88234 return ret;
88235@@ -2646,7 +2701,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88236 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
88237
88238 if (info->index.sym == 0) {
88239+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88240+ /*
88241+ * avoid potentially printing jibberish on attempted load
88242+ * of a module randomized with a different seed
88243+ */
88244+ pr_warn("module has no symbols (stripped?)\n");
88245+#else
88246 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
88247+#endif
88248 return ERR_PTR(-ENOEXEC);
88249 }
88250
88251@@ -2662,8 +2725,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88252 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88253 {
88254 const char *modmagic = get_modinfo(info, "vermagic");
88255+ const char *license = get_modinfo(info, "license");
88256 int err;
88257
88258+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
88259+ if (!license || !license_is_gpl_compatible(license))
88260+ return -ENOEXEC;
88261+#endif
88262+
88263 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
88264 modmagic = NULL;
88265
88266@@ -2688,7 +2757,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88267 }
88268
88269 /* Set up license info based on the info section */
88270- set_license(mod, get_modinfo(info, "license"));
88271+ set_license(mod, license);
88272
88273 return 0;
88274 }
88275@@ -2782,7 +2851,7 @@ static int move_module(struct module *mod, struct load_info *info)
88276 void *ptr;
88277
88278 /* Do the allocs. */
88279- ptr = module_alloc_update_bounds(mod->core_size);
88280+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
88281 /*
88282 * The pointer to this block is stored in the module structure
88283 * which is inside the block. Just mark it as not being a
88284@@ -2792,11 +2861,11 @@ static int move_module(struct module *mod, struct load_info *info)
88285 if (!ptr)
88286 return -ENOMEM;
88287
88288- memset(ptr, 0, mod->core_size);
88289- mod->module_core = ptr;
88290+ memset(ptr, 0, mod->core_size_rw);
88291+ mod->module_core_rw = ptr;
88292
88293- if (mod->init_size) {
88294- ptr = module_alloc_update_bounds(mod->init_size);
88295+ if (mod->init_size_rw) {
88296+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88297 /*
88298 * The pointer to this block is stored in the module structure
88299 * which is inside the block. This block doesn't need to be
88300@@ -2805,13 +2874,45 @@ static int move_module(struct module *mod, struct load_info *info)
88301 */
88302 kmemleak_ignore(ptr);
88303 if (!ptr) {
88304- module_free(mod, mod->module_core);
88305+ module_free(mod, mod->module_core_rw);
88306 return -ENOMEM;
88307 }
88308- memset(ptr, 0, mod->init_size);
88309- mod->module_init = ptr;
88310+ memset(ptr, 0, mod->init_size_rw);
88311+ mod->module_init_rw = ptr;
88312 } else
88313- mod->module_init = NULL;
88314+ mod->module_init_rw = NULL;
88315+
88316+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88317+ kmemleak_not_leak(ptr);
88318+ if (!ptr) {
88319+ if (mod->module_init_rw)
88320+ module_free(mod, mod->module_init_rw);
88321+ module_free(mod, mod->module_core_rw);
88322+ return -ENOMEM;
88323+ }
88324+
88325+ pax_open_kernel();
88326+ memset(ptr, 0, mod->core_size_rx);
88327+ pax_close_kernel();
88328+ mod->module_core_rx = ptr;
88329+
88330+ if (mod->init_size_rx) {
88331+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88332+ kmemleak_ignore(ptr);
88333+ if (!ptr && mod->init_size_rx) {
88334+ module_free_exec(mod, mod->module_core_rx);
88335+ if (mod->module_init_rw)
88336+ module_free(mod, mod->module_init_rw);
88337+ module_free(mod, mod->module_core_rw);
88338+ return -ENOMEM;
88339+ }
88340+
88341+ pax_open_kernel();
88342+ memset(ptr, 0, mod->init_size_rx);
88343+ pax_close_kernel();
88344+ mod->module_init_rx = ptr;
88345+ } else
88346+ mod->module_init_rx = NULL;
88347
88348 /* Transfer each section which specifies SHF_ALLOC */
88349 pr_debug("final section addresses:\n");
88350@@ -2822,16 +2923,45 @@ static int move_module(struct module *mod, struct load_info *info)
88351 if (!(shdr->sh_flags & SHF_ALLOC))
88352 continue;
88353
88354- if (shdr->sh_entsize & INIT_OFFSET_MASK)
88355- dest = mod->module_init
88356- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88357- else
88358- dest = mod->module_core + shdr->sh_entsize;
88359+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88360+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88361+ dest = mod->module_init_rw
88362+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88363+ else
88364+ dest = mod->module_init_rx
88365+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88366+ } else {
88367+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88368+ dest = mod->module_core_rw + shdr->sh_entsize;
88369+ else
88370+ dest = mod->module_core_rx + shdr->sh_entsize;
88371+ }
88372+
88373+ if (shdr->sh_type != SHT_NOBITS) {
88374+
88375+#ifdef CONFIG_PAX_KERNEXEC
88376+#ifdef CONFIG_X86_64
88377+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88378+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88379+#endif
88380+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88381+ pax_open_kernel();
88382+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88383+ pax_close_kernel();
88384+ } else
88385+#endif
88386
88387- if (shdr->sh_type != SHT_NOBITS)
88388 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88389+ }
88390 /* Update sh_addr to point to copy in image. */
88391- shdr->sh_addr = (unsigned long)dest;
88392+
88393+#ifdef CONFIG_PAX_KERNEXEC
88394+ if (shdr->sh_flags & SHF_EXECINSTR)
88395+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
88396+ else
88397+#endif
88398+
88399+ shdr->sh_addr = (unsigned long)dest;
88400 pr_debug("\t0x%lx %s\n",
88401 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88402 }
88403@@ -2888,12 +3018,12 @@ static void flush_module_icache(const struct module *mod)
88404 * Do it before processing of module parameters, so the module
88405 * can provide parameter accessor functions of its own.
88406 */
88407- if (mod->module_init)
88408- flush_icache_range((unsigned long)mod->module_init,
88409- (unsigned long)mod->module_init
88410- + mod->init_size);
88411- flush_icache_range((unsigned long)mod->module_core,
88412- (unsigned long)mod->module_core + mod->core_size);
88413+ if (mod->module_init_rx)
88414+ flush_icache_range((unsigned long)mod->module_init_rx,
88415+ (unsigned long)mod->module_init_rx
88416+ + mod->init_size_rx);
88417+ flush_icache_range((unsigned long)mod->module_core_rx,
88418+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
88419
88420 set_fs(old_fs);
88421 }
88422@@ -2950,8 +3080,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88423 static void module_deallocate(struct module *mod, struct load_info *info)
88424 {
88425 percpu_modfree(mod);
88426- module_free(mod, mod->module_init);
88427- module_free(mod, mod->module_core);
88428+ module_free_exec(mod, mod->module_init_rx);
88429+ module_free_exec(mod, mod->module_core_rx);
88430+ module_free(mod, mod->module_init_rw);
88431+ module_free(mod, mod->module_core_rw);
88432 }
88433
88434 int __weak module_finalize(const Elf_Ehdr *hdr,
88435@@ -2964,7 +3096,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88436 static int post_relocation(struct module *mod, const struct load_info *info)
88437 {
88438 /* Sort exception table now relocations are done. */
88439+ pax_open_kernel();
88440 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88441+ pax_close_kernel();
88442
88443 /* Copy relocated percpu area over. */
88444 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88445@@ -3018,16 +3152,16 @@ static int do_init_module(struct module *mod)
88446 MODULE_STATE_COMING, mod);
88447
88448 /* Set RO and NX regions for core */
88449- set_section_ro_nx(mod->module_core,
88450- mod->core_text_size,
88451- mod->core_ro_size,
88452- mod->core_size);
88453+ set_section_ro_nx(mod->module_core_rx,
88454+ mod->core_size_rx,
88455+ mod->core_size_rx,
88456+ mod->core_size_rx);
88457
88458 /* Set RO and NX regions for init */
88459- set_section_ro_nx(mod->module_init,
88460- mod->init_text_size,
88461- mod->init_ro_size,
88462- mod->init_size);
88463+ set_section_ro_nx(mod->module_init_rx,
88464+ mod->init_size_rx,
88465+ mod->init_size_rx,
88466+ mod->init_size_rx);
88467
88468 do_mod_ctors(mod);
88469 /* Start the module */
88470@@ -3088,11 +3222,12 @@ static int do_init_module(struct module *mod)
88471 mod->strtab = mod->core_strtab;
88472 #endif
88473 unset_module_init_ro_nx(mod);
88474- module_free(mod, mod->module_init);
88475- mod->module_init = NULL;
88476- mod->init_size = 0;
88477- mod->init_ro_size = 0;
88478- mod->init_text_size = 0;
88479+ module_free(mod, mod->module_init_rw);
88480+ module_free_exec(mod, mod->module_init_rx);
88481+ mod->module_init_rw = NULL;
88482+ mod->module_init_rx = NULL;
88483+ mod->init_size_rw = 0;
88484+ mod->init_size_rx = 0;
88485 mutex_unlock(&module_mutex);
88486 wake_up_all(&module_wq);
88487
88488@@ -3235,9 +3370,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88489 if (err)
88490 goto free_unload;
88491
88492+ /* Now copy in args */
88493+ mod->args = strndup_user(uargs, ~0UL >> 1);
88494+ if (IS_ERR(mod->args)) {
88495+ err = PTR_ERR(mod->args);
88496+ goto free_unload;
88497+ }
88498+
88499 /* Set up MODINFO_ATTR fields */
88500 setup_modinfo(mod, info);
88501
88502+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88503+ {
88504+ char *p, *p2;
88505+
88506+ if (strstr(mod->args, "grsec_modharden_netdev")) {
88507+ 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);
88508+ err = -EPERM;
88509+ goto free_modinfo;
88510+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88511+ p += sizeof("grsec_modharden_normal") - 1;
88512+ p2 = strstr(p, "_");
88513+ if (p2) {
88514+ *p2 = '\0';
88515+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88516+ *p2 = '_';
88517+ }
88518+ err = -EPERM;
88519+ goto free_modinfo;
88520+ }
88521+ }
88522+#endif
88523+
88524 /* Fix up syms, so that st_value is a pointer to location. */
88525 err = simplify_symbols(mod, info);
88526 if (err < 0)
88527@@ -3253,13 +3417,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88528
88529 flush_module_icache(mod);
88530
88531- /* Now copy in args */
88532- mod->args = strndup_user(uargs, ~0UL >> 1);
88533- if (IS_ERR(mod->args)) {
88534- err = PTR_ERR(mod->args);
88535- goto free_arch_cleanup;
88536- }
88537-
88538 dynamic_debug_setup(info->debug, info->num_debug);
88539
88540 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
88541@@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88542 ddebug_cleanup:
88543 dynamic_debug_remove(info->debug);
88544 synchronize_sched();
88545- kfree(mod->args);
88546- free_arch_cleanup:
88547 module_arch_cleanup(mod);
88548 free_modinfo:
88549 free_modinfo(mod);
88550+ kfree(mod->args);
88551 free_unload:
88552 module_unload_free(mod);
88553 unlink_mod:
88554@@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
88555 unsigned long nextval;
88556
88557 /* At worse, next value is at end of module */
88558- if (within_module_init(addr, mod))
88559- nextval = (unsigned long)mod->module_init+mod->init_text_size;
88560+ if (within_module_init_rx(addr, mod))
88561+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88562+ else if (within_module_init_rw(addr, mod))
88563+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88564+ else if (within_module_core_rx(addr, mod))
88565+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88566+ else if (within_module_core_rw(addr, mod))
88567+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88568 else
88569- nextval = (unsigned long)mod->module_core+mod->core_text_size;
88570+ return NULL;
88571
88572 /* Scan for closest preceding symbol, and next symbol. (ELF
88573 starts real symbols at 1). */
88574@@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
88575 return 0;
88576
88577 seq_printf(m, "%s %u",
88578- mod->name, mod->init_size + mod->core_size);
88579+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88580 print_unload_info(m, mod);
88581
88582 /* Informative for users. */
88583@@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
88584 mod->state == MODULE_STATE_COMING ? "Loading":
88585 "Live");
88586 /* Used by oprofile and other similar tools. */
88587- seq_printf(m, " 0x%pK", mod->module_core);
88588+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88589
88590 /* Taints info */
88591 if (mod->taints)
88592@@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
88593
88594 static int __init proc_modules_init(void)
88595 {
88596+#ifndef CONFIG_GRKERNSEC_HIDESYM
88597+#ifdef CONFIG_GRKERNSEC_PROC_USER
88598+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88599+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88600+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88601+#else
88602 proc_create("modules", 0, NULL, &proc_modules_operations);
88603+#endif
88604+#else
88605+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88606+#endif
88607 return 0;
88608 }
88609 module_init(proc_modules_init);
88610@@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
88611 {
88612 struct module *mod;
88613
88614- if (addr < module_addr_min || addr > module_addr_max)
88615+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88616+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
88617 return NULL;
88618
88619 list_for_each_entry_rcu(mod, &modules, list) {
88620 if (mod->state == MODULE_STATE_UNFORMED)
88621 continue;
88622- if (within_module_core(addr, mod)
88623- || within_module_init(addr, mod))
88624+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
88625 return mod;
88626 }
88627 return NULL;
88628@@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
88629 */
88630 struct module *__module_text_address(unsigned long addr)
88631 {
88632- struct module *mod = __module_address(addr);
88633+ struct module *mod;
88634+
88635+#ifdef CONFIG_X86_32
88636+ addr = ktla_ktva(addr);
88637+#endif
88638+
88639+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88640+ return NULL;
88641+
88642+ mod = __module_address(addr);
88643+
88644 if (mod) {
88645 /* Make sure it's within the text section. */
88646- if (!within(addr, mod->module_init, mod->init_text_size)
88647- && !within(addr, mod->module_core, mod->core_text_size))
88648+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88649 mod = NULL;
88650 }
88651 return mod;
88652diff --git a/kernel/notifier.c b/kernel/notifier.c
88653index 2d5cc4c..d9ea600 100644
88654--- a/kernel/notifier.c
88655+++ b/kernel/notifier.c
88656@@ -5,6 +5,7 @@
88657 #include <linux/rcupdate.h>
88658 #include <linux/vmalloc.h>
88659 #include <linux/reboot.h>
88660+#include <linux/mm.h>
88661
88662 /*
88663 * Notifier list for kernel code which wants to be called
88664@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88665 while ((*nl) != NULL) {
88666 if (n->priority > (*nl)->priority)
88667 break;
88668- nl = &((*nl)->next);
88669+ nl = (struct notifier_block **)&((*nl)->next);
88670 }
88671- n->next = *nl;
88672+ pax_open_kernel();
88673+ *(const void **)&n->next = *nl;
88674 rcu_assign_pointer(*nl, n);
88675+ pax_close_kernel();
88676 return 0;
88677 }
88678
88679@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88680 return 0;
88681 if (n->priority > (*nl)->priority)
88682 break;
88683- nl = &((*nl)->next);
88684+ nl = (struct notifier_block **)&((*nl)->next);
88685 }
88686- n->next = *nl;
88687+ pax_open_kernel();
88688+ *(const void **)&n->next = *nl;
88689 rcu_assign_pointer(*nl, n);
88690+ pax_close_kernel();
88691 return 0;
88692 }
88693
88694@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88695 {
88696 while ((*nl) != NULL) {
88697 if ((*nl) == n) {
88698+ pax_open_kernel();
88699 rcu_assign_pointer(*nl, n->next);
88700+ pax_close_kernel();
88701 return 0;
88702 }
88703- nl = &((*nl)->next);
88704+ nl = (struct notifier_block **)&((*nl)->next);
88705 }
88706 return -ENOENT;
88707 }
88708diff --git a/kernel/padata.c b/kernel/padata.c
88709index 161402f..598814c 100644
88710--- a/kernel/padata.c
88711+++ b/kernel/padata.c
88712@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88713 * seq_nr mod. number of cpus in use.
88714 */
88715
88716- seq_nr = atomic_inc_return(&pd->seq_nr);
88717+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88718 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88719
88720 return padata_index_to_cpu(pd, cpu_index);
88721@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88722 padata_init_pqueues(pd);
88723 padata_init_squeues(pd);
88724 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88725- atomic_set(&pd->seq_nr, -1);
88726+ atomic_set_unchecked(&pd->seq_nr, -1);
88727 atomic_set(&pd->reorder_objects, 0);
88728 atomic_set(&pd->refcnt, 0);
88729 pd->pinst = pinst;
88730diff --git a/kernel/panic.c b/kernel/panic.c
88731index 6d63003..486a109 100644
88732--- a/kernel/panic.c
88733+++ b/kernel/panic.c
88734@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88735 /*
88736 * Stop ourself in panic -- architecture code may override this
88737 */
88738-void __weak panic_smp_self_stop(void)
88739+void __weak __noreturn panic_smp_self_stop(void)
88740 {
88741 while (1)
88742 cpu_relax();
88743@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88744 disable_trace_on_warning();
88745
88746 pr_warn("------------[ cut here ]------------\n");
88747- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88748+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88749 raw_smp_processor_id(), current->pid, file, line, caller);
88750
88751 if (args)
88752@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88753 */
88754 void __stack_chk_fail(void)
88755 {
88756- panic("stack-protector: Kernel stack is corrupted in: %p\n",
88757+ dump_stack();
88758+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88759 __builtin_return_address(0));
88760 }
88761 EXPORT_SYMBOL(__stack_chk_fail);
88762diff --git a/kernel/pid.c b/kernel/pid.c
88763index 9b9a266..c20ef80 100644
88764--- a/kernel/pid.c
88765+++ b/kernel/pid.c
88766@@ -33,6 +33,7 @@
88767 #include <linux/rculist.h>
88768 #include <linux/bootmem.h>
88769 #include <linux/hash.h>
88770+#include <linux/security.h>
88771 #include <linux/pid_namespace.h>
88772 #include <linux/init_task.h>
88773 #include <linux/syscalls.h>
88774@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88775
88776 int pid_max = PID_MAX_DEFAULT;
88777
88778-#define RESERVED_PIDS 300
88779+#define RESERVED_PIDS 500
88780
88781 int pid_max_min = RESERVED_PIDS + 1;
88782 int pid_max_max = PID_MAX_LIMIT;
88783@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88784 */
88785 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88786 {
88787+ struct task_struct *task;
88788+
88789 rcu_lockdep_assert(rcu_read_lock_held(),
88790 "find_task_by_pid_ns() needs rcu_read_lock()"
88791 " protection");
88792- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88793+
88794+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88795+
88796+ if (gr_pid_is_chrooted(task))
88797+ return NULL;
88798+
88799+ return task;
88800 }
88801
88802 struct task_struct *find_task_by_vpid(pid_t vnr)
88803@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88804 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88805 }
88806
88807+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88808+{
88809+ rcu_lockdep_assert(rcu_read_lock_held(),
88810+ "find_task_by_pid_ns() needs rcu_read_lock()"
88811+ " protection");
88812+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88813+}
88814+
88815 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88816 {
88817 struct pid *pid;
88818diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88819index db95d8e..a0ca23f 100644
88820--- a/kernel/pid_namespace.c
88821+++ b/kernel/pid_namespace.c
88822@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88823 void __user *buffer, size_t *lenp, loff_t *ppos)
88824 {
88825 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88826- struct ctl_table tmp = *table;
88827+ ctl_table_no_const tmp = *table;
88828
88829 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88830 return -EPERM;
88831diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88832index 3b89464..5e38379 100644
88833--- a/kernel/posix-cpu-timers.c
88834+++ b/kernel/posix-cpu-timers.c
88835@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88836
88837 static __init int init_posix_cpu_timers(void)
88838 {
88839- struct k_clock process = {
88840+ static struct k_clock process = {
88841 .clock_getres = process_cpu_clock_getres,
88842 .clock_get = process_cpu_clock_get,
88843 .timer_create = process_cpu_timer_create,
88844 .nsleep = process_cpu_nsleep,
88845 .nsleep_restart = process_cpu_nsleep_restart,
88846 };
88847- struct k_clock thread = {
88848+ static struct k_clock thread = {
88849 .clock_getres = thread_cpu_clock_getres,
88850 .clock_get = thread_cpu_clock_get,
88851 .timer_create = thread_cpu_timer_create,
88852diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88853index 424c2d4..679242f 100644
88854--- a/kernel/posix-timers.c
88855+++ b/kernel/posix-timers.c
88856@@ -43,6 +43,7 @@
88857 #include <linux/hash.h>
88858 #include <linux/posix-clock.h>
88859 #include <linux/posix-timers.h>
88860+#include <linux/grsecurity.h>
88861 #include <linux/syscalls.h>
88862 #include <linux/wait.h>
88863 #include <linux/workqueue.h>
88864@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88865 * which we beg off on and pass to do_sys_settimeofday().
88866 */
88867
88868-static struct k_clock posix_clocks[MAX_CLOCKS];
88869+static struct k_clock *posix_clocks[MAX_CLOCKS];
88870
88871 /*
88872 * These ones are defined below.
88873@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88874 */
88875 static __init int init_posix_timers(void)
88876 {
88877- struct k_clock clock_realtime = {
88878+ static struct k_clock clock_realtime = {
88879 .clock_getres = hrtimer_get_res,
88880 .clock_get = posix_clock_realtime_get,
88881 .clock_set = posix_clock_realtime_set,
88882@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88883 .timer_get = common_timer_get,
88884 .timer_del = common_timer_del,
88885 };
88886- struct k_clock clock_monotonic = {
88887+ static struct k_clock clock_monotonic = {
88888 .clock_getres = hrtimer_get_res,
88889 .clock_get = posix_ktime_get_ts,
88890 .nsleep = common_nsleep,
88891@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88892 .timer_get = common_timer_get,
88893 .timer_del = common_timer_del,
88894 };
88895- struct k_clock clock_monotonic_raw = {
88896+ static struct k_clock clock_monotonic_raw = {
88897 .clock_getres = hrtimer_get_res,
88898 .clock_get = posix_get_monotonic_raw,
88899 };
88900- struct k_clock clock_realtime_coarse = {
88901+ static struct k_clock clock_realtime_coarse = {
88902 .clock_getres = posix_get_coarse_res,
88903 .clock_get = posix_get_realtime_coarse,
88904 };
88905- struct k_clock clock_monotonic_coarse = {
88906+ static struct k_clock clock_monotonic_coarse = {
88907 .clock_getres = posix_get_coarse_res,
88908 .clock_get = posix_get_monotonic_coarse,
88909 };
88910- struct k_clock clock_tai = {
88911+ static struct k_clock clock_tai = {
88912 .clock_getres = hrtimer_get_res,
88913 .clock_get = posix_get_tai,
88914 .nsleep = common_nsleep,
88915@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88916 .timer_get = common_timer_get,
88917 .timer_del = common_timer_del,
88918 };
88919- struct k_clock clock_boottime = {
88920+ static struct k_clock clock_boottime = {
88921 .clock_getres = hrtimer_get_res,
88922 .clock_get = posix_get_boottime,
88923 .nsleep = common_nsleep,
88924@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88925 return;
88926 }
88927
88928- posix_clocks[clock_id] = *new_clock;
88929+ posix_clocks[clock_id] = new_clock;
88930 }
88931 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88932
88933@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88934 return (id & CLOCKFD_MASK) == CLOCKFD ?
88935 &clock_posix_dynamic : &clock_posix_cpu;
88936
88937- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88938+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88939 return NULL;
88940- return &posix_clocks[id];
88941+ return posix_clocks[id];
88942 }
88943
88944 static int common_timer_create(struct k_itimer *new_timer)
88945@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88946 struct k_clock *kc = clockid_to_kclock(which_clock);
88947 struct k_itimer *new_timer;
88948 int error, new_timer_id;
88949- sigevent_t event;
88950+ sigevent_t event = { };
88951 int it_id_set = IT_ID_NOT_SET;
88952
88953 if (!kc)
88954@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88955 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88956 return -EFAULT;
88957
88958+ /* only the CLOCK_REALTIME clock can be set, all other clocks
88959+ have their clock_set fptr set to a nosettime dummy function
88960+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88961+ call common_clock_set, which calls do_sys_settimeofday, which
88962+ we hook
88963+ */
88964+
88965 return kc->clock_set(which_clock, &new_tp);
88966 }
88967
88968diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88969index 2fac9cc..56fef29 100644
88970--- a/kernel/power/Kconfig
88971+++ b/kernel/power/Kconfig
88972@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88973 config HIBERNATION
88974 bool "Hibernation (aka 'suspend to disk')"
88975 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88976+ depends on !GRKERNSEC_KMEM
88977+ depends on !PAX_MEMORY_SANITIZE
88978 select HIBERNATE_CALLBACKS
88979 select LZO_COMPRESS
88980 select LZO_DECOMPRESS
88981diff --git a/kernel/power/process.c b/kernel/power/process.c
88982index 06ec886..9dba35e 100644
88983--- a/kernel/power/process.c
88984+++ b/kernel/power/process.c
88985@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88986 unsigned int elapsed_msecs;
88987 bool wakeup = false;
88988 int sleep_usecs = USEC_PER_MSEC;
88989+ bool timedout = false;
88990
88991 do_gettimeofday(&start);
88992
88993@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88994
88995 while (true) {
88996 todo = 0;
88997+ if (time_after(jiffies, end_time))
88998+ timedout = true;
88999 read_lock(&tasklist_lock);
89000 do_each_thread(g, p) {
89001 if (p == current || !freeze_task(p))
89002 continue;
89003
89004- if (!freezer_should_skip(p))
89005+ if (!freezer_should_skip(p)) {
89006 todo++;
89007+ if (timedout) {
89008+ printk(KERN_ERR "Task refusing to freeze:\n");
89009+ sched_show_task(p);
89010+ }
89011+ }
89012 } while_each_thread(g, p);
89013 read_unlock(&tasklist_lock);
89014
89015@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
89016 todo += wq_busy;
89017 }
89018
89019- if (!todo || time_after(jiffies, end_time))
89020+ if (!todo || timedout)
89021 break;
89022
89023 if (pm_wakeup_pending()) {
89024diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
89025index 4dae9cb..039ffbb 100644
89026--- a/kernel/printk/printk.c
89027+++ b/kernel/printk/printk.c
89028@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
89029 if (from_file && type != SYSLOG_ACTION_OPEN)
89030 return 0;
89031
89032+#ifdef CONFIG_GRKERNSEC_DMESG
89033+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
89034+ return -EPERM;
89035+#endif
89036+
89037 if (syslog_action_restricted(type)) {
89038 if (capable(CAP_SYSLOG))
89039 return 0;
89040diff --git a/kernel/profile.c b/kernel/profile.c
89041index ebdd9c1..612ee05 100644
89042--- a/kernel/profile.c
89043+++ b/kernel/profile.c
89044@@ -37,7 +37,7 @@ struct profile_hit {
89045 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
89046 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
89047
89048-static atomic_t *prof_buffer;
89049+static atomic_unchecked_t *prof_buffer;
89050 static unsigned long prof_len, prof_shift;
89051
89052 int prof_on __read_mostly;
89053@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
89054 hits[i].pc = 0;
89055 continue;
89056 }
89057- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
89058+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
89059 hits[i].hits = hits[i].pc = 0;
89060 }
89061 }
89062@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
89063 * Add the current hit(s) and flush the write-queue out
89064 * to the global buffer:
89065 */
89066- atomic_add(nr_hits, &prof_buffer[pc]);
89067+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
89068 for (i = 0; i < NR_PROFILE_HIT; ++i) {
89069- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
89070+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
89071 hits[i].pc = hits[i].hits = 0;
89072 }
89073 out:
89074@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
89075 {
89076 unsigned long pc;
89077 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
89078- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
89079+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
89080 }
89081 #endif /* !CONFIG_SMP */
89082
89083@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
89084 return -EFAULT;
89085 buf++; p++; count--; read++;
89086 }
89087- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
89088+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
89089 if (copy_to_user(buf, (void *)pnt, count))
89090 return -EFAULT;
89091 read += count;
89092@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
89093 }
89094 #endif
89095 profile_discard_flip_buffers();
89096- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
89097+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
89098 return count;
89099 }
89100
89101diff --git a/kernel/ptrace.c b/kernel/ptrace.c
89102index 1f4bcb3..99cf7ab 100644
89103--- a/kernel/ptrace.c
89104+++ b/kernel/ptrace.c
89105@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
89106 if (seize)
89107 flags |= PT_SEIZED;
89108 rcu_read_lock();
89109- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
89110+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
89111 flags |= PT_PTRACE_CAP;
89112 rcu_read_unlock();
89113 task->ptrace = flags;
89114@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
89115 break;
89116 return -EIO;
89117 }
89118- if (copy_to_user(dst, buf, retval))
89119+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
89120 return -EFAULT;
89121 copied += retval;
89122 src += retval;
89123@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
89124 bool seized = child->ptrace & PT_SEIZED;
89125 int ret = -EIO;
89126 siginfo_t siginfo, *si;
89127- void __user *datavp = (void __user *) data;
89128+ void __user *datavp = (__force void __user *) data;
89129 unsigned long __user *datalp = datavp;
89130 unsigned long flags;
89131
89132@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
89133 goto out;
89134 }
89135
89136+ if (gr_handle_ptrace(child, request)) {
89137+ ret = -EPERM;
89138+ goto out_put_task_struct;
89139+ }
89140+
89141 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89142 ret = ptrace_attach(child, request, addr, data);
89143 /*
89144 * Some architectures need to do book-keeping after
89145 * a ptrace attach.
89146 */
89147- if (!ret)
89148+ if (!ret) {
89149 arch_ptrace_attach(child);
89150+ gr_audit_ptrace(child);
89151+ }
89152 goto out_put_task_struct;
89153 }
89154
89155@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
89156 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
89157 if (copied != sizeof(tmp))
89158 return -EIO;
89159- return put_user(tmp, (unsigned long __user *)data);
89160+ return put_user(tmp, (__force unsigned long __user *)data);
89161 }
89162
89163 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
89164@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
89165 }
89166
89167 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
89168- compat_long_t addr, compat_long_t data)
89169+ compat_ulong_t addr, compat_ulong_t data)
89170 {
89171 struct task_struct *child;
89172 long ret;
89173@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
89174 goto out;
89175 }
89176
89177+ if (gr_handle_ptrace(child, request)) {
89178+ ret = -EPERM;
89179+ goto out_put_task_struct;
89180+ }
89181+
89182 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89183 ret = ptrace_attach(child, request, addr, data);
89184 /*
89185 * Some architectures need to do book-keeping after
89186 * a ptrace attach.
89187 */
89188- if (!ret)
89189+ if (!ret) {
89190 arch_ptrace_attach(child);
89191+ gr_audit_ptrace(child);
89192+ }
89193 goto out_put_task_struct;
89194 }
89195
89196diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
89197index 3318d82..1a5b2d1 100644
89198--- a/kernel/rcu/srcu.c
89199+++ b/kernel/rcu/srcu.c
89200@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
89201
89202 idx = ACCESS_ONCE(sp->completed) & 0x1;
89203 preempt_disable();
89204- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89205+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89206 smp_mb(); /* B */ /* Avoid leaking the critical section. */
89207- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89208+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89209 preempt_enable();
89210 return idx;
89211 }
89212diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
89213index 1254f31..16258dc 100644
89214--- a/kernel/rcu/tiny.c
89215+++ b/kernel/rcu/tiny.c
89216@@ -46,7 +46,7 @@
89217 /* Forward declarations for tiny_plugin.h. */
89218 struct rcu_ctrlblk;
89219 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
89220-static void rcu_process_callbacks(struct softirq_action *unused);
89221+static void rcu_process_callbacks(void);
89222 static void __call_rcu(struct rcu_head *head,
89223 void (*func)(struct rcu_head *rcu),
89224 struct rcu_ctrlblk *rcp);
89225@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89226 false));
89227 }
89228
89229-static void rcu_process_callbacks(struct softirq_action *unused)
89230+static __latent_entropy void rcu_process_callbacks(void)
89231 {
89232 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89233 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89234diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
89235index 732f8ae..42c1919 100644
89236--- a/kernel/rcu/torture.c
89237+++ b/kernel/rcu/torture.c
89238@@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
89239 { 0 };
89240 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
89241 { 0 };
89242-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89243-static atomic_t n_rcu_torture_alloc;
89244-static atomic_t n_rcu_torture_alloc_fail;
89245-static atomic_t n_rcu_torture_free;
89246-static atomic_t n_rcu_torture_mberror;
89247-static atomic_t n_rcu_torture_error;
89248+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89249+static atomic_unchecked_t n_rcu_torture_alloc;
89250+static atomic_unchecked_t n_rcu_torture_alloc_fail;
89251+static atomic_unchecked_t n_rcu_torture_free;
89252+static atomic_unchecked_t n_rcu_torture_mberror;
89253+static atomic_unchecked_t n_rcu_torture_error;
89254 static long n_rcu_torture_barrier_error;
89255 static long n_rcu_torture_boost_ktrerror;
89256 static long n_rcu_torture_boost_rterror;
89257@@ -297,11 +297,11 @@ rcu_torture_alloc(void)
89258
89259 spin_lock_bh(&rcu_torture_lock);
89260 if (list_empty(&rcu_torture_freelist)) {
89261- atomic_inc(&n_rcu_torture_alloc_fail);
89262+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
89263 spin_unlock_bh(&rcu_torture_lock);
89264 return NULL;
89265 }
89266- atomic_inc(&n_rcu_torture_alloc);
89267+ atomic_inc_unchecked(&n_rcu_torture_alloc);
89268 p = rcu_torture_freelist.next;
89269 list_del_init(p);
89270 spin_unlock_bh(&rcu_torture_lock);
89271@@ -314,7 +314,7 @@ rcu_torture_alloc(void)
89272 static void
89273 rcu_torture_free(struct rcu_torture *p)
89274 {
89275- atomic_inc(&n_rcu_torture_free);
89276+ atomic_inc_unchecked(&n_rcu_torture_free);
89277 spin_lock_bh(&rcu_torture_lock);
89278 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
89279 spin_unlock_bh(&rcu_torture_lock);
89280@@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
89281 i = rp->rtort_pipe_count;
89282 if (i > RCU_TORTURE_PIPE_LEN)
89283 i = RCU_TORTURE_PIPE_LEN;
89284- atomic_inc(&rcu_torture_wcount[i]);
89285+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89286 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
89287 rp->rtort_mbtest = 0;
89288 rcu_torture_free(rp);
89289@@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
89290 i = old_rp->rtort_pipe_count;
89291 if (i > RCU_TORTURE_PIPE_LEN)
89292 i = RCU_TORTURE_PIPE_LEN;
89293- atomic_inc(&rcu_torture_wcount[i]);
89294+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89295 old_rp->rtort_pipe_count++;
89296 if (gp_normal == gp_exp)
89297 exp = !!(rcu_random(&rand) & 0x80);
89298@@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
89299 i = rp->rtort_pipe_count;
89300 if (i > RCU_TORTURE_PIPE_LEN)
89301 i = RCU_TORTURE_PIPE_LEN;
89302- atomic_inc(&rcu_torture_wcount[i]);
89303+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89304 if (++rp->rtort_pipe_count >=
89305 RCU_TORTURE_PIPE_LEN) {
89306 rp->rtort_mbtest = 0;
89307@@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
89308 return;
89309 }
89310 if (p->rtort_mbtest == 0)
89311- atomic_inc(&n_rcu_torture_mberror);
89312+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89313 spin_lock(&rand_lock);
89314 cur_ops->read_delay(&rand);
89315 n_rcu_torture_timers++;
89316@@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
89317 continue;
89318 }
89319 if (p->rtort_mbtest == 0)
89320- atomic_inc(&n_rcu_torture_mberror);
89321+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89322 cur_ops->read_delay(&rand);
89323 preempt_disable();
89324 pipe_count = p->rtort_pipe_count;
89325@@ -1068,15 +1068,15 @@ rcu_torture_printk(char *page)
89326 }
89327 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89328 page += sprintf(page,
89329- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89330+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89331 rcu_torture_current,
89332 rcu_torture_current_version,
89333 list_empty(&rcu_torture_freelist),
89334- atomic_read(&n_rcu_torture_alloc),
89335- atomic_read(&n_rcu_torture_alloc_fail),
89336- atomic_read(&n_rcu_torture_free));
89337+ atomic_read_unchecked(&n_rcu_torture_alloc),
89338+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89339+ atomic_read_unchecked(&n_rcu_torture_free));
89340 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89341- atomic_read(&n_rcu_torture_mberror),
89342+ atomic_read_unchecked(&n_rcu_torture_mberror),
89343 n_rcu_torture_boost_ktrerror,
89344 n_rcu_torture_boost_rterror);
89345 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89346@@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
89347 n_barrier_attempts,
89348 n_rcu_torture_barrier_error);
89349 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89350- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89351+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89352 n_rcu_torture_barrier_error != 0 ||
89353 n_rcu_torture_boost_ktrerror != 0 ||
89354 n_rcu_torture_boost_rterror != 0 ||
89355 n_rcu_torture_boost_failure != 0 ||
89356 i > 1) {
89357 page += sprintf(page, "!!! ");
89358- atomic_inc(&n_rcu_torture_error);
89359+ atomic_inc_unchecked(&n_rcu_torture_error);
89360 WARN_ON_ONCE(1);
89361 }
89362 page += sprintf(page, "Reader Pipe: ");
89363@@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
89364 page += sprintf(page, "Free-Block Circulation: ");
89365 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89366 page += sprintf(page, " %d",
89367- atomic_read(&rcu_torture_wcount[i]));
89368+ atomic_read_unchecked(&rcu_torture_wcount[i]));
89369 }
89370 page += sprintf(page, "\n");
89371 if (cur_ops->stats)
89372@@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
89373
89374 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89375
89376- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89377+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89378 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89379 else if (n_online_successes != n_online_attempts ||
89380 n_offline_successes != n_offline_attempts)
89381@@ -1961,18 +1961,18 @@ rcu_torture_init(void)
89382
89383 rcu_torture_current = NULL;
89384 rcu_torture_current_version = 0;
89385- atomic_set(&n_rcu_torture_alloc, 0);
89386- atomic_set(&n_rcu_torture_alloc_fail, 0);
89387- atomic_set(&n_rcu_torture_free, 0);
89388- atomic_set(&n_rcu_torture_mberror, 0);
89389- atomic_set(&n_rcu_torture_error, 0);
89390+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89391+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89392+ atomic_set_unchecked(&n_rcu_torture_free, 0);
89393+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89394+ atomic_set_unchecked(&n_rcu_torture_error, 0);
89395 n_rcu_torture_barrier_error = 0;
89396 n_rcu_torture_boost_ktrerror = 0;
89397 n_rcu_torture_boost_rterror = 0;
89398 n_rcu_torture_boost_failure = 0;
89399 n_rcu_torture_boosts = 0;
89400 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89401- atomic_set(&rcu_torture_wcount[i], 0);
89402+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89403 for_each_possible_cpu(cpu) {
89404 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89405 per_cpu(rcu_torture_count, cpu)[i] = 0;
89406diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89407index b3d116c..ebf6598 100644
89408--- a/kernel/rcu/tree.c
89409+++ b/kernel/rcu/tree.c
89410@@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89411 rcu_prepare_for_idle(smp_processor_id());
89412 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89413 smp_mb__before_atomic_inc(); /* See above. */
89414- atomic_inc(&rdtp->dynticks);
89415+ atomic_inc_unchecked(&rdtp->dynticks);
89416 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89417- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89418+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89419
89420 /*
89421 * It is illegal to enter an extended quiescent state while
89422@@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89423 int user)
89424 {
89425 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89426- atomic_inc(&rdtp->dynticks);
89427+ atomic_inc_unchecked(&rdtp->dynticks);
89428 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89429 smp_mb__after_atomic_inc(); /* See above. */
89430- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89431+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89432 rcu_cleanup_after_idle(smp_processor_id());
89433 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89434 if (!user && !is_idle_task(current)) {
89435@@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
89436 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89437
89438 if (rdtp->dynticks_nmi_nesting == 0 &&
89439- (atomic_read(&rdtp->dynticks) & 0x1))
89440+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89441 return;
89442 rdtp->dynticks_nmi_nesting++;
89443 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89444- atomic_inc(&rdtp->dynticks);
89445+ atomic_inc_unchecked(&rdtp->dynticks);
89446 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89447 smp_mb__after_atomic_inc(); /* See above. */
89448- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89449+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89450 }
89451
89452 /**
89453@@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
89454 return;
89455 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89456 smp_mb__before_atomic_inc(); /* See above. */
89457- atomic_inc(&rdtp->dynticks);
89458+ atomic_inc_unchecked(&rdtp->dynticks);
89459 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89460- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89461+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89462 }
89463
89464 /**
89465@@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
89466 */
89467 bool notrace __rcu_is_watching(void)
89468 {
89469- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89470+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89471 }
89472
89473 /**
89474@@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89475 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89476 bool *isidle, unsigned long *maxj)
89477 {
89478- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89479+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89480 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89481 return (rdp->dynticks_snap & 0x1) == 0;
89482 }
89483@@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89484 unsigned int curr;
89485 unsigned int snap;
89486
89487- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89488+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89489 snap = (unsigned int)rdp->dynticks_snap;
89490
89491 /*
89492@@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89493 rdp = this_cpu_ptr(rsp->rda);
89494 rcu_preempt_check_blocked_tasks(rnp);
89495 rnp->qsmask = rnp->qsmaskinit;
89496- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89497+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89498 WARN_ON_ONCE(rnp->completed != rsp->completed);
89499- ACCESS_ONCE(rnp->completed) = rsp->completed;
89500+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89501 if (rnp == rdp->mynode)
89502 __note_gp_changes(rsp, rnp, rdp);
89503 rcu_preempt_boost_start_gp(rnp);
89504@@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89505 rcu_for_each_node_breadth_first(rsp, rnp) {
89506 raw_spin_lock_irq(&rnp->lock);
89507 smp_mb__after_unlock_lock();
89508- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89509+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89510 rdp = this_cpu_ptr(rsp->rda);
89511 if (rnp == rdp->mynode)
89512 __note_gp_changes(rsp, rnp, rdp);
89513@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89514 rsp->qlen += rdp->qlen;
89515 rdp->n_cbs_orphaned += rdp->qlen;
89516 rdp->qlen_lazy = 0;
89517- ACCESS_ONCE(rdp->qlen) = 0;
89518+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89519 }
89520
89521 /*
89522@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89523 }
89524 smp_mb(); /* List handling before counting for rcu_barrier(). */
89525 rdp->qlen_lazy -= count_lazy;
89526- ACCESS_ONCE(rdp->qlen) -= count;
89527+ ACCESS_ONCE_RW(rdp->qlen) -= count;
89528 rdp->n_cbs_invoked += count;
89529
89530 /* Reinstate batch limit if we have worked down the excess. */
89531@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89532 /*
89533 * Do RCU core processing for the current CPU.
89534 */
89535-static void rcu_process_callbacks(struct softirq_action *unused)
89536+static void rcu_process_callbacks(void)
89537 {
89538 struct rcu_state *rsp;
89539
89540@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89541 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89542 if (debug_rcu_head_queue(head)) {
89543 /* Probable double call_rcu(), so leak the callback. */
89544- ACCESS_ONCE(head->func) = rcu_leak_callback;
89545+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89546 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89547 return;
89548 }
89549@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89550 local_irq_restore(flags);
89551 return;
89552 }
89553- ACCESS_ONCE(rdp->qlen)++;
89554+ ACCESS_ONCE_RW(rdp->qlen)++;
89555 if (lazy)
89556 rdp->qlen_lazy++;
89557 else
89558@@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
89559 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89560 * course be required on a 64-bit system.
89561 */
89562- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89563+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89564 (ulong)atomic_long_read(&rsp->expedited_done) +
89565 ULONG_MAX / 8)) {
89566 synchronize_sched();
89567- atomic_long_inc(&rsp->expedited_wrap);
89568+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
89569 return;
89570 }
89571
89572@@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
89573 * Take a ticket. Note that atomic_inc_return() implies a
89574 * full memory barrier.
89575 */
89576- snap = atomic_long_inc_return(&rsp->expedited_start);
89577+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89578 firstsnap = snap;
89579 get_online_cpus();
89580 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89581@@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
89582 synchronize_sched_expedited_cpu_stop,
89583 NULL) == -EAGAIN) {
89584 put_online_cpus();
89585- atomic_long_inc(&rsp->expedited_tryfail);
89586+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89587
89588 /* Check to see if someone else did our work for us. */
89589 s = atomic_long_read(&rsp->expedited_done);
89590 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89591 /* ensure test happens before caller kfree */
89592 smp_mb__before_atomic_inc(); /* ^^^ */
89593- atomic_long_inc(&rsp->expedited_workdone1);
89594+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89595 return;
89596 }
89597
89598@@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
89599 udelay(trycount * num_online_cpus());
89600 } else {
89601 wait_rcu_gp(call_rcu_sched);
89602- atomic_long_inc(&rsp->expedited_normal);
89603+ atomic_long_inc_unchecked(&rsp->expedited_normal);
89604 return;
89605 }
89606
89607@@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
89608 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89609 /* ensure test happens before caller kfree */
89610 smp_mb__before_atomic_inc(); /* ^^^ */
89611- atomic_long_inc(&rsp->expedited_workdone2);
89612+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89613 return;
89614 }
89615
89616@@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
89617 * period works for us.
89618 */
89619 get_online_cpus();
89620- snap = atomic_long_read(&rsp->expedited_start);
89621+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
89622 smp_mb(); /* ensure read is before try_stop_cpus(). */
89623 }
89624- atomic_long_inc(&rsp->expedited_stoppedcpus);
89625+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89626
89627 /*
89628 * Everyone up to our most recent fetch is covered by our grace
89629@@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
89630 * than we did already did their update.
89631 */
89632 do {
89633- atomic_long_inc(&rsp->expedited_done_tries);
89634+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89635 s = atomic_long_read(&rsp->expedited_done);
89636 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89637 /* ensure test happens before caller kfree */
89638 smp_mb__before_atomic_inc(); /* ^^^ */
89639- atomic_long_inc(&rsp->expedited_done_lost);
89640+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89641 break;
89642 }
89643 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89644- atomic_long_inc(&rsp->expedited_done_exit);
89645+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89646
89647 put_online_cpus();
89648 }
89649@@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89650 * ACCESS_ONCE() to prevent the compiler from speculating
89651 * the increment to precede the early-exit check.
89652 */
89653- ACCESS_ONCE(rsp->n_barrier_done)++;
89654+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89655 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89656 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89657 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89658@@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89659
89660 /* Increment ->n_barrier_done to prevent duplicate work. */
89661 smp_mb(); /* Keep increment after above mechanism. */
89662- ACCESS_ONCE(rsp->n_barrier_done)++;
89663+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89664 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89665 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89666 smp_mb(); /* Keep increment before caller's subsequent code. */
89667@@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89668 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89669 init_callback_list(rdp);
89670 rdp->qlen_lazy = 0;
89671- ACCESS_ONCE(rdp->qlen) = 0;
89672+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89673 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89674 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89675- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89676+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89677 rdp->cpu = cpu;
89678 rdp->rsp = rsp;
89679 rcu_boot_init_nocb_percpu_data(rdp);
89680@@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89681 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89682 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89683 rcu_sysidle_init_percpu_data(rdp->dynticks);
89684- atomic_set(&rdp->dynticks->dynticks,
89685- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89686+ atomic_set_unchecked(&rdp->dynticks->dynticks,
89687+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89688 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89689
89690 /* Add CPU to rcu_node bitmasks. */
89691diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89692index 8c19873..bf83c57 100644
89693--- a/kernel/rcu/tree.h
89694+++ b/kernel/rcu/tree.h
89695@@ -87,11 +87,11 @@ struct rcu_dynticks {
89696 long long dynticks_nesting; /* Track irq/process nesting level. */
89697 /* Process level is worth LLONG_MAX/2. */
89698 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89699- atomic_t dynticks; /* Even value for idle, else odd. */
89700+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89701 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89702 long long dynticks_idle_nesting;
89703 /* irq/process nesting level from idle. */
89704- atomic_t dynticks_idle; /* Even value for idle, else odd. */
89705+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89706 /* "Idle" excludes userspace execution. */
89707 unsigned long dynticks_idle_jiffies;
89708 /* End of last non-NMI non-idle period. */
89709@@ -431,17 +431,17 @@ struct rcu_state {
89710 /* _rcu_barrier(). */
89711 /* End of fields guarded by barrier_mutex. */
89712
89713- atomic_long_t expedited_start; /* Starting ticket. */
89714- atomic_long_t expedited_done; /* Done ticket. */
89715- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89716- atomic_long_t expedited_tryfail; /* # acquisition failures. */
89717- atomic_long_t expedited_workdone1; /* # done by others #1. */
89718- atomic_long_t expedited_workdone2; /* # done by others #2. */
89719- atomic_long_t expedited_normal; /* # fallbacks to normal. */
89720- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89721- atomic_long_t expedited_done_tries; /* # tries to update _done. */
89722- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89723- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89724+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89725+ atomic_long_t expedited_done; /* Done ticket. */
89726+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89727+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89728+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89729+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89730+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89731+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89732+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89733+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89734+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89735
89736 unsigned long jiffies_force_qs; /* Time at which to invoke */
89737 /* force_quiescent_state(). */
89738diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89739index 6e2ef4b..c15df94 100644
89740--- a/kernel/rcu/tree_plugin.h
89741+++ b/kernel/rcu/tree_plugin.h
89742@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89743 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89744 {
89745 return !rcu_preempted_readers_exp(rnp) &&
89746- ACCESS_ONCE(rnp->expmask) == 0;
89747+ ACCESS_ONCE_RW(rnp->expmask) == 0;
89748 }
89749
89750 /*
89751@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89752
89753 /* Clean up and exit. */
89754 smp_mb(); /* ensure expedited GP seen before counter increment. */
89755- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89756+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89757 unlock_mb_ret:
89758 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89759 mb_ret:
89760@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89761 free_cpumask_var(cm);
89762 }
89763
89764-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89765+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89766 .store = &rcu_cpu_kthread_task,
89767 .thread_should_run = rcu_cpu_kthread_should_run,
89768 .thread_fn = rcu_cpu_kthread,
89769@@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89770 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89771 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89772 cpu, ticks_value, ticks_title,
89773- atomic_read(&rdtp->dynticks) & 0xfff,
89774+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89775 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89776 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89777 fast_no_hz);
89778@@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89779
89780 /* Enqueue the callback on the nocb list and update counts. */
89781 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89782- ACCESS_ONCE(*old_rhpp) = rhp;
89783+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
89784 atomic_long_add(rhcount, &rdp->nocb_q_count);
89785 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89786
89787@@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
89788 * Extract queued callbacks, update counts, and wait
89789 * for a grace period to elapse.
89790 */
89791- ACCESS_ONCE(rdp->nocb_head) = NULL;
89792+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89793 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89794 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89795 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89796- ACCESS_ONCE(rdp->nocb_p_count) += c;
89797- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89798+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89799+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89800 rcu_nocb_wait_gp(rdp);
89801
89802 /* Each pass through the following loop invokes a callback. */
89803@@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
89804 list = next;
89805 }
89806 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89807- ACCESS_ONCE(rdp->nocb_p_count) -= c;
89808- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89809+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89810+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89811 rdp->n_nocbs_invoked += c;
89812 }
89813 return 0;
89814@@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89815 {
89816 if (!rcu_nocb_need_deferred_wakeup(rdp))
89817 return;
89818- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89819+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89820 wake_up(&rdp->nocb_wq);
89821 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89822 }
89823@@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89824 t = kthread_run(rcu_nocb_kthread, rdp,
89825 "rcuo%c/%d", rsp->abbr, cpu);
89826 BUG_ON(IS_ERR(t));
89827- ACCESS_ONCE(rdp->nocb_kthread) = t;
89828+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89829 }
89830 }
89831
89832@@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89833
89834 /* Record start of fully idle period. */
89835 j = jiffies;
89836- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89837+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89838 smp_mb__before_atomic_inc();
89839- atomic_inc(&rdtp->dynticks_idle);
89840+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89841 smp_mb__after_atomic_inc();
89842- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89843+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89844 }
89845
89846 /*
89847@@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89848
89849 /* Record end of idle period. */
89850 smp_mb__before_atomic_inc();
89851- atomic_inc(&rdtp->dynticks_idle);
89852+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89853 smp_mb__after_atomic_inc();
89854- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89855+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89856
89857 /*
89858 * If we are the timekeeping CPU, we are permitted to be non-idle
89859@@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89860 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89861
89862 /* Pick up current idle and NMI-nesting counter and check. */
89863- cur = atomic_read(&rdtp->dynticks_idle);
89864+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89865 if (cur & 0x1) {
89866 *isidle = false; /* We are not idle! */
89867 return;
89868@@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
89869 case RCU_SYSIDLE_NOT:
89870
89871 /* First time all are idle, so note a short idle period. */
89872- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89873+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89874 break;
89875
89876 case RCU_SYSIDLE_SHORT:
89877@@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
89878 static void rcu_sysidle_cancel(void)
89879 {
89880 smp_mb();
89881- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89882+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89883 }
89884
89885 /*
89886@@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89887 smp_mb(); /* grace period precedes setting inuse. */
89888
89889 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89890- ACCESS_ONCE(rshp->inuse) = 0;
89891+ ACCESS_ONCE_RW(rshp->inuse) = 0;
89892 }
89893
89894 /*
89895diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89896index 4def475..8ffddde 100644
89897--- a/kernel/rcu/tree_trace.c
89898+++ b/kernel/rcu/tree_trace.c
89899@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89900 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89901 rdp->passed_quiesce, rdp->qs_pending);
89902 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89903- atomic_read(&rdp->dynticks->dynticks),
89904+ atomic_read_unchecked(&rdp->dynticks->dynticks),
89905 rdp->dynticks->dynticks_nesting,
89906 rdp->dynticks->dynticks_nmi_nesting,
89907 rdp->dynticks_fqs);
89908@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89909 struct rcu_state *rsp = (struct rcu_state *)m->private;
89910
89911 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",
89912- atomic_long_read(&rsp->expedited_start),
89913+ atomic_long_read_unchecked(&rsp->expedited_start),
89914 atomic_long_read(&rsp->expedited_done),
89915- atomic_long_read(&rsp->expedited_wrap),
89916- atomic_long_read(&rsp->expedited_tryfail),
89917- atomic_long_read(&rsp->expedited_workdone1),
89918- atomic_long_read(&rsp->expedited_workdone2),
89919- atomic_long_read(&rsp->expedited_normal),
89920- atomic_long_read(&rsp->expedited_stoppedcpus),
89921- atomic_long_read(&rsp->expedited_done_tries),
89922- atomic_long_read(&rsp->expedited_done_lost),
89923- atomic_long_read(&rsp->expedited_done_exit));
89924+ atomic_long_read_unchecked(&rsp->expedited_wrap),
89925+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
89926+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
89927+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
89928+ atomic_long_read_unchecked(&rsp->expedited_normal),
89929+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89930+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
89931+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
89932+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
89933 return 0;
89934 }
89935
89936diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89937index c54609f..2e8829c 100644
89938--- a/kernel/rcu/update.c
89939+++ b/kernel/rcu/update.c
89940@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
89941 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89942 */
89943 if (till_stall_check < 3) {
89944- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89945+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89946 till_stall_check = 3;
89947 } else if (till_stall_check > 300) {
89948- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89949+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89950 till_stall_check = 300;
89951 }
89952 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89953diff --git a/kernel/resource.c b/kernel/resource.c
89954index 3f285dc..5755f62 100644
89955--- a/kernel/resource.c
89956+++ b/kernel/resource.c
89957@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89958
89959 static int __init ioresources_init(void)
89960 {
89961+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89962+#ifdef CONFIG_GRKERNSEC_PROC_USER
89963+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89964+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89965+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89966+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89967+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89968+#endif
89969+#else
89970 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89971 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89972+#endif
89973 return 0;
89974 }
89975 __initcall(ioresources_init);
89976diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89977index 4a07353..66b5291 100644
89978--- a/kernel/sched/auto_group.c
89979+++ b/kernel/sched/auto_group.c
89980@@ -11,7 +11,7 @@
89981
89982 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89983 static struct autogroup autogroup_default;
89984-static atomic_t autogroup_seq_nr;
89985+static atomic_unchecked_t autogroup_seq_nr;
89986
89987 void __init autogroup_init(struct task_struct *init_task)
89988 {
89989@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89990
89991 kref_init(&ag->kref);
89992 init_rwsem(&ag->lock);
89993- ag->id = atomic_inc_return(&autogroup_seq_nr);
89994+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89995 ag->tg = tg;
89996 #ifdef CONFIG_RT_GROUP_SCHED
89997 /*
89998diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89999index a63f4dc..349bbb0 100644
90000--- a/kernel/sched/completion.c
90001+++ b/kernel/sched/completion.c
90002@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
90003 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
90004 * or number of jiffies left till timeout) if completed.
90005 */
90006-long __sched
90007+long __sched __intentional_overflow(-1)
90008 wait_for_completion_interruptible_timeout(struct completion *x,
90009 unsigned long timeout)
90010 {
90011@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
90012 *
90013 * Return: -ERESTARTSYS if interrupted, 0 if completed.
90014 */
90015-int __sched wait_for_completion_killable(struct completion *x)
90016+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
90017 {
90018 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
90019 if (t == -ERESTARTSYS)
90020@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
90021 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
90022 * or number of jiffies left till timeout) if completed.
90023 */
90024-long __sched
90025+long __sched __intentional_overflow(-1)
90026 wait_for_completion_killable_timeout(struct completion *x,
90027 unsigned long timeout)
90028 {
90029diff --git a/kernel/sched/core.c b/kernel/sched/core.c
90030index 0aae0fc..2ba2b81 100644
90031--- a/kernel/sched/core.c
90032+++ b/kernel/sched/core.c
90033@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
90034 int sysctl_numa_balancing(struct ctl_table *table, int write,
90035 void __user *buffer, size_t *lenp, loff_t *ppos)
90036 {
90037- struct ctl_table t;
90038+ ctl_table_no_const t;
90039 int err;
90040 int state = numabalancing_enabled;
90041
90042@@ -2251,8 +2251,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
90043 next->active_mm = oldmm;
90044 atomic_inc(&oldmm->mm_count);
90045 enter_lazy_tlb(oldmm, next);
90046- } else
90047+ } else {
90048 switch_mm(oldmm, mm, next);
90049+ populate_stack();
90050+ }
90051
90052 if (!prev->mm) {
90053 prev->active_mm = NULL;
90054@@ -3049,6 +3051,8 @@ int can_nice(const struct task_struct *p, const int nice)
90055 /* convert nice value [19,-20] to rlimit style value [1,40] */
90056 int nice_rlim = 20 - nice;
90057
90058+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
90059+
90060 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
90061 capable(CAP_SYS_NICE));
90062 }
90063@@ -3082,7 +3086,8 @@ SYSCALL_DEFINE1(nice, int, increment)
90064 if (nice > 19)
90065 nice = 19;
90066
90067- if (increment < 0 && !can_nice(current, nice))
90068+ if (increment < 0 && (!can_nice(current, nice) ||
90069+ gr_handle_chroot_nice()))
90070 return -EPERM;
90071
90072 retval = security_task_setnice(current, nice);
90073@@ -3355,6 +3360,7 @@ recheck:
90074 if (policy != p->policy && !rlim_rtprio)
90075 return -EPERM;
90076
90077+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
90078 /* can't increase priority */
90079 if (attr->sched_priority > p->rt_priority &&
90080 attr->sched_priority > rlim_rtprio)
90081@@ -4726,8 +4732,10 @@ void idle_task_exit(void)
90082
90083 BUG_ON(cpu_online(smp_processor_id()));
90084
90085- if (mm != &init_mm)
90086+ if (mm != &init_mm) {
90087 switch_mm(mm, &init_mm, current);
90088+ populate_stack();
90089+ }
90090 mmdrop(mm);
90091 }
90092
90093@@ -4805,7 +4813,7 @@ static void migrate_tasks(unsigned int dead_cpu)
90094
90095 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
90096
90097-static struct ctl_table sd_ctl_dir[] = {
90098+static ctl_table_no_const sd_ctl_dir[] __read_only = {
90099 {
90100 .procname = "sched_domain",
90101 .mode = 0555,
90102@@ -4822,17 +4830,17 @@ static struct ctl_table sd_ctl_root[] = {
90103 {}
90104 };
90105
90106-static struct ctl_table *sd_alloc_ctl_entry(int n)
90107+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
90108 {
90109- struct ctl_table *entry =
90110+ ctl_table_no_const *entry =
90111 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
90112
90113 return entry;
90114 }
90115
90116-static void sd_free_ctl_entry(struct ctl_table **tablep)
90117+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
90118 {
90119- struct ctl_table *entry;
90120+ ctl_table_no_const *entry;
90121
90122 /*
90123 * In the intermediate directories, both the child directory and
90124@@ -4840,22 +4848,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
90125 * will always be set. In the lowest directory the names are
90126 * static strings and all have proc handlers.
90127 */
90128- for (entry = *tablep; entry->mode; entry++) {
90129- if (entry->child)
90130- sd_free_ctl_entry(&entry->child);
90131+ for (entry = tablep; entry->mode; entry++) {
90132+ if (entry->child) {
90133+ sd_free_ctl_entry(entry->child);
90134+ pax_open_kernel();
90135+ entry->child = NULL;
90136+ pax_close_kernel();
90137+ }
90138 if (entry->proc_handler == NULL)
90139 kfree(entry->procname);
90140 }
90141
90142- kfree(*tablep);
90143- *tablep = NULL;
90144+ kfree(tablep);
90145 }
90146
90147 static int min_load_idx = 0;
90148 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
90149
90150 static void
90151-set_table_entry(struct ctl_table *entry,
90152+set_table_entry(ctl_table_no_const *entry,
90153 const char *procname, void *data, int maxlen,
90154 umode_t mode, proc_handler *proc_handler,
90155 bool load_idx)
90156@@ -4875,7 +4886,7 @@ set_table_entry(struct ctl_table *entry,
90157 static struct ctl_table *
90158 sd_alloc_ctl_domain_table(struct sched_domain *sd)
90159 {
90160- struct ctl_table *table = sd_alloc_ctl_entry(13);
90161+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
90162
90163 if (table == NULL)
90164 return NULL;
90165@@ -4910,9 +4921,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
90166 return table;
90167 }
90168
90169-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
90170+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
90171 {
90172- struct ctl_table *entry, *table;
90173+ ctl_table_no_const *entry, *table;
90174 struct sched_domain *sd;
90175 int domain_num = 0, i;
90176 char buf[32];
90177@@ -4939,11 +4950,13 @@ static struct ctl_table_header *sd_sysctl_header;
90178 static void register_sched_domain_sysctl(void)
90179 {
90180 int i, cpu_num = num_possible_cpus();
90181- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
90182+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
90183 char buf[32];
90184
90185 WARN_ON(sd_ctl_dir[0].child);
90186+ pax_open_kernel();
90187 sd_ctl_dir[0].child = entry;
90188+ pax_close_kernel();
90189
90190 if (entry == NULL)
90191 return;
90192@@ -4966,8 +4979,12 @@ static void unregister_sched_domain_sysctl(void)
90193 if (sd_sysctl_header)
90194 unregister_sysctl_table(sd_sysctl_header);
90195 sd_sysctl_header = NULL;
90196- if (sd_ctl_dir[0].child)
90197- sd_free_ctl_entry(&sd_ctl_dir[0].child);
90198+ if (sd_ctl_dir[0].child) {
90199+ sd_free_ctl_entry(sd_ctl_dir[0].child);
90200+ pax_open_kernel();
90201+ sd_ctl_dir[0].child = NULL;
90202+ pax_close_kernel();
90203+ }
90204 }
90205 #else
90206 static void register_sched_domain_sysctl(void)
90207diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
90208index 9b4c4f3..665489b 100644
90209--- a/kernel/sched/fair.c
90210+++ b/kernel/sched/fair.c
90211@@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
90212
90213 static void reset_ptenuma_scan(struct task_struct *p)
90214 {
90215- ACCESS_ONCE(p->mm->numa_scan_seq)++;
90216+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
90217 p->mm->numa_scan_offset = 0;
90218 }
90219
90220@@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
90221 * run_rebalance_domains is triggered when needed from the scheduler tick.
90222 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
90223 */
90224-static void run_rebalance_domains(struct softirq_action *h)
90225+static __latent_entropy void run_rebalance_domains(void)
90226 {
90227 struct rq *this_rq = this_rq();
90228 enum cpu_idle_type idle = this_rq->idle_balance ?
90229diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
90230index f964add..dcd823d 100644
90231--- a/kernel/sched/sched.h
90232+++ b/kernel/sched/sched.h
90233@@ -1157,7 +1157,7 @@ struct sched_class {
90234 #ifdef CONFIG_FAIR_GROUP_SCHED
90235 void (*task_move_group) (struct task_struct *p, int on_rq);
90236 #endif
90237-};
90238+} __do_const;
90239
90240 #define sched_class_highest (&stop_sched_class)
90241 #define for_each_class(class) \
90242diff --git a/kernel/signal.c b/kernel/signal.c
90243index 52f881d..1e9f941 100644
90244--- a/kernel/signal.c
90245+++ b/kernel/signal.c
90246@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
90247
90248 int print_fatal_signals __read_mostly;
90249
90250-static void __user *sig_handler(struct task_struct *t, int sig)
90251+static __sighandler_t sig_handler(struct task_struct *t, int sig)
90252 {
90253 return t->sighand->action[sig - 1].sa.sa_handler;
90254 }
90255
90256-static int sig_handler_ignored(void __user *handler, int sig)
90257+static int sig_handler_ignored(__sighandler_t handler, int sig)
90258 {
90259 /* Is it explicitly or implicitly ignored? */
90260 return handler == SIG_IGN ||
90261@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
90262
90263 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
90264 {
90265- void __user *handler;
90266+ __sighandler_t handler;
90267
90268 handler = sig_handler(t, sig);
90269
90270@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
90271 atomic_inc(&user->sigpending);
90272 rcu_read_unlock();
90273
90274+ if (!override_rlimit)
90275+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
90276+
90277 if (override_rlimit ||
90278 atomic_read(&user->sigpending) <=
90279 task_rlimit(t, RLIMIT_SIGPENDING)) {
90280@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
90281
90282 int unhandled_signal(struct task_struct *tsk, int sig)
90283 {
90284- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
90285+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
90286 if (is_global_init(tsk))
90287 return 1;
90288 if (handler != SIG_IGN && handler != SIG_DFL)
90289@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
90290 }
90291 }
90292
90293+ /* allow glibc communication via tgkill to other threads in our
90294+ thread group */
90295+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90296+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90297+ && gr_handle_signal(t, sig))
90298+ return -EPERM;
90299+
90300 return security_task_kill(t, info, sig, 0);
90301 }
90302
90303@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90304 return send_signal(sig, info, p, 1);
90305 }
90306
90307-static int
90308+int
90309 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90310 {
90311 return send_signal(sig, info, t, 0);
90312@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90313 unsigned long int flags;
90314 int ret, blocked, ignored;
90315 struct k_sigaction *action;
90316+ int is_unhandled = 0;
90317
90318 spin_lock_irqsave(&t->sighand->siglock, flags);
90319 action = &t->sighand->action[sig-1];
90320@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90321 }
90322 if (action->sa.sa_handler == SIG_DFL)
90323 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90324+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90325+ is_unhandled = 1;
90326 ret = specific_send_sig_info(sig, info, t);
90327 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90328
90329+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
90330+ normal operation */
90331+ if (is_unhandled) {
90332+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90333+ gr_handle_crash(t, sig);
90334+ }
90335+
90336 return ret;
90337 }
90338
90339@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90340 ret = check_kill_permission(sig, info, p);
90341 rcu_read_unlock();
90342
90343- if (!ret && sig)
90344+ if (!ret && sig) {
90345 ret = do_send_sig_info(sig, info, p, true);
90346+ if (!ret)
90347+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90348+ }
90349
90350 return ret;
90351 }
90352@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90353 int error = -ESRCH;
90354
90355 rcu_read_lock();
90356- p = find_task_by_vpid(pid);
90357+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90358+ /* allow glibc communication via tgkill to other threads in our
90359+ thread group */
90360+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90361+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
90362+ p = find_task_by_vpid_unrestricted(pid);
90363+ else
90364+#endif
90365+ p = find_task_by_vpid(pid);
90366 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90367 error = check_kill_permission(sig, info, p);
90368 /*
90369@@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90370 }
90371 seg = get_fs();
90372 set_fs(KERNEL_DS);
90373- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90374- (stack_t __force __user *) &uoss,
90375+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90376+ (stack_t __force_user *) &uoss,
90377 compat_user_stack_pointer());
90378 set_fs(seg);
90379 if (ret >= 0 && uoss_ptr) {
90380diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90381index eb89e18..a4e6792 100644
90382--- a/kernel/smpboot.c
90383+++ b/kernel/smpboot.c
90384@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90385 }
90386 smpboot_unpark_thread(plug_thread, cpu);
90387 }
90388- list_add(&plug_thread->list, &hotplug_threads);
90389+ pax_list_add(&plug_thread->list, &hotplug_threads);
90390 out:
90391 mutex_unlock(&smpboot_threads_lock);
90392 return ret;
90393@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90394 {
90395 get_online_cpus();
90396 mutex_lock(&smpboot_threads_lock);
90397- list_del(&plug_thread->list);
90398+ pax_list_del(&plug_thread->list);
90399 smpboot_destroy_threads(plug_thread);
90400 mutex_unlock(&smpboot_threads_lock);
90401 put_online_cpus();
90402diff --git a/kernel/softirq.c b/kernel/softirq.c
90403index 490fcbb..1e502c6 100644
90404--- a/kernel/softirq.c
90405+++ b/kernel/softirq.c
90406@@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90407 EXPORT_SYMBOL(irq_stat);
90408 #endif
90409
90410-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90411+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90412
90413 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90414
90415@@ -267,7 +267,7 @@ restart:
90416 kstat_incr_softirqs_this_cpu(vec_nr);
90417
90418 trace_softirq_entry(vec_nr);
90419- h->action(h);
90420+ h->action();
90421 trace_softirq_exit(vec_nr);
90422 if (unlikely(prev_count != preempt_count())) {
90423 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90424@@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90425 or_softirq_pending(1UL << nr);
90426 }
90427
90428-void open_softirq(int nr, void (*action)(struct softirq_action *))
90429+void __init open_softirq(int nr, void (*action)(void))
90430 {
90431 softirq_vec[nr].action = action;
90432 }
90433@@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90434 }
90435 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90436
90437-static void tasklet_action(struct softirq_action *a)
90438+static void tasklet_action(void)
90439 {
90440 struct tasklet_struct *list;
90441
90442@@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
90443 }
90444 }
90445
90446-static void tasklet_hi_action(struct softirq_action *a)
90447+static __latent_entropy void tasklet_hi_action(void)
90448 {
90449 struct tasklet_struct *list;
90450
90451@@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
90452 .notifier_call = cpu_callback
90453 };
90454
90455-static struct smp_hotplug_thread softirq_threads = {
90456+static struct smp_hotplug_thread softirq_threads __read_only = {
90457 .store = &ksoftirqd,
90458 .thread_should_run = ksoftirqd_should_run,
90459 .thread_fn = run_ksoftirqd,
90460diff --git a/kernel/sys.c b/kernel/sys.c
90461index c0a58be..784c618 100644
90462--- a/kernel/sys.c
90463+++ b/kernel/sys.c
90464@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90465 error = -EACCES;
90466 goto out;
90467 }
90468+
90469+ if (gr_handle_chroot_setpriority(p, niceval)) {
90470+ error = -EACCES;
90471+ goto out;
90472+ }
90473+
90474 no_nice = security_task_setnice(p, niceval);
90475 if (no_nice) {
90476 error = no_nice;
90477@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90478 goto error;
90479 }
90480
90481+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90482+ goto error;
90483+
90484 if (rgid != (gid_t) -1 ||
90485 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90486 new->sgid = new->egid;
90487@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90488 old = current_cred();
90489
90490 retval = -EPERM;
90491+
90492+ if (gr_check_group_change(kgid, kgid, kgid))
90493+ goto error;
90494+
90495 if (ns_capable(old->user_ns, CAP_SETGID))
90496 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90497 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90498@@ -403,7 +416,7 @@ error:
90499 /*
90500 * change the user struct in a credentials set to match the new UID
90501 */
90502-static int set_user(struct cred *new)
90503+int set_user(struct cred *new)
90504 {
90505 struct user_struct *new_user;
90506
90507@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90508 goto error;
90509 }
90510
90511+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90512+ goto error;
90513+
90514 if (!uid_eq(new->uid, old->uid)) {
90515 retval = set_user(new);
90516 if (retval < 0)
90517@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90518 old = current_cred();
90519
90520 retval = -EPERM;
90521+
90522+ if (gr_check_crash_uid(kuid))
90523+ goto error;
90524+ if (gr_check_user_change(kuid, kuid, kuid))
90525+ goto error;
90526+
90527 if (ns_capable(old->user_ns, CAP_SETUID)) {
90528 new->suid = new->uid = kuid;
90529 if (!uid_eq(kuid, old->uid)) {
90530@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90531 goto error;
90532 }
90533
90534+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
90535+ goto error;
90536+
90537 if (ruid != (uid_t) -1) {
90538 new->uid = kruid;
90539 if (!uid_eq(kruid, old->uid)) {
90540@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90541 goto error;
90542 }
90543
90544+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
90545+ goto error;
90546+
90547 if (rgid != (gid_t) -1)
90548 new->gid = krgid;
90549 if (egid != (gid_t) -1)
90550@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90551 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90552 ns_capable(old->user_ns, CAP_SETUID)) {
90553 if (!uid_eq(kuid, old->fsuid)) {
90554+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90555+ goto error;
90556+
90557 new->fsuid = kuid;
90558 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90559 goto change_okay;
90560 }
90561 }
90562
90563+error:
90564 abort_creds(new);
90565 return old_fsuid;
90566
90567@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90568 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90569 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90570 ns_capable(old->user_ns, CAP_SETGID)) {
90571+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90572+ goto error;
90573+
90574 if (!gid_eq(kgid, old->fsgid)) {
90575 new->fsgid = kgid;
90576 goto change_okay;
90577 }
90578 }
90579
90580+error:
90581 abort_creds(new);
90582 return old_fsgid;
90583
90584@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90585 return -EFAULT;
90586
90587 down_read(&uts_sem);
90588- error = __copy_to_user(&name->sysname, &utsname()->sysname,
90589+ error = __copy_to_user(name->sysname, &utsname()->sysname,
90590 __OLD_UTS_LEN);
90591 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90592- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90593+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
90594 __OLD_UTS_LEN);
90595 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90596- error |= __copy_to_user(&name->release, &utsname()->release,
90597+ error |= __copy_to_user(name->release, &utsname()->release,
90598 __OLD_UTS_LEN);
90599 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90600- error |= __copy_to_user(&name->version, &utsname()->version,
90601+ error |= __copy_to_user(name->version, &utsname()->version,
90602 __OLD_UTS_LEN);
90603 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90604- error |= __copy_to_user(&name->machine, &utsname()->machine,
90605+ error |= __copy_to_user(name->machine, &utsname()->machine,
90606 __OLD_UTS_LEN);
90607 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90608 up_read(&uts_sem);
90609@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90610 */
90611 new_rlim->rlim_cur = 1;
90612 }
90613+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90614+ is changed to a lower value. Since tasks can be created by the same
90615+ user in between this limit change and an execve by this task, force
90616+ a recheck only for this task by setting PF_NPROC_EXCEEDED
90617+ */
90618+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90619+ tsk->flags |= PF_NPROC_EXCEEDED;
90620 }
90621 if (!retval) {
90622 if (old_rlim)
90623diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90624index aae21e8..58d8c9a 100644
90625--- a/kernel/sysctl.c
90626+++ b/kernel/sysctl.c
90627@@ -94,7 +94,6 @@
90628
90629
90630 #if defined(CONFIG_SYSCTL)
90631-
90632 /* External variables not in a header file. */
90633 extern int max_threads;
90634 extern int suid_dumpable;
90635@@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
90636
90637 /* Constants used for minimum and maximum */
90638 #ifdef CONFIG_LOCKUP_DETECTOR
90639-static int sixty = 60;
90640+static int sixty __read_only = 60;
90641 #endif
90642
90643-static int __maybe_unused neg_one = -1;
90644-
90645-static int zero;
90646-static int __maybe_unused one = 1;
90647-static int __maybe_unused two = 2;
90648-static int __maybe_unused three = 3;
90649-static unsigned long one_ul = 1;
90650-static int one_hundred = 100;
90651+static int __maybe_unused neg_one __read_only = -1;
90652+static int zero __read_only = 0;
90653+static int __maybe_unused one __read_only = 1;
90654+static int __maybe_unused two __read_only = 2;
90655+static int __maybe_unused three __read_only = 3;
90656+static unsigned long one_ul __read_only = 1;
90657+static int one_hundred __read_only = 100;
90658 #ifdef CONFIG_PRINTK
90659-static int ten_thousand = 10000;
90660+static int ten_thousand __read_only = 10000;
90661 #endif
90662
90663 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90664@@ -182,10 +180,8 @@ static int proc_taint(struct ctl_table *table, int write,
90665 void __user *buffer, size_t *lenp, loff_t *ppos);
90666 #endif
90667
90668-#ifdef CONFIG_PRINTK
90669 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90670 void __user *buffer, size_t *lenp, loff_t *ppos);
90671-#endif
90672
90673 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90674 void __user *buffer, size_t *lenp, loff_t *ppos);
90675@@ -216,6 +212,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90676
90677 #endif
90678
90679+extern struct ctl_table grsecurity_table[];
90680+
90681 static struct ctl_table kern_table[];
90682 static struct ctl_table vm_table[];
90683 static struct ctl_table fs_table[];
90684@@ -230,6 +228,20 @@ extern struct ctl_table epoll_table[];
90685 int sysctl_legacy_va_layout;
90686 #endif
90687
90688+#ifdef CONFIG_PAX_SOFTMODE
90689+static ctl_table pax_table[] = {
90690+ {
90691+ .procname = "softmode",
90692+ .data = &pax_softmode,
90693+ .maxlen = sizeof(unsigned int),
90694+ .mode = 0600,
90695+ .proc_handler = &proc_dointvec,
90696+ },
90697+
90698+ { }
90699+};
90700+#endif
90701+
90702 /* The default sysctl tables: */
90703
90704 static struct ctl_table sysctl_base_table[] = {
90705@@ -278,6 +290,22 @@ static int max_extfrag_threshold = 1000;
90706 #endif
90707
90708 static struct ctl_table kern_table[] = {
90709+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90710+ {
90711+ .procname = "grsecurity",
90712+ .mode = 0500,
90713+ .child = grsecurity_table,
90714+ },
90715+#endif
90716+
90717+#ifdef CONFIG_PAX_SOFTMODE
90718+ {
90719+ .procname = "pax",
90720+ .mode = 0500,
90721+ .child = pax_table,
90722+ },
90723+#endif
90724+
90725 {
90726 .procname = "sched_child_runs_first",
90727 .data = &sysctl_sched_child_runs_first,
90728@@ -640,7 +668,7 @@ static struct ctl_table kern_table[] = {
90729 .data = &modprobe_path,
90730 .maxlen = KMOD_PATH_LEN,
90731 .mode = 0644,
90732- .proc_handler = proc_dostring,
90733+ .proc_handler = proc_dostring_modpriv,
90734 },
90735 {
90736 .procname = "modules_disabled",
90737@@ -807,16 +835,20 @@ static struct ctl_table kern_table[] = {
90738 .extra1 = &zero,
90739 .extra2 = &one,
90740 },
90741+#endif
90742 {
90743 .procname = "kptr_restrict",
90744 .data = &kptr_restrict,
90745 .maxlen = sizeof(int),
90746 .mode = 0644,
90747 .proc_handler = proc_dointvec_minmax_sysadmin,
90748+#ifdef CONFIG_GRKERNSEC_HIDESYM
90749+ .extra1 = &two,
90750+#else
90751 .extra1 = &zero,
90752+#endif
90753 .extra2 = &two,
90754 },
90755-#endif
90756 {
90757 .procname = "ngroups_max",
90758 .data = &ngroups_max,
90759@@ -1061,10 +1093,17 @@ static struct ctl_table kern_table[] = {
90760 */
90761 {
90762 .procname = "perf_event_paranoid",
90763- .data = &sysctl_perf_event_paranoid,
90764- .maxlen = sizeof(sysctl_perf_event_paranoid),
90765+ .data = &sysctl_perf_event_legitimately_concerned,
90766+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90767 .mode = 0644,
90768- .proc_handler = proc_dointvec,
90769+ /* go ahead, be a hero */
90770+ .proc_handler = proc_dointvec_minmax_sysadmin,
90771+ .extra1 = &neg_one,
90772+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90773+ .extra2 = &three,
90774+#else
90775+ .extra2 = &two,
90776+#endif
90777 },
90778 {
90779 .procname = "perf_event_mlock_kb",
90780@@ -1335,6 +1374,13 @@ static struct ctl_table vm_table[] = {
90781 .proc_handler = proc_dointvec_minmax,
90782 .extra1 = &zero,
90783 },
90784+ {
90785+ .procname = "heap_stack_gap",
90786+ .data = &sysctl_heap_stack_gap,
90787+ .maxlen = sizeof(sysctl_heap_stack_gap),
90788+ .mode = 0644,
90789+ .proc_handler = proc_doulongvec_minmax,
90790+ },
90791 #else
90792 {
90793 .procname = "nr_trim_pages",
90794@@ -1799,6 +1845,16 @@ int proc_dostring(struct ctl_table *table, int write,
90795 buffer, lenp, ppos);
90796 }
90797
90798+int proc_dostring_modpriv(struct ctl_table *table, int write,
90799+ void __user *buffer, size_t *lenp, loff_t *ppos)
90800+{
90801+ if (write && !capable(CAP_SYS_MODULE))
90802+ return -EPERM;
90803+
90804+ return _proc_do_string(table->data, table->maxlen, write,
90805+ buffer, lenp, ppos);
90806+}
90807+
90808 static size_t proc_skip_spaces(char **buf)
90809 {
90810 size_t ret;
90811@@ -1904,6 +1960,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90812 len = strlen(tmp);
90813 if (len > *size)
90814 len = *size;
90815+ if (len > sizeof(tmp))
90816+ len = sizeof(tmp);
90817 if (copy_to_user(*buf, tmp, len))
90818 return -EFAULT;
90819 *size -= len;
90820@@ -2068,7 +2126,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90821 static int proc_taint(struct ctl_table *table, int write,
90822 void __user *buffer, size_t *lenp, loff_t *ppos)
90823 {
90824- struct ctl_table t;
90825+ ctl_table_no_const t;
90826 unsigned long tmptaint = get_taint();
90827 int err;
90828
90829@@ -2096,7 +2154,6 @@ static int proc_taint(struct ctl_table *table, int write,
90830 return err;
90831 }
90832
90833-#ifdef CONFIG_PRINTK
90834 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90835 void __user *buffer, size_t *lenp, loff_t *ppos)
90836 {
90837@@ -2105,7 +2162,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90838
90839 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90840 }
90841-#endif
90842
90843 struct do_proc_dointvec_minmax_conv_param {
90844 int *min;
90845@@ -2652,6 +2708,12 @@ int proc_dostring(struct ctl_table *table, int write,
90846 return -ENOSYS;
90847 }
90848
90849+int proc_dostring_modpriv(struct ctl_table *table, int write,
90850+ void __user *buffer, size_t *lenp, loff_t *ppos)
90851+{
90852+ return -ENOSYS;
90853+}
90854+
90855 int proc_dointvec(struct ctl_table *table, int write,
90856 void __user *buffer, size_t *lenp, loff_t *ppos)
90857 {
90858@@ -2708,5 +2770,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90859 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90860 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90861 EXPORT_SYMBOL(proc_dostring);
90862+EXPORT_SYMBOL(proc_dostring_modpriv);
90863 EXPORT_SYMBOL(proc_doulongvec_minmax);
90864 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90865diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90866index 13d2f7c..c93d0b0 100644
90867--- a/kernel/taskstats.c
90868+++ b/kernel/taskstats.c
90869@@ -28,9 +28,12 @@
90870 #include <linux/fs.h>
90871 #include <linux/file.h>
90872 #include <linux/pid_namespace.h>
90873+#include <linux/grsecurity.h>
90874 #include <net/genetlink.h>
90875 #include <linux/atomic.h>
90876
90877+extern int gr_is_taskstats_denied(int pid);
90878+
90879 /*
90880 * Maximum length of a cpumask that can be specified in
90881 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90882@@ -576,6 +579,9 @@ err:
90883
90884 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90885 {
90886+ if (gr_is_taskstats_denied(current->pid))
90887+ return -EACCES;
90888+
90889 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90890 return cmd_attr_register_cpumask(info);
90891 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90892diff --git a/kernel/time.c b/kernel/time.c
90893index 7c7964c..2a0d412 100644
90894--- a/kernel/time.c
90895+++ b/kernel/time.c
90896@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90897 return error;
90898
90899 if (tz) {
90900+ /* we log in do_settimeofday called below, so don't log twice
90901+ */
90902+ if (!tv)
90903+ gr_log_timechange();
90904+
90905 sys_tz = *tz;
90906 update_vsyscall_tz();
90907 if (firsttime) {
90908diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90909index 88c9c65..7497ebc 100644
90910--- a/kernel/time/alarmtimer.c
90911+++ b/kernel/time/alarmtimer.c
90912@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90913 struct platform_device *pdev;
90914 int error = 0;
90915 int i;
90916- struct k_clock alarm_clock = {
90917+ static struct k_clock alarm_clock = {
90918 .clock_getres = alarm_clock_getres,
90919 .clock_get = alarm_clock_get,
90920 .timer_create = alarm_timer_create,
90921diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90922index 5b40279..81e58db 100644
90923--- a/kernel/time/timekeeping.c
90924+++ b/kernel/time/timekeeping.c
90925@@ -15,6 +15,7 @@
90926 #include <linux/init.h>
90927 #include <linux/mm.h>
90928 #include <linux/sched.h>
90929+#include <linux/grsecurity.h>
90930 #include <linux/syscore_ops.h>
90931 #include <linux/clocksource.h>
90932 #include <linux/jiffies.h>
90933@@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
90934 if (!timespec_valid_strict(tv))
90935 return -EINVAL;
90936
90937+ gr_log_timechange();
90938+
90939 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90940 write_seqcount_begin(&timekeeper_seq);
90941
90942diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90943index 61ed862..3b52c65 100644
90944--- a/kernel/time/timer_list.c
90945+++ b/kernel/time/timer_list.c
90946@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90947
90948 static void print_name_offset(struct seq_file *m, void *sym)
90949 {
90950+#ifdef CONFIG_GRKERNSEC_HIDESYM
90951+ SEQ_printf(m, "<%p>", NULL);
90952+#else
90953 char symname[KSYM_NAME_LEN];
90954
90955 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90956 SEQ_printf(m, "<%pK>", sym);
90957 else
90958 SEQ_printf(m, "%s", symname);
90959+#endif
90960 }
90961
90962 static void
90963@@ -119,7 +123,11 @@ next_one:
90964 static void
90965 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90966 {
90967+#ifdef CONFIG_GRKERNSEC_HIDESYM
90968+ SEQ_printf(m, " .base: %p\n", NULL);
90969+#else
90970 SEQ_printf(m, " .base: %pK\n", base);
90971+#endif
90972 SEQ_printf(m, " .index: %d\n",
90973 base->index);
90974 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90975@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90976 {
90977 struct proc_dir_entry *pe;
90978
90979+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90980+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90981+#else
90982 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90983+#endif
90984 if (!pe)
90985 return -ENOMEM;
90986 return 0;
90987diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90988index 1fb08f2..ca4bb1e 100644
90989--- a/kernel/time/timer_stats.c
90990+++ b/kernel/time/timer_stats.c
90991@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90992 static unsigned long nr_entries;
90993 static struct entry entries[MAX_ENTRIES];
90994
90995-static atomic_t overflow_count;
90996+static atomic_unchecked_t overflow_count;
90997
90998 /*
90999 * The entries are in a hash-table, for fast lookup:
91000@@ -140,7 +140,7 @@ static void reset_entries(void)
91001 nr_entries = 0;
91002 memset(entries, 0, sizeof(entries));
91003 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
91004- atomic_set(&overflow_count, 0);
91005+ atomic_set_unchecked(&overflow_count, 0);
91006 }
91007
91008 static struct entry *alloc_entry(void)
91009@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
91010 if (likely(entry))
91011 entry->count++;
91012 else
91013- atomic_inc(&overflow_count);
91014+ atomic_inc_unchecked(&overflow_count);
91015
91016 out_unlock:
91017 raw_spin_unlock_irqrestore(lock, flags);
91018@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
91019
91020 static void print_name_offset(struct seq_file *m, unsigned long addr)
91021 {
91022+#ifdef CONFIG_GRKERNSEC_HIDESYM
91023+ seq_printf(m, "<%p>", NULL);
91024+#else
91025 char symname[KSYM_NAME_LEN];
91026
91027 if (lookup_symbol_name(addr, symname) < 0)
91028- seq_printf(m, "<%p>", (void *)addr);
91029+ seq_printf(m, "<%pK>", (void *)addr);
91030 else
91031 seq_printf(m, "%s", symname);
91032+#endif
91033 }
91034
91035 static int tstats_show(struct seq_file *m, void *v)
91036@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
91037
91038 seq_puts(m, "Timer Stats Version: v0.3\n");
91039 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
91040- if (atomic_read(&overflow_count))
91041- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
91042+ if (atomic_read_unchecked(&overflow_count))
91043+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
91044 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
91045
91046 for (i = 0; i < nr_entries; i++) {
91047@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
91048 {
91049 struct proc_dir_entry *pe;
91050
91051+#ifdef CONFIG_GRKERNSEC_PROC_ADD
91052+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
91053+#else
91054 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
91055+#endif
91056 if (!pe)
91057 return -ENOMEM;
91058 return 0;
91059diff --git a/kernel/timer.c b/kernel/timer.c
91060index 38f0d40..96b2ebf 100644
91061--- a/kernel/timer.c
91062+++ b/kernel/timer.c
91063@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
91064 /*
91065 * This function runs timers and the timer-tq in bottom half context.
91066 */
91067-static void run_timer_softirq(struct softirq_action *h)
91068+static __latent_entropy void run_timer_softirq(void)
91069 {
91070 struct tvec_base *base = __this_cpu_read(tvec_bases);
91071
91072@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
91073 *
91074 * In all cases the return value is guaranteed to be non-negative.
91075 */
91076-signed long __sched schedule_timeout(signed long timeout)
91077+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
91078 {
91079 struct timer_list timer;
91080 unsigned long expire;
91081diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
91082index 4f3a3c03..04b7886 100644
91083--- a/kernel/trace/blktrace.c
91084+++ b/kernel/trace/blktrace.c
91085@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
91086 struct blk_trace *bt = filp->private_data;
91087 char buf[16];
91088
91089- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
91090+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
91091
91092 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
91093 }
91094@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
91095 return 1;
91096
91097 bt = buf->chan->private_data;
91098- atomic_inc(&bt->dropped);
91099+ atomic_inc_unchecked(&bt->dropped);
91100 return 0;
91101 }
91102
91103@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
91104
91105 bt->dir = dir;
91106 bt->dev = dev;
91107- atomic_set(&bt->dropped, 0);
91108+ atomic_set_unchecked(&bt->dropped, 0);
91109 INIT_LIST_HEAD(&bt->running_list);
91110
91111 ret = -EIO;
91112diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
91113index 868633e..921dc41 100644
91114--- a/kernel/trace/ftrace.c
91115+++ b/kernel/trace/ftrace.c
91116@@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
91117 if (unlikely(ftrace_disabled))
91118 return 0;
91119
91120+ ret = ftrace_arch_code_modify_prepare();
91121+ FTRACE_WARN_ON(ret);
91122+ if (ret)
91123+ return 0;
91124+
91125 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
91126+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
91127 if (ret) {
91128 ftrace_bug(ret, ip);
91129- return 0;
91130 }
91131- return 1;
91132+ return ret ? 0 : 1;
91133 }
91134
91135 /*
91136@@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
91137 if (!count)
91138 return 0;
91139
91140+ pax_open_kernel();
91141 sort(start, count, sizeof(*start),
91142 ftrace_cmp_ips, ftrace_swap_ips);
91143+ pax_close_kernel();
91144
91145 start_pg = ftrace_allocate_pages(count);
91146 if (!start_pg)
91147@@ -4890,8 +4897,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
91148 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
91149
91150 static int ftrace_graph_active;
91151-static struct notifier_block ftrace_suspend_notifier;
91152-
91153 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
91154 {
91155 return 0;
91156@@ -5067,6 +5072,10 @@ static void update_function_graph_func(void)
91157 ftrace_graph_entry = ftrace_graph_entry_test;
91158 }
91159
91160+static struct notifier_block ftrace_suspend_notifier = {
91161+ .notifier_call = ftrace_suspend_notifier_call
91162+};
91163+
91164 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91165 trace_func_graph_ent_t entryfunc)
91166 {
91167@@ -5080,7 +5089,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91168 goto out;
91169 }
91170
91171- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
91172 register_pm_notifier(&ftrace_suspend_notifier);
91173
91174 ftrace_graph_active++;
91175diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
91176index fc4da2d..f3e800b 100644
91177--- a/kernel/trace/ring_buffer.c
91178+++ b/kernel/trace/ring_buffer.c
91179@@ -352,9 +352,9 @@ struct buffer_data_page {
91180 */
91181 struct buffer_page {
91182 struct list_head list; /* list of buffer pages */
91183- local_t write; /* index for next write */
91184+ local_unchecked_t write; /* index for next write */
91185 unsigned read; /* index for next read */
91186- local_t entries; /* entries on this page */
91187+ local_unchecked_t entries; /* entries on this page */
91188 unsigned long real_end; /* real end of data */
91189 struct buffer_data_page *page; /* Actual data page */
91190 };
91191@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
91192 unsigned long last_overrun;
91193 local_t entries_bytes;
91194 local_t entries;
91195- local_t overrun;
91196- local_t commit_overrun;
91197+ local_unchecked_t overrun;
91198+ local_unchecked_t commit_overrun;
91199 local_t dropped_events;
91200 local_t committing;
91201 local_t commits;
91202@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91203 *
91204 * We add a counter to the write field to denote this.
91205 */
91206- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
91207- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
91208+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
91209+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
91210
91211 /*
91212 * Just make sure we have seen our old_write and synchronize
91213@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91214 * cmpxchg to only update if an interrupt did not already
91215 * do it for us. If the cmpxchg fails, we don't care.
91216 */
91217- (void)local_cmpxchg(&next_page->write, old_write, val);
91218- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
91219+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
91220+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
91221
91222 /*
91223 * No need to worry about races with clearing out the commit.
91224@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
91225
91226 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
91227 {
91228- return local_read(&bpage->entries) & RB_WRITE_MASK;
91229+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
91230 }
91231
91232 static inline unsigned long rb_page_write(struct buffer_page *bpage)
91233 {
91234- return local_read(&bpage->write) & RB_WRITE_MASK;
91235+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
91236 }
91237
91238 static int
91239@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
91240 * bytes consumed in ring buffer from here.
91241 * Increment overrun to account for the lost events.
91242 */
91243- local_add(page_entries, &cpu_buffer->overrun);
91244+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
91245 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91246 }
91247
91248@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
91249 * it is our responsibility to update
91250 * the counters.
91251 */
91252- local_add(entries, &cpu_buffer->overrun);
91253+ local_add_unchecked(entries, &cpu_buffer->overrun);
91254 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91255
91256 /*
91257@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91258 if (tail == BUF_PAGE_SIZE)
91259 tail_page->real_end = 0;
91260
91261- local_sub(length, &tail_page->write);
91262+ local_sub_unchecked(length, &tail_page->write);
91263 return;
91264 }
91265
91266@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91267 rb_event_set_padding(event);
91268
91269 /* Set the write back to the previous setting */
91270- local_sub(length, &tail_page->write);
91271+ local_sub_unchecked(length, &tail_page->write);
91272 return;
91273 }
91274
91275@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91276
91277 /* Set write to end of buffer */
91278 length = (tail + length) - BUF_PAGE_SIZE;
91279- local_sub(length, &tail_page->write);
91280+ local_sub_unchecked(length, &tail_page->write);
91281 }
91282
91283 /*
91284@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91285 * about it.
91286 */
91287 if (unlikely(next_page == commit_page)) {
91288- local_inc(&cpu_buffer->commit_overrun);
91289+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91290 goto out_reset;
91291 }
91292
91293@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91294 cpu_buffer->tail_page) &&
91295 (cpu_buffer->commit_page ==
91296 cpu_buffer->reader_page))) {
91297- local_inc(&cpu_buffer->commit_overrun);
91298+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91299 goto out_reset;
91300 }
91301 }
91302@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91303 length += RB_LEN_TIME_EXTEND;
91304
91305 tail_page = cpu_buffer->tail_page;
91306- write = local_add_return(length, &tail_page->write);
91307+ write = local_add_return_unchecked(length, &tail_page->write);
91308
91309 /* set write to only the index of the write */
91310 write &= RB_WRITE_MASK;
91311@@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91312 kmemcheck_annotate_bitfield(event, bitfield);
91313 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91314
91315- local_inc(&tail_page->entries);
91316+ local_inc_unchecked(&tail_page->entries);
91317
91318 /*
91319 * If this is the first commit on the page, then update
91320@@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91321
91322 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91323 unsigned long write_mask =
91324- local_read(&bpage->write) & ~RB_WRITE_MASK;
91325+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91326 unsigned long event_length = rb_event_length(event);
91327 /*
91328 * This is on the tail page. It is possible that
91329@@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91330 */
91331 old_index += write_mask;
91332 new_index += write_mask;
91333- index = local_cmpxchg(&bpage->write, old_index, new_index);
91334+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91335 if (index == old_index) {
91336 /* update counters */
91337 local_sub(event_length, &cpu_buffer->entries_bytes);
91338@@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91339
91340 /* Do the likely case first */
91341 if (likely(bpage->page == (void *)addr)) {
91342- local_dec(&bpage->entries);
91343+ local_dec_unchecked(&bpage->entries);
91344 return;
91345 }
91346
91347@@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91348 start = bpage;
91349 do {
91350 if (bpage->page == (void *)addr) {
91351- local_dec(&bpage->entries);
91352+ local_dec_unchecked(&bpage->entries);
91353 return;
91354 }
91355 rb_inc_page(cpu_buffer, &bpage);
91356@@ -3146,7 +3146,7 @@ static inline unsigned long
91357 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91358 {
91359 return local_read(&cpu_buffer->entries) -
91360- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91361+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91362 }
91363
91364 /**
91365@@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91366 return 0;
91367
91368 cpu_buffer = buffer->buffers[cpu];
91369- ret = local_read(&cpu_buffer->overrun);
91370+ ret = local_read_unchecked(&cpu_buffer->overrun);
91371
91372 return ret;
91373 }
91374@@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91375 return 0;
91376
91377 cpu_buffer = buffer->buffers[cpu];
91378- ret = local_read(&cpu_buffer->commit_overrun);
91379+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91380
91381 return ret;
91382 }
91383@@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91384 /* if you care about this being correct, lock the buffer */
91385 for_each_buffer_cpu(buffer, cpu) {
91386 cpu_buffer = buffer->buffers[cpu];
91387- overruns += local_read(&cpu_buffer->overrun);
91388+ overruns += local_read_unchecked(&cpu_buffer->overrun);
91389 }
91390
91391 return overruns;
91392@@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91393 /*
91394 * Reset the reader page to size zero.
91395 */
91396- local_set(&cpu_buffer->reader_page->write, 0);
91397- local_set(&cpu_buffer->reader_page->entries, 0);
91398+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91399+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91400 local_set(&cpu_buffer->reader_page->page->commit, 0);
91401 cpu_buffer->reader_page->real_end = 0;
91402
91403@@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91404 * want to compare with the last_overrun.
91405 */
91406 smp_mb();
91407- overwrite = local_read(&(cpu_buffer->overrun));
91408+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91409
91410 /*
91411 * Here's the tricky part.
91412@@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91413
91414 cpu_buffer->head_page
91415 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91416- local_set(&cpu_buffer->head_page->write, 0);
91417- local_set(&cpu_buffer->head_page->entries, 0);
91418+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
91419+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91420 local_set(&cpu_buffer->head_page->page->commit, 0);
91421
91422 cpu_buffer->head_page->read = 0;
91423@@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91424
91425 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91426 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91427- local_set(&cpu_buffer->reader_page->write, 0);
91428- local_set(&cpu_buffer->reader_page->entries, 0);
91429+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91430+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91431 local_set(&cpu_buffer->reader_page->page->commit, 0);
91432 cpu_buffer->reader_page->read = 0;
91433
91434 local_set(&cpu_buffer->entries_bytes, 0);
91435- local_set(&cpu_buffer->overrun, 0);
91436- local_set(&cpu_buffer->commit_overrun, 0);
91437+ local_set_unchecked(&cpu_buffer->overrun, 0);
91438+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91439 local_set(&cpu_buffer->dropped_events, 0);
91440 local_set(&cpu_buffer->entries, 0);
91441 local_set(&cpu_buffer->committing, 0);
91442@@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91443 rb_init_page(bpage);
91444 bpage = reader->page;
91445 reader->page = *data_page;
91446- local_set(&reader->write, 0);
91447- local_set(&reader->entries, 0);
91448+ local_set_unchecked(&reader->write, 0);
91449+ local_set_unchecked(&reader->entries, 0);
91450 reader->read = 0;
91451 *data_page = bpage;
91452
91453diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91454index 24c1f23..781fd73f 100644
91455--- a/kernel/trace/trace.c
91456+++ b/kernel/trace/trace.c
91457@@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91458 return 0;
91459 }
91460
91461-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91462+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91463 {
91464 /* do nothing if flag is already set */
91465 if (!!(trace_flags & mask) == !!enabled)
91466diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91467index 02b592f..f971546 100644
91468--- a/kernel/trace/trace.h
91469+++ b/kernel/trace/trace.h
91470@@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
91471 void trace_printk_init_buffers(void);
91472 void trace_printk_start_comm(void);
91473 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91474-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91475+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91476
91477 /*
91478 * Normal trace_printk() and friends allocates special buffers
91479diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91480index 26dc348..8708ca7 100644
91481--- a/kernel/trace/trace_clock.c
91482+++ b/kernel/trace/trace_clock.c
91483@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
91484 return now;
91485 }
91486
91487-static atomic64_t trace_counter;
91488+static atomic64_unchecked_t trace_counter;
91489
91490 /*
91491 * trace_clock_counter(): simply an atomic counter.
91492@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
91493 */
91494 u64 notrace trace_clock_counter(void)
91495 {
91496- return atomic64_add_return(1, &trace_counter);
91497+ return atomic64_inc_return_unchecked(&trace_counter);
91498 }
91499diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91500index 7b16d40..1b2875d 100644
91501--- a/kernel/trace/trace_events.c
91502+++ b/kernel/trace/trace_events.c
91503@@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91504 return 0;
91505 }
91506
91507-struct ftrace_module_file_ops;
91508 static void __add_event_to_tracers(struct ftrace_event_call *call);
91509
91510 /* Add an additional event_call dynamically */
91511diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91512index 0abd9b8..6a663a2 100644
91513--- a/kernel/trace/trace_mmiotrace.c
91514+++ b/kernel/trace/trace_mmiotrace.c
91515@@ -24,7 +24,7 @@ struct header_iter {
91516 static struct trace_array *mmio_trace_array;
91517 static bool overrun_detected;
91518 static unsigned long prev_overruns;
91519-static atomic_t dropped_count;
91520+static atomic_unchecked_t dropped_count;
91521
91522 static void mmio_reset_data(struct trace_array *tr)
91523 {
91524@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91525
91526 static unsigned long count_overruns(struct trace_iterator *iter)
91527 {
91528- unsigned long cnt = atomic_xchg(&dropped_count, 0);
91529+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91530 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91531
91532 if (over > prev_overruns)
91533@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91534 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91535 sizeof(*entry), 0, pc);
91536 if (!event) {
91537- atomic_inc(&dropped_count);
91538+ atomic_inc_unchecked(&dropped_count);
91539 return;
91540 }
91541 entry = ring_buffer_event_data(event);
91542@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91543 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91544 sizeof(*entry), 0, pc);
91545 if (!event) {
91546- atomic_inc(&dropped_count);
91547+ atomic_inc_unchecked(&dropped_count);
91548 return;
91549 }
91550 entry = ring_buffer_event_data(event);
91551diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91552index ed32284..884d6c3 100644
91553--- a/kernel/trace/trace_output.c
91554+++ b/kernel/trace/trace_output.c
91555@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91556
91557 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91558 if (!IS_ERR(p)) {
91559- p = mangle_path(s->buffer + s->len, p, "\n");
91560+ p = mangle_path(s->buffer + s->len, p, "\n\\");
91561 if (p) {
91562 s->len = p - s->buffer;
91563 return 1;
91564@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
91565 goto out;
91566 }
91567
91568+ pax_open_kernel();
91569 if (event->funcs->trace == NULL)
91570- event->funcs->trace = trace_nop_print;
91571+ *(void **)&event->funcs->trace = trace_nop_print;
91572 if (event->funcs->raw == NULL)
91573- event->funcs->raw = trace_nop_print;
91574+ *(void **)&event->funcs->raw = trace_nop_print;
91575 if (event->funcs->hex == NULL)
91576- event->funcs->hex = trace_nop_print;
91577+ *(void **)&event->funcs->hex = trace_nop_print;
91578 if (event->funcs->binary == NULL)
91579- event->funcs->binary = trace_nop_print;
91580+ *(void **)&event->funcs->binary = trace_nop_print;
91581+ pax_close_kernel();
91582
91583 key = event->type & (EVENT_HASHSIZE - 1);
91584
91585diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91586index e6be585..d73ae5e 100644
91587--- a/kernel/trace/trace_stack.c
91588+++ b/kernel/trace/trace_stack.c
91589@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91590 return;
91591
91592 /* we do not handle interrupt stacks yet */
91593- if (!object_is_on_stack(stack))
91594+ if (!object_starts_on_stack(stack))
91595 return;
91596
91597 local_irq_save(flags);
91598diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91599index 80a57af..7f5a7ff 100644
91600--- a/kernel/user_namespace.c
91601+++ b/kernel/user_namespace.c
91602@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91603 !kgid_has_mapping(parent_ns, group))
91604 return -EPERM;
91605
91606+#ifdef CONFIG_GRKERNSEC
91607+ /*
91608+ * This doesn't really inspire confidence:
91609+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91610+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91611+ * Increases kernel attack surface in areas developers
91612+ * previously cared little about ("low importance due
91613+ * to requiring "root" capability")
91614+ * To be removed when this code receives *proper* review
91615+ */
91616+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91617+ !capable(CAP_SETGID))
91618+ return -EPERM;
91619+#endif
91620+
91621 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91622 if (!ns)
91623 return -ENOMEM;
91624@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91625 if (atomic_read(&current->mm->mm_users) > 1)
91626 return -EINVAL;
91627
91628- if (current->fs->users != 1)
91629+ if (atomic_read(&current->fs->users) != 1)
91630 return -EINVAL;
91631
91632 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91633diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91634index 4f69f9a..7c6f8f8 100644
91635--- a/kernel/utsname_sysctl.c
91636+++ b/kernel/utsname_sysctl.c
91637@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91638 static int proc_do_uts_string(ctl_table *table, int write,
91639 void __user *buffer, size_t *lenp, loff_t *ppos)
91640 {
91641- struct ctl_table uts_table;
91642+ ctl_table_no_const uts_table;
91643 int r;
91644 memcpy(&uts_table, table, sizeof(uts_table));
91645 uts_table.data = get_uts(table, write);
91646diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91647index 4431610..4265616 100644
91648--- a/kernel/watchdog.c
91649+++ b/kernel/watchdog.c
91650@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91651 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91652 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91653
91654-static struct smp_hotplug_thread watchdog_threads = {
91655+static struct smp_hotplug_thread watchdog_threads __read_only = {
91656 .store = &softlockup_watchdog,
91657 .thread_should_run = watchdog_should_run,
91658 .thread_fn = watchdog,
91659diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91660index b6a3941..b68f191 100644
91661--- a/kernel/workqueue.c
91662+++ b/kernel/workqueue.c
91663@@ -4702,7 +4702,7 @@ static void rebind_workers(struct worker_pool *pool)
91664 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91665 worker_flags |= WORKER_REBOUND;
91666 worker_flags &= ~WORKER_UNBOUND;
91667- ACCESS_ONCE(worker->flags) = worker_flags;
91668+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
91669 }
91670
91671 spin_unlock_irq(&pool->lock);
91672diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91673index a48abea..e108def 100644
91674--- a/lib/Kconfig.debug
91675+++ b/lib/Kconfig.debug
91676@@ -854,7 +854,7 @@ config DEBUG_MUTEXES
91677
91678 config DEBUG_WW_MUTEX_SLOWPATH
91679 bool "Wait/wound mutex debugging: Slowpath testing"
91680- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91681+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91682 select DEBUG_LOCK_ALLOC
91683 select DEBUG_SPINLOCK
91684 select DEBUG_MUTEXES
91685@@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91686
91687 config DEBUG_LOCK_ALLOC
91688 bool "Lock debugging: detect incorrect freeing of live locks"
91689- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91690+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91691 select DEBUG_SPINLOCK
91692 select DEBUG_MUTEXES
91693 select LOCKDEP
91694@@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
91695
91696 config PROVE_LOCKING
91697 bool "Lock debugging: prove locking correctness"
91698- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91699+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91700 select LOCKDEP
91701 select DEBUG_SPINLOCK
91702 select DEBUG_MUTEXES
91703@@ -932,7 +932,7 @@ config LOCKDEP
91704
91705 config LOCK_STAT
91706 bool "Lock usage statistics"
91707- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91708+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91709 select LOCKDEP
91710 select DEBUG_SPINLOCK
91711 select DEBUG_MUTEXES
91712@@ -1394,6 +1394,7 @@ config LATENCYTOP
91713 depends on DEBUG_KERNEL
91714 depends on STACKTRACE_SUPPORT
91715 depends on PROC_FS
91716+ depends on !GRKERNSEC_HIDESYM
91717 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91718 select KALLSYMS
91719 select KALLSYMS_ALL
91720@@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91721 config DEBUG_STRICT_USER_COPY_CHECKS
91722 bool "Strict user copy size checks"
91723 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91724- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91725+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91726 help
91727 Enabling this option turns a certain set of sanity checks for user
91728 copy operations into compile time failures.
91729@@ -1529,7 +1530,7 @@ endmenu # runtime tests
91730
91731 config PROVIDE_OHCI1394_DMA_INIT
91732 bool "Remote debugging over FireWire early on boot"
91733- depends on PCI && X86
91734+ depends on PCI && X86 && !GRKERNSEC
91735 help
91736 If you want to debug problems which hang or crash the kernel early
91737 on boot and the crashing machine has a FireWire port, you can use
91738diff --git a/lib/Makefile b/lib/Makefile
91739index 48140e3..de854e5 100644
91740--- a/lib/Makefile
91741+++ b/lib/Makefile
91742@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91743 obj-$(CONFIG_BTREE) += btree.o
91744 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91745 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91746-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91747+obj-y += list_debug.o
91748 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91749
91750 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91751diff --git a/lib/average.c b/lib/average.c
91752index 114d1be..ab0350c 100644
91753--- a/lib/average.c
91754+++ b/lib/average.c
91755@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91756 {
91757 unsigned long internal = ACCESS_ONCE(avg->internal);
91758
91759- ACCESS_ONCE(avg->internal) = internal ?
91760+ ACCESS_ONCE_RW(avg->internal) = internal ?
91761 (((internal << avg->weight) - internal) +
91762 (val << avg->factor)) >> avg->weight :
91763 (val << avg->factor);
91764diff --git a/lib/bitmap.c b/lib/bitmap.c
91765index 06f7e4f..f3cf2b0 100644
91766--- a/lib/bitmap.c
91767+++ b/lib/bitmap.c
91768@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91769 {
91770 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91771 u32 chunk;
91772- const char __user __force *ubuf = (const char __user __force *)buf;
91773+ const char __user *ubuf = (const char __force_user *)buf;
91774
91775 bitmap_zero(maskp, nmaskbits);
91776
91777@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91778 {
91779 if (!access_ok(VERIFY_READ, ubuf, ulen))
91780 return -EFAULT;
91781- return __bitmap_parse((const char __force *)ubuf,
91782+ return __bitmap_parse((const char __force_kernel *)ubuf,
91783 ulen, 1, maskp, nmaskbits);
91784
91785 }
91786@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91787 {
91788 unsigned a, b;
91789 int c, old_c, totaldigits;
91790- const char __user __force *ubuf = (const char __user __force *)buf;
91791+ const char __user *ubuf = (const char __force_user *)buf;
91792 int exp_digit, in_range;
91793
91794 totaldigits = c = 0;
91795@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91796 {
91797 if (!access_ok(VERIFY_READ, ubuf, ulen))
91798 return -EFAULT;
91799- return __bitmap_parselist((const char __force *)ubuf,
91800+ return __bitmap_parselist((const char __force_kernel *)ubuf,
91801 ulen, 1, maskp, nmaskbits);
91802 }
91803 EXPORT_SYMBOL(bitmap_parselist_user);
91804diff --git a/lib/bug.c b/lib/bug.c
91805index 1686034..a9c00c8 100644
91806--- a/lib/bug.c
91807+++ b/lib/bug.c
91808@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91809 return BUG_TRAP_TYPE_NONE;
91810
91811 bug = find_bug(bugaddr);
91812+ if (!bug)
91813+ return BUG_TRAP_TYPE_NONE;
91814
91815 file = NULL;
91816 line = 0;
91817diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91818index e0731c3..ad66444 100644
91819--- a/lib/debugobjects.c
91820+++ b/lib/debugobjects.c
91821@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91822 if (limit > 4)
91823 return;
91824
91825- is_on_stack = object_is_on_stack(addr);
91826+ is_on_stack = object_starts_on_stack(addr);
91827 if (is_on_stack == onstack)
91828 return;
91829
91830diff --git a/lib/devres.c b/lib/devres.c
91831index 8235331..5881053 100644
91832--- a/lib/devres.c
91833+++ b/lib/devres.c
91834@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
91835 void devm_iounmap(struct device *dev, void __iomem *addr)
91836 {
91837 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
91838- (void *)addr));
91839+ (void __force *)addr));
91840 iounmap(addr);
91841 }
91842 EXPORT_SYMBOL(devm_iounmap);
91843@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
91844 {
91845 ioport_unmap(addr);
91846 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
91847- devm_ioport_map_match, (void *)addr));
91848+ devm_ioport_map_match, (void __force *)addr));
91849 }
91850 EXPORT_SYMBOL(devm_ioport_unmap);
91851 #endif /* CONFIG_HAS_IOPORT */
91852diff --git a/lib/div64.c b/lib/div64.c
91853index 4382ad7..08aa558 100644
91854--- a/lib/div64.c
91855+++ b/lib/div64.c
91856@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91857 EXPORT_SYMBOL(__div64_32);
91858
91859 #ifndef div_s64_rem
91860-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91861+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91862 {
91863 u64 quotient;
91864
91865@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91866 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91867 */
91868 #ifndef div64_u64
91869-u64 div64_u64(u64 dividend, u64 divisor)
91870+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91871 {
91872 u32 high = divisor >> 32;
91873 u64 quot;
91874diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91875index 98f2d7e..899da5c 100644
91876--- a/lib/dma-debug.c
91877+++ b/lib/dma-debug.c
91878@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91879
91880 void dma_debug_add_bus(struct bus_type *bus)
91881 {
91882- struct notifier_block *nb;
91883+ notifier_block_no_const *nb;
91884
91885 if (global_disable)
91886 return;
91887@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91888
91889 static void check_for_stack(struct device *dev, void *addr)
91890 {
91891- if (object_is_on_stack(addr))
91892+ if (object_starts_on_stack(addr))
91893 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91894 "stack [addr=%p]\n", addr);
91895 }
91896diff --git a/lib/hash.c b/lib/hash.c
91897index fea973f..386626f 100644
91898--- a/lib/hash.c
91899+++ b/lib/hash.c
91900@@ -14,7 +14,7 @@
91901 #include <linux/hash.h>
91902 #include <linux/cache.h>
91903
91904-static struct fast_hash_ops arch_hash_ops __read_mostly = {
91905+static struct fast_hash_ops arch_hash_ops __read_only = {
91906 .hash = jhash,
91907 .hash2 = jhash2,
91908 };
91909diff --git a/lib/inflate.c b/lib/inflate.c
91910index 013a761..c28f3fc 100644
91911--- a/lib/inflate.c
91912+++ b/lib/inflate.c
91913@@ -269,7 +269,7 @@ static void free(void *where)
91914 malloc_ptr = free_mem_ptr;
91915 }
91916 #else
91917-#define malloc(a) kmalloc(a, GFP_KERNEL)
91918+#define malloc(a) kmalloc((a), GFP_KERNEL)
91919 #define free(a) kfree(a)
91920 #endif
91921
91922diff --git a/lib/ioremap.c b/lib/ioremap.c
91923index 0c9216c..863bd89 100644
91924--- a/lib/ioremap.c
91925+++ b/lib/ioremap.c
91926@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91927 unsigned long next;
91928
91929 phys_addr -= addr;
91930- pmd = pmd_alloc(&init_mm, pud, addr);
91931+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91932 if (!pmd)
91933 return -ENOMEM;
91934 do {
91935@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91936 unsigned long next;
91937
91938 phys_addr -= addr;
91939- pud = pud_alloc(&init_mm, pgd, addr);
91940+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91941 if (!pud)
91942 return -ENOMEM;
91943 do {
91944diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91945index bd2bea9..6b3c95e 100644
91946--- a/lib/is_single_threaded.c
91947+++ b/lib/is_single_threaded.c
91948@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91949 struct task_struct *p, *t;
91950 bool ret;
91951
91952+ if (!mm)
91953+ return true;
91954+
91955 if (atomic_read(&task->signal->live) != 1)
91956 return false;
91957
91958diff --git a/lib/kobject.c b/lib/kobject.c
91959index cb14aea..8c53cdb 100644
91960--- a/lib/kobject.c
91961+++ b/lib/kobject.c
91962@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91963
91964
91965 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91966-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91967+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91968
91969-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91970+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91971 {
91972 enum kobj_ns_type type = ops->type;
91973 int error;
91974diff --git a/lib/list_debug.c b/lib/list_debug.c
91975index c24c2f7..f0296f4 100644
91976--- a/lib/list_debug.c
91977+++ b/lib/list_debug.c
91978@@ -11,7 +11,9 @@
91979 #include <linux/bug.h>
91980 #include <linux/kernel.h>
91981 #include <linux/rculist.h>
91982+#include <linux/mm.h>
91983
91984+#ifdef CONFIG_DEBUG_LIST
91985 /*
91986 * Insert a new entry between two known consecutive entries.
91987 *
91988@@ -19,21 +21,40 @@
91989 * the prev/next entries already!
91990 */
91991
91992+static bool __list_add_debug(struct list_head *new,
91993+ struct list_head *prev,
91994+ struct list_head *next)
91995+{
91996+ if (unlikely(next->prev != prev)) {
91997+ printk(KERN_ERR "list_add corruption. next->prev should be "
91998+ "prev (%p), but was %p. (next=%p).\n",
91999+ prev, next->prev, next);
92000+ BUG();
92001+ return false;
92002+ }
92003+ if (unlikely(prev->next != next)) {
92004+ printk(KERN_ERR "list_add corruption. prev->next should be "
92005+ "next (%p), but was %p. (prev=%p).\n",
92006+ next, prev->next, prev);
92007+ BUG();
92008+ return false;
92009+ }
92010+ if (unlikely(new == prev || new == next)) {
92011+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
92012+ new, prev, next);
92013+ BUG();
92014+ return false;
92015+ }
92016+ return true;
92017+}
92018+
92019 void __list_add(struct list_head *new,
92020- struct list_head *prev,
92021- struct list_head *next)
92022+ struct list_head *prev,
92023+ struct list_head *next)
92024 {
92025- WARN(next->prev != prev,
92026- "list_add corruption. next->prev should be "
92027- "prev (%p), but was %p. (next=%p).\n",
92028- prev, next->prev, next);
92029- WARN(prev->next != next,
92030- "list_add corruption. prev->next should be "
92031- "next (%p), but was %p. (prev=%p).\n",
92032- next, prev->next, prev);
92033- WARN(new == prev || new == next,
92034- "list_add double add: new=%p, prev=%p, next=%p.\n",
92035- new, prev, next);
92036+ if (!__list_add_debug(new, prev, next))
92037+ return;
92038+
92039 next->prev = new;
92040 new->next = next;
92041 new->prev = prev;
92042@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
92043 }
92044 EXPORT_SYMBOL(__list_add);
92045
92046-void __list_del_entry(struct list_head *entry)
92047+static bool __list_del_entry_debug(struct list_head *entry)
92048 {
92049 struct list_head *prev, *next;
92050
92051 prev = entry->prev;
92052 next = entry->next;
92053
92054- if (WARN(next == LIST_POISON1,
92055- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
92056- entry, LIST_POISON1) ||
92057- WARN(prev == LIST_POISON2,
92058- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
92059- entry, LIST_POISON2) ||
92060- WARN(prev->next != entry,
92061- "list_del corruption. prev->next should be %p, "
92062- "but was %p\n", entry, prev->next) ||
92063- WARN(next->prev != entry,
92064- "list_del corruption. next->prev should be %p, "
92065- "but was %p\n", entry, next->prev))
92066+ if (unlikely(next == LIST_POISON1)) {
92067+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
92068+ entry, LIST_POISON1);
92069+ BUG();
92070+ return false;
92071+ }
92072+ if (unlikely(prev == LIST_POISON2)) {
92073+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
92074+ entry, LIST_POISON2);
92075+ BUG();
92076+ return false;
92077+ }
92078+ if (unlikely(entry->prev->next != entry)) {
92079+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
92080+ "but was %p\n", entry, prev->next);
92081+ BUG();
92082+ return false;
92083+ }
92084+ if (unlikely(entry->next->prev != entry)) {
92085+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
92086+ "but was %p\n", entry, next->prev);
92087+ BUG();
92088+ return false;
92089+ }
92090+ return true;
92091+}
92092+
92093+void __list_del_entry(struct list_head *entry)
92094+{
92095+ if (!__list_del_entry_debug(entry))
92096 return;
92097
92098- __list_del(prev, next);
92099+ __list_del(entry->prev, entry->next);
92100 }
92101 EXPORT_SYMBOL(__list_del_entry);
92102
92103@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
92104 void __list_add_rcu(struct list_head *new,
92105 struct list_head *prev, struct list_head *next)
92106 {
92107- WARN(next->prev != prev,
92108- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
92109- prev, next->prev, next);
92110- WARN(prev->next != next,
92111- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
92112- next, prev->next, prev);
92113+ if (!__list_add_debug(new, prev, next))
92114+ return;
92115+
92116 new->next = next;
92117 new->prev = prev;
92118 rcu_assign_pointer(list_next_rcu(prev), new);
92119 next->prev = new;
92120 }
92121 EXPORT_SYMBOL(__list_add_rcu);
92122+#endif
92123+
92124+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
92125+{
92126+#ifdef CONFIG_DEBUG_LIST
92127+ if (!__list_add_debug(new, prev, next))
92128+ return;
92129+#endif
92130+
92131+ pax_open_kernel();
92132+ next->prev = new;
92133+ new->next = next;
92134+ new->prev = prev;
92135+ prev->next = new;
92136+ pax_close_kernel();
92137+}
92138+EXPORT_SYMBOL(__pax_list_add);
92139+
92140+void pax_list_del(struct list_head *entry)
92141+{
92142+#ifdef CONFIG_DEBUG_LIST
92143+ if (!__list_del_entry_debug(entry))
92144+ return;
92145+#endif
92146+
92147+ pax_open_kernel();
92148+ __list_del(entry->prev, entry->next);
92149+ entry->next = LIST_POISON1;
92150+ entry->prev = LIST_POISON2;
92151+ pax_close_kernel();
92152+}
92153+EXPORT_SYMBOL(pax_list_del);
92154+
92155+void pax_list_del_init(struct list_head *entry)
92156+{
92157+ pax_open_kernel();
92158+ __list_del(entry->prev, entry->next);
92159+ INIT_LIST_HEAD(entry);
92160+ pax_close_kernel();
92161+}
92162+EXPORT_SYMBOL(pax_list_del_init);
92163+
92164+void __pax_list_add_rcu(struct list_head *new,
92165+ struct list_head *prev, struct list_head *next)
92166+{
92167+#ifdef CONFIG_DEBUG_LIST
92168+ if (!__list_add_debug(new, prev, next))
92169+ return;
92170+#endif
92171+
92172+ pax_open_kernel();
92173+ new->next = next;
92174+ new->prev = prev;
92175+ rcu_assign_pointer(list_next_rcu(prev), new);
92176+ next->prev = new;
92177+ pax_close_kernel();
92178+}
92179+EXPORT_SYMBOL(__pax_list_add_rcu);
92180+
92181+void pax_list_del_rcu(struct list_head *entry)
92182+{
92183+#ifdef CONFIG_DEBUG_LIST
92184+ if (!__list_del_entry_debug(entry))
92185+ return;
92186+#endif
92187+
92188+ pax_open_kernel();
92189+ __list_del(entry->prev, entry->next);
92190+ entry->next = LIST_POISON1;
92191+ entry->prev = LIST_POISON2;
92192+ pax_close_kernel();
92193+}
92194+EXPORT_SYMBOL(pax_list_del_rcu);
92195diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
92196index 963b703..438bc51 100644
92197--- a/lib/percpu-refcount.c
92198+++ b/lib/percpu-refcount.c
92199@@ -29,7 +29,7 @@
92200 * can't hit 0 before we've added up all the percpu refs.
92201 */
92202
92203-#define PCPU_COUNT_BIAS (1U << 31)
92204+#define PCPU_COUNT_BIAS (1U << 30)
92205
92206 /**
92207 * percpu_ref_init - initialize a percpu refcount
92208diff --git a/lib/radix-tree.c b/lib/radix-tree.c
92209index bd4a8df..9e4804f 100644
92210--- a/lib/radix-tree.c
92211+++ b/lib/radix-tree.c
92212@@ -93,7 +93,7 @@ struct radix_tree_preload {
92213 int nr;
92214 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
92215 };
92216-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
92217+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
92218
92219 static inline void *ptr_to_indirect(void *ptr)
92220 {
92221diff --git a/lib/random32.c b/lib/random32.c
92222index 6148967..009bfe8 100644
92223--- a/lib/random32.c
92224+++ b/lib/random32.c
92225@@ -44,7 +44,7 @@
92226 static void __init prandom_state_selftest(void);
92227 #endif
92228
92229-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
92230+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
92231
92232 /**
92233 * prandom_u32_state - seeded pseudo-random number generator.
92234diff --git a/lib/rbtree.c b/lib/rbtree.c
92235index 65f4eff..2cfa167 100644
92236--- a/lib/rbtree.c
92237+++ b/lib/rbtree.c
92238@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
92239 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
92240
92241 static const struct rb_augment_callbacks dummy_callbacks = {
92242- dummy_propagate, dummy_copy, dummy_rotate
92243+ .propagate = dummy_propagate,
92244+ .copy = dummy_copy,
92245+ .rotate = dummy_rotate
92246 };
92247
92248 void rb_insert_color(struct rb_node *node, struct rb_root *root)
92249diff --git a/lib/show_mem.c b/lib/show_mem.c
92250index 0922579..9d7adb9 100644
92251--- a/lib/show_mem.c
92252+++ b/lib/show_mem.c
92253@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
92254 quicklist_total_size());
92255 #endif
92256 #ifdef CONFIG_MEMORY_FAILURE
92257- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
92258+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
92259 #endif
92260 }
92261diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
92262index bb2b201..46abaf9 100644
92263--- a/lib/strncpy_from_user.c
92264+++ b/lib/strncpy_from_user.c
92265@@ -21,7 +21,7 @@
92266 */
92267 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
92268 {
92269- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92270+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92271 long res = 0;
92272
92273 /*
92274diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
92275index a28df52..3d55877 100644
92276--- a/lib/strnlen_user.c
92277+++ b/lib/strnlen_user.c
92278@@ -26,7 +26,7 @@
92279 */
92280 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92281 {
92282- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92283+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92284 long align, res = 0;
92285 unsigned long c;
92286
92287diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92288index b604b83..c0547f6 100644
92289--- a/lib/swiotlb.c
92290+++ b/lib/swiotlb.c
92291@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92292
92293 void
92294 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92295- dma_addr_t dev_addr)
92296+ dma_addr_t dev_addr, struct dma_attrs *attrs)
92297 {
92298 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92299
92300diff --git a/lib/usercopy.c b/lib/usercopy.c
92301index 4f5b1dd..7cab418 100644
92302--- a/lib/usercopy.c
92303+++ b/lib/usercopy.c
92304@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92305 WARN(1, "Buffer overflow detected!\n");
92306 }
92307 EXPORT_SYMBOL(copy_from_user_overflow);
92308+
92309+void copy_to_user_overflow(void)
92310+{
92311+ WARN(1, "Buffer overflow detected!\n");
92312+}
92313+EXPORT_SYMBOL(copy_to_user_overflow);
92314diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92315index 185b6d3..823c48c 100644
92316--- a/lib/vsprintf.c
92317+++ b/lib/vsprintf.c
92318@@ -16,6 +16,9 @@
92319 * - scnprintf and vscnprintf
92320 */
92321
92322+#ifdef CONFIG_GRKERNSEC_HIDESYM
92323+#define __INCLUDED_BY_HIDESYM 1
92324+#endif
92325 #include <stdarg.h>
92326 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92327 #include <linux/types.h>
92328@@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
92329 return number(buf, end, num, spec);
92330 }
92331
92332+#ifdef CONFIG_GRKERNSEC_HIDESYM
92333+int kptr_restrict __read_mostly = 2;
92334+#else
92335 int kptr_restrict __read_mostly;
92336+#endif
92337
92338 /*
92339 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92340@@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
92341 * - 'f' For simple symbolic function names without offset
92342 * - 'S' For symbolic direct pointers with offset
92343 * - 's' For symbolic direct pointers without offset
92344+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92345 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92346 * - 'B' For backtraced symbolic direct pointers with offset
92347 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92348@@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92349
92350 if (!ptr && *fmt != 'K') {
92351 /*
92352- * Print (null) with the same width as a pointer so it makes
92353+ * Print (nil) with the same width as a pointer so it makes
92354 * tabular output look nice.
92355 */
92356 if (spec.field_width == -1)
92357 spec.field_width = default_width;
92358- return string(buf, end, "(null)", spec);
92359+ return string(buf, end, "(nil)", spec);
92360 }
92361
92362 switch (*fmt) {
92363@@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92364 /* Fallthrough */
92365 case 'S':
92366 case 's':
92367+#ifdef CONFIG_GRKERNSEC_HIDESYM
92368+ break;
92369+#else
92370+ return symbol_string(buf, end, ptr, spec, fmt);
92371+#endif
92372+ case 'A':
92373 case 'B':
92374 return symbol_string(buf, end, ptr, spec, fmt);
92375 case 'R':
92376@@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92377 va_end(va);
92378 return buf;
92379 }
92380+ case 'P':
92381+ break;
92382 case 'K':
92383 /*
92384 * %pK cannot be used in IRQ context because its test
92385@@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92386 ((const struct file *)ptr)->f_path.dentry,
92387 spec, fmt);
92388 }
92389+
92390+#ifdef CONFIG_GRKERNSEC_HIDESYM
92391+ /* 'P' = approved pointers to copy to userland,
92392+ as in the /proc/kallsyms case, as we make it display nothing
92393+ for non-root users, and the real contents for root users
92394+ Also ignore 'K' pointers, since we force their NULLing for non-root users
92395+ above
92396+ */
92397+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92398+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92399+ dump_stack();
92400+ ptr = NULL;
92401+ }
92402+#endif
92403+
92404 spec.flags |= SMALL;
92405 if (spec.field_width == -1) {
92406 spec.field_width = default_width;
92407@@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92408 typeof(type) value; \
92409 if (sizeof(type) == 8) { \
92410 args = PTR_ALIGN(args, sizeof(u32)); \
92411- *(u32 *)&value = *(u32 *)args; \
92412- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92413+ *(u32 *)&value = *(const u32 *)args; \
92414+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92415 } else { \
92416 args = PTR_ALIGN(args, sizeof(type)); \
92417- value = *(typeof(type) *)args; \
92418+ value = *(const typeof(type) *)args; \
92419 } \
92420 args += sizeof(type); \
92421 value; \
92422@@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92423 case FORMAT_TYPE_STR: {
92424 const char *str_arg = args;
92425 args += strlen(str_arg) + 1;
92426- str = string(str, end, (char *)str_arg, spec);
92427+ str = string(str, end, str_arg, spec);
92428 break;
92429 }
92430
92431diff --git a/localversion-grsec b/localversion-grsec
92432new file mode 100644
92433index 0000000..7cd6065
92434--- /dev/null
92435+++ b/localversion-grsec
92436@@ -0,0 +1 @@
92437+-grsec
92438diff --git a/mm/Kconfig b/mm/Kconfig
92439index 2888024..c15a810 100644
92440--- a/mm/Kconfig
92441+++ b/mm/Kconfig
92442@@ -326,10 +326,11 @@ config KSM
92443 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92444
92445 config DEFAULT_MMAP_MIN_ADDR
92446- int "Low address space to protect from user allocation"
92447+ int "Low address space to protect from user allocation"
92448 depends on MMU
92449- default 4096
92450- help
92451+ default 32768 if ALPHA || ARM || PARISC || SPARC32
92452+ default 65536
92453+ help
92454 This is the portion of low virtual memory which should be protected
92455 from userspace allocation. Keeping a user from writing to low pages
92456 can help reduce the impact of kernel NULL pointer bugs.
92457@@ -360,7 +361,7 @@ config MEMORY_FAILURE
92458
92459 config HWPOISON_INJECT
92460 tristate "HWPoison pages injector"
92461- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92462+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92463 select PROC_PAGE_MONITOR
92464
92465 config NOMMU_INITIAL_TRIM_EXCESS
92466diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92467index 09d9591..165bb75 100644
92468--- a/mm/backing-dev.c
92469+++ b/mm/backing-dev.c
92470@@ -12,7 +12,7 @@
92471 #include <linux/device.h>
92472 #include <trace/events/writeback.h>
92473
92474-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92475+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92476
92477 struct backing_dev_info default_backing_dev_info = {
92478 .name = "default",
92479@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92480 return err;
92481
92482 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92483- atomic_long_inc_return(&bdi_seq));
92484+ atomic_long_inc_return_unchecked(&bdi_seq));
92485 if (err) {
92486 bdi_destroy(bdi);
92487 return err;
92488diff --git a/mm/filemap.c b/mm/filemap.c
92489index 7a13f6a..e31738b 100644
92490--- a/mm/filemap.c
92491+++ b/mm/filemap.c
92492@@ -192,9 +192,11 @@ static int filemap_check_errors(struct address_space *mapping)
92493 {
92494 int ret = 0;
92495 /* Check for outstanding write errors */
92496- if (test_and_clear_bit(AS_ENOSPC, &mapping->flags))
92497+ if (test_bit(AS_ENOSPC, &mapping->flags) &&
92498+ test_and_clear_bit(AS_ENOSPC, &mapping->flags))
92499 ret = -ENOSPC;
92500- if (test_and_clear_bit(AS_EIO, &mapping->flags))
92501+ if (test_bit(AS_EIO, &mapping->flags) &&
92502+ test_and_clear_bit(AS_EIO, &mapping->flags))
92503 ret = -EIO;
92504 return ret;
92505 }
92506@@ -1766,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92507 struct address_space *mapping = file->f_mapping;
92508
92509 if (!mapping->a_ops->readpage)
92510- return -ENOEXEC;
92511+ return -ENODEV;
92512 file_accessed(file);
92513 vma->vm_ops = &generic_file_vm_ops;
92514 return 0;
92515@@ -1948,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92516
92517 while (bytes) {
92518 char __user *buf = iov->iov_base + base;
92519- int copy = min(bytes, iov->iov_len - base);
92520+ size_t copy = min(bytes, iov->iov_len - base);
92521
92522 base = 0;
92523 left = __copy_from_user_inatomic(vaddr, buf, copy);
92524@@ -1977,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92525 BUG_ON(!in_atomic());
92526 kaddr = kmap_atomic(page);
92527 if (likely(i->nr_segs == 1)) {
92528- int left;
92529+ size_t left;
92530 char __user *buf = i->iov->iov_base + i->iov_offset;
92531 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92532 copied = bytes - left;
92533@@ -2005,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92534
92535 kaddr = kmap(page);
92536 if (likely(i->nr_segs == 1)) {
92537- int left;
92538+ size_t left;
92539 char __user *buf = i->iov->iov_base + i->iov_offset;
92540 left = __copy_from_user(kaddr + offset, buf, bytes);
92541 copied = bytes - left;
92542@@ -2035,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92543 * zero-length segments (without overruning the iovec).
92544 */
92545 while (bytes || unlikely(i->count && !iov->iov_len)) {
92546- int copy;
92547+ size_t copy;
92548
92549 copy = min(bytes, iov->iov_len - base);
92550 BUG_ON(!i->count || i->count < copy);
92551@@ -2106,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92552 *pos = i_size_read(inode);
92553
92554 if (limit != RLIM_INFINITY) {
92555+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92556 if (*pos >= limit) {
92557 send_sig(SIGXFSZ, current, 0);
92558 return -EFBIG;
92559diff --git a/mm/fremap.c b/mm/fremap.c
92560index 34feba6..315fe78 100644
92561--- a/mm/fremap.c
92562+++ b/mm/fremap.c
92563@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92564 retry:
92565 vma = find_vma(mm, start);
92566
92567+#ifdef CONFIG_PAX_SEGMEXEC
92568+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92569+ goto out;
92570+#endif
92571+
92572 /*
92573 * Make sure the vma is shared, that it supports prefaulting,
92574 * and that the remapped range is valid and fully within
92575diff --git a/mm/highmem.c b/mm/highmem.c
92576index b32b70c..e512eb0 100644
92577--- a/mm/highmem.c
92578+++ b/mm/highmem.c
92579@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92580 * So no dangers, even with speculative execution.
92581 */
92582 page = pte_page(pkmap_page_table[i]);
92583+ pax_open_kernel();
92584 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92585-
92586+ pax_close_kernel();
92587 set_page_address(page, NULL);
92588 need_flush = 1;
92589 }
92590@@ -198,9 +199,11 @@ start:
92591 }
92592 }
92593 vaddr = PKMAP_ADDR(last_pkmap_nr);
92594+
92595+ pax_open_kernel();
92596 set_pte_at(&init_mm, vaddr,
92597 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92598-
92599+ pax_close_kernel();
92600 pkmap_count[last_pkmap_nr] = 1;
92601 set_page_address(page, (void *)vaddr);
92602
92603diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92604index 06a9bc0..cfbba83 100644
92605--- a/mm/hugetlb.c
92606+++ b/mm/hugetlb.c
92607@@ -2070,15 +2070,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92608 struct hstate *h = &default_hstate;
92609 unsigned long tmp;
92610 int ret;
92611+ ctl_table_no_const hugetlb_table;
92612
92613 tmp = h->max_huge_pages;
92614
92615 if (write && h->order >= MAX_ORDER)
92616 return -EINVAL;
92617
92618- table->data = &tmp;
92619- table->maxlen = sizeof(unsigned long);
92620- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92621+ hugetlb_table = *table;
92622+ hugetlb_table.data = &tmp;
92623+ hugetlb_table.maxlen = sizeof(unsigned long);
92624+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92625 if (ret)
92626 goto out;
92627
92628@@ -2123,15 +2125,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92629 struct hstate *h = &default_hstate;
92630 unsigned long tmp;
92631 int ret;
92632+ ctl_table_no_const hugetlb_table;
92633
92634 tmp = h->nr_overcommit_huge_pages;
92635
92636 if (write && h->order >= MAX_ORDER)
92637 return -EINVAL;
92638
92639- table->data = &tmp;
92640- table->maxlen = sizeof(unsigned long);
92641- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92642+ hugetlb_table = *table;
92643+ hugetlb_table.data = &tmp;
92644+ hugetlb_table.maxlen = sizeof(unsigned long);
92645+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92646 if (ret)
92647 goto out;
92648
92649@@ -2600,6 +2604,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92650 return 1;
92651 }
92652
92653+#ifdef CONFIG_PAX_SEGMEXEC
92654+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92655+{
92656+ struct mm_struct *mm = vma->vm_mm;
92657+ struct vm_area_struct *vma_m;
92658+ unsigned long address_m;
92659+ pte_t *ptep_m;
92660+
92661+ vma_m = pax_find_mirror_vma(vma);
92662+ if (!vma_m)
92663+ return;
92664+
92665+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92666+ address_m = address + SEGMEXEC_TASK_SIZE;
92667+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92668+ get_page(page_m);
92669+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
92670+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92671+}
92672+#endif
92673+
92674 /*
92675 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92676 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92677@@ -2716,6 +2741,11 @@ retry_avoidcopy:
92678 make_huge_pte(vma, new_page, 1));
92679 page_remove_rmap(old_page);
92680 hugepage_add_new_anon_rmap(new_page, vma, address);
92681+
92682+#ifdef CONFIG_PAX_SEGMEXEC
92683+ pax_mirror_huge_pte(vma, address, new_page);
92684+#endif
92685+
92686 /* Make the old page be freed below */
92687 new_page = old_page;
92688 }
92689@@ -2880,6 +2910,10 @@ retry:
92690 && (vma->vm_flags & VM_SHARED)));
92691 set_huge_pte_at(mm, address, ptep, new_pte);
92692
92693+#ifdef CONFIG_PAX_SEGMEXEC
92694+ pax_mirror_huge_pte(vma, address, page);
92695+#endif
92696+
92697 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92698 /* Optimization, do the COW without a second fault */
92699 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92700@@ -2910,6 +2944,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92701 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
92702 struct hstate *h = hstate_vma(vma);
92703
92704+#ifdef CONFIG_PAX_SEGMEXEC
92705+ struct vm_area_struct *vma_m;
92706+#endif
92707+
92708 address &= huge_page_mask(h);
92709
92710 ptep = huge_pte_offset(mm, address);
92711@@ -2923,6 +2961,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92712 VM_FAULT_SET_HINDEX(hstate_index(h));
92713 }
92714
92715+#ifdef CONFIG_PAX_SEGMEXEC
92716+ vma_m = pax_find_mirror_vma(vma);
92717+ if (vma_m) {
92718+ unsigned long address_m;
92719+
92720+ if (vma->vm_start > vma_m->vm_start) {
92721+ address_m = address;
92722+ address -= SEGMEXEC_TASK_SIZE;
92723+ vma = vma_m;
92724+ h = hstate_vma(vma);
92725+ } else
92726+ address_m = address + SEGMEXEC_TASK_SIZE;
92727+
92728+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92729+ return VM_FAULT_OOM;
92730+ address_m &= HPAGE_MASK;
92731+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92732+ }
92733+#endif
92734+
92735 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92736 if (!ptep)
92737 return VM_FAULT_OOM;
92738diff --git a/mm/internal.h b/mm/internal.h
92739index 3e91000..4741a60 100644
92740--- a/mm/internal.h
92741+++ b/mm/internal.h
92742@@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92743 * in mm/page_alloc.c
92744 */
92745 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92746+extern void free_compound_page(struct page *page);
92747 extern void prep_compound_page(struct page *page, unsigned long order);
92748 #ifdef CONFIG_MEMORY_FAILURE
92749 extern bool is_free_buddy_page(struct page *page);
92750@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
92751
92752 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92753 unsigned long, unsigned long,
92754- unsigned long, unsigned long);
92755+ unsigned long, unsigned long) __intentional_overflow(-1);
92756
92757 extern void set_pageblock_order(void);
92758 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92759diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92760index 31f01c5..7015178 100644
92761--- a/mm/kmemleak.c
92762+++ b/mm/kmemleak.c
92763@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
92764
92765 for (i = 0; i < object->trace_len; i++) {
92766 void *ptr = (void *)object->trace[i];
92767- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92768+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92769 }
92770 }
92771
92772@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
92773 return -ENOMEM;
92774 }
92775
92776- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92777+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92778 &kmemleak_fops);
92779 if (!dentry)
92780 pr_warning("Failed to create the debugfs kmemleak file\n");
92781diff --git a/mm/maccess.c b/mm/maccess.c
92782index d53adf9..03a24bf 100644
92783--- a/mm/maccess.c
92784+++ b/mm/maccess.c
92785@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92786 set_fs(KERNEL_DS);
92787 pagefault_disable();
92788 ret = __copy_from_user_inatomic(dst,
92789- (__force const void __user *)src, size);
92790+ (const void __force_user *)src, size);
92791 pagefault_enable();
92792 set_fs(old_fs);
92793
92794@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92795
92796 set_fs(KERNEL_DS);
92797 pagefault_disable();
92798- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92799+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92800 pagefault_enable();
92801 set_fs(old_fs);
92802
92803diff --git a/mm/madvise.c b/mm/madvise.c
92804index 539eeb9..e24a987 100644
92805--- a/mm/madvise.c
92806+++ b/mm/madvise.c
92807@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92808 pgoff_t pgoff;
92809 unsigned long new_flags = vma->vm_flags;
92810
92811+#ifdef CONFIG_PAX_SEGMEXEC
92812+ struct vm_area_struct *vma_m;
92813+#endif
92814+
92815 switch (behavior) {
92816 case MADV_NORMAL:
92817 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92818@@ -126,6 +130,13 @@ success:
92819 /*
92820 * vm_flags is protected by the mmap_sem held in write mode.
92821 */
92822+
92823+#ifdef CONFIG_PAX_SEGMEXEC
92824+ vma_m = pax_find_mirror_vma(vma);
92825+ if (vma_m)
92826+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92827+#endif
92828+
92829 vma->vm_flags = new_flags;
92830
92831 out:
92832@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92833 struct vm_area_struct **prev,
92834 unsigned long start, unsigned long end)
92835 {
92836+
92837+#ifdef CONFIG_PAX_SEGMEXEC
92838+ struct vm_area_struct *vma_m;
92839+#endif
92840+
92841 *prev = vma;
92842 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92843 return -EINVAL;
92844@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92845 zap_page_range(vma, start, end - start, &details);
92846 } else
92847 zap_page_range(vma, start, end - start, NULL);
92848+
92849+#ifdef CONFIG_PAX_SEGMEXEC
92850+ vma_m = pax_find_mirror_vma(vma);
92851+ if (vma_m) {
92852+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92853+ struct zap_details details = {
92854+ .nonlinear_vma = vma_m,
92855+ .last_index = ULONG_MAX,
92856+ };
92857+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92858+ } else
92859+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92860+ }
92861+#endif
92862+
92863 return 0;
92864 }
92865
92866@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92867 if (end < start)
92868 return error;
92869
92870+#ifdef CONFIG_PAX_SEGMEXEC
92871+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92872+ if (end > SEGMEXEC_TASK_SIZE)
92873+ return error;
92874+ } else
92875+#endif
92876+
92877+ if (end > TASK_SIZE)
92878+ return error;
92879+
92880 error = 0;
92881 if (end == start)
92882 return error;
92883diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92884index e346fa9..5d32f0a 100644
92885--- a/mm/memory-failure.c
92886+++ b/mm/memory-failure.c
92887@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92888
92889 int sysctl_memory_failure_recovery __read_mostly = 1;
92890
92891-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92892+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92893
92894 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92895
92896@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92897 pfn, t->comm, t->pid);
92898 si.si_signo = SIGBUS;
92899 si.si_errno = 0;
92900- si.si_addr = (void *)addr;
92901+ si.si_addr = (void __user *)addr;
92902 #ifdef __ARCH_SI_TRAPNO
92903 si.si_trapno = trapno;
92904 #endif
92905@@ -762,7 +762,7 @@ static struct page_state {
92906 unsigned long res;
92907 char *msg;
92908 int (*action)(struct page *p, unsigned long pfn);
92909-} error_states[] = {
92910+} __do_const error_states[] = {
92911 { reserved, reserved, "reserved kernel", me_kernel },
92912 /*
92913 * free pages are specially detected outside this table:
92914@@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92915 nr_pages = 1 << compound_order(hpage);
92916 else /* normal page or thp */
92917 nr_pages = 1;
92918- atomic_long_add(nr_pages, &num_poisoned_pages);
92919+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92920
92921 /*
92922 * We need/can do nothing about count=0 pages.
92923@@ -1091,7 +1091,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92924 if (PageHWPoison(hpage)) {
92925 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
92926 || (p != hpage && TestSetPageHWPoison(hpage))) {
92927- atomic_long_sub(nr_pages, &num_poisoned_pages);
92928+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92929 unlock_page(hpage);
92930 return 0;
92931 }
92932@@ -1157,14 +1157,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92933 */
92934 if (!PageHWPoison(p)) {
92935 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
92936- atomic_long_sub(nr_pages, &num_poisoned_pages);
92937+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92938 put_page(hpage);
92939 res = 0;
92940 goto out;
92941 }
92942 if (hwpoison_filter(p)) {
92943 if (TestClearPageHWPoison(p))
92944- atomic_long_sub(nr_pages, &num_poisoned_pages);
92945+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92946 unlock_page(hpage);
92947 put_page(hpage);
92948 return 0;
92949@@ -1386,7 +1386,7 @@ int unpoison_memory(unsigned long pfn)
92950 return 0;
92951 }
92952 if (TestClearPageHWPoison(p))
92953- atomic_long_dec(&num_poisoned_pages);
92954+ atomic_long_dec_unchecked(&num_poisoned_pages);
92955 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92956 return 0;
92957 }
92958@@ -1400,7 +1400,7 @@ int unpoison_memory(unsigned long pfn)
92959 */
92960 if (TestClearPageHWPoison(page)) {
92961 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92962- atomic_long_sub(nr_pages, &num_poisoned_pages);
92963+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92964 freeit = 1;
92965 if (PageHuge(page))
92966 clear_page_hwpoison_huge_page(page);
92967@@ -1525,11 +1525,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92968 if (PageHuge(page)) {
92969 set_page_hwpoison_huge_page(hpage);
92970 dequeue_hwpoisoned_huge_page(hpage);
92971- atomic_long_add(1 << compound_order(hpage),
92972+ atomic_long_add_unchecked(1 << compound_order(hpage),
92973 &num_poisoned_pages);
92974 } else {
92975 SetPageHWPoison(page);
92976- atomic_long_inc(&num_poisoned_pages);
92977+ atomic_long_inc_unchecked(&num_poisoned_pages);
92978 }
92979 }
92980 return ret;
92981@@ -1568,7 +1568,7 @@ static int __soft_offline_page(struct page *page, int flags)
92982 put_page(page);
92983 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92984 SetPageHWPoison(page);
92985- atomic_long_inc(&num_poisoned_pages);
92986+ atomic_long_inc_unchecked(&num_poisoned_pages);
92987 return 0;
92988 }
92989
92990@@ -1619,7 +1619,7 @@ static int __soft_offline_page(struct page *page, int flags)
92991 if (!is_free_buddy_page(page))
92992 pr_info("soft offline: %#lx: page leaked\n",
92993 pfn);
92994- atomic_long_inc(&num_poisoned_pages);
92995+ atomic_long_inc_unchecked(&num_poisoned_pages);
92996 }
92997 } else {
92998 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92999@@ -1693,11 +1693,11 @@ int soft_offline_page(struct page *page, int flags)
93000 if (PageHuge(page)) {
93001 set_page_hwpoison_huge_page(hpage);
93002 dequeue_hwpoisoned_huge_page(hpage);
93003- atomic_long_add(1 << compound_order(hpage),
93004+ atomic_long_add_unchecked(1 << compound_order(hpage),
93005 &num_poisoned_pages);
93006 } else {
93007 SetPageHWPoison(page);
93008- atomic_long_inc(&num_poisoned_pages);
93009+ atomic_long_inc_unchecked(&num_poisoned_pages);
93010 }
93011 }
93012 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
93013diff --git a/mm/memory.c b/mm/memory.c
93014index 49e930f..90d7ec5 100644
93015--- a/mm/memory.c
93016+++ b/mm/memory.c
93017@@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
93018 free_pte_range(tlb, pmd, addr);
93019 } while (pmd++, addr = next, addr != end);
93020
93021+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
93022 start &= PUD_MASK;
93023 if (start < floor)
93024 return;
93025@@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
93026 pmd = pmd_offset(pud, start);
93027 pud_clear(pud);
93028 pmd_free_tlb(tlb, pmd, start);
93029+#endif
93030+
93031 }
93032
93033 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93034@@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93035 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
93036 } while (pud++, addr = next, addr != end);
93037
93038+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
93039 start &= PGDIR_MASK;
93040 if (start < floor)
93041 return;
93042@@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93043 pud = pud_offset(pgd, start);
93044 pgd_clear(pgd);
93045 pud_free_tlb(tlb, pud, start);
93046+#endif
93047+
93048 }
93049
93050 /*
93051@@ -1636,12 +1642,6 @@ no_page_table:
93052 return page;
93053 }
93054
93055-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
93056-{
93057- return stack_guard_page_start(vma, addr) ||
93058- stack_guard_page_end(vma, addr+PAGE_SIZE);
93059-}
93060-
93061 /**
93062 * __get_user_pages() - pin user pages in memory
93063 * @tsk: task_struct of target task
93064@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93065
93066 i = 0;
93067
93068- do {
93069+ while (nr_pages) {
93070 struct vm_area_struct *vma;
93071
93072- vma = find_extend_vma(mm, start);
93073+ vma = find_vma(mm, start);
93074 if (!vma && in_gate_area(mm, start)) {
93075 unsigned long pg = start & PAGE_MASK;
93076 pgd_t *pgd;
93077@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93078 goto next_page;
93079 }
93080
93081- if (!vma ||
93082+ if (!vma || start < vma->vm_start ||
93083 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
93084 !(vm_flags & vma->vm_flags))
93085 return i ? : -EFAULT;
93086@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93087 int ret;
93088 unsigned int fault_flags = 0;
93089
93090- /* For mlock, just skip the stack guard page. */
93091- if (foll_flags & FOLL_MLOCK) {
93092- if (stack_guard_page(vma, start))
93093- goto next_page;
93094- }
93095 if (foll_flags & FOLL_WRITE)
93096 fault_flags |= FAULT_FLAG_WRITE;
93097 if (nonblocking)
93098@@ -1893,7 +1888,7 @@ next_page:
93099 start += page_increm * PAGE_SIZE;
93100 nr_pages -= page_increm;
93101 } while (nr_pages && start < vma->vm_end);
93102- } while (nr_pages);
93103+ }
93104 return i;
93105 }
93106 EXPORT_SYMBOL(__get_user_pages);
93107@@ -2105,6 +2100,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
93108 page_add_file_rmap(page);
93109 set_pte_at(mm, addr, pte, mk_pte(page, prot));
93110
93111+#ifdef CONFIG_PAX_SEGMEXEC
93112+ pax_mirror_file_pte(vma, addr, page, ptl);
93113+#endif
93114+
93115 retval = 0;
93116 pte_unmap_unlock(pte, ptl);
93117 return retval;
93118@@ -2149,9 +2148,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
93119 if (!page_count(page))
93120 return -EINVAL;
93121 if (!(vma->vm_flags & VM_MIXEDMAP)) {
93122+
93123+#ifdef CONFIG_PAX_SEGMEXEC
93124+ struct vm_area_struct *vma_m;
93125+#endif
93126+
93127 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
93128 BUG_ON(vma->vm_flags & VM_PFNMAP);
93129 vma->vm_flags |= VM_MIXEDMAP;
93130+
93131+#ifdef CONFIG_PAX_SEGMEXEC
93132+ vma_m = pax_find_mirror_vma(vma);
93133+ if (vma_m)
93134+ vma_m->vm_flags |= VM_MIXEDMAP;
93135+#endif
93136+
93137 }
93138 return insert_page(vma, addr, page, vma->vm_page_prot);
93139 }
93140@@ -2234,6 +2245,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
93141 unsigned long pfn)
93142 {
93143 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
93144+ BUG_ON(vma->vm_mirror);
93145
93146 if (addr < vma->vm_start || addr >= vma->vm_end)
93147 return -EFAULT;
93148@@ -2481,7 +2493,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
93149
93150 BUG_ON(pud_huge(*pud));
93151
93152- pmd = pmd_alloc(mm, pud, addr);
93153+ pmd = (mm == &init_mm) ?
93154+ pmd_alloc_kernel(mm, pud, addr) :
93155+ pmd_alloc(mm, pud, addr);
93156 if (!pmd)
93157 return -ENOMEM;
93158 do {
93159@@ -2501,7 +2515,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
93160 unsigned long next;
93161 int err;
93162
93163- pud = pud_alloc(mm, pgd, addr);
93164+ pud = (mm == &init_mm) ?
93165+ pud_alloc_kernel(mm, pgd, addr) :
93166+ pud_alloc(mm, pgd, addr);
93167 if (!pud)
93168 return -ENOMEM;
93169 do {
93170@@ -2591,6 +2607,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
93171 copy_user_highpage(dst, src, va, vma);
93172 }
93173
93174+#ifdef CONFIG_PAX_SEGMEXEC
93175+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
93176+{
93177+ struct mm_struct *mm = vma->vm_mm;
93178+ spinlock_t *ptl;
93179+ pte_t *pte, entry;
93180+
93181+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93182+ entry = *pte;
93183+ if (!pte_present(entry)) {
93184+ if (!pte_none(entry)) {
93185+ BUG_ON(pte_file(entry));
93186+ free_swap_and_cache(pte_to_swp_entry(entry));
93187+ pte_clear_not_present_full(mm, address, pte, 0);
93188+ }
93189+ } else {
93190+ struct page *page;
93191+
93192+ flush_cache_page(vma, address, pte_pfn(entry));
93193+ entry = ptep_clear_flush(vma, address, pte);
93194+ BUG_ON(pte_dirty(entry));
93195+ page = vm_normal_page(vma, address, entry);
93196+ if (page) {
93197+ update_hiwater_rss(mm);
93198+ if (PageAnon(page))
93199+ dec_mm_counter_fast(mm, MM_ANONPAGES);
93200+ else
93201+ dec_mm_counter_fast(mm, MM_FILEPAGES);
93202+ page_remove_rmap(page);
93203+ page_cache_release(page);
93204+ }
93205+ }
93206+ pte_unmap_unlock(pte, ptl);
93207+}
93208+
93209+/* PaX: if vma is mirrored, synchronize the mirror's PTE
93210+ *
93211+ * the ptl of the lower mapped page is held on entry and is not released on exit
93212+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
93213+ */
93214+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93215+{
93216+ struct mm_struct *mm = vma->vm_mm;
93217+ unsigned long address_m;
93218+ spinlock_t *ptl_m;
93219+ struct vm_area_struct *vma_m;
93220+ pmd_t *pmd_m;
93221+ pte_t *pte_m, entry_m;
93222+
93223+ BUG_ON(!page_m || !PageAnon(page_m));
93224+
93225+ vma_m = pax_find_mirror_vma(vma);
93226+ if (!vma_m)
93227+ return;
93228+
93229+ BUG_ON(!PageLocked(page_m));
93230+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93231+ address_m = address + SEGMEXEC_TASK_SIZE;
93232+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93233+ pte_m = pte_offset_map(pmd_m, address_m);
93234+ ptl_m = pte_lockptr(mm, pmd_m);
93235+ if (ptl != ptl_m) {
93236+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93237+ if (!pte_none(*pte_m))
93238+ goto out;
93239+ }
93240+
93241+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93242+ page_cache_get(page_m);
93243+ page_add_anon_rmap(page_m, vma_m, address_m);
93244+ inc_mm_counter_fast(mm, MM_ANONPAGES);
93245+ set_pte_at(mm, address_m, pte_m, entry_m);
93246+ update_mmu_cache(vma_m, address_m, pte_m);
93247+out:
93248+ if (ptl != ptl_m)
93249+ spin_unlock(ptl_m);
93250+ pte_unmap(pte_m);
93251+ unlock_page(page_m);
93252+}
93253+
93254+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93255+{
93256+ struct mm_struct *mm = vma->vm_mm;
93257+ unsigned long address_m;
93258+ spinlock_t *ptl_m;
93259+ struct vm_area_struct *vma_m;
93260+ pmd_t *pmd_m;
93261+ pte_t *pte_m, entry_m;
93262+
93263+ BUG_ON(!page_m || PageAnon(page_m));
93264+
93265+ vma_m = pax_find_mirror_vma(vma);
93266+ if (!vma_m)
93267+ return;
93268+
93269+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93270+ address_m = address + SEGMEXEC_TASK_SIZE;
93271+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93272+ pte_m = pte_offset_map(pmd_m, address_m);
93273+ ptl_m = pte_lockptr(mm, pmd_m);
93274+ if (ptl != ptl_m) {
93275+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93276+ if (!pte_none(*pte_m))
93277+ goto out;
93278+ }
93279+
93280+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93281+ page_cache_get(page_m);
93282+ page_add_file_rmap(page_m);
93283+ inc_mm_counter_fast(mm, MM_FILEPAGES);
93284+ set_pte_at(mm, address_m, pte_m, entry_m);
93285+ update_mmu_cache(vma_m, address_m, pte_m);
93286+out:
93287+ if (ptl != ptl_m)
93288+ spin_unlock(ptl_m);
93289+ pte_unmap(pte_m);
93290+}
93291+
93292+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93293+{
93294+ struct mm_struct *mm = vma->vm_mm;
93295+ unsigned long address_m;
93296+ spinlock_t *ptl_m;
93297+ struct vm_area_struct *vma_m;
93298+ pmd_t *pmd_m;
93299+ pte_t *pte_m, entry_m;
93300+
93301+ vma_m = pax_find_mirror_vma(vma);
93302+ if (!vma_m)
93303+ return;
93304+
93305+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93306+ address_m = address + SEGMEXEC_TASK_SIZE;
93307+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93308+ pte_m = pte_offset_map(pmd_m, address_m);
93309+ ptl_m = pte_lockptr(mm, pmd_m);
93310+ if (ptl != ptl_m) {
93311+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93312+ if (!pte_none(*pte_m))
93313+ goto out;
93314+ }
93315+
93316+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93317+ set_pte_at(mm, address_m, pte_m, entry_m);
93318+out:
93319+ if (ptl != ptl_m)
93320+ spin_unlock(ptl_m);
93321+ pte_unmap(pte_m);
93322+}
93323+
93324+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93325+{
93326+ struct page *page_m;
93327+ pte_t entry;
93328+
93329+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93330+ goto out;
93331+
93332+ entry = *pte;
93333+ page_m = vm_normal_page(vma, address, entry);
93334+ if (!page_m)
93335+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93336+ else if (PageAnon(page_m)) {
93337+ if (pax_find_mirror_vma(vma)) {
93338+ pte_unmap_unlock(pte, ptl);
93339+ lock_page(page_m);
93340+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93341+ if (pte_same(entry, *pte))
93342+ pax_mirror_anon_pte(vma, address, page_m, ptl);
93343+ else
93344+ unlock_page(page_m);
93345+ }
93346+ } else
93347+ pax_mirror_file_pte(vma, address, page_m, ptl);
93348+
93349+out:
93350+ pte_unmap_unlock(pte, ptl);
93351+}
93352+#endif
93353+
93354 /*
93355 * This routine handles present pages, when users try to write
93356 * to a shared page. It is done by copying the page to a new address
93357@@ -2815,6 +3011,12 @@ gotten:
93358 */
93359 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93360 if (likely(pte_same(*page_table, orig_pte))) {
93361+
93362+#ifdef CONFIG_PAX_SEGMEXEC
93363+ if (pax_find_mirror_vma(vma))
93364+ BUG_ON(!trylock_page(new_page));
93365+#endif
93366+
93367 if (old_page) {
93368 if (!PageAnon(old_page)) {
93369 dec_mm_counter_fast(mm, MM_FILEPAGES);
93370@@ -2866,6 +3068,10 @@ gotten:
93371 page_remove_rmap(old_page);
93372 }
93373
93374+#ifdef CONFIG_PAX_SEGMEXEC
93375+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93376+#endif
93377+
93378 /* Free the old page.. */
93379 new_page = old_page;
93380 ret |= VM_FAULT_WRITE;
93381@@ -3143,6 +3349,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93382 swap_free(entry);
93383 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93384 try_to_free_swap(page);
93385+
93386+#ifdef CONFIG_PAX_SEGMEXEC
93387+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93388+#endif
93389+
93390 unlock_page(page);
93391 if (page != swapcache) {
93392 /*
93393@@ -3166,6 +3377,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93394
93395 /* No need to invalidate - it was non-present before */
93396 update_mmu_cache(vma, address, page_table);
93397+
93398+#ifdef CONFIG_PAX_SEGMEXEC
93399+ pax_mirror_anon_pte(vma, address, page, ptl);
93400+#endif
93401+
93402 unlock:
93403 pte_unmap_unlock(page_table, ptl);
93404 out:
93405@@ -3185,40 +3401,6 @@ out_release:
93406 }
93407
93408 /*
93409- * This is like a special single-page "expand_{down|up}wards()",
93410- * except we must first make sure that 'address{-|+}PAGE_SIZE'
93411- * doesn't hit another vma.
93412- */
93413-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93414-{
93415- address &= PAGE_MASK;
93416- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93417- struct vm_area_struct *prev = vma->vm_prev;
93418-
93419- /*
93420- * Is there a mapping abutting this one below?
93421- *
93422- * That's only ok if it's the same stack mapping
93423- * that has gotten split..
93424- */
93425- if (prev && prev->vm_end == address)
93426- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93427-
93428- expand_downwards(vma, address - PAGE_SIZE);
93429- }
93430- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93431- struct vm_area_struct *next = vma->vm_next;
93432-
93433- /* As VM_GROWSDOWN but s/below/above/ */
93434- if (next && next->vm_start == address + PAGE_SIZE)
93435- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93436-
93437- expand_upwards(vma, address + PAGE_SIZE);
93438- }
93439- return 0;
93440-}
93441-
93442-/*
93443 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93444 * but allow concurrent faults), and pte mapped but not yet locked.
93445 * We return with mmap_sem still held, but pte unmapped and unlocked.
93446@@ -3227,27 +3409,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93447 unsigned long address, pte_t *page_table, pmd_t *pmd,
93448 unsigned int flags)
93449 {
93450- struct page *page;
93451+ struct page *page = NULL;
93452 spinlock_t *ptl;
93453 pte_t entry;
93454
93455- pte_unmap(page_table);
93456-
93457- /* Check if we need to add a guard page to the stack */
93458- if (check_stack_guard_page(vma, address) < 0)
93459- return VM_FAULT_SIGBUS;
93460-
93461- /* Use the zero-page for reads */
93462 if (!(flags & FAULT_FLAG_WRITE)) {
93463 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93464 vma->vm_page_prot));
93465- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93466+ ptl = pte_lockptr(mm, pmd);
93467+ spin_lock(ptl);
93468 if (!pte_none(*page_table))
93469 goto unlock;
93470 goto setpte;
93471 }
93472
93473 /* Allocate our own private page. */
93474+ pte_unmap(page_table);
93475+
93476 if (unlikely(anon_vma_prepare(vma)))
93477 goto oom;
93478 page = alloc_zeroed_user_highpage_movable(vma, address);
93479@@ -3271,6 +3449,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93480 if (!pte_none(*page_table))
93481 goto release;
93482
93483+#ifdef CONFIG_PAX_SEGMEXEC
93484+ if (pax_find_mirror_vma(vma))
93485+ BUG_ON(!trylock_page(page));
93486+#endif
93487+
93488 inc_mm_counter_fast(mm, MM_ANONPAGES);
93489 page_add_new_anon_rmap(page, vma, address);
93490 setpte:
93491@@ -3278,6 +3461,12 @@ setpte:
93492
93493 /* No need to invalidate - it was non-present before */
93494 update_mmu_cache(vma, address, page_table);
93495+
93496+#ifdef CONFIG_PAX_SEGMEXEC
93497+ if (page)
93498+ pax_mirror_anon_pte(vma, address, page, ptl);
93499+#endif
93500+
93501 unlock:
93502 pte_unmap_unlock(page_table, ptl);
93503 return 0;
93504@@ -3422,6 +3611,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93505 */
93506 /* Only go through if we didn't race with anybody else... */
93507 if (likely(pte_same(*page_table, orig_pte))) {
93508+
93509+#ifdef CONFIG_PAX_SEGMEXEC
93510+ if (anon && pax_find_mirror_vma(vma))
93511+ BUG_ON(!trylock_page(page));
93512+#endif
93513+
93514 flush_icache_page(vma, page);
93515 entry = mk_pte(page, vma->vm_page_prot);
93516 if (flags & FAULT_FLAG_WRITE)
93517@@ -3443,6 +3638,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93518
93519 /* no need to invalidate: a not-present page won't be cached */
93520 update_mmu_cache(vma, address, page_table);
93521+
93522+#ifdef CONFIG_PAX_SEGMEXEC
93523+ if (anon)
93524+ pax_mirror_anon_pte(vma, address, page, ptl);
93525+ else
93526+ pax_mirror_file_pte(vma, address, page, ptl);
93527+#endif
93528+
93529 } else {
93530 if (cow_page)
93531 mem_cgroup_uncharge_page(cow_page);
93532@@ -3690,6 +3893,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93533 if (flags & FAULT_FLAG_WRITE)
93534 flush_tlb_fix_spurious_fault(vma, address);
93535 }
93536+
93537+#ifdef CONFIG_PAX_SEGMEXEC
93538+ pax_mirror_pte(vma, address, pte, pmd, ptl);
93539+ return 0;
93540+#endif
93541+
93542 unlock:
93543 pte_unmap_unlock(pte, ptl);
93544 return 0;
93545@@ -3706,9 +3915,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93546 pmd_t *pmd;
93547 pte_t *pte;
93548
93549+#ifdef CONFIG_PAX_SEGMEXEC
93550+ struct vm_area_struct *vma_m;
93551+#endif
93552+
93553 if (unlikely(is_vm_hugetlb_page(vma)))
93554 return hugetlb_fault(mm, vma, address, flags);
93555
93556+#ifdef CONFIG_PAX_SEGMEXEC
93557+ vma_m = pax_find_mirror_vma(vma);
93558+ if (vma_m) {
93559+ unsigned long address_m;
93560+ pgd_t *pgd_m;
93561+ pud_t *pud_m;
93562+ pmd_t *pmd_m;
93563+
93564+ if (vma->vm_start > vma_m->vm_start) {
93565+ address_m = address;
93566+ address -= SEGMEXEC_TASK_SIZE;
93567+ vma = vma_m;
93568+ } else
93569+ address_m = address + SEGMEXEC_TASK_SIZE;
93570+
93571+ pgd_m = pgd_offset(mm, address_m);
93572+ pud_m = pud_alloc(mm, pgd_m, address_m);
93573+ if (!pud_m)
93574+ return VM_FAULT_OOM;
93575+ pmd_m = pmd_alloc(mm, pud_m, address_m);
93576+ if (!pmd_m)
93577+ return VM_FAULT_OOM;
93578+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93579+ return VM_FAULT_OOM;
93580+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93581+ }
93582+#endif
93583+
93584 pgd = pgd_offset(mm, address);
93585 pud = pud_alloc(mm, pgd, address);
93586 if (!pud)
93587@@ -3839,6 +4080,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93588 spin_unlock(&mm->page_table_lock);
93589 return 0;
93590 }
93591+
93592+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93593+{
93594+ pud_t *new = pud_alloc_one(mm, address);
93595+ if (!new)
93596+ return -ENOMEM;
93597+
93598+ smp_wmb(); /* See comment in __pte_alloc */
93599+
93600+ spin_lock(&mm->page_table_lock);
93601+ if (pgd_present(*pgd)) /* Another has populated it */
93602+ pud_free(mm, new);
93603+ else
93604+ pgd_populate_kernel(mm, pgd, new);
93605+ spin_unlock(&mm->page_table_lock);
93606+ return 0;
93607+}
93608 #endif /* __PAGETABLE_PUD_FOLDED */
93609
93610 #ifndef __PAGETABLE_PMD_FOLDED
93611@@ -3869,6 +4127,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93612 spin_unlock(&mm->page_table_lock);
93613 return 0;
93614 }
93615+
93616+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93617+{
93618+ pmd_t *new = pmd_alloc_one(mm, address);
93619+ if (!new)
93620+ return -ENOMEM;
93621+
93622+ smp_wmb(); /* See comment in __pte_alloc */
93623+
93624+ spin_lock(&mm->page_table_lock);
93625+#ifndef __ARCH_HAS_4LEVEL_HACK
93626+ if (pud_present(*pud)) /* Another has populated it */
93627+ pmd_free(mm, new);
93628+ else
93629+ pud_populate_kernel(mm, pud, new);
93630+#else
93631+ if (pgd_present(*pud)) /* Another has populated it */
93632+ pmd_free(mm, new);
93633+ else
93634+ pgd_populate_kernel(mm, pud, new);
93635+#endif /* __ARCH_HAS_4LEVEL_HACK */
93636+ spin_unlock(&mm->page_table_lock);
93637+ return 0;
93638+}
93639 #endif /* __PAGETABLE_PMD_FOLDED */
93640
93641 #if !defined(__HAVE_ARCH_GATE_AREA)
93642@@ -3882,7 +4164,7 @@ static int __init gate_vma_init(void)
93643 gate_vma.vm_start = FIXADDR_USER_START;
93644 gate_vma.vm_end = FIXADDR_USER_END;
93645 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93646- gate_vma.vm_page_prot = __P101;
93647+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93648
93649 return 0;
93650 }
93651@@ -4016,8 +4298,8 @@ out:
93652 return ret;
93653 }
93654
93655-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93656- void *buf, int len, int write)
93657+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93658+ void *buf, size_t len, int write)
93659 {
93660 resource_size_t phys_addr;
93661 unsigned long prot = 0;
93662@@ -4043,8 +4325,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93663 * Access another process' address space as given in mm. If non-NULL, use the
93664 * given task for page fault accounting.
93665 */
93666-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93667- unsigned long addr, void *buf, int len, int write)
93668+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93669+ unsigned long addr, void *buf, size_t len, int write)
93670 {
93671 struct vm_area_struct *vma;
93672 void *old_buf = buf;
93673@@ -4052,7 +4334,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93674 down_read(&mm->mmap_sem);
93675 /* ignore errors, just check how much was successfully transferred */
93676 while (len) {
93677- int bytes, ret, offset;
93678+ ssize_t bytes, ret, offset;
93679 void *maddr;
93680 struct page *page = NULL;
93681
93682@@ -4111,8 +4393,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93683 *
93684 * The caller must hold a reference on @mm.
93685 */
93686-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93687- void *buf, int len, int write)
93688+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93689+ void *buf, size_t len, int write)
93690 {
93691 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93692 }
93693@@ -4122,11 +4404,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93694 * Source/target buffer must be kernel space,
93695 * Do not walk the page table directly, use get_user_pages
93696 */
93697-int access_process_vm(struct task_struct *tsk, unsigned long addr,
93698- void *buf, int len, int write)
93699+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93700+ void *buf, size_t len, int write)
93701 {
93702 struct mm_struct *mm;
93703- int ret;
93704+ ssize_t ret;
93705
93706 mm = get_task_mm(tsk);
93707 if (!mm)
93708diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93709index 56224d9..a74c77e 100644
93710--- a/mm/mempolicy.c
93711+++ b/mm/mempolicy.c
93712@@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93713 unsigned long vmstart;
93714 unsigned long vmend;
93715
93716+#ifdef CONFIG_PAX_SEGMEXEC
93717+ struct vm_area_struct *vma_m;
93718+#endif
93719+
93720 vma = find_vma(mm, start);
93721 if (!vma || vma->vm_start > start)
93722 return -EFAULT;
93723@@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93724 err = vma_replace_policy(vma, new_pol);
93725 if (err)
93726 goto out;
93727+
93728+#ifdef CONFIG_PAX_SEGMEXEC
93729+ vma_m = pax_find_mirror_vma(vma);
93730+ if (vma_m) {
93731+ err = vma_replace_policy(vma_m, new_pol);
93732+ if (err)
93733+ goto out;
93734+ }
93735+#endif
93736+
93737 }
93738
93739 out:
93740@@ -1256,6 +1270,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93741
93742 if (end < start)
93743 return -EINVAL;
93744+
93745+#ifdef CONFIG_PAX_SEGMEXEC
93746+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93747+ if (end > SEGMEXEC_TASK_SIZE)
93748+ return -EINVAL;
93749+ } else
93750+#endif
93751+
93752+ if (end > TASK_SIZE)
93753+ return -EINVAL;
93754+
93755 if (end == start)
93756 return 0;
93757
93758@@ -1484,8 +1509,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93759 */
93760 tcred = __task_cred(task);
93761 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93762- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93763- !capable(CAP_SYS_NICE)) {
93764+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93765 rcu_read_unlock();
93766 err = -EPERM;
93767 goto out_put;
93768@@ -1516,6 +1540,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93769 goto out;
93770 }
93771
93772+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93773+ if (mm != current->mm &&
93774+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93775+ mmput(mm);
93776+ err = -EPERM;
93777+ goto out;
93778+ }
93779+#endif
93780+
93781 err = do_migrate_pages(mm, old, new,
93782 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93783
93784diff --git a/mm/migrate.c b/mm/migrate.c
93785index bed4880..a493f67 100644
93786--- a/mm/migrate.c
93787+++ b/mm/migrate.c
93788@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93789 */
93790 tcred = __task_cred(task);
93791 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93792- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93793- !capable(CAP_SYS_NICE)) {
93794+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93795 rcu_read_unlock();
93796 err = -EPERM;
93797 goto out;
93798diff --git a/mm/mlock.c b/mm/mlock.c
93799index b1eb536..091d154 100644
93800--- a/mm/mlock.c
93801+++ b/mm/mlock.c
93802@@ -14,6 +14,7 @@
93803 #include <linux/pagevec.h>
93804 #include <linux/mempolicy.h>
93805 #include <linux/syscalls.h>
93806+#include <linux/security.h>
93807 #include <linux/sched.h>
93808 #include <linux/export.h>
93809 #include <linux/rmap.h>
93810@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93811 {
93812 unsigned long nstart, end, tmp;
93813 struct vm_area_struct * vma, * prev;
93814- int error;
93815+ int error = 0;
93816
93817 VM_BUG_ON(start & ~PAGE_MASK);
93818 VM_BUG_ON(len != PAGE_ALIGN(len));
93819@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93820 return -EINVAL;
93821 if (end == start)
93822 return 0;
93823+ if (end > TASK_SIZE)
93824+ return -EINVAL;
93825+
93826 vma = find_vma(current->mm, start);
93827 if (!vma || vma->vm_start > start)
93828 return -ENOMEM;
93829@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93830 for (nstart = start ; ; ) {
93831 vm_flags_t newflags;
93832
93833+#ifdef CONFIG_PAX_SEGMEXEC
93834+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93835+ break;
93836+#endif
93837+
93838 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93839
93840 newflags = vma->vm_flags & ~VM_LOCKED;
93841@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93842 locked += current->mm->locked_vm;
93843
93844 /* check against resource limits */
93845+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93846 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93847 error = do_mlock(start, len, 1);
93848
93849@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93850 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93851 vm_flags_t newflags;
93852
93853+#ifdef CONFIG_PAX_SEGMEXEC
93854+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93855+ break;
93856+#endif
93857+
93858 newflags = vma->vm_flags & ~VM_LOCKED;
93859 if (flags & MCL_CURRENT)
93860 newflags |= VM_LOCKED;
93861@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93862 lock_limit >>= PAGE_SHIFT;
93863
93864 ret = -ENOMEM;
93865+
93866+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93867+
93868 down_write(&current->mm->mmap_sem);
93869-
93870 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93871 capable(CAP_IPC_LOCK))
93872 ret = do_mlockall(flags);
93873diff --git a/mm/mmap.c b/mm/mmap.c
93874index 20ff0c3..a9eda98 100644
93875--- a/mm/mmap.c
93876+++ b/mm/mmap.c
93877@@ -36,6 +36,7 @@
93878 #include <linux/sched/sysctl.h>
93879 #include <linux/notifier.h>
93880 #include <linux/memory.h>
93881+#include <linux/random.h>
93882
93883 #include <asm/uaccess.h>
93884 #include <asm/cacheflush.h>
93885@@ -52,6 +53,16 @@
93886 #define arch_rebalance_pgtables(addr, len) (addr)
93887 #endif
93888
93889+static inline void verify_mm_writelocked(struct mm_struct *mm)
93890+{
93891+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93892+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93893+ up_read(&mm->mmap_sem);
93894+ BUG();
93895+ }
93896+#endif
93897+}
93898+
93899 static void unmap_region(struct mm_struct *mm,
93900 struct vm_area_struct *vma, struct vm_area_struct *prev,
93901 unsigned long start, unsigned long end);
93902@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
93903 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93904 *
93905 */
93906-pgprot_t protection_map[16] = {
93907+pgprot_t protection_map[16] __read_only = {
93908 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93909 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93910 };
93911
93912-pgprot_t vm_get_page_prot(unsigned long vm_flags)
93913+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93914 {
93915- return __pgprot(pgprot_val(protection_map[vm_flags &
93916+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93917 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93918 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93919+
93920+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93921+ if (!(__supported_pte_mask & _PAGE_NX) &&
93922+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93923+ (vm_flags & (VM_READ | VM_WRITE)))
93924+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93925+#endif
93926+
93927+ return prot;
93928 }
93929 EXPORT_SYMBOL(vm_get_page_prot);
93930
93931@@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93932 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93933 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93934 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93935+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93936 /*
93937 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93938 * other variables. It can be updated by several CPUs frequently.
93939@@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93940 struct vm_area_struct *next = vma->vm_next;
93941
93942 might_sleep();
93943+ BUG_ON(vma->vm_mirror);
93944 if (vma->vm_ops && vma->vm_ops->close)
93945 vma->vm_ops->close(vma);
93946 if (vma->vm_file)
93947@@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93948 * not page aligned -Ram Gupta
93949 */
93950 rlim = rlimit(RLIMIT_DATA);
93951+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93952 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93953 (mm->end_data - mm->start_data) > rlim)
93954 goto out;
93955@@ -940,6 +963,12 @@ static int
93956 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93957 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93958 {
93959+
93960+#ifdef CONFIG_PAX_SEGMEXEC
93961+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93962+ return 0;
93963+#endif
93964+
93965 if (is_mergeable_vma(vma, file, vm_flags) &&
93966 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93967 if (vma->vm_pgoff == vm_pgoff)
93968@@ -959,6 +988,12 @@ static int
93969 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93970 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93971 {
93972+
93973+#ifdef CONFIG_PAX_SEGMEXEC
93974+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93975+ return 0;
93976+#endif
93977+
93978 if (is_mergeable_vma(vma, file, vm_flags) &&
93979 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93980 pgoff_t vm_pglen;
93981@@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93982 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93983 struct vm_area_struct *prev, unsigned long addr,
93984 unsigned long end, unsigned long vm_flags,
93985- struct anon_vma *anon_vma, struct file *file,
93986+ struct anon_vma *anon_vma, struct file *file,
93987 pgoff_t pgoff, struct mempolicy *policy)
93988 {
93989 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93990 struct vm_area_struct *area, *next;
93991 int err;
93992
93993+#ifdef CONFIG_PAX_SEGMEXEC
93994+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93995+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93996+
93997+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93998+#endif
93999+
94000 /*
94001 * We later require that vma->vm_flags == vm_flags,
94002 * so this tests vma->vm_flags & VM_SPECIAL, too.
94003@@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94004 if (next && next->vm_end == end) /* cases 6, 7, 8 */
94005 next = next->vm_next;
94006
94007+#ifdef CONFIG_PAX_SEGMEXEC
94008+ if (prev)
94009+ prev_m = pax_find_mirror_vma(prev);
94010+ if (area)
94011+ area_m = pax_find_mirror_vma(area);
94012+ if (next)
94013+ next_m = pax_find_mirror_vma(next);
94014+#endif
94015+
94016 /*
94017 * Can it merge with the predecessor?
94018 */
94019@@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94020 /* cases 1, 6 */
94021 err = vma_adjust(prev, prev->vm_start,
94022 next->vm_end, prev->vm_pgoff, NULL);
94023- } else /* cases 2, 5, 7 */
94024+
94025+#ifdef CONFIG_PAX_SEGMEXEC
94026+ if (!err && prev_m)
94027+ err = vma_adjust(prev_m, prev_m->vm_start,
94028+ next_m->vm_end, prev_m->vm_pgoff, NULL);
94029+#endif
94030+
94031+ } else { /* cases 2, 5, 7 */
94032 err = vma_adjust(prev, prev->vm_start,
94033 end, prev->vm_pgoff, NULL);
94034+
94035+#ifdef CONFIG_PAX_SEGMEXEC
94036+ if (!err && prev_m)
94037+ err = vma_adjust(prev_m, prev_m->vm_start,
94038+ end_m, prev_m->vm_pgoff, NULL);
94039+#endif
94040+
94041+ }
94042 if (err)
94043 return NULL;
94044 khugepaged_enter_vma_merge(prev);
94045@@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94046 mpol_equal(policy, vma_policy(next)) &&
94047 can_vma_merge_before(next, vm_flags,
94048 anon_vma, file, pgoff+pglen)) {
94049- if (prev && addr < prev->vm_end) /* case 4 */
94050+ if (prev && addr < prev->vm_end) { /* case 4 */
94051 err = vma_adjust(prev, prev->vm_start,
94052 addr, prev->vm_pgoff, NULL);
94053- else /* cases 3, 8 */
94054+
94055+#ifdef CONFIG_PAX_SEGMEXEC
94056+ if (!err && prev_m)
94057+ err = vma_adjust(prev_m, prev_m->vm_start,
94058+ addr_m, prev_m->vm_pgoff, NULL);
94059+#endif
94060+
94061+ } else { /* cases 3, 8 */
94062 err = vma_adjust(area, addr, next->vm_end,
94063 next->vm_pgoff - pglen, NULL);
94064+
94065+#ifdef CONFIG_PAX_SEGMEXEC
94066+ if (!err && area_m)
94067+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
94068+ next_m->vm_pgoff - pglen, NULL);
94069+#endif
94070+
94071+ }
94072 if (err)
94073 return NULL;
94074 khugepaged_enter_vma_merge(area);
94075@@ -1172,8 +1253,10 @@ none:
94076 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
94077 struct file *file, long pages)
94078 {
94079- const unsigned long stack_flags
94080- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
94081+
94082+#ifdef CONFIG_PAX_RANDMMAP
94083+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94084+#endif
94085
94086 mm->total_vm += pages;
94087
94088@@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
94089 mm->shared_vm += pages;
94090 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
94091 mm->exec_vm += pages;
94092- } else if (flags & stack_flags)
94093+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
94094 mm->stack_vm += pages;
94095 }
94096 #endif /* CONFIG_PROC_FS */
94097@@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
94098 locked += mm->locked_vm;
94099 lock_limit = rlimit(RLIMIT_MEMLOCK);
94100 lock_limit >>= PAGE_SHIFT;
94101+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94102 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
94103 return -EAGAIN;
94104 }
94105@@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94106 * (the exception is when the underlying filesystem is noexec
94107 * mounted, in which case we dont add PROT_EXEC.)
94108 */
94109- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94110+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94111 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
94112 prot |= PROT_EXEC;
94113
94114@@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94115 /* Obtain the address to map to. we verify (or select) it and ensure
94116 * that it represents a valid section of the address space.
94117 */
94118- addr = get_unmapped_area(file, addr, len, pgoff, flags);
94119+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
94120 if (addr & ~PAGE_MASK)
94121 return addr;
94122
94123@@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94124 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
94125 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
94126
94127+#ifdef CONFIG_PAX_MPROTECT
94128+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94129+
94130+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
94131+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
94132+ mm->binfmt->handle_mmap)
94133+ mm->binfmt->handle_mmap(file);
94134+#endif
94135+
94136+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94137+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
94138+ gr_log_rwxmmap(file);
94139+
94140+#ifdef CONFIG_PAX_EMUPLT
94141+ vm_flags &= ~VM_EXEC;
94142+#else
94143+ return -EPERM;
94144+#endif
94145+
94146+ }
94147+
94148+ if (!(vm_flags & VM_EXEC))
94149+ vm_flags &= ~VM_MAYEXEC;
94150+#else
94151+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94152+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94153+#endif
94154+ else
94155+ vm_flags &= ~VM_MAYWRITE;
94156+ }
94157+#endif
94158+
94159+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94160+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
94161+ vm_flags &= ~VM_PAGEEXEC;
94162+#endif
94163+
94164 if (flags & MAP_LOCKED)
94165 if (!can_do_mlock())
94166 return -EPERM;
94167@@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94168 vm_flags |= VM_NORESERVE;
94169 }
94170
94171+ if (!gr_acl_handle_mmap(file, prot))
94172+ return -EACCES;
94173+
94174 addr = mmap_region(file, addr, len, vm_flags, pgoff);
94175 if (!IS_ERR_VALUE(addr) &&
94176 ((vm_flags & VM_LOCKED) ||
94177@@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
94178 vm_flags_t vm_flags = vma->vm_flags;
94179
94180 /* If it was private or non-writable, the write bit is already clear */
94181- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
94182+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
94183 return 0;
94184
94185 /* The backer wishes to know when pages are first written to? */
94186@@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94187 struct rb_node **rb_link, *rb_parent;
94188 unsigned long charged = 0;
94189
94190+#ifdef CONFIG_PAX_SEGMEXEC
94191+ struct vm_area_struct *vma_m = NULL;
94192+#endif
94193+
94194+ /*
94195+ * mm->mmap_sem is required to protect against another thread
94196+ * changing the mappings in case we sleep.
94197+ */
94198+ verify_mm_writelocked(mm);
94199+
94200 /* Check against address space limit. */
94201+
94202+#ifdef CONFIG_PAX_RANDMMAP
94203+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94204+#endif
94205+
94206 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
94207 unsigned long nr_pages;
94208
94209@@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94210
94211 /* Clear old maps */
94212 error = -ENOMEM;
94213-munmap_back:
94214 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94215 if (do_munmap(mm, addr, len))
94216 return -ENOMEM;
94217- goto munmap_back;
94218+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94219 }
94220
94221 /*
94222@@ -1554,6 +1692,16 @@ munmap_back:
94223 goto unacct_error;
94224 }
94225
94226+#ifdef CONFIG_PAX_SEGMEXEC
94227+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
94228+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94229+ if (!vma_m) {
94230+ error = -ENOMEM;
94231+ goto free_vma;
94232+ }
94233+ }
94234+#endif
94235+
94236 vma->vm_mm = mm;
94237 vma->vm_start = addr;
94238 vma->vm_end = addr + len;
94239@@ -1573,6 +1721,13 @@ munmap_back:
94240 if (error)
94241 goto unmap_and_free_vma;
94242
94243+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94244+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
94245+ vma->vm_flags |= VM_PAGEEXEC;
94246+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94247+ }
94248+#endif
94249+
94250 /* Can addr have changed??
94251 *
94252 * Answer: Yes, several device drivers can do it in their
94253@@ -1606,6 +1761,12 @@ munmap_back:
94254 }
94255
94256 vma_link(mm, vma, prev, rb_link, rb_parent);
94257+
94258+#ifdef CONFIG_PAX_SEGMEXEC
94259+ if (vma_m)
94260+ BUG_ON(pax_mirror_vma(vma_m, vma));
94261+#endif
94262+
94263 /* Once vma denies write, undo our temporary denial count */
94264 if (vm_flags & VM_DENYWRITE)
94265 allow_write_access(file);
94266@@ -1614,6 +1775,7 @@ out:
94267 perf_event_mmap(vma);
94268
94269 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
94270+ track_exec_limit(mm, addr, addr + len, vm_flags);
94271 if (vm_flags & VM_LOCKED) {
94272 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94273 vma == get_gate_vma(current->mm)))
94274@@ -1646,6 +1808,12 @@ unmap_and_free_vma:
94275 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94276 charged = 0;
94277 free_vma:
94278+
94279+#ifdef CONFIG_PAX_SEGMEXEC
94280+ if (vma_m)
94281+ kmem_cache_free(vm_area_cachep, vma_m);
94282+#endif
94283+
94284 kmem_cache_free(vm_area_cachep, vma);
94285 unacct_error:
94286 if (charged)
94287@@ -1653,7 +1821,63 @@ unacct_error:
94288 return error;
94289 }
94290
94291-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94292+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94293+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94294+{
94295+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94296+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94297+
94298+ return 0;
94299+}
94300+#endif
94301+
94302+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94303+{
94304+ if (!vma) {
94305+#ifdef CONFIG_STACK_GROWSUP
94306+ if (addr > sysctl_heap_stack_gap)
94307+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94308+ else
94309+ vma = find_vma(current->mm, 0);
94310+ if (vma && (vma->vm_flags & VM_GROWSUP))
94311+ return false;
94312+#endif
94313+ return true;
94314+ }
94315+
94316+ if (addr + len > vma->vm_start)
94317+ return false;
94318+
94319+ if (vma->vm_flags & VM_GROWSDOWN)
94320+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94321+#ifdef CONFIG_STACK_GROWSUP
94322+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94323+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94324+#endif
94325+ else if (offset)
94326+ return offset <= vma->vm_start - addr - len;
94327+
94328+ return true;
94329+}
94330+
94331+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94332+{
94333+ if (vma->vm_start < len)
94334+ return -ENOMEM;
94335+
94336+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
94337+ if (offset <= vma->vm_start - len)
94338+ return vma->vm_start - len - offset;
94339+ else
94340+ return -ENOMEM;
94341+ }
94342+
94343+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
94344+ return vma->vm_start - len - sysctl_heap_stack_gap;
94345+ return -ENOMEM;
94346+}
94347+
94348+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94349 {
94350 /*
94351 * We implement the search by looking for an rbtree node that
94352@@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94353 }
94354 }
94355
94356- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94357+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94358 check_current:
94359 /* Check if current node has a suitable gap */
94360 if (gap_start > high_limit)
94361 return -ENOMEM;
94362+
94363+ if (gap_end - gap_start > info->threadstack_offset)
94364+ gap_start += info->threadstack_offset;
94365+ else
94366+ gap_start = gap_end;
94367+
94368+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94369+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94370+ gap_start += sysctl_heap_stack_gap;
94371+ else
94372+ gap_start = gap_end;
94373+ }
94374+ if (vma->vm_flags & VM_GROWSDOWN) {
94375+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94376+ gap_end -= sysctl_heap_stack_gap;
94377+ else
94378+ gap_end = gap_start;
94379+ }
94380 if (gap_end >= low_limit && gap_end - gap_start >= length)
94381 goto found;
94382
94383@@ -1755,7 +1997,7 @@ found:
94384 return gap_start;
94385 }
94386
94387-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94388+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94389 {
94390 struct mm_struct *mm = current->mm;
94391 struct vm_area_struct *vma;
94392@@ -1809,6 +2051,24 @@ check_current:
94393 gap_end = vma->vm_start;
94394 if (gap_end < low_limit)
94395 return -ENOMEM;
94396+
94397+ if (gap_end - gap_start > info->threadstack_offset)
94398+ gap_end -= info->threadstack_offset;
94399+ else
94400+ gap_end = gap_start;
94401+
94402+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94403+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94404+ gap_start += sysctl_heap_stack_gap;
94405+ else
94406+ gap_start = gap_end;
94407+ }
94408+ if (vma->vm_flags & VM_GROWSDOWN) {
94409+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94410+ gap_end -= sysctl_heap_stack_gap;
94411+ else
94412+ gap_end = gap_start;
94413+ }
94414 if (gap_start <= high_limit && gap_end - gap_start >= length)
94415 goto found;
94416
94417@@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94418 struct mm_struct *mm = current->mm;
94419 struct vm_area_struct *vma;
94420 struct vm_unmapped_area_info info;
94421+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94422
94423 if (len > TASK_SIZE - mmap_min_addr)
94424 return -ENOMEM;
94425@@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94426 if (flags & MAP_FIXED)
94427 return addr;
94428
94429+#ifdef CONFIG_PAX_RANDMMAP
94430+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94431+#endif
94432+
94433 if (addr) {
94434 addr = PAGE_ALIGN(addr);
94435 vma = find_vma(mm, addr);
94436 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94437- (!vma || addr + len <= vma->vm_start))
94438+ check_heap_stack_gap(vma, addr, len, offset))
94439 return addr;
94440 }
94441
94442@@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94443 info.low_limit = mm->mmap_base;
94444 info.high_limit = TASK_SIZE;
94445 info.align_mask = 0;
94446+ info.threadstack_offset = offset;
94447 return vm_unmapped_area(&info);
94448 }
94449 #endif
94450@@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94451 struct mm_struct *mm = current->mm;
94452 unsigned long addr = addr0;
94453 struct vm_unmapped_area_info info;
94454+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94455
94456 /* requested length too big for entire address space */
94457 if (len > TASK_SIZE - mmap_min_addr)
94458@@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94459 if (flags & MAP_FIXED)
94460 return addr;
94461
94462+#ifdef CONFIG_PAX_RANDMMAP
94463+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94464+#endif
94465+
94466 /* requesting a specific address */
94467 if (addr) {
94468 addr = PAGE_ALIGN(addr);
94469 vma = find_vma(mm, addr);
94470 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94471- (!vma || addr + len <= vma->vm_start))
94472+ check_heap_stack_gap(vma, addr, len, offset))
94473 return addr;
94474 }
94475
94476@@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94477 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94478 info.high_limit = mm->mmap_base;
94479 info.align_mask = 0;
94480+ info.threadstack_offset = offset;
94481 addr = vm_unmapped_area(&info);
94482
94483 /*
94484@@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94485 VM_BUG_ON(addr != -ENOMEM);
94486 info.flags = 0;
94487 info.low_limit = TASK_UNMAPPED_BASE;
94488+
94489+#ifdef CONFIG_PAX_RANDMMAP
94490+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94491+ info.low_limit += mm->delta_mmap;
94492+#endif
94493+
94494 info.high_limit = TASK_SIZE;
94495 addr = vm_unmapped_area(&info);
94496 }
94497@@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94498 return vma;
94499 }
94500
94501+#ifdef CONFIG_PAX_SEGMEXEC
94502+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94503+{
94504+ struct vm_area_struct *vma_m;
94505+
94506+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94507+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94508+ BUG_ON(vma->vm_mirror);
94509+ return NULL;
94510+ }
94511+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94512+ vma_m = vma->vm_mirror;
94513+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94514+ BUG_ON(vma->vm_file != vma_m->vm_file);
94515+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94516+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94517+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94518+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94519+ return vma_m;
94520+}
94521+#endif
94522+
94523 /*
94524 * Verify that the stack growth is acceptable and
94525 * update accounting. This is shared with both the
94526@@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94527 return -ENOMEM;
94528
94529 /* Stack limit test */
94530+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
94531 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94532 return -ENOMEM;
94533
94534@@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94535 locked = mm->locked_vm + grow;
94536 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94537 limit >>= PAGE_SHIFT;
94538+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94539 if (locked > limit && !capable(CAP_IPC_LOCK))
94540 return -ENOMEM;
94541 }
94542@@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94543 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94544 * vma is the last one with address > vma->vm_end. Have to extend vma.
94545 */
94546+#ifndef CONFIG_IA64
94547+static
94548+#endif
94549 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94550 {
94551 int error;
94552+ bool locknext;
94553
94554 if (!(vma->vm_flags & VM_GROWSUP))
94555 return -EFAULT;
94556
94557+ /* Also guard against wrapping around to address 0. */
94558+ if (address < PAGE_ALIGN(address+1))
94559+ address = PAGE_ALIGN(address+1);
94560+ else
94561+ return -ENOMEM;
94562+
94563 /*
94564 * We must make sure the anon_vma is allocated
94565 * so that the anon_vma locking is not a noop.
94566 */
94567 if (unlikely(anon_vma_prepare(vma)))
94568 return -ENOMEM;
94569+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94570+ if (locknext && anon_vma_prepare(vma->vm_next))
94571+ return -ENOMEM;
94572 vma_lock_anon_vma(vma);
94573+ if (locknext)
94574+ vma_lock_anon_vma(vma->vm_next);
94575
94576 /*
94577 * vma->vm_start/vm_end cannot change under us because the caller
94578 * is required to hold the mmap_sem in read mode. We need the
94579- * anon_vma lock to serialize against concurrent expand_stacks.
94580- * Also guard against wrapping around to address 0.
94581+ * anon_vma locks to serialize against concurrent expand_stacks
94582+ * and expand_upwards.
94583 */
94584- if (address < PAGE_ALIGN(address+4))
94585- address = PAGE_ALIGN(address+4);
94586- else {
94587- vma_unlock_anon_vma(vma);
94588- return -ENOMEM;
94589- }
94590 error = 0;
94591
94592 /* Somebody else might have raced and expanded it already */
94593- if (address > vma->vm_end) {
94594+ 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)
94595+ error = -ENOMEM;
94596+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94597 unsigned long size, grow;
94598
94599 size = address - vma->vm_start;
94600@@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94601 }
94602 }
94603 }
94604+ if (locknext)
94605+ vma_unlock_anon_vma(vma->vm_next);
94606 vma_unlock_anon_vma(vma);
94607 khugepaged_enter_vma_merge(vma);
94608 validate_mm(vma->vm_mm);
94609@@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
94610 unsigned long address)
94611 {
94612 int error;
94613+ bool lockprev = false;
94614+ struct vm_area_struct *prev;
94615
94616 /*
94617 * We must make sure the anon_vma is allocated
94618@@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
94619 if (error)
94620 return error;
94621
94622+ prev = vma->vm_prev;
94623+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94624+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94625+#endif
94626+ if (lockprev && anon_vma_prepare(prev))
94627+ return -ENOMEM;
94628+ if (lockprev)
94629+ vma_lock_anon_vma(prev);
94630+
94631 vma_lock_anon_vma(vma);
94632
94633 /*
94634@@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
94635 */
94636
94637 /* Somebody else might have raced and expanded it already */
94638- if (address < vma->vm_start) {
94639+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94640+ error = -ENOMEM;
94641+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94642 unsigned long size, grow;
94643
94644+#ifdef CONFIG_PAX_SEGMEXEC
94645+ struct vm_area_struct *vma_m;
94646+
94647+ vma_m = pax_find_mirror_vma(vma);
94648+#endif
94649+
94650 size = vma->vm_end - address;
94651 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94652
94653@@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
94654 vma->vm_pgoff -= grow;
94655 anon_vma_interval_tree_post_update_vma(vma);
94656 vma_gap_update(vma);
94657+
94658+#ifdef CONFIG_PAX_SEGMEXEC
94659+ if (vma_m) {
94660+ anon_vma_interval_tree_pre_update_vma(vma_m);
94661+ vma_m->vm_start -= grow << PAGE_SHIFT;
94662+ vma_m->vm_pgoff -= grow;
94663+ anon_vma_interval_tree_post_update_vma(vma_m);
94664+ vma_gap_update(vma_m);
94665+ }
94666+#endif
94667+
94668 spin_unlock(&vma->vm_mm->page_table_lock);
94669
94670+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94671 perf_event_mmap(vma);
94672 }
94673 }
94674 }
94675 vma_unlock_anon_vma(vma);
94676+ if (lockprev)
94677+ vma_unlock_anon_vma(prev);
94678 khugepaged_enter_vma_merge(vma);
94679 validate_mm(vma->vm_mm);
94680 return error;
94681@@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94682 do {
94683 long nrpages = vma_pages(vma);
94684
94685+#ifdef CONFIG_PAX_SEGMEXEC
94686+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94687+ vma = remove_vma(vma);
94688+ continue;
94689+ }
94690+#endif
94691+
94692 if (vma->vm_flags & VM_ACCOUNT)
94693 nr_accounted += nrpages;
94694 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94695@@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94696 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94697 vma->vm_prev = NULL;
94698 do {
94699+
94700+#ifdef CONFIG_PAX_SEGMEXEC
94701+ if (vma->vm_mirror) {
94702+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94703+ vma->vm_mirror->vm_mirror = NULL;
94704+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
94705+ vma->vm_mirror = NULL;
94706+ }
94707+#endif
94708+
94709 vma_rb_erase(vma, &mm->mm_rb);
94710 mm->map_count--;
94711 tail_vma = vma;
94712@@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94713 struct vm_area_struct *new;
94714 int err = -ENOMEM;
94715
94716+#ifdef CONFIG_PAX_SEGMEXEC
94717+ struct vm_area_struct *vma_m, *new_m = NULL;
94718+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94719+#endif
94720+
94721 if (is_vm_hugetlb_page(vma) && (addr &
94722 ~(huge_page_mask(hstate_vma(vma)))))
94723 return -EINVAL;
94724
94725+#ifdef CONFIG_PAX_SEGMEXEC
94726+ vma_m = pax_find_mirror_vma(vma);
94727+#endif
94728+
94729 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94730 if (!new)
94731 goto out_err;
94732
94733+#ifdef CONFIG_PAX_SEGMEXEC
94734+ if (vma_m) {
94735+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94736+ if (!new_m) {
94737+ kmem_cache_free(vm_area_cachep, new);
94738+ goto out_err;
94739+ }
94740+ }
94741+#endif
94742+
94743 /* most fields are the same, copy all, and then fixup */
94744 *new = *vma;
94745
94746@@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94747 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94748 }
94749
94750+#ifdef CONFIG_PAX_SEGMEXEC
94751+ if (vma_m) {
94752+ *new_m = *vma_m;
94753+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
94754+ new_m->vm_mirror = new;
94755+ new->vm_mirror = new_m;
94756+
94757+ if (new_below)
94758+ new_m->vm_end = addr_m;
94759+ else {
94760+ new_m->vm_start = addr_m;
94761+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94762+ }
94763+ }
94764+#endif
94765+
94766 err = vma_dup_policy(vma, new);
94767 if (err)
94768 goto out_free_vma;
94769@@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94770 else
94771 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94772
94773+#ifdef CONFIG_PAX_SEGMEXEC
94774+ if (!err && vma_m) {
94775+ struct mempolicy *pol = vma_policy(new);
94776+
94777+ if (anon_vma_clone(new_m, vma_m))
94778+ goto out_free_mpol;
94779+
94780+ mpol_get(pol);
94781+ set_vma_policy(new_m, pol);
94782+
94783+ if (new_m->vm_file)
94784+ get_file(new_m->vm_file);
94785+
94786+ if (new_m->vm_ops && new_m->vm_ops->open)
94787+ new_m->vm_ops->open(new_m);
94788+
94789+ if (new_below)
94790+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94791+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94792+ else
94793+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94794+
94795+ if (err) {
94796+ if (new_m->vm_ops && new_m->vm_ops->close)
94797+ new_m->vm_ops->close(new_m);
94798+ if (new_m->vm_file)
94799+ fput(new_m->vm_file);
94800+ mpol_put(pol);
94801+ }
94802+ }
94803+#endif
94804+
94805 /* Success. */
94806 if (!err)
94807 return 0;
94808@@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94809 new->vm_ops->close(new);
94810 if (new->vm_file)
94811 fput(new->vm_file);
94812- unlink_anon_vmas(new);
94813 out_free_mpol:
94814 mpol_put(vma_policy(new));
94815 out_free_vma:
94816+
94817+#ifdef CONFIG_PAX_SEGMEXEC
94818+ if (new_m) {
94819+ unlink_anon_vmas(new_m);
94820+ kmem_cache_free(vm_area_cachep, new_m);
94821+ }
94822+#endif
94823+
94824+ unlink_anon_vmas(new);
94825 kmem_cache_free(vm_area_cachep, new);
94826 out_err:
94827 return err;
94828@@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94829 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94830 unsigned long addr, int new_below)
94831 {
94832+
94833+#ifdef CONFIG_PAX_SEGMEXEC
94834+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94835+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94836+ if (mm->map_count >= sysctl_max_map_count-1)
94837+ return -ENOMEM;
94838+ } else
94839+#endif
94840+
94841 if (mm->map_count >= sysctl_max_map_count)
94842 return -ENOMEM;
94843
94844@@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94845 * work. This now handles partial unmappings.
94846 * Jeremy Fitzhardinge <jeremy@goop.org>
94847 */
94848+#ifdef CONFIG_PAX_SEGMEXEC
94849 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94850 {
94851+ int ret = __do_munmap(mm, start, len);
94852+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94853+ return ret;
94854+
94855+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94856+}
94857+
94858+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94859+#else
94860+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94861+#endif
94862+{
94863 unsigned long end;
94864 struct vm_area_struct *vma, *prev, *last;
94865
94866+ /*
94867+ * mm->mmap_sem is required to protect against another thread
94868+ * changing the mappings in case we sleep.
94869+ */
94870+ verify_mm_writelocked(mm);
94871+
94872 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94873 return -EINVAL;
94874
94875@@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94876 /* Fix up all other VM information */
94877 remove_vma_list(mm, vma);
94878
94879+ track_exec_limit(mm, start, end, 0UL);
94880+
94881 return 0;
94882 }
94883
94884@@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
94885 int ret;
94886 struct mm_struct *mm = current->mm;
94887
94888+
94889+#ifdef CONFIG_PAX_SEGMEXEC
94890+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94891+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94892+ return -EINVAL;
94893+#endif
94894+
94895 down_write(&mm->mmap_sem);
94896 ret = do_munmap(mm, start, len);
94897 up_write(&mm->mmap_sem);
94898@@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94899 return vm_munmap(addr, len);
94900 }
94901
94902-static inline void verify_mm_writelocked(struct mm_struct *mm)
94903-{
94904-#ifdef CONFIG_DEBUG_VM
94905- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94906- WARN_ON(1);
94907- up_read(&mm->mmap_sem);
94908- }
94909-#endif
94910-}
94911-
94912 /*
94913 * this is really a simplified "do_mmap". it only handles
94914 * anonymous maps. eventually we may be able to do some
94915@@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94916 struct rb_node ** rb_link, * rb_parent;
94917 pgoff_t pgoff = addr >> PAGE_SHIFT;
94918 int error;
94919+ unsigned long charged;
94920
94921 len = PAGE_ALIGN(len);
94922 if (!len)
94923@@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94924
94925 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94926
94927+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94928+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94929+ flags &= ~VM_EXEC;
94930+
94931+#ifdef CONFIG_PAX_MPROTECT
94932+ if (mm->pax_flags & MF_PAX_MPROTECT)
94933+ flags &= ~VM_MAYEXEC;
94934+#endif
94935+
94936+ }
94937+#endif
94938+
94939 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94940 if (error & ~PAGE_MASK)
94941 return error;
94942
94943+ charged = len >> PAGE_SHIFT;
94944+
94945 error = mlock_future_check(mm, mm->def_flags, len);
94946 if (error)
94947 return error;
94948@@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94949 /*
94950 * Clear old maps. this also does some error checking for us
94951 */
94952- munmap_back:
94953 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94954 if (do_munmap(mm, addr, len))
94955 return -ENOMEM;
94956- goto munmap_back;
94957+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94958 }
94959
94960 /* Check against address space limits *after* clearing old maps... */
94961- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94962+ if (!may_expand_vm(mm, charged))
94963 return -ENOMEM;
94964
94965 if (mm->map_count > sysctl_max_map_count)
94966 return -ENOMEM;
94967
94968- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94969+ if (security_vm_enough_memory_mm(mm, charged))
94970 return -ENOMEM;
94971
94972 /* Can we just expand an old private anonymous mapping? */
94973@@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94974 */
94975 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94976 if (!vma) {
94977- vm_unacct_memory(len >> PAGE_SHIFT);
94978+ vm_unacct_memory(charged);
94979 return -ENOMEM;
94980 }
94981
94982@@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94983 vma_link(mm, vma, prev, rb_link, rb_parent);
94984 out:
94985 perf_event_mmap(vma);
94986- mm->total_vm += len >> PAGE_SHIFT;
94987+ mm->total_vm += charged;
94988 if (flags & VM_LOCKED)
94989- mm->locked_vm += (len >> PAGE_SHIFT);
94990+ mm->locked_vm += charged;
94991 vma->vm_flags |= VM_SOFTDIRTY;
94992+ track_exec_limit(mm, addr, addr + len, flags);
94993 return addr;
94994 }
94995
94996@@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
94997 while (vma) {
94998 if (vma->vm_flags & VM_ACCOUNT)
94999 nr_accounted += vma_pages(vma);
95000+ vma->vm_mirror = NULL;
95001 vma = remove_vma(vma);
95002 }
95003 vm_unacct_memory(nr_accounted);
95004@@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
95005 struct vm_area_struct *prev;
95006 struct rb_node **rb_link, *rb_parent;
95007
95008+#ifdef CONFIG_PAX_SEGMEXEC
95009+ struct vm_area_struct *vma_m = NULL;
95010+#endif
95011+
95012+ if (security_mmap_addr(vma->vm_start))
95013+ return -EPERM;
95014+
95015 /*
95016 * The vm_pgoff of a purely anonymous vma should be irrelevant
95017 * until its first write fault, when page's anon_vma and index
95018@@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
95019 security_vm_enough_memory_mm(mm, vma_pages(vma)))
95020 return -ENOMEM;
95021
95022+#ifdef CONFIG_PAX_SEGMEXEC
95023+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
95024+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95025+ if (!vma_m)
95026+ return -ENOMEM;
95027+ }
95028+#endif
95029+
95030 vma_link(mm, vma, prev, rb_link, rb_parent);
95031+
95032+#ifdef CONFIG_PAX_SEGMEXEC
95033+ if (vma_m)
95034+ BUG_ON(pax_mirror_vma(vma_m, vma));
95035+#endif
95036+
95037 return 0;
95038 }
95039
95040@@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
95041 struct rb_node **rb_link, *rb_parent;
95042 bool faulted_in_anon_vma = true;
95043
95044+ BUG_ON(vma->vm_mirror);
95045+
95046 /*
95047 * If anonymous vma has not yet been faulted, update new pgoff
95048 * to match new location, to increase its chance of merging.
95049@@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
95050 return NULL;
95051 }
95052
95053+#ifdef CONFIG_PAX_SEGMEXEC
95054+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
95055+{
95056+ struct vm_area_struct *prev_m;
95057+ struct rb_node **rb_link_m, *rb_parent_m;
95058+ struct mempolicy *pol_m;
95059+
95060+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
95061+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
95062+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
95063+ *vma_m = *vma;
95064+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
95065+ if (anon_vma_clone(vma_m, vma))
95066+ return -ENOMEM;
95067+ pol_m = vma_policy(vma_m);
95068+ mpol_get(pol_m);
95069+ set_vma_policy(vma_m, pol_m);
95070+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
95071+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
95072+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
95073+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
95074+ if (vma_m->vm_file)
95075+ get_file(vma_m->vm_file);
95076+ if (vma_m->vm_ops && vma_m->vm_ops->open)
95077+ vma_m->vm_ops->open(vma_m);
95078+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
95079+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
95080+ vma_m->vm_mirror = vma;
95081+ vma->vm_mirror = vma_m;
95082+ return 0;
95083+}
95084+#endif
95085+
95086 /*
95087 * Return true if the calling process may expand its vm space by the passed
95088 * number of pages
95089@@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
95090
95091 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
95092
95093+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
95094 if (cur + npages > lim)
95095 return 0;
95096 return 1;
95097@@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
95098 vma->vm_start = addr;
95099 vma->vm_end = addr + len;
95100
95101+#ifdef CONFIG_PAX_MPROTECT
95102+ if (mm->pax_flags & MF_PAX_MPROTECT) {
95103+#ifndef CONFIG_PAX_MPROTECT_COMPAT
95104+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
95105+ return -EPERM;
95106+ if (!(vm_flags & VM_EXEC))
95107+ vm_flags &= ~VM_MAYEXEC;
95108+#else
95109+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
95110+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
95111+#endif
95112+ else
95113+ vm_flags &= ~VM_MAYWRITE;
95114+ }
95115+#endif
95116+
95117 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
95118 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
95119
95120diff --git a/mm/mprotect.c b/mm/mprotect.c
95121index 769a67a..414d24f 100644
95122--- a/mm/mprotect.c
95123+++ b/mm/mprotect.c
95124@@ -24,10 +24,18 @@
95125 #include <linux/migrate.h>
95126 #include <linux/perf_event.h>
95127 #include <linux/ksm.h>
95128+#include <linux/sched/sysctl.h>
95129+
95130+#ifdef CONFIG_PAX_MPROTECT
95131+#include <linux/elf.h>
95132+#include <linux/binfmts.h>
95133+#endif
95134+
95135 #include <asm/uaccess.h>
95136 #include <asm/pgtable.h>
95137 #include <asm/cacheflush.h>
95138 #include <asm/tlbflush.h>
95139+#include <asm/mmu_context.h>
95140
95141 #ifndef pgprot_modify
95142 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
95143@@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
95144 return pages;
95145 }
95146
95147+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95148+/* called while holding the mmap semaphor for writing except stack expansion */
95149+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
95150+{
95151+ unsigned long oldlimit, newlimit = 0UL;
95152+
95153+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
95154+ return;
95155+
95156+ spin_lock(&mm->page_table_lock);
95157+ oldlimit = mm->context.user_cs_limit;
95158+ if ((prot & VM_EXEC) && oldlimit < end)
95159+ /* USER_CS limit moved up */
95160+ newlimit = end;
95161+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
95162+ /* USER_CS limit moved down */
95163+ newlimit = start;
95164+
95165+ if (newlimit) {
95166+ mm->context.user_cs_limit = newlimit;
95167+
95168+#ifdef CONFIG_SMP
95169+ wmb();
95170+ cpus_clear(mm->context.cpu_user_cs_mask);
95171+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
95172+#endif
95173+
95174+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
95175+ }
95176+ spin_unlock(&mm->page_table_lock);
95177+ if (newlimit == end) {
95178+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
95179+
95180+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
95181+ if (is_vm_hugetlb_page(vma))
95182+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
95183+ else
95184+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
95185+ }
95186+}
95187+#endif
95188+
95189 int
95190 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95191 unsigned long start, unsigned long end, unsigned long newflags)
95192@@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95193 int error;
95194 int dirty_accountable = 0;
95195
95196+#ifdef CONFIG_PAX_SEGMEXEC
95197+ struct vm_area_struct *vma_m = NULL;
95198+ unsigned long start_m, end_m;
95199+
95200+ start_m = start + SEGMEXEC_TASK_SIZE;
95201+ end_m = end + SEGMEXEC_TASK_SIZE;
95202+#endif
95203+
95204 if (newflags == oldflags) {
95205 *pprev = vma;
95206 return 0;
95207 }
95208
95209+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
95210+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
95211+
95212+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
95213+ return -ENOMEM;
95214+
95215+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
95216+ return -ENOMEM;
95217+ }
95218+
95219 /*
95220 * If we make a private mapping writable we increase our commit;
95221 * but (without finer accounting) cannot reduce our commit if we
95222@@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95223 }
95224 }
95225
95226+#ifdef CONFIG_PAX_SEGMEXEC
95227+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
95228+ if (start != vma->vm_start) {
95229+ error = split_vma(mm, vma, start, 1);
95230+ if (error)
95231+ goto fail;
95232+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
95233+ *pprev = (*pprev)->vm_next;
95234+ }
95235+
95236+ if (end != vma->vm_end) {
95237+ error = split_vma(mm, vma, end, 0);
95238+ if (error)
95239+ goto fail;
95240+ }
95241+
95242+ if (pax_find_mirror_vma(vma)) {
95243+ error = __do_munmap(mm, start_m, end_m - start_m);
95244+ if (error)
95245+ goto fail;
95246+ } else {
95247+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95248+ if (!vma_m) {
95249+ error = -ENOMEM;
95250+ goto fail;
95251+ }
95252+ vma->vm_flags = newflags;
95253+ error = pax_mirror_vma(vma_m, vma);
95254+ if (error) {
95255+ vma->vm_flags = oldflags;
95256+ goto fail;
95257+ }
95258+ }
95259+ }
95260+#endif
95261+
95262 /*
95263 * First try to merge with previous and/or next vma.
95264 */
95265@@ -277,9 +381,21 @@ success:
95266 * vm_flags and vm_page_prot are protected by the mmap_sem
95267 * held in write mode.
95268 */
95269+
95270+#ifdef CONFIG_PAX_SEGMEXEC
95271+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
95272+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95273+#endif
95274+
95275 vma->vm_flags = newflags;
95276+
95277+#ifdef CONFIG_PAX_MPROTECT
95278+ if (mm->binfmt && mm->binfmt->handle_mprotect)
95279+ mm->binfmt->handle_mprotect(vma, newflags);
95280+#endif
95281+
95282 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95283- vm_get_page_prot(newflags));
95284+ vm_get_page_prot(vma->vm_flags));
95285
95286 if (vma_wants_writenotify(vma)) {
95287 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95288@@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95289 end = start + len;
95290 if (end <= start)
95291 return -ENOMEM;
95292+
95293+#ifdef CONFIG_PAX_SEGMEXEC
95294+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95295+ if (end > SEGMEXEC_TASK_SIZE)
95296+ return -EINVAL;
95297+ } else
95298+#endif
95299+
95300+ if (end > TASK_SIZE)
95301+ return -EINVAL;
95302+
95303 if (!arch_validate_prot(prot))
95304 return -EINVAL;
95305
95306@@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95307 /*
95308 * Does the application expect PROT_READ to imply PROT_EXEC:
95309 */
95310- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95311+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95312 prot |= PROT_EXEC;
95313
95314 vm_flags = calc_vm_prot_bits(prot);
95315@@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95316 if (start > vma->vm_start)
95317 prev = vma;
95318
95319+#ifdef CONFIG_PAX_MPROTECT
95320+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95321+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
95322+#endif
95323+
95324 for (nstart = start ; ; ) {
95325 unsigned long newflags;
95326
95327@@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95328
95329 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95330 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95331+ if (prot & (PROT_WRITE | PROT_EXEC))
95332+ gr_log_rwxmprotect(vma);
95333+
95334+ error = -EACCES;
95335+ goto out;
95336+ }
95337+
95338+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95339 error = -EACCES;
95340 goto out;
95341 }
95342@@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95343 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95344 if (error)
95345 goto out;
95346+
95347+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
95348+
95349 nstart = tmp;
95350
95351 if (nstart < prev->vm_end)
95352diff --git a/mm/mremap.c b/mm/mremap.c
95353index 05f1180..c3cde48 100644
95354--- a/mm/mremap.c
95355+++ b/mm/mremap.c
95356@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95357 continue;
95358 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95359 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95360+
95361+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95362+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95363+ pte = pte_exprotect(pte);
95364+#endif
95365+
95366 pte = move_soft_dirty_pte(pte);
95367 set_pte_at(mm, new_addr, new_pte, pte);
95368 }
95369@@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95370 if (is_vm_hugetlb_page(vma))
95371 goto Einval;
95372
95373+#ifdef CONFIG_PAX_SEGMEXEC
95374+ if (pax_find_mirror_vma(vma))
95375+ goto Einval;
95376+#endif
95377+
95378 /* We can't remap across vm area boundaries */
95379 if (old_len > vma->vm_end - addr)
95380 goto Efault;
95381@@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95382 unsigned long ret = -EINVAL;
95383 unsigned long charged = 0;
95384 unsigned long map_flags;
95385+ unsigned long pax_task_size = TASK_SIZE;
95386
95387 if (new_addr & ~PAGE_MASK)
95388 goto out;
95389
95390- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95391+#ifdef CONFIG_PAX_SEGMEXEC
95392+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95393+ pax_task_size = SEGMEXEC_TASK_SIZE;
95394+#endif
95395+
95396+ pax_task_size -= PAGE_SIZE;
95397+
95398+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95399 goto out;
95400
95401 /* Check if the location we're moving into overlaps the
95402 * old location at all, and fail if it does.
95403 */
95404- if ((new_addr <= addr) && (new_addr+new_len) > addr)
95405- goto out;
95406-
95407- if ((addr <= new_addr) && (addr+old_len) > new_addr)
95408+ if (addr + old_len > new_addr && new_addr + new_len > addr)
95409 goto out;
95410
95411 ret = do_munmap(mm, new_addr, new_len);
95412@@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95413 unsigned long ret = -EINVAL;
95414 unsigned long charged = 0;
95415 bool locked = false;
95416+ unsigned long pax_task_size = TASK_SIZE;
95417
95418 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95419 return ret;
95420@@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95421 if (!new_len)
95422 return ret;
95423
95424+#ifdef CONFIG_PAX_SEGMEXEC
95425+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95426+ pax_task_size = SEGMEXEC_TASK_SIZE;
95427+#endif
95428+
95429+ pax_task_size -= PAGE_SIZE;
95430+
95431+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95432+ old_len > pax_task_size || addr > pax_task_size-old_len)
95433+ return ret;
95434+
95435 down_write(&current->mm->mmap_sem);
95436
95437 if (flags & MREMAP_FIXED) {
95438@@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95439 new_addr = addr;
95440 }
95441 ret = addr;
95442+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95443 goto out;
95444 }
95445 }
95446@@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95447 goto out;
95448 }
95449
95450+ map_flags = vma->vm_flags;
95451 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95452+ if (!(ret & ~PAGE_MASK)) {
95453+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95454+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95455+ }
95456 }
95457 out:
95458 if (ret & ~PAGE_MASK)
95459diff --git a/mm/nommu.c b/mm/nommu.c
95460index 8740213..f87e25b 100644
95461--- a/mm/nommu.c
95462+++ b/mm/nommu.c
95463@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95464 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95465 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95466 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95467-int heap_stack_gap = 0;
95468
95469 atomic_long_t mmap_pages_allocated;
95470
95471@@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95472 EXPORT_SYMBOL(find_vma);
95473
95474 /*
95475- * find a VMA
95476- * - we don't extend stack VMAs under NOMMU conditions
95477- */
95478-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95479-{
95480- return find_vma(mm, addr);
95481-}
95482-
95483-/*
95484 * expand a stack to a given address
95485 * - not supported under NOMMU conditions
95486 */
95487@@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95488
95489 /* most fields are the same, copy all, and then fixup */
95490 *new = *vma;
95491+ INIT_LIST_HEAD(&new->anon_vma_chain);
95492 *region = *vma->vm_region;
95493 new->vm_region = region;
95494
95495@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95496 }
95497 EXPORT_SYMBOL(generic_file_remap_pages);
95498
95499-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95500- unsigned long addr, void *buf, int len, int write)
95501+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95502+ unsigned long addr, void *buf, size_t len, int write)
95503 {
95504 struct vm_area_struct *vma;
95505
95506@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95507 *
95508 * The caller must hold a reference on @mm.
95509 */
95510-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95511- void *buf, int len, int write)
95512+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95513+ void *buf, size_t len, int write)
95514 {
95515 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95516 }
95517@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95518 * Access another process' address space.
95519 * - source/target buffer must be kernel space
95520 */
95521-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95522+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95523 {
95524 struct mm_struct *mm;
95525
95526diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95527index 8f6daa6..1f8587c 100644
95528--- a/mm/page-writeback.c
95529+++ b/mm/page-writeback.c
95530@@ -685,7 +685,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
95531 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95532 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95533 */
95534-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95535+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95536 unsigned long thresh,
95537 unsigned long bg_thresh,
95538 unsigned long dirty,
95539diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95540index 7387a67..67105e4 100644
95541--- a/mm/page_alloc.c
95542+++ b/mm/page_alloc.c
95543@@ -61,6 +61,7 @@
95544 #include <linux/page-debug-flags.h>
95545 #include <linux/hugetlb.h>
95546 #include <linux/sched/rt.h>
95547+#include <linux/random.h>
95548
95549 #include <asm/sections.h>
95550 #include <asm/tlbflush.h>
95551@@ -354,7 +355,7 @@ out:
95552 * This usage means that zero-order pages may not be compound.
95553 */
95554
95555-static void free_compound_page(struct page *page)
95556+void free_compound_page(struct page *page)
95557 {
95558 __free_pages_ok(page, compound_order(page));
95559 }
95560@@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95561 int i;
95562 int bad = 0;
95563
95564+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95565+ unsigned long index = 1UL << order;
95566+#endif
95567+
95568 trace_mm_page_free(page, order);
95569 kmemcheck_free_shadow(page, order);
95570
95571@@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95572 debug_check_no_obj_freed(page_address(page),
95573 PAGE_SIZE << order);
95574 }
95575+
95576+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95577+ for (; index; --index)
95578+ sanitize_highpage(page + index - 1);
95579+#endif
95580+
95581 arch_free_page(page, order);
95582 kernel_map_pages(page, 1 << order, 0);
95583
95584@@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95585 local_irq_restore(flags);
95586 }
95587
95588+#ifdef CONFIG_PAX_LATENT_ENTROPY
95589+bool __meminitdata extra_latent_entropy;
95590+
95591+static int __init setup_pax_extra_latent_entropy(char *str)
95592+{
95593+ extra_latent_entropy = true;
95594+ return 0;
95595+}
95596+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95597+
95598+volatile u64 latent_entropy __latent_entropy;
95599+EXPORT_SYMBOL(latent_entropy);
95600+#endif
95601+
95602 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95603 {
95604 unsigned int nr_pages = 1 << order;
95605@@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95606 __ClearPageReserved(p);
95607 set_page_count(p, 0);
95608
95609+#ifdef CONFIG_PAX_LATENT_ENTROPY
95610+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95611+ u64 hash = 0;
95612+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95613+ const u64 *data = lowmem_page_address(page);
95614+
95615+ for (index = 0; index < end; index++)
95616+ hash ^= hash + data[index];
95617+ latent_entropy ^= hash;
95618+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95619+ }
95620+#endif
95621+
95622 page_zone(page)->managed_pages += nr_pages;
95623 set_page_refcounted(page);
95624 __free_pages(page, order);
95625@@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95626 arch_alloc_page(page, order);
95627 kernel_map_pages(page, 1 << order, 1);
95628
95629+#ifndef CONFIG_PAX_MEMORY_SANITIZE
95630 if (gfp_flags & __GFP_ZERO)
95631 prep_zero_page(page, order, gfp_flags);
95632+#endif
95633
95634 if (order && (gfp_flags & __GFP_COMP))
95635 prep_compound_page(page, order);
95636@@ -2401,7 +2441,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95637 continue;
95638 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95639 high_wmark_pages(zone) - low_wmark_pages(zone) -
95640- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95641+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95642 }
95643 }
95644
95645@@ -6565,4 +6605,4 @@ void dump_page(struct page *page, char *reason)
95646 {
95647 dump_page_badflags(page, reason, 0);
95648 }
95649-EXPORT_SYMBOL_GPL(dump_page);
95650+EXPORT_SYMBOL(dump_page);
95651diff --git a/mm/page_io.c b/mm/page_io.c
95652index 7c59ef6..1358905 100644
95653--- a/mm/page_io.c
95654+++ b/mm/page_io.c
95655@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95656 struct file *swap_file = sis->swap_file;
95657 struct address_space *mapping = swap_file->f_mapping;
95658 struct iovec iov = {
95659- .iov_base = kmap(page),
95660+ .iov_base = (void __force_user *)kmap(page),
95661 .iov_len = PAGE_SIZE,
95662 };
95663
95664diff --git a/mm/percpu.c b/mm/percpu.c
95665index a2a54a8..43ecb68 100644
95666--- a/mm/percpu.c
95667+++ b/mm/percpu.c
95668@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95669 static unsigned int pcpu_high_unit_cpu __read_mostly;
95670
95671 /* the address of the first chunk which starts with the kernel static area */
95672-void *pcpu_base_addr __read_mostly;
95673+void *pcpu_base_addr __read_only;
95674 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95675
95676 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95677diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95678index fd26d04..0cea1b0 100644
95679--- a/mm/process_vm_access.c
95680+++ b/mm/process_vm_access.c
95681@@ -13,6 +13,7 @@
95682 #include <linux/uio.h>
95683 #include <linux/sched.h>
95684 #include <linux/highmem.h>
95685+#include <linux/security.h>
95686 #include <linux/ptrace.h>
95687 #include <linux/slab.h>
95688 #include <linux/syscalls.h>
95689@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95690 size_t iov_l_curr_offset = 0;
95691 ssize_t iov_len;
95692
95693+ return -ENOSYS; // PaX: until properly audited
95694+
95695 /*
95696 * Work out how many pages of struct pages we're going to need
95697 * when eventually calling get_user_pages
95698 */
95699 for (i = 0; i < riovcnt; i++) {
95700 iov_len = rvec[i].iov_len;
95701- if (iov_len > 0) {
95702- nr_pages_iov = ((unsigned long)rvec[i].iov_base
95703- + iov_len)
95704- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95705- / PAGE_SIZE + 1;
95706- nr_pages = max(nr_pages, nr_pages_iov);
95707- }
95708+ if (iov_len <= 0)
95709+ continue;
95710+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95711+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95712+ nr_pages = max(nr_pages, nr_pages_iov);
95713 }
95714
95715 if (nr_pages == 0)
95716@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95717 goto free_proc_pages;
95718 }
95719
95720+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95721+ rc = -EPERM;
95722+ goto put_task_struct;
95723+ }
95724+
95725 mm = mm_access(task, PTRACE_MODE_ATTACH);
95726 if (!mm || IS_ERR(mm)) {
95727 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95728diff --git a/mm/rmap.c b/mm/rmap.c
95729index 5d91bb7..3784601 100644
95730--- a/mm/rmap.c
95731+++ b/mm/rmap.c
95732@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95733 struct anon_vma *anon_vma = vma->anon_vma;
95734 struct anon_vma_chain *avc;
95735
95736+#ifdef CONFIG_PAX_SEGMEXEC
95737+ struct anon_vma_chain *avc_m = NULL;
95738+#endif
95739+
95740 might_sleep();
95741 if (unlikely(!anon_vma)) {
95742 struct mm_struct *mm = vma->vm_mm;
95743@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95744 if (!avc)
95745 goto out_enomem;
95746
95747+#ifdef CONFIG_PAX_SEGMEXEC
95748+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95749+ if (!avc_m)
95750+ goto out_enomem_free_avc;
95751+#endif
95752+
95753 anon_vma = find_mergeable_anon_vma(vma);
95754 allocated = NULL;
95755 if (!anon_vma) {
95756@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95757 /* page_table_lock to protect against threads */
95758 spin_lock(&mm->page_table_lock);
95759 if (likely(!vma->anon_vma)) {
95760+
95761+#ifdef CONFIG_PAX_SEGMEXEC
95762+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95763+
95764+ if (vma_m) {
95765+ BUG_ON(vma_m->anon_vma);
95766+ vma_m->anon_vma = anon_vma;
95767+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
95768+ avc_m = NULL;
95769+ }
95770+#endif
95771+
95772 vma->anon_vma = anon_vma;
95773 anon_vma_chain_link(vma, avc, anon_vma);
95774 allocated = NULL;
95775@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95776
95777 if (unlikely(allocated))
95778 put_anon_vma(allocated);
95779+
95780+#ifdef CONFIG_PAX_SEGMEXEC
95781+ if (unlikely(avc_m))
95782+ anon_vma_chain_free(avc_m);
95783+#endif
95784+
95785 if (unlikely(avc))
95786 anon_vma_chain_free(avc);
95787 }
95788 return 0;
95789
95790 out_enomem_free_avc:
95791+
95792+#ifdef CONFIG_PAX_SEGMEXEC
95793+ if (avc_m)
95794+ anon_vma_chain_free(avc_m);
95795+#endif
95796+
95797 anon_vma_chain_free(avc);
95798 out_enomem:
95799 return -ENOMEM;
95800@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95801 * Attach the anon_vmas from src to dst.
95802 * Returns 0 on success, -ENOMEM on failure.
95803 */
95804-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95805+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95806 {
95807 struct anon_vma_chain *avc, *pavc;
95808 struct anon_vma *root = NULL;
95809@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95810 * the corresponding VMA in the parent process is attached to.
95811 * Returns 0 on success, non-zero on failure.
95812 */
95813-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95814+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95815 {
95816 struct anon_vma_chain *avc;
95817 struct anon_vma *anon_vma;
95818@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
95819 void __init anon_vma_init(void)
95820 {
95821 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95822- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95823- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95824+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95825+ anon_vma_ctor);
95826+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95827+ SLAB_PANIC|SLAB_NO_SANITIZE);
95828 }
95829
95830 /*
95831diff --git a/mm/shmem.c b/mm/shmem.c
95832index 1f18c9d..b550bab 100644
95833--- a/mm/shmem.c
95834+++ b/mm/shmem.c
95835@@ -33,7 +33,7 @@
95836 #include <linux/swap.h>
95837 #include <linux/aio.h>
95838
95839-static struct vfsmount *shm_mnt;
95840+struct vfsmount *shm_mnt;
95841
95842 #ifdef CONFIG_SHMEM
95843 /*
95844@@ -77,14 +77,15 @@ static struct vfsmount *shm_mnt;
95845 #define BOGO_DIRENT_SIZE 20
95846
95847 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95848-#define SHORT_SYMLINK_LEN 128
95849+#define SHORT_SYMLINK_LEN 64
95850
95851 /*
95852- * shmem_fallocate and shmem_writepage communicate via inode->i_private
95853- * (with i_mutex making sure that it has only one user at a time):
95854- * we would prefer not to enlarge the shmem inode just for that.
95855+ * shmem_fallocate communicates with shmem_fault or shmem_writepage via
95856+ * inode->i_private (with i_mutex making sure that it has only one user at
95857+ * a time): we would prefer not to enlarge the shmem inode just for that.
95858 */
95859 struct shmem_falloc {
95860+ int mode; /* FALLOC_FL mode currently operating */
95861 pgoff_t start; /* start of range currently being fallocated */
95862 pgoff_t next; /* the next page offset to be fallocated */
95863 pgoff_t nr_falloced; /* how many new pages have been fallocated */
95864@@ -824,6 +825,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
95865 spin_lock(&inode->i_lock);
95866 shmem_falloc = inode->i_private;
95867 if (shmem_falloc &&
95868+ !shmem_falloc->mode &&
95869 index >= shmem_falloc->start &&
95870 index < shmem_falloc->next)
95871 shmem_falloc->nr_unswapped++;
95872@@ -1298,6 +1300,43 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
95873 int error;
95874 int ret = VM_FAULT_LOCKED;
95875
95876+ /*
95877+ * Trinity finds that probing a hole which tmpfs is punching can
95878+ * prevent the hole-punch from ever completing: which in turn
95879+ * locks writers out with its hold on i_mutex. So refrain from
95880+ * faulting pages into the hole while it's being punched, and
95881+ * wait on i_mutex to be released if vmf->flags permits,
95882+ */
95883+ if (unlikely(inode->i_private)) {
95884+ struct shmem_falloc *shmem_falloc;
95885+ spin_lock(&inode->i_lock);
95886+ shmem_falloc = inode->i_private;
95887+ if (!shmem_falloc ||
95888+ shmem_falloc->mode != FALLOC_FL_PUNCH_HOLE ||
95889+ vmf->pgoff < shmem_falloc->start ||
95890+ vmf->pgoff >= shmem_falloc->next)
95891+ shmem_falloc = NULL;
95892+ spin_unlock(&inode->i_lock);
95893+ /*
95894+ * i_lock has protected us from taking shmem_falloc seriously
95895+ * once return from shmem_fallocate() went back up that stack.
95896+ * i_lock does not serialize with i_mutex at all, but it does
95897+ * not matter if sometimes we wait unnecessarily, or sometimes
95898+ * miss out on waiting: we just need to make those cases rare.
95899+ */
95900+ if (shmem_falloc) {
95901+ if ((vmf->flags & FAULT_FLAG_ALLOW_RETRY) &&
95902+ !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
95903+ up_read(&vma->vm_mm->mmap_sem);
95904+ mutex_lock(&inode->i_mutex);
95905+ mutex_unlock(&inode->i_mutex);
95906+ return VM_FAULT_RETRY;
95907+ }
95908+ /* cond_resched? Leave that to GUP or return to user */
95909+ return VM_FAULT_NOPAGE;
95910+ }
95911+ }
95912+
95913 error = shmem_getpage(inode, vmf->pgoff, &vmf->page, SGP_CACHE, &ret);
95914 if (error)
95915 return ((error == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS);
95916@@ -1813,18 +1852,26 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset,
95917
95918 mutex_lock(&inode->i_mutex);
95919
95920+ shmem_falloc.mode = mode & ~FALLOC_FL_KEEP_SIZE;
95921+
95922 if (mode & FALLOC_FL_PUNCH_HOLE) {
95923 struct address_space *mapping = file->f_mapping;
95924 loff_t unmap_start = round_up(offset, PAGE_SIZE);
95925 loff_t unmap_end = round_down(offset + len, PAGE_SIZE) - 1;
95926
95927+ shmem_falloc.start = unmap_start >> PAGE_SHIFT;
95928+ shmem_falloc.next = (unmap_end + 1) >> PAGE_SHIFT;
95929+ spin_lock(&inode->i_lock);
95930+ inode->i_private = &shmem_falloc;
95931+ spin_unlock(&inode->i_lock);
95932+
95933 if ((u64)unmap_end > (u64)unmap_start)
95934 unmap_mapping_range(mapping, unmap_start,
95935 1 + unmap_end - unmap_start, 0);
95936 shmem_truncate_range(inode, offset, offset + len - 1);
95937 /* No need to unmap again: hole-punching leaves COWed pages */
95938 error = 0;
95939- goto out;
95940+ goto undone;
95941 }
95942
95943 /* We need to check rlimit even when FALLOC_FL_KEEP_SIZE */
95944@@ -2218,6 +2265,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95945 static int shmem_xattr_validate(const char *name)
95946 {
95947 struct { const char *prefix; size_t len; } arr[] = {
95948+
95949+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95950+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95951+#endif
95952+
95953 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95954 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95955 };
95956@@ -2273,6 +2325,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95957 if (err)
95958 return err;
95959
95960+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95961+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95962+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95963+ return -EOPNOTSUPP;
95964+ if (size > 8)
95965+ return -EINVAL;
95966+ }
95967+#endif
95968+
95969 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95970 }
95971
95972@@ -2585,8 +2646,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95973 int err = -ENOMEM;
95974
95975 /* Round up to L1_CACHE_BYTES to resist false sharing */
95976- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95977- L1_CACHE_BYTES), GFP_KERNEL);
95978+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95979 if (!sbinfo)
95980 return -ENOMEM;
95981
95982diff --git a/mm/slab.c b/mm/slab.c
95983index b264214..83872cd 100644
95984--- a/mm/slab.c
95985+++ b/mm/slab.c
95986@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95987 if ((x)->max_freeable < i) \
95988 (x)->max_freeable = i; \
95989 } while (0)
95990-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95991-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95992-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95993-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95994+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95995+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95996+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95997+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95998+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95999+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
96000 #else
96001 #define STATS_INC_ACTIVE(x) do { } while (0)
96002 #define STATS_DEC_ACTIVE(x) do { } while (0)
96003@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
96004 #define STATS_INC_ALLOCMISS(x) do { } while (0)
96005 #define STATS_INC_FREEHIT(x) do { } while (0)
96006 #define STATS_INC_FREEMISS(x) do { } while (0)
96007+#define STATS_INC_SANITIZED(x) do { } while (0)
96008+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
96009 #endif
96010
96011 #if DEBUG
96012@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
96013 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
96014 */
96015 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
96016- const struct page *page, void *obj)
96017+ const struct page *page, const void *obj)
96018 {
96019 u32 offset = (obj - page->s_mem);
96020 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
96021@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
96022 */
96023
96024 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
96025- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
96026+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
96027
96028 if (INDEX_AC != INDEX_NODE)
96029 kmalloc_caches[INDEX_NODE] =
96030 create_kmalloc_cache("kmalloc-node",
96031- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
96032+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
96033
96034 slab_early_init = 0;
96035
96036@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
96037 struct array_cache *ac = cpu_cache_get(cachep);
96038
96039 check_irq_off();
96040+
96041+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96042+ if (pax_sanitize_slab) {
96043+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
96044+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
96045+
96046+ if (cachep->ctor)
96047+ cachep->ctor(objp);
96048+
96049+ STATS_INC_SANITIZED(cachep);
96050+ } else
96051+ STATS_INC_NOT_SANITIZED(cachep);
96052+ }
96053+#endif
96054+
96055 kmemleak_free_recursive(objp, cachep->flags);
96056 objp = cache_free_debugcheck(cachep, objp, caller);
96057
96058@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
96059
96060 if (unlikely(ZERO_OR_NULL_PTR(objp)))
96061 return;
96062+ VM_BUG_ON(!virt_addr_valid(objp));
96063 local_irq_save(flags);
96064 kfree_debugcheck(objp);
96065 c = virt_to_cache(objp);
96066@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
96067 }
96068 /* cpu stats */
96069 {
96070- unsigned long allochit = atomic_read(&cachep->allochit);
96071- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
96072- unsigned long freehit = atomic_read(&cachep->freehit);
96073- unsigned long freemiss = atomic_read(&cachep->freemiss);
96074+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
96075+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
96076+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
96077+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
96078
96079 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
96080 allochit, allocmiss, freehit, freemiss);
96081 }
96082+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96083+ {
96084+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
96085+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
96086+
96087+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
96088+ }
96089+#endif
96090 #endif
96091 }
96092
96093@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
96094 static int __init slab_proc_init(void)
96095 {
96096 #ifdef CONFIG_DEBUG_SLAB_LEAK
96097- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
96098+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
96099 #endif
96100 return 0;
96101 }
96102 module_init(slab_proc_init);
96103 #endif
96104
96105+bool is_usercopy_object(const void *ptr)
96106+{
96107+ struct page *page;
96108+ struct kmem_cache *cachep;
96109+
96110+ if (ZERO_OR_NULL_PTR(ptr))
96111+ return false;
96112+
96113+ if (!slab_is_available())
96114+ return false;
96115+
96116+ if (!virt_addr_valid(ptr))
96117+ return false;
96118+
96119+ page = virt_to_head_page(ptr);
96120+
96121+ if (!PageSlab(page))
96122+ return false;
96123+
96124+ cachep = page->slab_cache;
96125+ return cachep->flags & SLAB_USERCOPY;
96126+}
96127+
96128+#ifdef CONFIG_PAX_USERCOPY
96129+const char *check_heap_object(const void *ptr, unsigned long n)
96130+{
96131+ struct page *page;
96132+ struct kmem_cache *cachep;
96133+ unsigned int objnr;
96134+ unsigned long offset;
96135+
96136+ if (ZERO_OR_NULL_PTR(ptr))
96137+ return "<null>";
96138+
96139+ if (!virt_addr_valid(ptr))
96140+ return NULL;
96141+
96142+ page = virt_to_head_page(ptr);
96143+
96144+ if (!PageSlab(page))
96145+ return NULL;
96146+
96147+ cachep = page->slab_cache;
96148+ if (!(cachep->flags & SLAB_USERCOPY))
96149+ return cachep->name;
96150+
96151+ objnr = obj_to_index(cachep, page, ptr);
96152+ BUG_ON(objnr >= cachep->num);
96153+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
96154+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
96155+ return NULL;
96156+
96157+ return cachep->name;
96158+}
96159+#endif
96160+
96161 /**
96162 * ksize - get the actual amount of memory allocated for a given object
96163 * @objp: Pointer to the object
96164diff --git a/mm/slab.h b/mm/slab.h
96165index 8184a7c..ab27737 100644
96166--- a/mm/slab.h
96167+++ b/mm/slab.h
96168@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
96169 /* The slab cache that manages slab cache information */
96170 extern struct kmem_cache *kmem_cache;
96171
96172+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96173+#ifdef CONFIG_X86_64
96174+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
96175+#else
96176+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
96177+#endif
96178+extern bool pax_sanitize_slab;
96179+#endif
96180+
96181 unsigned long calculate_alignment(unsigned long flags,
96182 unsigned long align, unsigned long size);
96183
96184@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96185
96186 /* Legal flag mask for kmem_cache_create(), for various configurations */
96187 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
96188- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
96189+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
96190+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
96191
96192 #if defined(CONFIG_DEBUG_SLAB)
96193 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
96194@@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
96195 return s;
96196
96197 page = virt_to_head_page(x);
96198+
96199+ BUG_ON(!PageSlab(page));
96200+
96201 cachep = page->slab_cache;
96202 if (slab_equal_or_root(cachep, s))
96203 return cachep;
96204diff --git a/mm/slab_common.c b/mm/slab_common.c
96205index 1ec3c61..2067c11 100644
96206--- a/mm/slab_common.c
96207+++ b/mm/slab_common.c
96208@@ -23,11 +23,22 @@
96209
96210 #include "slab.h"
96211
96212-enum slab_state slab_state;
96213+enum slab_state slab_state __read_only;
96214 LIST_HEAD(slab_caches);
96215 DEFINE_MUTEX(slab_mutex);
96216 struct kmem_cache *kmem_cache;
96217
96218+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96219+bool pax_sanitize_slab __read_only = true;
96220+static int __init pax_sanitize_slab_setup(char *str)
96221+{
96222+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
96223+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
96224+ return 1;
96225+}
96226+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
96227+#endif
96228+
96229 #ifdef CONFIG_DEBUG_VM
96230 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
96231 size_t size)
96232@@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
96233 if (err)
96234 goto out_free_cache;
96235
96236- s->refcount = 1;
96237+ atomic_set(&s->refcount, 1);
96238 list_add(&s->list, &slab_caches);
96239 memcg_register_cache(s);
96240
96241@@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96242
96243 get_online_cpus();
96244 mutex_lock(&slab_mutex);
96245- s->refcount--;
96246- if (!s->refcount) {
96247+ if (atomic_dec_and_test(&s->refcount)) {
96248 list_del(&s->list);
96249
96250 if (!__kmem_cache_shutdown(s)) {
96251@@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
96252 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
96253 name, size, err);
96254
96255- s->refcount = -1; /* Exempt from merging for now */
96256+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
96257 }
96258
96259 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96260@@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96261
96262 create_boot_cache(s, name, size, flags);
96263 list_add(&s->list, &slab_caches);
96264- s->refcount = 1;
96265+ atomic_set(&s->refcount, 1);
96266 return s;
96267 }
96268
96269@@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
96270 EXPORT_SYMBOL(kmalloc_dma_caches);
96271 #endif
96272
96273+#ifdef CONFIG_PAX_USERCOPY_SLABS
96274+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
96275+EXPORT_SYMBOL(kmalloc_usercopy_caches);
96276+#endif
96277+
96278 /*
96279 * Conversion table for small slabs sizes / 8 to the index in the
96280 * kmalloc array. This is necessary for slabs < 192 since we have non power
96281@@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
96282 return kmalloc_dma_caches[index];
96283
96284 #endif
96285+
96286+#ifdef CONFIG_PAX_USERCOPY_SLABS
96287+ if (unlikely((flags & GFP_USERCOPY)))
96288+ return kmalloc_usercopy_caches[index];
96289+
96290+#endif
96291+
96292 return kmalloc_caches[index];
96293 }
96294
96295@@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
96296 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
96297 if (!kmalloc_caches[i]) {
96298 kmalloc_caches[i] = create_kmalloc_cache(NULL,
96299- 1 << i, flags);
96300+ 1 << i, SLAB_USERCOPY | flags);
96301 }
96302
96303 /*
96304@@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
96305 * earlier power of two caches
96306 */
96307 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
96308- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
96309+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
96310
96311 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
96312- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
96313+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
96314 }
96315
96316 /* Kmalloc array is now usable */
96317@@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
96318 }
96319 }
96320 #endif
96321+
96322+#ifdef CONFIG_PAX_USERCOPY_SLABS
96323+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96324+ struct kmem_cache *s = kmalloc_caches[i];
96325+
96326+ if (s) {
96327+ int size = kmalloc_size(i);
96328+ char *n = kasprintf(GFP_NOWAIT,
96329+ "usercopy-kmalloc-%d", size);
96330+
96331+ BUG_ON(!n);
96332+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96333+ size, SLAB_USERCOPY | flags);
96334+ }
96335+ }
96336+#endif
96337+
96338 }
96339 #endif /* !CONFIG_SLOB */
96340
96341@@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
96342 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96343 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96344 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96345+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96346+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
96347+#endif
96348 #endif
96349 seq_putc(m, '\n');
96350 }
96351diff --git a/mm/slob.c b/mm/slob.c
96352index 4bf8809..98a6914 100644
96353--- a/mm/slob.c
96354+++ b/mm/slob.c
96355@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96356 /*
96357 * Return the size of a slob block.
96358 */
96359-static slobidx_t slob_units(slob_t *s)
96360+static slobidx_t slob_units(const slob_t *s)
96361 {
96362 if (s->units > 0)
96363 return s->units;
96364@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96365 /*
96366 * Return the next free slob block pointer after this one.
96367 */
96368-static slob_t *slob_next(slob_t *s)
96369+static slob_t *slob_next(const slob_t *s)
96370 {
96371 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96372 slobidx_t next;
96373@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96374 /*
96375 * Returns true if s is the last free block in its page.
96376 */
96377-static int slob_last(slob_t *s)
96378+static int slob_last(const slob_t *s)
96379 {
96380 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96381 }
96382
96383-static void *slob_new_pages(gfp_t gfp, int order, int node)
96384+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96385 {
96386- void *page;
96387+ struct page *page;
96388
96389 #ifdef CONFIG_NUMA
96390 if (node != NUMA_NO_NODE)
96391@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96392 if (!page)
96393 return NULL;
96394
96395- return page_address(page);
96396+ __SetPageSlab(page);
96397+ return page;
96398 }
96399
96400-static void slob_free_pages(void *b, int order)
96401+static void slob_free_pages(struct page *sp, int order)
96402 {
96403 if (current->reclaim_state)
96404 current->reclaim_state->reclaimed_slab += 1 << order;
96405- free_pages((unsigned long)b, order);
96406+ __ClearPageSlab(sp);
96407+ page_mapcount_reset(sp);
96408+ sp->private = 0;
96409+ __free_pages(sp, order);
96410 }
96411
96412 /*
96413@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96414
96415 /* Not enough space: must allocate a new page */
96416 if (!b) {
96417- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96418- if (!b)
96419+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96420+ if (!sp)
96421 return NULL;
96422- sp = virt_to_page(b);
96423- __SetPageSlab(sp);
96424+ b = page_address(sp);
96425
96426 spin_lock_irqsave(&slob_lock, flags);
96427 sp->units = SLOB_UNITS(PAGE_SIZE);
96428 sp->freelist = b;
96429+ sp->private = 0;
96430 INIT_LIST_HEAD(&sp->list);
96431 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96432 set_slob_page_free(sp, slob_list);
96433@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96434 if (slob_page_free(sp))
96435 clear_slob_page_free(sp);
96436 spin_unlock_irqrestore(&slob_lock, flags);
96437- __ClearPageSlab(sp);
96438- page_mapcount_reset(sp);
96439- slob_free_pages(b, 0);
96440+ slob_free_pages(sp, 0);
96441 return;
96442 }
96443
96444+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96445+ if (pax_sanitize_slab)
96446+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96447+#endif
96448+
96449 if (!slob_page_free(sp)) {
96450 /* This slob page is about to become partially free. Easy! */
96451 sp->units = units;
96452@@ -424,11 +431,10 @@ out:
96453 */
96454
96455 static __always_inline void *
96456-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96457+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96458 {
96459- unsigned int *m;
96460- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96461- void *ret;
96462+ slob_t *m;
96463+ void *ret = NULL;
96464
96465 gfp &= gfp_allowed_mask;
96466
96467@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96468
96469 if (!m)
96470 return NULL;
96471- *m = size;
96472+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96473+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96474+ m[0].units = size;
96475+ m[1].units = align;
96476 ret = (void *)m + align;
96477
96478 trace_kmalloc_node(caller, ret,
96479 size, size + align, gfp, node);
96480 } else {
96481 unsigned int order = get_order(size);
96482+ struct page *page;
96483
96484 if (likely(order))
96485 gfp |= __GFP_COMP;
96486- ret = slob_new_pages(gfp, order, node);
96487+ page = slob_new_pages(gfp, order, node);
96488+ if (page) {
96489+ ret = page_address(page);
96490+ page->private = size;
96491+ }
96492
96493 trace_kmalloc_node(caller, ret,
96494 size, PAGE_SIZE << order, gfp, node);
96495 }
96496
96497- kmemleak_alloc(ret, size, 1, gfp);
96498+ return ret;
96499+}
96500+
96501+static __always_inline void *
96502+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96503+{
96504+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96505+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96506+
96507+ if (!ZERO_OR_NULL_PTR(ret))
96508+ kmemleak_alloc(ret, size, 1, gfp);
96509 return ret;
96510 }
96511
96512@@ -493,34 +517,112 @@ void kfree(const void *block)
96513 return;
96514 kmemleak_free(block);
96515
96516+ VM_BUG_ON(!virt_addr_valid(block));
96517 sp = virt_to_page(block);
96518- if (PageSlab(sp)) {
96519+ VM_BUG_ON(!PageSlab(sp));
96520+ if (!sp->private) {
96521 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96522- unsigned int *m = (unsigned int *)(block - align);
96523- slob_free(m, *m + align);
96524- } else
96525+ slob_t *m = (slob_t *)(block - align);
96526+ slob_free(m, m[0].units + align);
96527+ } else {
96528+ __ClearPageSlab(sp);
96529+ page_mapcount_reset(sp);
96530+ sp->private = 0;
96531 __free_pages(sp, compound_order(sp));
96532+ }
96533 }
96534 EXPORT_SYMBOL(kfree);
96535
96536+bool is_usercopy_object(const void *ptr)
96537+{
96538+ if (!slab_is_available())
96539+ return false;
96540+
96541+ // PAX: TODO
96542+
96543+ return false;
96544+}
96545+
96546+#ifdef CONFIG_PAX_USERCOPY
96547+const char *check_heap_object(const void *ptr, unsigned long n)
96548+{
96549+ struct page *page;
96550+ const slob_t *free;
96551+ const void *base;
96552+ unsigned long flags;
96553+
96554+ if (ZERO_OR_NULL_PTR(ptr))
96555+ return "<null>";
96556+
96557+ if (!virt_addr_valid(ptr))
96558+ return NULL;
96559+
96560+ page = virt_to_head_page(ptr);
96561+ if (!PageSlab(page))
96562+ return NULL;
96563+
96564+ if (page->private) {
96565+ base = page;
96566+ if (base <= ptr && n <= page->private - (ptr - base))
96567+ return NULL;
96568+ return "<slob>";
96569+ }
96570+
96571+ /* some tricky double walking to find the chunk */
96572+ spin_lock_irqsave(&slob_lock, flags);
96573+ base = (void *)((unsigned long)ptr & PAGE_MASK);
96574+ free = page->freelist;
96575+
96576+ while (!slob_last(free) && (void *)free <= ptr) {
96577+ base = free + slob_units(free);
96578+ free = slob_next(free);
96579+ }
96580+
96581+ while (base < (void *)free) {
96582+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96583+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
96584+ int offset;
96585+
96586+ if (ptr < base + align)
96587+ break;
96588+
96589+ offset = ptr - base - align;
96590+ if (offset >= m) {
96591+ base += size;
96592+ continue;
96593+ }
96594+
96595+ if (n > m - offset)
96596+ break;
96597+
96598+ spin_unlock_irqrestore(&slob_lock, flags);
96599+ return NULL;
96600+ }
96601+
96602+ spin_unlock_irqrestore(&slob_lock, flags);
96603+ return "<slob>";
96604+}
96605+#endif
96606+
96607 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96608 size_t ksize(const void *block)
96609 {
96610 struct page *sp;
96611 int align;
96612- unsigned int *m;
96613+ slob_t *m;
96614
96615 BUG_ON(!block);
96616 if (unlikely(block == ZERO_SIZE_PTR))
96617 return 0;
96618
96619 sp = virt_to_page(block);
96620- if (unlikely(!PageSlab(sp)))
96621- return PAGE_SIZE << compound_order(sp);
96622+ VM_BUG_ON(!PageSlab(sp));
96623+ if (sp->private)
96624+ return sp->private;
96625
96626 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96627- m = (unsigned int *)(block - align);
96628- return SLOB_UNITS(*m) * SLOB_UNIT;
96629+ m = (slob_t *)(block - align);
96630+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96631 }
96632 EXPORT_SYMBOL(ksize);
96633
96634@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96635
96636 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96637 {
96638- void *b;
96639+ void *b = NULL;
96640
96641 flags &= gfp_allowed_mask;
96642
96643 lockdep_trace_alloc(flags);
96644
96645+#ifdef CONFIG_PAX_USERCOPY_SLABS
96646+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96647+#else
96648 if (c->size < PAGE_SIZE) {
96649 b = slob_alloc(c->size, flags, c->align, node);
96650 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96651 SLOB_UNITS(c->size) * SLOB_UNIT,
96652 flags, node);
96653 } else {
96654- b = slob_new_pages(flags, get_order(c->size), node);
96655+ struct page *sp;
96656+
96657+ sp = slob_new_pages(flags, get_order(c->size), node);
96658+ if (sp) {
96659+ b = page_address(sp);
96660+ sp->private = c->size;
96661+ }
96662 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96663 PAGE_SIZE << get_order(c->size),
96664 flags, node);
96665 }
96666+#endif
96667
96668 if (b && c->ctor)
96669 c->ctor(b);
96670@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96671
96672 static void __kmem_cache_free(void *b, int size)
96673 {
96674- if (size < PAGE_SIZE)
96675+ struct page *sp;
96676+
96677+ sp = virt_to_page(b);
96678+ BUG_ON(!PageSlab(sp));
96679+ if (!sp->private)
96680 slob_free(b, size);
96681 else
96682- slob_free_pages(b, get_order(size));
96683+ slob_free_pages(sp, get_order(size));
96684 }
96685
96686 static void kmem_rcu_free(struct rcu_head *head)
96687@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96688
96689 void kmem_cache_free(struct kmem_cache *c, void *b)
96690 {
96691+ int size = c->size;
96692+
96693+#ifdef CONFIG_PAX_USERCOPY_SLABS
96694+ if (size + c->align < PAGE_SIZE) {
96695+ size += c->align;
96696+ b -= c->align;
96697+ }
96698+#endif
96699+
96700 kmemleak_free_recursive(b, c->flags);
96701 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96702 struct slob_rcu *slob_rcu;
96703- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96704- slob_rcu->size = c->size;
96705+ slob_rcu = b + (size - sizeof(struct slob_rcu));
96706+ slob_rcu->size = size;
96707 call_rcu(&slob_rcu->head, kmem_rcu_free);
96708 } else {
96709- __kmem_cache_free(b, c->size);
96710+ __kmem_cache_free(b, size);
96711 }
96712
96713+#ifdef CONFIG_PAX_USERCOPY_SLABS
96714+ trace_kfree(_RET_IP_, b);
96715+#else
96716 trace_kmem_cache_free(_RET_IP_, b);
96717+#endif
96718+
96719 }
96720 EXPORT_SYMBOL(kmem_cache_free);
96721
96722diff --git a/mm/slub.c b/mm/slub.c
96723index 25f14ad..c904f6f 100644
96724--- a/mm/slub.c
96725+++ b/mm/slub.c
96726@@ -207,7 +207,7 @@ struct track {
96727
96728 enum track_item { TRACK_ALLOC, TRACK_FREE };
96729
96730-#ifdef CONFIG_SYSFS
96731+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96732 static int sysfs_slab_add(struct kmem_cache *);
96733 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96734 static void sysfs_slab_remove(struct kmem_cache *);
96735@@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
96736 if (!t->addr)
96737 return;
96738
96739- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96740+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96741 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96742 #ifdef CONFIG_STACKTRACE
96743 {
96744@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96745
96746 slab_free_hook(s, x);
96747
96748+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96749+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96750+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96751+ if (s->ctor)
96752+ s->ctor(x);
96753+ }
96754+#endif
96755+
96756 redo:
96757 /*
96758 * Determine the currently cpus per cpu slab.
96759@@ -2733,7 +2741,7 @@ static int slub_min_objects;
96760 * Merge control. If this is set then no merging of slab caches will occur.
96761 * (Could be removed. This was introduced to pacify the merge skeptics.)
96762 */
96763-static int slub_nomerge;
96764+static int slub_nomerge = 1;
96765
96766 /*
96767 * Calculate the order of allocation given an slab object size.
96768@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96769 s->inuse = size;
96770
96771 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96772+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96773+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96774+#endif
96775 s->ctor)) {
96776 /*
96777 * Relocate free pointer after the object if it is not
96778@@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96779 EXPORT_SYMBOL(__kmalloc_node);
96780 #endif
96781
96782+bool is_usercopy_object(const void *ptr)
96783+{
96784+ struct page *page;
96785+ struct kmem_cache *s;
96786+
96787+ if (ZERO_OR_NULL_PTR(ptr))
96788+ return false;
96789+
96790+ if (!slab_is_available())
96791+ return false;
96792+
96793+ if (!virt_addr_valid(ptr))
96794+ return false;
96795+
96796+ page = virt_to_head_page(ptr);
96797+
96798+ if (!PageSlab(page))
96799+ return false;
96800+
96801+ s = page->slab_cache;
96802+ return s->flags & SLAB_USERCOPY;
96803+}
96804+
96805+#ifdef CONFIG_PAX_USERCOPY
96806+const char *check_heap_object(const void *ptr, unsigned long n)
96807+{
96808+ struct page *page;
96809+ struct kmem_cache *s;
96810+ unsigned long offset;
96811+
96812+ if (ZERO_OR_NULL_PTR(ptr))
96813+ return "<null>";
96814+
96815+ if (!virt_addr_valid(ptr))
96816+ return NULL;
96817+
96818+ page = virt_to_head_page(ptr);
96819+
96820+ if (!PageSlab(page))
96821+ return NULL;
96822+
96823+ s = page->slab_cache;
96824+ if (!(s->flags & SLAB_USERCOPY))
96825+ return s->name;
96826+
96827+ offset = (ptr - page_address(page)) % s->size;
96828+ if (offset <= s->object_size && n <= s->object_size - offset)
96829+ return NULL;
96830+
96831+ return s->name;
96832+}
96833+#endif
96834+
96835 size_t ksize(const void *object)
96836 {
96837 struct page *page;
96838@@ -3387,6 +3451,7 @@ void kfree(const void *x)
96839 if (unlikely(ZERO_OR_NULL_PTR(x)))
96840 return;
96841
96842+ VM_BUG_ON(!virt_addr_valid(x));
96843 page = virt_to_head_page(x);
96844 if (unlikely(!PageSlab(page))) {
96845 BUG_ON(!PageCompound(page));
96846@@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96847 /*
96848 * We may have set a slab to be unmergeable during bootstrap.
96849 */
96850- if (s->refcount < 0)
96851+ if (atomic_read(&s->refcount) < 0)
96852 return 1;
96853
96854 return 0;
96855@@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96856
96857 s = find_mergeable(memcg, size, align, flags, name, ctor);
96858 if (s) {
96859- s->refcount++;
96860+ atomic_inc(&s->refcount);
96861 /*
96862 * Adjust the object sizes so that we clear
96863 * the complete object on kzalloc.
96864@@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96865 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
96866
96867 if (sysfs_slab_alias(s, name)) {
96868- s->refcount--;
96869+ atomic_dec(&s->refcount);
96870 s = NULL;
96871 }
96872 }
96873@@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96874 }
96875 #endif
96876
96877-#ifdef CONFIG_SYSFS
96878+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96879 static int count_inuse(struct page *page)
96880 {
96881 return page->inuse;
96882@@ -4163,7 +4228,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
96883 len += sprintf(buf + len, "%7ld ", l->count);
96884
96885 if (l->addr)
96886+#ifdef CONFIG_GRKERNSEC_HIDESYM
96887+ len += sprintf(buf + len, "%pS", NULL);
96888+#else
96889 len += sprintf(buf + len, "%pS", (void *)l->addr);
96890+#endif
96891 else
96892 len += sprintf(buf + len, "<not-available>");
96893
96894@@ -4268,12 +4337,12 @@ static void resiliency_test(void)
96895 validate_slab_cache(kmalloc_caches[9]);
96896 }
96897 #else
96898-#ifdef CONFIG_SYSFS
96899+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96900 static void resiliency_test(void) {};
96901 #endif
96902 #endif
96903
96904-#ifdef CONFIG_SYSFS
96905+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96906 enum slab_stat_type {
96907 SL_ALL, /* All slabs */
96908 SL_PARTIAL, /* Only partially allocated slabs */
96909@@ -4513,13 +4582,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
96910 {
96911 if (!s->ctor)
96912 return 0;
96913+#ifdef CONFIG_GRKERNSEC_HIDESYM
96914+ return sprintf(buf, "%pS\n", NULL);
96915+#else
96916 return sprintf(buf, "%pS\n", s->ctor);
96917+#endif
96918 }
96919 SLAB_ATTR_RO(ctor);
96920
96921 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96922 {
96923- return sprintf(buf, "%d\n", s->refcount - 1);
96924+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96925 }
96926 SLAB_ATTR_RO(aliases);
96927
96928@@ -4607,6 +4680,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96929 SLAB_ATTR_RO(cache_dma);
96930 #endif
96931
96932+#ifdef CONFIG_PAX_USERCOPY_SLABS
96933+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96934+{
96935+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96936+}
96937+SLAB_ATTR_RO(usercopy);
96938+#endif
96939+
96940 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96941 {
96942 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96943@@ -4941,6 +5022,9 @@ static struct attribute *slab_attrs[] = {
96944 #ifdef CONFIG_ZONE_DMA
96945 &cache_dma_attr.attr,
96946 #endif
96947+#ifdef CONFIG_PAX_USERCOPY_SLABS
96948+ &usercopy_attr.attr,
96949+#endif
96950 #ifdef CONFIG_NUMA
96951 &remote_node_defrag_ratio_attr.attr,
96952 #endif
96953@@ -5173,6 +5257,7 @@ static char *create_unique_id(struct kmem_cache *s)
96954 return name;
96955 }
96956
96957+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96958 static int sysfs_slab_add(struct kmem_cache *s)
96959 {
96960 int err;
96961@@ -5230,6 +5315,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
96962 kobject_del(&s->kobj);
96963 kobject_put(&s->kobj);
96964 }
96965+#endif
96966
96967 /*
96968 * Need to buffer aliases during bootup until sysfs becomes
96969@@ -5243,6 +5329,7 @@ struct saved_alias {
96970
96971 static struct saved_alias *alias_list;
96972
96973+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96974 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96975 {
96976 struct saved_alias *al;
96977@@ -5265,6 +5352,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96978 alias_list = al;
96979 return 0;
96980 }
96981+#endif
96982
96983 static int __init slab_sysfs_init(void)
96984 {
96985diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96986index 4cba9c2..b4f9fcc 100644
96987--- a/mm/sparse-vmemmap.c
96988+++ b/mm/sparse-vmemmap.c
96989@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96990 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96991 if (!p)
96992 return NULL;
96993- pud_populate(&init_mm, pud, p);
96994+ pud_populate_kernel(&init_mm, pud, p);
96995 }
96996 return pud;
96997 }
96998@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96999 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
97000 if (!p)
97001 return NULL;
97002- pgd_populate(&init_mm, pgd, p);
97003+ pgd_populate_kernel(&init_mm, pgd, p);
97004 }
97005 return pgd;
97006 }
97007diff --git a/mm/sparse.c b/mm/sparse.c
97008index 63c3ea5..95c0858 100644
97009--- a/mm/sparse.c
97010+++ b/mm/sparse.c
97011@@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
97012
97013 for (i = 0; i < PAGES_PER_SECTION; i++) {
97014 if (PageHWPoison(&memmap[i])) {
97015- atomic_long_sub(1, &num_poisoned_pages);
97016+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
97017 ClearPageHWPoison(&memmap[i]);
97018 }
97019 }
97020diff --git a/mm/swap.c b/mm/swap.c
97021index 0092097..33361ff 100644
97022--- a/mm/swap.c
97023+++ b/mm/swap.c
97024@@ -31,6 +31,7 @@
97025 #include <linux/memcontrol.h>
97026 #include <linux/gfp.h>
97027 #include <linux/uio.h>
97028+#include <linux/hugetlb.h>
97029
97030 #include "internal.h"
97031
97032@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
97033
97034 __page_cache_release(page);
97035 dtor = get_compound_page_dtor(page);
97036+ if (!PageHuge(page))
97037+ BUG_ON(dtor != free_compound_page);
97038 (*dtor)(page);
97039 }
97040
97041diff --git a/mm/swapfile.c b/mm/swapfile.c
97042index 4a7f7e6..22cddf5 100644
97043--- a/mm/swapfile.c
97044+++ b/mm/swapfile.c
97045@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
97046
97047 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
97048 /* Activity counter to indicate that a swapon or swapoff has occurred */
97049-static atomic_t proc_poll_event = ATOMIC_INIT(0);
97050+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
97051
97052 static inline unsigned char swap_count(unsigned char ent)
97053 {
97054@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
97055 spin_unlock(&swap_lock);
97056
97057 err = 0;
97058- atomic_inc(&proc_poll_event);
97059+ atomic_inc_unchecked(&proc_poll_event);
97060 wake_up_interruptible(&proc_poll_wait);
97061
97062 out_dput:
97063@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
97064
97065 poll_wait(file, &proc_poll_wait, wait);
97066
97067- if (seq->poll_event != atomic_read(&proc_poll_event)) {
97068- seq->poll_event = atomic_read(&proc_poll_event);
97069+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
97070+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
97071 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
97072 }
97073
97074@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
97075 return ret;
97076
97077 seq = file->private_data;
97078- seq->poll_event = atomic_read(&proc_poll_event);
97079+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
97080 return 0;
97081 }
97082
97083@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
97084 (frontswap_map) ? "FS" : "");
97085
97086 mutex_unlock(&swapon_mutex);
97087- atomic_inc(&proc_poll_event);
97088+ atomic_inc_unchecked(&proc_poll_event);
97089 wake_up_interruptible(&proc_poll_wait);
97090
97091 if (S_ISREG(inode->i_mode))
97092diff --git a/mm/util.c b/mm/util.c
97093index a24aa22..a0d41ae 100644
97094--- a/mm/util.c
97095+++ b/mm/util.c
97096@@ -297,6 +297,12 @@ done:
97097 void arch_pick_mmap_layout(struct mm_struct *mm)
97098 {
97099 mm->mmap_base = TASK_UNMAPPED_BASE;
97100+
97101+#ifdef CONFIG_PAX_RANDMMAP
97102+ if (mm->pax_flags & MF_PAX_RANDMMAP)
97103+ mm->mmap_base += mm->delta_mmap;
97104+#endif
97105+
97106 mm->get_unmapped_area = arch_get_unmapped_area;
97107 }
97108 #endif
97109diff --git a/mm/vmalloc.c b/mm/vmalloc.c
97110index 0fdf968..2183ba3 100644
97111--- a/mm/vmalloc.c
97112+++ b/mm/vmalloc.c
97113@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97114
97115 pte = pte_offset_kernel(pmd, addr);
97116 do {
97117- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97118- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97119+
97120+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97121+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
97122+ BUG_ON(!pte_exec(*pte));
97123+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
97124+ continue;
97125+ }
97126+#endif
97127+
97128+ {
97129+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97130+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97131+ }
97132 } while (pte++, addr += PAGE_SIZE, addr != end);
97133 }
97134
97135@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
97136 pte = pte_alloc_kernel(pmd, addr);
97137 if (!pte)
97138 return -ENOMEM;
97139+
97140+ pax_open_kernel();
97141 do {
97142 struct page *page = pages[*nr];
97143
97144- if (WARN_ON(!pte_none(*pte)))
97145+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97146+ if (pgprot_val(prot) & _PAGE_NX)
97147+#endif
97148+
97149+ if (!pte_none(*pte)) {
97150+ pax_close_kernel();
97151+ WARN_ON(1);
97152 return -EBUSY;
97153- if (WARN_ON(!page))
97154+ }
97155+ if (!page) {
97156+ pax_close_kernel();
97157+ WARN_ON(1);
97158 return -ENOMEM;
97159+ }
97160 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
97161 (*nr)++;
97162 } while (pte++, addr += PAGE_SIZE, addr != end);
97163+ pax_close_kernel();
97164 return 0;
97165 }
97166
97167@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
97168 pmd_t *pmd;
97169 unsigned long next;
97170
97171- pmd = pmd_alloc(&init_mm, pud, addr);
97172+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
97173 if (!pmd)
97174 return -ENOMEM;
97175 do {
97176@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
97177 pud_t *pud;
97178 unsigned long next;
97179
97180- pud = pud_alloc(&init_mm, pgd, addr);
97181+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
97182 if (!pud)
97183 return -ENOMEM;
97184 do {
97185@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
97186 if (addr >= MODULES_VADDR && addr < MODULES_END)
97187 return 1;
97188 #endif
97189+
97190+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97191+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
97192+ return 1;
97193+#endif
97194+
97195 return is_vmalloc_addr(x);
97196 }
97197
97198@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
97199
97200 if (!pgd_none(*pgd)) {
97201 pud_t *pud = pud_offset(pgd, addr);
97202+#ifdef CONFIG_X86
97203+ if (!pud_large(*pud))
97204+#endif
97205 if (!pud_none(*pud)) {
97206 pmd_t *pmd = pmd_offset(pud, addr);
97207+#ifdef CONFIG_X86
97208+ if (!pmd_large(*pmd))
97209+#endif
97210 if (!pmd_none(*pmd)) {
97211 pte_t *ptep, pte;
97212
97213@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
97214 struct vm_struct *area;
97215
97216 BUG_ON(in_interrupt());
97217+
97218+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97219+ if (flags & VM_KERNEXEC) {
97220+ if (start != VMALLOC_START || end != VMALLOC_END)
97221+ return NULL;
97222+ start = (unsigned long)MODULES_EXEC_VADDR;
97223+ end = (unsigned long)MODULES_EXEC_END;
97224+ }
97225+#endif
97226+
97227 if (flags & VM_IOREMAP)
97228 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
97229
97230@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
97231 if (count > totalram_pages)
97232 return NULL;
97233
97234+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97235+ if (!(pgprot_val(prot) & _PAGE_NX))
97236+ flags |= VM_KERNEXEC;
97237+#endif
97238+
97239 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
97240 __builtin_return_address(0));
97241 if (!area)
97242@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
97243 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
97244 goto fail;
97245
97246+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97247+ if (!(pgprot_val(prot) & _PAGE_NX))
97248+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
97249+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
97250+ else
97251+#endif
97252+
97253 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
97254 start, end, node, gfp_mask, caller);
97255 if (!area)
97256@@ -1701,6 +1759,12 @@ static inline void *__vmalloc_node_flags(unsigned long size,
97257 node, __builtin_return_address(0));
97258 }
97259
97260+void *vmalloc_stack(int node)
97261+{
97262+ return __vmalloc_node(THREAD_SIZE, THREAD_SIZE, THREADINFO_GFP, PAGE_KERNEL,
97263+ node, __builtin_return_address(0));
97264+}
97265+
97266 /**
97267 * vmalloc - allocate virtually contiguous memory
97268 * @size: allocation size
97269@@ -1810,10 +1874,9 @@ EXPORT_SYMBOL(vzalloc_node);
97270 * For tight control over page level allocator and protection flags
97271 * use __vmalloc() instead.
97272 */
97273-
97274 void *vmalloc_exec(unsigned long size)
97275 {
97276- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
97277+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
97278 NUMA_NO_NODE, __builtin_return_address(0));
97279 }
97280
97281@@ -2120,6 +2183,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
97282 {
97283 struct vm_struct *area;
97284
97285+ BUG_ON(vma->vm_mirror);
97286+
97287 size = PAGE_ALIGN(size);
97288
97289 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
97290@@ -2602,7 +2667,11 @@ static int s_show(struct seq_file *m, void *p)
97291 v->addr, v->addr + v->size, v->size);
97292
97293 if (v->caller)
97294+#ifdef CONFIG_GRKERNSEC_HIDESYM
97295+ seq_printf(m, " %pK", v->caller);
97296+#else
97297 seq_printf(m, " %pS", v->caller);
97298+#endif
97299
97300 if (v->nr_pages)
97301 seq_printf(m, " pages=%d", v->nr_pages);
97302diff --git a/mm/vmstat.c b/mm/vmstat.c
97303index def5dd2..4ce55cec 100644
97304--- a/mm/vmstat.c
97305+++ b/mm/vmstat.c
97306@@ -20,6 +20,7 @@
97307 #include <linux/writeback.h>
97308 #include <linux/compaction.h>
97309 #include <linux/mm_inline.h>
97310+#include <linux/grsecurity.h>
97311
97312 #include "internal.h"
97313
97314@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
97315 *
97316 * vm_stat contains the global counters
97317 */
97318-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97319+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97320 EXPORT_SYMBOL(vm_stat);
97321
97322 #ifdef CONFIG_SMP
97323@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
97324
97325 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97326 if (diff[i])
97327- atomic_long_add(diff[i], &vm_stat[i]);
97328+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
97329 }
97330
97331 /*
97332@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
97333 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97334 if (v) {
97335
97336- atomic_long_add(v, &zone->vm_stat[i]);
97337+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97338 global_diff[i] += v;
97339 #ifdef CONFIG_NUMA
97340 /* 3 seconds idle till flush */
97341@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97342
97343 v = p->vm_stat_diff[i];
97344 p->vm_stat_diff[i] = 0;
97345- atomic_long_add(v, &zone->vm_stat[i]);
97346+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97347 global_diff[i] += v;
97348 }
97349 }
97350@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97351 if (pset->vm_stat_diff[i]) {
97352 int v = pset->vm_stat_diff[i];
97353 pset->vm_stat_diff[i] = 0;
97354- atomic_long_add(v, &zone->vm_stat[i]);
97355- atomic_long_add(v, &vm_stat[i]);
97356+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97357+ atomic_long_add_unchecked(v, &vm_stat[i]);
97358 }
97359 }
97360 #endif
97361@@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97362 stat_items_size += sizeof(struct vm_event_state);
97363 #endif
97364
97365- v = kmalloc(stat_items_size, GFP_KERNEL);
97366+ v = kzalloc(stat_items_size, GFP_KERNEL);
97367 m->private = v;
97368 if (!v)
97369 return ERR_PTR(-ENOMEM);
97370+
97371+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97372+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97373+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97374+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97375+ && !in_group_p(grsec_proc_gid)
97376+#endif
97377+ )
97378+ return (unsigned long *)m->private + *pos;
97379+#endif
97380+#endif
97381+
97382 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97383 v[i] = global_page_state(i);
97384 v += NR_VM_ZONE_STAT_ITEMS;
97385@@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
97386 put_online_cpus();
97387 #endif
97388 #ifdef CONFIG_PROC_FS
97389- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97390- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97391- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97392- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97393+ {
97394+ mode_t gr_mode = S_IRUGO;
97395+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97396+ gr_mode = S_IRUSR;
97397+#endif
97398+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97399+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97400+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97401+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97402+ }
97403 #endif
97404 return 0;
97405 }
97406diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97407index 44ebd5c..1f732bae 100644
97408--- a/net/8021q/vlan.c
97409+++ b/net/8021q/vlan.c
97410@@ -475,7 +475,7 @@ out:
97411 return NOTIFY_DONE;
97412 }
97413
97414-static struct notifier_block vlan_notifier_block __read_mostly = {
97415+static struct notifier_block vlan_notifier_block = {
97416 .notifier_call = vlan_device_event,
97417 };
97418
97419@@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97420 err = -EPERM;
97421 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97422 break;
97423- if ((args.u.name_type >= 0) &&
97424- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97425+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97426 struct vlan_net *vn;
97427
97428 vn = net_generic(net, vlan_net_id);
97429diff --git a/net/9p/client.c b/net/9p/client.c
97430index 9186550..e604a2f 100644
97431--- a/net/9p/client.c
97432+++ b/net/9p/client.c
97433@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97434 len - inline_len);
97435 } else {
97436 err = copy_from_user(ename + inline_len,
97437- uidata, len - inline_len);
97438+ (char __force_user *)uidata, len - inline_len);
97439 if (err) {
97440 err = -EFAULT;
97441 goto out_err;
97442@@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97443 kernel_buf = 1;
97444 indata = data;
97445 } else
97446- indata = (__force char *)udata;
97447+ indata = (__force_kernel char *)udata;
97448 /*
97449 * response header len is 11
97450 * PDU Header(7) + IO Size (4)
97451@@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97452 kernel_buf = 1;
97453 odata = data;
97454 } else
97455- odata = (char *)udata;
97456+ odata = (char __force_kernel *)udata;
97457 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97458 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97459 fid->fid, offset, rsize);
97460diff --git a/net/9p/mod.c b/net/9p/mod.c
97461index 6ab36ae..6f1841b 100644
97462--- a/net/9p/mod.c
97463+++ b/net/9p/mod.c
97464@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97465 void v9fs_register_trans(struct p9_trans_module *m)
97466 {
97467 spin_lock(&v9fs_trans_lock);
97468- list_add_tail(&m->list, &v9fs_trans_list);
97469+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97470 spin_unlock(&v9fs_trans_lock);
97471 }
97472 EXPORT_SYMBOL(v9fs_register_trans);
97473@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97474 void v9fs_unregister_trans(struct p9_trans_module *m)
97475 {
97476 spin_lock(&v9fs_trans_lock);
97477- list_del_init(&m->list);
97478+ pax_list_del_init((struct list_head *)&m->list);
97479 spin_unlock(&v9fs_trans_lock);
97480 }
97481 EXPORT_SYMBOL(v9fs_unregister_trans);
97482diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97483index b7bd7f2..2498bf7 100644
97484--- a/net/9p/trans_fd.c
97485+++ b/net/9p/trans_fd.c
97486@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97487 oldfs = get_fs();
97488 set_fs(get_ds());
97489 /* The cast to a user pointer is valid due to the set_fs() */
97490- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97491+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97492 set_fs(oldfs);
97493
97494 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97495diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97496index af46bc4..f9adfcd 100644
97497--- a/net/appletalk/atalk_proc.c
97498+++ b/net/appletalk/atalk_proc.c
97499@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97500 struct proc_dir_entry *p;
97501 int rc = -ENOMEM;
97502
97503- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97504+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97505 if (!atalk_proc_dir)
97506 goto out;
97507
97508diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97509index 876fbe8..8bbea9f 100644
97510--- a/net/atm/atm_misc.c
97511+++ b/net/atm/atm_misc.c
97512@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97513 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97514 return 1;
97515 atm_return(vcc, truesize);
97516- atomic_inc(&vcc->stats->rx_drop);
97517+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97518 return 0;
97519 }
97520 EXPORT_SYMBOL(atm_charge);
97521@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97522 }
97523 }
97524 atm_return(vcc, guess);
97525- atomic_inc(&vcc->stats->rx_drop);
97526+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97527 return NULL;
97528 }
97529 EXPORT_SYMBOL(atm_alloc_charge);
97530@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97531
97532 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97533 {
97534-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97535+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97536 __SONET_ITEMS
97537 #undef __HANDLE_ITEM
97538 }
97539@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97540
97541 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97542 {
97543-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97544+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97545 __SONET_ITEMS
97546 #undef __HANDLE_ITEM
97547 }
97548diff --git a/net/atm/lec.c b/net/atm/lec.c
97549index 5a2f602..9396143 100644
97550--- a/net/atm/lec.c
97551+++ b/net/atm/lec.c
97552@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97553 }
97554
97555 static struct lane2_ops lane2_ops = {
97556- lane2_resolve, /* resolve, spec 3.1.3 */
97557- lane2_associate_req, /* associate_req, spec 3.1.4 */
97558- NULL /* associate indicator, spec 3.1.5 */
97559+ .resolve = lane2_resolve,
97560+ .associate_req = lane2_associate_req,
97561+ .associate_indicator = NULL
97562 };
97563
97564 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97565diff --git a/net/atm/lec.h b/net/atm/lec.h
97566index 4149db1..f2ab682 100644
97567--- a/net/atm/lec.h
97568+++ b/net/atm/lec.h
97569@@ -48,7 +48,7 @@ struct lane2_ops {
97570 const u8 *tlvs, u32 sizeoftlvs);
97571 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97572 const u8 *tlvs, u32 sizeoftlvs);
97573-};
97574+} __no_const;
97575
97576 /*
97577 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97578diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97579index d1b2d9a..d549f7f 100644
97580--- a/net/atm/mpoa_caches.c
97581+++ b/net/atm/mpoa_caches.c
97582@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97583
97584
97585 static struct in_cache_ops ingress_ops = {
97586- in_cache_add_entry, /* add_entry */
97587- in_cache_get, /* get */
97588- in_cache_get_with_mask, /* get_with_mask */
97589- in_cache_get_by_vcc, /* get_by_vcc */
97590- in_cache_put, /* put */
97591- in_cache_remove_entry, /* remove_entry */
97592- cache_hit, /* cache_hit */
97593- clear_count_and_expired, /* clear_count */
97594- check_resolving_entries, /* check_resolving */
97595- refresh_entries, /* refresh */
97596- in_destroy_cache /* destroy_cache */
97597+ .add_entry = in_cache_add_entry,
97598+ .get = in_cache_get,
97599+ .get_with_mask = in_cache_get_with_mask,
97600+ .get_by_vcc = in_cache_get_by_vcc,
97601+ .put = in_cache_put,
97602+ .remove_entry = in_cache_remove_entry,
97603+ .cache_hit = cache_hit,
97604+ .clear_count = clear_count_and_expired,
97605+ .check_resolving = check_resolving_entries,
97606+ .refresh = refresh_entries,
97607+ .destroy_cache = in_destroy_cache
97608 };
97609
97610 static struct eg_cache_ops egress_ops = {
97611- eg_cache_add_entry, /* add_entry */
97612- eg_cache_get_by_cache_id, /* get_by_cache_id */
97613- eg_cache_get_by_tag, /* get_by_tag */
97614- eg_cache_get_by_vcc, /* get_by_vcc */
97615- eg_cache_get_by_src_ip, /* get_by_src_ip */
97616- eg_cache_put, /* put */
97617- eg_cache_remove_entry, /* remove_entry */
97618- update_eg_cache_entry, /* update */
97619- clear_expired, /* clear_expired */
97620- eg_destroy_cache /* destroy_cache */
97621+ .add_entry = eg_cache_add_entry,
97622+ .get_by_cache_id = eg_cache_get_by_cache_id,
97623+ .get_by_tag = eg_cache_get_by_tag,
97624+ .get_by_vcc = eg_cache_get_by_vcc,
97625+ .get_by_src_ip = eg_cache_get_by_src_ip,
97626+ .put = eg_cache_put,
97627+ .remove_entry = eg_cache_remove_entry,
97628+ .update = update_eg_cache_entry,
97629+ .clear_expired = clear_expired,
97630+ .destroy_cache = eg_destroy_cache
97631 };
97632
97633
97634diff --git a/net/atm/proc.c b/net/atm/proc.c
97635index bbb6461..cf04016 100644
97636--- a/net/atm/proc.c
97637+++ b/net/atm/proc.c
97638@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97639 const struct k_atm_aal_stats *stats)
97640 {
97641 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97642- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97643- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97644- atomic_read(&stats->rx_drop));
97645+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97646+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97647+ atomic_read_unchecked(&stats->rx_drop));
97648 }
97649
97650 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97651diff --git a/net/atm/resources.c b/net/atm/resources.c
97652index 0447d5d..3cf4728 100644
97653--- a/net/atm/resources.c
97654+++ b/net/atm/resources.c
97655@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97656 static void copy_aal_stats(struct k_atm_aal_stats *from,
97657 struct atm_aal_stats *to)
97658 {
97659-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97660+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97661 __AAL_STAT_ITEMS
97662 #undef __HANDLE_ITEM
97663 }
97664@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97665 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97666 struct atm_aal_stats *to)
97667 {
97668-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97669+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97670 __AAL_STAT_ITEMS
97671 #undef __HANDLE_ITEM
97672 }
97673diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97674index 919a5ce..cc6b444 100644
97675--- a/net/ax25/sysctl_net_ax25.c
97676+++ b/net/ax25/sysctl_net_ax25.c
97677@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97678 {
97679 char path[sizeof("net/ax25/") + IFNAMSIZ];
97680 int k;
97681- struct ctl_table *table;
97682+ ctl_table_no_const *table;
97683
97684 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97685 if (!table)
97686diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97687index d074d06..ad3cfcf 100644
97688--- a/net/batman-adv/bat_iv_ogm.c
97689+++ b/net/batman-adv/bat_iv_ogm.c
97690@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97691
97692 /* randomize initial seqno to avoid collision */
97693 get_random_bytes(&random_seqno, sizeof(random_seqno));
97694- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97695+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97696
97697 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97698 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97699@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97700 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97701
97702 /* change sequence number to network order */
97703- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97704+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97705 batadv_ogm_packet->seqno = htonl(seqno);
97706- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97707+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97708
97709 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97710
97711@@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97712 return;
97713
97714 /* could be changed by schedule_own_packet() */
97715- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97716+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97717
97718 if (ogm_packet->flags & BATADV_DIRECTLINK)
97719 has_directlink_flag = true;
97720diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97721index cc1cfd6..7a68e022 100644
97722--- a/net/batman-adv/fragmentation.c
97723+++ b/net/batman-adv/fragmentation.c
97724@@ -446,7 +446,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97725 frag_header.packet_type = BATADV_UNICAST_FRAG;
97726 frag_header.version = BATADV_COMPAT_VERSION;
97727 frag_header.ttl = BATADV_TTL;
97728- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97729+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97730 frag_header.reserved = 0;
97731 frag_header.no = 0;
97732 frag_header.total_size = htons(skb->len);
97733diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97734index f82c267..0e56d32 100644
97735--- a/net/batman-adv/soft-interface.c
97736+++ b/net/batman-adv/soft-interface.c
97737@@ -283,7 +283,7 @@ send:
97738 primary_if->net_dev->dev_addr, ETH_ALEN);
97739
97740 /* set broadcast sequence number */
97741- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97742+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97743 bcast_packet->seqno = htonl(seqno);
97744
97745 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97746@@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97747 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97748
97749 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97750- atomic_set(&bat_priv->bcast_seqno, 1);
97751+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97752 atomic_set(&bat_priv->tt.vn, 0);
97753 atomic_set(&bat_priv->tt.local_changes, 0);
97754 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97755@@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97756
97757 /* randomize initial seqno to avoid collision */
97758 get_random_bytes(&random_seqno, sizeof(random_seqno));
97759- atomic_set(&bat_priv->frag_seqno, random_seqno);
97760+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97761
97762 bat_priv->primary_if = NULL;
97763 bat_priv->num_ifaces = 0;
97764diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97765index 78370ab..1cb3614 100644
97766--- a/net/batman-adv/types.h
97767+++ b/net/batman-adv/types.h
97768@@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
97769 struct batadv_hard_iface_bat_iv {
97770 unsigned char *ogm_buff;
97771 int ogm_buff_len;
97772- atomic_t ogm_seqno;
97773+ atomic_unchecked_t ogm_seqno;
97774 };
97775
97776 /**
97777@@ -714,7 +714,7 @@ struct batadv_priv {
97778 atomic_t bonding;
97779 atomic_t fragmentation;
97780 atomic_t packet_size_max;
97781- atomic_t frag_seqno;
97782+ atomic_unchecked_t frag_seqno;
97783 #ifdef CONFIG_BATMAN_ADV_BLA
97784 atomic_t bridge_loop_avoidance;
97785 #endif
97786@@ -730,7 +730,7 @@ struct batadv_priv {
97787 #endif
97788 uint32_t isolation_mark;
97789 uint32_t isolation_mark_mask;
97790- atomic_t bcast_seqno;
97791+ atomic_unchecked_t bcast_seqno;
97792 atomic_t bcast_queue_left;
97793 atomic_t batman_queue_left;
97794 char num_ifaces;
97795diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97796index 7552f9e..074ce29 100644
97797--- a/net/bluetooth/hci_sock.c
97798+++ b/net/bluetooth/hci_sock.c
97799@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97800 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97801 }
97802
97803- len = min_t(unsigned int, len, sizeof(uf));
97804+ len = min((size_t)len, sizeof(uf));
97805 if (copy_from_user(&uf, optval, len)) {
97806 err = -EFAULT;
97807 break;
97808diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97809index 6afa3b4..7a14180 100644
97810--- a/net/bluetooth/l2cap_core.c
97811+++ b/net/bluetooth/l2cap_core.c
97812@@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
97813 break;
97814
97815 case L2CAP_CONF_RFC:
97816- if (olen == sizeof(rfc))
97817- memcpy(&rfc, (void *)val, olen);
97818+ if (olen != sizeof(rfc))
97819+ break;
97820+
97821+ memcpy(&rfc, (void *)val, olen);
97822
97823 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
97824 rfc.mode != chan->mode)
97825diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
97826index d58f76b..b69600a 100644
97827--- a/net/bluetooth/l2cap_sock.c
97828+++ b/net/bluetooth/l2cap_sock.c
97829@@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97830 struct sock *sk = sock->sk;
97831 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
97832 struct l2cap_options opts;
97833- int len, err = 0;
97834+ int err = 0;
97835+ size_t len = optlen;
97836 u32 opt;
97837
97838 BT_DBG("sk %p", sk);
97839@@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97840 opts.max_tx = chan->max_tx;
97841 opts.txwin_size = chan->tx_win;
97842
97843- len = min_t(unsigned int, sizeof(opts), optlen);
97844+ len = min(sizeof(opts), len);
97845 if (copy_from_user((char *) &opts, optval, len)) {
97846 err = -EFAULT;
97847 break;
97848@@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97849 struct bt_security sec;
97850 struct bt_power pwr;
97851 struct l2cap_conn *conn;
97852- int len, err = 0;
97853+ int err = 0;
97854+ size_t len = optlen;
97855 u32 opt;
97856
97857 BT_DBG("sk %p", sk);
97858@@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97859
97860 sec.level = BT_SECURITY_LOW;
97861
97862- len = min_t(unsigned int, sizeof(sec), optlen);
97863+ len = min(sizeof(sec), len);
97864 if (copy_from_user((char *) &sec, optval, len)) {
97865 err = -EFAULT;
97866 break;
97867@@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97868
97869 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
97870
97871- len = min_t(unsigned int, sizeof(pwr), optlen);
97872+ len = min(sizeof(pwr), len);
97873 if (copy_from_user((char *) &pwr, optval, len)) {
97874 err = -EFAULT;
97875 break;
97876diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97877index 3c2d3e4..884855a 100644
97878--- a/net/bluetooth/rfcomm/sock.c
97879+++ b/net/bluetooth/rfcomm/sock.c
97880@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97881 struct sock *sk = sock->sk;
97882 struct bt_security sec;
97883 int err = 0;
97884- size_t len;
97885+ size_t len = optlen;
97886 u32 opt;
97887
97888 BT_DBG("sk %p", sk);
97889@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97890
97891 sec.level = BT_SECURITY_LOW;
97892
97893- len = min_t(unsigned int, sizeof(sec), optlen);
97894+ len = min(sizeof(sec), len);
97895 if (copy_from_user((char *) &sec, optval, len)) {
97896 err = -EFAULT;
97897 break;
97898diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97899index f9c0980a..fcbbfeb 100644
97900--- a/net/bluetooth/rfcomm/tty.c
97901+++ b/net/bluetooth/rfcomm/tty.c
97902@@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97903 BT_DBG("tty %p id %d", tty, tty->index);
97904
97905 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97906- dev->channel, dev->port.count);
97907+ dev->channel, atomic_read(&dev->port.count));
97908
97909 err = tty_port_open(&dev->port, tty, filp);
97910 if (err)
97911@@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97912 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97913
97914 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97915- dev->port.count);
97916+ atomic_read(&dev->port.count));
97917
97918 tty_port_close(&dev->port, tty, filp);
97919 }
97920diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97921index 1059ed3..d70846a 100644
97922--- a/net/bridge/netfilter/ebtables.c
97923+++ b/net/bridge/netfilter/ebtables.c
97924@@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97925 tmp.valid_hooks = t->table->valid_hooks;
97926 }
97927 mutex_unlock(&ebt_mutex);
97928- if (copy_to_user(user, &tmp, *len) != 0) {
97929+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97930 BUGPRINT("c2u Didn't work\n");
97931 ret = -EFAULT;
97932 break;
97933@@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97934 goto out;
97935 tmp.valid_hooks = t->valid_hooks;
97936
97937- if (copy_to_user(user, &tmp, *len) != 0) {
97938+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97939 ret = -EFAULT;
97940 break;
97941 }
97942@@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97943 tmp.entries_size = t->table->entries_size;
97944 tmp.valid_hooks = t->table->valid_hooks;
97945
97946- if (copy_to_user(user, &tmp, *len) != 0) {
97947+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97948 ret = -EFAULT;
97949 break;
97950 }
97951diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97952index 0f45522..dab651f 100644
97953--- a/net/caif/cfctrl.c
97954+++ b/net/caif/cfctrl.c
97955@@ -10,6 +10,7 @@
97956 #include <linux/spinlock.h>
97957 #include <linux/slab.h>
97958 #include <linux/pkt_sched.h>
97959+#include <linux/sched.h>
97960 #include <net/caif/caif_layer.h>
97961 #include <net/caif/cfpkt.h>
97962 #include <net/caif/cfctrl.h>
97963@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97964 memset(&dev_info, 0, sizeof(dev_info));
97965 dev_info.id = 0xff;
97966 cfsrvl_init(&this->serv, 0, &dev_info, false);
97967- atomic_set(&this->req_seq_no, 1);
97968- atomic_set(&this->rsp_seq_no, 1);
97969+ atomic_set_unchecked(&this->req_seq_no, 1);
97970+ atomic_set_unchecked(&this->rsp_seq_no, 1);
97971 this->serv.layer.receive = cfctrl_recv;
97972 sprintf(this->serv.layer.name, "ctrl");
97973 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97974@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97975 struct cfctrl_request_info *req)
97976 {
97977 spin_lock_bh(&ctrl->info_list_lock);
97978- atomic_inc(&ctrl->req_seq_no);
97979- req->sequence_no = atomic_read(&ctrl->req_seq_no);
97980+ atomic_inc_unchecked(&ctrl->req_seq_no);
97981+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97982 list_add_tail(&req->list, &ctrl->list);
97983 spin_unlock_bh(&ctrl->info_list_lock);
97984 }
97985@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97986 if (p != first)
97987 pr_warn("Requests are not received in order\n");
97988
97989- atomic_set(&ctrl->rsp_seq_no,
97990+ atomic_set_unchecked(&ctrl->rsp_seq_no,
97991 p->sequence_no);
97992 list_del(&p->list);
97993 goto out;
97994diff --git a/net/can/af_can.c b/net/can/af_can.c
97995index a27f8aa..67174a3 100644
97996--- a/net/can/af_can.c
97997+++ b/net/can/af_can.c
97998@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97999 };
98000
98001 /* notifier block for netdevice event */
98002-static struct notifier_block can_netdev_notifier __read_mostly = {
98003+static struct notifier_block can_netdev_notifier = {
98004 .notifier_call = can_notifier,
98005 };
98006
98007diff --git a/net/can/bcm.c b/net/can/bcm.c
98008index dcb75c0..24b1b43 100644
98009--- a/net/can/bcm.c
98010+++ b/net/can/bcm.c
98011@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
98012 }
98013
98014 /* create /proc/net/can-bcm directory */
98015- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
98016+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
98017 return 0;
98018 }
98019
98020diff --git a/net/can/gw.c b/net/can/gw.c
98021index ac31891..4799c17 100644
98022--- a/net/can/gw.c
98023+++ b/net/can/gw.c
98024@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
98025 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
98026
98027 static HLIST_HEAD(cgw_list);
98028-static struct notifier_block notifier;
98029
98030 static struct kmem_cache *cgw_cache __read_mostly;
98031
98032@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
98033 return err;
98034 }
98035
98036+static struct notifier_block notifier = {
98037+ .notifier_call = cgw_notifier
98038+};
98039+
98040 static __init int cgw_module_init(void)
98041 {
98042 /* sanitize given module parameter */
98043@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
98044 return -ENOMEM;
98045
98046 /* set notifier */
98047- notifier.notifier_call = cgw_notifier;
98048 register_netdevice_notifier(&notifier);
98049
98050 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
98051diff --git a/net/can/proc.c b/net/can/proc.c
98052index b543470..d2ddae2 100644
98053--- a/net/can/proc.c
98054+++ b/net/can/proc.c
98055@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
98056 void can_init_proc(void)
98057 {
98058 /* create /proc/net/can directory */
98059- can_dir = proc_mkdir("can", init_net.proc_net);
98060+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
98061
98062 if (!can_dir) {
98063 printk(KERN_INFO "can: failed to create /proc/net/can . "
98064diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
98065index 988721a..947846d 100644
98066--- a/net/ceph/messenger.c
98067+++ b/net/ceph/messenger.c
98068@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
98069 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
98070
98071 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
98072-static atomic_t addr_str_seq = ATOMIC_INIT(0);
98073+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
98074
98075 static struct page *zero_page; /* used in certain error cases */
98076
98077@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
98078 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
98079 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
98080
98081- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98082+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98083 s = addr_str[i];
98084
98085 switch (ss->ss_family) {
98086diff --git a/net/compat.c b/net/compat.c
98087index f50161f..94fa415 100644
98088--- a/net/compat.c
98089+++ b/net/compat.c
98090@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
98091 return -EFAULT;
98092 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
98093 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
98094- kmsg->msg_name = compat_ptr(tmp1);
98095- kmsg->msg_iov = compat_ptr(tmp2);
98096- kmsg->msg_control = compat_ptr(tmp3);
98097+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
98098+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
98099+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
98100 return 0;
98101 }
98102
98103@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98104
98105 if (kern_msg->msg_namelen) {
98106 if (mode == VERIFY_READ) {
98107- int err = move_addr_to_kernel(kern_msg->msg_name,
98108+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
98109 kern_msg->msg_namelen,
98110 kern_address);
98111 if (err < 0)
98112@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98113 kern_msg->msg_name = NULL;
98114
98115 tot_len = iov_from_user_compat_to_kern(kern_iov,
98116- (struct compat_iovec __user *)kern_msg->msg_iov,
98117+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
98118 kern_msg->msg_iovlen);
98119 if (tot_len >= 0)
98120 kern_msg->msg_iov = kern_iov;
98121@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98122
98123 #define CMSG_COMPAT_FIRSTHDR(msg) \
98124 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
98125- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
98126+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
98127 (struct compat_cmsghdr __user *)NULL)
98128
98129 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
98130 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
98131 (ucmlen) <= (unsigned long) \
98132 ((mhdr)->msg_controllen - \
98133- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
98134+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
98135
98136 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
98137 struct compat_cmsghdr __user *cmsg, int cmsg_len)
98138 {
98139 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
98140- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
98141+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
98142 msg->msg_controllen)
98143 return NULL;
98144 return (struct compat_cmsghdr __user *)ptr;
98145@@ -222,7 +222,7 @@ Efault:
98146
98147 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
98148 {
98149- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98150+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98151 struct compat_cmsghdr cmhdr;
98152 struct compat_timeval ctv;
98153 struct compat_timespec cts[3];
98154@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
98155
98156 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
98157 {
98158- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98159+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98160 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
98161 int fdnum = scm->fp->count;
98162 struct file **fp = scm->fp->fp;
98163@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
98164 return -EFAULT;
98165 old_fs = get_fs();
98166 set_fs(KERNEL_DS);
98167- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
98168+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
98169 set_fs(old_fs);
98170
98171 return err;
98172@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
98173 len = sizeof(ktime);
98174 old_fs = get_fs();
98175 set_fs(KERNEL_DS);
98176- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
98177+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
98178 set_fs(old_fs);
98179
98180 if (!err) {
98181@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98182 case MCAST_JOIN_GROUP:
98183 case MCAST_LEAVE_GROUP:
98184 {
98185- struct compat_group_req __user *gr32 = (void *)optval;
98186+ struct compat_group_req __user *gr32 = (void __user *)optval;
98187 struct group_req __user *kgr =
98188 compat_alloc_user_space(sizeof(struct group_req));
98189 u32 interface;
98190@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98191 case MCAST_BLOCK_SOURCE:
98192 case MCAST_UNBLOCK_SOURCE:
98193 {
98194- struct compat_group_source_req __user *gsr32 = (void *)optval;
98195+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
98196 struct group_source_req __user *kgsr = compat_alloc_user_space(
98197 sizeof(struct group_source_req));
98198 u32 interface;
98199@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98200 }
98201 case MCAST_MSFILTER:
98202 {
98203- struct compat_group_filter __user *gf32 = (void *)optval;
98204+ struct compat_group_filter __user *gf32 = (void __user *)optval;
98205 struct group_filter __user *kgf;
98206 u32 interface, fmode, numsrc;
98207
98208@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
98209 char __user *optval, int __user *optlen,
98210 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
98211 {
98212- struct compat_group_filter __user *gf32 = (void *)optval;
98213+ struct compat_group_filter __user *gf32 = (void __user *)optval;
98214 struct group_filter __user *kgf;
98215 int __user *koptlen;
98216 u32 interface, fmode, numsrc;
98217@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
98218
98219 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
98220 return -EINVAL;
98221- if (copy_from_user(a, args, nas[call]))
98222+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
98223 return -EFAULT;
98224 a0 = a[0];
98225 a1 = a[1];
98226diff --git a/net/core/datagram.c b/net/core/datagram.c
98227index a16ed7b..eb44d17 100644
98228--- a/net/core/datagram.c
98229+++ b/net/core/datagram.c
98230@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
98231 }
98232
98233 kfree_skb(skb);
98234- atomic_inc(&sk->sk_drops);
98235+ atomic_inc_unchecked(&sk->sk_drops);
98236 sk_mem_reclaim_partial(sk);
98237
98238 return err;
98239diff --git a/net/core/dev.c b/net/core/dev.c
98240index fccc195..c8486ab 100644
98241--- a/net/core/dev.c
98242+++ b/net/core/dev.c
98243@@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
98244 {
98245 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
98246 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
98247- atomic_long_inc(&dev->rx_dropped);
98248+ atomic_long_inc_unchecked(&dev->rx_dropped);
98249 kfree_skb(skb);
98250 return NET_RX_DROP;
98251 }
98252 }
98253
98254 if (unlikely(!is_skb_forwardable(dev, skb))) {
98255- atomic_long_inc(&dev->rx_dropped);
98256+ atomic_long_inc_unchecked(&dev->rx_dropped);
98257 kfree_skb(skb);
98258 return NET_RX_DROP;
98259 }
98260@@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
98261
98262 struct dev_gso_cb {
98263 void (*destructor)(struct sk_buff *skb);
98264-};
98265+} __no_const;
98266
98267 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
98268
98269@@ -3227,7 +3227,7 @@ enqueue:
98270
98271 local_irq_restore(flags);
98272
98273- atomic_long_inc(&skb->dev->rx_dropped);
98274+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98275 kfree_skb(skb);
98276 return NET_RX_DROP;
98277 }
98278@@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
98279 }
98280 EXPORT_SYMBOL(netif_rx_ni);
98281
98282-static void net_tx_action(struct softirq_action *h)
98283+static __latent_entropy void net_tx_action(void)
98284 {
98285 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98286
98287@@ -3645,7 +3645,7 @@ ncls:
98288 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
98289 } else {
98290 drop:
98291- atomic_long_inc(&skb->dev->rx_dropped);
98292+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98293 kfree_skb(skb);
98294 /* Jamal, now you will not able to escape explaining
98295 * me how you were going to use this. :-)
98296@@ -4333,7 +4333,7 @@ void netif_napi_del(struct napi_struct *napi)
98297 }
98298 EXPORT_SYMBOL(netif_napi_del);
98299
98300-static void net_rx_action(struct softirq_action *h)
98301+static __latent_entropy void net_rx_action(void)
98302 {
98303 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98304 unsigned long time_limit = jiffies + 2;
98305@@ -6302,7 +6302,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
98306 } else {
98307 netdev_stats_to_stats64(storage, &dev->stats);
98308 }
98309- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
98310+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
98311 return storage;
98312 }
98313 EXPORT_SYMBOL(dev_get_stats);
98314diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
98315index cf999e0..c59a975 100644
98316--- a/net/core/dev_ioctl.c
98317+++ b/net/core/dev_ioctl.c
98318@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
98319 if (no_module && capable(CAP_NET_ADMIN))
98320 no_module = request_module("netdev-%s", name);
98321 if (no_module && capable(CAP_SYS_MODULE)) {
98322+#ifdef CONFIG_GRKERNSEC_MODHARDEN
98323+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
98324+#else
98325 if (!request_module("%s", name))
98326 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
98327 name);
98328+#endif
98329 }
98330 }
98331 EXPORT_SYMBOL(dev_load);
98332diff --git a/net/core/filter.c b/net/core/filter.c
98333index ebce437..9fed9d0 100644
98334--- a/net/core/filter.c
98335+++ b/net/core/filter.c
98336@@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
98337 void *ptr;
98338 u32 A = 0; /* Accumulator */
98339 u32 X = 0; /* Index Register */
98340- u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
98341+ u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
98342 u32 tmp;
98343 int k;
98344
98345@@ -292,10 +292,10 @@ load_b:
98346 X = K;
98347 continue;
98348 case BPF_S_LD_MEM:
98349- A = mem[K];
98350+ A = mem[K&15];
98351 continue;
98352 case BPF_S_LDX_MEM:
98353- X = mem[K];
98354+ X = mem[K&15];
98355 continue;
98356 case BPF_S_MISC_TAX:
98357 X = A;
98358@@ -308,10 +308,10 @@ load_b:
98359 case BPF_S_RET_A:
98360 return A;
98361 case BPF_S_ST:
98362- mem[K] = A;
98363+ mem[K&15] = A;
98364 continue;
98365 case BPF_S_STX:
98366- mem[K] = X;
98367+ mem[K&15] = X;
98368 continue;
98369 case BPF_S_ANC_PROTOCOL:
98370 A = ntohs(skb->protocol);
98371@@ -395,9 +395,10 @@ load_b:
98372 continue;
98373 #endif
98374 default:
98375- WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
98376+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98377 fentry->code, fentry->jt,
98378 fentry->jf, fentry->k);
98379+ BUG();
98380 return 0;
98381 }
98382 }
98383@@ -420,7 +421,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98384 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98385 int pc, ret = 0;
98386
98387- BUILD_BUG_ON(BPF_MEMWORDS > 16);
98388+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
98389 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98390 if (!masks)
98391 return -ENOMEM;
98392@@ -683,7 +684,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98393 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
98394 if (!fp)
98395 return -ENOMEM;
98396- memcpy(fp->insns, fprog->filter, fsize);
98397+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98398
98399 atomic_set(&fp->refcnt, 1);
98400 fp->len = fprog->len;
98401diff --git a/net/core/flow.c b/net/core/flow.c
98402index dfa602c..3103d88 100644
98403--- a/net/core/flow.c
98404+++ b/net/core/flow.c
98405@@ -61,7 +61,7 @@ struct flow_cache {
98406 struct timer_list rnd_timer;
98407 };
98408
98409-atomic_t flow_cache_genid = ATOMIC_INIT(0);
98410+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
98411 EXPORT_SYMBOL(flow_cache_genid);
98412 static struct flow_cache flow_cache_global;
98413 static struct kmem_cache *flow_cachep __read_mostly;
98414@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98415
98416 static int flow_entry_valid(struct flow_cache_entry *fle)
98417 {
98418- if (atomic_read(&flow_cache_genid) != fle->genid)
98419+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
98420 return 0;
98421 if (fle->object && !fle->object->ops->check(fle->object))
98422 return 0;
98423@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98424 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98425 fcp->hash_count++;
98426 }
98427- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
98428+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
98429 flo = fle->object;
98430 if (!flo)
98431 goto ret_object;
98432@@ -279,7 +279,7 @@ nocache:
98433 }
98434 flo = resolver(net, key, family, dir, flo, ctx);
98435 if (fle) {
98436- fle->genid = atomic_read(&flow_cache_genid);
98437+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
98438 if (!IS_ERR(flo))
98439 fle->object = flo;
98440 else
98441diff --git a/net/core/iovec.c b/net/core/iovec.c
98442index b618694..192bbba 100644
98443--- a/net/core/iovec.c
98444+++ b/net/core/iovec.c
98445@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98446 if (m->msg_namelen) {
98447 if (mode == VERIFY_READ) {
98448 void __user *namep;
98449- namep = (void __user __force *) m->msg_name;
98450+ namep = (void __force_user *) m->msg_name;
98451 err = move_addr_to_kernel(namep, m->msg_namelen,
98452 address);
98453 if (err < 0)
98454@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98455 }
98456
98457 size = m->msg_iovlen * sizeof(struct iovec);
98458- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98459+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98460 return -EFAULT;
98461
98462 m->msg_iov = iov;
98463diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98464index 7d95f69..a6065de 100644
98465--- a/net/core/neighbour.c
98466+++ b/net/core/neighbour.c
98467@@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98468 void __user *buffer, size_t *lenp, loff_t *ppos)
98469 {
98470 int size, ret;
98471- struct ctl_table tmp = *ctl;
98472+ ctl_table_no_const tmp = *ctl;
98473
98474 tmp.extra1 = &zero;
98475 tmp.extra2 = &unres_qlen_max;
98476@@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98477 void __user *buffer,
98478 size_t *lenp, loff_t *ppos)
98479 {
98480- struct ctl_table tmp = *ctl;
98481+ ctl_table_no_const tmp = *ctl;
98482 int ret;
98483
98484 tmp.extra1 = &zero;
98485@@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98486 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98487 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98488 } else {
98489+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98490 dev_name_source = "default";
98491- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98492- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98493- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98494- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98495+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98496+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98497+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98498+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98499 }
98500
98501 if (handler) {
98502diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98503index 2bf8329..2eb1423 100644
98504--- a/net/core/net-procfs.c
98505+++ b/net/core/net-procfs.c
98506@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98507 struct rtnl_link_stats64 temp;
98508 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98509
98510- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98511+ if (gr_proc_is_restricted())
98512+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98513+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98514+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98515+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98516+ else
98517+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98518 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98519 dev->name, stats->rx_bytes, stats->rx_packets,
98520 stats->rx_errors,
98521@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98522 return 0;
98523 }
98524
98525-static const struct seq_operations dev_seq_ops = {
98526+const struct seq_operations dev_seq_ops = {
98527 .start = dev_seq_start,
98528 .next = dev_seq_next,
98529 .stop = dev_seq_stop,
98530@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98531
98532 static int softnet_seq_open(struct inode *inode, struct file *file)
98533 {
98534- return seq_open(file, &softnet_seq_ops);
98535+ return seq_open_restrict(file, &softnet_seq_ops);
98536 }
98537
98538 static const struct file_operations softnet_seq_fops = {
98539@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98540 else
98541 seq_printf(seq, "%04x", ntohs(pt->type));
98542
98543+#ifdef CONFIG_GRKERNSEC_HIDESYM
98544+ seq_printf(seq, " %-8s %pf\n",
98545+ pt->dev ? pt->dev->name : "", NULL);
98546+#else
98547 seq_printf(seq, " %-8s %pf\n",
98548 pt->dev ? pt->dev->name : "", pt->func);
98549+#endif
98550 }
98551
98552 return 0;
98553diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98554index 7c8ffd9..0cb3687 100644
98555--- a/net/core/net_namespace.c
98556+++ b/net/core/net_namespace.c
98557@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98558 int error;
98559 LIST_HEAD(net_exit_list);
98560
98561- list_add_tail(&ops->list, list);
98562+ pax_list_add_tail((struct list_head *)&ops->list, list);
98563 if (ops->init || (ops->id && ops->size)) {
98564 for_each_net(net) {
98565 error = ops_init(ops, net);
98566@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98567
98568 out_undo:
98569 /* If I have an error cleanup all namespaces I initialized */
98570- list_del(&ops->list);
98571+ pax_list_del((struct list_head *)&ops->list);
98572 ops_exit_list(ops, &net_exit_list);
98573 ops_free_list(ops, &net_exit_list);
98574 return error;
98575@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98576 struct net *net;
98577 LIST_HEAD(net_exit_list);
98578
98579- list_del(&ops->list);
98580+ pax_list_del((struct list_head *)&ops->list);
98581 for_each_net(net)
98582 list_add_tail(&net->exit_list, &net_exit_list);
98583 ops_exit_list(ops, &net_exit_list);
98584@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98585 mutex_lock(&net_mutex);
98586 error = register_pernet_operations(&pernet_list, ops);
98587 if (!error && (first_device == &pernet_list))
98588- first_device = &ops->list;
98589+ first_device = (struct list_head *)&ops->list;
98590 mutex_unlock(&net_mutex);
98591 return error;
98592 }
98593diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98594index df9e6b1..6e68e4e 100644
98595--- a/net/core/netpoll.c
98596+++ b/net/core/netpoll.c
98597@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98598 struct udphdr *udph;
98599 struct iphdr *iph;
98600 struct ethhdr *eth;
98601- static atomic_t ip_ident;
98602+ static atomic_unchecked_t ip_ident;
98603 struct ipv6hdr *ip6h;
98604
98605 udp_len = len + sizeof(*udph);
98606@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98607 put_unaligned(0x45, (unsigned char *)iph);
98608 iph->tos = 0;
98609 put_unaligned(htons(ip_len), &(iph->tot_len));
98610- iph->id = htons(atomic_inc_return(&ip_ident));
98611+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98612 iph->frag_off = 0;
98613 iph->ttl = 64;
98614 iph->protocol = IPPROTO_UDP;
98615diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98616index fdac61c..e5e5b46 100644
98617--- a/net/core/pktgen.c
98618+++ b/net/core/pktgen.c
98619@@ -3719,7 +3719,7 @@ static int __net_init pg_net_init(struct net *net)
98620 pn->net = net;
98621 INIT_LIST_HEAD(&pn->pktgen_threads);
98622 pn->pktgen_exiting = false;
98623- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98624+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98625 if (!pn->proc_dir) {
98626 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98627 return -ENODEV;
98628diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98629index 83b9d6a..cff1ce7 100644
98630--- a/net/core/rtnetlink.c
98631+++ b/net/core/rtnetlink.c
98632@@ -58,7 +58,7 @@ struct rtnl_link {
98633 rtnl_doit_func doit;
98634 rtnl_dumpit_func dumpit;
98635 rtnl_calcit_func calcit;
98636-};
98637+} __no_const;
98638
98639 static DEFINE_MUTEX(rtnl_mutex);
98640
98641@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98642 if (rtnl_link_ops_get(ops->kind))
98643 return -EEXIST;
98644
98645- if (!ops->dellink)
98646- ops->dellink = unregister_netdevice_queue;
98647+ if (!ops->dellink) {
98648+ pax_open_kernel();
98649+ *(void **)&ops->dellink = unregister_netdevice_queue;
98650+ pax_close_kernel();
98651+ }
98652
98653- list_add_tail(&ops->list, &link_ops);
98654+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98655 return 0;
98656 }
98657 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98658@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98659 for_each_net(net) {
98660 __rtnl_kill_links(net, ops);
98661 }
98662- list_del(&ops->list);
98663+ pax_list_del((struct list_head *)&ops->list);
98664 }
98665 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98666
98667diff --git a/net/core/scm.c b/net/core/scm.c
98668index b442e7e..6f5b5a2 100644
98669--- a/net/core/scm.c
98670+++ b/net/core/scm.c
98671@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98672 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98673 {
98674 struct cmsghdr __user *cm
98675- = (__force struct cmsghdr __user *)msg->msg_control;
98676+ = (struct cmsghdr __force_user *)msg->msg_control;
98677 struct cmsghdr cmhdr;
98678 int cmlen = CMSG_LEN(len);
98679 int err;
98680@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98681 err = -EFAULT;
98682 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98683 goto out;
98684- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98685+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98686 goto out;
98687 cmlen = CMSG_SPACE(len);
98688 if (msg->msg_controllen < cmlen)
98689@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98690 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98691 {
98692 struct cmsghdr __user *cm
98693- = (__force struct cmsghdr __user*)msg->msg_control;
98694+ = (struct cmsghdr __force_user *)msg->msg_control;
98695
98696 int fdmax = 0;
98697 int fdnum = scm->fp->count;
98698@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98699 if (fdnum < fdmax)
98700 fdmax = fdnum;
98701
98702- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98703+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98704 i++, cmfptr++)
98705 {
98706 struct socket *sock;
98707diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98708index e5ae776e..15c90cb 100644
98709--- a/net/core/skbuff.c
98710+++ b/net/core/skbuff.c
98711@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98712 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98713 int len, __wsum csum)
98714 {
98715- const struct skb_checksum_ops ops = {
98716+ static const struct skb_checksum_ops ops = {
98717 .update = csum_partial_ext,
98718 .combine = csum_block_add_ext,
98719 };
98720@@ -3220,13 +3220,15 @@ void __init skb_init(void)
98721 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98722 sizeof(struct sk_buff),
98723 0,
98724- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98725+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98726+ SLAB_NO_SANITIZE,
98727 NULL);
98728 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98729 (2*sizeof(struct sk_buff)) +
98730 sizeof(atomic_t),
98731 0,
98732- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98733+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98734+ SLAB_NO_SANITIZE,
98735 NULL);
98736 }
98737
98738diff --git a/net/core/sock.c b/net/core/sock.c
98739index c0fc6bd..51d8326 100644
98740--- a/net/core/sock.c
98741+++ b/net/core/sock.c
98742@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98743 struct sk_buff_head *list = &sk->sk_receive_queue;
98744
98745 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98746- atomic_inc(&sk->sk_drops);
98747+ atomic_inc_unchecked(&sk->sk_drops);
98748 trace_sock_rcvqueue_full(sk, skb);
98749 return -ENOMEM;
98750 }
98751@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98752 return err;
98753
98754 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98755- atomic_inc(&sk->sk_drops);
98756+ atomic_inc_unchecked(&sk->sk_drops);
98757 return -ENOBUFS;
98758 }
98759
98760@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98761 skb_dst_force(skb);
98762
98763 spin_lock_irqsave(&list->lock, flags);
98764- skb->dropcount = atomic_read(&sk->sk_drops);
98765+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98766 __skb_queue_tail(list, skb);
98767 spin_unlock_irqrestore(&list->lock, flags);
98768
98769@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98770 skb->dev = NULL;
98771
98772 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98773- atomic_inc(&sk->sk_drops);
98774+ atomic_inc_unchecked(&sk->sk_drops);
98775 goto discard_and_relse;
98776 }
98777 if (nested)
98778@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98779 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98780 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98781 bh_unlock_sock(sk);
98782- atomic_inc(&sk->sk_drops);
98783+ atomic_inc_unchecked(&sk->sk_drops);
98784 goto discard_and_relse;
98785 }
98786
98787@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98788 struct timeval tm;
98789 } v;
98790
98791- int lv = sizeof(int);
98792- int len;
98793+ unsigned int lv = sizeof(int);
98794+ unsigned int len;
98795
98796 if (get_user(len, optlen))
98797 return -EFAULT;
98798- if (len < 0)
98799+ if (len > INT_MAX)
98800 return -EINVAL;
98801
98802 memset(&v, 0, sizeof(v));
98803@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98804
98805 case SO_PEERNAME:
98806 {
98807- char address[128];
98808+ char address[_K_SS_MAXSIZE];
98809
98810 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98811 return -ENOTCONN;
98812- if (lv < len)
98813+ if (lv < len || sizeof address < len)
98814 return -EINVAL;
98815 if (copy_to_user(optval, address, len))
98816 return -EFAULT;
98817@@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98818
98819 if (len > lv)
98820 len = lv;
98821- if (copy_to_user(optval, &v, len))
98822+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
98823 return -EFAULT;
98824 lenout:
98825 if (put_user(len, optlen))
98826@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
98827 */
98828 smp_wmb();
98829 atomic_set(&sk->sk_refcnt, 1);
98830- atomic_set(&sk->sk_drops, 0);
98831+ atomic_set_unchecked(&sk->sk_drops, 0);
98832 }
98833 EXPORT_SYMBOL(sock_init_data);
98834
98835@@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
98836 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98837 int level, int type)
98838 {
98839+ struct sock_extended_err ee;
98840 struct sock_exterr_skb *serr;
98841 struct sk_buff *skb, *skb2;
98842 int copied, err;
98843@@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98844 sock_recv_timestamp(msg, sk, skb);
98845
98846 serr = SKB_EXT_ERR(skb);
98847- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98848+ ee = serr->ee;
98849+ put_cmsg(msg, level, type, sizeof ee, &ee);
98850
98851 msg->msg_flags |= MSG_ERRQUEUE;
98852 err = copied;
98853diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98854index 6a7fae2..d7c22e6 100644
98855--- a/net/core/sock_diag.c
98856+++ b/net/core/sock_diag.c
98857@@ -9,26 +9,33 @@
98858 #include <linux/inet_diag.h>
98859 #include <linux/sock_diag.h>
98860
98861-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98862+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98863 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98864 static DEFINE_MUTEX(sock_diag_table_mutex);
98865
98866 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98867 {
98868+#ifndef CONFIG_GRKERNSEC_HIDESYM
98869 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98870 cookie[1] != INET_DIAG_NOCOOKIE) &&
98871 ((u32)(unsigned long)sk != cookie[0] ||
98872 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98873 return -ESTALE;
98874 else
98875+#endif
98876 return 0;
98877 }
98878 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98879
98880 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98881 {
98882+#ifdef CONFIG_GRKERNSEC_HIDESYM
98883+ cookie[0] = 0;
98884+ cookie[1] = 0;
98885+#else
98886 cookie[0] = (u32)(unsigned long)sk;
98887 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98888+#endif
98889 }
98890 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98891
98892@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98893 mutex_lock(&sock_diag_table_mutex);
98894 if (sock_diag_handlers[hndl->family])
98895 err = -EBUSY;
98896- else
98897+ else {
98898+ pax_open_kernel();
98899 sock_diag_handlers[hndl->family] = hndl;
98900+ pax_close_kernel();
98901+ }
98902 mutex_unlock(&sock_diag_table_mutex);
98903
98904 return err;
98905@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98906
98907 mutex_lock(&sock_diag_table_mutex);
98908 BUG_ON(sock_diag_handlers[family] != hnld);
98909+ pax_open_kernel();
98910 sock_diag_handlers[family] = NULL;
98911+ pax_close_kernel();
98912 mutex_unlock(&sock_diag_table_mutex);
98913 }
98914 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98915diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98916index cf9cd13..8b56af3 100644
98917--- a/net/core/sysctl_net_core.c
98918+++ b/net/core/sysctl_net_core.c
98919@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98920 {
98921 unsigned int orig_size, size;
98922 int ret, i;
98923- struct ctl_table tmp = {
98924+ ctl_table_no_const tmp = {
98925 .data = &size,
98926 .maxlen = sizeof(size),
98927 .mode = table->mode
98928@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98929 void __user *buffer, size_t *lenp, loff_t *ppos)
98930 {
98931 char id[IFNAMSIZ];
98932- struct ctl_table tbl = {
98933+ ctl_table_no_const tbl = {
98934 .data = id,
98935 .maxlen = IFNAMSIZ,
98936 };
98937@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98938
98939 static __net_init int sysctl_core_net_init(struct net *net)
98940 {
98941- struct ctl_table *tbl;
98942+ ctl_table_no_const *tbl = NULL;
98943
98944 net->core.sysctl_somaxconn = SOMAXCONN;
98945
98946- tbl = netns_core_table;
98947 if (!net_eq(net, &init_net)) {
98948- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98949+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98950 if (tbl == NULL)
98951 goto err_dup;
98952
98953@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98954 if (net->user_ns != &init_user_ns) {
98955 tbl[0].procname = NULL;
98956 }
98957- }
98958-
98959- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98960+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98961+ } else
98962+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98963 if (net->core.sysctl_hdr == NULL)
98964 goto err_reg;
98965
98966 return 0;
98967
98968 err_reg:
98969- if (tbl != netns_core_table)
98970- kfree(tbl);
98971+ kfree(tbl);
98972 err_dup:
98973 return -ENOMEM;
98974 }
98975@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98976 kfree(tbl);
98977 }
98978
98979-static __net_initdata struct pernet_operations sysctl_core_ops = {
98980+static __net_initconst struct pernet_operations sysctl_core_ops = {
98981 .init = sysctl_core_net_init,
98982 .exit = sysctl_core_net_exit,
98983 };
98984diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98985index 4c04848..f575934 100644
98986--- a/net/decnet/af_decnet.c
98987+++ b/net/decnet/af_decnet.c
98988@@ -465,6 +465,7 @@ static struct proto dn_proto = {
98989 .sysctl_rmem = sysctl_decnet_rmem,
98990 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98991 .obj_size = sizeof(struct dn_sock),
98992+ .slab_flags = SLAB_USERCOPY,
98993 };
98994
98995 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98996diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98997index a603823..a36ee0b 100644
98998--- a/net/decnet/dn_dev.c
98999+++ b/net/decnet/dn_dev.c
99000@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
99001 .extra1 = &min_t3,
99002 .extra2 = &max_t3
99003 },
99004- {0}
99005+ { }
99006 },
99007 };
99008
99009diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
99010index 5325b54..a0d4d69 100644
99011--- a/net/decnet/sysctl_net_decnet.c
99012+++ b/net/decnet/sysctl_net_decnet.c
99013@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
99014
99015 if (len > *lenp) len = *lenp;
99016
99017- if (copy_to_user(buffer, addr, len))
99018+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
99019 return -EFAULT;
99020
99021 *lenp = len;
99022@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
99023
99024 if (len > *lenp) len = *lenp;
99025
99026- if (copy_to_user(buffer, devname, len))
99027+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
99028 return -EFAULT;
99029
99030 *lenp = len;
99031diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
99032index 1846c1f..96d4a9f 100644
99033--- a/net/ieee802154/dgram.c
99034+++ b/net/ieee802154/dgram.c
99035@@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
99036 if (saddr) {
99037 saddr->family = AF_IEEE802154;
99038 saddr->addr = mac_cb(skb)->sa;
99039+ }
99040+ if (addr_len)
99041 *addr_len = sizeof(*saddr);
99042- }
99043
99044 if (flags & MSG_TRUNC)
99045 copied = skb->len;
99046diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
99047index 19ab78a..bf575c9 100644
99048--- a/net/ipv4/af_inet.c
99049+++ b/net/ipv4/af_inet.c
99050@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
99051
99052 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
99053
99054- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
99055- if (!sysctl_local_reserved_ports)
99056- goto out;
99057-
99058 rc = proto_register(&tcp_prot, 1);
99059 if (rc)
99060- goto out_free_reserved_ports;
99061+ goto out;
99062
99063 rc = proto_register(&udp_prot, 1);
99064 if (rc)
99065@@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
99066 proto_unregister(&udp_prot);
99067 out_unregister_tcp_proto:
99068 proto_unregister(&tcp_prot);
99069-out_free_reserved_ports:
99070- kfree(sysctl_local_reserved_ports);
99071 goto out;
99072 }
99073
99074diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
99075index bdbf68b..deb4759 100644
99076--- a/net/ipv4/devinet.c
99077+++ b/net/ipv4/devinet.c
99078@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
99079 idx = 0;
99080 head = &net->dev_index_head[h];
99081 rcu_read_lock();
99082- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99083+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99084 net->dev_base_seq;
99085 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99086 if (idx < s_idx)
99087@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
99088 idx = 0;
99089 head = &net->dev_index_head[h];
99090 rcu_read_lock();
99091- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99092+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99093 net->dev_base_seq;
99094 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99095 if (idx < s_idx)
99096@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
99097 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
99098 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
99099
99100-static struct devinet_sysctl_table {
99101+static const struct devinet_sysctl_table {
99102 struct ctl_table_header *sysctl_header;
99103 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
99104 } devinet_sysctl = {
99105@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
99106 int err;
99107 struct ipv4_devconf *all, *dflt;
99108 #ifdef CONFIG_SYSCTL
99109- struct ctl_table *tbl = ctl_forward_entry;
99110+ ctl_table_no_const *tbl = NULL;
99111 struct ctl_table_header *forw_hdr;
99112 #endif
99113
99114@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
99115 goto err_alloc_dflt;
99116
99117 #ifdef CONFIG_SYSCTL
99118- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
99119+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
99120 if (tbl == NULL)
99121 goto err_alloc_ctl;
99122
99123@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
99124 goto err_reg_dflt;
99125
99126 err = -ENOMEM;
99127- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99128+ if (!net_eq(net, &init_net))
99129+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99130+ else
99131+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
99132 if (forw_hdr == NULL)
99133 goto err_reg_ctl;
99134 net->ipv4.forw_hdr = forw_hdr;
99135@@ -2272,8 +2275,7 @@ err_reg_ctl:
99136 err_reg_dflt:
99137 __devinet_sysctl_unregister(all);
99138 err_reg_all:
99139- if (tbl != ctl_forward_entry)
99140- kfree(tbl);
99141+ kfree(tbl);
99142 err_alloc_ctl:
99143 #endif
99144 if (dflt != &ipv4_devconf_dflt)
99145diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
99146index c7539e2..b455e51 100644
99147--- a/net/ipv4/fib_frontend.c
99148+++ b/net/ipv4/fib_frontend.c
99149@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
99150 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99151 fib_sync_up(dev);
99152 #endif
99153- atomic_inc(&net->ipv4.dev_addr_genid);
99154+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99155 rt_cache_flush(dev_net(dev));
99156 break;
99157 case NETDEV_DOWN:
99158 fib_del_ifaddr(ifa, NULL);
99159- atomic_inc(&net->ipv4.dev_addr_genid);
99160+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99161 if (ifa->ifa_dev->ifa_list == NULL) {
99162 /* Last address was deleted from this interface.
99163 * Disable IP.
99164@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
99165 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99166 fib_sync_up(dev);
99167 #endif
99168- atomic_inc(&net->ipv4.dev_addr_genid);
99169+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99170 rt_cache_flush(net);
99171 break;
99172 case NETDEV_DOWN:
99173diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
99174index 9d43468..ffa28cc 100644
99175--- a/net/ipv4/fib_semantics.c
99176+++ b/net/ipv4/fib_semantics.c
99177@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
99178 nh->nh_saddr = inet_select_addr(nh->nh_dev,
99179 nh->nh_gw,
99180 nh->nh_parent->fib_scope);
99181- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
99182+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
99183
99184 return nh->nh_saddr;
99185 }
99186diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
99187index 0d1e2cb..4501a2c 100644
99188--- a/net/ipv4/inet_connection_sock.c
99189+++ b/net/ipv4/inet_connection_sock.c
99190@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
99191 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
99192 #endif
99193
99194-unsigned long *sysctl_local_reserved_ports;
99195+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
99196 EXPORT_SYMBOL(sysctl_local_reserved_ports);
99197
99198 void inet_get_local_port_range(struct net *net, int *low, int *high)
99199diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
99200index 8b9cf27..0d8d592 100644
99201--- a/net/ipv4/inet_hashtables.c
99202+++ b/net/ipv4/inet_hashtables.c
99203@@ -18,6 +18,7 @@
99204 #include <linux/sched.h>
99205 #include <linux/slab.h>
99206 #include <linux/wait.h>
99207+#include <linux/security.h>
99208
99209 #include <net/inet_connection_sock.h>
99210 #include <net/inet_hashtables.h>
99211@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
99212 return inet_ehashfn(net, laddr, lport, faddr, fport);
99213 }
99214
99215+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
99216+
99217 /*
99218 * Allocate and initialize a new local port bind bucket.
99219 * The bindhash mutex for snum's hash chain must be held here.
99220@@ -554,6 +557,8 @@ ok:
99221 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
99222 spin_unlock(&head->lock);
99223
99224+ gr_update_task_in_ip_table(current, inet_sk(sk));
99225+
99226 if (tw) {
99227 inet_twsk_deschedule(tw, death_row);
99228 while (twrefcnt) {
99229diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
99230index 48f4244..f56d83a 100644
99231--- a/net/ipv4/inetpeer.c
99232+++ b/net/ipv4/inetpeer.c
99233@@ -496,8 +496,8 @@ relookup:
99234 if (p) {
99235 p->daddr = *daddr;
99236 atomic_set(&p->refcnt, 1);
99237- atomic_set(&p->rid, 0);
99238- atomic_set(&p->ip_id_count,
99239+ atomic_set_unchecked(&p->rid, 0);
99240+ atomic_set_unchecked(&p->ip_id_count,
99241 (daddr->family == AF_INET) ?
99242 secure_ip_id(daddr->addr.a4) :
99243 secure_ipv6_id(daddr->addr.a6));
99244diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
99245index c10a3ce..dd71f84 100644
99246--- a/net/ipv4/ip_fragment.c
99247+++ b/net/ipv4/ip_fragment.c
99248@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
99249 return 0;
99250
99251 start = qp->rid;
99252- end = atomic_inc_return(&peer->rid);
99253+ end = atomic_inc_return_unchecked(&peer->rid);
99254 qp->rid = end;
99255
99256 rc = qp->q.fragments && (end - start) > max;
99257@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
99258
99259 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99260 {
99261- struct ctl_table *table;
99262+ ctl_table_no_const *table = NULL;
99263 struct ctl_table_header *hdr;
99264
99265- table = ip4_frags_ns_ctl_table;
99266 if (!net_eq(net, &init_net)) {
99267- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99268+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99269 if (table == NULL)
99270 goto err_alloc;
99271
99272@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99273 /* Don't export sysctls to unprivileged users */
99274 if (net->user_ns != &init_user_ns)
99275 table[0].procname = NULL;
99276- }
99277+ hdr = register_net_sysctl(net, "net/ipv4", table);
99278+ } else
99279+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
99280
99281- hdr = register_net_sysctl(net, "net/ipv4", table);
99282 if (hdr == NULL)
99283 goto err_reg;
99284
99285@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99286 return 0;
99287
99288 err_reg:
99289- if (!net_eq(net, &init_net))
99290- kfree(table);
99291+ kfree(table);
99292 err_alloc:
99293 return -ENOMEM;
99294 }
99295diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
99296index 94213c8..8bdb342 100644
99297--- a/net/ipv4/ip_gre.c
99298+++ b/net/ipv4/ip_gre.c
99299@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
99300 module_param(log_ecn_error, bool, 0644);
99301 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99302
99303-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
99304+static struct rtnl_link_ops ipgre_link_ops;
99305 static int ipgre_tunnel_init(struct net_device *dev);
99306
99307 static int ipgre_net_id __read_mostly;
99308@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99309 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99310 };
99311
99312-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99313+static struct rtnl_link_ops ipgre_link_ops = {
99314 .kind = "gre",
99315 .maxtype = IFLA_GRE_MAX,
99316 .policy = ipgre_policy,
99317@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99318 .fill_info = ipgre_fill_info,
99319 };
99320
99321-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99322+static struct rtnl_link_ops ipgre_tap_ops = {
99323 .kind = "gretap",
99324 .maxtype = IFLA_GRE_MAX,
99325 .policy = ipgre_policy,
99326diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99327index 580dd96..9fcef7e 100644
99328--- a/net/ipv4/ip_sockglue.c
99329+++ b/net/ipv4/ip_sockglue.c
99330@@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99331 len = min_t(unsigned int, len, opt->optlen);
99332 if (put_user(len, optlen))
99333 return -EFAULT;
99334- if (copy_to_user(optval, opt->__data, len))
99335+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99336+ copy_to_user(optval, opt->__data, len))
99337 return -EFAULT;
99338 return 0;
99339 }
99340@@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99341 if (sk->sk_type != SOCK_STREAM)
99342 return -ENOPROTOOPT;
99343
99344- msg.msg_control = optval;
99345+ msg.msg_control = (void __force_kernel *)optval;
99346 msg.msg_controllen = len;
99347 msg.msg_flags = flags;
99348
99349diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99350index e4a8f76..dd8ad72 100644
99351--- a/net/ipv4/ip_vti.c
99352+++ b/net/ipv4/ip_vti.c
99353@@ -44,7 +44,7 @@
99354 #include <net/net_namespace.h>
99355 #include <net/netns/generic.h>
99356
99357-static struct rtnl_link_ops vti_link_ops __read_mostly;
99358+static struct rtnl_link_ops vti_link_ops;
99359
99360 static int vti_net_id __read_mostly;
99361 static int vti_tunnel_init(struct net_device *dev);
99362@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99363 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99364 };
99365
99366-static struct rtnl_link_ops vti_link_ops __read_mostly = {
99367+static struct rtnl_link_ops vti_link_ops = {
99368 .kind = "vti",
99369 .maxtype = IFLA_VTI_MAX,
99370 .policy = vti_policy,
99371diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99372index b3e86ea..18ce98c 100644
99373--- a/net/ipv4/ipconfig.c
99374+++ b/net/ipv4/ipconfig.c
99375@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99376
99377 mm_segment_t oldfs = get_fs();
99378 set_fs(get_ds());
99379- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99380+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99381 set_fs(oldfs);
99382 return res;
99383 }
99384@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99385
99386 mm_segment_t oldfs = get_fs();
99387 set_fs(get_ds());
99388- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99389+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99390 set_fs(oldfs);
99391 return res;
99392 }
99393@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99394
99395 mm_segment_t oldfs = get_fs();
99396 set_fs(get_ds());
99397- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99398+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99399 set_fs(oldfs);
99400 return res;
99401 }
99402diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99403index 812b183..56cbe9c 100644
99404--- a/net/ipv4/ipip.c
99405+++ b/net/ipv4/ipip.c
99406@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99407 static int ipip_net_id __read_mostly;
99408
99409 static int ipip_tunnel_init(struct net_device *dev);
99410-static struct rtnl_link_ops ipip_link_ops __read_mostly;
99411+static struct rtnl_link_ops ipip_link_ops;
99412
99413 static int ipip_err(struct sk_buff *skb, u32 info)
99414 {
99415@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99416 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99417 };
99418
99419-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99420+static struct rtnl_link_ops ipip_link_ops = {
99421 .kind = "ipip",
99422 .maxtype = IFLA_IPTUN_MAX,
99423 .policy = ipip_policy,
99424diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99425index f95b6f9..2ee2097 100644
99426--- a/net/ipv4/netfilter/arp_tables.c
99427+++ b/net/ipv4/netfilter/arp_tables.c
99428@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99429 #endif
99430
99431 static int get_info(struct net *net, void __user *user,
99432- const int *len, int compat)
99433+ int len, int compat)
99434 {
99435 char name[XT_TABLE_MAXNAMELEN];
99436 struct xt_table *t;
99437 int ret;
99438
99439- if (*len != sizeof(struct arpt_getinfo)) {
99440- duprintf("length %u != %Zu\n", *len,
99441+ if (len != sizeof(struct arpt_getinfo)) {
99442+ duprintf("length %u != %Zu\n", len,
99443 sizeof(struct arpt_getinfo));
99444 return -EINVAL;
99445 }
99446@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99447 info.size = private->size;
99448 strcpy(info.name, name);
99449
99450- if (copy_to_user(user, &info, *len) != 0)
99451+ if (copy_to_user(user, &info, len) != 0)
99452 ret = -EFAULT;
99453 else
99454 ret = 0;
99455@@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99456
99457 switch (cmd) {
99458 case ARPT_SO_GET_INFO:
99459- ret = get_info(sock_net(sk), user, len, 1);
99460+ ret = get_info(sock_net(sk), user, *len, 1);
99461 break;
99462 case ARPT_SO_GET_ENTRIES:
99463 ret = compat_get_entries(sock_net(sk), user, len);
99464@@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99465
99466 switch (cmd) {
99467 case ARPT_SO_GET_INFO:
99468- ret = get_info(sock_net(sk), user, len, 0);
99469+ ret = get_info(sock_net(sk), user, *len, 0);
99470 break;
99471
99472 case ARPT_SO_GET_ENTRIES:
99473diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99474index 99e810f..3711b81 100644
99475--- a/net/ipv4/netfilter/ip_tables.c
99476+++ b/net/ipv4/netfilter/ip_tables.c
99477@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99478 #endif
99479
99480 static int get_info(struct net *net, void __user *user,
99481- const int *len, int compat)
99482+ int len, int compat)
99483 {
99484 char name[XT_TABLE_MAXNAMELEN];
99485 struct xt_table *t;
99486 int ret;
99487
99488- if (*len != sizeof(struct ipt_getinfo)) {
99489- duprintf("length %u != %zu\n", *len,
99490+ if (len != sizeof(struct ipt_getinfo)) {
99491+ duprintf("length %u != %zu\n", len,
99492 sizeof(struct ipt_getinfo));
99493 return -EINVAL;
99494 }
99495@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99496 info.size = private->size;
99497 strcpy(info.name, name);
99498
99499- if (copy_to_user(user, &info, *len) != 0)
99500+ if (copy_to_user(user, &info, len) != 0)
99501 ret = -EFAULT;
99502 else
99503 ret = 0;
99504@@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99505
99506 switch (cmd) {
99507 case IPT_SO_GET_INFO:
99508- ret = get_info(sock_net(sk), user, len, 1);
99509+ ret = get_info(sock_net(sk), user, *len, 1);
99510 break;
99511 case IPT_SO_GET_ENTRIES:
99512 ret = compat_get_entries(sock_net(sk), user, len);
99513@@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99514
99515 switch (cmd) {
99516 case IPT_SO_GET_INFO:
99517- ret = get_info(sock_net(sk), user, len, 0);
99518+ ret = get_info(sock_net(sk), user, *len, 0);
99519 break;
99520
99521 case IPT_SO_GET_ENTRIES:
99522diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99523index 2510c02..cfb34fa 100644
99524--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99525+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99526@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99527 spin_lock_init(&cn->lock);
99528
99529 #ifdef CONFIG_PROC_FS
99530- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99531+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99532 if (!cn->procdir) {
99533 pr_err("Unable to proc dir entry\n");
99534 return -ENOMEM;
99535diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99536index e21934b..3ae545c 100644
99537--- a/net/ipv4/ping.c
99538+++ b/net/ipv4/ping.c
99539@@ -59,7 +59,7 @@ struct ping_table {
99540 };
99541
99542 static struct ping_table ping_table;
99543-struct pingv6_ops pingv6_ops;
99544+struct pingv6_ops *pingv6_ops;
99545 EXPORT_SYMBOL_GPL(pingv6_ops);
99546
99547 static u16 ping_port_rover;
99548@@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99549 return -ENODEV;
99550 }
99551 }
99552- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99553+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99554 scoped);
99555 rcu_read_unlock();
99556
99557@@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99558 }
99559 #if IS_ENABLED(CONFIG_IPV6)
99560 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99561- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99562+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99563 #endif
99564 }
99565
99566@@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99567 info, (u8 *)icmph);
99568 #if IS_ENABLED(CONFIG_IPV6)
99569 } else if (family == AF_INET6) {
99570- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99571+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99572 info, (u8 *)icmph);
99573 #endif
99574 }
99575@@ -844,6 +844,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99576 {
99577 struct inet_sock *isk = inet_sk(sk);
99578 int family = sk->sk_family;
99579+ struct sockaddr_in *sin;
99580+ struct sockaddr_in6 *sin6;
99581 struct sk_buff *skb;
99582 int copied, err;
99583
99584@@ -853,12 +855,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99585 if (flags & MSG_OOB)
99586 goto out;
99587
99588+ if (addr_len) {
99589+ if (family == AF_INET)
99590+ *addr_len = sizeof(*sin);
99591+ else if (family == AF_INET6 && addr_len)
99592+ *addr_len = sizeof(*sin6);
99593+ }
99594+
99595 if (flags & MSG_ERRQUEUE) {
99596 if (family == AF_INET) {
99597 return ip_recv_error(sk, msg, len, addr_len);
99598 #if IS_ENABLED(CONFIG_IPV6)
99599 } else if (family == AF_INET6) {
99600- return pingv6_ops.ipv6_recv_error(sk, msg, len,
99601+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
99602 addr_len);
99603 #endif
99604 }
99605@@ -890,7 +899,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99606 sin->sin_port = 0 /* skb->h.uh->source */;
99607 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99608 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99609- *addr_len = sizeof(*sin);
99610 }
99611
99612 if (isk->cmsg_flags)
99613@@ -912,14 +920,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99614 sin6->sin6_scope_id =
99615 ipv6_iface_scope_id(&sin6->sin6_addr,
99616 IP6CB(skb)->iif);
99617- *addr_len = sizeof(*sin6);
99618 }
99619
99620 if (inet6_sk(sk)->rxopt.all)
99621- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99622+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99623 if (skb->protocol == htons(ETH_P_IPV6) &&
99624 inet6_sk(sk)->rxopt.all)
99625- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99626+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99627 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99628 ip_cmsg_recv(msg, skb);
99629 #endif
99630@@ -1111,7 +1118,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99631 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99632 0, sock_i_ino(sp),
99633 atomic_read(&sp->sk_refcnt), sp,
99634- atomic_read(&sp->sk_drops));
99635+ atomic_read_unchecked(&sp->sk_drops));
99636 }
99637
99638 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99639diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99640index c04518f..824ebe5 100644
99641--- a/net/ipv4/raw.c
99642+++ b/net/ipv4/raw.c
99643@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99644 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99645 {
99646 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99647- atomic_inc(&sk->sk_drops);
99648+ atomic_inc_unchecked(&sk->sk_drops);
99649 kfree_skb(skb);
99650 return NET_RX_DROP;
99651 }
99652@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99653 if (flags & MSG_OOB)
99654 goto out;
99655
99656+ if (addr_len)
99657+ *addr_len = sizeof(*sin);
99658+
99659 if (flags & MSG_ERRQUEUE) {
99660 err = ip_recv_error(sk, msg, len, addr_len);
99661 goto out;
99662@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99663 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99664 sin->sin_port = 0;
99665 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99666- *addr_len = sizeof(*sin);
99667 }
99668 if (inet->cmsg_flags)
99669 ip_cmsg_recv(msg, skb);
99670@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99671
99672 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99673 {
99674+ struct icmp_filter filter;
99675+
99676 if (optlen > sizeof(struct icmp_filter))
99677 optlen = sizeof(struct icmp_filter);
99678- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99679+ if (copy_from_user(&filter, optval, optlen))
99680 return -EFAULT;
99681+ raw_sk(sk)->filter = filter;
99682 return 0;
99683 }
99684
99685 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99686 {
99687 int len, ret = -EFAULT;
99688+ struct icmp_filter filter;
99689
99690 if (get_user(len, optlen))
99691 goto out;
99692@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99693 if (len > sizeof(struct icmp_filter))
99694 len = sizeof(struct icmp_filter);
99695 ret = -EFAULT;
99696- if (put_user(len, optlen) ||
99697- copy_to_user(optval, &raw_sk(sk)->filter, len))
99698+ filter = raw_sk(sk)->filter;
99699+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99700 goto out;
99701 ret = 0;
99702 out: return ret;
99703@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99704 0, 0L, 0,
99705 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99706 0, sock_i_ino(sp),
99707- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99708+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99709 }
99710
99711 static int raw_seq_show(struct seq_file *seq, void *v)
99712diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99713index 1344373..02f339e 100644
99714--- a/net/ipv4/route.c
99715+++ b/net/ipv4/route.c
99716@@ -233,7 +233,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99717
99718 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99719 {
99720- return seq_open(file, &rt_cache_seq_ops);
99721+ return seq_open_restrict(file, &rt_cache_seq_ops);
99722 }
99723
99724 static const struct file_operations rt_cache_seq_fops = {
99725@@ -324,7 +324,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99726
99727 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99728 {
99729- return seq_open(file, &rt_cpu_seq_ops);
99730+ return seq_open_restrict(file, &rt_cpu_seq_ops);
99731 }
99732
99733 static const struct file_operations rt_cpu_seq_fops = {
99734@@ -362,7 +362,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99735
99736 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99737 {
99738- return single_open(file, rt_acct_proc_show, NULL);
99739+ return single_open_restrict(file, rt_acct_proc_show, NULL);
99740 }
99741
99742 static const struct file_operations rt_acct_proc_fops = {
99743@@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99744 .maxlen = sizeof(int),
99745 .mode = 0200,
99746 .proc_handler = ipv4_sysctl_rtcache_flush,
99747+ .extra1 = &init_net,
99748 },
99749 { },
99750 };
99751
99752 static __net_init int sysctl_route_net_init(struct net *net)
99753 {
99754- struct ctl_table *tbl;
99755+ ctl_table_no_const *tbl = NULL;
99756
99757- tbl = ipv4_route_flush_table;
99758 if (!net_eq(net, &init_net)) {
99759- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99760+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99761 if (tbl == NULL)
99762 goto err_dup;
99763
99764 /* Don't export sysctls to unprivileged users */
99765 if (net->user_ns != &init_user_ns)
99766 tbl[0].procname = NULL;
99767- }
99768- tbl[0].extra1 = net;
99769+ tbl[0].extra1 = net;
99770+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99771+ } else
99772+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99773
99774- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99775 if (net->ipv4.route_hdr == NULL)
99776 goto err_reg;
99777 return 0;
99778
99779 err_reg:
99780- if (tbl != ipv4_route_flush_table)
99781- kfree(tbl);
99782+ kfree(tbl);
99783 err_dup:
99784 return -ENOMEM;
99785 }
99786@@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
99787
99788 static __net_init int rt_genid_init(struct net *net)
99789 {
99790- atomic_set(&net->ipv4.rt_genid, 0);
99791- atomic_set(&net->fnhe_genid, 0);
99792+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
99793+ atomic_set_unchecked(&net->fnhe_genid, 0);
99794 get_random_bytes(&net->ipv4.dev_addr_genid,
99795 sizeof(net->ipv4.dev_addr_genid));
99796 return 0;
99797diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
99798index 44eba05..b36864b 100644
99799--- a/net/ipv4/sysctl_net_ipv4.c
99800+++ b/net/ipv4/sysctl_net_ipv4.c
99801@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
99802 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
99803 int ret;
99804 int range[2];
99805- struct ctl_table tmp = {
99806+ ctl_table_no_const tmp = {
99807 .data = &range,
99808 .maxlen = sizeof(range),
99809 .mode = table->mode,
99810@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
99811 int ret;
99812 gid_t urange[2];
99813 kgid_t low, high;
99814- struct ctl_table tmp = {
99815+ ctl_table_no_const tmp = {
99816 .data = &urange,
99817 .maxlen = sizeof(urange),
99818 .mode = table->mode,
99819@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99820 void __user *buffer, size_t *lenp, loff_t *ppos)
99821 {
99822 char val[TCP_CA_NAME_MAX];
99823- struct ctl_table tbl = {
99824+ ctl_table_no_const tbl = {
99825 .data = val,
99826 .maxlen = TCP_CA_NAME_MAX,
99827 };
99828@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99829 void __user *buffer, size_t *lenp,
99830 loff_t *ppos)
99831 {
99832- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99833+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99834 int ret;
99835
99836 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99837@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99838 void __user *buffer, size_t *lenp,
99839 loff_t *ppos)
99840 {
99841- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99842+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99843 int ret;
99844
99845 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99846@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99847 void __user *buffer, size_t *lenp,
99848 loff_t *ppos)
99849 {
99850- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99851+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99852 struct tcp_fastopen_context *ctxt;
99853 int ret;
99854 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99855@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99856 },
99857 {
99858 .procname = "ip_local_reserved_ports",
99859- .data = NULL, /* initialized in sysctl_ipv4_init */
99860+ .data = sysctl_local_reserved_ports,
99861 .maxlen = 65536,
99862 .mode = 0644,
99863 .proc_handler = proc_do_large_bitmap,
99864@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99865
99866 static __net_init int ipv4_sysctl_init_net(struct net *net)
99867 {
99868- struct ctl_table *table;
99869+ ctl_table_no_const *table = NULL;
99870
99871- table = ipv4_net_table;
99872 if (!net_eq(net, &init_net)) {
99873 int i;
99874
99875- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99876+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99877 if (table == NULL)
99878 goto err_alloc;
99879
99880@@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99881 net->ipv4.sysctl_local_ports.range[0] = 32768;
99882 net->ipv4.sysctl_local_ports.range[1] = 61000;
99883
99884- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99885+ if (!net_eq(net, &init_net))
99886+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99887+ else
99888+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99889 if (net->ipv4.ipv4_hdr == NULL)
99890 goto err_reg;
99891
99892 return 0;
99893
99894 err_reg:
99895- if (!net_eq(net, &init_net))
99896- kfree(table);
99897+ kfree(table);
99898 err_alloc:
99899 return -ENOMEM;
99900 }
99901@@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
99902 static __init int sysctl_ipv4_init(void)
99903 {
99904 struct ctl_table_header *hdr;
99905- struct ctl_table *i;
99906-
99907- for (i = ipv4_table; i->procname; i++) {
99908- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
99909- i->data = sysctl_local_reserved_ports;
99910- break;
99911- }
99912- }
99913- if (!i->procname)
99914- return -EINVAL;
99915
99916 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
99917 if (hdr == NULL)
99918diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
99919index eeaac39..dc29942 100644
99920--- a/net/ipv4/tcp_input.c
99921+++ b/net/ipv4/tcp_input.c
99922@@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99923 * without any lock. We want to make sure compiler wont store
99924 * intermediate values in this location.
99925 */
99926- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99927+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99928 sk->sk_max_pacing_rate);
99929 }
99930
99931@@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99932 * simplifies code)
99933 */
99934 static void
99935-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99936+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99937 struct sk_buff *head, struct sk_buff *tail,
99938 u32 start, u32 end)
99939 {
99940@@ -5562,6 +5562,7 @@ discard:
99941 tcp_paws_reject(&tp->rx_opt, 0))
99942 goto discard_and_undo;
99943
99944+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99945 if (th->syn) {
99946 /* We see SYN without ACK. It is attempt of
99947 * simultaneous connect with crossed SYNs.
99948@@ -5612,6 +5613,7 @@ discard:
99949 goto discard;
99950 #endif
99951 }
99952+#endif
99953 /* "fifth, if neither of the SYN or RST bits is set then
99954 * drop the segment and return."
99955 */
99956@@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99957 goto discard;
99958
99959 if (th->syn) {
99960- if (th->fin)
99961+ if (th->fin || th->urg || th->psh)
99962 goto discard;
99963 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99964 return 1;
99965diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99966index 1e4eac7..a66fa4a 100644
99967--- a/net/ipv4/tcp_ipv4.c
99968+++ b/net/ipv4/tcp_ipv4.c
99969@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99970 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99971
99972
99973+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99974+extern int grsec_enable_blackhole;
99975+#endif
99976+
99977 #ifdef CONFIG_TCP_MD5SIG
99978 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99979 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99980@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99981 return 0;
99982
99983 reset:
99984+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99985+ if (!grsec_enable_blackhole)
99986+#endif
99987 tcp_v4_send_reset(rsk, skb);
99988 discard:
99989 kfree_skb(skb);
99990@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99991 TCP_SKB_CB(skb)->sacked = 0;
99992
99993 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99994- if (!sk)
99995+ if (!sk) {
99996+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99997+ ret = 1;
99998+#endif
99999 goto no_tcp_socket;
100000-
100001+ }
100002 process:
100003- if (sk->sk_state == TCP_TIME_WAIT)
100004+ if (sk->sk_state == TCP_TIME_WAIT) {
100005+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100006+ ret = 2;
100007+#endif
100008 goto do_time_wait;
100009+ }
100010
100011 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
100012 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100013@@ -2033,6 +2047,10 @@ csum_error:
100014 bad_packet:
100015 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100016 } else {
100017+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100018+ if (!grsec_enable_blackhole || (ret == 1 &&
100019+ (skb->dev->flags & IFF_LOOPBACK)))
100020+#endif
100021 tcp_v4_send_reset(NULL, skb);
100022 }
100023
100024diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
100025index 7a436c5..1b05c59 100644
100026--- a/net/ipv4/tcp_minisocks.c
100027+++ b/net/ipv4/tcp_minisocks.c
100028@@ -27,6 +27,10 @@
100029 #include <net/inet_common.h>
100030 #include <net/xfrm.h>
100031
100032+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100033+extern int grsec_enable_blackhole;
100034+#endif
100035+
100036 int sysctl_tcp_syncookies __read_mostly = 1;
100037 EXPORT_SYMBOL(sysctl_tcp_syncookies);
100038
100039@@ -709,7 +713,10 @@ embryonic_reset:
100040 * avoid becoming vulnerable to outside attack aiming at
100041 * resetting legit local connections.
100042 */
100043- req->rsk_ops->send_reset(sk, skb);
100044+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100045+ if (!grsec_enable_blackhole)
100046+#endif
100047+ req->rsk_ops->send_reset(sk, skb);
100048 } else if (fastopen) { /* received a valid RST pkt */
100049 reqsk_fastopen_remove(sk, req, true);
100050 tcp_reset(sk);
100051diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
100052index 1f2d376..01d18c4 100644
100053--- a/net/ipv4/tcp_probe.c
100054+++ b/net/ipv4/tcp_probe.c
100055@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
100056 if (cnt + width >= len)
100057 break;
100058
100059- if (copy_to_user(buf + cnt, tbuf, width))
100060+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
100061 return -EFAULT;
100062 cnt += width;
100063 }
100064diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
100065index 64f0354..a81b39d 100644
100066--- a/net/ipv4/tcp_timer.c
100067+++ b/net/ipv4/tcp_timer.c
100068@@ -22,6 +22,10 @@
100069 #include <linux/gfp.h>
100070 #include <net/tcp.h>
100071
100072+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100073+extern int grsec_lastack_retries;
100074+#endif
100075+
100076 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
100077 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
100078 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
100079@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
100080 }
100081 }
100082
100083+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100084+ if ((sk->sk_state == TCP_LAST_ACK) &&
100085+ (grsec_lastack_retries > 0) &&
100086+ (grsec_lastack_retries < retry_until))
100087+ retry_until = grsec_lastack_retries;
100088+#endif
100089+
100090 if (retransmits_timed_out(sk, retry_until,
100091 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
100092 /* Has it gone just too far? */
100093diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
100094index 77bd16f..5f7174a 100644
100095--- a/net/ipv4/udp.c
100096+++ b/net/ipv4/udp.c
100097@@ -87,6 +87,7 @@
100098 #include <linux/types.h>
100099 #include <linux/fcntl.h>
100100 #include <linux/module.h>
100101+#include <linux/security.h>
100102 #include <linux/socket.h>
100103 #include <linux/sockios.h>
100104 #include <linux/igmp.h>
100105@@ -113,6 +114,10 @@
100106 #include <net/busy_poll.h>
100107 #include "udp_impl.h"
100108
100109+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100110+extern int grsec_enable_blackhole;
100111+#endif
100112+
100113 struct udp_table udp_table __read_mostly;
100114 EXPORT_SYMBOL(udp_table);
100115
100116@@ -615,6 +620,9 @@ found:
100117 return s;
100118 }
100119
100120+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
100121+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
100122+
100123 /*
100124 * This routine is called by the ICMP module when it gets some
100125 * sort of error condition. If err < 0 then the socket should
100126@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100127 dport = usin->sin_port;
100128 if (dport == 0)
100129 return -EINVAL;
100130+
100131+ err = gr_search_udp_sendmsg(sk, usin);
100132+ if (err)
100133+ return err;
100134 } else {
100135 if (sk->sk_state != TCP_ESTABLISHED)
100136 return -EDESTADDRREQ;
100137+
100138+ err = gr_search_udp_sendmsg(sk, NULL);
100139+ if (err)
100140+ return err;
100141+
100142 daddr = inet->inet_daddr;
100143 dport = inet->inet_dport;
100144 /* Open fast path for connected socket.
100145@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
100146 IS_UDPLITE(sk));
100147 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100148 IS_UDPLITE(sk));
100149- atomic_inc(&sk->sk_drops);
100150+ atomic_inc_unchecked(&sk->sk_drops);
100151 __skb_unlink(skb, rcvq);
100152 __skb_queue_tail(&list_kill, skb);
100153 }
100154@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100155 int is_udplite = IS_UDPLITE(sk);
100156 bool slow;
100157
100158+ /*
100159+ * Check any passed addresses
100160+ */
100161+ if (addr_len)
100162+ *addr_len = sizeof(*sin);
100163+
100164 if (flags & MSG_ERRQUEUE)
100165 return ip_recv_error(sk, msg, len, addr_len);
100166
100167@@ -1243,6 +1266,10 @@ try_again:
100168 if (!skb)
100169 goto out;
100170
100171+ err = gr_search_udp_recvmsg(sk, skb);
100172+ if (err)
100173+ goto out_free;
100174+
100175 ulen = skb->len - sizeof(struct udphdr);
100176 copied = len;
100177 if (copied > ulen)
100178@@ -1276,7 +1303,7 @@ try_again:
100179 if (unlikely(err)) {
100180 trace_kfree_skb(skb, udp_recvmsg);
100181 if (!peeked) {
100182- atomic_inc(&sk->sk_drops);
100183+ atomic_inc_unchecked(&sk->sk_drops);
100184 UDP_INC_STATS_USER(sock_net(sk),
100185 UDP_MIB_INERRORS, is_udplite);
100186 }
100187@@ -1295,7 +1322,6 @@ try_again:
100188 sin->sin_port = udp_hdr(skb)->source;
100189 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100190 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100191- *addr_len = sizeof(*sin);
100192 }
100193 if (inet->cmsg_flags)
100194 ip_cmsg_recv(msg, skb);
100195@@ -1566,7 +1592,7 @@ csum_error:
100196 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100197 drop:
100198 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100199- atomic_inc(&sk->sk_drops);
100200+ atomic_inc_unchecked(&sk->sk_drops);
100201 kfree_skb(skb);
100202 return -1;
100203 }
100204@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100205 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100206
100207 if (!skb1) {
100208- atomic_inc(&sk->sk_drops);
100209+ atomic_inc_unchecked(&sk->sk_drops);
100210 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100211 IS_UDPLITE(sk));
100212 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100213@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100214 goto csum_error;
100215
100216 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100217+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100218+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100219+#endif
100220 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
100221
100222 /*
100223@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
100224 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100225 0, sock_i_ino(sp),
100226 atomic_read(&sp->sk_refcnt), sp,
100227- atomic_read(&sp->sk_drops));
100228+ atomic_read_unchecked(&sp->sk_drops));
100229 }
100230
100231 int udp4_seq_show(struct seq_file *seq, void *v)
100232diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
100233index e1a6393..f634ce5 100644
100234--- a/net/ipv4/xfrm4_policy.c
100235+++ b/net/ipv4/xfrm4_policy.c
100236@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
100237 fl4->flowi4_tos = iph->tos;
100238 }
100239
100240-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
100241+static int xfrm4_garbage_collect(struct dst_ops *ops)
100242 {
100243 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
100244
100245- xfrm4_policy_afinfo.garbage_collect(net);
100246+ xfrm_garbage_collect_deferred(net);
100247 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
100248 }
100249
100250@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
100251
100252 static int __net_init xfrm4_net_init(struct net *net)
100253 {
100254- struct ctl_table *table;
100255+ ctl_table_no_const *table = NULL;
100256 struct ctl_table_header *hdr;
100257
100258- table = xfrm4_policy_table;
100259 if (!net_eq(net, &init_net)) {
100260- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100261+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100262 if (!table)
100263 goto err_alloc;
100264
100265 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
100266- }
100267-
100268- hdr = register_net_sysctl(net, "net/ipv4", table);
100269+ hdr = register_net_sysctl(net, "net/ipv4", table);
100270+ } else
100271+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
100272 if (!hdr)
100273 goto err_reg;
100274
100275@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100276 return 0;
100277
100278 err_reg:
100279- if (!net_eq(net, &init_net))
100280- kfree(table);
100281+ kfree(table);
100282 err_alloc:
100283 return -ENOMEM;
100284 }
100285diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100286index 6c7fa08..285086c 100644
100287--- a/net/ipv6/addrconf.c
100288+++ b/net/ipv6/addrconf.c
100289@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100290 idx = 0;
100291 head = &net->dev_index_head[h];
100292 rcu_read_lock();
100293- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100294+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100295 net->dev_base_seq;
100296 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100297 if (idx < s_idx)
100298@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100299 p.iph.ihl = 5;
100300 p.iph.protocol = IPPROTO_IPV6;
100301 p.iph.ttl = 64;
100302- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100303+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100304
100305 if (ops->ndo_do_ioctl) {
100306 mm_segment_t oldfs = get_fs();
100307@@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100308 s_ip_idx = ip_idx = cb->args[2];
100309
100310 rcu_read_lock();
100311- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100312+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100313 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100314 idx = 0;
100315 head = &net->dev_index_head[h];
100316@@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100317 dst_free(&ifp->rt->dst);
100318 break;
100319 }
100320- atomic_inc(&net->ipv6.dev_addr_genid);
100321+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100322 rt_genid_bump_ipv6(net);
100323 }
100324
100325@@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100326 int *valp = ctl->data;
100327 int val = *valp;
100328 loff_t pos = *ppos;
100329- struct ctl_table lctl;
100330+ ctl_table_no_const lctl;
100331 int ret;
100332
100333 /*
100334@@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100335 int *valp = ctl->data;
100336 int val = *valp;
100337 loff_t pos = *ppos;
100338- struct ctl_table lctl;
100339+ ctl_table_no_const lctl;
100340 int ret;
100341
100342 /*
100343diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100344index d935889..2f64330 100644
100345--- a/net/ipv6/af_inet6.c
100346+++ b/net/ipv6/af_inet6.c
100347@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100348 net->ipv6.sysctl.bindv6only = 0;
100349 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100350 net->ipv6.sysctl.flowlabel_consistency = 1;
100351- atomic_set(&net->ipv6.rt_genid, 0);
100352+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100353
100354 err = ipv6_init_mibs(net);
100355 if (err)
100356diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100357index c3bf2d2..1f00573 100644
100358--- a/net/ipv6/datagram.c
100359+++ b/net/ipv6/datagram.c
100360@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100361 0,
100362 sock_i_ino(sp),
100363 atomic_read(&sp->sk_refcnt), sp,
100364- atomic_read(&sp->sk_drops));
100365+ atomic_read_unchecked(&sp->sk_drops));
100366 }
100367diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100368index 7b32652..0bc348b 100644
100369--- a/net/ipv6/icmp.c
100370+++ b/net/ipv6/icmp.c
100371@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100372
100373 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100374 {
100375- struct ctl_table *table;
100376+ ctl_table_no_const *table;
100377
100378 table = kmemdup(ipv6_icmp_table_template,
100379 sizeof(ipv6_icmp_table_template),
100380diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100381index 2465d18..bc5bf7f 100644
100382--- a/net/ipv6/ip6_gre.c
100383+++ b/net/ipv6/ip6_gre.c
100384@@ -71,7 +71,7 @@ struct ip6gre_net {
100385 struct net_device *fb_tunnel_dev;
100386 };
100387
100388-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100389+static struct rtnl_link_ops ip6gre_link_ops;
100390 static int ip6gre_tunnel_init(struct net_device *dev);
100391 static void ip6gre_tunnel_setup(struct net_device *dev);
100392 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100393@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100394 }
100395
100396
100397-static struct inet6_protocol ip6gre_protocol __read_mostly = {
100398+static struct inet6_protocol ip6gre_protocol = {
100399 .handler = ip6gre_rcv,
100400 .err_handler = ip6gre_err,
100401 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100402@@ -1643,7 +1643,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100403 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100404 };
100405
100406-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100407+static struct rtnl_link_ops ip6gre_link_ops = {
100408 .kind = "ip6gre",
100409 .maxtype = IFLA_GRE_MAX,
100410 .policy = ip6gre_policy,
100411@@ -1657,7 +1657,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100412 .fill_info = ip6gre_fill_info,
100413 };
100414
100415-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100416+static struct rtnl_link_ops ip6gre_tap_ops = {
100417 .kind = "ip6gretap",
100418 .maxtype = IFLA_GRE_MAX,
100419 .policy = ip6gre_policy,
100420diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100421index 0e51f68..1f501e1 100644
100422--- a/net/ipv6/ip6_tunnel.c
100423+++ b/net/ipv6/ip6_tunnel.c
100424@@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100425
100426 static int ip6_tnl_dev_init(struct net_device *dev);
100427 static void ip6_tnl_dev_setup(struct net_device *dev);
100428-static struct rtnl_link_ops ip6_link_ops __read_mostly;
100429+static struct rtnl_link_ops ip6_link_ops;
100430
100431 static int ip6_tnl_net_id __read_mostly;
100432 struct ip6_tnl_net {
100433@@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100434 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100435 };
100436
100437-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100438+static struct rtnl_link_ops ip6_link_ops = {
100439 .kind = "ip6tnl",
100440 .maxtype = IFLA_IPTUN_MAX,
100441 .policy = ip6_tnl_policy,
100442diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100443index 2d19272..3a46322 100644
100444--- a/net/ipv6/ip6_vti.c
100445+++ b/net/ipv6/ip6_vti.c
100446@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100447
100448 static int vti6_dev_init(struct net_device *dev);
100449 static void vti6_dev_setup(struct net_device *dev);
100450-static struct rtnl_link_ops vti6_link_ops __read_mostly;
100451+static struct rtnl_link_ops vti6_link_ops;
100452
100453 static int vti6_net_id __read_mostly;
100454 struct vti6_net {
100455@@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100456 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100457 };
100458
100459-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100460+static struct rtnl_link_ops vti6_link_ops = {
100461 .kind = "vti6",
100462 .maxtype = IFLA_VTI_MAX,
100463 .policy = vti6_policy,
100464diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100465index 0a00f44..bec42b2 100644
100466--- a/net/ipv6/ipv6_sockglue.c
100467+++ b/net/ipv6/ipv6_sockglue.c
100468@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100469 if (sk->sk_type != SOCK_STREAM)
100470 return -ENOPROTOOPT;
100471
100472- msg.msg_control = optval;
100473+ msg.msg_control = (void __force_kernel *)optval;
100474 msg.msg_controllen = len;
100475 msg.msg_flags = flags;
100476
100477diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100478index e080fbb..412b3cf 100644
100479--- a/net/ipv6/netfilter/ip6_tables.c
100480+++ b/net/ipv6/netfilter/ip6_tables.c
100481@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100482 #endif
100483
100484 static int get_info(struct net *net, void __user *user,
100485- const int *len, int compat)
100486+ int len, int compat)
100487 {
100488 char name[XT_TABLE_MAXNAMELEN];
100489 struct xt_table *t;
100490 int ret;
100491
100492- if (*len != sizeof(struct ip6t_getinfo)) {
100493- duprintf("length %u != %zu\n", *len,
100494+ if (len != sizeof(struct ip6t_getinfo)) {
100495+ duprintf("length %u != %zu\n", len,
100496 sizeof(struct ip6t_getinfo));
100497 return -EINVAL;
100498 }
100499@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100500 info.size = private->size;
100501 strcpy(info.name, name);
100502
100503- if (copy_to_user(user, &info, *len) != 0)
100504+ if (copy_to_user(user, &info, len) != 0)
100505 ret = -EFAULT;
100506 else
100507 ret = 0;
100508@@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100509
100510 switch (cmd) {
100511 case IP6T_SO_GET_INFO:
100512- ret = get_info(sock_net(sk), user, len, 1);
100513+ ret = get_info(sock_net(sk), user, *len, 1);
100514 break;
100515 case IP6T_SO_GET_ENTRIES:
100516 ret = compat_get_entries(sock_net(sk), user, len);
100517@@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100518
100519 switch (cmd) {
100520 case IP6T_SO_GET_INFO:
100521- ret = get_info(sock_net(sk), user, len, 0);
100522+ ret = get_info(sock_net(sk), user, *len, 0);
100523 break;
100524
100525 case IP6T_SO_GET_ENTRIES:
100526diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100527index 767ab8d..c5ec70a 100644
100528--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100529+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100530@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100531
100532 static int nf_ct_frag6_sysctl_register(struct net *net)
100533 {
100534- struct ctl_table *table;
100535+ ctl_table_no_const *table = NULL;
100536 struct ctl_table_header *hdr;
100537
100538- table = nf_ct_frag6_sysctl_table;
100539 if (!net_eq(net, &init_net)) {
100540- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100541+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100542 GFP_KERNEL);
100543 if (table == NULL)
100544 goto err_alloc;
100545@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100546 table[0].data = &net->nf_frag.frags.timeout;
100547 table[1].data = &net->nf_frag.frags.low_thresh;
100548 table[2].data = &net->nf_frag.frags.high_thresh;
100549- }
100550-
100551- hdr = register_net_sysctl(net, "net/netfilter", table);
100552+ hdr = register_net_sysctl(net, "net/netfilter", table);
100553+ } else
100554+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100555 if (hdr == NULL)
100556 goto err_reg;
100557
100558@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100559 return 0;
100560
100561 err_reg:
100562- if (!net_eq(net, &init_net))
100563- kfree(table);
100564+ kfree(table);
100565 err_alloc:
100566 return -ENOMEM;
100567 }
100568diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100569index 827f795..bdff9eb 100644
100570--- a/net/ipv6/output_core.c
100571+++ b/net/ipv6/output_core.c
100572@@ -9,8 +9,8 @@
100573
100574 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100575 {
100576- static atomic_t ipv6_fragmentation_id;
100577- int old, new;
100578+ static atomic_unchecked_t ipv6_fragmentation_id;
100579+ int id;
100580
100581 #if IS_ENABLED(CONFIG_IPV6)
100582 if (rt && !(rt->dst.flags & DST_NOPEER)) {
100583@@ -26,13 +26,8 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100584 }
100585 }
100586 #endif
100587- do {
100588- old = atomic_read(&ipv6_fragmentation_id);
100589- new = old + 1;
100590- if (!new)
100591- new = 1;
100592- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
100593- fhdr->identification = htonl(new);
100594+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100595+ fhdr->identification = htonl(id);
100596 }
100597 EXPORT_SYMBOL(ipv6_select_ident);
100598
100599diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100600index bda7429..469b26b 100644
100601--- a/net/ipv6/ping.c
100602+++ b/net/ipv6/ping.c
100603@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100604 };
100605 #endif
100606
100607+static struct pingv6_ops real_pingv6_ops = {
100608+ .ipv6_recv_error = ipv6_recv_error,
100609+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100610+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100611+ .icmpv6_err_convert = icmpv6_err_convert,
100612+ .ipv6_icmp_error = ipv6_icmp_error,
100613+ .ipv6_chk_addr = ipv6_chk_addr,
100614+};
100615+
100616+static struct pingv6_ops dummy_pingv6_ops = {
100617+ .ipv6_recv_error = dummy_ipv6_recv_error,
100618+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100619+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100620+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
100621+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
100622+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
100623+};
100624+
100625 int __init pingv6_init(void)
100626 {
100627 #ifdef CONFIG_PROC_FS
100628@@ -253,13 +271,7 @@ int __init pingv6_init(void)
100629 if (ret)
100630 return ret;
100631 #endif
100632- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100633- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100634- pingv6_ops.ip6_datagram_recv_specific_ctl =
100635- ip6_datagram_recv_specific_ctl;
100636- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100637- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100638- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100639+ pingv6_ops = &real_pingv6_ops;
100640 return inet6_register_protosw(&pingv6_protosw);
100641 }
100642
100643@@ -268,14 +280,9 @@ int __init pingv6_init(void)
100644 */
100645 void pingv6_exit(void)
100646 {
100647- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100648- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100649- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100650- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100651- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100652- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100653 #ifdef CONFIG_PROC_FS
100654 unregister_pernet_subsys(&ping_v6_net_ops);
100655 #endif
100656+ pingv6_ops = &dummy_pingv6_ops;
100657 inet6_unregister_protosw(&pingv6_protosw);
100658 }
100659diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100660index 091d066..139d410 100644
100661--- a/net/ipv6/proc.c
100662+++ b/net/ipv6/proc.c
100663@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100664 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100665 goto proc_snmp6_fail;
100666
100667- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100668+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100669 if (!net->mib.proc_net_devsnmp6)
100670 goto proc_dev_snmp6_fail;
100671 return 0;
100672diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100673index 1f29996..46fe0c7 100644
100674--- a/net/ipv6/raw.c
100675+++ b/net/ipv6/raw.c
100676@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100677 {
100678 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100679 skb_checksum_complete(skb)) {
100680- atomic_inc(&sk->sk_drops);
100681+ atomic_inc_unchecked(&sk->sk_drops);
100682 kfree_skb(skb);
100683 return NET_RX_DROP;
100684 }
100685@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100686 struct raw6_sock *rp = raw6_sk(sk);
100687
100688 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100689- atomic_inc(&sk->sk_drops);
100690+ atomic_inc_unchecked(&sk->sk_drops);
100691 kfree_skb(skb);
100692 return NET_RX_DROP;
100693 }
100694@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100695
100696 if (inet->hdrincl) {
100697 if (skb_checksum_complete(skb)) {
100698- atomic_inc(&sk->sk_drops);
100699+ atomic_inc_unchecked(&sk->sk_drops);
100700 kfree_skb(skb);
100701 return NET_RX_DROP;
100702 }
100703@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100704 if (flags & MSG_OOB)
100705 return -EOPNOTSUPP;
100706
100707+ if (addr_len)
100708+ *addr_len=sizeof(*sin6);
100709+
100710 if (flags & MSG_ERRQUEUE)
100711 return ipv6_recv_error(sk, msg, len, addr_len);
100712
100713@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100714 sin6->sin6_flowinfo = 0;
100715 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100716 IP6CB(skb)->iif);
100717- *addr_len = sizeof(*sin6);
100718 }
100719
100720 sock_recv_ts_and_drops(msg, sk, skb);
100721@@ -610,7 +612,7 @@ out:
100722 return err;
100723 }
100724
100725-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100726+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100727 struct flowi6 *fl6, struct dst_entry **dstp,
100728 unsigned int flags)
100729 {
100730@@ -922,12 +924,15 @@ do_confirm:
100731 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100732 char __user *optval, int optlen)
100733 {
100734+ struct icmp6_filter filter;
100735+
100736 switch (optname) {
100737 case ICMPV6_FILTER:
100738 if (optlen > sizeof(struct icmp6_filter))
100739 optlen = sizeof(struct icmp6_filter);
100740- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100741+ if (copy_from_user(&filter, optval, optlen))
100742 return -EFAULT;
100743+ raw6_sk(sk)->filter = filter;
100744 return 0;
100745 default:
100746 return -ENOPROTOOPT;
100747@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100748 char __user *optval, int __user *optlen)
100749 {
100750 int len;
100751+ struct icmp6_filter filter;
100752
100753 switch (optname) {
100754 case ICMPV6_FILTER:
100755@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100756 len = sizeof(struct icmp6_filter);
100757 if (put_user(len, optlen))
100758 return -EFAULT;
100759- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100760+ filter = raw6_sk(sk)->filter;
100761+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
100762 return -EFAULT;
100763 return 0;
100764 default:
100765diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100766index cc85a9b..526a133 100644
100767--- a/net/ipv6/reassembly.c
100768+++ b/net/ipv6/reassembly.c
100769@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100770
100771 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100772 {
100773- struct ctl_table *table;
100774+ ctl_table_no_const *table = NULL;
100775 struct ctl_table_header *hdr;
100776
100777- table = ip6_frags_ns_ctl_table;
100778 if (!net_eq(net, &init_net)) {
100779- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100780+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100781 if (table == NULL)
100782 goto err_alloc;
100783
100784@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100785 /* Don't export sysctls to unprivileged users */
100786 if (net->user_ns != &init_user_ns)
100787 table[0].procname = NULL;
100788- }
100789+ hdr = register_net_sysctl(net, "net/ipv6", table);
100790+ } else
100791+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
100792
100793- hdr = register_net_sysctl(net, "net/ipv6", table);
100794 if (hdr == NULL)
100795 goto err_reg;
100796
100797@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100798 return 0;
100799
100800 err_reg:
100801- if (!net_eq(net, &init_net))
100802- kfree(table);
100803+ kfree(table);
100804 err_alloc:
100805 return -ENOMEM;
100806 }
100807diff --git a/net/ipv6/route.c b/net/ipv6/route.c
100808index 7cc1102..7785931 100644
100809--- a/net/ipv6/route.c
100810+++ b/net/ipv6/route.c
100811@@ -2973,7 +2973,7 @@ struct ctl_table ipv6_route_table_template[] = {
100812
100813 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100814 {
100815- struct ctl_table *table;
100816+ ctl_table_no_const *table;
100817
100818 table = kmemdup(ipv6_route_table_template,
100819 sizeof(ipv6_route_table_template),
100820diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100821index b4d74c8..b4f3fbe 100644
100822--- a/net/ipv6/sit.c
100823+++ b/net/ipv6/sit.c
100824@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100825 static void ipip6_dev_free(struct net_device *dev);
100826 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100827 __be32 *v4dst);
100828-static struct rtnl_link_ops sit_link_ops __read_mostly;
100829+static struct rtnl_link_ops sit_link_ops;
100830
100831 static int sit_net_id __read_mostly;
100832 struct sit_net {
100833@@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100834 unregister_netdevice_queue(dev, head);
100835 }
100836
100837-static struct rtnl_link_ops sit_link_ops __read_mostly = {
100838+static struct rtnl_link_ops sit_link_ops = {
100839 .kind = "sit",
100840 .maxtype = IFLA_IPTUN_MAX,
100841 .policy = ipip6_policy,
100842diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100843index 7f405a1..eabef92 100644
100844--- a/net/ipv6/sysctl_net_ipv6.c
100845+++ b/net/ipv6/sysctl_net_ipv6.c
100846@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100847
100848 static int __net_init ipv6_sysctl_net_init(struct net *net)
100849 {
100850- struct ctl_table *ipv6_table;
100851+ ctl_table_no_const *ipv6_table;
100852 struct ctl_table *ipv6_route_table;
100853 struct ctl_table *ipv6_icmp_table;
100854 int err;
100855diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100856index 889079b..a04512c 100644
100857--- a/net/ipv6/tcp_ipv6.c
100858+++ b/net/ipv6/tcp_ipv6.c
100859@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100860 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100861 }
100862
100863+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100864+extern int grsec_enable_blackhole;
100865+#endif
100866+
100867 static void tcp_v6_hash(struct sock *sk)
100868 {
100869 if (sk->sk_state != TCP_CLOSE) {
100870@@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100871 return 0;
100872
100873 reset:
100874+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100875+ if (!grsec_enable_blackhole)
100876+#endif
100877 tcp_v6_send_reset(sk, skb);
100878 discard:
100879 if (opt_skb)
100880@@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100881 TCP_SKB_CB(skb)->sacked = 0;
100882
100883 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100884- if (!sk)
100885+ if (!sk) {
100886+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100887+ ret = 1;
100888+#endif
100889 goto no_tcp_socket;
100890+ }
100891
100892 process:
100893- if (sk->sk_state == TCP_TIME_WAIT)
100894+ if (sk->sk_state == TCP_TIME_WAIT) {
100895+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100896+ ret = 2;
100897+#endif
100898 goto do_time_wait;
100899+ }
100900
100901 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
100902 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100903@@ -1553,6 +1568,10 @@ csum_error:
100904 bad_packet:
100905 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100906 } else {
100907+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100908+ if (!grsec_enable_blackhole || (ret == 1 &&
100909+ (skb->dev->flags & IFF_LOOPBACK)))
100910+#endif
100911 tcp_v6_send_reset(NULL, skb);
100912 }
100913
100914diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
100915index 1e586d9..384a9c9 100644
100916--- a/net/ipv6/udp.c
100917+++ b/net/ipv6/udp.c
100918@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
100919 udp_ipv6_hash_secret + net_hash_mix(net));
100920 }
100921
100922+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100923+extern int grsec_enable_blackhole;
100924+#endif
100925+
100926 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100927 {
100928 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100929@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100930 int is_udp4;
100931 bool slow;
100932
100933+ if (addr_len)
100934+ *addr_len = sizeof(struct sockaddr_in6);
100935+
100936 if (flags & MSG_ERRQUEUE)
100937 return ipv6_recv_error(sk, msg, len, addr_len);
100938
100939@@ -435,7 +442,7 @@ try_again:
100940 if (unlikely(err)) {
100941 trace_kfree_skb(skb, udpv6_recvmsg);
100942 if (!peeked) {
100943- atomic_inc(&sk->sk_drops);
100944+ atomic_inc_unchecked(&sk->sk_drops);
100945 if (is_udp4)
100946 UDP_INC_STATS_USER(sock_net(sk),
100947 UDP_MIB_INERRORS,
100948@@ -475,7 +482,7 @@ try_again:
100949 ipv6_iface_scope_id(&sin6->sin6_addr,
100950 IP6CB(skb)->iif);
100951 }
100952- *addr_len = sizeof(*sin6);
100953+
100954 }
100955
100956 if (np->rxopt.all)
100957@@ -690,7 +697,7 @@ csum_error:
100958 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100959 drop:
100960 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100961- atomic_inc(&sk->sk_drops);
100962+ atomic_inc_unchecked(&sk->sk_drops);
100963 kfree_skb(skb);
100964 return -1;
100965 }
100966@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100967 if (likely(skb1 == NULL))
100968 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100969 if (!skb1) {
100970- atomic_inc(&sk->sk_drops);
100971+ atomic_inc_unchecked(&sk->sk_drops);
100972 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100973 IS_UDPLITE(sk));
100974 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100975@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100976 goto csum_error;
100977
100978 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100979+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100980+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100981+#endif
100982 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100983
100984 kfree_skb(skb);
100985diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100986index 5f8e128..865d38e 100644
100987--- a/net/ipv6/xfrm6_policy.c
100988+++ b/net/ipv6/xfrm6_policy.c
100989@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100990 }
100991 }
100992
100993-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100994+static int xfrm6_garbage_collect(struct dst_ops *ops)
100995 {
100996 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100997
100998- xfrm6_policy_afinfo.garbage_collect(net);
100999+ xfrm_garbage_collect_deferred(net);
101000 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
101001 }
101002
101003@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
101004
101005 static int __net_init xfrm6_net_init(struct net *net)
101006 {
101007- struct ctl_table *table;
101008+ ctl_table_no_const *table = NULL;
101009 struct ctl_table_header *hdr;
101010
101011- table = xfrm6_policy_table;
101012 if (!net_eq(net, &init_net)) {
101013- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101014+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101015 if (!table)
101016 goto err_alloc;
101017
101018 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
101019- }
101020+ hdr = register_net_sysctl(net, "net/ipv6", table);
101021+ } else
101022+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
101023
101024- hdr = register_net_sysctl(net, "net/ipv6", table);
101025 if (!hdr)
101026 goto err_reg;
101027
101028@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
101029 return 0;
101030
101031 err_reg:
101032- if (!net_eq(net, &init_net))
101033- kfree(table);
101034+ kfree(table);
101035 err_alloc:
101036 return -ENOMEM;
101037 }
101038diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
101039index e15c16a..7cf07aa 100644
101040--- a/net/ipx/ipx_proc.c
101041+++ b/net/ipx/ipx_proc.c
101042@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
101043 struct proc_dir_entry *p;
101044 int rc = -ENOMEM;
101045
101046- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
101047+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
101048
101049 if (!ipx_proc_dir)
101050 goto out;
101051diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
101052index 2ba8b97..6d33010 100644
101053--- a/net/irda/ircomm/ircomm_tty.c
101054+++ b/net/irda/ircomm/ircomm_tty.c
101055@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101056 add_wait_queue(&port->open_wait, &wait);
101057
101058 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
101059- __FILE__, __LINE__, tty->driver->name, port->count);
101060+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101061
101062 spin_lock_irqsave(&port->lock, flags);
101063 if (!tty_hung_up_p(filp))
101064- port->count--;
101065+ atomic_dec(&port->count);
101066 port->blocked_open++;
101067 spin_unlock_irqrestore(&port->lock, flags);
101068
101069@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101070 }
101071
101072 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
101073- __FILE__, __LINE__, tty->driver->name, port->count);
101074+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101075
101076 schedule();
101077 }
101078@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101079
101080 spin_lock_irqsave(&port->lock, flags);
101081 if (!tty_hung_up_p(filp))
101082- port->count++;
101083+ atomic_inc(&port->count);
101084 port->blocked_open--;
101085 spin_unlock_irqrestore(&port->lock, flags);
101086
101087 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
101088- __FILE__, __LINE__, tty->driver->name, port->count);
101089+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101090
101091 if (!retval)
101092 port->flags |= ASYNC_NORMAL_ACTIVE;
101093@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
101094
101095 /* ++ is not atomic, so this should be protected - Jean II */
101096 spin_lock_irqsave(&self->port.lock, flags);
101097- self->port.count++;
101098+ atomic_inc(&self->port.count);
101099 spin_unlock_irqrestore(&self->port.lock, flags);
101100 tty_port_tty_set(&self->port, tty);
101101
101102 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
101103- self->line, self->port.count);
101104+ self->line, atomic_read(&self->port.count));
101105
101106 /* Not really used by us, but lets do it anyway */
101107 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
101108@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
101109 tty_kref_put(port->tty);
101110 }
101111 port->tty = NULL;
101112- port->count = 0;
101113+ atomic_set(&port->count, 0);
101114 spin_unlock_irqrestore(&port->lock, flags);
101115
101116 wake_up_interruptible(&port->open_wait);
101117@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
101118 seq_putc(m, '\n');
101119
101120 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
101121- seq_printf(m, "Open count: %d\n", self->port.count);
101122+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
101123 seq_printf(m, "Max data size: %d\n", self->max_data_size);
101124 seq_printf(m, "Max header size: %d\n", self->max_header_size);
101125
101126diff --git a/net/irda/irproc.c b/net/irda/irproc.c
101127index b9ac598..f88cc56 100644
101128--- a/net/irda/irproc.c
101129+++ b/net/irda/irproc.c
101130@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
101131 {
101132 int i;
101133
101134- proc_irda = proc_mkdir("irda", init_net.proc_net);
101135+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
101136 if (proc_irda == NULL)
101137 return;
101138
101139diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
101140index c4b7218..c7e9f14 100644
101141--- a/net/iucv/af_iucv.c
101142+++ b/net/iucv/af_iucv.c
101143@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
101144
101145 write_lock_bh(&iucv_sk_list.lock);
101146
101147- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
101148+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101149 while (__iucv_get_sock_by_name(name)) {
101150 sprintf(name, "%08x",
101151- atomic_inc_return(&iucv_sk_list.autobind_name));
101152+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101153 }
101154
101155 write_unlock_bh(&iucv_sk_list.lock);
101156@@ -1829,7 +1829,7 @@ static void iucv_callback_txdone(struct iucv_path *path,
101157 spin_lock_irqsave(&list->lock, flags);
101158
101159 while (list_skb != (struct sk_buff *)list) {
101160- if (msg->tag != IUCV_SKB_CB(list_skb)->tag) {
101161+ if (msg->tag == IUCV_SKB_CB(list_skb)->tag) {
101162 this = list_skb;
101163 break;
101164 }
101165diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
101166index cd5b8ec..f205e6b 100644
101167--- a/net/iucv/iucv.c
101168+++ b/net/iucv/iucv.c
101169@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
101170 return NOTIFY_OK;
101171 }
101172
101173-static struct notifier_block __refdata iucv_cpu_notifier = {
101174+static struct notifier_block iucv_cpu_notifier = {
101175 .notifier_call = iucv_cpu_notify,
101176 };
101177
101178diff --git a/net/key/af_key.c b/net/key/af_key.c
101179index 7932697..a13d158 100644
101180--- a/net/key/af_key.c
101181+++ b/net/key/af_key.c
101182@@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
101183 static u32 get_acqseq(void)
101184 {
101185 u32 res;
101186- static atomic_t acqseq;
101187+ static atomic_unchecked_t acqseq;
101188
101189 do {
101190- res = atomic_inc_return(&acqseq);
101191+ res = atomic_inc_return_unchecked(&acqseq);
101192 } while (!res);
101193 return res;
101194 }
101195diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
101196index 0b44d85..1a7f88b 100644
101197--- a/net/l2tp/l2tp_ip.c
101198+++ b/net/l2tp/l2tp_ip.c
101199@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101200 if (flags & MSG_OOB)
101201 goto out;
101202
101203+ if (addr_len)
101204+ *addr_len = sizeof(*sin);
101205+
101206 skb = skb_recv_datagram(sk, flags, noblock, &err);
101207 if (!skb)
101208 goto out;
101209@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101210 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
101211 sin->sin_port = 0;
101212 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
101213- *addr_len = sizeof(*sin);
101214 }
101215 if (inet->cmsg_flags)
101216 ip_cmsg_recv(msg, skb);
101217diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
101218index 1a3c7e0..80f8b0c 100644
101219--- a/net/llc/llc_proc.c
101220+++ b/net/llc/llc_proc.c
101221@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
101222 int rc = -ENOMEM;
101223 struct proc_dir_entry *p;
101224
101225- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
101226+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
101227 if (!llc_proc_dir)
101228 goto out;
101229
101230diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
101231index 453e974..b3a43a5 100644
101232--- a/net/mac80211/cfg.c
101233+++ b/net/mac80211/cfg.c
101234@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
101235 ret = ieee80211_vif_use_channel(sdata, chandef,
101236 IEEE80211_CHANCTX_EXCLUSIVE);
101237 }
101238- } else if (local->open_count == local->monitors) {
101239+ } else if (local_read(&local->open_count) == local->monitors) {
101240 local->_oper_chandef = *chandef;
101241 ieee80211_hw_config(local, 0);
101242 }
101243@@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
101244 else
101245 local->probe_req_reg--;
101246
101247- if (!local->open_count)
101248+ if (!local_read(&local->open_count))
101249 break;
101250
101251 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
101252@@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
101253 if (chanctx_conf) {
101254 *chandef = chanctx_conf->def;
101255 ret = 0;
101256- } else if (local->open_count > 0 &&
101257- local->open_count == local->monitors &&
101258+ } else if (local_read(&local->open_count) > 0 &&
101259+ local_read(&local->open_count) == local->monitors &&
101260 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
101261 if (local->use_chanctx)
101262 *chandef = local->monitor_chandef;
101263diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
101264index b127902..9dc4947 100644
101265--- a/net/mac80211/ieee80211_i.h
101266+++ b/net/mac80211/ieee80211_i.h
101267@@ -28,6 +28,7 @@
101268 #include <net/ieee80211_radiotap.h>
101269 #include <net/cfg80211.h>
101270 #include <net/mac80211.h>
101271+#include <asm/local.h>
101272 #include "key.h"
101273 #include "sta_info.h"
101274 #include "debug.h"
101275@@ -995,7 +996,7 @@ struct ieee80211_local {
101276 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
101277 spinlock_t queue_stop_reason_lock;
101278
101279- int open_count;
101280+ local_t open_count;
101281 int monitors, cooked_mntrs;
101282 /* number of interfaces with corresponding FIF_ flags */
101283 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101284diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101285index ce1c443..6cd39e1 100644
101286--- a/net/mac80211/iface.c
101287+++ b/net/mac80211/iface.c
101288@@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101289 break;
101290 }
101291
101292- if (local->open_count == 0) {
101293+ if (local_read(&local->open_count) == 0) {
101294 res = drv_start(local);
101295 if (res)
101296 goto err_del_bss;
101297@@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101298 res = drv_add_interface(local, sdata);
101299 if (res)
101300 goto err_stop;
101301- } else if (local->monitors == 0 && local->open_count == 0) {
101302+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101303 res = ieee80211_add_virtual_monitor(local);
101304 if (res)
101305 goto err_stop;
101306@@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101307 atomic_inc(&local->iff_promiscs);
101308
101309 if (coming_up)
101310- local->open_count++;
101311+ local_inc(&local->open_count);
101312
101313 if (hw_reconf_flags)
101314 ieee80211_hw_config(local, hw_reconf_flags);
101315@@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101316 err_del_interface:
101317 drv_remove_interface(local, sdata);
101318 err_stop:
101319- if (!local->open_count)
101320+ if (!local_read(&local->open_count))
101321 drv_stop(local);
101322 err_del_bss:
101323 sdata->bss = NULL;
101324@@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101325 }
101326
101327 if (going_down)
101328- local->open_count--;
101329+ local_dec(&local->open_count);
101330
101331 switch (sdata->vif.type) {
101332 case NL80211_IFTYPE_AP_VLAN:
101333@@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101334 }
101335 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101336
101337- if (local->open_count == 0)
101338+ if (local_read(&local->open_count) == 0)
101339 ieee80211_clear_tx_pending(local);
101340
101341 /*
101342@@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101343
101344 ieee80211_recalc_ps(local, -1);
101345
101346- if (local->open_count == 0) {
101347+ if (local_read(&local->open_count) == 0) {
101348 ieee80211_stop_device(local);
101349
101350 /* no reconfiguring after stop! */
101351@@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101352 ieee80211_configure_filter(local);
101353 ieee80211_hw_config(local, hw_reconf_flags);
101354
101355- if (local->monitors == local->open_count)
101356+ if (local->monitors == local_read(&local->open_count))
101357 ieee80211_add_virtual_monitor(local);
101358 }
101359
101360diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101361index c7a7a86..a74f57b 100644
101362--- a/net/mac80211/main.c
101363+++ b/net/mac80211/main.c
101364@@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101365 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101366 IEEE80211_CONF_CHANGE_POWER);
101367
101368- if (changed && local->open_count) {
101369+ if (changed && local_read(&local->open_count)) {
101370 ret = drv_config(local, changed);
101371 /*
101372 * Goal:
101373diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101374index d478b88..8c8d157 100644
101375--- a/net/mac80211/pm.c
101376+++ b/net/mac80211/pm.c
101377@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101378 struct ieee80211_sub_if_data *sdata;
101379 struct sta_info *sta;
101380
101381- if (!local->open_count)
101382+ if (!local_read(&local->open_count))
101383 goto suspend;
101384
101385 ieee80211_scan_cancel(local);
101386@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101387 cancel_work_sync(&local->dynamic_ps_enable_work);
101388 del_timer_sync(&local->dynamic_ps_timer);
101389
101390- local->wowlan = wowlan && local->open_count;
101391+ local->wowlan = wowlan && local_read(&local->open_count);
101392 if (local->wowlan) {
101393 int err = drv_suspend(local, wowlan);
101394 if (err < 0) {
101395@@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101396 WARN_ON(!list_empty(&local->chanctx_list));
101397
101398 /* stop hardware - this must stop RX */
101399- if (local->open_count)
101400+ if (local_read(&local->open_count))
101401 ieee80211_stop_device(local);
101402
101403 suspend:
101404diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101405index 22b223f..ab70070 100644
101406--- a/net/mac80211/rate.c
101407+++ b/net/mac80211/rate.c
101408@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101409
101410 ASSERT_RTNL();
101411
101412- if (local->open_count)
101413+ if (local_read(&local->open_count))
101414 return -EBUSY;
101415
101416 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101417diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101418index 6ff1346..936ca9a 100644
101419--- a/net/mac80211/rc80211_pid_debugfs.c
101420+++ b/net/mac80211/rc80211_pid_debugfs.c
101421@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101422
101423 spin_unlock_irqrestore(&events->lock, status);
101424
101425- if (copy_to_user(buf, pb, p))
101426+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101427 return -EFAULT;
101428
101429 return p;
101430diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101431index 6427625..afa5a5a 100644
101432--- a/net/mac80211/util.c
101433+++ b/net/mac80211/util.c
101434@@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101435 }
101436 #endif
101437 /* everything else happens only if HW was up & running */
101438- if (!local->open_count)
101439+ if (!local_read(&local->open_count))
101440 goto wake_up;
101441
101442 /*
101443@@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101444 local->in_reconfig = false;
101445 barrier();
101446
101447- if (local->monitors == local->open_count && local->monitors > 0)
101448+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101449 ieee80211_add_virtual_monitor(local);
101450
101451 /*
101452diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101453index e9410d1..77b6378 100644
101454--- a/net/netfilter/Kconfig
101455+++ b/net/netfilter/Kconfig
101456@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101457
101458 To compile it as a module, choose M here. If unsure, say N.
101459
101460+config NETFILTER_XT_MATCH_GRADM
101461+ tristate '"gradm" match support'
101462+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101463+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101464+ ---help---
101465+ The gradm match allows to match on grsecurity RBAC being enabled.
101466+ It is useful when iptables rules are applied early on bootup to
101467+ prevent connections to the machine (except from a trusted host)
101468+ while the RBAC system is disabled.
101469+
101470 config NETFILTER_XT_MATCH_HASHLIMIT
101471 tristate '"hashlimit" match support'
101472 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101473diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101474index bffdad7..f9317d1 100644
101475--- a/net/netfilter/Makefile
101476+++ b/net/netfilter/Makefile
101477@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101478 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101479 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101480 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101481+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101482 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101483 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101484 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101485diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101486index de770ec..3fc49d2 100644
101487--- a/net/netfilter/ipset/ip_set_core.c
101488+++ b/net/netfilter/ipset/ip_set_core.c
101489@@ -1922,7 +1922,7 @@ done:
101490 return ret;
101491 }
101492
101493-static struct nf_sockopt_ops so_set __read_mostly = {
101494+static struct nf_sockopt_ops so_set = {
101495 .pf = PF_INET,
101496 .get_optmin = SO_IP_SET,
101497 .get_optmax = SO_IP_SET + 1,
101498diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101499index a8eb0a8..86f2de4 100644
101500--- a/net/netfilter/ipvs/ip_vs_conn.c
101501+++ b/net/netfilter/ipvs/ip_vs_conn.c
101502@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101503 /* Increase the refcnt counter of the dest */
101504 ip_vs_dest_hold(dest);
101505
101506- conn_flags = atomic_read(&dest->conn_flags);
101507+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
101508 if (cp->protocol != IPPROTO_UDP)
101509 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101510 flags = cp->flags;
101511@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101512
101513 cp->control = NULL;
101514 atomic_set(&cp->n_control, 0);
101515- atomic_set(&cp->in_pkts, 0);
101516+ atomic_set_unchecked(&cp->in_pkts, 0);
101517
101518 cp->packet_xmit = NULL;
101519 cp->app = NULL;
101520@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101521
101522 /* Don't drop the entry if its number of incoming packets is not
101523 located in [0, 8] */
101524- i = atomic_read(&cp->in_pkts);
101525+ i = atomic_read_unchecked(&cp->in_pkts);
101526 if (i > 8 || i < 0) return 0;
101527
101528 if (!todrop_rate[i]) return 0;
101529diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101530index 4f26ee4..6a9d7c3 100644
101531--- a/net/netfilter/ipvs/ip_vs_core.c
101532+++ b/net/netfilter/ipvs/ip_vs_core.c
101533@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101534 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101535 /* do not touch skb anymore */
101536
101537- atomic_inc(&cp->in_pkts);
101538+ atomic_inc_unchecked(&cp->in_pkts);
101539 ip_vs_conn_put(cp);
101540 return ret;
101541 }
101542@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101543 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101544 pkts = sysctl_sync_threshold(ipvs);
101545 else
101546- pkts = atomic_add_return(1, &cp->in_pkts);
101547+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101548
101549 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101550 ip_vs_sync_conn(net, cp, pkts);
101551diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101552index 35be035..50f8834 100644
101553--- a/net/netfilter/ipvs/ip_vs_ctl.c
101554+++ b/net/netfilter/ipvs/ip_vs_ctl.c
101555@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101556 */
101557 ip_vs_rs_hash(ipvs, dest);
101558 }
101559- atomic_set(&dest->conn_flags, conn_flags);
101560+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
101561
101562 /* bind the service */
101563 old_svc = rcu_dereference_protected(dest->svc, 1);
101564@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101565 * align with netns init in ip_vs_control_net_init()
101566 */
101567
101568-static struct ctl_table vs_vars[] = {
101569+static ctl_table_no_const vs_vars[] __read_only = {
101570 {
101571 .procname = "amemthresh",
101572 .maxlen = sizeof(int),
101573@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101574 " %-7s %-6d %-10d %-10d\n",
101575 &dest->addr.in6,
101576 ntohs(dest->port),
101577- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101578+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101579 atomic_read(&dest->weight),
101580 atomic_read(&dest->activeconns),
101581 atomic_read(&dest->inactconns));
101582@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101583 "%-7s %-6d %-10d %-10d\n",
101584 ntohl(dest->addr.ip),
101585 ntohs(dest->port),
101586- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101587+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101588 atomic_read(&dest->weight),
101589 atomic_read(&dest->activeconns),
101590 atomic_read(&dest->inactconns));
101591@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101592
101593 entry.addr = dest->addr.ip;
101594 entry.port = dest->port;
101595- entry.conn_flags = atomic_read(&dest->conn_flags);
101596+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101597 entry.weight = atomic_read(&dest->weight);
101598 entry.u_threshold = dest->u_threshold;
101599 entry.l_threshold = dest->l_threshold;
101600@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101601 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101602 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101603 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101604- (atomic_read(&dest->conn_flags) &
101605+ (atomic_read_unchecked(&dest->conn_flags) &
101606 IP_VS_CONN_F_FWD_MASK)) ||
101607 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101608 atomic_read(&dest->weight)) ||
101609@@ -3580,7 +3580,7 @@ out:
101610 }
101611
101612
101613-static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
101614+static const struct genl_ops ip_vs_genl_ops[] = {
101615 {
101616 .cmd = IPVS_CMD_NEW_SERVICE,
101617 .flags = GENL_ADMIN_PERM,
101618@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101619 {
101620 int idx;
101621 struct netns_ipvs *ipvs = net_ipvs(net);
101622- struct ctl_table *tbl;
101623+ ctl_table_no_const *tbl;
101624
101625 atomic_set(&ipvs->dropentry, 0);
101626 spin_lock_init(&ipvs->dropentry_lock);
101627diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101628index ca056a3..9cf01ef 100644
101629--- a/net/netfilter/ipvs/ip_vs_lblc.c
101630+++ b/net/netfilter/ipvs/ip_vs_lblc.c
101631@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101632 * IPVS LBLC sysctl table
101633 */
101634 #ifdef CONFIG_SYSCTL
101635-static struct ctl_table vs_vars_table[] = {
101636+static ctl_table_no_const vs_vars_table[] __read_only = {
101637 {
101638 .procname = "lblc_expiration",
101639 .data = NULL,
101640diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101641index 3f21a2f..a112e85 100644
101642--- a/net/netfilter/ipvs/ip_vs_lblcr.c
101643+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101644@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101645 * IPVS LBLCR sysctl table
101646 */
101647
101648-static struct ctl_table vs_vars_table[] = {
101649+static ctl_table_no_const vs_vars_table[] __read_only = {
101650 {
101651 .procname = "lblcr_expiration",
101652 .data = NULL,
101653diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101654index db80126..ef7110e 100644
101655--- a/net/netfilter/ipvs/ip_vs_sync.c
101656+++ b/net/netfilter/ipvs/ip_vs_sync.c
101657@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101658 cp = cp->control;
101659 if (cp) {
101660 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101661- pkts = atomic_add_return(1, &cp->in_pkts);
101662+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101663 else
101664 pkts = sysctl_sync_threshold(ipvs);
101665 ip_vs_sync_conn(net, cp->control, pkts);
101666@@ -771,7 +771,7 @@ control:
101667 if (!cp)
101668 return;
101669 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101670- pkts = atomic_add_return(1, &cp->in_pkts);
101671+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101672 else
101673 pkts = sysctl_sync_threshold(ipvs);
101674 goto sloop;
101675@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101676
101677 if (opt)
101678 memcpy(&cp->in_seq, opt, sizeof(*opt));
101679- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101680+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101681 cp->state = state;
101682 cp->old_state = cp->state;
101683 /*
101684diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101685index c47444e..b0961c6 100644
101686--- a/net/netfilter/ipvs/ip_vs_xmit.c
101687+++ b/net/netfilter/ipvs/ip_vs_xmit.c
101688@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
101689 else
101690 rc = NF_ACCEPT;
101691 /* do not touch skb anymore */
101692- atomic_inc(&cp->in_pkts);
101693+ atomic_inc_unchecked(&cp->in_pkts);
101694 goto out;
101695 }
101696
101697@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
101698 else
101699 rc = NF_ACCEPT;
101700 /* do not touch skb anymore */
101701- atomic_inc(&cp->in_pkts);
101702+ atomic_inc_unchecked(&cp->in_pkts);
101703 goto out;
101704 }
101705
101706diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
101707index a4b5e2a..13b1de3 100644
101708--- a/net/netfilter/nf_conntrack_acct.c
101709+++ b/net/netfilter/nf_conntrack_acct.c
101710@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101711 #ifdef CONFIG_SYSCTL
101712 static int nf_conntrack_acct_init_sysctl(struct net *net)
101713 {
101714- struct ctl_table *table;
101715+ ctl_table_no_const *table;
101716
101717 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
101718 GFP_KERNEL);
101719diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
101720index 356bef5..99932cb 100644
101721--- a/net/netfilter/nf_conntrack_core.c
101722+++ b/net/netfilter/nf_conntrack_core.c
101723@@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
101724 #define DYING_NULLS_VAL ((1<<30)+1)
101725 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
101726
101727+#ifdef CONFIG_GRKERNSEC_HIDESYM
101728+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
101729+#endif
101730+
101731 int nf_conntrack_init_net(struct net *net)
101732 {
101733 int ret;
101734@@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
101735 goto err_stat;
101736 }
101737
101738+#ifdef CONFIG_GRKERNSEC_HIDESYM
101739+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
101740+#else
101741 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
101742+#endif
101743 if (!net->ct.slabname) {
101744 ret = -ENOMEM;
101745 goto err_slabname;
101746diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
101747index 1df1761..ce8b88a 100644
101748--- a/net/netfilter/nf_conntrack_ecache.c
101749+++ b/net/netfilter/nf_conntrack_ecache.c
101750@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
101751 #ifdef CONFIG_SYSCTL
101752 static int nf_conntrack_event_init_sysctl(struct net *net)
101753 {
101754- struct ctl_table *table;
101755+ ctl_table_no_const *table;
101756
101757 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
101758 GFP_KERNEL);
101759diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
101760index 974a2a4..52cc6ff 100644
101761--- a/net/netfilter/nf_conntrack_helper.c
101762+++ b/net/netfilter/nf_conntrack_helper.c
101763@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
101764
101765 static int nf_conntrack_helper_init_sysctl(struct net *net)
101766 {
101767- struct ctl_table *table;
101768+ ctl_table_no_const *table;
101769
101770 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
101771 GFP_KERNEL);
101772diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
101773index b65d586..beec902 100644
101774--- a/net/netfilter/nf_conntrack_proto.c
101775+++ b/net/netfilter/nf_conntrack_proto.c
101776@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
101777
101778 static void
101779 nf_ct_unregister_sysctl(struct ctl_table_header **header,
101780- struct ctl_table **table,
101781+ ctl_table_no_const **table,
101782 unsigned int users)
101783 {
101784 if (users > 0)
101785diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
101786index f641751..d3c5b51 100644
101787--- a/net/netfilter/nf_conntrack_standalone.c
101788+++ b/net/netfilter/nf_conntrack_standalone.c
101789@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
101790
101791 static int nf_conntrack_standalone_init_sysctl(struct net *net)
101792 {
101793- struct ctl_table *table;
101794+ ctl_table_no_const *table;
101795
101796 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
101797 GFP_KERNEL);
101798diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
101799index 7a394df..bd91a8a 100644
101800--- a/net/netfilter/nf_conntrack_timestamp.c
101801+++ b/net/netfilter/nf_conntrack_timestamp.c
101802@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
101803 #ifdef CONFIG_SYSCTL
101804 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
101805 {
101806- struct ctl_table *table;
101807+ ctl_table_no_const *table;
101808
101809 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
101810 GFP_KERNEL);
101811diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
101812index 85296d4..8becdec 100644
101813--- a/net/netfilter/nf_log.c
101814+++ b/net/netfilter/nf_log.c
101815@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
101816
101817 #ifdef CONFIG_SYSCTL
101818 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
101819-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
101820+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
101821
101822 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101823 void __user *buffer, size_t *lenp, loff_t *ppos)
101824@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101825 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101826 mutex_unlock(&nf_log_mutex);
101827 } else {
101828+ ctl_table_no_const nf_log_table = *table;
101829+
101830 mutex_lock(&nf_log_mutex);
101831 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
101832 lockdep_is_held(&nf_log_mutex));
101833 if (!logger)
101834- table->data = "NONE";
101835+ nf_log_table.data = "NONE";
101836 else
101837- table->data = logger->name;
101838- r = proc_dostring(table, write, buffer, lenp, ppos);
101839+ nf_log_table.data = logger->name;
101840+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
101841 mutex_unlock(&nf_log_mutex);
101842 }
101843
101844diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
101845index f042ae5..30ea486 100644
101846--- a/net/netfilter/nf_sockopt.c
101847+++ b/net/netfilter/nf_sockopt.c
101848@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
101849 }
101850 }
101851
101852- list_add(&reg->list, &nf_sockopts);
101853+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
101854 out:
101855 mutex_unlock(&nf_sockopt_mutex);
101856 return ret;
101857@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
101858 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
101859 {
101860 mutex_lock(&nf_sockopt_mutex);
101861- list_del(&reg->list);
101862+ pax_list_del((struct list_head *)&reg->list);
101863 mutex_unlock(&nf_sockopt_mutex);
101864 }
101865 EXPORT_SYMBOL(nf_unregister_sockopt);
101866diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
101867index c68e5e0..8d52d50 100644
101868--- a/net/netfilter/nf_tables_api.c
101869+++ b/net/netfilter/nf_tables_api.c
101870@@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
101871 #ifdef CONFIG_MODULES
101872 if (autoload) {
101873 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
101874- request_module("nft-chain-%u-%*.s", afi->family,
101875- nla_len(nla)-1, (const char *)nla_data(nla));
101876+ request_module("nft-chain-%u-%.*s", afi->family,
101877+ nla_len(nla), (const char *)nla_data(nla));
101878 nfnl_lock(NFNL_SUBSYS_NFTABLES);
101879 type = __nf_tables_chain_type_lookup(afi->family, nla);
101880 if (type != NULL)
101881diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
101882index a155d19..726b0f2 100644
101883--- a/net/netfilter/nfnetlink_log.c
101884+++ b/net/netfilter/nfnetlink_log.c
101885@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
101886 struct nfnl_log_net {
101887 spinlock_t instances_lock;
101888 struct hlist_head instance_table[INSTANCE_BUCKETS];
101889- atomic_t global_seq;
101890+ atomic_unchecked_t global_seq;
101891 };
101892
101893 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
101894@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
101895 /* global sequence number */
101896 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
101897 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
101898- htonl(atomic_inc_return(&log->global_seq))))
101899+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
101900 goto nla_put_failure;
101901
101902 if (data_len) {
101903diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
101904index 82cb823..5685dd5 100644
101905--- a/net/netfilter/nft_compat.c
101906+++ b/net/netfilter/nft_compat.c
101907@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
101908 /* We want to reuse existing compat_to_user */
101909 old_fs = get_fs();
101910 set_fs(KERNEL_DS);
101911- t->compat_to_user(out, in);
101912+ t->compat_to_user((void __force_user *)out, in);
101913 set_fs(old_fs);
101914 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
101915 kfree(out);
101916@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
101917 /* We want to reuse existing compat_to_user */
101918 old_fs = get_fs();
101919 set_fs(KERNEL_DS);
101920- m->compat_to_user(out, in);
101921+ m->compat_to_user((void __force_user *)out, in);
101922 set_fs(old_fs);
101923 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101924 kfree(out);
101925diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101926new file mode 100644
101927index 0000000..c566332
101928--- /dev/null
101929+++ b/net/netfilter/xt_gradm.c
101930@@ -0,0 +1,51 @@
101931+/*
101932+ * gradm match for netfilter
101933